Restrict ldsr (load system register) to modifying just non-reserved PSW bits.
[binutils-gdb.git] / sim / v850 / sim-main.h
1 #define WITH_CORE
2 #define WITH_MODULO_MEMORY 1
3 #define WITH_WATCHPOINTS 1
4 #define WITH_TARGET_WORD_MSB 31
5
6 #include "sim-basics.h"
7
8 #include <signal.h>
9 typedef address_word sim_cia;
10
11
12 /* This simulator doesn't cache state */
13 #define SIM_ENGINE_HALT_HOOK(sd,last_cpu,cia) while (0)
14 #define SIM_ENGINE_RESTART_HOOK(sd,last_cpu,cia) while (0)
15
16 /* Get the number of instructions. FIXME: must be a more elegant way
17 of doing this. */
18 #include "itable.h"
19 #define MAX_INSNS (nr_itable_entries)
20 #define INSN_NAME(i) itable[(i)].name
21
22 #include "sim-base.h"
23
24 #include "simops.h"
25 #include "bfd.h"
26
27
28 typedef signed8 int8;
29 typedef unsigned8 uint8;
30 typedef signed16 int16;
31 typedef unsigned16 uint16;
32 typedef signed32 int32;
33 typedef unsigned32 uint32;
34 typedef unsigned32 reg_t;
35
36
37 /* The current state of the processor; registers, memory, etc. */
38
39 typedef struct _v850_regs {
40 reg_t regs[32]; /* general-purpose registers */
41 reg_t sregs[32]; /* system registers, including psw */
42 reg_t pc;
43 int dummy_mem; /* where invalid accesses go */
44 int pending_nmi;
45 } v850_regs;
46
47 struct _sim_cpu
48 {
49 /* ... simulator specific members ... */
50 v850_regs reg;
51 reg_t psw_mask; /* only allow non-reserved bits to be set */
52 /* ... base type ... */
53 sim_cpu_base base;
54 };
55
56 #define CPU_CIA(CPU) ((CPU)->reg.pc)
57
58 struct sim_state {
59 sim_cpu cpu[MAX_NR_PROCESSORS];
60 #if (WITH_SMP)
61 #define STATE_CPU(sd,n) (&(sd)->cpu[n])
62 #else
63 #define STATE_CPU(sd,n) (&(sd)->cpu[0])
64 #endif
65 #if 0
66 SIM_ADDR rom_size;
67 SIM_ADDR low_end;
68 SIM_ADDR high_start;
69 SIM_ADDR high_base;
70 void *mem;
71 #endif
72 sim_state_base base;
73 };
74
75 /* For compatibility, until all functions converted to passing
76 SIM_DESC as an argument */
77 extern SIM_DESC simulator;
78
79
80 #define V850_ROM_SIZE 0x8000
81 #define V850_LOW_END 0x200000
82 #define V850_HIGH_START 0xffe000
83
84
85 #define SIG_V850_EXIT -1 /* indication of a normal exit */
86
87 extern uint32 OP[4];
88
89 /* Because we are still using the old semantic table, provide compat
90 macro's that store the instruction where the old simops expects
91 it. */
92
93 #if 0
94 OP[0] = inst & 0x1f; /* RRRRR -> reg1 */
95 OP[1] = (inst >> 11) & 0x1f; /* rrrrr -> reg2 */
96 OP[2] = (inst >> 16) & 0xffff; /* wwwww -> reg3 */
97 OP[3] = inst;
98 #endif
99
100 #define SAVE_1 \
101 PC = cia; \
102 OP[0] = instruction_0 & 0x1f; \
103 OP[1] = (instruction_0 >> 11) & 0x1f; \
104 OP[2] = 0; \
105 OP[3] = instruction_0
106
107 #define COMPAT_1(CALL) \
108 SAVE_1; \
109 PC += (CALL); \
110 nia = PC
111
112 #define SAVE_2 \
113 PC = cia; \
114 OP[0] = instruction_0 & 0x1f; \
115 OP[1] = (instruction_0 >> 11) & 0x1f; \
116 OP[2] = instruction_1; \
117 OP[3] = (instruction_1 << 16) | instruction_0
118
119 #define COMPAT_2(CALL) \
120 SAVE_2; \
121 PC += (CALL); \
122 nia = PC
123
124
125 #if 0
126 extern struct simops Simops[];
127 #endif
128
129 #define State (STATE_CPU (simulator, 0)->reg)
130 #define PC (State.pc)
131 #define SP (State.regs[3])
132 #define EP (State.regs[30])
133
134 #define EIPC (State.sregs[0])
135 #define EIPSW (State.sregs[1])
136 #define FEPC (State.sregs[2])
137 #define FEPSW (State.sregs[3])
138 #define ECR (State.sregs[4])
139 #define PSW (State.sregs[5])
140 /* start-sanitize-v850e */
141 #define CTPC (State.sregs[16])
142 #define CTPSW (State.sregs[17])
143 /* end-sanitize-v850e */
144 #define DBPC (State.sregs[18])
145 #define DBPSW (State.sregs[19])
146 /* start-sanitize-v850e */
147 #define CTBP (State.sregs[20])
148 /* end-sanitize-v850e */
149
150 /* start-sanitize-v850eq */
151 #define PSW_US BIT32 (8)
152 /* end-sanitize-v850eq */
153 #define PSW_NP 0x80
154 #define PSW_EP 0x40
155 #define PSW_ID 0x20
156 #define PSW_SAT 0x10
157 #define PSW_CY 0x8
158 #define PSW_OV 0x4
159 #define PSW_S 0x2
160 #define PSW_Z 0x1
161
162 #define SEXT3(x) ((((x)&0x7)^(~0x3))+0x4)
163
164 /* sign-extend a 4-bit number */
165 #define SEXT4(x) ((((x)&0xf)^(~0x7))+0x8)
166
167 /* sign-extend a 5-bit number */
168 #define SEXT5(x) ((((x)&0x1f)^(~0xf))+0x10)
169
170 /* sign-extend a 9-bit number */
171 #define SEXT9(x) ((((x)&0x1ff)^(~0xff))+0x100)
172
173 /* sign-extend a 22-bit number */
174 #define SEXT22(x) ((((x)&0x3fffff)^(~0x1fffff))+0x200000)
175
176 /* sign extend a 40 bit number */
177 #define SEXT40(x) ((((x) & UNSIGNED64 (0xffffffffff)) \
178 ^ (~UNSIGNED64 (0x7fffffffff))) \
179 + UNSIGNED64 (0x8000000000))
180
181 /* sign extend a 44 bit number */
182 #define SEXT44(x) ((((x) & UNSIGNED64 (0xfffffffffff)) \
183 ^ (~ UNSIGNED64 (0x7ffffffffff))) \
184 + UNSIGNED64 (0x80000000000))
185
186 /* sign extend a 60 bit number */
187 #define SEXT60(x) ((((x) & UNSIGNED64 (0xfffffffffffffff)) \
188 ^ (~ UNSIGNED64 (0x7ffffffffffffff))) \
189 + UNSIGNED64 (0x800000000000000))
190
191 /* No sign extension */
192 #define NOP(x) (x)
193
194 #define INC_ADDR(x,i) x = ((State.MD && x == MOD_E) ? MOD_S : (x)+(i))
195
196 #define RLW(x) load_mem (x, 4)
197
198 #ifdef _WIN32
199 #ifndef SIGTRAP
200 #define SIGTRAP 5
201 #endif
202 #ifndef SIGQUIT
203 #define SIGQUIT 3
204 #endif
205 #endif
206
207 /* Function declarations. */
208
209 #define IMEM(EA) \
210 sim_core_read_aligned_2 (STATE_CPU (sd, 0), \
211 PC, sim_core_execute_map, (EA))
212
213 #define IMEM_IMMED(EA,N) \
214 sim_core_read_aligned_2 (STATE_CPU (sd, 0), \
215 PC, sim_core_execute_map, (EA) + (N) * 2)
216
217 #define load_mem(ADDR,LEN) \
218 sim_core_read_unaligned_##LEN (STATE_CPU (simulator, 0), \
219 PC, sim_core_read_map, (ADDR))
220
221 #define store_mem(ADDR,LEN,DATA) \
222 sim_core_write_unaligned_##LEN (STATE_CPU (simulator, 0), \
223 PC, sim_core_write_map, (ADDR), (DATA))
224
225
226 /* Debug/tracing calls */
227
228 enum op_types
229 {
230 OP_UNKNOWN,
231 OP_NONE,
232 OP_TRAP,
233 OP_REG,
234 OP_REG_REG,
235 OP_REG_REG_CMP,
236 OP_REG_REG_MOVE,
237 OP_IMM_REG,
238 OP_IMM_REG_CMP,
239 OP_IMM_REG_MOVE,
240 OP_COND_BR,
241 OP_LOAD16,
242 OP_STORE16,
243 OP_LOAD32,
244 OP_STORE32,
245 OP_JUMP,
246 OP_IMM_REG_REG,
247 OP_UIMM_REG_REG,
248 OP_BIT,
249 OP_EX1,
250 OP_EX2,
251 OP_LDSR,
252 OP_STSR,
253 /* start-sanitize-v850e */
254 OP_BIT_CHANGE,
255 OP_REG_REG_REG,
256 OP_REG_REG3,
257 /* end-sanitize-v850e */
258 /* start-sanitize-v850eq */
259 OP_IMM_REG_REG_REG,
260 OP_PUSHPOP1,
261 OP_PUSHPOP2,
262 OP_PUSHPOP3,
263 /* end-sanitize-v850eq */
264 };
265
266 #ifdef DEBUG
267 void trace_input PARAMS ((char *name, enum op_types type, int size));
268 void trace_output PARAMS ((enum op_types result));
269 #else
270 #define trace_input(NAME, IN1, IN2)
271 #define trace_output(RESULT)
272 #endif
273
274
275 /* start-sanitize-v850eq */
276 extern void divun ( unsigned int N,
277 unsigned long int als,
278 unsigned long int sfi,
279 unsigned long int * quotient_ptr,
280 unsigned long int * remainder_ptr,
281 boolean * overflow_ptr
282 );
283 extern void divn ( unsigned int N,
284 unsigned long int als,
285 unsigned long int sfi,
286 signed long int * quotient_ptr,
287 signed long int * remainder_ptr,
288 boolean * overflow_ptr
289 );
290 /* end-sanitize-v850eq */
291 /* start-sanitize-v850e */
292 extern int type1_regs[];
293 extern int type2_regs[];
294 /* end-sanitize-v850e */
295 /* start-sanitize-v850eq */
296 extern int type3_regs[];
297 /* end-sanitize-v850eq */