From 0d0f25004d4142666c28c8ec2cd02d7e01212012 Mon Sep 17 00:00:00 2001 From: "warren.toomey" Date: Tue, 6 May 2008 01:09:49 +0000 Subject: [PATCH] Added initial support for loading symbol table from 0407 binary. --- tools/disaout/aout.c | 13 ++++---- tools/disaout/aout.h | 25 +++++++++++++- tools/disaout/magic.c | 5 ++- tools/disaout/main.c | 4 +-- tools/disaout/opset.c | 3 -- tools/disaout/symbols.c | 71 +++++++++++++++++++++++++++++++++++++--- tools/disaout/syscalls.c | 1 - 7 files changed, 102 insertions(+), 20 deletions(-) diff --git a/tools/disaout/aout.c b/tools/disaout/aout.c index 3ba3a79..37d709e 100644 --- a/tools/disaout/aout.c +++ b/tools/disaout/aout.c @@ -1,12 +1,9 @@ -#include -#include -#include #include "aout.h" - /* This code borrowed from Apout */ extern int special_magic(u_int16_t *cptr); +extern void load_0407_symbols(FILE *zin, int offset, int size, int base); int Binary; /* Type of binary this a.out is */ u_int8_t *ispace, *dspace; /* Instruction and Data spaces */ @@ -153,11 +150,14 @@ int load_a_out(const char *file, struct exec * e) e->a_entry = V12_MEMBASE; dbase = &(ispace[e->a_text + V12_MEMBASE]); bbase = &(ispace[e->a_text + e->a_data + V12_MEMBASE]); - } else - { + } else { dbase = &(ispace[e->a_text]); bbase = &(ispace[e->a_text + e->a_data]); } + + /* If there is a symbol table, load it */ + if (e->a_syms) + load_0407_symbols(zin, 16 + e->a_text + e->a_data,e->a_syms,e->a_entry); break; case ANY_ROTEXT: /* Move back to end of V5/6/7 header */ @@ -259,6 +259,7 @@ int load_a_out(const char *file, struct exec * e) if ((bbase != 0) && (e->a_bss != 0)) memset(bbase, 0, (size_t) e->a_bss); + (void) fclose(zin); return (0); } diff --git a/tools/disaout/aout.h b/tools/disaout/aout.h index 65ce030..c20a0d0 100644 --- a/tools/disaout/aout.h +++ b/tools/disaout/aout.h @@ -2,8 +2,13 @@ * aout.h - parse and load the contents of a UNIX a.out file, for several * flavours of PDP-11 UNIX * - * $Revision: 1.6 $ $Date: 2008/05/01 03:23:21 $ + * $Revision: 1.7 $ $Date: 2008/05/06 01:09:01 $ */ +#include +#include +#include +#include +#include #include #define EIGHT_K 8192 #define PDP_MEM_SIZE 65536 /* Size of inst-space and data-space */ @@ -55,6 +60,24 @@ struct exec { /* the read of this section */ }; +/* Symbol table entries for 0407 binaries */ +struct sym0407 { + u_int8_t name[8]; + u_int16_t type; + u_int16_t addr; +}; + +#define ASYM_UNDEFINED 00 +#define ASYM_ABSOLUTE 01 +#define ASYM_TEXT 02 +#define ASYM_DATA 03 +#define ASYM_BSS 04 +#define ASYM_UNDEFEXT 40 +#define ASYM_ABSEXT 41 +#define ASYM_TEXTEXT 42 +#define ASYM_DATAEXT 43 +#define ASYM_BSSDEXT 44 + /* * Because V5, V6, V7 and 2.11BSD share several magic numbers in their a.out * headers, we must distinguish them so as to set up the correct emulated diff --git a/tools/disaout/magic.c b/tools/disaout/magic.c index 0636161..1833fcf 100644 --- a/tools/disaout/magic.c +++ b/tools/disaout/magic.c @@ -8,10 +8,9 @@ * a.out header. If it matches any of the checksums below, it returns * the appropriate environment value. Otherwise, it returns IS_UNKNOWN. * - * $Revision: 1.1 $ - * $Date: 2008/04/30 03:46:29 $ + * $Revision: 1.2 $ + * $Date: 2008/05/06 01:09:01 $ */ -#include #include "aout.h" struct spec_aout { diff --git a/tools/disaout/main.c b/tools/disaout/main.c index 2e38718..16c22c6 100644 --- a/tools/disaout/main.c +++ b/tools/disaout/main.c @@ -1,10 +1,9 @@ -#include -#include #include "aout.h" extern int load_a_out(const char *file, struct exec *E); extern int printins(int addr); extern void patch_symbols(void); +extern void print_symtables(void); extern u_int8_t *ispace, *dspace; /* Instruction and Data spaces */ extern int doprint; int onepass = 0; /* Only do a single pass */ @@ -70,6 +69,7 @@ int main(int argc, char *argv[]) doprint = 0; dopass(&E); /* Do pass 1 to infer symbols */ patch_symbols(); + /* print_symtables(); */ } doprint = 1; dopass(&E); /* Do pass 2 to print it out */ diff --git a/tools/disaout/opset.c b/tools/disaout/opset.c index 8cd146e..90a5fe1 100644 --- a/tools/disaout/opset.c +++ b/tools/disaout/opset.c @@ -1,8 +1,5 @@ /* This code borrowed from 2.11BSD adb */ -#include -#include -#include #include "aout.h" extern void add_symbol(int addr, int type, int size); diff --git a/tools/disaout/symbols.c b/tools/disaout/symbols.c index be6cc93..6f76e31 100644 --- a/tools/disaout/symbols.c +++ b/tools/disaout/symbols.c @@ -1,8 +1,5 @@ /* Tables and functions to keep track of symbols */ -#include -#include -#include #include "aout.h" struct symbol * isym[PDP_MEM_SIZE], * dsym[PDP_MEM_SIZE]; @@ -20,6 +17,18 @@ struct symtype { { "jsrdata%d", 1, isym }, }; +/* Debug code */ +void print_symtables(void) +{ + int i; + for (i=0; i< PDP_MEM_SIZE; i++) { + if (isym[i]!=NULL) + printf("0%06o %d %d %s\n",i, isym[i]->type, isym[i]->size, isym[i]->name); + if (dsym[i]!=NULL) + printf("0%06o %d %d %s\n",i, dsym[i]->type, dsym[i]->size, dsym[i]->name); + } +} + void add_symbol(int addr, int type, int size) { struct symbol *s; @@ -33,6 +42,7 @@ void add_symbol(int addr, int type, int size) s->name= malloc(12); snprintf(s->name,12,symtypelist[type].format, symtypelist[type].counter++); #endif + s->name= NULL; /* To be filled in later */ s->type= type; s->size= size; symtypelist[type].table[addr]= s; @@ -47,8 +57,10 @@ void patch_symbols(void) struct symbol *s; for (i=0; i< PDP_MEM_SIZE; i++) { if (isym[i]==NULL) continue; - s= isym[i]; s->name= malloc(12); + s= isym[i]; + if (s->name != NULL) continue; type=s->type; + s->name= malloc(12); snprintf(s->name,12,symtypelist[type].format, symtypelist[type].counter++); } for (i=0; i< PDP_MEM_SIZE; i++) { @@ -68,3 +80,54 @@ struct symbol * get_dsym(int addr) { return(dsym[addr]); } + +/* Walk the 0407 symbol table and load the symbols found */ +void load_0407_symbols(FILE *zin, int offset, int size, int base) +{ + struct sym0407 S; + struct symbol *oursym; + char name[9]; + long curpos; + + /* Record where we are, and seek to the symbol table */ + curpos= ftell(zin); + if (fseek(zin, offset, SEEK_SET) != 0) { + printf("Unable to load symbol table at offset %d\n", offset); + return; + } + name[8]='\0'; /* Ensure we get a properly terminated string */ + + /* Walk the list */ + while (size>0) { + fread(&S, sizeof(S), 1, zin); size -= sizeof(S); + memcpy(name, S.name, 8); + S.addr += base; + + switch (S.type) { + case ASYM_DATA: + case ASYM_BSS: + case ASYM_DATAEXT: + case ASYM_BSSDEXT: + oursym= malloc(sizeof(struct symbol)); + oursym->name= strdup(name); + oursym->type= SYM_DATA; + oursym->size= 0; + dsym[S.addr]= oursym; + break; + + case ASYM_TEXT: + case ASYM_TEXTEXT: + oursym= malloc(sizeof(struct symbol)); + oursym->name= strdup(name); + /* If it starts with l[0-9], it's a branch */ + if (name[0]=='l' && name[1] >= '0' && name[1] <= '9') + oursym->type= SYM_BRANCH; + else + oursym->type= SYM_FUNCTION; + oursym->size= 0; + isym[S.addr]= oursym; + break; + } + } + fseek(zin, curpos, SEEK_SET); +} diff --git a/tools/disaout/syscalls.c b/tools/disaout/syscalls.c index 24aa4d6..cedeeef 100644 --- a/tools/disaout/syscalls.c +++ b/tools/disaout/syscalls.c @@ -1,7 +1,6 @@ /* List of system calls, per UNIX version */ #include "aout.h" - struct syscallinfo v1syscalls[]= { { "rele", 0 }, { "exit", 0 },