1 /* m6811_cpu.c -- 68HC11&68HC12 CPU Emulation
2 Copyright 1999-2024 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. */
26 #include "sim-assert.h"
27 #include "sim-module.h"
28 #include "sim-options.h"
29 #include "sim-signal.h"
31 #include "m68hc11-sim.h"
34 OPTION_CPU_RESET
= OPTION_START
,
41 static DECLARE_OPTION_HANDLER (cpu_option_handler
);
43 static const OPTION cpu_options
[] =
45 { {"cpu-reset", no_argument
, NULL
, OPTION_CPU_RESET
},
46 '\0', NULL
, "Reset the CPU",
49 { {"emulos", no_argument
, NULL
, OPTION_EMUL_OS
},
50 '\0', NULL
, "Emulate some OS system calls (read, write, ...)",
53 { {"cpu-config", required_argument
, NULL
, OPTION_CPU_CONFIG
},
54 '\0', NULL
, "Specify the initial CPU configuration register",
57 { {"bootstrap", no_argument
, NULL
, OPTION_CPU_BOOTSTRAP
},
58 '\0', NULL
, "Start the processing in bootstrap mode",
61 { {NULL
, no_argument
, NULL
, 0}, '\0', NULL
, NULL
, NULL
}
66 cpu_option_handler (SIM_DESC sd
, sim_cpu
*cpu
,
67 int opt
, char *arg
, int is_command
)
69 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
72 cpu
= STATE_CPU (sd
, 0);
75 case OPTION_CPU_RESET
:
80 m68hc11_cpu
->cpu_emul_syscall
= 1;
83 case OPTION_CPU_CONFIG
:
84 if (sscanf(arg
, "0x%x", &val
) == 1
85 || sscanf(arg
, "%d", &val
) == 1)
87 m68hc11_cpu
->cpu_config
= val
;
88 m68hc11_cpu
->cpu_use_local_config
= 1;
91 m68hc11_cpu
->cpu_use_local_config
= 0;
94 case OPTION_CPU_BOOTSTRAP
:
95 m68hc11_cpu
->cpu_start_mode
= "bootstrap";
107 cpu_call (sim_cpu
*cpu
, uint16_t addr
)
110 cpu_set_pc (cpu
, addr
);
114 cpu_return (sim_cpu
*cpu
)
118 /* Set the stack pointer and re-compute the current frame. */
120 cpu_set_sp (sim_cpu
*cpu
, uint16_t val
)
122 M68HC11_SIM_CPU (cpu
)->cpu_regs
.sp
= val
;
126 cpu_get_reg (sim_cpu
*cpu
, uint8_t reg
)
131 return cpu_get_x (cpu
);
134 return cpu_get_y (cpu
);
137 return cpu_get_sp (cpu
);
140 return cpu_get_pc (cpu
);
148 cpu_get_src_reg (sim_cpu
*cpu
, uint8_t reg
)
153 return cpu_get_a (cpu
);
156 return cpu_get_b (cpu
);
159 return cpu_get_ccr (cpu
);
162 return cpu_get_tmp3 (cpu
);
165 return cpu_get_d (cpu
);
168 return cpu_get_x (cpu
);
171 return cpu_get_y (cpu
);
174 return cpu_get_sp (cpu
);
182 cpu_set_dst_reg (sim_cpu
*cpu
, uint8_t reg
, uint16_t val
)
187 cpu_set_a (cpu
, val
);
191 cpu_set_b (cpu
, val
);
195 cpu_set_ccr (cpu
, val
);
199 cpu_set_tmp2 (cpu
, val
);
203 cpu_set_d (cpu
, val
);
207 cpu_set_x (cpu
, val
);
211 cpu_set_y (cpu
, val
);
215 cpu_set_sp (cpu
, val
);
224 cpu_set_reg (sim_cpu
*cpu
, uint8_t reg
, uint16_t val
)
229 cpu_set_x (cpu
, val
);
233 cpu_set_y (cpu
, val
);
237 cpu_set_sp (cpu
, val
);
241 cpu_set_pc (cpu
, val
);
249 /* Returns the address of a 68HC12 indexed operand.
250 Pre and post modifications are handled on the source register. */
252 cpu_get_indexed_operand_addr (sim_cpu
*cpu
, int restricted
)
259 code
= cpu_fetch8 (cpu
);
261 /* n,r with 5-bit signed constant. */
262 if ((code
& 0x20) == 0)
264 reg
= (code
>> 6) & 3;
265 sval
= (code
& 0x1f);
269 addr
= cpu_get_reg (cpu
, reg
);
273 /* Auto pre/post increment/decrement. */
274 else if ((code
& 0xc0) != 0xc0)
276 reg
= (code
>> 6) & 3;
277 sval
= (code
& 0x0f);
286 addr
= cpu_get_reg (cpu
, reg
);
287 cpu_set_reg (cpu
, reg
, addr
+ sval
);
288 if ((code
& 0x10) == 0)
294 /* [n,r] 16-bits offset indexed indirect. */
295 else if ((code
& 0x07) == 3)
301 reg
= (code
>> 3) & 0x03;
302 addr
= cpu_get_reg (cpu
, reg
);
303 addr
+= cpu_fetch16 (cpu
);
304 addr
= memory_read16 (cpu
, addr
);
305 cpu_add_cycles (cpu
, 1);
307 else if ((code
& 0x4) == 0)
313 reg
= (code
>> 3) & 0x03;
314 addr
= cpu_get_reg (cpu
, reg
);
317 sval
= cpu_fetch16 (cpu
);
318 cpu_add_cycles (cpu
, 1);
322 sval
= cpu_fetch8 (cpu
);
325 cpu_add_cycles (cpu
, 1);
331 reg
= (code
>> 3) & 0x03;
332 addr
= cpu_get_reg (cpu
, reg
);
336 addr
+= cpu_get_a (cpu
);
339 addr
+= cpu_get_b (cpu
);
342 addr
+= cpu_get_d (cpu
);
346 addr
+= cpu_get_d (cpu
);
347 addr
= memory_read16 (cpu
, addr
);
348 cpu_add_cycles (cpu
, 1);
357 cpu_get_indexed_operand8 (sim_cpu
*cpu
, int restricted
)
361 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
362 return memory_read8 (cpu
, addr
);
366 cpu_get_indexed_operand16 (sim_cpu
*cpu
, int restricted
)
370 addr
= cpu_get_indexed_operand_addr (cpu
, restricted
);
371 return memory_read16 (cpu
, addr
);
375 cpu_move8 (sim_cpu
*cpu
, uint8_t code
)
383 src
= cpu_fetch8 (cpu
);
384 addr
= cpu_fetch16 (cpu
);
388 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
389 src
= cpu_fetch8 (cpu
);
393 addr
= cpu_fetch16 (cpu
);
394 src
= memory_read8 (cpu
, addr
);
395 addr
= cpu_fetch16 (cpu
);
399 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
400 src
= memory_read8 (cpu
, cpu_fetch16 (cpu
));
404 src
= cpu_get_indexed_operand8 (cpu
, 1);
405 addr
= cpu_fetch16 (cpu
);
409 src
= cpu_get_indexed_operand8 (cpu
, 1);
410 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
414 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
415 "Invalid code 0x%0x -- internal error?", code
);
418 memory_write8 (cpu
, addr
, src
);
422 cpu_move16 (sim_cpu
*cpu
, uint8_t code
)
430 src
= cpu_fetch16 (cpu
);
431 addr
= cpu_fetch16 (cpu
);
435 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
436 src
= cpu_fetch16 (cpu
);
440 addr
= cpu_fetch16 (cpu
);
441 src
= memory_read16 (cpu
, addr
);
442 addr
= cpu_fetch16 (cpu
);
446 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
447 src
= memory_read16 (cpu
, cpu_fetch16 (cpu
));
451 src
= cpu_get_indexed_operand16 (cpu
, 1);
452 addr
= cpu_fetch16 (cpu
);
456 src
= cpu_get_indexed_operand16 (cpu
, 1);
457 addr
= cpu_get_indexed_operand_addr (cpu
, 1);
461 sim_engine_abort (CPU_STATE (cpu
), cpu
, 0,
462 "Invalid code 0x%0x -- internal error?", code
);
465 memory_write16 (cpu
, addr
, src
);
469 cpu_initialize (SIM_DESC sd
, sim_cpu
*cpu
)
471 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
472 sim_add_option_table (sd
, 0, cpu_options
);
474 memset (&m68hc11_cpu
->cpu_regs
, 0, sizeof(m68hc11_cpu
->cpu_regs
));
476 m68hc11_cpu
->cpu_absolute_cycle
= 0;
477 m68hc11_cpu
->cpu_current_cycle
= 0;
478 m68hc11_cpu
->cpu_emul_syscall
= 1;
479 m68hc11_cpu
->cpu_running
= 1;
480 m68hc11_cpu
->cpu_stop_on_interrupt
= 0;
481 m68hc11_cpu
->cpu_frequency
= 8 * 1000 * 1000;
482 m68hc11_cpu
->cpu_use_elf_start
= 0;
483 m68hc11_cpu
->cpu_elf_start
= 0;
484 m68hc11_cpu
->cpu_use_local_config
= 0;
485 m68hc11_cpu
->bank_start
= 0;
486 m68hc11_cpu
->bank_end
= 0;
487 m68hc11_cpu
->bank_shift
= 0;
488 m68hc11_cpu
->cpu_config
= M6811_NOSEC
| M6811_NOCOP
| M6811_ROMON
|
490 interrupts_initialize (sd
, cpu
);
492 m68hc11_cpu
->cpu_is_initialized
= 1;
497 /* Reinitialize the processor after a reset. */
499 cpu_reset (sim_cpu
*cpu
)
501 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
503 /* Initialize the config register.
504 It is only initialized at reset time. */
505 memset (m68hc11_cpu
->ios
, 0, sizeof (m68hc11_cpu
->ios
));
506 if (m68hc11_cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
507 m68hc11_cpu
->ios
[M6811_INIT
] = 0x1;
509 m68hc11_cpu
->ios
[M6811_INIT
] = 0;
511 /* Output compare registers set to 0xFFFF. */
512 m68hc11_cpu
->ios
[M6811_TOC1_H
] = 0xFF;
513 m68hc11_cpu
->ios
[M6811_TOC1_L
] = 0xFF;
514 m68hc11_cpu
->ios
[M6811_TOC2_H
] = 0xFF;
515 m68hc11_cpu
->ios
[M6811_TOC2_L
] = 0xFF;
516 m68hc11_cpu
->ios
[M6811_TOC3_H
] = 0xFF;
517 m68hc11_cpu
->ios
[M6811_TOC4_L
] = 0xFF;
518 m68hc11_cpu
->ios
[M6811_TOC5_H
] = 0xFF;
519 m68hc11_cpu
->ios
[M6811_TOC5_L
] = 0xFF;
521 /* Setup the processor registers. */
522 memset (&m68hc11_cpu
->cpu_regs
, 0, sizeof(m68hc11_cpu
->cpu_regs
));
523 m68hc11_cpu
->cpu_absolute_cycle
= 0;
524 m68hc11_cpu
->cpu_current_cycle
= 0;
525 m68hc11_cpu
->cpu_is_initialized
= 0;
527 /* Reset interrupts. */
528 interrupts_reset (&m68hc11_cpu
->cpu_interrupts
);
530 /* Reinitialize the CPU operating mode. */
531 m68hc11_cpu
->ios
[M6811_HPRIO
] = m68hc11_cpu
->cpu_mode
;
535 /* Reinitialize the processor after a reset. */
537 cpu_restart (sim_cpu
*cpu
)
539 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
542 /* Get CPU starting address depending on the CPU mode. */
543 if (m68hc11_cpu
->cpu_use_elf_start
== 0)
545 switch ((m68hc11_cpu
->ios
[M6811_HPRIO
]) & (M6811_SMOD
| M6811_MDA
))
550 addr
= memory_read16 (cpu
, 0xFFFE);
553 /* Expanded Multiplexed */
555 addr
= memory_read16 (cpu
, 0xFFFE);
558 /* Special Bootstrap */
564 case M6811_MDA
| M6811_SMOD
:
565 addr
= memory_read16 (cpu
, 0xFFFE);
571 addr
= m68hc11_cpu
->cpu_elf_start
;
574 /* Setup the processor registers. */
575 m68hc11_cpu
->cpu_insn_pc
= addr
;
576 m68hc11_cpu
->cpu_regs
.pc
= addr
;
577 m68hc11_cpu
->cpu_regs
.ccr
= M6811_X_BIT
| M6811_I_BIT
| M6811_S_BIT
;
578 m68hc11_cpu
->cpu_absolute_cycle
= 0;
579 m68hc11_cpu
->cpu_is_initialized
= 1;
580 m68hc11_cpu
->cpu_current_cycle
= 0;
582 cpu_call (cpu
, addr
);
588 print_io_reg_desc (SIM_DESC sd
, io_reg_desc
*desc
, int val
, int mode
)
592 if (val
& desc
->mask
)
593 sim_io_printf (sd
, "%s",
594 mode
== 0 ? desc
->short_name
: desc
->long_name
);
600 print_io_byte (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
601 uint8_t val
, uint16_t addr
)
603 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%02x ", name
, addr
, val
);
605 print_io_reg_desc (sd
, desc
, val
, 0);
609 print_io_word (SIM_DESC sd
, const char *name
, io_reg_desc
*desc
,
610 uint16_t val
, uint16_t addr
)
612 sim_io_printf (sd
, " %-9.9s @ 0x%04x 0x%04x ", name
, addr
, val
);
614 print_io_reg_desc (sd
, desc
, val
, 0);
618 cpu_ccr_update_tst8 (sim_cpu
*cpu
, uint8_t val
)
620 cpu_set_ccr_V (cpu
, 0);
621 cpu_set_ccr_N (cpu
, val
& 0x80 ? 1 : 0);
622 cpu_set_ccr_Z (cpu
, val
== 0 ? 1 : 0);
627 cpu_fetch_relbranch (sim_cpu
*cpu
)
629 uint16_t addr
= (uint16_t) cpu_fetch8 (cpu
);
635 addr
+= M68HC11_SIM_CPU (cpu
)->cpu_regs
.pc
;
640 cpu_fetch_relbranch16 (sim_cpu
*cpu
)
642 uint16_t addr
= cpu_fetch16 (cpu
);
644 addr
+= M68HC11_SIM_CPU (cpu
)->cpu_regs
.pc
;
648 /* Push all the CPU registers (when an interruption occurs). */
650 cpu_push_all (sim_cpu
*cpu
)
652 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
654 if (m68hc11_cpu
->cpu_configured_arch
->arch
== bfd_arch_m68hc11
)
656 cpu_m68hc11_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.pc
);
657 cpu_m68hc11_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.iy
);
658 cpu_m68hc11_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.ix
);
659 cpu_m68hc11_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.d
);
660 cpu_m68hc11_push_uint8 (cpu
, m68hc11_cpu
->cpu_regs
.ccr
);
664 cpu_m68hc12_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.pc
);
665 cpu_m68hc12_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.iy
);
666 cpu_m68hc12_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.ix
);
667 cpu_m68hc12_push_uint16 (cpu
, m68hc11_cpu
->cpu_regs
.d
);
668 cpu_m68hc12_push_uint8 (cpu
, m68hc11_cpu
->cpu_regs
.ccr
);
672 /* Simulation of the dbcc/ibcc/tbcc 68HC12 conditional branch operations. */
674 cpu_dbcc (sim_cpu
*cpu
)
681 code
= cpu_fetch8 (cpu
);
684 case 0x80: /* ibcc */
687 case 0x40: /* tbcc */
698 addr
= cpu_fetch8 (cpu
);
702 addr
+= cpu_get_pc (cpu
);
703 reg
= cpu_get_src_reg (cpu
, code
& 0x07);
706 /* Branch according to register value. */
707 if ((reg
!= 0 && (code
& 0x20)) || (reg
== 0 && !(code
& 0x20)))
709 cpu_set_pc (cpu
, addr
);
711 cpu_set_dst_reg (cpu
, code
& 0x07, reg
);
715 cpu_exg (sim_cpu
*cpu
, uint8_t code
)
721 r1
= (code
>> 4) & 0x07;
725 src1
= cpu_get_src_reg (cpu
, r1
);
726 src2
= cpu_get_src_reg (cpu
, r2
);
727 if (r2
== 1 || r2
== 2)
730 cpu_set_dst_reg (cpu
, r2
, src1
);
731 cpu_set_dst_reg (cpu
, r1
, src2
);
735 src1
= cpu_get_src_reg (cpu
, r1
);
737 /* Sign extend the 8-bit registers (A, B, CCR). */
738 if ((r1
== 0 || r1
== 1 || r1
== 2) && (src1
& 0x80))
741 cpu_set_dst_reg (cpu
, r2
, src1
);
745 /* Handle special instructions. */
747 cpu_special (sim_cpu
*cpu
, enum M6811_Special special
)
749 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
757 ccr
= cpu_m68hc11_pop_uint8 (cpu
);
758 cpu_set_ccr (cpu
, ccr
);
759 cpu_set_d (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
760 cpu_set_x (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
761 cpu_set_y (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
762 cpu_set_pc (cpu
, cpu_m68hc11_pop_uint16 (cpu
));
771 ccr
= cpu_m68hc12_pop_uint8 (cpu
);
772 cpu_set_ccr (cpu
, ccr
);
773 cpu_set_d (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
774 cpu_set_x (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
775 cpu_set_y (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
776 cpu_set_pc (cpu
, cpu_m68hc12_pop_uint16 (cpu
));
782 /* In the ELF-start mode, we are in a special mode where
783 the WAI corresponds to an exit. */
784 if (m68hc11_cpu
->cpu_use_elf_start
)
786 cpu_set_pc (cpu
, m68hc11_cpu
->cpu_insn_pc
);
787 sim_engine_halt (CPU_STATE (cpu
), cpu
,
788 NULL
, NULL_CIA
, sim_exited
,
792 /* SCz: not correct... */
797 interrupts_raise (&m68hc11_cpu
->cpu_interrupts
, M6811_INT_SWI
);
798 interrupts_process (&m68hc11_cpu
->cpu_interrupts
);
801 case M6811_EMUL_SYSCALL
:
803 if (m68hc11_cpu
->cpu_emul_syscall
)
805 uint8_t op
= memory_read8 (cpu
,
806 cpu_get_pc (cpu
) - 1);
809 cpu_set_pc (cpu
, m68hc11_cpu
->cpu_insn_pc
);
810 sim_engine_halt (CPU_STATE (cpu
), cpu
,
811 NULL
, NULL_CIA
, sim_exited
,
822 interrupts_raise (&m68hc11_cpu
->cpu_interrupts
, M6811_INT_ILLEGAL
);
823 interrupts_process (&m68hc11_cpu
->cpu_interrupts
);
831 sd
= CPU_STATE (cpu
);
833 /* Breakpoint instruction if we are under gdb. */
834 if (STATE_OPEN_KIND (sd
) == SIM_OPEN_DEBUG
)
836 m68hc11_cpu
->cpu_regs
.pc
--;
837 sim_engine_halt (CPU_STATE (cpu
), cpu
,
838 0, cpu_get_pc (cpu
), sim_stopped
,
841 /* else this is a nop but not in test factory mode. */
847 int32_t src1
= (int16_t) cpu_get_d (cpu
);
848 int32_t src2
= (int16_t) cpu_get_x (cpu
);
852 cpu_set_ccr_C (cpu
, 1);
856 cpu_set_d (cpu
, src1
% src2
);
858 cpu_set_x (cpu
, src1
);
859 cpu_set_ccr_C (cpu
, 0);
860 cpu_set_ccr_Z (cpu
, src1
== 0);
861 cpu_set_ccr_N (cpu
, src1
& 0x8000);
862 cpu_set_ccr_V (cpu
, src1
>= 32768 || src1
< -32768);
869 uint32_t src1
= (uint32_t) cpu_get_x (cpu
);
870 uint32_t src2
= (uint32_t) (cpu_get_y (cpu
) << 16)
871 | (uint32_t) (cpu_get_d (cpu
));
875 cpu_set_ccr_C (cpu
, 1);
879 cpu_set_ccr_C (cpu
, 0);
880 cpu_set_d (cpu
, src2
% src1
);
882 cpu_set_y (cpu
, src2
);
883 cpu_set_ccr_Z (cpu
, src2
== 0);
884 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
885 cpu_set_ccr_V (cpu
, (src2
& 0xffff0000) != 0);
892 int32_t src1
= (int16_t) cpu_get_x (cpu
);
893 int32_t src2
= (uint32_t) (cpu_get_y (cpu
) << 16)
894 | (uint32_t) (cpu_get_d (cpu
));
898 cpu_set_ccr_C (cpu
, 1);
902 cpu_set_ccr_C (cpu
, 0);
903 cpu_set_d (cpu
, src2
% src1
);
905 cpu_set_y (cpu
, src2
);
906 cpu_set_ccr_Z (cpu
, src2
== 0);
907 cpu_set_ccr_N (cpu
, (src2
& 0x8000) != 0);
908 cpu_set_ccr_V (cpu
, src2
> 32767 || src2
< -32768);
917 src1
= (int16_t) cpu_get_d (cpu
);
918 src2
= (int16_t) cpu_get_y (cpu
);
920 cpu_set_d (cpu
, src1
& 0x0ffff);
921 cpu_set_y (cpu
, src1
>> 16);
922 cpu_set_ccr_Z (cpu
, src1
== 0);
923 cpu_set_ccr_N (cpu
, (src1
& 0x80000000) != 0);
924 cpu_set_ccr_C (cpu
, (src1
& 0x00008000) != 0);
933 addr
= cpu_fetch16 (cpu
);
934 src1
= (int16_t) memory_read16 (cpu
, cpu_get_x (cpu
));
935 src2
= (int16_t) memory_read16 (cpu
, cpu_get_y (cpu
));
937 src2
= (((uint32_t) memory_read16 (cpu
, addr
)) << 16)
938 | (uint32_t) memory_read16 (cpu
, addr
+ 2);
940 memory_write16 (cpu
, addr
, (src1
+ src2
) >> 16);
941 memory_write16 (cpu
, addr
+ 2, (src1
+ src2
));
952 addr
= cpu_fetch16 (cpu
);
953 page
= cpu_fetch8 (cpu
);
955 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
956 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
958 cpu_set_page (cpu
, page
);
959 cpu_set_pc (cpu
, addr
);
963 case M6812_CALL_INDIRECT
:
969 code
= memory_read8 (cpu
, cpu_get_pc (cpu
));
970 /* Indirect addressing call has the page specified in the
971 memory location pointed to by the address. */
972 if ((code
& 0xE3) == 0xE3)
974 addr
= cpu_get_indexed_operand_addr (cpu
, 0);
975 page
= memory_read8 (cpu
, addr
+ 2);
976 addr
= memory_read16 (cpu
, addr
);
980 /* Otherwise, page is in the opcode. */
981 addr
= cpu_get_indexed_operand16 (cpu
, 0);
982 page
= cpu_fetch8 (cpu
);
984 cpu_m68hc12_push_uint16 (cpu
, cpu_get_pc (cpu
));
985 cpu_m68hc12_push_uint8 (cpu
, cpu_get_page (cpu
));
986 cpu_set_page (cpu
, page
);
987 cpu_set_pc (cpu
, addr
);
993 uint8_t page
= cpu_m68hc12_pop_uint8 (cpu
);
994 uint16_t addr
= cpu_m68hc12_pop_uint16 (cpu
);
996 cpu_set_page (cpu
, page
);
997 cpu_set_pc (cpu
, addr
);
1003 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
1004 cpu_get_pc (cpu
), sim_stopped
,
1012 cpu_single_step (sim_cpu
*cpu
)
1014 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
1016 m68hc11_cpu
->cpu_current_cycle
= 0;
1017 m68hc11_cpu
->cpu_insn_pc
= cpu_get_pc (cpu
);
1019 /* Handle the pending interrupts. If an interrupt is handled,
1020 treat this as an single step. */
1021 if (interrupts_process (&m68hc11_cpu
->cpu_interrupts
))
1023 m68hc11_cpu
->cpu_absolute_cycle
+= m68hc11_cpu
->cpu_current_cycle
;
1027 /* printf("PC = 0x%04x\n", cpu_get_pc (cpu));*/
1028 m68hc11_cpu
->cpu_interpretor (cpu
);
1029 m68hc11_cpu
->cpu_absolute_cycle
+= m68hc11_cpu
->cpu_current_cycle
;
1034 sim_memory_error (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1035 uint16_t addr
, const char *message
, ...)
1040 va_start (args
, message
);
1041 vsprintf (buf
, message
, args
);
1044 sim_io_printf (CPU_STATE (cpu
), "%s\n", buf
);
1045 cpu_memory_exception (cpu
, excep
, addr
, buf
);
1050 cpu_memory_exception (sim_cpu
*cpu
, SIM_SIGNAL excep
,
1051 uint16_t addr
, const char *message
)
1053 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
1055 if (m68hc11_cpu
->cpu_running
== 0)
1058 cpu_set_pc (cpu
, m68hc11_cpu
->cpu_insn_pc
);
1059 sim_engine_halt (CPU_STATE (cpu
), cpu
, NULL
,
1060 cpu_get_pc (cpu
), sim_stopped
, excep
);
1063 m68hc11_cpu
->mem_exception
= excep
;
1064 m68hc11_cpu
->fault_addr
= addr
;
1065 m68hc11_cpu
->fault_msg
= strdup (message
);
1067 if (m68hc11_cpu
->cpu_use_handler
)
1069 longjmp (&m68hc11_cpu
->cpu_exception_handler
, 1);
1071 (* m68hc11_cpu
->callback
->printf_filtered
)
1072 (m68hc11_cpu
->callback
, "Fault at 0x%04x: %s\n", addr
, message
);
1077 cpu_info (SIM_DESC sd
, sim_cpu
*cpu
)
1079 struct m68hc11_sim_cpu
*m68hc11_cpu
= M68HC11_SIM_CPU (cpu
);
1081 sim_io_printf (sd
, "CPU info:\n");
1082 sim_io_printf (sd
, " Absolute cycle: %s\n",
1083 cycle_to_string (cpu
, m68hc11_cpu
->cpu_absolute_cycle
,
1084 PRINT_TIME
| PRINT_CYCLE
));
1086 sim_io_printf (sd
, " Syscall emulation: %s\n",
1087 m68hc11_cpu
->cpu_emul_syscall
? "yes, via 0xcd <n>" : "no");
1088 sim_io_printf (sd
, " Memory errors detection: %s\n",
1089 m68hc11_cpu
->cpu_check_memory
? "yes" : "no");
1090 sim_io_printf (sd
, " Stop on interrupt: %s\n",
1091 m68hc11_cpu
->cpu_stop_on_interrupt
? "yes" : "no");