4 #include "remote-sim.h"
17 #define MEM_SIZE 18 /* V850 memory size is 18 bits XXX */
19 host_callback *v850_callback;
24 static struct hash_entry *lookup_hash PARAMS ((uint32 ins));
25 static long hash PARAMS ((long));
26 static void do_format_1_2 PARAMS ((uint32));
27 static void do_format_3 PARAMS ((uint32));
28 static void do_format_4 PARAMS ((uint32));
29 static void do_format_5 PARAMS ((uint32));
30 static void do_format_6 PARAMS ((uint32));
31 static void do_format_7 PARAMS ((uint32));
32 static void do_format_8 PARAMS ((uint32));
33 static void do_format_9_10 PARAMS ((uint32));
34 static void init_system PARAMS ((void));
39 struct hash_entry *next;
45 struct hash_entry hash_table[MAX_HASH+1];
52 if ((insn & 0x0600) == 0
53 || (insn & 0x0700) == 0x0200
54 || (insn & 0x0700) == 0x0600
55 || (insn & 0x0780) == 0x0700)
56 return (insn & 0x07e0) >> 5;
57 if ((insn & 0x0700) == 0x0300
58 || (insn & 0x0700) == 0x0400
59 || (insn & 0x0700) == 0x0500)
60 return (insn & 0x0780) >> 7;
61 if ((insn & 0x07c0) == 0x0780)
62 return (insn & 0x07c0) >> 6;
63 return (insn & 0x07e0) >> 5;
66 static struct hash_entry *
72 h = &hash_table[hash(ins)];
74 while ((ins & h->mask) != h->opcode)
78 printf ("ERROR looking up hash for %x\n",ins);
98 return (a[1] << 8) + (a[0]);
106 return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
110 put_byte (addr, data)
119 put_half (addr, data)
125 a[1] = (data >> 8) & 0xff;
129 put_word (addr, data)
135 a[1] = (data >> 8) & 0xff;
136 a[2] = (data >> 16) & 0xff;
137 a[3] = (data >> 24) & 0xff;
144 struct hash_entry *h;
146 h = lookup_hash (insn);
148 OP[1] = (insn >> 11) & 0x1f;
156 struct hash_entry *h;
158 h = lookup_hash (insn);
159 OP[0] = (((insn & 0x70) >> 4) | ((insn & 0xf800) >> 8)) << 1;
167 struct hash_entry *h;
169 h = lookup_hash (insn);
170 OP[0] = (insn >> 11) & 0x1f;
171 OP[1] = (insn & 0x7f);
179 struct hash_entry *h;
181 h = lookup_hash (insn);
182 OP[0] = (((insn & 0x3f) << 15) | ((insn >> 17) & 0x7fff)) << 1;
183 OP[1] = (insn >> 11) & 0x1f;
191 struct hash_entry *h;
193 h = lookup_hash (insn);
194 OP[0] = (insn >> 16) & 0xffff;
196 OP[2] = (insn >> 11) & 0x1f;
204 struct hash_entry *h;
206 h = lookup_hash (insn);
208 OP[1] = (insn >> 11) & 0x1f;
209 OP[2] = (insn >> 16) & 0xffff;
217 struct hash_entry *h;
219 h = lookup_hash (insn);
221 OP[1] = (insn >> 11) & 0x7;
222 OP[2] = (insn >> 16) & 0xffff;
227 do_format_9_10 (insn)
230 struct hash_entry *h;
232 h = lookup_hash (insn);
234 OP[1] = (insn >> 11) & 0x1f;
248 State.mem = (uint8 *)calloc(1,1<<MEM_SIZE);
251 fprintf (stderr,"Memory allocation failed.\n");
264 sim_write (addr, buffer, size)
266 unsigned char *buffer;
272 for (i = 0; i < size; i++)
274 State.mem[i+addr] = buffer[i];
284 struct hash_entry *h;
286 printf ("sim_open %s\n",args);
288 /* put all the opcodes in the hash table */
289 for (s = Simops; s->func; s++)
291 h = &hash_table[hash(s->opcode)];
293 /* go to the last entry in the chain */
299 h->next = calloc(1,sizeof(struct hash_entry));
304 h->opcode = s->opcode;
320 printf ("sim_set_profile %d\n",n);
324 sim_set_profile_size (n)
327 printf ("sim_set_profile_size %d\n",n);
331 sim_resume (step, siggnal)
338 State.exception = SIGTRAP;
346 opcode = (inst & 0x07e0) >> 5;
347 if ((opcode & 0x30) == 0
348 || (opcode & 0x38) == 0x10)
350 do_format_1_2 (inst & 0xffff);
353 else if ((opcode & 0x3C) == 0x18
354 || (opcode & 0x3C) == 0x1C
355 || (opcode & 0x3C) == 0x20
356 || (opcode & 0x3C) == 0x24
357 || (opcode & 0x3C) == 0x28)
359 do_format_4 (inst & 0xffff);
362 else if ((opcode & 0x3C) == 0x2C)
364 do_format_3 (inst & 0xffff);
365 /* No PC update, it's done in the instruction. */
367 else if ((opcode & 0x38) == 0x30)
372 else if ((opcode & 0x3C) == 0x38)
377 else if ((opcode & 0x3E) == 0x3C)
380 /* No PC update, it's done in the instruction. */
382 else if ((opcode & 0x3F) == 0x3E)
389 do_format_9_10 (inst);
393 while (!State.exception);
399 printf ("sim_trace\n");
407 printf ("sim_info\n");
411 sim_create_inferior (start_address, argv, env)
412 SIM_ADDR start_address;
433 /* All the code for exiting, signals, etc needs to be revamped.
435 This is enough to get c-torture limping though. */
437 sim_stop_reason (reason, sigrc)
438 enum sim_stop *reason;
442 *reason = sim_stopped;
443 if (State.exception == SIGQUIT)
446 *sigrc = State.exception;
450 sim_fetch_register (rn, memory)
452 unsigned char *memory;
454 *(uint32 *)memory = State.regs[rn];
458 sim_store_register (rn, memory)
460 unsigned char *memory;
462 State.regs[rn]= *(uint32 *)memory;
466 sim_read (addr, buffer, size)
468 unsigned char *buffer;
472 for (i = 0; i < size; i++)
474 buffer[i] = State.mem[addr + i];
483 printf("sim_do_command: %s\n",cmd);
487 sim_load (prog, from_tty)
491 /* Return nonzero so GDB will handle it. */