/programs/develop/libraries/menuetlibc/src/libmcoff/Makefile |
---|
0,0 → 1,17 |
include $(MENUETDEV)/osrules.mak |
OUTFILE = libmcoff.a |
OBJS = loadcoff.o section.o symtab.o relocate.o debug.o |
CFLAGS = -O2 -fomit-frame-pointer -fno-common -DMCOFF_MENUETOS=1 |
_all: $(OUTFILE) |
ifdef ON_MINGW |
del $(MENUETDEV)\lib\$(OUTFILE) |
copy $(OUTFILE) $(MENUETDEV)\lib |
copy *.h $(MENUETDEV)\include\mcoff |
else |
rm -f $(MENUETDEV)/lib/$(OUTFILE) |
cp $(OUTFILE) $(MENUETDEV)/lib |
cp *.h $(MENUETDEV)/include/mcoff |
endif |
include $(MENUETDEV)/makefiles/Makefile_for_lib |
/programs/develop/libraries/menuetlibc/src/libmcoff/_coff.h |
---|
0,0 → 1,315 |
#ifndef __MENUET_COFF_H |
#define __MENUET_COFF_H |
#ifdef __cplusplus |
extern "C" { |
#endif |
/********************** FILE HEADER **********************/ |
struct external_filehdr { |
unsigned short f_magic; /* magic number */ |
unsigned short f_nscns; /* number of sections */ |
unsigned long f_timdat; /* time & date stamp */ |
unsigned long f_symptr; /* file pointer to symtab */ |
unsigned long f_nsyms; /* number of symtab entries */ |
unsigned short f_opthdr; /* sizeof(optional hdr) */ |
unsigned short f_flags; /* flags */ |
}; |
/* Bits for f_flags: |
* F_RELFLG relocation info stripped from file |
* F_EXEC file is executable (no unresolved external references) |
* F_LNNO line numbers stripped from file |
* F_LSYMS local symbols stripped from file |
* F_AR32WR file has byte ordering of an AR32WR machine (e.g. vax) |
*/ |
#define F_RELFLG (0x0001) |
#define F_EXEC (0x0002) |
#define F_LNNO (0x0004) |
#define F_LSYMS (0x0008) |
#define I386MAGIC 0x14c |
#define I386AIXMAGIC 0x175 |
#define I386BADMAG(x) (((x).f_magic!=I386MAGIC) && (x).f_magic!=I386AIXMAGIC) |
#define FILHDR struct external_filehdr |
#define FILHSZ sizeof(FILHDR) |
/********************** AOUT "OPTIONAL HEADER" **********************/ |
typedef struct |
{ |
unsigned short magic; /* type of file */ |
unsigned short vstamp; /* version stamp */ |
unsigned long tsize; /* text size in bytes, padded to FW bdry*/ |
unsigned long dsize; /* initialized data " " */ |
unsigned long bsize; /* uninitialized data " " */ |
unsigned long entry; /* entry pt. */ |
unsigned long text_start; /* base of text used for this file */ |
unsigned long data_start; /* base of data used for this file */ |
} AOUTHDR; |
typedef struct gnu_aout { |
unsigned long info; |
unsigned long tsize; |
unsigned long dsize; |
unsigned long bsize; |
unsigned long symsize; |
unsigned long entry; |
unsigned long txrel; |
unsigned long dtrel; |
} GNU_AOUT; |
#define AOUTSZ (sizeof(AOUTHDR)) |
#define OMAGIC 0404 /* object files, eg as output */ |
#define ZMAGIC 0413 /* demand load format, eg normal ld output */ |
#define STMAGIC 0401 /* target shlib */ |
#define SHMAGIC 0443 /* host shlib */ |
/********************** SECTION HEADER **********************/ |
struct external_scnhdr { |
char s_name[8]; /* section name */ |
unsigned long s_paddr; /* physical address, aliased s_nlib */ |
unsigned long s_vaddr; /* virtual address */ |
unsigned long s_size; /* section size */ |
unsigned long s_scnptr; /* file ptr to raw data for section */ |
unsigned long s_relptr; /* file ptr to relocation */ |
unsigned long s_lnnoptr; /* file ptr to line numbers */ |
unsigned short s_nreloc; /* number of relocation entries */ |
unsigned short s_nlnno; /* number of line number entries*/ |
unsigned long s_flags; /* flags */ |
}; |
#define SCNHDR struct external_scnhdr |
#define SCNHSZ sizeof(SCNHDR) |
/* |
* names of "special" sections |
*/ |
#define _TEXT ".text" |
#define _DATA ".data" |
#define _BSS ".bss" |
#define _COMMENT ".comment" |
#define _LIB ".lib" |
/* |
* s_flags "type" |
*/ |
#define STYP_TEXT (0x0020) /* section contains text only */ |
#define STYP_DATA (0x0040) /* section contains data only */ |
#define STYP_BSS (0x0080) /* section contains bss only */ |
/********************** LINE NUMBERS **********************/ |
/* 1 line number entry for every "breakpointable" source line in a section. |
* Line numbers are grouped on a per function basis; first entry in a function |
* grouping will have l_lnno = 0 and in place of physical address will be the |
* symbol table index of the function name. |
*/ |
struct external_lineno { |
union { |
unsigned long l_symndx __attribute__((packed)); /* function name symbol index, iff l_lnno == 0 */ |
unsigned long l_paddr __attribute__((packed)); /* (physical) address of line number */ |
} l_addr; |
unsigned short l_lnno; /* line number */ |
}; |
#define LINENO struct external_lineno |
#define LINESZ sizeof(LINENO) |
/********************** SYMBOLS **********************/ |
#define E_SYMNMLEN 8 /* # characters in a symbol name */ |
#define E_FILNMLEN 14 /* # characters in a file name */ |
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */ |
struct external_syment |
{ |
union { |
char e_name[E_SYMNMLEN]; |
struct { |
unsigned long e_zeroes __attribute__((packed)); |
unsigned long e_offset __attribute__((packed)); |
} e; |
} e; |
unsigned long e_value __attribute__((packed)); |
short e_scnum; |
unsigned short e_type; |
unsigned char e_sclass; |
unsigned char e_numaux; |
} __attribute__((packed)); |
#define N_BTMASK (0xf) |
#define N_TMASK (0x30) |
#define N_BTSHFT (4) |
#define N_TSHIFT (2) |
union external_auxent |
{ |
struct |
{ |
unsigned long x_tagndx __attribute__((packed)); /* str, un, or enum tag indx */ |
union |
{ |
struct |
{ |
unsigned short x_lnno; /* declaration line number */ |
unsigned short x_size; /* str/union/array size */ |
} x_lnsz; |
unsigned long x_fsize __attribute__((packed)); /* size of function */ |
} x_misc; |
union |
{ |
struct |
{ /* if ISFCN, tag, or .bb */ |
unsigned long x_lnnoptr __attribute__((packed)); /* ptr to fcn line # */ |
unsigned long x_endndx __attribute__((packed)); /* entry ndx past block end */ |
} x_fcn; |
struct { /* if ISARY, up to 4 dimen. */ |
unsigned short x_dimen[E_DIMNUM]; |
} x_ary; |
} x_fcnary; |
unsigned short x_tvndx; /* tv index */ |
} x_sym; |
union |
{ |
char x_fname[E_FILNMLEN]; |
struct |
{ |
unsigned long x_zeroes __attribute__((packed)); |
unsigned long x_offset __attribute__((packed)); |
} x_n; |
} x_file; |
struct |
{ |
unsigned long x_scnlen __attribute__((packed)); /* section length */ |
unsigned short x_nreloc; /* # relocation entries */ |
unsigned short x_nlinno; /* # line numbers */ |
} x_scn; |
struct |
{ |
unsigned long x_tvfill __attribute__((packed)); /* tv fill value */ |
unsigned short x_tvlen; /* length of .tv */ |
unsigned short x_tvran[2]; /* tv range */ |
} x_tv; /* info about .tv section (in auxent of symbol .tv)) */ |
}; |
#define SYMENT struct external_syment |
#define SYMESZ sizeof(SYMENT) |
#define AUXENT union external_auxent |
#define AUXESZ sizeof(AUXENT) |
#define _ETEXT "etext" |
/* Relocatable symbols have number of the section in which they are defined, |
or one of the following: */ |
#define N_UNDEF ((short)0) /* undefined symbol */ |
#define N_ABS ((short)-1) /* value of symbol is absolute */ |
#define N_DEBUG ((short)-2) /* debugging symbol -- value is meaningless */ |
#define N_TV ((short)-3) /* indicates symbol needs preload transfer vector */ |
#define P_TV ((short)-4) /* indicates symbol needs postload transfer vector*/ |
/* |
* Type of a symbol, in low N bits of the word |
*/ |
#define T_NULL 0 |
#define T_VOID 1 /* function argument (only used by compiler) */ |
#define T_CHAR 2 /* character */ |
#define T_SHORT 3 /* short integer */ |
#define T_INT 4 /* integer */ |
#define T_LONG 5 /* long integer */ |
#define T_FLOAT 6 /* floating point */ |
#define T_DOUBLE 7 /* double word */ |
#define T_STRUCT 8 /* structure */ |
#define T_UNION 9 /* union */ |
#define T_ENUM 10 /* enumeration */ |
#define T_MOE 11 /* member of enumeration*/ |
#define T_UCHAR 12 /* unsigned character */ |
#define T_USHORT 13 /* unsigned short */ |
#define T_UINT 14 /* unsigned integer */ |
#define T_ULONG 15 /* unsigned long */ |
#define T_LNGDBL 16 /* long double */ |
/* |
* derived types, in n_type |
*/ |
#define DT_NON (0) /* no derived type */ |
#define DT_PTR (1) /* pointer */ |
#define DT_FCN (2) /* function */ |
#define DT_ARY (3) /* array */ |
#define BTYPE(x) ((x) & N_BTMASK) |
#define ISPTR(x) (((x) & N_TMASK) == (DT_PTR << N_BTSHFT)) |
#define ISFCN(x) (((x) & N_TMASK) == (DT_FCN << N_BTSHFT)) |
#define ISARY(x) (((x) & N_TMASK) == (DT_ARY << N_BTSHFT)) |
#define ISTAG(x) ((x)==C_STRTAG||(x)==C_UNTAG||(x)==C_ENTAG) |
#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK)) |
/********************** STORAGE CLASSES **********************/ |
/* This used to be defined as -1, but now n_sclass is unsigned. */ |
#define C_EFCN 0xff /* physical end of function */ |
#define C_NULL 0 |
#define C_AUTO 1 /* automatic variable */ |
#define C_EXT 2 /* external symbol */ |
#define C_STAT 3 /* static */ |
#define C_REG 4 /* register variable */ |
#define C_EXTDEF 5 /* external definition */ |
#define C_LABEL 6 /* label */ |
#define C_ULABEL 7 /* undefined label */ |
#define C_MOS 8 /* member of structure */ |
#define C_ARG 9 /* function argument */ |
#define C_STRTAG 10 /* structure tag */ |
#define C_MOU 11 /* member of union */ |
#define C_UNTAG 12 /* union tag */ |
#define C_TPDEF 13 /* type definition */ |
#define C_USTATIC 14 /* undefined static */ |
#define C_ENTAG 15 /* enumeration tag */ |
#define C_MOE 16 /* member of enumeration */ |
#define C_REGPARM 17 /* register parameter */ |
#define C_FIELD 18 /* bit field */ |
#define C_AUTOARG 19 /* auto argument */ |
#define C_LASTENT 20 /* dummy entry (end of block) */ |
#define C_BLOCK 100 /* ".bb" or ".eb" */ |
#define C_FCN 101 /* ".bf" or ".ef" */ |
#define C_EOS 102 /* end of structure */ |
#define C_FILE 103 /* file name */ |
#define C_LINE 104 /* line # reformatted as symbol table entry */ |
#define C_ALIAS 105 /* duplicate tag */ |
#define C_HIDDEN 106 /* ext symbol in dmert public lib */ |
/********************** RELOCATION DIRECTIVES **********************/ |
struct external_reloc { |
unsigned long r_vaddr __attribute__((packed)); |
unsigned long r_symndx __attribute__((packed)); |
unsigned short r_type; |
}; |
#define RELOC struct external_reloc |
#define RELSZ sizeof(RELOC) |
#define RELOC_REL32 20 /* 32-bit PC-relative address */ |
#define RELOC_ADDR32 6 /* 32-bit absolute address */ |
#define DEFAULT_DATA_SECTION_ALIGNMENT 4 |
#define DEFAULT_BSS_SECTION_ALIGNMENT 4 |
#define DEFAULT_TEXT_SECTION_ALIGNMENT 4 |
/* For new sections we havn't heard of before */ |
#define DEFAULT_SECTION_ALIGNMENT 4 |
#ifdef __cplusplus |
} |
#endif |
#endif |
/programs/develop/libraries/menuetlibc/src/libmcoff/debug.c |
---|
0,0 → 1,44 |
#include<stdio.h> |
#include<stdarg.h> |
#if (MCOFF_MENUETOS==1) |
static int vdprintf_help(unsigned c) |
{ |
int d0; |
if(c=='\n') |
{ |
c='\r'; |
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c)); |
c='\n'; |
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c)); |
return 0; |
} |
__asm__ __volatile__("int $0x40":"=&a"(d0):"0"(63),"b"(1),"c"(c)); |
return 0 ; |
} |
static void xputs(char * p) |
{ |
for(;*p;p++) vdprintf_help((*p)&0xff); |
} |
static char dbg_buf[1024]; |
void dprintf(const char * fmt,...) |
{ |
va_list ap; |
va_start(ap,fmt); |
vsprintf(dbg_buf,fmt,ap); |
va_end(ap); |
xputs(dbg_buf); |
} |
#else |
void dprintf(const char * fmt,...) |
{ |
va_list ap; |
va_start(ap,fmt); |
vfprintf(stderr,fmt,ap); |
va_end(ap); |
} |
#endif |
/programs/develop/libraries/menuetlibc/src/libmcoff/loadcoff.c |
---|
0,0 → 1,190 |
#include"mcoff.h" |
#include<stdio.h> |
#include<stdlib.h> |
#include"string.h" |
#undef MCOFF_MENUETOS |
#define MCOFF_MENUETOS 0 |
#if (MCOFF_MENUETOS==1) |
struct systree_blk { |
unsigned long cmd,pos,blks; |
void * data,* work; |
char name[128]; |
} __attribute__((packed)); |
static char systree_work[16384]; |
static char temp_block[512]; |
static struct systree_blk sblk={ |
0, |
0, |
1, |
NULL, |
systree_work, |
}; |
static unsigned long open_on_path(char * pth,char * name) |
{ |
int l; |
int d0,d1; |
l=strlen(pth); |
if(!pth) |
{ |
sprintf(sblk.name,"%s",pth); |
} else { |
if(pth[l]!='/') |
sprintf(sblk.name,"%s/%s",pth,name); |
else |
sprintf(sblk.name,"%s%s",pth,name); |
} |
sblk.data=&temp_block; |
sblk.cmd=0; |
sblk.pos=0; |
sblk.blks=1; |
sblk.work=systree_work; |
__asm__ __volatile__("int $0x40":"=a"(d0),"=b"(d1):"0"(58),"1"((void *)&sblk)); |
if(d0!=0) return 0; |
return d1; |
} |
#endif |
coffobj_t * mcoff_load_file(char * fname) |
{ |
coffobj_t * obj; |
int i; |
#if (MCOFF_MENUETOS==1) |
unsigned long sz; |
#endif |
obj=(coffobj_t *)malloc(sizeof(coffobj_t)); |
if(!obj) |
{ |
dprintf("malloc error1\n"); |
return NULL; |
} |
#if (MCOFF_MENUETOS==0) |
FILE * f=fopen(fname,"rb"); |
if(!f) |
{ |
dprintf("Unable to open file\n"); |
free(obj); |
return NULL; |
} |
dprintf("File opened\n"); |
fseek(f,0,SEEK_END); |
dprintf("After seek to end\n"); |
obj->co_filesize=ftell(f); |
dprintf("After ftell\n"); |
fseek(f,0,SEEK_SET); |
dprintf("After seek to start\n"); |
dprintf("File size is %u bytes\n",obj->co_filesize); |
#else |
/* Special actions for MenuetOS, because it doesn't support relative paths */ |
/* We just search some paths if it is relative */ |
if(fname[0]!='/') |
{ |
sz=open_on_path("/RD/1",fname); |
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */ |
sz=open_on_path("/HD/1/MENUETOS",fname); |
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */ |
sz=open_on_path("/HD/1/MENUETOS/DLL",fname); |
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */ |
} else { |
dprintf("Opening on std path\n"); |
sz=open_on_path("",fname); |
if(sz>64 && sz<0x1000000) goto OK; /* Max 16MB for DLL */ |
} |
free(obj); |
return NULL; |
OK: |
obj->co_filesize=sz; |
dprintf("File size is %u bytes\n",sz); |
#endif |
obj->co_loadptr=(char *)malloc((obj->co_filesize+511)&~511); |
if(!obj->co_loadptr) |
{ |
dprintf("Unable to create file memory\n"); |
#if (MCOFF_MENUETOS==0) |
fclose(f); |
#endif |
free(obj); |
return NULL; |
} |
dprintf("Memory allocated\n"); |
#if (MCOFF_MENUETOS==0) |
dprintf("Before fread\n"); |
fread(obj->co_loadptr,1,obj->co_filesize,f); |
dprintf("After fread\n"); |
fclose(f); |
dprintf("After fclose\n"); |
#else |
sblk.cmd=0; |
sblk.pos=0; |
sblk.blks=((sz+511)&~511)/512; |
sblk.data=obj->co_loadptr; |
sblk.work=systree_work; |
{ |
int d0,d1; |
__asm__ __volatile__("int $0x40":"=a"(d0),"=b"(d1):"0"(58),"1"((void *)&sblk)); |
} |
dprintf("Done reading file\n"); |
#endif |
dprintf("Checking file\n"); |
obj->co_loadaddr=(unsigned long)obj->co_loadptr; |
obj->co_filehdr=(FILHDR *)obj->co_loadaddr; |
/* Check if file is really COFF */ |
if(I386BADMAG(*obj->co_filehdr)) |
{ |
dprintf("bad magic\n"); |
NOREL: |
free(obj->co_loadptr); |
free(obj); |
return NULL; |
} |
/* We don't support files with relocations stripped */ |
/* if(obj->co_filehdr->f_flags & F_RELFLG) |
{ |
printf("No relocation info\n"); |
goto NOREL; |
} */ |
/* Get into section table, symbol table and string table */ |
obj->co_sections=(SCNHDR *)(obj->co_loadaddr+FILHSZ+obj->co_filehdr->f_opthdr); |
obj->co_symtab=(SYMENT *)(obj->co_loadaddr+obj->co_filehdr->f_symptr); |
obj->co_strtab=(char *)(obj->co_loadaddr+obj->co_filehdr->f_symptr+ |
SYMESZ*obj->co_filehdr->f_nsyms); |
/* Setup .bss section */ |
{ |
SCNHDR * h; |
h=obj->co_sections; |
dprintf("Looking for bss...\n"); |
for(i=0;i<obj->co_filehdr->f_nscns;i++,h++) |
{ |
unsigned long r; |
if((h->s_flags & 0xE0)!=0x80) continue; |
r=h->s_size; |
obj->co_bssptr=(char *)malloc(r); |
obj->co_bsssize=r; |
if(!obj->co_bssptr) |
{ |
dprintf("Unable to alloc %u bytes for bss\n",r); |
free(obj->co_loadptr); |
free(obj); |
return NULL; |
} |
obj->co_bssaddr=(unsigned long)obj->co_bssptr; |
h->s_scnptr=obj->co_bssaddr-obj->co_loadaddr; |
obj->co_bsssectnum=i+1; /* So we don't have to do it later */ |
dprintf("BSS size=%u bytes\n",obj->co_bsssize); |
} |
} |
NOBSS: |
/* File is COFF. Just return obj */ |
return obj; |
} |
void unload_coff_file(coffobj_t * obj) |
{ |
if(!obj) return; |
free(obj->co_loadptr); |
return; |
} |
/programs/develop/libraries/menuetlibc/src/libmcoff/mcoff.h |
---|
0,0 → 1,64 |
#ifndef __MENUETOS_MCOFF_H |
#define __MENUETOS_MCOFF_H |
#include"_coff.h" |
typedef struct { |
char * co_loadptr; |
unsigned long co_loadaddr; |
unsigned long co_filesize; |
FILHDR * co_filehdr; |
SCNHDR * co_sections; |
SYMENT * co_symtab; |
char * co_strtab; |
char * co_bssptr; |
unsigned long co_bssaddr; |
unsigned long co_bsssize; |
unsigned long co_bsssectnum; |
} coffobj_t; |
coffobj_t * mcoff_load_file(char * fname); |
void unload_coff_file(coffobj_t * obj); |
SCNHDR * find_section(char * name,coffobj_t * obj); |
int read_section_data(coffobj_t * obj,SCNHDR * hdr,void ** readp); |
SYMENT * find_coff_symbol(coffobj_t * obj,char * objname); |
typedef int (* symlookupfn_t)(coffobj_t *,unsigned long *,unsigned long *,int); |
int relocate_coff_file(coffobj_t * obj,symlookupfn_t lookupfn); |
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val, |
unsigned long * sym_sect,int index); |
unsigned long mcoff_get_ref(coffobj_t * obj,char * symname); |
/* |
Your lookup function can be similar to this: |
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val, |
unsigned long * sym_sect,int index) |
{ |
SYMENT * symtab,* lookup; |
char xname[9]; |
char * symnamep; |
symtab=obj->co_symtab+index; |
*sym_sect=(unsigned long)symtab->e_scnum; |
if(symtab->e_scnum>0) |
{ |
*sym_val=symtab->e_value; |
return 0; |
} |
if(symtab->e.e.e_zeroes==0) |
{ |
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset); |
} else { |
symnamep=(char *)symtab->e.e_name; |
memset(xname,0,9); |
memcpy(xname,symnamep,8); |
symnamep=xname; |
} |
lookup=find_coff_symbol(obj,symnamep); |
if(!lookup) return -1; |
*sym_val=lookup->e_value+obj->co_sections[lookup->e_scnum-1].s_scnptr+obj->co_loadaddr; |
return 0; |
} |
*/ |
#endif |
/programs/develop/libraries/menuetlibc/src/libmcoff/relocate.c |
---|
0,0 → 1,91 |
#include"mcoff.h" |
#include<stdlib.h> |
#include"string.h" |
static int do_coff_relocation(coffobj_t * obj,unsigned long relno, |
SCNHDR * sect,symlookupfn_t lookup_fn) |
{ |
int r_delta,t_delta=0; |
unsigned long sym_val,sym_sect; |
unsigned long * where; |
int err; |
RELOC * rel; |
r_delta=obj->co_loadaddr+sect->s_scnptr-sect->s_vaddr; |
rel=((RELOC *)(obj->co_loadaddr+sect->s_relptr))+relno; |
where=(unsigned long *)(r_delta+rel->r_vaddr); |
err=lookup_fn(obj,&sym_val,&sym_sect,rel->r_symndx); |
if(err!=0) |
{ |
printf("Unable to find symbol relno=%u\n",relno); |
return err; |
} |
if(sym_sect!=0) |
{ |
sect=&obj->co_sections[sym_sect-1]; |
t_delta=obj->co_loadaddr+sect->s_scnptr-sect->s_vaddr; |
} |
switch(rel->r_type) |
{ |
case RELOC_ADDR32: |
if(!sym_sect) |
*where=sym_val; |
else |
*where+=t_delta; |
break; |
case RELOC_REL32: |
if(!sym_sect) |
*where+=sym_val-r_delta; |
else |
*where+=t_delta-r_delta; |
break; |
default: |
printf("Invalid relocation type\n"); |
return -1; |
} |
return 0; |
} |
int relocate_coff_file(coffobj_t * obj,symlookupfn_t lookupfn) |
{ |
int s,r; |
for(s=0;s<obj->co_filehdr->f_nscns;s++) |
{ |
for(r=0;r<obj->co_sections[s].s_nreloc;r++) |
{ |
if(do_coff_relocation( |
obj, |
r, |
&obj->co_sections[s], |
lookupfn)!=0) return -1; |
} |
} |
return 0; |
} |
int mcoff_std_symlookupfn(coffobj_t * obj,unsigned long * sym_val, |
unsigned long * sym_sect,int index) |
{ |
SYMENT * symtab,* lookup; |
char xname[9]; |
char * symnamep; |
symtab=obj->co_symtab+index; |
*sym_sect=(unsigned long)symtab->e_scnum; |
if(symtab->e_scnum>0) |
{ |
*sym_val=symtab->e_value; |
return 0; |
} |
if(symtab->e.e.e_zeroes==0) |
{ |
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset); |
} else { |
symnamep=(char *)symtab->e.e_name; |
memset(xname,0,9); |
memcpy(xname,symnamep,8); |
symnamep=xname; |
} |
lookup=find_coff_symbol(obj,symnamep); |
if(!lookup) return -1; |
*sym_val=lookup->e_value+obj->co_sections[lookup->e_scnum-1].s_scnptr+obj->co_loadaddr; |
return 0; |
} |
/programs/develop/libraries/menuetlibc/src/libmcoff/section.c |
---|
0,0 → 1,26 |
#include"mcoff.h" |
#include"string.h" |
#include<stdlib.h> |
SCNHDR * find_section(char * name,coffobj_t * obj) |
{ |
char newname[9]; |
int i,j; |
if(!name || !obj) return NULL; |
memset(newname,0,9); |
memcpy(newname,name,8); |
j=strlen(newname); |
for(i=0;i<obj->co_filehdr->f_nscns;i++) |
{ |
if(!strncmp(obj->co_sections[i].s_name,newname,j)) return &obj->co_sections[i]; |
} |
return NULL; |
} |
int read_section_data(coffobj_t * obj,SCNHDR * hdr,void ** readp) |
{ |
*readp=malloc(hdr->s_size); |
if(!(*readp)) return -1; |
memcpy(*readp,obj->co_loadptr+hdr->s_scnptr,hdr->s_size); |
return 0; |
} |
/programs/develop/libraries/menuetlibc/src/libmcoff/symtab.c |
---|
0,0 → 1,48 |
#include"mcoff.h" |
#include<stdlib.h> |
#include"string.h" |
/* static inline void nprintf(char * s,int n) |
{ |
printf("nprintf(%u, '",n); |
for(;n;n--) |
putch(*s++); |
printf("')"); |
} */ |
SYMENT * find_coff_symbol(coffobj_t * obj,char * objname) |
{ |
int namelen; |
int symno; |
int xlen; |
SYMENT * symtab; |
char * symnamep,symnamelen; |
symtab=obj->co_symtab; |
namelen=strlen(objname); |
for(symno=0;symno<obj->co_filehdr->f_nsyms;symno++,symtab++) |
{ |
if(symtab->e.e.e_zeroes==0) |
{ |
symnamep=(char *)(((long)obj->co_strtab)+symtab->e.e.e_offset); |
symnamelen=strlen(symnamep); |
/* printf("strtab=%u %x %u ",symtab->e.e.e_offset,symnamep,symnamelen); */ |
} else { |
symnamep=(char *)symtab->e.e_name; |
symnamelen=strlen(symnamep); |
if(symnamelen>E_SYMNMLEN) |
symnamelen=E_SYMNMLEN; |
} |
/* nprintf(symnamep,symnamelen); |
printf("\n"); */ |
if(symtab->e_scnum!=0 && namelen==symnamelen && !strncmp(objname,symnamep,namelen)) |
return symtab; |
} |
return NULL; |
} |
unsigned long mcoff_get_ref(coffobj_t * obj,char * symname) |
{ |
SYMENT * sym=find_coff_symbol(obj,symname); |
if(!sym) return 0; |
return sym->e_value+obj->co_sections[sym->e_scnum-1].s_scnptr+obj->co_loadaddr; |
} |