9bf97e4959a0c5cee4144d69ac46274149e7a780
[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 /** Arguments for debug mode.  PENDING: ignored */
61         const char *debug_opts;
62 /** Arguments for normal assembly mode.  PENDING: ignored */
63         const char *plain_opts;
64         /* print externs as global */
65         int externGlobal;
66         /* assembler file extension */
67         const char *file_ext;
68       }
69     assembler;
70
71     /* linker related info */
72     struct
73       {
74 /** Command to run (eg link-z80) */
75         const char **cmd;
76 /** If non-null will be used to execute the link. */
77         void (*do_link) (void);
78 /** Extention for object files (.rel, .obj, ...) */
79         const char *rel_ext;
80       }
81     linker;
82
83     struct
84       {
85 /** Default peephole rules */
86         char *default_rules;
87       }
88     peep;
89
90 /** Basic type sizes */
91     struct
92       {
93         int char_size;
94         int short_size;
95         int int_size;
96         int long_size;
97         int ptr_size;
98         int fptr_size;
99         int gptr_size;
100         int bit_size;
101         int float_size;
102         int max_base_size;
103       }
104     s;
105
106 /** memory regions related stuff */
107     struct
108       {
109         const char *xstack_name;
110         const char *istack_name;
111         const char *code_name;
112         const char *data_name;
113         const char *idata_name;
114         const char *xdata_name;
115         const char *bit_name;
116         const char *reg_name;
117         const char *static_name;
118         const char *overlay_name;
119         const char *post_static_name;
120         const char *home_name;
121         struct memmap *default_local_map;       /* default location for auto vars */
122         struct memmap *default_globl_map;       /* default location for globl vars */
123         int code_ro;            /* code space read-only 1=yes */
124       }
125     mem;
126
127     /* stack related information */
128     struct
129       {
130 /** -1 for grows down (z80), +1 for grows up (mcs51) */
131         int direction;
132 /** Extra overhead when calling between banks */
133         int bank_overhead;
134 /** Extra overhead when the function is an ISR */
135         int isr_overhead;
136 /** Standard overhead for a function call */
137         int call_overhead;
138 /** Re-enterant space */
139         int reent_overhead;
140         /** 'banked' call overhead.
141             Mild overlap with bank_overhead */
142         int banked_overhead;
143       }
144     stack;
145
146     struct
147       {
148         /** One more than the smallest 
149             mul/div operation the processor can do nativley 
150             Eg if the processor has an 8 bit mul, nativebelow is 2 */
151         unsigned native_below;
152         /** The mul/div/mod functions will be made to use regparams
153             for sizeof(param) < log2(force_reg)
154             i.e. Use 2 for WORD and BYTE, 0 for none. */
155         int force_reg_param_below;
156       }
157     muldiv;
158
159 /** Prefix to add to a C function (eg "_") */
160     const char *fun_prefix;
161
162     /** Called once the processor target has been selected.
163         First chance to initalise and set any port specific variables.
164         'port' is set before calling this.  May be NULL.
165     */
166     void (*init) (void);
167 /** Parses one option + its arguments */
168       bool (*parseOption) (int *pargc, char **argv, int *i);
169 /** Called after all the options have been parsed. */
170     void (*finaliseOptions) (void);
171     /** Called after the port has been selected but before any
172         options are parsed. */
173     void (*setDefaultOptions) (void);
174 /** Does the dirty work. */
175     void (*assignRegisters) (struct eBBlock **, int);
176
177     /** Returns the register name of a symbol.
178         Used so that 'regs' can be an incomplete type. */
179     const char *(*getRegName) (struct regs * reg);
180
181     /* list of keywords that are used by this
182        target (used by lexer) */
183     char **keywords;
184
185     /* Write any port specific assembler output. */
186     void (*genAssemblerPreamble) (FILE * of);
187
188     /* Write the port specific IVT. If genIVT is NULL or if
189      * it returns zero, default (8051) IVT generation code
190      * will be used. 
191      */
192     int (*genIVT) (FILE * of, symbol ** intTable, int intCount);
193
194
195     /* parameter passing in register related functions */
196     void (*reset_regparms) ();  /* reset the register count */
197     int (*reg_parm) (struct sym_link *);        /* will return 1 if can be passed in register */
198
199     /** Process the pragma string 'sz'.  Returns 0 if recognised and
200         processed, 1 otherwise.  May be NULL.
201     */
202     int (*process_pragma) (const char *sz);
203
204     /** Mangles a support function name to reflect the calling model. 
205      */
206     char *(*getMangledFunctionName) (char *szOrginial);
207
208     /** If TRUE, then tprintf and !dw will be used for some initalisers
209      */
210     bool use_dw_for_init;
211
212     /* condition transformations */
213     bool lt_nge;                /* transform (a < b)  to !(a >= b)  */
214     bool gt_nle;                /* transform (a > b)  to !(a <= b)  */
215     bool le_ngt;                /* transform (a <= b) to !(a > b)   */
216     bool ge_nlt;                /* transform (a >= b) to !(a < b)   */
217     bool ne_neq;                /* transform a != b --> ! (a == b)  */
218     bool eq_nne;                /* transform a == b --> ! (a != b)  */
219
220 #define PORT_MAGIC 0xAC32
221 /** Used at runtime to detect if this structure has been completly filled in. */
222     int magic;
223   }
224 PORT;
225
226 extern PORT *port;
227
228 #if !OPT_DISABLE_MCS51
229 extern PORT mcs51_port;
230 #endif
231 #if !OPT_DISABLE_GBZ80
232 extern PORT gbz80_port;
233 #endif
234 #if !OPT_DISABLE_Z80
235 extern PORT z80_port;
236 #endif
237 #if !OPT_DISABLE_AVR
238 extern PORT avr_port;
239 #endif
240 #if !OPT_DISABLE_DS390
241 extern PORT ds390_port;
242 #endif
243 #if !OPT_DISABLE_PIC
244 extern PORT pic_port;
245 #endif
246 #if !OPT_DISABLE_I186
247 extern PORT i186_port;
248 #endif
249 #if !OPT_DISABLE_TLCS900H
250 extern PORT tlcs900h_port;
251 #endif
252
253 #endif /* PORT_INCLUDE*/