081e26db06f2010008fe04ea183d191d709c95ec
[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     /** Target name used for -m */
11     const char *target;
12
13     /** Target name string, used for --help */
14     const char *target_name;
15
16     struct {
17         /** TRUE if all types of glue functions should be inseted into
18             the file that also defines main.
19             We dont want this in cases like the z80 where the startup
20             code is provided by a seperate module.
21         */
22         bool glue_up_main;
23     } general;
24
25     /* assembler related information */
26     struct {
27         /** Command to run and arguments (eg as-z80) */
28         const char **cmd;
29         /** Arguments for debug mode.  PENDING: ignored */
30         const char *debug_opts;
31         /** Arguments for normal assembly mode.  PENDING: ignored */
32         const char *plain_opts;
33         /* print externs as global */
34         int externGlobal;
35     } assembler;
36
37     /* linker related info */
38     struct {
39         /** Command to run (eg link-z80) */
40         const char **cmd;
41     } linker;
42
43     struct {
44         /** Default peephole rules */
45         char *default_rules;
46     } peep;
47
48     /** Basic type sizes */
49     struct {
50         int char_size;
51         int short_size;
52         int int_size;
53         int long_size;
54         int ptr_size;
55         int fptr_size;
56         int gptr_size;
57         int bit_size;
58         int float_size;
59         int max_base_size;
60     } s;
61
62     /** memory regions related stuff */
63     struct {
64         const char *xstack_name;
65         const char *istack_name;
66         const char *code_name;
67         const char *data_name;
68         const char *idata_name;
69         const char *xdata_name;
70         const char *bit_name;
71         const char *reg_name;
72         const char *static_name;
73         const char *overlay_name;
74         const char *post_static_name;
75         struct memmap *default_local_map ; /* default location for auto vars */
76         struct memmap *default_globl_map ; /* default location for globl vars*/
77         int         code_ro;               /* code space read-only 1=yes */
78     } mem;
79     
80     /* stack related information */
81     struct {
82         /** -1 for grows down (z80), +1 for grows up (mcs51) */
83         int direction;
84         /** Extra overhead when calling between banks */
85         int bank_overhead;
86         /** Extra overhead when the function is an ISR */
87         int isr_overhead;
88         /** Standard overhead for a function call */
89         int call_overhead;
90         /** Re-enterant space */
91         int reent_overhead;
92     } stack;
93
94     struct {
95         /** One more than the smallest 
96             mul/div operation the processor can do nativley 
97             Eg if the processor has an 8 bit mul, nativebelow is 2 */
98         int native_below;
99     } muldiv;
100
101     /** Prefix to add to a C function (eg "_") */
102     const char *fun_prefix;
103
104     /** Called once the processor target has been selected.
105         First chance to initalise and set any port specific varibles.
106         'port' is set before calling this.  May be NULL.
107     */
108     void (*init)(void);
109     /** Parses one option + its arguments */
110     bool (*parseOption)(int *pargc, char **argv, int *i);
111     /** Called after all the options have been parsed. */
112     void (*finaliseOptions)(void);
113     /** Called after the port has been selected but before any
114         options are parsed. */
115     void (*setDefaultOptions)(void);
116     /** Does the dirty work. */
117     void (*assignRegisters)(eBBlock **, int);
118     
119     /** Returns the register name of a symbol.
120         Used so that 'regs' can be an incomplete type. */
121     const char *(*getRegName)(struct regs *reg);
122
123     /* list of keywords that are used by this
124        target (used by lexer) */
125     char **keywords; 
126     
127     /* Write any port specific assembler output. */
128     void (*genAssemblerPreamble)(FILE *of);
129     
130     /* Write the port specific IVT. If genIVT is NULL or if
131      * it returns zero, default (8051) IVT generation code
132      * will be used. 
133      */
134     int (*genIVT)(FILE *of, symbol **intTable, int intCount); 
135
136
137     /* parameter passing in register related functions */
138     void (*reset_regparms)();          /* reset the register count */
139     int  (*reg_parm)(struct link *);   /* will return 1 if can be passed in register */
140
141     /** Process the pragma string 'sz'.  Returns 0 if recognised and
142         processed, 1 otherwise.  May be NULL.
143     */
144     int (*process_pragma)(const char *sz);
145
146     /** If TRUE, then tprintf and !dw will be used for some initalisers
147      */
148     bool use_dw_for_init;
149 } PORT;
150
151 extern PORT *port;
152
153 #endif