Some code cleanup & fixed problem of used bdefore definitions
[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
35 void avr_assignRegisters (eBBlock **ebbs, int count);
36
37 static bool _avr_parseOptions(int *pargc, char **argv, int *i)
38 {
39     /* TODO: allow port-specific command line options to specify
40      * segment names here.
41      */
42     return FALSE;
43 }
44
45 static void _avr_finaliseOptions(void)
46 {
47     port->default_local_map =
48         port->default_globl_map = xdata;
49 }
50
51 static void _avr_setDefaultOptions(void)
52 {
53 }
54
55 static const char *_avr_getRegName(struct regs *reg)
56 {
57     if (reg)
58         return reg->name;
59     return "err";
60 }
61
62 static void _avr_genAssemblerPreamble(FILE *of)
63 {
64
65 }
66
67 /* Generate interrupt vector table. */
68 static int _avr_genIVT(FILE *of, symbol **interrupts, int maxInterrupts)
69 {
70     return TRUE;
71 }
72
73 /** $1 is always the basename.
74     $2 is always the output file.
75     $3 varies
76     $l is the list of extra options that should be there somewhere...
77     MUST be terminated with a NULL.
78 */
79 static const char *_linkCmd[] = {
80     "aslink", "-nf", "$1", NULL
81 };
82
83 static const char *_asmCmd[] = {
84     "asx8051", "-plosgffc", "$1.asm", NULL
85 };
86
87 /* Globals */
88 PORT avr_port = {
89     "avr",
90     "ATMEL AVR",                /* Target name */
91     {
92         TRUE,                   /* Emit glue around main */
93     },
94     {   
95         _asmCmd,
96         "-plosgffc",            /* Options with debug */
97         "-plosgff",             /* Options without debug */
98     },
99     {
100         _linkCmd
101     },
102     {
103         _defaultRules
104     },
105     {
106         /* Sizes: char, short, int, long, ptr, fptr, gptr, bit, float, max */
107         1, 1, 2, 4, 1, 2, 3, 1, 4, 4
108     },
109     {
110         "XSEG    (XDATA)",
111         "STACK   (DATA)",
112         "CSEG    (CODE)",
113         "DSEG    (DATA)",
114         "ISEG    (DATA)",
115         "XSEG    (XDATA)",
116         "BSEG    (BIT)",
117         "RSEG    (DATA)",
118         "GSINIT  (CODE)",
119         "OSEG    (OVR,DATA)",
120         "GSFINAL (CODE)",
121         NULL,
122         NULL,
123     },
124     { 
125         +1, 1, 4, 1, 1
126     },
127     /* avr has an 8 bit mul */
128     {
129         1
130     },
131     NULL,
132     _avr_parseOptions,
133     _avr_finaliseOptions,
134     _avr_setDefaultOptions,
135     avr_assignRegisters,
136     _avr_getRegName ,
137     _avr_keywords,
138     _avr_genAssemblerPreamble,
139     _avr_genIVT
140 };
141