1 /* m6811_cpu.c -- 68HC11&68HC12 CPU Emulation
2 Copyright 1999-2019 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/>. */
21 #include "sim-assert.h"
22 #include "sim-module.h"
23 #include "sim-options.h"
26 OPTION_CPU_RESET
= OPTION_START
,
33 static DECLARE_OPTION_HANDLER (cpu_option_handler
);
35 static const OPTION cpu_options
[] =
37 { {"cpu-reset", no_argument
, NULL
, OPTION_CPU_RESET
},
38 '\0', NULL
, "Reset the CPU",
41 { {"emulos", no_argument
, NULL
, OPTION_EMUL_OS
},
42 '\0', NULL
, "Emulate some OS system calls (read, write, ...)",
45 { {"cpu-config", required_argument
, NULL
, OPTION_CPU_CONFIG
},
46 '\0', NULL
, "Specify the initial CPU configuration register",
49 { {"bootstrap", no_argument
, NULL
, OPTION_CPU_BOOTSTRAP
},
50 '\0', NULL
, "Start the processing in bootstrap mode",
53 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
58 cpu_option_handler (SIM_DESC sd
, sim_cpu
*cpu
,
59 int opt
, char *arg
, int is_command
)
63 cpu
= STATE_CPU (sd
, 0);
66 case OPTION_CPU_RESET
:
71 cpu
->cpu_emul_syscall
= 1;
74 case OPTION_CPU_CONFIG
:
75 if (sscanf(arg
, "0x%x", &val
) == 1
76 || sscanf(arg
, "%d", &val
) == 1)
78 cpu
->cpu_config
= val
;
79 cpu
->cpu_use_local_config
= 1;
82 cpu
->cpu_use_local_config
= 0;
85 case OPTION_CPU_BOOTSTRAP
:
86 cpu
->cpu_start_mode
= "bootstrap";
98 cpu_call (sim_cpu
*cpu
, uint16 addr
)
101 cpu_set_pc (cpu
, addr
);
105 cpu_return (sim_cpu
*cpu
)
109 /* Set the stack pointer and re-compute the current frame. */
111 cpu_set_sp (sim_cpu
*cpu
, uint16 val
)
113 cpu
->cpu_regs
.sp
= val
;
117 cpu_get_reg (sim_cpu
*cpu
, uint8 reg
)
122 return cpu_get_x (cpu
);
125 return cpu_get_y (cpu
);
128 return cpu_get_sp (cpu
);
131 return cpu_get_pc (cpu
);
139 cpu_get_src_reg (sim_cpu
*cpu
, uint8 reg
)
144 return cpu_get_a (cpu
);
147 return cpu_get_b (cpu
);
150 return cpu_get_ccr (cpu
);
153 return cpu_get_tmp3 (cpu
);
156 return cpu_get_d (cpu
);
159 return cpu_get_x (cpu
);
162 return cpu_get_y (cpu
);
165 return cpu_get_sp (cpu
);
173 cpu_set_dst_reg (sim_cpu
*cpu
, uint8 reg
, uint16 val
)
178 cpu_set_a (cpu
, val
);
182 cpu_set_b (cpu
, val
);
186 cpu_set_ccr (cpu
, val
);
190 cpu_set_tmp2 (cpu
, val
);
194 cpu_set_d (cpu
, val
);
198 cpu_set_x (cpu
, val
);
202 cpu_set_y (cpu
, val
);
206 cpu_set_sp (cpu
, val
);
215 cpu_set_reg (sim_cpu
*cpu
, uint8 reg
, uint16 val
)
220 cpu_set_x (cpu
, val
);
224 cpu_set_y (cpu
, val
);
228 cpu_set_sp (cpu
, val
);
232 cpu_set_pc (cpu
, val
);
240 /* Returns the address of a 68HC12 indexed operand.
241 Pre and post modifications are handled on the source register. */
243 cpu_get_indexed_operand_addr (sim_cpu
*cpu
, int restricted
)
250 code
= cpu_fetch8 (cpu
);
252 /* n,r with 5-bit signed constant. */
253 if ((code
& 0x20) == 0)
255 reg
= (code
>> 6) & 3;
256 sval
= (code
& 0x1f);
260 addr
= cpu_get_reg (cpu
, reg
);
264 /* Auto pre/post increment/decrement. */
265 else if ((code
& 0xc0) != 0xc0)
267 reg
= (code
>> 6) & 3;
268 sval
= (code
& 0x0f);
277 addr
= cpu_get_reg (cpu
, reg
);
278 cpu_set_reg (cpu
, reg
, addr
+ sval
);
279 if ((code
& 0x10) == 0)
285 /* [n,r] 16-bits offset indexed indirect. */
286 else if ((code
& 0x07) == 3)
292 reg
= (code
>> 3) & 0x03;
293 addr
= cpu_get_reg (cpu
, reg
);
294 addr
+= cpu_fetch16 (cpu
);
295 addr
= memory_read16 (cpu
, addr
);
296 cpu_add_cycles (cpu
, 1);
298 else if ((code
& 0x4) == 0)
304 reg
= (code
>> 3) & 0x03;
305 addr
= cpu_get_reg (cpu
, reg
);
308 sval
= cpu_fetch16 (cpu
);
309 cpu_add_cycles (cpu
, 1);
313 sval
= cpu_fetch8 (cpu
);
316 cpu_add_cycles (cpu
, 1);
322 reg
= (code
>> 3) & 0x03;
323 addr
= cpu_get_reg (cpu
, reg
);
327 addr
+= cpu_get_a (cpu
);
330 addr
+= cpu_get_b (cpu
);
333 addr
+= cpu_get_d (cpu
);
337 addr
+= cpu_get_d (cpu
);
338 addr
= memory_read16 (cpu
, addr
);
339 cpu_add_cycles (cpu
, 1);
348 cpu_get_indexed_operand8 (sim_cpu
*cpu
, int restricted
)
352 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
353 return memory_read8 (cpu
, addr
);
357 cpu_get_indexed_operand16 (sim_cpu
*cpu
, int restricted
)
361 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
362 return memory_read16 (cpu
, addr
);
366 cpu_move8 (sim_cpu
*cpu
, uint8 code
)
374 src
= cpu_fetch8 (cpu
);
375 addr
= cpu_fetch16 (cpu
);
379 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
380 src
= cpu_fetch8 (cpu
);
384 addr
= cpu_fetch16 (cpu
);
385 src
= memory_read8 (cpu
, addr
);
386 addr
= cpu_fetch16 (cpu
);
390 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
391 src
= memory_read8 (cpu
, cpu_fetch16 (cpu
));
395 src
= cpu_get_indexed_operand8 (cpu
, 1);
396 addr
= cpu_fetch16 (cpu
);
400 src
= cpu_get_indexed_operand8 (cpu
, 1);
401 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
405 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
406 "Invalid code 0x%0x -- internal error?", code
);
409 memory_write8 (cpu
, addr
, src
);
413 cpu_move16 (sim_cpu
*cpu
, uint8 code
)
421 src
= cpu_fetch16 (cpu
);
422 addr
= cpu_fetch16 (cpu
);
426 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
427 src
= cpu_fetch16 (cpu
);
431 addr
= cpu_fetch16 (cpu
);
432 src
= memory_read16 (cpu
, addr
);
433 addr
= cpu_fetch16 (cpu
);
437 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
438 src
= memory_read16 (cpu
, cpu_fetch16 (cpu
));
442 src
= cpu_get_indexed_operand16 (cpu
, 1);
443 addr
= cpu_fetch16 (cpu
);
447 src
= cpu_get_indexed_operand16 (cpu
, 1);
448 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
452 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
453 "Invalid code 0x%0x -- internal error?", code
);
456 memory_write16 (cpu
, addr
, src
);
460 cpu_initialize (SIM_DESC sd
, sim_cpu
*cpu
)
462 sim_add_option_table (sd
, 0, cpu_options
);
464 memset (&cpu
->cpu_regs
, 0, sizeof(cpu
->cpu_regs
));
466 cpu
->cpu_absolute_cycle
= 0;
467 cpu
->cpu_current_cycle
= 0;
468 cpu
->cpu_emul_syscall
= 1;
469 cpu
->cpu_running
= 1;
470 cpu
->cpu_stop_on_interrupt
= 0;
471 cpu
->cpu_frequency
= 8 * 1000 * 1000;
472 cpu
->cpu_use_elf_start
= 0;
473 cpu
->cpu_elf_start
= 0;
474 cpu
->cpu_use_local_config
= 0;
478 cpu
->cpu_config
= M6811_NOSEC
| M6811_NOCOP
| M6811_ROMON
|
480 interrupts_initialize (sd
, cpu
);
482 cpu
->cpu_is_initialized
= 1;
487 /* Reinitialize the processor after a reset. */
489 cpu_reset (sim_cpu
*cpu
)
491 /* Initialize the config register.
492 It is only initialized at reset time. */
493 memset (cpu
->ios
, 0, sizeof (cpu
->ios
));
494 if (cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
495 cpu
->ios
[M6811_INIT
] = 0x1;
497 cpu
->ios
[M6811_INIT
] = 0;
499 /* Output compare registers set to 0xFFFF. */
500 cpu
->ios
[M6811_TOC1_H
] = 0xFF;
501 cpu
->ios
[M6811_TOC1_L
] = 0xFF;
502 cpu
->ios
[M6811_TOC2_H
] = 0xFF;
503 cpu
->ios
[M6811_TOC2_L
] = 0xFF;
504 cpu
->ios
[M6811_TOC3_H
] = 0xFF;
505 cpu
->ios
[M6811_TOC4_L
] = 0xFF;
506 cpu
->ios
[M6811_TOC5_H
] = 0xFF;
507 cpu
->ios
[M6811_TOC5_L
] = 0xFF;
509 /* Setup the processor registers. */
510 memset (&cpu
->cpu_regs
, 0, sizeof(cpu
->cpu_regs
));
511 cpu
->cpu_absolute_cycle
= 0;
512 cpu
->cpu_current_cycle
= 0;
513 cpu
->cpu_is_initialized
= 0;
515 /* Reset interrupts. */
516 interrupts_reset (&cpu
->cpu_interrupts
);
518 /* Reinitialize the CPU operating mode. */
519 cpu
->ios
[M6811_HPRIO
] = cpu
->cpu_mode
;
523 /* Reinitialize the processor after a reset. */
525 cpu_restart (sim_cpu
*cpu
)
529 /* Get CPU starting address depending on the CPU mode. */
530 if (cpu
->cpu_use_elf_start
== 0)
532 switch ((cpu
->ios
[M6811_HPRIO
]) & (M6811_SMOD
| M6811_MDA
))
537 addr
= memory_read16 (cpu
, 0xFFFE);
540 /* Expanded Multiplexed */
542 addr
= memory_read16 (cpu
, 0xFFFE);
545 /* Special Bootstrap */
551 case M6811_MDA
| M6811_SMOD
:
552 addr
= memory_read16 (cpu
, 0xFFFE);
558 addr
= cpu
->cpu_elf_start
;
561 /* Setup the processor registers. */
562 cpu
->cpu_insn_pc
= addr
;
563 cpu
->cpu_regs
.pc
= addr
;
564 cpu
->cpu_regs
.ccr
= M6811_X_BIT
| M6811_I_BIT
| M6811_S_BIT
;
565 cpu
->cpu_absolute_cycle
= 0;
566 cpu
->cpu_is_initialized
= 1;
567 cpu
->cpu_current_cycle
= 0;
569 cpu_call (cpu
, addr
);
575 print_io_reg_desc (SIM_DESC sd
, io_reg_desc
*desc
, int val
, int mode
)
579 if (val
& desc
->mask
)
580 sim_io_printf (sd
, "%s",
581 mode
== 0 ? desc
->short_name
: desc
->long_name
);
587 print_io_byte (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
588 uint8 val
, uint16 addr
)
590 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%02x ", name
, addr
, val
);
592 print_io_reg_desc (sd
, desc
, val
, 0);
596 print_io_word (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
597 uint16 val
, uint16 addr
)
599 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%04x ", name
, addr
, val
);
601 print_io_reg_desc (sd
, desc
, val
, 0);
605 cpu_ccr_update_tst8 (sim_cpu
*cpu
, uint8 val
)
607 cpu_set_ccr_V (cpu
, 0);
608 cpu_set_ccr_N (cpu
, val
& 0x80 ? 1 : 0);
609 cpu_set_ccr_Z (cpu
, val
== 0 ? 1 : 0);
614 cpu_fetch_relbranch (sim_cpu
*cpu
)
616 uint16 addr
= (uint16
) cpu_fetch8 (cpu
);
622 addr
+= cpu
->cpu_regs
.pc
;
627 cpu_fetch_relbranch16 (sim_cpu
*cpu
)
629 uint16 addr
= cpu_fetch16 (cpu
);
631 addr
+= cpu
->cpu_regs
.pc
;
635 /* Push all the CPU registers (when an interruption occurs). */
637 cpu_push_all (sim_cpu
*cpu
)
639 if (cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
641 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.pc
);
642 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.iy
);
643 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.ix
);
644 cpu_m68hc11_push_uint16 (cpu
, cpu
->cpu_regs
.d
);
645 cpu_m68hc11_push_uint8 (cpu
, cpu
->cpu_regs
.ccr
);
649 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.pc
);
650 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.iy
);
651 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.ix
);
652 cpu_m68hc12_push_uint16 (cpu
, cpu
->cpu_regs
.d
);
653 cpu_m68hc12_push_uint8 (cpu
, cpu
->cpu_regs
.ccr
);
657 /* Simulation of the dbcc/ibcc/tbcc 68HC12 conditional branch operations. */
659 cpu_dbcc (sim_cpu
*cpu
)
666 code
= cpu_fetch8 (cpu
);
669 case 0x80: /* ibcc */
672 case 0x40: /* tbcc */
683 addr
= cpu_fetch8 (cpu
);
687 addr
+= cpu_get_pc (cpu
);
688 reg
= cpu_get_src_reg (cpu
, code
& 0x07);
691 /* Branch according to register value. */
692 if ((reg
!= 0 && (code
& 0x20)) || (reg
== 0 && !(code
& 0x20)))
694 cpu_set_pc (cpu
, addr
);
696 cpu_set_dst_reg (cpu
, code
& 0x07, reg
);
700 cpu_exg (sim_cpu
*cpu
, uint8 code
)
706 r1
= (code
>> 4) & 0x07;
710 src1
= cpu_get_src_reg (cpu
, r1
);
711 src2
= cpu_get_src_reg (cpu
, r2
);
712 if (r2
== 1 || r2
== 2)
715 cpu_set_dst_reg (cpu
, r2
, src1
);
716 cpu_set_dst_reg (cpu
, r1
, src2
);
720 src1
= cpu_get_src_reg (cpu
, r1
);
722 /* Sign extend the 8-bit registers (A, B, CCR). */
723 if ((r1
== 0 || r1
== 1 || r1
== 2) && (src1
& 0x80))
726 cpu_set_dst_reg (cpu
, r2
, src1
);
730 /* Handle special instructions. */
732 cpu_special (sim_cpu
*cpu
, enum M6811_Special special
)
740 ccr
= cpu_m68hc11_pop_uint8 (cpu
);
741 cpu_set_ccr (cpu
, ccr
);
742 cpu_set_d (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
743 cpu_set_x (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
744 cpu_set_y (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
745 cpu_set_pc (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
754 ccr
= cpu_m68hc12_pop_uint8 (cpu
);
755 cpu_set_ccr (cpu
, ccr
);
756 cpu_set_d (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
757 cpu_set_x (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
758 cpu_set_y (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
759 cpu_set_pc (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
765 /* In the ELF-start mode, we are in a special mode where
766 the WAI corresponds to an exit. */
767 if (cpu
->cpu_use_elf_start
)
769 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
770 sim_engine_halt (CPU_STATE (cpu
), cpu
,
771 NULL
, NULL_CIA
, sim_exited
,
775 /* SCz: not correct... */
780 interrupts_raise (&cpu
->cpu_interrupts
, M6811_INT_SWI
);
781 interrupts_process (&cpu
->cpu_interrupts
);
784 case M6811_EMUL_SYSCALL
:
786 if (cpu
->cpu_emul_syscall
)
788 uint8 op
= memory_read8 (cpu
,
789 cpu_get_pc (cpu
) - 1);
792 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
793 sim_engine_halt (CPU_STATE (cpu
), cpu
,
794 NULL
, NULL_CIA
, sim_exited
,
805 interrupts_raise (&cpu
->cpu_interrupts
, M6811_INT_ILLEGAL
);
806 interrupts_process (&cpu
->cpu_interrupts
);
814 sd
= CPU_STATE (cpu
);
816 /* Breakpoint instruction if we are under gdb. */
817 if (STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
)
820 sim_engine_halt (CPU_STATE (cpu
), cpu
,
821 0, cpu_get_pc (cpu
), sim_stopped
,
824 /* else this is a nop but not in test factory mode. */
830 int32 src1
= (int16
) cpu_get_d (cpu
);
831 int32 src2
= (int16
) cpu_get_x (cpu
);
835 cpu_set_ccr_C (cpu
, 1);
839 cpu_set_d (cpu
, src1
% src2
);
841 cpu_set_x (cpu
, src1
);
842 cpu_set_ccr_C (cpu
, 0);
843 cpu_set_ccr_Z (cpu
, src1
== 0);
844 cpu_set_ccr_N (cpu
, src1
& 0x8000);
845 cpu_set_ccr_V (cpu
, src1
>= 32768 || src1
< -32768);
852 uint32 src1
= (uint32
) cpu_get_x (cpu
);
853 uint32 src2
= (uint32
) (cpu_get_y (cpu
) << 16)
854 | (uint32
) (cpu_get_d (cpu
));
858 cpu_set_ccr_C (cpu
, 1);
862 cpu_set_ccr_C (cpu
, 0);
863 cpu_set_d (cpu
, src2
% src1
);
865 cpu_set_y (cpu
, src2
);
866 cpu_set_ccr_Z (cpu
, src2
== 0);
867 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
868 cpu_set_ccr_V (cpu
, (src2
& 0xffff0000) != 0);
875 int32 src1
= (int16
) cpu_get_x (cpu
);
876 int32 src2
= (uint32
) (cpu_get_y (cpu
) << 16)
877 | (uint32
) (cpu_get_d (cpu
));
881 cpu_set_ccr_C (cpu
, 1);
885 cpu_set_ccr_C (cpu
, 0);
886 cpu_set_d (cpu
, src2
% src1
);
888 cpu_set_y (cpu
, src2
);
889 cpu_set_ccr_Z (cpu
, src2
== 0);
890 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
891 cpu_set_ccr_V (cpu
, src2
> 32767 || src2
< -32768);
900 src1
= (int16
) cpu_get_d (cpu
);
901 src2
= (int16
) cpu_get_y (cpu
);
903 cpu_set_d (cpu
, src1
& 0x0ffff);
904 cpu_set_y (cpu
, src1
>> 16);
905 cpu_set_ccr_Z (cpu
, src1
== 0);
906 cpu_set_ccr_N (cpu
, (src1
& 0x80000000) != 0);
907 cpu_set_ccr_C (cpu
, (src1
& 0x00008000) != 0);
916 addr
= cpu_fetch16 (cpu
);
917 src1
= (int16
) memory_read16 (cpu
, cpu_get_x (cpu
));
918 src2
= (int16
) memory_read16 (cpu
, cpu_get_y (cpu
));
920 src2
= (((uint32
) memory_read16 (cpu
, addr
)) << 16)
921 | (uint32
) memory_read16 (cpu
, addr
+ 2);
923 memory_write16 (cpu
, addr
, (src1
+ src2
) >> 16);
924 memory_write16 (cpu
, addr
+ 2, (src1
+ src2
));
935 addr
= cpu_fetch16 (cpu
);
936 page
= cpu_fetch8 (cpu
);
938 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
939 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
941 cpu_set_page (cpu
, page
);
942 cpu_set_pc (cpu
, addr
);
946 case M6812_CALL_INDIRECT
:
952 code
= memory_read8 (cpu
, cpu_get_pc (cpu
));
953 /* Indirect addressing call has the page specified in the
954 memory location pointed to by the address. */
955 if ((code
& 0xE3) == 0xE3)
957 addr
= cpu_get_indexed_operand_addr (cpu
, 0);
958 page
= memory_read8 (cpu
, addr
+ 2);
959 addr
= memory_read16 (cpu
, addr
);
963 /* Otherwise, page is in the opcode. */
964 addr
= cpu_get_indexed_operand16 (cpu
, 0);
965 page
= cpu_fetch8 (cpu
);
967 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
968 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
969 cpu_set_page (cpu
, page
);
970 cpu_set_pc (cpu
, addr
);
976 uint8 page
= cpu_m68hc12_pop_uint8 (cpu
);
977 uint16 addr
= cpu_m68hc12_pop_uint16 (cpu
);
979 cpu_set_page (cpu
, page
);
980 cpu_set_pc (cpu
, addr
);
986 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
987 cpu_get_pc (cpu
), sim_stopped
,
995 cpu_single_step (sim_cpu
*cpu
)
997 cpu
->cpu_current_cycle
= 0;
998 cpu
->cpu_insn_pc
= cpu_get_pc (cpu
);
1000 /* Handle the pending interrupts. If an interrupt is handled,
1001 treat this as an single step. */
1002 if (interrupts_process (&cpu
->cpu_interrupts
))
1004 cpu
->cpu_absolute_cycle
+= cpu
->cpu_current_cycle
;
1008 /* printf("PC = 0x%04x\n", cpu_get_pc (cpu));*/
1009 cpu
->cpu_interpretor (cpu
);
1010 cpu
->cpu_absolute_cycle
+= cpu
->cpu_current_cycle
;
1015 sim_memory_error (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1016 uint16 addr
, const char *message
, ...)
1021 va_start (args
, message
);
1022 vsprintf (buf
, message
, args
);
1025 sim_io_printf (CPU_STATE (cpu
), "%s\n", buf
);
1026 cpu_memory_exception (cpu
, excep
, addr
, buf
);
1031 cpu_memory_exception (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1032 uint16 addr
, const char *message
)
1034 if (cpu
->cpu_running
== 0)
1037 cpu_set_pc (cpu
, cpu
->cpu_insn_pc
);
1038 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
1039 cpu_get_pc (cpu
), sim_stopped
, excep
);
1042 cpu
->mem_exception
= excep
;
1043 cpu
->fault_addr
= addr
;
1044 cpu
->fault_msg
= strdup (message
);
1046 if (cpu
->cpu_use_handler
)
1048 longjmp (&cpu
->cpu_exception_handler
, 1);
1050 (* cpu
->callback
->printf_filtered
)
1051 (cpu
->callback
, "Fault at 0x%04x: %s\n", addr
, message
);
1056 cpu_info (SIM_DESC sd
, sim_cpu
*cpu
)
1058 sim_io_printf (sd
, "CPU info:\n");
1059 sim_io_printf (sd
, " Absolute cycle: %s\n",
1060 cycle_to_string (cpu
, cpu
->cpu_absolute_cycle
,
1061 PRINT_TIME
| PRINT_CYCLE
));
1063 sim_io_printf (sd
, " Syscall emulation: %s\n",
1064 cpu
->cpu_emul_syscall
? "yes, via 0xcd <n>" : "no");
1065 sim_io_printf (sd
, " Memory errors detection: %s\n",
1066 cpu
->cpu_check_memory
? "yes" : "no");
1067 sim_io_printf (sd
, " Stop on interrupt: %s\n",
1068 cpu
->cpu_stop_on_interrupt
? "yes" : "no");