X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fds390%2Fmain.c;h=d05c2ad08a9a94ec6fec91ee6ba9fbf2c824ed66;hb=8e59bbd8bbe6ea78f0d9bdd1fed4c5cb495ca6d8;hp=211e9dc180239627d96e1b8227fb1b48fe5e8c89;hpb=8c9c17bede2d442a7690c614260ee38e6b40b39a;p=fw%2Fsdcc diff --git a/src/ds390/main.c b/src/ds390/main.c index 211e9dc1..d05c2ad0 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -32,6 +32,8 @@ static char *_ds390_keywords[] = "pdata", "reentrant", "sfr", + "sfr16", + "sfr32", "sbit", "using", "xdata", @@ -58,8 +60,8 @@ static builtins __ds390_builtins[] = { { "__builtin_memcmp_x2x","c",3,{"cx*","cx*","i"}}, /* void __builtin_memcmp_x2x (xdata char *,xdata char *,int) */ { "__builtin_memcmp_c2x","c",3,{"cx*","cp*","i"}}, /* void __builtin_memcmp_c2x (xdata char *,code char *,int) */ { NULL , NULL,0, {NULL}} /* mark end of table */ -}; -void ds390_assignRegisters (eBBlock ** ebbs, int count); +}; +void ds390_assignRegisters (ebbIndex * ebbi); static int regParmFlg = 0; /* determine if we can register a parameter */ @@ -70,15 +72,16 @@ _ds390_init (void) } static void -_ds390_reset_regparm () +_ds390_reset_regparm (void) { regParmFlg = 0; } static int -_ds390_regparm (sym_link * l) +_ds390_regparm (sym_link * l, bool reentrant) { - + if (IS_SPEC(l) && (SPEC_NOUN(l) == V_BIT)) + return 0; if (options.parms_in_bank1 == 0) { /* simple can pass only the first parameter in a register */ if (regParmFlg) @@ -102,7 +105,7 @@ _ds390_regparm (sym_link * l) return 0; } regParmFlg += size ; - return regParmFlg - size + 1; + return regParmFlg - size + 1; } } @@ -145,9 +148,9 @@ _ds390_finaliseOptions (void) port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */ - port->stack.call_overhead += 2; /* This acounts for the extra byte + port->stack.call_overhead += 2; /* This acounts for the extra byte * of return addres on the stack. - * but is ugly. There must be a + * but is ugly. There must be a * better way. */ @@ -161,11 +164,11 @@ _ds390_finaliseOptions (void) } else { if (!options.stack_loc) options.stack_loc = 0x400008; } - + /* generate native code 16*16 mul/div */ - if (options.useAccelerator) + if (options.useAccelerator) port->support.muldiv=2; - else + else port->support.muldiv=1; /* Fixup the memory map for the stack; it is now in @@ -236,8 +239,25 @@ _ds390_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) if (options.model != MODEL_FLAT24) { - /* Let the default code handle it. */ - return FALSE; + fprintf (of, "\tljmp\t__sdcc_gsinit_startup\n"); + + /* now for the other interrupts */ + for (i = 0; i < maxInterrupts; i++) + { + if (interrupts[i]) + { + fprintf (of, "\tljmp\t%s\n", interrupts[i]->rname); + if ( i != maxInterrupts - 1 ) + fprintf (of, "\t.ds\t5\n"); + } + else + { + fprintf (of, "\treti\n"); + if ( i != maxInterrupts - 1 ) + fprintf (of, "\t.ds\t7\n"); + } + } + return TRUE; } fprintf (of, "\tajmp\t__reset_vect\n"); @@ -298,11 +318,11 @@ static bool cseCostEstimation (iCode *ic, iCode *pdic) sym_link *result_type = operandType(result); //sym_link *right_type = (right ? operandType(right) : 0); //sym_link *left_type = (left ? operandType(left) : 0); - + /* if it is a pointer then return ok for now */ if (IC_RESULT(ic) && IS_PTR(result_type)) return 1; - - /* if bitwise | add & subtract then no since mcs51 is pretty good at it + + /* if bitwise | add & subtract then no since mcs51 is pretty good at it so we will cse only if they are local (i.e. both ic & pdic belong to the same basic block */ if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') { @@ -310,7 +330,7 @@ static bool cseCostEstimation (iCode *ic, iCode *pdic) if (ic->eBBlockNum == pdic->eBBlockNum) return 1; else return 0; } - + /* for others it is cheaper to do the cse */ return 1; } @@ -340,7 +360,7 @@ oclsExpense (struct memmap *oclass) { if (IN_FARSPACE(oclass)) return 1; - + return 0; } @@ -348,7 +368,7 @@ static int instructionSize(char *inst, char *op1, char *op2) { int isflat24 = (options.model == MODEL_FLAT24); - + #define ISINST(s) (strncmp(inst, (s), sizeof(s)-1) == 0) #define IS_A(s) (*(s) == 'a' && *(s+1) == '\0') #define IS_C(s) (*(s) == 'c' && *(s+1) == '\0') @@ -357,7 +377,7 @@ instructionSize(char *inst, char *op1, char *op2) /* Based on the current (2003-08-22) code generation for the small library, the top instruction probability is: - + 57% mov/movx/movc 6% push 6% pop @@ -387,7 +407,7 @@ instructionSize(char *inst, char *op1, char *op2) if (IS_A (op2) || IS_Rn (op2) || IS_atRi (op2)) return 2; return 3; } - + if (ISINST ("push")) return 2; if (ISINST ("pop")) return 2; @@ -418,7 +438,7 @@ instructionSize(char *inst, char *op1, char *op2) if (ISINST ("acall")) return 2+isflat24; if (ISINST ("ajmp")) return 2+isflat24; - + if (ISINST ("add") || ISINST ("addc") || ISINST ("subb") || ISINST ("xch")) { if (IS_Rn(op2) || IS_atRi(op2)) return 1; @@ -471,7 +491,7 @@ ds390newAsmLineNode (int currentDPS) aln->regsWritten = NULL; aln->initialized = 0; aln->currentDPS = currentDPS; - + return aln; } @@ -535,7 +555,7 @@ ds390operandCompare (const void *key, const void *member) return strcmp((const char *)key, ((ds390operanddata *)member)->name); } -static void +static void updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS) { ds390operanddata *opdat; @@ -543,7 +563,7 @@ updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS) int regIdx1 = -1; int regIdx2 = -1; int regIdx3 = -1; - + dot = strchr(op, '.'); if (dot) *dot = '\0'; @@ -551,7 +571,7 @@ updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS) opdat = bsearch (op, ds390operandDataTable, sizeof(ds390operandDataTable)/sizeof(ds390operanddata), sizeof(ds390operanddata), ds390operandCompare); - + if (opdat) { regIdx1 = opdat->regIdx1; @@ -572,7 +592,7 @@ updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS) regIdx3 = DPX1_IDX; } } - + if (strchr(optype,'r')) { if (regIdx1 >= 0) @@ -630,9 +650,9 @@ ds390opcodedata; static ds390opcodedata ds390opcodeDataTable[] = { {"acall","j", "", "", ""}, - {"ajmp", "j", "", "", ""}, {"add", "", "w", "rw", "r"}, {"addc", "", "rw", "rw", "r"}, + {"ajmp", "j", "", "", ""}, {"anl", "", "", "rw", "r"}, {"cjne", "j", "w", "r", "r"}, {"clr", "", "", "w", ""}, @@ -674,7 +694,7 @@ static ds390opcodedata ds390opcodeDataTable[] = {"xchd", "", "", "rw", "rw"}, {"xrl", "", "", "rw", "r"}, }; - + static int ds390opcodeCompare (const void *key, const void *member) { @@ -692,9 +712,9 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) ds390opcodedata *opdat; aln->initialized = 1; - + p = ln->line; - + while (*p && isspace(*p)) p++; for (op = inst, opsize=1; *p; p++) { @@ -708,7 +728,7 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) if (*p == ';' || *p == ':' || *p == '=') return aln; - + while (*p && isspace(*p)) p++; if (*p == '=') return aln; @@ -719,7 +739,7 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) *op++ = tolower(*p), opsize++; } *op = '\0'; - + if (*p == ',') p++; for (op = op2, opsize=1; *p && *p != ','; p++) { @@ -796,7 +816,8 @@ static const char *_linkCmd[] = "aslink", "-nf", "\"$1\"", NULL }; -/* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ static const char *_asmCmd[] = +/* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ +static const char *_asmCmd[] = { "asx8051", "$l", "$3", "\"$1.asm\"", NULL }; @@ -840,12 +861,17 @@ PORT ds390_port = /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */ 1, 2, 2, 4, 1, 2, 3, 1, 4, 4 }, + + /* tags for generic pointers */ + { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */ + { "XSEG (XDATA)", "STACK (DATA)", "CSEG (CODE)", "DSEG (DATA)", "ISEG (DATA)", + "PSEG (PAG,XDATA)", "XSEG (XDATA)", "BSEG (BIT)", "RSEG (DATA)", @@ -855,6 +881,7 @@ PORT ds390_port = "HOME (CODE)", "XISEG (XDATA)", // initialized xdata "XINIT (CODE)", // a code copy of xiseg + "CONST (CODE)", // const_name - const data (code or not) NULL, NULL, 1 @@ -867,10 +894,22 @@ PORT ds390_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, + { + 255/4, /* maxCount */ + 4, /* sizeofElement */ + {8,12,20}, /* sizeofMatchJump[] */ + {10,14,22}, /* sizeofRangeCompare[] */ + 4, /* sizeofSubtract */ + 7, /* sizeofDispatch */ + }, "_", _ds390_init, _ds390_parseOptions, NULL, + NULL, _ds390_finaliseOptions, _ds390_setDefaultOptions, ds390_assignRegisters, @@ -936,31 +975,31 @@ static void _tininative_finaliseOptions (void) } port->s.fptr_size = 3; port->s.gptr_size = 4; - + port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */ - - port->stack.call_overhead += 2; /* This acounts for the extra byte + + port->stack.call_overhead += 2; /* This acounts for the extra byte * of return addres on the stack. - * but is ugly. There must be a + * but is ugly. There must be a * better way. */ - + port->mem.default_local_map = xdata; port->mem.default_globl_map = xdata; - + if (!options.stack10bit) { options.stack10bit = 1; fprintf(stderr,"TININative supports only stack10bit \n"); } - + if (!options.stack_loc) options.stack_loc = 0x400008; - + /* generate native code 16*16 mul/div */ - if (options.useAccelerator) + if (options.useAccelerator) port->support.muldiv=2; - else + else port->support.muldiv=1; - + /* Fixup the memory map for the stack; it is now in * far space and requires a FPOINTER to access it. */ @@ -969,9 +1008,9 @@ static void _tininative_finaliseOptions (void) options.cc_only =1; } -static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) +static int _tininative_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) { - return 1; + return TRUE; } static void _tininative_genAssemblerPreamble (FILE * of) { @@ -1020,7 +1059,7 @@ static void _tininative_do_assemble (set *asmOptions) buildCmdLine(buffer,a390Cmd,dstFileName,NULL,NULL,asmOptions); if (my_system(buffer)) { exit(1); - } + } } /* list of key words used by TININative */ @@ -1095,7 +1134,7 @@ static builtins __tininative_builtins[] = { { "System_GetCurrentProcessId","c",0,{NULL}}, /* char System_GetCurrentProcessId() */ { "System_GetCurrentThreadId","c",0,{NULL}}, /* char System_GetCurrentThreadId() */ { NULL , NULL,0, {NULL}} /* mark end of table */ -}; +}; static const char *_a390Cmd[] = { @@ -1139,21 +1178,26 @@ PORT tininative_port = /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */ 1, 2, 2, 4, 1, 3, 3, 1, 4, 4 }, + /* tags for generic pointers */ + { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */ + { "XSEG (XDATA)", "STACK (DATA)", "CSEG (CODE)", "DSEG (DATA)", "ISEG (DATA)", + "PSEG (PAG,XDATA)", "XSEG (XDATA)", "BSEG (BIT)", "RSEG (DATA)", "GSINIT (CODE)", "OSEG (OVR,DATA)", "GSFINAL (CODE)", - "HOME (CODE)", + "HOME (CODE)", NULL, NULL, + "CONST (CODE)", // const_name - const data (code or not) NULL, NULL, 1 @@ -1166,10 +1210,22 @@ PORT tininative_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, + { + 255/4, /* maxCount */ + 4, /* sizeofElement */ + {8,12,20}, /* sizeofMatchJump[] */ + {10,14,22}, /* sizeofRangeCompare[] */ + 4, /* sizeofSubtract */ + 7, /* sizeofDispatch */ + }, "", _tininative_init, _ds390_parseOptions, NULL, + NULL, _tininative_finaliseOptions, _tininative_setDefaultOptions, ds390_assignRegisters, @@ -1209,7 +1265,7 @@ _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) { /* We can't generate a static IVT, since the boot rom creates one * for us in rom_init. - * + * * we must patch it as part of the C startup. */ fprintf (of, ";\tDS80C400 IVT must be generated at runtime.\n"); @@ -1220,7 +1276,7 @@ _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return TRUE; } - + static void _ds400_finaliseOptions (void) @@ -1232,7 +1288,7 @@ _ds400_finaliseOptions (void) // hackhack: we're a superset of the 390. addSet(&preArgvSet, Safe_strdup("-DSDCC_ds390")); addSet(&preArgvSet, Safe_strdup("-D__ds390")); - + /* Hack-o-matic: if we are using the flat24 model, * adjust pointer sizes. */ @@ -1256,9 +1312,9 @@ _ds400_finaliseOptions (void) port->stack.isr_overhead += 2; /* Will save dpx on ISR entry. */ - port->stack.call_overhead += 2; /* This acounts for the extra byte + port->stack.call_overhead += 2; /* This acounts for the extra byte * of return addres on the stack. - * but is ugly. There must be a + * but is ugly. There must be a * better way. */ @@ -1273,11 +1329,11 @@ _ds400_finaliseOptions (void) if (!options.stack_loc) options.stack_loc = 0xffdc00; // assumes IDM1:0 = 1:0, CMA = 1. } - + /* generate native code 16*16 mul/div */ - if (options.useAccelerator) + if (options.useAccelerator) port->support.muldiv=2; - else + else port->support.muldiv=1; /* Fixup the memory map for the stack; it is now in @@ -1289,10 +1345,10 @@ _ds400_finaliseOptions (void) if (options.parms_in_bank1) { addSet(&preArgvSet, Safe_strdup("-DSDCC_PARMS_IN_BANK1")); } - + // the DS400 rom calling interface uses register bank 3. RegBankUsed[3] = 1; - + } /* MODEL_FLAT24 */ } @@ -1353,12 +1409,17 @@ PORT ds400_port = /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */ 1, 2, 2, 4, 1, 2, 3, 1, 4, 4 }, + + /* tags for generic pointers */ + { 0x00, 0x40, 0x60, 0x80 }, /* far, near, xstack, code */ + { "XSEG (XDATA)", "STACK (DATA)", "CSEG (CODE)", "DSEG (DATA)", "ISEG (DATA)", + "PSEG (PAG,XDATA)", "XSEG (XDATA)", "BSEG (BIT)", "RSEG (DATA)", @@ -1368,6 +1429,7 @@ PORT ds400_port = "HOME (CODE)", "XISEG (XDATA)", // initialized xdata "XINIT (CODE)", // a code copy of xiseg + "CONST (CODE)", // const_name - const data (code or not) NULL, NULL, 1 @@ -1380,10 +1442,22 @@ PORT ds400_port = { 2, -1 }, + { + ds390_emitDebuggerSymbol + }, + { + 255/4, /* maxCount */ + 4, /* sizeofElement */ + {8,12,20}, /* sizeofMatchJump[] */ + {10,14,22}, /* sizeofRangeCompare[] */ + 4, /* sizeofSubtract */ + 7, /* sizeofDispatch */ + }, "_", _ds390_init, _ds390_parseOptions, NULL, + NULL, _ds400_finaliseOptions, _ds390_setDefaultOptions, ds390_assignRegisters,