2004-01-16 Vangelis Rokas <vrokas@otenet.gr>
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 16 Jan 2004 15:06:35 +0000 (15:06 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 16 Jan 2004 15:06:35 +0000 (15:06 +0000)
* src/SDCCmain.c (linkEdit): variable $3 of the linker command is
loaded with the linker search paths (-L arguments) and the libraries
to be linked with the current source (-l arguments). Changes
currently will affect only the pic16 port.
* src/pic16/main.c (_pic16_finaliseOptions): add to the linker
include path the port specific paths and port specific libraries,
* gplink command now contains the $3 argument,
* src/pic16/device.h,
* src/pic16/device.c,: structure PIC_device is made public and
renamed to PIC16_device, the same for variable Pics which is renamed
to Pics16. Updated all references to them.
* src/pic16/glue.c (pic16glue): corrected bug with code
initialization which bypassed the variable initializations block.

* device/lib/pic16/Makefile.rules: removed --penable-stack from
COMPILE_FLAGS and added the --nostdinc option

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3137 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCmain.c
src/pic16/device.c
src/pic16/device.h
src/pic16/gen.c
src/pic16/glue.c
src/pic16/main.c
src/pic16/pcode.c

index 6804100c4c3482c93608cd20261200f36bc59411..566c547f20fa0256e5a63b2bece4631b91c60fae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2004-01-16 Vangelis Rokas <vrokas@otenet.gr>
+
+       * src/SDCCmain.c (linkEdit): variable $3 of the linker command is
+       loaded with the linker search paths (-L arguments) and the libraries
+       to be linked with the current source (-l arguments). Changes
+       currently will affect only the pic16 port.
+       * src/pic16/main.c (_pic16_finaliseOptions): add to the linker
+       include path the port specific paths and port specific libraries,
+       * gplink command now contains the $3 argument,
+       * src/pic16/device.h,
+       * src/pic16/device.c,: structure PIC_device is made public and
+       renamed to PIC16_device, the same for variable Pics which is renamed
+       to Pics16. Updated all references to them.
+       * src/pic16/glue.c (pic16glue): corrected bug with code
+       initialization which bypassed the variable initializations block.
+       
+       * device/lib/pic16/Makefile.rules: removed --penable-stack from
+       COMPILE_FLAGS and added the --nostdinc option
+
 2004-01-15 Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * device/include/mc68hc908jb8.h: Register defs for another member
index 3eeddd1a99274182cc0fec407ce52b460bf1e1bc..59f2763287bb8bbf8e5a5e669407d8d992dd003e 100644 (file)
@@ -1573,9 +1573,18 @@ linkEdit (char **envp)
   if (port->linker.cmd)
     {
       char buffer2[PATH_MAX];
+      set *libSet=NULL;
 
-      /* VR 030517 - gplink needs linker options to set the linker script,*/
-      buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, NULL, linkOptionsSet);
+      if(TARGET_IS_PIC16) {
+         /* use $3 to set the linker include directories */
+         libSet = appendStrSet(libDirsSet, "-I\"", "\"");
+
+         /* now add the libraries from command line */
+         mergeSets(&libSet, libFilesSet);
+      }
+      
+      buildCmdLine (buffer2, port->linker.cmd, dstFileName, scratchFileName, (libSet?joinStrSet(libSet):NULL), linkOptionsSet);
+      if(libSet)deleteSet(&libSet);
 
       buildCmdLine2 (buffer, sizeof(buffer), buffer2);
     }
index 841742faa14736d93d50ec8fedd4af54e5252ccd..df8f3367495d0147d49ff74d8ed4e17edb0e7645 100644 (file)
@@ -45,7 +45,7 @@
 #define STRCASECMP strcasecmp
 #endif
 
-static PIC_device Pics[] = {
+static PIC16_device Pics16[] = {
   {
     {"p18f242", "18f242", "pic18f242", "f242"},                // aliases
     (memRange *)NULL,                                  // ram memory map
@@ -202,14 +202,11 @@ static PIC_device Pics[] = {
 
 };
 
-static int num_of_supported_PICS = sizeof(Pics)/sizeof(PIC_device);
+static int num_of_supported_PICS = sizeof(Pics16)/sizeof(PIC16_device);
 
 #define DEFAULT_PIC "452"
 
-static PIC_device *pic=NULL;
-
-//AssignedMemory *pic16_finalMapping=NULL;
-//int pic16_finalMappingSize=0;
+PIC16_device *pic16=NULL;
 
 #define DEFAULT_CONFIG_BYTE 0xff
 
@@ -265,85 +262,21 @@ extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, i
 void pic16_setMaxRAM(int size)
 {
   regs * reg;
-  pic->maxRAMaddress = size;
-  stackPos = pic->RAMsize-1;
-
-       reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "stack", 1, 0, NULL);
-       addSet(&pic16_fix_udata, reg);
-
-  if (pic->maxRAMaddress < 0) {
-    fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
-           pic->maxRAMaddress);
-    return;
-  }
-
-//  pic16_finalMapping = Safe_calloc(1+pic->maxRAMaddress,
-//                          sizeof(AssignedMemory));
-
-  /* Now initialize the pic16_finalMapping array */
-
-//  for(i=0; i<=pic->maxRAMaddress; i++) {
-//    pic16_finalMapping[i].reg = NULL;
-//    pic16_finalMapping[i].isValid = 0;
-//  }
-}
-
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-#if 0
-int pic16_isREGinBank(regs *reg, int bank)
-{
-
-  if(!reg || !pic)
-    return 0;
-
-  if(pic16_finalMapping[reg->address].bank == bank)
-    return 1;
-
-  return 0;
-}
-#endif
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-int pic16_REGallBanks(regs *reg)
-{
-
-  if(!reg || !pic)
-    return 0;
-
-  if ((int)reg->address > pic->maxRAMaddress)
-    return 0;
-
-  return 1;
+  pic16->maxRAMaddress = size;
+  stackPos = pic16->RAMsize-1;
 
-}
 
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-
-/*
- *  pic16_dump_map -- debug stuff
- */
-#if 0
-void pic16_dump_map(void)
-{
-  int i;
-
-  for(i=0; i<=pic->maxRAMaddress; i++) {
-    //fprintf(stdout , "addr 0x%02x is %s\n", i, ((pic16_finalMapping[i].isValid) ? "valid":"invalid"));
-
-    if(pic16_finalMapping[i].isValid) {
-      fprintf(stderr,"addr: 0x%02x",i);
-      if(pic16_finalMapping[i].isSFR)
-       fprintf(stderr," isSFR");
-      if(pic16_finalMapping[i].reg) 
-       fprintf( stderr, "  reg %s", pic16_finalMapping[i].reg->name);
-      fprintf(stderr, "\n");
-    }
-  }
+       if(USE_STACK) {
+               reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "stack", 1, 0, NULL);
+               addSet(&pic16_fix_udata, reg);
+       }
 
+       if (pic16->maxRAMaddress < 0) {
+               fprintf(stderr, "invalid \"#pragma maxram 0x%x\" setting\n",
+                       pic16->maxRAMaddress);
+         return;
+       }
 }
-#endif
 
 extern char *iComments2;
 
@@ -439,7 +372,7 @@ void pic16_list_valid_pics(int ncols, int list_alias)
   int i,j,k,l;
 
   if(list_alias)
-    list_alias = sizeof(Pics[0].name) / sizeof(Pics[0].name[0]);
+    list_alias = sizeof(Pics16[0].name) / sizeof(Pics16[0].name[0]);
 
   /* decrement the column number if it's greater than zero */
   ncols = (ncols > 1) ? ncols-1 : 4;
@@ -447,7 +380,7 @@ void pic16_list_valid_pics(int ncols, int list_alias)
   /* Find the device with the longest name */
   for(i=0,longest=0; i<num_of_supported_PICS; i++) {
     for(j=0; j<=list_alias; j++) {
-      k = strlen(Pics[i].name[j]);
+      k = strlen(Pics16[i].name[j]);
       if(k>longest)
        longest = k;
     }
@@ -459,9 +392,9 @@ void pic16_list_valid_pics(int ncols, int list_alias)
     j = 0;
     do {
 
-      fprintf(stderr,"%s", Pics[i].name[j]);
+      fprintf(stderr,"%s", Pics16[i].name[j]);
       if(col<ncols) {
-       l = longest + 2 - strlen(Pics[i].name[j]);
+       l = longest + 2 - strlen(Pics16[i].name[j]);
        for(k=0; k<l; k++)
          fputc(' ',stderr);
 
@@ -483,7 +416,7 @@ void pic16_list_valid_pics(int ncols, int list_alias)
 /*-----------------------------------------------------------------*
  *  
  *-----------------------------------------------------------------*/
-PIC_device *pic16_find_device(char *name)
+PIC16_device *pic16_find_device(char *name)
 {
 
   int i,j;
@@ -494,8 +427,8 @@ PIC_device *pic16_find_device(char *name)
   for(i = 0; i<num_of_supported_PICS; i++) {
 
     for(j=0; j<PROCESSOR_NAMES; j++)
-      if(!STRCASECMP(Pics[i].name[j], name) )
-       return &Pics[i];
+      if(!STRCASECMP(Pics16[i].name[j], name) )
+       return &Pics16[i];
   }
 
   /* not found */
@@ -507,9 +440,9 @@ PIC_device *pic16_find_device(char *name)
  *-----------------------------------------------------------------*/
 void pic16_init_pic(char *pic_type)
 {
-       pic = pic16_find_device(pic_type);
+       pic16 = pic16_find_device(pic_type);
 
-       if(!pic) {
+       if(!pic16) {
                if(pic_type)
                        fprintf(stderr, "'%s' was not found.\n", pic_type);
                else
@@ -530,7 +463,7 @@ void pic16_init_pic(char *pic_type)
  *-----------------------------------------------------------------*/
 int pic16_picIsInitialized(void)
 {
-  if(pic && pic->maxRAMaddress > 0)
+  if(pic16 && pic16->maxRAMaddress > 0)
     return 1;
 
   return 0;
@@ -543,40 +476,13 @@ int pic16_picIsInitialized(void)
 char *pic16_processor_base_name(void)
 {
 
-  if(!pic)
+  if(!pic16)
     return NULL;
 
-  return pic->name[0];
+  return pic16->name[0];
 }
 
 
-#if 0
-/*-----------------------------------------------------------------*
- *-----------------------------------------------------------------*/
-static int validAddress(int address, int reg_size)
-{
-  int i;
-
-#if 0
-  if (pic->maxRAMaddress < 0) {
-    fprintf(stderr, "missing \"#pragma maxram\" setting\n");
-    return 0;
-  }
-//  fprintf(stderr, "validAddress: Checking 0x%04x (max=0x%04x) (reg_size = %d)\n",address, pic->maxRAMaddress, reg_size);
-  if(address > pic->maxRAMaddress)
-    return 0;
-
-  for (i=0; i<reg_size; i++)
-    if(!pic16_finalMapping[address + i].isValid || 
-       pic16_finalMapping[address+i].reg ||
-       pic16_finalMapping[address+i].isSFR )
-      return 0;
-#endif
-
-  return 1;
-}
-#endif
-
 void checkAddReg(set **set, regs *reg)
 {
   regs *tmp;
index 9e3d115136ddd996e557a3d1e9cbc0236e56e245..5ec7798657330618ab4ed53670b774e9edf23e71 100644 (file)
@@ -82,7 +82,7 @@ typedef struct AssignedMemory {
 
 #define PROCESSOR_NAMES    4
 /* Processor unique attributes */
-typedef struct PIC_device {
+typedef struct PIC16_device {
   char *name[PROCESSOR_NAMES];/* aliases for the processor name */
 
   memRange *ram;              /* RAM memory map */
@@ -92,7 +92,7 @@ typedef struct PIC_device {
   int bankMask;               /* Bitmask that is ANDed with address to extract banking bits */
   int RAMsize;               /* size of Data RAM - VR 031120 */
   int extMIface;               /* device has external memory interface */
-} PIC_device;
+} PIC16_device;
 
 /* Given a pointer to a register, this macro returns the bank that it is in */
 #define REG_ADDR(r)        ((r)->isBitField ? (((r)->address)>>3) : (r)->address)
@@ -117,7 +117,7 @@ typedef struct {
 
 
 extern pic16_options_t pic16_options;
-
+extern PIC16_device *pic16;
 
 /****************************************/
 void pic16_assignConfigWordValue(int address, int value);
index 1f13393251bf1166da7bbd6cfa9dc64f711c2d96..5167f5dcf60e46d8e7959ac4d48423cc233735e2 100644 (file)
@@ -10332,6 +10332,7 @@ void genpic16Code (iCode *lic)
        
        if(options.iCodeInAsm) {
                /* insert here code to print iCode as comment */
+               pic16_emitcomment("; ic:%d: %s", ic->seq, printILine(ic));
        }
        
        /* if the result is marked as
index ba5703f4ad1de3767c3cfb9829525a15af01f0d0..f02dd928d0897273c1e7ef4c682918abdd723c82 100644 (file)
@@ -1004,10 +1004,16 @@ pic16glue ()
        fprintf (asmFile, ";\t.area %s\n", port->mem.post_static_name);
        fprintf (asmFile, ";\t.area %s\n", port->mem.static_name);
 #endif
+
+#if 0
        /* copy over code */
        fprintf (asmFile, "%s", iComments2);
        fprintf (asmFile, "\tcode\n");
        fprintf (asmFile, "%s", iComments2);
+#endif
+
+       fprintf(asmFile, "; A code from now on!\n");
+       pic16_copypCode(asmFile, 'A');
 
 
        if(mainf && IFFUNC_HASBODY(mainf->type)) {
@@ -1030,28 +1036,24 @@ pic16glue ()
 
 //     copyFile (stderr, code->oFile);
 
-
-       if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) {
-               fprintf (asmFile,"\tgoto\t__sdcc_program_startup\t;VR2\n");
-       }
-
-
        fprintf(asmFile, "; I code from now on!\n");
        pic16_copypCode(asmFile, 'I');
 
-       fprintf(asmFile, "; A code from now on!\n");
-       pic16_copypCode(asmFile, 'A');
-
-       
-       if(pic16_debug_verbose)
+//     if(pic16_debug_verbose)
                fprintf(asmFile, "; dbName from now on!\n");
        pic16_copypCode(asmFile, statsg->dbName);
 
-       if(pic16_debug_verbose)
+
+       if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type)) {
+               fprintf (asmFile,"\tgoto\t__sdcc_program_startup\t;VR2\n");
+       }
+       
+
+//     if(pic16_debug_verbose)
                fprintf(asmFile, "; X code from now on!\n");
        pic16_copypCode(asmFile, 'X');
 
-       if(pic16_debug_verbose)
+//     if(pic16_debug_verbose)
                fprintf(asmFile, "; M code from now on!\n");
        pic16_copypCode(asmFile, 'M');
 
index 44f4c13dcb0aa0e00a9a2ae0c4cbbab40152635f..ef3227fced02770f8b78ee16181927576b1eb3b6 100644 (file)
@@ -398,9 +398,19 @@ _pic16_parseOptions (int *pargc, char **argv, int *i)
   return FALSE;
 }
 
+extern set *includeDirsSet;
+extern set *dataDirsSet;
+extern set *libFilesSet;
+
 static void
 _pic16_finaliseOptions (void)
 {
+  char pic16incDir[512];
+  char pic16libDir[512];
+  set *pic16incDirsSet;
+  set *pic16libDirsSet;
+  char devlib[512];
+
        port->mem.default_local_map = data;
        port->mem.default_globl_map = data;
 
@@ -408,6 +418,25 @@ _pic16_finaliseOptions (void)
 
        setMainValue("mcu", pic16_processor_base_name() );
        addSet(&preArgvSet, Safe_strdup("-DMCU={mcu}"));
+
+       sprintf(pic16incDir, "%s/pic16", INCLUDE_DIR_SUFFIX);
+       sprintf(pic16libDir, "%s/pic16", LIB_DIR_SUFFIX);
+
+       if(!options.nostdinc) {
+               /* setup pic16 include directory */
+               pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+               mergeSets(&includeDirsSet, pic16incDirsSet);
+       }
+       
+       if(!options.nostdlib) {
+               /* setup pic16 library directory */
+               pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
+               mergeSets(&libDirsSet, pic16libDirsSet);
+       
+               /* now add the library for the device */
+               sprintf(devlib, "%s.lib", pic16->name[2]);
+               addSet(&libFilesSet, Safe_strdup(devlib));
+       }
 }
 
 
@@ -651,22 +680,26 @@ oclsExpense (struct memmap *oclass)
 
 /** $1 is always the basename.
     $2 is always the output file.
-    $3 varies
+    $3 -L path and -l libraries
     $l is the list of extra options that should be there somewhere...
     MUST be terminated with a NULL.
 */
 static const char *_linkCmd[] =
 {
-  "gplink", "\"$1.o\"", "-o $1", "$l", NULL
+  "gplink", "$3", "\"$1.o\"", "-o $1", "$l", NULL
 };
 
-/* Sigh. This really is not good. For now, I recommend:
- * sdcc -S -mpic16 file.c
- * the -S option does not compile or link
- */
+
+
+/** $1 is always the basename.
+    $2 is always the output file.
+    $3 varies (nothing currently)
+    $l is the list of extra options that should be there somewhere...
+    MUST be terminated with a NULL.
+*/
 static const char *_asmCmd[] =
 {
-  "gpasm", "$l", "-c", "\"$1.asm\"", NULL
+  "gpasm", "$l", "$3", "-c", "\"$1.asm\"", NULL
 
 };
 
index f5952a7253d3e3633534230f72733472449aa50e..b05aaf59a9d30bc4572edf641485f1dee8877b5e 100644 (file)
@@ -3602,14 +3602,16 @@ pCodeOp *pic16_newpCodeOpRegFromStr(char *name)
   pCodeOp *pcop;
   regs *r;
 
-  pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
-  PCOR(pcop)->r = r = pic16_allocRegByName(name, 1);
-  PCOR(pcop)->rIdx = PCOR(pcop)->r->rIdx;
-  pcop->type = PCOR(pcop)->r->pc_type;
-  pcop->name = PCOR(pcop)->r->name;
-
-  fprintf(stderr, "%s:%d %s allocates register %s rIdx:0x%02x\n",
-       __FILE__, __LINE__, __FUNCTION__, r->name, r->rIdx);
+       pcop = Safe_calloc(1,sizeof(pCodeOpReg) );
+       PCOR(pcop)->r = r = pic16_allocRegByName(name, 1);
+       PCOR(pcop)->rIdx = PCOR(pcop)->r->rIdx;
+       pcop->type = PCOR(pcop)->r->pc_type;
+       pcop->name = PCOR(pcop)->r->name;
+
+       if(pic16_pcode_verbose) {
+               fprintf(stderr, "%s:%d %s allocates register %s rIdx:0x%02x\n",
+                       __FILE__, __LINE__, __FUNCTION__, r->name, r->rIdx);
+       }
 
   return pcop;
 }