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 printf("format 4 0x%x\n", insn);
164 struct hash_entry *h;
165 printf("format 5 0x%x\n", insn);
167 h = lookup_hash (insn);
168 OP[0] = ((insn & 0x3f) | (((insn >> 17) & 0x7fff) << 6)) << 1;
169 OP[1] = (insn >> 11) & 0x1f;
177 struct hash_entry *h;
178 printf("format 6 0x%x\n", insn);
180 h = lookup_hash (insn);
181 OP[0] = (insn >> 16) & 0xffff;
183 OP[2] = (insn >> 11) & 0x1f;
191 struct hash_entry *h;
192 printf("format 7 0x%x\n", insn);
194 h = lookup_hash (insn);
196 OP[1] = (insn >> 11) & 0x1f;
197 OP[2] = (insn >> 16) & 0xffff;
205 printf("format 8 0x%x\n", insn);
209 do_formats_9_10 (insn)
212 struct hash_entry *h;
213 printf("formats 9 and 10 0x%x\n", insn);
215 h = lookup_hash (insn);
217 OP[1] = (insn >> 11) & 0x1f;
231 State.mem = (uint8 *)calloc(1,1<<MEM_SIZE);
234 fprintf (stderr,"Memory allocation failed.\n");
237 printf ("Allocated %d bytes memory and\n",1<<MEM_SIZE);
248 sim_write (addr, buffer, size)
250 unsigned char *buffer;
256 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
257 for (i = 0; i < size; i++)
259 State.mem[i+addr] = buffer[i];
269 struct hash_entry *h, *prev;
271 printf ("sim_open %s\n",args);
273 /* put all the opcodes in the hash table */
274 for (s = Simops; s->func; s++)
276 h = &hash_table[hash(s->opcode)];
278 /* go to the last entry in the chain */
284 h->next = calloc(1,sizeof(struct hash_entry));
289 h->opcode = s->opcode;
305 printf ("sim_set_profile %d\n",n);
309 sim_set_profile_size (n)
312 printf ("sim_set_profile_size %d\n",n);
316 sim_resume (step, siggnal)
323 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
326 State.exception = SIGTRAP;
334 opcode = (inst & 0x07e0) >> 5;
335 if ((opcode & 0x30) == 0
336 || (opcode & 0x38) == 0x10)
338 do_format_1_2 (inst & 0xffff);
341 else if ((opcode & 0x3C) == 0x18
342 || (opcode & 0x3C) == 0x1C
343 || (opcode & 0x3C) == 0x20
344 || (opcode & 0x3C) == 0x24
345 || (opcode & 0x3C) == 0x28)
347 do_format_4 (inst & 0xffff);
350 else if ((opcode & 0x3C) == 0x23)
352 do_format_3 (inst & 0xffff);
353 /* No PC update, it's done in the instruction. */
355 else if ((opcode & 0x38) == 0x30)
360 else if ((opcode & 0x3C) == 0x38)
365 else if ((opcode & 0x3E) == 0x3C)
368 /* No PC update, it's done in the instruction. */
370 else if ((opcode & 0x3F) == 0x3E)
377 do_formats_9_10 (inst);
381 while (!State.exception);
387 printf ("sim_trace\n");
395 printf ("sim_info\n");
399 sim_create_inferior (start_address, argv, env)
400 SIM_ADDR start_address;
404 printf ("sim_create_inferior: PC=0x%x\n",start_address);
419 printf ("sim_set_callbacks\n");
424 sim_stop_reason (reason, sigrc)
425 enum sim_stop *reason;
428 /* printf ("sim_stop_reason: PC=0x%x\n",PC); */
430 if (State.exception == SIGQUIT)
432 *reason = sim_exited;
433 *sigrc = State.exception;
437 *reason = sim_stopped;
438 *sigrc = State.exception;
443 sim_fetch_register (rn, memory)
445 unsigned char *memory;
447 *(uint32 *)memory = State.regs[rn];
448 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
452 sim_store_register (rn, memory)
454 unsigned char *memory;
456 State.regs[rn]= *(uint32 *)memory;
457 /* printf ("store: r%d=0x%x\n",rn,State.regs[rn]); */
460 sim_read (addr, buffer, size)
462 unsigned char *buffer;
466 for (i = 0; i < size; i++)
468 buffer[i] = State.mem[addr + i];
477 printf("sim_do_command: %s\n",cmd);
481 sim_load (prog, from_tty)
485 /* Return nonzero so GDB will handle it. */