* src/port.h: use const poiters to strings
[fw/sdcc] / src / pic16 / main.c
1 /*-------------------------------------------------------------------------
2
3   main.c - pic16 specific general functions.
4
5    Written by - Scott Dattalo scott@dattalo.com
6    Ported to PIC16 by - Martin Dubuc m.debuc@rogers.com
7     
8    Note that mlh prepended _pic16_ on the static functions.  Makes
9    it easier to set a breakpoint using the debugger.
10
11
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
15    later version.
16    
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.
21    
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 -------------------------------------------------------------------------*/
26
27 #include "common.h"
28 #include "main.h"
29 #include "ralloc.h"
30 #include "device.h"
31 #include "SDCCutil.h"
32 #include "glue.h"
33 #include "pcode.h"
34 #include "SDCCargs.h"
35 #include "dbuf_string.h"
36
37
38 static char _defaultRules[] =
39 {
40 #include "peeph.rul"
41 };
42
43 /* list of key words used by pic16 */
44 static char *_pic16_keywords[] =
45 {
46   "at",
47   "code",
48   "critical",
49   "register",
50   "data",
51   "far",
52   "interrupt",
53   "near",
54   "pdata",
55   "reentrant",
56   "sfr",
57   "sfr16",
58   "using",
59   "_data",
60   "_code",
61   "_generic",
62   "_near",
63   "_pdata",
64   "_naked",
65   "shadowregs",
66   "wparam",
67   "prodlp",
68   "prodhp",
69   "fsr0lp",
70   "fixed16x16",
71   
72 //  "bit",
73 //  "idata",
74 //  "sbit",
75 //  "xdata",
76 //  "_xdata",
77 //  "_idata",
78   NULL
79 };
80
81
82 pic16_sectioninfo_t pic16_sectioninfo;
83
84 int xinst=0;
85
86
87 extern char *pic16_processor_base_name(void);
88
89 void  pic16_pCodeInitRegisters(void);
90
91 void pic16_assignRegisters (ebbIndex *);
92
93 static int regParmFlg = 0;      /* determine if we can register a parameter */
94
95 pic16_options_t pic16_options;
96
97 extern set *includeDirsSet;
98 extern set *dataDirsSet;
99 extern set *libFilesSet;
100
101 /* Also defined in gen.h, but the #include is commented out */
102 /* for an unknowned reason. - EEP */
103 void pic16_emitDebuggerSymbol (char *);
104  
105 extern void pic16_emitConfigRegs(FILE *of);
106 extern void pic16_emitIDRegs(FILE *of);
107
108
109
110 static void
111 _pic16_init (void)
112 {
113   asm_addTree (&asm_asxxxx_mapping);
114   pic16_pCodeInitRegisters();
115   maxInterrupts = 2;
116 }
117
118 static void
119 _pic16_reset_regparm (void)
120 {
121   regParmFlg = 0;
122 }
123
124 static int
125 _pic16_regparm (sym_link * l, bool reentrant)
126 {
127   /* force all parameters via SEND/RECEIVE */
128   if(0 /*pic16_options.ip_stack*/) {
129     /* for this processor it is simple
130      * can pass only the first parameter in a register */
131     if(regParmFlg)return 0;
132       regParmFlg++;
133       return 1; //regParmFlg;
134   } else {
135     /* otherwise pass all arguments in registers via SEND/RECEIVE */
136     regParmFlg++;// = 1;
137     return regParmFlg;
138   }
139 }
140
141
142 int initsfpnt=0;                /* set to 1 if source provides a pragma for stack
143                                  * so glue() later emits code to initialize stack/frame pointers */
144 set *absSymSet;
145
146 set *sectNames=NULL;                    /* list of section listed in pragma directives */
147 set *sectSyms=NULL;                     /* list of symbols set in a specific section */
148 set *wparamList=NULL;
149
150 #if 0
151 /* This is an experimental code for #pragma inline
152    and is temporarily disabled for 2.5.0 release */
153 set *asmInlineMap=NULL;
154 #endif  /* 0 */
155
156 struct {
157   unsigned ignore: 1;
158   unsigned want_libc: 1;
159   unsigned want_libm: 1;
160   unsigned want_libio: 1;
161   unsigned want_libdebug: 1;
162 } libflags = { 0, 0, 0, 0, 0 };
163   
164
165 enum {
166   P_MAXRAM = 1,
167   P_STACK,
168   P_CODE,
169   P_UDATA,
170   P_LIBRARY
171 };
172
173 static int
174 do_pragma(int id, const char *name, const char *cp)
175 {
176   struct pragma_token_s token;
177   int err = 0;
178   int processed = 1;
179
180   init_pragma_token(&token);
181
182   switch (id)
183     {
184     /* #pragma maxram [maxram] */
185     case P_MAXRAM:
186       {
187         int max_ram;
188
189         cp = get_pragma_token(cp, &token);
190         if (TOKEN_INT == token.type)
191           max_ram = token.val.int_val;
192         else
193           {
194             err = 1;
195             break;
196           }
197
198         cp = get_pragma_token(cp, &token);
199         if (TOKEN_EOL != token.type)
200           {
201             err = 1;
202             break;
203           }
204
205         pic16_setMaxRAM(max_ram);
206       }
207       break;
208
209     /* #pragma stack [stack-position] [stack-len] */
210     case  P_STACK:
211       {
212         unsigned int stackPos, stackLen;
213         regs *reg;
214         symbol *sym;
215
216         cp = get_pragma_token(cp, &token);
217         if (TOKEN_INT != token.type)
218           {
219             err = 1;
220             break;
221           }
222         stackPos = token.val.int_val;
223
224         cp = get_pragma_token(cp, &token);
225         if (TOKEN_INT != token.type)
226           {
227             err = 1;
228             break;
229           }
230         stackLen = token.val.int_val;
231
232         cp = get_pragma_token(cp, &token);
233         if (TOKEN_EOL != token.type)
234           {
235             err = 1;
236             break;
237           }
238
239         if (stackLen < 1) {
240           stackLen = 64;
241           fprintf(stderr, "%s:%d: warning: setting stack to default size %d (0x%04x)\n",
242                   filename, lineno, stackLen, stackLen);
243         }
244
245         /* check sanity of stack */
246         if ((stackPos >> 8) != ((stackPos + stackLen - 1) >> 8)) {
247           fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] crosses memory bank boundaries (not fully tested)\n",
248                   filename, lineno, stackPos, stackPos + stackLen - 1);
249         }
250
251         if (pic16) {
252           if (stackPos < pic16->acsSplitOfs) {
253             fprintf (stderr, "%s:%u: warning: stack [0x%03X, 0x%03X] intersects with the access bank [0x000,0x%03x] -- this is highly discouraged!\n",
254                   filename, lineno, stackPos, stackPos + stackLen - 1, pic16->acsSplitOfs);
255           }
256
257           if (stackPos+stackLen > 0xF00 + pic16->acsSplitOfs) {
258             fprintf (stderr, "%s:%u: warning: stack [0x%03X,0x%03X] intersects with special function registers [0x%03X,0xFFF]-- this is highly discouraged!\n",
259                    filename, lineno, stackPos, stackPos + stackLen - 1, 0xF00 + pic16->acsSplitOfs);
260           }
261
262           if (stackPos+stackLen > pic16->RAMsize) {
263             fprintf (stderr, "%s:%u: error: stack [0x%03X,0x%03X] is placed outside available memory [0x000,0x%03X]!\n",
264                   filename, lineno, stackPos, stackPos + stackLen - 1, pic16->RAMsize-1);
265             err = 1;
266             break;
267           }
268         }
269
270         reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos, "_stack", stackLen-1, 0, NULL);
271         addSet(&pic16_fix_udata, reg);
272
273         reg = newReg(REG_SFR, PO_SFR_REGISTER, stackPos + stackLen-1, "_stack_end", 1, 0, NULL);
274         addSet(&pic16_fix_udata, reg);
275
276         sym = newSymbol("stack", 0);
277         sprintf(sym->rname, "_%s", sym->name);
278         addSet(&publics, sym);
279
280         sym = newSymbol("stack_end", 0);
281         sprintf(sym->rname, "_%s", sym->name);
282         addSet(&publics, sym);
283     
284         initsfpnt = 1;    // force glue() to initialize stack/frame pointers */
285       }
286       break;
287
288     /* #pragma code [symbol] [location] */
289     case P_CODE:
290       {
291         absSym *absS;
292
293         cp = get_pragma_token(cp, &token);
294         if (TOKEN_STR != token.type)
295           goto code_err;
296
297         absS = Safe_calloc(1, sizeof(absSym));
298         sprintf(absS->name, "_%s", get_pragma_string(&token));
299
300         cp = get_pragma_token(cp, &token);
301         if (TOKEN_INT != token.type)
302           {
303           code_err:
304             //fprintf (stderr, "%s:%d: #pragma code [symbol] [location] -- symbol or location missing\n", filename, lineno);
305             err = 1;
306             break;
307           }
308         absS->address = token.val.int_val;
309
310         cp = get_pragma_token(cp, &token);
311         if (TOKEN_EOL != token.type)
312           {
313             err = 1;
314             break;
315           }
316
317         if ((absS->address % 2) != 0) {
318           absS->address--;
319           fprintf(stderr, "%s:%d: warning: code memory locations should be word aligned, will locate to 0x%06x instead\n",
320                   filename, lineno, absS->address);
321         }
322
323         addSet(&absSymSet, absS);
324 //      fprintf(stderr, "%s:%d symbol %s will be placed in location 0x%06x in code memory\n",
325 //        __FILE__, __LINE__, symname, absS->address);
326       }
327       break;
328
329     /* #pragma udata [section-name] [symbol] */
330     case P_UDATA:
331       {
332         char *sectname;
333         const char *symname;
334         symbol *nsym;
335         sectSym *ssym;
336         sectName *snam;
337         int found = 0;
338
339         cp = get_pragma_token(cp, &token);
340         if (TOKEN_STR == token.type)
341           sectname = Safe_strdup(get_pragma_string(&token));
342         else
343           {
344             err = 1;
345             break;
346           }
347
348         cp = get_pragma_token(cp, &token);
349         if (TOKEN_STR == token.type)
350           symname = get_pragma_string(&token);
351         else
352           {
353             //fprintf (stderr, "%s:%d: #pragma udata [section-name] [symbol] -- section-name or symbol missing!\n", filename, lineno);
354             err = 1;
355             symname = NULL;
356           }
357
358         while (symname)
359           {
360             ssym = Safe_calloc(1, sizeof(sectSym));
361             ssym->name = Safe_calloc(1, strlen(symname) + 2);
362             sprintf(ssym->name, "%s%s", port->fun_prefix, symname);
363             ssym->reg = NULL;
364
365             addSet(&sectSyms, ssym);
366
367             nsym = newSymbol((char *)symname, 0);
368             strcpy(nsym->rname, ssym->name);
369
370 #if 0
371             checkAddSym(&publics, nsym);
372 #endif
373
374             found = 0;
375             for (snam = setFirstItem(sectNames);snam;snam=setNextItem(sectNames))
376               {
377                 if (!strcmp(sectname, snam->name))
378                   {
379                     found=1;
380                     break;
381                   }
382               }
383
384             if(!found)
385               {
386                 snam = Safe_calloc(1, sizeof(sectName));
387                 snam->name = Safe_strdup(sectname);
388                 snam->regsSet = NULL;
389
390                 addSet(&sectNames, snam);
391               }
392
393             ssym->section = snam;
394
395 #if 0
396             fprintf(stderr, "%s:%d placing symbol %s at section %s (%p)\n", __FILE__, __LINE__,
397                ssym->name, snam->name, snam);
398 #endif
399
400             cp = get_pragma_token(cp, &token);
401             if (TOKEN_STR == token.type)
402               symname = get_pragma_string(&token);
403             else if (TOKEN_EOL == token.type)
404               symname = NULL;
405             else
406               {
407                 err = 1;
408                 symname = NULL;
409               }
410           }
411
412           Safe_free(sectname);
413       }
414       break;
415
416     /* #pragma library library_module */
417     case P_LIBRARY:
418       {
419         const char *lmodule;
420
421         cp = get_pragma_token(cp, &token);
422         if (TOKEN_EOL != token.type)
423           {
424             lmodule = get_pragma_string(&token);
425
426             /* lmodule can be:
427              * c        link the C library
428              * math     link the math library
429              * io       link the IO library
430              * debug    link the debug libary
431              * anything else, will link as-is */
432      
433             if(!strcmp(lmodule, "c"))
434               libflags.want_libc = 1;
435             else if(!strcmp(lmodule, "math"))
436               libflags.want_libm = 1;
437             else if(!strcmp(lmodule, "io"))
438               libflags.want_libio = 1;
439             else if(!strcmp(lmodule, "debug"))
440               libflags.want_libdebug = 1;
441             else if(!strcmp(lmodule, "ignore"))
442               libflags.ignore = 1;
443             else
444               {
445                 if(!libflags.ignore)
446                   {
447                     fprintf(stderr, "link library %s\n", lmodule);
448                     addSetHead(&libFilesSet, (char *)lmodule);
449                   }
450               }
451           }
452         else
453           {
454             err = 1;
455             break;
456           }
457
458         cp = get_pragma_token(cp, &token);
459         if (TOKEN_EOL != token.type)
460           {
461             err = 1;
462             break;
463           }
464       }
465       break;
466
467 #if 0
468   /* This is an experimental code for #pragma inline
469      and is temporarily disabled for 2.5.0 release */
470     case P_INLINE:
471       {
472         char *tmp = strtok((char *)NULL, WHITECOMMA);
473
474         while(tmp) {
475           addSet(&asmInlineMap, Safe_strdup( tmp ));
476           tmp = strtok((char *)NULL, WHITECOMMA);
477         }
478
479         {
480           char *s;
481           
482           for(s = setFirstItem(asmInlineMap); s ; s = setNextItem(asmInlineMap)) {
483             debugf("inline asm: `%s'\n", s);
484           }
485         }
486       }
487       break;
488 #endif  /* 0 */
489
490     default:
491       processed = 0;
492       break;
493   }
494
495   get_pragma_token(cp, &token);
496
497   if (1 == err)
498     werror(W_BAD_PRAGMA_ARGUMENTS, name);
499
500   free_pragma_token(&token);
501   return processed;
502 }
503
504 static struct pragma_s pragma_tbl[] = {
505   { "maxram",  P_MAXRAM,  0, do_pragma },
506   { "stack",   P_STACK,   0, do_pragma },
507   { "code",    P_CODE,    0, do_pragma },
508   { "udata",   P_UDATA,   0, do_pragma },
509   { "library", P_LIBRARY, 0, do_pragma },
510 /*{ "inline",  P_INLINE,  0, do_pragma }, */
511   { NULL,      0,         0, NULL },
512   };
513
514 static int
515 _process_pragma(const char *s)
516 {
517   return process_pragma_tbl(pragma_tbl, s);
518 }
519
520 #define REP_UDATA       "--preplace-udata-with="
521
522 #define STACK_MODEL     "--pstack-model="
523 #define OPT_BANKSEL     "--obanksel="
524
525 #define ALT_ASM         "--asm="
526 #define ALT_LINK        "--link="
527
528 #define IVT_LOC         "--ivt-loc="
529 #define NO_DEFLIBS      "--nodefaultlibs"
530 #define MPLAB_COMPAT    "--mplab-comp"
531
532 #define NL_OPT          "--nl="
533 #define USE_CRT         "--use-crt="
534
535 #define OFMSG_LRSUPPORT "--flr-support"
536
537 #define OPTIMIZE_GOTO   "--optimize-goto"
538 #define OPTIMIZE_CMP    "--optimize-cmp"
539 #define OPTIMIZE_DF     "--optimize-df"
540
541 char *alt_asm=NULL;
542 char *alt_link=NULL;
543
544 int pic16_mplab_comp=0;
545 extern int pic16_debug_verbose;
546 extern int pic16_ralloc_debug;
547 extern int pic16_pcode_verbose;
548
549 int pic16_fstack=0;
550 int pic16_enable_peeps=0;
551 int pic16_nl=0;                 /* 0 for LF, 1 for CRLF */
552
553 OPTION pic16_optionsTable[]= {
554         { 0,    NO_DEFLIBS,             &pic16_options.nodefaultlibs,   "do not link default libraries when linking"},
555         { 0,    "--pno-banksel",        &pic16_options.no_banksel,      "do not generate BANKSEL assembler directives"},
556         { 0,    OPT_BANKSEL,            NULL,                           "set banksel optimization level (default=0 no)"},
557 //      { 0,    "--pomit-config-words", &pic16_options.omit_configw,    "omit the generation of configuration words"},
558 //      { 0,    "--pomit-ivt",          &pic16_options.omit_ivt,        "omit the generation of the Interrupt Vector Table"},
559 //      { 0,    "--pleave-reset-vector",&pic16_options.leave_reset,     "when omitting IVT leave RESET vector"},
560         { 0,    STACK_MODEL,            NULL,                           "use stack model 'small' (default) or 'large'"},
561
562         { 0,    "--debug-xtra",         &pic16_debug_verbose,   "show more debug info in assembly output"},
563         { 0,    "--debug-ralloc",       &pic16_ralloc_debug,    "dump register allocator debug file *.d"},
564         { 0,    "--pcode-verbose",      &pic16_pcode_verbose,   "dump pcode related info"},
565                 
566         { 0,    REP_UDATA,      NULL,   "Place udata variables at another section: udata_acs, udata_ovr, udata_shr"},
567
568         { 0,    ALT_ASM,        NULL,   "Use alternative assembler"},
569         { 0,    ALT_LINK,       NULL,   "Use alternative linker"},
570
571         { 0,    "--denable-peeps",      &pic16_enable_peeps,    "explicit enable of peepholes"},
572         { 0,    IVT_LOC,        NULL,   "<nnnn> interrupt vector table location"},
573         { 0,    "--calltree",           &pic16_options.dumpcalltree,    "dump call tree in .calltree file"},
574         { 0,    MPLAB_COMPAT,           &pic16_mplab_comp,      "enable compatibility mode for MPLAB utilities (MPASM/MPLINK)"},
575         { 0,    "--fstack",             &pic16_fstack,          "enable stack optimizations"},
576         { 0,    NL_OPT,         NULL,                           "new line, \"lf\" or \"crlf\""},
577         { 0,    USE_CRT,        NULL,   "use <crt-o> run-time initialization module"},
578         { 0,    "--no-crt",     &pic16_options.no_crt,  "do not link any default run-time initialization module"},
579         { 0,    "--gstack",     &pic16_options.gstack,  "trace stack pointer push/pop to overflow"},
580         { 0,    OPTIMIZE_GOTO,  NULL,                   "try to use (conditional) BRA instead of GOTO"},
581         { 0,    OPTIMIZE_CMP,   NULL,                   "try to optimize some compares"},
582         { 0,    OPTIMIZE_DF,    NULL,                   "thoroughly analyze data flow (memory and time intensive!)"},
583         { 0,    "--num-func-alloc-regs", &pic16_options.CATregs, "dump number of temporary registers allocated for each function"},
584 #if XINST
585         { 'y',  "--extended",   &xinst, "enable Extended Instruction Set/Literal Offset Addressing mode"},
586 #endif
587         { 0,    NULL,           NULL,   NULL}
588         };
589
590
591 #define ISOPT(str)      !strncmp(argv[ *i ], str, strlen(str) )
592
593 static bool
594 _pic16_parseOptions (int *pargc, char **argv, int *i)
595 {
596   int j=0;
597   char *stkmodel;
598   
599   /* TODO: allow port-specific command line options to specify
600    * segment names here.
601    */
602   
603     /* check for arguments that have associated an integer variable */
604     while(pic16_optionsTable[j].pparameter) {
605       if(ISOPT( pic16_optionsTable[j].longOpt )) {
606         (*pic16_optionsTable[j].pparameter)++;
607         return TRUE;
608       }
609       j++;
610     }
611
612     if(ISOPT(STACK_MODEL)) {
613       stkmodel = getStringArg(STACK_MODEL, argv, i, *pargc);
614       if(!STRCASECMP(stkmodel, "small"))pic16_options.stack_model = 0;
615       else if(!STRCASECMP(stkmodel, "large"))pic16_options.stack_model = 1;
616       else {
617         fprintf(stderr, "Unknown stack model: %s", stkmodel);
618         exit(EXIT_FAILURE);
619       }
620       return TRUE;
621     }
622
623     if(ISOPT(OPT_BANKSEL)) {
624       pic16_options.opt_banksel = getIntArg(OPT_BANKSEL, argv, i, *pargc);
625       return TRUE;
626     }
627
628     if(ISOPT(REP_UDATA)) {
629       pic16_sectioninfo.at_udata = Safe_strdup(getStringArg(REP_UDATA, argv, i, *pargc));
630       return TRUE;
631     }
632         
633     if(ISOPT(ALT_ASM)) {
634       alt_asm = Safe_strdup(getStringArg(ALT_ASM, argv, i, *pargc));
635       return TRUE;
636     }
637         
638     if(ISOPT(ALT_LINK)) {
639       alt_link = Safe_strdup(getStringArg(ALT_LINK, argv, i, *pargc));
640       return TRUE;
641     }
642
643     if(ISOPT(IVT_LOC)) {
644       pic16_options.ivt_loc = getIntArg(IVT_LOC, argv, i, *pargc);
645       fprintf(stderr, "%s:%d setting interrupt vector addresses 0x%x\n", __FILE__, __LINE__, pic16_options.ivt_loc);
646       return TRUE;
647     }
648         
649     if(ISOPT(NL_OPT)) {
650       char *tmp;
651             
652         tmp = Safe_strdup( getStringArg(NL_OPT, argv, i, *pargc) );
653         if(!STRCASECMP(tmp, "lf"))pic16_nl = 0;
654         else if(!STRCASECMP(tmp, "crlf"))pic16_nl = 1;
655         else {
656           fprintf(stderr, "invalid termination character id\n");
657           exit(EXIT_FAILURE);
658         }
659         return TRUE;
660     }
661
662     if(ISOPT(USE_CRT)) {
663       pic16_options.no_crt = 0;
664       pic16_options.crt_name = Safe_strdup( getStringArg(USE_CRT, argv, i, *pargc) );
665
666       return TRUE;
667     }
668
669 #if 0
670     if(ISOPT(OFMSG_LRSUPPORT)) {
671       pic16_options.opt_flags |= OF_LR_SUPPORT;
672       return TRUE;
673     }
674 #endif
675
676     if (ISOPT(OPTIMIZE_GOTO)) {
677       pic16_options.opt_flags |= OF_OPTIMIZE_GOTO;
678       return TRUE;
679     }
680
681     if(ISOPT(OPTIMIZE_CMP)) {
682       pic16_options.opt_flags |= OF_OPTIMIZE_CMP;
683       return TRUE;
684     }
685
686     if (ISOPT(OPTIMIZE_DF)) {
687       pic16_options.opt_flags |= OF_OPTIMIZE_DF;
688       return TRUE;
689     }
690     
691
692   return FALSE;
693 }
694
695 extern set *userIncDirsSet;
696
697 static void _pic16_initPaths(void)
698 {
699   set *pic16incDirsSet=NULL;
700   set *pic16libDirsSet=NULL;
701   char devlib[512];
702
703     setMainValue("mcu", pic16->name[2] );
704     addSet(&preArgvSet, Safe_strdup("-D{mcu}"));
705
706     setMainValue("mcu1", pic16->name[1] );
707     addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
708
709     if(!options.nostdinc) {
710       struct dbuf_s pic16incDir;
711
712       dbuf_init(&pic16incDir, 128);
713       dbuf_makePath(&pic16incDir, INCLUDE_DIR_SUFFIX, "pic16");
714
715       /* setup pic16 include directory */
716       pic16incDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16incDir));
717       dbuf_destroy(&pic16incDir);
718       includeDirsSet = pic16incDirsSet;
719 //      mergeSets(&includeDirsSet, pic16incDirsSet);
720     }
721     /* pic16 port should not search to the SDCC standard include directories,
722      * so add here the deleted include dirs that user has issued in command line */
723     mergeSets(&pic16incDirsSet, userIncDirsSet);
724
725     if(!options.nostdlib) {
726       struct dbuf_s pic16libDir;
727
728       dbuf_init(&pic16libDir, 128);
729       dbuf_makePath(&pic16libDir, LIB_DIR_SUFFIX, "pic16");
730       /* setup pic16 library directory */
731       pic16libDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16libDir));
732       dbuf_destroy(&pic16libDir);
733       libDirsSet = pic16libDirsSet;
734 //      mergeSets(&libDirsSet, pic16libDirsSet);
735     }
736
737     if(!pic16_options.nodefaultlibs) {
738       /* now add the library for the device */
739       sprintf(devlib, "%s.lib", pic16->name[2]);
740       addSet(&libFilesSet, Safe_strdup(devlib));
741
742       /* add the internal SDCC library */
743       addSet(&libFilesSet, Safe_strdup( "libsdcc.lib" ));
744     }
745 }
746
747 extern set *linkOptionsSet;
748 char *msprintf(hTab *pvals, const char *pformat, ...);
749 int my_system(const char *cmd);
750
751 /* forward declarations */   
752 extern const char *pic16_linkCmd[];
753 extern const char *pic16_asmCmd[];
754 extern set *asmOptionsSet;
755   
756 /* custom function to link objects */
757 static void _pic16_linkEdit(void)
758 {
759   hTab *linkValues=NULL;
760   char lfrm[1024];
761   char *lcmd;
762   char temp[1024];
763   set *tSet=NULL;
764   int ret;
765   
766         /*
767          * link command format:
768          * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs}
769          *
770          */
771         sprintf(lfrm, "{linker} {incdirs} {lflags} -w -r -o {outfile} {user_ofile} {ofiles} {spec_ofiles} {libs}");
772
773         shash_add(&linkValues, "linker", pic16_linkCmd[0]);
774
775         mergeSets(&tSet, libDirsSet);
776         mergeSets(&tSet, libPathsSet);
777         
778         shash_add(&linkValues, "incdirs", joinStrSet( appendStrSet(tSet, "-I\"", "\"")));
779         shash_add(&linkValues, "lflags", joinStrSet(linkOptionsSet));
780   
781         shash_add(&linkValues, "outfile", fullDstFileName ? fullDstFileName : dstFileName);
782
783         if(fullSrcFileName) {
784                 sprintf(temp, "%s.o", fullDstFileName ? fullDstFileName : dstFileName);
785 //              addSetHead(&relFilesSet, Safe_strdup(temp));
786                 shash_add(&linkValues, "user_ofile", temp);
787         }
788
789         if(!pic16_options.no_crt)
790           shash_add(&linkValues, "spec_ofiles", pic16_options.crt_name);
791
792         shash_add(&linkValues, "ofiles", joinStrSet(relFilesSet));
793
794         if(!libflags.ignore) {
795           if(libflags.want_libc)
796             addSet(&libFilesSet, Safe_strdup("libc18f.lib"));
797         
798           if(libflags.want_libm)
799             addSet(&libFilesSet, Safe_strdup("libm18f.lib"));
800         
801           if(libflags.want_libio) {
802             sprintf(temp, "libio%s.lib", pic16->name[1]);       /* build libio18f452.lib name */
803             addSet(&libFilesSet, Safe_strdup(temp));
804           }
805         
806           if(libflags.want_libdebug)
807             addSet(&libFilesSet, Safe_strdup("libdebug.lib"));
808         }
809
810         shash_add(&linkValues, "libs", joinStrSet(libFilesSet));
811         
812         lcmd = msprintf(linkValues, lfrm);
813          
814         ret = my_system( lcmd );
815          
816         Safe_free( lcmd );
817          
818         if(ret)
819                 exit(1);
820 }
821
822
823 static void
824 _pic16_finaliseOptions (void)
825 {
826     port->mem.default_local_map = data;
827     port->mem.default_globl_map = data;
828
829     /* peepholes are disabled for the time being */
830     options.nopeep = 1;
831
832     /* explicit enable peepholes for testing */
833     if(pic16_enable_peeps)
834       options.nopeep = 0;
835
836     options.all_callee_saves = 1;               // always callee saves
837
838 #if 0
839     options.float_rent = 1;
840     options.intlong_rent = 1;
841 #endif
842         
843
844     if(alt_asm && strlen(alt_asm))
845       pic16_asmCmd[0] = alt_asm;
846         
847     if(alt_link && strlen(alt_link))
848       pic16_linkCmd[0] = alt_link;
849         
850     if(!pic16_options.no_crt) {
851       pic16_options.omit_ivt = 1;
852       pic16_options.leave_reset = 0;
853     }
854     
855     if(options.model == MODEL_SMALL)
856       addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_SMALL"));
857     else
858     if(options.model == MODEL_LARGE)
859       addSet(&asmOptionsSet, Safe_strdup("-DSDCC_MODEL_LARGE"));
860     
861     {
862       char buf[128];
863
864         sprintf(buf, "-D%s -D__%s", pic16->name[2], pic16->name[1]);
865         *(strrchr(buf, 'f')) = 'F';
866         addSet(&asmOptionsSet, Safe_strdup( buf ));
867     }
868     
869     if(STACK_MODEL_LARGE) {
870       addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
871       addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_LARGE"));
872     } else {
873       addSet(&preArgvSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
874       addSet(&asmOptionsSet, Safe_strdup("-DSTACK_MODEL_SMALL"));
875     }
876 }
877
878
879 #if 0
880   if (options.model == MODEL_LARGE)
881     {
882       port->mem.default_local_map = xdata;
883       port->mem.default_globl_map = xdata;
884     }
885   else
886     {
887       port->mem.default_local_map = data;
888       port->mem.default_globl_map = data;
889     }
890
891   if (options.stack10bit)
892     {
893       if (options.model != MODEL_FLAT24)
894         {
895           fprintf (stderr,
896                    "*** warning: 10 bit stack mode is only supported in flat24 model.\n");
897           fprintf (stderr, "\t10 bit stack mode disabled.\n");
898           options.stack10bit = 0;
899         }
900       else
901         {
902           /* Fixup the memory map for the stack; it is now in
903            * far space and requires a FPOINTER to access it.
904            */
905           istack->fmap = 1;
906           istack->ptrType = FPOINTER;
907         }
908     }
909 #endif
910
911
912 static void
913 _pic16_setDefaultOptions (void)
914 {
915   options.stackAuto = 0;                /* implicit declaration */
916   /* port is not capable yet to allocate separate registers 
917    * dedicated for passing certain parameters */
918   
919   /* initialize to defaults section locations, names and addresses */
920   pic16_sectioninfo.at_udata    = "udata";
921
922   /* set pic16 port options to defaults */
923   pic16_options.no_banksel = 0;
924   pic16_options.opt_banksel = 0;
925   pic16_options.omit_configw = 0;
926   pic16_options.omit_ivt = 0;
927   pic16_options.leave_reset = 0;
928   pic16_options.stack_model = 0;                        /* 0 for 'small', 1 for 'large' */
929   pic16_options.ivt_loc = 0x000000;
930   pic16_options.nodefaultlibs = 0;
931   pic16_options.dumpcalltree = 0;
932   pic16_options.crt_name = "crt0i.o";           /* the default crt to link */
933   pic16_options.no_crt = 0;                     /* use crt by default */
934   pic16_options.ip_stack = 1;           /* set to 1 to enable ipop/ipush for stack */
935   pic16_options.gstack = 0;
936   pic16_options.debgen = 0;
937   pic16_options.CATregs = 0;
938 }
939
940 static const char *
941 _pic16_getRegName (struct regs *reg)
942 {
943   if (reg)
944     return reg->name;
945   return "err";
946 }
947
948
949 #if 1
950 static  char *_pic16_mangleFunctionName(char *sz)
951 {
952 //      fprintf(stderr, "mangled function name: %s\n", sz);
953
954   return sz;
955 }
956 #endif
957
958
959 static void
960 _pic16_genAssemblerPreamble (FILE * of)
961 {
962   char *name = pic16_processor_base_name();
963
964         if(!name) {
965                 name = "p18f452";
966                 fprintf(stderr,"WARNING: No Pic has been selected, defaulting to %s\n",name);
967         }
968
969         fprintf (of, "\tlist\tp=%s\n",&name[1]);
970         if (pic16_mplab_comp) {
971           // provide ACCESS macro used during SFR accesses
972           fprintf (of, "\tinclude <p%s.inc>\n", &name[1]);
973         }
974
975         if(!pic16_options.omit_configw) {
976                 pic16_emitConfigRegs(of);
977                 fprintf(of, "\n");
978                 pic16_emitIDRegs(of);
979         }
980         
981   fprintf (of, "\tradix dec\n");
982 }
983
984 /* Generate interrupt vector table. */
985 static int
986 _pic16_genIVT (struct dbuf_s * oBuf, symbol ** interrupts, int maxInterrupts)
987 {
988 #if 1
989         /* PIC18F family has only two interrupts, the high and the low
990          * priority interrupts, which reside at 0x0008 and 0x0018 respectively - VR */
991
992         if((!pic16_options.omit_ivt) || (pic16_options.omit_ivt && pic16_options.leave_reset)) {
993                 dbuf_printf(oBuf, "; RESET vector\n");
994                 dbuf_printf(oBuf, "\tgoto\t__sdcc_gsinit_startup\n");
995         }
996         
997         if(!pic16_options.omit_ivt) {
998                 dbuf_printf(oBuf, "\tres 4\n");
999
1000
1001                 dbuf_printf(oBuf, "; High priority interrupt vector 0x0008\n");
1002                 if(interrupts[1]) {
1003                         dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[1]->rname);
1004                         dbuf_printf(oBuf, "\tres\t12\n"); 
1005                 } else {
1006                         dbuf_printf(oBuf, "\tretfie\n");
1007                         dbuf_printf(oBuf, "\tres\t14\n");
1008                 }
1009
1010                 dbuf_printf(oBuf, "; Low priority interrupt vector 0x0018\n");
1011                 if(interrupts[2]) {
1012                         dbuf_printf(oBuf, "\tgoto\t%s\n", interrupts[2]->rname);
1013                 } else {
1014                         dbuf_printf(oBuf, "\tretfie\n");
1015                 }
1016         }
1017 #endif
1018   return TRUE;
1019 }
1020
1021 /* return True if the port can handle the type,
1022  * False to convert it to function call */
1023 static bool _hasNativeMulFor (iCode *ic, sym_link *left, sym_link *right)
1024 {
1025   //fprintf(stderr,"checking for native mult for %c (size: %d)\n", ic->op, getSize(OP_SYMBOL(IC_RESULT(ic))->type));
1026   int symL, symR, symRes, sizeL = 0, sizeR = 0, sizeRes = 0;
1027
1028   /* left/right are symbols? */
1029   symL = IS_SYMOP(IC_LEFT(ic));
1030   symR = IS_SYMOP(IC_RIGHT(ic));
1031   symRes = IS_SYMOP(IC_RESULT(ic));
1032
1033   /* --> then determine their sizes */
1034   sizeL = symL ? getSize(OP_SYM_TYPE(IC_LEFT(ic))) : 4;
1035   sizeR = symR ? getSize(OP_SYM_TYPE(IC_RIGHT(ic))) : 4;
1036   sizeRes = symRes ? getSize(OP_SYM_TYPE(IC_RESULT(ic))) : 4;
1037
1038   /* Checks to enable native multiplication.
1039    * PICs do not offer native division at all...
1040    *
1041    * Ideas:
1042    * (  i) if result is just one byte, use native MUL
1043    *       (regardless of the operands)
1044    * ( ii) if left and right are unsigned 8-bit operands,
1045    *       use native MUL
1046    * (iii) if left or right is a literal in the range of [-128..256)
1047    *       and the other is an unsigned byte, use native MUL
1048    */
1049   if (ic->op == '*')
1050   {
1051     /* use native mult for `*: <?> x <?> --> {u8_t, s8_t}' */
1052     if (sizeRes == 1) { return TRUE; }
1053
1054     /* use native mult for `u8_t x u8_t --> { u16_t, s16_t }' */
1055     if (sizeL == 1 && symL /*&& SPEC_USIGN(OP_SYM_TYPE(IC_LEFT(ic)))*/) {
1056       sizeL = 1;
1057     } else {
1058       //printf( "%s: left too large (%u) / signed (%u)\n", __FUNCTION__, sizeL, symL && !SPEC_USIGN(OP_SYM_TYPE(IC_LEFT(ic))));
1059       sizeL = 4;
1060     }
1061     if (sizeR == 1 && symR /*&& SPEC_USIGN(OP_SYM_TYPE(IC_RIGHT(ic)))*/) {
1062       sizeR = 1;
1063     } else {
1064       //printf( "%s: right too large (%u) / signed (%u)\n", __FUNCTION__, sizeR, symR && !SPEC_USIGN(OP_SYM_TYPE(IC_RIGHT(ic))));
1065       sizeR = 4;
1066     }
1067
1068     /* also allow literals [-128..256) for left/right operands */
1069     if (IS_VALOP(IC_LEFT(ic)))
1070     {
1071       long l = (long)floatFromVal( OP_VALUE( IC_LEFT(ic) ) );
1072       sizeL = 4;
1073       //printf( "%s: val(left) = %ld\n", __FUNCTION__, l );
1074       if (l >= -128 && l < 256)
1075       {
1076         sizeL = 1;
1077       } else {
1078         //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l );
1079       }
1080     }
1081     if (IS_VALOP( IC_RIGHT(ic) ))
1082     {
1083       long l = (long)floatFromVal( OP_VALUE( IC_RIGHT(ic) ) );
1084       sizeR = 4;
1085       //printf( "%s: val(right) = %ld\n", __FUNCTION__, l );
1086       if (l >= -128 && l < 256)
1087       {
1088         sizeR = 1;
1089       } else {
1090         //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l );
1091       }
1092     }
1093
1094     /* use native mult iff left and right are (unsigned) 8-bit operands */
1095     if (sizeL == 1 && sizeR == 1) { return TRUE; }
1096   }
1097
1098   if (ic->op == '/' || ic->op == '%')
1099   {
1100     /* We must catch /: {u8_t,s8_t} x {u8_t,s8_t} --> {u8_t,s8_t},
1101      * because SDCC will call 'divuchar' even for u8_t / s8_t.
1102      * Example: 128 / -2 becomes 128 / 254 = 0 != -64... */
1103     if (sizeL == 1 && sizeR == 1) return TRUE;
1104
1105     /* What about literals? */
1106     if (IS_VALOP( IC_LEFT(ic) ))
1107     {
1108       long l = (long)floatFromVal( OP_VALUE( IC_LEFT(ic) ) );
1109       sizeL = 4;
1110       //printf( "%s: val(left) = %ld\n", __FUNCTION__, l );
1111       if (l >= -128 && l < 256)
1112       {
1113         sizeL = 1;
1114       } else {
1115         //printf( "%s: left value %ld outside [-128..256)\n", __FUNCTION__, l );
1116       }
1117     }
1118     if (IS_VALOP( IC_RIGHT(ic) ))
1119     {
1120       long l = (long)floatFromVal( OP_VALUE( IC_RIGHT(ic) ) );
1121       sizeR = 4;
1122       //printf( "%s: val(right) = %ld\n", __FUNCTION__, l );
1123       if (l >= -128 && l < 256)
1124       {
1125         sizeR = 1;
1126       } else {
1127         //printf( "%s: right value %ld outside [-128..256)\n", __FUNCTION__, l );
1128       }
1129     }
1130     if (sizeL == 1 && sizeR == 1) { return TRUE; }
1131   }
1132
1133   return FALSE;
1134 }
1135
1136
1137 #if 0
1138 /* Do CSE estimation */
1139 static bool cseCostEstimation (iCode *ic, iCode *pdic)
1140 {
1141 //    operand *result = IC_RESULT(ic);
1142 //    sym_link *result_type = operandType(result);
1143
1144
1145         /* VR -- this is an adhoc. Put here after conversation
1146          * with Erik Epetrich */
1147
1148         if(ic->op == '<'
1149                 || ic->op == '>'
1150                 || ic->op == EQ_OP) {
1151
1152                 fprintf(stderr, "%d %s\n", __LINE__, __FUNCTION__);
1153           return 0;
1154         }
1155
1156 #if 0
1157     /* if it is a pointer then return ok for now */
1158     if (IC_RESULT(ic) && IS_PTR(result_type)) return 1;
1159
1160     /* if bitwise | add & subtract then no since mcs51 is pretty good at it
1161        so we will cse only if they are local (i.e. both ic & pdic belong to
1162        the same basic block */
1163     if (IS_BITWISE_OP(ic) || ic->op == '+' || ic->op == '-') {
1164         /* then if they are the same Basic block then ok */
1165         if (ic->eBBlockNum == pdic->eBBlockNum) return 1;
1166         else return 0;
1167     }
1168 #endif
1169
1170     /* for others it is cheaper to do the cse */
1171     return 1;
1172 }
1173 #endif
1174
1175
1176 /* Indicate which extended bit operations this port supports */
1177 static bool
1178 hasExtBitOp (int op, int size)
1179 {
1180   if (op == RRC
1181       || op == RLC
1182       /* || op == GETHBIT */ /* GETHBIT doesn't look complete for PIC */
1183      )
1184     return TRUE;
1185   else
1186     return FALSE;
1187 }
1188
1189 /* Indicate the expense of an access to an output storage class */
1190 static int
1191 oclsExpense (struct memmap *oclass)
1192 {
1193   /* The IN_FARSPACE test is compatible with historical behaviour, */
1194   /* but I don't think it is applicable to PIC. If so, please feel */
1195   /* free to remove this test -- EEP */
1196   if (IN_FARSPACE(oclass))
1197     return 1;
1198     
1199   return 0;
1200 }
1201
1202 /** $1 is the input object file (PIC16 specific)        // >>always the basename<<.
1203     $2 is always the output file.
1204     $3 -L path and -l libraries
1205     $l is the list of extra options that should be there somewhere...
1206     MUST be terminated with a NULL.
1207 */
1208 const char *pic16_linkCmd[] =
1209 {
1210   "gplink", "$l", "-w", "-r", "-o \"$2\"", "\"$1\"","$3", NULL
1211 };
1212
1213
1214
1215 /** $1 is always the basename.
1216     $2 is always the output file.
1217     $3 varies (nothing currently)
1218     $l is the list of extra options that should be there somewhere...
1219     MUST be terminated with a NULL.
1220 */
1221 const char *pic16_asmCmd[] =
1222 {
1223   "gpasm", "$l", "$3", "-c", "\"$1.asm\"", "-o \"$2\"", NULL
1224
1225 };
1226
1227 /* Globals */
1228 PORT pic16_port =
1229 {
1230   TARGET_ID_PIC16,
1231   "pic16",
1232   "MCU PIC16",                  /* Target name */
1233   "p18f452",                    /* Processor */
1234   {
1235     pic16glue,
1236     TRUE,                       /* Emit glue around main */
1237     MODEL_SMALL | MODEL_LARGE | MODEL_FLAT24,
1238     MODEL_SMALL
1239   },
1240   {
1241     pic16_asmCmd,               /* assembler command and arguments */
1242     NULL,                       /* alternate macro based form */
1243     "-g",                       /* arguments for debug mode */
1244     NULL,                       /* arguments for normal mode */
1245     0,                          /* print externs as global */
1246     ".asm",                     /* assembler file extension */
1247     NULL                        /* no do_assemble function */
1248   },
1249   {
1250     NULL,                       //    pic16_linkCmd,            /* linker command and arguments */
1251     NULL,                       /* alternate macro based form */
1252     _pic16_linkEdit,            //NULL,                 /* no do_link function */
1253     ".o",                       /* extension for object files */
1254     0                           /* no need for linker file */
1255   },
1256   {
1257     _defaultRules
1258   },
1259   {
1260         /* Sizes */
1261     1,          /* char */
1262     2,          /* short */
1263     2,          /* int */
1264     4,          /* long */
1265     2,          /* ptr */
1266     3,          /* fptr, far pointers (see Microchip) */
1267     3,          /* gptr */
1268     1,          /* bit */
1269     4,          /* float */
1270     4           /* max */
1271   },
1272
1273     /* generic pointer tags */
1274   {
1275     0x00,       /* far */
1276     0x80,       /* near */
1277     0x00,       /* xstack */
1278     0x00        /* code */
1279   },
1280   
1281   {
1282     "XSEG    (XDATA)",          // xstack
1283     "STACK   (DATA)",           // istack
1284     "CSEG    (CODE)",           // code
1285     "DSEG    (DATA)",           // data
1286     "ISEG    (DATA)",           // idata
1287     "PSEG    (DATA)",           // pdata
1288     "XSEG    (XDATA)",          // xdata
1289     "BSEG    (BIT)",            // bit
1290     "RSEG    (DATA)",           // reg
1291     "GSINIT  (CODE)",           // static
1292     "OSEG    (OVR,DATA)",       // overlay
1293     "GSFINAL (CODE)",           // post static
1294     "HOME    (CODE)",   // home
1295     NULL,                       // xidata
1296     NULL,                       // xinit
1297     "CONST   (CODE)",           // const_name - const data (code or not)
1298     "CABS    (ABS,CODE)",       // cabs_name - const absolute data (code or not)
1299     "XABS    (ABS,XDATA)",      // xabs_name - absolute xdata
1300     "IABS    (ABS,DATA)",       // iabs_name - absolute data
1301     NULL,                       // default location for auto vars
1302     NULL,                       // default location for global vars
1303     1                           // code is read only 1=yes
1304   },
1305   {
1306     NULL,               /* genExtraAreaDeclaration */
1307     NULL                /* genExatrAreaLinkOptions */
1308   },
1309   {
1310         /* stack related information */
1311     -1,                 /* -1 stack grows downwards, +1 upwards */
1312     1,                  /* extra overhead when calling between banks */
1313     4,                  /* extra overhead when the function is an ISR */
1314     1,                  /* extra overhead for a function call */
1315     1,                  /* re-entrant space */
1316     0                   /* 'banked' call overhead, mild overlap with bank_overhead */
1317   },
1318     /* pic16 has an 8 bit mul */
1319   {
1320      0, -1
1321   },
1322   {
1323     pic16_emitDebuggerSymbol
1324   },
1325   {
1326     255/3,      /* maxCount */
1327     3,          /* sizeofElement */
1328     /* The rest of these costs are bogus. They approximate */
1329     /* the behavior of src/SDCCicode.c 1.207 and earlier.  */
1330     {4,4,4},    /* sizeofMatchJump[] */
1331     {0,0,0},    /* sizeofRangeCompare[] */
1332     0,          /* sizeofSubtract */
1333     3,          /* sizeofDispatch */
1334   },
1335   "_",
1336   _pic16_init,
1337   _pic16_parseOptions,
1338   pic16_optionsTable,
1339   _pic16_initPaths,
1340   _pic16_finaliseOptions,
1341   _pic16_setDefaultOptions,
1342   pic16_assignRegisters,
1343   _pic16_getRegName,
1344   _pic16_keywords,
1345   _pic16_genAssemblerPreamble,
1346   NULL,                         /* no genAssemblerEnd */
1347   _pic16_genIVT,
1348   NULL, // _pic16_genXINIT
1349   NULL,                         /* genInitStartup */
1350   _pic16_reset_regparm,
1351   _pic16_regparm,
1352   _process_pragma,                              /* process a pragma */
1353   _pic16_mangleFunctionName,                            /* mangles function name */
1354   _hasNativeMulFor,
1355   hasExtBitOp,                  /* hasExtBitOp */
1356   oclsExpense,                  /* oclsExpense */
1357   FALSE,                        
1358   TRUE,                         /* little endian */
1359   0,                            /* leave lt */
1360   0,                            /* leave gt */
1361   1,                            /* transform <= to ! > */
1362   1,                            /* transform >= to ! < */
1363   1,                            /* transform != to !(a == b) */
1364   0,                            /* leave == */
1365   FALSE,                        /* No array initializer support. */
1366   0,    //cseCostEstimation,            /* !!!no CSE cost estimation yet */
1367   NULL,                         /* no builtin functions */
1368   GPOINTER,                     /* treat unqualified pointers as "generic" pointers */
1369   1,                            /* reset labelKey to 1 */
1370   1,                            /* globals & local static allowed */
1371   PORT_MAGIC
1372 };