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