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