Fixed up z80 port so that it works again
[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         MODEL_LARGE | MODEL_SMALL,
144         MODEL_SMALL
145     },
146     {   
147         _asmCmd,
148         "-plosgffc",            /* Options with debug */
149         "-plosgff",             /* Options without debug */
150         0
151     },
152     {
153         _linkCmd, 
154         NULL,
155         ".rel"
156     },
157     {
158         _defaultRules
159     },
160     {
161         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
162         1, 1, 2, 4, 2, 2, 3, 1, 4, 4
163     },
164     {
165         "XSEG    (XDATA)",
166         "STACK   (DATA)",
167         "CSEG    (CODE)",
168         "DSEG    (DATA)",
169         "ISEG    (DATA)",
170         "XSEG    (XDATA)",
171         "BSEG    (BIT)",
172         "RSEG    (DATA)",
173         "GSINIT  (CODE)",
174         "OSEG    (OVR,DATA)",
175         "GSFINAL (CODE)",
176         "HOME    (CODE)",
177         NULL,
178         NULL,
179         0,
180     },
181     { 
182         -1, 1, 4, 1, 1, 0
183     },
184     /* avr has an 8 bit mul */
185     {
186         1, 0
187     },
188     "_",
189     _avr_init,
190     _avr_parseOptions,
191     _avr_finaliseOptions,
192     _avr_setDefaultOptions,
193     avr_assignRegisters,
194     _avr_getRegName ,
195     _avr_keywords,
196     _avr_genAssemblerPreamble,
197     _avr_genIVT,
198     _avr_reset_regparm,
199     _avr_regparm,
200     FALSE
201 };
202