2004-01-13 Vangelis Rokas <vrokas@otenet.gr>
[fw/sdcc] / src / pic16 / main.c
index 71cf8b2b07292b92ec095259b3a614c289eb2083..44f4c13dcb0aa0e00a9a2ae0c4cbbab40152635f 100644 (file)
@@ -63,6 +63,7 @@ static char *_pic16_keywords[] =
   "_xdata",
   "_pdata",
   "_idata",
+  "_naked",
   NULL
 };
 
@@ -117,10 +118,13 @@ _pic16_regparm (sym_link * l)
 }
 
 
+set *absSymSet;
+
 static int
 _process_pragma(const char *sz)
 {
   static const char *WHITE = " \t";
+  
   char *ptr = strtok((char *)sz, WHITE);
 
        if (startsWith (ptr, "maxram")) {
@@ -143,9 +147,29 @@ _process_pragma(const char *sz)
 //             fprintf(stderr, "Initializing stack pointer to 0x%x\n", (int)floatFromVal(constVal(stackPos)));
                stackPosVal = constVal( stackPosS );
                stackPos = (unsigned int)floatFromVal( stackPosVal );
+
+         return 0;
        }
+       
+       if(startsWith(ptr, "code")) {
+         char *symname = strtok((char *)NULL, WHITE);
+         char *location = strtok((char *)NULL, WHITE);
+         absSym *absS;
+         value *addr;
 
-  return 0;
+               absS = Safe_calloc(1, sizeof(absSym));
+               absS->name = Safe_strdup( symname );
+               addr = constVal( location );
+               absS->address = (unsigned int)floatFromVal( addr );
+
+               addSet(&absSymSet, absS);
+               fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
+                       __FILE__, __LINE__, symname, absS->address);
+
+         return 0;
+       }         
+
+  return 1;
 }
 
 #define REP_UDATA      "--preplace-udata-with="
@@ -172,6 +196,8 @@ _process_pragma(const char *sz)
 
 
 extern int pic16_debug_verbose;
+extern int pic16_ralloc_debug;
+extern int pic16_pcode_verbose;
 
 OPTION pic16_optionsTable[]= {
        { 0,    "--pgen-banksel",       &pic16_options.gen_banksel,     "generate BANKSEL assembler directives"},
@@ -183,6 +209,9 @@ OPTION pic16_optionsTable[]= {
        { 0,    STACK_MODEL,    NULL,   "use stack model 'small' (default) or 'large'"},
 
        { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
+       { 0,    "--debug-ralloc",       &pic16_ralloc_debug,    "dump register allocator debug file *.d"},
+       { 0,    "--pcode-verbose",      &pic16_pcode_verbose,   "dump pcode related info"},
+               
        { 0,    REP_UDATA,      NULL,   "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
 
 #if 0
@@ -375,6 +404,8 @@ _pic16_finaliseOptions (void)
        port->mem.default_local_map = data;
        port->mem.default_globl_map = data;
 
+       options.all_callee_saves = 1;           // always callee saves
+
        setMainValue("mcu", pic16_processor_base_name() );
        addSet(&preArgvSet, Safe_strdup("-DMCU={mcu}"));
 }
@@ -473,10 +504,10 @@ _pic16_getRegName (struct regs *reg)
 }
 
 
-#if 0
+#if 1
 static  char *_pic16_mangleFunctionName(char *sz)
 {
-       fprintf(stderr, "mangled function name: %s\n", sz);
+//     fprintf(stderr, "mangled function name: %s\n", sz);
 
   return sz;
 }
@@ -496,17 +527,17 @@ _pic16_genAssemblerPreamble (FILE * of)
        fprintf (of, "\tlist\tp=%s\n",&name[1]);
 
        if(!pic16_options.omit_configw) {
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300001, pic16_getConfigWord(0x300001));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300002, pic16_getConfigWord(0x300002));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300003, pic16_getConfigWord(0x300003));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300005, pic16_getConfigWord(0x300005));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300006, pic16_getConfigWord(0x300006));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300008, pic16_getConfigWord(0x300008));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x300009, pic16_getConfigWord(0x300009));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000a, pic16_getConfigWord(0x30000a));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000b, pic16_getConfigWord(0x30000b));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000c, pic16_getConfigWord(0x30000c));
-               fprintf (of, "\t__config 0x%x,0x%x\n", 0x30000d, pic16_getConfigWord(0x30000d));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300001, pic16_getConfigWord(0x300001));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300002, pic16_getConfigWord(0x300002));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300003, pic16_getConfigWord(0x300003));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300005, pic16_getConfigWord(0x300005));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300006, pic16_getConfigWord(0x300006));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300008, pic16_getConfigWord(0x300008));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x300009, pic16_getConfigWord(0x300009));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000a, pic16_getConfigWord(0x30000a));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000b, pic16_getConfigWord(0x30000b));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000c, pic16_getConfigWord(0x30000c));
+               fprintf (of, "\t__config 0x%x,0x%hhx\n", 0x30000d, pic16_getConfigWord(0x30000d));
        }
        
   fprintf (of, "\tradix dec\n");
@@ -635,7 +666,7 @@ static const char *_linkCmd[] =
  */
 static const char *_asmCmd[] =
 {
-  "gpasm", "-c  -I/usr/local/share/gputils/header", "\"$1.asm\"", NULL
+  "gpasm", "$l", "-c", "\"$1.asm\"", NULL
 
 };
 
@@ -665,7 +696,8 @@ PORT pic16_port =
     _linkCmd,                  /* linker command and arguments */
     NULL,                      /* alternate macro based form */
     NULL,                      /* no do_link function */
-    ".rel"                     /* extension for object files */
+    ".o",                      /* extension for object files */
+    0                          /* no need for linker file */
   },
   {
     _defaultRules
@@ -677,7 +709,7 @@ PORT pic16_port =
     2,         /* int */
     4,         /* long */
     2,         /* ptr */
-    2,         /* fptr, this should be changed to 3 for far pointers (see Microchip) */
+    3,         /* fptr, far pointers (see Microchip) */
     2,         /* gptr */
     1,         /* bit */
     4,         /* float */
@@ -735,7 +767,7 @@ PORT pic16_port =
   _pic16_reset_regparm,
   _pic16_regparm,
   _process_pragma,                             /* process a pragma */
-  NULL,                                //_pic16_mangleFunctionName,                            /* mangles function name */
+  _pic16_mangleFunctionName,                           /* mangles function name */
   _hasNativeMulFor,
   hasExtBitOp,                 /* hasExtBitOp */
   oclsExpense,                 /* oclsExpense */