• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision7a290b65f23f670a3fd137e69b437ee77b780c64 (tree)
Time2019-06-02 23:44:26
AuthorYoshinori Sato <ysato@user...>
CommiterYoshinori Sato

Log Message

WIP: mov

Change Summary

Incremental Difference

--- a/arch_init.c
+++ b/arch_init.c
@@ -52,6 +52,8 @@ int graphic_depth = 32;
5252 #define QEMU_ARCH QEMU_ARCH_ARM
5353 #elif defined(TARGET_CRIS)
5454 #define QEMU_ARCH QEMU_ARCH_CRIS
55+#elif defined(TARGET_H8300)
56+#define QEMU_ARCH QEMU_ARCH_H8300
5557 #elif defined(TARGET_HPPA)
5658 #define QEMU_ARCH QEMU_ARCH_HPPA
5759 #elif defined(TARGET_I386)
--- a/hw/Kconfig
+++ b/hw/Kconfig
@@ -42,6 +42,7 @@ source watchdog/Kconfig
4242 source arm/Kconfig
4343 source alpha/Kconfig
4444 source cris/Kconfig
45+source h8300/Kconfig
4546 source hppa/Kconfig
4647 source i386/Kconfig
4748 source lm32/Kconfig
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -26,6 +26,7 @@ enum {
2626 QEMU_ARCH_HPPA = (1 << 18),
2727 QEMU_ARCH_RISCV = (1 << 19),
2828 QEMU_ARCH_RX = (1 << 20),
29+ QEMU_ARCH_H8300 = (1 << 21),
2930 };
3031
3132 extern const uint32_t arch_type;
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -177,10 +177,13 @@ class Field:
177177 return str(self.pos) + ':' + s + str(self.len)
178178
179179 def str_extract(self):
180- if self.sign:
181- extr = 'sextract32'
180+ if self.pos == 0 and self.len ==0:
181+ extr = 'dummy'
182182 else:
183- extr = 'extract32'
183+ if self.sign:
184+ extr = 'sextract32'
185+ else:
186+ extr = 'extract32'
184187 return '{0}(insn, {1}, {2})'.format(extr, self.pos, self.len)
185188
186189 def __eq__(self, other):
--- a/target/h8300/cpu.c
+++ b/target/h8300/cpu.c
@@ -49,19 +49,19 @@ static void h8300_cpu_reset(CPUState *s)
4949 {
5050 H8300CPU *cpu = H8300CPU(s);
5151 H8300CPUClass *rcc = H8300CPU_GET_CLASS(cpu);
52- CPURXState *env = &cpu->env;
52+ CPUH8300State *env = &cpu->env;
5353 uint32_t *resetvec;
5454
5555 rcc->parent_reset(s);
5656
57- memset(env, 0, offsetof(CPURXState, end_reset_fields));
57+ memset(env, 0, offsetof(CPUH8300State, end_reset_fields));
5858
5959 resetvec = rom_ptr(0x000000, 4);
6060 if (resetvec) {
6161 /* In the case of kernel, it is ignored because it is not set. */
6262 env->pc = ldl_p(resetvec);
6363 }
64- h8300_cpu_unpack_psw(env, 0);
64+ h8300_cpu_unpack_ccr(env, 0x80);
6565 }
6666
6767 static void h8300_cpu_list_entry(gpointer data, gpointer user_data)
@@ -121,7 +121,7 @@ static void h8300_cpu_set_irq(void *opaque, int no, int request)
121121
122122 if (irq) {
123123 cpu->env.req_irq = irq;
124- cpu->env.req_ipl = (request >> 8) & 0x03;
124+ cpu->env.req_pri = (request >> 8) & 0x03;
125125 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
126126 } else {
127127 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
@@ -138,7 +138,7 @@ static void h8300_cpu_init(Object *obj)
138138 {
139139 CPUState *cs = CPU(obj);
140140 H8300CPU *cpu = H8300CPU(obj);
141- CPURXState *env = &cpu->env;
141+ CPUH8300State *env = &cpu->env;
142142
143143 cs->env_ptr = env;
144144 qdev_init_gpio_in(DEVICE(cpu), h8300_cpu_set_irq, 1);
@@ -208,6 +208,8 @@ type_init(rxcpu_register_types)
208208
209209 static uint32_t extable[64];
210210
211+#define IRAMTOP 0xffbf20
212+
211213 void h8300_load_image(H8300CPU *cpu, const char *filename,
212214 uint32_t start, uint32_t size)
213215 {
--- a/target/h8300/cpu.h
+++ b/target/h8300/cpu.h
@@ -24,14 +24,14 @@
2424 #include "hw/registerfields.h"
2525 #include "qom/cpu.h"
2626
27-#define TYPE_RXCPU "h8300cpu"
27+#define TYPE_H8300CPU "h8300cpu"
2828
29-#define RXCPU_CLASS(klass) \
30- OBJECT_CLASS_CHECK(RXCPUClass, (klass), TYPE_RXCPU)
31-#define RXCPU(obj) \
32- OBJECT_CHECK(RXCPU, (obj), TYPE_RXCPU)
33-#define RXCPU_GET_CLASS(obj) \
34- OBJECT_GET_CLASS(RXCPUClass, (obj), TYPE_RXCPU)
29+#define H8300CPU_CLASS(klass) \
30+ OBJECT_CLASS_CHECK(H8300CPUClass, (klass), TYPE_H8300CPU)
31+#define H8300CPU(obj) \
32+ OBJECT_CHECK(H8300CPU, (obj), TYPE_H8300CPU)
33+#define H8300CPU_GET_CLASS(obj) \
34+ OBJECT_GET_CLASS(H8300CPUClass, (obj), TYPE_H8300CPU)
3535
3636 /*
3737 * H8300CPUClass:
@@ -62,15 +62,23 @@ typedef struct H8300CPUClass {
6262
6363 /* CCR define */
6464 REG8(CCR, 0)
65-FIELD(PSW, C, 0, 1)
66-FIELD(PSW, V, 1, 1)
67-FIELD(PSW, Z, 2, 1)
68-FIELD(PSW, N, 3, 1)
69-FIELD(PSW, U, 4, 1)
70-FIELD(PSW, H, 5, 1)
71-FIELD(PSW, UI, 6, 1)
72-FIELD(PSW, I, 7, 4)
73-
65+FIELD(CCR, C, 0, 1)
66+FIELD(CCR, V, 1, 1)
67+FIELD(CCR, Z, 2, 1)
68+FIELD(CCR, N, 3, 1)
69+FIELD(CCR, U, 4, 1)
70+FIELD(CCR, H, 5, 1)
71+FIELD(CCR, UI, 6, 1)
72+FIELD(CCR, I, 7, 1)
73+
74+/* SYSCR */
75+REG8(SYSCR, 0)
76+FIELD(SYSCR, RAME, 0, 1)
77+FIELD(SYSCR, SSOE, 1, 1)
78+FIELD(SYSCR, NMIEG, 2, 1)
79+FIELD(SYSCR, UE, 3, 1)
80+FIELD(SYSCR, STS, 4, 3)
81+FIELD(SYSCR, SSBY, 7, 1)
7482
7583 #define NB_MMU_MODES 1
7684 #define MMU_MODE0_SUFFIX _all
@@ -82,14 +90,14 @@ enum {
8290 typedef struct CPUH8300State {
8391 /* CPU registers */
8492 uint32_t regs[NUM_REGS]; /* general registers */
85- uint32_t psw_c; /* O bit of status register */
86- uint32_t psw_v; /* S bit of status register */
87- uint32_t psw_z; /* Z bit of status register */
88- uint32_t psw_n; /* C bit of status register */
89- uint32_t psw_u;
90- uint32_t psw_h;
91- uint32_t psw_ui;
92- uint32_t psw_i;
93+ uint32_t ccr_c; /* C bit of status register */
94+ uint32_t ccr_v; /* V bit of status register */
95+ uint32_t ccr_z; /* Z bit of status register */
96+ uint32_t ccr_n; /* N bit of status register */
97+ uint32_t ccr_u;
98+ uint32_t ccr_h;
99+ uint32_t ccr_ui;
100+ uint32_t ccr_i;
93101 uint32_t pc; /* program counter */
94102
95103 /* Fields up to this point are cleared by a CPU reset */
@@ -98,9 +106,9 @@ typedef struct CPUH8300State {
98106 /* Internal use */
99107 uint32_t in_sleep;
100108 uint32_t req_irq; /* Requested interrupt no (hard) */
101- uint32_t req_ipl; /* Requested interrupt level */
102109 uint32_t ack_irq; /* execute irq */
103- uint32_t ack_ipl; /* execute ipl */
110+ uint32_t req_pri;
111+ uint8_t syscr;
104112 qemu_irq ack; /* Interrupt acknowledge */
105113
106114 CPU_COMMON
@@ -112,7 +120,7 @@ typedef struct CPUH8300State {
112120 *
113121 * A H8300 CPU
114122 */
115-struct H830CPU {
123+struct H8300CPU {
116124 /*< private >*/
117125 CPUState parent_obj;
118126 /*< public >*/
@@ -131,8 +139,8 @@ static inline H8300CPU *h8300_env_get_cpu(CPUH8300State *env)
131139
132140 #define ENV_OFFSET offsetof(H8300CPU, env)
133141
134-#define RX_CPU_TYPE_SUFFIX "-" TYPE_H8300CPU
135-#define RX_CPU_TYPE_NAME(model) model H8300_CPU_TYPE_SUFFIX
142+#define H8300_CPU_TYPE_SUFFIX "-" TYPE_H8300CPU
143+#define H8300_CPU_TYPE_NAME(model) model H8300_CPU_TYPE_SUFFIX
136144 #define CPU_RESOLVING_TYPE TYPE_H8300CPU
137145
138146 void h8300_cpu_do_interrupt(CPUState *cpu);
@@ -147,9 +155,9 @@ int cpu_h8300_signal_handler(int host_signum, void *pinfo,
147155 void *puc);
148156
149157 void h8300_cpu_list(void);
150-void h8300_load_image(RXCPU *cpu, const char *filename,
158+void h8300_load_image(H8300CPU *cpu, const char *filename,
151159 uint32_t start, uint32_t size);
152-void h8300_cpu_unpack_psw(CPURXState *env, uint32_t psw, int rte);
160+void h8300_cpu_unpack_ccr(CPUH8300State *env, uint32_t psw);
153161
154162 #define cpu_signal_handler cpu_h8300_signal_handler
155163 #define cpu_list h8300_cpu_list
@@ -160,7 +168,7 @@ void h8300_cpu_unpack_psw(CPURXState *env, uint32_t psw, int rte);
160168
161169 #define H8300_CPU_IRQ 0
162170
163-static inline void cpu_get_tb_cpu_state(CPURXState *env, target_ulong *pc,
171+static inline void cpu_get_tb_cpu_state(CPUH8300State *env, target_ulong *pc,
164172 target_ulong *cs_base, uint32_t *flags)
165173 {
166174 *pc = env->pc;
@@ -168,12 +176,12 @@ static inline void cpu_get_tb_cpu_state(CPURXState *env, target_ulong *pc,
168176 *flags = 0;
169177 }
170178
171-static inline int cpu_mmu_index(CPURXState *env, bool ifetch)
179+static inline int cpu_mmu_index(CPUH8300State *env, bool ifetch)
172180 {
173181 return 0;
174182 }
175183
176-static inline uint32_t h8300_cpu_pack_ccr(CPURXState *env)
184+static inline uint32_t h8300_cpu_pack_ccr(CPUH8300State *env)
177185 {
178186 uint32_t ccr = 0;
179187 ccr = FIELD_DP32(ccr, CCR, I, env->ccr_i);
--- a/target/h8300/helper.h
+++ b/target/h8300/helper.h
@@ -9,3 +9,5 @@ DEF_HELPER_FLAGS_2(daa, TCG_CALL_NO_WG, i32, env, i32)
99 DEF_HELPER_FLAGS_2(das, TCG_CALL_NO_WG, i32, env, i32)
1010 DEF_HELPER_1(eepmovb, void, env)
1111 DEF_HELPER_1(eepmovw, void, env)
12+DEF_HELPER_1(sim_write, void, env)
13+DEF_HELPER_1(dump, void, i32)
--- a/target/h8300/insns.decode
+++ b/target/h8300/insns.decode
@@ -18,10 +18,12 @@
1818 #
1919
2020 &i imm
21-&ri rd imm sz
21+&ri r imm sz
22+&rdi rd imm sz
23+&eri er imm
2224 &rr rs rd sz
2325 &ai abs imm
24-&cd cc dsp
26+&cd cd dsp
2527 &rn rd rn
2628 &an abs rn
2729 &r r sz
@@ -34,47 +36,47 @@
3436 %imm32 0:0 !function=imm32
3537 %dsp16 0:0 !function=dsp16
3638 %dsp24 0:0 !function=dsp24
39+%dsp24l 0:0 !function=dsp24l
3740 %abs16 0:0 !function=abs16
3841 %abs24 0:0 !function=abs24
3942 %b10_er 0:0 !function=b10_er
4043 %b10_ldst 0:0 !function=b10_ldst
4144
42-@b2_imm .... .... imm:8 &i
43-@b2_r_imm .... rd:4 imm:8 &ri sz=0
45+@b2_imm .... .... imm:s8 &i
46+@b2_r_imm .... rd:4 imm:s8 &rdi sz=0
4447 @b2_rs_rd .... .... rs:4 rd:4 &rr
45-@b2_adds .... .... .... 0 rd:3 &ri sz=2
48+@b2_adds .... .... .... 0 rd:3 &rdi sz=2
4649 @b2_ers_erd .... .... 1 rs:3 0 rd:3 &rr
4750 @b2_er_r .... .... . er:3 r:4 &rrdsp
48-@b2_bop_r .... .... . imm:3 rd:4 &ri sz=0
49-@b2_bcc .... cc:4 dsp:s8 &cd
50-@b2_idb .... .... .... rd:4 &ri
51-@b2_idw .... .... .... rd:4 &ri
52-@b2_idl .... .... .... 0 rd:3 &ri
51+@b2_bop_r .... .... . imm:3 r:4 &ri sz=0
52+@b2_bcc .... cd:4 dsp:s8 &cd
53+@b2_idb .... .... .... rd:4 &rdi
54+@b2_idw .... .... .... rd:4 &rdi
55+@b2_idl .... .... .... 0 rd:3 &rdi
5356 @b2_r .... .... .... r:4 &r
5457 @b2_rs_erd .... .... rs:4 0 rd:3 &rr
5558 @b2_er .... .... .... 0 r:3 &r
5659 @b2_r_abs .... r:4 abs:8 &rabs
57-@b4_rd_imm .... .... .... rd:4 imm:16 &ri sz=1
60+@b4_rd_imm .... .... .... rd:4 imm:s16 &rdi sz=1
5861 @b4_ers_erd .... .... .... .... .... .... . rs:3 0 rd:3 &rr sz=2
5962 @b4_ers_erd_d .... .... .... .... .... .... . er:3 0 r:3 &rrdsp sz=2 dsp=0
60-@b4_bop_m .... .... 0 rd:3 .... .... .... . imm:3 .... &ri sz=0
63+@b4_bop_m .... .... 0 er:3 .... .... .... . imm:3 .... &eri
6164 @b4_bop_a .... .... abs:8 .... .... . imm:3 .... &ai
62-@b4_bcc .... .... cc:4 .... dsp:s16 &cd
65+@b4_bcc .... .... cd:4 .... dsp:s16 &cd
6366 @b4_rn_rd .... .... 0 rd:3 .... .... .... rn:4 .... &rn
6467 @b4_rn_a .... .... abs:8 .... .... rn:4 .... &an
6568 @b4_rs_rd .... .... .... .... .... .... rs:4 rd:4 &rr
6669 @b4_rs_erd .... .... .... .... .... .... rs:4 0 rd:3 &rr
6770 @b4_er .... .... .... .... .... .... . r:3 .... &rdsp dsp=0
68-@b4_er_p .... .... .... .... .... .... .... 0 r:3 &r
6971 @b4_r_abs .... .... .... r:4 abs:16 &rabs
70-@b6_rd_imm .... .... .... 0 rd:3 &ri imm=%imm32 sz=2
72+@b6_rd_imm .... .... .... 0 rd:3 &rdi imm=%imm32 sz=2
7173 @b6_er16 .... .... .... .... .... .... . r:3 .... &rdsp dsp=%dsp16
7274 @b6_abs16 .... .... .... .... .... .... .... .... &abs abs=%abs16
7375 @b6_r_abs .... .... .... r:4 &rabs abs=%abs24
7476 @b6_er_abs .... .... .... .... .... .... .... 0 r:3 &rabs abs=%abs16
7577 @b6_ers_erd .... .... .... .... .... .... . er:3 0 r:3 &rrdsp sz=2 dsp=%dsp16
7678 @b10_er24 .... .... .... .... .... .... 0 r:3 .... &ldstccr ldst=%b10_ldst dsp=%dsp24
77-@b10_ers_erd .... .... .... .... .... .... . er:3 0000 &rrdsp sz=2 r=%b10_er dsp=%dsp24
79+@b10_ers_erd .... .... .... .... .... .... . er:3 0000 &rrdsp sz=2 r=%b10_er dsp=%dsp24l
7880 @b8_abs24 .... .... .... .... .... .... .... .... &abs abs=%abs24
7981 @b8_er_r .... .... 0 er:3 .... .... .... .... r:4 &rrdsp
8082 @b8_er_abs .... .... .... .... .... .... .... 0 r:3 &rabs abs=%abs24
@@ -137,7 +139,7 @@ BAND_a 0111 1110 .... .... 0111 0110 0 ... 0000 @b4_bop_a
137139 # BLT d:8
138140 # BGT d:8
139141 # BLE d:8
140-Bcc_B 0100 .... .... .... @b2_bcc
142+Bcc 0100 .... .... .... @b2_bcc
141143 # BRA d:16
142144 # BRN d:16
143145 # BHI d:16
@@ -154,7 +156,7 @@ Bcc_B 0100 .... .... .... @b2_bcc
154156 # BLT d:16
155157 # BGT d:16
156158 # BLE d:16
157-Bcc_W 0101 1000 .... 0000 .... .... .... .... @b4_bcc
159+Bcc 0101 1000 .... 0000 .... .... .... .... @b4_bcc
158160 # BCLR #xx:3,Rd
159161 BCLR_ir 0111 0010 0... .... @b2_bop_r
160162 # BCLR #xx:3,@ERd
@@ -234,9 +236,9 @@ BSET_rm 0111 1101 .... 0000 0110 0000 .... 0000 @b4_rn_rd
234236 # BSET Rn,@aa:8
235237 BSET_ra 0111 1111 .... .... 0110 0000 .... 0000 @b4_rn_a
236238 # BSR d:8
237-BSR_b 0101 0101 dsp:8
239+BSR 0101 0101 dsp:s8
238240 # BSR d:16
239-BSR_w 0101 1100 0000 0000 dsp:16
241+BSR 0101 1100 0000 0000 dsp:s16
240242 # BST #xx:3,Rd
241243 BST_r 0110 0111 0 ... .... @b2_bop_r
242244 # BST #xx:3,@ERd
@@ -297,7 +299,7 @@ DIVXU 0101 0001 .... .... @b2_rs_rd sz=0
297299 DIVXU 0101 0011 .... .... @b2_rs_erd sz=1
298300 # EEPMOV.B
299301 EEPMOV_B 0111 1011 0101 1100 0101 1001 1000 1111
300-EEPMOV.W 0111 1011 1101 0100 0101 1001 1000 1111
302+EEPMOV_W 0111 1011 1101 0100 0101 1001 1000 1111
301303 # EXTS.W Rd
302304 EXTS 0001 0111 1101 .... @b2_r sz=1
303305 # EXTS.L ERd
@@ -392,7 +394,7 @@ MOV_mpr 0110 1101 0 ... .... @b2_er_r dsp=0 sz=1
392394 # MOV.W @aa:16,Rd
393395 MOV_ar 0110 1011 0000 .... .... .... .... .... @b4_r_abs sz=1 a=16
394396 # MOV.W @aa:24,Rd
395-MOV_ar 0001 1011 0010 .... @b6_r_abs sz=0 a=24
397+MOV_ar 0110 1011 0010 .... @b6_r_abs sz=0 a=24
396398 # MOV.W Rs,@ERd
397399 MOV_rm 0110 1001 1 ... .... @b2_er_r dsp=0 sz=1
398400 # MOV.W Rs,@(d:16,ERd)
@@ -434,7 +436,7 @@ MOV_ra 0000 0001 0000 0000 0110 1011 1000 .... @b6_er_abs sz=2 a=16
434436 # MOV.L ERs,@aa:24
435437 MOV_ra 0000 0001 0000 0000 0110 1011 1010 .... @b8_er_abs sz=2 a=24
436438 # MOVFPE @aa:16,Rd
437-MOVVPE 0110 1010 0100 .... .... .... .... .... @b4_r_abs a=16 sz=0
439+MOVFPE 0110 1010 0100 .... .... .... .... .... @b4_r_abs a=16 sz=0
438440 # MOVTPE Rs,@aa:16
439441 MOVTPE 0110 1010 1100 .... .... .... .... .... @b4_r_abs a=16 sz=0
440442 # MULXS.B Rs,Rd
@@ -476,55 +478,55 @@ ORC 0000 0100 .... .... @b2_imm
476478 # ROTL.B Rd
477479 ROTL 0001 0010 1000 .... @b2_r sz=0
478480 # ROTL.W Rd
479-ROTL_W 0001 0010 1001 .... @b2_r sz=1
481+ROTL 0001 0010 1001 .... @b2_r sz=1
480482 # ROTL.L ERd
481-ROTL_L 0001 0010 1011 .... @b2_er sz=2
483+ROTL 0001 0010 1011 .... @b2_er sz=2
482484 # ROTR.B Rd
483-ROTR_B 0001 0011 1000 .... @b2_r sz=0
485+ROTR 0001 0011 1000 .... @b2_r sz=0
484486 # ROTR.W Rd
485-ROTR_W 0001 0011 1001 .... @b2_r sz=1
487+ROTR 0001 0011 1001 .... @b2_r sz=1
486488 # ROTR.L ERd
487-ROTR_L 0001 0011 1011 .... @b2_er sz=2
489+ROTR 0001 0011 1011 .... @b2_er sz=2
488490 # ROTXL.B Rd
489-ROTXL_B 0001 0010 0000 .... @b2_r sz=0
491+ROTXL 0001 0010 0000 .... @b2_r sz=0
490492 # ROTXL.W Rd
491-ROTXL_W 0001 0010 0001 .... @b2_r sz=1
493+ROTXL 0001 0010 0001 .... @b2_r sz=1
492494 # ROTXL.L ERd
493-ROTXL_L 0001 0010 0011 .... @b2_er sz=2
495+ROTXL 0001 0010 0011 .... @b2_er sz=2
494496 # ROTXR.B Rd
495-ROTXR_B 0001 0011 0000 .... @b2_r sz=0
497+ROTXR 0001 0011 0000 .... @b2_r sz=0
496498 # ROTXR.W Rd
497-ROTXR_W 0001 0011 0001 .... @b2_r sz=1
499+ROTXR 0001 0011 0001 .... @b2_r sz=1
498500 # ROTXR.L ERd
499-ROTXWR_L 0001 0011 0011 .... @b2_er sz=2
501+ROTXR 0001 0011 0011 .... @b2_er sz=2
500502 # RTE
501503 RTE 0101 0110 0111 0000
502504 # RTS
503505 RTS 0101 0100 0111 0000
504506 # SHAL.B Rd
505-SHAL_B 0001 0000 1000 .... @b2_r sz=0
507+SHAL 0001 0000 1000 .... @b2_r sz=0
506508 # SHAL.W Rd
507-SHAL_W 0001 0000 1001 .... @b2_r sz=1
509+SHAL 0001 0000 1001 .... @b2_r sz=1
508510 # SHAL.L ERd
509-SHAL_L 0001 0000 1011 .... @b2_er sz=2
511+SHAL 0001 0000 1011 .... @b2_er sz=2
510512 # SHAR.B Rd
511-SHAR_B 0001 0001 1000 .... @b2_r sz=0
513+SHAR 0001 0001 1000 .... @b2_r sz=0
512514 # SHAR.W Rd
513-SHAR_W 0001 0001 1001 .... @b2_r sz=1
515+SHAR 0001 0001 1001 .... @b2_r sz=1
514516 # SHAR.L ERd
515-SHAR_L 0001 0001 1011 .... @b2_er sz=2
517+SHAR 0001 0001 1011 .... @b2_er sz=2
516518 # SHLL.B Rd
517-SHLL_B 0001 0000 0000 .... @b2_r sz=0
519+SHLL 0001 0000 0000 .... @b2_r sz=0
518520 # SHLL.W Rd
519-SHLL_W 0001 0000 0001 .... @b2_r sz=1
521+SHLL 0001 0000 0001 .... @b2_r sz=1
520522 # SHLL.L ERd
521-SHLL_L 0001 0000 0011 .... @b2_er sz=2
523+SHLL 0001 0000 0011 .... @b2_er sz=2
522524 # SHLR.B Rd
523-SHLR_B 0001 0001 0000 .... @b2_r sz=0
525+SHLR 0001 0001 0000 .... @b2_r sz=0
524526 # SHLR.W Rd
525-SHLR_W 0001 0001 0001 .... @b2_r sz=1
527+SHLR 0001 0001 0001 .... @b2_r sz=1
526528 # SHLR.L ERd
527-SHLR_L 0001 0001 0011 .... @b2_er sz=2
529+SHLR 0001 0001 0011 .... @b2_er sz=2
528530 # SLEEP
529531 SLEEP 0000 0001 1000 0000
530532 # STC CCR,Rd
@@ -552,9 +554,9 @@ SUB_r 0001 1010 .... .... @b2_ers_erd sz=2
552554 # SUBS #1,ERd
553555 SUBS 0001 1011 0000 .... @b2_adds imm=1
554556 # SUBS #2,ERd
555-SUBS_2 0001 1011 1000 .... @b2_adds imm=2
557+SUBS 0001 1011 1000 .... @b2_adds imm=2
556558 # SUBS #4,ERd
557-SUBS_4 0001 1011 1001 .... @b2_adds imm=4
559+SUBS 0001 1011 1001 .... @b2_adds imm=4
558560 # SUBX #xx:8,Rd
559561 SUBX_i 1011 .... .... .... @b2_r_imm
560562 # SUBX Rs,Rd
--- a/target/h8300/op_helper.c
+++ b/target/h8300/op_helper.c
@@ -24,9 +24,6 @@
2424 #include "exec/cpu_ldst.h"
2525 #include "fpu/softfloat.h"
2626
27-static inline void QEMU_NORETURN raise_exception(CPURXState *env, int index,
28- uintptr_t retaddr);
29-
3027 void helper_set_ccr(CPUH8300State *env, uint32_t ccr)
3128 {
3229 h8300_cpu_unpack_ccr(env, ccr);
@@ -34,7 +31,7 @@ void helper_set_ccr(CPUH8300State *env, uint32_t ccr)
3431
3532 uint32_t helper_get_ccr(CPUH8300State *env)
3633 {
37- return h8300_cpu_pack_psw(env);
34+ return h8300_cpu_pack_ccr(env);
3835 }
3936
4037 /* div */
@@ -122,11 +119,11 @@ uint32_t helper_das(CPUH8300State *env, uint32_t num)
122119 }
123120 }
124121
125-static void helper_eepmovb(CPUH8300State *env)
122+void helper_eepmovb(CPUH8300State *env)
126123 {
127124 int cnt;
128125 uint8_t tmp;
129- cnt = extracr32(cpu_regs[4], 0, 8);
126+ cnt = extract32(env->regs[4], 0, 8);
130127 while(cnt > 0) {
131128 tmp = cpu_ldub_data_ra(env, env->regs[5], GETPC());
132129 cpu_stb_data_ra(env, env->regs[6], tmp, GETPC());
@@ -134,14 +131,14 @@ static void helper_eepmovb(CPUH8300State *env)
134131 env->regs[6]++;
135132 cnt--;
136133 }
137- cpu_regs[4] = deposit32(cpu_regs[4], cnt, 0, 8);
134+ env->regs[4] = deposit32(env->regs[4], cnt, 0, 8);
138135 }
139136
140-static void helper_eepmovw(CPUH8300State *env)
137+void helper_eepmovw(CPUH8300State *env)
141138 {
142139 int cnt;
143140 uint8_t tmp;
144- cnt = extracr32(cpu_regs[4], 0, 16);
141+ cnt = extract32(env->regs[4], 0, 16);
145142 while(cnt > 0) {
146143 tmp = cpu_ldub_data_ra(env, env->regs[5], GETPC());
147144 cpu_stb_data_ra(env, env->regs[6], tmp, GETPC());
@@ -149,7 +146,29 @@ static void helper_eepmovw(CPUH8300State *env)
149146 env->regs[6]++;
150147 cnt--;
151148 }
152- cpu_regs[4] = deposit32(cpu_regs[4], cnt, 0, 16);
149+ env->regs[4] = deposit32(env->regs[4], cnt, 0, 16);
150+}
151+
152+void helper_sim_write(CPUH8300State *env)
153+{
154+ int fd, size, i;
155+ char *buf, *p;
156+ uint32_t addr;
157+
158+ fd = env->regs[0];
159+ addr = env->regs[1];
160+ size = env->regs[2];
161+ buf = malloc(size);
162+ for (p = buf, i = 0; i < size; i++) {
163+ *p++ = cpu_ldub_data_ra(env, addr++, GETPC());
164+ }
165+ write(fd, buf, size);
166+ free(buf);
167+}
168+
169+void helper_dump(uint32_t val)
170+{
171+ printf("val: %08x\n", val);
153172 }
154173
155174 /* exception */
--- a/target/h8300/translate.c
+++ b/target/h8300/translate.c
@@ -31,7 +31,7 @@
3131
3232 typedef struct DisasContext {
3333 DisasContextBase base;
34- CPURXState *env;
34+ CPUH8300State *env;
3535 uint32_t pc;
3636 } DisasContext;
3737
@@ -48,8 +48,8 @@ typedef struct DisasCompare {
4848
4949 /* global register indexes */
5050 static TCGv cpu_regs[8];
51-static TCGv cpu_psw_c, cpu_psw_v, cpu_psw_z, cpu_psw_n;
52-static TCGv cpu_psw_u, cpu_psw_h, cpu_psw_ui, cpu_psw_i;
51+static TCGv cpu_ccr_c, cpu_ccr_v, cpu_ccr_z, cpu_ccr_n;
52+static TCGv cpu_ccr_u, cpu_ccr_h, cpu_ccr_ui, cpu_ccr_i;
5353 static TCGv cpu_pc;
5454
5555 #define cpu_sp cpu_regs[7]
@@ -69,17 +69,17 @@ static uint32_t decode_load_bytes(DisasContext *ctx, uint32_t insn,
6969
7070 static uint32_t imm32(DisasContext *ctx, int dummy)
7171 {
72- CPURXState *env = ctx->env;
73- addr = ctx->base.pc_next;
72+ CPUH8300State *env = ctx->env;
73+ uint32_t addr = ctx->base.pc_next;
7474
75- ctx->base.pc_next += 2;
75+ ctx->base.pc_next += 4;
7676 return cpu_ldl_code(env, addr);
7777 }
7878
7979 static uint32_t dsp16(DisasContext *ctx, int dummy)
8080 {
81- CPURXState *env = ctx->env;
82- addr = ctx->base.pc_next;
81+ CPUH8300State *env = ctx->env;
82+ uint32_t addr = ctx->base.pc_next;
8383
8484 ctx->base.pc_next += 2;
8585 return cpu_ldsw_code(env, addr);
@@ -87,20 +87,32 @@ static uint32_t dsp16(DisasContext *ctx, int dummy)
8787
8888 static uint32_t dsp24(DisasContext *ctx, int dummy)
8989 {
90- CPURXState *env = ctx->env;
90+ CPUH8300State *env = ctx->env;
9191 uint32_t dsp24;
92- addr = ctx->pc + 6;
92+ uint32_t addr = ctx->pc + 4;
93+
94+ ctx->base.pc_next = ctx->pc + 8;
95+ dsp24 = cpu_ldl_code(env, addr);
96+ dsp24 = deposit32(dsp24, 16, 16, sextract32(dsp24, 16, 8));
97+ return dsp24;
98+}
99+
100+static uint32_t dsp24l(DisasContext *ctx, int dummy)
101+{
102+ CPUH8300State *env = ctx->env;
103+ uint32_t dsp24;
104+ uint32_t addr = ctx->pc + 6;
93105
94106 ctx->base.pc_next = ctx->pc + 10;
95107 dsp24 = cpu_ldl_code(env, addr);
96- dsp24 = deposit(dsp24, 16, 16, sextract32(dsp24, 16, 8));
108+ dsp24 = deposit32(dsp24, 16, 16, sextract32(dsp24, 16, 8));
97109 return dsp24;
98110 }
99111
100112 static uint32_t abs16(DisasContext *ctx, int dummy)
101113 {
102- CPURXState *env = ctx->env;
103- addr = ctx->base.pc_next;
114+ CPUH8300State *env = ctx->env;
115+ uint32_t addr = ctx->base.pc_next;
104116
105117 ctx->base.pc_next += 2;
106118 return cpu_ldsw_code(env, addr);
@@ -108,8 +120,8 @@ static uint32_t abs16(DisasContext *ctx, int dummy)
108120
109121 static uint32_t abs24(DisasContext *ctx, int dummy)
110122 {
111- CPURXState *env = ctx->env;
112- addr = ctx->base.pc_next;
123+ CPUH8300State *env = ctx->env;
124+ uint32_t addr = ctx->base.pc_next;
113125
114126 ctx->base.pc_next += 4;
115127 return cpu_ldl_code(env, addr);
@@ -117,20 +129,25 @@ static uint32_t abs24(DisasContext *ctx, int dummy)
117129
118130 static uint32_t b10_er(DisasContext *ctx, int dummy)
119131 {
120- CPURXState *env = ctx->env;
121- addr = ctx->pc + 5;
132+ CPUH8300State *env = ctx->env;
133+ uint32_t addr = ctx->pc + 5;
122134
123135 return extract32(cpu_ldub_code(env, addr), 0, 3);
124136 }
125137
126138 static uint32_t b10_ldst(DisasContext *ctx, int dummy)
127139 {
128- CPURXState *env = ctx->env;
129- addr = ctx->pc + 5;
140+ CPUH8300State *env = ctx->env;
141+ uint32_t addr = ctx->pc + 5;
130142
131143 return extract32(cpu_ldub_code(env, addr), 4, 4);
132144 }
133145
146+static int dummy(uint32_t insn, int pos, int len)
147+{
148+ return 0;
149+}
150+
134151 /* Include the auto-generated decoder. */
135152 #include "decode.inc.c"
136153
@@ -139,11 +156,11 @@ void h8300_cpu_dump_state(CPUState *cs, FILE *f, int flags)
139156 H8300CPU *cpu = H8300CPU(cs);
140157 CPUH8300State *env = &cpu->env;
141158 int i;
142- uint32_t psw;
159+ uint32_t ccr;
143160
144- psw = h8300_cpu_pack_psw(env);
145- qemu_fprintf(f, "pc=0x%08x psw=0x%02x\n",
146- env->pc, psw);
161+ ccr = h8300_cpu_pack_ccr(env);
162+ qemu_fprintf(f, "pc=0x%08x ccr=0x%02x\n",
163+ env->pc, ccr);
147164 for (i = 0; i < 8; i += 4) {
148165 qemu_fprintf(f, "er%d=0x%08x er%d=0x%08x er%d=0x%08x er%d=0x%08x\n",
149166 i, env->regs[i], i + 1, env->regs[i + 1],
@@ -178,60 +195,60 @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest)
178195 }
179196
180197 /* generate QEMU condition */
181-static void psw_cond(DisasCompare *dc, uint32_t cond)
198+static void ccr_cond(DisasCompare *dc, uint32_t cond)
182199 {
183200 tcg_debug_assert(cond < 16);
184201 switch (cond) {
185202 case 2: /* !(c | z) */
186203 case 3: /* c | z */
187- tcg_gen_setcondi_i32(TCG_COND_NE, dc->temp, cpu_psw_z, 0);
188- tcg_gen_or_i32(dc->temp, dc->temp, cpu_psw_c);
204+ tcg_gen_setcondi_i32(TCG_COND_NE, dc->temp, cpu_ccr_z, 0);
205+ tcg_gen_or_i32(dc->temp, dc->temp, cpu_ccr_c);
189206 dc->cond = (cond == 2) ? TCG_COND_EQ : TCG_COND_NE;
190207 dc->value = dc->temp;
191208 break;
192209 case 4: /* !c */
193210 dc->cond = TCG_COND_EQ;
194- dc->value = cpu_psw_c;
211+ dc->value = cpu_ccr_c;
195212 break;
196213 case 5: /* c */
197214 dc->cond = TCG_COND_NE;
198- dc->value = cpu_psw_c;
215+ dc->value = cpu_ccr_c;
199216 break;
200217 case 6: /* !z */
201218 dc->cond = TCG_COND_NE;
202- dc->value = cpu_psw_z;
219+ dc->value = cpu_ccr_z;
203220 break;
204221 case 7: /* z */
205222 dc->cond = TCG_COND_EQ;
206- dc->value = cpu_psw_z;
223+ dc->value = cpu_ccr_z;
207224 break;
208225 case 8: /* !v */
209226 dc->cond = TCG_COND_EQ;
210- dc->value = cpu_psw_v;
227+ dc->value = cpu_ccr_v;
211228 break;
212229 case 9: /* v */
213230 dc->cond = TCG_COND_NE;
214- dc->value = cpu_psw_v;
231+ dc->value = cpu_ccr_v;
215232 break;
216233 case 10: /* !n */
217234 dc->cond = TCG_COND_GE;
218- dc->value = cpu_psw_s;
235+ dc->value = cpu_ccr_n;
219236 break;
220237 case 11: /* n */
221238 dc->cond = TCG_COND_LT;
222- dc->value = cpu_psw_s;
239+ dc->value = cpu_ccr_n;
223240 break;
224241 case 12: /* !(n^v) */
225242 case 13: /* n^v */
226- tcg_gen_xor_i32(dc->temp, cpu_psw_o, cpu_psw_s);
243+ tcg_gen_xor_i32(dc->temp, cpu_ccr_v, cpu_ccr_n);
227244 dc->cond = (cond == 8) ? TCG_COND_GE : TCG_COND_LT;
228245 dc->value = dc->temp;
229246 break;
230247 case 14: /* !((n^v) | z) */
231248 case 15: /* ((n^v) | z) */
232- tcg_gen_xor_i32(dc->temp, cpu_psw_v, cpu_psw_s);
249+ tcg_gen_xor_i32(dc->temp, cpu_ccr_v, cpu_ccr_n);
233250 tcg_gen_sari_i32(dc->temp, dc->temp, 31);
234- tcg_gen_andc_i32(dc->temp, cpu_psw_z, dc->temp);
251+ tcg_gen_andc_i32(dc->temp, cpu_ccr_z, dc->temp);
235252 dc->cond = (cond == 10) ? TCG_COND_NE : TCG_COND_EQ;
236253 dc->value = dc->temp;
237254 break;
@@ -240,41 +257,43 @@ static void psw_cond(DisasCompare *dc, uint32_t cond)
240257
241258 static inline void h8300_gen_reg_ldb(int rn, TCGv val)
242259 {
243- g_assert(a < 16);
260+ g_assert(rn < 16);
244261 if (rn < 8) {
245- tcg_gen_sextract32(val, cpu_regs[rn], 8, 8);
262+ tcg_gen_sextract_i32(val, cpu_regs[rn], 8, 8);
246263 } else {
247- tcg_gen_sextract32(val, cpu_regs[rn], 8, 8);
264+ tcg_gen_sextract_i32(val, cpu_regs[rn & 7], 0, 8);
248265 }
249266 }
250267
251268 static inline void h8300_gen_reg_stb(int rn, TCGv val)
252269 {
253- g_assert(a < 16);
270+ g_assert(rn < 16);
254271 if (rn < 8) {
255- tcg_gen_deposit32(cpu_regs[rn], 8, 8, val);
272+ tcg_gen_deposit_i32(cpu_regs[rn], cpu_regs[rn], val, 8, 8);
256273 } else {
257- tcg_gen_deposit32(cpu_regs[rn], 8, 8, val);
274+ rn &= 7;
275+ tcg_gen_deposit_i32(cpu_regs[rn], cpu_regs[rn], val, 0, 8);
258276 }
259277 }
260278
261279 static inline void h8300_gen_reg_ldw(int rn, TCGv val)
262280 {
263- g_assert(a < 16);
281+ g_assert(rn < 16);
264282 if (rn < 8) {
265- tcg_gen_sextract32(val, cpu_regs[rn], 0, 16);
283+ tcg_gen_sextract_i32(val, cpu_regs[rn], 0, 16);
266284 } else {
267- tcg_gen_sextract32(val, cpu_regs[rn], 16, 16);
285+ tcg_gen_sextract_i32(val, cpu_regs[rn & 7], 16, 16);
268286 }
269287 }
270288
271289 static inline void h8300_gen_reg_stw(int rn, TCGv val)
272290 {
273- g_assert(a < 16);
291+ g_assert(rn < 16);
274292 if (rn < 8) {
275- tcg_gen_deposit32(cpu_regs[rn], 0, 16, val);
293+ tcg_gen_deposit_i32(cpu_regs[rn], cpu_regs[rn], val, 0, 16);
276294 } else {
277- tcg_gen_deposit32(cpu_regs[rn], 16, 16, val);
295+ rn &= 7;
296+ tcg_gen_deposit_i32(cpu_regs[rn], cpu_regs[rn], val, 16, 16);
278297 }
279298 }
280299
@@ -287,18 +306,18 @@ static bool trans_MOV_i(DisasContext *ctx, arg_MOV_i *a)
287306 TCGv imm = tcg_const_i32(a->imm);
288307 switch(a->sz) {
289308 case SZ_B:
290- h8300_gen_reg_stb(a->r, imm);
309+ h8300_gen_reg_stb(a->rd, imm);
291310 break;
292311 case SZ_W:
293- h8300_gen_reg_stw(a->r, imm);
312+ h8300_gen_reg_stw(a->rd, imm);
294313 break;
295- case SZ_W:
296- tcg_gen_mov_i32(cpu_regs[a->r], imm);
314+ case SZ_L:
315+ tcg_gen_mov_i32(cpu_regs[a->rd], imm);
297316 break;
298317 }
299- tcg_gen_mov_i32(cpu_psw_z, imm);
300- tcg_gen_mov_i32(cpu_psw_n, imm);
301- tcg_gen_movi_i32(cpu_psw_v, 0);
318+ tcg_gen_mov_i32(cpu_ccr_z, imm);
319+ tcg_gen_mov_i32(cpu_ccr_n, imm);
320+ tcg_gen_movi_i32(cpu_ccr_v, 0);
302321 tcg_temp_free(imm);
303322 return true;
304323 }
@@ -315,14 +334,14 @@ static bool trans_MOV_r(DisasContext *ctx, arg_MOV_r *a)
315334 h8300_gen_reg_ldw(a->rs, temp);
316335 h8300_gen_reg_stw(a->rd, temp);
317336 break;
318- case SZ_W:
337+ case SZ_L:
319338 tcg_gen_mov_i32(cpu_regs[a->rd], cpu_regs[a->rs]);
320339 tcg_gen_mov_i32(temp, cpu_regs[a->rs]);
321340 break;
322341 }
323- tcg_gen_mov_i32(cpu_psw_z, temp);
324- tcg_gen_mov_i32(cpu_psw_n, temp);
325- tcg_gen_movi_i32(cpu_psw_v, 0);
342+ tcg_gen_mov_i32(cpu_ccr_z, temp);
343+ tcg_gen_mov_i32(cpu_ccr_n, temp);
344+ tcg_gen_movi_i32(cpu_ccr_v, 0);
326345 tcg_temp_free(temp);
327346 return true;
328347 }
@@ -339,15 +358,15 @@ static bool trans_MOV_mr(DisasContext *ctx, arg_MOV_mr *a)
339358 h8300_gen_reg_stb(a->r, temp);
340359 break;
341360 case SZ_W:
342- h8300_gen_reg_stw(a->rr, temp);
361+ h8300_gen_reg_stw(a->r, temp);
343362 break;
344- case SZ_W:
363+ case SZ_L:
345364 tcg_gen_mov_i32(cpu_regs[a->r], temp);
346365 break;
347366 }
348- tcg_gen_mov_i32(cpu_psw_z, temp);
349- tcg_gen_mov_i32(cpu_psw_n, temp);
350- tcg_gen_movi_i32(cpu_psw_v, 0);
367+ tcg_gen_mov_i32(cpu_ccr_z, temp);
368+ tcg_gen_mov_i32(cpu_ccr_n, temp);
369+ tcg_gen_movi_i32(cpu_ccr_v, 0);
351370 tcg_temp_free(mem);
352371 tcg_temp_free(temp);
353372 return true;
@@ -364,15 +383,15 @@ static bool trans_MOV_mpr(DisasContext *ctx, arg_MOV_mr *a)
364383 h8300_gen_reg_stb(a->r, temp);
365384 break;
366385 case SZ_W:
367- h8300_gen_reg_stw(a->rr, temp);
386+ h8300_gen_reg_stw(a->r, temp);
368387 break;
369- case SZ_W:
388+ case SZ_L:
370389 tcg_gen_mov_i32(cpu_regs[a->r], temp);
371390 break;
372391 }
373- tcg_gen_mov_i32(cpu_psw_z, temp);
374- tcg_gen_mov_i32(cpu_psw_n, temp);
375- tcg_gen_movi_i32(cpu_psw_v, 0);
392+ tcg_gen_mov_i32(cpu_ccr_z, temp);
393+ tcg_gen_mov_i32(cpu_ccr_n, temp);
394+ tcg_gen_movi_i32(cpu_ccr_v, 0);
376395 tcg_temp_free(temp);
377396 return true;
378397 }
@@ -397,15 +416,15 @@ static bool trans_MOV_ar(DisasContext *ctx, arg_MOV_ar *a)
397416 h8300_gen_reg_stb(a->r, temp);
398417 break;
399418 case SZ_W:
400- h8300_gen_reg_stw(a->rr, temp);
419+ h8300_gen_reg_stw(a->r, temp);
401420 break;
402- case SZ_W:
421+ case SZ_L:
403422 tcg_gen_mov_i32(cpu_regs[a->r], temp);
404423 break;
405424 }
406- tcg_gen_mov_i32(cpu_psw_z, temp);
407- tcg_gen_mov_i32(cpu_psw_n, temp);
408- tcg_gen_movi_i32(cpu_psw_v, 0);
425+ tcg_gen_mov_i32(cpu_ccr_z, temp);
426+ tcg_gen_mov_i32(cpu_ccr_n, temp);
427+ tcg_gen_movi_i32(cpu_ccr_v, 0);
409428 tcg_temp_free(mem);
410429 tcg_temp_free(temp);
411430 return true;
@@ -422,16 +441,16 @@ static bool trans_MOV_rm(DisasContext *ctx, arg_MOV_mr *a)
422441 h8300_gen_reg_ldb(a->r, temp);
423442 break;
424443 case SZ_W:
425- h8300_gen_reg_ldw(a->rr, temp);
444+ h8300_gen_reg_ldw(a->r, temp);
426445 break;
427- case SZ_W:
428- tcg_gen_mov_i32(cpu_regs[a->r], temp);
446+ case SZ_L:
447+ tcg_gen_mov_i32(temp, cpu_regs[a->r]);
429448 break;
430449 }
431450 tcg_gen_qemu_st_i32(temp, mem, 0, a->sz | MO_SIGN | MO_TE);
432- tcg_gen_mov_i32(cpu_psw_z, temp);
433- tcg_gen_mov_i32(cpu_psw_n, temp);
434- tcg_gen_movi_i32(cpu_psw_v, 0);
451+ tcg_gen_mov_i32(cpu_ccr_z, temp);
452+ tcg_gen_mov_i32(cpu_ccr_n, temp);
453+ tcg_gen_movi_i32(cpu_ccr_v, 0);
435454 tcg_temp_free(mem);
436455 tcg_temp_free(temp);
437456 return true;
@@ -445,19 +464,19 @@ static bool trans_MOV_rmp(DisasContext *ctx, arg_MOV_mr *a)
445464 tcg_gen_subi_i32(cpu_regs[a->er], cpu_regs[a->er], 1 << a->sz);
446465 switch(a->sz) {
447466 case SZ_B:
448- h8300_gen_reg_stb(a->r, temp);
467+ h8300_gen_reg_ldb(a->r, temp);
449468 break;
450469 case SZ_W:
451- h8300_gen_reg_stw(a->rr, temp);
470+ h8300_gen_reg_ldw(a->r, temp);
452471 break;
453- case SZ_W:
472+ case SZ_L:
454473 tcg_gen_mov_i32(temp, cpu_regs[a->r]);
455474 break;
456475 }
457476 tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, a->sz | MO_SIGN | MO_TE);
458- tcg_gen_mov_i32(cpu_psw_z, temp);
459- tcg_gen_mov_i32(cpu_psw_n, temp);
460- tcg_gen_movi_i32(cpu_psw_v, 0);
477+ tcg_gen_mov_i32(cpu_ccr_z, temp);
478+ tcg_gen_mov_i32(cpu_ccr_n, temp);
479+ tcg_gen_movi_i32(cpu_ccr_v, 0);
461480 tcg_temp_free(mem);
462481 tcg_temp_free(temp);
463482 return true;
@@ -482,16 +501,16 @@ static bool trans_MOV_ra(DisasContext *ctx, arg_MOV_ra *a)
482501 h8300_gen_reg_ldb(a->r, temp);
483502 break;
484503 case SZ_W:
485- h8300_gen_reg_ldw(a->rr, temp);
504+ h8300_gen_reg_ldw(a->r, temp);
486505 break;
487- case SZ_W:
506+ case SZ_L:
488507 tcg_gen_mov_i32(temp, cpu_regs[a->r]);
489508 break;
490509 }
491510 tcg_gen_qemu_st_i32(temp, mem, 0, a->sz | MO_SIGN | MO_TE);
492- tcg_gen_mov_i32(cpu_psw_z, temp);
493- tcg_gen_mov_i32(cpu_psw_n, temp);
494- tcg_gen_movi_i32(cpu_psw_v, 0);
511+ tcg_gen_mov_i32(cpu_ccr_z, temp);
512+ tcg_gen_mov_i32(cpu_ccr_n, temp);
513+ tcg_gen_movi_i32(cpu_ccr_v, 0);
495514 tcg_temp_free(mem);
496515 tcg_temp_free(temp);
497516 return true;
@@ -499,25 +518,29 @@ static bool trans_MOV_ra(DisasContext *ctx, arg_MOV_ra *a)
499518
500519 static bool trans_MOVFPE(DisasContext *ctx, arg_MOVFPE *a)
501520 {
502- TCGv mem;
521+ TCGv mem, temp;
503522
504523 a->abs = sextract32(a->abs, 0, 16) & 0x00ffffff;
505524 mem = tcg_const_i32(a->abs);
506- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
525+ temp = tcg_temp_new();
526+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
507527 h8300_gen_reg_stb(a->r, temp);
508528 tcg_temp_free(mem);
529+ tcg_temp_free(temp);
509530 return true;
510531 }
511532
512533 static bool trans_MOVTPE(DisasContext *ctx, arg_MOVTPE *a)
513534 {
514- TCGv mem;
535+ TCGv mem, temp;
515536
516537 a->abs = sextract32(a->abs, 0, 16) & 0x00ffffff;
517538 mem = tcg_const_i32(a->abs);
539+ temp = tcg_temp_new();
518540 h8300_gen_reg_ldb(a->r, temp);
519- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
541+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
520542 tcg_temp_free(mem);
543+ tcg_temp_free(temp);
521544 return true;
522545 }
523546
@@ -559,36 +582,36 @@ static inline void h8300_add(int sz, TCGv ret, TCGv arg1, TCGv arg2, bool c)
559582 z = tcg_const_i32(0);
560583
561584 if (c) {
562- tcg_gen_add2_i32(cpu_psw_s, cpu_psw_c, arg1, z, arg2, z);
585+ tcg_gen_add2_i32(cpu_ccr_n, cpu_ccr_c, arg1, z, arg2, z);
563586 } else {
564- tcg_gen_add_i32(cpu_psw_s, arg1, arg2);
587+ tcg_gen_add_i32(cpu_ccr_n, arg1, arg2);
565588 }
566- tcg_gen_mov_i32(cpu_psw_z, cpu_psw_s);
567- tcg_gen_xor_i32(cpu_psw_o, cpu_psw_s, arg1);
589+ tcg_gen_mov_i32(cpu_ccr_z, cpu_ccr_n);
590+ tcg_gen_xor_i32(cpu_ccr_v, cpu_ccr_n, arg1);
568591 switch(sz) {
569592 case SZ_B:
570- tcg_gen_ext8s(cpu_psw_s, cpu_psw_s);
593+ tcg_gen_ext8s_i32(cpu_ccr_n, cpu_ccr_n);
571594 if (c) {
572- tcg_gen_extract_i32(cpu_psw_c, cpu_psw_o, 8, 1);
595+ tcg_gen_extract_i32(cpu_ccr_c, cpu_ccr_v, 8, 1);
573596 }
574- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 4, 1);
597+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 4, 1);
575598 break;
576599 case SZ_W:
577- tcg_gen_ext16s(cpu_psw_s, cpu_psw_s);
600+ tcg_gen_ext16s_i32(cpu_ccr_n, cpu_ccr_n);
578601 if (c) {
579- tcg_gen_extract_i32(cpu_psw_c, cpu_psw_o, 16, 1);
602+ tcg_gen_extract_i32(cpu_ccr_c, cpu_ccr_v, 16, 1);
580603 }
581- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 12, 1);
604+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 12, 1);
582605 break;
583606 case SZ_L:
584- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 28, 1);
607+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 28, 1);
585608 break;
586609 default:
587610 g_assert_not_reached();
588611 }
589612 tcg_gen_xor_i32(z, arg1, arg2);
590- tcg_gen_andc_i32(cpu_psw_o, cpu_psw_o, z);
591- tcg_gen_mov_i32(ret, cpu_psw_s);
613+ tcg_gen_andc_i32(cpu_ccr_v, cpu_ccr_v, z);
614+ tcg_gen_mov_i32(ret, cpu_ccr_n);
592615 tcg_temp_free(z);
593616 }
594617
@@ -597,56 +620,56 @@ static inline void h8300_addx(TCGv ret, TCGv arg1, TCGv arg2)
597620 TCGv z;
598621 z = tcg_const_i32(0);
599622
600- tcg_gen_add_i32(cpu_psw_s, arg1, cpu_psw_c);
601- tcg_gen_add_i32(cpu_psw_s, cpu_psw_s, arg2);
602- tcg_gen_mov_i32(cpu_psw_z, cpu_psw_s);
603- tcg_gen_ext8s(cpu_psw_s, cpu_psw_s);
604- tcg_gen_xor_i32(cpu_psw_o, cpu_psw_s, arg1);
605- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 4, 1);
606- tcg_gen_extract_i32(cpu_psw_c, cpu_psw_o, 8, 1);
623+ tcg_gen_add_i32(cpu_ccr_n, arg1, cpu_ccr_c);
624+ tcg_gen_add_i32(cpu_ccr_n, cpu_ccr_n, arg2);
625+ tcg_gen_mov_i32(cpu_ccr_z, cpu_ccr_n);
626+ tcg_gen_ext8s_i32(cpu_ccr_n, cpu_ccr_n);
627+ tcg_gen_xor_i32(cpu_ccr_v, cpu_ccr_n, arg1);
628+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 4, 1);
629+ tcg_gen_extract_i32(cpu_ccr_c, cpu_ccr_v, 8, 1);
607630 tcg_gen_xor_i32(z, arg1, arg2);
608- tcg_gen_andc_i32(cpu_psw_o, cpu_psw_o, z);
609- tcg_gen_mov_i32(ret, cpu_psw_s);
631+ tcg_gen_andc_i32(cpu_ccr_v, cpu_ccr_v, z);
632+ tcg_gen_mov_i32(ret, cpu_ccr_n);
610633 tcg_temp_free(z);
611634 }
612635
613636 static void h8300_sub(int sz, TCGv ret, TCGv arg1, TCGv arg2, bool c)
614637 {
615638 TCGv temp;
616- tcg_gen_sub_i32(cpu_psw_s, arg1, arg2);
617- tcg_gen_mov_i32(cpu_psw_z, cpu_psw_s);
639+ tcg_gen_sub_i32(cpu_ccr_n, arg1, arg2);
640+ tcg_gen_mov_i32(cpu_ccr_z, cpu_ccr_n);
618641 if (c) {
619- tcg_gen_setcond_i32(TCG_COND_GEU, cpu_psw_c, arg1, arg2);
642+ tcg_gen_setcond_i32(TCG_COND_GEU, cpu_ccr_c, arg1, arg2);
620643 }
621- tcg_gen_xor_i32(cpu_psw_o, cpu_psw_s, arg1);
644+ tcg_gen_xor_i32(cpu_ccr_v, cpu_ccr_n, arg1);
622645 switch(sz) {
623646 case SZ_B:
624- tcg_gen_ext8s(cpu_psw_s, cpu_psw_s);
647+ tcg_gen_ext8s_i32(cpu_ccr_n, cpu_ccr_n);
625648 if (c) {
626- tcg_gen_extract_i32(cpu_psw_c, cpu_psw_o, 8, 1);
649+ tcg_gen_extract_i32(cpu_ccr_c, cpu_ccr_v, 8, 1);
627650 }
628- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 4, 1);
651+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 4, 1);
629652 break;
630653 case SZ_W:
631- tcg_gen_ext16s(cpu_psw_s, cpu_psw_s);
654+ tcg_gen_ext16s_i32(cpu_ccr_n, cpu_ccr_n);
632655 if (c) {
633- tcg_gen_extract_i32(cpu_psw_c, cpu_psw_o, 16, 1);
656+ tcg_gen_extract_i32(cpu_ccr_c, cpu_ccr_v, 16, 1);
634657 }
635- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 12, 1);
658+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 12, 1);
636659 break;
637660 case SZ_L:
638- tcg_gen_extract_i32(cpu_psw_h, cpu_psw_o, 28, 1);
661+ tcg_gen_extract_i32(cpu_ccr_h, cpu_ccr_v, 28, 1);
639662 break;
640663 default:
641664 g_assert_not_reached();
642665 }
643666 temp = tcg_temp_new_i32();
644667 tcg_gen_xor_i32(temp, arg1, arg2);
645- tcg_gen_and_i32(cpu_psw_o, cpu_psw_o, temp);
668+ tcg_gen_and_i32(cpu_ccr_v, cpu_ccr_v, temp);
646669 tcg_temp_free_i32(temp);
647670 /* CMP not requred return */
648671 if (ret) {
649- tcg_gen_mov_i32(ret, cpu_psw_s);
672+ tcg_gen_mov_i32(ret, cpu_ccr_n);
650673 }
651674 }
652675
@@ -654,12 +677,12 @@ static inline void h8300_ccr_adjust(int sz)
654677 {
655678 switch(sz) {
656679 case SZ_B:
657- tcg_gen_ext8s_i32(cpu_psw_s, cpu_psw_s);
658- tcg_gen_ext8s_i32(cpu_psw_z, cpu_psw_z);
680+ tcg_gen_ext8s_i32(cpu_ccr_n, cpu_ccr_n);
681+ tcg_gen_ext8s_i32(cpu_ccr_z, cpu_ccr_z);
659682 break;
660- case SZ_B:
661- tcg_gen_ext16s_i32(cpu_psw_s, cpu_psw_s);
662- tcg_gen_ext16s_i32(cpu_psw_z, cpu_psw_z);
683+ case SZ_W:
684+ tcg_gen_ext16s_i32(cpu_ccr_n, cpu_ccr_n);
685+ tcg_gen_ext16s_i32(cpu_ccr_z, cpu_ccr_z);
663686 break;
664687 case SZ_L:
665688 break;
@@ -670,7 +693,7 @@ static inline void h8300_ccr_adjust(int sz)
670693
671694 static bool trans_ADD_i(DisasContext *ctx, arg_ADD_i *a)
672695 {
673- TCGv temp, imm;
696+ TCGv temp, imm, reg;
674697 imm = tcg_const_i32(a->imm);
675698 temp = tcg_temp_new();
676699 reg = h8300_reg_ld(a->sz, a->rd, temp);
@@ -681,7 +704,7 @@ static bool trans_ADD_i(DisasContext *ctx, arg_ADD_i *a)
681704 return true;
682705 }
683706
684-static bool trans_ADD_r(DisasContext *ctx, arg_ADD_i *a)
707+static bool trans_ADD_r(DisasContext *ctx, arg_ADD_r *a)
685708 {
686709 TCGv temp1, temp2, reg1, reg2;
687710 temp1 = tcg_temp_new();
@@ -698,22 +721,23 @@ static bool trans_ADD_r(DisasContext *ctx, arg_ADD_i *a)
698721 static bool trans_ADDS(DisasContext *ctx, arg_ADDS *a)
699722 {
700723 tcg_gen_addi_i32(cpu_regs[a->rd], cpu_regs[a->rd], a->imm);
724+ return true;
701725 }
702726
703727 static bool trans_ADDX_i(DisasContext *ctx, arg_ADDX_i *a)
704728 {
705- TCGv temp, reg, h;
729+ TCGv temp, reg, imm;
706730 imm = tcg_const_i32(a->imm);
707731 temp = tcg_temp_new();
708732 reg = h8300_reg_ld(SZ_B, a->rd, temp);
709- h8300_addx(a->sz, reg, reg, imm);
733+ h8300_addx(reg, reg, imm);
710734 h8300_reg_st(SZ_B, a->rd, temp);
711735 tcg_temp_free(temp);
712736 tcg_temp_free(imm);
713737 return true;
714738 }
715739
716-static bool trans_ADDX_r(DisasContext *ctx, arg_ADDX_i *a)
740+static bool trans_ADDX_r(DisasContext *ctx, arg_ADDX_r *a)
717741 {
718742 TCGv temp1, temp2, reg1, reg2;
719743 temp1 = tcg_temp_new();
@@ -729,7 +753,7 @@ static bool trans_ADDX_r(DisasContext *ctx, arg_ADDX_i *a)
729753
730754 static bool trans_SUB_i(DisasContext *ctx, arg_SUB_i *a)
731755 {
732- TCGv temp, reg, h;
756+ TCGv temp, reg, imm;
733757 imm = tcg_const_i32(a->imm);
734758 temp = tcg_temp_new();
735759 reg = h8300_reg_ld(a->sz, a->rd, temp);
@@ -740,7 +764,7 @@ static bool trans_SUB_i(DisasContext *ctx, arg_SUB_i *a)
740764 return true;
741765 }
742766
743-static bool trans_SUB_r(DisasContext *ctx, arg_SUB_i *a)
767+static bool trans_SUB_r(DisasContext *ctx, arg_SUB_r *a)
744768 {
745769 TCGv temp1, temp2, reg1, reg2;
746770 temp1 = tcg_temp_new();
@@ -757,30 +781,32 @@ static bool trans_SUB_r(DisasContext *ctx, arg_SUB_i *a)
757781 static bool trans_SUBS(DisasContext *ctx, arg_SUBS *a)
758782 {
759783 tcg_gen_subi_i32(cpu_regs[a->rd], cpu_regs[a->rd], a->imm);
784+ return true;
760785 }
761786
762-static bool trans_SUBX_i(DisasContext *ctx, arg_SUB_i *a)
787+static bool trans_SUBX_i(DisasContext *ctx, arg_SUBX_i *a)
763788 {
764- TCGv temp, reg, h;
789+ TCGv temp, reg, imm;
765790 temp = tcg_temp_new();
791+ imm = tcg_temp_new();
766792 reg = h8300_reg_ld(SZ_B, a->rd, temp);
767- tcg_gen_addi_i32(imm, psw_c, a->imm);
768- h8300_sub(SZ_B, reg, reg, imm);
793+ tcg_gen_addi_i32(imm, cpu_ccr_c, a->imm);
794+ h8300_sub(SZ_B, reg, reg, imm, true);
769795 h8300_reg_st(SZ_B, a->rd, temp);
770796 tcg_temp_free(temp);
771797 tcg_temp_free(imm);
772798 return true;
773799 }
774800
775-static bool trans_SUBX_r(DisasContext *ctx, arg_SUB_i *a)
801+static bool trans_SUBX_r(DisasContext *ctx, arg_SUBX_r *a)
776802 {
777803 TCGv temp1, temp2, reg1, reg2;
778804 temp1 = tcg_temp_new();
779805 temp2 = tcg_temp_new();
780806 reg1 = h8300_reg_ld(SZ_B, a->rd, temp1);
781807 reg2 = h8300_reg_ld(SZ_B, a->rs, temp2);
782- tcg_gen_add_i32(reg2, reg2, 1);
783- h8300_sub(SZ_B, reg1, reg1, reg2);
808+ tcg_gen_add_i32(reg2, reg2, cpu_ccr_c);
809+ h8300_sub(SZ_B, reg1, reg1, reg2, true);
784810 h8300_reg_st(SZ_B, a->rd, reg1);
785811 tcg_temp_free(temp1);
786812 tcg_temp_free(temp2);
@@ -789,7 +815,7 @@ static bool trans_SUBX_r(DisasContext *ctx, arg_SUB_i *a)
789815
790816 static bool trans_CMP_i(DisasContext *ctx, arg_CMP_i *a)
791817 {
792- TCGv temp, reg, h;
818+ TCGv temp, reg, imm;
793819 imm = tcg_const_i32(a->imm);
794820 temp = tcg_temp_new();
795821 reg = h8300_reg_ld(a->sz, a->rd, temp);
@@ -799,7 +825,7 @@ static bool trans_CMP_i(DisasContext *ctx, arg_CMP_i *a)
799825 return true;
800826 }
801827
802-static bool trans_CMP_r(DisasContext *ctx, arg_CMP_i *a)
828+static bool trans_CMP_r(DisasContext *ctx, arg_CMP_r *a)
803829 {
804830 TCGv temp1, temp2, reg1, reg2;
805831 temp1 = tcg_temp_new();
@@ -814,7 +840,7 @@ static bool trans_CMP_r(DisasContext *ctx, arg_CMP_i *a)
814840
815841 static bool trans_INC(DisasContext *ctx, arg_INC *a)
816842 {
817- TCGv temp, imm;
843+ TCGv temp, imm, reg;
818844 imm = tcg_const_i32(a->imm);
819845 temp = tcg_temp_new();
820846 reg = h8300_reg_ld(a->sz, a->rd, temp);
@@ -827,7 +853,7 @@ static bool trans_INC(DisasContext *ctx, arg_INC *a)
827853
828854 static bool trans_DEC(DisasContext *ctx, arg_DEC *a)
829855 {
830- TCGv temp, imm;
856+ TCGv temp, imm, reg;
831857 imm = tcg_const_i32(a->imm);
832858 temp = tcg_temp_new();
833859 reg = h8300_reg_ld(a->sz, a->rd, temp);
@@ -842,9 +868,9 @@ static bool trans_DAA(DisasContext *ctx, arg_DAA *a)
842868 {
843869 TCGv temp;
844870 temp = tcg_temp_new();
845- h8300_reg_ld(SZ_B, a->rd, temp);
871+ h8300_reg_ld(SZ_B, a->r, temp);
846872 gen_helper_daa(temp, cpu_env, temp);
847- h8300_reg_st(SZ_B, a->rd, temp);
873+ h8300_reg_st(SZ_B, a->r, temp);
848874 return true;
849875 }
850876
@@ -852,9 +878,9 @@ static bool trans_DAS(DisasContext *ctx, arg_DAS *a)
852878 {
853879 TCGv temp;
854880 temp = tcg_temp_new();
855- h8300_reg_ld(SZ_B, a->rd, temp);
881+ h8300_reg_ld(SZ_B, a->r, temp);
856882 gen_helper_das(temp, cpu_env, temp);
857- h8300_reg_st(SZ_B, a->rd, temp);
883+ h8300_reg_st(SZ_B, a->r, temp);
858884 return true;
859885 }
860886
@@ -867,18 +893,18 @@ static bool trans_MULXU(DisasContext *ctx, arg_MULXU *a)
867893 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
868894 switch(a->sz) {
869895 case SZ_B:
870- tcg_gen_ext8u(reg1, reg1);
871- tcg_gen_ext8u(reg2, reg2);
896+ tcg_gen_ext8u_i32(reg1, reg1);
897+ tcg_gen_ext8u_i32(reg2, reg2);
872898 break;
873899 case SZ_W:
874- tcg_gen_ext16u(reg1, reg1);
875- tcg_gen_ext16u(reg2, reg2);
900+ tcg_gen_ext16u_i32(reg1, reg1);
901+ tcg_gen_ext16u_i32(reg2, reg2);
876902 break;
877903 default:
878904 g_assert_not_reached();
879905 }
880906 tcg_gen_mul_i32(reg1, reg1, reg2);
881- h8300_reg_st(a->sz + 1, reg1);
907+ h8300_reg_st(a->sz + 1, a->rd, reg1);
882908 tcg_temp_free(temp1);
883909 tcg_temp_free(temp2);
884910 return true;
@@ -892,7 +918,7 @@ static bool trans_MULXS(DisasContext *ctx, arg_MULXU *a)
892918 reg1 = h8300_reg_ld(a->sz + 1, a->rd, temp1);
893919 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
894920 tcg_gen_mul_i32(reg1, reg1, reg2);
895- h8300_reg_st(a->sz + 1, reg1);
921+ h8300_reg_st(a->sz + 1, a->rd, reg1);
896922 tcg_temp_free(temp1);
897923 tcg_temp_free(temp2);
898924 return true;
@@ -907,20 +933,20 @@ static bool trans_DIVXU(DisasContext *ctx, arg_DIVXU *a)
907933 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
908934 switch(a->sz) {
909935 case SZ_B:
910- tcg_gen_ext8u(reg1, reg1);
911- tcg_gen_ext8u(reg2, reg2);
936+ tcg_gen_ext8u_i32(reg1, reg1);
937+ tcg_gen_ext8u_i32(reg2, reg2);
912938 break;
913939 case SZ_W:
914- tcg_gen_ext16u(reg1, reg1);
915- tcg_gen_ext16u(reg2, reg2);
940+ tcg_gen_ext16u_i32(reg1, reg1);
941+ tcg_gen_ext16u_i32(reg2, reg2);
916942 break;
917943 default:
918944 g_assert_not_reached();
919945 }
920- gen_helper_divu(reg1, reg1, reg2);
946+ gen_helper_divu(reg1, cpu_env, reg1, reg2);
921947 tcg_gen_mov_i32(cpu_ccr_z, reg1);
922948 tcg_gen_mov_i32(cpu_ccr_n, reg1);
923- h8300_reg_st(a->sz + 1, reg1);
949+ h8300_reg_st(a->sz + 1, a->rd, reg1);
924950 tcg_temp_free(temp1);
925951 tcg_temp_free(temp2);
926952 return true;
@@ -933,10 +959,10 @@ static bool trans_DIVXS(DisasContext *ctx, arg_DIVXU *a)
933959 temp2 = tcg_temp_new();
934960 reg1 = h8300_reg_ld(a->sz + 1, a->rd, temp1);
935961 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
936- gen_helper_divu(reg1, reg1, reg2);
962+ gen_helper_divu(reg1, cpu_env, reg1, reg2);
937963 tcg_gen_mov_i32(cpu_ccr_z, reg1);
938964 tcg_gen_mov_i32(cpu_ccr_n, reg1);
939- h8300_reg_st(a->sz + 1, reg1);
965+ h8300_reg_st(a->sz + 1, a->rd, reg1);
940966 tcg_temp_free(temp1);
941967 tcg_temp_free(temp2);
942968 return true;
@@ -947,16 +973,16 @@ static bool trans_NEG(DisasContext *ctx, arg_NEG *a)
947973 TCGv temp, reg;
948974 uint32_t s;
949975 temp = tcg_temp_new();
950- reg = h8300_reg_ld(a->sz, a->rd, temp);
976+ reg = h8300_reg_ld(a->sz, a->r, temp);
951977 s = 8 * (1 << a->sz) - 1;
952978 s = 1 << s;
953- tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_psw_o, reg, s);
979+ tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ccr_v, reg, s);
954980 tcg_gen_neg_i32(reg, reg);
955- tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_psw_c, reg, 0);
956- tcg_gen_mov_i32(cpu_psw_z, reg);
957- tcg_gen_mov_i32(cpu_psw_s, reg);
958- h8300_ccr_adjist(a->sz);
959- h8300_reg_st(a->sz, reg);
981+ tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ccr_c, reg, 0);
982+ tcg_gen_mov_i32(cpu_ccr_z, reg);
983+ tcg_gen_mov_i32(cpu_ccr_n, reg);
984+ h8300_ccr_adjust(a->sz);
985+ h8300_reg_st(a->sz, a->r, reg);
960986 tcg_temp_free(temp);
961987 return true;
962988 }
@@ -965,7 +991,7 @@ static bool trans_EXTU(DisasContext *ctx, arg_EXTU *a)
965991 {
966992 TCGv temp, reg;
967993 temp = tcg_temp_new();
968- reg = h8300_reg_ld(a->sz - 1, a->rd, temp);
994+ reg = h8300_reg_ld(a->sz - 1, a->r, temp);
969995 switch(a->sz) {
970996 case SZ_W:
971997 tcg_gen_ext8u_i32(reg, reg);
@@ -973,12 +999,12 @@ static bool trans_EXTU(DisasContext *ctx, arg_EXTU *a)
973999 case SZ_L:
9741000 tcg_gen_ext16u_i32(reg, reg);
9751001 break;
976- defalut:
1002+ default:
9771003 g_assert_not_reached();
9781004 }
9791005 h8300_reg_st(a->sz, a->r, reg);
980- tcg_gen_mov_i32(cpu_psw_z, reg);
981- tcg_gen_mov_i32(cpu_psw_s, reg);
1006+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1007+ tcg_gen_mov_i32(cpu_ccr_n, reg);
9821008 tcg_gen_movi_i32(cpu_ccr_v, 0);
9831009 tcg_temp_free(temp);
9841010 return true;
@@ -990,9 +1016,9 @@ static bool trans_EXTS(DisasContext *ctx, arg_EXTU *a)
9901016 temp = tcg_temp_new();
9911017 reg = h8300_reg_ld(a->sz - 1, a->r, temp);
9921018 h8300_reg_st(a->sz, a->r, reg);
993- tcg_gen_mov_i32(cpu_psw_z, reg);
994- tcg_gen_mov_i32(cpu_psw_s, reg);
995- h8300_ccr_adjist(a->sz);
1019+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1020+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1021+ h8300_ccr_adjust(a->sz);
9961022 tcg_gen_movi_i32(cpu_ccr_v, 0);
9971023 tcg_temp_free(temp);
9981024 return true;
@@ -1002,12 +1028,12 @@ static bool trans_AND_i(DisasContext *ctx, arg_AND_i *a)
10021028 {
10031029 TCGv temp, reg;
10041030 temp = tcg_temp_new();
1005- reg = h8300_reg_ld(a->sz - 1, a->r, temp);
1031+ reg = h8300_reg_ld(a->sz - 1, a->rd, temp);
10061032 tcg_gen_andi_i32(reg, reg, a->imm);
1007- h8300_reg_st(a->sz, a->r, reg);
1008- tcg_gen_mov_i32(cpu_psw_z, reg);
1009- tcg_gen_mov_i32(cpu_psw_s, reg);
1010- h8300_ccr_adjist(a->sz);
1033+ h8300_reg_st(a->sz, a->rd, reg);
1034+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1035+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1036+ h8300_ccr_adjust(a->sz);
10111037 tcg_gen_movi_i32(cpu_ccr_v, 0);
10121038 tcg_temp_free(temp);
10131039 return true;
@@ -1022,9 +1048,9 @@ static bool trans_AND_r(DisasContext *ctx, arg_AND_r *a)
10221048 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
10231049 tcg_gen_and_i32(reg1, reg1, reg2);
10241050 h8300_reg_st(a->sz, a->rd, reg1);
1025- tcg_gen_mov_i32(cpu_psw_z, reg1);
1026- tcg_gen_mov_i32(cpu_psw_s, reg1);
1027- h8300_ccr_adjist(a->sz);
1051+ tcg_gen_mov_i32(cpu_ccr_z, reg1);
1052+ tcg_gen_mov_i32(cpu_ccr_n, reg1);
1053+ h8300_ccr_adjust(a->sz);
10281054 tcg_gen_movi_i32(cpu_ccr_v, 0);
10291055 tcg_temp_free(temp1);
10301056 tcg_temp_free(temp2);
@@ -1035,12 +1061,12 @@ static bool trans_OR_i(DisasContext *ctx, arg_OR_i *a)
10351061 {
10361062 TCGv temp, reg;
10371063 temp = tcg_temp_new();
1038- reg = h8300_reg_ld(a->sz - 1, a->r, temp);
1064+ reg = h8300_reg_ld(a->sz - 1, a->rd, temp);
10391065 tcg_gen_ori_i32(reg, reg, a->imm);
1040- h8300_reg_st(a->sz, a->r, reg);
1041- tcg_gen_mov_i32(cpu_psw_z, reg);
1042- tcg_gen_mov_i32(cpu_psw_s, reg);
1043- h8300_ccr_adjist(a->sz);
1066+ h8300_reg_st(a->sz, a->rd, reg);
1067+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1068+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1069+ h8300_ccr_adjust(a->sz);
10441070 tcg_gen_movi_i32(cpu_ccr_v, 0);
10451071 tcg_temp_free(temp);
10461072 return true;
@@ -1055,9 +1081,9 @@ static bool trans_OR_r(DisasContext *ctx, arg_OR_r *a)
10551081 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
10561082 tcg_gen_or_i32(reg1, reg1, reg2);
10571083 h8300_reg_st(a->sz, a->rd, reg1);
1058- tcg_gen_mov_i32(cpu_psw_z, reg1);
1059- tcg_gen_mov_i32(cpu_psw_s, reg1);
1060- h8300_ccr_adjist(a->sz);
1084+ tcg_gen_mov_i32(cpu_ccr_z, reg1);
1085+ tcg_gen_mov_i32(cpu_ccr_n, reg1);
1086+ h8300_ccr_adjust(a->sz);
10611087 tcg_gen_movi_i32(cpu_ccr_v, 0);
10621088 tcg_temp_free(temp1);
10631089 tcg_temp_free(temp2);
@@ -1068,12 +1094,12 @@ static bool trans_XOR_i(DisasContext *ctx, arg_XOR_i *a)
10681094 {
10691095 TCGv temp, reg;
10701096 temp = tcg_temp_new();
1071- reg = h8300_reg_ld(a->sz - 1, a->r, temp);
1097+ reg = h8300_reg_ld(a->sz - 1, a->rd, temp);
10721098 tcg_gen_xori_i32(reg, reg, a->imm);
1073- h8300_reg_st(a->sz, a->r, reg);
1074- tcg_gen_mov_i32(cpu_psw_z, reg);
1075- tcg_gen_mov_i32(cpu_psw_s, reg);
1076- h8300_ccr_adjist(a->sz);
1099+ h8300_reg_st(a->sz, a->rd, reg);
1100+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1101+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1102+ h8300_ccr_adjust(a->sz);
10771103 tcg_gen_movi_i32(cpu_ccr_v, 0);
10781104 tcg_temp_free(temp);
10791105 return true;
@@ -1088,30 +1114,27 @@ static bool trans_XOR_r(DisasContext *ctx, arg_XOR_r *a)
10881114 reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
10891115 tcg_gen_xor_i32(reg1, reg1, reg2);
10901116 h8300_reg_st(a->sz, a->rd, reg1);
1091- tcg_gen_mov_i32(cpu_psw_z, reg1);
1092- tcg_gen_mov_i32(cpu_psw_s, reg1);
1093- h8300_ccr_adjist(a->sz);
1117+ tcg_gen_mov_i32(cpu_ccr_z, reg1);
1118+ tcg_gen_mov_i32(cpu_ccr_n, reg1);
1119+ h8300_ccr_adjust(a->sz);
10941120 tcg_gen_movi_i32(cpu_ccr_v, 0);
10951121 tcg_temp_free(temp1);
10961122 tcg_temp_free(temp2);
10971123 return true;
10981124 }
10991125
1100-static bool trans_NOT_r(DisasContext *ctx, arg_NOT_r *a)
1126+static bool trans_NOT(DisasContext *ctx, arg_NOT *a)
11011127 {
1102- TCGv temp1, temp2, reg1, reg2;
1103- temp1 = tcg_temp_new();
1104- temp2 = tcg_temp_new();
1105- reg1 = h8300_reg_ld(a->sz, a->rd, temp1);
1106- reg2 = h8300_reg_ld(a->sz, a->rs, temp2);
1107- tcg_gen_not_i32(reg1, reg1, reg2);
1108- h8300_reg_st(a->sz, a->rd, reg1);
1109- tcg_gen_mov_i32(cpu_psw_z, reg1);
1110- tcg_gen_mov_i32(cpu_psw_s, reg1);
1111- h8300_ccr_adjist(a->sz);
1128+ TCGv temp, reg;
1129+ temp = tcg_temp_new();
1130+ reg = h8300_reg_ld(a->sz, a->r, temp);
1131+ tcg_gen_not_i32(reg, reg);
1132+ h8300_reg_st(a->sz, a->r, reg);
1133+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1134+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1135+ h8300_ccr_adjust(a->sz);
11121136 tcg_gen_movi_i32(cpu_ccr_v, 0);
1113- tcg_temp_free(temp1);
1114- tcg_temp_free(temp2);
1137+ tcg_temp_free(temp);
11151138 return true;
11161139 }
11171140
@@ -1120,16 +1143,16 @@ static bool trans_SHAL(DisasContext *ctx, arg_SHAL *a)
11201143 TCGv temp, reg;
11211144 int s;
11221145 temp = tcg_temp_new();
1123- reg = h8300_reg_ld(a->sz, a->rd, temp);
1146+ reg = h8300_reg_ld(a->sz, a->r, temp);
11241147 s = 8 * (1 << a->sz) - 1 ;
1125- tcg_gen_extract_i32(cpu_psw_c, reg, s, 1);
1126- tcg_gen_shli_i32(cpu_psw_v, reg, 1);
1127- tcg_gen_xor_i32(cpu_psw_v, cpu_psw_v, reg);
1128- tcg_gen_extract_i32(cpu_psw_v, cpu_psw_v, s, 1);
1129- h8300_reg_st(a->sz, a->rd, reg);
1130- tcg_gen_mov_i32(cpu_psw_z, reg);
1131- tcg_gen_mov_i32(cpu_psw_s, reg);
1132- h8300_ccr_adjist(a->sz);
1148+ tcg_gen_extract_i32(cpu_ccr_c, reg, s, 1);
1149+ tcg_gen_shli_i32(cpu_ccr_v, reg, 1);
1150+ tcg_gen_xor_i32(cpu_ccr_v, cpu_ccr_v, reg);
1151+ tcg_gen_extract_i32(cpu_ccr_v, cpu_ccr_v, s, 1);
1152+ h8300_reg_st(a->sz, a->r, reg);
1153+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1154+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1155+ h8300_ccr_adjust(a->sz);
11331156 tcg_temp_free(temp);
11341157 return true;
11351158 }
@@ -1139,17 +1162,17 @@ static bool trans_SHAR(DisasContext *ctx, arg_SHAR *a)
11391162 TCGv temp, reg;
11401163 int s;
11411164 temp = tcg_temp_new();
1142- reg = h8300_reg_ld(a->sz, a->rd, temp);
1165+ reg = h8300_reg_ld(a->sz, a->r, temp);
11431166 s = 8 * (1 << a->sz) - 1 ;
1144- tcg_gen_extract_i32(cpu_psw_c, reg, 0, 1);
1145- tcg_gen_andi_i32(cpu_psw_v, reg, 1 << s);
1167+ tcg_gen_extract_i32(cpu_ccr_c, reg, 0, 1);
1168+ tcg_gen_andi_i32(cpu_ccr_v, reg, 1 << s);
11461169 tcg_gen_shri_i32(reg, reg, 1);
1147- tcg_gen_or_i32(reg, reg, cpu_psw_v);
1148- h8300_reg_st(a->sz, a->rd, reg);
1149- tcg_gen_mov_i32(cpu_psw_z, reg);
1150- tcg_gen_mov_i32(cpu_psw_s, reg);
1151- tcg_gen_mov_i32(cpu_psw_v, 0);
1152- h8300_ccr_adjist(a->sz);
1170+ tcg_gen_or_i32(reg, reg, cpu_ccr_v);
1171+ h8300_reg_st(a->sz, a->r, reg);
1172+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1173+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1174+ tcg_gen_mov_i32(cpu_ccr_v, 0);
1175+ h8300_ccr_adjust(a->sz);
11531176 tcg_temp_free(temp);
11541177 return true;
11551178 }
@@ -1159,15 +1182,15 @@ static bool trans_SHLL(DisasContext *ctx, arg_SHLL *a)
11591182 TCGv temp, reg;
11601183 int s;
11611184 temp = tcg_temp_new();
1162- reg = h8300_reg_ld(a->sz, a->rd, temp);
1185+ reg = h8300_reg_ld(a->sz, a->r, temp);
11631186 s = 8 * (1 << a->sz) - 1 ;
1164- tcg_gen_extract_i32(cpu_psw_c, reg, s, 1);
1187+ tcg_gen_extract_i32(cpu_ccr_c, reg, s, 1);
11651188 tcg_gen_shli_i32(reg, reg, 1);
1166- h8300_reg_st(a->sz, a->rd, reg);
1167- tcg_gen_mov_i32(cpu_psw_z, reg);
1168- tcg_gen_mov_i32(cpu_psw_s, reg);
1169- h8300_ccr_adjist(a->sz);
1170- tcg_gen_mov_i32(cpu_psw_v, 0);
1189+ h8300_reg_st(a->sz, a->r, reg);
1190+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1191+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1192+ h8300_ccr_adjust(a->sz);
1193+ tcg_gen_mov_i32(cpu_ccr_v, 0);
11711194 tcg_temp_free(temp);
11721195 return true;
11731196 }
@@ -1175,17 +1198,15 @@ static bool trans_SHLL(DisasContext *ctx, arg_SHLL *a)
11751198 static bool trans_SHLR(DisasContext *ctx, arg_SHLR *a)
11761199 {
11771200 TCGv temp, reg;
1178- int s;
11791201 temp = tcg_temp_new();
1180- reg = h8300_reg_ld(a->sz, a->rd, temp);
1181- s = 8 * (1 << a->sz) - 1 ;
1182- tcg_gen_extract_i32(cpu_psw_c, reg, 0, 1);
1202+ reg = h8300_reg_ld(a->sz, a->r, temp);
1203+ tcg_gen_extract_i32(cpu_ccr_c, reg, 0, 1);
11831204 tcg_gen_shri_i32(reg, reg, 1);
1184- h8300_reg_st(a->sz, a->rd, reg);
1185- tcg_gen_mov_i32(cpu_psw_z, reg);
1186- tcg_gen_mov_i32(cpu_psw_s, reg);
1187- h8300_ccr_adjist(a->sz);
1188- tcg_gen_mov_i32(cpu_psw_v, 0);
1205+ h8300_reg_st(a->sz, a->r, reg);
1206+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1207+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1208+ h8300_ccr_adjust(a->sz);
1209+ tcg_gen_mov_i32(cpu_ccr_v, 0);
11891210 tcg_temp_free(temp);
11901211 return true;
11911212 }
@@ -1195,16 +1216,16 @@ static bool trans_ROTL(DisasContext *ctx, arg_ROTL *a)
11951216 TCGv temp, reg;
11961217 int s;
11971218 temp = tcg_temp_new();
1198- reg = h8300_reg_ld(a->sz, a->rd, temp);
1219+ reg = h8300_reg_ld(a->sz, a->r, temp);
11991220 s = 8 * (1 << a->sz) - 1 ;
1200- tcg_gen_extract_i32(cpu_psw_c, reg, s, 1);
1221+ tcg_gen_extract_i32(cpu_ccr_c, reg, s, 1);
12011222 tcg_gen_shli_i32(reg, reg, 1);
1202- tcg_gen_or_i32(reg, reg, cpu_psw_c);
1203- h8300_reg_st(a->sz, a->rd, reg);
1204- tcg_gen_mov_i32(cpu_psw_z, reg);
1205- tcg_gen_mov_i32(cpu_psw_s, reg);
1206- h8300_ccr_adjist(a->sz);
1207- tcg_gen_mov_i32(cpu_psw_v, 0);
1223+ tcg_gen_or_i32(reg, reg, cpu_ccr_c);
1224+ h8300_reg_st(a->sz, a->r, reg);
1225+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1226+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1227+ h8300_ccr_adjust(a->sz);
1228+ tcg_gen_mov_i32(cpu_ccr_v, 0);
12081229 tcg_temp_free(temp);
12091230 return true;
12101231 }
@@ -1212,20 +1233,18 @@ static bool trans_ROTL(DisasContext *ctx, arg_ROTL *a)
12121233 static bool trans_ROTR(DisasContext *ctx, arg_ROTR *a)
12131234 {
12141235 TCGv temp, reg, c;
1215- int s;
12161236 temp = tcg_temp_new();
12171237 c = tcg_temp_new();
1218- reg = h8300_reg_ld(a->sz, a->rd, temp);
1219- s = 8 * (1 << a->sz) - 1;
1220- tcg_gen_extract_i32(cpu_psw_c, reg, 0, 1);
1238+ reg = h8300_reg_ld(a->sz, a->r, temp);
1239+ tcg_gen_shli_i32(c, cpu_ccr_c, (1 << a->sz) - 1);
1240+ tcg_gen_extract_i32(cpu_ccr_c, reg, 0, 1);
12211241 tcg_gen_shri_i32(reg, reg, 1);
1222- tcg_gen_shli_i32(c, cpu_psw, (1 << a->sz) - 1);
12231242 tcg_gen_or_i32(reg, reg, c);
1224- h8300_reg_st(a->sz, a->rd, reg);
1225- tcg_gen_mov_i32(cpu_psw_z, reg);
1226- tcg_gen_mov_i32(cpu_psw_s, reg);
1227- h8300_ccr_adjist(a->sz);
1228- tcg_gen_mov_i32(cpu_psw_v, 0);
1243+ h8300_reg_st(a->sz, a->r, reg);
1244+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1245+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1246+ h8300_ccr_adjust(a->sz);
1247+ tcg_gen_mov_i32(cpu_ccr_v, 0);
12291248 tcg_temp_free(temp);
12301249 tcg_temp_free(c);
12311250 return true;
@@ -1237,17 +1256,17 @@ static bool trans_ROTXL(DisasContext *ctx, arg_ROTXL *a)
12371256 int s;
12381257 temp = tcg_temp_new();
12391258 c = tcg_temp_new();
1240- reg = h8300_reg_ld(a->sz, a->rd, temp);
1259+ reg = h8300_reg_ld(a->sz, a->r, temp);
12411260 s = 8 * (1 << a->sz) - 1 ;
12421261 tcg_gen_extract_i32(c, reg, s, 1);
12431262 tcg_gen_shli_i32(reg, reg, 1);
1244- tcg_gen_or_i32(reg, reg, cpu_psw_c);
1245- tcg_gen_mov_i32(cpu_psw_c, c);
1246- h8300_reg_st(a->sz, a->rd, reg);
1247- tcg_gen_mov_i32(cpu_psw_z, reg);
1248- tcg_gen_mov_i32(cpu_psw_s, reg);
1249- h8300_ccr_adjist(a->sz);
1250- tcg_gen_mov_i32(cpu_psw_v, 0);
1263+ tcg_gen_or_i32(reg, reg, cpu_ccr_c);
1264+ tcg_gen_mov_i32(cpu_ccr_c, c);
1265+ h8300_reg_st(a->sz, a->r, reg);
1266+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1267+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1268+ h8300_ccr_adjust(a->sz);
1269+ tcg_gen_mov_i32(cpu_ccr_v, 0);
12511270 tcg_temp_free(temp);
12521271 tcg_temp_free(c);
12531272 return true;
@@ -1256,21 +1275,19 @@ static bool trans_ROTXL(DisasContext *ctx, arg_ROTXL *a)
12561275 static bool trans_ROTXR(DisasContext *ctx, arg_ROTXR *a)
12571276 {
12581277 TCGv temp, reg, c;
1259- int s;
12601278 temp = tcg_temp_new();
12611279 c = tcg_temp_new();
1262- reg = h8300_reg_ld(a->sz, a->rd, temp);
1263- s = 8 * (1 << a->sz) - 1;
1280+ reg = h8300_reg_ld(a->sz, a->r, temp);
12641281 tcg_gen_extract_i32(c, reg, 0, 1);
12651282 tcg_gen_shri_i32(reg, reg, 1);
1266- tcg_gen_shli_i32(cpu_psw_c, cpu_psw_c, (1 << a->sz) - 1);
1267- tcg_gen_or_i32(reg, reg, cpu_psw_c);
1268- h8300_reg_st(a->sz, a->rd, reg);
1269- tcg_gen_mov_i32(cpu_psw_c, c);
1270- tcg_gen_mov_i32(cpu_psw_z, reg);
1271- tcg_gen_mov_i32(cpu_psw_s, reg);
1272- h8300_ccr_adjist(a->sz);
1273- tcg_gen_mov_i32(cpu_psw_v, 0);
1283+ tcg_gen_shli_i32(cpu_ccr_c, cpu_ccr_c, (1 << a->sz) - 1);
1284+ tcg_gen_or_i32(reg, reg, cpu_ccr_c);
1285+ h8300_reg_st(a->sz, a->r, reg);
1286+ tcg_gen_mov_i32(cpu_ccr_c, c);
1287+ tcg_gen_mov_i32(cpu_ccr_z, reg);
1288+ tcg_gen_mov_i32(cpu_ccr_n, reg);
1289+ h8300_ccr_adjust(a->sz);
1290+ tcg_gen_mov_i32(cpu_ccr_v, 0);
12741291 tcg_temp_free(temp);
12751292 tcg_temp_free(c);
12761293 return true;
@@ -1282,9 +1299,9 @@ static bool trans_BAND_r(DisasContext *ctx, arg_BAND_r *a)
12821299 temp = tcg_temp_new();
12831300 mask = tcg_temp_new();
12841301 h8300_gen_reg_ldb(a->r, temp);
1285- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1302+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
12861303 tcg_gen_and_i32(mask, temp, mask);
1287- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1304+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
12881305 tcg_temp_free(temp);
12891306 tcg_temp_free(mask);
12901307 return true;
@@ -1295,10 +1312,10 @@ static bool trans_BAND_m(DisasContext *ctx, arg_BAND_m *a)
12951312 TCGv temp, mask;
12961313 temp = tcg_temp_new();
12971314 mask = tcg_temp_new();
1298- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1299- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1315+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
1316+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
13001317 tcg_gen_and_i32(mask, temp, mask);
1301- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1318+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
13021319 tcg_temp_free(temp);
13031320 tcg_temp_free(mask);
13041321 return true;
@@ -1310,10 +1327,10 @@ static bool trans_BAND_a(DisasContext *ctx, arg_BAND_a *a)
13101327 temp = tcg_temp_new();
13111328 mask = tcg_temp_new();
13121329 mem = tcg_const_i32(0xffff00 | a->abs);
1313- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1314- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1330+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
1331+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
13151332 tcg_gen_and_i32(mask, temp, mask);
1316- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1333+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
13171334 tcg_temp_free(temp);
13181335 tcg_temp_free(mask);
13191336 tcg_temp_free(mem);
@@ -1327,9 +1344,9 @@ static bool trans_BIAND_r(DisasContext *ctx, arg_BIAND_r *a)
13271344 mask = tcg_temp_new();
13281345 h8300_gen_reg_ldb(a->r, temp);
13291346 tcg_gen_not_i32(temp, temp);
1330- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1347+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
13311348 tcg_gen_and_i32(mask, temp, mask);
1332- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1349+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
13331350 tcg_temp_free(temp);
13341351 tcg_temp_free(mask);
13351352 return true;
@@ -1340,11 +1357,11 @@ static bool trans_BIAND_m(DisasContext *ctx, arg_BIAND_m *a)
13401357 TCGv temp, mask;
13411358 temp = tcg_temp_new();
13421359 mask = tcg_temp_new();
1343- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1360+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
13441361 tcg_gen_not_i32(temp, temp);
1345- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1362+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
13461363 tcg_gen_and_i32(mask, temp, mask);
1347- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1364+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
13481365 tcg_temp_free(temp);
13491366 tcg_temp_free(mask);
13501367 return true;
@@ -1356,11 +1373,11 @@ static bool trans_BIAND_a(DisasContext *ctx, arg_BIAND_a *a)
13561373 temp = tcg_temp_new();
13571374 mask = tcg_temp_new();
13581375 mem = tcg_const_i32(0xffff00 | a->abs);
1359- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1376+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
13601377 tcg_gen_not_i32(temp, temp);
1361- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1378+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
13621379 tcg_gen_and_i32(mask, temp, mask);
1363- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1380+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
13641381 tcg_temp_free(temp);
13651382 tcg_temp_free(mask);
13661383 tcg_temp_free(mem);
@@ -1373,30 +1390,30 @@ static bool trans_BILD_r(DisasContext *ctx, arg_BILD_r *a)
13731390 temp = tcg_temp_new();
13741391 h8300_gen_reg_ldb(a->r, temp);
13751392 tcg_gen_not_i32(temp, temp);
1376- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1393+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
13771394 tcg_temp_free(temp);
13781395 return true;
13791396 }
13801397
13811398 static bool trans_BILD_m(DisasContext *ctx, arg_BILD_m *a)
13821399 {
1383- TCGv temp, mask;
1400+ TCGv temp;
13841401 temp = tcg_temp_new();
1385- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1402+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
13861403 tcg_gen_not_i32(temp, temp);
1387- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1404+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
13881405 tcg_temp_free(temp);
13891406 return true;
13901407 }
13911408
13921409 static bool trans_BILD_a(DisasContext *ctx, arg_BILD_a *a)
13931410 {
1394- TCGv temp, mask, mem;
1411+ TCGv temp, mem;
13951412 temp = tcg_temp_new();
13961413 mem = tcg_const_i32(0xffff00 | a->abs);
1397- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1414+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
13981415 tcg_gen_not_i32(temp, temp);
1399- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1416+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
14001417 tcg_temp_free(temp);
14011418 tcg_temp_free(mem);
14021419 return true;
@@ -1410,9 +1427,9 @@ static bool trans_BIOR_r(DisasContext *ctx, arg_BIOR_r *a)
14101427 h8300_gen_reg_ldb(a->r, temp);
14111428 tcg_gen_not_i32(temp, temp);
14121429 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1413- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1430+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
14141431 tcg_gen_or_i32(mask, temp, mask);
1415- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1432+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
14161433 tcg_temp_free(temp);
14171434 tcg_temp_free(mask);
14181435 return true;
@@ -1423,12 +1440,12 @@ static bool trans_BIOR_m(DisasContext *ctx, arg_BIOR_m *a)
14231440 TCGv temp, mask;
14241441 temp = tcg_temp_new();
14251442 mask = tcg_temp_new();
1426- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1443+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
14271444 tcg_gen_not_i32(temp, temp);
14281445 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1429- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1446+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
14301447 tcg_gen_or_i32(mask, temp, mask);
1431- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1448+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
14321449 tcg_temp_free(temp);
14331450 tcg_temp_free(mask);
14341451 return true;
@@ -1440,12 +1457,12 @@ static bool trans_BIOR_a(DisasContext *ctx, arg_BIOR_a *a)
14401457 temp = tcg_temp_new();
14411458 mask = tcg_temp_new();
14421459 mem = tcg_const_i32(0xffff00 | a->abs);
1443- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1460+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
14441461 tcg_gen_not_i32(temp, temp);
14451462 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1446- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1463+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
14471464 tcg_gen_or_i32(mask, temp, mask);
1448- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1465+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
14491466 tcg_temp_free(temp);
14501467 tcg_temp_free(mask);
14511468 tcg_temp_free(mem);
@@ -1459,7 +1476,7 @@ static bool trans_BIST_r(DisasContext *ctx, arg_BIST_r *a)
14591476 mask = tcg_temp_new();
14601477 h8300_gen_reg_ldb(a->r, temp);
14611478 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1462- tcg_gen_not_i32(mask, cpu_psw_c);
1479+ tcg_gen_not_i32(mask, cpu_ccr_c);
14631480 tcg_gen_shli_i32(mask, mask, a->imm);
14641481 tcg_gen_or_i32(temp, temp, mask);
14651482 h8300_gen_reg_stb(a->r, temp);
@@ -1473,13 +1490,13 @@ static bool trans_BIST_m(DisasContext *ctx, arg_BIST_m *a)
14731490 TCGv temp, mask;
14741491 temp = tcg_temp_new();
14751492 mask = tcg_temp_new();
1476- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1493+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
14771494 tcg_gen_not_i32(temp, temp);
14781495 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1479- tcg_gen_not_i32(mask, cpu_psw_c);
1496+ tcg_gen_not_i32(mask, cpu_ccr_c);
14801497 tcg_gen_shli_i32(mask, mask, a->imm);
14811498 tcg_gen_or_i32(temp, temp, mask);
1482- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1499+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
14831500 tcg_temp_free(temp);
14841501 tcg_temp_free(mask);
14851502 return true;
@@ -1491,13 +1508,13 @@ static bool trans_BIST_a(DisasContext *ctx, arg_BIST_a *a)
14911508 temp = tcg_temp_new();
14921509 mask = tcg_temp_new();
14931510 mem = tcg_const_i32(0xffff00 | a->abs);
1494- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1511+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
14951512 tcg_gen_not_i32(temp, temp);
14961513 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1497- tcg_gen_not_i32(mask, cpu_psw_c);
1514+ tcg_gen_not_i32(mask, cpu_ccr_c);
14981515 tcg_gen_shli_i32(mask, mask, a->imm);
14991516 tcg_gen_or_i32(temp, temp, mask);
1500- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1517+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
15011518 tcg_temp_free(temp);
15021519 tcg_temp_free(mask);
15031520 tcg_temp_free(mem);
@@ -1512,9 +1529,9 @@ static bool trans_BIXOR_r(DisasContext *ctx, arg_BIXOR_r *a)
15121529 h8300_gen_reg_ldb(a->r, temp);
15131530 tcg_gen_not_i32(temp, temp);
15141531 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1515- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1532+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
15161533 tcg_gen_xor_i32(mask, temp, mask);
1517- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1534+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
15181535 tcg_temp_free(temp);
15191536 tcg_temp_free(mask);
15201537 return true;
@@ -1525,12 +1542,12 @@ static bool trans_BIXOR_m(DisasContext *ctx, arg_BIXOR_m *a)
15251542 TCGv temp, mask;
15261543 temp = tcg_temp_new();
15271544 mask = tcg_temp_new();
1528- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1545+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
15291546 tcg_gen_not_i32(temp, temp);
15301547 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1531- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1548+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
15321549 tcg_gen_xor_i32(mask, temp, mask);
1533- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1550+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
15341551 tcg_temp_free(temp);
15351552 tcg_temp_free(mask);
15361553 return true;
@@ -1542,12 +1559,12 @@ static bool trans_BIXOR_a(DisasContext *ctx, arg_BIXOR_a *a)
15421559 temp = tcg_temp_new();
15431560 mask = tcg_temp_new();
15441561 mem = tcg_const_i32(0xffff00 | a->abs);
1545- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1562+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
15461563 tcg_gen_not_i32(temp, temp);
15471564 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1548- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1565+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
15491566 tcg_gen_xor_i32(mask, temp, mask);
1550- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1567+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
15511568 tcg_temp_free(temp);
15521569 tcg_temp_free(mask);
15531570 tcg_temp_free(mem);
@@ -1559,28 +1576,28 @@ static bool trans_BLD_r(DisasContext *ctx, arg_BLD_r *a)
15591576 TCGv temp;
15601577 temp = tcg_temp_new();
15611578 h8300_gen_reg_ldb(a->r, temp);
1562- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1579+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
15631580 tcg_temp_free(temp);
15641581 return true;
15651582 }
15661583
15671584 static bool trans_BLD_m(DisasContext *ctx, arg_BLD_m *a)
15681585 {
1569- TCGv temp, mask;
1586+ TCGv temp;
15701587 temp = tcg_temp_new();
1571- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1572- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1588+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
1589+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
15731590 tcg_temp_free(temp);
15741591 return true;
15751592 }
15761593
15771594 static bool trans_BLD_a(DisasContext *ctx, arg_BLD_a *a)
15781595 {
1579- TCGv temp, mask, mem;
1596+ TCGv temp, mem;
15801597 temp = tcg_temp_new();
15811598 mem = tcg_const_i32(0xffff00 | a->abs);
1582- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1583- tcg_gen_extract_i32(cpu_psw_c, temp, a->imm, 1);
1599+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
1600+ tcg_gen_extract_i32(cpu_ccr_c, temp, a->imm, 1);
15841601 tcg_temp_free(temp);
15851602 tcg_temp_free(mem);
15861603 return true;
@@ -1593,9 +1610,9 @@ static bool trans_BOR_r(DisasContext *ctx, arg_BOR_r *a)
15931610 mask = tcg_temp_new();
15941611 h8300_gen_reg_ldb(a->r, temp);
15951612 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1596- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1613+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
15971614 tcg_gen_or_i32(mask, temp, mask);
1598- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1615+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
15991616 tcg_temp_free(temp);
16001617 tcg_temp_free(mask);
16011618 return true;
@@ -1606,11 +1623,11 @@ static bool trans_BOR_m(DisasContext *ctx, arg_BOR_m *a)
16061623 TCGv temp, mask;
16071624 temp = tcg_temp_new();
16081625 mask = tcg_temp_new();
1609- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1626+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
16101627 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1611- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1628+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16121629 tcg_gen_or_i32(mask, temp, mask);
1613- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1630+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
16141631 tcg_temp_free(temp);
16151632 tcg_temp_free(mask);
16161633 return true;
@@ -1622,11 +1639,11 @@ static bool trans_BOR_a(DisasContext *ctx, arg_BOR_a *a)
16221639 temp = tcg_temp_new();
16231640 mask = tcg_temp_new();
16241641 mem = tcg_const_i32(0xffff00 | a->abs);
1625- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1642+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
16261643 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1627- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1644+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16281645 tcg_gen_or_i32(mask, temp, mask);
1629- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1646+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
16301647 tcg_temp_free(temp);
16311648 tcg_temp_free(mask);
16321649 tcg_temp_free(mem);
@@ -1640,7 +1657,7 @@ static bool trans_BST_r(DisasContext *ctx, arg_BST_r *a)
16401657 mask = tcg_temp_new();
16411658 h8300_gen_reg_ldb(a->r, temp);
16421659 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1643- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1660+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16441661 tcg_gen_or_i32(temp, temp, mask);
16451662 h8300_gen_reg_stb(a->r, temp);
16461663 tcg_temp_free(temp);
@@ -1648,34 +1665,32 @@ static bool trans_BST_r(DisasContext *ctx, arg_BST_r *a)
16481665 return true;
16491666 }
16501667
1651-static bool trans_BIST_m(DisasContext *ctx, arg_BIST_m *a)
1668+static bool trans_BST_m(DisasContext *ctx, arg_BST_m *a)
16521669 {
16531670 TCGv temp, mask;
16541671 temp = tcg_temp_new();
16551672 mask = tcg_temp_new();
1656- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1657- tcg_gen_not_i32(temp, temp);
1673+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
16581674 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1659- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1675+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16601676 tcg_gen_or_i32(temp, temp, mask);
1661- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1677+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
16621678 tcg_temp_free(temp);
16631679 tcg_temp_free(mask);
16641680 return true;
16651681 }
16661682
1667-static bool trans_BIST_a(DisasContext *ctx, arg_BIST_a *a)
1683+static bool trans_BST_a(DisasContext *ctx, arg_BST_a *a)
16681684 {
16691685 TCGv temp, mask, mem;
16701686 temp = tcg_temp_new();
16711687 mask = tcg_temp_new();
16721688 mem = tcg_const_i32(0xffff00 | a->abs);
1673- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1674- tcg_gen_not_i32(temp, temp);
1689+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
16751690 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1676- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1691+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16771692 tcg_gen_or_i32(temp, temp, mask);
1678- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1693+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
16791694 tcg_temp_free(temp);
16801695 tcg_temp_free(mask);
16811696 tcg_temp_free(mem);
@@ -1689,9 +1704,9 @@ static bool trans_BXOR_r(DisasContext *ctx, arg_BXOR_r *a)
16891704 mask = tcg_temp_new();
16901705 h8300_gen_reg_ldb(a->r, temp);
16911706 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1692- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1707+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
16931708 tcg_gen_xor_i32(mask, temp, mask);
1694- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1709+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
16951710 tcg_temp_free(temp);
16961711 tcg_temp_free(mask);
16971712 return true;
@@ -1702,11 +1717,11 @@ static bool trans_BXOR_m(DisasContext *ctx, arg_BXOR_m *a)
17021717 TCGv temp, mask;
17031718 temp = tcg_temp_new();
17041719 mask = tcg_temp_new();
1705- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1720+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
17061721 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1707- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1722+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
17081723 tcg_gen_xor_i32(mask, temp, mask);
1709- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1724+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
17101725 tcg_temp_free(temp);
17111726 tcg_temp_free(mask);
17121727 return true;
@@ -1718,11 +1733,11 @@ static bool trans_BXOR_a(DisasContext *ctx, arg_BXOR_a *a)
17181733 temp = tcg_temp_new();
17191734 mask = tcg_temp_new();
17201735 mem = tcg_const_i32(0xffff00 | a->abs);
1721- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1736+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
17221737 tcg_gen_andi_i32(temp, temp, 1 << a->imm);
1723- tcg_gen_shli_i32(mask, cpu_psw_c, a->imm);
1738+ tcg_gen_shli_i32(mask, cpu_ccr_c, a->imm);
17241739 tcg_gen_xor_i32(mask, temp, mask);
1725- tcg_gen_setcondi_i32(TCG_COND_NE, cpu_psw_c, mask, 0);
1740+ tcg_gen_setcondi_i32(TCG_COND_NE, cpu_ccr_c, mask, 0);
17261741 tcg_temp_free(temp);
17271742 tcg_temp_free(mask);
17281743 tcg_temp_free(mem);
@@ -1744,11 +1759,10 @@ static bool trans_BCLR_im(DisasContext *ctx, arg_BCLR_im *a)
17441759 {
17451760 TCGv temp;
17461761 temp = tcg_temp_new();
1747- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1762+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
17481763 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1749- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1764+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
17501765 tcg_temp_free(temp);
1751- tcg_temp_free(mask);
17521766 return true;
17531767 }
17541768
@@ -1757,9 +1771,9 @@ static bool trans_BCLR_ia(DisasContext *ctx, arg_BCLR_ia *a)
17571771 TCGv temp, mem;
17581772 temp = tcg_temp_new();
17591773 mem = tcg_const_i32(0xffff00 | a->abs);
1760- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1774+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
17611775 tcg_gen_andi_i32(temp, temp, ~1 << a->imm);
1762- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1776+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
17631777 tcg_temp_free(temp);
17641778 tcg_temp_free(mem);
17651779 return true;
@@ -1767,51 +1781,60 @@ static bool trans_BCLR_ia(DisasContext *ctx, arg_BCLR_ia *a)
17671781
17681782 static bool trans_BCLR_rr(DisasContext *ctx, arg_BCLR_rr *a)
17691783 {
1770- TCGv temp, mask;
1784+ TCGv temp, mask, shift;
17711785 temp = tcg_temp_new();
17721786 mask = tcg_temp_new();
1787+ shift = tcg_temp_new();
17731788 h8300_gen_reg_ldb(a->rd, temp);
1789+ h8300_gen_reg_ldb(a->rs, shift);
17741790 tcg_gen_movi_i32(mask, 1);
1775- tcg_gen_shl_i32(mask, mask, a->rs);
1791+ tcg_gen_shl_i32(mask, mask, shift);
17761792 tcg_gen_not_i32(mask, mask);
17771793 tcg_gen_and_i32(temp, temp, mask);
1778- h8300_gen_reg_stb(a->r, temp);
1794+ h8300_gen_reg_stb(a->rd, temp);
17791795 tcg_temp_free(temp);
17801796 tcg_temp_free(mask);
1797+ tcg_temp_free(shift);
17811798 return true;
17821799 }
17831800
17841801 static bool trans_BCLR_rm(DisasContext *ctx, arg_BCLR_rm *a)
17851802 {
1786- TCGv temp, mask;
1803+ TCGv temp, mask, shift;
17871804 temp = tcg_temp_new();
17881805 mask = tcg_temp_new();
1789- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1806+ shift = tcg_temp_new();
1807+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
1808+ h8300_gen_reg_ldb(a->rn, shift);
17901809 tcg_gen_movi_i32(mask, 1);
1791- tcg_gen_shl_i32(mask, mask, a->rs);
1810+ tcg_gen_shl_i32(mask, mask, shift);
17921811 tcg_gen_not_i32(mask, mask);
17931812 tcg_gen_and_i32(temp, temp, mask);
1794- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1813+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
17951814 tcg_temp_free(temp);
17961815 tcg_temp_free(mask);
1816+ tcg_temp_free(shift);
17971817 return true;
17981818 }
17991819
18001820 static bool trans_BCLR_ra(DisasContext *ctx, arg_BCLR_ra *a)
18011821 {
1802- TCGv temp, mask, mem;
1822+ TCGv temp, mask, mem, shift;
18031823 temp = tcg_temp_new();
18041824 mask = tcg_temp_new();
18051825 mem = tcg_const_i32(0xffff00 | a->abs);
1806- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1826+ shift = tcg_temp_new();
1827+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
1828+ h8300_gen_reg_ldb(a->rn, shift);
18071829 tcg_gen_movi_i32(mask, 1);
1808- tcg_gen_shl_i32(mask, mask, a->rs);
1830+ tcg_gen_shl_i32(mask, mask, shift);
18091831 tcg_gen_not_i32(mask, mask);
18101832 tcg_gen_and_i32(temp, temp, mask);
1811- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1833+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
18121834 tcg_temp_free(temp);
18131835 tcg_temp_free(mask);
18141836 tcg_temp_free(mem);
1837+ tcg_temp_free(shift);
18151838 return true;
18161839 }
18171840
@@ -1830,21 +1853,21 @@ static bool trans_BNOT_im(DisasContext *ctx, arg_BNOT_im *a)
18301853 {
18311854 TCGv temp;
18321855 temp = tcg_temp_new();
1833- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1856+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
18341857 tcg_gen_xori_i32(temp, temp, 1 << a->imm);
1835- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1858+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
18361859 tcg_temp_free(temp);
18371860 return true;
18381861 }
18391862
1840-static bool trans_BNOT_ia(DisasContext *ctx, arg_BNOT_ra *a)
1863+static bool trans_BNOT_ia(DisasContext *ctx, arg_BNOT_ia *a)
18411864 {
18421865 TCGv temp, mem;
18431866 temp = tcg_temp_new();
18441867 mem = tcg_const_i32(0xffff00 | a->abs);
1845- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1868+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
18461869 tcg_gen_xori_i32(temp, temp, 1 << a->imm);
1847- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1870+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
18481871 tcg_temp_free(temp);
18491872 tcg_temp_free(mem);
18501873 return true;
@@ -1852,29 +1875,34 @@ static bool trans_BNOT_ia(DisasContext *ctx, arg_BNOT_ra *a)
18521875
18531876 static bool trans_BNOT_rr(DisasContext *ctx, arg_BNOT_rr *a)
18541877 {
1855- TCGv temp, mask;
1878+ TCGv temp, mask, shift;
18561879 temp = tcg_temp_new();
18571880 mask = tcg_temp_new();
1881+ shift = tcg_temp_new();
18581882 h8300_gen_reg_ldb(a->rd, temp);
1883+ h8300_gen_reg_ldb(a->rs, shift);
18591884 tcg_gen_movi_i32(mask, 1);
1860- tcg_gen_shl_i32(mask, mask, a->rs);
1885+ tcg_gen_shl_i32(mask, mask, shift);
18611886 tcg_gen_xor_i32(temp, temp, mask);
1862- h8300_gen_reg_stb(a->r, temp);
1887+ h8300_gen_reg_stb(a->rd, temp);
18631888 tcg_temp_free(temp);
18641889 tcg_temp_free(mask);
1890+ tcg_temp_free(shift);
18651891 return true;
18661892 }
18671893
18681894 static bool trans_BNOT_rm(DisasContext *ctx, arg_BNOT_rm *a)
18691895 {
1870- TCGv temp, mask;
1896+ TCGv temp, mask, shift;
18711897 temp = tcg_temp_new();
18721898 mask = tcg_temp_new();
1873- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1899+ shift = tcg_temp_new();
1900+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
1901+ h8300_gen_reg_ldb(a->rn, shift);
18741902 tcg_gen_movi_i32(mask, 1);
1875- tcg_gen_shl_i32(mask, mask, a->rs);
1903+ tcg_gen_shl_i32(mask, mask, shift);
18761904 tcg_gen_xor_i32(temp, temp, mask);
1877- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1905+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
18781906 tcg_temp_free(temp);
18791907 tcg_temp_free(mask);
18801908 return true;
@@ -1882,18 +1910,21 @@ static bool trans_BNOT_rm(DisasContext *ctx, arg_BNOT_rm *a)
18821910
18831911 static bool trans_BNOT_ra(DisasContext *ctx, arg_BNOT_ra *a)
18841912 {
1885- TCGv temp, mask, mem;
1913+ TCGv temp, mask, mem, shift;
18861914 temp = tcg_temp_new();
18871915 mask = tcg_temp_new();
18881916 mem = tcg_const_i32(0xffff00 | a->abs);
1889- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1917+ shift = tcg_temp_new();
1918+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
1919+ h8300_gen_reg_ldb(a->rn, shift);
18901920 tcg_gen_movi_i32(mask, 1);
1891- tcg_gen_shl_i32(mask, mask, a->rs);
1921+ tcg_gen_shl_i32(mask, mask, shift);
18921922 tcg_gen_xor_i32(temp, temp, mask);
1893- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1923+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
18941924 tcg_temp_free(temp);
18951925 tcg_temp_free(mask);
18961926 tcg_temp_free(mem);
1927+ tcg_temp_free(shift);
18971928 return true;
18981929 }
18991930
@@ -1912,21 +1943,21 @@ static bool trans_BSET_im(DisasContext *ctx, arg_BSET_im *a)
19121943 {
19131944 TCGv temp;
19141945 temp = tcg_temp_new();
1915- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1946+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
19161947 tcg_gen_ori_i32(temp, temp, 1 << a->imm);
1917- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1948+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
19181949 tcg_temp_free(temp);
19191950 return true;
19201951 }
19211952
1922-static bool trans_BSET_ia(DisasContext *ctx, arg_BSET_ra *a)
1953+static bool trans_BSET_ia(DisasContext *ctx, arg_BSET_ia *a)
19231954 {
19241955 TCGv temp, mem;
19251956 temp = tcg_temp_new();
19261957 mem = tcg_const_i32(0xffff00 | a->abs);
1927- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1958+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
19281959 tcg_gen_ori_i32(temp, temp, 1 << a->imm);
1929- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
1960+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
19301961 tcg_temp_free(temp);
19311962 tcg_temp_free(mem);
19321963 return true;
@@ -1934,48 +1965,57 @@ static bool trans_BSET_ia(DisasContext *ctx, arg_BSET_ra *a)
19341965
19351966 static bool trans_BSET_rr(DisasContext *ctx, arg_BSET_rr *a)
19361967 {
1937- TCGv temp, mask;
1968+ TCGv temp, mask, shift;
19381969 temp = tcg_temp_new();
19391970 mask = tcg_temp_new();
1971+ shift = tcg_temp_new();
19401972 h8300_gen_reg_ldb(a->rd, temp);
1973+ h8300_gen_reg_ldb(a->rs, shift);
19411974 tcg_gen_movi_i32(mask, 1);
1942- tcg_gen_shl_i32(mask, mask, a->rs);
1975+ tcg_gen_shl_i32(mask, mask, shift);
19431976 tcg_gen_or_i32(temp, temp, mask);
1944- h8300_gen_reg_stb(a->r, temp);
1977+ h8300_gen_reg_stb(a->rd, temp);
19451978 tcg_temp_free(temp);
19461979 tcg_temp_free(mask);
1980+ tcg_temp_free(shift);
19471981 return true;
19481982 }
19491983
19501984 static bool trans_BSET_rm(DisasContext *ctx, arg_BSET_rm *a)
19511985 {
1952- TCGv temp, mask;
1986+ TCGv temp, mask, shift;
19531987 temp = tcg_temp_new();
19541988 mask = tcg_temp_new();
1955- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1989+ shift = tcg_temp_new();
1990+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
1991+ h8300_gen_reg_ldb(a->rn, shift);
19561992 tcg_gen_movi_i32(mask, 1);
1957- tcg_gen_shl_i32(mask, mask, a->rs);
1993+ tcg_gen_shl_i32(mask, mask, shift);
19581994 tcg_gen_or_i32(temp, temp, mask);
1959- tcg_gen_qemu_st_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1995+ tcg_gen_qemu_st_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
19601996 tcg_temp_free(temp);
19611997 tcg_temp_free(mask);
1998+ tcg_temp_free(shift);
19621999 return true;
19632000 }
19642001
19652002 static bool trans_BSET_ra(DisasContext *ctx, arg_BSET_ra *a)
19662003 {
1967- TCGv temp, mask, mem;
2004+ TCGv temp, mask, mem, shift;
19682005 temp = tcg_temp_new();
19692006 mask = tcg_temp_new();
19702007 mem = tcg_const_i32(0xffff00 | a->abs);
1971- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
2008+ shift = tcg_temp_new();
2009+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
2010+ h8300_gen_reg_ldb(a->rn, shift);
19722011 tcg_gen_movi_i32(mask, 1);
1973- tcg_gen_shl_i32(mask, mask, a->rs);
2012+ tcg_gen_shl_i32(mask, mask, shift);
19742013 tcg_gen_or_i32(temp, temp, mask);
1975- tcg_gen_qemu_st_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
2014+ tcg_gen_qemu_st_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
19762015 tcg_temp_free(temp);
19772016 tcg_temp_free(mask);
19782017 tcg_temp_free(mem);
2018+ tcg_temp_free(shift);
19792019 return true;
19802020 }
19812021
@@ -1984,7 +2024,7 @@ static bool trans_BTST_ir(DisasContext *ctx, arg_BTST_ir *a)
19842024 TCGv temp;
19852025 temp = tcg_temp_new();
19862026 h8300_gen_reg_ldb(a->r, temp);
1987- tcg_gen_andi_i32(cpu_psw_z, temp, 1 << a->imm);
2027+ tcg_gen_andi_i32(cpu_ccr_z, temp, 1 << a->imm);
19882028 tcg_temp_free(temp);
19892029 return true;
19902030 }
@@ -1993,19 +2033,19 @@ static bool trans_BTST_im(DisasContext *ctx, arg_BTST_im *a)
19932033 {
19942034 TCGv temp;
19952035 temp = tcg_temp_new();
1996- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
1997- tcg_gen_andi_i32(cpu_psw_z, temp, 1 << a->imm);
2036+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_8 | MO_SIGN | MO_TE);
2037+ tcg_gen_andi_i32(cpu_ccr_z, temp, 1 << a->imm);
19982038 tcg_temp_free(temp);
19992039 return true;
20002040 }
20012041
2002-static bool trans_BTST_ia(DisasContext *ctx, arg_BTST_ra *a)
2042+static bool trans_BTST_ia(DisasContext *ctx, arg_BTST_ia *a)
20032043 {
20042044 TCGv temp, mem;
20052045 temp = tcg_temp_new();
20062046 mem = tcg_const_i32(0xffff00 | a->abs);
2007- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
2008- tcg_gen_andi_i32(cpu_psw_z, temp, 1 << a->imm);
2047+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
2048+ tcg_gen_andi_i32(cpu_ccr_z, temp, 1 << a->imm);
20092049 tcg_temp_free(temp);
20102050 tcg_temp_free(mem);
20112051 return true;
@@ -2013,45 +2053,54 @@ static bool trans_BTST_ia(DisasContext *ctx, arg_BTST_ra *a)
20132053
20142054 static bool trans_BTST_rr(DisasContext *ctx, arg_BTST_rr *a)
20152055 {
2016- TCGv temp, mask;
2056+ TCGv temp, mask, shift;
20172057 temp = tcg_temp_new();
20182058 mask = tcg_temp_new();
2059+ shift = tcg_temp_new();
20192060 h8300_gen_reg_ldb(a->rd, temp);
2061+ h8300_gen_reg_ldb(a->rs, shift);
20202062 tcg_gen_movi_i32(mask, 1);
2021- tcg_gen_shl_i32(mask, mask, a->rs);
2022- tcg_gen_and_i32(cpu_psw_z, temp, mask);
2063+ tcg_gen_shl_i32(mask, mask, shift);
2064+ tcg_gen_and_i32(cpu_ccr_z, temp, mask);
20232065 tcg_temp_free(temp);
20242066 tcg_temp_free(mask);
2067+ tcg_temp_free(shift);
20252068 return true;
20262069 }
20272070
20282071 static bool trans_BTST_rm(DisasContext *ctx, arg_BTST_rm *a)
20292072 {
2030- TCGv temp, mask;
2073+ TCGv temp, mask, shift;
20312074 temp = tcg_temp_new();
20322075 mask = tcg_temp_new();
2033- tcg_gen_qemu_ld_i32(temp, cpu_regs[a->er], 0, MO_B | MO_SIGN | MO_TE);
2076+ shift = tcg_temp_new();
2077+ tcg_gen_qemu_ld_i32(temp, cpu_regs[a->rd], 0, MO_8 | MO_SIGN | MO_TE);
2078+ h8300_gen_reg_ldb(a->rn, shift);
20342079 tcg_gen_movi_i32(mask, 1);
2035- tcg_gen_shl_i32(mask, mask, a->rs);
2036- tcg_gen_and_i32(cpu_psw_z, temp, mask);
2080+ tcg_gen_shl_i32(mask, mask, shift);
2081+ tcg_gen_and_i32(cpu_ccr_z, temp, mask);
20372082 tcg_temp_free(temp);
20382083 tcg_temp_free(mask);
2084+ tcg_temp_free(shift);
20392085 return true;
20402086 }
20412087
20422088 static bool trans_BTST_ra(DisasContext *ctx, arg_BTST_ra *a)
20432089 {
2044- TCGv temp, mask, mem;
2090+ TCGv temp, mask, mem, shift;
20452091 temp = tcg_temp_new();
20462092 mask = tcg_temp_new();
20472093 mem = tcg_const_i32(0xffff00 | a->abs);
2048- tcg_gen_qemu_ld_i32(temp, mem, 0, MO_B | MO_SIGN | MO_TE);
2094+ shift = tcg_temp_new();
2095+ tcg_gen_qemu_ld_i32(temp, mem, 0, MO_8 | MO_SIGN | MO_TE);
2096+ h8300_gen_reg_ldb(a->rn, shift);
20492097 tcg_gen_movi_i32(mask, 1);
2050- tcg_gen_shl_i32(mask, mask, a->rs);
2051- tcg_gen_and_i32(cpu_psw_z, temp, mask);
2098+ tcg_gen_shl_i32(mask, mask, shift);
2099+ tcg_gen_and_i32(cpu_ccr_z, temp, mask);
20522100 tcg_temp_free(temp);
20532101 tcg_temp_free(mask);
20542102 tcg_temp_free(mem);
2103+ tcg_temp_free(shift);
20552104 return true;
20562105 }
20572106
@@ -2063,7 +2112,7 @@ static bool trans_Bcc(DisasContext *ctx, arg_Bcc *a)
20632112 switch (a->cd) {
20642113 case 0:
20652114 /* always true case */
2066- gen_goto_tb(ctx, 0, ctx->pc + dst);
2115+ gen_goto_tb(ctx, 0, ctx->base.pc_next + a->dsp);
20672116 break;
20682117 case 1:
20692118 /* always false case */
@@ -2071,30 +2120,24 @@ static bool trans_Bcc(DisasContext *ctx, arg_Bcc *a)
20712120 break;
20722121 case 2 ... 15:
20732122 dc.temp = tcg_temp_new();
2074- ccr_cond(&dc, cd);
2123+ ccr_cond(&dc, a->cd);
20752124 t = gen_new_label();
20762125 done = gen_new_label();
20772126 tcg_gen_brcondi_i32(dc.cond, dc.value, 0, t);
20782127 gen_goto_tb(ctx, 0, ctx->base.pc_next);
20792128 tcg_gen_br(done);
20802129 gen_set_label(t);
2081- gen_goto_tb(ctx, 1, ctx->pc + a->dst);
2130+ gen_goto_tb(ctx, 1, ctx->base.pc_next + a->dsp);
20822131 gen_set_label(done);
20832132 tcg_temp_free(dc.temp);
20842133 break;
20852134 }
2086-}
2087-
2088-static bool trans_JMP_r(DisasContext *ctx, arg_JMP_r *a)
2089-{
2090- tcg_gen_and_i32(cpu_pc, cpu_regs[a->r], 0x00ffffff);
2091- ctx->base.is_jmp = DISAS_JUMP;
20922135 return true;
20932136 }
20942137
20952138 static bool trans_JMP_r(DisasContext *ctx, arg_JMP_r *a)
20962139 {
2097- tcg_gen_andi_i32(cpu_pc, cpu_regs[a->r], 0x00ffffff);
2140+ tcg_gen_andi_i32(cpu_pc, cpu_regs[a->rs], 0x00ffffff);
20982141 ctx->base.is_jmp = DISAS_JUMP;
20992142 return true;
21002143 }
@@ -2115,9 +2158,9 @@ static bool trans_JMP_aa8(DisasContext *ctx, arg_JMP_aa8 *a)
21152158 return true;
21162159 }
21172160
2118-static inline void save_pc(void)
2161+static inline void save_pc(DisasContext *ctx)
21192162 {
2120- TCGv pc = tcg_const_i32(ctx->base.pc->next);
2163+ TCGv pc = tcg_const_i32(ctx->base.pc_next);
21212164 tcg_gen_subi_i32(cpu_sp, cpu_sp, 4);
21222165 tcg_gen_qemu_st_i32(pc, cpu_sp, 0, MO_32 | MO_SIGN | MO_TE);
21232166 tcg_temp_free(pc);
@@ -2125,15 +2168,15 @@ static inline void save_pc(void)
21252168
21262169 static bool trans_JSR_r(DisasContext *ctx, arg_JMP_r *a)
21272170 {
2128- save_pc();
2129- tcg_gen_andi_i32(cpu_pc, cpu_regs[a->r], 0x00ffffff);
2171+ save_pc(ctx);
2172+ tcg_gen_andi_i32(cpu_pc, cpu_regs[a->rs], 0x00ffffff);
21302173 ctx->base.is_jmp = DISAS_JUMP;
21312174 return true;
21322175 }
21332176
21342177 static bool trans_JSR_a24(DisasContext *ctx, arg_JSR_a24 *a)
21352178 {
2136- save_pc();
2179+ save_pc(ctx);
21372180 tcg_gen_movi_i32(cpu_pc, a->abs);
21382181 ctx->base.is_jmp = DISAS_JUMP;
21392182 return true;
@@ -2142,16 +2185,27 @@ static bool trans_JSR_a24(DisasContext *ctx, arg_JSR_a24 *a)
21422185 static bool trans_JSR_aa8(DisasContext *ctx, arg_JSR_aa8 *a)
21432186 {
21442187 TCGv mem = tcg_const_i32(a->abs);
2145- save_pc();
2146- tcg_gen_qemu_ld_i32(cpu_pc, mem, 0, MO_32 | MO_SIGN | MO_TE);
2147- ctx->base.is_jmp = DISAS_JUMP;
2188+ if (a->abs != 0xc7) {
2189+ save_pc(ctx);
2190+ tcg_gen_qemu_ld_i32(cpu_pc, mem, 0, MO_32 | MO_SIGN | MO_TE);
2191+ ctx->base.is_jmp = DISAS_JUMP;
2192+ } else {
2193+ gen_helper_sim_write(cpu_env);
2194+ }
21482195 tcg_temp_free(mem);
21492196 return true;
21502197 }
21512198
2199+static bool trans_BSR(DisasContext *ctx, arg_BSR *a)
2200+{
2201+ save_pc(ctx);
2202+ gen_goto_tb(ctx, 0, ctx->base.pc_next + a->dsp);
2203+ return true;
2204+}
2205+
21522206 static bool trans_RTS(DisasContext *ctx, arg_RTS *a)
21532207 {
2154- tcg_gen_qemu_ld_i32(cpu_pc, cpu_sp, 0, MO_32 | MO_SIGN | MO_TE);
2208+ tcg_gen_qemu_ld_i32(cpu_pc, cpu_sp, 0, MO_32 | MO_TE);
21552209 tcg_gen_addi_i32(cpu_sp, cpu_sp, 4);
21562210 ctx->base.is_jmp = DISAS_JUMP;
21572211 return true;
@@ -2161,11 +2215,11 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a)
21612215 {
21622216 TCGv ccr;
21632217 ccr = tcg_temp_new();
2164- tcg_gen_qemu_ld_i32(ccr, cpu_sp, 0, MO_32 | MO_SIGN | MO_TE);
2218+ tcg_gen_qemu_ld_i32(ccr, cpu_sp, 0, MO_32 | MO_TE);
21652219 tcg_gen_addi_i32(cpu_sp, cpu_sp, 4);
21662220 tcg_gen_extract_i32(cpu_pc, ccr, 0, 24);
21672221 tcg_gen_extract_i32(ccr, ccr, 24, 8);
2168- gen_set_ccr(cpu_env, ccr);
2222+ gen_helper_set_ccr(cpu_env, ccr);
21692223 ctx->base.is_jmp = DISAS_EXIT;
21702224 tcg_temp_free(ccr);
21712225 return true;
@@ -2186,8 +2240,8 @@ static bool trans_TRAPA(DisasContext *ctx, arg_TRAPA *a)
21862240
21872241 static bool trans_SLEEP(DisasContext *ctx, arg_SLEEP *a)
21882242 {
2189- tcg_gen_movi_i32(cpu_pc, ctx->base.pc->next);
2190- gen_helper_wait(cpu_env);
2243+ tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next);
2244+ gen_helper_sleep(cpu_env);
21912245 return true;
21922246 }
21932247
@@ -2195,7 +2249,7 @@ static bool trans_LDC_i(DisasContext *ctx, arg_LDC_i *a)
21952249 {
21962250 TCGv val;
21972251 val = tcg_const_i32(a->imm);
2198- gen_set_ccr(cpu_env, val);
2252+ gen_helper_set_ccr(cpu_env, val);
21992253 ctx->base.is_jmp = DISAS_UPDATE;
22002254 tcg_temp_free(val);
22012255 return true;
@@ -2206,7 +2260,7 @@ static bool trans_LDC_r(DisasContext *ctx, arg_LDC_r *a)
22062260 TCGv val;
22072261 val = tcg_temp_new();
22082262 h8300_gen_reg_ldb(a->r, val);
2209- gen_set_ccr(cpu_env, val);
2263+ gen_helper_set_ccr(cpu_env, val);
22102264 ctx->base.is_jmp = DISAS_UPDATE;
22112265 tcg_temp_free(val);
22122266 return true;
@@ -2217,10 +2271,10 @@ static bool trans_LDC_m(DisasContext *ctx, arg_LDC_m *a)
22172271 TCGv val, mem;
22182272 val = tcg_temp_new();
22192273 mem = tcg_temp_new();
2220- tcg_gen_addi_i32(mem, cpu_regs[a->er], a->dsp);
2221- tcg_gen_qemu_ldu_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2274+ tcg_gen_addi_i32(mem, cpu_regs[a->r], a->dsp);
2275+ tcg_gen_qemu_ld_i32(val, mem, 0, MO_16 | MO_TE);
22222276 tcg_gen_shri_i32(val, val, 8);
2223- gen_set_ccr(cpu_env, val);
2277+ gen_helper_set_ccr(cpu_env, val);
22242278 ctx->base.is_jmp = DISAS_UPDATE;
22252279 tcg_temp_free(val);
22262280 tcg_temp_free(mem);
@@ -2231,10 +2285,10 @@ static bool trans_LDC_mp(DisasContext *ctx, arg_LDC_mp *a)
22312285 {
22322286 TCGv val;
22332287 val = tcg_temp_new();
2234- tcg_gen_qemu_ldu_i32(val, cpu_regs[a->er], 0, MO_16 | MO_SIGN | MO_TE);
2235- tcg_gen_addi_i32(cpu_regs[a->er], cpu_regs[a->er], 4);
2288+ tcg_gen_qemu_ld_i32(val, cpu_regs[a->r], 0, MO_16 | MO_TE);
2289+ tcg_gen_addi_i32(cpu_regs[a->r], cpu_regs[a->r], 4);
22362290 tcg_gen_shri_i32(val, val, 8);
2237- gen_set_ccr(cpu_env, val);
2291+ gen_helper_set_ccr(cpu_env, val);
22382292 ctx->base.is_jmp = DISAS_UPDATE;
22392293 tcg_temp_free(val);
22402294 return true;
@@ -2245,9 +2299,9 @@ static bool trans_LDC_a(DisasContext *ctx, arg_LDC_a *a)
22452299 TCGv val, mem;
22462300 val = tcg_temp_new();
22472301 mem = tcg_const_i32(a->abs & 0x00ffffff);
2248- tcg_gen_qemu_ldu_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2302+ tcg_gen_qemu_ld_i32(val, mem, 0, MO_16 | MO_TE);
22492303 tcg_gen_shri_i32(val, val, 8);
2250- gen_set_ccr(cpu_env, val);
2304+ gen_helper_set_ccr(cpu_env, val);
22512305 ctx->base.is_jmp = DISAS_UPDATE;
22522306 tcg_temp_free(val);
22532307 tcg_temp_free(mem);
@@ -2259,17 +2313,17 @@ static bool trans_LDCSTC_m(DisasContext *ctx, arg_LDCSTC_m *a)
22592313 TCGv val, mem;
22602314 val = tcg_temp_new();
22612315 mem = tcg_temp_new();
2262- tcg_gen_addi_i32(mem, cpu_regs[a->er], a->dsp);
2316+ tcg_gen_addi_i32(mem, cpu_regs[a->r], a->dsp);
22632317 tcg_gen_andi_i32(mem, mem, 0x00ffffff);
22642318 if (a->ldst == 2) {
2265- tcg_gen_qemu_ldu_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2319+ tcg_gen_qemu_ld_i32(val, mem, 0, MO_16 | MO_TE);
22662320 tcg_gen_shri_i32(val, val, 8);
2267- gen_set_ccr(cpu_env, val);
2321+ gen_helper_set_ccr(cpu_env, val);
22682322 ctx->base.is_jmp = DISAS_UPDATE;
22692323 } else {
2270- gen_get_ccr(val, cpu_env);
2324+ gen_helper_get_ccr(val, cpu_env);
22712325 tcg_gen_shli_i32(val, val, 8);
2272- tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2326+ tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_TE);
22732327 }
22742328 tcg_temp_free(val);
22752329 tcg_temp_free(mem);
@@ -2280,7 +2334,7 @@ static bool trans_STC_r(DisasContext *ctx, arg_STC_r *a)
22802334 {
22812335 TCGv val;
22822336 val = tcg_temp_new();
2283- gen_get_ccr(val, cpu_env);
2337+ gen_helper_get_ccr(val, cpu_env);
22842338 h8300_gen_reg_ldb(a->r, val);
22852339 tcg_temp_free(val);
22862340 return true;
@@ -2291,10 +2345,10 @@ static bool trans_STC_m(DisasContext *ctx, arg_STC_m *a)
22912345 TCGv val, mem;
22922346 val = tcg_temp_new();
22932347 mem = tcg_temp_new();
2294- tcg_gen_addi_i32(mem, cpu_regs[a->er], a->dsp);
2295- gen_get_ccr(val, cpu_env);
2348+ tcg_gen_addi_i32(mem, cpu_regs[a->r], a->dsp);
2349+ gen_helper_get_ccr(val, cpu_env);
22962350 tcg_gen_shli_i32(val, val, 8);
2297- tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2351+ tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_TE);
22982352 tcg_temp_free(val);
22992353 tcg_temp_free(mem);
23002354 return true;
@@ -2304,10 +2358,10 @@ static bool trans_STC_mp(DisasContext *ctx, arg_STC_mp *a)
23042358 {
23052359 TCGv val;
23062360 val = tcg_temp_new();
2307- gen_get_ccr(val, cpu_env);
2361+ gen_helper_get_ccr(val, cpu_env);
23082362 tcg_gen_shli_i32(val, val, 8);
2309- tcg_gen_subi_i32(cpu_regs[a->er], cpu_regs[a->er], 4);
2310- tcg_gen_qemu_st_i32(val, cpu_regs[a->er], 0, MO_16 | MO_SIGN | MO_TE);
2363+ tcg_gen_subi_i32(cpu_regs[a->r], cpu_regs[a->r], 4);
2364+ tcg_gen_qemu_st_i32(val, cpu_regs[a->r], 0, MO_16 | MO_TE);
23112365 tcg_temp_free(val);
23122366 return true;
23132367 }
@@ -2317,9 +2371,9 @@ static bool trans_STC_a(DisasContext *ctx, arg_STC_a *a)
23172371 TCGv val, mem;
23182372 val = tcg_temp_new();
23192373 mem = tcg_const_i32(a->abs & 0x00ffffff);
2320- gen_get_ccr(val, cpu_env);
2374+ gen_helper_get_ccr(val, cpu_env);
23212375 tcg_gen_shli_i32(val, val, 8);
2322- tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_SIGN | MO_TE);
2376+ tcg_gen_qemu_st_i32(val, mem, 0, MO_16 | MO_TE);
23232377 tcg_temp_free(val);
23242378 tcg_temp_free(mem);
23252379 return true;
@@ -2329,9 +2383,9 @@ static bool trans_ANDC(DisasContext *ctx, arg_ANDC *a)
23292383 {
23302384 TCGv val;
23312385 val = tcg_temp_new();
2332- gen_get_ccr(val, cpu_env);
2333- gen_andi_i32(val, val, a->imm);
2334- gen_set_ccr(cpu_env, val);
2386+ gen_helper_get_ccr(val, cpu_env);
2387+ tcg_gen_andi_i32(val, val, a->imm);
2388+ gen_helper_set_ccr(cpu_env, val);
23352389 ctx->base.is_jmp = DISAS_UPDATE;
23362390 tcg_temp_free(val);
23372391 return true;
@@ -2341,9 +2395,9 @@ static bool trans_ORC(DisasContext *ctx, arg_ORC *a)
23412395 {
23422396 TCGv val;
23432397 val = tcg_temp_new();
2344- gen_get_ccr(val, cpu_env);
2345- gen_ori_i32(val, val, a->imm);
2346- gen_set_ccr(cpu_env, val);
2398+ gen_helper_get_ccr(val, cpu_env);
2399+ tcg_gen_ori_i32(val, val, a->imm);
2400+ gen_helper_set_ccr(cpu_env, val);
23472401 ctx->base.is_jmp = DISAS_UPDATE;
23482402 tcg_temp_free(val);
23492403 return true;
@@ -2353,9 +2407,9 @@ static bool trans_XORC(DisasContext *ctx, arg_XORC *a)
23532407 {
23542408 TCGv val;
23552409 val = tcg_temp_new();
2356- gen_get_ccr(val, cpu_env);
2357- gen_xori_i32(val, val, a->imm);
2358- gen_set_ccr(cpu_env, val);
2410+ gen_helper_get_ccr(val, cpu_env);
2411+ tcg_gen_xori_i32(val, val, a->imm);
2412+ gen_helper_set_ccr(cpu_env, val);
23592413 ctx->base.is_jmp = DISAS_UPDATE;
23602414 tcg_temp_free(val);
23612415 return true;
@@ -2366,13 +2420,13 @@ static bool trans_NOP(DisasContext *ctx, arg_NOP *a)
23662420 return true;
23672421 }
23682422
2369-static bool trans_EEPMOVB(DisasContext *ctx, arg_EEPMOVB *a)
2423+static bool trans_EEPMOV_B(DisasContext *ctx, arg_EEPMOV_B *a)
23702424 {
23712425 gen_helper_eepmovb(cpu_env);
23722426 return true;
23732427 }
23742428
2375-static bool trans_EEPMOVW(DisasContext *ctx, arg_EEPMOVW *a)
2429+static bool trans_EEPMOV_W(DisasContext *ctx, arg_EEPMOV_W *a)
23762430 {
23772431 gen_helper_eepmovw(cpu_env);
23782432 return true;
@@ -2417,7 +2471,8 @@ static void h8300_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
24172471 ctx->pc = ctx->base.pc_next;
24182472 insn = decode_load(ctx);
24192473 if (!decode(ctx, insn)) {
2420- gen_helper_raise_illegal_instruction(cpu_env);
2474+ qemu_log_mask(LOG_GUEST_ERROR,
2475+ "Unknwon instruction at 0x%06x", ctx->pc);
24212476 }
24222477 }
24232478
@@ -2495,12 +2550,12 @@ void h8300_translate_init(void)
24952550 regnames[i]);
24962551 }
24972552 ALLOC_REGISTER(pc, "PC");
2498- ALLOC_REGISTER(psw_v, "CCR(V)");
2499- ALLOC_REGISTER(psw_n, "CCR(N)");
2500- ALLOC_REGISTER(psw_z, "CCR(Z)");
2501- ALLOC_REGISTER(psw_c, "CCR(C)");
2502- ALLOC_REGISTER(psw_u, "CCR(U)");
2503- ALLOC_REGISTER(psw_h, "CCR(H)");
2504- ALLOC_REGISTER(psw_ui, "CCR(UI)");
2505- ALLOC_REGISTER(psw_i, "CCR(I)");
2553+ ALLOC_REGISTER(ccr_v, "CCR(V)");
2554+ ALLOC_REGISTER(ccr_n, "CCR(N)");
2555+ ALLOC_REGISTER(ccr_z, "CCR(Z)");
2556+ ALLOC_REGISTER(ccr_c, "CCR(C)");
2557+ ALLOC_REGISTER(ccr_u, "CCR(U)");
2558+ ALLOC_REGISTER(ccr_h, "CCR(H)");
2559+ ALLOC_REGISTER(ccr_ui, "CCR(UI)");
2560+ ALLOC_REGISTER(ccr_i, "CCR(I)");
25062561 }
--- a/target/rx/translate.c
+++ b/target/rx/translate.c
@@ -1087,6 +1087,7 @@ static void rx_sub(TCGv ret, TCGv arg1, TCGv arg2)
10871087 tcg_gen_mov_i32(ret, cpu_psw_s);
10881088 }
10891089 }
1090+
10901091 static void rx_cmp(TCGv dummy, TCGv arg1, TCGv arg2)
10911092 {
10921093 rx_sub(NULL, arg1, arg2);