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
31 #include "exec/exec-all.h"
32 #include "disas/disas.h"
34 #include "exec/cpu_ldst.h"
36 #include "exec/helper-proto.h"
37 #include "exec/helper-gen.h"
39 /* This is the state at translation time. */
40 typedef struct DisasContext
{
41 struct TranslationBlock
*tb
;
42 target_ulong pc
, saved_pc
;
45 /* Routine used to access memory */
49 int singlestep_enabled
;
53 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
54 * exception condition */
55 BS_STOP
= 1, /* We want to stop translation for any reason */
56 BS_BRANCH
= 2, /* We reached a branch condition */
57 BS_EXCP
= 3, /* We reached an exception condition */
61 static TCGv cpu_gregs
[16];
62 static TCGv_ptr cpu_env
;
63 static TCGv cc_a
, cc_b
;
65 #include "exec/gen-icount.h"
67 #define REG(x) (cpu_gregs[x])
69 /* Extract the signed 10-bit offset from a 16-bit branch
71 static int extract_branch_offset(int opcode
)
73 return (((signed short)((opcode
& ((1 << 10) - 1)) << 6)) >> 6) << 1;
76 void moxie_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
79 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
80 CPUMoxieState
*env
= &cpu
->env
;
82 cpu_fprintf(f
, "pc=0x%08x\n", env
->pc
);
83 cpu_fprintf(f
, "$fp=0x%08x $sp=0x%08x $r0=0x%08x $r1=0x%08x\n",
84 env
->gregs
[0], env
->gregs
[1], env
->gregs
[2], env
->gregs
[3]);
85 for (i
= 4; i
< 16; i
+= 4) {
86 cpu_fprintf(f
, "$r%d=0x%08x $r%d=0x%08x $r%d=0x%08x $r%d=0x%08x\n",
87 i
-2, env
->gregs
[i
], i
-1, env
->gregs
[i
+ 1],
88 i
, env
->gregs
[i
+ 2], i
+1, env
->gregs
[i
+ 3]);
90 for (i
= 4; i
< 16; i
+= 4) {
91 cpu_fprintf(f
, "sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x\n",
92 i
-2, env
->sregs
[i
], i
-1, env
->sregs
[i
+ 1],
93 i
, env
->sregs
[i
+ 2], i
+1, env
->sregs
[i
+ 3]);
97 void moxie_translate_init(void)
100 static int done_init
;
101 static const char * const gregnames
[16] = {
102 "$fp", "$sp", "$r0", "$r1",
103 "$r2", "$r3", "$r4", "$r5",
104 "$r6", "$r7", "$r8", "$r9",
105 "$r10", "$r11", "$r12", "$r13"
111 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
112 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
113 offsetof(CPUMoxieState
, pc
), "$pc");
114 for (i
= 0; i
< 16; i
++)
115 cpu_gregs
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
116 offsetof(CPUMoxieState
, gregs
[i
]),
119 cc_a
= tcg_global_mem_new_i32(TCG_AREG0
,
120 offsetof(CPUMoxieState
, cc_a
), "cc_a");
121 cc_b
= tcg_global_mem_new_i32(TCG_AREG0
,
122 offsetof(CPUMoxieState
, cc_b
), "cc_b");
127 static inline void gen_goto_tb(CPUMoxieState
*env
, DisasContext
*ctx
,
128 int n
, target_ulong dest
)
130 TranslationBlock
*tb
;
133 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
134 !ctx
->singlestep_enabled
) {
136 tcg_gen_movi_i32(cpu_pc
, dest
);
137 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
139 tcg_gen_movi_i32(cpu_pc
, dest
);
140 if (ctx
->singlestep_enabled
) {
141 gen_helper_debug(cpu_env
);
147 static int decode_opc(MoxieCPU
*cpu
, DisasContext
*ctx
)
149 CPUMoxieState
*env
= &cpu
->env
;
151 /* Local cache for the instruction opcode. */
153 /* Set the default instruction length. */
156 /* Examine the 16-bit opcode. */
157 opcode
= ctx
->opcode
;
159 /* Decode instruction. */
160 if (opcode
& (1 << 15)) {
161 if (opcode
& (1 << 14)) {
162 /* This is a Form 3 instruction. */
163 int inst
= (opcode
>> 10 & 0xf);
165 #define BRANCH(cond) \
167 TCGLabel *l1 = gen_new_label(); \
168 tcg_gen_brcond_i32(cond, cc_a, cc_b, l1); \
169 gen_goto_tb(env, ctx, 1, ctx->pc+2); \
171 gen_goto_tb(env, ctx, 0, extract_branch_offset(opcode) + ctx->pc+2); \
172 ctx->bstate = BS_BRANCH; \
188 case 0x04: /* bltu */
189 BRANCH(TCG_COND_LTU
);
191 case 0x05: /* bgtu */
192 BRANCH(TCG_COND_GTU
);
200 case 0x08: /* bgeu */
201 BRANCH(TCG_COND_GEU
);
203 case 0x09: /* bleu */
204 BRANCH(TCG_COND_LEU
);
208 TCGv temp
= tcg_temp_new_i32();
209 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
210 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
211 gen_helper_raise_exception(cpu_env
, temp
);
212 tcg_temp_free_i32(temp
);
217 /* This is a Form 2 instruction. */
218 int inst
= (opcode
>> 12 & 0x3);
222 int a
= (opcode
>> 8) & 0xf;
223 unsigned int v
= (opcode
& 0xff);
224 tcg_gen_addi_i32(REG(a
), REG(a
), v
);
229 int a
= (opcode
>> 8) & 0xf;
230 unsigned int v
= (opcode
& 0xff);
231 tcg_gen_subi_i32(REG(a
), REG(a
), v
);
236 int a
= (opcode
>> 8) & 0xf;
237 unsigned v
= (opcode
& 0xff);
238 tcg_gen_ld_i32(REG(a
), cpu_env
,
239 offsetof(CPUMoxieState
, sregs
[v
]));
244 int a
= (opcode
>> 8) & 0xf;
245 unsigned v
= (opcode
& 0xff);
246 tcg_gen_st_i32(REG(a
), cpu_env
,
247 offsetof(CPUMoxieState
, sregs
[v
]));
252 TCGv temp
= tcg_temp_new_i32();
253 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
254 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
255 gen_helper_raise_exception(cpu_env
, temp
);
256 tcg_temp_free_i32(temp
);
262 /* This is a Form 1 instruction. */
263 int inst
= opcode
>> 8;
267 case 0x01: /* ldi.l (immediate) */
269 int reg
= (opcode
>> 4) & 0xf;
270 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
271 tcg_gen_movi_i32(REG(reg
), val
);
275 case 0x02: /* mov (register-to-register) */
277 int dest
= (opcode
>> 4) & 0xf;
278 int src
= opcode
& 0xf;
279 tcg_gen_mov_i32(REG(dest
), REG(src
));
282 case 0x03: /* jsra */
284 TCGv t1
= tcg_temp_new_i32();
285 TCGv t2
= tcg_temp_new_i32();
287 tcg_gen_movi_i32(t1
, ctx
->pc
+ 6);
289 /* Make space for the static chain and return address. */
290 tcg_gen_subi_i32(t2
, REG(1), 8);
291 tcg_gen_mov_i32(REG(1), t2
);
292 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
294 /* Push the current frame pointer. */
295 tcg_gen_subi_i32(t2
, REG(1), 4);
296 tcg_gen_mov_i32(REG(1), t2
);
297 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
299 /* Set the pc and $fp. */
300 tcg_gen_mov_i32(REG(0), REG(1));
302 gen_goto_tb(env
, ctx
, 0, cpu_ldl_code(env
, ctx
->pc
+2));
304 tcg_temp_free_i32(t1
);
305 tcg_temp_free_i32(t2
);
307 ctx
->bstate
= BS_BRANCH
;
313 TCGv t1
= tcg_temp_new_i32();
315 /* The new $sp is the old $fp. */
316 tcg_gen_mov_i32(REG(1), REG(0));
318 /* Pop the frame pointer. */
319 tcg_gen_qemu_ld32u(REG(0), REG(1), ctx
->memidx
);
320 tcg_gen_addi_i32(t1
, REG(1), 4);
321 tcg_gen_mov_i32(REG(1), t1
);
324 /* Pop the return address and skip over the static chain
326 tcg_gen_qemu_ld32u(cpu_pc
, REG(1), ctx
->memidx
);
327 tcg_gen_addi_i32(t1
, REG(1), 8);
328 tcg_gen_mov_i32(REG(1), t1
);
330 tcg_temp_free_i32(t1
);
335 ctx
->bstate
= BS_BRANCH
;
338 case 0x05: /* add.l */
340 int a
= (opcode
>> 4) & 0xf;
341 int b
= opcode
& 0xf;
343 tcg_gen_add_i32(REG(a
), REG(a
), REG(b
));
346 case 0x06: /* push */
348 int a
= (opcode
>> 4) & 0xf;
349 int b
= opcode
& 0xf;
351 TCGv t1
= tcg_temp_new_i32();
352 tcg_gen_subi_i32(t1
, REG(a
), 4);
353 tcg_gen_mov_i32(REG(a
), t1
);
354 tcg_gen_qemu_st32(REG(b
), REG(a
), ctx
->memidx
);
355 tcg_temp_free_i32(t1
);
360 int a
= (opcode
>> 4) & 0xf;
361 int b
= opcode
& 0xf;
362 TCGv t1
= tcg_temp_new_i32();
364 tcg_gen_qemu_ld32u(REG(b
), REG(a
), ctx
->memidx
);
365 tcg_gen_addi_i32(t1
, REG(a
), 4);
366 tcg_gen_mov_i32(REG(a
), t1
);
367 tcg_temp_free_i32(t1
);
370 case 0x08: /* lda.l */
372 int reg
= (opcode
>> 4) & 0xf;
374 TCGv ptr
= tcg_temp_new_i32();
375 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
376 tcg_gen_qemu_ld32u(REG(reg
), ptr
, ctx
->memidx
);
377 tcg_temp_free_i32(ptr
);
382 case 0x09: /* sta.l */
384 int val
= (opcode
>> 4) & 0xf;
386 TCGv ptr
= tcg_temp_new_i32();
387 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
388 tcg_gen_qemu_st32(REG(val
), ptr
, ctx
->memidx
);
389 tcg_temp_free_i32(ptr
);
394 case 0x0a: /* ld.l (register indirect) */
396 int src
= opcode
& 0xf;
397 int dest
= (opcode
>> 4) & 0xf;
399 tcg_gen_qemu_ld32u(REG(dest
), REG(src
), ctx
->memidx
);
402 case 0x0b: /* st.l */
404 int dest
= (opcode
>> 4) & 0xf;
405 int val
= opcode
& 0xf;
407 tcg_gen_qemu_st32(REG(val
), REG(dest
), ctx
->memidx
);
410 case 0x0c: /* ldo.l */
412 int a
= (opcode
>> 4) & 0xf;
413 int b
= opcode
& 0xf;
415 TCGv t1
= tcg_temp_new_i32();
416 TCGv t2
= tcg_temp_new_i32();
417 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
418 tcg_gen_qemu_ld32u(t2
, t1
, ctx
->memidx
);
419 tcg_gen_mov_i32(REG(a
), t2
);
421 tcg_temp_free_i32(t1
);
422 tcg_temp_free_i32(t2
);
427 case 0x0d: /* sto.l */
429 int a
= (opcode
>> 4) & 0xf;
430 int b
= opcode
& 0xf;
432 TCGv t1
= tcg_temp_new_i32();
433 TCGv t2
= tcg_temp_new_i32();
434 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
435 tcg_gen_qemu_st32(REG(b
), t1
, ctx
->memidx
);
437 tcg_temp_free_i32(t1
);
438 tcg_temp_free_i32(t2
);
445 int a
= (opcode
>> 4) & 0xf;
446 int b
= opcode
& 0xf;
448 tcg_gen_mov_i32(cc_a
, REG(a
));
449 tcg_gen_mov_i32(cc_b
, REG(b
));
454 int fnreg
= (opcode
>> 4) & 0xf;
456 /* Load the stack pointer into T0. */
457 TCGv t1
= tcg_temp_new_i32();
458 TCGv t2
= tcg_temp_new_i32();
460 tcg_gen_movi_i32(t1
, ctx
->pc
+2);
462 /* Make space for the static chain and return address. */
463 tcg_gen_subi_i32(t2
, REG(1), 8);
464 tcg_gen_mov_i32(REG(1), t2
);
465 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
467 /* Push the current frame pointer. */
468 tcg_gen_subi_i32(t2
, REG(1), 4);
469 tcg_gen_mov_i32(REG(1), t2
);
470 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
472 /* Set the pc and $fp. */
473 tcg_gen_mov_i32(REG(0), REG(1));
474 tcg_gen_mov_i32(cpu_pc
, REG(fnreg
));
475 tcg_temp_free_i32(t1
);
476 tcg_temp_free_i32(t2
);
478 ctx
->bstate
= BS_BRANCH
;
481 case 0x1a: /* jmpa */
483 tcg_gen_movi_i32(cpu_pc
, cpu_ldl_code(env
, ctx
->pc
+2));
485 ctx
->bstate
= BS_BRANCH
;
489 case 0x1b: /* ldi.b (immediate) */
491 int reg
= (opcode
>> 4) & 0xf;
492 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
493 tcg_gen_movi_i32(REG(reg
), val
);
497 case 0x1c: /* ld.b (register indirect) */
499 int src
= opcode
& 0xf;
500 int dest
= (opcode
>> 4) & 0xf;
502 tcg_gen_qemu_ld8u(REG(dest
), REG(src
), ctx
->memidx
);
505 case 0x1d: /* lda.b */
507 int reg
= (opcode
>> 4) & 0xf;
509 TCGv ptr
= tcg_temp_new_i32();
510 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
511 tcg_gen_qemu_ld8u(REG(reg
), ptr
, ctx
->memidx
);
512 tcg_temp_free_i32(ptr
);
517 case 0x1e: /* st.b */
519 int dest
= (opcode
>> 4) & 0xf;
520 int val
= opcode
& 0xf;
522 tcg_gen_qemu_st8(REG(val
), REG(dest
), ctx
->memidx
);
525 case 0x1f: /* sta.b */
527 int val
= (opcode
>> 4) & 0xf;
529 TCGv ptr
= tcg_temp_new_i32();
530 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
531 tcg_gen_qemu_st8(REG(val
), ptr
, ctx
->memidx
);
532 tcg_temp_free_i32(ptr
);
537 case 0x20: /* ldi.s (immediate) */
539 int reg
= (opcode
>> 4) & 0xf;
540 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
541 tcg_gen_movi_i32(REG(reg
), val
);
545 case 0x21: /* ld.s (register indirect) */
547 int src
= opcode
& 0xf;
548 int dest
= (opcode
>> 4) & 0xf;
550 tcg_gen_qemu_ld16u(REG(dest
), REG(src
), ctx
->memidx
);
553 case 0x22: /* lda.s */
555 int reg
= (opcode
>> 4) & 0xf;
557 TCGv ptr
= tcg_temp_new_i32();
558 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
559 tcg_gen_qemu_ld16u(REG(reg
), ptr
, ctx
->memidx
);
560 tcg_temp_free_i32(ptr
);
565 case 0x23: /* st.s */
567 int dest
= (opcode
>> 4) & 0xf;
568 int val
= opcode
& 0xf;
570 tcg_gen_qemu_st16(REG(val
), REG(dest
), ctx
->memidx
);
573 case 0x24: /* sta.s */
575 int val
= (opcode
>> 4) & 0xf;
577 TCGv ptr
= tcg_temp_new_i32();
578 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
579 tcg_gen_qemu_st16(REG(val
), ptr
, ctx
->memidx
);
580 tcg_temp_free_i32(ptr
);
587 int reg
= (opcode
>> 4) & 0xf;
588 tcg_gen_mov_i32(cpu_pc
, REG(reg
));
590 ctx
->bstate
= BS_BRANCH
;
595 int a
= (opcode
>> 4) & 0xf;
596 int b
= opcode
& 0xf;
598 tcg_gen_and_i32(REG(a
), REG(a
), REG(b
));
601 case 0x27: /* lshr */
603 int a
= (opcode
>> 4) & 0xf;
604 int b
= opcode
& 0xf;
606 TCGv sv
= tcg_temp_new_i32();
607 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
608 tcg_gen_shr_i32(REG(a
), REG(a
), sv
);
609 tcg_temp_free_i32(sv
);
612 case 0x28: /* ashl */
614 int a
= (opcode
>> 4) & 0xf;
615 int b
= opcode
& 0xf;
617 TCGv sv
= tcg_temp_new_i32();
618 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
619 tcg_gen_shl_i32(REG(a
), REG(a
), sv
);
620 tcg_temp_free_i32(sv
);
623 case 0x29: /* sub.l */
625 int a
= (opcode
>> 4) & 0xf;
626 int b
= opcode
& 0xf;
628 tcg_gen_sub_i32(REG(a
), REG(a
), REG(b
));
633 int a
= (opcode
>> 4) & 0xf;
634 int b
= opcode
& 0xf;
636 tcg_gen_neg_i32(REG(a
), REG(b
));
641 int a
= (opcode
>> 4) & 0xf;
642 int b
= opcode
& 0xf;
644 tcg_gen_or_i32(REG(a
), REG(a
), REG(b
));
649 int a
= (opcode
>> 4) & 0xf;
650 int b
= opcode
& 0xf;
652 tcg_gen_not_i32(REG(a
), REG(b
));
655 case 0x2d: /* ashr */
657 int a
= (opcode
>> 4) & 0xf;
658 int b
= opcode
& 0xf;
660 TCGv sv
= tcg_temp_new_i32();
661 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
662 tcg_gen_sar_i32(REG(a
), REG(a
), sv
);
663 tcg_temp_free_i32(sv
);
668 int a
= (opcode
>> 4) & 0xf;
669 int b
= opcode
& 0xf;
671 tcg_gen_xor_i32(REG(a
), REG(a
), REG(b
));
674 case 0x2f: /* mul.l */
676 int a
= (opcode
>> 4) & 0xf;
677 int b
= opcode
& 0xf;
679 tcg_gen_mul_i32(REG(a
), REG(a
), REG(b
));
684 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
686 TCGv temp
= tcg_temp_new_i32();
687 tcg_gen_movi_i32(temp
, val
);
688 tcg_gen_st_i32(temp
, cpu_env
,
689 offsetof(CPUMoxieState
, sregs
[3]));
690 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
691 tcg_gen_movi_i32(temp
, MOXIE_EX_SWI
);
692 gen_helper_raise_exception(cpu_env
, temp
);
693 tcg_temp_free_i32(temp
);
698 case 0x31: /* div.l */
700 int a
= (opcode
>> 4) & 0xf;
701 int b
= opcode
& 0xf;
702 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
703 gen_helper_div(REG(a
), cpu_env
, REG(a
), REG(b
));
706 case 0x32: /* udiv.l */
708 int a
= (opcode
>> 4) & 0xf;
709 int b
= opcode
& 0xf;
710 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
711 gen_helper_udiv(REG(a
), cpu_env
, REG(a
), REG(b
));
714 case 0x33: /* mod.l */
716 int a
= (opcode
>> 4) & 0xf;
717 int b
= opcode
& 0xf;
718 tcg_gen_rem_i32(REG(a
), REG(a
), REG(b
));
721 case 0x34: /* umod.l */
723 int a
= (opcode
>> 4) & 0xf;
724 int b
= opcode
& 0xf;
725 tcg_gen_remu_i32(REG(a
), REG(a
), REG(b
));
730 TCGv temp
= tcg_temp_new_i32();
731 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
732 tcg_gen_movi_i32(temp
, MOXIE_EX_BREAK
);
733 gen_helper_raise_exception(cpu_env
, temp
);
734 tcg_temp_free_i32(temp
);
737 case 0x36: /* ldo.b */
739 int a
= (opcode
>> 4) & 0xf;
740 int b
= opcode
& 0xf;
742 TCGv t1
= tcg_temp_new_i32();
743 TCGv t2
= tcg_temp_new_i32();
744 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
745 tcg_gen_qemu_ld8u(t2
, t1
, ctx
->memidx
);
746 tcg_gen_mov_i32(REG(a
), t2
);
748 tcg_temp_free_i32(t1
);
749 tcg_temp_free_i32(t2
);
754 case 0x37: /* sto.b */
756 int a
= (opcode
>> 4) & 0xf;
757 int b
= opcode
& 0xf;
759 TCGv t1
= tcg_temp_new_i32();
760 TCGv t2
= tcg_temp_new_i32();
761 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
762 tcg_gen_qemu_st8(REG(b
), t1
, ctx
->memidx
);
764 tcg_temp_free_i32(t1
);
765 tcg_temp_free_i32(t2
);
770 case 0x38: /* ldo.s */
772 int a
= (opcode
>> 4) & 0xf;
773 int b
= opcode
& 0xf;
775 TCGv t1
= tcg_temp_new_i32();
776 TCGv t2
= tcg_temp_new_i32();
777 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
778 tcg_gen_qemu_ld16u(t2
, t1
, ctx
->memidx
);
779 tcg_gen_mov_i32(REG(a
), t2
);
781 tcg_temp_free_i32(t1
);
782 tcg_temp_free_i32(t2
);
787 case 0x39: /* sto.s */
789 int a
= (opcode
>> 4) & 0xf;
790 int b
= opcode
& 0xf;
792 TCGv t1
= tcg_temp_new_i32();
793 TCGv t2
= tcg_temp_new_i32();
794 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
795 tcg_gen_qemu_st16(REG(b
), t1
, ctx
->memidx
);
796 tcg_temp_free_i32(t1
);
797 tcg_temp_free_i32(t2
);
804 TCGv temp
= tcg_temp_new_i32();
805 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
806 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
807 gen_helper_raise_exception(cpu_env
, temp
);
808 tcg_temp_free_i32(temp
);
817 /* generate intermediate code for basic block 'tb'. */
818 void gen_intermediate_code(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
820 MoxieCPU
*cpu
= moxie_env_get_cpu(env
);
821 CPUState
*cs
= CPU(cpu
);
823 target_ulong pc_start
;
824 int num_insns
, max_insns
;
831 ctx
.singlestep_enabled
= 0;
832 ctx
.bstate
= BS_NONE
;
834 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
835 if (max_insns
== 0) {
836 max_insns
= CF_COUNT_MASK
;
838 if (max_insns
> TCG_MAX_INSNS
) {
839 max_insns
= TCG_MAX_INSNS
;
844 tcg_gen_insn_start(ctx
.pc
);
847 if (unlikely(cpu_breakpoint_test(cs
, ctx
.pc
, BP_ANY
))) {
848 tcg_gen_movi_i32(cpu_pc
, ctx
.pc
);
849 gen_helper_debug(cpu_env
);
850 ctx
.bstate
= BS_EXCP
;
851 goto done_generating
;
854 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
855 ctx
.pc
+= decode_opc(cpu
, &ctx
);
857 if (num_insns
>= max_insns
) {
860 if (cs
->singlestep_enabled
) {
863 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) {
866 } while (ctx
.bstate
== BS_NONE
&& !tcg_op_buf_full());
868 if (cs
->singlestep_enabled
) {
869 tcg_gen_movi_tl(cpu_pc
, ctx
.pc
);
870 gen_helper_debug(cpu_env
);
872 switch (ctx
.bstate
) {
875 gen_goto_tb(env
, &ctx
, 0, ctx
.pc
);
886 gen_tb_end(tb
, num_insns
);
888 tb
->size
= ctx
.pc
- pc_start
;
889 tb
->icount
= num_insns
;
892 void restore_state_to_opc(CPUMoxieState
*env
, TranslationBlock
*tb
,