1 /*-------------------------------------------------------------------------
3 main.c - pic16 specific general functions.
5 Written by - Scott Dattalo scott@dattalo.com
6 Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com
8 Note that mlh prepended _pic16_ on the static functions. Makes
9 it easier to set a breakpoint using the debugger.
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by the
14 Free Software Foundation; either version 2, or (at your option) any
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 -------------------------------------------------------------------------*/
37 static char _defaultRules[] =
42 /* list of key words used by pic16 */
43 static char *_pic16_keywords[] =
77 pic16_sectioninfo_t pic16_sectioninfo;
80 extern char *pic16_processor_base_name(void);
82 void pic16_pCodeInitRegisters(void);
84 void pic16_assignRegisters (ebbIndex *);
86 static int regParmFlg = 0; /* determine if we can register a parameter */
88 pic16_options_t pic16_options;
90 extern set *includeDirsSet;
91 extern set *dataDirsSet;
92 extern set *libFilesSet;
94 /* Also defined in gen.h, but the #include is commented out */
95 /* for an unknowned reason. - EEP */
96 void pic16_emitDebuggerSymbol (char *);
98 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
99 extern void pic16_emitConfigRegs(FILE *of);
100 extern void pic16_emitIDRegs(FILE *of);
107 asm_addTree (&asm_asxxxx_mapping);
108 pic16_pCodeInitRegisters();
113 _pic16_reset_regparm (void)
119 _pic16_regparm (sym_link * l, bool reentrant)
121 /* force all parameters via SEND/RECEIVE */
122 if(0 /*pic16_options.ip_stack*/) {
123 /* for this processor it is simple
124 * can pass only the first parameter in a register */
125 if(regParmFlg)return 0;
127 return 1; //regParmFlg;
129 /* otherwise pass all arguments in registers via SEND/RECEIVE */
136 int initsfpnt=0; /* set to 1 if source provides a pragma for stack
137 * so glue() later emits code to initialize stack/frame pointers */
140 set *sectNames=NULL; /* list of section listed in pragma directives */
141 set *sectSyms=NULL; /* list of symbols set in a specific section */
142 set *wparamList=NULL;
145 /* This is an experimental code for #pragma inline
146 and is temporarily disabled for 2.5.0 release */
147 set *asmInlineMap=NULL;
152 unsigned want_libc: 1;
153 unsigned want_libm: 1;
154 unsigned want_libio: 1;
155 unsigned want_libdebug: 1;
156 } libflags = { 0, 0, 0, 0, 0 };
160 _process_pragma(const char *sz)
162 static const char *WHITE = " \t\n";
163 static const char *WHITECOMMA = " \t\n,";
164 char *ptr = strtok((char *)sz, WHITE);
166 /* #pragma maxram [maxram] */
167 if (startsWith (ptr, "maxram")) {
168 char *maxRAM = strtok((char *)NULL, WHITE);
170 if (maxRAM != (char *)NULL) {
174 maxRAMVal = constVal(maxRAM);
175 maxRAMaddress = (int)floatFromVal(maxRAMVal);
176 pic16_setMaxRAM(maxRAMaddress);
182 /* #pragma stack [stack-position] [stack-len] */
183 if(startsWith(ptr, "stack")) {
184 char *stackPosS = strtok((char *)NULL, WHITE);
185 char *stackLenS = strtok((char *)NULL, WHITE);
192 fprintf (stderr, "%s:%d: #pragma stack [stack-pos] [stack-length] -- stack-position missing\n", filename, lineno-1);
194 return 0; /* considered an error */
197 stackPosVal = constVal( stackPosS );
198 stackPos = (unsigned int)floatFromVal( stackPosVal );
201 stackLenVal = constVal( stackLenS );
202 stackLen = (unsigned int)floatFromVal( stackLenVal );
207 fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
208 filename, lineno-1, stackLen, stackLen);
210 // fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
213 // fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
215 /* check sanity of stack */
216 if ((stackPos >> 8) != ((stackPos+stackLen) >> 8)) {
217 fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] crosses memory bank boundaries (not fully tested)\n",
218 filename,lineno-1, stackPos, stackPos+stackLen-1);
222 if (stackPos < pic16->acsSplitOfs) {
223 fprintf (stderr, "%s:%u: warning: stack [0x%03X, 0x%03X] intersects with the access bank [0x000,0x%03x] -- this is highly discouraged!\n",
224 filename, lineno-1, stackPos, stackPos+stackLen-1, pic16->acsSplitOfs);
227 if (stackPos+stackLen > 0xF00 + pic16->acsSplitOfs) {
228 fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] intersects with special function registers [0x%03X,0xFFF]-- this is highly discouraged!\n",
229 filename, lineno-1, stackPos, stackPos+stackLen-1, 0xF00 + pic16->acsSplitOfs);
232 if (stackPos+stackLen > pic16->RAMsize) {
233 fprintf (stderr, "%s:%u: error: stack [0x%03X,0x%03X] is placed outside available memory [0x000,0x%03X]!\n",
234 filename, lineno-1, stackPos, stackPos+stackLen-1, pic16->RAMsize-1);
236 return 1; /* considered an error, but this reports "invalid pragma stack"... */
240 reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
241 addSet(&pic16_fix_udata, reg);
243 reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
244 addSet(&pic16_fix_udata, reg);
246 sym = newSymbol("stack", 0);
247 sprintf(sym->rname, "_%s", sym->name);
248 addSet(&publics, sym);
250 sym = newSymbol("stack_end", 0);
251 sprintf(sym->rname, "_%s", sym->name);
252 addSet(&publics, sym);
254 initsfpnt = 1; // force glue() to initialize stack/frame pointers */
259 /* #pragma code [symbol] [location] */
260 if(startsWith(ptr, "code")) {
261 char *symname = strtok((char *)NULL, WHITE);
262 char *location = strtok((char *)NULL, WHITE);
266 if (!symname || !location) {
267 fprintf (stderr, "%s:%d: #pragma code [symbol] [location] -- symbol or location missing\n", filename, lineno-1);
269 return 1; /* considered an error, but this reports "invalid pragma code"... */
272 absS = Safe_calloc(1, sizeof(absSym));
273 sprintf(absS->name, "_%s", symname);
275 addr = constVal( location );
276 absS->address = (unsigned int)floatFromVal( addr );
278 if((absS->address % 2) != 0) {
280 fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
281 filename, lineno-1, absS->address);
284 addSet(&absSymSet, absS);
285 // fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
286 // __FILE__, __LINE__, symname, absS->address);
291 /* #pragma udata [section-name] [symbol] */
292 if(startsWith(ptr, "udata")) {
293 char *sectname = strtok((char *)NULL, WHITE);
294 char *symname = strtok((char *)NULL, WHITE);
300 if (!symname || !sectname) {
301 fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno-1);
303 return 1; /* considered an error, but this reports "invalid pragma code"... */
307 ssym = Safe_calloc(1, sizeof(sectSym));
308 ssym->name = Safe_calloc(1, strlen(symname)+2);
309 sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
312 addSet(§Syms, ssym);
314 nsym = newSymbol(symname, 0);
315 strcpy(nsym->rname, ssym->name);
318 checkAddSym(&publics, nsym);
322 for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
323 if(!strcmp(sectname, snam->name)){ found=1; break; }
327 snam = Safe_calloc(1, sizeof(sectName));
328 snam->name = Safe_strdup( sectname );
329 snam->regsSet = NULL;
331 addSet(§Names, snam);
334 ssym->section = snam;
337 fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
338 ssym->name, snam->name, snam);
341 symname = strtok((char *)NULL, WHITE);
347 /* #pragma wparam function1[, function2[,...]] */
348 if(startsWith(ptr, "wparam")) {
349 char *fname = strtok((char *)NULL, WHITECOMMA);
353 fprintf(stderr, "PIC16 Warning: `%s' wparam pragma is obsolete. use function attribute `wparam' instead.\n", fname);
354 addSet(&wparamList, Safe_strdup(fname));
356 // debugf("passing with WREG to %s\n", fname);
357 fname = strtok((char *)NULL, WHITECOMMA);
363 /* #pragma library library_module */
364 if(startsWith(ptr, "library")) {
365 char *lmodule = strtok((char *)NULL, WHITE);
369 * c link the C library
370 * math link the math library
371 * io link the IO library
372 * debug link the debug libary
373 * anything else, will link as-is */
375 if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
376 else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
377 else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
378 else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
379 else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
381 if(!libflags.ignore) {
382 fprintf(stderr, "link library %s\n", lmodule);
383 addSetHead(&libFilesSet, lmodule);
392 /* This is an experimental code for #pragma inline
393 and is temporarily disabled for 2.5.0 release */
394 if(startsWith(ptr, "inline")) {
395 char *tmp = strtok((char *)NULL, WHITECOMMA);
398 addSet(&asmInlineMap, Safe_strdup( tmp ));
399 tmp = strtok((char *)NULL, WHITECOMMA);
405 for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
406 debugf("inline asm: `%s'\n", s);
417 #define REP_UDATA "--preplace-udata-with="
419 #define STACK_MODEL "--pstack-model="
420 #define OPT_BANKSEL "--obanksel="
422 #define ALT_ASM "--asm="
423 #define ALT_LINK "--link="
425 #define IVT_LOC "--ivt-loc="
426 #define NO_DEFLIBS "--nodefaultlibs"
427 #define MPLAB_COMPAT "--mplab-comp"
429 #define NL_OPT "--nl="
430 #define USE_CRT "--use-crt="
432 #define OFMSG_LRSUPPORT "--flr-support"
434 #define OPTIMIZE_GOTO "--optimize-goto"
435 #define OPTIMIZE_CMP "--optimize-cmp"
436 #define OPTIMIZE_DF "--optimize-df"
441 int pic16_mplab_comp=0;
442 extern int pic16_debug_verbose;
443 extern int pic16_ralloc_debug;
444 extern int pic16_pcode_verbose;
447 int pic16_enable_peeps=0;
448 int pic16_nl=0; /* 0 for LF, 1 for CRLF */
450 OPTION pic16_optionsTable[]= {
451 { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"},
452 { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"},
453 { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"},
454 // { 0, "--pomit-config-words", &pic16_options.omit_configw, "omit the generation of configuration words"},
455 // { 0, "--pomit-ivt", &pic16_options.omit_ivt, "omit the generation of the Interrupt Vector Table"},
456 // { 0, "--pleave-reset-vector",&pic16_options.leave_reset, "when omitting IVT leave RESET vector"},
457 { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"},
459 { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"},
460 { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"},
461 { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"},
463 { 0, REP_UDATA, NULL, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
465 { 0, ALT_ASM, NULL, "Use alternative assembler"},
466 { 0, ALT_LINK, NULL, "Use alternative linker"},
468 { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"},
469 { 0, IVT_LOC, NULL, "<nnnn> interrupt vector table location"},
470 { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"},
471 { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
472 { 0, "--fstack", &pic16_fstack, "enable stack optimizations"},
473 { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""},
474 { 0, USE_CRT, NULL, "use <crt-o> run-time initialization module"},
475 { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"},
476 { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"},
477 { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"},
478 { 0, OPTIMIZE_CMP, NULL, "try to optimize some compares"},
479 { 0, OPTIMIZE_DF, NULL, "thoroughly analyze data flow (memory and time intensive!)"},
480 { 0, NULL, NULL, NULL}
484 #define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) )
486 extern char *getStringArg(const char *, char **, int *, int);
487 extern int getIntArg(const char *, char **, int *, int);
490 _pic16_parseOptions (int *pargc, char **argv, int *i)
495 /* TODO: allow port-specific command line options to specify
496 * segment names here.
499 /* check for arguments that have associated an integer variable */
500 while(pic16_optionsTable[j].pparameter) {
501 if(ISOPT( pic16_optionsTable[j].longOpt )) {
502 (*pic16_optionsTable[j].pparameter)++;
508 if(ISOPT(STACK_MODEL)) {
509 stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
510 if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
511 else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
513 fprintf(stderr, "Unknown stack model: %s", stkmodel);
519 if(ISOPT(OPT_BANKSEL)) {
520 pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
524 if(ISOPT(REP_UDATA)) {
525 pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
530 alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
534 if(ISOPT(ALT_LINK)) {
535 alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
540 pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
541 fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc);
548 tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
549 if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
550 else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
552 fprintf(stderr, "invalid termination character id\n");
559 pic16_options.no_crt = 0;
560 pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
566 if(ISOPT(OFMSG_LRSUPPORT)) {
567 pic16_options.opt_flags |= OF_LR_SUPPORT;
572 if (ISOPT(OPTIMIZE_GOTO)) {
573 pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
577 if(ISOPT(OPTIMIZE_CMP)) {
578 pic16_options.opt_flags |= OF_OPTIMIZE_CMP;
582 if (ISOPT(OPTIMIZE_DF)) {
583 pic16_options.opt_flags |= OF_OPTIMIZE_DF;
591 extern set *userIncDirsSet;
593 static void _pic16_initPaths(void)
595 char pic16incDir[512];
596 char pic16libDir[512];
597 set *pic16incDirsSet=NULL;
598 set *pic16libDirsSet=NULL;
601 setMainValue("mcu", pic16->name[2] );
602 addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
604 setMainValue("mcu1", pic16->name[1] );
605 addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
607 sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
608 sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
611 if(!options.nostdinc) {
612 /* setup pic16 include directory */
613 pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
614 includeDirsSet = pic16incDirsSet;
615 // mergeSets(&includeDirsSet, pic16incDirsSet);
617 /* pic16 port should not search to the SDCC standard include directories,
618 * so add here the deleted include dirs that user has issued in command line */
619 mergeSets(&pic16incDirsSet, userIncDirsSet);
621 if(!options.nostdlib) {
622 /* setup pic16 library directory */
623 pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
624 libDirsSet = pic16libDirsSet;
625 // mergeSets(&libDirsSet, pic16libDirsSet);
628 if(!pic16_options.nodefaultlibs) {
629 /* now add the library for the device */
630 sprintf(devlib, "%s.lib", pic16->name[2]);
631 addSet(&libFilesSet, Safe_strdup(devlib));
633 /* add the internal SDCC library */
634 addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
638 extern set *linkOptionsSet;
639 char *msprintf(hTab *pvals, const char *pformat, ...);
640 int my_system(const char *cmd);
642 /* custom function to link objects */
643 static void _pic16_linkEdit(void)
645 hTab *linkValues=NULL;
653 * link command format:
654 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
658 sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
660 shash_add(&linkValues, "linker", "gplink");
662 mergeSets(&tSet, libDirsSet);
663 mergeSets(&tSet, libPathsSet);
665 shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\"")));
666 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
668 shash_add(&linkValues, "outfile", dstFileName);
670 if(fullSrcFileName) {
671 sprintf(temp, "%s.o", dstFileName);
672 // addSetHead(&relFilesSet, Safe_strdup(temp));
673 shash_add(&linkValues, "user_ofile", temp);
676 if(!pic16_options.no_crt)
677 shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
679 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
681 if(!libflags.ignore) {
682 if(libflags.want_libc)
683 addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
685 if(libflags.want_libm)
686 addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
688 if(libflags.want_libio) {
689 sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */
690 addSet(&libFilesSet, Safe_strdup(temp));
693 if(libflags.want_libdebug)
694 addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
697 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
699 lcmd = msprintf(linkValues, lfrm);
701 ret = my_system( lcmd );
710 /* forward declarations */
711 extern const char *pic16_linkCmd[];
712 extern const char *pic16_asmCmd[];
713 extern set *asmOptionsSet;
716 _pic16_finaliseOptions (void)
718 port->mem.default_local_map = data;
719 port->mem.default_globl_map = data;
721 /* peepholes are disabled for the time being */
724 /* explicit enable peepholes for testing */
725 if(pic16_enable_peeps)
728 options.all_callee_saves = 1; // always callee saves
731 options.float_rent = 1;
732 options.intlong_rent = 1;
736 if(alt_asm && strlen(alt_asm))
737 pic16_asmCmd[0] = alt_asm;
739 if(alt_link && strlen(alt_link))
740 pic16_linkCmd[0] = alt_link;
742 if(!pic16_options.no_crt) {
743 pic16_options.omit_ivt = 1;
744 pic16_options.leave_reset = 0;
747 if(options.model == MODEL_SMALL)
748 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
750 if(options.model == MODEL_LARGE)
751 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
756 sprintf(buf, "-D%s -D__%s", pic16->name[2], pic16->name[1]);
757 *(strrchr(buf, 'f')) = 'F';
758 addSet(&asmOptionsSet, Safe_strdup( buf ));
761 if(STACK_MODEL_LARGE) {
762 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
763 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
765 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
766 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
772 if (options.model == MODEL_LARGE)
774 port->mem.default_local_map = xdata;
775 port->mem.default_globl_map = xdata;
779 port->mem.default_local_map = data;
780 port->mem.default_globl_map = data;
783 if (options.stack10bit)
785 if (options.model != MODEL_FLAT24)
788 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
789 fprintf (stderr, "\t10 bit stack mode disabled.\n");
790 options.stack10bit = 0;
794 /* Fixup the memory map for the stack; it is now in
795 * far space and requires a FPOINTER to access it.
798 istack->ptrType = FPOINTER;
805 _pic16_setDefaultOptions (void)
807 options.stackAuto = 0; /* implicit declaration */
808 /* port is not capable yet to allocate separate registers
809 * dedicated for passing certain parameters */
811 /* initialize to defaults section locations, names and addresses */
812 pic16_sectioninfo.at_udata = "udata";
814 /* set pic16 port options to defaults */
815 pic16_options.no_banksel = 0;
816 pic16_options.opt_banksel = 0;
817 pic16_options.omit_configw = 0;
818 pic16_options.omit_ivt = 0;
819 pic16_options.leave_reset = 0;
820 pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
821 pic16_options.ivt_loc = 0x000000;
822 pic16_options.nodefaultlibs = 0;
823 pic16_options.dumpcalltree = 0;
824 pic16_options.crt_name = "crt0i.o"; /* the default crt to link */
825 pic16_options.no_crt = 0; /* use crt by default */
826 pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */
827 pic16_options.gstack = 0;
828 pic16_options.debgen = 0;
832 _pic16_getRegName (struct regs *reg)
841 static char *_pic16_mangleFunctionName(char *sz)
843 // fprintf(stderr, "mangled function name: %s\n", sz);
851 _pic16_genAssemblerPreamble (FILE * of)
853 char *name = pic16_processor_base_name();
857 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
860 fprintf (of, "\tlist\tp=%s\n",&name[1]);
862 if(!pic16_options.omit_configw) {
863 pic16_emitConfigRegs(of);
865 pic16_emitIDRegs(of);
868 fprintf (of, "\tradix dec\n");
871 /* Generate interrupt vector table. */
873 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
876 /* PIC18F family has only two interrupts, the high and the low
877 * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
879 if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
880 fprintf(of, "; RESET vector\n");
881 fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
884 if(!pic16_options.omit_ivt) {
885 fprintf(of, "\tres 4\n");
888 fprintf(of, "; High priority interrupt vector 0x0008\n");
890 fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
891 fprintf(of, "\tres\t12\n");
893 fprintf(of, "\tretfie\n");
894 fprintf(of, "\tres\t14\n");
897 fprintf(of, "; Low priority interrupt vector 0x0018\n");
899 fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
901 fprintf(of, "\tretfie\n");
908 /* return True if the port can handle the type,
909 * False to convert it to function call */
910 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
912 // fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
915 /* multiplication is fixed */
916 /* support mul for char/int/long */
918 && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
922 /* support div for char/int/long */
923 if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
924 && (ic->op == '/'))return TRUE;
932 /* Do CSE estimation */
933 static bool cseCostEstimation (iCode *ic, iCode *pdic)
935 // operand *result = IC_RESULT(ic);
936 // sym_link *result_type = operandType(result);
939 /* VR -- this is an adhoc. Put here after conversation
940 * with Erik Epetrich */
944 || ic->op == EQ_OP) {
946 fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
951 /* if it is a pointer then return ok for now */
952 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
954 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
955 so we will cse only if they are local (i.e. both ic & pdic belong to
956 the same basic block */
957 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
958 /* then if they are the same Basic block then ok */
959 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
964 /* for others it is cheaper to do the cse */
970 /* Indicate which extended bit operations this port supports */
972 hasExtBitOp (int op, int size)
976 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
983 /* Indicate the expense of an access to an output storage class */
985 oclsExpense (struct memmap *oclass)
987 /* The IN_FARSPACE test is compatible with historical behaviour, */
988 /* but I don't think it is applicable to PIC. If so, please feel */
989 /* free to remove this test -- EEP */
990 if (IN_FARSPACE(oclass))
996 /** $1 is the input object file (PIC16 specific) // >>always the basename<<.
997 $2 is always the output file.
998 $3 -L path and -l libraries
999 $l is the list of extra options that should be there somewhere...
1000 MUST be terminated with a NULL.
1002 const char *pic16_linkCmd[] =
1004 "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
1009 /** $1 is always the basename.
1010 $2 is always the output file.
1011 $3 varies (nothing currently)
1012 $l is the list of extra options that should be there somewhere...
1013 MUST be terminated with a NULL.
1015 const char *pic16_asmCmd[] =
1017 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
1026 "MCU PIC16", /* Target name */
1027 "p18f452", /* Processor */
1030 TRUE, /* Emit glue around main */
1031 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1035 pic16_asmCmd, /* assembler command and arguments */
1036 NULL, /* alternate macro based form */
1037 "-g", /* arguments for debug mode */
1038 NULL, /* arguments for normal mode */
1039 0, /* print externs as global */
1040 ".asm", /* assembler file extension */
1041 NULL /* no do_assemble function */
1044 NULL, // pic16_linkCmd, /* linker command and arguments */
1045 NULL, /* alternate macro based form */
1046 _pic16_linkEdit, //NULL, /* no do_link function */
1047 ".o", /* extension for object files */
1048 0 /* no need for linker file */
1060 3, /* fptr, far pointers (see Microchip) */
1067 "XSEG (XDATA)", // xstack
1068 "STACK (DATA)", // istack
1069 "CSEG (CODE)", // code
1070 "DSEG (DATA)", // data
1071 "ISEG (DATA)", // idata
1072 "PSEG (DATA)", // pdata
1073 "XSEG (XDATA)", // xdata
1074 "BSEG (BIT)", // bit
1075 "RSEG (DATA)", // reg
1076 "GSINIT (CODE)", // static
1077 "OSEG (OVR,DATA)", // overlay
1078 "GSFINAL (CODE)", // post static
1079 "HOME (CODE)", // home
1082 "CONST (CODE)", // const_name - const data (code or not)
1083 NULL, // default location for auto vars
1084 NULL, // default location for global vars
1085 1 // code is read only 1=yes
1088 NULL, /* genExtraAreaDeclaration */
1089 NULL /* genExatrAreaLinkOptions */
1092 /* stack related information */
1093 -1, /* -1 stack grows downwards, +1 upwards */
1094 1, /* extra overhead when calling between banks */
1095 4, /* extra overhead when the function is an ISR */
1096 1, /* extra overhead for a function call */
1097 1, /* re-entrant space */
1098 0 /* 'banked' call overhead, mild overlap with bank_overhead */
1100 /* pic16 has an 8 bit mul */
1105 pic16_emitDebuggerSymbol
1108 255/3, /* maxCount */
1109 3, /* sizeofElement */
1110 /* The rest of these costs are bogus. They approximate */
1111 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
1112 {4,4,4}, /* sizeofMatchJump[] */
1113 {0,0,0}, /* sizeofRangeCompare[] */
1114 0, /* sizeofSubtract */
1115 3, /* sizeofDispatch */
1119 _pic16_parseOptions,
1122 _pic16_finaliseOptions,
1123 _pic16_setDefaultOptions,
1124 pic16_assignRegisters,
1127 _pic16_genAssemblerPreamble,
1128 NULL, /* no genAssemblerEnd */
1130 NULL, // _pic16_genXINIT
1131 NULL, /* genInitStartup */
1132 _pic16_reset_regparm,
1134 _process_pragma, /* process a pragma */
1135 _pic16_mangleFunctionName, /* mangles function name */
1137 hasExtBitOp, /* hasExtBitOp */
1138 oclsExpense, /* oclsExpense */
1140 TRUE, /* little endian */
1143 1, /* transform <= to ! > */
1144 1, /* transform >= to ! < */
1145 1, /* transform != to !(a == b) */
1147 FALSE, /* No array initializer support. */
1148 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */
1149 NULL, /* no builtin functions */
1150 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1151 1, /* reset labelKey to 1 */
1152 1, /* globals & local static allowed */