5 #include "mn10200_sim.h"
7 #ifdef NEED_UI_LOOP_HOOK
8 /* How often to run the ui_loop update, when in use */
9 #define UI_LOOP_POLL_INTERVAL 0x60000
11 /* Counter for the ui_loop_hook update */
12 static long ui_loop_hook_counter
= UI_LOOP_POLL_INTERVAL
;
14 /* Actual hook to call to run through gdb's gui event loop */
15 extern int (*deprecated_ui_loop_hook
) (int);
16 #endif /* NEED_UI_LOOP_HOOK */
18 host_callback
*mn10200_callback
;
20 static SIM_OPEN_KIND sim_kind
;
23 static void dispatch
PARAMS ((uint32
, uint32
, int));
24 static long hash
PARAMS ((long));
25 static void init_system
PARAMS ((void));
30 struct hash_entry
*next
;
40 struct hash_entry hash_table
[MAX_HASH
+1];
43 /* This probably doesn't do a very good job at bucket filling, but
49 /* These are one byte insns. */
50 if ((insn
& 0xffffff00) == 0x00)
52 if ((insn
& 0xf0) != 0x80)
53 return ((insn
& 0xf0) >> 4) & 0x7f;
55 if ((insn
& 0xf0) == 0x80
56 && (insn
& 0x0c) >> 2 != (insn
& 0x03))
57 return (insn
& 0xf0) & 0x7f;
59 return (insn
& 0xff) & 0x7f;
62 if ((insn
& 0xffff0000) == 0)
64 if ((insn
& 0xf000) == 0xd000)
65 return ((insn
& 0xfc00) >> 10) & 0x7f;
67 if ((insn
& 0xf000) == 0xe000)
68 return ((insn
& 0xff00) >> 8) & 0x7f;
70 if ((insn
& 0xf200) == 0xf200)
71 return ((insn
& 0xfff0) >> 4) & 0x7f;
73 if ((insn
& 0xc000) == 0x4000
74 || (insn
& 0xf000) == 0x8000)
75 return ((insn
& 0xf000) >> 8) & 0x7f;
77 if ((insn
& 0xf200) == 0xf000)
78 return ((insn
& 0xffc0) >> 8) & 0x7f;
80 return ((insn
& 0xff00) >> 8) & 0x7f;
83 if ((insn
& 0xff000000) == 0)
86 if ((insn
& 0xf00000) != 0xf00000
87 || (insn
& 0xfc0000) == 0xf80000)
88 return ((insn
& 0xfc0000) >> 16) & 0x7f;
90 if ((insn
& 0xff0000) == 0xf50000)
91 return ((insn
& 0xfff000) >> 12) & 0x7f;
92 return ((insn
& 0xff0000) >> 16) & 0x7f;
95 return ((insn
& 0xfff0000) >> 20) & 0x7f;
99 dispatch (insn
, extension
, length
)
104 struct hash_entry
*h
;
106 h
= &hash_table
[hash(insn
)];
108 while ((insn
& h
->mask
) != h
->opcode
109 || (length
!= h
->ops
->length
))
113 (*mn10200_callback
->printf_filtered
) (mn10200_callback
,
114 "ERROR looking up hash for 0x%x, PC=0x%x\n", insn
, PC
);
125 /* Now call the right function. */
126 (h
->ops
->func
)(insn
, extension
);
130 /* FIXME These would more efficient to use than load_mem/store_mem,
131 but need to be changed to use the memory map. */
138 return (a
[3]<<24) + (a
[2]<<16) + (a
[1]<<8) + (a
[0]);
142 put_word (addr
, data
)
148 a
[1] = (data
>> 8) & 0xff;
149 a
[2] = (data
>> 16) & 0xff;
150 a
[3] = (data
>> 24) & 0xff;
161 max_mem
= 1 << power
;
162 State
.mem
= (uint8
*) calloc (1, 1 << power
);
165 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "Allocation of main memory failed.\n");
178 sim_write (sd
,addr
, buffer
, size
)
181 unsigned char *buffer
;
188 for (i
= 0; i
< size
; i
++)
189 store_byte (addr
+ i
, buffer
[i
]);
194 /* Compare two opcode table entries for qsort. */
196 compare_simops (arg1
, arg2
)
200 unsigned long code1
= ((struct simops
*)arg1
)->opcode
;
201 unsigned long code2
= ((struct simops
*)arg2
)->opcode
;
211 sim_open (kind
, cb
, abfd
, argv
)
218 struct hash_entry
*h
;
222 mn10200_callback
= cb
;
224 /* Sort the opcode array from smallest opcode to largest.
225 This will generally improve simulator performance as the smaller
226 opcodes are generally preferred to the larger opcodes. */
227 for (i
= 0, s
= Simops
; s
->func
; s
++, i
++)
229 qsort (Simops
, i
, sizeof (Simops
[0]), compare_simops
);
234 for (p
= argv
+ 1; *p
; ++p
)
236 if (strcmp (*p
, "-E") == 0)
237 ++p
; /* ignore endian spec */
240 if (strcmp (*p
, "-t") == 0)
241 mn10200_debug
= DEBUG
;
244 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "ERROR: unsupported option(s): %s\n",*p
);
247 /* put all the opcodes in the hash table */
248 for (s
= Simops
; s
->func
; s
++)
250 h
= &hash_table
[hash(s
->opcode
)];
252 /* go to the last entry in the chain */
255 /* Don't insert the same opcode more than once. */
256 if (h
->opcode
== s
->opcode
257 && h
->mask
== s
->mask
264 /* Don't insert the same opcode more than once. */
265 if (h
->opcode
== s
->opcode
266 && h
->mask
== s
->mask
272 h
->next
= calloc(1,sizeof(struct hash_entry
));
277 h
->opcode
= s
->opcode
;
283 /* fudge our descriptor for now */
292 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "sim_set_profile %d\n", n
);
296 sim_set_profile_size (n
)
299 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "sim_set_profile_size %d\n", n
);
306 State
.exception
= SIGINT
;
311 sim_resume (sd
, step
, siggnal
)
318 State
.exception
= SIGTRAP
;
326 unsigned long insn
, extension
;
328 #ifdef NEED_UI_LOOP_HOOK
329 if (deprecated_ui_loop_hook
!= NULL
&& ui_loop_hook_counter
-- < 0)
331 ui_loop_hook_counter
= UI_LOOP_POLL_INTERVAL
;
332 deprecated_ui_loop_hook (0);
334 #endif /* NEED_UI_LOOP_HOOK */
336 /* Fetch the current instruction, fetch a double word to
337 avoid redundant fetching for the common cases below. */
338 inst
= load_mem_big (PC
, 2);
340 /* Using a giant case statement may seem like a waste because of the
341 code/rodata size the table itself will consume. However, using
342 a giant case statement speeds up the simulator by 10-15% by avoiding
343 cascading if/else statements or cascading case statements. */
344 switch ((inst
>> 8) & 0xff)
346 /* All the single byte insns except 0x80, which must
347 be handled specially. */
464 insn
= (inst
>> 8) & 0xff;
466 dispatch (insn
, extension
, 1);
469 /* Special case as mov dX,dX really means mov imm8,dX. */
474 /* Fetch the full instruction. */
477 dispatch (insn
, extension
, 2);
492 insn
= (inst
>> 8) & 0xff;
494 dispatch (insn
, extension
, 1);
497 /* And the two byte insns. */
589 /* Fetch the full instruction. */
592 dispatch (insn
, extension
, 2);
595 /* And the 3 byte insns with a 16bit operand in little
627 insn
= load_byte (PC
);
629 insn
|= load_half (PC
+ 1);
631 dispatch (insn
, extension
, 3);
634 /* 3 byte insns without 16bit operand. */
636 insn
= load_mem_big (PC
, 3);
638 dispatch (insn
, extension
, 3);
645 insn
|= load_half (PC
+ 2);
647 dispatch (insn
, extension
, 4);
653 insn
|= load_mem_big (PC
+ 4, 1) << 8;
654 insn
|= load_mem_big (PC
+ 3, 1);
655 extension
= load_mem_big (PC
+ 2, 1);
656 dispatch (insn
, extension
, 5);
663 while (!State
.exception
);
668 for (i
= 0; i
< MAX_HASH
; i
++)
670 struct hash_entry
*h
;
673 printf("hash 0x%x:\n", i
);
677 printf("h->opcode = 0x%x, count = 0x%x\n", h
->opcode
, h
->count
);
691 sim_close (sd
, quitting
)
703 mn10200_debug
= DEBUG
;
705 sim_resume (sd
, 0, 0);
710 sim_info (sd
, verbose
)
714 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "sim_info\n");
718 sim_create_inferior (sd
, abfd
, argv
, env
)
725 PC
= bfd_get_start_address (abfd
);
732 sim_set_callbacks (p
)
735 mn10200_callback
= p
;
738 /* All the code for exiting, signals, etc needs to be revamped.
740 This is enough to get c-torture limping though. */
743 sim_stop_reason (sd
, reason
, sigrc
)
745 enum sim_stop
*reason
;
749 *reason
= sim_exited
;
751 *reason
= sim_stopped
;
752 if (State
.exception
== SIGQUIT
)
755 *sigrc
= State
.exception
;
759 sim_fetch_register (sd
, rn
, memory
, length
)
762 unsigned char *memory
;
765 put_word (memory
, State
.regs
[rn
]);
770 sim_store_register (sd
, rn
, memory
, length
)
773 unsigned char *memory
;
776 State
.regs
[rn
] = get_word (memory
);
781 sim_read (sd
, addr
, buffer
, size
)
784 unsigned char *buffer
;
788 for (i
= 0; i
< size
; i
++)
789 buffer
[i
] = load_byte (addr
+ i
);
795 sim_do_command (sd
, cmd
)
799 (*mn10200_callback
->printf_filtered
) (mn10200_callback
, "\"%s\" is not a valid mn10200 simulator command.\n", cmd
);
803 sim_load (sd
, prog
, abfd
, from_tty
)
809 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
812 prog_bfd
= sim_load_file (sd
, myname
, mn10200_callback
, prog
, abfd
,
813 sim_kind
== SIM_OPEN_DEBUG
,
815 if (prog_bfd
== NULL
)
818 bfd_close (prog_bfd
);
This page took 0.045354 seconds and 4 git commands to generate.