+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
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);
}
#define STRCASECMP strcasecmp
#endif
-static PIC_device Pics[] = {
+static PIC16_device Pics16[] = {
{
{"p18f242", "18f242", "pic18f242", "f242"}, // aliases
(memRange *)NULL, // ram memory map
};
-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
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;
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;
/* 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;
}
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);
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-PIC_device *pic16_find_device(char *name)
+PIC16_device *pic16_find_device(char *name)
{
int i,j;
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 */
*-----------------------------------------------------------------*/
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
*-----------------------------------------------------------------*/
int pic16_picIsInitialized(void)
{
- if(pic && pic->maxRAMaddress > 0)
+ if(pic16 && pic16->maxRAMaddress > 0)
return 1;
return 0;
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;
#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 */
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)
extern pic16_options_t pic16_options;
-
+extern PIC16_device *pic16;
/****************************************/
void pic16_assignConfigWordValue(int address, int value);
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
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)) {
// 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');
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;
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));
+ }
}
/** $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
};
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;
}