4 #include "sim/callback.h"
5 #include "opcode/mn10300.h"
10 #include "sim-signal.h"
12 extern SIM_DESC simulator
;
18 typedef uint32_t reg_t
;
31 /* The current state of the processor; registers, memory, etc. */
35 reg_t regs
[32]; /* registers, d0-d3, a0-a3, sp, pc, mdr, psw,
36 lir, lar, mdrq, plus some room for processor
40 reg_t fs
[32]; /* FS0-31 */
41 dword fd
[16]; /* FD0,2,...,30 */
44 /* All internal state modified by signal_exception() that may need to be
45 rolled back for passing moment-of-exception image back to gdb. */
46 reg_t exc_trigger_regs
[32];
47 reg_t exc_suspend_regs
[32];
50 #define SIM_CPU_EXCEPTION_TRIGGER(SD,CPU,CIA) mn10300_cpu_exception_trigger(SD,CPU,CIA)
51 #define SIM_CPU_EXCEPTION_SUSPEND(SD,CPU,EXC) mn10300_cpu_exception_suspend(SD,CPU,EXC)
52 #define SIM_CPU_EXCEPTION_RESUME(SD,CPU,EXC) mn10300_cpu_exception_resume(SD,CPU,EXC)
55 extern struct _state State
;
57 #define PC (State.regs[REG_PC])
58 #define SP (State.regs[REG_SP])
60 #define PSW (State.regs[11])
65 #define PSW_IE LSBIT (11)
66 #define PSW_LM LSMASK (10, 8)
68 #define EXTRACT_PSW_LM LSEXTRACTED16 (PSW, 10, 8)
69 #define INSERT_PSW_LM(l) LSINSERTED16 ((l), 10, 8)
90 #define FPCR (State.regs[REG_FPCR])
92 #define FCC_MASK LSMASK (21, 18)
93 #define RM_MASK LSMASK (17, 16) /* Must always be zero. */
94 #define EC_MASK LSMASK (14, 10)
95 #define EE_MASK LSMASK ( 9, 5)
96 #define EF_MASK LSMASK ( 4, 0)
97 #define FPCR_MASK (FCC_MASK | EC_MASK | EE_MASK | EF_MASK)
99 #define FCC_L LSBIT (21)
100 #define FCC_G LSBIT (20)
101 #define FCC_E LSBIT (19)
102 #define FCC_U LSBIT (18)
104 #define EC_V LSBIT (14)
105 #define EC_Z LSBIT (13)
106 #define EC_O LSBIT (12)
107 #define EC_U LSBIT (11)
108 #define EC_I LSBIT (10)
110 #define EE_V LSBIT (9)
111 #define EE_Z LSBIT (8)
112 #define EE_O LSBIT (7)
113 #define EE_U LSBIT (6)
114 #define EE_I LSBIT (5)
116 #define EF_V LSBIT (4)
117 #define EF_Z LSBIT (3)
118 #define EF_O LSBIT (2)
119 #define EF_U LSBIT (1)
120 #define EF_I LSBIT (0)
122 #define PSW_FE LSBIT(20)
123 #define FPU_DISABLED !(PSW & PSW_FE)
125 #define XS2FS(X,S) State.fpregs.fs[((X<<4)|(S))]
126 #define AS2FS(A,S) State.fpregs.fs[((A<<2)|(S))]
127 #define Xf2FD(X,f) State.fpregs.fd[((X<<3)|(f))]
129 #define FS2FPU(FS,F) sim_fpu_32to (&(F), (FS))
130 #define FD2FPU(FD,F) sim_fpu_232to (&(F), ((FD).high), ((FD).low))
131 #define FPU2FS(F,FS) sim_fpu_to32 (&(FS), &(F))
132 #define FPU2FD(F,FD) sim_fpu_to232 (&((FD).high), &((FD).low), &(F))
134 #define FETCH32(a,b,c,d) \
135 ((a)+((b)<<8)+((c)<<16)+((d)<<24))
137 #define FETCH24(a,b,c) \
138 ((a)+((b)<<8)+((c)<<16))
140 #define FETCH16(a,b) ((a)+((b)<<8))
142 #define load_byte(ADDR) \
143 sim_core_read_unaligned_1 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
145 #define load_half(ADDR) \
146 sim_core_read_unaligned_2 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
148 #define load_word(ADDR) \
149 sim_core_read_unaligned_4 (STATE_CPU (simulator, 0), PC, read_map, (ADDR))
151 #define load_dword(ADDR) \
152 u642dw (sim_core_read_unaligned_8 (STATE_CPU (simulator, 0), \
153 PC, read_map, (ADDR)))
160 r
.low
= (uint32_t)dw
;
161 r
.high
= (uint32_t)(dw
>> 32);
165 #define store_byte(ADDR, DATA) \
166 sim_core_write_unaligned_1 (STATE_CPU (simulator, 0), \
167 PC, write_map, (ADDR), (DATA))
170 #define store_half(ADDR, DATA) \
171 sim_core_write_unaligned_2 (STATE_CPU (simulator, 0), \
172 PC, write_map, (ADDR), (DATA))
175 #define store_word(ADDR, DATA) \
176 sim_core_write_unaligned_4 (STATE_CPU (simulator, 0), \
177 PC, write_map, (ADDR), (DATA))
178 #define store_dword(ADDR, DATA) \
179 sim_core_write_unaligned_8 (STATE_CPU (simulator, 0), \
180 PC, write_map, (ADDR), dw2u64 (DATA))
182 static INLINE2
uint64_t
185 return data
.low
| (((uint64_t)data
.high
) << 32);
188 /* Function declarations. */
190 INLINE_SIM_MAIN (void) genericAdd (uint32_t source
, uint32_t destReg
);
191 INLINE_SIM_MAIN (void) genericSub (uint32_t source
, uint32_t destReg
);
192 INLINE_SIM_MAIN (void) genericCmp (uint32_t leftOpnd
, uint32_t rightOpnd
);
193 INLINE_SIM_MAIN (void) genericOr (uint32_t source
, uint32_t destReg
);
194 INLINE_SIM_MAIN (void) genericXor (uint32_t source
, uint32_t destReg
);
195 INLINE_SIM_MAIN (void) genericBtst (uint32_t leftOpnd
, uint32_t rightOpnd
);
196 INLINE_SIM_MAIN (void) do_syscall (SIM_DESC sd
);
197 void program_interrupt (SIM_DESC sd
, sim_cpu
*cpu
, sim_cia cia
, SIM_SIGNAL sig
);
199 void mn10300_cpu_exception_trigger(SIM_DESC sd
, sim_cpu
* cpu
, address_word pc
);
200 void mn10300_cpu_exception_suspend(SIM_DESC sd
, sim_cpu
* cpu
, int exception
);
201 void mn10300_cpu_exception_resume(SIM_DESC sd
, sim_cpu
* cpu
, int exception
);
203 void fpu_disabled_exception (SIM_DESC
, sim_cpu
*, address_word
);
204 void fpu_unimp_exception (SIM_DESC
, sim_cpu
*, address_word
);
205 void fpu_check_signal_exception (SIM_DESC
, sim_cpu
*, address_word
);
207 extern const struct fp_prec_t
209 void (* reg2val
) (const void *, sim_fpu
*);
210 int (* round
) (sim_fpu
*);
211 void (* val2reg
) (const sim_fpu
*, void *);
212 } fp_single_prec
, fp_double_prec
;
214 #define FP_SINGLE (&fp_single_prec)
215 #define FP_DOUBLE (&fp_double_prec)
217 void fpu_rsqrt (SIM_DESC
, sim_cpu
*, address_word
, const void *, void *, const struct fp_prec_t
*);
218 void fpu_sqrt (SIM_DESC
, sim_cpu
*, address_word
, const void *, void *, const struct fp_prec_t
*);
219 void fpu_cmp (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, const struct fp_prec_t
*);
220 void fpu_add (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, void *, const struct fp_prec_t
*);
221 void fpu_sub (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, void *, const struct fp_prec_t
*);
222 void fpu_mul (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, void *, const struct fp_prec_t
*);
223 void fpu_div (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, void *, const struct fp_prec_t
*);
224 void fpu_fmadd (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, const void *, void *, const struct fp_prec_t
*);
225 void fpu_fmsub (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, const void *, void *, const struct fp_prec_t
*);
226 void fpu_fnmadd (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, const void *, void *, const struct fp_prec_t
*);
227 void fpu_fnmsub (SIM_DESC
, sim_cpu
*, address_word
, const void *, const void *, const void *, void *, const struct fp_prec_t
*);