4 #include "remote-sim.h"
9 #define IMEM_SIZE 18 /* V850 instruction memory size is 18 bits */
10 #define DMEM_SIZE 16 /* Data memory */
14 static struct hash_entry
*lookup_hash
PARAMS ((uint32 ins
));
19 struct hash_entry
*next
;
25 struct hash_entry hash_table
[MAX_HASH
+1];
31 if ((insn
& 0x30) == 0
32 || (insn
& 0x38) == 0x10)
33 return (insn
& 0x07e0) >> 5;
34 if ((insn
& 0x3c) == 0x18
35 || (insn
& 0x3c) == 0x1c
36 || (insn
& 0x3c) == 0x20
37 || (insn
& 0x3c) == 0x24
38 || (insn
& 0x3c) == 0x28
39 || (insn
& 0x3c) == 0x23)
40 return (insn
& 0x07c0) >> 6;
41 if ((insn
& 0x38) == 0x30)
42 return (insn
& 0x07e0) >> 5;
43 /* What about sub-op field? XXX */
44 if ((insn
& 0x38) == 0x38)
45 return (insn
& 0x07e0) >> 5;
46 if ((insn
& 0x3e) == 0x3c)
47 return (insn
& 0x07c0) >> 6;
48 if ((insn
& 0x3f) == 0x3e)
49 return (insn
& 0xc7e0) >> 5;
50 /* Not really correct. XXX */
51 return insn
& 0xffffffff;
55 static struct hash_entry
*
61 h
= &hash_table
[hash(ins
)];
63 while ( (ins
& h
->mask
) != h
->opcode
)
67 printf ("ERROR looking up hash for %x\n",ins
);
80 return (a
[3]<<24) + (a
[2]<<16) + (a
[1]<<8) + (a
[0]);
88 return ((int64
)a
[0]<<56) + ((int64
)a
[1]<<48) + ((int64
)a
[2]<<40) + ((int64
)a
[3]<<32) +
89 ((int64
)a
[4]<< 24) + ((int64
)a
[5]<<16) + ((int64
)a
[6]<<8) + (int64
)a
[7];
97 return ((uint16
)a
[0]<<8) + a
[1];
102 write_word (addr
, data
)
112 write_longword (addr
, data
)
116 addr
[0] = (data
>> 24) & 0xff;
117 addr
[1] = (data
>> 16) & 0xff;
118 addr
[2] = (data
>> 8) & 0xff;
119 addr
[3] = data
& 0xff;
123 write_longlong (addr
, data
)
129 a
[1] = (data
>> 48) & 0xff;
130 a
[2] = (data
>> 40) & 0xff;
131 a
[3] = (data
>> 32) & 0xff;
132 a
[4] = (data
>> 24) & 0xff;
133 a
[5] = (data
>> 16) & 0xff;
134 a
[6] = (data
>> 8) & 0xff;
139 get_operands (struct simops
*s
, uint32 ins
)
141 int i
, shift
, bits
, flags
;
143 for (i
=0; i
< s
->numops
; i
++)
145 shift
= s
->operands
[3*i
];
146 bits
= s
->operands
[3*i
+1];
147 flags
= s
->operands
[3*i
+2];
148 mask
= 0x7FFFFFFF >> (31 - bits
);
149 OP
[i
] = (ins
>> shift
) & mask
;
157 struct hash_entry
*h
;
158 printf("format 1 or 2 0x%x\n", insn
);
160 h
= lookup_hash (insn
);
162 OP
[1] = (insn
>> 11) & 0x1f;
170 struct hash_entry
*h
;
171 printf("format 3 0x%x\n", insn
);
173 h
= lookup_hash (insn
);
174 OP
[0] = (((insn
& 0x70) >> 4) | ((insn
& 0xf800) >> 8)) << 1;
182 printf("format 4 0x%x\n", insn
);
189 printf("format 5 0x%x\n", insn
);
196 struct hash_entry
*h
;
197 printf("format 6 0x%x\n", insn
);
199 h
= lookup_hash (insn
);
200 OP
[0] = (insn
>> 16) & 0xffff;
202 OP
[2] = (insn
>> 11) & 0x1f;
210 printf("format 7 0x%x\n", insn
);
217 printf("format 8 0x%x\n", insn
);
221 do_formats_9_10 (insn
)
224 struct hash_entry
*h
;
225 printf("formats 9 and 10 0x%x\n", insn
);
227 h
= lookup_hash (insn
);
229 OP
[1] = (insn
>> 11) & 0x1f;
244 State
.imem
= (uint8
*)calloc(1,1<<IMEM_SIZE
);
245 State
.dmem
= (uint8
*)calloc(1,1<<DMEM_SIZE
);
246 if (!State
.imem
|| !State
.dmem
)
248 fprintf (stderr
,"Memory allocation failed.\n");
251 printf ("Allocated %d bytes instruction memory and\n",1<<IMEM_SIZE
);
252 printf (" %d bytes data memory.\n",1<<DMEM_SIZE
);
263 sim_write (addr
, buffer
, size
)
265 unsigned char *buffer
;
271 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
272 for (i
= 0; i
< size
; i
++)
274 State
.imem
[i
+addr
] = buffer
[i
];
284 struct hash_entry
*h
, *prev
;
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 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
341 State
.exception
= SIGTRAP
;
349 opcode
= (inst
& 0x07e0) >> 5;
350 if ((opcode
& 0x30) == 0
351 || (opcode
& 0x38) == 0x10)
353 do_format_1_2 (inst
& 0xffff);
356 else if ((opcode
& 0x3C) == 0x18
357 || (opcode
& 0x3C) == 0x1C
358 || (opcode
& 0x3C) == 0x20
359 || (opcode
& 0x3C) == 0x24
360 || (opcode
& 0x3C) == 0x28)
362 do_format_4 (inst
& 0xffff);
365 else if ((opcode
& 0x3C) == 0x23)
367 do_format_3 (inst
& 0xffff);
368 /* No PC update, it's done in the instruction. */
370 else if ((opcode
& 0x38) == 0x30)
375 else if ((opcode
& 0x3C) == 0x38)
380 else if ((opcode
& 0x3E) == 0x3C)
385 else if ((opcode
& 0x3F) == 0x3E)
392 do_formats_9_10 (inst
);
396 while (!State
.exception
);
402 printf ("sim_trace\n");
410 printf ("sim_info\n");
414 sim_create_inferior (start_address
, argv
, env
)
415 SIM_ADDR start_address
;
419 printf ("sim_create_inferior: PC=0x%x\n",start_address
);
434 printf ("sim_set_callbacks\n");
439 sim_stop_reason (reason
, sigrc
)
440 enum sim_stop
*reason
;
443 /* printf ("sim_stop_reason: PC=0x%x\n",PC); */
445 if (State
.exception
== SIGQUIT
)
447 *reason
= sim_exited
;
448 *sigrc
= State
.exception
;
452 *reason
= sim_stopped
;
453 *sigrc
= State
.exception
;
458 sim_fetch_register (rn
, memory
)
460 unsigned char *memory
;
462 *(uint32
*)memory
= State
.regs
[rn
];
463 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
467 sim_store_register (rn
, memory
)
469 unsigned char *memory
;
471 State
.regs
[rn
]= *(uint32
*)memory
;
472 /* printf ("store: r%d=0x%x\n",rn,State.regs[rn]); */
475 sim_read (addr
, buffer
, size
)
477 unsigned char *buffer
;
481 for (i
= 0; i
< size
; i
++)
483 buffer
[i
] = State
.imem
[addr
+ i
];
492 printf("sim_do_command: %s\n",cmd
);
496 sim_load (prog
, from_tty
)
500 /* Return nonzero so GDB will handle it. */