2 * Alpha emulation cpu translation for qemu.
4 * Copyright (c) 2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but 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 Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define DO_SINGLE_STEP
32 #define ALPHA_DEBUG_DISAS
35 typedef struct DisasContext DisasContext
;
39 #if !defined (CONFIG_USER_ONLY)
45 static always_inline
void gen_op_nop (void)
47 #if defined(GENERATE_NOP)
52 #define GEN32(func, NAME) \
53 static GenOpFunc *NAME ## _table [32] = { \
54 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
55 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
56 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
57 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
58 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
59 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
60 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
61 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
63 static always_inline void func (int n) \
65 NAME ## _table[n](); \
69 /* Special hacks for ir31 */
70 #define gen_op_load_T0_ir31 gen_op_reset_T0
71 #define gen_op_load_T1_ir31 gen_op_reset_T1
72 #define gen_op_load_T2_ir31 gen_op_reset_T2
73 #define gen_op_store_T0_ir31 gen_op_nop
74 #define gen_op_store_T1_ir31 gen_op_nop
75 #define gen_op_store_T2_ir31 gen_op_nop
76 #define gen_op_cmov_ir31 gen_op_nop
77 GEN32(gen_op_load_T0_ir
, gen_op_load_T0_ir
);
78 GEN32(gen_op_load_T1_ir
, gen_op_load_T1_ir
);
79 GEN32(gen_op_load_T2_ir
, gen_op_load_T2_ir
);
80 GEN32(gen_op_store_T0_ir
, gen_op_store_T0_ir
);
81 GEN32(gen_op_store_T1_ir
, gen_op_store_T1_ir
);
82 GEN32(gen_op_store_T2_ir
, gen_op_store_T2_ir
);
83 GEN32(gen_op_cmov_ir
, gen_op_cmov_ir
);
85 static always_inline
void gen_load_ir (DisasContext
*ctx
, int irn
, int Tn
)
89 gen_op_load_T0_ir(irn
);
92 gen_op_load_T1_ir(irn
);
95 gen_op_load_T2_ir(irn
);
100 static always_inline
void gen_store_ir (DisasContext
*ctx
, int irn
, int Tn
)
104 gen_op_store_T0_ir(irn
);
107 gen_op_store_T1_ir(irn
);
110 gen_op_store_T2_ir(irn
);
116 /* Special hacks for fir31 */
117 #define gen_op_load_FT0_fir31 gen_op_reset_FT0
118 #define gen_op_load_FT1_fir31 gen_op_reset_FT1
119 #define gen_op_load_FT2_fir31 gen_op_reset_FT2
120 #define gen_op_store_FT0_fir31 gen_op_nop
121 #define gen_op_store_FT1_fir31 gen_op_nop
122 #define gen_op_store_FT2_fir31 gen_op_nop
123 #define gen_op_cmov_fir31 gen_op_nop
124 GEN32(gen_op_load_FT0_fir
, gen_op_load_FT0_fir
);
125 GEN32(gen_op_load_FT1_fir
, gen_op_load_FT1_fir
);
126 GEN32(gen_op_load_FT2_fir
, gen_op_load_FT2_fir
);
127 GEN32(gen_op_store_FT0_fir
, gen_op_store_FT0_fir
);
128 GEN32(gen_op_store_FT1_fir
, gen_op_store_FT1_fir
);
129 GEN32(gen_op_store_FT2_fir
, gen_op_store_FT2_fir
);
130 GEN32(gen_op_cmov_fir
, gen_op_cmov_fir
);
132 static always_inline
void gen_load_fir (DisasContext
*ctx
, int firn
, int Tn
)
136 gen_op_load_FT0_fir(firn
);
139 gen_op_load_FT1_fir(firn
);
142 gen_op_load_FT2_fir(firn
);
147 static always_inline
void gen_store_fir (DisasContext
*ctx
, int firn
, int Tn
)
151 gen_op_store_FT0_fir(firn
);
154 gen_op_store_FT1_fir(firn
);
157 gen_op_store_FT2_fir(firn
);
163 #if defined(CONFIG_USER_ONLY)
164 #define OP_LD_TABLE(width) \
165 static GenOpFunc *gen_op_ld##width[] = { \
166 &gen_op_ld##width##_raw, \
168 #define OP_ST_TABLE(width) \
169 static GenOpFunc *gen_op_st##width[] = { \
170 &gen_op_st##width##_raw, \
173 #define OP_LD_TABLE(width) \
174 static GenOpFunc *gen_op_ld##width[] = { \
175 &gen_op_ld##width##_kernel, \
176 &gen_op_ld##width##_executive, \
177 &gen_op_ld##width##_supervisor, \
178 &gen_op_ld##width##_user, \
180 #define OP_ST_TABLE(width) \
181 static GenOpFunc *gen_op_st##width[] = { \
182 &gen_op_st##width##_kernel, \
183 &gen_op_st##width##_executive, \
184 &gen_op_st##width##_supervisor, \
185 &gen_op_st##width##_user, \
189 #define GEN_LD(width) \
190 OP_LD_TABLE(width); \
191 static always_inline void gen_ld##width (DisasContext *ctx) \
193 (*gen_op_ld##width[ctx->mem_idx])(); \
196 #define GEN_ST(width) \
197 OP_ST_TABLE(width); \
198 static always_inline void gen_st##width (DisasContext *ctx) \
200 (*gen_op_st##width[ctx->mem_idx])(); \
218 #if 0 /* currently unused */
229 #if defined(__i386__) || defined(__x86_64__)
230 static always_inline
void gen_op_set_s16_T0 (int16_t imm
)
232 gen_op_set_s32_T0((int32_t)imm
);
235 static always_inline
void gen_op_set_s16_T1 (int16_t imm
)
237 gen_op_set_s32_T1((int32_t)imm
);
240 static always_inline
void gen_op_set_u16_T0 (uint16_t imm
)
242 gen_op_set_s32_T0((uint32_t)imm
);
245 static always_inline
void gen_op_set_u16_T1 (uint16_t imm
)
247 gen_op_set_s32_T1((uint32_t)imm
);
251 static always_inline
void gen_set_sT0 (DisasContext
*ctx
, int64_t imm
)
263 gen_op_set_s16_T0(imm16
);
266 gen_op_set_s32_T0(imm32
);
269 #if 0 // Qemu does not know how to do this...
270 gen_op_set_64_T0(imm
);
272 gen_op_set_64_T0(imm
>> 32, imm
);
277 static always_inline
void gen_set_sT1 (DisasContext
*ctx
, int64_t imm
)
289 gen_op_set_s16_T1(imm16
);
292 gen_op_set_s32_T1(imm32
);
295 #if 0 // Qemu does not know how to do this...
296 gen_op_set_64_T1(imm
);
298 gen_op_set_64_T1(imm
>> 32, imm
);
303 static always_inline
void gen_set_uT0 (DisasContext
*ctx
, uint64_t imm
)
310 gen_op_set_u16_T0(imm
);
312 gen_op_set_u32_T0(imm
);
315 #if 0 // Qemu does not know how to do this...
316 gen_op_set_64_T0(imm
);
318 gen_op_set_64_T0(imm
>> 32, imm
);
323 static always_inline
void gen_set_uT1 (DisasContext
*ctx
, uint64_t imm
)
330 gen_op_set_u16_T1(imm
);
332 gen_op_set_u32_T1(imm
);
335 #if 0 // Qemu does not know how to do this...
336 gen_op_set_64_T1(imm
);
338 gen_op_set_64_T1(imm
>> 32, imm
);
343 static always_inline
void gen_update_pc (DisasContext
*ctx
)
345 if (!(ctx
->pc
>> 32)) {
346 gen_op_update_pc32(ctx
->pc
);
348 #if 0 // Qemu does not know how to do this...
349 gen_op_update_pc(ctx
->pc
);
351 gen_op_update_pc(ctx
->pc
>> 32, ctx
->pc
);
356 static always_inline
void _gen_op_bcond (DisasContext
*ctx
)
358 #if 0 // Qemu does not know how to do this...
359 gen_op_bcond(ctx
->pc
);
361 gen_op_bcond(ctx
->pc
>> 32, ctx
->pc
);
365 static always_inline
void gen_excp (DisasContext
*ctx
,
366 int exception
, int error_code
)
369 gen_op_excp(exception
, error_code
);
372 static always_inline
void gen_invalid (DisasContext
*ctx
)
374 gen_excp(ctx
, EXCP_OPCDEC
, 0);
377 static always_inline
void gen_load_mem (DisasContext
*ctx
,
378 void (*gen_load_op
)(DisasContext
*ctx
),
379 int ra
, int rb
, int32_t disp16
,
382 if (ra
== 31 && disp16
== 0) {
386 gen_load_ir(ctx
, rb
, 0);
388 gen_set_sT1(ctx
, disp16
);
394 gen_store_ir(ctx
, ra
, 1);
398 static always_inline
void gen_store_mem (DisasContext
*ctx
,
399 void (*gen_store_op
)(DisasContext
*ctx
),
400 int ra
, int rb
, int32_t disp16
,
403 gen_load_ir(ctx
, rb
, 0);
405 gen_set_sT1(ctx
, disp16
);
410 gen_load_ir(ctx
, ra
, 1);
411 (*gen_store_op
)(ctx
);
414 static always_inline
void gen_load_fmem (DisasContext
*ctx
,
415 void (*gen_load_fop
)(DisasContext
*ctx
),
416 int ra
, int rb
, int32_t disp16
)
418 gen_load_ir(ctx
, rb
, 0);
420 gen_set_sT1(ctx
, disp16
);
423 (*gen_load_fop
)(ctx
);
424 gen_store_fir(ctx
, ra
, 1);
427 static always_inline
void gen_store_fmem (DisasContext
*ctx
,
428 void (*gen_store_fop
)(DisasContext
*ctx
),
429 int ra
, int rb
, int32_t disp16
)
431 gen_load_ir(ctx
, rb
, 0);
433 gen_set_sT1(ctx
, disp16
);
436 gen_load_fir(ctx
, ra
, 1);
437 (*gen_store_fop
)(ctx
);
440 static always_inline
void gen_bcond (DisasContext
*ctx
,
441 void (*gen_test_op
)(void),
442 int ra
, int32_t disp16
)
445 gen_set_uT0(ctx
, ctx
->pc
);
446 gen_set_sT1(ctx
, disp16
<< 2);
449 gen_set_uT1(ctx
, ctx
->pc
);
451 gen_load_ir(ctx
, ra
, 0);
456 static always_inline
void gen_fbcond (DisasContext
*ctx
,
457 void (*gen_test_op
)(void),
458 int ra
, int32_t disp16
)
461 gen_set_uT0(ctx
, ctx
->pc
);
462 gen_set_sT1(ctx
, disp16
<< 2);
465 gen_set_uT1(ctx
, ctx
->pc
);
467 gen_load_fir(ctx
, ra
, 0);
472 static always_inline
void gen_arith2 (DisasContext
*ctx
,
473 void (*gen_arith_op
)(void),
474 int rb
, int rc
, int islit
, int8_t lit
)
477 gen_set_sT0(ctx
, lit
);
479 gen_load_ir(ctx
, rb
, 0);
481 gen_store_ir(ctx
, rc
, 0);
484 static always_inline
void gen_arith3 (DisasContext
*ctx
,
485 void (*gen_arith_op
)(void),
486 int ra
, int rb
, int rc
,
487 int islit
, int8_t lit
)
489 gen_load_ir(ctx
, ra
, 0);
491 gen_set_sT1(ctx
, lit
);
493 gen_load_ir(ctx
, rb
, 1);
495 gen_store_ir(ctx
, rc
, 0);
498 static always_inline
void gen_cmov (DisasContext
*ctx
,
499 void (*gen_test_op
)(void),
500 int ra
, int rb
, int rc
,
501 int islit
, int8_t lit
)
503 gen_load_ir(ctx
, ra
, 1);
505 gen_set_sT0(ctx
, lit
);
507 gen_load_ir(ctx
, rb
, 0);
512 static always_inline
void gen_farith2 (DisasContext
*ctx
,
513 void (*gen_arith_fop
)(void),
516 gen_load_fir(ctx
, rb
, 0);
518 gen_store_fir(ctx
, rc
, 0);
521 static always_inline
void gen_farith3 (DisasContext
*ctx
,
522 void (*gen_arith_fop
)(void),
523 int ra
, int rb
, int rc
)
525 gen_load_fir(ctx
, ra
, 0);
526 gen_load_fir(ctx
, rb
, 1);
528 gen_store_fir(ctx
, rc
, 0);
531 static always_inline
void gen_fcmov (DisasContext
*ctx
,
532 void (*gen_test_fop
)(void),
533 int ra
, int rb
, int rc
)
535 gen_load_fir(ctx
, ra
, 0);
536 gen_load_fir(ctx
, rb
, 1);
541 static always_inline
void gen_fti (DisasContext
*ctx
,
542 void (*gen_move_fop
)(void),
545 gen_load_fir(ctx
, rc
, 0);
547 gen_store_ir(ctx
, ra
, 0);
550 static always_inline
void gen_itf (DisasContext
*ctx
,
551 void (*gen_move_fop
)(void),
554 gen_load_ir(ctx
, ra
, 0);
556 gen_store_fir(ctx
, rc
, 0);
559 static always_inline
void gen_s4addl (void)
565 static always_inline
void gen_s4subl (void)
571 static always_inline
void gen_s8addl (void)
577 static always_inline
void gen_s8subl (void)
583 static always_inline
void gen_s4addq (void)
589 static always_inline
void gen_s4subq (void)
595 static always_inline
void gen_s8addq (void)
601 static always_inline
void gen_s8subq (void)
607 static always_inline
void gen_amask (void)
613 static always_inline
int translate_one (DisasContext
*ctx
, uint32_t insn
)
616 int32_t disp21
, disp16
, disp12
;
618 uint8_t opc
, ra
, rb
, rc
, sbz
, fpfn
, fn7
, fn2
, islit
;
622 /* Decode all instruction fields */
624 ra
= (insn
>> 21) & 0x1F;
625 rb
= (insn
>> 16) & 0x1F;
627 sbz
= (insn
>> 13) & 0x07;
628 islit
= (insn
>> 12) & 1;
629 lit
= (insn
>> 13) & 0xFF;
630 palcode
= insn
& 0x03FFFFFF;
631 disp21
= ((int32_t)((insn
& 0x001FFFFF) << 11)) >> 11;
632 disp16
= (int16_t)(insn
& 0x0000FFFF);
633 disp12
= (int32_t)((insn
& 0x00000FFF) << 20) >> 20;
634 fn16
= insn
& 0x0000FFFF;
635 fn11
= (insn
>> 5) & 0x000007FF;
637 fn7
= (insn
>> 5) & 0x0000007F;
638 fn2
= (insn
>> 5) & 0x00000003;
640 #if defined ALPHA_DEBUG_DISAS
641 if (logfile
!= NULL
) {
642 fprintf(logfile
, "opc %02x ra %d rb %d rc %d disp16 %04x\n",
643 opc
, ra
, rb
, rc
, disp16
);
649 if (palcode
>= 0x80 && palcode
< 0xC0) {
650 /* Unprivileged PAL call */
651 gen_excp(ctx
, EXCP_CALL_PAL
+ ((palcode
& 0x1F) << 6), 0);
652 #if !defined (CONFIG_USER_ONLY)
653 } else if (palcode
< 0x40) {
654 /* Privileged PAL code */
655 if (ctx
->mem_idx
& 1)
658 gen_excp(ctx
, EXCP_CALL_PALP
+ ((palcode
& 0x1F) << 6), 0);
661 /* Invalid PAL call */
689 gen_load_ir(ctx
, rb
, 0);
690 gen_set_sT1(ctx
, disp16
);
692 gen_store_ir(ctx
, ra
, 0);
696 gen_load_ir(ctx
, rb
, 0);
697 gen_set_sT1(ctx
, disp16
<< 16);
699 gen_store_ir(ctx
, ra
, 0);
703 if (!(ctx
->amask
& AMASK_BWX
))
705 gen_load_mem(ctx
, &gen_ldbu
, ra
, rb
, disp16
, 0);
709 gen_load_mem(ctx
, &gen_ldq_u
, ra
, rb
, disp16
, 1);
713 if (!(ctx
->amask
& AMASK_BWX
))
715 gen_load_mem(ctx
, &gen_ldwu
, ra
, rb
, disp16
, 0);
719 if (!(ctx
->amask
& AMASK_BWX
))
721 gen_store_mem(ctx
, &gen_stw
, ra
, rb
, disp16
, 0);
725 if (!(ctx
->amask
& AMASK_BWX
))
727 gen_store_mem(ctx
, &gen_stb
, ra
, rb
, disp16
, 0);
731 gen_store_mem(ctx
, &gen_stq_u
, ra
, rb
, disp16
, 1);
737 gen_arith3(ctx
, &gen_op_addl
, ra
, rb
, rc
, islit
, lit
);
741 gen_arith3(ctx
, &gen_s4addl
, ra
, rb
, rc
, islit
, lit
);
745 gen_arith3(ctx
, &gen_op_subl
, ra
, rb
, rc
, islit
, lit
);
749 gen_arith3(ctx
, &gen_s4subl
, ra
, rb
, rc
, islit
, lit
);
753 gen_arith3(ctx
, &gen_op_cmpbge
, ra
, rb
, rc
, islit
, lit
);
757 gen_arith3(ctx
, &gen_s8addl
, ra
, rb
, rc
, islit
, lit
);
761 gen_arith3(ctx
, &gen_s8subl
, ra
, rb
, rc
, islit
, lit
);
765 gen_arith3(ctx
, &gen_op_cmpult
, ra
, rb
, rc
, islit
, lit
);
769 gen_arith3(ctx
, &gen_op_addq
, ra
, rb
, rc
, islit
, lit
);
773 gen_arith3(ctx
, &gen_s4addq
, ra
, rb
, rc
, islit
, lit
);
777 gen_arith3(ctx
, &gen_op_subq
, ra
, rb
, rc
, islit
, lit
);
781 gen_arith3(ctx
, &gen_s4subq
, ra
, rb
, rc
, islit
, lit
);
785 gen_arith3(ctx
, &gen_op_cmpeq
, ra
, rb
, rc
, islit
, lit
);
789 gen_arith3(ctx
, &gen_s8addq
, ra
, rb
, rc
, islit
, lit
);
793 gen_arith3(ctx
, &gen_s8subq
, ra
, rb
, rc
, islit
, lit
);
797 gen_arith3(ctx
, &gen_op_cmpule
, ra
, rb
, rc
, islit
, lit
);
801 gen_arith3(ctx
, &gen_op_addlv
, ra
, rb
, rc
, islit
, lit
);
805 gen_arith3(ctx
, &gen_op_sublv
, ra
, rb
, rc
, islit
, lit
);
809 gen_arith3(ctx
, &gen_op_cmplt
, ra
, rb
, rc
, islit
, lit
);
813 gen_arith3(ctx
, &gen_op_addqv
, ra
, rb
, rc
, islit
, lit
);
817 gen_arith3(ctx
, &gen_op_subqv
, ra
, rb
, rc
, islit
, lit
);
821 gen_arith3(ctx
, &gen_op_cmple
, ra
, rb
, rc
, islit
, lit
);
831 gen_arith3(ctx
, &gen_op_and
, ra
, rb
, rc
, islit
, lit
);
835 gen_arith3(ctx
, &gen_op_bic
, ra
, rb
, rc
, islit
, lit
);
839 gen_cmov(ctx
, &gen_op_cmplbs
, ra
, rb
, rc
, islit
, lit
);
843 gen_cmov(ctx
, &gen_op_cmplbc
, ra
, rb
, rc
, islit
, lit
);
847 if (ra
== rb
|| ra
== 31 || rb
== 31) {
848 if (ra
== 31 && rc
== 31) {
853 gen_load_ir(ctx
, rb
, 0);
854 gen_store_ir(ctx
, rc
, 0);
857 gen_arith3(ctx
, &gen_op_bis
, ra
, rb
, rc
, islit
, lit
);
862 gen_cmov(ctx
, &gen_op_cmpeqz
, ra
, rb
, rc
, islit
, lit
);
866 gen_cmov(ctx
, &gen_op_cmpnez
, ra
, rb
, rc
, islit
, lit
);
870 gen_arith3(ctx
, &gen_op_ornot
, ra
, rb
, rc
, islit
, lit
);
874 gen_arith3(ctx
, &gen_op_xor
, ra
, rb
, rc
, islit
, lit
);
878 gen_cmov(ctx
, &gen_op_cmpltz
, ra
, rb
, rc
, islit
, lit
);
882 gen_cmov(ctx
, &gen_op_cmpgez
, ra
, rb
, rc
, islit
, lit
);
886 gen_arith3(ctx
, &gen_op_eqv
, ra
, rb
, rc
, islit
, lit
);
890 gen_arith2(ctx
, &gen_amask
, rb
, rc
, islit
, lit
);
894 gen_cmov(ctx
, &gen_op_cmplez
, ra
, rb
, rc
, islit
, lit
);
898 gen_cmov(ctx
, &gen_op_cmpgtz
, ra
, rb
, rc
, islit
, lit
);
902 gen_op_load_implver();
903 gen_store_ir(ctx
, rc
, 0);
913 gen_arith3(ctx
, &gen_op_mskbl
, ra
, rb
, rc
, islit
, lit
);
917 gen_arith3(ctx
, &gen_op_extbl
, ra
, rb
, rc
, islit
, lit
);
921 gen_arith3(ctx
, &gen_op_insbl
, ra
, rb
, rc
, islit
, lit
);
925 gen_arith3(ctx
, &gen_op_mskwl
, ra
, rb
, rc
, islit
, lit
);
929 gen_arith3(ctx
, &gen_op_extwl
, ra
, rb
, rc
, islit
, lit
);
933 gen_arith3(ctx
, &gen_op_inswl
, ra
, rb
, rc
, islit
, lit
);
937 gen_arith3(ctx
, &gen_op_mskll
, ra
, rb
, rc
, islit
, lit
);
941 gen_arith3(ctx
, &gen_op_extll
, ra
, rb
, rc
, islit
, lit
);
945 gen_arith3(ctx
, &gen_op_insll
, ra
, rb
, rc
, islit
, lit
);
949 gen_arith3(ctx
, &gen_op_zap
, ra
, rb
, rc
, islit
, lit
);
953 gen_arith3(ctx
, &gen_op_zapnot
, ra
, rb
, rc
, islit
, lit
);
957 gen_arith3(ctx
, &gen_op_mskql
, ra
, rb
, rc
, islit
, lit
);
961 gen_arith3(ctx
, &gen_op_srl
, ra
, rb
, rc
, islit
, lit
);
965 gen_arith3(ctx
, &gen_op_extql
, ra
, rb
, rc
, islit
, lit
);
969 gen_arith3(ctx
, &gen_op_sll
, ra
, rb
, rc
, islit
, lit
);
973 gen_arith3(ctx
, &gen_op_insql
, ra
, rb
, rc
, islit
, lit
);
977 gen_arith3(ctx
, &gen_op_sra
, ra
, rb
, rc
, islit
, lit
);
981 gen_arith3(ctx
, &gen_op_mskwh
, ra
, rb
, rc
, islit
, lit
);
985 gen_arith3(ctx
, &gen_op_inswh
, ra
, rb
, rc
, islit
, lit
);
989 gen_arith3(ctx
, &gen_op_extwh
, ra
, rb
, rc
, islit
, lit
);
993 gen_arith3(ctx
, &gen_op_msklh
, ra
, rb
, rc
, islit
, lit
);
997 gen_arith3(ctx
, &gen_op_inslh
, ra
, rb
, rc
, islit
, lit
);
1001 gen_arith3(ctx
, &gen_op_extlh
, ra
, rb
, rc
, islit
, lit
);
1005 gen_arith3(ctx
, &gen_op_mskqh
, ra
, rb
, rc
, islit
, lit
);
1009 gen_arith3(ctx
, &gen_op_insqh
, ra
, rb
, rc
, islit
, lit
);
1013 gen_arith3(ctx
, &gen_op_extqh
, ra
, rb
, rc
, islit
, lit
);
1023 gen_arith3(ctx
, &gen_op_mull
, ra
, rb
, rc
, islit
, lit
);
1027 gen_arith3(ctx
, &gen_op_mulq
, ra
, rb
, rc
, islit
, lit
);
1031 gen_arith3(ctx
, &gen_op_umulh
, ra
, rb
, rc
, islit
, lit
);
1035 gen_arith3(ctx
, &gen_op_mullv
, ra
, rb
, rc
, islit
, lit
);
1039 gen_arith3(ctx
, &gen_op_mulqv
, ra
, rb
, rc
, islit
, lit
);
1046 switch (fpfn
) { /* f11 & 0x3F */
1049 if (!(ctx
->amask
& AMASK_FIX
))
1051 gen_itf(ctx
, &gen_op_itofs
, ra
, rc
);
1055 if (!(ctx
->amask
& AMASK_FIX
))
1057 gen_farith2(ctx
, &gen_op_sqrtf
, rb
, rc
);
1061 if (!(ctx
->amask
& AMASK_FIX
))
1063 gen_farith2(ctx
, &gen_op_sqrts
, rb
, rc
);
1067 if (!(ctx
->amask
& AMASK_FIX
))
1070 gen_itf(ctx
, &gen_op_itoff
, ra
, rc
);
1077 if (!(ctx
->amask
& AMASK_FIX
))
1079 gen_itf(ctx
, &gen_op_itoft
, ra
, rc
);
1083 if (!(ctx
->amask
& AMASK_FIX
))
1085 gen_farith2(ctx
, &gen_op_sqrtg
, rb
, rc
);
1089 if (!(ctx
->amask
& AMASK_FIX
))
1091 gen_farith2(ctx
, &gen_op_sqrtt
, rb
, rc
);
1098 /* VAX floating point */
1099 /* XXX: rounding mode and trap are ignored (!) */
1100 switch (fpfn
) { /* f11 & 0x3F */
1103 gen_farith3(ctx
, &gen_op_addf
, ra
, rb
, rc
);
1107 gen_farith3(ctx
, &gen_op_subf
, ra
, rb
, rc
);
1111 gen_farith3(ctx
, &gen_op_mulf
, ra
, rb
, rc
);
1115 gen_farith3(ctx
, &gen_op_divf
, ra
, rb
, rc
);
1120 gen_farith2(ctx
, &gen_op_cvtdg
, rb
, rc
);
1127 gen_farith3(ctx
, &gen_op_addg
, ra
, rb
, rc
);
1131 gen_farith3(ctx
, &gen_op_subg
, ra
, rb
, rc
);
1135 gen_farith3(ctx
, &gen_op_mulg
, ra
, rb
, rc
);
1139 gen_farith3(ctx
, &gen_op_divg
, ra
, rb
, rc
);
1143 gen_farith3(ctx
, &gen_op_cmpgeq
, ra
, rb
, rc
);
1147 gen_farith3(ctx
, &gen_op_cmpglt
, ra
, rb
, rc
);
1151 gen_farith3(ctx
, &gen_op_cmpgle
, ra
, rb
, rc
);
1155 gen_farith2(ctx
, &gen_op_cvtgf
, rb
, rc
);
1160 gen_farith2(ctx
, &gen_op_cvtgd
, rb
, rc
);
1167 gen_farith2(ctx
, &gen_op_cvtgq
, rb
, rc
);
1171 gen_farith2(ctx
, &gen_op_cvtqf
, rb
, rc
);
1175 gen_farith2(ctx
, &gen_op_cvtqg
, rb
, rc
);
1182 /* IEEE floating-point */
1183 /* XXX: rounding mode and traps are ignored (!) */
1184 switch (fpfn
) { /* f11 & 0x3F */
1187 gen_farith3(ctx
, &gen_op_adds
, ra
, rb
, rc
);
1191 gen_farith3(ctx
, &gen_op_subs
, ra
, rb
, rc
);
1195 gen_farith3(ctx
, &gen_op_muls
, ra
, rb
, rc
);
1199 gen_farith3(ctx
, &gen_op_divs
, ra
, rb
, rc
);
1203 gen_farith3(ctx
, &gen_op_addt
, ra
, rb
, rc
);
1207 gen_farith3(ctx
, &gen_op_subt
, ra
, rb
, rc
);
1211 gen_farith3(ctx
, &gen_op_mult
, ra
, rb
, rc
);
1215 gen_farith3(ctx
, &gen_op_divt
, ra
, rb
, rc
);
1219 gen_farith3(ctx
, &gen_op_cmptun
, ra
, rb
, rc
);
1223 gen_farith3(ctx
, &gen_op_cmpteq
, ra
, rb
, rc
);
1227 gen_farith3(ctx
, &gen_op_cmptlt
, ra
, rb
, rc
);
1231 gen_farith3(ctx
, &gen_op_cmptle
, ra
, rb
, rc
);
1234 /* XXX: incorrect */
1235 if (fn11
== 0x2AC) {
1237 gen_farith2(ctx
, &gen_op_cvtst
, rb
, rc
);
1240 gen_farith2(ctx
, &gen_op_cvtts
, rb
, rc
);
1245 gen_farith2(ctx
, &gen_op_cvttq
, rb
, rc
);
1249 gen_farith2(ctx
, &gen_op_cvtqs
, rb
, rc
);
1253 gen_farith2(ctx
, &gen_op_cvtqt
, rb
, rc
);
1263 gen_farith2(ctx
, &gen_op_cvtlq
, rb
, rc
);
1268 if (ra
== 31 && rc
== 31) {
1273 gen_load_fir(ctx
, rb
, 0);
1274 gen_store_fir(ctx
, rc
, 0);
1277 gen_farith3(ctx
, &gen_op_cpys
, ra
, rb
, rc
);
1282 gen_farith2(ctx
, &gen_op_cpysn
, rb
, rc
);
1286 gen_farith2(ctx
, &gen_op_cpyse
, rb
, rc
);
1290 gen_load_fir(ctx
, ra
, 0);
1291 gen_op_store_fpcr();
1296 gen_store_fir(ctx
, ra
, 0);
1300 gen_fcmov(ctx
, &gen_op_cmpfeq
, ra
, rb
, rc
);
1304 gen_fcmov(ctx
, &gen_op_cmpfne
, ra
, rb
, rc
);
1308 gen_fcmov(ctx
, &gen_op_cmpflt
, ra
, rb
, rc
);
1312 gen_fcmov(ctx
, &gen_op_cmpfge
, ra
, rb
, rc
);
1316 gen_fcmov(ctx
, &gen_op_cmpfle
, ra
, rb
, rc
);
1320 gen_fcmov(ctx
, &gen_op_cmpfgt
, ra
, rb
, rc
);
1324 gen_farith2(ctx
, &gen_op_cvtql
, rb
, rc
);
1328 gen_farith2(ctx
, &gen_op_cvtqlv
, rb
, rc
);
1332 gen_farith2(ctx
, &gen_op_cvtqlsv
, rb
, rc
);
1339 switch ((uint16_t)disp16
) {
1342 /* No-op. Just exit from the current tb */
1347 /* No-op. Just exit from the current tb */
1369 gen_store_ir(ctx
, ra
, 0);
1374 gen_store_ir(ctx
, ra
, 0);
1379 /* XXX: TODO: evict tb cache at address rb */
1389 gen_store_ir(ctx
, ra
, 0);
1401 /* HW_MFPR (PALcode) */
1402 #if defined (CONFIG_USER_ONLY)
1407 gen_op_mfpr(insn
& 0xFF);
1408 gen_store_ir(ctx
, ra
, 0);
1412 gen_load_ir(ctx
, rb
, 0);
1414 gen_set_uT1(ctx
, ctx
->pc
);
1415 gen_store_ir(ctx
, ra
, 1);
1418 /* Those four jumps only differ by the branch prediction hint */
1436 /* HW_LD (PALcode) */
1437 #if defined (CONFIG_USER_ONLY)
1442 gen_load_ir(ctx
, rb
, 0);
1443 gen_set_sT1(ctx
, disp12
);
1445 switch ((insn
>> 12) & 0xF) {
1447 /* Longword physical access */
1451 /* Quadword physical access */
1455 /* Longword physical access with lock */
1459 /* Quadword physical access with lock */
1463 /* Longword virtual PTE fetch */
1464 gen_op_ldl_kernel();
1467 /* Quadword virtual PTE fetch */
1468 gen_op_ldq_kernel();
1477 /* Longword virtual access */
1478 gen_op_ld_phys_to_virt();
1482 /* Quadword virtual access */
1483 gen_op_ld_phys_to_virt();
1487 /* Longword virtual access with protection check */
1491 /* Quadword virtual access with protection check */
1495 /* Longword virtual access with altenate access mode */
1496 gen_op_set_alt_mode();
1497 gen_op_ld_phys_to_virt();
1499 gen_op_restore_mode();
1502 /* Quadword virtual access with altenate access mode */
1503 gen_op_set_alt_mode();
1504 gen_op_ld_phys_to_virt();
1506 gen_op_restore_mode();
1509 /* Longword virtual access with alternate access mode and
1512 gen_op_set_alt_mode();
1514 gen_op_restore_mode();
1517 /* Quadword virtual access with alternate access mode and
1520 gen_op_set_alt_mode();
1522 gen_op_restore_mode();
1525 gen_store_ir(ctx
, ra
, 1);
1532 if (!(ctx
->amask
& AMASK_BWX
))
1534 gen_arith2(ctx
, &gen_op_sextb
, rb
, rc
, islit
, lit
);
1538 if (!(ctx
->amask
& AMASK_BWX
))
1540 gen_arith2(ctx
, &gen_op_sextw
, rb
, rc
, islit
, lit
);
1544 if (!(ctx
->amask
& AMASK_CIX
))
1546 gen_arith2(ctx
, &gen_op_ctpop
, rb
, rc
, 0, 0);
1550 if (!(ctx
->amask
& AMASK_MVI
))
1557 if (!(ctx
->amask
& AMASK_CIX
))
1559 gen_arith2(ctx
, &gen_op_ctlz
, rb
, rc
, 0, 0);
1563 if (!(ctx
->amask
& AMASK_CIX
))
1565 gen_arith2(ctx
, &gen_op_cttz
, rb
, rc
, 0, 0);
1569 if (!(ctx
->amask
& AMASK_MVI
))
1576 if (!(ctx
->amask
& AMASK_MVI
))
1583 if (!(ctx
->amask
& AMASK_MVI
))
1590 if (!(ctx
->amask
& AMASK_MVI
))
1597 if (!(ctx
->amask
& AMASK_MVI
))
1604 if (!(ctx
->amask
& AMASK_MVI
))
1611 if (!(ctx
->amask
& AMASK_MVI
))
1618 if (!(ctx
->amask
& AMASK_MVI
))
1625 if (!(ctx
->amask
& AMASK_MVI
))
1632 if (!(ctx
->amask
& AMASK_MVI
))
1639 if (!(ctx
->amask
& AMASK_MVI
))
1646 if (!(ctx
->amask
& AMASK_MVI
))
1653 if (!(ctx
->amask
& AMASK_FIX
))
1655 gen_fti(ctx
, &gen_op_ftoit
, ra
, rb
);
1659 if (!(ctx
->amask
& AMASK_FIX
))
1661 gen_fti(ctx
, &gen_op_ftois
, ra
, rb
);
1668 /* HW_MTPR (PALcode) */
1669 #if defined (CONFIG_USER_ONLY)
1674 gen_load_ir(ctx
, ra
, 0);
1675 gen_op_mtpr(insn
& 0xFF);
1680 /* HW_REI (PALcode) */
1681 #if defined (CONFIG_USER_ONLY)
1690 gen_load_ir(ctx
, rb
, 0);
1691 gen_set_uT1(ctx
, (((int64_t)insn
<< 51) >> 51));
1699 /* HW_ST (PALcode) */
1700 #if defined (CONFIG_USER_ONLY)
1705 gen_load_ir(ctx
, rb
, 0);
1706 gen_set_sT1(ctx
, disp12
);
1708 gen_load_ir(ctx
, ra
, 1);
1709 switch ((insn
>> 12) & 0xF) {
1711 /* Longword physical access */
1715 /* Quadword physical access */
1719 /* Longword physical access with lock */
1723 /* Quadword physical access with lock */
1727 /* Longword virtual access */
1728 gen_op_st_phys_to_virt();
1732 /* Quadword virtual access */
1733 gen_op_st_phys_to_virt();
1755 /* Longword virtual access with alternate access mode */
1756 gen_op_set_alt_mode();
1757 gen_op_st_phys_to_virt();
1759 gen_op_restore_mode();
1762 /* Quadword virtual access with alternate access mode */
1763 gen_op_set_alt_mode();
1764 gen_op_st_phys_to_virt();
1766 gen_op_restore_mode();
1781 gen_load_fmem(ctx
, &gen_ldf
, ra
, rb
, disp16
);
1789 gen_load_fmem(ctx
, &gen_ldg
, ra
, rb
, disp16
);
1796 gen_load_fmem(ctx
, &gen_lds
, ra
, rb
, disp16
);
1800 gen_load_fmem(ctx
, &gen_ldt
, ra
, rb
, disp16
);
1805 gen_store_fmem(ctx
, &gen_stf
, ra
, rb
, disp16
);
1813 gen_store_fmem(ctx
, &gen_stg
, ra
, rb
, disp16
);
1820 gen_store_fmem(ctx
, &gen_sts
, ra
, rb
, disp16
);
1824 gen_store_fmem(ctx
, &gen_stt
, ra
, rb
, disp16
);
1828 gen_load_mem(ctx
, &gen_ldl
, ra
, rb
, disp16
, 0);
1832 gen_load_mem(ctx
, &gen_ldq
, ra
, rb
, disp16
, 0);
1836 gen_load_mem(ctx
, &gen_ldl_l
, ra
, rb
, disp16
, 0);
1840 gen_load_mem(ctx
, &gen_ldq_l
, ra
, rb
, disp16
, 0);
1844 gen_store_mem(ctx
, &gen_stl
, ra
, rb
, disp16
, 0);
1848 gen_store_mem(ctx
, &gen_stq
, ra
, rb
, disp16
, 0);
1852 gen_store_mem(ctx
, &gen_stl_c
, ra
, rb
, disp16
, 0);
1856 gen_store_mem(ctx
, &gen_stq_c
, ra
, rb
, disp16
, 0);
1860 gen_set_uT0(ctx
, ctx
->pc
);
1861 gen_store_ir(ctx
, ra
, 0);
1863 gen_set_sT1(ctx
, disp21
<< 2);
1871 gen_fbcond(ctx
, &gen_op_cmpfeq
, ra
, disp16
);
1876 gen_fbcond(ctx
, &gen_op_cmpflt
, ra
, disp16
);
1881 gen_fbcond(ctx
, &gen_op_cmpfle
, ra
, disp16
);
1886 gen_set_uT0(ctx
, ctx
->pc
);
1887 gen_store_ir(ctx
, ra
, 0);
1889 gen_set_sT1(ctx
, disp21
<< 2);
1897 gen_fbcond(ctx
, &gen_op_cmpfne
, ra
, disp16
);
1902 gen_fbcond(ctx
, &gen_op_cmpfge
, ra
, disp16
);
1907 gen_fbcond(ctx
, &gen_op_cmpfgt
, ra
, disp16
);
1912 gen_bcond(ctx
, &gen_op_cmplbc
, ra
, disp16
);
1917 gen_bcond(ctx
, &gen_op_cmpeqz
, ra
, disp16
);
1922 gen_bcond(ctx
, &gen_op_cmpltz
, ra
, disp16
);
1927 gen_bcond(ctx
, &gen_op_cmplez
, ra
, disp16
);
1932 gen_bcond(ctx
, &gen_op_cmplbs
, ra
, disp16
);
1937 gen_bcond(ctx
, &gen_op_cmpnez
, ra
, disp16
);
1942 gen_bcond(ctx
, &gen_op_cmpgez
, ra
, disp16
);
1947 gen_bcond(ctx
, &gen_op_cmpgtz
, ra
, disp16
);
1959 static always_inline
int gen_intermediate_code_internal (CPUState
*env
,
1960 TranslationBlock
*tb
,
1963 #if defined ALPHA_DEBUG_DISAS
1964 static int insn_count
;
1966 DisasContext ctx
, *ctxp
= &ctx
;
1967 target_ulong pc_start
;
1969 uint16_t *gen_opc_end
;
1974 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
1976 ctx
.amask
= env
->amask
;
1977 #if defined (CONFIG_USER_ONLY)
1980 ctx
.mem_idx
= ((env
->ps
>> 3) & 3);
1981 ctx
.pal_mode
= env
->ipr
[IPR_EXC_ADDR
] & 1;
1983 for (ret
= 0; ret
== 0;) {
1984 if (env
->nb_breakpoints
> 0) {
1985 for(j
= 0; j
< env
->nb_breakpoints
; j
++) {
1986 if (env
->breakpoints
[j
] == ctx
.pc
) {
1987 gen_excp(&ctx
, EXCP_DEBUG
, 0);
1993 j
= gen_opc_ptr
- gen_opc_buf
;
1997 gen_opc_instr_start
[lj
++] = 0;
1998 gen_opc_pc
[lj
] = ctx
.pc
;
1999 gen_opc_instr_start
[lj
] = 1;
2002 #if defined ALPHA_DEBUG_DISAS
2004 if (logfile
!= NULL
) {
2005 fprintf(logfile
, "pc " TARGET_FMT_lx
" mem_idx %d\n",
2006 ctx
.pc
, ctx
.mem_idx
);
2009 insn
= ldl_code(ctx
.pc
);
2010 #if defined ALPHA_DEBUG_DISAS
2012 if (logfile
!= NULL
) {
2013 fprintf(logfile
, "opcode %08x %d\n", insn
, insn_count
);
2017 ret
= translate_one(ctxp
, insn
);
2020 /* if we reach a page boundary or are single stepping, stop
2023 if (((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
2024 (env
->singlestep_enabled
)) {
2027 #if defined (DO_SINGLE_STEP)
2031 if (ret
!= 1 && ret
!= 3) {
2032 gen_update_pc(&ctx
);
2034 #if defined (DO_TB_FLUSH)
2037 /* Generate the return instruction */
2039 *gen_opc_ptr
= INDEX_op_end
;
2041 j
= gen_opc_ptr
- gen_opc_buf
;
2044 gen_opc_instr_start
[lj
++] = 0;
2046 tb
->size
= ctx
.pc
- pc_start
;
2048 #if defined ALPHA_DEBUG_DISAS
2049 if (loglevel
& CPU_LOG_TB_CPU
) {
2050 cpu_dump_state(env
, logfile
, fprintf
, 0);
2052 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
2053 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
2054 target_disas(logfile
, pc_start
, ctx
.pc
- pc_start
, 1);
2055 fprintf(logfile
, "\n");
2062 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
2064 return gen_intermediate_code_internal(env
, tb
, 0);
2067 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
2069 return gen_intermediate_code_internal(env
, tb
, 1);
2072 CPUAlphaState
* cpu_alpha_init (const char *cpu_model
)
2077 env
= qemu_mallocz(sizeof(CPUAlphaState
));
2082 /* XXX: should not be hardcoded */
2083 env
->implver
= IMPLVER_2106x
;
2085 #if defined (CONFIG_USER_ONLY)
2089 /* Initialize IPR */
2090 hwpcb
= env
->ipr
[IPR_PCBB
];
2091 env
->ipr
[IPR_ASN
] = 0;
2092 env
->ipr
[IPR_ASTEN
] = 0;
2093 env
->ipr
[IPR_ASTSR
] = 0;
2094 env
->ipr
[IPR_DATFX
] = 0;
2096 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
2097 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
2098 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
2099 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
2100 env
->ipr
[IPR_FEN
] = 0;
2101 env
->ipr
[IPR_IPL
] = 31;
2102 env
->ipr
[IPR_MCES
] = 0;
2103 env
->ipr
[IPR_PERFMON
] = 0; /* Implementation specific */
2104 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
2105 env
->ipr
[IPR_SISR
] = 0;
2106 env
->ipr
[IPR_VIRBND
] = -1ULL;