Make sure there is a trailing space after the instruction
[deliverable/binutils-gdb.git] / sim / v850 / interp.c
CommitLineData
22c1c7dd
JL
1#include <signal.h>
2#include "sysdep.h"
3#include "bfd.h"
4#include "remote-sim.h"
5#include "callback.h"
6
7#include "v850_sim.h"
8
9909e232
JL
9#ifndef INLINE
10#ifdef __GNUC__
11#define INLINE inline
12#else
13#define INLINE
14#endif
15#endif
16
28647e4c 17#define MEM_SIZE 18 /* V850 memory size is 18 bits XXX */
22c1c7dd 18
d81352b8 19host_callback *v850_callback;
ead4a3f1 20int v850_debug;
d81352b8
JL
21
22
23uint32 OP[4];
22c1c7dd
JL
24
25static struct hash_entry *lookup_hash PARAMS ((uint32 ins));
9909e232
JL
26static long hash PARAMS ((long));
27static void do_format_1_2 PARAMS ((uint32));
28static void do_format_3 PARAMS ((uint32));
29static void do_format_4 PARAMS ((uint32));
30static void do_format_5 PARAMS ((uint32));
31static void do_format_6 PARAMS ((uint32));
32static void do_format_7 PARAMS ((uint32));
33static void do_format_8 PARAMS ((uint32));
34static void do_format_9_10 PARAMS ((uint32));
35static void init_system PARAMS ((void));
22c1c7dd
JL
36
37#define MAX_HASH 63
38struct hash_entry
39{
40 struct hash_entry *next;
41 long opcode;
42 long mask;
43 struct simops *ops;
44};
45
46struct hash_entry hash_table[MAX_HASH+1];
47
9909e232
JL
48
49static INLINE long
22c1c7dd
JL
50hash(insn)
51 long insn;
52{
83fc3bac 53 if ((insn & 0x0600) == 0
9909e232
JL
54 || (insn & 0x0700) == 0x0200
55 || (insn & 0x0700) == 0x0600
56 || (insn & 0x0780) == 0x0700)
0ef0eba5 57 return (insn & 0x07e0) >> 5;
83fc3bac
JL
58 if ((insn & 0x0700) == 0x0300
59 || (insn & 0x0700) == 0x0400
60 || (insn & 0x0700) == 0x0500)
61 return (insn & 0x0780) >> 7;
83fc3bac 62 if ((insn & 0x07c0) == 0x0780)
0ef0eba5 63 return (insn & 0x07c0) >> 6;
83fc3bac 64 return (insn & 0x07e0) >> 5;
22c1c7dd
JL
65}
66
67static struct hash_entry *
68lookup_hash (ins)
69 uint32 ins;
70{
71 struct hash_entry *h;
72
0ef0eba5 73 h = &hash_table[hash(ins)];
22c1c7dd 74
9909e232 75 while ((ins & h->mask) != h->opcode)
22c1c7dd
JL
76 {
77 if (h->next == NULL)
78 {
ead4a3f1 79 (*v850_callback->printf_filtered) (v850_callback, "ERROR looking up hash for %x\n", ins);
22c1c7dd
JL
80 exit(1);
81 }
82 h = h->next;
83 }
84 return (h);
85}
86
28647e4c
JL
87uint8
88get_byte (x)
89 uint8 *x;
22c1c7dd 90{
28647e4c 91 return *x;
0ef0eba5
JL
92}
93
28647e4c
JL
94uint16
95get_half (x)
96 uint8 *x;
0ef0eba5
JL
97{
98 uint8 *a = x;
28647e4c 99 return (a[1] << 8) + (a[0]);
22c1c7dd
JL
100}
101
28647e4c 102uint32
0ef0eba5
JL
103get_word (x)
104 uint8 *x;
22c1c7dd 105{
0ef0eba5 106 uint8 *a = x;
28647e4c 107 return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
22c1c7dd
JL
108}
109
110void
28647e4c 111put_byte (addr, data)
0ef0eba5 112 uint8 *addr;
28647e4c 113 uint8 data;
22c1c7dd 114{
0ef0eba5 115 uint8 *a = addr;
28647e4c 116 a[0] = data;
22c1c7dd
JL
117}
118
0ef0eba5 119void
28647e4c 120put_half (addr, data)
0ef0eba5 121 uint8 *addr;
28647e4c 122 uint16 data;
0ef0eba5 123{
28647e4c
JL
124 uint8 *a = addr;
125 a[0] = data & 0xff;
126 a[1] = (data >> 8) & 0xff;
0ef0eba5
JL
127}
128
129void
28647e4c 130put_word (addr, data)
0ef0eba5 131 uint8 *addr;
28647e4c 132 uint32 data;
0ef0eba5
JL
133{
134 uint8 *a = addr;
28647e4c
JL
135 a[0] = data & 0xff;
136 a[1] = (data >> 8) & 0xff;
137 a[2] = (data >> 16) & 0xff;
138 a[3] = (data >> 24) & 0xff;
22c1c7dd
JL
139}
140
141static void
0ef0eba5 142do_format_1_2 (insn)
22c1c7dd
JL
143 uint32 insn;
144{
0ef0eba5 145 struct hash_entry *h;
0ef0eba5
JL
146
147 h = lookup_hash (insn);
148 OP[0] = insn & 0x1f;
149 OP[1] = (insn >> 11) & 0x1f;
150 (h->ops->func) ();
22c1c7dd
JL
151}
152
153static void
154do_format_3 (insn)
155 uint32 insn;
156{
2108e864 157 struct hash_entry *h;
2108e864
JL
158
159 h = lookup_hash (insn);
160 OP[0] = (((insn & 0x70) >> 4) | ((insn & 0xf800) >> 8)) << 1;
161 (h->ops->func) ();
22c1c7dd
JL
162}
163
164static void
165do_format_4 (insn)
166 uint32 insn;
167{
3cb6bf78 168 struct hash_entry *h;
3cb6bf78
JL
169
170 h = lookup_hash (insn);
171 OP[0] = (insn >> 11) & 0x1f;
172 OP[1] = (insn & 0x7f);
173 (h->ops->func) ();
22c1c7dd
JL
174}
175
176static void
177do_format_5 (insn)
178 uint32 insn;
179{
e9b6cbac 180 struct hash_entry *h;
e9b6cbac
JL
181
182 h = lookup_hash (insn);
d81352b8 183 OP[0] = (((insn & 0x3f) << 15) | ((insn >> 17) & 0x7fff)) << 1;
e9b6cbac
JL
184 OP[1] = (insn >> 11) & 0x1f;
185 (h->ops->func) ();
22c1c7dd
JL
186}
187
188static void
189do_format_6 (insn)
190 uint32 insn;
191{
0ef0eba5 192 struct hash_entry *h;
0ef0eba5
JL
193
194 h = lookup_hash (insn);
195 OP[0] = (insn >> 16) & 0xffff;
196 OP[1] = insn & 0x1f;
197 OP[2] = (insn >> 11) & 0x1f;
198 (h->ops->func) ();
22c1c7dd
JL
199}
200
201static void
202do_format_7 (insn)
203 uint32 insn;
204{
28647e4c 205 struct hash_entry *h;
28647e4c
JL
206
207 h = lookup_hash (insn);
208 OP[0] = insn & 0x1f;
209 OP[1] = (insn >> 11) & 0x1f;
210 OP[2] = (insn >> 16) & 0xffff;
211 (h->ops->func) ();
22c1c7dd
JL
212}
213
214static void
215do_format_8 (insn)
216 uint32 insn;
217{
83fc3bac 218 struct hash_entry *h;
83fc3bac
JL
219
220 h = lookup_hash (insn);
221 OP[0] = insn & 0x1f;
222 OP[1] = (insn >> 11) & 0x7;
223 OP[2] = (insn >> 16) & 0xffff;
224 (h->ops->func) ();
22c1c7dd
JL
225}
226
227static void
9909e232 228do_format_9_10 (insn)
22c1c7dd
JL
229 uint32 insn;
230{
0ef0eba5 231 struct hash_entry *h;
0ef0eba5
JL
232
233 h = lookup_hash (insn);
234 OP[0] = insn & 0x1f;
235 OP[1] = (insn >> 11) & 0x1f;
236 (h->ops->func) ();
22c1c7dd
JL
237}
238
239void
240sim_size (power)
241 int power;
242
243{
28647e4c 244 if (State.mem)
22c1c7dd 245 {
28647e4c 246 free (State.mem);
22c1c7dd
JL
247 }
248
28647e4c
JL
249 State.mem = (uint8 *)calloc(1,1<<MEM_SIZE);
250 if (!State.mem)
22c1c7dd 251 {
ead4a3f1 252 (*v850_callback->printf_filtered) (v850_callback, "Memory allocation failed.\n");
22c1c7dd
JL
253 exit(1);
254 }
22c1c7dd
JL
255}
256
257static void
258init_system ()
259{
28647e4c 260 if (!State.mem)
22c1c7dd
JL
261 sim_size(1);
262}
263
264int
265sim_write (addr, buffer, size)
266 SIM_ADDR addr;
267 unsigned char *buffer;
268 int size;
269{
270 int i;
271 init_system ();
272
22c1c7dd
JL
273 for (i = 0; i < size; i++)
274 {
28647e4c 275 State.mem[i+addr] = buffer[i];
22c1c7dd
JL
276 }
277 return size;
278}
279
280void
281sim_open (args)
282 char *args;
283{
284 struct simops *s;
9909e232 285 struct hash_entry *h;
22c1c7dd 286 if (args != NULL)
ead4a3f1
MM
287 {
288#ifdef DEBUG
289 if (strcmp (args, "-t") == 0)
290 d10v_debug = DEBUG;
291 else
292#endif
293 (*d10v_callback->printf_filtered) (d10v_callback, "ERROR: unsupported option(s): %s\n",args);
294 }
22c1c7dd
JL
295
296 /* put all the opcodes in the hash table */
297 for (s = Simops; s->func; s++)
298 {
299 h = &hash_table[hash(s->opcode)];
300
301 /* go to the last entry in the chain */
302 while (h->next)
303 h = h->next;
304
305 if (h->ops)
306 {
307 h->next = calloc(1,sizeof(struct hash_entry));
308 h = h->next;
309 }
310 h->ops = s;
311 h->mask = s->mask;
312 h->opcode = s->opcode;
313 }
314}
315
316
317void
318sim_close (quitting)
319 int quitting;
320{
321 /* nothing to do */
322}
323
324void
325sim_set_profile (n)
326 int n;
327{
ead4a3f1 328 (*v850_callback->printf_filtered) (v850_callback, "sim_set_profile %d\n", n);
22c1c7dd
JL
329}
330
331void
332sim_set_profile_size (n)
333 int n;
334{
ead4a3f1 335 (*v850_callback->printf_filtered) (v850_callback, "sim_set_profile_size %d\n", n);
22c1c7dd
JL
336}
337
338void
339sim_resume (step, siggnal)
340 int step, siggnal;
341{
342 uint32 inst, opcode;
22c1c7dd
JL
343 reg_t oldpc;
344
22c1c7dd
JL
345 if (step)
346 State.exception = SIGTRAP;
347 else
348 State.exception = 0;
349
350 do
351 {
352 inst = RLW (PC);
353 oldpc = PC;
0ef0eba5
JL
354 opcode = (inst & 0x07e0) >> 5;
355 if ((opcode & 0x30) == 0
356 || (opcode & 0x38) == 0x10)
22c1c7dd 357 {
0ef0eba5 358 do_format_1_2 (inst & 0xffff);
22c1c7dd
JL
359 PC += 2;
360 }
361 else if ((opcode & 0x3C) == 0x18
362 || (opcode & 0x3C) == 0x1C
363 || (opcode & 0x3C) == 0x20
364 || (opcode & 0x3C) == 0x24
365 || (opcode & 0x3C) == 0x28)
366 {
0ef0eba5 367 do_format_4 (inst & 0xffff);
22c1c7dd
JL
368 PC += 2;
369 }
d81352b8 370 else if ((opcode & 0x3C) == 0x2C)
22c1c7dd 371 {
0ef0eba5
JL
372 do_format_3 (inst & 0xffff);
373 /* No PC update, it's done in the instruction. */
22c1c7dd
JL
374 }
375 else if ((opcode & 0x38) == 0x30)
376 {
377 do_format_6 (inst);
378 PC += 4;
379 }
380 else if ((opcode & 0x3C) == 0x38)
381 {
382 do_format_7 (inst);
383 PC += 4;
384 }
385 else if ((opcode & 0x3E) == 0x3C)
386 {
387 do_format_5 (inst);
e9b6cbac 388 /* No PC update, it's done in the instruction. */
22c1c7dd 389 }
0ef0eba5 390 else if ((opcode & 0x3F) == 0x3E)
22c1c7dd
JL
391 {
392 do_format_8 (inst);
393 PC += 4;
394 }
395 else
396 {
9909e232 397 do_format_9_10 (inst);
22c1c7dd
JL
398 PC += 4;
399 }
400 }
401 while (!State.exception);
402}
403
404int
405sim_trace ()
406{
ead4a3f1
MM
407#ifdef DEBUG
408 v850_debug = DEBUG;
409#endif
410 sim_resume (0, 0);
411 return 1;
22c1c7dd
JL
412}
413
414void
415sim_info (verbose)
416 int verbose;
417{
ead4a3f1 418 (*v850_callback->printf_filtered) (v850_callback, "sim_info\n");
22c1c7dd
JL
419}
420
421void
422sim_create_inferior (start_address, argv, env)
423 SIM_ADDR start_address;
424 char **argv;
425 char **env;
426{
22c1c7dd
JL
427 PC = start_address;
428}
429
430
431void
432sim_kill ()
433{
434 /* nothing to do */
435}
436
437void
438sim_set_callbacks(p)
439 host_callback *p;
440{
d81352b8 441 v850_callback = p;
22c1c7dd
JL
442}
443
2b6b2c6d 444/* All the code for exiting, signals, etc needs to be revamped.
d81352b8
JL
445
446 This is enough to get c-torture limping though. */
22c1c7dd
JL
447void
448sim_stop_reason (reason, sigrc)
449 enum sim_stop *reason;
450 int *sigrc;
451{
22c1c7dd 452
d81352b8 453 *reason = sim_stopped;
22c1c7dd 454 if (State.exception == SIGQUIT)
d81352b8 455 *sigrc = 0;
22c1c7dd 456 else
d81352b8 457 *sigrc = State.exception;
22c1c7dd
JL
458}
459
460void
461sim_fetch_register (rn, memory)
462 int rn;
463 unsigned char *memory;
464{
465 *(uint32 *)memory = State.regs[rn];
22c1c7dd
JL
466}
467
468void
469sim_store_register (rn, memory)
470 int rn;
471 unsigned char *memory;
472{
473 State.regs[rn]= *(uint32 *)memory;
22c1c7dd
JL
474}
475
9909e232 476int
22c1c7dd
JL
477sim_read (addr, buffer, size)
478 SIM_ADDR addr;
479 unsigned char *buffer;
480 int size;
481{
482 int i;
483 for (i = 0; i < size; i++)
484 {
28647e4c 485 buffer[i] = State.mem[addr + i];
22c1c7dd
JL
486 }
487 return size;
488}
489
490void
491sim_do_command (cmd)
492 char *cmd;
493{
ead4a3f1 494 (*v850_callback->printf_filtered) (v850_callback, "sim_do_command: %s\n", cmd);
22c1c7dd
JL
495}
496
497int
498sim_load (prog, from_tty)
499 char *prog;
500 int from_tty;
501{
502 /* Return nonzero so GDB will handle it. */
503 return 1;
504}
This page took 0.046279 seconds and 4 git commands to generate.