mn10300-sim.h revision 1.1.1.1.4.2 1 1.1.1.1.4.2 perseant #ifndef MN10300_SIM_H
2 1.1.1.1.4.2 perseant #define MN10300_SIM_H
3 1.1.1.1.4.2 perseant
4 1.1.1.1.4.2 perseant /* For compatibility, until all functions converted to passing
5 1.1.1.1.4.2 perseant SIM_DESC as an argument */
6 1.1.1.1.4.2 perseant extern SIM_DESC simulator;
7 1.1.1.1.4.2 perseant
8 1.1.1.1.4.2 perseant typedef struct
9 1.1.1.1.4.2 perseant {
10 1.1.1.1.4.2 perseant uint32_t low, high;
11 1.1.1.1.4.2 perseant } dword;
12 1.1.1.1.4.2 perseant typedef uint32_t reg_t;
13 1.1.1.1.4.2 perseant
14 1.1.1.1.4.2 perseant struct simops
15 1.1.1.1.4.2 perseant {
16 1.1.1.1.4.2 perseant long opcode;
17 1.1.1.1.4.2 perseant long mask;
18 1.1.1.1.4.2 perseant void (*func)();
19 1.1.1.1.4.2 perseant int length;
20 1.1.1.1.4.2 perseant int format;
21 1.1.1.1.4.2 perseant int numops;
22 1.1.1.1.4.2 perseant int operands[16];
23 1.1.1.1.4.2 perseant };
24 1.1.1.1.4.2 perseant
25 1.1.1.1.4.2 perseant /* The current state of the processor; registers, memory, etc. */
26 1.1.1.1.4.2 perseant
27 1.1.1.1.4.2 perseant struct _state
28 1.1.1.1.4.2 perseant {
29 1.1.1.1.4.2 perseant reg_t regs[32]; /* registers, d0-d3, a0-a3, sp, pc, mdr, psw,
30 1.1.1.1.4.2 perseant lir, lar, mdrq, plus some room for processor
31 1.1.1.1.4.2 perseant specific regs. */
32 1.1.1.1.4.2 perseant union
33 1.1.1.1.4.2 perseant {
34 1.1.1.1.4.2 perseant reg_t fs[32]; /* FS0-31 */
35 1.1.1.1.4.2 perseant dword fd[16]; /* FD0,2,...,30 */
36 1.1.1.1.4.2 perseant } fpregs;
37 1.1.1.1.4.2 perseant
38 1.1.1.1.4.2 perseant /* All internal state modified by signal_exception() that may need to be
39 1.1.1.1.4.2 perseant rolled back for passing moment-of-exception image back to gdb. */
40 1.1.1.1.4.2 perseant reg_t exc_trigger_regs[32];
41 1.1.1.1.4.2 perseant reg_t exc_suspend_regs[32];
42 1.1.1.1.4.2 perseant int exc_suspended;
43 1.1.1.1.4.2 perseant
44 1.1.1.1.4.2 perseant #define SIM_CPU_EXCEPTION_TRIGGER(SD,CPU,CIA) mn10300_cpu_exception_trigger(SD,CPU,CIA)
45 1.1.1.1.4.2 perseant #define SIM_CPU_EXCEPTION_SUSPEND(SD,CPU,EXC) mn10300_cpu_exception_suspend(SD,CPU,EXC)
46 1.1.1.1.4.2 perseant #define SIM_CPU_EXCEPTION_RESUME(SD,CPU,EXC) mn10300_cpu_exception_resume(SD,CPU,EXC)
47 1.1.1.1.4.2 perseant };
48 1.1.1.1.4.2 perseant
49 1.1.1.1.4.2 perseant extern struct _state State;
50 1.1.1.1.4.2 perseant
51 1.1.1.1.4.2 perseant #define PC (State.regs[REG_PC])
52 1.1.1.1.4.2 perseant #define SP (State.regs[REG_SP])
53 1.1.1.1.4.2 perseant
54 1.1.1.1.4.2 perseant #define PSW (State.regs[11])
55 1.1.1.1.4.2 perseant #define PSW_Z 0x1
56 1.1.1.1.4.2 perseant #define PSW_N 0x2
57 1.1.1.1.4.2 perseant #define PSW_C 0x4
58 1.1.1.1.4.2 perseant #define PSW_V 0x8
59 1.1.1.1.4.2 perseant #define PSW_IE LSBIT (11)
60 1.1.1.1.4.2 perseant #define PSW_LM LSMASK (10, 8)
61 1.1.1.1.4.2 perseant
62 1.1.1.1.4.2 perseant #define EXTRACT_PSW_LM LSEXTRACTED16 (PSW, 10, 8)
63 1.1.1.1.4.2 perseant #define INSERT_PSW_LM(l) LSINSERTED16 ((l), 10, 8)
64 1.1.1.1.4.2 perseant
65 1.1.1.1.4.2 perseant #define REG_D0 0
66 1.1.1.1.4.2 perseant #define REG_A0 4
67 1.1.1.1.4.2 perseant #define REG_SP 8
68 1.1.1.1.4.2 perseant #define REG_PC 9
69 1.1.1.1.4.2 perseant #define REG_MDR 10
70 1.1.1.1.4.2 perseant #define REG_PSW 11
71 1.1.1.1.4.2 perseant #define REG_LIR 12
72 1.1.1.1.4.2 perseant #define REG_LAR 13
73 1.1.1.1.4.2 perseant #define REG_MDRQ 14
74 1.1.1.1.4.2 perseant #define REG_E0 15
75 1.1.1.1.4.2 perseant #define REG_SSP 23
76 1.1.1.1.4.2 perseant #define REG_MSP 24
77 1.1.1.1.4.2 perseant #define REG_USP 25
78 1.1.1.1.4.2 perseant #define REG_MCRH 26
79 1.1.1.1.4.2 perseant #define REG_MCRL 27
80 1.1.1.1.4.2 perseant #define REG_MCVF 28
81 1.1.1.1.4.2 perseant
82 1.1.1.1.4.2 perseant #define REG_FPCR 29
83 1.1.1.1.4.2 perseant
84 1.1.1.1.4.2 perseant #define FPCR (State.regs[REG_FPCR])
85 1.1.1.1.4.2 perseant
86 1.1.1.1.4.2 perseant #define FCC_MASK LSMASK (21, 18)
87 1.1.1.1.4.2 perseant #define RM_MASK LSMASK (17, 16) /* Must always be zero. */
88 1.1.1.1.4.2 perseant #define EC_MASK LSMASK (14, 10)
89 1.1.1.1.4.2 perseant #define EE_MASK LSMASK ( 9, 5)
90 1.1.1.1.4.2 perseant #define EF_MASK LSMASK ( 4, 0)
91 1.1.1.1.4.2 perseant #define FPCR_MASK (FCC_MASK | EC_MASK | EE_MASK | EF_MASK)
92 1.1.1.1.4.2 perseant
93 1.1.1.1.4.2 perseant #define FCC_L LSBIT (21)
94 1.1.1.1.4.2 perseant #define FCC_G LSBIT (20)
95 1.1.1.1.4.2 perseant #define FCC_E LSBIT (19)
96 1.1.1.1.4.2 perseant #define FCC_U LSBIT (18)
97 1.1.1.1.4.2 perseant
98 1.1.1.1.4.2 perseant #define EC_V LSBIT (14)
99 1.1.1.1.4.2 perseant #define EC_Z LSBIT (13)
100 1.1.1.1.4.2 perseant #define EC_O LSBIT (12)
101 1.1.1.1.4.2 perseant #define EC_U LSBIT (11)
102 1.1.1.1.4.2 perseant #define EC_I LSBIT (10)
103 1.1.1.1.4.2 perseant
104 1.1.1.1.4.2 perseant #define EE_V LSBIT (9)
105 1.1.1.1.4.2 perseant #define EE_Z LSBIT (8)
106 1.1.1.1.4.2 perseant #define EE_O LSBIT (7)
107 1.1.1.1.4.2 perseant #define EE_U LSBIT (6)
108 1.1.1.1.4.2 perseant #define EE_I LSBIT (5)
109 1.1.1.1.4.2 perseant
110 1.1.1.1.4.2 perseant #define EF_V LSBIT (4)
111 1.1.1.1.4.2 perseant #define EF_Z LSBIT (3)
112 1.1.1.1.4.2 perseant #define EF_O LSBIT (2)
113 1.1.1.1.4.2 perseant #define EF_U LSBIT (1)
114 1.1.1.1.4.2 perseant #define EF_I LSBIT (0)
115 1.1.1.1.4.2 perseant
116 1.1.1.1.4.2 perseant #define PSW_FE LSBIT(20)
117 1.1.1.1.4.2 perseant #define FPU_DISABLED !(PSW & PSW_FE)
118 1.1.1.1.4.2 perseant
119 1.1.1.1.4.2 perseant #define XS2FS(X,S) State.fpregs.fs[((X<<4)|(S))]
120 1.1.1.1.4.2 perseant #define AS2FS(A,S) State.fpregs.fs[((A<<2)|(S))]
121 1.1.1.1.4.2 perseant #define Xf2FD(X,f) State.fpregs.fd[((X<<3)|(f))]
122 1.1.1.1.4.2 perseant
123 1.1.1.1.4.2 perseant #define FS2FPU(FS,F) sim_fpu_32to (&(F), (FS))
124 1.1.1.1.4.2 perseant #define FD2FPU(FD,F) sim_fpu_232to (&(F), ((FD).high), ((FD).low))
125 1.1.1.1.4.2 perseant #define FPU2FS(F,FS) sim_fpu_to32 (&(FS), &(F))
126 1.1.1.1.4.2 perseant #define FPU2FD(F,FD) sim_fpu_to232 (&((FD).high), &((FD).low), &(F))
127 1.1.1.1.4.2 perseant
128 1.1.1.1.4.2 perseant #define FETCH32(a,b,c,d) \
129 1.1.1.1.4.2 perseant ((a)+((b)<<8)+((c)<<16)+((d)<<24))
130 1.1.1.1.4.2 perseant
131 1.1.1.1.4.2 perseant #define FETCH24(a,b,c) \
132 1.1.1.1.4.2 perseant ((a)+((b)<<8)+((c)<<16))
133 1.1.1.1.4.2 perseant
134 1.1.1.1.4.2 perseant #define FETCH16(a,b) ((a)+((b)<<8))
135 1.1.1.1.4.2 perseant
136 1.1.1.1.4.2 perseant #define load_byte(ADDR) \
137 1.1.1.1.4.2 perseant sim_core_read_unaligned_1 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
138 1.1.1.1.4.2 perseant
139 1.1.1.1.4.2 perseant #define load_half(ADDR) \
140 1.1.1.1.4.2 perseant sim_core_read_unaligned_2 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
141 1.1.1.1.4.2 perseant
142 1.1.1.1.4.2 perseant #define load_word(ADDR) \
143 1.1.1.1.4.2 perseant sim_core_read_unaligned_4 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
144 1.1.1.1.4.2 perseant
145 1.1.1.1.4.2 perseant #define load_dword(ADDR) \
146 1.1.1.1.4.2 perseant u642dw (sim_core_read_unaligned_8 (STATE_CPU (simulator, 0), \
147 1.1.1.1.4.2 perseant PC, read_map, (ADDR)))
148 1.1.1.1.4.2 perseant
149 1.1.1.1.4.2 perseant static INLINE2 dword
150 1.1.1.1.4.2 perseant u642dw (uint64_t dw)
151 1.1.1.1.4.2 perseant {
152 1.1.1.1.4.2 perseant dword r;
153 1.1.1.1.4.2 perseant
154 1.1.1.1.4.2 perseant r.low = (uint32_t)dw;
155 1.1.1.1.4.2 perseant r.high = (uint32_t)(dw >> 32);
156 1.1.1.1.4.2 perseant return r;
157 1.1.1.1.4.2 perseant }
158 1.1.1.1.4.2 perseant
159 1.1.1.1.4.2 perseant #define store_byte(ADDR, DATA) \
160 1.1.1.1.4.2 perseant sim_core_write_unaligned_1 (STATE_CPU (simulator, 0), \
161 1.1.1.1.4.2 perseant PC, write_map, (ADDR), (DATA))
162 1.1.1.1.4.2 perseant
163 1.1.1.1.4.2 perseant
164 1.1.1.1.4.2 perseant #define store_half(ADDR, DATA) \
165 1.1.1.1.4.2 perseant sim_core_write_unaligned_2 (STATE_CPU (simulator, 0), \
166 1.1.1.1.4.2 perseant PC, write_map, (ADDR), (DATA))
167 1.1.1.1.4.2 perseant
168 1.1.1.1.4.2 perseant
169 1.1.1.1.4.2 perseant #define store_word(ADDR, DATA) \
170 1.1.1.1.4.2 perseant sim_core_write_unaligned_4 (STATE_CPU (simulator, 0), \
171 1.1.1.1.4.2 perseant PC, write_map, (ADDR), (DATA))
172 1.1.1.1.4.2 perseant #define store_dword(ADDR, DATA) \
173 1.1.1.1.4.2 perseant sim_core_write_unaligned_8 (STATE_CPU (simulator, 0), \
174 1.1.1.1.4.2 perseant PC, write_map, (ADDR), dw2u64 (DATA))
175 1.1.1.1.4.2 perseant
176 1.1.1.1.4.2 perseant static INLINE2 uint64_t
177 1.1.1.1.4.2 perseant dw2u64 (dword data)
178 1.1.1.1.4.2 perseant {
179 1.1.1.1.4.2 perseant return data.low | (((uint64_t)data.high) << 32);
180 1.1.1.1.4.2 perseant }
181 1.1.1.1.4.2 perseant
182 1.1.1.1.4.2 perseant /* Bring data in from the cold */
183 1.1.1.1.4.2 perseant
184 1.1.1.1.4.2 perseant #define IMEM8(EA) \
185 1.1.1.1.4.2 perseant (sim_core_read_aligned_1(STATE_CPU (SD, 0), EA, exec_map, (EA)))
186 1.1.1.1.4.2 perseant
187 1.1.1.1.4.2 perseant #define IMEM8_IMMED(EA, N) \
188 1.1.1.1.4.2 perseant (sim_core_read_aligned_1(STATE_CPU (SD, 0), EA, exec_map, (EA) + (N)))
189 1.1.1.1.4.2 perseant
190 1.1.1.1.4.2 perseant /* Function declarations. */
191 1.1.1.1.4.2 perseant
192 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericAdd (uint32_t source, uint32_t destReg);
193 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericSub (uint32_t source, uint32_t destReg);
194 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericCmp (uint32_t leftOpnd, uint32_t rightOpnd);
195 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericOr (uint32_t source, uint32_t destReg);
196 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericXor (uint32_t source, uint32_t destReg);
197 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) genericBtst (uint32_t leftOpnd, uint32_t rightOpnd);
198 1.1.1.1.4.2 perseant INLINE_SIM_MAIN (void) do_syscall (SIM_DESC sd);
199 1.1.1.1.4.2 perseant void program_interrupt (SIM_DESC sd, sim_cpu *cpu, sim_cia cia, SIM_SIGNAL sig)
200 1.1.1.1.4.2 perseant ATTRIBUTE_NORETURN;
201 1.1.1.1.4.2 perseant
202 1.1.1.1.4.2 perseant void mn10300_cpu_exception_trigger(SIM_DESC sd, sim_cpu* cpu, address_word pc);
203 1.1.1.1.4.2 perseant void mn10300_cpu_exception_suspend(SIM_DESC sd, sim_cpu* cpu, int exception);
204 1.1.1.1.4.2 perseant void mn10300_cpu_exception_resume(SIM_DESC sd, sim_cpu* cpu, int exception);
205 1.1.1.1.4.2 perseant
206 1.1.1.1.4.2 perseant void fpu_disabled_exception (SIM_DESC, sim_cpu *, address_word);
207 1.1.1.1.4.2 perseant void fpu_unimp_exception (SIM_DESC, sim_cpu *, address_word);
208 1.1.1.1.4.2 perseant void fpu_check_signal_exception (SIM_DESC, sim_cpu *, address_word);
209 1.1.1.1.4.2 perseant
210 1.1.1.1.4.2 perseant extern const struct fp_prec_t
211 1.1.1.1.4.2 perseant {
212 1.1.1.1.4.2 perseant void (* reg2val) (const void *, sim_fpu *);
213 1.1.1.1.4.2 perseant int (* round) (sim_fpu *);
214 1.1.1.1.4.2 perseant void (* val2reg) (const sim_fpu *, void *);
215 1.1.1.1.4.2 perseant } fp_single_prec, fp_double_prec;
216 1.1.1.1.4.2 perseant
217 1.1.1.1.4.2 perseant #define FP_SINGLE (&fp_single_prec)
218 1.1.1.1.4.2 perseant #define FP_DOUBLE (&fp_double_prec)
219 1.1.1.1.4.2 perseant
220 1.1.1.1.4.2 perseant void fpu_rsqrt (SIM_DESC, sim_cpu *, address_word, const void *, void *, const struct fp_prec_t *);
221 1.1.1.1.4.2 perseant void fpu_sqrt (SIM_DESC, sim_cpu *, address_word, const void *, void *, const struct fp_prec_t *);
222 1.1.1.1.4.2 perseant void fpu_cmp (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const struct fp_prec_t *);
223 1.1.1.1.4.2 perseant void fpu_add (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
224 1.1.1.1.4.2 perseant void fpu_sub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
225 1.1.1.1.4.2 perseant void fpu_mul (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
226 1.1.1.1.4.2 perseant void fpu_div (SIM_DESC, sim_cpu *, address_word, const void *, const void *, void *, const struct fp_prec_t *);
227 1.1.1.1.4.2 perseant void fpu_fmadd (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
228 1.1.1.1.4.2 perseant void fpu_fmsub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
229 1.1.1.1.4.2 perseant void fpu_fnmadd (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
230 1.1.1.1.4.2 perseant void fpu_fnmsub (SIM_DESC, sim_cpu *, address_word, const void *, const void *, const void *, void *, const struct fp_prec_t *);
231 1.1.1.1.4.2 perseant
232 1.1.1.1.4.2 perseant #endif
233