From a6209c13974db8d38261366f3460a920189239b3 Mon Sep 17 00:00:00 2001 From: johanknol Date: Tue, 29 Jan 2002 18:05:45 +0000 Subject: [PATCH] xa51, work in progress git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1856 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- as/xa51/xa_asm.y | 8 +++- as/xa51/xa_main.c | 28 ++++++----- device/examples/xa51/Makefile | 8 ++-- sim/ucsim/packages.mk | 30 ------------ sim/ucsim/xa.src/glob.cc | 10 +++- sim/ucsim/xa.src/glob.h | 9 +++- sim/ucsim/xa.src/inst.cc | 4 ++ sim/ucsim/xa.src/xa.cc | 31 +++++++++--- src/xa51/gen.c | 90 ++++++++++++++++++++++++++++------- src/xa51/main.c | 28 ++++++----- 10 files changed, 159 insertions(+), 87 deletions(-) delete mode 100644 sim/ucsim/packages.mk diff --git a/as/xa51/xa_asm.y b/as/xa51/xa_asm.y index 7872da4e..4b87ea3f 100644 --- a/as/xa51/xa_asm.y +++ b/as/xa51/xa_asm.y @@ -84,7 +84,7 @@ line: linesymbol ':' linenosym { } linenosym: directive EOL { - if (p3) out(op, $1); + if (p3) out(op, $1); $$ = $1; } | instruction EOL { @@ -138,7 +138,7 @@ directive: '.' ORG expr { $$ = 0; } | bitsymbol BITDEF expr { - if (p1) { + if (p1) { build_sym_list(symbol_name); mk_bit(symbol_name); } @@ -184,6 +184,10 @@ directive: '.' ORG expr { /* ignore global symbol declaration */ $$ = 0; } + | '.' GLOBL bit { + /* ignore bit symbol declaration */ + $$ = 0; + } | '.' DS expr { /* todo: if CSEG, emit some filler bytes */ $$ = $3; diff --git a/as/xa51/xa_main.c b/as/xa51/xa_main.c index d0a0832d..91c70944 100644 --- a/as/xa51/xa_main.c +++ b/as/xa51/xa_main.c @@ -232,8 +232,8 @@ void print_symbol_table() #else if (p->issfr) { fprintf (sym_fp, "%-5s", "SFR"); - } else if (p->isbit) { - fprintf (sym_fp, "%-5s", "BIT"); + } else if (p->isbit && !p->area) { + fprintf (sym_fp, "%-5s", "SBIT"); } else { fprintf (sym_fp, "%-5s", areaToString(p->area)); } @@ -326,17 +326,19 @@ void out(int *byte_list, int num) if (num > 0) fprintf(list_fp, "%06X: ", MEM_POS); else fprintf(list_fp, "\t"); - for (i=0; i> 16; // kludgy, param info +#undef FUNC1 #define FUNC1 add1 +#undef FUNC2 #define FUNC2 add2 #include "inst_gen.cc" @@ -78,7 +80,9 @@ cl_xa::inst_ADDC(uint code) { int operands = code >> 16; // kludgy, param info +#undef FUNC1 #define FUNC1 addc1 +#undef FUNC2 #define FUNC2 addc2 #include "inst_gen.cc" diff --git a/sim/ucsim/xa.src/xa.cc b/sim/ucsim/xa.src/xa.cc index d9865e58..67c3f671 100644 --- a/sim/ucsim/xa.src/xa.cc +++ b/sim/ucsim/xa.src/xa.cc @@ -402,16 +402,16 @@ cl_xa::disass(t_addr addr, char *sep) immed_offset += 4; break; case DIRECT_DATA8 : - sprintf(parm_str, "#%04d 0x%02x", - ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset), - get_mem(MEM_ROM, addr+immed_offset+1) ); + sprintf(parm_str, "0x%03x,#0x%02x", + ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset), + get_mem(MEM_ROM, addr+immed_offset+1)); immed_offset += 3; break; case DIRECT_DATA16 : - sprintf(parm_str, "#%04d 0x%04x", - ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset), - (short)((get_mem(MEM_ROM, addr+immed_offset+2)) | - (get_mem(MEM_ROM, addr+immed_offset+1)<<8)) ); + sprintf(parm_str, "%0x03x,#0x%04x", + ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset), + get_mem(MEM_ROM, addr+immed_offset+2) + + (get_mem(MEM_ROM, addr+immed_offset+1)<<8)); immed_offset += 3; break; @@ -445,6 +445,10 @@ cl_xa::disass(t_addr addr, char *sep) sprintf(parm_str, "%s", reg_strs[((code >> 4) & 0xf)] ); break; + case IREG_ALONE : + sprintf(parm_str, "[%s]", + reg_strs[((code >> 4) & 0xf)] ); + break; case ADDR24 : strcpy(parm_str, "ADDR24"); break; @@ -454,6 +458,19 @@ cl_xa::disass(t_addr addr, char *sep) case DIRECT_REL8 : strcpy(parm_str, "DIRECT_REL8"); break; + + case REL8 : + //strcpy(parm_str, "REL8"); + sprintf(parm_str, "0x%04x", + (get_mem(MEM_ROM, addr+1)*2+addr+len)&0xfffe); + break; + case REL16 : + //strcpy(parm_str, "REL16"); + sprintf(parm_str, "0x%04x", + (((get_mem(MEM_ROM, addr+1)<<8) | + get_mem(MEM_ROM, addr+2))*2+addr+len)&0xfffe); + break; + default: strcpy(parm_str, "???"); break; diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 9d525df1..74f0947d 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -446,7 +446,7 @@ bool aopIsPtr(operand *op) { } } -char *opRegName(operand *op, int offset, char *opName) { +char *opRegName(operand *op, int offset, char *opName, bool decorate) { if (IS_SYMOP(op)) { if (OP_SYMBOL(op)->onStack) { @@ -471,17 +471,21 @@ char *opRegName(operand *op, int offset, char *opName) { } // fall through case V_CHAR: - sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int); + sprintf (opName, "#%s0x%02x", decorate?"(char)":"", + SPEC_CVAL(OP_VALUE(op)->type).v_int); break; case V_INT: if (SPEC_LONG(OP_VALUE(op)->type)) { - sprintf (opName, "#0x%02lx", SPEC_CVAL(OP_VALUE(op)->type).v_long); + sprintf (opName, "#%s0x%02lx", decorate?"(long)":"", + SPEC_CVAL(OP_VALUE(op)->type).v_long); } else { - sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int); + sprintf (opName, "#%s0x%02x", decorate?"(int)":"", + SPEC_CVAL(OP_VALUE(op)->type).v_int); } break; case V_FLOAT: - sprintf (opName, "#%f", SPEC_CVAL(OP_VALUE(op)->type).v_float); + sprintf (opName, "#%s%f", decorate?"(float)":"", + SPEC_CVAL(OP_VALUE(op)->type).v_float); break; default: bailOut("opRegName: unexpected noun"); @@ -553,7 +557,7 @@ char * printOp (operand *op) { strcat (line, "unknown"); return line; } else if (IS_VALOP(op)) { - opRegName(op, 0, line); + opRegName(op, 0, line, 1); } else if (IS_TYPOP(op)) { sprintf (line, "["); if (isPtr) { @@ -694,10 +698,43 @@ static void genUminus (iCode * ic) { } /*-----------------------------------------------------------------*/ -/* genIpush - genrate code for pushing this gets a little complex */ +/* genIpush - generate code for pushing */ /*-----------------------------------------------------------------*/ static void genIpush (iCode * ic) { + operand *left=IC_LEFT(ic); + printIc ("genIpush", ic, 0,1,0); + aopOp(left,FALSE,FALSE); + if (AOP_TYPE(left)==AOP_LIT) { + switch (AOP_SIZE(left)) + { + case 1: + emitcode ("mov", "r1l,%s", AOP_NAME(left)[0]); + emitcode ("push", "r1l"); + return; + case 2: + emitcode ("mov", "r1,%s", AOP_NAME(left)[0]); + emitcode ("push", "r1"); + return; + case 3: + emitcode ("mov", "r1l,%s", AOP_NAME(left)[1]); + emitcode ("push", "r1l"); + emitcode ("mov", "r1,%s", AOP_NAME(left)[0]); + emitcode ("push", "r1"); + return; + case 4: + emitcode ("mov", "r1,%s", AOP_NAME(left)[1]); + emitcode ("push", "r1"); + emitcode ("mov", "r1,%s", AOP_NAME(left)[0]); + emitcode ("push", "r1"); + return; + } + } else { + if (AOP_SIZE(left)>2) { + emitcode ("push", "%s", AOP_NAME(left)[1]); + } + emitcode ("push", "%s", AOP_NAME(left)[0]); + } } /*-----------------------------------------------------------------*/ @@ -711,8 +748,37 @@ static void genIpop (iCode * ic) { /* genCall - generates a call statement */ /*-----------------------------------------------------------------*/ static void genCall (iCode * ic) { - emitcode (";", "genCall %s result=%s", OP_SYMBOL(IC_LEFT(ic))->name, + operand *result=IC_RESULT(ic); + + emitcode (";", "genCall(%d) %s result=%s", ic->lineno, + OP_SYMBOL(IC_LEFT(ic))->name, printOp (IC_RESULT(ic))); + emitcode ("call", "%s", OP_SYMBOL(IC_LEFT(ic))->rname); + + /* if we need to assign a result value */ + if (IS_ITEMP (IC_RESULT(ic)) && + OP_SYMBOL (IC_RESULT (ic))->nRegs) { + aopOp(result,FALSE,FALSE); + switch (AOP_SIZE(result)) + { + case 1: + emitcode ("mov", "%s,r0l", AOP_NAME(result)[0]); + return; + case 2: + emitcode ("mov", "%s,r0", AOP_NAME(result)[0]); + return; + case 3: + // generic pointer + emitcode ("mov", "%s,r1l", AOP_NAME(result)[1]); + emitcode ("mov", "%s,r0", AOP_NAME(result)[0]); + return; + case 4: + emitcode ("mov", "%s,r1", AOP_NAME(result)[1]); + emitcode ("mov", "%s,r0", AOP_NAME(result)[0]); + return; + } + bailOut("genCall"); + } } /*-----------------------------------------------------------------*/ @@ -987,14 +1053,6 @@ static iCode *hasInc (operand *op, iCode *ic, int osize) { while (lic) { /* if operand of the form op = op + */ if (lic->op == '+') { - fprintf (stderr, "isOperandEqual(IC_LEFT(lic),op):%d\n", - isOperandEqual(IC_LEFT(lic),op)); - fprintf (stderr, "isOperandEqual(IC_RESULT(lic),op):%d\n", - isOperandEqual(IC_RESULT(lic),op)); - fprintf (stderr, "isOperandLiteral(IC_RIGHT(lic)):%d\n", - isOperandLiteral(IC_RIGHT(lic))); - fprintf (stderr, "operandLitValue(IC_RIGHT(lic)) %f %d\n", - operandLitValue(IC_RIGHT(lic)), isize); if (isOperandEqual(IC_LEFT(lic),op) && //isOperandEqual(IC_RESULT(lic),op) && isOperandLiteral(IC_RIGHT(lic)) && diff --git a/src/xa51/main.c b/src/xa51/main.c index 03aa0cb5..03c72ef3 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -136,18 +136,24 @@ static void _xa51_genXINIT (FILE * of) { static void _xa51_genAssemblerPreamble (FILE * of) { + symbol *mainExists=newSymbol("main", 0); + mainExists->block=0; + fprintf (of, "_errno\tsfr\t0x00; to keep the fp-lib's happy for now\n\n"); - fprintf (of, "\t.area CSEG\t(CODE)\n"); - fprintf (of, "__interrupt_vect:\n"); - fprintf (of, "\t.dw\t0x8f00\n"); - fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n"); - fprintf (of, "\n"); - fprintf (of, "__sdcc_gsinit_startup:\n"); - fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc); - fprintf (of, "\tcall\t_external_startup\n"); - _xa51_genXINIT(of); - fprintf (of, "\tcall\t_main\n"); - fprintf (of, "\treset\t;main should not return\n"); + + if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) { + fprintf (of, "\t.area CSEG\t(CODE)\n"); + fprintf (of, "__interrupt_vect:\n"); + fprintf (of, "\t.dw\t0x8f00\n"); + fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n"); + fprintf (of, "\n"); + fprintf (of, "__sdcc_gsinit_startup:\n"); + fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc); + fprintf (of, "\tcall\t_external_startup\n"); + _xa51_genXINIT(of); + fprintf (of, "\tcall\t_main\n"); + fprintf (of, "\treset\t;main should not return\n"); + } } /* dummy linker for now */ -- 2.30.2