X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fds390%2Fmain.c;h=7f735daae2c767b140325effde37255bc5fdfd26;hb=c2f2abbf9d58d7f0def3509779547f50ade2e2ab;hp=556447e12d21ebcfa77b472b90baa5183ba98a6d;hpb=7cafa742776543fdfa27fda1258ce8a8d64c7c9c;p=fw%2Fsdcc diff --git a/src/ds390/main.c b/src/ds390/main.c index 556447e1..7f735daa 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 @@ -195,30 +198,36 @@ _ds390_getRegName (struct regs *reg) return "err"; } +extern char * iComments2; + static void _ds390_genAssemblerPreamble (FILE * of) { + fputs (iComments2, of); + fputs ("; CPU specific extensions\n",of); + fputs (iComments2, of); + if (options.model == MODEL_FLAT24) fputs (".flat24 on\t\t; 24 bit flat addressing\n", of); - fputs ("dpx = 0x93\t\t; dpx register unknown to assembler\n", of); - fputs ("dps = 0x86\t\t; dps register unknown to assembler\n", of); - fputs ("dpl1 = 0x84\t\t; dpl1 register unknown to assembler\n", of); - fputs ("dph1 = 0x85\t\t; dph1 register unknown to assembler\n", of); - fputs ("dpx1 = 0x95\t\t; dpx1 register unknown to assembler\n", of); - fputs ("ap = 0x9C\t\t; ap register unknown to assembler\n", of); - fputs ("_ap = 0x9C\t\t; _ap register unknown to assembler\n", of); - fputs ("mcnt0 = 0xD1\t\t; mcnt0 register unknown to assembler\n", of); - fputs ("mcnt1 = 0xD2\t\t; mcnt1 register unknown to assembler\n", of); - fputs ("ma = 0xD3\t\t; ma register unknown to assembler\n", of); - fputs ("mb = 0xD4\t\t; mb register unknown to assembler\n", of); - fputs ("mc = 0xD5\t\t; mc register unknown to assembler\n", of); - fputs ("F1 = 0xD1\t\t; F1 user flag unknown to assembler\n", of); - fputs ("esp = 0x9B\t\t; ESP user flag unknown to assembler\n", of); + fputs ("dpl1\t=\t0x84\n", of); + fputs ("dph1\t=\t0x85\n", of); + fputs ("dps\t=\t0x86\n", of); + fputs ("dpx\t=\t0x93\n", of); + fputs ("dpx1\t=\t0x95\n", of); + fputs ("esp\t=\t0x9B\n", of); + fputs ("ap\t=\t0x9C\n", of); + fputs ("_ap\t=\t0x9C\n", of); + fputs ("mcnt0\t=\t0xD1\n", of); + fputs ("mcnt1\t=\t0xD2\n", of); + fputs ("ma\t=\t0xD3\n", of); + fputs ("mb\t=\t0xD4\n", of); + fputs ("mc\t=\t0xD5\n", of); + fputs ("F1\t=\t0xD1\t; user flag\n", of); if (options.parms_in_bank1) { int i ; for (i=0; i < 8 ; i++ ) - fprintf (of,"b1_%d = 0x%x \n",i,8+i); + fprintf (of,"b1_%d\t=\t0x%02X\n",i,8+i); } } @@ -230,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"); @@ -292,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 == '-') { @@ -304,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; } @@ -334,7 +360,7 @@ oclsExpense (struct memmap *oclass) { if (IN_FARSPACE(oclass)) return 1; - + return 0; } @@ -342,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') @@ -351,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 @@ -381,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; @@ -412,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; @@ -465,7 +491,7 @@ ds390newAsmLineNode (int currentDPS) aln->regsWritten = NULL; aln->initialized = 0; aln->currentDPS = currentDPS; - + return aln; } @@ -529,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; @@ -537,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'; @@ -545,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; @@ -566,7 +592,7 @@ updateOpRW (asmLineNode *aln, char *op, char *optype, int currentDPS) regIdx3 = DPX1_IDX; } } - + if (strchr(optype,'r')) { if (regIdx1 >= 0) @@ -624,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", ""}, @@ -668,7 +694,7 @@ static ds390opcodedata ds390opcodeDataTable[] = {"xchd", "", "", "rw", "rw"}, {"xrl", "", "", "rw", "r"}, }; - + static int ds390opcodeCompare (const void *key, const void *member) { @@ -681,14 +707,14 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) asmLineNode *aln = ds390newAsmLineNode(currentDPS); char *op, op1[256], op2[256]; int opsize; - const char *p; + const unsigned char *p; char inst[8]; ds390opcodedata *opdat; aln->initialized = 1; - + p = ln->line; - + while (*p && isspace(*p)) p++; for (op = inst, opsize=1; *p; p++) { @@ -702,7 +728,7 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) if (*p == ';' || *p == ':' || *p == '=') return aln; - + while (*p && isspace(*p)) p++; if (*p == '=') return aln; @@ -713,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++) { @@ -790,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,6 +867,7 @@ PORT ds390_port = "CSEG (CODE)", "DSEG (DATA)", "ISEG (DATA)", + "PSEG (PAG,XDATA)", "XSEG (XDATA)", "BSEG (BIT)", "RSEG (DATA)", @@ -849,6 +877,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 @@ -861,10 +890,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, @@ -874,6 +915,7 @@ PORT ds390_port = NULL, /* no genAssemblerEnd */ _ds390_genIVT, _ds390_genXINIT, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL, @@ -929,31 +971,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. */ @@ -962,9 +1004,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) { @@ -1013,7 +1055,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 */ @@ -1088,7 +1130,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[] = { @@ -1138,15 +1180,17 @@ PORT tininative_port = "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 @@ -1159,10 +1203,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, @@ -1172,6 +1228,7 @@ PORT tininative_port = _tininative_genAssemblerEnd, _tininative_genIVT, NULL, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL, @@ -1201,7 +1258,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"); @@ -1212,7 +1269,7 @@ _ds400_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return TRUE; } - + static void _ds400_finaliseOptions (void) @@ -1224,7 +1281,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. */ @@ -1248,9 +1305,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. */ @@ -1265,11 +1322,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 @@ -1281,15 +1338,13 @@ _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 */ } -extern char * iComments2; - static void _ds400_generateRomDataArea(FILE *fp, bool isMain) { /* Only do this for the file containing main() */ @@ -1353,6 +1408,7 @@ PORT ds400_port = "CSEG (CODE)", "DSEG (DATA)", "ISEG (DATA)", + "PSEG (PAG,XDATA)", "XSEG (XDATA)", "BSEG (BIT)", "RSEG (DATA)", @@ -1362,6 +1418,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 @@ -1374,10 +1431,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, @@ -1387,6 +1456,7 @@ PORT ds400_port = NULL, /* no genAssemblerEnd */ _ds400_genIVT, _ds390_genXINIT, + NULL, /* genInitStartup */ _ds390_reset_regparm, _ds390_regparm, NULL,