1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/vm/pc/sym.c

65 lines
1.4 KiB
C
Raw Normal View History

2019-06-19 13:47:10 +02:00
// 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)
{
2019-06-19 21:41:22 +02:00
logerr("Couldn't open symtab\n");
2019-06-19 13:47:10 +02:00
return -1;
}
while (fscanf(tab, "%s %lu\n", buf, &addr) > 0 && it < SYMTAB_LEN)
{
// log("SYM: '%.*s' '%lu'\n", SYMLEN_MAX, buf, addr);
2019-06-21 19:38:31 +02:00
if (prev_addr > addr)
2019-06-19 13:47:10 +02:00
{
2019-06-19 21:41:22 +02:00
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);
2019-06-19 13:47:10 +02:00
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;
}