More AVR stuff
[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_reset_regparm()
41 {
42     regParmFlg = 0;
43 }
44
45 static int _avr_regparm( link *l)
46 {
47     /* the first eight bytes will be passed in
48        registers r16-r23. but we won't split variables
49        i.e. if not enough registers left to hold
50        the parameter then the whole parameter along
51        with rest of the parameters go onto the stack */
52     if (regParmFlg < 8 ) {
53         int size ;
54         if ((size = getSize(l)) > (8 - regParmFlg)) {
55             /* all remaining go on stack */
56             regParmFlg = 8;
57             return 0;
58         }
59         regParmFlg += size;
60         return 1;
61     }
62     
63     return 0;
64 }
65
66 void avr_assignRegisters (eBBlock **ebbs, int count);
67
68 static bool _avr_parseOptions(int *pargc, char **argv, int *i)
69 {
70     /* TODO: allow port-specific command line options to specify
71      * segment names here.
72      */
73     return FALSE;
74 }
75
76 static void _avr_finaliseOptions(void)
77 {
78     port->mem.default_local_map =
79         port->mem.default_globl_map = xdata;
80     /* change stack to be in far space */
81     /* internal stack segment ;   
82        SFRSPACE       -   NO
83        FAR-SPACE      -   YES
84        PAGED          -   NO
85        DIRECT-ACCESS  -   NO
86        BIT-ACCESS     -   NO
87        CODE-ACESS     -   NO 
88        DEBUG-NAME     -   'B'
89        POINTER-TYPE   -   POINTER
90     */
91     istack        = allocMap (0, 1, 0, 0, 0, 0,options.stack_loc, ISTACK_NAME,'B',FPOINTER);
92
93 }
94
95 static void _avr_setDefaultOptions(void)
96 {
97     options.stackAuto = 1;
98 }
99
100 static const char *_avr_getRegName(struct regs *reg)
101 {
102     if (reg)
103         return reg->name;
104     return "err";
105 }
106
107 static void _avr_genAssemblerPreamble(FILE *of)
108 {
109
110 }
111
112 /* Generate interrupt vector table. */
113 static int _avr_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
114 {
115     return TRUE;
116 }
117
118 /** $1 is always the basename.
119     $2 is always the output file.
120     $3 varies
121     $l is the list of extra options that should be there somewhere...
122     MUST be terminated with a NULL.
123 */
124 static const char *_linkCmd[] = {
125     "aslink", "-nf", "$1", NULL
126 };
127
128 static const char *_asmCmd[] = {
129     "asx8051", "-plosgffc", "$1.asm", NULL
130 };
131
132 /* Globals */
133 PORT avr_port = {
134     "avr",
135     "ATMEL AVR",                /* Target name */
136     {
137         TRUE,                   /* Emit glue around main */
138     },
139     {   
140         _asmCmd,
141         "-plosgffc",            /* Options with debug */
142         "-plosgff",             /* Options without debug */
143     },
144     {
145         _linkCmd
146     },
147     {
148         _defaultRules
149     },
150     {
151         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
152         1, 1, 2, 4, 2, 2, 3, 1, 4, 4
153     },
154     {
155         "XSEG    (XDATA)",
156         "STACK   (DATA)",
157         "CSEG    (CODE)",
158         "DSEG    (DATA)",
159         "ISEG    (DATA)",
160         "XSEG    (XDATA)",
161         "BSEG    (BIT)",
162         "RSEG    (DATA)",
163         "GSINIT  (CODE)",
164         "OSEG    (OVR,DATA)",
165         "GSFINAL (CODE)",
166         NULL,
167         NULL,
168         0,
169     },
170     { 
171         -1, 1, 4, 1, 1
172     },
173     /* avr has an 8 bit mul */
174     {
175         1
176     },
177     NULL,
178     _avr_parseOptions,
179     _avr_finaliseOptions,
180     _avr_setDefaultOptions,
181     avr_assignRegisters,
182     _avr_getRegName ,
183     _avr_keywords,
184     _avr_genAssemblerPreamble,
185     _avr_genIVT,
186     _avr_reset_regparm,
187     _avr_regparm
188 };
189