From: vrokas Date: Fri, 16 Jan 2004 15:06:35 +0000 (+0000) Subject: 2004-01-16 Vangelis Rokas X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=7cefa1ef25ee351b687ec882cfba1d9e33e45343;p=fw%2Fsdcc 2004-01-16 Vangelis Rokas * 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 --- diff --git a/ChangeLog b/ChangeLog index 6804100c..566c547f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-01-16 Vangelis Rokas + + * 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 * device/include/mc68hc908jb8.h: Register defs for another member diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 3eeddd1a..59f27632 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -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); } diff --git a/src/pic16/device.c b/src/pic16/device.c index 841742fa..df8f3367 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -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; ilongest) 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(colmaxRAMaddress > 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; iisBitField ? (((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); diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 1f133932..5167f5dc 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -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 diff --git a/src/pic16/glue.c b/src/pic16/glue.c index ba5703f4..f02dd928 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -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'); diff --git a/src/pic16/main.c b/src/pic16/main.c index 44f4c13d..ef3227fc 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -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 }; diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index f5952a72..b05aaf59 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -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; }