X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fmain.c;h=29373d19a741c5785e8f400c2aa7ee6012d99824;hb=63177e2f4a9a0cb897997b0da23cf4f5fe6209f4;hp=2e85421e4d71e1c6a64c46fab69bcadc8cef2925;hpb=1e268ec9106bf4b907eff98c705e11689c9dcb64;p=fw%2Fsdcc diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 2e85421e..29373d19 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -39,6 +39,7 @@ static char *_mcs51_keywords[] = "_xdata", "_pdata", "_idata", + "_naked", NULL }; @@ -83,8 +84,7 @@ _mcs51_parseOptions (int *pargc, char **argv, int *i) static void _mcs51_finaliseOptions (void) { - if (options.model == MODEL_LARGE) - { + if (options.model == MODEL_LARGE) { port->mem.default_local_map = xdata; port->mem.default_globl_map = xdata; } @@ -120,6 +120,60 @@ _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) return FALSE; } +/* Generate code to copy XINIT to XISEG */ +static void _mcs51_genXINIT (FILE * of) { + fprintf (of, "; _mcs51_genXINIT() start\n"); + fprintf (of, " mov a,#l_XINIT\n"); + fprintf (of, " orl a,#l_XINIT>>8\n"); + fprintf (of, " jz 00003$\n"); + fprintf (of, " mov a,#s_XINIT\n"); + fprintf (of, " add a,#l_XINIT\n"); + fprintf (of, " mov r1,a\n"); + fprintf (of, " mov a,#s_XINIT>>8\n"); + fprintf (of, " addc a,#l_XINIT>>8\n"); + fprintf (of, " mov r2,a\n"); + fprintf (of, " mov dptr,#s_XINIT\n"); + fprintf (of, " mov r0,#s_XISEG\n"); + fprintf (of, " mov p2,#(s_XISEG >> 8)\n"); + fprintf (of, "00001$: clr a\n"); + fprintf (of, " movc a,@a+dptr\n"); + fprintf (of, " movx @r0,a\n"); + fprintf (of, " inc dptr\n"); + fprintf (of, " inc r0\n"); + fprintf (of, " cjne r0,#0,00002$\n"); + fprintf (of, " inc p2\n"); + fprintf (of, "00002$: mov a,dpl\n"); + fprintf (of, " cjne a,ar1,00001$\n"); + fprintf (of, " mov a,dph\n"); + fprintf (of, " cjne a,ar2,00001$\n"); + fprintf (of, " mov p2,#0xFF\n"); + fprintf (of, "00003$:\n"); + fprintf (of, "; _mcs51_genXINIT() end\n"); +} + + +/* Do CSE estimation */ +static bool cseCostEstimation (iCode *ic, iCode *pdic) +{ + operand *result = IC_RESULT(ic); + sym_link *result_type = operandType(result); + + /* 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 + 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 == '-') { + /* then if they are the same Basic block then ok */ + if (ic->eBBlockNum == pdic->eBBlockNum) return 1; + else return 0; + } + + /* for others it is cheaper to do the cse */ + return 1; +} + /** $1 is always the basename. $2 is always the output file. $3 varies @@ -128,12 +182,13 @@ _mcs51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts) */ static const char *_linkCmd[] = { - "aslink", "-nf", "$1", NULL + "{bindir}{sep}aslink", "-nf", "$1", NULL }; +/* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */ static const char *_asmCmd[] = { - "asx8051", "-plosgffc", "$1.asm", NULL + "asx8051", "$l", "$3", "$1.asm", NULL }; /* Globals */ @@ -149,13 +204,16 @@ PORT mcs51_port = }, { _asmCmd, + NULL, "-plosgffc", /* Options with debug */ "-plosgff", /* Options without debug */ - 0 + 0, + ".asm" }, { _linkCmd, NULL, + NULL, ".rel" }, { @@ -163,7 +221,7 @@ PORT mcs51_port = }, { /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */ - 1, 1, 2, 4, 1, 2, 3, 1, 4, 4 + 1, 2, 2, 4, 1, 2, 3, 1, 4, 4 }, { "XSEG (XDATA)", @@ -177,7 +235,9 @@ PORT mcs51_port = "GSINIT (CODE)", "OSEG (OVR,DATA)", "GSFINAL (CODE)", - "HOME (CODE)", + "HOME (CODE)", + "XISEG (XDATA)", // initialized xdata + "XINIT (CODE)", // a code copy of xiseg NULL, NULL, 1 @@ -187,7 +247,7 @@ PORT mcs51_port = }, /* mcs51 has an 8 bit mul */ { - 1, 0 + 1, -1 }, "_", _mcs51_init, @@ -199,9 +259,12 @@ PORT mcs51_port = _mcs51_keywords, _mcs51_genAssemblerPreamble, _mcs51_genIVT, + _mcs51_genXINIT, _mcs51_reset_regparm, _mcs51_regparm, NULL, + NULL, + NULL, FALSE, 0, /* leave lt */ 0, /* leave gt */ @@ -209,5 +272,8 @@ PORT mcs51_port = 1, /* transform >= to ! < */ 1, /* transform != to !(a == b) */ 0, /* leave == */ + FALSE, /* No array initializer support. */ + cseCostEstimation, + NULL, /* no builtin functions */ PORT_MAGIC };