1 /* m6811_cpu.c -- 68HC11&68HC12 CPU Emulation
2 Copyright 1999-2021 Free Software Foundation, Inc.
3 Written by Stephane Carrez (stcarrez@nerim.fr)
5 This file is part of GDB, GAS, and the GNU binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* This must come before any other includes. */
24 #include "sim-assert.h"
25 #include "sim-module.h"
26 #include "sim-options.h"
31 OPTION_CPU_RESET
= OPTION_START
,
38 static DECLARE_OPTION_HANDLER (cpu_option_handler
);
40 static const OPTION cpu_options
[] =
42 { {"cpu-reset", no_argument
, NULL
, OPTION_CPU_RESET
},
43 '\0', NULL
, "Reset the CPU",
46 { {"emulos", no_argument
, NULL
, OPTION_EMUL_OS
},
47 '\0', NULL
, "Emulate some OS system calls (read, write, ...)",
50 { {"cpu-config", required_argument
, NULL
, OPTION_CPU_CONFIG
},
51 '\0', NULL
, "Specify the initial CPU configuration register",
54 { {"bootstrap", no_argument
, NULL
, OPTION_CPU_BOOTSTRAP
},
55 '\0', NULL
, "Start the processing in bootstrap mode",
58 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
63 cpu_option_handler (SIM_DESC sd
, sim_cpu
*cpu
,
64 int opt
, char *arg
, int is_command
)
68 cpu
= STATE_CPU (sd
, 0);
71 case OPTION_CPU_RESET
:
76 cpu
->cpu_emul_syscall
= 1;
79 case OPTION_CPU_CONFIG
:
80 if (sscanf(arg
, "0x%x", &val
) == 1
81 || sscanf(arg
, "%d", &val
) == 1)
83 cpu
->cpu_config
= val
;
84 cpu
->cpu_use_local_config
= 1;
87 cpu
->cpu_use_local_config
= 0;
90 case OPTION_CPU_BOOTSTRAP
:
91 cpu
->cpu_start_mode
= "bootstrap";
103 cpu_call (sim_cpu
*cpu
, uint16 addr
)
106 cpu_set_pc (cpu
, addr
);
110 cpu_return (sim_cpu
*cpu
)
114 /* Set the stack pointer and re-compute the current frame. */
116 cpu_set_sp (sim_cpu
*cpu
, uint16 val
)
118 cpu
->cpu_regs
.sp
= val
;
122 cpu_get_reg (sim_cpu
*cpu
, uint8 reg
)
127 return cpu_get_x (cpu
);
130 return cpu_get_y (cpu
);
133 return cpu_get_sp (cpu
);
136 return cpu_get_pc (cpu
);
144 cpu_get_src_reg (sim_cpu
*cpu
, uint8 reg
)
149 return cpu_get_a (cpu
);
152 return cpu_get_b (cpu
);
155 return cpu_get_ccr (cpu
);
158 return cpu_get_tmp3 (cpu
);
161 return cpu_get_d (cpu
);
164 return cpu_get_x (cpu
);
167 return cpu_get_y (cpu
);
170 return cpu_get_sp (cpu
);
178 cpu_set_dst_reg (sim_cpu
*cpu
, uint8 reg
, uint16 val
)
183 cpu_set_a (cpu
, val
);
187 cpu_set_b (cpu
, val
);
191 cpu_set_ccr (cpu
, val
);
195 cpu_set_tmp2 (cpu
, val
);
199 cpu_set_d (cpu
, val
);
203 cpu_set_x (cpu
, val
);
207 cpu_set_y (cpu
, val
);
211 cpu_set_sp (cpu
, val
);
220 cpu_set_reg (sim_cpu
*cpu
, uint8 reg
, uint16 val
)
225 cpu_set_x (cpu
, val
);
229 cpu_set_y (cpu
, val
);
233 cpu_set_sp (cpu
, val
);
237 cpu_set_pc (cpu
, val
);
245 /* Returns the address of a 68HC12 indexed operand.
246 Pre and post modifications are handled on the source register. */
248 cpu_get_indexed_operand_addr (sim_cpu
*cpu
, int restricted
)
255 code
= cpu_fetch8 (cpu
);
257 /* n,r with 5-bit signed constant. */
258 if ((code
& 0x20) == 0)
260 reg
= (code
>> 6) & 3;
261 sval
= (code
& 0x1f);
265 addr
= cpu_get_reg (cpu
, reg
);
269 /* Auto pre/post increment/decrement. */
270 else if ((code
& 0xc0) != 0xc0)
272 reg
= (code
>> 6) & 3;
273 sval
= (code
& 0x0f);
282 addr
= cpu_get_reg (cpu
, reg
);
283 cpu_set_reg (cpu
, reg
, addr
+ sval
);
284 if ((code
& 0x10) == 0)
290 /* [n,r] 16-bits offset indexed indirect. */
291 else if ((code
& 0x07) == 3)
297 reg
= (code
>> 3) & 0x03;
298 addr
= cpu_get_reg (cpu
, reg
);
299 addr
+= cpu_fetch16 (cpu
);
300 addr
= memory_read16 (cpu
, addr
);
301 cpu_add_cycles (cpu
, 1);
303 else if ((code
& 0x4) == 0)
309 reg
= (code
>> 3) & 0x03;
310 addr
= cpu_get_reg (cpu
, reg
);
313 sval
= cpu_fetch16 (cpu
);
314 cpu_add_cycles (cpu
, 1);
318 sval
= cpu_fetch8 (cpu
);
321 cpu_add_cycles (cpu
, 1);
327 reg
= (code
>> 3) & 0x03;
328 addr
= cpu_get_reg (cpu
, reg
);
332 addr
+= cpu_get_a (cpu
);
335 addr
+= cpu_get_b (cpu
);
338 addr
+= cpu_get_d (cpu
);
342 addr
+= cpu_get_d (cpu
);
343 addr
= memory_read16 (cpu
, addr
);
344 cpu_add_cycles (cpu
, 1);
353 cpu_get_indexed_operand8 (sim_cpu
*cpu
, int restricted
)
357 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
358 return memory_read8 (cpu
, addr
);
362 cpu_get_indexed_operand16 (sim_cpu
*cpu
, int restricted
)
366 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
367 return memory_read16 (cpu
, addr
);
371 cpu_move8 (sim_cpu
*cpu
, uint8 code
)
379 src
= cpu_fetch8 (cpu
);
380 addr
= cpu_fetch16 (cpu
);
384 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
385 src
= cpu_fetch8 (cpu
);
389 addr
= cpu_fetch16 (cpu
);
390 src
= memory_read8 (cpu
, addr
);
391 addr
= cpu_fetch16 (cpu
);
395 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
396 src
= memory_read8 (cpu
, cpu_fetch16 (cpu
));
400 src
= cpu_get_indexed_operand8 (cpu
, 1);
401 addr
= cpu_fetch16 (cpu
);
405 src
= cpu_get_indexed_operand8 (cpu
, 1);
406 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
410 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
411 "Invalid code 0x%0x -- internal error?", code
);
414 memory_write8 (cpu
, addr
, src
);
418 cpu_move16 (sim_cpu
*cpu
, uint8 code
)
426 src
= cpu_fetch16 (cpu
);
427 addr
= cpu_fetch16 (cpu
);
431 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
432 src
= cpu_fetch16 (cpu
);
436 addr
= cpu_fetch16 (cpu
);
437 src
= memory_read16 (cpu
, addr
);
438 addr
= cpu_fetch16 (cpu
);
442 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
443 src
= memory_read16 (cpu
, cpu_fetch16 (cpu
));
447 src
= cpu_get_indexed_operand16 (cpu
, 1);
448 addr
= cpu_fetch16 (cpu
);
452 src
= cpu_get_indexed_operand16 (cpu
, 1);
453 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
457 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
458 "Invalid code 0x%0x -- internal error?", code
);
461 memory_write16 (cpu
, addr
, src
);
465 cpu_initialize (SIM_DESC sd
, sim_cpu
*cpu
)
467 sim_add_option_table (sd
, 0, cpu_options
);
469 memset (&cpu
->cpu_regs
, 0, sizeof(cpu
->cpu_regs
));
471 cpu
->cpu_absolute_cycle
= 0;
472 cpu
->cpu_current_cycle
= 0;
473 cpu
->cpu_emul_syscall
= 1;
474 cpu
->cpu_running
= 1;
475 cpu
->cpu_stop_on_interrupt
= 0;
476 cpu
->cpu_frequency
= 8 * 1000 * 1000;
477 cpu
->cpu_use_elf_start
= 0;
478 cpu
->cpu_elf_start
= 0;
479 cpu
->cpu_use_local_config
= 0;
483 cpu
->cpu_config
= M6811_NOSEC
| M6811_NOCOP
| M6811_ROMON
|
485 interrupts_initialize (sd
, cpu
);
487 cpu
->cpu_is_initialized
= 1;
492 /* Reinitialize the processor after a reset. */
494 cpu_reset (sim_cpu
*cpu
)
496 /* Initialize the config register.
497 It is only initialized at reset time. */
498 memset (cpu
->ios
, 0, sizeof (cpu
->ios
));
499 if (cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
500 cpu
->ios
[M6811_INIT
] = 0x1;
502 cpu
->ios
[M6811_INIT
] = 0;
504 /* Output compare registers set to 0xFFFF. */
505 cpu
->ios
[M6811_TOC1_H
] = 0xFF;
506 cpu
->ios
[M6811_TOC1_L
] = 0xFF;
507 cpu
->ios
[M6811_TOC2_H
] = 0xFF;
508 cpu
->ios
[M6811_TOC2_L
] = 0xFF;
509 cpu
->ios
[M6811_TOC3_H
] = 0xFF;
510 cpu
->ios
[M6811_TOC4_L
] = 0xFF;
511 cpu
->ios
[M6811_TOC5_H
] = 0xFF;
512 cpu
->ios
[M6811_TOC5_L
] = 0xFF;
514 /* Setup the processor registers. */
515 memset (&cpu
->cpu_regs
, 0, sizeof(cpu
->cpu_regs
));
516 cpu
->cpu_absolute_cycle
= 0;
517 cpu
->cpu_current_cycle
= 0;
518 cpu
->cpu_is_initialized
= 0;
520 /* Reset interrupts. */
521 interrupts_reset (&cpu
->cpu_interrupts
);
523 /* Reinitialize the CPU operating mode. */
524 cpu
->ios
[M6811_HPRIO
] = cpu
->cpu_mode
;
528 /* Reinitialize the processor after a reset. */
530 cpu_restart (sim_cpu
*cpu
)
534 /* Get CPU starting address depending on the CPU mode. */
535 if (cpu
->cpu_use_elf_start
== 0)
537 switch ((cpu
->ios
[M6811_HPRIO
]) & (M6811_SMOD
| M6811_MDA
))
542 addr
= memory_read16 (cpu
, 0xFFFE);
545 /* Expanded Multiplexed */
547 addr
= memory_read16 (cpu
, 0xFFFE);
550 /* Special Bootstrap */
556 case M6811_MDA
| M6811_SMOD
:
557 addr
= memory_read16 (cpu
, 0xFFFE);
563 addr
= cpu
->cpu_elf_start
;
566 /* Setup the processor registers. */
567 cpu
->cpu_insn_pc
= addr
;
568 cpu
->cpu_regs
.pc
= addr
;
569 cpu
->cpu_regs
.ccr
= M6811_X_BIT
| M6811_I_BIT
| M6811_S_BIT
;
570 cpu
->cpu_absolute_cycle
= 0;
571 cpu
->cpu_is_initialized
= 1;
572 cpu
->cpu_current_cycle
= 0;
574 cpu_call (cpu
, addr
);
580 print_io_reg_desc (SIM_DESC sd
, io_reg_desc
*desc
, int val
, int mode
)
584 if (val
& desc
->mask
)
585 sim_io_printf (sd
, "%s",
586 mode
== 0 ? desc
->short_name
: desc
->long_name
);
592 print_io_byte (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
593 uint8 val
, uint16 addr
)
595 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%02x ", name
, addr
, val
);
597 print_io_reg_desc (sd
, desc
, val
, 0);
601 print_io_word (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
602 uint16 val
, uint16 addr
)
604 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%04x ", name
, addr
, val
);
606 print_io_reg_desc (sd
, desc
, val
, 0);
610 cpu_ccr_update_tst8 (sim_cpu
*cpu
, uint8 val
)
612 cpu_set_ccr_V (cpu
, 0);
613 cpu_set_ccr_N (cpu
, val
& 0x80 ? 1 : 0);
614 cpu_set_ccr_Z (cpu
, val
== 0 ? 1 : 0);
619 cpu_fetch_relbranch (sim_cpu
*cpu
)
621 uint16 addr
= (uint16
) cpu_fetch8 (cpu
);
627 addr
+= cpu
->cpu_regs
.pc
;
632 cpu_fetch_relbranch16 (sim_cpu
*cpu
)
634 uint16 addr
= cpu_fetch16 (cpu
);
636 addr
+= cpu
->cpu_regs
.pc
;
640 /* Push all the CPU registers (when an interruption occurs). */
642 cpu_push_all (sim_cpu
*cpu
)
644 if (cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
646 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.pc
);
647 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.iy
);
648 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.ix
);
649 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.d
);
650 cpu_m68hc11_push_uint8 (cpu
, cpu
->cpu_regs
.ccr
);
654 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.pc
);
655 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.iy
);
656 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.ix
);
657 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.d
);
658 cpu_m68hc12_push_uint8 (cpu
, cpu
->cpu_regs
.ccr
);
662 /* Simulation of the dbcc/ibcc/tbcc 68HC12 conditional branch operations. */
664 cpu_dbcc (sim_cpu
*cpu
)
671 code
= cpu_fetch8 (cpu
);
674 case 0x80: /* ibcc */
677 case 0x40: /* tbcc */
688 addr
= cpu_fetch8 (cpu
);
692 addr
+= cpu_get_pc (cpu
);
693 reg
= cpu_get_src_reg (cpu
, code
& 0x07);
696 /* Branch according to register value. */
697 if ((reg
!= 0 && (code
& 0x20)) || (reg
== 0 && !(code
& 0x20)))
699 cpu_set_pc (cpu
, addr
);
701 cpu_set_dst_reg (cpu
, code
& 0x07, reg
);
705 cpu_exg (sim_cpu
*cpu
, uint8 code
)
711 r1
= (code
>> 4) & 0x07;
715 src1
= cpu_get_src_reg (cpu
, r1
);
716 src2
= cpu_get_src_reg (cpu
, r2
);
717 if (r2
== 1 || r2
== 2)
720 cpu_set_dst_reg (cpu
, r2
, src1
);
721 cpu_set_dst_reg (cpu
, r1
, src2
);
725 src1
= cpu_get_src_reg (cpu
, r1
);
727 /* Sign extend the 8-bit registers (A, B, CCR). */
728 if ((r1
== 0 || r1
== 1 || r1
== 2) && (src1
& 0x80))
731 cpu_set_dst_reg (cpu
, r2
, src1
);
735 /* Handle special instructions. */
737 cpu_special (sim_cpu
*cpu
, enum M6811_Special special
)
745 ccr
= cpu_m68hc11_pop_uint8 (cpu
);
746 cpu_set_ccr (cpu
, ccr
);
747 cpu_set_d (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
748 cpu_set_x (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
749 cpu_set_y (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
750 cpu_set_pc (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
759 ccr
= cpu_m68hc12_pop_uint8 (cpu
);
760 cpu_set_ccr (cpu
, ccr
);
761 cpu_set_d (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
762 cpu_set_x (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
763 cpu_set_y (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
764 cpu_set_pc (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
770 /* In the ELF-start mode, we are in a special mode where
771 the WAI corresponds to an exit. */
772 if (cpu
->cpu_use_elf_start
)
774 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
775 sim_engine_halt (CPU_STATE (cpu
), cpu
,
776 NULL
, NULL_CIA
, sim_exited
,
780 /* SCz: not correct... */
785 interrupts_raise (&cpu
->cpu_interrupts
, M6811_INT_SWI
);
786 interrupts_process (&cpu
->cpu_interrupts
);
789 case M6811_EMUL_SYSCALL
:
791 if (cpu
->cpu_emul_syscall
)
793 uint8 op
= memory_read8 (cpu
,
794 cpu_get_pc (cpu
) - 1);
797 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
798 sim_engine_halt (CPU_STATE (cpu
), cpu
,
799 NULL
, NULL_CIA
, sim_exited
,
810 interrupts_raise (&cpu
->cpu_interrupts
, M6811_INT_ILLEGAL
);
811 interrupts_process (&cpu
->cpu_interrupts
);
819 sd
= CPU_STATE (cpu
);
821 /* Breakpoint instruction if we are under gdb. */
822 if (STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
)
825 sim_engine_halt (CPU_STATE (cpu
), cpu
,
826 0, cpu_get_pc (cpu
), sim_stopped
,
829 /* else this is a nop but not in test factory mode. */
835 int32 src1
= (int16
) cpu_get_d (cpu
);
836 int32 src2
= (int16
) cpu_get_x (cpu
);
840 cpu_set_ccr_C (cpu
, 1);
844 cpu_set_d (cpu
, src1
% src2
);
846 cpu_set_x (cpu
, src1
);
847 cpu_set_ccr_C (cpu
, 0);
848 cpu_set_ccr_Z (cpu
, src1
== 0);
849 cpu_set_ccr_N (cpu
, src1
& 0x8000);
850 cpu_set_ccr_V (cpu
, src1
>= 32768 || src1
< -32768);
857 uint32 src1
= (uint32
) cpu_get_x (cpu
);
858 uint32 src2
= (uint32
) (cpu_get_y (cpu
) << 16)
859 | (uint32
) (cpu_get_d (cpu
));
863 cpu_set_ccr_C (cpu
, 1);
867 cpu_set_ccr_C (cpu
, 0);
868 cpu_set_d (cpu
, src2
% src1
);
870 cpu_set_y (cpu
, src2
);
871 cpu_set_ccr_Z (cpu
, src2
== 0);
872 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
873 cpu_set_ccr_V (cpu
, (src2
& 0xffff0000) != 0);
880 int32 src1
= (int16
) cpu_get_x (cpu
);
881 int32 src2
= (uint32
) (cpu_get_y (cpu
) << 16)
882 | (uint32
) (cpu_get_d (cpu
));
886 cpu_set_ccr_C (cpu
, 1);
890 cpu_set_ccr_C (cpu
, 0);
891 cpu_set_d (cpu
, src2
% src1
);
893 cpu_set_y (cpu
, src2
);
894 cpu_set_ccr_Z (cpu
, src2
== 0);
895 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
896 cpu_set_ccr_V (cpu
, src2
> 32767 || src2
< -32768);
905 src1
= (int16
) cpu_get_d (cpu
);
906 src2
= (int16
) cpu_get_y (cpu
);
908 cpu_set_d (cpu
, src1
& 0x0ffff);
909 cpu_set_y (cpu
, src1
>> 16);
910 cpu_set_ccr_Z (cpu
, src1
== 0);
911 cpu_set_ccr_N (cpu
, (src1
& 0x80000000) != 0);
912 cpu_set_ccr_C (cpu
, (src1
& 0x00008000) != 0);
921 addr
= cpu_fetch16 (cpu
);
922 src1
= (int16
) memory_read16 (cpu
, cpu_get_x (cpu
));
923 src2
= (int16
) memory_read16 (cpu
, cpu_get_y (cpu
));
925 src2
= (((uint32
) memory_read16 (cpu
, addr
)) << 16)
926 | (uint32
) memory_read16 (cpu
, addr
+ 2);
928 memory_write16 (cpu
, addr
, (src1
+ src2
) >> 16);
929 memory_write16 (cpu
, addr
+ 2, (src1
+ src2
));
940 addr
= cpu_fetch16 (cpu
);
941 page
= cpu_fetch8 (cpu
);
943 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
944 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
946 cpu_set_page (cpu
, page
);
947 cpu_set_pc (cpu
, addr
);
951 case M6812_CALL_INDIRECT
:
957 code
= memory_read8 (cpu
, cpu_get_pc (cpu
));
958 /* Indirect addressing call has the page specified in the
959 memory location pointed to by the address. */
960 if ((code
& 0xE3) == 0xE3)
962 addr
= cpu_get_indexed_operand_addr (cpu
, 0);
963 page
= memory_read8 (cpu
, addr
+ 2);
964 addr
= memory_read16 (cpu
, addr
);
968 /* Otherwise, page is in the opcode. */
969 addr
= cpu_get_indexed_operand16 (cpu
, 0);
970 page
= cpu_fetch8 (cpu
);
972 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
973 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
974 cpu_set_page (cpu
, page
);
975 cpu_set_pc (cpu
, addr
);
981 uint8 page
= cpu_m68hc12_pop_uint8 (cpu
);
982 uint16 addr
= cpu_m68hc12_pop_uint16 (cpu
);
984 cpu_set_page (cpu
, page
);
985 cpu_set_pc (cpu
, addr
);
991 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
992 cpu_get_pc (cpu
), sim_stopped
,
1000 cpu_single_step (sim_cpu
*cpu
)
1002 cpu
->cpu_current_cycle
= 0;
1003 cpu
->cpu_insn_pc
= cpu_get_pc (cpu
);
1005 /* Handle the pending interrupts. If an interrupt is handled,
1006 treat this as an single step. */
1007 if (interrupts_process (&cpu
->cpu_interrupts
))
1009 cpu
->cpu_absolute_cycle
+= cpu
->cpu_current_cycle
;
1013 /* printf("PC = 0x%04x\n", cpu_get_pc (cpu));*/
1014 cpu
->cpu_interpretor (cpu
);
1015 cpu
->cpu_absolute_cycle
+= cpu
->cpu_current_cycle
;
1020 sim_memory_error (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1021 uint16 addr
, const char *message
, ...)
1026 va_start (args
, message
);
1027 vsprintf (buf
, message
, args
);
1030 sim_io_printf (CPU_STATE (cpu
), "%s\n", buf
);
1031 cpu_memory_exception (cpu
, excep
, addr
, buf
);
1036 cpu_memory_exception (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1037 uint16 addr
, const char *message
)
1039 if (cpu
->cpu_running
== 0)
1042 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
1043 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
1044 cpu_get_pc (cpu
), sim_stopped
, excep
);
1047 cpu
->mem_exception
= excep
;
1048 cpu
->fault_addr
= addr
;
1049 cpu
->fault_msg
= strdup (message
);
1051 if (cpu
->cpu_use_handler
)
1053 longjmp (&cpu
->cpu_exception_handler
, 1);
1055 (* cpu
->callback
->printf_filtered
)
1056 (cpu
->callback
, "Fault at 0x%04x: %s\n", addr
, message
);
1061 cpu_info (SIM_DESC sd
, sim_cpu
*cpu
)
1063 sim_io_printf (sd
, "CPU info:\n");
1064 sim_io_printf (sd
, " Absolute cycle: %s\n",
1065 cycle_to_string (cpu
, cpu
->cpu_absolute_cycle
,
1066 PRINT_TIME
| PRINT_CYCLE
));
1068 sim_io_printf (sd
, " Syscall emulation: %s\n",
1069 cpu
->cpu_emul_syscall
? "yes, via 0xcd <n>" : "no");
1070 sim_io_printf (sd
, " Memory errors detection: %s\n",
1071 cpu
->cpu_check_memory
? "yes" : "no");
1072 sim_io_printf (sd
, " Stop on interrupt: %s\n",
1073 cpu
->cpu_stop_on_interrupt
? "yes" : "no");