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
32 #include "exec/exec-all.h"
33 #include "disas/disas.h"
40 /* This is the state at translation time. */
41 typedef struct DisasContext
{
42 struct TranslationBlock
*tb
;
43 target_ulong pc
, saved_pc
;
46 /* Routine used to access memory */
50 int singlestep_enabled
;
54 BS_NONE
= 0, /* We go out of the TB without reaching a branch or an
55 * exception condition */
56 BS_STOP
= 1, /* We want to stop translation for any reason */
57 BS_BRANCH
= 2, /* We reached a branch condition */
58 BS_EXCP
= 3, /* We reached an exception condition */
62 static TCGv cpu_gregs
[16];
63 static TCGv_ptr cpu_env
;
64 static TCGv cc_a
, cc_b
;
66 #include "exec/gen-icount.h"
68 #define REG(x) (cpu_gregs[x])
70 /* Extract the signed 10-bit offset from a 16-bit branch
72 static int extract_branch_offset(int opcode
)
74 return (((signed short)((opcode
& ((1 << 10) - 1)) << 6)) >> 6) << 1;
77 void moxie_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
80 MoxieCPU
*cpu
= MOXIE_CPU(cs
);
81 CPUMoxieState
*env
= &cpu
->env
;
83 cpu_fprintf(f
, "pc=0x%08x\n", env
->pc
);
84 cpu_fprintf(f
, "$fp=0x%08x $sp=0x%08x $r0=0x%08x $r1=0x%08x\n",
85 env
->gregs
[0], env
->gregs
[1], env
->gregs
[2], env
->gregs
[3]);
86 for (i
= 4; i
< 16; i
+= 4) {
87 cpu_fprintf(f
, "$r%d=0x%08x $r%d=0x%08x $r%d=0x%08x $r%d=0x%08x\n",
88 i
-2, env
->gregs
[i
], i
-1, env
->gregs
[i
+ 1],
89 i
, env
->gregs
[i
+ 2], i
+1, env
->gregs
[i
+ 3]);
91 for (i
= 4; i
< 16; i
+= 4) {
92 cpu_fprintf(f
, "sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x sr%d=0x%08x\n",
93 i
-2, env
->sregs
[i
], i
-1, env
->sregs
[i
+ 1],
94 i
, env
->sregs
[i
+ 2], i
+1, env
->sregs
[i
+ 3]);
98 void moxie_translate_init(void)
101 static int done_init
;
102 static const char * const gregnames
[16] = {
103 "$fp", "$sp", "$r0", "$r1",
104 "$r2", "$r3", "$r4", "$r5",
105 "$r6", "$r7", "$r8", "$r9",
106 "$r10", "$r11", "$r12", "$r13"
112 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
113 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
114 offsetof(CPUMoxieState
, pc
), "$pc");
115 for (i
= 0; i
< 16; i
++)
116 cpu_gregs
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
117 offsetof(CPUMoxieState
, gregs
[i
]),
120 cc_a
= tcg_global_mem_new_i32(TCG_AREG0
,
121 offsetof(CPUMoxieState
, cc_a
), "cc_a");
122 cc_b
= tcg_global_mem_new_i32(TCG_AREG0
,
123 offsetof(CPUMoxieState
, cc_b
), "cc_b");
128 static inline void gen_goto_tb(CPUMoxieState
*env
, DisasContext
*ctx
,
129 int n
, target_ulong dest
)
131 TranslationBlock
*tb
;
134 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
135 !ctx
->singlestep_enabled
) {
137 tcg_gen_movi_i32(cpu_pc
, dest
);
138 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
140 tcg_gen_movi_i32(cpu_pc
, dest
);
141 if (ctx
->singlestep_enabled
) {
142 gen_helper_debug(cpu_env
);
148 static int decode_opc(MoxieCPU
*cpu
, DisasContext
*ctx
)
150 CPUMoxieState
*env
= &cpu
->env
;
152 /* Local cache for the instruction opcode. */
154 /* Set the default instruction length. */
157 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
158 tcg_gen_debug_insn_start(ctx
->pc
);
161 /* Examine the 16-bit opcode. */
162 opcode
= ctx
->opcode
;
164 /* Decode instruction. */
165 if (opcode
& (1 << 15)) {
166 if (opcode
& (1 << 14)) {
167 /* This is a Form 3 instruction. */
168 int inst
= (opcode
>> 10 & 0xf);
170 #define BRANCH(cond) \
172 int l1 = gen_new_label(); \
173 tcg_gen_brcond_i32(cond, cc_a, cc_b, l1); \
174 gen_goto_tb(env, ctx, 1, ctx->pc+2); \
176 gen_goto_tb(env, ctx, 0, extract_branch_offset(opcode) + ctx->pc+2); \
177 ctx->bstate = BS_BRANCH; \
193 case 0x04: /* bltu */
194 BRANCH(TCG_COND_LTU
);
196 case 0x05: /* bgtu */
197 BRANCH(TCG_COND_GTU
);
205 case 0x08: /* bgeu */
206 BRANCH(TCG_COND_GEU
);
208 case 0x09: /* bleu */
209 BRANCH(TCG_COND_LEU
);
213 TCGv temp
= tcg_temp_new_i32();
214 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
215 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
216 gen_helper_raise_exception(cpu_env
, temp
);
217 tcg_temp_free_i32(temp
);
222 /* This is a Form 2 instruction. */
223 int inst
= (opcode
>> 12 & 0x3);
227 int a
= (opcode
>> 8) & 0xf;
228 unsigned int v
= (opcode
& 0xff);
229 tcg_gen_addi_i32(REG(a
), REG(a
), v
);
234 int a
= (opcode
>> 8) & 0xf;
235 unsigned int v
= (opcode
& 0xff);
236 tcg_gen_subi_i32(REG(a
), REG(a
), v
);
241 int a
= (opcode
>> 8) & 0xf;
242 unsigned v
= (opcode
& 0xff);
243 tcg_gen_ld_i32(REG(a
), cpu_env
,
244 offsetof(CPUMoxieState
, sregs
[v
]));
249 int a
= (opcode
>> 8) & 0xf;
250 unsigned v
= (opcode
& 0xff);
251 tcg_gen_st_i32(REG(a
), cpu_env
,
252 offsetof(CPUMoxieState
, sregs
[v
]));
257 TCGv temp
= tcg_temp_new_i32();
258 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
259 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
260 gen_helper_raise_exception(cpu_env
, temp
);
261 tcg_temp_free_i32(temp
);
267 /* This is a Form 1 instruction. */
268 int inst
= opcode
>> 8;
272 case 0x01: /* ldi.l (immediate) */
274 int reg
= (opcode
>> 4) & 0xf;
275 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
276 tcg_gen_movi_i32(REG(reg
), val
);
280 case 0x02: /* mov (register-to-register) */
282 int dest
= (opcode
>> 4) & 0xf;
283 int src
= opcode
& 0xf;
284 tcg_gen_mov_i32(REG(dest
), REG(src
));
287 case 0x03: /* jsra */
289 TCGv t1
= tcg_temp_new_i32();
290 TCGv t2
= tcg_temp_new_i32();
292 tcg_gen_movi_i32(t1
, ctx
->pc
+ 6);
294 /* Make space for the static chain and return address. */
295 tcg_gen_subi_i32(t2
, REG(1), 8);
296 tcg_gen_mov_i32(REG(1), t2
);
297 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
299 /* Push the current frame pointer. */
300 tcg_gen_subi_i32(t2
, REG(1), 4);
301 tcg_gen_mov_i32(REG(1), t2
);
302 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
304 /* Set the pc and $fp. */
305 tcg_gen_mov_i32(REG(0), REG(1));
307 gen_goto_tb(env
, ctx
, 0, cpu_ldl_code(env
, ctx
->pc
+2));
309 tcg_temp_free_i32(t1
);
310 tcg_temp_free_i32(t2
);
312 ctx
->bstate
= BS_BRANCH
;
318 TCGv t1
= tcg_temp_new_i32();
320 /* The new $sp is the old $fp. */
321 tcg_gen_mov_i32(REG(1), REG(0));
323 /* Pop the frame pointer. */
324 tcg_gen_qemu_ld32u(REG(0), REG(1), ctx
->memidx
);
325 tcg_gen_addi_i32(t1
, REG(1), 4);
326 tcg_gen_mov_i32(REG(1), t1
);
329 /* Pop the return address and skip over the static chain
331 tcg_gen_qemu_ld32u(cpu_pc
, REG(1), ctx
->memidx
);
332 tcg_gen_addi_i32(t1
, REG(1), 8);
333 tcg_gen_mov_i32(REG(1), t1
);
335 tcg_temp_free_i32(t1
);
340 ctx
->bstate
= BS_BRANCH
;
343 case 0x05: /* add.l */
345 int a
= (opcode
>> 4) & 0xf;
346 int b
= opcode
& 0xf;
348 tcg_gen_add_i32(REG(a
), REG(a
), REG(b
));
351 case 0x06: /* push */
353 int a
= (opcode
>> 4) & 0xf;
354 int b
= opcode
& 0xf;
356 TCGv t1
= tcg_temp_new_i32();
357 tcg_gen_subi_i32(t1
, REG(a
), 4);
358 tcg_gen_mov_i32(REG(a
), t1
);
359 tcg_gen_qemu_st32(REG(b
), REG(a
), ctx
->memidx
);
360 tcg_temp_free_i32(t1
);
365 int a
= (opcode
>> 4) & 0xf;
366 int b
= opcode
& 0xf;
367 TCGv t1
= tcg_temp_new_i32();
369 tcg_gen_qemu_ld32u(REG(b
), REG(a
), ctx
->memidx
);
370 tcg_gen_addi_i32(t1
, REG(a
), 4);
371 tcg_gen_mov_i32(REG(a
), t1
);
372 tcg_temp_free_i32(t1
);
375 case 0x08: /* lda.l */
377 int reg
= (opcode
>> 4) & 0xf;
379 TCGv ptr
= tcg_temp_new_i32();
380 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
381 tcg_gen_qemu_ld32u(REG(reg
), ptr
, ctx
->memidx
);
382 tcg_temp_free_i32(ptr
);
387 case 0x09: /* sta.l */
389 int val
= (opcode
>> 4) & 0xf;
391 TCGv ptr
= tcg_temp_new_i32();
392 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
393 tcg_gen_qemu_st32(REG(val
), ptr
, ctx
->memidx
);
394 tcg_temp_free_i32(ptr
);
399 case 0x0a: /* ld.l (register indirect) */
401 int src
= opcode
& 0xf;
402 int dest
= (opcode
>> 4) & 0xf;
404 tcg_gen_qemu_ld32u(REG(dest
), REG(src
), ctx
->memidx
);
407 case 0x0b: /* st.l */
409 int dest
= (opcode
>> 4) & 0xf;
410 int val
= opcode
& 0xf;
412 tcg_gen_qemu_st32(REG(val
), REG(dest
), ctx
->memidx
);
415 case 0x0c: /* ldo.l */
417 int a
= (opcode
>> 4) & 0xf;
418 int b
= opcode
& 0xf;
420 TCGv t1
= tcg_temp_new_i32();
421 TCGv t2
= tcg_temp_new_i32();
422 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
423 tcg_gen_qemu_ld32u(t2
, t1
, ctx
->memidx
);
424 tcg_gen_mov_i32(REG(a
), t2
);
426 tcg_temp_free_i32(t1
);
427 tcg_temp_free_i32(t2
);
432 case 0x0d: /* sto.l */
434 int a
= (opcode
>> 4) & 0xf;
435 int b
= opcode
& 0xf;
437 TCGv t1
= tcg_temp_new_i32();
438 TCGv t2
= tcg_temp_new_i32();
439 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
440 tcg_gen_qemu_st32(REG(b
), t1
, ctx
->memidx
);
442 tcg_temp_free_i32(t1
);
443 tcg_temp_free_i32(t2
);
450 int a
= (opcode
>> 4) & 0xf;
451 int b
= opcode
& 0xf;
453 tcg_gen_mov_i32(cc_a
, REG(a
));
454 tcg_gen_mov_i32(cc_b
, REG(b
));
459 int fnreg
= (opcode
>> 4) & 0xf;
461 /* Load the stack pointer into T0. */
462 TCGv t1
= tcg_temp_new_i32();
463 TCGv t2
= tcg_temp_new_i32();
465 tcg_gen_movi_i32(t1
, ctx
->pc
+2);
467 /* Make space for the static chain and return address. */
468 tcg_gen_subi_i32(t2
, REG(1), 8);
469 tcg_gen_mov_i32(REG(1), t2
);
470 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
472 /* Push the current frame pointer. */
473 tcg_gen_subi_i32(t2
, REG(1), 4);
474 tcg_gen_mov_i32(REG(1), t2
);
475 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
477 /* Set the pc and $fp. */
478 tcg_gen_mov_i32(REG(0), REG(1));
479 tcg_gen_mov_i32(cpu_pc
, REG(fnreg
));
480 tcg_temp_free_i32(t1
);
481 tcg_temp_free_i32(t2
);
483 ctx
->bstate
= BS_BRANCH
;
486 case 0x1a: /* jmpa */
488 tcg_gen_movi_i32(cpu_pc
, cpu_ldl_code(env
, ctx
->pc
+2));
490 ctx
->bstate
= BS_BRANCH
;
494 case 0x1b: /* ldi.b (immediate) */
496 int reg
= (opcode
>> 4) & 0xf;
497 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
498 tcg_gen_movi_i32(REG(reg
), val
);
502 case 0x1c: /* ld.b (register indirect) */
504 int src
= opcode
& 0xf;
505 int dest
= (opcode
>> 4) & 0xf;
507 tcg_gen_qemu_ld8u(REG(dest
), REG(src
), ctx
->memidx
);
510 case 0x1d: /* lda.b */
512 int reg
= (opcode
>> 4) & 0xf;
514 TCGv ptr
= tcg_temp_new_i32();
515 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
516 tcg_gen_qemu_ld8u(REG(reg
), ptr
, ctx
->memidx
);
517 tcg_temp_free_i32(ptr
);
522 case 0x1e: /* st.b */
524 int dest
= (opcode
>> 4) & 0xf;
525 int val
= opcode
& 0xf;
527 tcg_gen_qemu_st8(REG(val
), REG(dest
), ctx
->memidx
);
530 case 0x1f: /* sta.b */
532 int val
= (opcode
>> 4) & 0xf;
534 TCGv ptr
= tcg_temp_new_i32();
535 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
536 tcg_gen_qemu_st8(REG(val
), ptr
, ctx
->memidx
);
537 tcg_temp_free_i32(ptr
);
542 case 0x20: /* ldi.s (immediate) */
544 int reg
= (opcode
>> 4) & 0xf;
545 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
546 tcg_gen_movi_i32(REG(reg
), val
);
550 case 0x21: /* ld.s (register indirect) */
552 int src
= opcode
& 0xf;
553 int dest
= (opcode
>> 4) & 0xf;
555 tcg_gen_qemu_ld16u(REG(dest
), REG(src
), ctx
->memidx
);
558 case 0x22: /* lda.s */
560 int reg
= (opcode
>> 4) & 0xf;
562 TCGv ptr
= tcg_temp_new_i32();
563 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
564 tcg_gen_qemu_ld16u(REG(reg
), ptr
, ctx
->memidx
);
565 tcg_temp_free_i32(ptr
);
570 case 0x23: /* st.s */
572 int dest
= (opcode
>> 4) & 0xf;
573 int val
= opcode
& 0xf;
575 tcg_gen_qemu_st16(REG(val
), REG(dest
), ctx
->memidx
);
578 case 0x24: /* sta.s */
580 int val
= (opcode
>> 4) & 0xf;
582 TCGv ptr
= tcg_temp_new_i32();
583 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
584 tcg_gen_qemu_st16(REG(val
), ptr
, ctx
->memidx
);
585 tcg_temp_free_i32(ptr
);
592 int reg
= (opcode
>> 4) & 0xf;
593 tcg_gen_mov_i32(cpu_pc
, REG(reg
));
595 ctx
->bstate
= BS_BRANCH
;
600 int a
= (opcode
>> 4) & 0xf;
601 int b
= opcode
& 0xf;
603 tcg_gen_and_i32(REG(a
), REG(a
), REG(b
));
606 case 0x27: /* lshr */
608 int a
= (opcode
>> 4) & 0xf;
609 int b
= opcode
& 0xf;
611 TCGv sv
= tcg_temp_new_i32();
612 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
613 tcg_gen_shr_i32(REG(a
), REG(a
), sv
);
614 tcg_temp_free_i32(sv
);
617 case 0x28: /* ashl */
619 int a
= (opcode
>> 4) & 0xf;
620 int b
= opcode
& 0xf;
622 TCGv sv
= tcg_temp_new_i32();
623 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
624 tcg_gen_shl_i32(REG(a
), REG(a
), sv
);
625 tcg_temp_free_i32(sv
);
628 case 0x29: /* sub.l */
630 int a
= (opcode
>> 4) & 0xf;
631 int b
= opcode
& 0xf;
633 tcg_gen_sub_i32(REG(a
), REG(a
), REG(b
));
638 int a
= (opcode
>> 4) & 0xf;
639 int b
= opcode
& 0xf;
641 tcg_gen_neg_i32(REG(a
), REG(b
));
646 int a
= (opcode
>> 4) & 0xf;
647 int b
= opcode
& 0xf;
649 tcg_gen_or_i32(REG(a
), REG(a
), REG(b
));
654 int a
= (opcode
>> 4) & 0xf;
655 int b
= opcode
& 0xf;
657 tcg_gen_not_i32(REG(a
), REG(b
));
660 case 0x2d: /* ashr */
662 int a
= (opcode
>> 4) & 0xf;
663 int b
= opcode
& 0xf;
665 TCGv sv
= tcg_temp_new_i32();
666 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
667 tcg_gen_sar_i32(REG(a
), REG(a
), sv
);
668 tcg_temp_free_i32(sv
);
673 int a
= (opcode
>> 4) & 0xf;
674 int b
= opcode
& 0xf;
676 tcg_gen_xor_i32(REG(a
), REG(a
), REG(b
));
679 case 0x2f: /* mul.l */
681 int a
= (opcode
>> 4) & 0xf;
682 int b
= opcode
& 0xf;
684 tcg_gen_mul_i32(REG(a
), REG(a
), REG(b
));
689 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
691 TCGv temp
= tcg_temp_new_i32();
692 tcg_gen_movi_i32(temp
, val
);
693 tcg_gen_st_i32(temp
, cpu_env
,
694 offsetof(CPUMoxieState
, sregs
[3]));
695 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
696 tcg_gen_movi_i32(temp
, MOXIE_EX_SWI
);
697 gen_helper_raise_exception(cpu_env
, temp
);
698 tcg_temp_free_i32(temp
);
703 case 0x31: /* div.l */
705 int a
= (opcode
>> 4) & 0xf;
706 int b
= opcode
& 0xf;
707 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
708 gen_helper_div(REG(a
), cpu_env
, REG(a
), REG(b
));
711 case 0x32: /* udiv.l */
713 int a
= (opcode
>> 4) & 0xf;
714 int b
= opcode
& 0xf;
715 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
716 gen_helper_udiv(REG(a
), cpu_env
, REG(a
), REG(b
));
719 case 0x33: /* mod.l */
721 int a
= (opcode
>> 4) & 0xf;
722 int b
= opcode
& 0xf;
723 tcg_gen_rem_i32(REG(a
), REG(a
), REG(b
));
726 case 0x34: /* umod.l */
728 int a
= (opcode
>> 4) & 0xf;
729 int b
= opcode
& 0xf;
730 tcg_gen_remu_i32(REG(a
), REG(a
), REG(b
));
735 TCGv temp
= tcg_temp_new_i32();
736 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
737 tcg_gen_movi_i32(temp
, MOXIE_EX_BREAK
);
738 gen_helper_raise_exception(cpu_env
, temp
);
739 tcg_temp_free_i32(temp
);
742 case 0x36: /* ldo.b */
744 int a
= (opcode
>> 4) & 0xf;
745 int b
= opcode
& 0xf;
747 TCGv t1
= tcg_temp_new_i32();
748 TCGv t2
= tcg_temp_new_i32();
749 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
750 tcg_gen_qemu_ld8u(t2
, t1
, ctx
->memidx
);
751 tcg_gen_mov_i32(REG(a
), t2
);
753 tcg_temp_free_i32(t1
);
754 tcg_temp_free_i32(t2
);
759 case 0x37: /* sto.b */
761 int a
= (opcode
>> 4) & 0xf;
762 int b
= opcode
& 0xf;
764 TCGv t1
= tcg_temp_new_i32();
765 TCGv t2
= tcg_temp_new_i32();
766 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
767 tcg_gen_qemu_st8(REG(b
), t1
, ctx
->memidx
);
769 tcg_temp_free_i32(t1
);
770 tcg_temp_free_i32(t2
);
775 case 0x38: /* ldo.s */
777 int a
= (opcode
>> 4) & 0xf;
778 int b
= opcode
& 0xf;
780 TCGv t1
= tcg_temp_new_i32();
781 TCGv t2
= tcg_temp_new_i32();
782 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
783 tcg_gen_qemu_ld16u(t2
, t1
, ctx
->memidx
);
784 tcg_gen_mov_i32(REG(a
), t2
);
786 tcg_temp_free_i32(t1
);
787 tcg_temp_free_i32(t2
);
792 case 0x39: /* sto.s */
794 int a
= (opcode
>> 4) & 0xf;
795 int b
= opcode
& 0xf;
797 TCGv t1
= tcg_temp_new_i32();
798 TCGv t2
= tcg_temp_new_i32();
799 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
800 tcg_gen_qemu_st16(REG(b
), t1
, ctx
->memidx
);
801 tcg_temp_free_i32(t1
);
802 tcg_temp_free_i32(t2
);
809 TCGv temp
= tcg_temp_new_i32();
810 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
811 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
812 gen_helper_raise_exception(cpu_env
, temp
);
813 tcg_temp_free_i32(temp
);
822 /* generate intermediate code for basic block 'tb'. */
824 gen_intermediate_code_internal(MoxieCPU
*cpu
, TranslationBlock
*tb
,
827 CPUState
*cs
= CPU(cpu
);
829 target_ulong pc_start
;
830 uint16_t *gen_opc_end
;
833 CPUMoxieState
*env
= &cpu
->env
;
837 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
842 ctx
.singlestep_enabled
= 0;
843 ctx
.bstate
= BS_NONE
;
848 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
849 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
850 if (ctx
.pc
== bp
->pc
) {
851 tcg_gen_movi_i32(cpu_pc
, ctx
.pc
);
852 gen_helper_debug(cpu_env
);
853 ctx
.bstate
= BS_EXCP
;
854 goto done_generating
;
860 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
864 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
867 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.pc
;
868 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
869 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
871 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
872 ctx
.pc
+= decode_opc(cpu
, &ctx
);
875 if (cs
->singlestep_enabled
) {
879 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) {
882 } while (ctx
.bstate
== BS_NONE
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
884 if (cs
->singlestep_enabled
) {
885 tcg_gen_movi_tl(cpu_pc
, ctx
.pc
);
886 gen_helper_debug(cpu_env
);
888 switch (ctx
.bstate
) {
891 gen_goto_tb(env
, &ctx
, 0, ctx
.pc
);
902 gen_tb_end(tb
, num_insns
);
903 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
905 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
908 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
911 tb
->size
= ctx
.pc
- pc_start
;
912 tb
->icount
= num_insns
;
916 void gen_intermediate_code(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
918 gen_intermediate_code_internal(moxie_env_get_cpu(env
), tb
, false);
921 void gen_intermediate_code_pc(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
923 gen_intermediate_code_internal(moxie_env_get_cpu(env
), tb
, true);
926 void restore_state_to_opc(CPUMoxieState
*env
, TranslationBlock
*tb
, int pc_pos
)
928 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];