mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
65 lines
1.4 KiB
C
65 lines
1.4 KiB
C
// The OS/K Team licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
#include <pc/arch.h>
|
|
|
|
sym_t symtab[SYMTAB_LEN] = { 0 };
|
|
|
|
int create_symtab(const char *name)
|
|
{
|
|
FILE *tab = fopen(name, "r");
|
|
ulong addr, prev_addr = 0;
|
|
char buf[SYMLEN_MAX] = { 0 };
|
|
size_t it = 0;
|
|
|
|
if (!tab)
|
|
{
|
|
logerr("Couldn't open symtab\n");
|
|
return -1;
|
|
}
|
|
|
|
while (fscanf(tab, "%s %lu\n", buf, &addr) > 0 && it < SYMTAB_LEN)
|
|
{
|
|
// log("SYM: '%.*s' '%lu'\n", SYMLEN_MAX, buf, addr);
|
|
|
|
if (prev_addr >= addr)
|
|
{
|
|
logerr("Symbol addresses in symbol table not in increasing order\n");
|
|
logerr("Previous symbol: '%s' '%lu'\n", symtab[it-1].name, prev_addr);
|
|
logerr("Current symbol: '%s' '%lu'\n", buf, addr);
|
|
exit(-55);
|
|
}
|
|
|
|
prev_addr = addr;
|
|
|
|
symtab[it].addr = addr;
|
|
strcpy(symtab[it].name, buf);
|
|
it++;
|
|
}
|
|
|
|
fclose(tab);
|
|
|
|
return 0;
|
|
}
|
|
|
|
sym_t *find_sym_by_addr(ulong addr)
|
|
{
|
|
ulong it;
|
|
sym_t *sym;
|
|
|
|
for (it = 0; it < SYMTAB_LEN; it++)
|
|
{
|
|
sym = &symtab[it];
|
|
|
|
if (sym->addr == addr)
|
|
return sym;
|
|
|
|
// Addresses in symtab are in increasing order
|
|
if (sym->addr == 0 || sym->addr > addr)
|
|
return NULL;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|