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[] =
73 pic16_sectioninfo_t pic16_sectioninfo;
76 extern char *pic16_processor_base_name(void);
78 void pic16_pCodeInitRegisters(void);
80 void pic16_assignRegisters (eBBlock ** ebbs, int count);
82 static int regParmFlg = 0; /* determine if we can register a parameter */
84 pic16_options_t pic16_options;
86 extern set *includeDirsSet;
87 extern set *dataDirsSet;
88 extern set *libFilesSet;
90 /* Also defined in gen.h, but the #include is commented out */
91 /* for an unknowned reason. - EEP */
92 void pic16_emitDebuggerSymbol (char *);
94 extern regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alias, operand *refop);
95 extern void pic16_emitConfigRegs(FILE *of);
96 extern void pic16_emitIDRegs(FILE *of);
103 asm_addTree (&asm_asxxxx_mapping);
104 pic16_pCodeInitRegisters();
109 _pic16_reset_regparm (void)
115 _pic16_regparm (sym_link * l)
117 /* force all parameters via SEND/RECEIVE */
118 if(0 /*pic16_options.ip_stack*/) {
119 /* for this processor it is simple
120 * can pass only the first parameter in a register */
121 if(regParmFlg)return 0;
123 return 1; //regParmFlg;
125 /* otherwise pass all arguments in registers via SEND/RECEIVE */
132 int initsfpnt=0; /* set to 1 if source provides a pragma for stack
133 * so glue() later emits code to initialize stack/frame pointers */
136 set *sectNames=NULL; /* list of section listed in pragma directives */
137 set *sectSyms=NULL; /* list of symbols set in a specific section */
138 set *wparamList=NULL;
142 unsigned want_libc: 1;
143 unsigned want_libm: 1;
144 unsigned want_libio: 1;
145 unsigned want_libdebug: 1;
146 } libflags = { 0, 0, 0, 0, 0 };
150 _process_pragma(const char *sz)
152 static const char *WHITE = " \t\n";
153 static const char *WHITECOMMA = " \t\n,";
155 char *ptr = strtok((char *)sz, WHITE);
157 /* #pragma maxram [maxram] */
158 if (startsWith (ptr, "maxram")) {
159 char *maxRAM = strtok((char *)NULL, WHITE);
161 if (maxRAM != (char *)NULL) {
165 maxRAMVal = constVal(maxRAM);
166 maxRAMaddress = (int)floatFromVal(maxRAMVal);
167 pic16_setMaxRAM(maxRAMaddress);
173 /* #pragma stack [stack-position] [stack-len] */
174 if(startsWith(ptr, "stack")) {
175 char *stackPosS = strtok((char *)NULL, WHITE);
176 char *stackLenS = strtok((char *)NULL, WHITE);
182 stackPosVal = constVal( stackPosS );
183 stackPos = (unsigned int)floatFromVal( stackPosVal );
187 stackLenVal = constVal( stackLenS );
188 stackLen = (unsigned int)floatFromVal( stackLenVal );
193 fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
194 filename, lineno-1, stackLen, stackLen);
196 // fprintf(stderr, "%s:%d setting stack to default size %d\n", __FILE__, __LINE__, stackLen);
199 // fprintf(stderr, "Initializing stack pointer at 0x%x len 0x%x\n", stackPos, stackLen);
201 reg=newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
202 addSet(&pic16_fix_udata, reg);
204 reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
205 addSet(&pic16_fix_udata, reg);
207 sym = newSymbol("stack", 0);
208 sprintf(sym->rname, "_%s", sym->name);
209 addSet(&publics, sym);
211 sym = newSymbol("stack_end", 0);
212 sprintf(sym->rname, "_%s", sym->name);
213 addSet(&publics, sym);
215 initsfpnt = 1; // force glue() to initialize stack/frame pointers */
220 /* #pragma code [symbol] [location] */
221 if(startsWith(ptr, "code")) {
222 char *symname = strtok((char *)NULL, WHITE);
223 char *location = strtok((char *)NULL, WHITE);
227 absS = Safe_calloc(1, sizeof(absSym));
228 sprintf(absS->name, "_%s", symname);
230 addr = constVal( location );
231 absS->address = (unsigned int)floatFromVal( addr );
233 if((absS->address % 2) != 0) {
235 fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
236 filename, lineno-1, absS->address);
239 addSet(&absSymSet, absS);
240 // fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
241 // __FILE__, __LINE__, symname, absS->address);
246 /* #pragma udata [section-name] [symbol] */
247 if(startsWith(ptr, "udata")) {
248 char *sectname = strtok((char *)NULL, WHITE);
249 char *symname = strtok((char *)NULL, WHITE);
256 ssym = Safe_calloc(1, sizeof(sectSyms));
257 ssym->name = Safe_calloc(1, strlen(symname)+2);
258 sprintf(ssym->name, "_%s", symname);
261 addSet(§Syms, ssym);
263 nsym = newSymbol(symname, 0);
264 strcpy(nsym->rname, ssym->name);
266 checkAddSym(&publics, nsym);
270 for(snam=setFirstItem(sectNames);snam;snam=setNextItem(sectNames)) {
271 if(!strcmp(sectname, snam->name)){ found=1; break; }
275 snam = Safe_calloc(1, sizeof(sectNames));
276 snam->name = Safe_strdup( sectname );
277 snam->regsSet = NULL;
279 addSet(§Names, snam);
282 ssym->section = snam;
285 fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
286 ssym->name, snam->name, snam);
289 symname = strtok((char *)NULL, WHITE);
295 /* #pragma wparam function1[, function2[,...]] */
296 if(startsWith(ptr, "wparam")) {
297 char *fname = strtok((char *)NULL, WHITECOMMA);
300 addSet(&wparamList, Safe_strdup(fname));
302 // debugf("passing with WREG to %s\n", fname);
303 fname = strtok((char *)NULL, WHITECOMMA);
309 /* #pragma library library_module */
310 if(startsWith(ptr, "library")) {
311 char *lmodule = strtok((char *)NULL, WHITE);
315 * c link the C library
316 * math link the math library
317 * io link the IO library
318 * debug link the debug libary
319 * anything else, will link as-is */
320 if(!strcmp(lmodule, "c"))libflags.want_libc = 1;
321 else if(!strcmp(lmodule, "math"))libflags.want_libm = 1;
322 else if(!strcmp(lmodule, "io"))libflags.want_libio = 1;
323 else if(!strcmp(lmodule, "debug"))libflags.want_libdebug = 1;
324 else if(!strcmp(lmodule, "ignore"))libflags.ignore = 1;
326 if(!libflags.ignore) {
327 fprintf(stderr, "link library %s\n", lmodule);
328 addSetHead(&libFilesSet, lmodule);
341 #define REP_UDATA "--preplace-udata-with="
343 #define STACK_MODEL "--pstack-model="
344 #define OPT_BANKSEL "--obanksel="
346 #define ALT_ASM "--asm="
347 #define ALT_LINK "--link="
349 #define IVT_LOC "--ivt-loc"
350 #define NO_DEFLIBS "--nodefaultlibs"
351 #define MPLAB_COMPAT "--mplab-comp"
353 #define NL_OPT "--nl="
354 #define USE_CRT "--use-crt="
356 #define OFMSG_LRSUPPORT "--flr-support"
358 #define OPTIMIZE_GOTO "--optimize-goto"
363 int pic16_mplab_comp=0;
364 extern int pic16_debug_verbose;
365 extern int pic16_ralloc_debug;
366 extern int pic16_pcode_verbose;
369 int pic16_enable_peeps=0;
370 int pic16_nl=0; /* 0 for LF, 1 for CRLF */
372 OPTION pic16_optionsTable[]= {
373 { 0, NO_DEFLIBS, &pic16_options.nodefaultlibs, "do not link default libraries when linking"},
374 { 0, "--pno-banksel", &pic16_options.no_banksel, "do not generate BANKSEL assembler directives"},
375 { 0, OPT_BANKSEL, NULL, "set banksel optimization level (default=0 no)"},
376 // { 0, "--pomit-config-words", &pic16_options.omit_configw, "omit the generation of configuration words"},
377 // { 0, "--pomit-ivt", &pic16_options.omit_ivt, "omit the generation of the Interrupt Vector Table"},
378 // { 0, "--pleave-reset-vector",&pic16_options.leave_reset, "when omitting IVT leave RESET vector"},
379 { 0, STACK_MODEL, NULL, "use stack model 'small' (default) or 'large'"},
381 { 0, "--debug-xtra", &pic16_debug_verbose, "show more debug info in assembly output"},
382 { 0, "--debug-ralloc", &pic16_ralloc_debug, "dump register allocator debug file *.d"},
383 { 0, "--pcode-verbose", &pic16_pcode_verbose, "dump pcode related info"},
385 { 0, REP_UDATA, NULL, "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
387 { 0, ALT_ASM, NULL, "Use alternative assembler"},
388 { 0, ALT_LINK, NULL, "Use alternative linker"},
390 { 0, "--denable-peeps", &pic16_enable_peeps, "explicit enable of peepholes"},
391 { 0, IVT_LOC, NULL, "<nnnn> interrupt vector table location"},
392 { 0, "--calltree", &pic16_options.dumpcalltree, "dump call tree in .calltree file"},
393 { 0, MPLAB_COMPAT, &pic16_mplab_comp, "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
394 { 0, "--fstack", &pic16_fstack, "enable stack optimizations"},
395 { 0, NL_OPT, NULL, "new line, \"lf\" or \"crlf\""},
396 { 0, USE_CRT, NULL, "use <crt-o> run-time initialization module"},
397 { 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"},
398 { 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"},
399 // { 0, OFMSG_LRSUPPORT, NULL, "use support functions for local register store/restore"},
400 { 0, OPTIMIZE_GOTO, NULL, "try to use (conditional) BRA instead of GOTO"},
401 { 0, NULL, NULL, NULL}
405 #define ISOPT(str) !strncmp(argv[ *i ], str, strlen(str) )
407 extern char *getStringArg(const char *, char **, int *, int);
408 extern int getIntArg(const char *, char **, int *, int);
411 _pic16_parseOptions (int *pargc, char **argv, int *i)
416 /* TODO: allow port-specific command line options to specify
417 * segment names here.
420 /* check for arguments that have associated an integer variable */
421 while(pic16_optionsTable[j].pparameter) {
422 if(ISOPT( pic16_optionsTable[j].longOpt )) {
423 (*pic16_optionsTable[j].pparameter)++;
429 if(ISOPT(STACK_MODEL)) {
430 stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
431 if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
432 else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
434 fprintf(stderr, "Unknown stack model: %s", stkmodel);
440 if(ISOPT(OPT_BANKSEL)) {
441 pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
445 if(ISOPT(REP_UDATA)) {
446 pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
451 alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
455 if(ISOPT(ALT_LINK)) {
456 alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
461 pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
468 tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
469 if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
470 else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
472 fprintf(stderr, "invalid termination character id\n");
479 pic16_options.no_crt = 0;
480 pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
486 if(ISOPT(OFMSG_LRSUPPORT)) {
487 pic16_options.opt_flags |= OF_LR_SUPPORT;
493 if (ISOPT(OPTIMIZE_GOTO)) {
494 pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
502 extern set *userIncDirsSet;
504 static void _pic16_initPaths(void)
506 char pic16incDir[512];
507 char pic16libDir[512];
508 set *pic16incDirsSet=NULL;
509 set *pic16libDirsSet=NULL;
512 setMainValue("mcu", pic16->name[2] );
513 addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
515 sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
516 sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
519 if(!options.nostdinc) {
520 /* setup pic16 include directory */
521 pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
522 includeDirsSet = pic16incDirsSet;
523 // mergeSets(&includeDirsSet, pic16incDirsSet);
525 /* pic16 port should not search to the SDCC standard include directories,
526 * so add here the deleted include dirs that user has issued in command line */
527 mergeSets(&pic16incDirsSet, userIncDirsSet);
529 if(!options.nostdlib) {
530 /* setup pic16 library directory */
531 pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
532 libDirsSet = pic16libDirsSet;
533 // mergeSets(&libDirsSet, pic16libDirsSet);
536 if(!pic16_options.nodefaultlibs) {
537 /* now add the library for the device */
538 sprintf(devlib, "%s.lib", pic16->name[2]);
539 addSet(&libFilesSet, Safe_strdup(devlib));
541 /* add the internal SDCC library */
542 addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
546 extern set *linkOptionsSet;
547 char *msprintf(hTab *pvals, const char *pformat, ...);
548 int my_system(const char *cmd);
550 /* custom function to link objects */
551 static void _pic16_linkEdit(void)
553 hTab *linkValues=NULL;
561 * link command format:
562 * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
566 sprintf(lfrm, "{linker} {incdirs} {lflags} -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}");
568 shash_add(&linkValues, "linker", "gplink");
570 mergeSets(&tSet, libDirsSet);
571 mergeSets(&tSet, libPathsSet);
573 shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\"")));
574 shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
576 shash_add(&linkValues, "outfile", dstFileName);
578 if(fullSrcFileName) {
579 sprintf(temp, "%s.o", dstFileName);
580 // addSetHead(&relFilesSet, Safe_strdup(temp));
581 shash_add(&linkValues, "user_ofile", temp);
584 if(!pic16_options.no_crt)
585 shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
587 shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
589 if(!libflags.ignore) {
590 if(libflags.want_libc)
591 addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
593 if(libflags.want_libm)
594 addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
596 if(libflags.want_libio) {
597 sprintf(temp, "libio%s.lib", pic16->name[1]); /* build libio18f452.lib name */
598 addSet(&libFilesSet, Safe_strdup(temp));
601 if(libflags.want_libdebug)
602 addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
605 shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
607 lcmd = msprintf(linkValues, lfrm);
609 ret = my_system( lcmd );
618 /* forward declarations */
619 extern const char *pic16_linkCmd[];
620 extern const char *pic16_asmCmd[];
621 extern set *asmOptionsSet;
624 _pic16_finaliseOptions (void)
626 port->mem.default_local_map = data;
627 port->mem.default_globl_map = data;
629 /* peepholes are disabled for the time being */
632 /* explicit enable peepholes for testing */
633 if(pic16_enable_peeps)
636 options.all_callee_saves = 1; // always callee saves
639 options.float_rent = 1;
640 options.intlong_rent = 1;
644 if(alt_asm && strlen(alt_asm))
645 pic16_asmCmd[0] = alt_asm;
647 if(alt_link && strlen(alt_link))
648 pic16_linkCmd[0] = alt_link;
650 if(!pic16_options.no_crt) {
651 pic16_options.omit_ivt = 1;
652 pic16_options.leave_reset = 0;
655 if(options.model == MODEL_SMALL)
656 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
658 if(options.model == MODEL_LARGE)
659 addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
661 if(STACK_MODEL_LARGE) {
662 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
663 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
665 addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
666 addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
672 if (options.model == MODEL_LARGE)
674 port->mem.default_local_map = xdata;
675 port->mem.default_globl_map = xdata;
679 port->mem.default_local_map = data;
680 port->mem.default_globl_map = data;
683 if (options.stack10bit)
685 if (options.model != MODEL_FLAT24)
688 "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
689 fprintf (stderr, "\t10 bit stack mode disabled.\n");
690 options.stack10bit = 0;
694 /* Fixup the memory map for the stack; it is now in
695 * far space and requires a FPOINTER to access it.
698 istack->ptrType = FPOINTER;
705 _pic16_setDefaultOptions (void)
707 options.stackAuto = 0; /* implicit declaration */
708 /* port is not capable yet to allocate separate registers
709 * dedicated for passing certain parameters */
711 /* initialize to defaults section locations, names and addresses */
712 pic16_sectioninfo.at_udata = "udata";
714 /* set pic16 port options to defaults */
715 pic16_options.no_banksel = 0;
716 pic16_options.opt_banksel = 0;
717 pic16_options.omit_configw = 0;
718 pic16_options.omit_ivt = 0;
719 pic16_options.leave_reset = 0;
720 pic16_options.stack_model = 0; /* 0 for 'small', 1 for 'large' */
721 pic16_options.ivt_loc = 0x000000;
722 pic16_options.nodefaultlibs = 0;
723 pic16_options.dumpcalltree = 0;
724 pic16_options.crt_name = "crt0i.o"; /* the default crt to link */
725 pic16_options.no_crt = 0; /* use crt by default */
726 pic16_options.ip_stack = 1; /* set to 1 to enable ipop/ipush for stack */
727 pic16_options.gstack = 0;
728 pic16_options.debgen = 0;
732 _pic16_getRegName (struct regs *reg)
741 static char *_pic16_mangleFunctionName(char *sz)
743 // fprintf(stderr, "mangled function name: %s\n", sz);
751 _pic16_genAssemblerPreamble (FILE * of)
753 char *name = pic16_processor_base_name();
757 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
760 fprintf (of, "\tlist\tp=%s\n",&name[1]);
762 if(!pic16_options.omit_configw) {
763 pic16_emitConfigRegs(of);
765 pic16_emitIDRegs(of);
768 fprintf (of, "\tradix dec\n");
771 /* Generate interrupt vector table. */
773 _pic16_genIVT (FILE * of, symbol ** interrupts, int maxInterrupts)
776 /* PIC18F family has only two interrupts, the high and the low
777 * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
779 if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
780 fprintf(of, "; RESET vector\n");
781 fprintf(of, "\tgoto\t__sdcc_gsinit_startup\n");
784 if(!pic16_options.omit_ivt) {
785 fprintf(of, "\tres 4\n");
788 fprintf(of, "; High priority interrupt vector 0x0008\n");
790 fprintf(of, "\tgoto\t%s\n", interrupts[1]->rname);
791 fprintf(of, "\tres\t12\n");
793 fprintf(of, "\tretfie\n");
794 fprintf(of, "\tres\t14\n");
797 fprintf(of, "; Low priority interrupt vector 0x0018\n");
799 fprintf(of, "\tgoto\t%s\n", interrupts[2]->rname);
801 fprintf(of, "\tretfie\n");
808 /* return True if the port can handle the type,
809 * False to convert it to function call */
810 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
812 // fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
815 /* multiplication is fixed */
816 /* support mul for char/int/long */
818 && (getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 2))return TRUE;
822 /* support div for char/int/long */
823 if((getSize(OP_SYMBOL(IC_LEFT(ic))->type ) < 0)
824 && (ic->op == '/'))return TRUE;
832 /* Do CSE estimation */
833 static bool cseCostEstimation (iCode *ic, iCode *pdic)
835 // operand *result = IC_RESULT(ic);
836 // sym_link *result_type = operandType(result);
839 /* VR -- this is an adhoc. Put here after conversation
840 * with Erik Epetrich */
844 || ic->op == EQ_OP) {
846 fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
851 /* if it is a pointer then return ok for now */
852 if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
854 /* if bitwise | add & subtract then no since mcs51 is pretty good at it
855 so we will cse only if they are local (i.e. both ic & pdic belong to
856 the same basic block */
857 if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
858 /* then if they are the same Basic block then ok */
859 if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
864 /* for others it is cheaper to do the cse */
870 /* Indicate which extended bit operations this port supports */
872 hasExtBitOp (int op, int size)
876 /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
883 /* Indicate the expense of an access to an output storage class */
885 oclsExpense (struct memmap *oclass)
887 /* The IN_FARSPACE test is compatible with historical behaviour, */
888 /* but I don't think it is applicable to PIC. If so, please feel */
889 /* free to remove this test -- EEP */
890 if (IN_FARSPACE(oclass))
896 /** $1 is the input object file (PIC16 specific) // >>always the basename<<.
897 $2 is always the output file.
898 $3 -L path and -l libraries
899 $l is the list of extra options that should be there somewhere...
900 MUST be terminated with a NULL.
902 const char *pic16_linkCmd[] =
904 "gplink", "$l", "-o \"$2\"", "\"$1\"","$3", NULL
909 /** $1 is always the basename.
910 $2 is always the output file.
911 $3 varies (nothing currently)
912 $l is the list of extra options that should be there somewhere...
913 MUST be terminated with a NULL.
915 const char *pic16_asmCmd[] =
917 "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
926 "MCU PIC16", /* Target name */
927 "p18f452", /* Processor */
930 TRUE, /* Emit glue around main */
931 MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
935 pic16_asmCmd, /* assembler command and arguments */
936 NULL, /* alternate macro based form */
937 "-g", /* arguments for debug mode */
938 NULL, /* arguments for normal mode */
939 0, /* print externs as global */
940 ".asm", /* assembler file extension */
941 NULL /* no do_assemble function */
944 NULL, // pic16_linkCmd, /* linker command and arguments */
945 NULL, /* alternate macro based form */
946 _pic16_linkEdit, //NULL, /* no do_link function */
947 ".o", /* extension for object files */
948 0 /* no need for linker file */
960 3, /* fptr, far pointers (see Microchip) */
967 "XSEG (XDATA)", // xstack
968 "STACK (DATA)", // istack
969 "CSEG (CODE)", // code
970 "DSEG (DATA)", // data
971 "ISEG (DATA)", // idata
972 "PSEG (DATA)", // pdata
973 "XSEG (XDATA)", // xdata
975 "RSEG (DATA)", // reg
976 "GSINIT (CODE)", // static
977 "OSEG (OVR,DATA)", // overlay
978 "GSFINAL (CODE)", // post static
979 "HOME (CODE)", // home
982 NULL, // default location for auto vars
983 NULL, // default location for global vars
984 1 // code is read only 1=yes
987 NULL, /* genExtraAreaDeclaration */
988 NULL /* genExatrAreaLinkOptions */
991 /* stack related information */
992 -1, /* -1 stack grows downwards, +1 upwards */
993 1, /* extra overhead when calling between banks */
994 4, /* extra overhead when the function is an ISR */
995 1, /* extra overhead for a function call */
996 1, /* re-entrant space */
997 0 /* 'banked' call overhead, mild overlap with bank_overhead */
999 /* pic16 has an 8 bit mul */
1004 pic16_emitDebuggerSymbol
1007 255/3, /* maxCount */
1008 3, /* sizeofElement */
1009 /* The rest of these costs are bogus. They approximate */
1010 /* the behavior of src/SDCCicode.c 1.207 and earlier. */
1011 {4,4,4}, /* sizeofMatchJump[] */
1012 {0,0,0}, /* sizeofRangeCompare[] */
1013 0, /* sizeofSubtract */
1014 3, /* sizeofDispatch */
1018 _pic16_parseOptions,
1021 _pic16_finaliseOptions,
1022 _pic16_setDefaultOptions,
1023 pic16_assignRegisters,
1026 _pic16_genAssemblerPreamble,
1027 NULL, /* no genAssemblerEnd */
1029 NULL, // _pic16_genXINIT
1030 NULL, /* genInitStartup */
1031 _pic16_reset_regparm,
1033 _process_pragma, /* process a pragma */
1034 _pic16_mangleFunctionName, /* mangles function name */
1036 hasExtBitOp, /* hasExtBitOp */
1037 oclsExpense, /* oclsExpense */
1039 TRUE, /* little endian */
1042 1, /* transform <= to ! > */
1043 1, /* transform >= to ! < */
1044 1, /* transform != to !(a == b) */
1046 FALSE, /* No array initializer support. */
1047 0, //cseCostEstimation, /* !!!no CSE cost estimation yet */
1048 NULL, /* no builtin functions */
1049 GPOINTER, /* treat unqualified pointers as "generic" pointers */
1050 1, /* reset labelKey to 1 */
1051 1, /* globals & local static allowed */