2 * Moxie emulation for qemu: main translation routines.
4 * Copyright (c) 2009, 2013 Anthony Green
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /* For information on the Moxie architecture, see
21 * http://moxielogic.org/wiki
24 #include "qemu/osdep.h"
27 #include "exec/exec-all.h"
28 #include "disas/disas.h"
30 #include "exec/cpu_ldst.h"
32 #include "exec/helper-proto.h"
33 #include "exec/helper-gen.h"
36 /* This is the state at translation time. */
37 typedef struct DisasContext
{
38 struct TranslationBlock
*tb
;
39 target_ulong pc
, saved_pc
;
42 /* Routine used to access memory */
46 int singlestep_enabled
;
50 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
51 * exception condition */
52 BS_STOP
= 1, /* We want to stop translation for any reason */
53 BS_BRANCH
= 2, /* We reached a branch condition */
54 BS_EXCP
= 3, /* We reached an exception condition */
58 static TCGv cpu_gregs
[16];
59 static TCGv_env cpu_env
;
60 static TCGv cc_a
, cc_b
;
62 #include "exec/gen-icount.h"
64 #define REG(x) (cpu_gregs[x])
66 /* Extract the signed 10-bit offset from a 16-bit branch
68 static int extract_branch_offset(int opcode
)
70 return (((signed short)((opcode
& ((1 << 10) - 1)) << 6)) >> 6) << 1;
73 void moxie_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
76 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
77 CPUMoxieState
*env
= &cpu
->env
;
79 cpu_fprintf(f
, "pc=0x%08x\n", env
->pc
);
80 cpu_fprintf(f
, "$fp=0x%08x $sp=0x%08x $r0=0x%08x $r1=0x%08x\n",
81 env
->gregs
[0], env
->gregs
[1], env
->gregs
[2], env
->gregs
[3]);
82 for (i
= 4; i
< 16; i
+= 4) {
83 cpu_fprintf(f
, "$r%d=0x%08x $r%d=0x%08x $r%d=0x%08x $r%d=0x%08x\n",
84 i
-2, env
->gregs
[i
], i
-1, env
->gregs
[i
+ 1],
85 i
, env
->gregs
[i
+ 2], i
+1, env
->gregs
[i
+ 3]);
87 for (i
= 4; i
< 16; i
+= 4) {
88 cpu_fprintf(f
, "sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x\n",
89 i
-2, env
->sregs
[i
], i
-1, env
->sregs
[i
+ 1],
90 i
, env
->sregs
[i
+ 2], i
+1, env
->sregs
[i
+ 3]);
94 void moxie_translate_init(void)
98 static const char * const gregnames
[16] = {
99 "$fp", "$sp", "$r0", "$r1",
100 "$r2", "$r3", "$r4", "$r5",
101 "$r6", "$r7", "$r8", "$r9",
102 "$r10", "$r11", "$r12", "$r13"
108 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
109 cpu_pc
= tcg_global_mem_new_i32(cpu_env
,
110 offsetof(CPUMoxieState
, pc
), "$pc");
111 for (i
= 0; i
< 16; i
++)
112 cpu_gregs
[i
] = tcg_global_mem_new_i32(cpu_env
,
113 offsetof(CPUMoxieState
, gregs
[i
]),
116 cc_a
= tcg_global_mem_new_i32(cpu_env
,
117 offsetof(CPUMoxieState
, cc_a
), "cc_a");
118 cc_b
= tcg_global_mem_new_i32(cpu_env
,
119 offsetof(CPUMoxieState
, cc_b
), "cc_b");
124 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
126 if (unlikely(ctx
->singlestep_enabled
)) {
130 #ifndef CONFIG_USER_ONLY
131 return (ctx
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
137 static inline void gen_goto_tb(CPUMoxieState
*env
, DisasContext
*ctx
,
138 int n
, target_ulong dest
)
140 if (use_goto_tb(ctx
, dest
)) {
142 tcg_gen_movi_i32(cpu_pc
, dest
);
143 tcg_gen_exit_tb((uintptr_t)ctx
->tb
+ n
);
145 tcg_gen_movi_i32(cpu_pc
, dest
);
146 if (ctx
->singlestep_enabled
) {
147 gen_helper_debug(cpu_env
);
153 static int decode_opc(MoxieCPU
*cpu
, DisasContext
*ctx
)
155 CPUMoxieState
*env
= &cpu
->env
;
157 /* Local cache for the instruction opcode. */
159 /* Set the default instruction length. */
162 /* Examine the 16-bit opcode. */
163 opcode
= ctx
->opcode
;
165 /* Decode instruction. */
166 if (opcode
& (1 << 15)) {
167 if (opcode
& (1 << 14)) {
168 /* This is a Form 3 instruction. */
169 int inst
= (opcode
>> 10 & 0xf);
171 #define BRANCH(cond) \
173 TCGLabel *l1 = gen_new_label(); \
174 tcg_gen_brcond_i32(cond, cc_a, cc_b, l1); \
175 gen_goto_tb(env, ctx, 1, ctx->pc+2); \
177 gen_goto_tb(env, ctx, 0, extract_branch_offset(opcode) + ctx->pc+2); \
178 ctx->bstate = BS_BRANCH; \
194 case 0x04: /* bltu */
195 BRANCH(TCG_COND_LTU
);
197 case 0x05: /* bgtu */
198 BRANCH(TCG_COND_GTU
);
206 case 0x08: /* bgeu */
207 BRANCH(TCG_COND_GEU
);
209 case 0x09: /* bleu */
210 BRANCH(TCG_COND_LEU
);
214 TCGv temp
= tcg_temp_new_i32();
215 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
216 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
217 gen_helper_raise_exception(cpu_env
, temp
);
218 tcg_temp_free_i32(temp
);
223 /* This is a Form 2 instruction. */
224 int inst
= (opcode
>> 12 & 0x3);
228 int a
= (opcode
>> 8) & 0xf;
229 unsigned int v
= (opcode
& 0xff);
230 tcg_gen_addi_i32(REG(a
), REG(a
), v
);
235 int a
= (opcode
>> 8) & 0xf;
236 unsigned int v
= (opcode
& 0xff);
237 tcg_gen_subi_i32(REG(a
), REG(a
), v
);
242 int a
= (opcode
>> 8) & 0xf;
243 unsigned v
= (opcode
& 0xff);
244 tcg_gen_ld_i32(REG(a
), cpu_env
,
245 offsetof(CPUMoxieState
, sregs
[v
]));
250 int a
= (opcode
>> 8) & 0xf;
251 unsigned v
= (opcode
& 0xff);
252 tcg_gen_st_i32(REG(a
), cpu_env
,
253 offsetof(CPUMoxieState
, sregs
[v
]));
258 TCGv temp
= tcg_temp_new_i32();
259 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
260 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
261 gen_helper_raise_exception(cpu_env
, temp
);
262 tcg_temp_free_i32(temp
);
268 /* This is a Form 1 instruction. */
269 int inst
= opcode
>> 8;
273 case 0x01: /* ldi.l (immediate) */
275 int reg
= (opcode
>> 4) & 0xf;
276 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
277 tcg_gen_movi_i32(REG(reg
), val
);
281 case 0x02: /* mov (register-to-register) */
283 int dest
= (opcode
>> 4) & 0xf;
284 int src
= opcode
& 0xf;
285 tcg_gen_mov_i32(REG(dest
), REG(src
));
288 case 0x03: /* jsra */
290 TCGv t1
= tcg_temp_new_i32();
291 TCGv t2
= tcg_temp_new_i32();
293 tcg_gen_movi_i32(t1
, ctx
->pc
+ 6);
295 /* Make space for the static chain and return address. */
296 tcg_gen_subi_i32(t2
, REG(1), 8);
297 tcg_gen_mov_i32(REG(1), t2
);
298 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
300 /* Push the current frame pointer. */
301 tcg_gen_subi_i32(t2
, REG(1), 4);
302 tcg_gen_mov_i32(REG(1), t2
);
303 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
305 /* Set the pc and $fp. */
306 tcg_gen_mov_i32(REG(0), REG(1));
308 gen_goto_tb(env
, ctx
, 0, cpu_ldl_code(env
, ctx
->pc
+2));
310 tcg_temp_free_i32(t1
);
311 tcg_temp_free_i32(t2
);
313 ctx
->bstate
= BS_BRANCH
;
319 TCGv t1
= tcg_temp_new_i32();
321 /* The new $sp is the old $fp. */
322 tcg_gen_mov_i32(REG(1), REG(0));
324 /* Pop the frame pointer. */
325 tcg_gen_qemu_ld32u(REG(0), REG(1), ctx
->memidx
);
326 tcg_gen_addi_i32(t1
, REG(1), 4);
327 tcg_gen_mov_i32(REG(1), t1
);
330 /* Pop the return address and skip over the static chain
332 tcg_gen_qemu_ld32u(cpu_pc
, REG(1), ctx
->memidx
);
333 tcg_gen_addi_i32(t1
, REG(1), 8);
334 tcg_gen_mov_i32(REG(1), t1
);
336 tcg_temp_free_i32(t1
);
341 ctx
->bstate
= BS_BRANCH
;
344 case 0x05: /* add.l */
346 int a
= (opcode
>> 4) & 0xf;
347 int b
= opcode
& 0xf;
349 tcg_gen_add_i32(REG(a
), REG(a
), REG(b
));
352 case 0x06: /* push */
354 int a
= (opcode
>> 4) & 0xf;
355 int b
= opcode
& 0xf;
357 TCGv t1
= tcg_temp_new_i32();
358 tcg_gen_subi_i32(t1
, REG(a
), 4);
359 tcg_gen_mov_i32(REG(a
), t1
);
360 tcg_gen_qemu_st32(REG(b
), REG(a
), ctx
->memidx
);
361 tcg_temp_free_i32(t1
);
366 int a
= (opcode
>> 4) & 0xf;
367 int b
= opcode
& 0xf;
368 TCGv t1
= tcg_temp_new_i32();
370 tcg_gen_qemu_ld32u(REG(b
), REG(a
), ctx
->memidx
);
371 tcg_gen_addi_i32(t1
, REG(a
), 4);
372 tcg_gen_mov_i32(REG(a
), t1
);
373 tcg_temp_free_i32(t1
);
376 case 0x08: /* lda.l */
378 int reg
= (opcode
>> 4) & 0xf;
380 TCGv ptr
= tcg_temp_new_i32();
381 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
382 tcg_gen_qemu_ld32u(REG(reg
), ptr
, ctx
->memidx
);
383 tcg_temp_free_i32(ptr
);
388 case 0x09: /* sta.l */
390 int val
= (opcode
>> 4) & 0xf;
392 TCGv ptr
= tcg_temp_new_i32();
393 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
394 tcg_gen_qemu_st32(REG(val
), ptr
, ctx
->memidx
);
395 tcg_temp_free_i32(ptr
);
400 case 0x0a: /* ld.l (register indirect) */
402 int src
= opcode
& 0xf;
403 int dest
= (opcode
>> 4) & 0xf;
405 tcg_gen_qemu_ld32u(REG(dest
), REG(src
), ctx
->memidx
);
408 case 0x0b: /* st.l */
410 int dest
= (opcode
>> 4) & 0xf;
411 int val
= opcode
& 0xf;
413 tcg_gen_qemu_st32(REG(val
), REG(dest
), ctx
->memidx
);
416 case 0x0c: /* ldo.l */
418 int a
= (opcode
>> 4) & 0xf;
419 int b
= opcode
& 0xf;
421 TCGv t1
= tcg_temp_new_i32();
422 TCGv t2
= tcg_temp_new_i32();
423 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
424 tcg_gen_qemu_ld32u(t2
, t1
, ctx
->memidx
);
425 tcg_gen_mov_i32(REG(a
), t2
);
427 tcg_temp_free_i32(t1
);
428 tcg_temp_free_i32(t2
);
433 case 0x0d: /* sto.l */
435 int a
= (opcode
>> 4) & 0xf;
436 int b
= opcode
& 0xf;
438 TCGv t1
= tcg_temp_new_i32();
439 TCGv t2
= tcg_temp_new_i32();
440 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
441 tcg_gen_qemu_st32(REG(b
), t1
, ctx
->memidx
);
443 tcg_temp_free_i32(t1
);
444 tcg_temp_free_i32(t2
);
451 int a
= (opcode
>> 4) & 0xf;
452 int b
= opcode
& 0xf;
454 tcg_gen_mov_i32(cc_a
, REG(a
));
455 tcg_gen_mov_i32(cc_b
, REG(b
));
460 int fnreg
= (opcode
>> 4) & 0xf;
462 /* Load the stack pointer into T0. */
463 TCGv t1
= tcg_temp_new_i32();
464 TCGv t2
= tcg_temp_new_i32();
466 tcg_gen_movi_i32(t1
, ctx
->pc
+2);
468 /* Make space for the static chain and return address. */
469 tcg_gen_subi_i32(t2
, REG(1), 8);
470 tcg_gen_mov_i32(REG(1), t2
);
471 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
473 /* Push the current frame pointer. */
474 tcg_gen_subi_i32(t2
, REG(1), 4);
475 tcg_gen_mov_i32(REG(1), t2
);
476 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
478 /* Set the pc and $fp. */
479 tcg_gen_mov_i32(REG(0), REG(1));
480 tcg_gen_mov_i32(cpu_pc
, REG(fnreg
));
481 tcg_temp_free_i32(t1
);
482 tcg_temp_free_i32(t2
);
484 ctx
->bstate
= BS_BRANCH
;
487 case 0x1a: /* jmpa */
489 tcg_gen_movi_i32(cpu_pc
, cpu_ldl_code(env
, ctx
->pc
+2));
491 ctx
->bstate
= BS_BRANCH
;
495 case 0x1b: /* ldi.b (immediate) */
497 int reg
= (opcode
>> 4) & 0xf;
498 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
499 tcg_gen_movi_i32(REG(reg
), val
);
503 case 0x1c: /* ld.b (register indirect) */
505 int src
= opcode
& 0xf;
506 int dest
= (opcode
>> 4) & 0xf;
508 tcg_gen_qemu_ld8u(REG(dest
), REG(src
), ctx
->memidx
);
511 case 0x1d: /* lda.b */
513 int reg
= (opcode
>> 4) & 0xf;
515 TCGv ptr
= tcg_temp_new_i32();
516 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
517 tcg_gen_qemu_ld8u(REG(reg
), ptr
, ctx
->memidx
);
518 tcg_temp_free_i32(ptr
);
523 case 0x1e: /* st.b */
525 int dest
= (opcode
>> 4) & 0xf;
526 int val
= opcode
& 0xf;
528 tcg_gen_qemu_st8(REG(val
), REG(dest
), ctx
->memidx
);
531 case 0x1f: /* sta.b */
533 int val
= (opcode
>> 4) & 0xf;
535 TCGv ptr
= tcg_temp_new_i32();
536 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
537 tcg_gen_qemu_st8(REG(val
), ptr
, ctx
->memidx
);
538 tcg_temp_free_i32(ptr
);
543 case 0x20: /* ldi.s (immediate) */
545 int reg
= (opcode
>> 4) & 0xf;
546 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
547 tcg_gen_movi_i32(REG(reg
), val
);
551 case 0x21: /* ld.s (register indirect) */
553 int src
= opcode
& 0xf;
554 int dest
= (opcode
>> 4) & 0xf;
556 tcg_gen_qemu_ld16u(REG(dest
), REG(src
), ctx
->memidx
);
559 case 0x22: /* lda.s */
561 int reg
= (opcode
>> 4) & 0xf;
563 TCGv ptr
= tcg_temp_new_i32();
564 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
565 tcg_gen_qemu_ld16u(REG(reg
), ptr
, ctx
->memidx
);
566 tcg_temp_free_i32(ptr
);
571 case 0x23: /* st.s */
573 int dest
= (opcode
>> 4) & 0xf;
574 int val
= opcode
& 0xf;
576 tcg_gen_qemu_st16(REG(val
), REG(dest
), ctx
->memidx
);
579 case 0x24: /* sta.s */
581 int val
= (opcode
>> 4) & 0xf;
583 TCGv ptr
= tcg_temp_new_i32();
584 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
585 tcg_gen_qemu_st16(REG(val
), ptr
, ctx
->memidx
);
586 tcg_temp_free_i32(ptr
);
593 int reg
= (opcode
>> 4) & 0xf;
594 tcg_gen_mov_i32(cpu_pc
, REG(reg
));
596 ctx
->bstate
= BS_BRANCH
;
601 int a
= (opcode
>> 4) & 0xf;
602 int b
= opcode
& 0xf;
604 tcg_gen_and_i32(REG(a
), REG(a
), REG(b
));
607 case 0x27: /* lshr */
609 int a
= (opcode
>> 4) & 0xf;
610 int b
= opcode
& 0xf;
612 TCGv sv
= tcg_temp_new_i32();
613 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
614 tcg_gen_shr_i32(REG(a
), REG(a
), sv
);
615 tcg_temp_free_i32(sv
);
618 case 0x28: /* ashl */
620 int a
= (opcode
>> 4) & 0xf;
621 int b
= opcode
& 0xf;
623 TCGv sv
= tcg_temp_new_i32();
624 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
625 tcg_gen_shl_i32(REG(a
), REG(a
), sv
);
626 tcg_temp_free_i32(sv
);
629 case 0x29: /* sub.l */
631 int a
= (opcode
>> 4) & 0xf;
632 int b
= opcode
& 0xf;
634 tcg_gen_sub_i32(REG(a
), REG(a
), REG(b
));
639 int a
= (opcode
>> 4) & 0xf;
640 int b
= opcode
& 0xf;
642 tcg_gen_neg_i32(REG(a
), REG(b
));
647 int a
= (opcode
>> 4) & 0xf;
648 int b
= opcode
& 0xf;
650 tcg_gen_or_i32(REG(a
), REG(a
), REG(b
));
655 int a
= (opcode
>> 4) & 0xf;
656 int b
= opcode
& 0xf;
658 tcg_gen_not_i32(REG(a
), REG(b
));
661 case 0x2d: /* ashr */
663 int a
= (opcode
>> 4) & 0xf;
664 int b
= opcode
& 0xf;
666 TCGv sv
= tcg_temp_new_i32();
667 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
668 tcg_gen_sar_i32(REG(a
), REG(a
), sv
);
669 tcg_temp_free_i32(sv
);
674 int a
= (opcode
>> 4) & 0xf;
675 int b
= opcode
& 0xf;
677 tcg_gen_xor_i32(REG(a
), REG(a
), REG(b
));
680 case 0x2f: /* mul.l */
682 int a
= (opcode
>> 4) & 0xf;
683 int b
= opcode
& 0xf;
685 tcg_gen_mul_i32(REG(a
), REG(a
), REG(b
));
690 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
692 TCGv temp
= tcg_temp_new_i32();
693 tcg_gen_movi_i32(temp
, val
);
694 tcg_gen_st_i32(temp
, cpu_env
,
695 offsetof(CPUMoxieState
, sregs
[3]));
696 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
697 tcg_gen_movi_i32(temp
, MOXIE_EX_SWI
);
698 gen_helper_raise_exception(cpu_env
, temp
);
699 tcg_temp_free_i32(temp
);
704 case 0x31: /* div.l */
706 int a
= (opcode
>> 4) & 0xf;
707 int b
= opcode
& 0xf;
708 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
709 gen_helper_div(REG(a
), cpu_env
, REG(a
), REG(b
));
712 case 0x32: /* udiv.l */
714 int a
= (opcode
>> 4) & 0xf;
715 int b
= opcode
& 0xf;
716 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
717 gen_helper_udiv(REG(a
), cpu_env
, REG(a
), REG(b
));
720 case 0x33: /* mod.l */
722 int a
= (opcode
>> 4) & 0xf;
723 int b
= opcode
& 0xf;
724 tcg_gen_rem_i32(REG(a
), REG(a
), REG(b
));
727 case 0x34: /* umod.l */
729 int a
= (opcode
>> 4) & 0xf;
730 int b
= opcode
& 0xf;
731 tcg_gen_remu_i32(REG(a
), REG(a
), REG(b
));
736 TCGv temp
= tcg_temp_new_i32();
737 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
738 tcg_gen_movi_i32(temp
, MOXIE_EX_BREAK
);
739 gen_helper_raise_exception(cpu_env
, temp
);
740 tcg_temp_free_i32(temp
);
743 case 0x36: /* ldo.b */
745 int a
= (opcode
>> 4) & 0xf;
746 int b
= opcode
& 0xf;
748 TCGv t1
= tcg_temp_new_i32();
749 TCGv t2
= tcg_temp_new_i32();
750 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
751 tcg_gen_qemu_ld8u(t2
, t1
, ctx
->memidx
);
752 tcg_gen_mov_i32(REG(a
), t2
);
754 tcg_temp_free_i32(t1
);
755 tcg_temp_free_i32(t2
);
760 case 0x37: /* sto.b */
762 int a
= (opcode
>> 4) & 0xf;
763 int b
= opcode
& 0xf;
765 TCGv t1
= tcg_temp_new_i32();
766 TCGv t2
= tcg_temp_new_i32();
767 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
768 tcg_gen_qemu_st8(REG(b
), t1
, ctx
->memidx
);
770 tcg_temp_free_i32(t1
);
771 tcg_temp_free_i32(t2
);
776 case 0x38: /* ldo.s */
778 int a
= (opcode
>> 4) & 0xf;
779 int b
= opcode
& 0xf;
781 TCGv t1
= tcg_temp_new_i32();
782 TCGv t2
= tcg_temp_new_i32();
783 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
784 tcg_gen_qemu_ld16u(t2
, t1
, ctx
->memidx
);
785 tcg_gen_mov_i32(REG(a
), t2
);
787 tcg_temp_free_i32(t1
);
788 tcg_temp_free_i32(t2
);
793 case 0x39: /* sto.s */
795 int a
= (opcode
>> 4) & 0xf;
796 int b
= opcode
& 0xf;
798 TCGv t1
= tcg_temp_new_i32();
799 TCGv t2
= tcg_temp_new_i32();
800 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
801 tcg_gen_qemu_st16(REG(b
), t1
, ctx
->memidx
);
802 tcg_temp_free_i32(t1
);
803 tcg_temp_free_i32(t2
);
810 TCGv temp
= tcg_temp_new_i32();
811 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
812 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
813 gen_helper_raise_exception(cpu_env
, temp
);
814 tcg_temp_free_i32(temp
);
823 /* generate intermediate code for basic block 'tb'. */
824 void gen_intermediate_code(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
826 MoxieCPU
*cpu
= moxie_env_get_cpu(env
);
827 CPUState
*cs
= CPU(cpu
);
829 target_ulong pc_start
;
830 int num_insns
, max_insns
;
837 ctx
.singlestep_enabled
= 0;
838 ctx
.bstate
= BS_NONE
;
840 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
841 if (max_insns
== 0) {
842 max_insns
= CF_COUNT_MASK
;
844 if (max_insns
> TCG_MAX_INSNS
) {
845 max_insns
= TCG_MAX_INSNS
;
850 tcg_gen_insn_start(ctx
.pc
);
853 if (unlikely(cpu_breakpoint_test(cs
, ctx
.pc
, BP_ANY
))) {
854 tcg_gen_movi_i32(cpu_pc
, ctx
.pc
);
855 gen_helper_debug(cpu_env
);
856 ctx
.bstate
= BS_EXCP
;
857 /* The address covered by the breakpoint must be included in
858 [tb->pc, tb->pc + tb->size) in order to for it to be
859 properly cleared -- thus we increment the PC here so that
860 the logic setting tb->size below does the right thing. */
862 goto done_generating
;
865 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
866 ctx
.pc
+= decode_opc(cpu
, &ctx
);
868 if (num_insns
>= max_insns
) {
871 if (cs
->singlestep_enabled
) {
874 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) {
877 } while (ctx
.bstate
== BS_NONE
&& !tcg_op_buf_full());
879 if (cs
->singlestep_enabled
) {
880 tcg_gen_movi_tl(cpu_pc
, ctx
.pc
);
881 gen_helper_debug(cpu_env
);
883 switch (ctx
.bstate
) {
886 gen_goto_tb(env
, &ctx
, 0, ctx
.pc
);
897 gen_tb_end(tb
, num_insns
);
899 tb
->size
= ctx
.pc
- pc_start
;
900 tb
->icount
= num_insns
;
903 void restore_state_to_opc(CPUMoxieState
*env
, TranslationBlock
*tb
,