4 #include "remote-sim.h"
9 #define MEM_SIZE 18 /* V850 memory size is 18 bits XXX */
13 static struct hash_entry *lookup_hash PARAMS ((uint32 ins));
18 struct hash_entry *next;
24 struct hash_entry hash_table[MAX_HASH+1];
30 if ((insn & 0x30) == 0
31 || (insn & 0x38) == 0x10)
32 return (insn & 0x07e0) >> 5;
33 if ((insn & 0x3c) == 0x18
34 || (insn & 0x3c) == 0x1c
35 || (insn & 0x3c) == 0x20
36 || (insn & 0x3c) == 0x24
37 || (insn & 0x3c) == 0x28
38 || (insn & 0x3c) == 0x23)
39 return (insn & 0x07c0) >> 6;
40 if ((insn & 0x38) == 0x30)
41 return (insn & 0x07e0) >> 5;
42 /* What about sub-op field? XXX */
43 if ((insn & 0x38) == 0x38)
44 return (insn & 0x07e0) >> 5;
45 if ((insn & 0x3e) == 0x3c)
46 return (insn & 0x07c0) >> 6;
47 if ((insn & 0x3f) == 0x3e)
48 return (insn & 0xc7e0) >> 5;
49 /* Not really correct. XXX */
50 return insn & 0xffffffff;
54 static struct hash_entry *
60 h = &hash_table[hash(ins)];
62 while ( (ins & h->mask) != h->opcode)
66 printf ("ERROR looking up hash for %x\n",ins);
86 return (a[1] << 8) + (a[0]);
94 return (a[3]<<24) + (a[2]<<16) + (a[1]<<8) + (a[0]);
107 put_half (addr, data)
113 a[1] = (data >> 8) & 0xff;
117 put_word (addr, data)
123 a[1] = (data >> 8) & 0xff;
124 a[2] = (data >> 16) & 0xff;
125 a[3] = (data >> 24) & 0xff;
132 struct hash_entry *h;
133 printf("format 1 or 2 0x%x\n", insn);
135 h = lookup_hash (insn);
137 OP[1] = (insn >> 11) & 0x1f;
145 struct hash_entry *h;
146 printf("format 3 0x%x\n", insn);
148 h = lookup_hash (insn);
149 OP[0] = (((insn & 0x70) >> 4) | ((insn & 0xf800) >> 8)) << 1;
157 struct hash_entry *h;
158 printf("format 4 0x%x\n", insn);
160 h = lookup_hash (insn);
161 OP[0] = (insn >> 11) & 0x1f;
162 OP[1] = (insn & 0x7f);
170 struct hash_entry *h;
171 printf("format 5 0x%x\n", insn);
173 h = lookup_hash (insn);
174 OP[0] = ((insn & 0x3f) | (((insn >> 17) & 0x7fff) << 6)) << 1;
175 OP[1] = (insn >> 11) & 0x1f;
183 struct hash_entry *h;
184 printf("format 6 0x%x\n", insn);
186 h = lookup_hash (insn);
187 OP[0] = (insn >> 16) & 0xffff;
189 OP[2] = (insn >> 11) & 0x1f;
197 struct hash_entry *h;
198 printf("format 7 0x%x\n", insn);
200 h = lookup_hash (insn);
202 OP[1] = (insn >> 11) & 0x1f;
203 OP[2] = (insn >> 16) & 0xffff;
211 printf("format 8 0x%x\n", insn);
215 do_formats_9_10 (insn)
218 struct hash_entry *h;
219 printf("formats 9 and 10 0x%x\n", insn);
221 h = lookup_hash (insn);
223 OP[1] = (insn >> 11) & 0x1f;
237 State.mem = (uint8 *)calloc(1,1<<MEM_SIZE);
240 fprintf (stderr,"Memory allocation failed.\n");
243 printf ("Allocated %d bytes memory and\n",1<<MEM_SIZE);
254 sim_write (addr, buffer, size)
256 unsigned char *buffer;
262 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
263 for (i = 0; i < size; i++)
265 State.mem[i+addr] = buffer[i];
275 struct hash_entry *h, *prev;
277 printf ("sim_open %s\n",args);
279 /* put all the opcodes in the hash table */
280 for (s = Simops; s->func; s++)
282 h = &hash_table[hash(s->opcode)];
284 /* go to the last entry in the chain */
290 h->next = calloc(1,sizeof(struct hash_entry));
295 h->opcode = s->opcode;
311 printf ("sim_set_profile %d\n",n);
315 sim_set_profile_size (n)
318 printf ("sim_set_profile_size %d\n",n);
322 sim_resume (step, siggnal)
329 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
332 State.exception = SIGTRAP;
340 opcode = (inst & 0x07e0) >> 5;
341 if ((opcode & 0x30) == 0
342 || (opcode & 0x38) == 0x10)
344 do_format_1_2 (inst & 0xffff);
347 else if ((opcode & 0x3C) == 0x18
348 || (opcode & 0x3C) == 0x1C
349 || (opcode & 0x3C) == 0x20
350 || (opcode & 0x3C) == 0x24
351 || (opcode & 0x3C) == 0x28)
353 do_format_4 (inst & 0xffff);
356 else if ((opcode & 0x3C) == 0x23)
358 do_format_3 (inst & 0xffff);
359 /* No PC update, it's done in the instruction. */
361 else if ((opcode & 0x38) == 0x30)
366 else if ((opcode & 0x3C) == 0x38)
371 else if ((opcode & 0x3E) == 0x3C)
374 /* No PC update, it's done in the instruction. */
376 else if ((opcode & 0x3F) == 0x3E)
383 do_formats_9_10 (inst);
387 while (!State.exception);
393 printf ("sim_trace\n");
401 printf ("sim_info\n");
405 sim_create_inferior (start_address, argv, env)
406 SIM_ADDR start_address;
410 printf ("sim_create_inferior: PC=0x%x\n",start_address);
425 printf ("sim_set_callbacks\n");
430 sim_stop_reason (reason, sigrc)
431 enum sim_stop *reason;
434 /* printf ("sim_stop_reason: PC=0x%x\n",PC); */
436 if (State.exception == SIGQUIT)
438 *reason = sim_exited;
439 *sigrc = State.exception;
443 *reason = sim_stopped;
444 *sigrc = State.exception;
449 sim_fetch_register (rn, memory)
451 unsigned char *memory;
453 *(uint32 *)memory = State.regs[rn];
454 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
458 sim_store_register (rn, memory)
460 unsigned char *memory;
462 State.regs[rn]= *(uint32 *)memory;
463 /* printf ("store: r%d=0x%x\n",rn,State.regs[rn]); */
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. */