// 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 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; }