20cbdbe99cc05b9a66eebbabf4042d6d3f9ddc6d
4 #include "remote-sim.h"
9 #define IMEM_SIZE 18 /* D10V instruction memory size is 18 bits */
10 #define DMEM_SIZE 16 /* Data memory */
14 static struct hash_entry
*lookup_hash
PARAMS ((uint32 ins
, int size
));
19 struct hash_entry
*next
;
25 struct hash_entry hash_table
[MAX_HASH
+1];
32 if (format
& LONG_OPCODE
)
33 return ((insn
& 0x3F000000) >> 24);
35 return((insn
& 0x7E00) >> 9);
38 static struct hash_entry
*
39 lookup_hash (ins
, size
)
46 h
= &hash_table
[(ins
& 0x3F000000) >> 24];
48 h
= &hash_table
[(ins
& 0x7E00) >> 9];
50 while ( (ins
& h
->mask
) != h
->opcode
)
54 printf ("ERROR looking up hash for %x\n",ins
);
67 return (a
[0]<<24) + (a
[1]<<16) + (a
[2]<<8) + (a
[3]);
75 return ((int64
)a
[0]<<56) + ((int64
)a
[1]<<48) + ((int64
)a
[2]<<40) + ((int64
)a
[3]<<32) +
76 ((int64
)a
[4]<< 24) + ((int64
)a
[5]<<16) + ((int64
)a
[6]<<8) + (int64
)a
[7];
84 return ((uint16
)a
[0]<<8) + a
[1];
88 write_word (addr
, data
)
98 write_longlong (addr
, data
)
104 a
[1] = (data
>> 48) & 0xff;
105 a
[2] = (data
>> 40) & 0xff;
106 a
[3] = (data
>> 32) & 0xff;
107 a
[4] = (data
>> 24) & 0xff;
108 a
[5] = (data
>> 16) & 0xff;
109 a
[6] = (data
>> 8) & 0xff;
115 get_operands (struct simops
*s
, uint32 ins
)
117 int i
, shift
, bits
, flags
;
119 for (i
=0; i
< s
->numops
; i
++)
121 shift
= s
->operands
[3*i
];
122 bits
= s
->operands
[3*i
+1];
123 flags
= s
->operands
[3*i
+2];
124 mask
= 0x7FFFFFFF >> (31 - bits
);
125 OP
[i
] = (ins
>> shift
) & mask
;
133 struct hash_entry
*h
;
134 /* printf ("do_long %x\n",ins); */
135 h
= lookup_hash (ins
, 1);
136 get_operands (h
->ops
, ins
);
140 do_2_short (ins1
, ins2
)
143 struct hash_entry
*h
;
144 /* printf ("do_2_short %x -> %x\n",ins1,ins2); */
145 h
= lookup_hash (ins1
, 0);
146 get_operands (h
->ops
, ins1
);
148 h
= lookup_hash (ins2
, 0);
149 get_operands (h
->ops
, ins2
);
153 do_parallel (ins1
, ins2
)
156 struct hash_entry
*h1
, *h2
;
157 /* printf ("do_parallel %x || %x\n",ins1,ins2); */
158 h1
= lookup_hash (ins1
, 0);
159 h2
= lookup_hash (ins2
, 0);
161 if (h1
->ops
->exec_type
== PARONLY
)
163 get_operands (h1
->ops
, ins1
);
167 get_operands (h2
->ops
, ins2
);
171 else if (h2
->ops
->exec_type
== PARONLY
)
173 get_operands (h2
->ops
, ins2
);
177 get_operands (h1
->ops
, ins1
);
183 get_operands (h1
->ops
, ins1
);
185 get_operands (h2
->ops
, ins2
);
202 State
.imem
= (uint8
*)calloc(1,1<<IMEM_SIZE
);
203 State
.dmem
= (uint8
*)calloc(1,1<<DMEM_SIZE
);
204 if (!State
.imem
|| !State
.dmem
)
206 fprintf (stderr
,"Memory allocation failed.\n");
209 printf ("Allocated %d bytes instruction memory and\n",1<<IMEM_SIZE
);
210 printf (" %d bytes data memory.\n",1<<DMEM_SIZE
);
221 sim_write (addr
, buffer
, size
)
223 unsigned char *buffer
;
229 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
230 for (i
= 0; i
< size
; i
++)
232 State
.imem
[i
+addr
] = buffer
[i
];
242 struct hash_entry
*h
, *prev
;
244 printf ("sim_open %s\n",args
);
246 /* put all the opcodes in the hash table */
247 for (s
= Simops
; s
->func
; s
++)
249 h
= &hash_table
[hash(s
->opcode
,s
->format
)];
251 /* go to the last entry in the chain */
257 h
->next
= calloc(1,sizeof(struct hash_entry
));
262 h
->opcode
= s
->opcode
;
278 printf ("sim_set_profile %d\n",n
);
282 sim_set_profile_size (n
)
285 printf ("sim_set_profile_size %d\n",n
);
289 sim_resume (step
, siggnal
)
296 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
299 State
.exception
= SIGTRAP
;
305 inst
= RLW (PC
<< 2);
307 switch (inst
& 0xC0000000)
310 /* long instruction */
311 do_long (inst
& 0x3FFFFFFF);
315 do_2_short ( inst
& 0x7FFF, (inst
& 0x3FFF8000) >> 15);
319 do_2_short ((inst
& 0x3FFF8000) >> 15, inst
& 0x7FFF);
322 do_parallel ((inst
& 0x3FFF8000) >> 15, inst
& 0x7FFF);
326 if (State
.RP
&& PC
== RPT_E
)
339 while (!State
.exception
);
345 printf ("sim_trace\n");
353 printf ("sim_info\n");
357 sim_create_inferior (start_address
, argv
, env
)
358 SIM_ADDR start_address
;
362 printf ("sim_create_inferior: PC=0x%x\n",start_address
);
363 PC
= start_address
>> 2;
377 printf ("sim_set_callbacks\n");
382 sim_stop_reason (reason
, sigrc
)
383 enum sim_stop
*reason
;
386 /* printf ("sim_stop_reason: PC=0x%x\n",PC<<2); */
388 if (State
.exception
== SIGQUIT
)
390 *reason
= sim_exited
;
391 *sigrc
= State
.exception
;
395 *reason
= sim_stopped
;
396 *sigrc
= State
.exception
;
401 sim_fetch_register (rn
, memory
)
403 unsigned char *memory
;
407 WRITE_64 (memory
, State
.a
[rn
-32]);
408 /* printf ("sim_fetch_register %d 0x%llx\n",rn,State.a[rn-32]); */
412 WRITE_16 (memory
, State
.regs
[rn
]);
413 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
418 sim_store_register (rn
, memory
)
420 unsigned char *memory
;
424 State
.a
[rn
-32] = READ_64 (memory
) & MASK40
;
425 /* printf ("store: a%d=0x%llx\n",rn-32,State.a[rn-32]); */
429 State
.regs
[rn
]= READ_16 (memory
);
430 /* printf ("store: r%d=0x%x\n",rn,State.regs[rn]); */
434 sim_read (addr
, buffer
, size
)
436 unsigned char *buffer
;
440 for (i
= 0; i
< size
; i
++)
442 buffer
[i
] = State
.imem
[addr
+ i
];
451 printf("sim_do_command: %s\n",cmd
);
455 sim_load (prog
, from_tty
)
459 /* Return nonzero so GDB will handle it. */
This page took 0.037801 seconds and 4 git commands to generate.