../cvsm
[fw/sdcc] / src / port.h
1 /** @file port.h
2     Definitions for what a port must provide.
3     All ports are referenced in SDCCmain.c.
4 */
5 #ifndef PORT_INCLUDE
6 #define PORT_INCLUDE
7
8 #define TARGET_ID_MCS51    1
9 #define TARGET_ID_GBZ80    2
10 #define TARGET_ID_Z80      3
11 #define TARGET_ID_AVR      4
12 #define TARGET_ID_DS390    5
13 #define TARGET_ID_PIC      6
14 #define TARGET_ID_I186     7
15 #define TARGET_ID_TLCS900H 8
16 #define TARGET_ID_XA51     9
17
18 /* Macro to test the target we are compiling for.
19    Can only be used after SDCCmain has defined the port
20 */
21 #define TARGET_IS_MCS51 (port->id==TARGET_ID_MCS51)
22 #define TARGET_IS_GBZ80 (port->id==TARGET_ID_GBZ80)
23 #define TARGET_IS_Z80 (port->id==TARGET_ID_Z80)
24 #define TARGET_IS_AVR (port->id==TARGET_ID_AVR)
25 #define TARGET_IS_DS390 (port->id==TARGET_ID_DS390)
26 #define TARGET_IS_PIC   (port->id==TARGET_ID_PIC)
27 #define TARGET_IS_I186 (port->id==TARGET_ID_I186)
28 #define TARGET_IS_TCLS900H (port->id==TARGET_ID_TCLS900H)
29
30 /* Processor specific names */
31 typedef struct
32   {
33 /** Unique id for this target */
34     const int id;
35 /** Target name used for -m */
36     const char *target;
37
38 /** Target name string, used for --help */
39     const char *target_name;
40
41     struct
42       {
43         /** TRUE if all types of glue functions should be inserted into
44             the file that also defines main.
45             We dont want this in cases like the z80 where the startup
46             code is provided by a seperate module.
47         */
48         bool glue_up_main;
49         /* OR of MODEL_* */
50         int supported_models;
51         int default_model;
52       }
53     general;
54
55     /* assembler related information */
56     struct
57       {
58         /** Command to run and arguments (eg as-z80) */
59         const char **cmd;
60         /** Alternate macro based form. */
61         const char *mcmd;
62         /** Arguments for debug mode. */
63         const char *debug_opts;
64         /** Arguments for normal assembly mode. */
65         const char *plain_opts;
66         /* print externs as global */
67         int externGlobal;
68         /* assembler file extension */
69         const char *file_ext;
70       }
71     assembler;
72
73     /* linker related info */
74     struct
75       {
76         /** Command to run (eg link-z80) */
77         const char **cmd;
78         /** Alternate macro based form. */
79         const char *mcmd;
80         /** If non-null will be used to execute the link. */
81         void (*do_link) (void);
82         /** Extention for object files (.rel, .obj, ...) */
83         const char *rel_ext;
84       }
85     linker;
86
87     struct
88       {
89 /** Default peephole rules */
90         char *default_rules;
91       }
92     peep;
93
94 /** Basic type sizes */
95     struct
96       {
97         int char_size;
98         int short_size;
99         int int_size;
100         int long_size;
101         int ptr_size;
102         int fptr_size;
103         int gptr_size;
104         int bit_size;
105         int float_size;
106         int max_base_size;
107       }
108     s;
109
110 /** memory regions related stuff */
111     struct
112       {
113         const char *xstack_name;
114         const char *istack_name;
115         const char *code_name;
116         const char *data_name;
117         const char *idata_name;
118         const char *xdata_name;
119         const char *bit_name;
120         const char *reg_name;
121         const char *static_name;
122         const char *overlay_name;
123         const char *post_static_name;
124         const char *home_name;
125         struct memmap *default_local_map;       /* default location for auto vars */
126         struct memmap *default_globl_map;       /* default location for globl vars */
127         int code_ro;            /* code space read-only 1=yes */
128       }
129     mem;
130
131     /* stack related information */
132     struct
133       {
134 /** -1 for grows down (z80), +1 for grows up (mcs51) */
135         int direction;
136 /** Extra overhead when calling between banks */
137         int bank_overhead;
138 /** Extra overhead when the function is an ISR */
139         int isr_overhead;
140 /** Standard overhead for a function call */
141         int call_overhead;
142 /** Re-enterant space */
143         int reent_overhead;
144         /** 'banked' call overhead.
145             Mild overlap with bank_overhead */
146         int banked_overhead;
147       }
148     stack;
149
150     struct
151       {
152         /** One more than the smallest 
153             mul/div operation the processor can do nativley 
154             Eg if the processor has an 8 bit mul, nativebelow is 2 */
155         unsigned muldiv;
156         unsigned shift;
157       }
158     support;
159
160 /** Prefix to add to a C function (eg "_") */
161     const char *fun_prefix;
162
163     /** Called once the processor target has been selected.
164         First chance to initalise and set any port specific variables.
165         'port' is set before calling this.  May be NULL.
166     */
167     void (*init) (void);
168 /** Parses one option + its arguments */
169       bool (*parseOption) (int *pargc, char **argv, int *i);
170 /** Called after all the options have been parsed. */
171     void (*finaliseOptions) (void);
172     /** Called after the port has been selected but before any
173         options are parsed. */
174     void (*setDefaultOptions) (void);
175 /** Does the dirty work. */
176     void (*assignRegisters) (struct eBBlock **, int);
177
178     /** Returns the register name of a symbol.
179         Used so that 'regs' can be an incomplete type. */
180     const char *(*getRegName) (struct regs * reg);
181
182     /* list of keywords that are used by this
183        target (used by lexer) */
184     char **keywords;
185
186     /* Write any port specific assembler output. */
187     void (*genAssemblerPreamble) (FILE * of);
188
189     /* Write the port specific IVT. If genIVT is NULL or if
190      * it returns zero, default (8051) IVT generation code
191      * will be used. 
192      */
193     int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
194
195
196     /* parameter passing in register related functions */
197     void (*reset_regparms) ();  /* reset the register count */
198     int (*reg_parm) (struct sym_link *);        /* will return 1 if can be passed in register */
199
200     /** Process the pragma string 'sz'.  Returns 0 if recognised and
201         processed, 1 otherwise.  May be NULL.
202     */
203     int (*process_pragma) (const char *sz);
204
205     /** Mangles a support function name to reflect the calling model. 
206      */
207     char *(*getMangledFunctionName) (char *szOrginial);
208
209     /** If TRUE, then tprintf and !dw will be used for some initalisers
210      */
211     bool use_dw_for_init;
212
213     /* condition transformations */
214     bool lt_nge;                /* transform (a < b)  to !(a >= b)  */
215     bool gt_nle;                /* transform (a > b)  to !(a <= b)  */
216     bool le_ngt;                /* transform (a <= b) to !(a > b)   */
217     bool ge_nlt;                /* transform (a >= b) to !(a < b)   */
218     bool ne_neq;                /* transform a != b --> ! (a == b)  */
219     bool eq_nne;                /* transform a == b --> ! (a != b)  */
220
221     bool arrayInitializerSuppported;  
222       
223 #define PORT_MAGIC 0xAC32
224 /** Used at runtime to detect if this structure has been completly filled in. */
225     int magic;
226   }
227 PORT;
228
229 extern PORT *port;
230
231 #if !OPT_DISABLE_MCS51
232 extern PORT mcs51_port;
233 #endif
234 #if !OPT_DISABLE_GBZ80
235 extern PORT gbz80_port;
236 #endif
237 #if !OPT_DISABLE_Z80
238 extern PORT z80_port;
239 #endif
240 #if !OPT_DISABLE_AVR
241 extern PORT avr_port;
242 #endif
243 #if !OPT_DISABLE_DS390
244 extern PORT ds390_port;
245 #endif
246 #if !OPT_DISABLE_PIC
247 extern PORT pic_port;
248 #endif
249 #if !OPT_DISABLE_I186
250 extern PORT i186_port;
251 #endif
252 #if !OPT_DISABLE_TLCS900H
253 extern PORT tlcs900h_port;
254 #endif
255
256 #endif /* PORT_INCLUDE*/