X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic16%2Fmain.c;h=430f3425bf3cd675680aeafaad244d5553aae8aa;hb=93c80c9bf6ee0e7699677cf52cbffc6fd8a10502;hp=c62ea9dd8d3add63899395b774372279860ef620;hpb=9e374461da1807d52abbb32cba66d31f9824ea95;p=fw%2Fsdcc diff --git a/src/pic16/main.c b/src/pic16/main.c index c62ea9dd..430f3425 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -100,41 +100,32 @@ extern void pic16_emitIDRegs(FILE *of); static void _pic16_init (void) { - asm_addTree (&asm_asxxxx_mapping); - pic16_pCodeInitRegisters(); - maxInterrupts = 2; - - /* set pic16 port options to defaults */ - pic16_options.no_banksel = 0; - pic16_options.opt_banksel = 0; - pic16_options.omit_configw = 0; - pic16_options.omit_ivt = 0; - pic16_options.leave_reset = 0; - pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */ - pic16_options.ivt_loc = 0x000000; /* default location of interrupt vectors */ - pic16_options.nodefaultlibs = 0; /* link default libraries */ - pic16_options.dumpcalltree = 0; + asm_addTree (&asm_asxxxx_mapping); + pic16_pCodeInitRegisters(); + maxInterrupts = 2; } static void -_pic16_reset_regparm () +_pic16_reset_regparm (void) { - regParmFlg = 0; + regParmFlg = 0; } static int _pic16_regparm (sym_link * l) { - /* for this processor it is simple - * can pass only the first parameter in a register */ - if(pic16_fstack) { - if(regParmFlg)return 0; - regParmFlg = 1; - return 1; - } else { - regParmFlg++;// = 1; - return 1; - } + /* force all parameters via SEND/RECEIVE */ + if(0 /*pic16_options.ip_stack*/) { + /* for this processor it is simple + * can pass only the first parameter in a register */ + if(regParmFlg)return 0; + regParmFlg++; + return 1; //regParmFlg; + } else { + /* otherwise pass all arguments in registers via SEND/RECEIVE */ + regParmFlg++;// = 1; + return regParmFlg; + } } @@ -144,12 +135,13 @@ set *absSymSet; set *sectNames=NULL; /* list of section listed in pragma directives */ set *sectSyms=NULL; /* list of symbols set in a specific section */ - +set *wparamList=NULL; static int _process_pragma(const char *sz) { static const char *WHITE = " \t\n"; + static const char *WHITECOMMA = " \t\n,"; char *ptr = strtok((char *)sz, WHITE); @@ -165,6 +157,8 @@ _process_pragma(const char *sz) maxRAMaddress = (int)floatFromVal(maxRAMVal); pic16_setMaxRAM(maxRAMaddress); } + + return 0; } /* #pragma stack [stack-position] [stack-len] */ @@ -187,7 +181,10 @@ _process_pragma(const char *sz) if(stackLen < 1) { stackLen = 64; - fprintf(stderr, "%s:%d setting stack to default size 0x%x\n", __FILE__, __LINE__, stackLen); + fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n", + filename, lineno-1, stackLen, stackLen); + +// fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen); } // fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen); @@ -219,13 +216,20 @@ _process_pragma(const char *sz) value *addr; absS = Safe_calloc(1, sizeof(absSym)); - absS->name = Safe_strdup( symname ); + sprintf(absS->name, "_%s", symname); + addr = constVal( location ); absS->address = (unsigned int)floatFromVal( addr ); + if((absS->address % 2) != 0) { + absS->address--; + fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n", + filename, lineno-1, absS->address); + } + 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); +// fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n", +// __FILE__, __LINE__, symname, absS->address); return 0; } @@ -234,12 +238,12 @@ _process_pragma(const char *sz) if(startsWith(ptr, "udata")) { char *sectname = strtok((char *)NULL, WHITE); char *symname = strtok((char *)NULL, WHITE); + symbol *nsym; sectSym *ssym; sectName *snam; int found=0; while(symname) { - ssym = Safe_calloc(1, sizeof(sectSyms)); ssym->name = Safe_calloc(1, strlen(symname)+2); sprintf(ssym->name, "_%s", symname); @@ -247,6 +251,10 @@ _process_pragma(const char *sz) addSet(§Syms, ssym); + nsym = newSymbol(symname, 0); + strcpy(nsym->rname, ssym->name); + checkAddSym(&publics, nsym); + found = 0; for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) { if(!strcmp(sectname, snam->name)){ found=1; break; } @@ -271,6 +279,19 @@ _process_pragma(const char *sz) return 0; } + if(startsWith(ptr, "wparam")) { + char *fname = strtok((char *)NULL, WHITECOMMA); + + while(fname) { + addSet(&wparamList, Safe_strdup(fname)); + +// debugf("passing with WREG to %s\n", fname); + fname = strtok((char *)NULL, WHITECOMMA); + } + + return 0; + } + return 1; } @@ -289,6 +310,10 @@ _process_pragma(const char *sz) #define NL_OPT "--nl=" #define USE_CRT "--use-crt=" +#define OFMSG_LRSUPPORT "--flr-support" + +#define OPTIMIZE_GOTO "--optimize-goto" + char *alt_asm=NULL; char *alt_link=NULL; @@ -327,6 +352,9 @@ OPTION pic16_optionsTable[]= { { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""}, { 0, USE_CRT, NULL, "use run-time initialization module"}, { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"}, + { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"}, +// { 0, OFMSG_LRSUPPORT, NULL, "use support functions for local register store/restore"}, + { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"}, { 0, NULL, NULL, NULL} }; @@ -345,79 +373,97 @@ _pic16_parseOptions (int *pargc, char **argv, int *i) /* TODO: allow port-specific command line options to specify * segment names here. */ - /* check for arguments that have associated an integer variable */ - while(pic16_optionsTable[j].pparameter) { - if(ISOPT( pic16_optionsTable[j].longOpt )) { - (*pic16_optionsTable[j].pparameter)++; - return TRUE; - } - j++; - } - + + /* check for arguments that have associated an integer variable */ + while(pic16_optionsTable[j].pparameter) { + if(ISOPT( pic16_optionsTable[j].longOpt )) { + (*pic16_optionsTable[j].pparameter)++; + return TRUE; + } + j++; + } - if(ISOPT(STACK_MODEL)) { - stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc); - if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0; - else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1; - else { - fprintf(stderr, "Unknown stack model: %s", stkmodel); - exit(-1); - } - return TRUE; - } + if(ISOPT(STACK_MODEL)) { + stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc); + if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0; + else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1; + else { + fprintf(stderr, "Unknown stack model: %s", stkmodel); + exit(-1); + } + return TRUE; + } - if(ISOPT(OPT_BANKSEL)) { - pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc); - return TRUE; - } + if(ISOPT(OPT_BANKSEL)) { + pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc); + return TRUE; + } - if(ISOPT(REP_UDATA)) { - pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc)); - return TRUE; - } + if(ISOPT(REP_UDATA)) { + pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc)); + return TRUE; + } - if(ISOPT(ALT_ASM)) { - alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc)); - return TRUE; - } + if(ISOPT(ALT_ASM)) { + alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc)); + return TRUE; + } - if(ISOPT(ALT_LINK)) { - alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc)); - return TRUE; - } + if(ISOPT(ALT_LINK)) { + alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc)); + return TRUE; + } - if(ISOPT(IVT_LOC)) { - pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc); - return TRUE; - } + if(ISOPT(IVT_LOC)) { + pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc); + return TRUE; + } - if(ISOPT(NL_OPT)) { - char *tmp; + if(ISOPT(NL_OPT)) { + char *tmp; - tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) ); - if(!STRCASECMP(tmp, "lf"))pic16_nl = 0; - else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1; - else { - fprintf(stderr, "invalid termination character id\n"); - exit(-1); - } - return TRUE; + tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) ); + if(!STRCASECMP(tmp, "lf"))pic16_nl = 0; + else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1; + else { + fprintf(stderr, "invalid termination character id\n"); + exit(-1); } + return TRUE; + } + + if(ISOPT(USE_CRT)) { + pic16_options.no_crt = 0; + pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) ); + + return TRUE; + } + +#if 0 + if(ISOPT(OFMSG_LRSUPPORT)) { + pic16_options.opt_flags |= OF_LR_SUPPORT; + return TRUE; + } +#endif + +#if 1 + if (ISOPT(OPTIMIZE_GOTO)) { + pic16_options.opt_flags |= OF_OPTIMIZE_GOTO; + return TRUE; + } +#endif - if(ISOPT(USE_CRT)) { - pic16_options.no_crt = 0; - pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) ); - } - return FALSE; } +extern set *userIncDirsSet; + static void _pic16_initPaths(void) { char pic16incDir[512]; char pic16libDir[512]; - set *pic16incDirsSet; - set *pic16libDirsSet; + set *pic16incDirsSet=NULL; + set *pic16libDirsSet=NULL; char devlib[512]; setMainValue("mcu", pic16->name[2] ); @@ -426,16 +472,22 @@ static void _pic16_initPaths(void) sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR); sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR); + if(!options.nostdinc) { /* setup pic16 include directory */ pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir); - mergeSets(&includeDirsSet, pic16incDirsSet); + includeDirsSet = pic16incDirsSet; +// mergeSets(&includeDirsSet, pic16incDirsSet); } + /* pic16 port should not search to the SDCC standard include directories, + * so add here the deleted include dirs that user has issued in command line */ + mergeSets(&pic16incDirsSet, userIncDirsSet); if(!options.nostdlib) { /* setup pic16 library directory */ pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir); - mergeSets(&libDirsSet, pic16libDirsSet); + libDirsSet = pic16libDirsSet; +// mergeSets(&libDirsSet, pic16libDirsSet); } if(!pic16_options.nodefaultlibs) { @@ -468,7 +520,7 @@ static void _pic16_linkEdit(void) * */ - sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}"); + sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}"); shash_add(&linkValues, "linker", "gplink"); @@ -482,7 +534,8 @@ static void _pic16_linkEdit(void) if(fullSrcFileName) { sprintf(temp, "%s.o", dstFileName); - addSetHead(&relFilesSet, Safe_strdup(temp)); +// addSetHead(&relFilesSet, Safe_strdup(temp)); + shash_add(&linkValues, "user_ofile", temp); } if(!pic16_options.no_crt) @@ -520,8 +573,11 @@ _pic16_finaliseOptions (void) options.nopeep = 0; options.all_callee_saves = 1; // always callee saves -// options.float_rent = 1; -// options.intlong_rent = 1; + +#if 0 + options.float_rent = 1; + options.intlong_rent = 1; +#endif if(alt_asm && strlen(alt_asm)) @@ -573,21 +629,28 @@ _pic16_finaliseOptions (void) static void _pic16_setDefaultOptions (void) { - /* initialize to defaults section locations, names and addresses */ - pic16_sectioninfo.at_udata = "udata"; - - /* set pic16 port options to defaults */ - pic16_options.no_banksel = 0; - pic16_options.opt_banksel = 0; - pic16_options.omit_configw = 0; - pic16_options.omit_ivt = 0; - pic16_options.leave_reset = 0; - pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */ - pic16_options.ivt_loc = 0x000000; - pic16_options.nodefaultlibs = 0; - pic16_options.dumpcalltree = 0; - pic16_options.crt_name = "crt0i.o"; /* the default crt to link */ - pic16_options.no_crt = 0; /* use crt by default */ + options.stackAuto = 0; /* implicit declaration */ + /* port is not capable yet to allocate separate registers + * dedicated for passing certain parameters */ + + /* initialize to defaults section locations, names and addresses */ + pic16_sectioninfo.at_udata = "udata"; + + /* set pic16 port options to defaults */ + pic16_options.no_banksel = 0; + pic16_options.opt_banksel = 0; + pic16_options.omit_configw = 0; + pic16_options.omit_ivt = 0; + pic16_options.leave_reset = 0; + pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */ + pic16_options.ivt_loc = 0x000000; + pic16_options.nodefaultlibs = 0; + pic16_options.dumpcalltree = 0; + pic16_options.crt_name = "crt0i.o"; /* the default crt to link */ + pic16_options.no_crt = 0; /* use crt by default */ + pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */ + pic16_options.gstack = 0; + pic16_options.debgen = 0; } static const char * @@ -820,7 +883,7 @@ PORT pic16_port = 4, /* long */ 2, /* ptr */ 3, /* fptr, far pointers (see Microchip) */ - 2, /* gptr */ + 3, /* gptr */ 1, /* bit */ 4, /* float */ 4 /* max */ @@ -831,6 +894,7 @@ PORT pic16_port = "CSEG (CODE)", // code "DSEG (DATA)", // data "ISEG (DATA)", // idata + NULL, // pdata "XSEG (XDATA)", // xdata "BSEG (BIT)", // bit "RSEG (DATA)", // reg