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