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[] =
76 pic16_sectioninfo_t pic16_sectioninfo;
79 extern char *pic16_processor_base_name(void);
81 void pic16_pCodeInitRegisters(void);
83 void pic16_assignRegisters (ebbIndex *);
85 static int regParmFlg = 0; /* determine if we can register a parameter */
87 pic16_options_t pic16_options;
89 extern set *includeDirsSet;
90 extern set *dataDirsSet;
91 extern set *libFilesSet;
93 /* Also defined in gen.h, but the #include is commented out */
94 /* for an unknowned reason. - EEP */
95 void pic16_emitDebuggerSymbol (char *);
97 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
98 extern void pic16_emitConfigRegs(FILE *of);
99 extern void pic16_emitIDRegs(FILE *of);
106 asm_addTree (&asm_asxxxx_mapping);
107 pic16_pCodeInitRegisters();
112 _pic16_reset_regparm (void)
118 _pic16_regparm (sym_link * l)
120 /* force all parameters via SEND/RECEIVE */
121 if(0 /*pic16_options.ip_stack*/) {
122 /* for this processor it is simple
123 * can pass only the first parameter in a register */
124 if(regParmFlg)return 0;
126 return 1; //regParmFlg;
128 /* otherwise pass all arguments in registers via SEND/RECEIVE */
135 int initsfpnt=0; /* set to 1 if source provides a pragma for stack
136 * so glue() later emits code to initialize stack/frame pointers */
139 set *sectNames=NULL; /* list of section listed in pragma directives */
140 set *sectSyms=NULL; /* list of symbols set in a specific section */
141 set *wparamList=NULL;
144 /* This is an experimental code for #pragma inline
145 and is temporarily disabled for 2.5.0 release */
146 set *asmInlineMap=NULL;
151 unsigned want_libc: 1;
152 unsigned want_libm: 1;
153 unsigned want_libio: 1;
154 unsigned want_libdebug: 1;
155 } libflags = { 0, 0, 0, 0, 0 };
159 _process_pragma(const char *sz)
161 static const char *WHITE = " \t\n";
162 static const char *WHITECOMMA = " \t\n,";
163 char *ptr = strtok((char *)sz, WHITE);
165 /* #pragma maxram [maxram] */
166 if (startsWith (ptr, "maxram")) {
167 char *maxRAM = strtok((char *)NULL, WHITE);
169 if (maxRAM != (char *)NULL) {
173 maxRAMVal = constVal(maxRAM);
174 maxRAMaddress = (int)floatFromVal(maxRAMVal);
175 pic16_setMaxRAM(maxRAMaddress);
181 /* #pragma stack [stack-position] [stack-len] */
182 if(startsWith(ptr, "stack")) {
183 char *stackPosS = strtok((char *)NULL, WHITE);
184 char *stackLenS = strtok((char *)NULL, WHITE);
190 stackPosVal = constVal( stackPosS );
191 stackPos = (unsigned int)floatFromVal( stackPosVal );
194 stackLenVal = constVal( stackLenS );
195 stackLen = (unsigned int)floatFromVal( stackLenVal );
200 fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
201 filename, lineno-1, stackLen, stackLen);
203 // fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
206 // fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
208 reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
209 addSet(&pic16_fix_udata, reg);
211 reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
212 addSet(&pic16_fix_udata, reg);
214 sym = newSymbol("stack", 0);
215 sprintf(sym->rname, "_%s", sym->name);
216 addSet(&publics, sym);
218 sym = newSymbol("stack_end", 0);
219 sprintf(sym->rname, "_%s", sym->name);
220 addSet(&publics, sym);
222 initsfpnt = 1; // force glue() to initialize stack/frame pointers */
227 /* #pragma code [symbol] [location] */
228 if(startsWith(ptr, "code")) {
229 char *symname = strtok((char *)NULL, WHITE);
230 char *location = strtok((char *)NULL, WHITE);
234 if (!symname || !location) {
235 fprintf (stderr, "%s:%d: #pragma code [symbol] [location] -- symbol or location missing\n", filename, lineno-1);
236 return 1; /* considered an error */
239 absS = Safe_calloc(1, sizeof(absSym));
240 sprintf(absS->name, "_%s", symname);
242 addr = constVal( location );
243 absS->address = (unsigned int)floatFromVal( addr );
245 if((absS->address % 2) != 0) {
247 fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
248 filename, lineno-1, absS->address);
251 addSet(&absSymSet, absS);
252 // fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
253 // __FILE__, __LINE__, symname, absS->address);
258 /* #pragma udata [section-name] [symbol] */
259 if(startsWith(ptr, "udata")) {
260 char *sectname = strtok((char *)NULL, WHITE);
261 char *symname = strtok((char *)NULL, WHITE);
267 if (!symname || !sectname) {
268 fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno-1);
269 return 1; /* considered an error */
273 ssym = Safe_calloc(1, sizeof(sectSym));
274 ssym->name = Safe_calloc(1, strlen(symname)+2);
275 sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
278 addSet(§Syms, ssym);
280 nsym = newSymbol(symname, 0);
281 strcpy(nsym->rname, ssym->name);
284 checkAddSym(&publics, nsym);
288 for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
289 if(!strcmp(sectname, snam->name)){ found=1; break; }
293 snam = Safe_calloc(1, sizeof(sectName));
294 snam->name = Safe_strdup( sectname );
295 snam->regsSet = NULL;
297 addSet(§Names, snam);
300 ssym->section = snam;
303 fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
304 ssym->name, snam->name, snam);
307 symname = strtok((char *)NULL, WHITE);
313 /* #pragma wparam function1[, function2[,...]] */
314 if(startsWith(ptr, "wparam")) {
315 char *fname = strtok((char *)NULL, WHITECOMMA);
319 fprintf(stderr, "PIC16 Warning: `%s' wparam pragma is obsolete. use function attribute `wparam' instead.\n", fname);
320 addSet(&wparamList, Safe_strdup(fname));
322 // debugf("passing with WREG to %s\n", fname);
323 fname = strtok((char *)NULL, WHITECOMMA);
329 /* #pragma library library_module */
330 if(startsWith(ptr, "library")) {
331 char *lmodule = strtok((char *)NULL, WHITE);
335 * c link the C library
336 * math link the math library
337 * io link the IO library
338 * debug link the debug libary
339 * anything else, will link as-is */
341 if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
342 else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
343 else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
344 else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
345 else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
347 if(!libflags.ignore) {
348 fprintf(stderr, "link library %s\n", lmodule);
349 addSetHead(&libFilesSet, lmodule);
358 /* This is an experimental code for #pragma inline
359 and is temporarily disabled for 2.5.0 release */
360 if(startsWith(ptr, "inline")) {
361 char *tmp = strtok((char *)NULL, WHITECOMMA);
364 addSet(&asmInlineMap, Safe_strdup( tmp ));
365 tmp = strtok((char *)NULL, WHITECOMMA);
371 for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
372 debugf("inline asm: `%s'\n", s);
383 #define REP_UDATA "--preplace-udata-with="
385 #define STACK_MODEL "--pstack-model="
386 #define OPT_BANKSEL "--obanksel="
388 #define ALT_ASM "--asm="
389 #define ALT_LINK "--link="
391 #define IVT_LOC "--ivt-loc="
392 #define NO_DEFLIBS "--nodefaultlibs"
393 #define MPLAB_COMPAT "--mplab-comp"
395 #define NL_OPT "--nl="
396 #define USE_CRT "--use-crt="
398 #define OFMSG_LRSUPPORT "--flr-support"
400 #define OPTIMIZE_GOTO "--optimize-goto"
401 #define OPTIMIZE_CMP "--optimize-cmp"
402 #define OPTIMIZE_DF "--optimize-df"
407 int pic16_mplab_comp=0;
408 extern int pic16_debug_verbose;
409 extern int pic16_ralloc_debug;
410 extern int pic16_pcode_verbose;
413 int pic16_enable_peeps=0;
414 int pic16_nl=0; /* 0 for LF, 1 for CRLF */
416 OPTION pic16_optionsTable[]= {
417 { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"},
418 { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"},
419 { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"},
420 // { 0, "--pomit-config-words", &pic16_options.omit_configw, "omit the generation of configuration words"},
421 // { 0, "--pomit-ivt", &pic16_options.omit_ivt, "omit the generation of the Interrupt Vector Table"},
422 // { 0, "--pleave-reset-vector",&pic16_options.leave_reset, "when omitting IVT leave RESET vector"},
423 { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"},
425 { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"},
426 { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"},
427 { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"},
429 { 0, REP_UDATA, NULL, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
431 { 0, ALT_ASM, NULL, "Use alternative assembler"},
432 { 0, ALT_LINK, NULL, "Use alternative linker"},
434 { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"},
435 { 0, IVT_LOC, NULL, "<nnnn> interrupt vector table location"},
436 { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"},
437 { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
438 { 0, "--fstack", &pic16_fstack, "enable stack optimizations"},
439 { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""},
440 { 0, USE_CRT, NULL, "use <crt-o> run-time initialization module"},
441 { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"},
442 { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"},
443 { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"},
444 { 0, OPTIMIZE_CMP, NULL, "try to optimize some compares"},
445 { 0, OPTIMIZE_DF, NULL, "thoroughly analyze data flow (memory and time intensive!)"},
446 { 0, NULL, NULL, NULL}
450 #define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) )
452 extern char *getStringArg(const char *, char **, int *, int);
453 extern int getIntArg(const char *, char **, int *, int);
456 _pic16_parseOptions (int *pargc, char **argv, int *i)
461 /* TODO: allow port-specific command line options to specify
462 * segment names here.
465 /* check for arguments that have associated an integer variable */
466 while(pic16_optionsTable[j].pparameter) {
467 if(ISOPT( pic16_optionsTable[j].longOpt )) {
468 (*pic16_optionsTable[j].pparameter)++;
474 if(ISOPT(STACK_MODEL)) {
475 stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
476 if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
477 else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
479 fprintf(stderr, "Unknown stack model: %s", stkmodel);
485 if(ISOPT(OPT_BANKSEL)) {
486 pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
490 if(ISOPT(REP_UDATA)) {
491 pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
496 alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
500 if(ISOPT(ALT_LINK)) {
501 alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
506 pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
507 fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc);
514 tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
515 if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
516 else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
518 fprintf(stderr, "invalid termination character id\n");
525 pic16_options.no_crt = 0;
526 pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
532 if(ISOPT(OFMSG_LRSUPPORT)) {
533 pic16_options.opt_flags |= OF_LR_SUPPORT;
538 if (ISOPT(OPTIMIZE_GOTO)) {
539 pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
543 if(ISOPT(OPTIMIZE_CMP)) {
544 pic16_options.opt_flags |= OF_OPTIMIZE_CMP;
548 if (ISOPT(OPTIMIZE_DF)) {
549 pic16_options.opt_flags |= OF_OPTIMIZE_DF;
557 extern set *userIncDirsSet;
559 static void _pic16_initPaths(void)
561 char pic16incDir[512];
562 char pic16libDir[512];
563 set *pic16incDirsSet=NULL;
564 set *pic16libDirsSet=NULL;
567 setMainValue("mcu", pic16->name[2] );
568 addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
570 setMainValue("mcu1", pic16->name[1] );
571 addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
573 sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
574 sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
577 if(!options.nostdinc) {
578 /* setup pic16 include directory */
579 pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
580 includeDirsSet = pic16incDirsSet;
581 // mergeSets(&includeDirsSet, pic16incDirsSet);
583 /* pic16 port should not search to the SDCC standard include directories,
584 * so add here the deleted include dirs that user has issued in command line */
585 mergeSets(&pic16incDirsSet, userIncDirsSet);
587 if(!options.nostdlib) {
588 /* setup pic16 library directory */
589 pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
590 libDirsSet = pic16libDirsSet;
591 // mergeSets(&libDirsSet, pic16libDirsSet);
594 if(!pic16_options.nodefaultlibs) {
595 /* now add the library for the device */
596 sprintf(devlib, "%s.lib", pic16->name[2]);
597 addSet(&libFilesSet, Safe_strdup(devlib));
599 /* add the internal SDCC library */
600 addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
604 extern set *linkOptionsSet;
605 char *msprintf(hTab *pvals, const char *pformat, ...);
606 int my_system(const char *cmd);
608 /* custom function to link objects */
609 static void _pic16_linkEdit(void)
611 hTab *linkValues=NULL;
619 * link command format:
620 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
624 sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
626 shash_add(&linkValues, "linker", "gplink");
628 mergeSets(&tSet, libDirsSet);
629 mergeSets(&tSet, libPathsSet);
631 shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\"")));
632 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
634 shash_add(&linkValues, "outfile", dstFileName);
636 if(fullSrcFileName) {
637 sprintf(temp, "%s.o", dstFileName);
638 // addSetHead(&relFilesSet, Safe_strdup(temp));
639 shash_add(&linkValues, "user_ofile", temp);
642 if(!pic16_options.no_crt)
643 shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
645 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
647 if(!libflags.ignore) {
648 if(libflags.want_libc)
649 addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
651 if(libflags.want_libm)
652 addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
654 if(libflags.want_libio) {
655 sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */
656 addSet(&libFilesSet, Safe_strdup(temp));
659 if(libflags.want_libdebug)
660 addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
663 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
665 lcmd = msprintf(linkValues, lfrm);
667 ret = my_system( lcmd );
676 /* forward declarations */
677 extern const char *pic16_linkCmd[];
678 extern const char *pic16_asmCmd[];
679 extern set *asmOptionsSet;
682 _pic16_finaliseOptions (void)
684 port->mem.default_local_map = data;
685 port->mem.default_globl_map = data;
687 /* peepholes are disabled for the time being */
690 /* explicit enable peepholes for testing */
691 if(pic16_enable_peeps)
694 options.all_callee_saves = 1; // always callee saves
697 options.float_rent = 1;
698 options.intlong_rent = 1;
702 if(alt_asm && strlen(alt_asm))
703 pic16_asmCmd[0] = alt_asm;
705 if(alt_link && strlen(alt_link))
706 pic16_linkCmd[0] = alt_link;
708 if(!pic16_options.no_crt) {
709 pic16_options.omit_ivt = 1;
710 pic16_options.leave_reset = 0;
713 if(options.model == MODEL_SMALL)
714 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
716 if(options.model == MODEL_LARGE)
717 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
722 sprintf(buf, "-D%s -D__%s", pic16->name[2], pic16->name[1]);
723 *(strrchr(buf, 'f')) = 'F';
724 addSet(&asmOptionsSet, Safe_strdup( buf ));
727 if(STACK_MODEL_LARGE) {
728 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
729 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
731 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
732 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
738 if (options.model == MODEL_LARGE)
740 port->mem.default_local_map = xdata;
741 port->mem.default_globl_map = xdata;
745 port->mem.default_local_map = data;
746 port->mem.default_globl_map = data;
749 if (options.stack10bit)
751 if (options.model != MODEL_FLAT24)
754 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
755 fprintf (stderr, "\t10 bit stack mode disabled.\n");
756 options.stack10bit = 0;
760 /* Fixup the memory map for the stack; it is now in
761 * far space and requires a FPOINTER to access it.
764 istack->ptrType = FPOINTER;
771 _pic16_setDefaultOptions (void)
773 options.stackAuto = 0; /* implicit declaration */
774 /* port is not capable yet to allocate separate registers
775 * dedicated for passing certain parameters */
777 /* initialize to defaults section locations, names and addresses */
778 pic16_sectioninfo.at_udata = "udata";
780 /* set pic16 port options to defaults */
781 pic16_options.no_banksel = 0;
782 pic16_options.opt_banksel = 0;
783 pic16_options.omit_configw = 0;
784 pic16_options.omit_ivt = 0;
785 pic16_options.leave_reset = 0;
786 pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
787 pic16_options.ivt_loc = 0x000000;
788 pic16_options.nodefaultlibs = 0;
789 pic16_options.dumpcalltree = 0;
790 pic16_options.crt_name = "crt0i.o"; /* the default crt to link */
791 pic16_options.no_crt = 0; /* use crt by default */
792 pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */
793 pic16_options.gstack = 0;
794 pic16_options.debgen = 0;
798 _pic16_getRegName (struct regs *reg)
807 static char *_pic16_mangleFunctionName(char *sz)
809 // fprintf(stderr, "mangled function name: %s\n", sz);
817 _pic16_genAssemblerPreamble (FILE * of)
819 char *name = pic16_processor_base_name();
823 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
826 fprintf (of, "\tlist\tp=%s\n",&name[1]);
828 if(!pic16_options.omit_configw) {
829 pic16_emitConfigRegs(of);
831 pic16_emitIDRegs(of);
834 fprintf (of, "\tradix dec\n");
837 /* Generate interrupt vector table. */
839 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
842 /* PIC18F family has only two interrupts, the high and the low
843 * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
845 if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
846 fprintf(of, "; RESET vector\n");
847 fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
850 if(!pic16_options.omit_ivt) {
851 fprintf(of, "\tres 4\n");
854 fprintf(of, "; High priority interrupt vector 0x0008\n");
856 fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
857 fprintf(of, "\tres\t12\n");
859 fprintf(of, "\tretfie\n");
860 fprintf(of, "\tres\t14\n");
863 fprintf(of, "; Low priority interrupt vector 0x0018\n");
865 fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
867 fprintf(of, "\tretfie\n");
874 /* return True if the port can handle the type,
875 * False to convert it to function call */
876 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
878 // fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
881 /* multiplication is fixed */
882 /* support mul for char/int/long */
884 && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
888 /* support div for char/int/long */
889 if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
890 && (ic->op == '/'))return TRUE;
898 /* Do CSE estimation */
899 static bool cseCostEstimation (iCode *ic, iCode *pdic)
901 // operand *result = IC_RESULT(ic);
902 // sym_link *result_type = operandType(result);
905 /* VR -- this is an adhoc. Put here after conversation
906 * with Erik Epetrich */
910 || ic->op == EQ_OP) {
912 fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
917 /* if it is a pointer then return ok for now */
918 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
920 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
921 so we will cse only if they are local (i.e. both ic & pdic belong to
922 the same basic block */
923 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
924 /* then if they are the same Basic block then ok */
925 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
930 /* for others it is cheaper to do the cse */
936 /* Indicate which extended bit operations this port supports */
938 hasExtBitOp (int op, int size)
942 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
949 /* Indicate the expense of an access to an output storage class */
951 oclsExpense (struct memmap *oclass)
953 /* The IN_FARSPACE test is compatible with historical behaviour, */
954 /* but I don't think it is applicable to PIC. If so, please feel */
955 /* free to remove this test -- EEP */
956 if (IN_FARSPACE(oclass))
962 /** $1 is the input object file (PIC16 specific) // >>always the basename<<.
963 $2 is always the output file.
964 $3 -L path and -l libraries
965 $l is the list of extra options that should be there somewhere...
966 MUST be terminated with a NULL.
968 const char *pic16_linkCmd[] =
970 "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
975 /** $1 is always the basename.
976 $2 is always the output file.
977 $3 varies (nothing currently)
978 $l is the list of extra options that should be there somewhere...
979 MUST be terminated with a NULL.
981 const char *pic16_asmCmd[] =
983 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
992 "MCU PIC16", /* Target name */
993 "p18f452", /* Processor */
996 TRUE, /* Emit glue around main */
997 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1001 pic16_asmCmd, /* assembler command and arguments */
1002 NULL, /* alternate macro based form */
1003 "-g", /* arguments for debug mode */
1004 NULL, /* arguments for normal mode */
1005 0, /* print externs as global */
1006 ".asm", /* assembler file extension */
1007 NULL /* no do_assemble function */
1010 NULL, // pic16_linkCmd, /* linker command and arguments */
1011 NULL, /* alternate macro based form */
1012 _pic16_linkEdit, //NULL, /* no do_link function */
1013 ".o", /* extension for object files */
1014 0 /* no need for linker file */
1026 3, /* fptr, far pointers (see Microchip) */
1033 "XSEG (XDATA)", // xstack
1034 "STACK (DATA)", // istack
1035 "CSEG (CODE)", // code
1036 "DSEG (DATA)", // data
1037 "ISEG (DATA)", // idata
1038 "PSEG (DATA)", // pdata
1039 "XSEG (XDATA)", // xdata
1040 "BSEG (BIT)", // bit
1041 "RSEG (DATA)", // reg
1042 "GSINIT (CODE)", // static
1043 "OSEG (OVR,DATA)", // overlay
1044 "GSFINAL (CODE)", // post static
1045 "HOME (CODE)", // home
1048 NULL, // default location for auto vars
1049 NULL, // default location for global vars
1050 1 // code is read only 1=yes
1053 NULL, /* genExtraAreaDeclaration */
1054 NULL /* genExatrAreaLinkOptions */
1057 /* stack related information */
1058 -1, /* -1 stack grows downwards, +1 upwards */
1059 1, /* extra overhead when calling between banks */
1060 4, /* extra overhead when the function is an ISR */
1061 1, /* extra overhead for a function call */
1062 1, /* re-entrant space */
1063 0 /* 'banked' call overhead, mild overlap with bank_overhead */
1065 /* pic16 has an 8 bit mul */
1070 pic16_emitDebuggerSymbol
1073 255/3, /* maxCount */
1074 3, /* sizeofElement */
1075 /* The rest of these costs are bogus. They approximate */
1076 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
1077 {4,4,4}, /* sizeofMatchJump[] */
1078 {0,0,0}, /* sizeofRangeCompare[] */
1079 0, /* sizeofSubtract */
1080 3, /* sizeofDispatch */
1084 _pic16_parseOptions,
1087 _pic16_finaliseOptions,
1088 _pic16_setDefaultOptions,
1089 pic16_assignRegisters,
1092 _pic16_genAssemblerPreamble,
1093 NULL, /* no genAssemblerEnd */
1095 NULL, // _pic16_genXINIT
1096 NULL, /* genInitStartup */
1097 _pic16_reset_regparm,
1099 _process_pragma, /* process a pragma */
1100 _pic16_mangleFunctionName, /* mangles function name */
1102 hasExtBitOp, /* hasExtBitOp */
1103 oclsExpense, /* oclsExpense */
1105 TRUE, /* little endian */
1108 1, /* transform <= to ! > */
1109 1, /* transform >= to ! < */
1110 1, /* transform != to !(a == b) */
1112 FALSE, /* No array initializer support. */
1113 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */
1114 NULL, /* no builtin functions */
1115 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1116 1, /* reset labelKey to 1 */
1117 1, /* globals & local static allowed */