5 #include "sim-options.h"
8 #include "mn10300_sim.h"
13 #include "sim-assert.h"
39 host_callback
*mn10300_callback
;
44 /* simulation target board. NULL=default configuration */
45 static char* board
= NULL
;
47 static DECLARE_OPTION_HANDLER (mn10300_option_handler
);
50 OPTION_BOARD
= OPTION_START
,
54 mn10300_option_handler (sd
, cpu
, opt
, arg
, is_command
)
68 board
= zalloc(strlen(arg
) + 1);
78 static const OPTION mn10300_options
[] =
80 #define BOARD_AM32 "stdeval1"
81 { {"board", required_argument
, NULL
, OPTION_BOARD
},
82 '\0', "none" /* rely on compile-time string concatenation for other options */
84 , "Customize simulation for a particular board.", mn10300_option_handler
},
86 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
91 static void dispatch
PARAMS ((uint32
, uint32
, int));
92 static long hash
PARAMS ((long));
93 static void init_system
PARAMS ((void));
95 static SIM_OPEN_KIND sim_kind
;
101 struct hash_entry
*next
;
110 static int max_mem
= 0;
111 struct hash_entry hash_table
[MAX_HASH
+1];
114 /* This probably doesn't do a very good job at bucket filling, but
120 /* These are one byte insns, we special case these since, in theory,
121 they should be the most heavily used. */
122 if ((insn
& 0xffffff00) == 0)
167 /* These are two byte insns */
168 if ((insn
& 0xffff0000) == 0)
170 if ((insn
& 0xf000) == 0x2000
171 || (insn
& 0xf000) == 0x5000)
172 return ((insn
& 0xfc00) >> 8) & 0x7f;
174 if ((insn
& 0xf000) == 0x4000)
175 return ((insn
& 0xf300) >> 8) & 0x7f;
177 if ((insn
& 0xf000) == 0x8000
178 || (insn
& 0xf000) == 0x9000
179 || (insn
& 0xf000) == 0xa000
180 || (insn
& 0xf000) == 0xb000)
181 return ((insn
& 0xf000) >> 8) & 0x7f;
183 if ((insn
& 0xff00) == 0xf000
184 || (insn
& 0xff00) == 0xf100
185 || (insn
& 0xff00) == 0xf200
186 || (insn
& 0xff00) == 0xf500
187 || (insn
& 0xff00) == 0xf600)
188 return ((insn
& 0xfff0) >> 4) & 0x7f;
190 if ((insn
& 0xf000) == 0xc000)
191 return ((insn
& 0xff00) >> 8) & 0x7f;
193 return ((insn
& 0xffc0) >> 6) & 0x7f;
196 /* These are three byte insns. */
197 if ((insn
& 0xff000000) == 0)
199 if ((insn
& 0xf00000) == 0x000000)
200 return ((insn
& 0xf30000) >> 16) & 0x7f;
202 if ((insn
& 0xf00000) == 0x200000
203 || (insn
& 0xf00000) == 0x300000)
204 return ((insn
& 0xfc0000) >> 16) & 0x7f;
206 if ((insn
& 0xff0000) == 0xf80000)
207 return ((insn
& 0xfff000) >> 12) & 0x7f;
209 if ((insn
& 0xff0000) == 0xf90000)
210 return ((insn
& 0xfffc00) >> 10) & 0x7f;
212 return ((insn
& 0xff0000) >> 16) & 0x7f;
215 /* These are four byte or larger insns. */
216 if ((insn
& 0xf0000000) == 0xf0000000)
217 return ((insn
& 0xfff00000) >> 20) & 0x7f;
219 return ((insn
& 0xff000000) >> 24) & 0x7f;
223 dispatch (insn
, extension
, length
)
228 struct hash_entry
*h
;
230 h
= &hash_table
[hash(insn
)];
232 while ((insn
& h
->mask
) != h
->opcode
233 || (length
!= h
->ops
->length
))
237 (*mn10300_callback
->printf_filtered
) (mn10300_callback
,
238 "ERROR looking up hash for 0x%x, PC=0x%x\n", insn
, PC
);
249 /* Now call the right function. */
250 (h
->ops
->func
)(insn
, extension
);
262 max_mem
= 1 << power
;
263 State
.mem
= (uint8
*) calloc (1, 1 << power
);
266 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "Allocation of main memory failed.\n");
279 sim_write (sd
, addr
, buffer
, size
)
282 unsigned char *buffer
;
289 for (i
= 0; i
< size
; i
++)
290 store_byte (addr
+ i
, buffer
[i
]);
295 /* Compare two opcode table entries for qsort. */
297 compare_simops (arg1
, arg2
)
301 unsigned long code1
= ((struct simops
*)arg1
)->opcode
;
302 unsigned long code2
= ((struct simops
*)arg2
)->opcode
;
312 sim_open (kind
, cb
, abfd
, argv
)
319 struct hash_entry
*h
;
323 mn10300_callback
= cb
;
325 /* Sort the opcode array from smallest opcode to largest.
326 This will generally improve simulator performance as the smaller
327 opcodes are generally preferred to the larger opcodes. */
328 for (i
= 0, s
= Simops
; s
->func
; s
++, i
++)
330 qsort (Simops
, i
, sizeof (Simops
[0]), compare_simops
);
335 for (p
= argv
+ 1; *p
; ++p
)
337 if (strcmp (*p
, "-E") == 0)
338 ++p
; /* ignore endian spec */
341 if (strcmp (*p
, "-t") == 0)
342 mn10300_debug
= DEBUG
;
345 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "ERROR: unsupported option(s): %s\n",*p
);
348 /* put all the opcodes in the hash table */
349 for (s
= Simops
; s
->func
; s
++)
351 h
= &hash_table
[hash(s
->opcode
)];
353 /* go to the last entry in the chain */
356 /* Don't insert the same opcode more than once. */
357 if (h
->opcode
== s
->opcode
358 && h
->mask
== s
->mask
365 /* Don't insert the same opcode more than once. */
366 if (h
->opcode
== s
->opcode
367 && h
->mask
== s
->mask
373 h
->next
= calloc(1,sizeof(struct hash_entry
));
378 h
->opcode
= s
->opcode
;
385 /* fudge our descriptor for now */
391 sim_close (sd
, quitting
)
402 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "sim_set_profile %d\n", n
);
406 sim_set_profile_size (n
)
409 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "sim_set_profile_size %d\n", n
);
420 sim_resume (sd
, step
, siggnal
)
426 struct hash_entry
*h
;
429 State
.exception
= SIGTRAP
;
437 unsigned long insn
, extension
;
439 /* Fetch the current instruction. */
440 inst
= load_mem_big (PC
, 2);
443 /* Using a giant case statement may seem like a waste because of the
444 code/rodata size the table itself will consume. However, using
445 a giant case statement speeds up the simulator by 10-15% by avoiding
446 cascading if/else statements or cascading case statements. */
448 switch ((inst
>> 8) & 0xff)
450 /* All the single byte insns except 0x80, 0x90, 0xa0, 0xb0
451 which must be handled specially. */
554 insn
= (inst
>> 8) & 0xff;
556 dispatch (insn
, extension
, 1);
559 /* Special cases where dm == dn is used to encode a different
579 dispatch (insn
, extension
, 2);
630 insn
= (inst
>> 8) & 0xff;
632 dispatch (insn
, extension
, 1);
635 /* The two byte instructions. */
682 dispatch (insn
, extension
, 2);
685 /* The three byte insns with a 16bit operand in little endian
720 insn
= load_byte (PC
);
722 insn
|= load_half (PC
+ 1);
724 dispatch (insn
, extension
, 3);
727 /* The three byte insns without 16bit operand. */
732 insn
= load_mem_big (PC
, 3);
734 dispatch (insn
, extension
, 3);
737 /* Four byte insns. */
740 if ((inst
& 0xfffc) == 0xfaf0
741 || (inst
& 0xfffc) == 0xfaf4
742 || (inst
& 0xfffc) == 0xfaf8)
743 insn
= load_mem_big (PC
, 4);
748 insn
|= load_half (PC
+ 2);
751 dispatch (insn
, extension
, 4);
754 /* Five byte insns. */
756 insn
= load_byte (PC
);
758 insn
|= (load_half (PC
+ 1) << 8);
759 insn
|= load_byte (PC
+ 3);
760 extension
= load_byte (PC
+ 4);
761 dispatch (insn
, extension
, 5);
765 insn
= load_byte (PC
);
767 extension
= load_word (PC
+ 1);
768 insn
|= (extension
& 0xffffff00) >> 8;
770 dispatch (insn
, extension
, 5);
773 /* Six byte insns. */
777 extension
= load_word (PC
+ 2);
778 insn
|= ((extension
& 0xffff0000) >> 16);
780 dispatch (insn
, extension
, 6);
784 insn
= load_byte (PC
) << 24;
785 extension
= load_word (PC
+ 1);
786 insn
|= ((extension
>> 8) & 0xffffff);
787 extension
= (extension
& 0xff) << 16;
788 extension
|= load_byte (PC
+ 5) << 8;
789 extension
|= load_byte (PC
+ 6);
790 dispatch (insn
, extension
, 7);
795 extension
= load_word (PC
+ 2);
796 insn
|= ((extension
>> 16) & 0xffff);
798 extension
&= 0xffff00;
799 extension
|= load_byte (PC
+ 6);
800 dispatch (insn
, extension
, 7);
807 while (!State
.exception
);
812 for (i
= 0; i
< MAX_HASH
; i
++)
814 struct hash_entry
*h
;
817 printf("hash 0x%x:\n", i
);
821 printf("h->opcode = 0x%x, count = 0x%x\n", h
->opcode
, h
->count
);
838 mn10300_debug
= DEBUG
;
840 sim_resume (sd
, 0, 0);
845 sim_info (sd
, verbose
)
849 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "sim_info\n");
853 sim_create_inferior (sd
, abfd
, argv
, env
)
860 PC
= bfd_get_start_address (abfd
);
867 sim_set_callbacks (p
)
870 mn10300_callback
= p
;
873 /* All the code for exiting, signals, etc needs to be revamped.
875 This is enough to get c-torture limping though. */
878 sim_stop_reason (sd
, reason
, sigrc
)
880 enum sim_stop
*reason
;
884 *reason
= sim_exited
;
886 *reason
= sim_stopped
;
888 if (State
.exception
== SIGQUIT
)
891 *sigrc
= State
.exception
;
895 sim_read (sd
, addr
, buffer
, size
)
898 unsigned char *buffer
;
902 for (i
= 0; i
< size
; i
++)
903 buffer
[i
] = load_byte (addr
+ i
);
909 sim_do_command (sd
, cmd
)
913 (*mn10300_callback
->printf_filtered
) (mn10300_callback
, "\"%s\" is not a valid mn10300 simulator command.\n", cmd
);
917 sim_load (sd
, prog
, abfd
, from_tty
)
923 extern bfd
*sim_load_file (); /* ??? Don't know where this should live. */
926 prog_bfd
= sim_load_file (sd
, myname
, mn10300_callback
, prog
, abfd
,
927 sim_kind
== SIM_OPEN_DEBUG
,
929 if (prog_bfd
== NULL
)
932 bfd_close (prog_bfd
);
935 #endif /* not WITH_COMMON */
940 /* For compatibility */
943 /* These default values correspond to expected usage for the chip. */
946 sim_open (kind
, cb
, abfd
, argv
)
952 SIM_DESC sd
= sim_state_alloc (kind
, cb
);
953 mn10300_callback
= cb
;
955 SIM_ASSERT (STATE_MAGIC (sd
) == SIM_MAGIC_NUMBER
);
957 /* for compatibility */
960 /* FIXME: should be better way of setting up interrupts. For
961 moment, only support watchpoints causing a breakpoint (gdb
963 STATE_WATCHPOINTS (sd
)->pc
= &(PC
);
964 STATE_WATCHPOINTS (sd
)->sizeof_pc
= sizeof (PC
);
965 STATE_WATCHPOINTS (sd
)->interrupt_handler
= NULL
;
966 STATE_WATCHPOINTS (sd
)->interrupt_names
= NULL
;
968 if (sim_pre_argv_init (sd
, argv
[0]) != SIM_RC_OK
)
970 sim_add_option_table (sd
, NULL
, mn10300_options
);
972 /* Allocate core managed memory */
973 sim_do_command (sd
, "memory region 0,0x100000");
974 sim_do_command (sd
, "memory region 0x40000000,0x200000");
976 /* getopt will print the error message so we just have to exit if this fails.
977 FIXME: Hmmm... in the case of gdb we need getopt to call
979 if (sim_parse_args (sd
, argv
) != SIM_RC_OK
)
981 /* Uninstall the modules to avoid memory leaks,
982 file descriptor leaks, etc. */
983 sim_module_uninstall (sd
);
988 && (strcmp(board
, BOARD_AM32
) == 0 ) )
991 STATE_ENVIRONMENT (sd
) = OPERATING_ENVIRONMENT
;
993 sim_do_command (sd
, "memory region 0x44000000,0x40000");
994 sim_do_command (sd
, "memory region 0x48000000,0x400000");
996 /* device support for mn1030002 */
997 /* interrupt controller */
999 sim_hw_parse (sd
, "/mn103int@0x34000100/reg 0x34000100 0x7C 0x34000200 0x8 0x34000280 0x8");
1001 /* DEBUG: NMI input's */
1002 sim_hw_parse (sd
, "/glue@0x30000000/reg 0x30000000 12");
1003 sim_hw_parse (sd
, "/glue@0x30000000 > int0 nmirq /mn103int");
1004 sim_hw_parse (sd
, "/glue@0x30000000 > int1 watchdog /mn103int");
1005 sim_hw_parse (sd
, "/glue@0x30000000 > int2 syserr /mn103int");
1007 /* DEBUG: ACK input */
1008 sim_hw_parse (sd
, "/glue@0x30002000/reg 0x30002000 4");
1009 sim_hw_parse (sd
, "/glue@0x30002000 > int ack /mn103int");
1011 /* DEBUG: LEVEL output */
1012 sim_hw_parse (sd
, "/glue@0x30004000/reg 0x30004000 8");
1013 sim_hw_parse (sd
, "/mn103int > nmi int0 /glue@0x30004000");
1014 sim_hw_parse (sd
, "/mn103int > level int1 /glue@0x30004000");
1016 /* DEBUG: A bunch of interrupt inputs */
1017 sim_hw_parse (sd
, "/glue@0x30006000/reg 0x30006000 32");
1018 sim_hw_parse (sd
, "/glue@0x30006000 > int0 irq-0 /mn103int");
1019 sim_hw_parse (sd
, "/glue@0x30006000 > int1 irq-1 /mn103int");
1020 sim_hw_parse (sd
, "/glue@0x30006000 > int2 irq-2 /mn103int");
1021 sim_hw_parse (sd
, "/glue@0x30006000 > int3 irq-3 /mn103int");
1022 sim_hw_parse (sd
, "/glue@0x30006000 > int4 irq-4 /mn103int");
1023 sim_hw_parse (sd
, "/glue@0x30006000 > int5 irq-5 /mn103int");
1024 sim_hw_parse (sd
, "/glue@0x30006000 > int6 irq-6 /mn103int");
1025 sim_hw_parse (sd
, "/glue@0x30006000 > int7 irq-7 /mn103int");
1027 /* processor interrupt device */
1030 sim_hw_parse (sd
, "/mn103cpu@0x20000000");
1031 sim_hw_parse (sd
, "/mn103cpu@0x20000000/reg 0x20000000 0x42");
1033 /* DEBUG: ACK output wired upto a glue device */
1034 sim_hw_parse (sd
, "/glue@0x20002000");
1035 sim_hw_parse (sd
, "/glue@0x20002000/reg 0x20002000 4");
1036 sim_hw_parse (sd
, "/mn103cpu > ack int0 /glue@0x20002000");
1038 /* DEBUG: RESET/NMI/LEVEL wired up to a glue device */
1039 sim_hw_parse (sd
, "/glue@0x20004000");
1040 sim_hw_parse (sd
, "/glue@0x20004000/reg 0x20004000 12");
1041 sim_hw_parse (sd
, "/glue@0x20004000 > int0 reset /mn103cpu");
1042 sim_hw_parse (sd
, "/glue@0x20004000 > int1 nmi /mn103cpu");
1043 sim_hw_parse (sd
, "/glue@0x20004000 > int2 level /mn103cpu");
1045 /* REAL: The processor wired up to the real interrupt controller */
1046 sim_hw_parse (sd
, "/mn103cpu > ack ack /mn103int");
1047 sim_hw_parse (sd
, "/mn103int > level level /mn103cpu");
1048 sim_hw_parse (sd
, "/mn103int > nmi nmi /mn103cpu");
1054 sim_hw_parse (sd
, "/pal@0x31000000");
1055 sim_hw_parse (sd
, "/pal@0x31000000/reg 0x31000000 64");
1056 sim_hw_parse (sd
, "/pal@0x31000000/poll? true");
1058 /* DEBUG: PAL wired up to a glue device */
1059 sim_hw_parse (sd
, "/glue@0x31002000");
1060 sim_hw_parse (sd
, "/glue@0x31002000/reg 0x31002000 16");
1061 sim_hw_parse (sd
, "/pal@0x31000000 > countdown int0 /glue@0x31002000");
1062 sim_hw_parse (sd
, "/pal@0x31000000 > timer int1 /glue@0x31002000");
1063 sim_hw_parse (sd
, "/pal@0x31000000 > int int2 /glue@0x31002000");
1064 sim_hw_parse (sd
, "/glue@0x31002000 > int0 int3 /glue@0x31002000");
1065 sim_hw_parse (sd
, "/glue@0x31002000 > int1 int3 /glue@0x31002000");
1066 sim_hw_parse (sd
, "/glue@0x31002000 > int2 int3 /glue@0x31002000");
1068 /* REAL: The PAL wired up to the real interrupt controller */
1069 sim_hw_parse (sd
, "/pal@0x31000000 > countdown irq-0 /mn103int");
1070 sim_hw_parse (sd
, "/pal@0x31000000 > timer irq-1 /mn103int");
1071 sim_hw_parse (sd
, "/pal@0x31000000 > int irq-2 /mn103int");
1073 /* 8 and 16 bit timers */
1074 sim_hw_parse (sd
, "/mn103tim@0x34001000/reg 0x34001000 36 0x34001080 100 0x34004000 16");
1076 /* Hook timer interrupts up to interrupt controller */
1077 sim_hw_parse (sd
, "/mn103tim > timer-0-underflow timer-0-underflow /mn103int");
1078 sim_hw_parse (sd
, "/mn103tim > timer-1-underflow timer-1-underflow /mn103int");
1079 sim_hw_parse (sd
, "/mn103tim > timer-2-underflow timer-2-underflow /mn103int");
1080 sim_hw_parse (sd
, "/mn103tim > timer-3-underflow timer-3-underflow /mn103int");
1081 sim_hw_parse (sd
, "/mn103tim > timer-4-underflow timer-4-underflow /mn103int");
1082 sim_hw_parse (sd
, "/mn103tim > timer-5-underflow timer-5-underflow /mn103int");
1083 sim_hw_parse (sd
, "/mn103tim > timer-6-underflow timer-6-underflow /mn103int");
1084 sim_hw_parse (sd
, "/mn103tim > timer-6-compare-a timer-6-compare-a /mn103int");
1085 sim_hw_parse (sd
, "/mn103tim > timer-6-compare-b timer-6-compare-b /mn103int");
1088 /* Serial devices 0,1,2 */
1089 sim_hw_parse (sd
, "/mn103ser@0x34000800/reg 0x34000800 48");
1090 sim_hw_parse (sd
, "/mn103ser@0x34000800/poll? true");
1092 /* Hook serial interrupts up to interrupt controller */
1093 sim_hw_parse (sd
, "/mn103ser > serial-0-receive serial-0-receive /mn103int");
1094 sim_hw_parse (sd
, "/mn103ser > serial-0-transmit serial-0-transmit /mn103int");
1095 sim_hw_parse (sd
, "/mn103ser > serial-1-receive serial-1-receive /mn103int");
1096 sim_hw_parse (sd
, "/mn103ser > serial-1-transmit serial-1-transmit /mn103int");
1097 sim_hw_parse (sd
, "/mn103ser > serial-2-receive serial-2-receive /mn103int");
1098 sim_hw_parse (sd
, "/mn103ser > serial-2-transmit serial-2-transmit /mn103int");
1100 sim_hw_parse (sd
, "/mn103iop@0x36008000/reg 0x36008000 8 0x36008020 8 0x36008040 0xc 0x36008060 8 0x36008080 8");
1102 /* Memory control registers */
1103 sim_do_command (sd
, "memory region 0x32000020,0x30");
1104 /* Cache control register */
1105 sim_do_command (sd
, "memory region 0x20000070,0x4");
1106 /* Cache purge regions */
1107 sim_do_command (sd
, "memory region 0x28400000,0x800");
1108 sim_do_command (sd
, "memory region 0x28401000,0x800");
1110 sim_do_command (sd
, "memory region 0x32000100,0xF");
1111 sim_do_command (sd
, "memory region 0x32000200,0xF");
1112 sim_do_command (sd
, "memory region 0x32000400,0xF");
1113 sim_do_command (sd
, "memory region 0x32000800,0xF");
1119 sim_io_eprintf (sd
, "Error: Board `%s' unknown.\n", board
);
1126 /* check for/establish the a reference program image */
1127 if (sim_analyze_program (sd
,
1128 (STATE_PROG_ARGV (sd
) != NULL
1129 ? *STATE_PROG_ARGV (sd
)
1133 sim_module_uninstall (sd
);
1137 /* establish any remaining configuration options */
1138 if (sim_config (sd
) != SIM_RC_OK
)
1140 sim_module_uninstall (sd
);
1144 if (sim_post_argv_init (sd
) != SIM_RC_OK
)
1146 /* Uninstall the modules to avoid memory leaks,
1147 file descriptor leaks, etc. */
1148 sim_module_uninstall (sd
);
1153 /* set machine specific configuration */
1154 /* STATE_CPU (sd, 0)->psw_mask = (PSW_NP | PSW_EP | PSW_ID | PSW_SAT */
1155 /* | PSW_CY | PSW_OV | PSW_S | PSW_Z); */
1162 sim_close (sd
, quitting
)
1166 sim_module_uninstall (sd
);
1171 sim_create_inferior (sd
, prog_bfd
, argv
, env
)
1173 struct _bfd
*prog_bfd
;
1177 memset (&State
, 0, sizeof (State
));
1178 if (prog_bfd
!= NULL
) {
1179 PC
= bfd_get_start_address (prog_bfd
);
1183 CIA_SET (STATE_CPU (sd
, 0), (unsigned64
) PC
);
1189 sim_do_command (sd
, cmd
)
1193 char *mm_cmd
= "memory-map";
1194 char *int_cmd
= "interrupt";
1196 if (sim_args_command (sd
, cmd
) != SIM_RC_OK
)
1198 if (strncmp (cmd
, mm_cmd
, strlen (mm_cmd
) == 0))
1199 sim_io_eprintf (sd
, "`memory-map' command replaced by `sim memory'\n");
1200 else if (strncmp (cmd
, int_cmd
, strlen (int_cmd
)) == 0)
1201 sim_io_eprintf (sd
, "`interrupt' command replaced by `sim watch'\n");
1203 sim_io_eprintf (sd
, "Unknown command `%s'\n", cmd
);
1206 #endif /* WITH_COMMON */
1208 /* FIXME These would more efficient to use than load_mem/store_mem,
1209 but need to be changed to use the memory map. */
1223 return (a
[1] << 8) + (a
[0]);
1231 return (a
[3]<<24) + (a
[2]<<16) + (a
[1]<<8) + (a
[0]);
1235 put_byte (addr
, data
)
1244 put_half (addr
, data
)
1250 a
[1] = (data
>> 8) & 0xff;
1254 put_word (addr
, data
)
1260 a
[1] = (data
>> 8) & 0xff;
1261 a
[2] = (data
>> 16) & 0xff;
1262 a
[3] = (data
>> 24) & 0xff;
1266 sim_fetch_register (sd
, rn
, memory
, length
)
1269 unsigned char *memory
;
1272 put_word (memory
, State
.regs
[rn
]);
1277 sim_store_register (sd
, rn
, memory
, length
)
1280 unsigned char *memory
;
1283 State
.regs
[rn
] = get_word (memory
);
1289 mn10300_core_signal (SIM_DESC sd
,
1295 transfer_type transfer
,
1296 sim_core_signals sig
)
1298 const char *copy
= (transfer
== read_transfer
? "read" : "write");
1299 address_word ip
= CIA_ADDR (cia
);
1303 case sim_core_unmapped_signal
:
1304 sim_io_eprintf (sd
, "mn10300-core: %d byte %s to unmapped address 0x%lx at 0x%lx\n",
1306 (unsigned long) addr
, (unsigned long) ip
);
1307 program_interrupt(sd
, cpu
, cia
, SIM_SIGSEGV
);
1310 case sim_core_unaligned_signal
:
1311 sim_io_eprintf (sd
, "mn10300-core: %d byte %s to unaligned address 0x%lx at 0x%lx\n",
1313 (unsigned long) addr
, (unsigned long) ip
);
1314 program_interrupt(sd
, cpu
, cia
, SIM_SIGBUS
);
1318 sim_engine_abort (sd
, cpu
, cia
,
1319 "mn10300_core_signal - internal error - bad switch");
1325 program_interrupt (SIM_DESC sd
,
1332 static int in_interrupt
= 0;
1334 #ifdef SIM_CPU_EXCEPTION_TRIGGER
1335 SIM_CPU_EXCEPTION_TRIGGER(sd
,cpu
,cia
);
1338 /* avoid infinite recursion */
1341 (*mn10300_callback
->printf_filtered
) (mn10300_callback
,
1342 "ERROR: recursion in program_interrupt during software exception dispatch.");
1347 /* copy NMI handler code from dv-mn103cpu.c */
1348 store_word (SP
- 4, CIA_GET (cpu
));
1349 store_half (SP
- 8, PSW
);
1351 /* Set the SYSEF flag in NMICR by backdoor method. See
1352 dv-mn103int.c:write_icr(). This is necessary because
1353 software exceptions are not modelled by actually talking to
1354 the interrupt controller, so it cannot set its own SYSEF
1356 if ((NULL
!= board
) && (strcmp(board
, BOARD_AM32
) == 0))
1357 store_byte (0x34000103, 0x04);
1362 CIA_SET (cpu
, 0x40000008);
1365 sim_engine_halt(sd
, cpu
, NULL
, cia
, sim_stopped
, sig
);
1370 mn10300_cpu_exception_trigger(SIM_DESC sd
, sim_cpu
* cpu
, address_word cia
)
1372 ASSERT(cpu
!= NULL
);
1374 if(State
.exc_suspended
> 0)
1375 sim_io_eprintf(sd
, "Warning, nested exception triggered (%d)\n", State
.exc_suspended
);
1378 memcpy(State
.exc_trigger_regs
, State
.regs
, sizeof(State
.exc_trigger_regs
));
1379 State
.exc_suspended
= 0;
1383 mn10300_cpu_exception_suspend(SIM_DESC sd
, sim_cpu
* cpu
, int exception
)
1385 ASSERT(cpu
!= NULL
);
1387 if(State
.exc_suspended
> 0)
1388 sim_io_eprintf(sd
, "Warning, nested exception signal (%d then %d)\n",
1389 State
.exc_suspended
, exception
);
1391 memcpy(State
.exc_suspend_regs
, State
.regs
, sizeof(State
.exc_suspend_regs
));
1392 memcpy(State
.regs
, State
.exc_trigger_regs
, sizeof(State
.regs
));
1393 CIA_SET (cpu
, PC
); /* copy PC back from new State.regs */
1394 State
.exc_suspended
= exception
;
1398 mn10300_cpu_exception_resume(SIM_DESC sd
, sim_cpu
* cpu
, int exception
)
1400 ASSERT(cpu
!= NULL
);
1402 if(exception
== 0 && State
.exc_suspended
> 0)
1404 if(State
.exc_suspended
!= SIGTRAP
) /* warn not for breakpoints */
1405 sim_io_eprintf(sd
, "Warning, resuming but ignoring pending exception signal (%d)\n",
1406 State
.exc_suspended
);
1408 else if(exception
!= 0 && State
.exc_suspended
> 0)
1410 if(exception
!= State
.exc_suspended
)
1411 sim_io_eprintf(sd
, "Warning, resuming with mismatched exception signal (%d vs %d)\n",
1412 State
.exc_suspended
, exception
);
1414 memcpy(State
.regs
, State
.exc_suspend_regs
, sizeof(State
.regs
));
1415 CIA_SET (cpu
, PC
); /* copy PC back from new State.regs */
1417 else if(exception
!= 0 && State
.exc_suspended
== 0)
1419 sim_io_eprintf(sd
, "Warning, ignoring spontanous exception signal (%d)\n", exception
);
1421 State
.exc_suspended
= 0;