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
& 0x0600) == 0
31 || (insn
& 0x0700) == 0x0200)
32 return (insn
& 0x07e0) >> 5;
33 if ((insn
& 0x0700) == 0x0300
34 || (insn
& 0x0700) == 0x0400
35 || (insn
& 0x0700) == 0x0500)
36 return (insn
& 0x0780) >> 7;
37 if ((insn
& 0x0700) == 0x0600)
38 return (insn
& 0x07e0) >> 5;
39 if ((insn
& 0x0780) == 0x0700)
40 return (insn
& 0x07e0) >> 5;
41 if ((insn
& 0x07c0) == 0x0780)
42 return (insn
& 0x07c0) >> 6;
43 if ((insn
& 0x07E0) == 0x07C0)
44 return (insn
& 0x07e0) >> 5;
45 return (insn
& 0x07e0) >> 5;
48 static struct hash_entry
*
54 h
= &hash_table
[hash(ins
)];
56 while ( (ins
& h
->mask
) != h
->opcode
)
60 printf ("ERROR looking up hash for %x\n",ins
);
80 return (a
[1] << 8) + (a
[0]);
88 return (a
[3]<<24) + (a
[2]<<16) + (a
[1]<<8) + (a
[0]);
101 put_half (addr
, data
)
107 a
[1] = (data
>> 8) & 0xff;
111 put_word (addr
, data
)
117 a
[1] = (data
>> 8) & 0xff;
118 a
[2] = (data
>> 16) & 0xff;
119 a
[3] = (data
>> 24) & 0xff;
126 struct hash_entry
*h
;
127 printf("format 1 or 2 0x%x\n", insn
);
129 h
= lookup_hash (insn
);
131 OP
[1] = (insn
>> 11) & 0x1f;
139 struct hash_entry
*h
;
140 printf("format 3 0x%x\n", insn
);
142 h
= lookup_hash (insn
);
143 OP
[0] = (((insn
& 0x70) >> 4) | ((insn
& 0xf800) >> 8)) << 1;
151 struct hash_entry
*h
;
152 printf("format 4 0x%x\n", insn
);
154 h
= lookup_hash (insn
);
155 OP
[0] = (insn
>> 11) & 0x1f;
156 OP
[1] = (insn
& 0x7f);
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 struct hash_entry
*h
;
206 printf("format 8 0x%x\n", insn
);
208 h
= lookup_hash (insn
);
210 OP
[1] = (insn
>> 11) & 0x7;
211 OP
[2] = (insn
>> 16) & 0xffff;
216 do_formats_9_10 (insn
)
219 struct hash_entry
*h
;
220 printf("formats 9 and 10 0x%x\n", insn
);
222 h
= lookup_hash (insn
);
224 OP
[1] = (insn
>> 11) & 0x1f;
238 State
.mem
= (uint8
*)calloc(1,1<<MEM_SIZE
);
241 fprintf (stderr
,"Memory allocation failed.\n");
244 printf ("Allocated %d bytes memory and\n",1<<MEM_SIZE
);
255 sim_write (addr
, buffer
, size
)
257 unsigned char *buffer
;
263 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
264 for (i
= 0; i
< size
; i
++)
266 State
.mem
[i
+addr
] = buffer
[i
];
276 struct hash_entry
*h
, *prev
;
278 printf ("sim_open %s\n",args
);
280 /* put all the opcodes in the hash table */
281 for (s
= Simops
; s
->func
; s
++)
283 h
= &hash_table
[hash(s
->opcode
)];
285 /* go to the last entry in the chain */
291 h
->next
= calloc(1,sizeof(struct hash_entry
));
296 h
->opcode
= s
->opcode
;
312 printf ("sim_set_profile %d\n",n
);
316 sim_set_profile_size (n
)
319 printf ("sim_set_profile_size %d\n",n
);
323 sim_resume (step
, siggnal
)
330 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
333 State
.exception
= SIGTRAP
;
341 opcode
= (inst
& 0x07e0) >> 5;
342 if ((opcode
& 0x30) == 0
343 || (opcode
& 0x38) == 0x10)
345 do_format_1_2 (inst
& 0xffff);
348 else if ((opcode
& 0x3C) == 0x18
349 || (opcode
& 0x3C) == 0x1C
350 || (opcode
& 0x3C) == 0x20
351 || (opcode
& 0x3C) == 0x24
352 || (opcode
& 0x3C) == 0x28)
354 do_format_4 (inst
& 0xffff);
357 else if ((opcode
& 0x3C) == 0x23)
359 do_format_3 (inst
& 0xffff);
360 /* No PC update, it's done in the instruction. */
362 else if ((opcode
& 0x38) == 0x30)
367 else if ((opcode
& 0x3C) == 0x38)
372 else if ((opcode
& 0x3E) == 0x3C)
375 /* No PC update, it's done in the instruction. */
377 else if ((opcode
& 0x3F) == 0x3E)
384 do_formats_9_10 (inst
);
388 while (!State
.exception
);
394 printf ("sim_trace\n");
402 printf ("sim_info\n");
406 sim_create_inferior (start_address
, argv
, env
)
407 SIM_ADDR start_address
;
411 printf ("sim_create_inferior: PC=0x%x\n",start_address
);
426 printf ("sim_set_callbacks\n");
431 sim_stop_reason (reason
, sigrc
)
432 enum sim_stop
*reason
;
435 /* printf ("sim_stop_reason: PC=0x%x\n",PC); */
437 if (State
.exception
== SIGQUIT
)
439 *reason
= sim_exited
;
440 *sigrc
= State
.exception
;
444 *reason
= sim_stopped
;
445 *sigrc
= State
.exception
;
450 sim_fetch_register (rn
, memory
)
452 unsigned char *memory
;
454 *(uint32
*)memory
= State
.regs
[rn
];
455 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
459 sim_store_register (rn
, memory
)
461 unsigned char *memory
;
463 State
.regs
[rn
]= *(uint32
*)memory
;
464 /* printf ("store: r%d=0x%x\n",rn,State.regs[rn]); */
467 sim_read (addr
, buffer
, size
)
469 unsigned char *buffer
;
473 for (i
= 0; i
< size
; i
++)
475 buffer
[i
] = State
.mem
[addr
+ i
];
484 printf("sim_do_command: %s\n",cmd
);
488 sim_load (prog
, from_tty
)
492 /* Return nonzero so GDB will handle it. */