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 void gen_goto_tb(CPUMoxieState
*env
, DisasContext
*ctx
,
125 int n
, target_ulong dest
)
127 TranslationBlock
*tb
;
130 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
131 !ctx
->singlestep_enabled
) {
133 tcg_gen_movi_i32(cpu_pc
, dest
);
134 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
136 tcg_gen_movi_i32(cpu_pc
, dest
);
137 if (ctx
->singlestep_enabled
) {
138 gen_helper_debug(cpu_env
);
144 static int decode_opc(MoxieCPU
*cpu
, DisasContext
*ctx
)
146 CPUMoxieState
*env
= &cpu
->env
;
148 /* Local cache for the instruction opcode. */
150 /* Set the default instruction length. */
153 /* Examine the 16-bit opcode. */
154 opcode
= ctx
->opcode
;
156 /* Decode instruction. */
157 if (opcode
& (1 << 15)) {
158 if (opcode
& (1 << 14)) {
159 /* This is a Form 3 instruction. */
160 int inst
= (opcode
>> 10 & 0xf);
162 #define BRANCH(cond) \
164 TCGLabel *l1 = gen_new_label(); \
165 tcg_gen_brcond_i32(cond, cc_a, cc_b, l1); \
166 gen_goto_tb(env, ctx, 1, ctx->pc+2); \
168 gen_goto_tb(env, ctx, 0, extract_branch_offset(opcode) + ctx->pc+2); \
169 ctx->bstate = BS_BRANCH; \
185 case 0x04: /* bltu */
186 BRANCH(TCG_COND_LTU
);
188 case 0x05: /* bgtu */
189 BRANCH(TCG_COND_GTU
);
197 case 0x08: /* bgeu */
198 BRANCH(TCG_COND_GEU
);
200 case 0x09: /* bleu */
201 BRANCH(TCG_COND_LEU
);
205 TCGv temp
= tcg_temp_new_i32();
206 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
207 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
208 gen_helper_raise_exception(cpu_env
, temp
);
209 tcg_temp_free_i32(temp
);
214 /* This is a Form 2 instruction. */
215 int inst
= (opcode
>> 12 & 0x3);
219 int a
= (opcode
>> 8) & 0xf;
220 unsigned int v
= (opcode
& 0xff);
221 tcg_gen_addi_i32(REG(a
), REG(a
), v
);
226 int a
= (opcode
>> 8) & 0xf;
227 unsigned int v
= (opcode
& 0xff);
228 tcg_gen_subi_i32(REG(a
), REG(a
), v
);
233 int a
= (opcode
>> 8) & 0xf;
234 unsigned v
= (opcode
& 0xff);
235 tcg_gen_ld_i32(REG(a
), cpu_env
,
236 offsetof(CPUMoxieState
, sregs
[v
]));
241 int a
= (opcode
>> 8) & 0xf;
242 unsigned v
= (opcode
& 0xff);
243 tcg_gen_st_i32(REG(a
), cpu_env
,
244 offsetof(CPUMoxieState
, sregs
[v
]));
249 TCGv temp
= tcg_temp_new_i32();
250 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
251 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
252 gen_helper_raise_exception(cpu_env
, temp
);
253 tcg_temp_free_i32(temp
);
259 /* This is a Form 1 instruction. */
260 int inst
= opcode
>> 8;
264 case 0x01: /* ldi.l (immediate) */
266 int reg
= (opcode
>> 4) & 0xf;
267 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
268 tcg_gen_movi_i32(REG(reg
), val
);
272 case 0x02: /* mov (register-to-register) */
274 int dest
= (opcode
>> 4) & 0xf;
275 int src
= opcode
& 0xf;
276 tcg_gen_mov_i32(REG(dest
), REG(src
));
279 case 0x03: /* jsra */
281 TCGv t1
= tcg_temp_new_i32();
282 TCGv t2
= tcg_temp_new_i32();
284 tcg_gen_movi_i32(t1
, ctx
->pc
+ 6);
286 /* Make space for the static chain and return address. */
287 tcg_gen_subi_i32(t2
, REG(1), 8);
288 tcg_gen_mov_i32(REG(1), t2
);
289 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
291 /* Push the current frame pointer. */
292 tcg_gen_subi_i32(t2
, REG(1), 4);
293 tcg_gen_mov_i32(REG(1), t2
);
294 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
296 /* Set the pc and $fp. */
297 tcg_gen_mov_i32(REG(0), REG(1));
299 gen_goto_tb(env
, ctx
, 0, cpu_ldl_code(env
, ctx
->pc
+2));
301 tcg_temp_free_i32(t1
);
302 tcg_temp_free_i32(t2
);
304 ctx
->bstate
= BS_BRANCH
;
310 TCGv t1
= tcg_temp_new_i32();
312 /* The new $sp is the old $fp. */
313 tcg_gen_mov_i32(REG(1), REG(0));
315 /* Pop the frame pointer. */
316 tcg_gen_qemu_ld32u(REG(0), REG(1), ctx
->memidx
);
317 tcg_gen_addi_i32(t1
, REG(1), 4);
318 tcg_gen_mov_i32(REG(1), t1
);
321 /* Pop the return address and skip over the static chain
323 tcg_gen_qemu_ld32u(cpu_pc
, REG(1), ctx
->memidx
);
324 tcg_gen_addi_i32(t1
, REG(1), 8);
325 tcg_gen_mov_i32(REG(1), t1
);
327 tcg_temp_free_i32(t1
);
332 ctx
->bstate
= BS_BRANCH
;
335 case 0x05: /* add.l */
337 int a
= (opcode
>> 4) & 0xf;
338 int b
= opcode
& 0xf;
340 tcg_gen_add_i32(REG(a
), REG(a
), REG(b
));
343 case 0x06: /* push */
345 int a
= (opcode
>> 4) & 0xf;
346 int b
= opcode
& 0xf;
348 TCGv t1
= tcg_temp_new_i32();
349 tcg_gen_subi_i32(t1
, REG(a
), 4);
350 tcg_gen_mov_i32(REG(a
), t1
);
351 tcg_gen_qemu_st32(REG(b
), REG(a
), ctx
->memidx
);
352 tcg_temp_free_i32(t1
);
357 int a
= (opcode
>> 4) & 0xf;
358 int b
= opcode
& 0xf;
359 TCGv t1
= tcg_temp_new_i32();
361 tcg_gen_qemu_ld32u(REG(b
), REG(a
), ctx
->memidx
);
362 tcg_gen_addi_i32(t1
, REG(a
), 4);
363 tcg_gen_mov_i32(REG(a
), t1
);
364 tcg_temp_free_i32(t1
);
367 case 0x08: /* lda.l */
369 int reg
= (opcode
>> 4) & 0xf;
371 TCGv ptr
= tcg_temp_new_i32();
372 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
373 tcg_gen_qemu_ld32u(REG(reg
), ptr
, ctx
->memidx
);
374 tcg_temp_free_i32(ptr
);
379 case 0x09: /* sta.l */
381 int val
= (opcode
>> 4) & 0xf;
383 TCGv ptr
= tcg_temp_new_i32();
384 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
385 tcg_gen_qemu_st32(REG(val
), ptr
, ctx
->memidx
);
386 tcg_temp_free_i32(ptr
);
391 case 0x0a: /* ld.l (register indirect) */
393 int src
= opcode
& 0xf;
394 int dest
= (opcode
>> 4) & 0xf;
396 tcg_gen_qemu_ld32u(REG(dest
), REG(src
), ctx
->memidx
);
399 case 0x0b: /* st.l */
401 int dest
= (opcode
>> 4) & 0xf;
402 int val
= opcode
& 0xf;
404 tcg_gen_qemu_st32(REG(val
), REG(dest
), ctx
->memidx
);
407 case 0x0c: /* ldo.l */
409 int a
= (opcode
>> 4) & 0xf;
410 int b
= opcode
& 0xf;
412 TCGv t1
= tcg_temp_new_i32();
413 TCGv t2
= tcg_temp_new_i32();
414 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
415 tcg_gen_qemu_ld32u(t2
, t1
, ctx
->memidx
);
416 tcg_gen_mov_i32(REG(a
), t2
);
418 tcg_temp_free_i32(t1
);
419 tcg_temp_free_i32(t2
);
424 case 0x0d: /* sto.l */
426 int a
= (opcode
>> 4) & 0xf;
427 int b
= opcode
& 0xf;
429 TCGv t1
= tcg_temp_new_i32();
430 TCGv t2
= tcg_temp_new_i32();
431 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
432 tcg_gen_qemu_st32(REG(b
), t1
, ctx
->memidx
);
434 tcg_temp_free_i32(t1
);
435 tcg_temp_free_i32(t2
);
442 int a
= (opcode
>> 4) & 0xf;
443 int b
= opcode
& 0xf;
445 tcg_gen_mov_i32(cc_a
, REG(a
));
446 tcg_gen_mov_i32(cc_b
, REG(b
));
451 int fnreg
= (opcode
>> 4) & 0xf;
453 /* Load the stack pointer into T0. */
454 TCGv t1
= tcg_temp_new_i32();
455 TCGv t2
= tcg_temp_new_i32();
457 tcg_gen_movi_i32(t1
, ctx
->pc
+2);
459 /* Make space for the static chain and return address. */
460 tcg_gen_subi_i32(t2
, REG(1), 8);
461 tcg_gen_mov_i32(REG(1), t2
);
462 tcg_gen_qemu_st32(t1
, REG(1), ctx
->memidx
);
464 /* Push the current frame pointer. */
465 tcg_gen_subi_i32(t2
, REG(1), 4);
466 tcg_gen_mov_i32(REG(1), t2
);
467 tcg_gen_qemu_st32(REG(0), REG(1), ctx
->memidx
);
469 /* Set the pc and $fp. */
470 tcg_gen_mov_i32(REG(0), REG(1));
471 tcg_gen_mov_i32(cpu_pc
, REG(fnreg
));
472 tcg_temp_free_i32(t1
);
473 tcg_temp_free_i32(t2
);
475 ctx
->bstate
= BS_BRANCH
;
478 case 0x1a: /* jmpa */
480 tcg_gen_movi_i32(cpu_pc
, cpu_ldl_code(env
, ctx
->pc
+2));
482 ctx
->bstate
= BS_BRANCH
;
486 case 0x1b: /* ldi.b (immediate) */
488 int reg
= (opcode
>> 4) & 0xf;
489 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
490 tcg_gen_movi_i32(REG(reg
), val
);
494 case 0x1c: /* ld.b (register indirect) */
496 int src
= opcode
& 0xf;
497 int dest
= (opcode
>> 4) & 0xf;
499 tcg_gen_qemu_ld8u(REG(dest
), REG(src
), ctx
->memidx
);
502 case 0x1d: /* lda.b */
504 int reg
= (opcode
>> 4) & 0xf;
506 TCGv ptr
= tcg_temp_new_i32();
507 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
508 tcg_gen_qemu_ld8u(REG(reg
), ptr
, ctx
->memidx
);
509 tcg_temp_free_i32(ptr
);
514 case 0x1e: /* st.b */
516 int dest
= (opcode
>> 4) & 0xf;
517 int val
= opcode
& 0xf;
519 tcg_gen_qemu_st8(REG(val
), REG(dest
), ctx
->memidx
);
522 case 0x1f: /* sta.b */
524 int val
= (opcode
>> 4) & 0xf;
526 TCGv ptr
= tcg_temp_new_i32();
527 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
528 tcg_gen_qemu_st8(REG(val
), ptr
, ctx
->memidx
);
529 tcg_temp_free_i32(ptr
);
534 case 0x20: /* ldi.s (immediate) */
536 int reg
= (opcode
>> 4) & 0xf;
537 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
538 tcg_gen_movi_i32(REG(reg
), val
);
542 case 0x21: /* ld.s (register indirect) */
544 int src
= opcode
& 0xf;
545 int dest
= (opcode
>> 4) & 0xf;
547 tcg_gen_qemu_ld16u(REG(dest
), REG(src
), ctx
->memidx
);
550 case 0x22: /* lda.s */
552 int reg
= (opcode
>> 4) & 0xf;
554 TCGv ptr
= tcg_temp_new_i32();
555 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
556 tcg_gen_qemu_ld16u(REG(reg
), ptr
, ctx
->memidx
);
557 tcg_temp_free_i32(ptr
);
562 case 0x23: /* st.s */
564 int dest
= (opcode
>> 4) & 0xf;
565 int val
= opcode
& 0xf;
567 tcg_gen_qemu_st16(REG(val
), REG(dest
), ctx
->memidx
);
570 case 0x24: /* sta.s */
572 int val
= (opcode
>> 4) & 0xf;
574 TCGv ptr
= tcg_temp_new_i32();
575 tcg_gen_movi_i32(ptr
, cpu_ldl_code(env
, ctx
->pc
+2));
576 tcg_gen_qemu_st16(REG(val
), ptr
, ctx
->memidx
);
577 tcg_temp_free_i32(ptr
);
584 int reg
= (opcode
>> 4) & 0xf;
585 tcg_gen_mov_i32(cpu_pc
, REG(reg
));
587 ctx
->bstate
= BS_BRANCH
;
592 int a
= (opcode
>> 4) & 0xf;
593 int b
= opcode
& 0xf;
595 tcg_gen_and_i32(REG(a
), REG(a
), REG(b
));
598 case 0x27: /* lshr */
600 int a
= (opcode
>> 4) & 0xf;
601 int b
= opcode
& 0xf;
603 TCGv sv
= tcg_temp_new_i32();
604 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
605 tcg_gen_shr_i32(REG(a
), REG(a
), sv
);
606 tcg_temp_free_i32(sv
);
609 case 0x28: /* ashl */
611 int a
= (opcode
>> 4) & 0xf;
612 int b
= opcode
& 0xf;
614 TCGv sv
= tcg_temp_new_i32();
615 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
616 tcg_gen_shl_i32(REG(a
), REG(a
), sv
);
617 tcg_temp_free_i32(sv
);
620 case 0x29: /* sub.l */
622 int a
= (opcode
>> 4) & 0xf;
623 int b
= opcode
& 0xf;
625 tcg_gen_sub_i32(REG(a
), REG(a
), REG(b
));
630 int a
= (opcode
>> 4) & 0xf;
631 int b
= opcode
& 0xf;
633 tcg_gen_neg_i32(REG(a
), REG(b
));
638 int a
= (opcode
>> 4) & 0xf;
639 int b
= opcode
& 0xf;
641 tcg_gen_or_i32(REG(a
), REG(a
), REG(b
));
646 int a
= (opcode
>> 4) & 0xf;
647 int b
= opcode
& 0xf;
649 tcg_gen_not_i32(REG(a
), REG(b
));
652 case 0x2d: /* ashr */
654 int a
= (opcode
>> 4) & 0xf;
655 int b
= opcode
& 0xf;
657 TCGv sv
= tcg_temp_new_i32();
658 tcg_gen_andi_i32(sv
, REG(b
), 0x1f);
659 tcg_gen_sar_i32(REG(a
), REG(a
), sv
);
660 tcg_temp_free_i32(sv
);
665 int a
= (opcode
>> 4) & 0xf;
666 int b
= opcode
& 0xf;
668 tcg_gen_xor_i32(REG(a
), REG(a
), REG(b
));
671 case 0x2f: /* mul.l */
673 int a
= (opcode
>> 4) & 0xf;
674 int b
= opcode
& 0xf;
676 tcg_gen_mul_i32(REG(a
), REG(a
), REG(b
));
681 int val
= cpu_ldl_code(env
, ctx
->pc
+2);
683 TCGv temp
= tcg_temp_new_i32();
684 tcg_gen_movi_i32(temp
, val
);
685 tcg_gen_st_i32(temp
, cpu_env
,
686 offsetof(CPUMoxieState
, sregs
[3]));
687 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
688 tcg_gen_movi_i32(temp
, MOXIE_EX_SWI
);
689 gen_helper_raise_exception(cpu_env
, temp
);
690 tcg_temp_free_i32(temp
);
695 case 0x31: /* div.l */
697 int a
= (opcode
>> 4) & 0xf;
698 int b
= opcode
& 0xf;
699 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
700 gen_helper_div(REG(a
), cpu_env
, REG(a
), REG(b
));
703 case 0x32: /* udiv.l */
705 int a
= (opcode
>> 4) & 0xf;
706 int b
= opcode
& 0xf;
707 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
708 gen_helper_udiv(REG(a
), cpu_env
, REG(a
), REG(b
));
711 case 0x33: /* mod.l */
713 int a
= (opcode
>> 4) & 0xf;
714 int b
= opcode
& 0xf;
715 tcg_gen_rem_i32(REG(a
), REG(a
), REG(b
));
718 case 0x34: /* umod.l */
720 int a
= (opcode
>> 4) & 0xf;
721 int b
= opcode
& 0xf;
722 tcg_gen_remu_i32(REG(a
), REG(a
), REG(b
));
727 TCGv temp
= tcg_temp_new_i32();
728 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
729 tcg_gen_movi_i32(temp
, MOXIE_EX_BREAK
);
730 gen_helper_raise_exception(cpu_env
, temp
);
731 tcg_temp_free_i32(temp
);
734 case 0x36: /* ldo.b */
736 int a
= (opcode
>> 4) & 0xf;
737 int b
= opcode
& 0xf;
739 TCGv t1
= tcg_temp_new_i32();
740 TCGv t2
= tcg_temp_new_i32();
741 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
742 tcg_gen_qemu_ld8u(t2
, t1
, ctx
->memidx
);
743 tcg_gen_mov_i32(REG(a
), t2
);
745 tcg_temp_free_i32(t1
);
746 tcg_temp_free_i32(t2
);
751 case 0x37: /* sto.b */
753 int a
= (opcode
>> 4) & 0xf;
754 int b
= opcode
& 0xf;
756 TCGv t1
= tcg_temp_new_i32();
757 TCGv t2
= tcg_temp_new_i32();
758 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
759 tcg_gen_qemu_st8(REG(b
), t1
, ctx
->memidx
);
761 tcg_temp_free_i32(t1
);
762 tcg_temp_free_i32(t2
);
767 case 0x38: /* ldo.s */
769 int a
= (opcode
>> 4) & 0xf;
770 int b
= opcode
& 0xf;
772 TCGv t1
= tcg_temp_new_i32();
773 TCGv t2
= tcg_temp_new_i32();
774 tcg_gen_addi_i32(t1
, REG(b
), cpu_ldl_code(env
, ctx
->pc
+2));
775 tcg_gen_qemu_ld16u(t2
, t1
, ctx
->memidx
);
776 tcg_gen_mov_i32(REG(a
), t2
);
778 tcg_temp_free_i32(t1
);
779 tcg_temp_free_i32(t2
);
784 case 0x39: /* sto.s */
786 int a
= (opcode
>> 4) & 0xf;
787 int b
= opcode
& 0xf;
789 TCGv t1
= tcg_temp_new_i32();
790 TCGv t2
= tcg_temp_new_i32();
791 tcg_gen_addi_i32(t1
, REG(a
), cpu_ldl_code(env
, ctx
->pc
+2));
792 tcg_gen_qemu_st16(REG(b
), t1
, ctx
->memidx
);
793 tcg_temp_free_i32(t1
);
794 tcg_temp_free_i32(t2
);
801 TCGv temp
= tcg_temp_new_i32();
802 tcg_gen_movi_i32(cpu_pc
, ctx
->pc
);
803 tcg_gen_movi_i32(temp
, MOXIE_EX_BAD
);
804 gen_helper_raise_exception(cpu_env
, temp
);
805 tcg_temp_free_i32(temp
);
814 /* generate intermediate code for basic block 'tb'. */
815 void gen_intermediate_code(CPUMoxieState
*env
, struct TranslationBlock
*tb
)
817 MoxieCPU
*cpu
= moxie_env_get_cpu(env
);
818 CPUState
*cs
= CPU(cpu
);
820 target_ulong pc_start
;
821 int num_insns
, max_insns
;
828 ctx
.singlestep_enabled
= 0;
829 ctx
.bstate
= BS_NONE
;
831 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
832 if (max_insns
== 0) {
833 max_insns
= CF_COUNT_MASK
;
835 if (max_insns
> TCG_MAX_INSNS
) {
836 max_insns
= TCG_MAX_INSNS
;
841 tcg_gen_insn_start(ctx
.pc
);
844 if (unlikely(cpu_breakpoint_test(cs
, ctx
.pc
, BP_ANY
))) {
845 tcg_gen_movi_i32(cpu_pc
, ctx
.pc
);
846 gen_helper_debug(cpu_env
);
847 ctx
.bstate
= BS_EXCP
;
848 /* The address covered by the breakpoint must be included in
849 [tb->pc, tb->pc + tb->size) in order to for it to be
850 properly cleared -- thus we increment the PC here so that
851 the logic setting tb->size below does the right thing. */
853 goto done_generating
;
856 ctx
.opcode
= cpu_lduw_code(env
, ctx
.pc
);
857 ctx
.pc
+= decode_opc(cpu
, &ctx
);
859 if (num_insns
>= max_insns
) {
862 if (cs
->singlestep_enabled
) {
865 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) {
868 } while (ctx
.bstate
== BS_NONE
&& !tcg_op_buf_full());
870 if (cs
->singlestep_enabled
) {
871 tcg_gen_movi_tl(cpu_pc
, ctx
.pc
);
872 gen_helper_debug(cpu_env
);
874 switch (ctx
.bstate
) {
877 gen_goto_tb(env
, &ctx
, 0, ctx
.pc
);
888 gen_tb_end(tb
, num_insns
);
890 tb
->size
= ctx
.pc
- pc_start
;
891 tb
->icount
= num_insns
;
894 void restore_state_to_opc(CPUMoxieState
*env
, TranslationBlock
*tb
,