# HG changeset patch # User Michael Spacefalcon # Date 1395772443 0 # Node ID 10f3fbff5e97f40058460af7e0b84e0bf9adcd49 # Parent 2bec477178fc60db7390caf5a418ab198de75dff tiobjd: symbol table parsing implemented diff -r 2bec477178fc -r 10f3fbff5e97 ticoff/basics.c --- a/ticoff/basics.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/basics.c Tue Mar 25 18:34:03 2014 +0000 @@ -45,6 +45,17 @@ return ptr[0] | ptr[1] << 8; } +get_s16(ptr) + u_char *ptr; +{ + int i; + + i = ptr[0] | ptr[1] << 8; + if (i >= 32768) + i -= 65536; + return(i); +} + unsigned get_u32(ptr) u_char *ptr; diff -r 2bec477178fc -r 10f3fbff5e97 ticoff/globals.c --- a/ticoff/globals.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/globals.c Tue Mar 25 18:34:03 2014 +0000 @@ -16,3 +16,4 @@ unsigned strtab_offset; struct internal_scnhdr *sections; +struct internal_syment **symtab; diff -r 2bec477178fc -r 10f3fbff5e97 ticoff/globals.h --- a/ticoff/globals.h Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/globals.h Tue Mar 25 18:34:03 2014 +0000 @@ -14,3 +14,4 @@ extern unsigned strtab_offset; extern struct internal_scnhdr *sections; +extern struct internal_syment **symtab; diff -r 2bec477178fc -r 10f3fbff5e97 ticoff/intstruct.h --- a/ticoff/intstruct.h Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/intstruct.h Tue Mar 25 18:34:03 2014 +0000 @@ -13,3 +13,12 @@ unsigned nlineent; unsigned flags; }; + +struct internal_syment { + char *name; + unsigned value; + int scnum; + int type; + int class; + u_char *aux; +}; diff -r 2bec477178fc -r 10f3fbff5e97 ticoff/tables.c --- a/ticoff/tables.c Tue Mar 25 08:51:32 2014 +0000 +++ b/ticoff/tables.c Tue Mar 25 18:34:03 2014 +0000 @@ -93,3 +93,53 @@ } exit(0); } + +get_int_symbol_table() +{ + unsigned n; + struct internal_syment *in; + + symtab = malloc(sizeof(struct internal_syment *) * nsymtab); + if (!symtab) { + perror("malloc"); + exit(1); + } + for (n = 0; n < nsymtab; ) { + in = malloc(sizeof(struct internal_syment)); + if (!in) { + perror("malloc"); + exit(1); + } + symtab[n] = in; + in->name = get_secorsym_name(symtab_raw[n].e_name); + in->value = get_u32(symtab_raw[n].e_value); + in->scnum = get_s16(symtab_raw[n].e_scnum); + if (in->scnum < -2 || in->scnum > nsections) { + fprintf(stderr, + "symtab entry #%u: scnum out of range\n", n); + exit(1); + } + in->type = get_u16(symtab_raw[n].e_type); + in->class = symtab_raw[n].e_sclass; + switch (symtab_raw[n++].e_numaux) { + case 0: + in->aux = 0; + continue; + case 1: + if (n >= nsymtab) { + fprintf(stderr, + "error: last symbol's aux spills over\n"); + exit(1); + } + symtab[n] = 0; + in->aux = (u_char *)(symtab_raw + n); + n++; + continue; + default: + n--; + fprintf(stderr, "symtab entry #%u: invalid numaux\n", + n); + exit(1); + } + } +}