+2006-04-22 Maarten Brock <sourceforge.brock AT dse.nl>
+
+ * 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 <borut.razem AT siol.net>
* doc/sdccman.lyx, */Makefile, */Makefile.in:
SOURCE=.\mcs51\i8051.h
# End Source File
+# Begin Source File
+
+SOURCE=.\mcs51\strcmpi.h
+# End Source File
# End Group
# End Target
# End Project
# 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
/* lkarea.c */
extern VOID lkparea();
extern VOID lnkarea();
-extern VOID lnksect();
+extern Addr_T lnksect(struct area *tap);
extern VOID newarea();
/* lkhead.c */
* 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
/* 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;
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 */
#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.
*/
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 */
*/
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"
*/
* 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
*/
/*
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.
*/
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');
}
}
}
*p = 0;
- if (++incfil == MAXINC ||
- (ifp[incfil] = fopen(fn, "r")) == NULL) {
+ if ((++incfil == MAXINC) ||
+ (ifp[incfil] = fopen(fn, "r")) == NULL) {
--incfil;
err('i');
} else {
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) {
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);
int numlinenum=0;
_linenum * linenum=NULL;
-
+#if 0
typedef struct
{
char * name;
{"BSEG", 4},
{"", 5} /*A typeless number?*/
};
-
+#endif
char * UsageTypeName[]={"CODE", "XDATA", "DATA", "IDATA", "BIT", "NUMBER"};
int AddNumber;
unsigned char * ihxBuff=NULL;
* 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
*/
#include <string.h>
#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.
*/
/*
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_<areaname> and l_<areaname> 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_<areaname> and l_<areaname> 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) {
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_<areaname> the start address of the area
- * l_<areaname> 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_<areaname> the start address of the area
+ * l_<areaname> 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;
}
* Setup Absolute DEF linkage.
*/
lkparea(_abs_);
- ap->a_flag = A_ABS|A_OVR;
+ ap->a_flag = A_ABS;
}
/*)Function VOID module()
#include <string.h>
#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)
{
}
}
-/*)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
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(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;
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; i<NHASH; ++i) {
- sp = symhash[i];
- while (sp) {
- /* If we find an undefined symbol
- * (one where S_DEF is not set), then
- * try looking for it. If we find it
- * in any of the libraries then
- * increment symfnd. This will force
- * another pass of symbol searching and
- * make sure that back references work.
- */
- if ((sp->s_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; i<NHASH; ++i) {
+ sp = symhash[i];
+ while (sp) {
+ /* If we find an undefined symbol
+ * (one where S_DEF is not set), then
+ * try looking for it. If we find it
+ * in any of the libraries then
+ * increment symfnd. This will force
+ * another pass of symbol searching and
+ * make sure that back references work.
+ */
+ if ((sp->s_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, "<FILE>"))
- {
- 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, "<REL>")) state=2;
- break;
- case 2:
- if(EQ(str, "</REL>")) 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, "<FILE>"))
+ {
+ 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, "<REL>")) state=2;
+ break;
+ case 2:
+ if(EQ(str, "</REL>")) return;
+ ip = str;
+ link_main();
+ break;
+ }
+ }
}
/*Load an .adb file embedded in a sdcclib file. If there is
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, "<ADB>")) state=1;
- break;
- case 1:
- if(EQ(str, "</ADB>")) 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, "<ADB>")) state=1;
+ break;
+ case 1:
+ if(EQ(str, "</ADB>")) 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
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);
case 0:
if(EQ(FLine, "<INDEX>"))
{
- /*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, "<MODULE>"))
- {
- /*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, "</INDEX>"))
- {
- /*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, "</MODULE>"))
- {
- /*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, "<SDCCLIB>")==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, "<SDCCLIB>")==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);
+ }
}
{ 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 },
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 */
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 */
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.
*/
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');
}
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) {
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);
{ 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},
int numlinenum=0;
_linenum * linenum=NULL;
-
+#if 0
typedef struct
{
char * name;
{"BSEG", 4},
{"", 5} /*A typeless number?*/
};
-
+#endif
char * UsageTypeName[]={"CODE", "XDATA", "DATA", "IDATA", "BIT", "NUMBER"};
int AddNumber;
unsigned char * ihxBuff=NULL;
/* lkerr++; */
/* } */
}
+ /*
+ * Evaluate area address
+ */
+ skip(-1);
+ axp->a_addr = eval();
/*
* Place pointer in header area list
*/
}
}
-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]=' ';
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)
{
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);
}
{
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);
}
/*
#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";
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*/
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 */
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') )
}
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;
"\n?ASlink-Warning-Paged Area %8s Boundary Error\n", tap->a_id);
lkerr++;
}
+ return addr;
}
* Setup Absolute DEF linkage.
*/
lkparea(_abs_);
- ap->a_flag = A_ABS|A_OVR;
+ ap->a_flag = A_ABS;
}
/*)Function VOID module()
#include <ctype.h>
#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()
*
*/
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 */
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)
{
}
}
-/*)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
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'*/
}
}
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;
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; i<NHASH; ++i) {
- sp = symhash[i];
- while (sp) {
- /* If we find an undefined symbol
- * (one where S_DEF is not set), then
- * try looking for it. If we find it
- * in any of the libraries then
- * increment symfnd. This will force
- * another pass of symbol searching and
- * make sure that back references work.
- */
- if ((sp->s_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; i<NHASH; ++i) {
+ sp = symhash[i];
+ while (sp) {
+ /* If we find an undefined symbol
+ * (one where S_DEF is not set), then
+ * try looking for it. If we find it
+ * in any of the libraries then
+ * increment symfnd. This will force
+ * another pass of symbol searching and
+ * make sure that back references work.
+ */
+ if ((sp->s_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, "<FILE>"))
- {
- 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, "<FILE>"))
+ {
+ 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, "<REL>")) state=2;
- break;
- case 2:
- if(EQ(str, "</REL>")) return;
- ip = str;
- link_main();
- break;
- }
- }
+ lkexit(1);
+ }
+ }
+ break;
+ case 1:
+ if(EQ(str, "<REL>")) state=2;
+ break;
+ case 2:
+ if(EQ(str, "</REL>")) return;
+ ip = str;
+ link_main();
+ break;
+ }
+ }
}
/*Load an .adb file embedded in a sdcclib file. If there is
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, "<ADB>")) state=1;
- break;
- case 1:
- if(EQ(str, "</ADB>")) 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, "<ADB>")) state=1;
+ break;
+ case 1:
+ if(EQ(str, "</ADB>")) 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
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);
case 0:
if(EQ(FLine, "<INDEX>"))
{
- /*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, "<MODULE>"))
- {
- /*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, "</INDEX>"))
- {
- /*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, "</MODULE>"))
- {
- /*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*/
}
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)
{
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);
case 0:
if(EQ(FLine, "<INDEX>"))
{
- /*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, "<MODULE>"))
- {
- /*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)
}
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, "</INDEX>"))
- {
- return This; /*Finish, get out of here*/
- }
+ {
+ return This; /*Finish, get out of here*/
+ }
break;
case 2:
if(EQ(FLine, "</MODULE>"))
- {
- 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)
{
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, "<SDCCLIB>")==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 */
}
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;
ThisLibr=ThisLibr->next;
free(ThisLibr2Free);
}
-
+
libr=NULL;
}
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, "<SDCCLIB>")==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, "<SDCCLIB>")==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);
+ }
}
-
{ 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, ".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 */
__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 */
__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) */
#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
\size normal
-SDCC 2.5.5
+SDCC 2.5.6
\size footnotesize
\newline
\series default
- Disable peep-hole optimization.
+ Disable peep-hole optimization with built-in rules.
\layout List
\labelwidthstring 00.00.0000
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
\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
\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
</cell>
</row>
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);
}
| 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);
/*-----------------------------------------------------------------*/
/* Get size in byte of ptr need to access an array */
/*-----------------------------------------------------------------*/
-static int
+static unsigned int
getArraySizePtr (operand * op)
{
sym_link *ltype = operandType(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;
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]);
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)
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
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);
{"hihil","(%05d$ >> 16)"},
{"hihihil","(%05d$ >> 24)"},
{"equ","="},
- {"org", ".org %04X"},
+ {"org", ".org 0x%04X"},
{NULL, NULL}
};
{"hihil","((L%05d / 65536) & 0FFh)"},
{"hihihil","((L%09d / 16777216) & 0FFh)"},
{"equ"," equ"},
+ {"org", ".org 0x%04X"},
{NULL, NULL}
};
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;
}
/*-----------------------------------------------------------------*/
-/* genMinusDec :- does subtraction with deccrement if possible */
+/* genMinusDec :- does subtraction with decrement if possible */
/*-----------------------------------------------------------------*/
static bool
genMinusDec (iCode * ic)
/* 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)
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);
# 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
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)
# 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
/*-----------------------------------------------------------------*/
/* 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;
*-----------------------------------------------------------------*/
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);
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;
#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)
/*-----------------------------------------------------------------*/
/* 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);
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;
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);
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);
/* 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);
/*-----------------------------------------------------------------*/
/* 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;
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
# 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
/*-----------------------------------------------------------------*/
/* 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;
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
{
int char_size;
int short_size;
- int int_size;
+ unsigned int int_size;
int long_size;
int ptr_size; //near
int fptr_size; //far
/* 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__);