From: johanknol Date: Wed, 13 Feb 2002 18:28:07 +0000 (+0000) Subject: xa51, work in progress X-Git-Url: https://git.gag.com/?a=commitdiff_plain;ds=sidebyside;h=37911686415ff7fa528ef889dcbbc173625e0c07;hp=aaf96b9876747cba48c6ceb49554df147845545b;p=fw%2Fsdcc xa51, work in progress git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1924 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/as/xa51/xa_link.c b/as/xa51/xa_link.c index 3284925d..30dbe978 100644 --- a/as/xa51/xa_link.c +++ b/as/xa51/xa_link.c @@ -14,7 +14,7 @@ /* This is a cheap hack. The xa51 has a couple of ways to scramble relocation info into it's opcode that the standard linker can't - handle. + handle. No hash or qsort yet. The relocatable format looks like the known one, BUT ISN'T. @@ -34,7 +34,7 @@ the address of the following instruction). So, this is not a standalone linker. It will only link files generated - by xa_asm, which will only process files generated by the xa51 sdcc + by xa_rasm, which will only process files generated by the xa51 sdcc port. */ @@ -121,6 +121,7 @@ struct MODULE { char *name; int offset[MAX_SEGMENTS]; int size[MAX_SEGMENTS]; + int isLib; struct MODULE *next; struct MODULE *last; } *modules=NULL; @@ -143,16 +144,19 @@ struct REFERENCE { int lineno; unsigned address, pc; short how; + short resolved; struct REFERENCE *next; struct REFERENCE *last; } *references=NULL; -char *libPaths[128]; +char *libraryPaths[128]; int nlibPaths=0; -char *libFiles[128]; +char *libraryFiles[128]; int nlibFiles=0; static char outFileName[PATH_MAX]={'\0'}; +static char mapFileName[PATH_MAX]={'\0'}; +FILE *mapOut; struct SEGMENT *currentSegment; struct MODULE *currentModule; @@ -188,20 +192,19 @@ struct SYMBOL *findSymbolByName(char *symName) { return 0; } -void addToModules (char *name) { +void addToModules (char *name, int isLib) { struct MODULE *module; int s; - //fprintf (stderr, "addToModules: %s\n", name); - module=calloc(1, sizeof(struct MODULE)); module->name=strdup(name); for (s=0; soffset[s]=segments[s].current; } + module->isLib=isLib; if (!modules) { modules=module; - } else { + } else { modules->last->next=module; } currentModule=modules->last=module; @@ -210,8 +213,6 @@ void addToModules (char *name) { void addToRefs(char *ref, int address, char *how, int pc) { struct REFERENCE *reference; - //fprintf (stderr, "addToRefs: %s\n", ref); - reference=calloc(1, sizeof(struct REFERENCE)); reference->name=strdup(ref); reference->module=currentModule; @@ -227,14 +228,37 @@ void addToRefs(char *ref, int address, char *how, int pc) { references->last=reference; } +void resolve() { + struct REFERENCE *reference; + for (reference=references; reference; reference=reference->next) { + if (findSymbolByName(reference->name)) { + reference->resolved=1; + } + } +} + +int isUnresolved(char *ref, int resolved) { + struct REFERENCE *reference; + + for (reference=references; reference; reference=reference->next) { + if (strcmp(reference->name, ref)==0) { + // found + if (reference->resolved) { + // already resolved + return 0; + } + if (resolved) { + reference->resolved=1; + return 1; + } + } + } + return 0; +} + void addToDefs(char *def, int address, char absolute) { struct SYMBOL *symbol; - /* fprintf (stderr, "addToDefs: %s %s 0x%04x + 0x%04x\n", - currentSegment->name, def, - currentModule->offset[currentSegment->id], - address); */ - // no duplicates allowed if ((symbol=findSymbolByName(def))) { fprintf (stderr, "*** %s:%d duplicate symbol %s first defined in " @@ -263,37 +287,10 @@ void addToDefs(char *def, int address, char absolute) { void syntaxError (char *err) { fprintf (stderr, "*** %s:%d error while parsing '%s'\n", currentModule->name, currentLine, err); - exit(1); + fatalErrors++; } -void baseName(char *name, char*base) { - int i, first, last; - - // find the last path seperator in name - for (first=strlen(name)-1; - (name[first]!='/' && name[first]!='\\') && first; - first--); - if (name[first]=='/' || name[first]=='\\') { - first++; - } - - // find the last ext seperator in name - for (last=strlen(name)-1; - (name[last]!='.' && last); - last--); - if (!last) { - last=strlen(name); - } - - fprintf (stderr, "baseName: %s %d %d\n", name, first, last); - // fill the base with the baseName - for (i=first; isize[currentSegment->id]) { if (currentModule->size[currentSegment->id] != size) { fprintf (stderr, "*** %s:%d error %s size %d != %d\n", @@ -367,6 +361,7 @@ void readModule(char *module) { currentSegment->name, currentModule->size[currentSegment->id], size); + fatalErrors++; } else { // pleased to meet you again } @@ -375,7 +370,6 @@ void readModule(char *module) { currentModule->offset[currentSegment->id]+=currentSegment->_size; currentSegment->_size += size; } - //fprintf (stderr, "Area: %s size: %d\n", segment, size); // never mind about the flags for now break; } @@ -417,26 +411,22 @@ void readModule(char *module) { } if (sscanf(strtok(&line[2], " "), "%04x", &address)!=1) { fprintf (stderr, "%s:%d error in T record\n", module, currentLine); - exit (1); + fatalErrors++; } - //fprintf (stderr, "%04x:", address); address+=currentSegment->current; for ( ; (tline=strtok(NULL, " \t\n")) && (sscanf(tline, "%02x", &byte)==1); ) { - //fprintf (stderr, " %02x", byte); currentSegment->image[address++]=byte; currentSegment->current++; } - //fprintf (stderr, "\n"); break; } case 'R': { unsigned address, from; char symbol[132]; char how[32]; - //fprintf (stderr, "%s", line); sscanf (line, "R %x %[^ ] %[^ ] %x", &address, how, symbol, &from); addToRefs (symbol, address, how, from); break; @@ -456,7 +446,6 @@ void readModule(char *module) { void writeModule(char *outFileName) { FILE *fOut; - fprintf (stderr, "WriteModule: %s\n", outFileName); if ((fOut=fopen(outFileName, "w"))==NULL) { perror (outFileName); } @@ -464,15 +453,14 @@ void writeModule(char *outFileName) { fclose (fOut); } -void relocate() { +int relocate() { struct SYMBOL *symbol; struct REFERENCE *reference; char *from, *to; int length=segments[GSINIT].current + segments[CSEG].current + segments[XINIT].current; - - //fprintf (stderr, "relocate: total code size: 0x%04x\n", length); + int unresolved=0; // first check if it will fit if (length > 0xffff) { @@ -480,10 +468,21 @@ void relocate() { fatalErrors++; } + // resolve reverences + for (reference=references; reference; reference=reference->next) { + if (!reference->resolved && !findSymbolByName(reference->name)) { + unresolved++; + } + } + if (unresolved) { + // first scan the libraries + return unresolved; + } + // GSINIT gets the --code-loc segments[GSINIT].start=segments[CSEG].start; segments[CSEG].start=segments[GSINIT].start+segments[GSINIT]._size; - // concat cseg to gsinit + // concat cseg and gsinit from=csegImage; to=&gsinitImage[segments[GSINIT].start+segments[GSINIT]._size]; memcpy(to, from, segments[CSEG]._size); @@ -503,19 +502,14 @@ void relocate() { symbol->address += symbol->segment->start; } } - // add the segment symbols - currentSegment=findSegmentByName("XINIT"); - addToDefs("s_XINIT", segments[XINIT].start, 0); - addToDefs("l_XINIT", segments[XINIT]._size, 0); - currentSegment=findSegmentByName("XISEG"); - addToDefs("s_XISEG", segments[XISEG].start, 0); - addToDefs("l_XISEG", segments[XISEG]._size, 0); // and the references for (reference=references; reference; reference=reference->next) { if (!(symbol=findSymbolByName(reference->name))) { + // this reference isn't defined after all fprintf (stderr, "*** %s:%d undefined symbol %s\n", reference->module->name, reference->lineno, reference->name); + fatalErrors++; } else { reference->address += symbol->segment->start; switch (reference->how) @@ -556,6 +550,7 @@ void relocate() { } } } + return 0; } void usage (char * progName, int errNo) { @@ -565,6 +560,48 @@ void usage (char * progName, int errNo) { } } +int scanLibraries(int unresolved) { + int resolved=0; + int nlp, nlf; + char libFiles[PATH_MAX]; + char libFile[PATH_MAX]; + char line[132]; + char symName[132]; + FILE *lf, *lfs; + + for (nlp=0; nlpnext) { + if (!reference->resolved) { + fprintf (stderr, "*** unresolved symbol %s in %s:%d\n", + reference->name, reference->module->name, + reference->lineno); + fatalErrors++; + } } + break; } } - relocate(); + if (unresolved==0) { + writeModule(outFileName); + } // the modules + fprintf (mapOut, "Modules:\n"); for (module=modules; module; module=module->next) { - fprintf (stderr, "%s: ", module->name); + fprintf (mapOut, "\t%s\n", module->name); for (s=0; ssize[s]) { - fprintf (stderr, "%s:0x%04x-0x%04x ", segments[s].name, + fprintf (mapOut, "\t\t%s:0x%04x-0x%04x\n", segments[s].name, module->offset[s], module->offset[s]+module->size[s]); } } - fprintf (stderr, "\n"); - } - - // the symbols - for (symbol=symbols; symbol; symbol=symbol->next) { - fprintf (stderr, "%s %s %s0x%04x %s\n", symbol->name, - symbol->segment->name, - symbol->absolute ? "= " : "", - symbol->address, symbol->module->name); } // the segments + fprintf (mapOut, "\nSegments:\n"); for (s=1; snext) { + fprintf (mapOut, "%s\t%s %s0x%04x %s\n", symbol->name, + symbol->segment->name, + symbol->absolute ? "= " : "", + symbol->address, symbol->module->name); + } + writeModule(outFileName); + fclose(mapOut); return fatalErrors? 1 : 0; } diff --git a/device/examples/xa51/Makefile b/device/examples/xa51/Makefile index de7a759e..fcc12611 100644 --- a/device/examples/xa51/Makefile +++ b/device/examples/xa51/Makefile @@ -1,6 +1,6 @@ CC = sdcc -CFLAGS= -Wa-s -V +CFLAGS= -Wa-s MFLAGS= -mxa51 LFLAGS= --xram-loc 0x4000 diff --git a/device/examples/xa51/hello.c b/device/examples/xa51/hello.c index c7906cd0..f908681d 100755 --- a/device/examples/xa51/hello.c +++ b/device/examples/xa51/hello.c @@ -13,7 +13,7 @@ xdata at 0x1234 abs; extern xdata xee; void main(void) { - xe=getchar(); + //xe=getchar(); abs=1; putchar('1'); putchar('2'); diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index 8efe2a18..8583abf1 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -113,7 +113,7 @@ XA51SOURCES = _atoi.c _atol.c _schar2fs.c \ asincosf.c asinf.c acosf.c atanf.c atan2f.c sincoshf.c \ sinhf.c coshf.c tanhf.c floorf.c ceilf.c modff.c -XA51OBJECTS = $(XA51SOURCES:%.c=$(PORTDIR)/%.xa) +XA51OBJECTS = $(XA51SOURCES:%.c=$(PORTDIR)/%.rel) OEXT = .rel @@ -139,11 +139,11 @@ model-ds390: model-xa51: if [ "`grep xa51 ../../ports.build`" = xa51 ]; then \ - $(MAKE) MODELFLAGS="-mxa51" PORT=xa51 objects-xa51 OEXT=.xa; \ + $(MAKE) MODELFLAGS="-mxa51" PORT=xa51 objects-xa51; \ fi objects-xa51: build-dir $(XA51OBJECTS) port-specific-objects - cd $(PORTDIR); ls *$(OEXT) > $(PORT).lib + cd $(PORTDIR); ls *$(OEXT) > lib$(PORT).lib model-z80: if [ "`grep z80 ../../ports.build`" = z80 ]; then \ @@ -234,7 +234,7 @@ include clean.mk $(PORTDIR)/%$(OEXT): %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c $< mv -f `basename $@` $@ - -mv -f `basename $@ $(OEXT)`.asm $(PORTDIR) + mv -f `basename $@ $(OEXT)`.asm $(PORTDIR) # Remaking configuration # ---------------------- diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 0f3e0725..4b44dd25 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1645,7 +1645,6 @@ geniCodeRValue (operand * op, bool force) if (IS_SPEC (type) && IS_TRUE_SYMOP (op) && (!IN_FARSPACE (SPEC_OCLS (etype)) || - /* TARGET_IS_DS390)) */ (options.model == MODEL_FLAT24) )) { op = operandFromOperand (op); @@ -2933,7 +2932,6 @@ geniCodeReceive (value * args) if (IN_FARSPACE (SPEC_OCLS (sym->etype)) && options.stackAuto == 0 && - /* !TARGET_IS_DS390) */ (!(options.model == MODEL_FLAT24)) ) { } diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 10d42aa0..710d72be 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1160,11 +1160,14 @@ linkEdit (char **envp) mfprintf (lnkfile, getRuntimeVariables(), "-k {libdir}{sep}%s\n", c); /* standard library files */ - /* if (strcmp (port->target, "ds390") == 0) */ if (options.model == MODEL_FLAT24) { fprintf (lnkfile, "-l %s\n", STD_DS390_LIB); } + if (options.model == MODEL_PAGE0) + { + fprintf (lnkfile, "-l %s\n", STD_XA51_LIB); + } fprintf (lnkfile, "-l %s\n", STD_LIB); fprintf (lnkfile, "-l %s\n", STD_INT_LIB); fprintf (lnkfile, "-l %s\n", STD_LONG_LIB); diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 73951801..ddadefa8 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -861,28 +861,31 @@ genEndFunction (iCode * ic) /*-----------------------------------------------------------------*/ static void genRet (iCode * ic) { - printIc ("genRet", ic, 0,1,0); - - aopOp(IC_LEFT(ic), TRUE, TRUE); + if (!IC_LEFT(ic)) { + printIc ("genRet", ic, 0, 0, 0); + } else { + printIc ("genRet", ic, 0, 1, 0); + aopOp(IC_LEFT(ic), TRUE, TRUE); + switch (AOP_SIZE(IC_LEFT(ic))) + { + case 4: + emitcode ("mov", "r1,%s", AOP_NAME(IC_LEFT(ic))[1]); + emitcode ("mov", "r0,%s", AOP_NAME(IC_LEFT(ic))[0]); + break; + case 3: + emitcode ("mov", "r1l,%s", AOP_NAME(IC_LEFT(ic))[1]); + // fall through + case 2: + emitcode ("mov", "r0,%s", AOP_NAME(IC_LEFT(ic))[0]); + break; + case 1: + emitcode ("mov", "r0l,%s", AOP_NAME(IC_LEFT(ic))[0]); + break; + default: + bailOut("genRet"); + } + } - switch (AOP_SIZE(IC_LEFT(ic))) - { - case 4: - emitcode ("mov", "r1,%s", AOP_NAME(IC_LEFT(ic))[1]); - emitcode ("mov", "r0,%s", AOP_NAME(IC_LEFT(ic))[0]); - break; - case 3: - emitcode ("mov", "r1l,%s", AOP_NAME(IC_LEFT(ic))[1]); - // fall through - case 2: - emitcode ("mov", "r0,%s", AOP_NAME(IC_LEFT(ic))[0]); - break; - case 1: - emitcode ("mov", "r0l,%s", AOP_NAME(IC_LEFT(ic))[0]); - break; - default: - bailOut("genRet"); - } emitcode ("jmp", "%05d$", returnLabel->key+100); } @@ -941,6 +944,27 @@ static void genPlus (iCode * ic) { aopOp(left, !aopIsPtr(result), !aopIsDir(result)); aopOp(right, !aopIsPtr(result), !aopIsDir(result)); + // special case for * = * + char, needs a closer look + // heck, this shouldn't have come here but bug-223113 does + if (size==3 && AOP_SIZE(right)==1) { + emitcode ("mov", "r1l,%s", AOP_NAME(right)[0]); + emitcode ("mov", "r1h,#0"); // ptr arith unsigned???????????? + emitcode ("mov", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + emitcode ("add.w", "%s,r1", AOP_NAME(result)[0]); + emitcode ("mov", "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]); + return; + } + + // special case for (whatever)* = (whatever)** + char, needs a closer look + // heck, this shouldn't have come here but bug-441448 does + if (size==2 && AOP_SIZE(right)==1) { + emitcode ("mov", "r1l,%s", AOP_NAME(right)[0]); + emitcode ("mov", "r1h,#0"); // ptr arith unsigned???????????? + emitcode ("mov", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + emitcode ("add.w", "%s,r1", AOP_NAME(result)[0]); + return; + } + if (size>1) { instr="add.w"; } else { @@ -1276,6 +1300,10 @@ static void genPointerGet (iCode * ic, iCode *pi) { switch (AOP_TYPE(left)) { + case AOP_LIT: + emitcode("mov","r1,%s", AOP_NAME(left)[0]); + sprintf (AOP_NAME(left)[0], "r1"); + // fall through case AOP_REG: if (size>1) { if (codePointer) { @@ -1472,7 +1500,7 @@ static void genAddrOf (iCode * ic) { getStackOffset(OP_SYMBOL(left)->stack)); if (size > 2) { // this must be a generic pointer - emitcode ("mov", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], FPOINTER); + emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(IC_RESULT(ic))[1], FPOINTER); } return; } @@ -1648,13 +1676,13 @@ static void genCast (iCode * ic) { switch (ptrType) { case POINTER: - emitcode ("mov", "%s,#0x00", AOP_NAME(result)[1]); + emitcode ("mov.b", "%s,#0x00", AOP_NAME(result)[1]); break; case FPOINTER: - emitcode ("mov", "%s,#0x01", AOP_NAME(result)[1]); + emitcode ("mov.b", "%s,#0x01", AOP_NAME(result)[1]); break; case CPOINTER: - emitcode ("mov", "%s,#0x02", AOP_NAME(result)[1]); + emitcode ("mov.b", "%s,#0x02", AOP_NAME(result)[1]); break; default: bailOut("genCast: got unknown storage class"); diff --git a/support/regression/ports/xa51/spec.mk b/support/regression/ports/xa51/spec.mk index a235690c..27137dde 100755 --- a/support/regression/ports/xa51/spec.mk +++ b/support/regression/ports/xa51/spec.mk @@ -25,7 +25,7 @@ EXTRAS = fwk/lib/testfwk$(OBJEXT) $(PORTS_DIR)/$(PORT)/support$(OBJEXT) # run simulator with 10 seconds timeout %.out: %$(EXEEXT) fwk/lib/timeout mkdir -p `dirname $@` - -fwk/lib/timeout 10 $(SXA) -S in=/dev/null,out=$@ $< < $(PORTS_DIR)/xa51/uCsim.cmd >/dev/null || \ + -fwk/lib/timeout 1 $(SXA) -S in=/dev/null,out=$@ $< < $(PORTS_DIR)/xa51/uCsim.cmd >/dev/null || \ echo -e --- FAIL: \"timeout, simulation killed\" in $(<:.ihx=.c)"\n"--- Summary: 1/1/1: timeout >> $@ -grep -n FAIL $@ /dev/null || true diff --git a/support/regression/ports/xa51/support.c b/support/regression/ports/xa51/support.c index fa3f3cd4..a725e4e5 100755 --- a/support/regression/ports/xa51/support.c +++ b/support/regression/ports/xa51/support.c @@ -22,9 +22,14 @@ #include +void external_startup(void) { + return; +} + void _putchar (char c) { + c; _asm mov.b r0l,[r7+2] trap #0x0e diff --git a/support/regression/tests/bug-460010.c b/support/regression/tests/bug-460010.c index d42caabb..60020552 100644 --- a/support/regression/tests/bug-460010.c +++ b/support/regression/tests/bug-460010.c @@ -2,7 +2,7 @@ */ #include -#if defined __mcs51 || defined __ds390 +#if defined __mcs51 || defined __ds390 || defined __xa51 #define XDATA xdata #else #define XDATA