*** empty log message ***
[fw/sdcc] / src / xa51 / main.c
index 429a2cda3373963830093ee2da71f791c8388d05..8875d3e7b964b4c88d0985e0afca507e54c1dda1 100755 (executable)
@@ -1,9 +1,7 @@
-/** @file main.c
-    xa51 specific general functions.
-
-    Note that mlh prepended _xa51_ on the static functions.  Makes
-    it easier to set a breakpoint using the debugger.
+/* @file main.c
+   xa51 specific general functions.
 */
+
 #include "common.h"
 #include "main.h"
 #include "ralloc.h"
@@ -40,14 +38,14 @@ 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');
+  //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);
@@ -57,7 +55,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
@@ -93,6 +91,10 @@ _xa51_finaliseOptions (void)
 {
   port->mem.default_local_map = istack;
   port->mem.default_globl_map = xdata;
+  if (options.model!=MODEL_PAGE0) {
+    fprintf (stderr, "-mxa51 only supports --model-page0\n");
+    exit (1);
+  }
 }
 
 static void
@@ -101,6 +103,8 @@ _xa51_setDefaultOptions (void)
   options.stackAuto=1;
   options.intlong_rent=1;
   options.float_rent=1;
+  options.stack_loc=0x100;
+  options.data_loc=0;
 }
 
 static const char *
@@ -111,23 +115,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 +129,40 @@ 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;
+
+  if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) {
+    fprintf (of, "\t.area GSINIT\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.b\t_SCR,#0x01\t; page zero mode\n");
+    fprintf (of, "\t.db 0x96,0x48,0x40,0x01\n");
+    fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
+    fprintf (of, "\tcall\t_external_startup\n");
+    _xa51_genXINIT(of);
+    fprintf (of, "\t.area CSEG\t(CODE)\n");
+    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)
@@ -175,13 +194,13 @@ static bool cseCostEstimation (iCode *ic, iCode *pdic)
 */
 static const char *_linkCmd[] =
 {
-  "{bindir}{sep}aslink", "-nf", "$1", NULL
+  "xa_link", "", "$1", NULL
 };
 
 /* $3 is replaced by assembler.debug_opts resp. port->assembler.plain_opts */
 static const char *_asmCmd[] =
 {
-  "xa_asm", "$l", "$3", "$1.xa", NULL
+  "xa_rasm", "$l", "$3", "$1.asm", NULL
 };
 
 /* Globals */
@@ -191,9 +210,9 @@ PORT xa51_port =
   "xa51",
   "MCU 80C51XA",                       /* Target name */
   {
-    TRUE,                      /* Emit glue around main */
-    MODEL_LARGE,
-    MODEL_LARGE
+    FALSE,                     /* Emit glue around main */
+    MODEL_PAGE0,
+    MODEL_PAGE0
   },
   {
     _asmCmd,
@@ -201,7 +220,7 @@ PORT xa51_port =
     "",                                /* Options with debug */
     "",                                /* Options without debug */
     0,
-    ".xa",
+    ".asm",
     NULL                       /* no do_assemble function */
   },
   {
@@ -219,15 +238,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
@@ -239,8 +258,8 @@ PORT xa51_port =
   {
     -1, // stack grows down
     0, // bank overhead NUY
-    6, // isr overhead
-    4, // function call overhead
+    4, // isr overhead, page zero mode
+    2, // function call overhead, page zero mode
     0, // reentrant overhead NUY
     0 // banked overhead NUY
   },
@@ -268,9 +287,9 @@ PORT xa51_port =
   TRUE, // use_dw_for_init
   0,                           /* leave lt */
   0,                           /* leave gt */
-  0,                           /* transform <= to ! > */
-  0,                           /* transform >= to ! < */
-  0,                           /* transform != to !(a == b) */
+  1,                           /* transform <= to ! > */
+  1,                           /* transform >= to ! < */
+  1,                           /* transform != to !(a == b) */
   0,                           /* leave == */
   FALSE,                        /* No array initializer support. */
   cseCostEstimation,