From 471d04e308e77523505e67ef7722ab94e7ec385a Mon Sep 17 00:00:00 2001 From: johanknol Date: Mon, 18 Feb 2002 14:21:12 +0000 Subject: [PATCH] last ci before completely rewrite ralloc.c git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1936 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- as/xa51/xa_link.c | 28 +++++++------- as/xa51/xa_main.c | 21 ++++++++--- as/xa51/xa_rasm.y | 4 +- device/examples/xa51/hello.c | 2 +- src/xa51/gen.c | 71 +++++++++++++++++++++++++++++++----- src/xa51/main.c | 2 +- 6 files changed, 98 insertions(+), 30 deletions(-) diff --git a/as/xa51/xa_link.c b/as/xa51/xa_link.c index f6d708eb..f9a81c75 100644 --- a/as/xa51/xa_link.c +++ b/as/xa51/xa_link.c @@ -14,7 +14,9 @@ /* 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. No hash or qsort yet. + handle, not to mention word allignment. + + No hash or qsort yet. The relocatable format looks like the known one, BUT ISN'T. @@ -50,13 +52,17 @@ enum { GSINIT=1, CSEG, XINIT, - GSFINAL, // here goes the final output + + // here goes the final output and should be used by the assembler + GSFINAL, // these are only for storage BSEG, DSEG, XSEG, XISEG, + + // that's all MAX_SEGMENTS }; @@ -455,7 +461,6 @@ void readModule(char *module, int isLib) { } currentLine++; } - // that's all for now, thanks for watching */ fclose (relModule); } @@ -595,8 +600,9 @@ int relocate() { int rel8 = symbol->address-(reference->pc & ~1); if (rel8<-256 || rel8>256) { fprintf (stderr, - "rel8 target for %s is out of range in module %s\n", - reference->name, reference->module->name); + "rel8 target for %s is out of range in module %s:%d\n", + reference->name, reference->module->name, + reference->lineno); fatalErrors++; } gsfinalImage[reference->address]=rel8/2; @@ -606,8 +612,9 @@ int relocate() { int rel16 = symbol->address-(reference->pc & ~1); if (rel16<-65536 || rel16>65534) { fprintf (stderr, - "rel16 target for %s is out of range in module %s\n", - reference->name, reference->module->name); + "rel16 target for %s is out of range in module %s:%d\n", + reference->name, reference->module->name, + reference->lineno); fatalErrors++; } gsfinalImage[reference->address]=(rel16/2)>>8; @@ -667,7 +674,6 @@ int scanLibraries(int unresolved) { for (nlp=0; nlpline_def); #else if (p->issfr) { - fprintf (sym_fp, "%-5s", "SFR"); + fprintf (sym_fp, "%-7s", "SFR"); } else if (p->isbit && !p->area) { - fprintf (sym_fp, "%-5s", "SBIT"); + fprintf (sym_fp, "%-7s", "SBIT"); } else if (p->mode=='=') { - fprintf (sym_fp,"ABS"); + fprintf (sym_fp,"ABS "); } else if (!p->isdef) { - fprintf (sym_fp,"EXTRN"); + fprintf (sym_fp,"EXTRN "); } else { - fprintf (sym_fp, "%-5s", areaToString(p->area)); + fprintf (sym_fp, "%-7s", areaToString(p->area)); } fprintf (sym_fp, " 0x%04x (%5d)", p->value, p->value); fprintf (sym_fp, " %s", p->isdef ? "D" : "-"); @@ -384,6 +384,17 @@ struct symbol *is_ref(char *thename) { return NULL; } +int is_abs(char *thename) { + struct symbol *p; + p = sym_list; + while (p != NULL) { + if (strcasecmp(thename, p->name)==0) + return p->mode == '='; + p = p->next; + } + return 0; +} + /* this routine is used to dump a group of bytes to the output */ /* it is responsible for generating the list file and sending */ /* the bytes one at a time to the object code generator */ diff --git a/as/xa51/xa_rasm.y b/as/xa51/xa_rasm.y index c99078e2..5db81555 100755 --- a/as/xa51/xa_rasm.y +++ b/as/xa51/xa_rasm.y @@ -167,7 +167,9 @@ line: linesymbol ':' linenosym { MEM_POS += $3; } | linenosym { - MEM_POS += $1; + if (!is_abs(symbol_name)) { + MEM_POS += $1; + } } linenosym: directive EOL { diff --git a/device/examples/xa51/hello.c b/device/examples/xa51/hello.c index 224327fc..db0f05b7 100755 --- a/device/examples/xa51/hello.c +++ b/device/examples/xa51/hello.c @@ -9,8 +9,8 @@ extern bit be; extern code ce; extern data de; extern xdata xe; -xdata at 0x1234 abs; extern xdata xee; +xdata at 0x1234 abs; void main(void) { puts ("Hello world.\n\r"); diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 2ce67532..25dcc5dc 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -205,23 +205,23 @@ static asmop *aopForSym(symbol *sym, switch (size) { case 1: - emitcode ("mov.b", "r0l,[%s]", getStackOffset(sym->stack)); + emitcode ("mov.b", "r0l,[%s] ;aopForSym:stack:1", getStackOffset(sym->stack)); sprintf (aop->name[0], "r0l"); return aop; case 2: - emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack)); + emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:2", getStackOffset(sym->stack)); sprintf (aop->name[0], "r0"); return aop; case 3: - emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack)); + emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack)); sprintf (aop->name[0], "r0"); - emitcode ("mov.b", "r1l,[%s]", getStackOffset(sym->stack+2)); + emitcode ("mov.b", "r1l,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack+2)); sprintf (aop->name[1], "r1l"); return aop; case 4: - emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack)); + emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:4", getStackOffset(sym->stack)); sprintf (aop->name[0], "r0"); - emitcode ("mov.w", "r1,[%s]", getStackOffset(sym->stack+2)); + emitcode ("mov.w", "r1,[%s] ;aopForSym:stack:4", getStackOffset(sym->stack+2)); sprintf (aop->name[1], "r1"); return aop; } @@ -949,7 +949,7 @@ 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 + // 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]); @@ -960,7 +960,7 @@ static void genPlus (iCode * ic) { return; } - // special case for (whatever)* = (whatever)** + char, needs a closer look + // special case for "xdata * = xdata * + 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]); @@ -996,9 +996,62 @@ static void genPlus (iCode * ic) { /* genMinus - generates code for subtraction */ /*-----------------------------------------------------------------*/ static void genMinus (iCode * ic) { + operand *result=IC_RESULT(ic), *left=IC_LEFT(ic), *right=IC_RIGHT(ic); + int size; + char *instr; + printIc (0, "genMinus", ic, 1,1,1); -} + size=aopOp(result, TRUE, TRUE); + + /* if left is a literal, then exchange them */ + if (IS_LITERAL(operandType(left))) { + operand *tmp = right; + right = left; + left = tmp; + } + + if (aopIsBit(result)) { + if (IS_LITERAL(operandType(right))) { + if (operandLitValue(right)) { + emitcode ("clr", AOP_NAME(result)[0]); + return; + } + aopOp(left, TRUE, TRUE); + emitcode ("mov", "%s,%s", AOP_NAME(result)[0], toBoolean(left)); + return; + } + bailOut("genPlus: unfinished genPlus bit"); + } + + if (isOperandEqual(result,left)) { + left->aop=result->aop; + } else { + aopOp(left, !aopIsPtr(result), !aopIsDir(result)); + } + aopOp(right, !aopIsPtr(result), !aopIsDir(result)); + + if (size>1) { + instr="sub.w"; + } else { + instr="sub.b"; + } + if (!aopEqual(result->aop, left->aop, 0)) { + emitcode ("mov", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + } + emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(right)[0]); + if (size>2) { + if (!aopEqual(result->aop, left->aop, 1)) { + emitcode ("mov", "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]); + } + if (size==3) { + // generic pointer + } else { + emitcode ("subb.w", "%s,%s", AOP_NAME(result)[1], AOP_NAME(right)[1]); + } + } + return; +} /*-----------------------------------------------------------------*/ /* genMult - generates code for multiplication */ diff --git a/src/xa51/main.c b/src/xa51/main.c index 8875d3e7..eb2c944f 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -149,7 +149,7 @@ _xa51_genAssemblerPreamble (FILE * of) fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n"); fprintf (of, "\n"); fprintf (of, "__sdcc_gsinit_startup:\n"); - //fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n"); + fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n"); fprintf (of, "\t.db 0x96,0x48,0x40,0x01\n"); fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc); fprintf (of, "\tcall\t_external_startup\n"); -- 2.30.2