xa51, work in progress
[fw/sdcc] / src / xa51 / main.c
index 9021f599ab0ddaaaf1bd57a99f5d7860c30e2eb1..03c72ef30505de72d3f577507518e6c7e9818df7 100755 (executable)
@@ -31,7 +31,7 @@ static char *_xa51_keywords[] =
   "sfr",
   "sbit",
   "using",
-  //"xdata",
+  "xdata",
   //"_data",
   //"_code",
   //"_generic",
@@ -40,10 +40,15 @@ static char *_xa51_keywords[] =
   //"_pdata",
   //"_idata",
   "_naked",
-  "_overlay",
+  //"_overlay",
   NULL
 };
 
+extern int rewinds;
+void   _xa51_genAssemblerEnd () {
+  //fprintf (stderr, "Did %d rewind%c for c-line in asm comments\n", rewinds,
+  //rewinds==1 ? '\0' : 's');
+}
 
 void xa51_assignRegisters (eBBlock ** ebbs, int count);
 
@@ -52,7 +57,7 @@ static int regParmFlg = 0;    /* determine if we can register a parameter */
 static void
 _xa51_init (void)
 {
-  asm_addTree (&asm_asxxxx_mapping);
+  asm_addTree (&asm_xa_asm_mapping);
 }
 
 static void
@@ -94,6 +99,9 @@ static void
 _xa51_setDefaultOptions (void)
 {
   options.stackAuto=1;
+  options.intlong_rent=1;
+  options.float_rent=1;
+  options.stack_loc=0x100;
 }
 
 static const char *
@@ -104,49 +112,53 @@ _xa51_getRegName (struct regs *reg)
   return "err";
 }
 
-static void
-_xa51_genAssemblerPreamble (FILE * of)
-{
-}
-
 /* Generate interrupt vector table. */
 static int
 _xa51_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
 {
-  return FALSE;
+  return TRUE;
 }
 
 /* Generate code to copy XINIT to XISEG */
 static void _xa51_genXINIT (FILE * of) {
   fprintf (of, ";      _xa51_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, "       mov     r0,#l_XINIT\n");
+  fprintf (of, "       beq     00002$\n");
+  fprintf (of, "       mov     r1,#s_XINIT\n");
+  fprintf (of, "        mov     r2,#s_XISEG\n");
+  fprintf (of, "00001$: movc    r3l,[r1+]\n");
+  fprintf (of, "        mov     [r2+],r3l\n");
+  fprintf (of, "        djnz    r0,00001$\n");
+  fprintf (of, "00002$:\n");
   fprintf (of, ";      _xa51_genXINIT() end\n");
 }
 
+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");
+
+  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 */
+void xa_link(void) {
+}
 
 /* Do CSE estimation */
 static bool cseCostEstimation (iCode *ic, iCode *pdic)
@@ -170,6 +182,7 @@ static bool cseCostEstimation (iCode *ic, iCode *pdic)
     return 1;
 }
 
+#if 0
 /** $1 is always the basename.
     $2 is always the output file.
     $3 varies
@@ -180,11 +193,12 @@ static const char *_linkCmd[] =
 {
   "{bindir}{sep}aslink", "-nf", "$1", NULL
 };
+#endif
 
 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
 static const char *_asmCmd[] =
 {
-  "xa_asm", "$l", "$3", "$1.asm", NULL
+  "xa_asm", "$l", "$3", "$1.xa", NULL
 };
 
 /* Globals */
@@ -194,23 +208,23 @@ PORT xa51_port =
   "xa51",
   "MCU 80C51XA",                       /* Target name */
   {
-    TRUE,                      /* Emit glue around main */
+    FALSE,                     /* Emit glue around main */
     MODEL_LARGE,
     MODEL_LARGE
   },
   {
     _asmCmd,
     NULL,
-    "-plosgffc",               /* Options with debug */
-    "-plosgff",                        /* Options without debug */
+    "",                                /* Options with debug */
+    "",                                /* Options without debug */
     0,
-    ".asm",
+    ".xa",
     NULL                       /* no do_assemble function */
   },
   {
-    _linkCmd,
-    NULL,
+    NULL, //_linkCmd,
     NULL,
+    xa_link,
     ".rel"
   },
   {
@@ -218,19 +232,19 @@ PORT xa51_port =
   },
   {
        /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
-    1, 2, 2, 4, 1, 2, 3, 1, 4, 4
+    1, 2, 2, 4, 2, 2, 3, 1, 4, 4
   },
   {
     "XSEG    (XDATA)",
-    "STACK   (DATA)",
+    "STACK   (XDATA)",
     "CSEG    (CODE)",
     "DSEG    (DATA)",
-    "ISEG    (DATA)",
+    NULL, //"ISEG    (DATA)",
     "XSEG    (XDATA)",
     "BSEG    (BIT)",
-    "RSEG    (DATA)",
+    NULL, //"RSEG    (DATA)",
     "GSINIT  (CODE)",
-    "OSEG    (OVR,DATA)",
+    NULL, //"OSEG    (OVR,XDATA)",
     "GSFINAL (CODE)",
     "HOME    (CODE)",
     "XISEG   (XDATA)", // initialized xdata
@@ -260,20 +274,20 @@ PORT xa51_port =
   _xa51_getRegName,
   _xa51_keywords,
   _xa51_genAssemblerPreamble,
-  NULL,                                /* no genAssemblerEnd */
+  _xa51_genAssemblerEnd,
   _xa51_genIVT,
   _xa51_genXINIT,
   _xa51_reset_regparm,
   _xa51_regparm,
-  NULL,
-  NULL,
-  NULL,
-  FALSE,
+  NULL, // process_pragma()
+  NULL, // getMangledFunctionName()
+  NULL, // hasNativeMulFor()
+  TRUE, // use_dw_for_init
   0,                           /* leave lt */
   0,                           /* leave gt */
-  1,                           /* transform <= to ! > */
-  1,                           /* transform >= to ! < */
-  1,                           /* transform != to !(a == b) */
+  0,                           /* transform <= to ! > */
+  0,                           /* transform >= to ! < */
+  0,                           /* transform != to !(a == b) */
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */
   cseCostEstimation,