mirror of
https://github.com/DoctorWkt/unix-jun72.git
synced 2026-02-26 17:04:03 +00:00
Added initial support for loading symbol table from 0407 binary.
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -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 <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#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
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
#include "aout.h"
|
||||
|
||||
struct spec_aout {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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 */
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
/* This code borrowed from 2.11BSD adb */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include "aout.h"
|
||||
|
||||
extern void add_symbol(int addr, int type, int size);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
/* Tables and functions to keep track of symbols */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* List of system calls, per UNIX version */
|
||||
#include "aout.h"
|
||||
|
||||
|
||||
struct syscallinfo v1syscalls[]= {
|
||||
{ "rele", 0 },
|
||||
{ "exit", 0 },
|
||||
|
||||
Reference in New Issue
Block a user