* Fixed up multi bank support
[fw/sdcc] / src / avr / main.c
1 /** @file main.c
2     avr specific general functions.
3
4     Note that mlh prepended _avr_ on the static functions.  Makes
5     it easier to set a breakpoint using the debugger.
6 */
7 #include "common.h"
8 #include "main.h"
9 #include "ralloc.h"
10 #include "gen.h"
11
12 static char _defaultRules[] =
13 {
14 #include "peeph.rul"
15 };
16
17 /* list of key words used by msc51 */
18 static char *_avr_keywords[] =     {
19     "at",
20     "code",
21     "critical",
22     "eeprom",
23     "interrupt",
24     "sfr",
25     "sbit",
26     "xdata",
27     "_code",
28     "_eeprom",
29     "_generic",
30     "_xdata",
31     "sram" ,
32     "_sram",
33     "flash",
34     "_flash",
35     NULL
36 };
37
38 static int regParmFlg = 0; /* determine if we can register a parameter */
39
40 static void _avr_init(void)
41 {
42     asm_addTree(&asm_asxxxx_mapping);
43 }
44
45 static void _avr_reset_regparm()
46 {
47     regParmFlg = 0;
48 }
49
50 static int _avr_regparm( link *l)
51 {
52     /* the first eight bytes will be passed in
53        registers r16-r23. but we won't split variables
54        i.e. if not enough registers left to hold
55        the parameter then the whole parameter along
56        with rest of the parameters go onto the stack */
57     if (regParmFlg < 8 ) {
58         int size ;
59         if ((size = getSize(l)) > (8 - regParmFlg)) {
60             /* all remaining go on stack */
61             regParmFlg = 8;
62             return 0;
63         }
64         regParmFlg += size;
65         return 1;
66     }
67     
68     return 0;
69 }
70
71 void avr_assignRegisters (eBBlock **ebbs, int count);
72
73 static bool _avr_parseOptions(int *pargc, char **argv, int *i)
74 {
75     /* TODO: allow port-specific command line options to specify
76      * segment names here.
77      */
78     return FALSE;
79 }
80
81 static void _avr_finaliseOptions(void)
82 {
83     port->mem.default_local_map =
84         port->mem.default_globl_map = xdata;
85     /* change stack to be in far space */
86     /* internal stack segment ;   
87        SFRSPACE       -   NO
88        FAR-SPACE      -   YES
89        PAGED          -   NO
90        DIRECT-ACCESS  -   NO
91        BIT-ACCESS     -   NO
92        CODE-ACESS     -   NO 
93        DEBUG-NAME     -   'B'
94        POINTER-TYPE   -   POINTER
95     */
96     istack        = allocMap (0, 1, 0, 0, 0, 0,options.stack_loc, ISTACK_NAME,'B',FPOINTER);
97
98 }
99
100 static void _avr_setDefaultOptions(void)
101 {
102     options.stackAuto = 1;
103 }
104
105 static const char *_avr_getRegName(struct regs *reg)
106 {
107     if (reg)
108         return reg->name;
109     return "err";
110 }
111
112 static void _avr_genAssemblerPreamble(FILE *of)
113 {
114
115 }
116
117 /* Generate interrupt vector table. */
118 static int _avr_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
119 {
120     return TRUE;
121 }
122
123 /** $1 is always the basename.
124     $2 is always the output file.
125     $3 varies
126     $l is the list of extra options that should be there somewhere...
127     MUST be terminated with a NULL.
128 */
129 static const char *_linkCmd[] = {
130     "aslink", "-nf", "$1", NULL
131 };
132
133 static const char *_asmCmd[] = {
134     "asx8051", "-plosgffc", "$1.asm", NULL
135 };
136
137 /* Globals */
138 PORT avr_port = {
139     "avr",
140     "ATMEL AVR",                /* Target name */
141     {
142         TRUE,                   /* Emit glue around main */
143     },
144     {   
145         _asmCmd,
146         "-plosgffc",            /* Options with debug */
147         "-plosgff",             /* Options without debug */
148     },
149     {
150         _linkCmd
151     },
152     {
153         _defaultRules
154     },
155     {
156         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
157         1, 1, 2, 4, 2, 2, 3, 1, 4, 4
158     },
159     {
160         "XSEG    (XDATA)",
161         "STACK   (DATA)",
162         "CSEG    (CODE)",
163         "DSEG    (DATA)",
164         "ISEG    (DATA)",
165         "XSEG    (XDATA)",
166         "BSEG    (BIT)",
167         "RSEG    (DATA)",
168         "GSINIT  (CODE)",
169         "OSEG    (OVR,DATA)",
170         "GSFINAL (CODE)",
171         NULL,
172         NULL,
173         0,
174     },
175     { 
176         -1, 1, 4, 1, 1
177     },
178     /* avr has an 8 bit mul */
179     {
180         1
181     },
182     _avr_init,
183     _avr_parseOptions,
184     _avr_finaliseOptions,
185     _avr_setDefaultOptions,
186     avr_assignRegisters,
187     _avr_getRegName ,
188     _avr_keywords,
189     _avr_genAssemblerPreamble,
190     _avr_genIVT,
191     _avr_reset_regparm,
192     _avr_regparm
193 };
194