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