xa51, work in progress
[fw/sdcc] / src / xa51 / main.c
index b92ae24c744ef20932871785d01d1cb97541be14..03c72ef30505de72d3f577507518e6c7e9818df7 100755 (executable)
@@ -40,7 +40,7 @@ static char *_xa51_keywords[] =
   //"_pdata",
   //"_idata",
   "_naked",
-  "_overlay",
+  //"_overlay",
   NULL
 };
 
@@ -101,6 +101,7 @@ _xa51_setDefaultOptions (void)
   options.stackAuto=1;
   options.intlong_rent=1;
   options.float_rent=1;
+  options.stack_loc=0x100;
 }
 
 static const char *
@@ -111,23 +112,11 @@ _xa51_getRegName (struct regs *reg)
   return "err";
 }
 
-static void
-_xa51_genAssemblerPreamble (FILE * of)
-{
-  // this needs to be an include file someday
-  fputs ("pswl\tsfr\t0x400\n", of);
-  fputs ("z\tbit\tpswl.0\n", of);
-  fputs ("n\tbit\tpswl.1\n", of);
-  fputs ("v\tbit\tpswl.2\n", of);
-  fputs ("ac\tbit\tpswl.6\n", of);
-  fputs ("cy\tbit\tpswl.7\n", 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 */
@@ -137,13 +126,39 @@ static void _xa51_genXINIT (FILE * of) {
   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, "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)
@@ -167,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
@@ -177,6 +193,7 @@ 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[] =
@@ -191,7 +208,7 @@ PORT xa51_port =
   "xa51",
   "MCU 80C51XA",                       /* Target name */
   {
-    TRUE,                      /* Emit glue around main */
+    FALSE,                     /* Emit glue around main */
     MODEL_LARGE,
     MODEL_LARGE
   },
@@ -205,9 +222,9 @@ PORT xa51_port =
     NULL                       /* no do_assemble function */
   },
   {
-    _linkCmd,
-    NULL,
+    NULL, //_linkCmd,
     NULL,
+    xa_link,
     ".rel"
   },
   {
@@ -219,15 +236,15 @@ PORT xa51_port =
   },
   {
     "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