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 tcg_ctx
.tcg_env
= cpu_env
;
110 cpu_pc
= tcg_global_mem_new_i32(cpu_env
,
111 offsetof(CPUMoxieState
, pc
), "$pc");
112 for (i
= 0; i
< 16; i
++)
113 cpu_gregs
[i
] = tcg_global_mem_new_i32(cpu_env
,
114 offsetof(CPUMoxieState
, gregs
[i
]),
117 cc_a
= tcg_global_mem_new_i32(cpu_env
,
118 offsetof(CPUMoxieState
, cc_a
), "cc_a");
119 cc_b
= tcg_global_mem_new_i32(cpu_env
,
120 offsetof(CPUMoxieState
, cc_b
), "cc_b");
125 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
127 if (unlikely(ctx
->singlestep_enabled
)) {
131 #ifndef CONFIG_USER_ONLY
132 return (ctx
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
138 static inline void gen_goto_tb(CPUMoxieState
*env
, DisasContext
*ctx
,
139 int n
, target_ulong dest
)
141 if (use_goto_tb(ctx
, dest
)) {
143 tcg_gen_movi_i32(cpu_pc
, dest
);
144 tcg_gen_exit_tb((uintptr_t)ctx
->tb
+ n
);
146 tcg_gen_movi_i32(cpu_pc
, dest
);
147 if (ctx
->singlestep_enabled
) {
148 gen_helper_debug(cpu_env
);
154 static int decode_opc(MoxieCPU
*cpu
, DisasContext
*ctx
)
156 CPUMoxieState
*env
= &cpu
->env
;
158 /* Local cache for the instruction opcode. */
160 /* Set the default instruction length. */
163 /* Examine the 16-bit opcode. */
164 opcode
= ctx
->opcode
;
166 /* Decode instruction. */
167 if (opcode
& (1 << 15)) {
168 if (opcode
& (1 << 14)) {
169 /* This is a Form 3 instruction. */
170 int inst
= (opcode
>> 10 & 0xf);
172 #define BRANCH(cond) \
174 TCGLabel *l1 = gen_new_label(); \
175 tcg_gen_brcond_i32(cond, cc_a, cc_b, l1); \
176 gen_goto_tb(env, ctx, 1, ctx->pc+2); \
178 gen_goto_tb(env, ctx, 0, extract_branch_offset(opcode) + ctx->pc+2); \
179 ctx->bstate = BS_BRANCH; \
195 case 0x04: /* bltu */
196 BRANCH(TCG_COND_LTU
);
198 case 0x05: /* bgtu */
199 BRANCH(TCG_COND_GTU
);
207 case 0x08: /* bgeu */
208 BRANCH(TCG_COND_GEU
);
210 case 0x09: /* bleu */
211 BRANCH(TCG_COND_LEU
);
215 TCGv temp
= tcg_temp_new_i32();
216 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
217 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
218 gen_helper_raise_exception(cpu_env
, temp
);
219 tcg_temp_free_i32(temp
);
224 /* This is a Form 2 instruction. */
225 int inst
= (opcode
>> 12 & 0x3);
229 int a
= (opcode
>> 8) & 0xf;
230 unsigned int v
= (opcode
& 0xff);
231 tcg_gen_addi_i32(REG(a
), REG(a
), v
);
236 int a
= (opcode
>> 8) & 0xf;
237 unsigned int v
= (opcode
& 0xff);
238 tcg_gen_subi_i32(REG(a
), REG(a
), v
);
243 int a
= (opcode
>> 8) & 0xf;
244 unsigned v
= (opcode
& 0xff);
245 tcg_gen_ld_i32(REG(a
), cpu_env
,
246 offsetof(CPUMoxieState
, sregs
[v
]));
251 int a
= (opcode
>> 8) & 0xf;
252 unsigned v
= (opcode
& 0xff);
253 tcg_gen_st_i32(REG(a
), cpu_env
,
254 offsetof(CPUMoxieState
, sregs
[v
]));
259 TCGv temp
= tcg_temp_new_i32();
260 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
261 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
262 gen_helper_raise_exception(cpu_env
, temp
);
263 tcg_temp_free_i32(temp
);
269 /* This is a Form 1 instruction. */
270 int inst
= opcode
>> 8;
274 case 0x01: /* ldi.l (immediate) */
276 int reg
= (opcode
>> 4) & 0xf;
277 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
278 tcg_gen_movi_i32(REG(reg
), val
);
282 case 0x02: /* mov (register-to-register) */
284 int dest
= (opcode
>> 4) & 0xf;
285 int src
= opcode
& 0xf;
286 tcg_gen_mov_i32(REG(dest
), REG(src
));
289 case 0x03: /* jsra */
291 TCGv t1
= tcg_temp_new_i32();
292 TCGv t2
= tcg_temp_new_i32();
294 tcg_gen_movi_i32(t1
, ctx
->pc
+ 6);
296 /* Make space for the static chain and return address. */
297 tcg_gen_subi_i32(t2
, REG(1), 8);
298 tcg_gen_mov_i32(REG(1), t2
);
299 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
301 /* Push the current frame pointer. */
302 tcg_gen_subi_i32(t2
, REG(1), 4);
303 tcg_gen_mov_i32(REG(1), t2
);
304 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
306 /* Set the pc and $fp. */
307 tcg_gen_mov_i32(REG(0), REG(1));
309 gen_goto_tb(env
, ctx
, 0, cpu_ldl_code(env
, ctx
->pc
+2));
311 tcg_temp_free_i32(t1
);
312 tcg_temp_free_i32(t2
);
314 ctx
->bstate
= BS_BRANCH
;
320 TCGv t1
= tcg_temp_new_i32();
322 /* The new $sp is the old $fp. */
323 tcg_gen_mov_i32(REG(1), REG(0));
325 /* Pop the frame pointer. */
326 tcg_gen_qemu_ld32u(REG(0), REG(1), ctx
->memidx
);
327 tcg_gen_addi_i32(t1
, REG(1), 4);
328 tcg_gen_mov_i32(REG(1), t1
);
331 /* Pop the return address and skip over the static chain
333 tcg_gen_qemu_ld32u(cpu_pc
, REG(1), ctx
->memidx
);
334 tcg_gen_addi_i32(t1
, REG(1), 8);
335 tcg_gen_mov_i32(REG(1), t1
);
337 tcg_temp_free_i32(t1
);
342 ctx
->bstate
= BS_BRANCH
;
345 case 0x05: /* add.l */
347 int a
= (opcode
>> 4) & 0xf;
348 int b
= opcode
& 0xf;
350 tcg_gen_add_i32(REG(a
), REG(a
), REG(b
));
353 case 0x06: /* push */
355 int a
= (opcode
>> 4) & 0xf;
356 int b
= opcode
& 0xf;
358 TCGv t1
= tcg_temp_new_i32();
359 tcg_gen_subi_i32(t1
, REG(a
), 4);
360 tcg_gen_mov_i32(REG(a
), t1
);
361 tcg_gen_qemu_st32(REG(b
), REG(a
), ctx
->memidx
);
362 tcg_temp_free_i32(t1
);
367 int a
= (opcode
>> 4) & 0xf;
368 int b
= opcode
& 0xf;
369 TCGv t1
= tcg_temp_new_i32();
371 tcg_gen_qemu_ld32u(REG(b
), REG(a
), ctx
->memidx
);
372 tcg_gen_addi_i32(t1
, REG(a
), 4);
373 tcg_gen_mov_i32(REG(a
), t1
);
374 tcg_temp_free_i32(t1
);
377 case 0x08: /* lda.l */
379 int reg
= (opcode
>> 4) & 0xf;
381 TCGv ptr
= tcg_temp_new_i32();
382 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
383 tcg_gen_qemu_ld32u(REG(reg
), ptr
, ctx
->memidx
);
384 tcg_temp_free_i32(ptr
);
389 case 0x09: /* sta.l */
391 int val
= (opcode
>> 4) & 0xf;
393 TCGv ptr
= tcg_temp_new_i32();
394 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
395 tcg_gen_qemu_st32(REG(val
), ptr
, ctx
->memidx
);
396 tcg_temp_free_i32(ptr
);
401 case 0x0a: /* ld.l (register indirect) */
403 int src
= opcode
& 0xf;
404 int dest
= (opcode
>> 4) & 0xf;
406 tcg_gen_qemu_ld32u(REG(dest
), REG(src
), ctx
->memidx
);
409 case 0x0b: /* st.l */
411 int dest
= (opcode
>> 4) & 0xf;
412 int val
= opcode
& 0xf;
414 tcg_gen_qemu_st32(REG(val
), REG(dest
), ctx
->memidx
);
417 case 0x0c: /* ldo.l */
419 int a
= (opcode
>> 4) & 0xf;
420 int b
= opcode
& 0xf;
422 TCGv t1
= tcg_temp_new_i32();
423 TCGv t2
= tcg_temp_new_i32();
424 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
425 tcg_gen_qemu_ld32u(t2
, t1
, ctx
->memidx
);
426 tcg_gen_mov_i32(REG(a
), t2
);
428 tcg_temp_free_i32(t1
);
429 tcg_temp_free_i32(t2
);
434 case 0x0d: /* sto.l */
436 int a
= (opcode
>> 4) & 0xf;
437 int b
= opcode
& 0xf;
439 TCGv t1
= tcg_temp_new_i32();
440 TCGv t2
= tcg_temp_new_i32();
441 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
442 tcg_gen_qemu_st32(REG(b
), t1
, ctx
->memidx
);
444 tcg_temp_free_i32(t1
);
445 tcg_temp_free_i32(t2
);
452 int a
= (opcode
>> 4) & 0xf;
453 int b
= opcode
& 0xf;
455 tcg_gen_mov_i32(cc_a
, REG(a
));
456 tcg_gen_mov_i32(cc_b
, REG(b
));
461 int fnreg
= (opcode
>> 4) & 0xf;
463 /* Load the stack pointer into T0. */
464 TCGv t1
= tcg_temp_new_i32();
465 TCGv t2
= tcg_temp_new_i32();
467 tcg_gen_movi_i32(t1
, ctx
->pc
+2);
469 /* Make space for the static chain and return address. */
470 tcg_gen_subi_i32(t2
, REG(1), 8);
471 tcg_gen_mov_i32(REG(1), t2
);
472 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
474 /* Push the current frame pointer. */
475 tcg_gen_subi_i32(t2
, REG(1), 4);
476 tcg_gen_mov_i32(REG(1), t2
);
477 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
479 /* Set the pc and $fp. */
480 tcg_gen_mov_i32(REG(0), REG(1));
481 tcg_gen_mov_i32(cpu_pc
, REG(fnreg
));
482 tcg_temp_free_i32(t1
);
483 tcg_temp_free_i32(t2
);
485 ctx
->bstate
= BS_BRANCH
;
488 case 0x1a: /* jmpa */
490 tcg_gen_movi_i32(cpu_pc
, cpu_ldl_code(env
, ctx
->pc
+2));
492 ctx
->bstate
= BS_BRANCH
;
496 case 0x1b: /* ldi.b (immediate) */
498 int reg
= (opcode
>> 4) & 0xf;
499 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
500 tcg_gen_movi_i32(REG(reg
), val
);
504 case 0x1c: /* ld.b (register indirect) */
506 int src
= opcode
& 0xf;
507 int dest
= (opcode
>> 4) & 0xf;
509 tcg_gen_qemu_ld8u(REG(dest
), REG(src
), ctx
->memidx
);
512 case 0x1d: /* lda.b */
514 int reg
= (opcode
>> 4) & 0xf;
516 TCGv ptr
= tcg_temp_new_i32();
517 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
518 tcg_gen_qemu_ld8u(REG(reg
), ptr
, ctx
->memidx
);
519 tcg_temp_free_i32(ptr
);
524 case 0x1e: /* st.b */
526 int dest
= (opcode
>> 4) & 0xf;
527 int val
= opcode
& 0xf;
529 tcg_gen_qemu_st8(REG(val
), REG(dest
), ctx
->memidx
);
532 case 0x1f: /* sta.b */
534 int val
= (opcode
>> 4) & 0xf;
536 TCGv ptr
= tcg_temp_new_i32();
537 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
538 tcg_gen_qemu_st8(REG(val
), ptr
, ctx
->memidx
);
539 tcg_temp_free_i32(ptr
);
544 case 0x20: /* ldi.s (immediate) */
546 int reg
= (opcode
>> 4) & 0xf;
547 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
548 tcg_gen_movi_i32(REG(reg
), val
);
552 case 0x21: /* ld.s (register indirect) */
554 int src
= opcode
& 0xf;
555 int dest
= (opcode
>> 4) & 0xf;
557 tcg_gen_qemu_ld16u(REG(dest
), REG(src
), ctx
->memidx
);
560 case 0x22: /* lda.s */
562 int reg
= (opcode
>> 4) & 0xf;
564 TCGv ptr
= tcg_temp_new_i32();
565 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
566 tcg_gen_qemu_ld16u(REG(reg
), ptr
, ctx
->memidx
);
567 tcg_temp_free_i32(ptr
);
572 case 0x23: /* st.s */
574 int dest
= (opcode
>> 4) & 0xf;
575 int val
= opcode
& 0xf;
577 tcg_gen_qemu_st16(REG(val
), REG(dest
), ctx
->memidx
);
580 case 0x24: /* sta.s */
582 int val
= (opcode
>> 4) & 0xf;
584 TCGv ptr
= tcg_temp_new_i32();
585 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
586 tcg_gen_qemu_st16(REG(val
), ptr
, ctx
->memidx
);
587 tcg_temp_free_i32(ptr
);
594 int reg
= (opcode
>> 4) & 0xf;
595 tcg_gen_mov_i32(cpu_pc
, REG(reg
));
597 ctx
->bstate
= BS_BRANCH
;
602 int a
= (opcode
>> 4) & 0xf;
603 int b
= opcode
& 0xf;
605 tcg_gen_and_i32(REG(a
), REG(a
), REG(b
));
608 case 0x27: /* lshr */
610 int a
= (opcode
>> 4) & 0xf;
611 int b
= opcode
& 0xf;
613 TCGv sv
= tcg_temp_new_i32();
614 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
615 tcg_gen_shr_i32(REG(a
), REG(a
), sv
);
616 tcg_temp_free_i32(sv
);
619 case 0x28: /* ashl */
621 int a
= (opcode
>> 4) & 0xf;
622 int b
= opcode
& 0xf;
624 TCGv sv
= tcg_temp_new_i32();
625 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
626 tcg_gen_shl_i32(REG(a
), REG(a
), sv
);
627 tcg_temp_free_i32(sv
);
630 case 0x29: /* sub.l */
632 int a
= (opcode
>> 4) & 0xf;
633 int b
= opcode
& 0xf;
635 tcg_gen_sub_i32(REG(a
), REG(a
), REG(b
));
640 int a
= (opcode
>> 4) & 0xf;
641 int b
= opcode
& 0xf;
643 tcg_gen_neg_i32(REG(a
), REG(b
));
648 int a
= (opcode
>> 4) & 0xf;
649 int b
= opcode
& 0xf;
651 tcg_gen_or_i32(REG(a
), REG(a
), REG(b
));
656 int a
= (opcode
>> 4) & 0xf;
657 int b
= opcode
& 0xf;
659 tcg_gen_not_i32(REG(a
), REG(b
));
662 case 0x2d: /* ashr */
664 int a
= (opcode
>> 4) & 0xf;
665 int b
= opcode
& 0xf;
667 TCGv sv
= tcg_temp_new_i32();
668 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
669 tcg_gen_sar_i32(REG(a
), REG(a
), sv
);
670 tcg_temp_free_i32(sv
);
675 int a
= (opcode
>> 4) & 0xf;
676 int b
= opcode
& 0xf;
678 tcg_gen_xor_i32(REG(a
), REG(a
), REG(b
));
681 case 0x2f: /* mul.l */
683 int a
= (opcode
>> 4) & 0xf;
684 int b
= opcode
& 0xf;
686 tcg_gen_mul_i32(REG(a
), REG(a
), REG(b
));
691 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
693 TCGv temp
= tcg_temp_new_i32();
694 tcg_gen_movi_i32(temp
, val
);
695 tcg_gen_st_i32(temp
, cpu_env
,
696 offsetof(CPUMoxieState
, sregs
[3]));
697 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
698 tcg_gen_movi_i32(temp
, MOXIE_EX_SWI
);
699 gen_helper_raise_exception(cpu_env
, temp
);
700 tcg_temp_free_i32(temp
);
705 case 0x31: /* div.l */
707 int a
= (opcode
>> 4) & 0xf;
708 int b
= opcode
& 0xf;
709 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
710 gen_helper_div(REG(a
), cpu_env
, REG(a
), REG(b
));
713 case 0x32: /* udiv.l */
715 int a
= (opcode
>> 4) & 0xf;
716 int b
= opcode
& 0xf;
717 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
718 gen_helper_udiv(REG(a
), cpu_env
, REG(a
), REG(b
));
721 case 0x33: /* mod.l */
723 int a
= (opcode
>> 4) & 0xf;
724 int b
= opcode
& 0xf;
725 tcg_gen_rem_i32(REG(a
), REG(a
), REG(b
));
728 case 0x34: /* umod.l */
730 int a
= (opcode
>> 4) & 0xf;
731 int b
= opcode
& 0xf;
732 tcg_gen_remu_i32(REG(a
), REG(a
), REG(b
));
737 TCGv temp
= tcg_temp_new_i32();
738 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
739 tcg_gen_movi_i32(temp
, MOXIE_EX_BREAK
);
740 gen_helper_raise_exception(cpu_env
, temp
);
741 tcg_temp_free_i32(temp
);
744 case 0x36: /* ldo.b */
746 int a
= (opcode
>> 4) & 0xf;
747 int b
= opcode
& 0xf;
749 TCGv t1
= tcg_temp_new_i32();
750 TCGv t2
= tcg_temp_new_i32();
751 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
752 tcg_gen_qemu_ld8u(t2
, t1
, ctx
->memidx
);
753 tcg_gen_mov_i32(REG(a
), t2
);
755 tcg_temp_free_i32(t1
);
756 tcg_temp_free_i32(t2
);
761 case 0x37: /* sto.b */
763 int a
= (opcode
>> 4) & 0xf;
764 int b
= opcode
& 0xf;
766 TCGv t1
= tcg_temp_new_i32();
767 TCGv t2
= tcg_temp_new_i32();
768 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
769 tcg_gen_qemu_st8(REG(b
), t1
, ctx
->memidx
);
771 tcg_temp_free_i32(t1
);
772 tcg_temp_free_i32(t2
);
777 case 0x38: /* ldo.s */
779 int a
= (opcode
>> 4) & 0xf;
780 int b
= opcode
& 0xf;
782 TCGv t1
= tcg_temp_new_i32();
783 TCGv t2
= tcg_temp_new_i32();
784 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
785 tcg_gen_qemu_ld16u(t2
, t1
, ctx
->memidx
);
786 tcg_gen_mov_i32(REG(a
), t2
);
788 tcg_temp_free_i32(t1
);
789 tcg_temp_free_i32(t2
);
794 case 0x39: /* sto.s */
796 int a
= (opcode
>> 4) & 0xf;
797 int b
= opcode
& 0xf;
799 TCGv t1
= tcg_temp_new_i32();
800 TCGv t2
= tcg_temp_new_i32();
801 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
802 tcg_gen_qemu_st16(REG(b
), t1
, ctx
->memidx
);
803 tcg_temp_free_i32(t1
);
804 tcg_temp_free_i32(t2
);
811 TCGv temp
= tcg_temp_new_i32();
812 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
813 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
814 gen_helper_raise_exception(cpu_env
, temp
);
815 tcg_temp_free_i32(temp
);
824 /* generate intermediate code for basic block 'tb'. */
825 void gen_intermediate_code(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
827 MoxieCPU
*cpu
= moxie_env_get_cpu(env
);
828 CPUState
*cs
= CPU(cpu
);
830 target_ulong pc_start
;
831 int num_insns
, max_insns
;
838 ctx
.singlestep_enabled
= 0;
839 ctx
.bstate
= BS_NONE
;
841 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
842 if (max_insns
== 0) {
843 max_insns
= CF_COUNT_MASK
;
845 if (max_insns
> TCG_MAX_INSNS
) {
846 max_insns
= TCG_MAX_INSNS
;
851 tcg_gen_insn_start(ctx
.pc
);
854 if (unlikely(cpu_breakpoint_test(cs
, ctx
.pc
, BP_ANY
))) {
855 tcg_gen_movi_i32(cpu_pc
, ctx
.pc
);
856 gen_helper_debug(cpu_env
);
857 ctx
.bstate
= BS_EXCP
;
858 /* The address covered by the breakpoint must be included in
859 [tb->pc, tb->pc + tb->size) in order to for it to be
860 properly cleared -- thus we increment the PC here so that
861 the logic setting tb->size below does the right thing. */
863 goto done_generating
;
866 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
867 ctx
.pc
+= decode_opc(cpu
, &ctx
);
869 if (num_insns
>= max_insns
) {
872 if (cs
->singlestep_enabled
) {
875 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) {
878 } while (ctx
.bstate
== BS_NONE
&& !tcg_op_buf_full());
880 if (cs
->singlestep_enabled
) {
881 tcg_gen_movi_tl(cpu_pc
, ctx
.pc
);
882 gen_helper_debug(cpu_env
);
884 switch (ctx
.bstate
) {
887 gen_goto_tb(env
, &ctx
, 0, ctx
.pc
);
898 gen_tb_end(tb
, num_insns
);
900 tb
->size
= ctx
.pc
- pc_start
;
901 tb
->icount
= num_insns
;
904 void restore_state_to_opc(CPUMoxieState
*env
, TranslationBlock
*tb
,