From: MaartenBrock Date: Sat, 22 Apr 2006 21:35:27 +0000 (+0000) Subject: * as/asx8051.dsp: added mcs51/strcmpi.h X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=a646dcff1ba10145839a6724656269ab5261d99a;p=fw%2Fsdcc * as/asx8051.dsp: added mcs51/strcmpi.h * as/hc08/as_hc08.dsp: added asm.h, m6808.h, strcmpi.h * as/hc08/aslink.h: updated lnksect prototype * as/hc08/asm.h, * as/mcs51/asm.h: added a_addr to struct area and s_org to struct sym * as/hc08/asmain.c, * as/mcs51/asmain.c (asmbl): init dot.s_org for S_ORG, (newdot): handle A_ABS * as/hc08/asout.c, * as/mcs51/asout.c (outarea): output address * as/hc08/lkaomf51.c, * as/mcs51/lkaomf51.c: disabled unused array UsageType * as/hc08/m08pst.c, * as/mcs51/i51pst.c, * as/z80/z80pst.c: "ABS" is not A_OVR * as/hc08/lkarea.c (newarea): read a_addr, (lnkarea): added codemap array, sort absolute areas to the front, combine all GSINITx/GSFINAL, (find_empty_space, allocate_space): new functions, (lnksect): return next address, handle absolute sections * as/mcs51/lkarea.c (newarea): read a_addr, lnksect2 prototype changed, (lnkarea2): define codemap unsigned, combine all GSINITx/GSFINAL, (find_empty_space, allocate_space): new, factored out of lnksect2, (lnksect2): return next address, handle absolute sections * as/hc08/lkhead.c, * as/mcs51/lkhead.c (newhead): head is absolute but not overlay * as/hc08/lklibr.c (addfile, fndsym), * as/mcs51/lklibr.c (addfile, buildlibraryindex, fndsym): prevent index out of range and detect both '\' and '/' * device/include/mcs51/c8051f200.h: added _XPAGE, removed bad comment * device/include/stdbool.h: removed SDCC_ds390 from check to pass regression tests (ds390 cannot return bool yet) * doc/sdccman.lyx: changed version number, document changed --no-peep, document critical interrupts on z80, document changed SDCC define * src/asm.c (_asxxxx_mapping): fixed .org directive, (_a390_mapping): added .org directive * src/hc08/gen.c (transferAopAop): made bytemask log to fix warning, (genMultOneByte): fixed warnings * src/hc08/hc08.dsp: lowered warning level to 2 to suppress pedantic ones * src/pic16/device.c: removed newReg prototype, removed BYTE_IN_LONG * src/pic16/gen.c (pic16_popGetLabel): made parameter key signed, (pic16_genLeftShiftLiteral, genRightShiftLiteral): fixed warnings * src/pic16/gen.h: changed prototype for pic16_popGetLabel * src/pic16/main.c: removed newReg prototype * src/pic16/pcode.c, * src/pic16/pcode.h (pic16_emitDB): changed parameter c to int to fix warnings * src/pic16/pic16.dsp: lowered warning level to 2 to suppress pedantic ones * src/pic16/ralloc.c * src/pic16/ralloc.h (newReg): changed type to int and size to unsigned to fix warnings * src/pic/pcode.c (allocInternalRegister): changed parameter optype from short to PIC_OPTYPE * src/pic/pic.dsp: lowered warning level to 2 to suppress pedantic ones * src/pic/ralloc.c (newReg, allocInternalRegister): changed parameter optype from short to PIC_OPTYPE * src/port.h: made int_size unsigned to fix warnings * src/SDCC.y: fixed warning on MSVC * src/SDCCicode.c (getArraySizePtr): return unsigned int * src/SDCCopt.c (convertToFcall): fixed warnings * src/SDCCsymt.h: removed double prototype for genSymName * src/xa51/ralloc.c (allocReg): made size unsigned int, type int and offset int to fix warnings git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4112 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 577b429c..692ef83a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,72 @@ +2006-04-22 Maarten Brock + + * as/asx8051.dsp: added mcs51/strcmpi.h + * as/hc08/as_hc08.dsp: added asm.h, m6808.h, strcmpi.h + * as/hc08/aslink.h: updated lnksect prototype + * as/hc08/asm.h, + * as/mcs51/asm.h: added a_addr to struct area and s_org to struct sym + * as/hc08/asmain.c, + * as/mcs51/asmain.c (asmbl): init dot.s_org for S_ORG, + (newdot): handle A_ABS + * as/hc08/asout.c, + * as/mcs51/asout.c (outarea): output address + * as/hc08/lkaomf51.c, + * as/mcs51/lkaomf51.c: disabled unused array UsageType + * as/hc08/m08pst.c, + * as/mcs51/i51pst.c, + * as/z80/z80pst.c: "ABS" is not A_OVR + * as/hc08/lkarea.c (newarea): read a_addr, + (lnkarea): added codemap array, sort absolute areas to the front, + combine all GSINITx/GSFINAL, + (find_empty_space, allocate_space): new functions, + (lnksect): return next address, handle absolute sections + * as/mcs51/lkarea.c (newarea): read a_addr, + lnksect2 prototype changed, + (lnkarea2): define codemap unsigned, combine all GSINITx/GSFINAL, + (find_empty_space, allocate_space): new, factored out of lnksect2, + (lnksect2): return next address, handle absolute sections + * as/hc08/lkhead.c, + * as/mcs51/lkhead.c (newhead): head is absolute but not overlay + * as/hc08/lklibr.c (addfile, fndsym), + * as/mcs51/lklibr.c (addfile, buildlibraryindex, fndsym): prevent + index out of range and detect both '\' and '/' + * device/include/mcs51/c8051f200.h: added _XPAGE, removed bad comment + * device/include/stdbool.h: removed SDCC_ds390 from check to pass + regression tests (ds390 cannot return bool yet) + * doc/sdccman.lyx: changed version number, document changed --no-peep, + document critical interrupts on z80, document changed SDCC define + * src/asm.c (_asxxxx_mapping): fixed .org directive, + (_a390_mapping): added .org directive + * src/hc08/gen.c (transferAopAop): made bytemask log to fix warning, + (genMultOneByte): fixed warnings + * src/hc08/hc08.dsp: lowered warning level to 2 to suppress pedantic + ones + * src/pic16/device.c: removed newReg prototype, removed BYTE_IN_LONG + * src/pic16/gen.c (pic16_popGetLabel): made parameter key signed, + (pic16_genLeftShiftLiteral, genRightShiftLiteral): fixed warnings + * src/pic16/gen.h: changed prototype for pic16_popGetLabel + * src/pic16/main.c: removed newReg prototype + * src/pic16/pcode.c, + * src/pic16/pcode.h (pic16_emitDB): changed parameter c to int to fix + warnings + * src/pic16/pic16.dsp: lowered warning level to 2 to suppress pedantic + ones + * src/pic16/ralloc.c + * src/pic16/ralloc.h (newReg): changed type to int and size to unsigned + to fix warnings + * src/pic/pcode.c (allocInternalRegister): changed parameter optype + from short to PIC_OPTYPE + * src/pic/pic.dsp: lowered warning level to 2 to suppress pedantic ones + * src/pic/ralloc.c (newReg, allocInternalRegister): changed parameter + optype from short to PIC_OPTYPE + * src/port.h: made int_size unsigned to fix warnings + * src/SDCC.y: fixed warning on MSVC + * src/SDCCicode.c (getArraySizePtr): return unsigned int + * src/SDCCopt.c (convertToFcall): fixed warnings + * src/SDCCsymt.h: removed double prototype for genSymName + * src/xa51/ralloc.c (allocReg): made size unsigned int, type int and + offset int to fix warnings + 2006-04-22 Borut Razem * doc/sdccman.lyx, */Makefile, */Makefile.in: diff --git a/as/asx8051.dsp b/as/asx8051.dsp index ccc19d3a..cb6e1e6b 100644 --- a/as/asx8051.dsp +++ b/as/asx8051.dsp @@ -158,6 +158,10 @@ SOURCE=.\mcs51\asm.h SOURCE=.\mcs51\i8051.h # End Source File +# Begin Source File + +SOURCE=.\mcs51\strcmpi.h +# End Source File # End Group # End Target # End Project diff --git a/as/hc08/as_hc08.dsp b/as/hc08/as_hc08.dsp index b7c2a2f7..dae50fc3 100644 --- a/as/hc08/as_hc08.dsp +++ b/as/hc08/as_hc08.dsp @@ -149,10 +149,18 @@ SOURCE=.\strcmpi.c # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" -# End Group -# Begin Group "Resource Files" +# Begin Source File + +SOURCE=.\asm.h +# End Source File +# Begin Source File -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +SOURCE=.\m6808.h +# End Source File +# Begin Source File + +SOURCE=.\strcmpi.h +# End Source File # End Group # End Target # End Project diff --git a/as/hc08/aslink.h b/as/hc08/aslink.h index 7a4dd81d..a3c0ea79 100644 --- a/as/hc08/aslink.h +++ b/as/hc08/aslink.h @@ -690,7 +690,7 @@ extern VOID chop_crlf(); /* lkarea.c */ extern VOID lkparea(); extern VOID lnkarea(); -extern VOID lnksect(); +extern Addr_T lnksect(struct area *tap); extern VOID newarea(); /* lkhead.c */ diff --git a/as/hc08/asm.h b/as/hc08/asm.h index ad5f1714..5b6e8e13 100644 --- a/as/hc08/asm.h +++ b/as/hc08/asm.h @@ -8,7 +8,7 @@ * 721 Berkeley St. * Kent, Ohio 44240 * - * 28-Oct-97 JLH: + * 28-Oct-97 JLH: * - add proto for StoreString * - change s_id from [NCPS] to pointer * - change m_id from [NCPS] to pointer @@ -121,7 +121,7 @@ /* NB: for Flat24 extentions to work, Addr_T must be at least 24 - * bits. This is checked at runtime when the .flat24 directive + * bits. This is checked at runtime when the .flat24 directive * is processed. */ typedef unsigned int Addr_T; @@ -145,6 +145,7 @@ struct area struct area *a_ap; /* Area link */ char a_id[NCPS]; /* Area Name */ int a_ref; /* Ref. number */ + Addr_T a_addr; /* Area address */ Addr_T a_size; /* Area size */ Addr_T a_fuzz; /* Area fuzz */ int a_flag; /* Area flags */ @@ -213,7 +214,7 @@ struct area #define R_LSB 0x00 /* low byte */ #define R_MSB 0x80 /* high byte */ -#define R_BYT3 0x100 /* if R_BYTE is set, this is a +#define R_BYT3 0x100 /* if R_BYTE is set, this is a * 3 byte address, of which * the linker must select one byte. */ @@ -295,6 +296,7 @@ struct sym struct area *s_area; /* Area line, 0 if absolute */ int s_ref; /* Ref. number */ Addr_T s_addr; /* Address */ + Addr_T s_org; /* Start Address if absolute */ }; #define S_GBL 01 /* Global */ @@ -483,10 +485,10 @@ extern char tb[NTITL]; /* Title string buffer */ extern char stb[NSBTL]; /* Subtitle string buffer */ -extern char optsdcc[NINPUT]; /* sdcc compile options +extern char optsdcc[NINPUT]; /* sdcc compile options */ -extern int flat24Mode; /* non-zero if we are using DS390 24 bit - * flat mode (via .flat24 directive). +extern int flat24Mode; /* non-zero if we are using DS390 24 bit + * flat mode (via .flat24 directive). */ extern char symtbl[]; /* string "Symbol Table" */ @@ -508,7 +510,7 @@ extern unsigned char ctype[128]; /* array of character types, one per * ASCII character */ -extern char ccase[128]; /* an array of characters which +extern char ccase[128]; /* an array of characters which * perform the case translation function */ /* diff --git a/as/hc08/asmain.c b/as/hc08/asmain.c index 08a5f11a..fb12b4f7 100644 --- a/as/hc08/asmain.c +++ b/as/hc08/asmain.c @@ -556,7 +556,7 @@ loop: goto loop; } /* - * If the first character is a letter then assume a lable, + * If the first character is a letter then assume a label, * symbol, assembler directive, or assembler mnemonic is * being processed. */ @@ -906,7 +906,7 @@ loop: case S_ORG: if (dot.s_area->a_flag & A_ABS) { outall(); - laddr = dot.s_addr = absexpr(); + laddr = dot.s_addr = dot.s_org = absexpr(); } else { err('o'); } @@ -960,8 +960,8 @@ loop: } } *p = 0; - if (++incfil == MAXINC || - (ifp[incfil] = fopen(fn, "r")) == NULL) { + if ((++incfil == MAXINC) || + (ifp[incfil] = fopen(fn, "r")) == NULL) { --incfil; err('i'); } else { @@ -1164,7 +1164,11 @@ register struct area *nap; if (oap->a_size < dot.s_addr) { oap->a_size = dot.s_addr; } + } else if (oap->a_flag & A_ABS) { + oap->a_addr = dot.s_org; + oap->a_size = dot.s_addr - dot.s_org; } else { + oap->a_addr = 0; oap->a_size = dot.s_addr; } if (nap->a_flag & A_OVR) { diff --git a/as/hc08/asout.c b/as/hc08/asout.c index 363a2c12..f5b731f5 100644 --- a/as/hc08/asout.c +++ b/as/hc08/asout.c @@ -1004,7 +1004,7 @@ register struct area *ap; putc(c, ofp); } if (xflag == 0) { - fprintf(ofp, " size %X flags %X\n", ap->a_size, ap->a_flag); + fprintf(ofp, " size %X flags %X addr %X\n", ap->a_size, ap->a_flag, ap->a_addr); } else if (xflag == 1) { fprintf(ofp, " size %o flags %o\n", ap->a_size, ap->a_flag); diff --git a/as/hc08/lkaomf51.c b/as/hc08/lkaomf51.c index 7e0122dd..f1477e79 100644 --- a/as/hc08/lkaomf51.c +++ b/as/hc08/lkaomf51.c @@ -74,7 +74,7 @@ typedef struct int numlinenum=0; _linenum * linenum=NULL; - +#if 0 typedef struct { char * name; @@ -102,7 +102,7 @@ _UsageType UsageType[]= {"BSEG", 4}, {"", 5} /*A typeless number?*/ }; - +#endif char * UsageTypeName[]={"CODE", "XDATA", "DATA", "IDATA", "BIT", "NUMBER"}; int AddNumber; unsigned char * ihxBuff=NULL; diff --git a/as/hc08/lkarea.c b/as/hc08/lkarea.c index 5b8eaf85..86105da0 100644 --- a/as/hc08/lkarea.c +++ b/as/hc08/lkarea.c @@ -8,7 +8,7 @@ * 721 Berkeley St. * Kent, Ohio 44240 * - * 3-Nov-97 JLH: + * 3-Nov-97 JLH: * - change lkparea to use a_type == 0 as "virgin area" flag * 02-Apr-98 JLH: add code to link 8051 data spaces */ @@ -17,77 +17,77 @@ #include #include "aslink.h" -/*)Module lkarea.c +/*)Module lkarea.c * - * The module lkarea.c contains the functions which - * create and link together all area definitions read - * from the .rel file(s). + * The module lkarea.c contains the functions which + * create and link together all area definitions read + * from the .rel file(s). * - * lkarea.c contains the following functions: - * VOID lnkarea() - * VOID lnksect() - * VOID lkparea() - * VOID newarea() + * lkarea.c contains the following functions: + * VOID lnkarea() + * VOID lnksect() + * VOID lkparea() + * VOID newarea() * - * lkarea.c contains no global variables. + * lkarea.c contains no global variables. */ -/*)Function VOID newarea() - * - * The function newarea() creates and/or modifies area - * and areax structures for each A directive read from - * the .rel file(s). The function lkparea() is called - * to find tha area structure associated with this name. - * If the area does not yet exist then a new area - * structure is created and linked to any existing - * linked area structures. The area flags are copied - * into the area flag variable. For each occurence of - * an A directive an areax structure is created and - * linked to the areax structures associated with this - * area. The size of this area section is placed into - * the areax structure. The flag value for all subsequent - * area definitions for the same area are compared and - * flagged as an error if they are not identical. - * The areax structure created for every occurence of - * an A directive is loaded with a pointer to the base - * area structure and a pointer to the associated - * head structure. And finally, a pointer to this - * areax structure is loaded into the list of areax - * structures in the head structure. Refer to lkdata.c - * for details of the structures and their linkage. - * - * local variables: - * areax **halp pointer to an array of pointers - * int i counter, loop variable, value - * char id[] id string - * int narea number of areas in this head structure - * areax * taxp pointer to an areax structure - * to areax structures - * - * global variables: - * area *ap Pointer to the current - * area structure - * areax *axp Pointer to the current - * areax structure - * head *hp Pointer to the current - * head structure - * int lkerr error flag - * - * functions called: - * Addr_T eval() lkeval.c - * VOID exit() c_library - * int fprintf() c_library - * VOID getid() lklex.c - * VOID lkparea() lkarea.c - * VOID skip() lklex.c - * - * side effects: - * The area and areax structures are created and - * linked with the appropriate head structures. - * Failure to allocate area or areax structure - * space will terminate the linker. Other internal - * errors most likely caused by corrupted .rel - * files will also terminate the linker. +/*)Function VOID newarea() + * + * The function newarea() creates and/or modifies area + * and areax structures for each A directive read from + * the .rel file(s). The function lkparea() is called + * to find tha area structure associated with this name. + * If the area does not yet exist then a new area + * structure is created and linked to any existing + * linked area structures. The area flags are copied + * into the area flag variable. For each occurence of + * an A directive an areax structure is created and + * linked to the areax structures associated with this + * area. The size of this area section is placed into + * the areax structure. The flag value for all subsequent + * area definitions for the same area are compared and + * flagged as an error if they are not identical. + * The areax structure created for every occurence of + * an A directive is loaded with a pointer to the base + * area structure and a pointer to the associated + * head structure. And finally, a pointer to this + * areax structure is loaded into the list of areax + * structures in the head structure. Refer to lkdata.c + * for details of the structures and their linkage. + * + * local variables: + * areax **halp pointer to an array of pointers + * int i counter, loop variable, value + * char id[] id string + * int narea number of areas in this head structure + * areax * taxp pointer to an areax structure + * to areax structures + * + * global variables: + * area *ap Pointer to the current + * area structure + * areax *axp Pointer to the current + * areax structure + * head *hp Pointer to the current + * head structure + * int lkerr error flag + * + * functions called: + * Addr_T eval() lkeval.c + * VOID exit() c_library + * int fprintf() c_library + * VOID getid() lklex.c + * VOID lkparea() lkarea.c + * VOID skip() lklex.c + * + * side effects: + * The area and areax structures are created and + * linked with the appropriate head structures. + * Failure to allocate area or areax structure + * space will terminate the linker. Other internal + * errors most likely caused by corrupted .rel + * files will also terminate the linker. */ /* @@ -103,237 +103,289 @@ VOID newarea() { - register int i, narea; - struct areax *taxp; - struct areax **halp; - char id[NCPS]; - - /* - * Create Area entry - */ - getid(id, -1); - lkparea(id); - /* - * Evaluate area size - */ - skip(-1); - axp->a_size = eval(); - /* - * Evaluate flags - */ - skip(-1); - i = 0; - taxp = ap->a_axp; - while (taxp->a_axp) { - ++i; - taxp = taxp->a_axp; - } - if (i == 0) { - ap->a_flag = eval(); - } else { - i = eval(); -/* if (i && (ap->a_flag != i)) { */ -/* fprintf(stderr, "Conflicting flags in area %8s\n", id); */ -/* lkerr++; */ -/* } */ - } - /* - * Place pointer in header area list - */ - if (headp == NULL) { - fprintf(stderr, "No header defined\n"); - lkexit(1); - } - narea = hp->h_narea; - halp = hp->a_list; - for (i=0; i < narea ;++i) { - if (halp[i] == NULL) { - halp[i] = taxp; - return; - } - } - fprintf(stderr, "Header area list overflow\n"); - lkexit(1); + register int i, narea; + struct areax *taxp; + struct areax **halp; + char id[NCPS]; + + /* + * Create Area entry + */ + getid(id, -1); + lkparea(id); + /* + * Evaluate area size + */ + skip(-1); + axp->a_size = eval(); + /* + * Evaluate flags + */ + skip(-1); + i = 0; + taxp = ap->a_axp; + while (taxp->a_axp) { + ++i; + taxp = taxp->a_axp; + } + if (i == 0) { + ap->a_flag = eval(); + } else { + i = eval(); +/* if (i && (ap->a_flag != i)) { */ +/* fprintf(stderr, "Conflicting flags in area %8s\n", id); */ +/* lkerr++; */ +/* } */ + } + /* + * Evaluate area address + */ + skip(-1); + axp->a_addr = eval(); + /* + * Place pointer in header area list + */ + if (headp == NULL) { + fprintf(stderr, "No header defined\n"); + lkexit(1); + } + narea = hp->h_narea; + halp = hp->a_list; + for (i=0; i < narea ;++i) { + if (halp[i] == NULL) { + halp[i] = taxp; + return; + } + } + fprintf(stderr, "Header area list overflow\n"); + lkexit(1); } -/*)Function VOID lkparea(id) - * - * char * id pointer to the area name string - * - * The function lkparea() searches the linked area structures - * for a name match. If the name is not found then an area - * structure is created. An areax structure is created and - * appended to the areax structures linked to the area structure. - * The associated base area and head structure pointers are - * loaded into the areax structure. - * - * local variables: - * area * tap pointer to an area structure - * areax * taxp pointer to an areax structure - * - * global variables: - * area *ap Pointer to the current - * area structure - * area *areap The pointer to the first - * area structure of a linked list - * areax *axp Pointer to the current - * areax structure - * - * functions called: - * VOID * new() lksym() - * char * strcpy() c_library - * int symeq() lksym.c - * - * side effects: - * Area and/or areax structures are created. - * Failure to allocate space for created structures - * will terminate the linker. +/*)Function VOID lkparea(id) + * + * char * id pointer to the area name string + * + * The function lkparea() searches the linked area structures + * for a name match. If the name is not found then an area + * structure is created. An areax structure is created and + * appended to the areax structures linked to the area structure. + * The associated base area and head structure pointers are + * loaded into the areax structure. + * + * local variables: + * area * tap pointer to an area structure + * areax * taxp pointer to an areax structure + * + * global variables: + * area *ap Pointer to the current + * area structure + * area *areap The pointer to the first + * area structure of a linked list + * areax *axp Pointer to the current + * areax structure + * + * functions called: + * VOID * new() lksym() + * char * strcpy() c_library + * int symeq() lksym.c + * + * side effects: + * Area and/or areax structures are created. + * Failure to allocate space for created structures + * will terminate the linker. */ VOID -lkparea(id) -char *id; +lkparea(char *id) { - register struct area *tap; - register struct areax *taxp; - - ap = areap; - axp = (struct areax *) new (sizeof(struct areax)); - while (ap) { - if (symeq(id, ap->a_id)) { - taxp = ap->a_axp; - while (taxp->a_axp) - taxp = taxp->a_axp; - taxp->a_axp = axp; - axp->a_bap = ap; - axp->a_bhp = hp; - return; - } - ap = ap->a_ap; - } - ap = (struct area *) new (sizeof(struct area)); - if (areap == NULL) { - areap = ap; - } else { - tap = areap; - while (tap->a_ap) - tap = tap->a_ap; - tap->a_ap = ap; - } - ap->a_axp = axp; - axp->a_bap = ap; - axp->a_bhp = hp; - strncpy(ap->a_id, id, NCPS); - ap->a_addr = 0; + register struct area *tap; + register struct areax *taxp; + + ap = areap; + axp = (struct areax *) new (sizeof(struct areax)); + while (ap) { + if (symeq(id, ap->a_id)) { + taxp = ap->a_axp; + while (taxp->a_axp) + taxp = taxp->a_axp; + taxp->a_axp = axp; + axp->a_bap = ap; + axp->a_bhp = hp; + return; + } + ap = ap->a_ap; + } + ap = (struct area *) new (sizeof(struct area)); + if (areap == NULL) { + areap = ap; + } else { + tap = areap; + while (tap->a_ap) + tap = tap->a_ap; + tap->a_ap = ap; + } + ap->a_axp = axp; + axp->a_bap = ap; + axp->a_bhp = hp; + strncpy(ap->a_id, id, NCPS); + ap->a_addr = 0; } -/*)Function VOID lnkarea() - * - * The function lnkarea() resolves all area addresses. - * The function evaluates each area structure (and all - * the associated areax structures) in sequence. The - * linking process supports four (4) possible area types: - * - * ABS/OVR - All sections (each individual areax - * section) starts at the identical base - * area address overlaying all other - * areax sections for this area. The - * size of the area is largest of the area - * sections. - * - * ABS/CON - All sections (each individual areax - * section) are concatenated with the - * first section starting at the base - * area address. The size of the area - * is the sum of the section sizes. - * - * NOTE: Multiple absolute (ABS) areas are - * never concatenated with each other, - * thus absolute area A and absolute area - * B will overlay each other if they begin - * at the same location (the default is - * always address 0 for absolute areas). - * - * REL/OVR - All sections (each individual areax - * section) starts at the identical base - * area address overlaying all other - * areax sections for this area. The - * size of the area is largest of the area - * sections. - * - * REL/CON - All sections (each individual areax - * section) are concatenated with the - * first section starting at the base - * area address. The size of the area - * is the sum of the section sizes. - * - * NOTE: Relocatable (REL) areas ae always concatenated - * with each other, thus relocatable area B - * (defined after area A) will follow - * relocatable area A independent of the - * starting address of area A. Within a - * specific area each areax section may be - * overlayed or concatenated with other - * areax sections. - * - * - * If a base address for an area is specified then the - * area will start at that address. Any relocatable - * areas defined subsequently will be concatenated to the - * previous relocatable area if it does not have a base - * address specified. - * - * The names s_ and l_ are created to - * define the starting address and length of each area. - * - * local variables: - * Addr_T rloc ;current relocation address - * char temp[] ;temporary string - * struct symbol *sp ;symbol structure - * - * global variables: - * area *ap Pointer to the current - * area structure - * area *areap The pointer to the first - * area structure of a linked list - * - * functions called: - * int fprintf() c_library - * VOID lnksect() lkarea.c - * symbol *lkpsym() lksysm.c - * char * strncpy() c_library - * int symeq() lksysm.c - * - * side effects: - * All area and areax addresses and sizes are - * determined and saved in their respective - * structures. +/*)Function VOID lnkarea() + * + * The function lnkarea() resolves all area addresses. + * The function evaluates each area structure (and all + * the associated areax structures) in sequence. The + * linking process supports four (4) possible area types: + * + * ABS/OVR - All sections (each individual areax + * section) starts at the identical base + * area address overlaying all other + * areax sections for this area. The + * size of the area is largest of the area + * sections. + * + * ABS/CON - All sections (each individual areax + * section) are concatenated with the + * first section starting at the base + * area address. The size of the area + * is the sum of the section sizes. + * + * NOTE: Multiple absolute (ABS) areas are + * never concatenated with each other, + * thus absolute area A and absolute area + * B will overlay each other if they begin + * at the same location (the default is + * always address 0 for absolute areas). + * + * REL/OVR - All sections (each individual areax + * section) starts at the identical base + * area address overlaying all other + * areax sections for this area. The + * size of the area is largest of the area + * sections. + * + * REL/CON - All sections (each individual areax + * section) are concatenated with the + * first section starting at the base + * area address. The size of the area + * is the sum of the section sizes. + * + * NOTE: Relocatable (REL) areas ae always concatenated + * with each other, thus relocatable area B + * (defined after area A) will follow + * relocatable area A independent of the + * starting address of area A. Within a + * specific area each areax section may be + * overlayed or concatenated with other + * areax sections. + * + * + * If a base address for an area is specified then the + * area will start at that address. Any relocatable + * areas defined subsequently will be concatenated to the + * previous relocatable area if it does not have a base + * address specified. + * + * The names s_ and l_ are created to + * define the starting address and length of each area. + * + * local variables: + * Addr_T rloc ;current relocation address + * char temp[] ;temporary string + * struct symbol *sp ;symbol structure + * + * global variables: + * area *ap Pointer to the current + * area structure + * area *areap The pointer to the first + * area structure of a linked list + * + * functions called: + * int fprintf() c_library + * VOID lnksect() lkarea.c + * symbol *lkpsym() lksysm.c + * char * strncpy() c_library + * int symeq() lksysm.c + * + * side effects: + * All area and areax addresses and sizes are + * determined and saved in their respective + * structures. */ +unsigned long codemap[2048]; /* * Resolve all area addresses. */ VOID lnkarea() { - Addr_T rloc[4]; - int locIndex; - char temp[NCPS]; - struct sym *sp; - /*JCF: used to save the REG_BANK_[0-3] and SBIT_BYTES area pointers*/ - struct area *ta[5]; - int j; - - rloc[0] = rloc[1] = rloc[2] = rloc[3] = 0; - ap = areap; - while (ap) { - if (ap->a_flag&A_ABS) { - /* - * Absolute sections - */ - lnksect(ap); - } else { - /* Determine memory space */ + Addr_T rloc[4] = {0, 0, 0, 0}; + Addr_T gs_size = 0; + int locIndex; + char temp[NCPS]; + struct sym *sp; + /*JCF: used to save the REG_BANK_[0-3] and SBIT_BYTES area pointers*/ + struct area *ta[5]; + int j; + struct area *abs_ap = NULL; + struct area *gs0_ap = NULL; + + memset(codemap, 0, sizeof(codemap)); + + /* first sort all absolute areas to the front */ + ap = areap; + /* no need to check first area, it's in front anyway */ + while (ap && ap->a_ap) + { + if (ap->a_ap->a_flag & A_ABS) + {/* next area is absolute, move it to front, + reversed sequence is no problem for absolutes */ + abs_ap = ap->a_ap; + ap->a_ap = abs_ap->a_ap; + abs_ap->a_ap = areap; + areap = abs_ap; + } + ap = ap->a_ap; + } + + /* next accumulate all GSINITx/GSFINAL area sizes + into GSINIT so they stay together */ + ap = areap; + while (ap) + { + if (!strncmp(ap->a_id, "GS", 2)) + {/* GSxxxxx area */ + if (ap->a_size == 0) + { + axp = ap->a_axp; + while (axp) + { + ap->a_size += axp->a_size; + axp = axp->a_axp; + } + } + gs_size += ap->a_size; + if (!strcmp(ap->a_id, "GSINIT0")) + {/* GSINIT0 area */ + gs0_ap = ap; + } + } + ap = ap->a_ap; + } + if (gs0_ap) + gs0_ap->a_size = gs_size; + + ap = areap; + while (ap) { + if (ap->a_flag & A_ABS) { + /* + * Absolute sections + */ + lnksect(ap); + } else { + /* Determine memory space */ locIndex = 0; #if 0 if (ap->a_flag & A_CODE) { @@ -346,138 +398,240 @@ lnkarea() locIndex = 3; } #endif - /* - * Relocatable sections - */ - if (ap->a_type == 0) { /* JLH */ - if (ap->a_flag & A_NOLOAD) { - locIndex = 2; - ap->a_addr = 0; - } else { - ap->a_addr = rloc[ locIndex ]; - } - ap->a_type = 1; - } - lnksect(ap); - rloc[ locIndex ] = ap->a_addr + ap->a_size; - } - - /* - * Create symbols called: - * s_ the start address of the area - * l_ the length of the area - */ - - if (! symeq(ap->a_id, _abs_)) { - strncpy(temp+2,ap->a_id,NCPS-2); - *(temp+1) = '_'; - - *temp = 's'; - sp = lkpsym(temp, 1); - sp->s_addr = ap->a_addr ; - /* sp->s_axp = ap->a_axp; JLH: was NULL; */ - sp->s_type |= S_DEF; - - *temp = 'l'; - sp = lkpsym(temp, 1); - sp->s_addr = ap->a_size; - sp->s_axp = NULL; - sp->s_type |= S_DEF; - - } - - /*JCF: Since area BSEG is defined just before BSEG_BYTES, use the bit size of BSEG - to compute the byte size of BSEG_BYTES: */ - if (!strcmp(ap->a_id, "BSEG")) { - ap->a_ap->a_axp->a_size=(ap->a_addr/8)+((ap->a_size+7)/8); /*Bits to bytes*/ - } - else if (!strcmp(ap->a_id, "REG_BANK_0")) ta[0]=ap; - else if (!strcmp(ap->a_id, "REG_BANK_1")) ta[1]=ap; - else if (!strcmp(ap->a_id, "REG_BANK_2")) ta[2]=ap; - else if (!strcmp(ap->a_id, "REG_BANK_3")) ta[3]=ap; - else if (!strcmp(ap->a_id, "BSEG_BYTES")) - { - ta[4]=ap; - for(j=4; j>1; j--) - { - /*If upper register banks are not used roll back the rellocation counter*/ - if ( (ta[j]->a_size==0) && (ta[j-1]->a_size==0) ) - { - rloc[0]-=8; - } - else break; - } - } - ap = ap->a_ap; - } + /* + * Relocatable sections + */ + if (ap->a_type == 0) { /* JLH */ + if (ap->a_flag & A_NOLOAD) { + locIndex = 2; + ap->a_addr = 0; + } else { + ap->a_addr = rloc[ locIndex ]; + } + ap->a_type = 1; + } + rloc[ locIndex ] = lnksect(ap); + } + + /* + * Create symbols called: + * s_ the start address of the area + * l_ the length of the area + */ + + if (! symeq(ap->a_id, _abs_)) { + strncpy(temp+2,ap->a_id,NCPS-2); + *(temp+1) = '_'; + + *temp = 's'; + sp = lkpsym(temp, 1); + sp->s_addr = ap->a_addr ; + /* sp->s_axp = ap->a_axp; JLH: was NULL; */ + sp->s_type |= S_DEF; + + *temp = 'l'; + sp = lkpsym(temp, 1); + sp->s_addr = ap->a_size; + sp->s_axp = NULL; + sp->s_type |= S_DEF; + + } + + /*JCF: Since area BSEG is defined just before BSEG_BYTES, use the bit size of BSEG + to compute the byte size of BSEG_BYTES: */ + if (!strcmp(ap->a_id, "BSEG")) { + ap->a_ap->a_axp->a_size=(ap->a_addr/8)+((ap->a_size+7)/8); /*Bits to bytes*/ + } + else if (!strcmp(ap->a_id, "REG_BANK_0")) ta[0]=ap; + else if (!strcmp(ap->a_id, "REG_BANK_1")) ta[1]=ap; + else if (!strcmp(ap->a_id, "REG_BANK_2")) ta[2]=ap; + else if (!strcmp(ap->a_id, "REG_BANK_3")) ta[3]=ap; + else if (!strcmp(ap->a_id, "BSEG_BYTES")) + { + ta[4]=ap; + for(j=4; j>1; j--) + { + /*If upper register banks are not used roll back the relocation counter*/ + if ( (ta[j]->a_size==0) && (ta[j-1]->a_size==0) ) + { + rloc[0]-=8; + } + else break; + } + } + ap = ap->a_ap; + } } -/*)Function VOID lnksect() +static +Addr_T find_empty_space(Addr_T start, Addr_T size) +{ + int i, j, k; + unsigned long mask, b; + + while (1) + { + Addr_T a = start; + i = start >> 5; + j = (start + size) >> 5; + mask = -(1 << (start & 0x1F)); + + while (i < j) + { + if (codemap[i] & mask) + { + k = 32; + for (b=0x80000000; b!=0; b>>=1, k--) + { + if (codemap[i] & b) + break; + } + start = a + k; + break; + } + i++; + mask = 0xFFFFFFFF; + a += 32; + } + if (start > a) + continue; + + mask &= (1 << ((start + size) & 0x1F)) - 1; + if (codemap[i] & mask) + { + k = 32; + for (b=0x80000000; b!=0; b>>=1, k--) + { + if (codemap[i] & b) + break; + } + start = (a & ~0x1F) + k; + } + if (start <= a) + break; + } + return start; +} + +static +Addr_T allocate_space(Addr_T start, Addr_T size, char* id) +{ + int i, j; + unsigned long mask; + Addr_T a = start; + i = start >> 5; + j = (start + size) >> 5; + mask = -(1 << (start & 0x1F)); + + while (i < j) + { + if (codemap[i] & mask) + { + fprintf(stderr, "memory overlap near 0x%X for %s\n", a, id); + } + codemap[i++] |= mask; + mask = 0xFFFFFFFF; + a += 32; + } + mask &= (1 << ((start + size) & 0x1F)) - 1; + if (codemap[i] & mask) + { + fprintf(stderr, "memory overlap near 0x%X for %s\n", a, id); + } + codemap[i] |= mask; + return start; +} + +/*)Function VOID lnksect() * - * area * tap pointer to an area structure + * area * tap pointer to an area structure * - * The function lnksect() is the function called by - * lnkarea() to resolve the areax addresses. Refer - * to the function lnkarea() for more detail. Pageing - * boundary and length errors will be reported by this - * function. + * The function lnksect() is the function called by + * lnkarea() to resolve the areax addresses. Refer + * to the function lnkarea() for more detail. Pageing + * boundary and length errors will be reported by this + * function. * - * local variables: - * Addr_T size size of area - * Addr_T addr address of area - * areax * taxp pointer to an areax structure + * local variables: + * Addr_T size size of area + * Addr_T addr address of area + * areax * taxp pointer to an areax structure * - * global variables: - * int lkerr error flag + * global variables: + * int lkerr error flag * - * functions called: - * none + * functions called: + * none * - * side effects: - * All area and areax addresses and sizes area determined - * and linked into the structures. + * side effects: + * All area and areax addresses and sizes area determined + * and linked into the structures. */ -VOID -lnksect(tap) -register struct area *tap; +Addr_T lnksect(struct area *tap) { - register Addr_T size, addr; - register struct areax *taxp; - - size = 0; - addr = tap->a_addr; - if ((tap->a_flag&A_PAG) && (addr & 0xFF)) { - fprintf(stderr, - "\n?ASlink-Warning-Paged Area %8s Boundary Error\n", tap->a_id); - lkerr++; - } - taxp = tap->a_axp; - if (tap->a_flag&A_OVR) { - /* - * Overlayed sections - */ - while (taxp) { - taxp->a_addr = addr; - if (taxp->a_size > size) - size = taxp->a_size; - taxp = taxp->a_axp; - } - } else { - /* - * Concatenated sections - */ - while (taxp) { - taxp->a_addr = addr; - addr += taxp->a_size; - size += taxp->a_size; - taxp = taxp->a_axp; - } - } - tap->a_size = size; - if ((tap->a_flag&A_PAG) && (size > 256)) { - fprintf(stderr, - "\n?ASlink-Warning-Paged Area %8s Length Error\n", tap->a_id); - lkerr++; - } + register Addr_T size, addr; + register struct areax *taxp; + + size = 0; + addr = tap->a_addr; + + /* MB: is this possible for hc08 ??? */ + if ((tap->a_flag&A_PAG) && (addr & 0xFF)) { + fprintf(stderr, + "\n?ASlink-Warning-Paged Area %8s Boundary Error\n", tap->a_id); + lkerr++; + } + + taxp = tap->a_axp; + if (tap->a_flag&A_OVR) { + /* + * Overlayed sections + */ + while (taxp) { + taxp->a_addr = addr; + if (taxp->a_size > size) + size = taxp->a_size; + taxp = taxp->a_axp; + } + } else if (tap->a_flag & A_ABS) { + /* + * Absolute sections + */ + while (taxp) { + allocate_space(taxp->a_addr, taxp->a_size, tap->a_id); + taxp->a_addr = 0; /* reset to zero so relative addresses become absolute */ + size += taxp->a_size; + taxp = taxp->a_axp; + } + } else { + /* + * Concatenated sections + */ + if (tap->a_size) { + addr = find_empty_space(addr, tap->a_size); + } + while (taxp) { + //find next unused address now + if (taxp->a_size) + { + addr = find_empty_space(addr, taxp->a_size); + allocate_space(addr, taxp->a_size, tap->a_id); + } + taxp->a_addr = addr; + addr += taxp->a_size; + size += taxp->a_size; + taxp = taxp->a_axp; + } + } + tap->a_size = size; + + /* MB: is this possible for hc08 ??? */ + if ((tap->a_flag&A_PAG) && (size > 256)) { + fprintf(stderr, + "\n?ASlink-Warning-Paged Area %8s Length Error\n", tap->a_id); + lkerr++; + } + + return addr; } diff --git a/as/hc08/lkhead.c b/as/hc08/lkhead.c index 1cd390ab..41a5198c 100644 --- a/as/hc08/lkhead.c +++ b/as/hc08/lkhead.c @@ -107,7 +107,7 @@ newhead() * Setup Absolute DEF linkage. */ lkparea(_abs_); - ap->a_flag = A_ABS|A_OVR; + ap->a_flag = A_ABS; } /*)Function VOID module() diff --git a/as/hc08/lklibr.c b/as/hc08/lklibr.c index eb33beaf..9a36e262 100644 --- a/as/hc08/lklibr.c +++ b/as/hc08/lklibr.c @@ -23,113 +23,113 @@ #include #include "aslink.h" -/*)Module lklibr.c - * - * The module lklibr.c contains the functions which - * (1) specify the path(s) to library files [.LIB] - * (2) specify the library file(s) [.LIB] to search - * (3) search the library files for specific symbols - * and link the module containing this symbol - * - * lklibr.c contains the following functions: - * VOID addpath() - * VOID addlib() - * VOID addfile() - * VOID search() - * VOID fndsym() - * VOID library() - * VOID loadfile() +/*)Module lklibr.c + * + * The module lklibr.c contains the functions which + * (1) specify the path(s) to library files [.LIB] + * (2) specify the library file(s) [.LIB] to search + * (3) search the library files for specific symbols + * and link the module containing this symbol + * + * lklibr.c contains the following functions: + * VOID addpath() + * VOID addlib() + * VOID addfile() + * VOID search() + * VOID fndsym() + * VOID library() + * VOID loadfile() * */ -/*)Function VOID addpath() +/*)Function VOID addpath() * - * The function addpath() creates a linked structure containing - * the paths to various object module library files. + * The function addpath() creates a linked structure containing + * the paths to various object module library files. * - * local variables: - * lbpath *lbph pointer to new path structure - * lbpath *lbp temporary pointer + * local variables: + * lbpath *lbph pointer to new path structure + * lbpath *lbp temporary pointer * - * global variables: - * lbpath *lbphead The pointer to the first - * path structure + * global variables: + * lbpath *lbphead The pointer to the first + * path structure * - * functions called: - * char getnb() lklex.c - * VOID * new() lksym.c - * int strlen() c_library - * char * strcpy() c_library - * VOID unget() lklex.c + * functions called: + * char getnb() lklex.c + * VOID * new() lksym.c + * int strlen() c_library + * char * strcpy() c_library + * VOID unget() lklex.c * - * side effects: - * An lbpath structure may be created. + * side effects: + * An lbpath structure may be created. */ VOID addpath() { - struct lbpath *lbph, *lbp; - - lbph = (struct lbpath *) new (sizeof(struct lbpath)); - if (lbphead == NULL) { - lbphead = lbph; - } else { - lbp = lbphead; - while (lbp->next) - lbp = lbp->next; - lbp->next = lbph; - } - unget(getnb()); - lbph->path = (char *) new (strlen(ip)+1); - strcpy(lbph->path, ip); + struct lbpath *lbph, *lbp; + + lbph = (struct lbpath *) new (sizeof(struct lbpath)); + if (lbphead == NULL) { + lbphead = lbph; + } else { + lbp = lbphead; + while (lbp->next) + lbp = lbp->next; + lbp->next = lbph; + } + unget(getnb()); + lbph->path = (char *) new (strlen(ip)+1); + strcpy(lbph->path, ip); } -/*)Function VOID addlib() +/*)Function VOID addlib() * - * The function addlib() tests for the existance of a - * library path structure to determine the method of - * adding this library file to the library search structure. + * The function addlib() tests for the existance of a + * library path structure to determine the method of + * adding this library file to the library search structure. * - * This function calls the function addfile() to actually - * add the library file to the search list. + * This function calls the function addfile() to actually + * add the library file to the search list. * - * local variables: - * lbpath *lbph pointer to path structure + * local variables: + * lbpath *lbph pointer to path structure * - * global variables: - * lbpath *lbphead The pointer to the first - * path structure + * global variables: + * lbpath *lbphead The pointer to the first + * path structure * ip a pointer to the library name * - * functions called: - * VOID addfile() lklibr.c - * char getnb() lklex.c - * VOID unget() lklex.c + * functions called: + * VOID addfile() lklibr.c + * char getnb() lklex.c + * VOID unget() lklex.c * - * side effects: - * The function addfile() may add the file to - * the library search list. + * side effects: + * The function addfile() may add the file to + * the library search list. */ VOID addlib() { - struct lbpath *lbph; + struct lbpath *lbph; int foundcount=0; - unget(getnb()); + unget(getnb()); - if (lbphead == NULL) + if (lbphead == NULL) { - foundcount=addfile(NULL, ip); - } + foundcount=addfile(NULL, ip); + } else { - for (lbph=lbphead; lbph; lbph=lbph->next) + for (lbph=lbphead; lbph; lbph=lbph->next) { - foundcount+=addfile(lbph->path, ip); - } + foundcount+=addfile(lbph->path, ip); + } } if(foundcount == 0) { @@ -137,38 +137,38 @@ addlib() } } -/*)Function int addfile(path,libfil) +/*)Function int addfile(path,libfil) * - * char *path library path specification - * char *libfil library file specification + * char *path library path specification + * char *libfil library file specification * - * The function addfile() searches for the library file - * by concatenating the path and libfil specifications. - * if the library is found, an lbname structure is created - * and linked to any previously defined structures. This - * linked list is used by the function fndsym() to attempt - * to find any undefined symbols. + * The function addfile() searches for the library file + * by concatenating the path and libfil specifications. + * if the library is found, an lbname structure is created + * and linked to any previously defined structures. This + * linked list is used by the function fndsym() to attempt + * to find any undefined symbols. * - * The function does not give report an error on invalid - * path / file specifications or if the file is not found. + * The function does not give report an error on invalid + * path / file specifications or if the file is not found. * - * local variables: - * lbname *lbnh pointer to new name structure - * lbname *lbn temporary pointer + * local variables: + * lbname *lbnh pointer to new name structure + * lbname *lbn temporary pointer * - * global variables: - * lbname *lbnhead The pointer to the first - * path structure + * global variables: + * lbname *lbnhead The pointer to the first + * path structure * - * functions called: - * char getnb() lklex.c - * VOID * new() lksym.c - * int strlen() c_library - * char * strcpy() c_library - * VOID unget() lklex.c + * functions called: + * char getnb() lklex.c + * VOID * new() lksym.c + * int strlen() c_library + * char * strcpy() c_library + * VOID unget() lklex.c * - * side effects: - * An lbname structure may be created. + * side effects: + * An lbname structure may be created. * * return: * 1: the library was found @@ -177,52 +177,52 @@ addlib() int addfile(char * path, char * libfil) { - FILE *fp; - char *str; - struct lbname *lbnh, *lbn; -#ifdef OTHERSYSTEM + FILE *fp; + char *str; + struct lbname *lbnh, *lbn; +#ifdef OTHERSYSTEM int libfilinc=0; #endif - if (path != NULL) + if (path != NULL) { - str = (char *) new (strlen(path) + strlen(libfil) + 6); - strcpy(str,path); -#ifdef OTHERSYSTEM - if (str[strlen(str)-1] != '/') + str = (char *) new (strlen(path) + strlen(libfil) + 6); + strcpy(str,path); +#ifdef OTHERSYSTEM + if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\')) { - strcat(str,"/"); - } + strcat(str,"/"); + } #endif - } + } else { - str = (char *) new (strlen(libfil) + 5); - } + str = (char *) new (strlen(libfil) + 5); + } -#ifdef OTHERSYSTEM - if (libfil[0] == '/') +#ifdef OTHERSYSTEM + if ((libfil[0] == '/') || (libfil[0] == '\\')) { libfil++; libfilinc=1; } #endif - + strcat(str, libfil); - if(strchr(libfil, FSEPX) == NULL) + if(strchr(libfil, FSEPX) == NULL) { - sprintf(&str[strlen(str)], "%clib", FSEPX); - } + sprintf(&str[strlen(str)], "%clib", FSEPX); + } fp=fopen(str, "r"); if(fp == NULL) { /*Ok, that didn't work. Try with the 'libfil' name only*/ -#ifdef OTHERSYSTEM +#ifdef OTHERSYSTEM if(libfilinc) libfil--; #endif fp=fopen(libfil, "r"); - if(fp != NULL) + if(fp != NULL) { /*Bingo! 'libfil' is the absolute path of the library*/ strcpy(str, libfil); @@ -241,7 +241,7 @@ int addfile(char * path, char * libfil) strcpy(path, str); for(j=strlen(path)-1; j>=0; j--) { - if((path[j]=='\\')||(path[j]=='/')) + if((path[j] == '/') || (path[j] == '\\')) { strcpy(libfil, &path[j+1]); path[j+1]=0; @@ -251,140 +251,140 @@ int addfile(char * path, char * libfil) if(j<=0) path[0]=0; } - if (fp != NULL) + if (fp != NULL) { - fclose(fp); - lbnh = (struct lbname *) new (sizeof(struct lbname)); - if (lbnhead == NULL) + fclose(fp); + lbnh = (struct lbname *) new (sizeof(struct lbname)); + if (lbnhead == NULL) { - lbnhead = lbnh; - } + lbnhead = lbnh; + } else { - lbn = lbnhead; - while (lbn->next) - lbn = lbn->next; - lbn->next = lbnh; - } - + lbn = lbnhead; + while (lbn->next) + lbn = lbn->next; + lbn->next = lbnh; + } + lbnh->path = path; - lbnh->libfil = (char *) new (strlen(libfil) + 1); - strcpy(lbnh->libfil,libfil); - lbnh->libspc = str; + lbnh->libfil = (char *) new (strlen(libfil) + 1); + strcpy(lbnh->libfil,libfil); + lbnh->libspc = str; return 1; - } - else + } + else { - free(str); + free(str); return 0; - } + } } -/*)Function VOID search() +/*)Function VOID search() * - * The function search() looks through all the symbol tables - * at the end of pass 1. If any undefined symbols are found - * then the function fndsym() is called. Function fndsym() - * searches any specified library files to automagically - * import the object modules containing the needed symbol. + * The function search() looks through all the symbol tables + * at the end of pass 1. If any undefined symbols are found + * then the function fndsym() is called. Function fndsym() + * searches any specified library files to automagically + * import the object modules containing the needed symbol. * - * After a symbol is found and imported by the function - * fndsym() the symbol tables are again searched. The - * symbol tables are search until no more symbols can be - * resolved within the library files. This ensures that - * back references from one library module to another are - * also resolved. + * After a symbol is found and imported by the function + * fndsym() the symbol tables are again searched. The + * symbol tables are search until no more symbols can be + * resolved within the library files. This ensures that + * back references from one library module to another are + * also resolved. * - * local variables: - * int i temporary counter - * sym *sp pointer to a symbol structure - * int symfnd found a symbol flag + * local variables: + * int i temporary counter + * sym *sp pointer to a symbol structure + * int symfnd found a symbol flag * - * global variables: - * sym *symhash[] array of pointers to symbol tables + * global variables: + * sym *symhash[] array of pointers to symbol tables * - * functions called: - * int fndsym() lklibr.c + * functions called: + * int fndsym() lklibr.c * - * side effects: - * If a symbol is found then the library object module - * containing the symbol will be imported and linked. + * side effects: + * If a symbol is found then the library object module + * containing the symbol will be imported and linked. */ VOID search() { - register struct sym *sp; - register int i,symfnd; - - /* - * Look for undefined symbols. Keep - * searching until no more symbols are resolved. - */ - symfnd = 1; - while (symfnd) { - symfnd = 0; - /* - * Look through all the symbols - */ - for (i=0; is_type & S_DEF) == 0) { - if (fndsym(sp->s_id)) { - symfnd++; - } - } - sp = sp->s_sp; - } - } - } + register struct sym *sp; + register int i,symfnd; + + /* + * Look for undefined symbols. Keep + * searching until no more symbols are resolved. + */ + symfnd = 1; + while (symfnd) { + symfnd = 0; + /* + * Look through all the symbols + */ + for (i=0; is_type & S_DEF) == 0) { + if (fndsym(sp->s_id)) { + symfnd++; + } + } + sp = sp->s_sp; + } + } + } } /*Load a .rel file embedded in a sdcclib file*/ void LoadRel(FILE * libfp, char * ModName) { - char str[NINPUT+2]; - int state=0; - - while (fgets(str, NINPUT, libfp) != NULL) - { - str[NINPUT+1] = '\0'; - chop_crlf(str); - switch(state) - { - case 0: - if(EQ(str, "")) - { - fgets(str, NINPUT, libfp); - str[NINPUT+1] = '\0'; - chop_crlf(str); - if(EQ(str, ModName)) state=1; - else - { - printf("Bad offset in library file str=%s, Modname=%s\n", str, ModName); - lkexit(1); - } - } - break; - case 1: - if(EQ(str, "")) state=2; - break; - case 2: - if(EQ(str, "")) return; - ip = str; - link_main(); - break; - } - } + char str[NINPUT+2]; + int state=0; + + while (fgets(str, NINPUT, libfp) != NULL) + { + str[NINPUT+1] = '\0'; + chop_crlf(str); + switch(state) + { + case 0: + if(EQ(str, "")) + { + fgets(str, NINPUT, libfp); + str[NINPUT+1] = '\0'; + chop_crlf(str); + if(EQ(str, ModName)) state=1; + else + { + printf("Bad offset in library file str=%s, Modname=%s\n", str, ModName); + lkexit(1); + } + } + break; + case 1: + if(EQ(str, "")) state=2; + break; + case 2: + if(EQ(str, "")) return; + ip = str; + link_main(); + break; + } + } } /*Load an .adb file embedded in a sdcclib file. If there is @@ -393,27 +393,27 @@ This way the aomf51 will not have uselless empty modules. */ int LoadAdb(FILE * libfp) { - char str[MAXLINE+1]; - int state=0; - int ToReturn=0; - - while (fgets(str, MAXLINE, libfp) != NULL) - { - str[NINPUT+1] = '\0'; - chop_crlf(str); - switch(state) - { - case 0: - if(EQ(str, "")) state=1; - break; - case 1: - if(EQ(str, "")) return ToReturn; - fprintf(dfp, "%s\n", str); - ToReturn=1; - break; - } - } - return ToReturn; + char str[MAXLINE+1]; + int state=0; + int ToReturn=0; + + while (fgets(str, MAXLINE, libfp) != NULL) + { + str[NINPUT+1] = '\0'; + chop_crlf(str); + switch(state) + { + case 0: + if(EQ(str, "")) state=1; + break; + case 1: + if(EQ(str, "")) return ToReturn; + fprintf(dfp, "%s\n", str); + ToReturn=1; + break; + } + } + return ToReturn; } /*Check for a symbol in a SDCC library. If found, add the embedded .rel and @@ -423,13 +423,13 @@ embedded in the library file.*/ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) { - struct lbfile *lbfh, *lbf; - char ModName[NCPS]=""; - char FLine[MAXLINE+1]; - int state=0; - long IndexOffset=0, FileOffset; + struct lbfile *lbfh, *lbf; + char ModName[NCPS]=""; + char FLine[MAXLINE+1]; + int state=0; + long IndexOffset=0, FileOffset; - while(!feof(libfp)) + while(!feof(libfp)) { FLine[0]=0; fgets(FLine, MAXLINE, libfp); @@ -440,425 +440,425 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) case 0: if(EQ(FLine, "")) { - /*The next line has the size of the index*/ + /*The next line has the size of the index*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - IndexOffset=atol(FLine); - state=1; + IndexOffset=atol(FLine); + state=1; } break; case 1: if(EQ(FLine, "")) - { - /*The next line has the name of the module and the offset - of the corresponding embedded file in the library*/ + { + /*The next line has the name of the module and the offset + of the corresponding embedded file in the library*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - sscanf(FLine, "%s %ld", ModName, &FileOffset); - state=2; - } + sscanf(FLine, "%s %ld", ModName, &FileOffset); + state=2; + } else if(EQ(FLine, "")) - { - /*Reached the end of the index. The symbol is not in this library.*/ - return 0; - } + { + /*Reached the end of the index. The symbol is not in this library.*/ + return 0; + } break; case 2: if(EQ(FLine, "")) - { - /*The symbol is not in this module, try the next one*/ + { + /*The symbol is not in this module, try the next one*/ state=1; - } + } else - { - /*Check if this is the symbol we are looking for.*/ - if (strncmp(SymName, FLine, NCPS)==0) - { - /*The symbol is in this module.*/ - - /*As in the original library format, it is assumed that the .rel - files reside in the same directory as the lib files.*/ - strcat(DirLib, ModName); - sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX); - - /*If this module has been loaded already don't load it again.*/ - lbf = lbfhead; - while (lbf) - { - if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/ - lbf=lbf->next; - } - - /*Add the embedded file to the list of files to be loaded in - the second pass. That is performed latter by the function - library() below.*/ - lbfh = (struct lbfile *) new (sizeof(struct lbfile)); - if (lbfhead == NULL) - { - lbfhead = lbfh; - } - else - { - lbf = lbfhead; - while (lbf->next) - lbf = lbf->next; - lbf->next = lbfh; - } - - lbfh->libspc = PathLib; - lbfh->filspc = DirLib; - lbfh->relfil = (char *) new (strlen(ModName) + 1); - strcpy(lbfh->relfil, ModName); - /*Library embedded file, so lbfh->offset must be >=0*/ - lbfh->offset = IndexOffset+FileOffset; - - /*Jump to where the .rel begins and load it.*/ - fseek(libfp, lbfh->offset, SEEK_SET); - LoadRel(libfp, ModName); - - /* if cdb information required & .adb file present */ - if (dflag && dfp) - { - if(LoadAdb(libfp)) - SaveLinkedFilePath(DirLib); - } - return 1; /*Found the symbol, so success!*/ - } - } + { + /*Check if this is the symbol we are looking for.*/ + if (strncmp(SymName, FLine, NCPS)==0) + { + /*The symbol is in this module.*/ + + /*As in the original library format, it is assumed that the .rel + files reside in the same directory as the lib files.*/ + strcat(DirLib, ModName); + sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX); + + /*If this module has been loaded already don't load it again.*/ + lbf = lbfhead; + while (lbf) + { + if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/ + lbf=lbf->next; + } + + /*Add the embedded file to the list of files to be loaded in + the second pass. That is performed latter by the function + library() below.*/ + lbfh = (struct lbfile *) new (sizeof(struct lbfile)); + if (lbfhead == NULL) + { + lbfhead = lbfh; + } + else + { + lbf = lbfhead; + while (lbf->next) + lbf = lbf->next; + lbf->next = lbfh; + } + + lbfh->libspc = PathLib; + lbfh->filspc = DirLib; + lbfh->relfil = (char *) new (strlen(ModName) + 1); + strcpy(lbfh->relfil, ModName); + /*Library embedded file, so lbfh->offset must be >=0*/ + lbfh->offset = IndexOffset+FileOffset; + + /*Jump to where the .rel begins and load it.*/ + fseek(libfp, lbfh->offset, SEEK_SET); + LoadRel(libfp, ModName); + + /* if cdb information required & .adb file present */ + if (dflag && dfp) + { + if(LoadAdb(libfp)) + SaveLinkedFilePath(DirLib); + } + return 1; /*Found the symbol, so success!*/ + } + } + break; + + default: + return 0; /*It should never reach this point, but just in case...*/ break; - - default: - return 0; /*It should never reach this point, but just in case...*/ - break; } } - return 0; /*The symbol is not in this library*/ + return 0; /*The symbol is not in this library*/ } -/*)Function VOID fndsym(name) - * - * char *name symbol name to find - * - * The function fndsym() searches through all combinations of the - * library path specifications (input by the -k option) and the - * library file specifications (input by the -l option) that - * lead to an existing file. - * - * The file specicifation may be formed in one of two ways: - * - * (1) If the library file contained an absolute - * path/file specification then this becomes filspc. - * (i.e. C:\...) - * - * (2) If the library file contains a relative path/file - * specification then the concatenation of the path - * and this file specification becomes filspc. - * (i.e. \...) - * - * The structure lbfile is created for the first library - * object file which contains the definition for the - * specified undefined symbol. - * - * If the library file [.LIB] contains file specifications for - * non existant files, no errors are returned. - * - * local variables: - * char buf[] [.REL] file input line - * char c [.REL] file input character - * FILE *fp file handle for object file - * lbfile *lbf temporary pointer - * lbfile *lbfh pointer to lbfile structure - * FILE *libfp file handle for library file - * lbname *lbnh pointer to lbname structure - * char *path file specification path - * char relfil[] [.REL] file specification - * char *str combined path and file specification - * char symname[] [.REL] file symbol string - * - * global variables: - * lbname *lbnhead The pointer to the first - * name structure - * lbfile *lbfhead The pointer to the first - * file structure - * - * functions called: - * int fclose() c_library - * int fgets() c_library - * FILE *fopen() c_library - * VOID free() c_library - * char getnb() lklex.c - * VOID lkexit() lkmain.c - * VOID loadfile() lklibr.c - * VOID * new() lksym.c - * char * sprintf() c_library - * int sscanf() c_library - * char * strcat() c_library - * char * strchr() c_library - * char * strcpy() c_library - * int strlen() c_library - * int strncmp() c_library - * VOID unget() lklex.c - * - * side effects: - * If the symbol is found then a new lbfile structure - * is created and added to the linked list of lbfile - * structures. The file containing the found symbol - * is linked. +/*)Function VOID fndsym(name) + * + * char *name symbol name to find + * + * The function fndsym() searches through all combinations of the + * library path specifications (input by the -k option) and the + * library file specifications (input by the -l option) that + * lead to an existing file. + * + * The file specicifation may be formed in one of two ways: + * + * (1) If the library file contained an absolute + * path/file specification then this becomes filspc. + * (i.e. C:\...) + * + * (2) If the library file contains a relative path/file + * specification then the concatenation of the path + * and this file specification becomes filspc. + * (i.e. \...) + * + * The structure lbfile is created for the first library + * object file which contains the definition for the + * specified undefined symbol. + * + * If the library file [.LIB] contains file specifications for + * non existant files, no errors are returned. + * + * local variables: + * char buf[] [.REL] file input line + * char c [.REL] file input character + * FILE *fp file handle for object file + * lbfile *lbf temporary pointer + * lbfile *lbfh pointer to lbfile structure + * FILE *libfp file handle for library file + * lbname *lbnh pointer to lbname structure + * char *path file specification path + * char relfil[] [.REL] file specification + * char *str combined path and file specification + * char symname[] [.REL] file symbol string + * + * global variables: + * lbname *lbnhead The pointer to the first + * name structure + * lbfile *lbfhead The pointer to the first + * file structure + * + * functions called: + * int fclose() c_library + * int fgets() c_library + * FILE *fopen() c_library + * VOID free() c_library + * char getnb() lklex.c + * VOID lkexit() lkmain.c + * VOID loadfile() lklibr.c + * VOID * new() lksym.c + * char * sprintf() c_library + * int sscanf() c_library + * char * strcat() c_library + * char * strchr() c_library + * char * strcpy() c_library + * int strlen() c_library + * int strncmp() c_library + * VOID unget() lklex.c + * + * side effects: + * If the symbol is found then a new lbfile structure + * is created and added to the linked list of lbfile + * structures. The file containing the found symbol + * is linked. */ int fndsym(name) char *name; { - FILE *libfp, *fp; - struct lbname *lbnh; - struct lbfile *lbfh, *lbf; - char relfil[NINPUT+2]; - char buf[NINPUT+2]; - char symname[NINPUT]; - char *path,*str; - char c; - int result; - - /* - * Search through every library in the linked list "lbnhead". - */ - - for (lbnh=lbnhead; lbnh; lbnh=lbnh->next) - { - if ((libfp = fopen(lbnh->libspc, "r")) == NULL) - { - fprintf(stderr, "Cannot open library file %s\n", - lbnh->libspc); - lkexit(1); - } - path = lbnh->path; - - /* - * Read in a line from the library file. - * This is the relative file specification - * for a .REL file in this library. - */ - - while (fgets(relfil, NINPUT, libfp) != NULL) - { - relfil[NINPUT+1] = '\0'; - chop_crlf(relfil); - if (path != NULL) - { - str = (char *) new (strlen(path)+strlen(relfil)+6); - strcpy(str,path); -#ifdef OTHERSYSTEM - if (str[strlen(str)-1] != '/') - { - strcat(str,"/"); - } + FILE *libfp, *fp; + struct lbname *lbnh; + struct lbfile *lbfh, *lbf; + char relfil[NINPUT+2]; + char buf[NINPUT+2]; + char symname[NINPUT]; + char *path,*str; + char c; + int result; + + /* + * Search through every library in the linked list "lbnhead". + */ + + for (lbnh=lbnhead; lbnh; lbnh=lbnh->next) + { + if ((libfp = fopen(lbnh->libspc, "r")) == NULL) + { + fprintf(stderr, "Cannot open library file %s\n", + lbnh->libspc); + lkexit(1); + } + path = lbnh->path; + + /* + * Read in a line from the library file. + * This is the relative file specification + * for a .REL file in this library. + */ + + while (fgets(relfil, NINPUT, libfp) != NULL) + { + relfil[NINPUT+1] = '\0'; + chop_crlf(relfil); + if (path != NULL) + { + str = (char *) new (strlen(path)+strlen(relfil)+6); + strcpy(str,path); +#ifdef OTHERSYSTEM + if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\')) + { + strcat(str,"/"); + } #endif - } - else - { - str = (char *) new (strlen(relfil) + 5); - } - - if(strcmp(relfil, "")==0) - { - result=SdccLib(lbnh->libspc, libfp, str, name); - fclose(libfp); - if(result) return(1); /*Found the symbol*/ - free(str); - /*The symbol is not in the current library, - check the next library in the list*/ - break; - } - - /*From here down is the support for libraries in the original format*/ - if (relfil[0] == '\\') - { - strcat(str,relfil+1); - } - else - { - strcat(str,relfil); - } - - if(strchr(relfil, FSEPX) == NULL) - { - sprintf(&str[strlen(str)], "%crel", FSEPX); - } - - if ((fp = fopen(str, "r")) != NULL) - { - - /* - * Read in the object file. Look for lines that - * begin with "S" and end with "D". These are - * symbol table definitions. If we find one, see - * if it is our symbol. Make sure we only read in - * our object file and don't go into the next one. - */ - - while (fgets(buf, NINPUT, fp) != NULL) - { - buf[NINPUT+1] = '\0'; - chop_crlf(buf); - /* - * Skip everything that's not a symbol record. - */ - if (buf[0] != 'S') continue; - - /* - * When a 'T line' is found terminate file scan. - * All 'S line's preceed 'T line's in .REL files. - */ - if (buf[0] == 'T') break; - - sscanf(buf, "S %s %c", symname, &c); - - /* - * If we find a symbol definition for the - * symbol we're looking for, load in the - * file and add it to lbfhead so it gets - * loaded on pass number 2. - */ - if (strncmp(symname, name, NCPS) == 0 && c == 'D') - { - lbfh = (struct lbfile *) new (sizeof(struct lbfile)); - if (lbfhead == NULL) - { - lbfhead = lbfh; - } - else - { - lbf = lbfhead; - while (lbf->next) - lbf = lbf->next; - lbf->next = lbfh; - } - - lbfh->libspc = lbnh->libspc; - lbfh->filspc = str; - lbfh->relfil = (char *) new (strlen(relfil) + 1); - lbfh->offset = -1; /*Stand alone rel file*/ - strcpy(lbfh->relfil,relfil); - fclose(fp); - fclose(libfp); - - /* if cdb information required & adb file present */ - if (dflag && dfp) - { - FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002 - if (xfp) - { - SaveLinkedFilePath(str); - copyfile(dfp,xfp); - fclose(xfp); - } - } - loadfile(str); - return (1); - } - } - fclose(fp); - } - free(str); - } - fclose(libfp); - } - return(0); + } + else + { + str = (char *) new (strlen(relfil) + 5); + } + + if(strcmp(relfil, "")==0) + { + result=SdccLib(lbnh->libspc, libfp, str, name); + fclose(libfp); + if(result) return(1); /*Found the symbol*/ + free(str); + /*The symbol is not in the current library, + check the next library in the list*/ + break; + } + + /*From here down is the support for libraries in the original format*/ + if (relfil[0] == '\\') + { + strcat(str,relfil+1); + } + else + { + strcat(str,relfil); + } + + if(strchr(relfil, FSEPX) == NULL) + { + sprintf(&str[strlen(str)], "%crel", FSEPX); + } + + if ((fp = fopen(str, "r")) != NULL) + { + + /* + * Read in the object file. Look for lines that + * begin with "S" and end with "D". These are + * symbol table definitions. If we find one, see + * if it is our symbol. Make sure we only read in + * our object file and don't go into the next one. + */ + + while (fgets(buf, NINPUT, fp) != NULL) + { + buf[NINPUT+1] = '\0'; + chop_crlf(buf); + /* + * Skip everything that's not a symbol record. + */ + if (buf[0] != 'S') continue; + + /* + * When a 'T line' is found terminate file scan. + * All 'S line's preceed 'T line's in .REL files. + */ + if (buf[0] == 'T') break; + + sscanf(buf, "S %s %c", symname, &c); + + /* + * If we find a symbol definition for the + * symbol we're looking for, load in the + * file and add it to lbfhead so it gets + * loaded on pass number 2. + */ + if (strncmp(symname, name, NCPS) == 0 && c == 'D') + { + lbfh = (struct lbfile *) new (sizeof(struct lbfile)); + if (lbfhead == NULL) + { + lbfhead = lbfh; + } + else + { + lbf = lbfhead; + while (lbf->next) + lbf = lbf->next; + lbf->next = lbfh; + } + + lbfh->libspc = lbnh->libspc; + lbfh->filspc = str; + lbfh->relfil = (char *) new (strlen(relfil) + 1); + lbfh->offset = -1; /*Stand alone rel file*/ + strcpy(lbfh->relfil,relfil); + fclose(fp); + fclose(libfp); + + /* if cdb information required & adb file present */ + if (dflag && dfp) + { + FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002 + if (xfp) + { + SaveLinkedFilePath(str); + copyfile(dfp,xfp); + fclose(xfp); + } + } + loadfile(str); + return (1); + } + } + fclose(fp); + } + free(str); + } + fclose(libfp); + } + return(0); } void loadfile_SdccLib(char * libspc, char * module, long offset) { - FILE *fp; - - if ((fp = fopen(libspc,"r")) != NULL) - { - fseek(fp, offset, SEEK_SET); - LoadRel(fp, module); - fclose(fp); - } + FILE *fp; + + if ((fp = fopen(libspc,"r")) != NULL) + { + fseek(fp, offset, SEEK_SET); + LoadRel(fp, module); + fclose(fp); + } } -/*)Function VOID library() +/*)Function VOID library() * - * The function library() links all the library object files - * contained in the lbfile structures. + * The function library() links all the library object files + * contained in the lbfile structures. * - * local variables: - * lbfile *lbfh pointer to lbfile structure + * local variables: + * lbfile *lbfh pointer to lbfile structure * - * global variables: - * lbfile *lbfhead pointer to first lbfile structure + * global variables: + * lbfile *lbfhead pointer to first lbfile structure * - * functions called: - * VOID loadfile lklibr.c + * functions called: + * VOID loadfile lklibr.c * - * side effects: - * Links all files contained in the lbfile structures. + * side effects: + * Links all files contained in the lbfile structures. */ VOID library() { - struct lbfile *lbfh; - - for (lbfh=lbfhead; lbfh; lbfh=lbfh->next) - { - if(lbfh->offset<0) - { - /*Stand alone rel file (original lib format)*/ - loadfile(lbfh->filspc); - } - else - { - /*rel file embedded in lib (new lib format)*/ - loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset); - } - } + struct lbfile *lbfh; + + for (lbfh=lbfhead; lbfh; lbfh=lbfh->next) + { + if(lbfh->offset<0) + { + /*Stand alone rel file (original lib format)*/ + loadfile(lbfh->filspc); + } + else + { + /*rel file embedded in lib (new lib format)*/ + loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset); + } + } } -/*)Function VOID loadfile(filspc) +/*)Function VOID loadfile(filspc) * - * char *filspc library object file specification + * char *filspc library object file specification * - * The function loadfile() links the library object module. + * The function loadfile() links the library object module. * - * local variables: - * FILE *fp file handle - * int i input line length - * char str[] file input line + * local variables: + * FILE *fp file handle + * int i input line length + * char str[] file input line * - * global variables: - * char *ip pointer to linker input string + * global variables: + * char *ip pointer to linker input string * - * functions called: - * int fclose() c_library - * int fgets() c_library - * FILE * fopen() c_library - * VOID link_main() lkmain.c - * int strlen() c_library + * functions called: + * int fclose() c_library + * int fgets() c_library + * FILE * fopen() c_library + * VOID link_main() lkmain.c + * int strlen() c_library * - * side effects: - * If file exists it is linked. + * side effects: + * If file exists it is linked. */ VOID loadfile(filspc) char *filspc; { - FILE *fp; - char str[NINPUT+2]; - - if ((fp = fopen(filspc,"r")) != NULL) { - while (fgets(str, NINPUT, fp) != NULL) { - str[NINPUT+1] = '\0'; - chop_crlf(str); - ip = str; - link_main(); - } - fclose(fp); - } + FILE *fp; + char str[NINPUT+2]; + + if ((fp = fopen(filspc,"r")) != NULL) { + while (fgets(str, NINPUT, fp) != NULL) { + str[NINPUT+1] = '\0'; + chop_crlf(str); + ip = str; + link_main(); + } + fclose(fp); + } } diff --git a/as/hc08/m08pst.c b/as/hc08/m08pst.c index 0da9cc9c..34b945bb 100644 --- a/as/hc08/m08pst.c +++ b/as/hc08/m08pst.c @@ -25,7 +25,7 @@ struct mne mne[] = { { NULL, "CON", S_ATYP, 0, A_CON }, { NULL, "OVR", S_ATYP, 0, A_OVR }, { NULL, "REL", S_ATYP, 0, A_REL }, - { NULL, "ABS", S_ATYP, 0, A_ABS|A_OVR }, + { NULL, "ABS", S_ATYP, 0, A_ABS }, { NULL, "NOPAG", S_ATYP, 0, A_NOPAG }, { NULL, "PAG", S_ATYP, 0, A_PAG }, { NULL, "CODE", S_ATYP, 0, A_CODE }, diff --git a/as/mcs51/asm.h b/as/mcs51/asm.h index 3d4cd97e..5490613c 100644 --- a/as/mcs51/asm.h +++ b/as/mcs51/asm.h @@ -145,6 +145,7 @@ struct area struct area *a_ap; /* Area link */ char a_id[NCPS]; /* Area Name */ int a_ref; /* Ref. number */ + Addr_T a_addr; /* Area address */ Addr_T a_size; /* Area size */ Addr_T a_fuzz; /* Area fuzz */ int a_flag; /* Area flags */ @@ -296,6 +297,7 @@ struct sym struct area *s_area; /* Area line, 0 if absolute */ int s_ref; /* Ref. number */ Addr_T s_addr; /* Address */ + Addr_T s_org; /* Start Address if absolute */ }; #define S_GBL 01 /* Global */ diff --git a/as/mcs51/asmain.c b/as/mcs51/asmain.c index 3d31bf03..13664abc 100644 --- a/as/mcs51/asmain.c +++ b/as/mcs51/asmain.c @@ -556,7 +556,7 @@ loop: goto loop; } /* - * If the first character is a letter then assume a lable, + * If the first character is a letter then assume a label, * symbol, assembler directive, or assembler mnemonic is * being processed. */ @@ -875,7 +875,7 @@ loop: case S_ORG: if (dot.s_area->a_flag & A_ABS) { outall(); - laddr = dot.s_addr = absexpr(); + laddr = dot.s_addr = dot.s_org = absexpr(); } else { err('o'); } @@ -1133,7 +1133,11 @@ register struct area *nap; if (oap->a_size < dot.s_addr) { oap->a_size = dot.s_addr; } + } else if (oap->a_flag & A_ABS) { + oap->a_addr = dot.s_org; + oap->a_size = dot.s_addr - dot.s_org; } else { + oap->a_addr = 0; oap->a_size = dot.s_addr; } if (nap->a_flag & A_OVR) { diff --git a/as/mcs51/asout.c b/as/mcs51/asout.c index 7c548fdc..c2ef5bfc 100644 --- a/as/mcs51/asout.c +++ b/as/mcs51/asout.c @@ -977,7 +977,7 @@ register struct area *ap; putc(c, ofp); } if (xflag == 0) { - fprintf(ofp, " size %X flags %X\n", ap->a_size, ap->a_flag); + fprintf(ofp, " size %X flags %X addr %X\n", ap->a_size, ap->a_flag, ap->a_addr); } else if (xflag == 1) { fprintf(ofp, " size %o flags %o\n", ap->a_size, ap->a_flag); diff --git a/as/mcs51/i51pst.c b/as/mcs51/i51pst.c index 16c40834..2e1908de 100644 --- a/as/mcs51/i51pst.c +++ b/as/mcs51/i51pst.c @@ -26,7 +26,7 @@ struct mne mne[] = { { NULL, "CON", S_ATYP, 0, A_CON}, { NULL, "OVR", S_ATYP, 0, A_OVR}, { NULL, "REL", S_ATYP, 0, A_REL}, - { NULL, "ABS", S_ATYP, 0, A_ABS|A_OVR}, + { NULL, "ABS", S_ATYP, 0, A_ABS}, { NULL, "NOPAG", S_ATYP, 0, A_NOPAG}, { NULL, "PAG", S_ATYP, 0, A_PAG}, diff --git a/as/mcs51/lkaomf51.c b/as/mcs51/lkaomf51.c index 812c616f..37462eb5 100644 --- a/as/mcs51/lkaomf51.c +++ b/as/mcs51/lkaomf51.c @@ -74,7 +74,7 @@ typedef struct int numlinenum=0; _linenum * linenum=NULL; - +#if 0 typedef struct { char * name; @@ -108,7 +108,7 @@ _UsageType UsageType[]= {"BSEG", 4}, {"", 5} /*A typeless number?*/ }; - +#endif char * UsageTypeName[]={"CODE", "XDATA", "DATA", "IDATA", "BIT", "NUMBER"}; int AddNumber; unsigned char * ihxBuff=NULL; diff --git a/as/mcs51/lkarea.c b/as/mcs51/lkarea.c index 3913ae83..e8fc29b8 100644 --- a/as/mcs51/lkarea.c +++ b/as/mcs51/lkarea.c @@ -137,6 +137,11 @@ newarea() /* lkerr++; */ /* } */ } + /* + * Evaluate area address + */ + skip(-1); + axp->a_addr = eval(); /* * Place pointer in header area list */ @@ -483,20 +488,22 @@ lnksect(register struct area *tap) } } -void lnksect2 (struct area *tap, int rloc); +Addr_T lnksect2 (struct area *tap, int rloc); char idatamap[256]; -long codemap[524288]; +unsigned long codemap[524288]; /*Modified version of the functions for packing variables in internal data memory*/ VOID lnkarea2 (void) { Addr_T rloc[4]={0, 0, 0, 0}; + Addr_T gs_size = 0; int locIndex; char temp[NCPS]; struct sym *sp; int j; struct area *dseg_ap = NULL; struct area *abs_ap = NULL; + struct area *gs0_ap = NULL; struct sym *sp_dseg_s=NULL, *sp_dseg_l=NULL; for(j=0; j<256; j++) idatamap[j]=' '; @@ -518,6 +525,33 @@ VOID lnkarea2 (void) ap = ap->a_ap; } + /* next accumulate all GSINITx/GSFINAL area sizes + into GSINIT so they stay together */ + ap = areap; + while (ap) + { + if (!strncmp(ap->a_id, "GS", 2)) + {/* GSxxxxx area */ + if (ap->a_size == 0) + { + axp = ap->a_axp; + while (axp) + { + ap->a_size += axp->a_size; + axp = axp->a_axp; + } + } + gs_size += ap->a_size; + if (!strcmp(ap->a_id, "GSINIT0")) + {/* GSINIT0 area */ + gs0_ap = ap; + } + } + ap = ap->a_ap; + } + if (gs0_ap) + gs0_ap->a_size = gs_size; + ap = areap; while (ap) { @@ -527,7 +561,7 @@ VOID lnkarea2 (void) else if (ap->a_flag & A_BIT) locIndex = 3; else locIndex = 0; - if (ap->a_flag&A_ABS) /* Absolute sections */ + if (ap->a_flag & A_ABS) /* Absolute sections */ { lnksect2(ap, locIndex); } @@ -535,12 +569,11 @@ VOID lnkarea2 (void) { if (ap->a_type == 0) { - ap->a_addr=rloc[locIndex]; - ap->a_type=1; + ap->a_addr = rloc[locIndex]; + ap->a_type = 1; } - lnksect2(ap, locIndex); - rloc[locIndex] = ap->a_addr + ap->a_size; + rloc[locIndex] = lnksect2(ap, locIndex); } /* @@ -604,12 +637,91 @@ VOID lnkarea2 (void) #endif } -void lnksect2 (struct area *tap, int rloc) +static +Addr_T find_empty_space(Addr_T start, Addr_T size) +{ + int i, j, k; + unsigned long mask, b; + + while (1) + { + Addr_T a = start; + i = start >> 5; + j = (start + size) >> 5; + mask = -(1 << (start & 0x1F)); + + while (i < j) + { + if (codemap[i] & mask) + { + k = 32; + for (b=0x80000000; b!=0; b>>=1, k--) + { + if (codemap[i] & b) + break; + } + start = a + k; + break; + } + i++; + mask = 0xFFFFFFFF; + a += 32; + } + if (start > a) + continue; + + mask &= (1 << ((start + size) & 0x1F)) - 1; + if (codemap[i] & mask) + { + k = 32; + for (b=0x80000000; b!=0; b>>=1, k--) + { + if (codemap[i] & b) + break; + } + start = (a & ~0x1F) + k; + } + if (start <= a) + break; + } + return start; +} + +static +Addr_T allocate_space(Addr_T start, Addr_T size, char* id) +{ + int i, j; + unsigned long mask; + Addr_T a = start; + i = start >> 5; + j = (start + size) >> 5; + mask = -(1 << (start & 0x1F)); + + while (i < j) + { + if (codemap[i] & mask) + { + fprintf(stderr, "memory overlap near 0x%X for %s\n", a, id); + } + codemap[i++] |= mask; + mask = 0xFFFFFFFF; + a += 32; + } + mask &= (1 << ((start + size) & 0x1F)) - 1; + if (codemap[i] & mask) + { + fprintf(stderr, "memory overlap near 0x%X for %s\n", a, id); + } + codemap[i] |= mask; + return start; +} + +Addr_T lnksect2 (struct area *tap, int rloc) { register Addr_T size, addr; register struct areax *taxp; int j, k, ramlimit; - char fchar, dchar='a'; + char fchar=' ', dchar='a'; char ErrMsg[]="?ASlink-Error-Could not get %d consecutive byte%s" " in internal RAM for area %s.\n"; @@ -644,7 +756,7 @@ void lnksect2 (struct area *tap, int rloc) taxp = tap->a_axp; /*Use a letter to identify each area in the internal RAM layout map*/ - if(rloc==0) + if (rloc==0) { /**/ if(!strcmp(tap->a_id, "DSEG")) fchar='D'; /*It will be converted to letters 'a' to 'z' later for each areax*/ @@ -669,9 +781,15 @@ void lnksect2 (struct area *tap, int rloc) else fchar=' ';/*???*/ } - else + else if (rloc==1) { - fchar=' '; + /**/ if(!strcmp(tap->a_id, "GSINIT")) + fchar='G'; + } + else if (rloc==2) + { + /**/ if(!strcmp(tap->a_id, "XSTK")) + fchar='K'; } if (tap->a_flag&A_OVR) /* Overlayed sections */ @@ -837,8 +955,25 @@ void lnksect2 (struct area *tap, int rloc) taxp = taxp->a_axp; } } + else if (tap->a_flag & A_ABS) /* Absolute sections */ + { + while (taxp) + { + if (rloc == 1) + { + allocate_space(taxp->a_addr, taxp->a_size, tap->a_id); + } + taxp->a_addr = 0; /* reset to zero so relative addresses become absolute */ + size += taxp->a_size; + taxp = taxp->a_axp; + } + } else /* Concatenated sections */ { + if ((rloc == 1) && tap->a_size) + { + addr = find_empty_space(addr, tap->a_size); + } while (taxp) { if( (fchar=='D') || (fchar=='I') ) @@ -897,35 +1032,15 @@ void lnksect2 (struct area *tap, int rloc) } else /*For concatenated BIT, CODE, and XRAM areax's*/ { - if(!strcmp(tap->a_id, "XSTK") && (taxp->a_size == 1)) + if((fchar=='K') && (taxp->a_size == 1)) { taxp->a_size = 256-(addr & 0xFF); } - //should find next unused address now!!! - //but let's first just warn for overlaps - if (rloc == 1) + //find next unused address now + if ((rloc == 1) && taxp->a_size) { - int a = addr; - int i = addr >> 5; - int j = (addr + taxp->a_size) >> 5; - long mask = -(1 << (addr & 0x1F)); - - while (i < j) - { - if (codemap[i] & mask) - { - fprintf(stderr, "memory overlap near 0x%X for %s\n", a, tap->a_id); - } - codemap[i++] |= mask; - mask = 0xFFFFFFFF; - a += 32; - } - mask &= (1 << ((addr + taxp->a_size) & 0x1F)) - 1; - if (codemap[i] & mask) - { - fprintf(stderr, "memory overlap near 0x%X for %s\n", a, tap->a_id); - } - codemap[i] |= mask; + addr = find_empty_space(addr, taxp->a_size); + allocate_space(addr, taxp->a_size, tap->a_id); } taxp->a_addr = addr; addr += taxp->a_size; @@ -949,4 +1064,5 @@ void lnksect2 (struct area *tap, int rloc) "\n?ASlink-Warning-Paged Area %8s Boundary Error\n", tap->a_id); lkerr++; } + return addr; } diff --git a/as/mcs51/lkhead.c b/as/mcs51/lkhead.c index 1cd390ab..41a5198c 100644 --- a/as/mcs51/lkhead.c +++ b/as/mcs51/lkhead.c @@ -107,7 +107,7 @@ newhead() * Setup Absolute DEF linkage. */ lkparea(_abs_); - ap->a_flag = A_ABS|A_OVR; + ap->a_flag = A_ABS; } /*)Function VOID module() diff --git a/as/mcs51/lklibr.c b/as/mcs51/lklibr.c index bb7218f8..e87c9ec3 100644 --- a/as/mcs51/lklibr.c +++ b/as/mcs51/lklibr.c @@ -24,22 +24,22 @@ #include #include "aslink.h" -/*)Module lklibr.c +/*)Module lklibr.c * - * The module lklibr.c contains the functions which - * (1) specify the path(s) to library files [.LIB] - * (2) specify the library file(s) [.LIB] to search - * (3) search the library files for specific symbols - * and link the module containing this symbol + * The module lklibr.c contains the functions which + * (1) specify the path(s) to library files [.LIB] + * (2) specify the library file(s) [.LIB] to search + * (3) search the library files for specific symbols + * and link the module containing this symbol * - * lklibr.c contains the following functions: - * VOID addpath() - * VOID addlib() - * VOID addfile() - * VOID search() - * VOID fndsym() - * VOID library() - * VOID loadfile() + * lklibr.c contains the following functions: + * VOID addpath() + * VOID addlib() + * VOID addfile() + * VOID search() + * VOID fndsym() + * VOID library() + * VOID loadfile() * */ @@ -48,21 +48,21 @@ typedef struct slibrarysymbol mlibrarysymbol; typedef struct slibrarysymbol *pmlibrarysymbol; struct slibrarysymbol { - char * name; /*Warning: allocate memory before using*/ - pmlibrarysymbol next; + char * name; /*Warning: allocate memory before using*/ + pmlibrarysymbol next; }; typedef struct slibraryfile mlibraryfile; typedef struct slibraryfile *pmlibraryfile; struct slibraryfile { - int loaded; - char * libspc; - char * relfil; /*Warning: allocate memory before using*/ - char * filename; /*Warning: allocate memory before using*/ + int loaded; + char * libspc; + char * relfil; /*Warning: allocate memory before using*/ + char * filename; /*Warning: allocate memory before using*/ long offset; //if > 0, the embedded file offset in the library file libspc - pmlibrarysymbol symbols; - pmlibraryfile next; + pmlibrarysymbol symbols; + pmlibraryfile next; }; /* First entry in the library object symbol cache */ @@ -72,94 +72,94 @@ int buildlibraryindex(); void freelibraryindex (void); #endif /* INDEXLIB */ -/*)Function VOID addpath() +/*)Function VOID addpath() * - * The function addpath() creates a linked structure containing - * the paths to various object module library files. + * The function addpath() creates a linked structure containing + * the paths to various object module library files. * - * local variables: - * lbpath *lbph pointer to new path structure - * lbpath *lbp temporary pointer + * local variables: + * lbpath *lbph pointer to new path structure + * lbpath *lbp temporary pointer * - * global variables: - * lbpath *lbphead The pointer to the first - * path structure + * global variables: + * lbpath *lbphead The pointer to the first + * path structure * - * functions called: - * char getnb() lklex.c - * VOID * new() lksym.c - * int strlen() c_library - * char * strcpy() c_library - * VOID unget() lklex.c + * functions called: + * char getnb() lklex.c + * VOID * new() lksym.c + * int strlen() c_library + * char * strcpy() c_library + * VOID unget() lklex.c * - * side effects: - * An lbpath structure may be created. + * side effects: + * An lbpath structure may be created. */ VOID addpath() { - struct lbpath *lbph, *lbp; - - lbph = (struct lbpath *) new (sizeof(struct lbpath)); - if (lbphead == NULL) { - lbphead = lbph; - } else { - lbp = lbphead; - while (lbp->next) - lbp = lbp->next; - lbp->next = lbph; - } - unget(getnb()); - lbph->path = (char *) new (strlen(ip)+1); - strcpy(lbph->path, ip); + struct lbpath *lbph, *lbp; + + lbph = (struct lbpath *) new (sizeof(struct lbpath)); + if (lbphead == NULL) { + lbphead = lbph; + } else { + lbp = lbphead; + while (lbp->next) + lbp = lbp->next; + lbp->next = lbph; + } + unget(getnb()); + lbph->path = (char *) new (strlen(ip)+1); + strcpy(lbph->path, ip); } -/*)Function VOID addlib() +/*)Function VOID addlib() * - * The function addlib() tests for the existance of a - * library path structure to determine the method of - * adding this library file to the library search structure. + * The function addlib() tests for the existance of a + * library path structure to determine the method of + * adding this library file to the library search structure. * - * This function calls the function addfile() to actually - * add the library file to the search list. + * This function calls the function addfile() to actually + * add the library file to the search list. * - * local variables: - * lbpath *lbph pointer to path structure + * local variables: + * lbpath *lbph pointer to path structure * - * global variables: - * lbpath *lbphead The pointer to the first - * path structure + * global variables: + * lbpath *lbphead The pointer to the first + * path structure * ip a pointer to the library name * - * functions called: - * VOID addfile() lklibr.c - * char getnb() lklex.c - * VOID unget() lklex.c + * functions called: + * VOID addfile() lklibr.c + * char getnb() lklex.c + * VOID unget() lklex.c * - * side effects: - * The function addfile() may add the file to - * the library search list. + * side effects: + * The function addfile() may add the file to + * the library search list. */ VOID addlib() { - struct lbpath *lbph; + struct lbpath *lbph; int foundcount=0; - unget(getnb()); + unget(getnb()); - if (lbphead == NULL) + if (lbphead == NULL) { - foundcount=addfile(NULL, ip); - } + foundcount=addfile(NULL, ip); + } else { - for (lbph=lbphead; lbph; lbph=lbph->next) + for (lbph=lbphead; lbph; lbph=lbph->next) { - foundcount+=addfile(lbph->path, ip); - } + foundcount+=addfile(lbph->path, ip); + } } if(foundcount == 0) { @@ -167,38 +167,38 @@ addlib() } } -/*)Function int addfile(path,libfil) +/*)Function int addfile(path,libfil) * - * char *path library path specification - * char *libfil library file specification + * char *path library path specification + * char *libfil library file specification * - * The function addfile() searches for the library file - * by concatenating the path and libfil specifications. - * if the library is found, an lbname structure is created - * and linked to any previously defined structures. This - * linked list is used by the function fndsym() to attempt - * to find any undefined symbols. + * The function addfile() searches for the library file + * by concatenating the path and libfil specifications. + * if the library is found, an lbname structure is created + * and linked to any previously defined structures. This + * linked list is used by the function fndsym() to attempt + * to find any undefined symbols. * - * The function does not give report an error on invalid - * path / file specifications or if the file is not found. + * The function does not give report an error on invalid + * path / file specifications or if the file is not found. * - * local variables: - * lbname *lbnh pointer to new name structure - * lbname *lbn temporary pointer + * local variables: + * lbname *lbnh pointer to new name structure + * lbname *lbn temporary pointer * - * global variables: - * lbname *lbnhead The pointer to the first - * path structure + * global variables: + * lbname *lbnhead The pointer to the first + * path structure * - * functions called: - * char getnb() lklex.c - * VOID * new() lksym.c - * int strlen() c_library - * char * strcpy() c_library - * VOID unget() lklex.c + * functions called: + * char getnb() lklex.c + * VOID * new() lksym.c + * int strlen() c_library + * char * strcpy() c_library + * VOID unget() lklex.c * - * side effects: - * An lbname structure may be created. + * side effects: + * An lbname structure may be created. * * return: * 1: the library was found @@ -207,55 +207,55 @@ addlib() int addfile(char * path, char * libfil) { - FILE *fp; - char *str; - struct lbname *lbnh, *lbn; -#ifdef OTHERSYSTEM + FILE *fp; + char *str; + struct lbname *lbnh, *lbn; +#ifdef OTHERSYSTEM int libfilinc=0; #endif - if (path != NULL) + if (path != NULL) { - str = (char *) new (strlen(path) + strlen(libfil) + 6); - strcpy(str,path); -#ifdef OTHERSYSTEM - if (str[strlen(str)-1] != '/') + str = (char *) new (strlen(path) + strlen(libfil) + 6); + strcpy(str,path); +#ifdef OTHERSYSTEM + if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\')) { - strcat(str,"/"); - } + strcat(str,"/"); + } #endif - } + } else { - str = (char *) new (strlen(libfil) + 5); - } + str = (char *) new (strlen(libfil) + 5); + } -#ifdef OTHERSYSTEM - if (libfil[0] == '/') +#ifdef OTHERSYSTEM + if ((libfil[0] == '/') || (libfil[0] == '\\')) { libfil++; libfilinc=1; } #endif - + strcat(str, libfil); - if(strchr(libfil, FSEPX) == NULL) + if(strchr(libfil, FSEPX) == NULL) { - sprintf(&str[strlen(str)], "%clib", FSEPX); - } + sprintf(&str[strlen(str)], "%clib", FSEPX); + } fp=fopen(str, "r"); if(fp == NULL) { /*Ok, that didn't work. Try with the 'libfil' name only*/ -#ifdef OTHERSYSTEM +#ifdef OTHERSYSTEM if(libfilinc) libfil--; #endif fp=fopen(libfil, "r"); - if(fp != NULL) + if(fp != NULL) { /*Bingo! 'libfil' is the absolute path of the library*/ - strcpy(str, libfil); + strcpy(str, libfil); path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/ } } @@ -271,7 +271,7 @@ int addfile(char * path, char * libfil) strcpy(path, str); for(j=strlen(path)-1; j>=0; j--) { - if((path[j]=='\\')||(path[j]=='/')) + if((path[j] == '/') || (path[j] == '\\')) { strcpy(libfil, &path[j+1]); path[j+1]=0; @@ -281,141 +281,141 @@ int addfile(char * path, char * libfil) if(j<=0) path[0]=0; } - if (fp != NULL) + if (fp != NULL) { - fclose(fp); - lbnh = (struct lbname *) new (sizeof(struct lbname)); - if (lbnhead == NULL) + fclose(fp); + lbnh = (struct lbname *) new (sizeof(struct lbname)); + if (lbnhead == NULL) { - lbnhead = lbnh; - } + lbnhead = lbnh; + } else { - lbn = lbnhead; - while (lbn->next) - lbn = lbn->next; - lbn->next = lbnh; - } - + lbn = lbnhead; + while (lbn->next) + lbn = lbn->next; + lbn->next = lbnh; + } + lbnh->path = path; - lbnh->libfil = (char *) new (strlen(libfil) + 1); - strcpy(lbnh->libfil,libfil); - lbnh->libspc = str; + lbnh->libfil = (char *) new (strlen(libfil) + 1); + strcpy(lbnh->libfil,libfil); + lbnh->libspc = str; return 1; - } - else + } + else { - free(str); + free(str); return 0; - } + } } -/*)Function VOID search() +/*)Function VOID search() * - * The function search() looks through all the symbol tables - * at the end of pass 1. If any undefined symbols are found - * then the function fndsym() is called. Function fndsym() - * searches any specified library files to automagically - * import the object modules containing the needed symbol. + * The function search() looks through all the symbol tables + * at the end of pass 1. If any undefined symbols are found + * then the function fndsym() is called. Function fndsym() + * searches any specified library files to automagically + * import the object modules containing the needed symbol. * - * After a symbol is found and imported by the function - * fndsym() the symbol tables are again searched. The - * symbol tables are search until no more symbols can be - * resolved within the library files. This ensures that - * back references from one library module to another are - * also resolved. + * After a symbol is found and imported by the function + * fndsym() the symbol tables are again searched. The + * symbol tables are search until no more symbols can be + * resolved within the library files. This ensures that + * back references from one library module to another are + * also resolved. * - * local variables: - * int i temporary counter - * sym *sp pointer to a symbol structure - * int symfnd found a symbol flag + * local variables: + * int i temporary counter + * sym *sp pointer to a symbol structure + * int symfnd found a symbol flag * - * global variables: - * sym *symhash[] array of pointers to symbol tables + * global variables: + * sym *symhash[] array of pointers to symbol tables * - * functions called: - * int fndsym() lklibr.c + * functions called: + * int fndsym() lklibr.c * - * side effects: - * If a symbol is found then the library object module - * containing the symbol will be imported and linked. + * side effects: + * If a symbol is found then the library object module + * containing the symbol will be imported and linked. */ VOID search() { - register struct sym *sp; - register int i,symfnd; - - /* - * Look for undefined symbols. Keep - * searching until no more symbols are resolved. - */ - symfnd = 1; - while (symfnd) { - symfnd = 0; - /* - * Look through all the symbols - */ - for (i=0; is_type & S_DEF) == 0) { - if (fndsym(sp->s_id)) { - symfnd++; - } - } - sp = sp->s_sp; - } - } - } + register struct sym *sp; + register int i,symfnd; + + /* + * Look for undefined symbols. Keep + * searching until no more symbols are resolved. + */ + symfnd = 1; + while (symfnd) { + symfnd = 0; + /* + * Look through all the symbols + */ + for (i=0; is_type & S_DEF) == 0) { + if (fndsym(sp->s_id)) { + symfnd++; + } + } + sp = sp->s_sp; + } + } + } } /*Load a .rel file embedded in a sdcclib file*/ void LoadRel(char * libfname, FILE * libfp, char * ModName) { - char str[NINPUT+2]; - int state=0; - - while (fgets(str, NINPUT, libfp) != NULL) - { - str[NINPUT+1] = '\0'; - chop_crlf(str); - switch(state) - { - case 0: - if(EQ(str, "")) - { - fgets(str, NINPUT, libfp); - str[NINPUT+1] = '\0'; - chop_crlf(str); - if(EQ(str, ModName)) state=1; - else - { - fprintf(stderr, "?Aslink-Error-Bad offset in library file %s(%s)\n", + char str[NINPUT+2]; + int state=0; + + while (fgets(str, NINPUT, libfp) != NULL) + { + str[NINPUT+1] = '\0'; + chop_crlf(str); + switch(state) + { + case 0: + if(EQ(str, "")) + { + fgets(str, NINPUT, libfp); + str[NINPUT+1] = '\0'; + chop_crlf(str); + if(EQ(str, ModName)) state=1; + else + { + fprintf(stderr, "?Aslink-Error-Bad offset in library file %s(%s)\n", libfname, ModName); - lkexit(1); - } - } - break; - case 1: - if(EQ(str, "")) state=2; - break; - case 2: - if(EQ(str, "")) return; - ip = str; - link_main(); - break; - } - } + lkexit(1); + } + } + break; + case 1: + if(EQ(str, "")) state=2; + break; + case 2: + if(EQ(str, "")) return; + ip = str; + link_main(); + break; + } + } } /*Load an .adb file embedded in a sdcclib file. If there is @@ -424,27 +424,27 @@ This way the aomf51 will not have uselless empty modules. */ int LoadAdb(FILE * libfp) { - char str[MAXLINE+1]; - int state=0; - int ToReturn=0; - - while (fgets(str, MAXLINE, libfp) != NULL) - { - str[NINPUT+1] = '\0'; - chop_crlf(str); - switch(state) - { - case 0: - if(EQ(str, "")) state=1; - break; - case 1: - if(EQ(str, "")) return ToReturn; - fprintf(dfp, "%s\n", str); - ToReturn=1; - break; - } - } - return ToReturn; + char str[MAXLINE+1]; + int state=0; + int ToReturn=0; + + while (fgets(str, MAXLINE, libfp) != NULL) + { + str[NINPUT+1] = '\0'; + chop_crlf(str); + switch(state) + { + case 0: + if(EQ(str, "")) state=1; + break; + case 1: + if(EQ(str, "")) return ToReturn; + fprintf(dfp, "%s\n", str); + ToReturn=1; + break; + } + } + return ToReturn; } /*Check for a symbol in a SDCC library. If found, add the embedded .rel and @@ -454,13 +454,13 @@ embedded in the library file.*/ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) { - struct lbfile *lbfh, *lbf; - char ModName[NCPS]=""; - char FLine[MAXLINE+1]; - int state=0; - long IndexOffset=0, FileOffset; + struct lbfile *lbfh, *lbf; + char ModName[NCPS]=""; + char FLine[MAXLINE+1]; + int state=0; + long IndexOffset=0, FileOffset; - while(!feof(libfp)) + while(!feof(libfp)) { FLine[0]=0; fgets(FLine, MAXLINE, libfp); @@ -471,220 +471,220 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) case 0: if(EQ(FLine, "")) { - /*The next line has the size of the index*/ + /*The next line has the size of the index*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - IndexOffset=atol(FLine); - state=1; + IndexOffset=atol(FLine); + state=1; } break; case 1: if(EQ(FLine, "")) - { - /*The next line has the name of the module and the offset - of the corresponding embedded file in the library*/ + { + /*The next line has the name of the module and the offset + of the corresponding embedded file in the library*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - sscanf(FLine, "%s %ld", ModName, &FileOffset); - state=2; - } + sscanf(FLine, "%s %ld", ModName, &FileOffset); + state=2; + } else if(EQ(FLine, "")) - { - /*Reached the end of the index. The symbol is not in this library.*/ - return 0; - } + { + /*Reached the end of the index. The symbol is not in this library.*/ + return 0; + } break; case 2: if(EQ(FLine, "")) - { - /*The symbol is not in this module, try the next one*/ + { + /*The symbol is not in this module, try the next one*/ state=1; - } + } else - { - /*Check if this is the symbol we are looking for.*/ - if (strncmp(SymName, FLine, NCPS)==0) - { - /*The symbol is in this module.*/ - - /*As in the original library format, it is assumed that the .rel - files reside in the same directory as the lib files.*/ - strcat(DirLib, ModName); - sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX); - - /*If this module has been loaded already don't load it again.*/ - lbf = lbfhead; - while (lbf) - { - if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/ - lbf=lbf->next; - } - - /*Add the embedded file to the list of files to be loaded in - the second pass. That is performed latter by the function - library() below.*/ - lbfh = (struct lbfile *) new (sizeof(struct lbfile)); - if (lbfhead == NULL) - { - lbfhead = lbfh; - } - else - { - lbf = lbfhead; - while (lbf->next) - lbf = lbf->next; - lbf->next = lbfh; - } - - lbfh->libspc = PathLib; - lbfh->filspc = DirLib; - lbfh->relfil = (char *) new (strlen(ModName) + 1); - strcpy(lbfh->relfil, ModName); - /*Library embedded file, so lbfh->offset must be >=0*/ - lbfh->offset = IndexOffset+FileOffset; - - /*Jump to where the .rel begins and load it.*/ - fseek(libfp, lbfh->offset, SEEK_SET); - LoadRel(PathLib, libfp, ModName); - - /* if cdb information required & .adb file present */ - if (dflag && dfp) - { - if(LoadAdb(libfp)) - SaveLinkedFilePath(DirLib); - } - return 1; /*Found the symbol, so success!*/ - } - } + { + /*Check if this is the symbol we are looking for.*/ + if (strncmp(SymName, FLine, NCPS)==0) + { + /*The symbol is in this module.*/ + + /*As in the original library format, it is assumed that the .rel + files reside in the same directory as the lib files.*/ + strcat(DirLib, ModName); + sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX); + + /*If this module has been loaded already don't load it again.*/ + lbf = lbfhead; + while (lbf) + { + if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/ + lbf=lbf->next; + } + + /*Add the embedded file to the list of files to be loaded in + the second pass. That is performed latter by the function + library() below.*/ + lbfh = (struct lbfile *) new (sizeof(struct lbfile)); + if (lbfhead == NULL) + { + lbfhead = lbfh; + } + else + { + lbf = lbfhead; + while (lbf->next) + lbf = lbf->next; + lbf->next = lbfh; + } + + lbfh->libspc = PathLib; + lbfh->filspc = DirLib; + lbfh->relfil = (char *) new (strlen(ModName) + 1); + strcpy(lbfh->relfil, ModName); + /*Library embedded file, so lbfh->offset must be >=0*/ + lbfh->offset = IndexOffset+FileOffset; + + /*Jump to where the .rel begins and load it.*/ + fseek(libfp, lbfh->offset, SEEK_SET); + LoadRel(PathLib, libfp, ModName); + + /* if cdb information required & .adb file present */ + if (dflag && dfp) + { + if(LoadAdb(libfp)) + SaveLinkedFilePath(DirLib); + } + return 1; /*Found the symbol, so success!*/ + } + } + break; + + default: + return 0; /*It should never reach this point, but just in case...*/ break; - - default: - return 0; /*It should never reach this point, but just in case...*/ - break; } } - return 0; /*The symbol is not in this library*/ + return 0; /*The symbol is not in this library*/ } -/*)Function VOID fndsym(name) +/*)Function VOID fndsym(name) * - * char *name symbol name to find + * char *name symbol name to find * - * The function fndsym() searches through all combinations of the - * library path specifications (input by the -k option) and the - * library file specifications (input by the -l option) that - * lead to an existing file. + * The function fndsym() searches through all combinations of the + * library path specifications (input by the -k option) and the + * library file specifications (input by the -l option) that + * lead to an existing file. * - * The file specicifation may be formed in one of two ways: + * The file specicifation may be formed in one of two ways: * - * (1) If the library file contained an absolute - * path/file specification then this becomes filspc. - * (i.e. C:\...) + * (1) If the library file contained an absolute + * path/file specification then this becomes filspc. + * (i.e. C:\...) * - * (2) If the library file contains a relative path/file - * specification then the concatenation of the path - * and this file specification becomes filspc. - * (i.e. \...) + * (2) If the library file contains a relative path/file + * specification then the concatenation of the path + * and this file specification becomes filspc. + * (i.e. \...) * - * The structure lbfile is created for the first library - * object file which contains the definition for the - * specified undefined symbol. + * The structure lbfile is created for the first library + * object file which contains the definition for the + * specified undefined symbol. * - * If the library file [.LIB] contains file specifications for - * non existant files, no errors are returned. + * If the library file [.LIB] contains file specifications for + * non existant files, no errors are returned. * - * local variables: - * char buf[] [.REL] file input line - * char c [.REL] file input character - * FILE *fp file handle for object file - * lbfile *lbf temporary pointer - * lbfile *lbfh pointer to lbfile structure - * FILE *libfp file handle for library file - * lbname *lbnh pointer to lbname structure - * char *path file specification path - * char relfil[] [.REL] file specification - * char *str combined path and file specification - * char symname[] [.REL] file symbol string + * local variables: + * char buf[] [.REL] file input line + * char c [.REL] file input character + * FILE *fp file handle for object file + * lbfile *lbf temporary pointer + * lbfile *lbfh pointer to lbfile structure + * FILE *libfp file handle for library file + * lbname *lbnh pointer to lbname structure + * char *path file specification path + * char relfil[] [.REL] file specification + * char *str combined path and file specification + * char symname[] [.REL] file symbol string * - * global variables: - * lbname *lbnhead The pointer to the first - * name structure - * lbfile *lbfhead The pointer to the first - * file structure + * global variables: + * lbname *lbnhead The pointer to the first + * name structure + * lbfile *lbfhead The pointer to the first + * file structure * - * functions called: - * int fclose() c_library - * int fgets() c_library - * FILE *fopen() c_library - * VOID free() c_library - * char getnb() lklex.c - * VOID lkexit() lkmain.c - * VOID loadfile() lklibr.c - * VOID * new() lksym.c - * char * sprintf() c_library - * int sscanf() c_library - * char * strcat() c_library - * char * strchr() c_library - * char * strcpy() c_library - * int strlen() c_library - * int strncmp() c_library - * VOID unget() lklex.c + * functions called: + * int fclose() c_library + * int fgets() c_library + * FILE *fopen() c_library + * VOID free() c_library + * char getnb() lklex.c + * VOID lkexit() lkmain.c + * VOID loadfile() lklibr.c + * VOID * new() lksym.c + * char * sprintf() c_library + * int sscanf() c_library + * char * strcat() c_library + * char * strchr() c_library + * char * strcpy() c_library + * int strlen() c_library + * int strncmp() c_library + * VOID unget() lklex.c * - * side effects: - * If the symbol is found then a new lbfile structure - * is created and added to the linked list of lbfile - * structures. The file containing the found symbol - * is linked. + * side effects: + * If the symbol is found then a new lbfile structure + * is created and added to the linked list of lbfile + * structures. The file containing the found symbol + * is linked. */ #ifdef INDEXLIB int fndsym( char *name ) { - struct lbfile *lbfh, *lbf; - pmlibraryfile ThisLibr; - pmlibrarysymbol ThisSym = NULL; + struct lbfile *lbfh, *lbf; + pmlibraryfile ThisLibr; + pmlibrarysymbol ThisSym = NULL; pmlibraryfile FirstFound; int numfound=0; - /* Build the index if this is the first call to fndsym */ - if (libr==NULL) buildlibraryindex(); - - /* Iterate through all library object files */ - ThisLibr = libr; + /* Build the index if this is the first call to fndsym */ + if (libr==NULL) buildlibraryindex(); + + /* Iterate through all library object files */ + ThisLibr = libr; FirstFound = libr; /*So gcc stops whining*/ - while (ThisLibr) + while (ThisLibr) { - /* Iterate through all symbols in an object file */ - ThisSym = ThisLibr->symbols; + /* Iterate through all symbols in an object file */ + ThisSym = ThisLibr->symbols; - while (ThisSym) + while (ThisSym) { - if (!strcmp(ThisSym->name, name)) + if (!strcmp(ThisSym->name, name)) { - if ((!ThisLibr->loaded) && (numfound==0)) + if ((!ThisLibr->loaded) && (numfound==0)) { - /* Object file is not loaded - add it to the list */ - lbfh = (struct lbfile *) new (sizeof(struct lbfile)); - if (lbfhead == NULL) + /* Object file is not loaded - add it to the list */ + lbfh = (struct lbfile *) new (sizeof(struct lbfile)); + if (lbfhead == NULL) { - lbfhead = lbfh; - } + lbfhead = lbfh; + } else { - lbf = lbfhead; - while (lbf->next) - lbf = lbf->next; - lbf->next = lbfh; - } - lbfh->libspc = ThisLibr->libspc; - lbfh->filspc = ThisLibr->filename; - lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1); - strcpy(lbfh->relfil, ThisLibr->relfil); + lbf = lbfhead; + while (lbf->next) + lbf = lbf->next; + lbf->next = lbfh; + } + lbfh->libspc = ThisLibr->libspc; + lbfh->filspc = ThisLibr->filename; + lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1); + strcpy(lbfh->relfil, ThisLibr->relfil); lbfh->offset = ThisLibr->offset; if(lbfh->offset>0) { /*For an embedded object file in a library*/ @@ -693,21 +693,21 @@ int fndsym( char *name ) } else { /*For a stand alone object file*/ - /* if cdb information required & adb file present */ - if (dflag && dfp) - { - FILE *xfp = afile(lbfh->filspc, "adb",0); - if (xfp) - { - SaveLinkedFilePath(lbfh->filspc); - copyfile(dfp, xfp); - fclose(xfp); - } - } + /* if cdb information required & adb file present */ + if (dflag && dfp) + { + FILE *xfp = afile(lbfh->filspc, "adb",0); + if (xfp) + { + SaveLinkedFilePath(lbfh->filspc); + copyfile(dfp, xfp); + fclose(xfp); + } + } loadfile(lbfh->filspc); } - ThisLibr->loaded=1; - } + ThisLibr->loaded=1; + } if(numfound==0) { @@ -743,24 +743,24 @@ int fndsym( char *name ) numfound++; } } - } - ThisSym=ThisSym->next; /* Next sym in library */ - } - ThisLibr=ThisLibr->next; /* Next library in list */ - } - return numfound; + } + ThisSym=ThisSym->next; /* Next sym in library */ + } + ThisLibr=ThisLibr->next; /* Next library in list */ + } + return numfound; } pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This) { - char ModName[NCPS]=""; - char FLine[MAXLINE+1]; + char ModName[NCPS]=""; + char FLine[MAXLINE+1]; char buff[PATH_MAX]; - int state=0; - long IndexOffset=0, FileOffset; + int state=0; + long IndexOffset=0, FileOffset; pmlibrarysymbol ThisSym = NULL; - while(!feof(libfp)) + while(!feof(libfp)) { FLine[0]=0; fgets(FLine, MAXLINE, libfp); @@ -771,24 +771,24 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir case 0: if(EQ(FLine, "")) { - /*The next line has the size of the index*/ + /*The next line has the size of the index*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - IndexOffset=atol(FLine); - state=1; + IndexOffset=atol(FLine); + state=1; } break; case 1: if(EQ(FLine, "")) - { - /*The next line has the name of the module and the offset - of the corresponding embedded file in the library*/ + { + /*The next line has the name of the module and the offset + of the corresponding embedded file in the library*/ FLine[0]=0; fgets(FLine, MAXLINE, libfp); chop_crlf(FLine); - sscanf(FLine, "%s %ld", ModName, &FileOffset); - state=2; + sscanf(FLine, "%s %ld", ModName, &FileOffset); + state=2; /*Create a new libraryfile object for this module*/ if(libr==NULL) @@ -797,95 +797,95 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir } else { - This->next=(pmlibraryfile)new( sizeof( mlibraryfile )); - This=This->next; + This->next=(pmlibraryfile)new( sizeof( mlibraryfile )); + This=This->next; } - This->next = NULL; - This->loaded=-1; + This->next = NULL; + This->loaded=-1; This->offset=FileOffset+IndexOffset; - This->libspc=PathLib; - + This->libspc=PathLib; + This->relfil=(char *)new(strlen(ModName)+1); - strcpy(This->relfil, ModName); - + strcpy(This->relfil, ModName); + sprintf(buff, "%s%s%crel", DirLib, ModName, FSEPX); This->filename=(char *)new(strlen(buff)+1); strcpy(This->filename, buff); - + This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/ - } + } else if(EQ(FLine, "")) - { - return This; /*Finish, get out of here*/ - } + { + return This; /*Finish, get out of here*/ + } break; case 2: if(EQ(FLine, "")) - { - This->loaded=0; - /*Create the index for the next module*/ + { + This->loaded=0; + /*Create the index for the next module*/ state=1; - } + } else - { - /*Add the symbols*/ + { + /*Add the symbols*/ if(ThisSym==NULL) /*First symbol of the current module*/ { - ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); + ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); } else { - ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol)); - ThisSym=ThisSym->next; + ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol)); + ThisSym=ThisSym->next; } - ThisSym->next=NULL; + ThisSym->next=NULL; ThisSym->name=(char *)new(strlen(FLine)+1); - strcpy(ThisSym->name, FLine); + strcpy(ThisSym->name, FLine); } break; - - default: - return This; /*State machine should never reach this point, but just in case...*/ - break; + + default: + return This; /*State machine should never reach this point, but just in case...*/ + break; } } - return This; /*State machine should never reach this point, but just in case...*/ + return This; /*State machine should never reach this point, but just in case...*/ } /* buildlibraryindex - build an in-memory cache of the symbols contained in - * the libraries + * the libraries */ int buildlibraryindex(void) { - FILE *libfp, *fp; - struct lbname *lbnh; - char relfil[NINPUT+2], str[PATH_MAX], *path; - char buf[NINPUT+2], c; - char symname[NINPUT+2]; - pmlibraryfile This=NULL; - pmlibrarysymbol ThisSym; - - /* - * Search through every library in the linked list "lbnhead". - */ + FILE *libfp, *fp; + struct lbname *lbnh; + char relfil[NINPUT+2], str[PATH_MAX], *path; + char buf[NINPUT+2], c; + char symname[NINPUT+2]; + pmlibraryfile This=NULL; + pmlibrarysymbol ThisSym; + + /* + * Search through every library in the linked list "lbnhead". + */ for (lbnh=lbnhead; lbnh; lbnh=lbnh->next) { - if ((libfp = fopen(lbnh->libspc, "r")) == NULL) - { - fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n", - lbnh->libspc); - lkexit(1); - } - path = lbnh->path; - - /* - * Read in a line from the library file. - * This is the relative file specification - * for a .REL file in this library. - */ + if ((libfp = fopen(lbnh->libspc, "r")) == NULL) + { + fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n", + lbnh->libspc); + lkexit(1); + } + path = lbnh->path; + + /* + * Read in a line from the library file. + * This is the relative file specification + * for a .REL file in this library. + */ while (fgets(relfil, NINPUT, libfp) != NULL) { @@ -893,42 +893,42 @@ int buildlibraryindex(void) chop_crlf(relfil); if (path != NULL) { - strcpy(str, path); -#ifdef OTHERSYSTEM - if (str[strlen(str)-1] != '/') - { - strcat(str,"/"); - } + strcpy(str, path); +#ifdef OTHERSYSTEM + if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\')) + { + strcat(str,"/"); + } #endif - } + } else { strcpy(str, ""); - } + } if(strcmp(relfil, "")==0) - { + { /*Get the built in index of this library*/ - This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This); - break; /*get the index for next library*/ - } - + This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This); + break; /*get the index for next library*/ + } + /*From here down, build the index for the original library format*/ - if (relfil[0] == '\\') + if (relfil[0] == '\\') { - strcat(str,relfil+1); - } + strcat(str,relfil+1); + } else { - strcat(str,relfil); - } + strcat(str,relfil); + } if(strchr(relfil, FSEPX) == NULL) { - sprintf(&str[strlen(str)], "%crel", FSEPX); - } - + sprintf(&str[strlen(str)], "%crel", FSEPX); + } + if ((fp = fopen(str, "r")) != NULL) { /* Opened OK - create a new libraryfile object for it */ @@ -938,92 +938,92 @@ int buildlibraryindex(void) } else { - This->next=(pmlibraryfile)new( sizeof( mlibraryfile )); - This=This->next; + This->next=(pmlibraryfile)new( sizeof( mlibraryfile )); + This=This->next; } - This->next = NULL; - This->loaded=-1; + This->next = NULL; + This->loaded=-1; This->offset=-1; /*We have a stand alone .rel file*/ - This->libspc = lbnh->libspc; - + This->libspc = lbnh->libspc; + This->relfil=(char *)new(strlen(relfil)+1); - strcpy(This->relfil, relfil); - + strcpy(This->relfil, relfil); + This->filename=(char *)new(strlen(str)+1); - strcpy(This->filename, str); + strcpy(This->filename, str); /*Start a new linked list of symbols for this module:*/ This->symbols=ThisSym=NULL; - /* - * Read in the object file. Look for lines that - * begin with "S" and end with "D". These are - * symbol table definitions. If we find one, see - * if it is our symbol. Make sure we only read in - * our object file and don't go into the next one. - */ - - while (fgets(buf, NINPUT, fp) != NULL) + /* + * Read in the object file. Look for lines that + * begin with "S" and end with "D". These are + * symbol table definitions. If we find one, see + * if it is our symbol. Make sure we only read in + * our object file and don't go into the next one. + */ + + while (fgets(buf, NINPUT, fp) != NULL) { - buf[NINPUT+1] = '\0'; - buf[strlen(buf) - 1] = '\0'; + buf[NINPUT+1] = '\0'; + buf[strlen(buf) - 1] = '\0'; - /* - * Skip everything that's not a symbol record. - */ - if (buf[0] != 'S') continue; + /* + * Skip everything that's not a symbol record. + */ + if (buf[0] != 'S') continue; - /* - * When a 'T line' is found terminate file scan. - * All 'S line's preceed 'T line's in .REL files. - */ - if (buf[0] == 'T') break; + /* + * When a 'T line' is found terminate file scan. + * All 'S line's preceed 'T line's in .REL files. + */ + if (buf[0] == 'T') break; - sscanf(buf, "S %s %c", symname, &c); + sscanf(buf, "S %s %c", symname, &c); - /* If it's an actual symbol, record it */ - if (c == 'D') + /* If it's an actual symbol, record it */ + if (c == 'D') { if(ThisSym==NULL) { - ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); + ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); } else { - ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); - ThisSym=ThisSym->next; + ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol)); + ThisSym=ThisSym->next; } - This->loaded=0; - ThisSym->next=NULL; + This->loaded=0; + ThisSym->next=NULL; ThisSym->name=(char *)new(strlen(symname)+1); - strcpy(ThisSym->name, symname); - } - } /* Closes while - read object file */ - fclose(fp); - } /* Closes if object file opened OK */ + strcpy(ThisSym->name, symname); + } + } /* Closes while - read object file */ + fclose(fp); + } /* Closes if object file opened OK */ else { - fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str); + fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str); } - } /* Ends while - processing all in libr */ - fclose(libfp); - } /* Ends good open of libr file */ - return 0; + } /* Ends while - processing all in libr */ + fclose(libfp); + } /* Ends good open of libr file */ + return 0; } /*Release all memory allocated for the in-memory library index*/ void freelibraryindex (void) { - pmlibraryfile ThisLibr, ThisLibr2Free; - pmlibrarysymbol ThisSym, ThisSym2Free; + pmlibraryfile ThisLibr, ThisLibr2Free; + pmlibrarysymbol ThisSym, ThisSym2Free; - ThisLibr = libr; + ThisLibr = libr; while (ThisLibr) { - ThisSym = ThisLibr->symbols; + ThisSym = ThisLibr->symbols; - while (ThisSym) + while (ThisSym) { free(ThisSym->name); ThisSym2Free=ThisSym; @@ -1036,7 +1036,7 @@ void freelibraryindex (void) ThisLibr=ThisLibr->next; free(ThisLibr2Free); } - + libr=NULL; } @@ -1046,257 +1046,256 @@ int fndsym(name) char *name; { - FILE *libfp, *fp; - struct lbname *lbnh; - struct lbfile *lbfh, *lbf; - char relfil[NINPUT+2]; - char buf[NINPUT+2]; - char symname[NINPUT]; - char *path,*str; - char c; - int result; - - /* - * Search through every library in the linked list "lbnhead". - */ - - for (lbnh=lbnhead; lbnh; lbnh=lbnh->next) - { - if ((libfp = fopen(lbnh->libspc, "r")) == NULL) - { - fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n", - lbnh->libspc); - lkexit(1); - } - path = lbnh->path; - - /* - * Read in a line from the library file. - * This is the relative file specification - * for a .REL file in this library. - */ - - while (fgets(relfil, NINPUT, libfp) != NULL) - { - relfil[NINPUT+1] = '\0'; - chop_crlf(relfil); - if (path != NULL) - { - str = (char *) new (strlen(path)+strlen(relfil)+6); - strcpy(str,path); -#ifdef OTHERSYSTEM - if (str[strlen(str)-1] != '/') - { - strcat(str,"/"); - } + FILE *libfp, *fp; + struct lbname *lbnh; + struct lbfile *lbfh, *lbf; + char relfil[NINPUT+2]; + char buf[NINPUT+2]; + char symname[NINPUT]; + char *path,*str; + char c; + int result; + + /* + * Search through every library in the linked list "lbnhead". + */ + + for (lbnh=lbnhead; lbnh; lbnh=lbnh->next) + { + if ((libfp = fopen(lbnh->libspc, "r")) == NULL) + { + fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n", + lbnh->libspc); + lkexit(1); + } + path = lbnh->path; + + /* + * Read in a line from the library file. + * This is the relative file specification + * for a .REL file in this library. + */ + + while (fgets(relfil, NINPUT, libfp) != NULL) + { + relfil[NINPUT+1] = '\0'; + chop_crlf(relfil); + if (path != NULL) + { + str = (char *) new (strlen(path)+strlen(relfil)+6); + strcpy(str,path); +#ifdef OTHERSYSTEM + if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\')) + { + strcat(str,"/"); + } #endif - } - else - { - str = (char *) new (strlen(relfil) + 5); - } - - if(strcmp(relfil, "")==0) - { - result=SdccLib(lbnh->libspc, libfp, str, name); - if(result) return(1); /*Found the symbol*/ - free(str); - /*The symbol is not in the current library, - check the next library in the list*/ - break; - } - - /*From here down is the support for libraries in the original format*/ - if (relfil[0] == '\\') - { - strcat(str,relfil+1); - } - else - { - strcat(str,relfil); - } - - if(strchr(relfil, FSEPX) == NULL) - { - sprintf(&str[strlen(str)], "%crel", FSEPX); - } - - if ((fp = fopen(str, "r")) != NULL) - { - - /* - * Read in the object file. Look for lines that - * begin with "S" and end with "D". These are - * symbol table definitions. If we find one, see - * if it is our symbol. Make sure we only read in - * our object file and don't go into the next one. - */ - - while (fgets(buf, NINPUT, fp) != NULL) - { - buf[NINPUT+1] = '\0'; - chop_crlf(buf); - /* - * Skip everything that's not a symbol record. - */ - if (buf[0] != 'S') continue; - - /* - * When a 'T line' is found terminate file scan. - * All 'S line's preceed 'T line's in .REL files. - */ - if (buf[0] == 'T') break; - - sscanf(buf, "S %s %c", symname, &c); - - /* - * If we find a symbol definition for the - * symbol we're looking for, load in the - * file and add it to lbfhead so it gets - * loaded on pass number 2. - */ - if (strncmp(symname, name, NCPS) == 0 && c == 'D') - { - lbfh = (struct lbfile *) new (sizeof(struct lbfile)); - if (lbfhead == NULL) - { - lbfhead = lbfh; - } - else - { - lbf = lbfhead; - while (lbf->next) - lbf = lbf->next; - lbf->next = lbfh; - } - - lbfh->libspc = lbnh->libspc; - lbfh->filspc = str; - lbfh->relfil = (char *) new (strlen(relfil) + 1); - lbfh->offset = -1; /*Stand alone rel file*/ - strcpy(lbfh->relfil,relfil); - fclose(fp); - fclose(libfp); - - /* if cdb information required & adb file present */ - if (dflag && dfp) - { - FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002 - if (xfp) - { - SaveLinkedFilePath(str); - copyfile(dfp,xfp); - fclose(xfp); - } - } - loadfile(str); - return (1); - } - } - fclose(fp); - } - free(str); - } - fclose(libfp); - } - return(0); + } + else + { + str = (char *) new (strlen(relfil) + 5); + } + + if(strcmp(relfil, "")==0) + { + result=SdccLib(lbnh->libspc, libfp, str, name); + if(result) return(1); /*Found the symbol*/ + free(str); + /*The symbol is not in the current library, + check the next library in the list*/ + break; + } + + /*From here down is the support for libraries in the original format*/ + if (relfil[0] == '\\') + { + strcat(str,relfil+1); + } + else + { + strcat(str,relfil); + } + + if(strchr(relfil, FSEPX) == NULL) + { + sprintf(&str[strlen(str)], "%crel", FSEPX); + } + + if ((fp = fopen(str, "r")) != NULL) + { + + /* + * Read in the object file. Look for lines that + * begin with "S" and end with "D". These are + * symbol table definitions. If we find one, see + * if it is our symbol. Make sure we only read in + * our object file and don't go into the next one. + */ + + while (fgets(buf, NINPUT, fp) != NULL) + { + buf[NINPUT+1] = '\0'; + chop_crlf(buf); + /* + * Skip everything that's not a symbol record. + */ + if (buf[0] != 'S') continue; + + /* + * When a 'T line' is found terminate file scan. + * All 'S line's preceed 'T line's in .REL files. + */ + if (buf[0] == 'T') break; + + sscanf(buf, "S %s %c", symname, &c); + + /* + * If we find a symbol definition for the + * symbol we're looking for, load in the + * file and add it to lbfhead so it gets + * loaded on pass number 2. + */ + if (strncmp(symname, name, NCPS) == 0 && c == 'D') + { + lbfh = (struct lbfile *) new (sizeof(struct lbfile)); + if (lbfhead == NULL) + { + lbfhead = lbfh; + } + else + { + lbf = lbfhead; + while (lbf->next) + lbf = lbf->next; + lbf->next = lbfh; + } + + lbfh->libspc = lbnh->libspc; + lbfh->filspc = str; + lbfh->relfil = (char *) new (strlen(relfil) + 1); + lbfh->offset = -1; /*Stand alone rel file*/ + strcpy(lbfh->relfil,relfil); + fclose(fp); + fclose(libfp); + + /* if cdb information required & adb file present */ + if (dflag && dfp) + { + FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002 + if (xfp) + { + SaveLinkedFilePath(str); + copyfile(dfp,xfp); + fclose(xfp); + } + } + loadfile(str); + return (1); + } + } + fclose(fp); + } + free(str); + } + fclose(libfp); + } + return(0); } #endif /*INDEXLIB*/ void loadfile_SdccLib(char * libspc, char * module, long offset) { - FILE *fp; - - if ((fp = fopen(libspc,"r")) != NULL) - { - fseek(fp, offset, SEEK_SET); - LoadRel(libspc, fp, module); - fclose(fp); - } + FILE *fp; + + if ((fp = fopen(libspc,"r")) != NULL) + { + fseek(fp, offset, SEEK_SET); + LoadRel(libspc, fp, module); + fclose(fp); + } } -/*)Function VOID library() +/*)Function VOID library() * - * The function library() links all the library object files - * contained in the lbfile structures. + * The function library() links all the library object files + * contained in the lbfile structures. * - * local variables: - * lbfile *lbfh pointer to lbfile structure + * local variables: + * lbfile *lbfh pointer to lbfile structure * - * global variables: - * lbfile *lbfhead pointer to first lbfile structure + * global variables: + * lbfile *lbfhead pointer to first lbfile structure * - * functions called: - * VOID loadfile lklibr.c + * functions called: + * VOID loadfile lklibr.c * - * side effects: - * Links all files contained in the lbfile structures. + * side effects: + * Links all files contained in the lbfile structures. */ VOID library() { - struct lbfile *lbfh; - - for (lbfh=lbfhead; lbfh; lbfh=lbfh->next) - { - if(lbfh->offset<0) - { - /*Stand alone rel file (original lib format)*/ - loadfile(lbfh->filspc); - } - else - { - /*rel file embedded in lib (new lib format)*/ - loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset); - } - } + struct lbfile *lbfh; + + for (lbfh=lbfhead; lbfh; lbfh=lbfh->next) + { + if(lbfh->offset<0) + { + /*Stand alone rel file (original lib format)*/ + loadfile(lbfh->filspc); + } + else + { + /*rel file embedded in lib (new lib format)*/ + loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset); + } + } #ifdef INDEXLIB freelibraryindex(); #endif } -/*)Function VOID loadfile(filspc) +/*)Function VOID loadfile(filspc) * - * char *filspc library object file specification + * char *filspc library object file specification * - * The function loadfile() links the library object module. + * The function loadfile() links the library object module. * - * local variables: - * FILE *fp file handle - * int i input line length - * char str[] file input line + * local variables: + * FILE *fp file handle + * int i input line length + * char str[] file input line * - * global variables: - * char *ip pointer to linker input string + * global variables: + * char *ip pointer to linker input string * - * functions called: - * int fclose() c_library - * int fgets() c_library - * FILE * fopen() c_library - * VOID link_main() lkmain.c - * int strlen() c_library + * functions called: + * int fclose() c_library + * int fgets() c_library + * FILE * fopen() c_library + * VOID link_main() lkmain.c + * int strlen() c_library * - * side effects: - * If file exists it is linked. + * side effects: + * If file exists it is linked. */ VOID loadfile(filspc) char *filspc; { - FILE *fp; - char str[NINPUT+2]; - - if ((fp = fopen(filspc,"r")) != NULL) { - while (fgets(str, NINPUT, fp) != NULL) { - str[NINPUT+1] = '\0'; - chop_crlf(str); - ip = str; - link_main(); - } - fclose(fp); - } + FILE *fp; + char str[NINPUT+2]; + + if ((fp = fopen(filspc,"r")) != NULL) { + while (fgets(str, NINPUT, fp) != NULL) { + str[NINPUT+1] = '\0'; + chop_crlf(str); + ip = str; + link_main(); + } + fclose(fp); + } } - diff --git a/as/z80/z80pst.c b/as/z80/z80pst.c index 74044865..5915e992 100644 --- a/as/z80/z80pst.c +++ b/as/z80/z80pst.c @@ -27,7 +27,7 @@ struct mne mne[] = { { NULL, "CON", S_ATYP, 0, A_CON }, { NULL, "OVR", S_ATYP, 0, A_OVR }, { NULL, "REL", S_ATYP, 0, A_REL }, - { NULL, "ABS", S_ATYP, 0, A_ABS|A_OVR }, + { NULL, "ABS", S_ATYP, 0, A_ABS }, { NULL, "NOPAG", S_ATYP, 0, A_NOPAG }, { NULL, "PAG", S_ATYP, 0, A_PAG }, @@ -56,7 +56,7 @@ struct mne mne[] = { { NULL, ".org", S_ORG, 0, 0 }, { NULL, ".module", S_MODUL, 0, 0 }, { NULL, ".ascis", S_ASCIS, 0, 0 }, - { NULL, ".optsdcc", S_OPTSDCC, 0, 0}, + { NULL, ".optsdcc", S_OPTSDCC, 0, 0 }, /* z80 / hd64180 */ diff --git a/device/include/mcs51/c8051f200.h b/device/include/mcs51/c8051f200.h index 9491b7f5..ddd5c5e5 100644 --- a/device/include/mcs51/c8051f200.h +++ b/device/include/mcs51/c8051f200.h @@ -53,6 +53,7 @@ __sfr __at (0xA8) IE ; /* Interrupt Enable __sfr __at (0xAD) SWCINT ; /* SOFTWARE-Controlled Interrupt FLAGS */ __sfr __at (0xAD) PRT1IF ; /* SOFTWARE-Controlled Interrupt FLAGS (LEGACY NAME) */ __sfr __at (0xAF) EMI0CN ; /* EXTERNAL MEMORY INTERFACE Control (F206/F226/F236)*/ +__sfr __at (0xAF) _XPAGE ; /* XDATA/PDATA PAGE */ __sfr __at (0xB0) P3 ; /* PORT 3 */ __sfr __at (0xB1) OSCXCN ; /* EXTERNAL OSCILLATOR Control */ __sfr __at (0xB2) OSCICN ; /* INTERNAL OSCILLATOR Control */ @@ -63,7 +64,7 @@ __sfr __at (0xBB) AMX0SL ; /* ADC 0 MUX CHANNEL SELECTION (Not on F230 __sfr __at (0xBC) ADC0CF ; /* ADC 0 Configuration (Not on F230/1/6) */ __sfr __at (0xBE) ADC0L ; /* ADC 0 Data LOW ( F206 only ) */ __sfr __at (0xBF) ADC0H ; /* ADC 0 Data High */ -__sfr __at (0xC4) ADC0GTL ; /* ADC 0 GREATER-THAN Register LOW( F206 only ) */ ( F206 only ) */ +__sfr __at (0xC4) ADC0GTL ; /* ADC 0 GREATER-THAN Register LOW( F206 only ) */ __sfr __at (0xC5) ADC0GTH ; /* ADC 0 GREATER-THAN Register (Not on F230/1/6) */ __sfr __at (0xC6) ADC0LTL ; /* ADC 0 LESS-THAN Register LOW ( F206 only ) */ __sfr __at (0xC7) ADC0LTH ; /* ADC 0 LESS-THAN Register (Not on F230/1/6) */ diff --git a/device/include/stdbool.h b/device/include/stdbool.h index 1eef4760..02f41cf6 100644 --- a/device/include/stdbool.h +++ b/device/include/stdbool.h @@ -28,7 +28,7 @@ #define false 0 #define __bool_true_false_are_defined 1 -#if defined (SDCC_ds390) || defined (SDCC_hc08) || defined (SDCC_z80) || defined (SDCC_gbz80) || defined (SDCC_pic14) || defined (SDCC_pic16) +#if defined (SDCC_hc08) || defined (SDCC_z80) || defined (SDCC_gbz80) || defined (SDCC_pic14) || defined (SDCC_pic16) #define BOOL char #else #define BOOL __bit diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 3300ca9f..e66d11e7 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -82,7 +82,7 @@ SDCC Compiler User Guide \size normal -SDCC 2.5.5 +SDCC 2.5.6 \size footnotesize \newline @@ -6972,7 +6972,7 @@ status Collapsed \series default - Disable peep-hole optimization. + Disable peep-hole optimization with built-in rules. \layout List \labelwidthstring 00.00.0000 @@ -11259,10 +11259,10 @@ The Z80 uses several different methods for determining the correct interrupt to generate an interrupt vector table. \layout Standard -By default, SDCC generates code for a maskable interrupt, which uses an - RETI instruction to return from the interrupt. +By default, SDCC generates code for a maskable interrupt, which uses a RETI + instruction to return from the interrupt. To write an interrupt handler for the non-maskable interrupt, which needs - an RETN instruction instead, add the + a RETN instruction instead, add the \emph on critical \emph default @@ -11283,6 +11283,16 @@ void nmi_isr (void) critical interrupt \newline } +\layout Standard + +However if you need to create a non-interruptable interrupt service routine + you would also require the +\emph on +critical +\emph default + keyword. + To distinguish between this and an nmi_isr you must provide an interrupt + number. \layout Section Enabling and Disabling Interrupts @@ -15586,7 +15596,9 @@ SDCC \layout Standard -this Symbol is always defined +this Symbol is always defined. + Since version 2.5.6 it's this version number as an int (ex. + 256) \end_inset diff --git a/src/SDCC.y b/src/SDCC.y index 1cdbd6ca..aae308d1 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -909,9 +909,9 @@ struct_declarator_list struct_declarator : declarator | ':' constant_expr { - int bitsize; + unsigned int bitsize; $$ = newSymbol (genSymName(NestLevel),NestLevel) ; - bitsize= (int) floatFromVal(constExprValue($2,TRUE)); + bitsize= (unsigned int) floatFromVal(constExprValue($2,TRUE)); if (bitsize > (port->s.int_size * 8)) { bitsize = port->s.int_size * 8; werror(E_BITFLD_SIZE, bitsize); @@ -922,8 +922,8 @@ struct_declarator } | declarator ':' constant_expr { - int bitsize; - bitsize= (int) floatFromVal(constExprValue($3,TRUE)); + unsigned int bitsize; + bitsize= (unsigned int) floatFromVal(constExprValue($3,TRUE)); if (bitsize > (port->s.int_size * 8)) { bitsize = port->s.int_size * 8; werror(E_BITFLD_SIZE, bitsize); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index d53bd25f..8ad10a8d 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1839,7 +1839,7 @@ setOperandType (operand * op, sym_link * type) /*-----------------------------------------------------------------*/ /* Get size in byte of ptr need to access an array */ /*-----------------------------------------------------------------*/ -static int +static unsigned int getArraySizePtr (operand * op) { sym_link *ltype = operandType(op); @@ -2843,7 +2843,7 @@ geniCodeAddressOf (operand * op) return op; } - /* other wise make this of the type coming in */ + /* otherwise make this of the type coming in */ ic = newiCode (ADDRESS_OF, op, NULL); IC_RESULT (ic) = newiTempOperand (p, 1); IC_RESULT (ic)->isaddr = 0; diff --git a/src/SDCCopt.c b/src/SDCCopt.c index e88c3050..822afc72 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -778,8 +778,8 @@ convertToFcall (eBBlock ** ebbs, int count) converted to function calls */ if ((IS_CONDITIONAL (ic) || IS_ARITHMETIC_OP (ic)) && - (IS_FLOAT (operandType (IC_RIGHT (ic))) - || IS_FIXED( operandType (IC_RIGHT (ic))))) + (IS_FLOAT (operandType (IC_RIGHT (ic))) || + IS_FIXED( operandType (IC_RIGHT (ic))))) { cnvToFcall (ic, ebbs[i]); @@ -803,7 +803,7 @@ convertToFcall (eBBlock ** ebbs, int count) if (ic->op == '%' && isOperandLiteral(IC_RIGHT(ic)) && IS_UNSIGNED(operandType(IC_LEFT(ic)))) { - unsigned litVal = fabs(operandLitValue(IC_RIGHT(ic))); + unsigned litVal = abs((unsigned)operandLitValue(IC_RIGHT(ic))); /* modulo by 1: no remainder */ if (litVal == 1) diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index dedf6e85..bcf6e418 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -246,8 +246,8 @@ typedef struct symbol char name[SDCC_SYMNAME_MAX + 1]; /* Input Variable Name */ char rname[SDCC_NAME_MAX + 1]; /* internal name */ - short level; /* declration lev,fld offset */ - short block; /* sequential block # of defintion */ + short level; /* declaration lev,fld offset */ + short block; /* sequential block # of definition */ int key; unsigned flexArrayLength; /* if the symbol specifies a struct with a "flexible array member", then the additional length in bytes for @@ -566,7 +566,6 @@ void printSymChain (symbol *, int); void printStruct (structdef *, int); char *genSymName (int); sym_link *getSpec (sym_link *); -char *genSymName (int); int compStructSize (int, structdef *); sym_link *copyLinkChain (sym_link *); int checkDecl (symbol *, int); diff --git a/src/asm.c b/src/asm.c index 73c545c3..9b75aac1 100644 --- a/src/asm.c +++ b/src/asm.c @@ -390,7 +390,7 @@ static const ASM_MAPPING _asxxxx_mapping[] = {"hihil","(%05d$ >> 16)"}, {"hihihil","(%05d$ >> 24)"}, {"equ","="}, - {"org", ".org %04X"}, + {"org", ".org 0x%04X"}, {NULL, NULL} }; @@ -483,6 +483,7 @@ static const ASM_MAPPING _a390_mapping[] = {"hihil","((L%05d / 65536) & 0FFh)"}, {"hihihil","((L%09d / 16777216) & 0FFh)"}, {"equ"," equ"}, + {"org", ".org 0x%04X"}, {NULL, NULL} }; diff --git a/src/hc08/gen.c b/src/hc08/gen.c index c3644711..1c624bdb 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -1173,7 +1173,7 @@ transferAopAop (asmop *srcaop, int srcofs, asmop *dstaop, int dstofs) if (srcaop->type == AOP_LIT) { unsigned long lit; - unsigned char bytemask; + unsigned long bytemask; lit = (unsigned long) floatFromVal (srcaop->aopu.aop_lit); bytemask = (lit >> (srcofs*8)) & 0xff; @@ -3325,7 +3325,7 @@ release: } /*-----------------------------------------------------------------*/ -/* genMinusDec :- does subtraction with deccrement if possible */ +/* genMinusDec :- does subtraction with decrement if possible */ /*-----------------------------------------------------------------*/ static bool genMinusDec (iCode * ic) @@ -3546,7 +3546,7 @@ genMultOneByte (operand * left, /* left unsigned, right signed literal -- literal determines sign handling */ if (AOP_TYPE(right)==AOP_LIT && lUnsigned && !rUnsigned) { - signed char val=floatFromVal (AOP (right)->aopu.aop_lit); + signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit); loadRegFromAop (hc08_reg_a, AOP (left), 0); if (val < 0) @@ -3590,7 +3590,7 @@ genMultOneByte (operand * left, if (AOP_TYPE(right)==AOP_LIT && !rUnsigned) { - signed char val=floatFromVal (AOP (right)->aopu.aop_lit); + signed char val=(signed char)floatFromVal (AOP (right)->aopu.aop_lit); /* AND literal negative */ if (val < 0) { emitcode ("ldx", "#0x%02x", -val); diff --git a/src/hc08/hc08.dsp b/src/hc08/hc08.dsp index 11648f1a..f0596cb9 100644 --- a/src/hc08/hc08.dsp +++ b/src/hc08/hc08.dsp @@ -41,7 +41,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm500 /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c +# ADD CPP /nologo /W2 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 58a6b85a..1540ec02 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -1337,7 +1337,7 @@ void SAFE_snprintf(char **str, size_t *size, const char *format, ...) extern void initStack(int base_address, int size); extern regs *allocProcessorRegister(int rIdx, char * name, short po_type, int alias); -extern regs *allocInternalRegister(int rIdx, char * name, short po_type, int alias); +extern regs *allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias); extern void init_pic(char *); void pCodeInitRegisters(void) diff --git a/src/pic/pic.dsp b/src/pic/pic.dsp index 34c1b22e..c0bbad1d 100644 --- a/src/pic/pic.dsp +++ b/src/pic/pic.dsp @@ -41,7 +41,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm500 /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c +# ADD CPP /nologo /W2 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 01e3cbfa..de2463e8 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -340,7 +340,7 @@ static regs *regWithIdx (set *dRegs, int idx, int fixed); /*-----------------------------------------------------------------*/ /* newReg - allocate and init memory for a new register */ /*-----------------------------------------------------------------*/ -static regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias) +static regs* newReg(short type, PIC_OPTYPE pc_type, int rIdx, char *name, int size, int alias) { regs *dReg; @@ -533,7 +533,7 @@ allocProcessorRegister(int rIdx, char * name, short po_type, int alias) *-----------------------------------------------------------------*/ regs * -allocInternalRegister(int rIdx, char * name, short po_type, int alias) +allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias) { regs * reg = newReg(REG_GPR, po_type, rIdx, name,1,alias); diff --git a/src/pic16/device.c b/src/pic16/device.c index ec66d530..8878ed07 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -59,8 +59,6 @@ PIC16_device *pic16=NULL; unsigned int stackPos = 0; unsigned int stackLen = 0; -extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop); - void pic16_setMaxRAM(int size) { pic16->maxRAMaddress = size; @@ -378,8 +376,6 @@ void pic16_dump_int_registers(FILE *of, set *section) #define _ENDIAN(x) (x) #endif -#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff) - /*-----------------------------------------------------------------* * void pic16_list_valid_pics(int ncols, int list_alias) diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 362cda21..aa77769e 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -1822,7 +1822,7 @@ void pic16_popReleaseTempReg(pCodeOp *pcop, int lock) /*-----------------------------------------------------------------*/ /* pic16_popGetLabel - create a new pCodeOp of type PO_LABEL */ /*-----------------------------------------------------------------*/ -pCodeOp *pic16_popGetLabel(unsigned int key) +pCodeOp *pic16_popGetLabel(int key) { DEBUGpic16_emitcode ("; ***","%s key=%d, label offset %d",__FUNCTION__,key, pic16_labelOffset); @@ -9409,7 +9409,7 @@ void pic16_genLeftShiftLiteral (operand *left, operand *result, iCode *ic) { - int shCount = (int) abs(floatFromVal (AOP(right)->aopu.aop_lit)); + int shCount = abs((int)floatFromVal (AOP(right)->aopu.aop_lit)); int size; FENTRY; @@ -10014,7 +10014,7 @@ static void genRightShiftLiteral (operand *left, iCode *ic, int sign) { - int shCount = (int) abs(floatFromVal (AOP(right)->aopu.aop_lit)); + int shCount = abs((int)floatFromVal (AOP(right)->aopu.aop_lit)); int lsize,res_size; pic16_freeAsmop(right,NULL,ic,TRUE); diff --git a/src/pic16/gen.h b/src/pic16/gen.h index 0225b917..4dbf2365 100644 --- a/src/pic16/gen.h +++ b/src/pic16/gen.h @@ -181,7 +181,7 @@ void pic16_genLeftShiftLiteral (operand *left, operand *right, operand *result, pCodeOp *pic16_popGet2p(pCodeOp *src, pCodeOp *dst); void pic16_emitpcomment (char *fmt, ...); -pCodeOp *pic16_popGetLabel(unsigned int key); +pCodeOp *pic16_popGetLabel(int key); pCodeOp *pic16_popCopyReg(pCodeOpReg *pc); pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval); pCodeOp *pic16_popGetLit(int lit); diff --git a/src/pic16/main.c b/src/pic16/main.c index 217fdd37..c9515fbb 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -100,7 +100,6 @@ extern set *libFilesSet; /* for an unknowned reason. - EEP */ void pic16_emitDebuggerSymbol (char *); -extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop); extern void pic16_emitConfigRegs(FILE *of); extern void pic16_emitIDRegs(FILE *of); diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 0590f9ce..2861da7e 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -4440,7 +4440,7 @@ void pic16_flushDB(char ptype, void *p) /*-----------------------------------------------------------------*/ /* Add "DB" directives to a pBlock */ /*-----------------------------------------------------------------*/ -void pic16_emitDB(char c, char ptype, void *p) +void pic16_emitDB(int c, char ptype, void *p) { int l; diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index c639122d..f4c4789b 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -1026,7 +1026,7 @@ void pCodePeepInit(void); void pic16_pBlockConvert2ISR(pBlock *pb); void pic16_pBlockConvert2Absolute(pBlock *pb); void pic16_initDB(void); -void pic16_emitDB(char c, char ptype, void *p); // Add DB directives to a pBlock +void pic16_emitDB(int c, char ptype, void *p); // Add DB directives to a pBlock void pic16_emitDS(char *s, char ptype, void *p); void pic16_flushDB(char ptype, void *p); // Add pending DB data to a pBlock diff --git a/src/pic16/pic16.dsp b/src/pic16/pic16.dsp index 51b7f5eb..fe0ff600 100644 --- a/src/pic16/pic16.dsp +++ b/src/pic16/pic16.dsp @@ -41,7 +41,7 @@ RSC=rc.exe # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm500 /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c +# ADD CPP /nologo /W2 /Gm /GX /ZI /Od /I ".." /I "." /I "..\.." /I "..\..\support\util" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /FR /FD /GZ /Zm1000 /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index f6c31e9a..21555884 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -374,7 +374,7 @@ static int regname2key(char const *name) /*-----------------------------------------------------------------*/ /* newReg - allocate and init memory for a new register */ /*-----------------------------------------------------------------*/ -regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop) +regs* newReg(int type, short pc_type, int rIdx, char *name, unsigned size, int alias, operand *refop) { regs *dReg; diff --git a/src/pic16/ralloc.h b/src/pic16/ralloc.h index 756e31be..653f973c 100644 --- a/src/pic16/ralloc.h +++ b/src/pic16/ralloc.h @@ -125,7 +125,7 @@ regs *pic16_allocDirReg (operand *op ); regs *pic16_allocRegByName (char *name, int size, operand *op); extern char *pic16_decodeOp(unsigned int op); -regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop); +regs* newReg(int type, short pc_type, int rIdx, char *name, unsigned size, int alias, operand *refop); /* Define register address that are constant across PIC16 family */ #define IDX_TMR0 0xfd6 diff --git a/src/port.h b/src/port.h index d5bcf342..1b7033d2 100644 --- a/src/port.h +++ b/src/port.h @@ -127,7 +127,7 @@ typedef struct { int char_size; int short_size; - int int_size; + unsigned int int_size; int long_size; int ptr_size; //near int fptr_size; //far diff --git a/src/xa51/ralloc.c b/src/xa51/ralloc.c index e9fc42f5..c9e326c6 100755 --- a/src/xa51/ralloc.c +++ b/src/xa51/ralloc.c @@ -199,8 +199,8 @@ static void freeReg (regs * reg, bool silent) { /* allocReg - allocates register of given size (byte, word, dword) */ /* and type (ptr, gpr, cnd) */ /*-----------------------------------------------------------------*/ -static bool allocReg (short size, short type, symbol *sym, - short offset, bool silent) { +static bool allocReg (unsigned int size, int type, symbol *sym, + int offset, bool silent) { int i; checkRegMask(__FUNCTION__);