]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/d10v/interp.c
4 #include "remote-sim.h"
8 #define IMEM_SIZE 18 /* D10V instruction memory size is 18 bits */
9 #define DMEM_SIZE 16 /* Data memory */
11 enum _leftright
{ LEFT_FIRST
, RIGHT_FIRST
};
13 host_callback
*d10v_callback
;
17 static struct hash_entry
*lookup_hash
PARAMS ((uint32 ins
, int size
));
22 struct hash_entry
*next
;
28 struct hash_entry hash_table
[MAX_HASH
+1];
35 if (format
& LONG_OPCODE
)
36 return ((insn
& 0x3F000000) >> 24);
38 return((insn
& 0x7E00) >> 9);
41 static struct hash_entry
*
42 lookup_hash (ins
, size
)
49 h
= &hash_table
[(ins
& 0x3F000000) >> 24];
51 h
= &hash_table
[(ins
& 0x7E00) >> 9];
53 while ( (ins
& h
->mask
) != h
->opcode
)
57 printf ("ERROR looking up hash for %x at PC %x\n",ins
, PC
);
70 return (a
[0]<<24) + (a
[1]<<16) + (a
[2]<<8) + (a
[3]);
78 return ((int64
)a
[0]<<56) + ((int64
)a
[1]<<48) + ((int64
)a
[2]<<40) + ((int64
)a
[3]<<32) +
79 ((int64
)a
[4]<< 24) + ((int64
)a
[5]<<16) + ((int64
)a
[6]<<8) + (int64
)a
[7];
87 return ((uint16
)a
[0]<<8) + a
[1];
92 write_word (addr
, data
)
102 write_longword (addr
, data
)
106 addr
[0] = (data
>> 24) & 0xff;
107 addr
[1] = (data
>> 16) & 0xff;
108 addr
[2] = (data
>> 8) & 0xff;
109 addr
[3] = data
& 0xff;
113 write_longlong (addr
, data
)
119 a
[1] = (data
>> 48) & 0xff;
120 a
[2] = (data
>> 40) & 0xff;
121 a
[3] = (data
>> 32) & 0xff;
122 a
[4] = (data
>> 24) & 0xff;
123 a
[5] = (data
>> 16) & 0xff;
124 a
[6] = (data
>> 8) & 0xff;
129 get_operands (struct simops
*s
, uint32 ins
)
131 int i
, shift
, bits
, flags
;
133 for (i
=0; i
< s
->numops
; i
++)
135 shift
= s
->operands
[3*i
];
136 bits
= s
->operands
[3*i
+1];
137 flags
= s
->operands
[3*i
+2];
138 mask
= 0x7FFFFFFF >> (31 - bits
);
139 OP
[i
] = (ins
>> shift
) & mask
;
147 struct hash_entry
*h
;
148 /* printf ("do_long %x\n",ins); */
149 h
= lookup_hash (ins
, 1);
150 get_operands (h
->ops
, ins
);
151 State
.ins_type
= INS_LONG
;
155 do_2_short (ins1
, ins2
, leftright
)
157 enum _leftright leftright
;
159 struct hash_entry
*h
;
160 /* printf ("do_2_short %x -> %x\n",ins1,ins2); */
161 h
= lookup_hash (ins1
, 0);
162 get_operands (h
->ops
, ins1
);
163 State
.ins_type
= (leftright
== LEFT_FIRST
) ? INS_LEFT
: INS_RIGHT
;
165 h
= lookup_hash (ins2
, 0);
166 get_operands (h
->ops
, ins2
);
167 State
.ins_type
= (leftright
== LEFT_FIRST
) ? INS_RIGHT
: INS_LEFT
;
171 do_parallel (ins1
, ins2
)
174 struct hash_entry
*h1
, *h2
;
175 /* printf ("do_parallel %x || %x\n",ins1,ins2); */
176 h1
= lookup_hash (ins1
, 0);
177 h2
= lookup_hash (ins2
, 0);
179 if (h1
->ops
->exec_type
== PARONLY
)
181 get_operands (h1
->ops
, ins1
);
182 State
.ins_type
= INS_LEFT
;
186 get_operands (h2
->ops
, ins2
);
187 State
.ins_type
= INS_RIGHT
;
191 else if (h2
->ops
->exec_type
== PARONLY
)
193 get_operands (h2
->ops
, ins2
);
194 State
.ins_type
= INS_RIGHT
;
198 get_operands (h1
->ops
, ins1
);
199 State
.ins_type
= INS_LEFT
;
205 get_operands (h1
->ops
, ins1
);
206 State
.ins_type
= INS_LEFT_PARALLEL
;
208 get_operands (h2
->ops
, ins2
);
209 State
.ins_type
= INS_RIGHT_PARALLEL
;
226 State
.imem
= (uint8
*)calloc(1,1<<IMEM_SIZE
);
227 State
.dmem
= (uint8
*)calloc(1,1<<DMEM_SIZE
);
228 if (!State
.imem
|| !State
.dmem
)
230 fprintf (stderr
,"Memory allocation failed.\n");
233 #if (DEBUG & DEBUG_MEMSIZE) != 0
234 printf ("Allocated %d bytes instruction memory and\n",1<<IMEM_SIZE
);
235 printf (" %d bytes data memory.\n",1<<DMEM_SIZE
);
247 sim_write (addr
, buffer
, size
)
249 unsigned char *buffer
;
255 /* printf ("sim_write %d bytes to 0x%x\n",size,addr); */
256 for (i
= 0; i
< size
; i
++)
258 State
.imem
[i
+addr
] = buffer
[i
];
268 struct hash_entry
*h
, *prev
;
270 printf ("sim_open %s\n",args
);
272 /* put all the opcodes in the hash table */
273 for (s
= Simops
; s
->func
; s
++)
275 h
= &hash_table
[hash(s
->opcode
,s
->format
)];
277 /* go to the last entry in the chain */
283 h
->next
= calloc(1,sizeof(struct hash_entry
));
288 h
->opcode
= s
->opcode
;
304 printf ("sim_set_profile %d\n",n
);
308 sim_set_profile_size (n
)
311 printf ("sim_set_profile_size %d\n",n
);
315 sim_resume (step
, siggnal
)
322 /* printf ("sim_resume (%d,%d) PC=0x%x\n",step,siggnal,PC); */
325 State
.exception
= SIGTRAP
;
331 inst
= RLW (PC
<< 2);
333 switch (inst
& 0xC0000000)
336 /* long instruction */
337 do_long (inst
& 0x3FFFFFFF);
341 do_2_short ( inst
& 0x7FFF, (inst
& 0x3FFF8000) >> 15, 0);
345 do_2_short ((inst
& 0x3FFF8000) >> 15, inst
& 0x7FFF, 1);
348 do_parallel ((inst
& 0x3FFF8000) >> 15, inst
& 0x7FFF);
352 if (State
.RP
&& PC
== RPT_E
)
365 while (!State
.exception
);
371 printf ("sim_trace\n");
379 printf ("sim_info\n");
383 sim_create_inferior (start_address
, argv
, env
)
384 SIM_ADDR start_address
;
388 printf ("sim_create_inferior: PC=0x%x\n",start_address
);
389 PC
= start_address
>> 2;
403 /* printf ("sim_set_callbacks\n"); */
408 sim_stop_reason (reason
, sigrc
)
409 enum sim_stop
*reason
;
412 /* printf ("sim_stop_reason: PC=0x%x\n",PC<<2); */
414 if (State
.exception
== SIGQUIT
)
416 *reason
= sim_exited
;
417 *sigrc
= State
.exception
;
421 *reason
= sim_stopped
;
422 *sigrc
= State
.exception
;
427 sim_fetch_register (rn
, memory
)
429 unsigned char *memory
;
433 WRITE_64 (memory
, State
.a
[rn
-32]);
434 /* printf ("sim_fetch_register %d 0x%llx\n",rn,State.a[rn-32]); */
438 WRITE_16 (memory
, State
.regs
[rn
]);
439 /* printf ("sim_fetch_register %d 0x%x\n",rn,State.regs[rn]); */
444 sim_store_register (rn
, memory
)
446 unsigned char *memory
;
450 State
.a
[rn
-32] = READ_64 (memory
) & MASK40
;
451 /* printf ("store: a%d=0x%llx\n",rn-32,State.a[rn-32]); */
455 State
.regs
[rn
]= READ_16 (memory
);
456 /* 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
.imem
[addr
+ i
];
477 printf("sim_do_command: %s\n",cmd
);
481 sim_load (prog
, from_tty
)
485 /* Return nonzero so GDB will handle it. */