nanoMIPS
cover nanoMIPS
This series of patches is implementing recently announced nanoMIPS on QEMU. nanoMIPS is a variable length ISA containing 16, 32 and 48 bit wide instructions. It is designed to be portable at assembly level with other MIPS and microMIPS code, but contains a number of changes which enhance code density and efficiency.
Most of nanoMIPS instructions exist in another MIPS ISAs. Therefore the large portion of patches is decoding nanoMIPS opcodes.
More patches will be added later after this.
For more information please refer following link.
https://www.mips.com/products/architectures/nanomips/
James Hogan (5):
target/mips: Implement nanoMIPS EXTW instruction target/mips: Fix nanoMIPS exception_resume_pc target/mips: Fix nanoMIPS set_hflags_for_handler target/mips: Fix nanoMIPS set_pc target/mips: Disable gdbstub nanoMIPS ISA bit
Matthew Fortune (4):
target/mips: Add nanoMIPS save and restore
target/mips: Add has_isa_mode
target/mips: Add nanoMIPS rotx instruction
hw/mips: Add basic nanoMIPS boot code
Paul Burton (1):
mips_malta: Setup GT64120 BARs in nanoMIPS bootloader
Stefan Markovic (3):
target/mips: Add nanoMIPS CP0_BadInstrX register hw/mips: Fix semihosting argument passing for nanoMIPS bare metal target/mips: Add I7200 CPU
Yongbok Kim (22):
target/mips: Raise a RI when given fs is n/a from CTC1 target/mips: Fix microMIPS on reset
target/mips: Add nanoMIPS OPCODE table target/mips: Add decode_nanomips_opc() target/mips: Add nanoMIPS 16bit ld/st instructions target/mips: Add nanoMIPS pool16c instructions target/mips: Add nanoMIPS 32bit instructions target/mips: Add nanoMIPS 48bit instructions target/mips: Add nanoMIPS pool32f instructions target/mips: Add nanoMIPS pool32a0 instructions target/mips: Add nanoMIPS pool32axf instructions target/mips: Update gen_flt_ldst()
target/mips: Add nanoMIPS p_lsx instructions target/mips: Add nanoMIPS load store instructions target/mips: Add nanoMIPS branch instructions target/mips: Implement nanoMIPS LLWP/SCWP pair target/mips: Fix not to update BadVAddr in Debug Mode target/mips: Fix data type for offset target/mips: Update BadInstr{P} regs on nanoMIPS target/mips: Config3.ISAOnExc is read only in nanoMIPS target/mips: Fix ERET/ERETNC can cause ADEL exception target/mips: Fix gdbstub to read/write 64 bit FP registers
hw/mips/mips_malta.c | 153 +- include/elf.h | 1 + linux-user/mips/cpu_loop.c | 25 +- target/mips/cpu.h | 3 + target/mips/gdbstub.c | 16 +- target/mips/helper.c | 39 +- target/mips/helper.h | 4 + target/mips/machine.c | 1 + target/mips/mips-defs.h | 4 + target/mips/op_helper.c | 166 ++- target/mips/translate.c | 3017 +++++++++++++++++++++++++++++++++++++- target/mips/translate_init.inc.c | 37 + 12 files changed, 3408 insertions(+), 58 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/35 target/mips: Raise a RI when given fs is n/a from CTC1
From: Yongbok Kim <[email protected]>
Fix to raise a Reserved Instruction exception when given fs is not available from CTC1.
--- target/mips/op_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/mips/op_helper.c +3 -0
@@ -2627,6 +2627,9 @@ void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt) (env->active_fpu.fcr31 & ~(env->active_fpu.fcr31_rw_bitmask));break ;default : +if (env->insn_flags &ISA_MIPS32R6 ) { +do_raise_exception (env,EXCP_RI ,GETPC ()); + }return ; }restore_fp_status (env);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 01/35] target/mips: Raise a RI when given fs is n/a from CTC1
Quoted 6 lines
From: Yongbok Kim <[email protected]>
Fix to raise a Reserved Instruction exception when given fs is not available from CTC1.
Signed-off-by Yongbok Kim <[email protected]>
Quoted 20 lines
--- target/mips/op_helper.c | 3 +++ 1 file changed, 3 insertions(+)target/mips/op_helper.c +3
-1@@ -2627,6 +2627,9 @@ void helper_ctc1(CPUMIPSState *env, target_ulong arg1, uint32_t fs, uint32_t rt) (env->active_fpu.fcr31 & ~(env->active_fpu.fcr31_rw_bitmask));break ;default : +if (env->insn_flags &ISA_MIPS32R6 ) { +do_raise_exception (env,EXCP_RI ,GETPC ()); + }return ; }restore_fp_status (env); --1.9.1
PATCH 2/35 target/mips: Fix microMIPS on reset
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Fix to activate microMIPS (and nanoMIPS) on reset when Config3.ISA == {1, 3}
--- target/mips/translate.c | 5 +++++ 1 file changed, 5 insertions(+)
target/mips/translate.c +5 -0
@@ -20713,6 +20713,11 @@ void cpu_state_reset(CPUMIPSState *env) env->CP0_Status |= (1 << CP0St_FR); } +if (env->CP0_Config3 & (1 <<CP0C3_ISA )) { +/* microMIPS/nanoMIPS on reset when Config3.ISA == {1, 3} */ + env->hflags |=MIPS_HFLAG_M16 ; + } +/* MSA */ if (env->CP0_Config3 & (1 <<CP0C3_MSAP )) {msa_reset (env);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 02/35] target/mips: Fix microMIPS on reset
Quoted 5 lines
From: Yongbok Kim <[email protected]>
Fix to activate microMIPS (and nanoMIPS) on reset when Config3.ISA == {1, 3}
Signed-off-by Yongbok Kim <[email protected]>
Quoted 22 lines
--- target/mips/translate.c | 5 +++++ 1 file changed, 5 insertions(+)target/mips/translate.c +5
-1@@ -20713,6 +20713,11 @@ void cpu_state_reset(CPUMIPSState *env) env->CP0_Status |= (1 << CP0St_FR); } +if (env->CP0_Config3 & (1 <<CP0C3_ISA )) { +/* microMIPS/nanoMIPS on reset when Config3.ISA == {1, 3} */ + env->hflags |=MIPS_HFLAG_M16 ; + } +/* MSA */ if (env->CP0_Config3 & (1 <<CP0C3_MSAP )) {msa_reset (env); --1.9.1
PATCH 3/35 target/mips: Add nanoMIPS OPCODE table
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Add nanoMIPS OPCODE table
Reference:
nanoMIPS Base ISA Technical Reference Manual
--- target/mips/mips-defs.h | 4 + target/mips/translate.c | 670 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 674 insertions(+)
target/mips/mips-defs.h +4 -0
@@ -39,6 +39,7 @@#define ISA_MIPS64R5 0x00001000#define ISA_MIPS32R6 0x00002000#define ISA_MIPS64R6 0x00004000 +#define ISA_NANOMIPS32 0x00008000/* MIPS ASEs. */ #define ASE_MIPS16 0x00010000
@@ -87,6 +88,9 @@#define CPU_MIPS32R6 (CPU_MIPS32R5 | ISA_MIPS32R6)#define CPU_MIPS64R6 (CPU_MIPS64R5 | CPU_MIPS32R6 | ISA_MIPS64R6) +/* MIPS Technologies "nanoMIPS" */ +#define CPU_NANOMIPS32 (CPU_MIPS32R6 | ISA_NANOMIPS32) +/* Strictly follow the architecture standard: - Disallow "special" instruction handling for PMON/SPIM. Note that we still maintain Count/Compare to match the host clock. */
target/mips/translate.c +670 -0
676 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 03/35] target/mips: Add nanoMIPS OPCODE table
Quoted 4 lines · Yongbok Kim
From: Yongbok Kim <[email protected]>
Add nanoMIPS OPCODE table
Quoted 8 lines
Reference:
nanoMIPS Base ISA Technical Reference ManualSigned-off-by Yongbok Kim <[email protected]>--- target/mips/mips-defs.h | 4 + target/mips/translate.c | 670 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 674 insertions(+)
I realize it's newish, and the mips target has a *lot* of legacy code and decode, but have you looked at qemu/scripts/decodetree.py? I think it would make a lot of this code significantly simpler.
How about simply splitting out this new code to a new file? After your patch, target/mips/translate.c weighs in at 23698 lines; you're adding over 3000 to that in this patch set.
That said, this patch matches a few spot checks I did of the manual.
r~
PATCH 4/35 target/mips: Add decode_nanomips_opc()
In reply to Yongbok KimAdd nanoMIPS decoder.
It covers P16 pool arithmetic and branch instructions.
--- target/mips/translate.c | 293 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 292 insertions(+), 1 deletion(-)
target/mips/translate.c +292 -1
@@ -16200,6 +16200,293 @@ enum {NM_EVP =0x01 }; +static int mmreg_nanomips (int r) +{ +static const int map[] = {16 ,17 ,18 ,19 ,4 ,5 ,6 ,7 }; + +return map[r &0x7 ]; +} + +static int mmreg4_nanomips (int r) +{ +static const int map[] = {8 ,9 ,10 ,11 ,4 ,5 ,6 ,7 , +16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 }; + +return map[r &0xf ]; +} + +/* Used for 16-bit store instructions. */ +static int mmreg4z_nanomips (int r) +{ +static const int map[] = {8 ,9 ,10 ,0 ,4 ,5 ,6 ,7 , +16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 }; + +return map[r &0xf ]; +} + +static int decode_nanomips_opc (CPUMIPSState *env,DisasContext *ctx) +{ +uint32_t op; +int rt =mmreg_nanomips (uMIPS_RD (ctx->opcode)); +int rs =mmreg_nanomips (uMIPS_RS (ctx->opcode)); +int rd =mmreg_nanomips (uMIPS_RS1 (ctx->opcode)); + +/* make sure instructions are on a halfword boundary */ +if (ctx->base.pc_next &0x1 ) { + env->CP0_BadVAddr = ctx->base.pc_next; +generate_exception_end (ctx, EXCP_AdEL); +return 2 ; + } + + op = (ctx->opcode >>10 ) &0x3f ; +switch (op) { +case NM_P16_MV : + { +int rt =uMIPS_RD5 (ctx->opcode); +if (rt !=0 ) { +/* MOVE */ +int rs =uMIPS_RS5 (ctx->opcode); +gen_arith (ctx,OPC_ADDU , rt, rs,0 ); + }else { +/* P16.RI */ +switch ((ctx->opcode >>3 ) &0x3 ) { +case NM_P16_SYSCALL : +generate_exception_end (ctx,EXCP_SYSCALL ); +break ; +case NM_BREAK16 : +generate_exception_end (ctx,EXCP_BREAK ); +break ; +case NM_SDBBP16 : +if (is_uhi (extract32 (ctx->opcode,0 ,3 ))) { +gen_helper_do_semihosting (cpu_env); + }else { +if (ctx->hflags &MIPS_HFLAG_SBRI ) { +generate_exception_end (ctx,EXCP_RI ); + }else { +generate_exception_end (ctx, EXCP_DBp); + } + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + } + } +break ; +case NM_P16_SHIFT : + { +int shift = (ctx->opcode) &0x7 ; +uint32_t opc =0 ; + shift = (shift ==0 ) ?8 : shift; + +switch ((ctx->opcode >>3 ) &1 ) { +case NM_SLL16 : + opc =OPC_SLL ; +break ; +case NM_SRL16 : + opc =OPC_SRL ; +break ; + } +gen_shift_imm (ctx, opc, rt, rs, shift); + } +break ; +case NM_P16C : +break ; +case NM_P16_A1 : +switch ((ctx->opcode >>6 ) &1 ) { +case NM_ADDIUR1SP : +gen_arith_imm (ctx,OPC_ADDIU , rt,29 , +extract32 (ctx->opcode,0 ,6 ) <<2 ); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_P16_A2 : +switch ((ctx->opcode >>3 ) &1 ) { +case NM_ADDIUR2 : + { +uint8_t u = (uint8_t )extract32 (ctx->opcode,0 ,3 ) <<2 ; +gen_arith_imm (ctx,OPC_ADDIU , rt, rs, u); + } +break ; +case NM_P_ADDIURS5 : + { +int rt =extract32 (ctx->opcode,5 ,5 ); +if (rt !=0 ) { +int s = (sextract32 (ctx->opcode,4 ,1 ) <<3 ) | +extract32 (ctx->opcode,0 ,3 ); +/* s = sign_extend( s[3] . s[2:0] , from_nbits = 4)*/ +gen_arith_imm (ctx,OPC_ADDIU , rt, rt, s); + } + } +break ; + } +break ; +case NM_P16_ADDU : +switch (ctx->opcode &0x1 ) { +case NM_ADDU16 : +gen_arith (ctx,OPC_ADDU , rd, rs, rt); +break ; +case NM_SUBU16 : +gen_arith (ctx,OPC_SUBU , rd, rs, rt); +break ; + } +break ; +case NM_P16_4X4 : + { +int rt = (extract32 (ctx->opcode,9 ,1 ) <<3 ) | +extract32 (ctx->opcode,5 ,3 ); +int rs = (extract32 (ctx->opcode,4 ,1 ) <<3 ) | +extract32 (ctx->opcode,0 ,3 ); + rt =mmreg4_nanomips (rt); + rs =mmreg4_nanomips (rs); + +switch (((ctx->opcode >>7 ) &0x2 ) | ((ctx->opcode >>3 ) &0x1 )) { +case NM_ADDU4X4 : +gen_arith (ctx,OPC_ADDU , rt, rs, rt); +break ; +case NM_MUL4X4 : +gen_r6_muldiv (ctx,R6_OPC_MUL , rt, rs, rt); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + } +break ; +case NM_LI16 : + { +int imm =extract32 (ctx->opcode,0 ,7 ); + imm = (imm ==0x7f ?-1 : imm); +if (rt !=0 ) { +tcg_gen_movi_tl (cpu_gpr[rt], imm); + } + } +break ; +case NM_ANDI16 : + { +uint32_t u =extract32 (ctx->opcode,0 ,4 ); + u = (u ==12 ) ?0xff : + (u ==13 ) ?0xffff : u; +gen_logic_imm (ctx,OPC_ANDI , rt, rs, u); + } +break ; +case NM_P16_LB : +break ; +case NM_P16_LH : +break ; +case NM_LW16 : +break ; +case NM_LWSP16 : +break ; +case NM_LW4X4 : +break ; +case NM_SW4X4 : +break ; +case NM_LWGP16 : +break ; +case NM_SWSP16 : +break ; +case NM_SW16 : +break ; +case NM_SWGP16 : +break ; +case NM_BC16 : +gen_compute_branch (ctx,OPC_BEQ ,2 ,0 ,0 , + (sextract32 (ctx->opcode,0 ,1 ) <<10 ) | + (extract32 (ctx->opcode,1 ,9 ) <<1 ), +0 ); +break ; +case NM_BALC16 : +gen_compute_branch (ctx,OPC_BGEZAL ,2 ,0 ,0 , + (sextract32 (ctx->opcode,0 ,1 ) <<10 ) | + (extract32 (ctx->opcode,1 ,9 ) <<1 ), +0 ); +break ; +case NM_BEQZC16 : +case NM_BNEZC16 : +gen_compute_branch (ctx, op ==NM_BNEZC16 ?OPC_BNE :OPC_BEQ ,2 , + rt,0 , + (sextract32 (ctx->opcode,0 ,1 ) <<7 ) | + (extract32 (ctx->opcode,1 ,6 ) <<1 ), +0 ); +break ; +case NM_P16_BR : +switch (ctx->opcode &0xf ) { +case 0 : +/* P16.JRC */ +switch ((ctx->opcode >>4 ) &1 ) { +case NM_JRC : +gen_compute_branch (ctx,OPC_JR ,2 , +extract32 (ctx->opcode,5 ,5 ),0 ,0 ,0 ); +break ; +case NM_JALRC16 : +gen_compute_branch (ctx,OPC_JALR ,2 , +extract32 (ctx->opcode,5 ,5 ),31 ,0 ,0 ); +break ; + } +break ; +default : +/* P16.BRI */ +if (extract32 (ctx->opcode,4 ,3 ) <extract32 (ctx->opcode,7 ,3 )) { +/* BEQC16 */ +gen_compute_branch (ctx,OPC_BEQ ,2 , rs, rt, +extract32 (ctx->opcode,0 ,4 ) <<1 ,0 ); + }else { +/* BNEC16 */ +gen_compute_branch (ctx,OPC_BNE ,2 , rs, rt, +extract32 (ctx->opcode,0 ,4 ) <<1 ,0 ); + } +break ; + } +break ; +case NM_P16_SR : +break ; +case NM_MOVEP : +case NM_MOVEPREV : + { +static const int gpr2reg1[] = {4 ,5 ,6 ,7 }; +static const int gpr2reg2[] = {5 ,6 ,7 ,8 }; +int re; +int rd2 =extract32 (ctx->opcode,3 ,1 ) <<1 | +extract32 (ctx->opcode,8 ,1 ); +int r1 = gpr2reg1[rd2]; +int r2 = gpr2reg2[rd2]; +int r3 =extract32 (ctx->opcode,4 ,1 ) <<3 | +extract32 (ctx->opcode,0 ,3 ); +int r4 =extract32 (ctx->opcode,9 ,1 ) <<3 | +extract32 (ctx->opcode,5 ,3 ); +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); +if (op ==NM_MOVEP ) { + rd = r1; + re = r2; + rs =mmreg4z_nanomips (r3); + rt =mmreg4z_nanomips (r4); + }else { + rd =mmreg4_nanomips (r3); + re =mmreg4_nanomips (r4); + rs = r1; + rt = r2; + } +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); +tcg_gen_mov_tl (cpu_gpr[rd], t0); +tcg_gen_mov_tl (cpu_gpr[re], t1); +tcg_temp_free (t0); +tcg_temp_free (t1); + } +break ; +default : +break ; + } + +return 2 ; +} +/* SmartMIPS extension to MIPS32 */ #if defined(TARGET_MIPS64 )
@@ -20950,7 +21237,11 @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)decode_opc (env, ctx); }else if (ctx->insn_flags &ASE_MICROMIPS ) { ctx->opcode =cpu_lduw_code (env, ctx->base.pc_next); - insn_bytes =decode_micromips_opc (env, ctx); +if (env->insn_flags &ISA_NANOMIPS32 ) { + insn_bytes =decode_nanomips_opc (env, ctx); + }else { + insn_bytes =decode_micromips_opc (env, ctx); + } }else if (ctx->insn_flags &ASE_MIPS16 ) { ctx->opcode =cpu_lduw_code (env, ctx->base.pc_next); insn_bytes =decode_mips16_opc (env, ctx);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 04/35] target/mips: Add decode_nanomips_opc()
target/mips/translate.c enum { · line 16232
Quoted 6 lines · Yongbok Kim
target/mips/translate.c +6
-0+static int decode_nanomips_opc (CPUMIPSState *env,DisasContext *ctx) +{ +uint32_t op; +int rt =mmreg_nanomips (uMIPS_RD (ctx->opcode)); +int rs =mmreg_nanomips (uMIPS_RS (ctx->opcode)); +int rd =mmreg_nanomips (uMIPS_RS1 (ctx->opcode));
Do you really want to be reusing micro-mips macros for nano-mips? Even if they are the same?
target/mips/translate.c enum { · line 16245
Quoted 13 lines
target/mips/translate.c +13
-0+ +/* make sure instructions are on a halfword boundary */ +if (ctx->base.pc_next &0x1 ) { + env->CP0_BadVAddr = ctx->base.pc_next; +generate_exception_end (ctx, EXCP_AdEL); +return 2 ; + } + + op = (ctx->opcode >>10 ) &0x3f ; +switch (op) { +case NM_P16_MV : + { +int rt =uMIPS_RD5 (ctx->opcode);
The formatting here is off. It should be
switch (op) {
case NM_P16_MV:
{
int rt ...but it might be even better to split each case off into a separate function. For the most part that could become
return table[op](ctx, insn);
where the table is fully populated with function pointers. It would have the same indirect branch predictability of the switch statement while producing smaller functions that are easier to reason with.
target/mips/translate.c enum { · line 16252
Quoted 7 lines
target/mips/translate.c +7
-0+if (rt !=0 ) { +/* MOVE */ +int rs =uMIPS_RS5 (ctx->opcode); +gen_arith (ctx,OPC_ADDU , rt, rs,0 ); + }else { +/* P16.RI */ +switch ((ctx->opcode >>3 ) &0x3 ) {
You have an eclectic mix of shift-and-mask and extract32 throughout. I would prefer if you standardized on extract32.
Quoted 24 lines
target/mips/translate.c +24
-0+case NM_MOVEP : +case NM_MOVEPREV : + { +static const int gpr2reg1[] = {4 ,5 ,6 ,7 }; +static const int gpr2reg2[] = {5 ,6 ,7 ,8 }; +int re; +int rd2 =extract32 (ctx->opcode,3 ,1 ) <<1 | +extract32 (ctx->opcode,8 ,1 ); +int r1 = gpr2reg1[rd2]; +int r2 = gpr2reg2[rd2]; +int r3 =extract32 (ctx->opcode,4 ,1 ) <<3 | +extract32 (ctx->opcode,0 ,3 ); +int r4 =extract32 (ctx->opcode,9 ,1 ) <<3 | +extract32 (ctx->opcode,5 ,3 ); +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); +if (op ==NM_MOVEP ) { + rd = r1; + re = r2; + rs =mmreg4z_nanomips (r3); + rt =mmreg4z_nanomips (r4); + }else { + rd =mmreg4_nanomips (r3); + re =mmreg4_nanomips (r4);
target/mips/translate.c enum { · line 16481
Quoted 10 lines
target/mips/translate.c +10
-0+ rs = r1; + rt = r2; + } +gen_load_gpr (t0, rs); +gen_load_gpr (t1, rt); +tcg_gen_mov_tl (cpu_gpr[rd], t0); +tcg_gen_mov_tl (cpu_gpr[re], t1); +tcg_temp_free (t0); +tcg_temp_free (t1); + }
I would encourage you to qemu_log_mask(LOG_GUEST_ERROR, ...) whenever the result of the instruction is UNKNOWN or UNPREDICTABLE, as here when destinations overlap sources.
target/mips/translate.c static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) · line 21244
Quoted 8 lines
} else if (ctx->insn_flags & ASE_MICROMIPS) { ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next);target/mips/translate.c +5
-1- insn_bytes =decode_micromips_opc (env, ctx); +if (env->insn_flags &ISA_NANOMIPS32 ) { + insn_bytes =decode_nanomips_opc (env, ctx); + }else { + insn_bytes =decode_micromips_opc (env, ctx); + }
Clearer without useless sharing of one line:
} else if (env->insn_flags & ISA_NANOMIPS32) {
ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next);
insn_bytes = decode_nanomips_opc(env, ctx);
} else if (ctx->insn_flags & ASE_MICROMIPS) {
ctx->opcode = cpu_lduw_code(env, ctx->base.pc_next);
insn_bytes = decode_micromips_opc(env, ctx);
}r~
PATCH 5/35 target/mips: Add nanoMIPS 16bit ld/st instructions
In reply to Yongbok KimAdd nanoMIPS 16bit load and store instructions
--- target/mips/translate.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)
target/mips/translate.c +110 -0
@@ -16207,6 +16207,14 @@ static int mmreg_nanomips(int r)return map[r &0x7 ]; } +/* Used for 16-bit store instructions. */ +static int mmreg2_nanomips (int r) +{ +static const int map[] = {0 ,17 ,18 ,19 ,4 ,5 ,6 ,7 }; + +return map[r &0x7 ]; +} +static int mmreg4_nanomips (int r) {static const int map[] = {8 ,9 ,10 ,11 ,4 ,5 ,6 ,7 ,
@@ -16292,6 +16300,13 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P16C : +switch (ctx->opcode &1 ) { +case NM_POOL16C_0 : +break ; +case NM_LWXS16 : +gen_ldxs (ctx, rt, rs, rd); +break ; + }break ;case NM_P16_A1 :switch ((ctx->opcode >>6 ) &1 ) {
@@ -16375,24 +16390,119 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P16_LB : + { +uint32_t u =extract32 (ctx->opcode,0 ,2 ); +switch (((ctx->opcode) >>2 ) &0x03 ) { +case NM_LB16 : +gen_ld (ctx,OPC_LB , rt, rs, u); +break ; +case NM_SB16 : + { +int rt =mmreg2_nanomips (uMIPS_RD (ctx->opcode)); +gen_st (ctx,OPC_SB , rt, rs, u); + } +break ; +case NM_LBU16 : +gen_ld (ctx,OPC_LBU , rt, rs, u); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_P16_LH : + { +uint32_t u =extract32 (ctx->opcode,1 ,2 ) <<1 ; +switch ((((ctx->opcode >>3 ) &1 ) <<1 ) | (ctx->opcode &1 )) { +case NM_LH16 : +gen_ld (ctx,OPC_LH , rt, rs, u); +break ; +case NM_SH16 : + { +int rt =mmreg2_nanomips (uMIPS_RD (ctx->opcode)); +gen_st (ctx,OPC_SH , rt, rs, u); + } +break ; +case NM_LHU16 : +gen_ld (ctx,OPC_LHU , rt, rs, u); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_LW16 : + { +int u =extract32 (ctx->opcode,0 ,4 ) <<2 ; +gen_ld (ctx,OPC_LW , rt, rs, u); + }break ;case NM_LWSP16 : + { +int rt =uMIPS_RD5 (ctx->opcode); +int u =extract32 (ctx->opcode,0 ,5 ) <<2 ; + +gen_ld (ctx,OPC_LW , rt,29 , u); + }break ;case NM_LW4X4 : + { +int rt = (extract32 (ctx->opcode,9 ,1 ) <<3 ) | +extract32 (ctx->opcode,5 ,3 ); +int rs = (extract32 (ctx->opcode,4 ,1 ) <<3 ) | +extract32 (ctx->opcode,0 ,3 ); +int u = (extract32 (ctx->opcode,3 ,1 ) <<3 ) | + (extract32 (ctx->opcode,8 ,1 ) <<2 ); + rt =mmreg4_nanomips (rt); + rs =mmreg4_nanomips (rs); +gen_ld (ctx,OPC_LW , rt, rs, u); + }break ;case NM_SW4X4 : + { +int rt = (extract32 (ctx->opcode,9 ,1 ) <<3 ) | +extract32 (ctx->opcode,5 ,3 ); +int rs = (extract32 (ctx->opcode,4 ,1 ) <<3 ) | +extract32 (ctx->opcode,0 ,3 ); +int u = (extract32 (ctx->opcode,3 ,1 ) <<3 ) | + (extract32 (ctx->opcode,8 ,1 ) <<2 ); + rt =mmreg4z_nanomips (rt); + rs =mmreg4_nanomips (rs); +gen_st (ctx,OPC_SW , rt, rs, u); + }break ;case NM_LWGP16 : + { +int u =extract32 (ctx->opcode,0 ,7 ) <<2 ; +gen_ld (ctx,OPC_LW , rt,28 , u); + }break ;case NM_SWSP16 : + { +int rt =uMIPS_RD5 (ctx->opcode); +int u =extract32 (ctx->opcode,0 ,5 ) <<2 ; + +gen_st (ctx,OPC_SW , rt,29 , u); + }break ;case NM_SW16 : + { +int rt =mmreg2_nanomips (uMIPS_RD (ctx->opcode)); +int rs =mmreg_nanomips (uMIPS_RS (ctx->opcode)); +int u =extract32 (ctx->opcode,0 ,4 ) <<2 ; + +gen_st (ctx,OPC_SW , rt, rs, u); + }break ;case NM_SWGP16 : + { +int rt =mmreg2_nanomips (uMIPS_RD (ctx->opcode)); +int u =extract32 (ctx->opcode,0 ,7 ) <<2 ; + +gen_st (ctx,OPC_SW , rt,28 , u); + }break ;case NM_BC16 : gen_compute_branch(ctx, OPC_BEQ, 2, 0, 0,
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 05/35] target/mips: Add nanoMIPS 16bit ld/st instructions
Quoted 12 lines · Yongbok Kim
Add nanoMIPS 16bit load and store instructions
Signed-off-by Yongbok Kim <[email protected]>--- target/mips/translate.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+)target/mips/translate.c +0
-0
target/mips/translate.c static int mmreg_nanomips(int r) · line 16215
Quoted 9 lines
target/mips/translate.c +6
-0@@ -16207,6 +16207,14 @@ static int mmreg_nanomips(int r)return map[r &0x7 ]; } +/* Used for 16-bit store instructions. */ +static int mmreg2_nanomips (int r) +{ +static const int map[] = {0 ,17 ,18 ,19 ,4 ,5 ,6 ,7 }; + +return map[r &0x7 ];
This is called gpr3.src.store in the manual.
Why the name change to "reg2"?
r~
PATCH 6/35 target/mips: Add nanoMIPS pool16c instructions
In reply to Yongbok KimAdd nanoMIPS pool16c instructions
--- target/mips/translate.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
target/mips/translate.c +22 -0
@@ -16232,6 +16232,27 @@ static int mmreg4z_nanomips(int r)return map[r &0xf ]; } +static void gen_pool16c_nanomips_insn (DisasContext *ctx) +{ +int rt =mmreg_nanomips (uMIPS_RD (ctx->opcode)); +int rs =mmreg_nanomips (uMIPS_RS (ctx->opcode)); + +switch ((ctx->opcode >>2 ) &0x3 ) { +case NM_NOT16 : +gen_logic (ctx,OPC_NOR , rt, rs,0 ); +break ; +case NM_AND16 : +gen_logic (ctx,OPC_AND , rt, rt, rs); +break ; +case NM_XOR16 : +gen_logic (ctx,OPC_XOR , rt, rt, rs); +break ; +case NM_OR16 : +gen_logic (ctx,OPC_OR , rt, rt, rs); +break ; + } +} +static int decode_nanomips_opc (CPUMIPSState *env,DisasContext *ctx) {uint32_t op;
@@ -16302,6 +16323,7 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx)case NM_P16C :switch (ctx->opcode &1 ) {case NM_POOL16C_0 : +gen_pool16c_nanomips_insn (ctx);break ;case NM_LWXS16 :gen_ldxs (ctx, rt, rs, rd);
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 06/35] target/mips: Add nanoMIPS pool16c instructions
Quoted 6 lines · Yongbok Kim
Add nanoMIPS pool16c instructions
Signed-off-by Yongbok Kim <[email protected]>--- target/mips/translate.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
This is a good example of using a subroutine that should be used elsewhere.
r~
Quoted 42 lines
target/mips/translate.c +22
-0@@ -16232,6 +16232,27 @@ static int mmreg4z_nanomips(int r)return map[r &0xf ]; } +static void gen_pool16c_nanomips_insn (DisasContext *ctx) +{ +int rt =mmreg_nanomips (uMIPS_RD (ctx->opcode)); +int rs =mmreg_nanomips (uMIPS_RS (ctx->opcode)); + +switch ((ctx->opcode >>2 ) &0x3 ) { +case NM_NOT16 : +gen_logic (ctx,OPC_NOR , rt, rs,0 ); +break ; +case NM_AND16 : +gen_logic (ctx,OPC_AND , rt, rt, rs); +break ; +case NM_XOR16 : +gen_logic (ctx,OPC_XOR , rt, rt, rs); +break ; +case NM_OR16 : +gen_logic (ctx,OPC_OR , rt, rt, rs); +break ; + } +} +static int decode_nanomips_opc (CPUMIPSState *env,DisasContext *ctx) {uint32_t op;@@ -16302,6 +16323,7 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx)case NM_P16C :switch (ctx->opcode &1 ) {case NM_POOL16C_0 : +gen_pool16c_nanomips_insn (ctx);break ;case NM_LWXS16 :gen_ldxs (ctx, rt, rs, rd);
PATCH 7/35 target/mips: Add nanoMIPS save and restore
In reply to Yongbok KimFrom: Matthew Fortune <[email protected]>
Add nanoMIPS save and restore instructions
--- target/mips/translate.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
target/mips/translate.c +74 -0
@@ -16232,6 +16232,66 @@ static int mmreg4z_nanomips(int r)return map[r &0xf ]; } +static void gen_adjust_sp (DisasContext *ctx,int u) +{ +TCGv tsp =tcg_temp_new (); +gen_base_offset_addr (ctx, tsp,29 , u); +gen_store_gpr (tsp,29 ); +tcg_temp_free (tsp); +} + +static void gen_save (DisasContext *ctx,uint8_t rt,uint8_t count, +uint8_t gp,uint16_t u) +{ +int counter =0 ; +TCGv va =tcg_temp_new (); +TCGv t0 =tcg_temp_new (); +/* fprintf(stderr, "save %d, %d, %d, %d\n", rt, count, gp, u); */ + +while (counter != count) { +bool use_gp = gp && (counter == count -1 ); +int this_rt = use_gp ?28 : (rt &0x10 ) | ((rt + counter) &0x1f ); +int this_offset = -((counter +1 ) <<2 ); +gen_base_offset_addr (ctx, va,29 , this_offset); +gen_load_gpr (t0, this_rt); +tcg_gen_qemu_st_tl (t0, va, ctx->mem_idx,MO_TEUL | + ctx->default_tcg_memop_mask); + counter++; + } + +/* adjust stack pointer */ +gen_adjust_sp (ctx, -u); + +tcg_temp_free (t0); +tcg_temp_free (va); +} + +static void gen_restore (DisasContext *ctx,uint8_t rt,uint8_t count, +uint8_t gp,uint16_t u) +{ +int counter =0 ; +TCGv va =tcg_temp_new (); +TCGv t0 =tcg_temp_new (); + +while (counter != count) { +bool use_gp = gp && (counter == count -1 ); +int this_rt = use_gp ?28 : (rt &0x10 ) | ((rt + counter) &0x1f ); +int this_offset = u - ((counter +1 ) <<2 ); +gen_base_offset_addr (ctx, va,29 , this_offset); +tcg_gen_qemu_ld_tl (t0, va, ctx->mem_idx,MO_TESL | + ctx->default_tcg_memop_mask); +tcg_gen_ext32s_tl (t0, t0); +gen_store_gpr (t0, this_rt); + counter++; + } + +/* adjust stack pointer */ +gen_adjust_sp (ctx, u); + +tcg_temp_free (t0); +tcg_temp_free (va); +} +static void gen_pool16c_nanomips_insn (DisasContext *ctx) {int rt =mmreg_nanomips (uMIPS_RD (ctx->opcode));
@@ -16576,6 +16636,20 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P16_SR : + { +int count =extract32 (ctx->opcode,0 ,4 ); +int u =extract32 (ctx->opcode,4 ,4 ) <<4 ; +int rt =30 + ((ctx->opcode >>9 ) &1 ); +switch ((ctx->opcode >>8 ) &1 ) { +case NM_SAVE16 : +gen_save (ctx, rt, count,0 , u); +break ; +case NM_RESTORE_JRC16 : +gen_restore (ctx, rt, count,0 , u); +gen_compute_branch (ctx,OPC_JR ,2 ,31 ,0 ,0 ,0 ); +break ; + } + }break ;case NM_MOVEP :case NM_MOVEPREV :
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 07/35] target/mips: Add nanoMIPS save and restore
target/mips/translate.c static int mmreg4z_nanomips(int r) · line 16276
Quoted 8 lines · Yongbok Kim
target/mips/translate.c +8
-0+static void gen_restore (DisasContext *ctx,uint8_t rt,uint8_t count, +uint8_t gp,uint16_t u) +{ +int counter =0 ; +TCGv va =tcg_temp_new (); +TCGv t0 =tcg_temp_new (); + +while (counter != count) {
Better written as a for loop?
target/mips/translate.c static int mmreg4z_nanomips(int r) · line 16282
Quoted 6 lines
target/mips/translate.c +6
-0+bool use_gp = gp && (counter == count -1 ); +int this_rt = use_gp ?28 : (rt &0x10 ) | ((rt + counter) &0x1f ); +int this_offset = u - ((counter +1 ) <<2 ); +gen_base_offset_addr (ctx, va,29 , this_offset); +tcg_gen_qemu_ld_tl (t0, va, ctx->mem_idx,MO_TESL | + ctx->default_tcg_memop_mask);
Indentation.
Quoted 1 line
+
tcg_gen_ext32s_tl(t0, t0);
You do not need to sign-extend; you've just loaded a sign-extended 32-bit value via MO_TESL.
r~
PATCH 8/35 target/mips: Add nanoMIPS 32bit instructions
In reply to Yongbok KimAdd nanoMIPS 32bit instructions
--- target/mips/translate.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 284 insertions(+), 1 deletion(-)
target/mips/translate.c +284 -1
@@ -16313,6 +16313,289 @@ static void gen_pool16c_nanomips_insn(DisasContext *ctx) } } +static int decode_nanomips_32_48_opc (CPUMIPSState *env,DisasContext *ctx) +{ +uint16_t insn; +int rt, rs; +uint32_t op; + + insn =cpu_lduw_code (env, ctx->base.pc_next +2 ); + ctx->opcode = (ctx->opcode <<16 ) | insn; + + rt = (ctx->opcode >>21 ) &0x1f ; + rs = (ctx->opcode >>16 ) &0x1f ; + + op = (ctx->opcode >>26 ) &0x3f ; +switch (op) { +case NM_P_ADDIU : +if (rt ==0 ) { +/* P.RI */ +switch ((ctx->opcode >>19 ) &0x03 ) { +case NM_SIGRIE : +default : +generate_exception_end (ctx,EXCP_RI ); +break ; +case NM_P_SYSCALL : +if (((ctx->opcode >>18 ) &0x01 ) ==NM_SYSCALL ) { +generate_exception_end (ctx,EXCP_SYSCALL ); + }else { +generate_exception_end (ctx,EXCP_RI ); + } +break ; +case NM_BREAK : +generate_exception_end (ctx,EXCP_BREAK ); +break ; +case NM_SDBBP : +if (is_uhi (extract32 (ctx->opcode,0 ,19 ))) { +gen_helper_do_semihosting (cpu_env); + }else { +if (ctx->hflags &MIPS_HFLAG_SBRI ) { +generate_exception_end (ctx,EXCP_RI ); + }else { +generate_exception_end (ctx, EXCP_DBp); + } + } +break ; + } + }else { +uint16_t imm; + imm = (uint16_t )extract32 (ctx->opcode,0 ,16 ); +if (rs !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[rs], imm); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + }else { +tcg_gen_movi_tl (cpu_gpr[rt], imm); + } + } +break ; +case NM_ADDIUPC : +if (rt !=0 ) { +int32_t offset =sextract32 (ctx->opcode,0 ,1 ) <<21 + |extract32 (ctx->opcode,1 ,20 ) <<1 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +4 , offset); +tcg_gen_movi_tl (cpu_gpr[rt], addr); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + } +break ; +case NM_POOL32A : +break ; +case NM_P_GP_W : +switch (ctx->opcode &0x03 ) { +case NM_ADDIUGP_W : +if (rt !=0 ) { +uint32_t offset =extract32 (ctx->opcode,0 ,21 ); +if (offset ==0 ) { +gen_load_gpr (cpu_gpr[rt],28 ); + }else { +TCGv t0; + t0 =tcg_temp_new (); +tcg_gen_movi_tl (t0, offset); +gen_op_addr_add (ctx, cpu_gpr[rt], cpu_gpr[28 ], t0); +tcg_temp_free (t0); + } + } +break ; +case NM_LWGP : +gen_ld (ctx,OPC_LW , rt,28 ,extract32 (ctx->opcode,2 ,19 ) <<2 ); +break ; +case NM_SWGP : +gen_st (ctx,OPC_SW , rt,28 ,extract32 (ctx->opcode,2 ,19 ) <<2 ); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_P48I : +return 6 ; +case NM_P_U12 : +switch ((ctx->opcode >>12 ) &0x0f ) { +case NM_ORI : +gen_logic_imm (ctx,OPC_ORI , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_XORI : +gen_logic_imm (ctx,OPC_XORI , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_ANDI : +gen_logic_imm (ctx,OPC_ANDI , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_P_SR : +switch ((ctx->opcode >>20 ) &1 ) { +case NM_PP_SR : +switch (ctx->opcode &3 ) { +case NM_SAVE : +gen_save (ctx, rt,extract32 (ctx->opcode,16 ,4 ), + (ctx->opcode >>2 ) &1 , +extract32 (ctx->opcode,3 ,9 ) <<3 ); +break ; +case NM_RESTORE : +case NM_RESTORE_JRC : +gen_restore (ctx, rt,extract32 (ctx->opcode,16 ,4 ), + (ctx->opcode >>2 ) &1 , +extract32 (ctx->opcode,3 ,9 ) <<3 ); +if ((ctx->opcode &3 ) ==NM_RESTORE_JRC ) { +gen_compute_branch (ctx,OPC_JR ,2 ,31 ,0 ,0 ,0 ); + } +break ; + } +break ; +case NM_P_SR_F : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_SLTI : +gen_slt_imm (ctx,OPC_SLTI , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_SLTIU : +gen_slt_imm (ctx,OPC_SLTIU , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_SEQI : + { +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); +TCGv t2 =tcg_temp_local_new (); +TCGLabel *l1 =gen_new_label (); + +gen_load_gpr (t0, rs); +tcg_gen_movi_tl (t1,extract32 (ctx->opcode,0 ,12 )); +tcg_gen_movi_tl (t2,0 ); +tcg_gen_brcond_tl (TCG_COND_NE , t0, t1, l1); +tcg_gen_movi_tl (t2,1 ); +gen_set_label (l1); +gen_store_gpr (t2, rt); + +tcg_temp_free (t0); +tcg_temp_free (t1); +tcg_temp_free (t2); + } +break ; +case NM_ADDIUNEG : + { +int16_t imm; + imm = (int16_t )extract32 (ctx->opcode,0 ,12 ); +gen_arith_imm (ctx,OPC_ADDIU , rt, rs, -imm); + } +break ; +case NM_P_SHIFT : + { +int shift =extract32 (ctx->opcode,0 ,5 ); +switch ((ctx->opcode >>5 ) &0x0f ) { +case NM_P_SLL : +if (rt ==0 && shift ==0 ) { +/* NOP */ + }else if (rt ==0 && shift ==3 ) { +/* EHB treat as NOP */ + }else if (rt ==0 && shift ==5 ) { +/* PAUSE */ +if (ctx->hflags &MIPS_HFLAG_BMASK ) { +generate_exception_end (ctx,EXCP_RI ); + } + }else if (rt ==0 && shift ==6 ) { +/* SYNC */ +check_insn (ctx,ISA_MIPS2 ); +/* Treat as NOP. */ + }else { +/* SLL */ +gen_shift_imm (ctx,OPC_SLL , rt, rs, +extract32 (ctx->opcode,0 ,5 )); + } +break ; +case NM_SRL : +gen_shift_imm (ctx,OPC_SRL , rt, rs, +extract32 (ctx->opcode,0 ,5 )); +break ; +case NM_SRA : +gen_shift_imm (ctx,OPC_SRA , rt, rs, +extract32 (ctx->opcode,0 ,5 )); +break ; +case NM_ROTR : +gen_shift_imm (ctx,OPC_ROTR , rt, rs, +extract32 (ctx->opcode,0 ,5 )); +break ; + } + } +break ; +case NM_P_ROTX : +break ; +case NM_P_INS : +switch (((ctx->opcode >>10 ) &2 ) | ((ctx->opcode >>5 ) &1 )) { +case NM_INS : +gen_bitops (ctx,OPC_INS , rt, rs,extract32 (ctx->opcode,0 ,5 ), +extract32 (ctx->opcode,6 ,5 )); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_P_EXT : +switch (((ctx->opcode >>10 ) &2 ) | ((ctx->opcode >>5 ) &1 )) { +case NM_EXT : +gen_bitops (ctx,OPC_EXT , rt, rs,extract32 (ctx->opcode,0 ,5 ), +extract32 (ctx->opcode,6 ,5 )); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_POOL32F : +break ; +case NM_POOL32S : +break ; +case NM_P_LUI : +switch ((ctx->opcode >>1 ) &1 ) { +case NM_LUI : +if (rt !=0 ) { +tcg_gen_movi_tl (cpu_gpr[rt], +sextract32 (ctx->opcode,0 ,1 ) <<31 | +extract32 (ctx->opcode,2 ,10 ) <<21 | +extract32 (ctx->opcode,12 ,9 ) <<12 ); + } +break ; +case NM_ALUIPC : +if (rt !=0 ) { +int offset =sextract32 (ctx->opcode,0 ,1 ) <<31 | +extract32 (ctx->opcode,2 ,10 ) <<21 | +extract32 (ctx->opcode,12 ,9 ) <<12 ; +target_long addr; + addr = ~0xFFF &addr_add (ctx, ctx->base.pc_next +4 , offset); +tcg_gen_movi_tl (cpu_gpr[rt], addr); + } +break ; + } +break ; +case NM_P_GP_BH : +break ; +case NM_P_LS_U12 : +break ; +case NM_P_LS_S9 : +break ; +case NM_MOVE_BALC : +break ; +case NM_P_BAL : +break ; +case NM_P_J : +break ; +case NM_P_BR1 : +break ; +case NM_P_BR2 : +break ; +case NM_P_BRI : +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +return 4 ; +} +static int decode_nanomips_opc (CPUMIPSState *env,DisasContext *ctx) {uint32_t op;
@@ -16687,7 +16970,7 @@ static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx) }break ;default : -break ; +return decode_nanomips_32_48_opc (env, ctx); }return 2 ;
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 08/35] target/mips: Add nanoMIPS 32bit instructions
Quoted 11 lines · Yongbok Kim
Add nanoMIPS 32bit instructions
Signed-off-by Yongbok Kim <[email protected]>--- target/mips/translate.c | 285 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 284 insertions(+), 1 deletion(-)target/mips/translate.c +0
-0
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16362
Quoted 3 lines
target/mips/translate.c +3
-0+ }else { +uint16_t imm; + imm = (uint16_t )extract32 (ctx->opcode,0 ,16 );
Unnecessary cast.
Quoted 5 lines
target/mips/translate.c +5
-0+if (rs !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[rs], imm); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + }else { +tcg_gen_movi_tl (cpu_gpr[rt], imm);
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16377
Quoted 10 lines
target/mips/translate.c +10
-0+ } + } +break ; +case NM_ADDIUPC : +if (rt !=0 ) { +int32_t offset =sextract32 (ctx->opcode,0 ,1 ) <<21 + |extract32 (ctx->opcode,1 ,20 ) <<1 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +4 , offset); +tcg_gen_movi_tl (cpu_gpr[rt], addr); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]);
ext32s is unnecessary.
The addr passed to movi_tl is signed and properly sized.
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16395
Quoted 12 lines
target/mips/translate.c +12
-0+case NM_ADDIUGP_W : +if (rt !=0 ) { +uint32_t offset =extract32 (ctx->opcode,0 ,21 ); +if (offset ==0 ) { +gen_load_gpr (cpu_gpr[rt],28 ); + }else { +TCGv t0; + t0 =tcg_temp_new (); +tcg_gen_movi_tl (t0, offset); +gen_op_addr_add (ctx, cpu_gpr[rt], cpu_gpr[28 ], t0); +tcg_temp_free (t0); + }
Your special-case of here fails to sign-extend for 0. That would want fixing for 64-bit nanoMIPS with AWRAP.
It would be worthwhile to have a gen_op_addr_addi, and not special-case offset here -- tcg_gen_addi_tl would do that for you.
Quoted 9 lines
target/mips/translate.c +9
-0+case NM_SLTI : +gen_slt_imm (ctx,OPC_SLTI , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_SLTIU : +gen_slt_imm (ctx,OPC_SLTIU , rt, rs,extract32 (ctx->opcode,0 ,12 )); +break ; +case NM_SEQI : + { +TCGv t0 =tcg_temp_new ();
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16465
Quoted 10 lines
target/mips/translate.c +10
-0+TCGv t1 =tcg_temp_new (); +TCGv t2 =tcg_temp_local_new (); +TCGLabel *l1 =gen_new_label (); + +gen_load_gpr (t0, rs); +tcg_gen_movi_tl (t1,extract32 (ctx->opcode,0 ,12 )); +tcg_gen_movi_tl (t2,0 ); +tcg_gen_brcond_tl (TCG_COND_NE , t0, t1, l1); +tcg_gen_movi_tl (t2,1 ); +gen_set_label (l1);
No labels required. This is
tcg_gen_setcondi_tl(TCG_COND_NE, t2, t0, extract32(...));
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16476
Quoted 11 lines
target/mips/translate.c +11
-0+gen_store_gpr (t2, rt); + +tcg_temp_free (t0); +tcg_temp_free (t1); +tcg_temp_free (t2); + } +break ; +case NM_ADDIUNEG : + { +int16_t imm; + imm = (int16_t )extract32 (ctx->opcode,0 ,12 );
Cast is unnecessary.
r~
PATCH 9/35 target/mips: Add nanoMIPS 48bit instructions
In reply to Yongbok KimAdd nanoMIPS 48bit instructions
--- target/mips/translate.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
target/mips/translate.c +66 -0
@@ -16407,6 +16407,72 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P48I : + insn =cpu_lduw_code (env, ctx->base.pc_next +4 ); +switch ((ctx->opcode >>16 ) &0x1f ) { +case NM_LI48 : +if (rt !=0 ) { +tcg_gen_movi_tl (cpu_gpr[rt], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 ); + } +break ; +case NM_ADDIU48 : +if (rt !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[rt], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 ); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + } +break ; +case NM_ADDIUGP48 : +if (rt !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[28 ], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 ); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + } +break ; +case NM_ADDIUPC48 : +if (rt !=0 ) { +int32_t offset =extract32 (ctx->opcode,0 ,16 ) | insn <<16 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +6 , offset); + +tcg_gen_movi_tl (cpu_gpr[rt], addr); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + } +break ; +case NM_LWPC48 : +if (rt !=0 ) { +TCGv t0; + t0 =tcg_temp_new (); + +int32_t offset =extract32 (ctx->opcode,0 ,16 ) | insn <<16 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +6 , offset); + +tcg_gen_movi_tl (t0, addr); +tcg_gen_qemu_ld_tl (cpu_gpr[rt], t0, ctx->mem_idx,MO_TESL ); +tcg_temp_free (t0); + } +break ; +case NM_SWPC48 : + { +TCGv t0, t1; + t0 =tcg_temp_new (); + t1 =tcg_temp_new (); + +int32_t offset =extract32 (ctx->opcode,0 ,16 ) | insn <<16 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +6 , offset); + +tcg_gen_movi_tl (t0, addr); +gen_load_gpr (t1, rt); + +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx,MO_TEUL ); + +tcg_temp_free (t0); +tcg_temp_free (t1); + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + }return 6 ;case NM_P_U12 :switch ((ctx->opcode >>12 ) &0x0f ) {
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 09/35] target/mips: Add nanoMIPS 48bit instructions
Quoted 2 lines · Yongbok Kim
case NM_P48I:+ insn =
cpu_lduw_code(env, ctx->base.pc_next + 4);
Surely split this case out to a new function. And properly form the common, signed 32-bit offset once before the switch.
target/mips/translate.c static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) · line 16415
Quoted 5 lines
target/mips/translate.c +5
-0+switch ((ctx->opcode >>16 ) &0x1f ) { +case NM_LI48 : +if (rt !=0 ) { +tcg_gen_movi_tl (cpu_gpr[rt], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 );
The 32-bit constant is to be sign-extended for nanomips 64.
target/mips/translate.c static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) · line 16421
Quoted 6 lines
target/mips/translate.c +6
-0+ } +break ; +case NM_ADDIU48 : +if (rt !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[rt], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 );
Likewise.
target/mips/translate.c static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) · line 16428
Quoted 7 lines
target/mips/translate.c +7
-0+tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]); + } +break ; +case NM_ADDIUGP48 : +if (rt !=0 ) { +tcg_gen_addi_tl (cpu_gpr[rt], cpu_gpr[28 ], +extract32 (ctx->opcode,0 ,16 ) | insn <<16 );
Likewise.
Quoted 1 line
+
tcg_gen_ext32s_tl(cpu_gpr[rt], cpu_gpr[rt]);
Behaves-like DADDIU[GP48]. Which would indicate using gen_op_addr_add[i].
I know you're only targeting nanomips32 now, but I think you need to be clearer about all of these 64-bit edge cases now, lest they be very difficult to pick out later.
target/mips/translate.c static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) · line 16438
Quoted 9 lines
target/mips/translate.c +9
-0+ } +break ; +case NM_ADDIUPC48 : +if (rt !=0 ) { +int32_t offset =extract32 (ctx->opcode,0 ,16 ) | insn <<16 ; +target_long addr =addr_add (ctx, ctx->base.pc_next +6 , offset); + +tcg_gen_movi_tl (cpu_gpr[rt], addr); +tcg_gen_ext32s_tl (cpu_gpr[rt], cpu_gpr[rt]);
Likewise. And the ext32s would be doubly redundant with that already done in addr_add.
r~
PATCH 10/35 target/mips: Add nanoMIPS pool32f instructions
In reply to Yongbok KimAdd nanoMIPS pool32f floating point instructions.
--- target/mips/translate.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+)
target/mips/translate.c +300 -0
@@ -16313,6 +16313,305 @@ static void gen_pool16c_nanomips_insn(DisasContext *ctx) } } +static void gen_pool32f_nanomips_insn (DisasContext *ctx) +{ +int rt, rs, rd; + + rt = (ctx->opcode >>21 ) &0x1f ; + rs = (ctx->opcode >>16 ) &0x1f ; + rd = (ctx->opcode >>11 ) &0x1f ; + +if (!(ctx->CP0_Config1 & (1 <<CP0C1_FP ))) { +generate_exception_end (ctx,EXCP_RI ); +return ; + } +check_cp1_enabled (ctx); +switch (ctx->opcode &0x07 ) { +case NM_POOL32F_0 : +switch ((ctx->opcode >>3 ) &0x7f ) { +case NM_RINT_S : +gen_farith (ctx,OPC_RINT_S ,0 , rt, rs,0 ); +break ; +case NM_RINT_D : +gen_farith (ctx,OPC_RINT_D ,0 , rt, rs,0 ); +break ; +case NM_CLASS_S : +gen_farith (ctx,OPC_CLASS_S ,0 , rt, rs,0 ); +break ; +case NM_CLASS_D : +gen_farith (ctx,OPC_CLASS_D ,0 , rt, rs,0 ); +break ; +case NM_ADD_S : +gen_farith (ctx,OPC_ADD_S , rt, rs, rd,0 ); +break ; +case NM_ADD_D : +gen_farith (ctx,OPC_ADD_D , rt, rs, rd,0 ); +break ; +case NM_SUB_S : +gen_farith (ctx,OPC_SUB_S , rt, rs, rd,0 ); +break ; +case NM_SUB_D : +gen_farith (ctx,OPC_SUB_D , rt, rs, rd,0 ); +break ; +case NM_MUL_S : +gen_farith (ctx,OPC_MUL_S , rt, rs, rd,0 ); +break ; +case NM_MUL_D : +gen_farith (ctx,OPC_MUL_D , rt, rs, rd,0 ); +break ; +case NM_DIV_S : +gen_farith (ctx,OPC_DIV_S , rt, rs, rd,0 ); +break ; +case NM_DIV_D : +gen_farith (ctx,OPC_DIV_D , rt, rs, rd,0 ); +break ; +case NM_SELEQZ_S : +gen_sel_s (ctx,OPC_SELEQZ_S , rd, rt, rs); +break ; +case NM_SELEQZ_D : +gen_sel_d (ctx,OPC_SELEQZ_D , rd, rt, rs); +break ; +case NM_SELNEZ_S : +gen_sel_s (ctx,OPC_SELNEZ_S , rd, rt, rs); +break ; +case NM_SELNEZ_D : +gen_sel_d (ctx,OPC_SELNEZ_D , rd, rt, rs); +break ; +case NM_SEL_S : +gen_sel_s (ctx,OPC_SEL_S , rd, rt, rs); +break ; +case NM_SEL_D : +gen_sel_d (ctx,OPC_SEL_D , rd, rt, rs); +break ; +case NM_MADDF_S : +gen_farith (ctx,OPC_MADDF_S , rt, rs, rd,0 ); +break ; +case NM_MADDF_D : +gen_farith (ctx,OPC_MADDF_D , rt, rs, rd,0 ); +break ; +case NM_MSUBF_S : +gen_farith (ctx,OPC_MSUBF_S , rt, rs, rd,0 ); +break ; +case NM_MSUBF_D : +gen_farith (ctx,OPC_MSUBF_D , rt, rs, rd,0 ); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_POOL32F_3 : +switch ((ctx->opcode >>3 ) &0x07 ) { +case NM_MIN_FMT : +switch ((ctx->opcode >>9 ) &1 ) { +case FMT_SDPS_S : +gen_farith (ctx,OPC_MIN_S , rt, rs, rd,0 ); +break ; +case FMT_SDPS_D : +gen_farith (ctx,OPC_MIN_D , rt, rs, rd,0 ); +break ; + } +break ; +case NM_MAX_FMT : +switch ((ctx->opcode >>9 ) &1 ) { +case FMT_SDPS_S : +gen_farith (ctx,OPC_MAX_S , rt, rs, rd,0 ); +break ; +case FMT_SDPS_D : +gen_farith (ctx,OPC_MAX_D , rt, rs, rd,0 ); +break ; + } +break ; +case NM_MINA_FMT : +switch ((ctx->opcode >>9 ) &1 ) { +case FMT_SDPS_S : +gen_farith (ctx,OPC_MINA_S , rt, rs, rd,0 ); +break ; +case FMT_SDPS_D : +gen_farith (ctx,OPC_MINA_D , rt, rs, rd,0 ); +break ; + } +break ; +case NM_MAXA_FMT : +switch ((ctx->opcode >>9 ) &1 ) { +case FMT_SDPS_S : +gen_farith (ctx,OPC_MAXA_S , rt, rs, rd,0 ); +break ; +case FMT_SDPS_D : +gen_farith (ctx,OPC_MAXA_D , rt, rs, rd,0 ); +break ; + } +break ; +case NM_POOL32FXF : +switch ((ctx->opcode >>6 ) &0xff ) { +case NM_CFC1 : +gen_cp1 (ctx,OPC_CFC1 , rt, rs); +break ; +case NM_CTC1 : +gen_cp1 (ctx,OPC_CTC1 , rt, rs); +break ; +case NM_MFC1 : +gen_cp1 (ctx,OPC_MFC1 , rt, rs); +break ; +case NM_MTC1 : +gen_cp1 (ctx,OPC_MTC1 , rt, rs); +break ; +case NM_MFHC1 : +gen_cp1 (ctx,OPC_MFHC1 , rt, rs); +break ; +case NM_MTHC1 : +gen_cp1 (ctx,OPC_MTHC1 , rt, rs); +break ; +case NM_CVT_S_PL : +gen_farith (ctx,OPC_CVT_S_PL ,-1 , rs, rt,0 ); +break ; +case NM_CVT_S_PU : +gen_farith (ctx,OPC_CVT_S_PU ,-1 , rs, rt,0 ); +break ; +default : +switch ((ctx->opcode >>6 ) &0x1ff ) { +case NM_CVT_L_S : +gen_farith (ctx,OPC_CVT_L_S ,-1 , rs, rt,0 ); +break ; +case NM_CVT_L_D : +gen_farith (ctx,OPC_CVT_L_D ,-1 , rs, rt,0 ); +break ; +case NM_CVT_W_S : +gen_farith (ctx,OPC_CVT_W_S ,-1 , rs, rt,0 ); +break ; +case NM_CVT_W_D : +gen_farith (ctx,OPC_CVT_W_D ,-1 , rs, rt,0 ); +break ; +case NM_RSQRT_S : +gen_farith (ctx,OPC_RSQRT_S ,-1 , rs, rt,0 ); +break ; +case NM_RSQRT_D : +gen_farith (ctx,OPC_RSQRT_D ,-1 , rs, rt,0 ); +break ; +case NM_SQRT_S : +gen_farith (ctx,OPC_SQRT_S ,-1 , rs, rt,0 ); +break ; +case NM_SQRT_D : +gen_farith (ctx,OPC_SQRT_D ,-1 , rs, rt,0 ); +break ; +case NM_RECIP_S : +gen_farith (ctx,OPC_RECIP_S ,-1 , rs, rt,0 ); +break ; +case NM_RECIP_D : +gen_farith (ctx,OPC_RECIP_D ,-1 , rs, rt,0 ); +break ; +case NM_FLOOR_L_S : +gen_farith (ctx,OPC_FLOOR_L_S ,-1 , rs, rt,0 ); +break ; +case NM_FLOOR_L_D : +gen_farith (ctx,OPC_FLOOR_L_D ,-1 , rs, rt,0 ); +break ; +case NM_FLOOR_W_S : +gen_farith (ctx,OPC_FLOOR_W_S ,-1 , rs, rt,0 ); +break ; +case NM_FLOOR_W_D : +gen_farith (ctx,OPC_FLOOR_W_D ,-1 , rs, rt,0 ); +break ; +case NM_CEIL_L_S : +gen_farith (ctx,OPC_CEIL_L_S ,-1 , rs, rt,0 ); +break ; +case NM_CEIL_L_D : +gen_farith (ctx,OPC_CEIL_L_D ,-1 , rs, rt,0 ); +break ; +case NM_CEIL_W_S : +gen_farith (ctx,OPC_CEIL_W_S ,-1 , rs, rt,0 ); +break ; +case NM_CEIL_W_D : +gen_farith (ctx,OPC_CEIL_W_D ,-1 , rs, rt,0 ); +break ; +case NM_TRUNC_L_S : +gen_farith (ctx,OPC_TRUNC_L_S ,-1 , rs, rt,0 ); +break ; +case NM_TRUNC_L_D : +gen_farith (ctx,OPC_TRUNC_L_D ,-1 , rs, rt,0 ); +break ; +case NM_TRUNC_W_S : +gen_farith (ctx,OPC_TRUNC_W_S ,-1 , rs, rt,0 ); +break ; +case NM_TRUNC_W_D : +gen_farith (ctx,OPC_TRUNC_W_D ,-1 , rs, rt,0 ); +break ; +case NM_ROUND_L_S : +gen_farith (ctx,OPC_ROUND_L_S ,-1 , rs, rt,0 ); +break ; +case NM_ROUND_L_D : +gen_farith (ctx,OPC_ROUND_L_D ,-1 , rs, rt,0 ); +break ; +case NM_ROUND_W_S : +gen_farith (ctx,OPC_ROUND_W_S ,-1 , rs, rt,0 ); +break ; +case NM_ROUND_W_D : +gen_farith (ctx,OPC_ROUND_W_D ,-1 , rs, rt,0 ); +break ; +case NM_MOV_S : +gen_farith (ctx,OPC_MOV_S ,-1 , rs, rt,0 ); +break ; +case NM_MOV_D : +gen_farith (ctx,OPC_MOV_D ,-1 , rs, rt,0 ); +break ; +case NM_ABS_S : +gen_farith (ctx,OPC_ABS_S ,-1 , rs, rt,0 ); +break ; +case NM_ABS_D : +gen_farith (ctx,OPC_ABS_D ,-1 , rs, rt,0 ); +break ; +case NM_NEG_S : +gen_farith (ctx,OPC_NEG_S ,-1 , rs, rt,0 ); +break ; +case NM_NEG_D : +gen_farith (ctx,OPC_NEG_D ,-1 , rs, rt,0 ); +break ; +case NM_CVT_D_S : +gen_farith (ctx,OPC_CVT_D_S ,-1 , rs, rt,0 ); +break ; +case NM_CVT_D_W : +gen_farith (ctx,OPC_CVT_D_W ,-1 , rs, rt,0 ); +break ; +case NM_CVT_D_L : +gen_farith (ctx,OPC_CVT_D_L ,-1 , rs, rt,0 ); +break ; +case NM_CVT_S_D : +gen_farith (ctx,OPC_CVT_S_D ,-1 , rs, rt,0 ); +break ; +case NM_CVT_S_W : +gen_farith (ctx,OPC_CVT_S_W ,-1 , rs, rt,0 ); +break ; +case NM_CVT_S_L : +gen_farith (ctx,OPC_CVT_S_L ,-1 , rs, rt,0 ); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; + } +break ; + } +break ; +case NM_POOL32F_5 : +switch ((ctx->opcode >>3 ) &0x07 ) { +case NM_CMP_CONDN_S : +gen_r6_cmp_s (ctx, (ctx->opcode >>6 ) &0x1f , rt, rs, rd); +break ; +case NM_CMP_CONDN_D : +gen_r6_cmp_d (ctx, (ctx->opcode >>6 ) &0x1f , rt, rs, rd); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +} +static int decode_nanomips_32_48_opc (CPUMIPSState *env,DisasContext *ctx) {uint16_t insn;
@@ -16612,6 +16911,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_POOL32F : +gen_pool32f_nanomips_insn (ctx);break ;case NM_POOL32S :break ;
Signature · 1 line
1.9.1
PATCH 11/35 target/mips: Add nanoMIPS pool32a0 instructions
In reply to Yongbok KimAdd nanoMIPS pool32a0 instructions
--- target/mips/translate.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+)
target/mips/translate.c +190 -0
@@ -16313,6 +16313,186 @@ static void gen_pool16c_nanomips_insn(DisasContext *ctx) } } +static void gen_pool32a0_nanomips_insn (DisasContext *ctx) +{ +int rt = (ctx->opcode >>21 ) &0x1f ; +int rs = (ctx->opcode >>16 ) &0x1f ; +int rd = (ctx->opcode >>11 ) &0x1f ; + +switch ((ctx->opcode >>3 ) &0x7f ) { +case NM_P_TRAP : +switch ((ctx->opcode >>10 ) &0x1 ) { +case NM_TEQ : +gen_trap (ctx,OPC_TEQ , rs, rt,-1 ); +break ; +case NM_TNE : +gen_trap (ctx,OPC_TNE , rs, rt,-1 ); +break ; + } +break ; +case NM_RDHWR : +gen_rdhwr (ctx, rt, rs,extract32 (ctx->opcode,11 ,3 )); +break ; +case NM_SEB : +gen_bshfl (ctx,OPC_SEB , rs, rt); +break ; +case NM_SEH : +gen_bshfl (ctx,OPC_SEH , rs, rt); +break ; +case NM_SLLV : +gen_shift (ctx,OPC_SLLV , rd, rt, rs); +break ; +case NM_SRLV : +gen_shift (ctx,OPC_SRLV , rd, rt, rs); +break ; +case NM_SRAV : +gen_shift (ctx,OPC_SRAV , rd, rt, rs); +break ; +case NM_ROTRV : +gen_shift (ctx,OPC_ROTRV , rd, rt, rs); +break ; +case NM_ADD : +gen_arith (ctx,OPC_ADD , rd, rs, rt); +break ; +case NM_ADDU : +gen_arith (ctx,OPC_ADDU , rd, rs, rt); +break ; +case NM_SUB : +gen_arith (ctx,OPC_SUB , rd, rs, rt); +break ; +case NM_SUBU : +gen_arith (ctx,OPC_SUBU , rd, rs, rt); +break ; +case NM_P_CMOVE : +switch ((ctx->opcode >>10 ) &1 ) { +case NM_MOVZ : +gen_cond_move (ctx,OPC_MOVZ , rd, rs, rt); +break ; +case NM_MOVN : +gen_cond_move (ctx,OPC_MOVN , rd, rs, rt); +break ; + } +break ; +case NM_AND : +gen_logic (ctx,OPC_AND , rd, rs, rt); +break ; +case NM_OR : +gen_logic (ctx,OPC_OR , rd, rs, rt); +break ; +case NM_NOR : +gen_logic (ctx,OPC_NOR , rd, rs, rt); +break ; +case NM_XOR : +gen_logic (ctx,OPC_XOR , rd, rs, rt); +break ; +case NM_SLT : +gen_slt (ctx,OPC_SLT , rd, rs, rt); +break ; +case NM_P_SLTU : +if (rd ==0 ) { +/* P_DVP */ +#ifndef CONFIG_USER_ONLY +TCGv t0 =tcg_temp_new (); +switch ((ctx->opcode >>10 ) &1 ) { +case NM_DVP : +if (ctx->vp) { +check_cp0_enabled (ctx); +gen_helper_dvp (t0, cpu_env); +gen_store_gpr (t0, rt); + } +break ; +case NM_EVP : +if (ctx->vp) { +check_cp0_enabled (ctx); +gen_helper_evp (t0, cpu_env); +gen_store_gpr (t0, rt); + } +break ; + } +tcg_temp_free (t0); +#endif + }else { +gen_slt (ctx,OPC_SLTU , rd, rs, rt); + } +break ; +case NM_SOV : + { +TCGv t0 =tcg_temp_local_new (); +TCGv t1 =tcg_temp_new (); +TCGv t2 =tcg_temp_new (); +TCGLabel *l1 =gen_new_label (); + +gen_load_gpr (t1, rs); +gen_load_gpr (t2, rt); +tcg_gen_add_tl (t0, t1, t2); +tcg_gen_ext32s_tl (t0, t0); +tcg_gen_xor_tl (t1, t1, t2); +tcg_gen_xor_tl (t2, t0, t2); +tcg_gen_andc_tl (t1, t2, t1); + +tcg_gen_movi_tl (t0,0 ); +tcg_gen_brcondi_tl (TCG_COND_GE , t1,0 , l1); +/* operands of same sign, result different sign */ + +tcg_gen_movi_tl (t0,1 ); +gen_set_label (l1); +gen_store_gpr (t0, rd); + +tcg_temp_free (t0); +tcg_temp_free (t1); +tcg_temp_free (t2); + } +break ; +case NM_MUL : +gen_r6_muldiv (ctx,R6_OPC_MUL , rd, rs, rt); +break ; +case NM_MUH : +gen_r6_muldiv (ctx,R6_OPC_MUH , rd, rs, rt); +break ; +case NM_MULU : +gen_r6_muldiv (ctx,R6_OPC_MULU , rd, rs, rt); +break ; +case NM_MUHU : +gen_r6_muldiv (ctx,R6_OPC_MUHU , rd, rs, rt); +break ; +case NM_DIV : +gen_r6_muldiv (ctx,R6_OPC_DIV , rd, rs, rt); +break ; +case NM_MOD : +gen_r6_muldiv (ctx,R6_OPC_MOD , rd, rs, rt); +break ; +case NM_DIVU : +gen_r6_muldiv (ctx,R6_OPC_DIVU , rd, rs, rt); +break ; +case NM_MODU : +gen_r6_muldiv (ctx,R6_OPC_MODU , rd, rs, rt); +break ; +#ifndef CONFIG_USER_ONLY +case NM_MFC0 : +check_cp0_enabled (ctx); +if (rt ==0 ) { +/* Treat as NOP. */ +break ; + } +gen_mfc0 (ctx, cpu_gpr[rt], rs, (ctx->opcode >>11 ) &0x7 ); +break ; +case NM_MTC0 : +check_cp0_enabled (ctx); + { +TCGv t0 =tcg_temp_new (); + +gen_load_gpr (t0, rt); +gen_mtc0 (ctx, t0, rs, (ctx->opcode >>11 ) &0x7 ); +tcg_temp_free (t0); + } +break ; +#endif +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +} +static void gen_pool32f_nanomips_insn (DisasContext *ctx) {int rt, rs, rd;
@@ -16677,6 +16857,16 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_POOL32A : +switch (ctx->opcode &0x07 ) { +case NM_POOL32A0 : +gen_pool32a0_nanomips_insn (ctx); +break ; +case NM_POOL32A7 : +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + }break ;case NM_P_GP_W :switch (ctx->opcode &0x03 ) {
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 11/35] target/mips: Add nanoMIPS pool32a0 instructions
Quoted 12 lines · Yongbok Kim
target/mips/translate.c +12
-0+case NM_SOV : + { +TCGv t0 =tcg_temp_local_new (); +TCGv t1 =tcg_temp_new (); +TCGv t2 =tcg_temp_new (); +TCGLabel *l1 =gen_new_label (); + +gen_load_gpr (t1, rs); +gen_load_gpr (t2, rt); +tcg_gen_add_tl (t0, t1, t2); +tcg_gen_ext32s_tl (t0, t0); +tcg_gen_xor_tl (t1, t1, t2);
target/mips/translate.c static void gen_pool16c_nanomips_insn(DisasContext *ctx) · line 16439
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_xor_tl (t2, t0, t2); +tcg_gen_andc_tl (t1, t2, t1); + +tcg_gen_movi_tl (t0,0 ); +tcg_gen_brcondi_tl (TCG_COND_GE , t1,0 , l1); +/* operands of same sign, result different sign */ + +tcg_gen_movi_tl (t0,1 ); +gen_set_label (l1); +gen_store_gpr (t0, rd);
No need for branch. This is just extracting the sign bit, so
tcg_gen_shri_tl(t0, t1, TARGET_LONG_BITS - 1);
r~
PATCH 12/35 target/mips: Add nanoMIPS pool32axf instructions
In reply to Yongbok KimAdd nanoMIPS pool32axf instructions
--- target/mips/translate.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
target/mips/translate.c +94 -0
@@ -16493,6 +16493,93 @@ static void gen_pool32a0_nanomips_insn(DisasContext *ctx) } } +static void gen_pool32axf_nanomips_insn (CPUMIPSState *env,DisasContext *ctx) +{ +int rt = (ctx->opcode >>21 ) &0x1f ; +int rs = (ctx->opcode >>16 ) &0x1f ; + +switch ((ctx->opcode >>6 ) &0x07 ) { +case NM_POOL32AXF_4 : +case NM_POOL32AXF_5 : +switch ((ctx->opcode >>9 ) &0x7f ) { +case NM_CLO : +gen_cl (ctx,OPC_CLO , rt, rs); +break ; +case NM_CLZ : +gen_cl (ctx,OPC_CLZ , rt, rs); +break ; +#ifndef CONFIG_USER_ONLY +case NM_TLBP : +gen_cp0 (env, ctx,OPC_TLBP ,0 ,0 ); +break ; +case NM_TLBR : +gen_cp0 (env, ctx,OPC_TLBR ,0 ,0 ); +break ; +case NM_TLBWI : +gen_cp0 (env, ctx,OPC_TLBWI ,0 ,0 ); +break ; +case NM_TLBWR : +gen_cp0 (env, ctx,OPC_TLBWR ,0 ,0 ); +break ; +case NM_TLBINV : +gen_cp0 (env, ctx,OPC_TLBINV ,0 ,0 ); +break ; +case NM_TLBINVF : +gen_cp0 (env, ctx,OPC_TLBINVF ,0 ,0 ); +break ; +case NM_DI : +check_cp0_enabled (ctx); + { +TCGv t0 =tcg_temp_new (); + +save_cpu_state (ctx,1 ); +gen_helper_di (t0, cpu_env); +gen_store_gpr (t0, rt); +/* Stop translation as we may have switched the execution mode */ + ctx->base.is_jmp =DISAS_STOP ; +tcg_temp_free (t0); + } +break ; +case NM_EI : +check_cp0_enabled (ctx); + { +TCGv t0 =tcg_temp_new (); + +save_cpu_state (ctx,1 ); +gen_helper_ei (t0, cpu_env); +gen_store_gpr (t0, rt); +/* Stop translation as we may have switched the execution mode */ + ctx->base.is_jmp =DISAS_STOP ; +tcg_temp_free (t0); + } +break ; +case NM_RDPGPR : +gen_load_srsgpr (rs, rt); +break ; +case NM_WRPGPR : +gen_store_srsgpr (rs, rt); +break ; +case NM_WAIT : +gen_cp0 (env, ctx,OPC_WAIT ,0 ,0 ); +break ; +case NM_DERET : +gen_cp0 (env, ctx,OPC_DERET ,0 ,0 ); +break ; +case NM_ERETX : +gen_cp0 (env, ctx,OPC_ERET ,0 ,0 ); +break ; +#endif +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +} +static void gen_pool32f_nanomips_insn (DisasContext *ctx) {int rt, rs, rd;
@@ -16862,6 +16949,13 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)gen_pool32a0_nanomips_insn (ctx);break ;case NM_POOL32A7 : + { +switch ((ctx->opcode >>3 ) &0x07 ) { +case NM_POOL32AXF : +gen_pool32axf_nanomips_insn (env, ctx); +break ; + } + }break ;default :generate_exception_end (ctx,EXCP_RI );
Signature · 1 line
1.9.1
PATCH 13/35 target/mips: Update gen_flt_ldst()
In reply to Yongbok KimUpdate gen_flt_ldst() in order to reuse the functions for nanoMIPS
--- target/mips/translate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
target/mips/translate.c +7 -8
@@ -2433,11 +2433,8 @@ static void gen_st_cond (DisasContext *ctx, uint32_t opc, int rt,/* Load and store */ static void gen_flt_ldst (DisasContext *ctx,uint32_t opc,int ft, -int base,int16_t offset) +TCGv t0) { -TCGv t0 =tcg_temp_new (); - -gen_base_offset_addr (ctx, t0, base, offset);/* Don't do NOP if destination is zero: we must perform the actual memory access. */ switch (opc) {
@@ -2480,15 +2477,15 @@ static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,default :MIPS_INVAL ("flt_ldst" );generate_exception_end (ctx,EXCP_RI ); - goto out; +break ; } - out: -tcg_temp_free (t0); }static void gen_cop1_ldst (DisasContext *ctx,uint32_t op,int rt,int rs,int16_t imm) { +TCGv t0 =tcg_temp_new (); +if (ctx->CP0_Config1 & (1 <<CP0C1_FP )) {check_cp1_enabled (ctx);switch (op) {
@@ -2497,11 +2494,13 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,check_insn (ctx,ISA_MIPS2 );/* Fallthrough */ default : -gen_flt_ldst (ctx, op, rt, rs, imm); +gen_base_offset_addr (ctx, t0, rs, imm); +gen_flt_ldst (ctx, op, rt, t0); } }else {generate_exception_err (ctx, EXCP_CpU,1 ); } +tcg_temp_free (t0); }/* Arithmetic with immediate operand */
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 13/35] target/mips: Update gen_flt_ldst()
Quoted 3 lines · Yongbok Kim
Update
gen_flt_ldst()in order to reuse the functions for nanoMIPSSigned-off-by Yongbok Kim <[email protected]>
Quoted 56 lines
--- target/mips/translate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)target/mips/translate.c +7
-8@@ -2433,11 +2433,8 @@ static void gen_st_cond (DisasContext *ctx, uint32_t opc, int rt,/* Load and store */ static void gen_flt_ldst (DisasContext *ctx,uint32_t opc,int ft, -int base,int16_t offset) +TCGv t0) { -TCGv t0 =tcg_temp_new (); - -gen_base_offset_addr (ctx, t0, base, offset);/* Don't do NOP if destination is zero: we must perform the actual memory access. */ switch (opc) {@@ -2480,15 +2477,15 @@ static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,default :MIPS_INVAL ("flt_ldst" );generate_exception_end (ctx,EXCP_RI ); - goto out; +break ; } - out: -tcg_temp_free (t0); }static void gen_cop1_ldst (DisasContext *ctx,uint32_t op,int rt,int rs,int16_t imm) { +TCGv t0 =tcg_temp_new (); +if (ctx->CP0_Config1 & (1 <<CP0C1_FP )) {check_cp1_enabled (ctx);switch (op) {@@ -2497,11 +2494,13 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,check_insn (ctx,ISA_MIPS2 );/* Fallthrough */ default : -gen_flt_ldst (ctx, op, rt, rs, imm); +gen_base_offset_addr (ctx, t0, rs, imm); +gen_flt_ldst (ctx, op, rt, t0); } }else {generate_exception_err (ctx, EXCP_CpU,1 ); } +tcg_temp_free (t0); }/* Arithmetic with immediate operand */
Re: [Qemu-devel] [PATCH 13/35] target/mips: Update gen_flt_ldst()
In reply to Yongbok KimQuoted 5 lines
From: Yongbok Kim <[email protected]>
Update
gen_flt_ldst()in order to reuse the functions for nanoMIPSSigned-off-by Yongbok Kim <[email protected]>
Quoted 57 lines
--- target/mips/translate.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)target/mips/translate.c +7
-9@@ -2433,11 +2433,8 @@ static void gen_st_cond (DisasContext *ctx, uint32_t opc, int rt,/* Load and store */ static void gen_flt_ldst (DisasContext *ctx,uint32_t opc,int ft, -int base,int16_t offset) +TCGv t0) { -TCGv t0 =tcg_temp_new (); - -gen_base_offset_addr (ctx, t0, base, offset);/* Don't do NOP if destination is zero: we must perform the actual memory access. */ switch (opc) {@@ -2480,15 +2477,15 @@ static void gen_flt_ldst (DisasContext *ctx, uint32_t opc, int ft,default :MIPS_INVAL ("flt_ldst" );generate_exception_end (ctx,EXCP_RI ); - goto out; +break ; } - out: -tcg_temp_free (t0); }static void gen_cop1_ldst (DisasContext *ctx,uint32_t op,int rt,int rs,int16_t imm) { +TCGv t0 =tcg_temp_new (); +if (ctx->CP0_Config1 & (1 <<CP0C1_FP )) {check_cp1_enabled (ctx);switch (op) {@@ -2497,11 +2494,13 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,check_insn (ctx,ISA_MIPS2 );/* Fallthrough */ default : -gen_flt_ldst (ctx, op, rt, rs, imm); +gen_base_offset_addr (ctx, t0, rs, imm); +gen_flt_ldst (ctx, op, rt, t0); } }else {generate_exception_err (ctx, EXCP_CpU,1 ); } +tcg_temp_free (t0); }/* Arithmetic with immediate operand */ --1.9.1
PATCH 14/35 target/mips: Add nanoMIPS p_lsx instructions
In reply to Yongbok KimAdd nanoMIPS p_lsx and LSA instructions
--- target/mips/translate.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-)
target/mips/translate.c +138 -1
@@ -16579,6 +16579,132 @@ static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) } } + +static void gen_p_lsx (DisasContext *ctx,int rd,int rs,int rt) +{ +TCGv t0, t1; + t0 =tcg_temp_new (); + t1 =tcg_temp_new (); +tcg_gen_movi_tl (t1,0 ); +if (rs ==0 ) { +tcg_gen_movi_tl (t0,0 ); + }else { +gen_load_gpr (t0, rs); + } +if (rt ==0 ) { +tcg_gen_movi_tl (t1,0 ); + }else { +gen_load_gpr (t1, rt); + } +if (((ctx->opcode >>6 ) &1 ) ==1 ) { +/* PP.LSXS instructions require shifting */ +switch ((ctx->opcode >>7 ) &0xf ) { +case NM_LHXS : +case NM_SHXS : +case NM_LHUXS : +tcg_gen_shli_tl (t0, t0,1 ); +break ; +case NM_LWXS : +case NM_SWXS : +case NM_LWC1XS : +case NM_SWC1XS : +tcg_gen_shli_tl (t0, t0,2 ); +break ; +case NM_LDC1XS : +case NM_SDC1XS : +tcg_gen_shli_tl (t0, t0,3 ); +break ; + } + } +gen_op_addr_add (ctx, t0, t0, t1); + +switch ((ctx->opcode >>7 ) &0xf ) { +case NM_LBX : +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_SB ); +gen_store_gpr (t0, rd); +break ; +case NM_LHX : +/*case NM_LHXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TESW ); +gen_store_gpr (t0, rd); +break ; +case NM_LWX : +/*case NM_LWXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TESL ); +gen_store_gpr (t0, rd); +break ; +case NM_LBUX : +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_UB ); +gen_store_gpr (t0, rd); +break ; +case NM_LHUX : +/*case NM_LHUXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TEUW ); +gen_store_gpr (t0, rd); +break ; +case NM_SBX : +gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_8 ); +break ; +case NM_SHX : +/*case NM_SHXS:*/ +gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_TEUW ); +break ; +case NM_SWX : +/*case NM_SWXS:*/ +gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_TEUL ); +break ; +case NM_LWC1X : +/*case NM_LWC1XS:*/ +case NM_LDC1X : +/*case NM_LDC1XS:*/ +case NM_SWC1X : +/*case NM_SWC1XS:*/ +case NM_SDC1X : +/*case NM_SDC1XS:*/ +if (ctx->CP0_Config1 & (1 <<CP0C1_FP )) { +check_cp1_enabled (ctx); +switch ((ctx->opcode >>7 ) &0xf ) { +case NM_LWC1X : +/*case NM_LWC1XS:*/ +gen_flt_ldst (ctx,OPC_LWC1 , rd, t0); +break ; +case NM_LDC1X : +/*case NM_LDC1XS:*/ +gen_flt_ldst (ctx,OPC_LDC1 , rd, t0); +break ; +case NM_SWC1X : +/*case NM_SWC1XS:*/ +gen_flt_ldst (ctx,OPC_SWC1 , rd, t0); +break ; +case NM_SDC1X : +/*case NM_SDC1XS:*/ +gen_flt_ldst (ctx,OPC_SDC1 , rd, t0); +break ; + } + }else { +generate_exception_err (ctx, EXCP_CpU,1 ); + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + +tcg_temp_free (t0); +tcg_temp_free (t1); +} +static void gen_pool32f_nanomips_insn (DisasContext *ctx) {int rt, rs, rd;
@@ -16881,7 +17007,7 @@ static void gen_pool32f_nanomips_insn(DisasContext *ctx)static int decode_nanomips_32_48_opc (CPUMIPSState *env,DisasContext *ctx) {uint16_t insn; -int rt, rs; +int rt, rs, rd;uint32_t op; insn =cpu_lduw_code (env, ctx->base.pc_next +2 );
@@ -16889,6 +17015,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) rt = (ctx->opcode >>21 ) &0x1f ; rs = (ctx->opcode >>16 ) &0x1f ; + rd = (ctx->opcode >>11 ) &0x1f ; op = (ctx->opcode >>26 ) &0x3f ;switch (op) {
@@ -16950,6 +17077,16 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)case NM_POOL32A7 : {switch ((ctx->opcode >>3 ) &0x07 ) { +case NM_P_LSX : +gen_p_lsx (ctx, rd, rs, rt); +break ; +case NM_LSA : +/* In nanoMIPS, the shift field directly encodes the shift +* amount, meaning that the supported shift values are in +* the range 0 to 3 (instead of 1 to 4 in MIPSR6). */ +gen_lsa (ctx,OPC_LSA , rd, rs, rt, +extract32 (ctx->opcode,9 ,2 ) -1 ); +break ;case NM_POOL32AXF :gen_pool32axf_nanomips_insn (env, ctx);break ;
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 14/35] target/mips: Add nanoMIPS p_lsx instructions
Quoted 17 lines · Yongbok Kim
Add nanoMIPS
p_lsxand LSA instructionsSigned-off-by Yongbok Kim <[email protected]>--- target/mips/translate.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-)target/mips/translate.c +2
-0@@ -16579,6 +16579,132 @@ static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) } } + +static void gen_p_lsx (DisasContext *ctx,int rd,int rs,int rt)
target/mips/translate.c static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) · line 16593
Quoted 10 lines
target/mips/translate.c +10
-0+{ +TCGv t0, t1; + t0 =tcg_temp_new (); + t1 =tcg_temp_new (); +tcg_gen_movi_tl (t1,0 ); +if (rs ==0 ) { +tcg_gen_movi_tl (t0,0 ); + }else { +gen_load_gpr (t0, rs); + }
gen_load_gpr already does exactly this == 0 test.
Quoted 10 lines
target/mips/translate.c +10
-0+if (((ctx->opcode >>6 ) &1 ) ==1 ) { +/* PP.LSXS instructions require shifting */ +switch ((ctx->opcode >>7 ) &0xf ) { +case NM_LHXS : +case NM_SHXS : +case NM_LHUXS : +tcg_gen_shli_tl (t0, t0,1 ); +break ; +case NM_LWXS : +case NM_SWXS :
target/mips/translate.c static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) · line 16618
Quoted 10 lines
target/mips/translate.c +10
-0+case NM_LWC1XS : +case NM_SWC1XS : +tcg_gen_shli_tl (t0, t0,2 ); +break ; +case NM_LDC1XS : +case NM_SDC1XS : +tcg_gen_shli_tl (t0, t0,3 ); +break ; + } + }
If you would set a TCGMemOp mop variable in the first switch, then the shift is
tcg_gen_shli_tl(t0, t0, mop * MO_SIZE);
Quoted 19 lines
target/mips/translate.c +19
-0+switch ((ctx->opcode >>7 ) &0xf ) { +case NM_LBX : +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_SB ); +gen_store_gpr (t0, rd); +break ; +case NM_LHX : +/*case NM_LHXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TESW ); +gen_store_gpr (t0, rd); +break ; +case NM_LWX : +/*case NM_LWXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TESL ); +gen_store_gpr (t0, rd); +break ; +case NM_LBUX :
target/mips/translate.c static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) · line 16649
Quoted 10 lines
target/mips/translate.c +10
-0+tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_UB ); +gen_store_gpr (t0, rd); +break ; +case NM_LHUX : +/*case NM_LHUXS:*/ +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx, +MO_TEUW ); +gen_store_gpr (t0, rd); +break ;
And all of these cases unify to
tcg_gen_qemu_ld_tl(t0, t0, ctx->mem_idx, mop);
Quoted 7 lines
target/mips/translate.c +7
-0+case NM_SBX : +gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_8 ); +break ; +case NM_SHX : +/*case NM_SHXS:*/
target/mips/translate.c static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) · line 16666
Quoted 10 lines
target/mips/translate.c +10
-0+gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_TEUW ); +break ; +case NM_SWX : +/*case NM_SWXS:*/ +gen_load_gpr (t1, rd); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx, +MO_TEUL ); +break ;
As do these.
r~
PATCH 15/35 target/mips: Implement nanoMIPS EXTW instruction
In reply to Yongbok KimFrom: James Hogan <[email protected]>
Implement the nanoMIPS EXTW instruction, which is similar to the MIPS r6 ALIGN instruction except that it counts the other way and in bits instead of bytes. We therefore generalise gen_align() into gen_align_bits() (which counts in bits instead of bytes and optimises when bits = size of the word), and implement gen_align() and a new gen_ext() based on that. Since we need to know the word size to check for when the number of bits == the word size, the opc argument is replaced with a wordsz argument (either 32 or 64).
--- target/mips/translate.c | 53 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-)
target/mips/translate.c +36 -17
@@ -4723,8 +4723,8 @@ static void gen_lsa(DisasContext *ctx, int opc, int rd, int rs, int rt,return ; } -static void gen_align (DisasContext *ctx,int opc,int rd,int rs,int rt, -int bp) +static void gen_align_bits (DisasContext *ctx,int wordsz,int rd,int rs, +int rt,int bits) {TCGv t0;if (rd ==0 ) {
@@ -4732,35 +4732,40 @@ static void gen_align(DisasContext *ctx, int opc, int rd, int rs, int rt,return ; } t0 =tcg_temp_new (); -gen_load_gpr (t0, rt); -if (bp ==0 ) { -switch (opc) { -case OPC_ALIGN : +if (bits ==0 || bits == wordsz) { +if (bits ==0 ) { +gen_load_gpr (t0, rt); + }else { +gen_load_gpr (t0, rs); + } +switch (wordsz) { +case 32 :tcg_gen_ext32s_tl (cpu_gpr[rd], t0);break ;#if defined(TARGET_MIPS64 ) -case OPC_DALIGN : +case 64 :tcg_gen_mov_tl (cpu_gpr[rd], t0);break ;#endif } }else {TCGv t1 =tcg_temp_new (); +gen_load_gpr (t0, rt);gen_load_gpr (t1, rs); -switch (opc) { -case OPC_ALIGN : +switch (wordsz) { +case 32 : {TCGv_i64 t2 =tcg_temp_new_i64 ();tcg_gen_concat_tl_i64 (t2, t1, t0); -tcg_gen_shri_i64 (t2, t2,8 * (4 - bp)); +tcg_gen_shri_i64 (t2, t2,32 - bits);gen_move_low32 (cpu_gpr[rd], t2);tcg_temp_free_i64 (t2); }break ;#if defined(TARGET_MIPS64 ) -case OPC_DALIGN : -tcg_gen_shli_tl (t0, t0,8 * bp); -tcg_gen_shri_tl (t1, t1,8 * (8 - bp)); +case 64 : +tcg_gen_shli_tl (t0, t0, bits); +tcg_gen_shri_tl (t1, t1,64 - bits);tcg_gen_or_tl (cpu_gpr[rd], t1, t0);break ;#endif
@@ -4771,6 +4776,18 @@ static void gen_align(DisasContext *ctx, int opc, int rd, int rs, int rt,tcg_temp_free (t0); } +static void gen_align (DisasContext *ctx,int wordsz,int rd,int rs,int rt, +int bp) +{ +gen_align_bits (ctx, wordsz, rd, rs, rt, bp *8 ); +} + +static void gen_ext (DisasContext *ctx,int wordsz,int rd,int rs,int rt, +int shift) +{ +gen_align_bits (ctx, wordsz, rd, rs, rt, wordsz - shift); +} +static void gen_bitswap (DisasContext *ctx,int opc,int rd,int rt) {TCGv t0;
@@ -14118,8 +14135,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)break ;case ALIGN :check_insn (ctx,ISA_MIPS32R6 ); -gen_align (ctx,OPC_ALIGN , rd, rs, rt, -extract32 (ctx->opcode,9 ,2 )); +gen_align (ctx,32 , rd, rs, rt,extract32 (ctx->opcode,9 ,2 ));break ;case EXT :gen_bitops (ctx,OPC_EXT , rt, rs, rr, rd);
@@ -17087,6 +17103,9 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)gen_lsa (ctx,OPC_LSA , rd, rs, rt,extract32 (ctx->opcode,9 ,2 ) -1 );break ; +case NM_EXTW : +gen_ext (ctx,32 , rd, rs, rt,extract32 (ctx->opcode,6 ,5 )); +break ;case NM_POOL32AXF :gen_pool32axf_nanomips_insn (env, ctx);break ;
@@ -19939,7 +19958,7 @@ static void decode_opc_special3_r6(CPUMIPSState *env, DisasContext *ctx) op2 =MASK_BSHFL (ctx->opcode);switch (op2) { case OPC_ALIGN ... OPC_ALIGN_END: -gen_align (ctx,OPC_ALIGN , rd, rs, rt, sa &3 ); +gen_align (ctx,32 , rd, rs, rt, sa &3 );break ;case OPC_BITSWAP :gen_bitswap (ctx, op2, rd, rt);
@@ -19964,7 +19983,7 @@ static void decode_opc_special3_r6(CPUMIPSState *env, DisasContext *ctx) op2 =MASK_DBSHFL (ctx->opcode);switch (op2) { case OPC_DALIGN ... OPC_DALIGN_END: -gen_align (ctx,OPC_DALIGN , rd, rs, rt, sa &7 ); +gen_align (ctx,64 , rd, rs, rt, sa &7 );break ;case OPC_DBITSWAP :gen_bitswap (ctx, op2, rd, rt);
Signature · 1 line
1.9.1
PATCH 16/35 target/mips: Add has_isa_mode
In reply to Yongbok KimFrom: Matthew Fortune <[email protected]>
ISA mode bit (LSB of address) is no longer required but is also masked to allow for tools transition.
--- target/mips/translate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target/mips/translate.c +6 -3
@@ -1458,6 +1458,7 @@ typedef struct DisasContext {bool mrp;bool nan2008;bool abs2008; +bool has_isa_mode; } DisasContext;#define DISAS_STOP DISAS_TARGET_0
@@ -4538,7 +4539,7 @@ static void gen_compute_branch (DisasContext *ctx, uint32_t opc,if (blink >0 ) {int post_delay = insn_bytes + delayslot_size; -int lowbit = !!(ctx->hflags &MIPS_HFLAG_M16 ); +int lowbit = ctx->has_isa_mode && !!(ctx->hflags &MIPS_HFLAG_M16 );tcg_gen_movi_tl (cpu_gpr[blink], ctx->base.pc_next + post_delay + lowbit);
@@ -10876,7 +10877,8 @@ static void gen_branch(DisasContext *ctx, int insn_bytes)break ;case MIPS_HFLAG_BR :/* unconditional branch to register */ -if (ctx->insn_flags & (ASE_MIPS16 |ASE_MICROMIPS )) { +if (ctx->has_isa_mode && + (ctx->insn_flags & (ASE_MIPS16 |ASE_MICROMIPS ))) {TCGv t0 =tcg_temp_new ();TCGv_i32 t1 =tcg_temp_new_i32 ();
@@ -10912,7 +10914,7 @@ static void gen_compute_compact_branch(DisasContext *ctx, uint32_t opc,int bcond_compute =0 ;TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new (); -int m16_lowbit = (ctx->hflags &MIPS_HFLAG_M16 ) !=0 ; +int m16_lowbit = ctx->has_isa_mode && ((ctx->hflags &MIPS_HFLAG_M16 ) !=0 );if (ctx->hflags &MIPS_HFLAG_BMASK ) {#ifdef MIPS_DEBUG_DISAS
@@ -22476,6 +22478,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->mrp = (env->CP0_Config5 >>CP0C5_MRP ) &1 ; ctx->nan2008 = (env->active_fpu.fcr31 >>FCR31_NAN2008 ) &1 ; ctx->abs2008 = (env->active_fpu.fcr31 >>FCR31_ABS2008 ) &1 ; + ctx->has_isa_mode = ((env->CP0_Config3 >>CP0C3_MMAR ) &0x7 ) !=3 ;restore_cpu_state (env, ctx);#ifdef CONFIG_USER_ONLY ctx->mem_idx =MIPS_HFLAG_UM ;
Signature · 1 line
1.9.1
PATCH 17/35 target/mips: Add nanoMIPS load store instructions
In reply to Yongbok KimAdd nanoMIPS load and store instructions
--- target/mips/translate.c | 271 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+)
target/mips/translate.c +271 -0
@@ -17379,10 +17379,281 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P_GP_BH : + { +uint32_t u =extract32 (ctx->opcode,0 ,18 ); +switch ((ctx->opcode >>18 ) &0x7 ) { +case NM_LBGP : +gen_ld (ctx,OPC_LB , rt,28 , u); +break ; +case NM_SBGP : +gen_st (ctx,OPC_SB , rt,28 , u); +break ; +case NM_LBUGP : +gen_ld (ctx,OPC_LBU , rt,28 , u); +break ; +case NM_ADDIUGP_B : +gen_arith_imm (ctx,OPC_ADDIU , rt,28 , u); +break ; +case NM_P_GP_LH : + u &= ~1 ; +switch (ctx->opcode &1 ) { +case NM_LHGP : +gen_ld (ctx,OPC_LH , rt,28 , u); +break ; +case NM_LHUGP : +gen_ld (ctx,OPC_LHU , rt,28 , u); +break ; + } +break ; +case NM_P_GP_SH : + u &= ~1 ; +switch (ctx->opcode &1 ) { +case NM_SHGP : +gen_st (ctx,OPC_SH , rt,28 , u); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_P_GP_CP1 : + u &= ~0x3 ; +switch ((ctx->opcode &0x3 )) { +case NM_LWC1GP : +gen_cop1_ldst (ctx,OPC_LWC1 , rt,28 , u); +break ; +case NM_LDC1GP : +gen_cop1_ldst (ctx,OPC_LDC1 , rt,28 , u); +break ; +case NM_SWC1GP : +gen_cop1_ldst (ctx,OPC_SWC1 , rt,28 , u); +break ; +case NM_SDC1GP : +gen_cop1_ldst (ctx,OPC_SDC1 , rt,28 , u); +break ; + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_P_LS_U12 : + { +uint32_t u =extract32 (ctx->opcode,0 ,12 ); +switch ((ctx->opcode >>12 ) &0x0f ) { +case NM_P_PREFU12 : +if (rt ==31 ) { +/* SYNCI */ +/* Break the TB to be able to sync copied instructions +immediately */ + ctx->base.is_jmp =DISAS_STOP ; + }else { +/* PREF */ +/* Treat as NOP. */ + } +break ; +case NM_LB : +gen_ld (ctx,OPC_LB , rt, rs, u); +break ; +case NM_LH : +gen_ld (ctx,OPC_LH , rt, rs, u); +break ; +case NM_LW : +gen_ld (ctx,OPC_LW , rt, rs, u); +break ; +case NM_LBU : +gen_ld (ctx,OPC_LBU , rt, rs, u); +break ; +case NM_LHU : +gen_ld (ctx,OPC_LHU , rt, rs, u); +break ; +case NM_SB : +gen_st (ctx,OPC_SB , rt, rs, u); +break ; +case NM_SH : +gen_st (ctx,OPC_SH , rt, rs, u); +break ; +case NM_SW : +gen_st (ctx,OPC_SW , rt, rs, u); +break ; +case NM_LWC1 : +gen_cop1_ldst (ctx,OPC_LWC1 , rt, rs, u); +break ; +case NM_LDC1 : +gen_cop1_ldst (ctx,OPC_LDC1 , rt, rs, u); +break ; +case NM_SWC1 : +gen_cop1_ldst (ctx,OPC_SWC1 , rt, rs, u); +break ; +case NM_SDC1 : +gen_cop1_ldst (ctx,OPC_SDC1 , rt, rs, u); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_P_LS_S9 : + { +int32_t s = (sextract32 (ctx->opcode,15 ,1 ) <<8 ) | +extract32 (ctx->opcode,0 ,8 ); +switch ((ctx->opcode >>8 ) &0x07 ) { +case NM_P_LS_S0 : +switch ((ctx->opcode >>11 ) &0x0f ) { +case NM_LBS9 : +gen_ld (ctx,OPC_LB , rt, rs, s); +break ; +case NM_LHS9 : +gen_ld (ctx,OPC_LH , rt, rs, s); +break ; +case NM_LWS9 : +gen_ld (ctx,OPC_LW , rt, rs, s); +break ; +case NM_LBUS9 : +gen_ld (ctx,OPC_LBU , rt, rs, s); +break ; +case NM_LHUS9 : +gen_ld (ctx,OPC_LHU , rt, rs, s); +break ; +case NM_SBS9 : +gen_st (ctx,OPC_SB , rt, rs, s); +break ; +case NM_SHS9 : +gen_st (ctx,OPC_SH , rt, rs, s); +break ; +case NM_SWS9 : +gen_st (ctx,OPC_SW , rt, rs, s); +break ; +case NM_LWC1S9 : +gen_cop1_ldst (ctx,OPC_LWC1 , rt, rs, s); +break ; +case NM_LDC1S9 : +gen_cop1_ldst (ctx,OPC_LDC1 , rt, rs, s); +break ; +case NM_SWC1S9 : +gen_cop1_ldst (ctx,OPC_SWC1 , rt, rs, s); +break ; +case NM_SDC1S9 : +gen_cop1_ldst (ctx,OPC_SDC1 , rt, rs, s); +break ; +case NM_P_PREFS9 : +if (rt ==31 ) { +/* SYNCI */ +/* Break the TB to be able to sync copied instructions +immediately */ + ctx->base.is_jmp =DISAS_STOP ; + }else { +/* PREF */ +/* Treat as NOP. */ + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } +break ; +case NM_P_LS_S1 : +switch ((ctx->opcode >>11 ) &0x0f ) { +case NM_UALH : +case NM_UASH : + { +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); + +gen_base_offset_addr (ctx, t0, rs, s); + +switch ((ctx->opcode >>11 ) &0x0f ) { +case NM_UALH : +tcg_gen_qemu_ld_tl (t0, t0, ctx->mem_idx,MO_TESW | +MO_UNALN ); +gen_store_gpr (t0, rt); +break ; +case NM_UASH : +gen_load_gpr (t1, rt); +tcg_gen_qemu_st_tl (t1, t0, ctx->mem_idx,MO_TEUW | +MO_UNALN ); +break ; + } +tcg_temp_free (t0); +tcg_temp_free (t1); + } +break ; +case NM_P_LL : +switch (ctx->opcode &0x03 ) { +case NM_LL : +gen_ld (ctx,OPC_LL , rt, rs, s); +break ; +case NM_LLWP : +break ; + } +break ; +case NM_P_SC : +switch (ctx->opcode &0x03 ) { +case NM_SC : +gen_st_cond (ctx,OPC_SC , rt, rs, s); +break ; +case NM_SCWP : +break ; + } +break ; +case NM_CACHE : +check_cp0_enabled (ctx); +if (ctx->hflags &MIPS_HFLAG_ITC_CACHE ) { +gen_cache_operation (ctx, rt, rs, s); + } +break ; + } +break ; +case NM_P_LS_WM : +case NM_P_LS_UAWM : + { +int32_t offset =sextract32 (ctx->opcode,15 ,1 ) <<8 | +extract32 (ctx->opcode,0 ,8 ); +int count =extract32 (ctx->opcode,12 ,3 ); +int counter =0 ; +TCGv va =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); +TCGMemOp memop = ((ctx->opcode >>8 ) &0x07 ) ==NM_P_LS_UAWM ? +MO_UNALN :0 ; + + count = (count ==0 ) ?8 : count; +while (counter != count) { +int this_rt = ((rt + counter) &0x1f ) | (rt &0x10 ); +int32_t this_offset = offset + (counter <<2 ); + +gen_base_offset_addr (ctx, va, rs, this_offset); + +switch (extract32 (ctx->opcode,11 ,1 )) { +case NM_LWM : +tcg_gen_qemu_ld_tl (t1, va, ctx->mem_idx, + memop |MO_TESL ); +gen_store_gpr (t1, this_rt); +if ((this_rt == rs) && + (counter != (count -1 ))) { +/* UNPREDICTABLE */ + } +break ; +case NM_SWM : + this_rt = (rt ==0 ) ?0 : this_rt; +gen_load_gpr (t1, this_rt); +tcg_gen_qemu_st_tl (t1, va, ctx->mem_idx, + memop |MO_TEUL ); +break ; + } + counter++; + } +tcg_temp_free (va); +tcg_temp_free (t1); + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_MOVE_BALC :break ;
Signature · 1 line
1.9.1
PATCH 18/35 target/mips: Add nanoMIPS branch instructions
In reply to Yongbok KimAdd nanoMIPS branch instructions
--- target/mips/translate.c | 277 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+)
target/mips/translate.c +277 -0
@@ -16597,6 +16597,168 @@ static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) } } +/* Immediate Value Compact Branches */ +static void gen_compute_imm_branch (DisasContext *ctx,uint32_t opc, +int rt,int32_t imm,int32_t offset) +{ +int bcond_compute =0 ; +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); + +if (ctx->hflags &MIPS_HFLAG_BMASK ) { +#ifdef MIPS_DEBUG_DISAS +LOG_DISAS ("Branch in delay / forbidden slot at PC 0x" TARGET_FMT_lx +"\n" , ctx->base.pc_next); +#endif +generate_exception_end (ctx,EXCP_RI ); + goto out; + } + +gen_load_gpr (t0, rt); +tcg_gen_movi_tl (t1, imm); + ctx->btarget =addr_add (ctx, ctx->base.pc_next +4 , offset); + +/* Load needed operands and calculate btarget */ +switch (opc) { +case NM_BEQIC : +if (rt ==0 && imm ==0 ) { +/* Unconditional branch */ + }else if (rt ==0 && imm !=0 ) { +/* Treat as NOP */ + goto out; + }else { + bcond_compute =1 ; + } +break ; +case NM_BBEQZC : +case NM_BBNEZC : +if (imm >=32 && !(ctx->hflags &MIPS_HFLAG_64 )) { +generate_exception_end (ctx,EXCP_RI ); + goto out; + }else if (rt ==0 && opc ==NM_BBEQZC ) { +/* Unconditional branch */ + }else if (rt ==0 && opc ==NM_BBNEZC ) { +/* Treat as NOP */ + goto out; + }else { +tcg_gen_shri_tl (t0, t0, imm); +tcg_gen_andi_tl (t0, t0,1 ); +tcg_gen_movi_tl (t1,0 ); + bcond_compute =1 ; + } +break ; +case NM_BNEIC : +if (rt ==0 && imm ==0 ) { +/* Treat as NOP */ + goto out; + }else if (rt ==0 && imm !=0 ) { +/* Unconditional branch */ + }else { + bcond_compute =1 ; + } +break ; +case NM_BGEIC : +if (rt ==0 && imm ==0 ) { +/* Unconditional branch */ + }else { + bcond_compute =1 ; + } +break ; +case NM_BLTIC : + bcond_compute =1 ; +break ; +case NM_BGEIUC : +if (rt ==0 && imm ==0 ) { +/* Unconditional branch */ + }else { + bcond_compute =1 ; + } +break ; +case NM_BLTIUC : + bcond_compute =1 ; +break ; +default : +MIPS_INVAL ("Immediate Value Compact branch" ); +generate_exception_end (ctx,EXCP_RI ); + goto out; + } + +if (bcond_compute ==0 ) { +/* Uncoditional compact branch */ + ctx->hflags |=MIPS_HFLAG_B ; +/* Generating branch here as compact branches don't have delay slot */ +gen_branch (ctx,4 ); + }else { +/* Conditional compact branch */ +TCGLabel *fs =gen_new_label (); +save_cpu_state (ctx,0 ); + +switch (opc) { +case NM_BEQIC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_EQ ), t0, t1, fs); +break ; +case NM_BBEQZC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_EQ ), t0, t1, fs); +break ; +case NM_BNEIC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_NE ), t0, t1, fs); +break ; +case NM_BBNEZC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_NE ), t0, t1, fs); +break ; +case NM_BGEIC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_GE ), t0, t1, fs); +break ; +case NM_BLTIC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_LT ), t0, t1, fs); +break ; +case NM_BGEIUC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_GEU ), t0, t1, fs); +break ; +case NM_BLTIUC : +tcg_gen_brcond_tl (tcg_invert_cond (TCG_COND_LTU ), t0, t1, fs); +break ; + } + +/* Generating branch here as compact branches don't have delay slot */ +gen_goto_tb (ctx,1 , ctx->btarget); +gen_set_label (fs); + + ctx->hflags |=MIPS_HFLAG_FBNSLOT ; + } + +out: +tcg_temp_free (t0); +tcg_temp_free (t1); +} + +/* P.BALRSC type nanoMIPS R6 branches: BALRSC and BRSC */ +static void gen_compute_nanomips_pbalrsc_branch (DisasContext *ctx,int rs, +int rt) +{ +TCGv t0 =tcg_temp_new (); +TCGv t1 =tcg_temp_new (); + +/* load rs */ +gen_load_gpr (t0, rs); + +/* link */ +if (rt !=0 ) { +tcg_gen_movi_tl (cpu_gpr[rt], ctx->base.pc_next +4 ); + } + +/* calculate btarget */ +tcg_gen_shli_tl (t0, t0,1 ); +tcg_gen_movi_tl (t1, ctx->base.pc_next +4 ); +gen_op_addr_add (ctx, btarget, t1, t0); + + ctx->hflags |=MIPS_HFLAG_BR ; +/* Generating branch here as compact branches don't have delay slot */ +gen_branch (ctx,4 ); + +tcg_temp_free (t0); +tcg_temp_free (t1); +}static void gen_p_lsx (DisasContext *ctx,int rd,int rs,int rt) {
@@ -17656,16 +17818,131 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_MOVE_BALC : + { +TCGv t0 =tcg_temp_new (); +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<21 | +extract32 (ctx->opcode,1 ,20 ) <<1 ; + rd = ((ctx->opcode >>24 ) &1 ) ==0 ?4 :5 ; + rt =mmreg4z_nanomips (extract32 (ctx->opcode,25 ,1 ) <<3 | +extract32 (ctx->opcode,21 ,3 )); +gen_load_gpr (t0, rt); +tcg_gen_mov_tl (cpu_gpr[rd], t0); +gen_compute_branch (ctx,OPC_BGEZAL ,4 ,0 ,0 , s,0 ); +tcg_temp_free (t0); + }break ;case NM_P_BAL : + { +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<25 | +extract32 (ctx->opcode,1 ,24 ) <<1 ; + +if (((ctx->opcode >>25 ) &1 ) ==0 ) { +/* BC */ +gen_compute_branch (ctx,OPC_BEQ ,4 ,0 ,0 , s,0 ); + }else { +/* BALC */ +gen_compute_branch (ctx,OPC_BGEZAL ,4 ,0 ,0 , s,0 ); + } + }break ;case NM_P_J : +switch ((ctx->opcode >>12 ) &0x0f ) { +case NM_JALRC : +case NM_JALRC_HB : +gen_compute_branch (ctx,OPC_JALR ,4 , rs, rt,0 ,0 ); +break ; +case NM_P_BALRSC : +gen_compute_nanomips_pbalrsc_branch (ctx, rs, rt); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + }break ;case NM_P_BR1 : + { +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<14 | +extract32 (ctx->opcode,1 ,13 ) <<1 ; +switch ((ctx->opcode >>14 ) &0x03 ) { +case NM_BEQC : +gen_compute_branch (ctx,OPC_BEQ ,4 , rs, rt, s,0 ); +break ; +case NM_P_BR3A : + { +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<14 | +extract32 (ctx->opcode,1 ,13 ) <<1 ; +check_cp1_enabled (ctx); +switch ((ctx->opcode >>16 ) &0x1f ) { +case NM_BC1EQZC : +gen_compute_branch1_r6 (ctx,OPC_BC1EQZ , rt, s,0 ); +break ; +case NM_BC1NEZC : +gen_compute_branch1_r6 (ctx,OPC_BC1NEZ , rt, s,0 ); +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + } +break ; +case NM_BGEC : +if (rs == rt) { +gen_compute_compact_branch (ctx,OPC_BC , rs, rt, s); + }else { +gen_compute_compact_branch (ctx,OPC_BGEC , rs, rt, s); + } +break ; +case NM_BGEUC : +if (rs == rt || rt ==0 ) { +gen_compute_compact_branch (ctx,OPC_BC ,0 ,0 , s); + }else if (rs ==0 ) { +gen_compute_compact_branch (ctx,OPC_BEQZC , rt,0 , s); + }else { +gen_compute_compact_branch (ctx,OPC_BGEUC , rs, rt, s); + } +break ; + } + }break ;case NM_P_BR2 : + { +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<14 | +extract32 (ctx->opcode,1 ,13 ) <<1 ; +switch ((ctx->opcode >>14 ) &0x03 ) { +case NM_BNEC : +gen_compute_branch (ctx,OPC_BNE ,4 , rs, rt, s,0 ); +break ; +case NM_BLTC : +if (rs !=0 && rt !=0 && rs == rt) { +/* NOP */ + ctx->hflags |=MIPS_HFLAG_FBNSLOT ; + }else { +gen_compute_compact_branch (ctx,OPC_BLTC , rs, rt, s); + } +break ; +case NM_BLTUC : +if (rs ==0 || rs == rt) { +/* NOP */ + ctx->hflags |=MIPS_HFLAG_FBNSLOT ; + }else { +gen_compute_compact_branch (ctx,OPC_BLTUC , rs, rt, s); + } +break ; +default : +generate_exception_end (ctx,EXCP_RI ); +break ; + } + }break ;case NM_P_BRI : + { +int32_t s =sextract32 (ctx->opcode,0 ,1 ) <<11 | +extract32 (ctx->opcode,1 ,10 ) <<1 ; +uint32_t u =extract32 (ctx->opcode,11 ,7 ); + +gen_compute_imm_branch (ctx,extract32 (ctx->opcode,18 ,3 ), + rt, u, s); + }break ;default :generate_exception_end (ctx,EXCP_RI );
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 18/35] target/mips: Add nanoMIPS branch instructions
target/mips/translate.c static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx) · line 16628
Quoted 5 lines · Yongbok Kim
target/mips/translate.c +5
-0+if (rt ==0 && imm ==0 ) { +/* Unconditional branch */ + }else if (rt ==0 && imm !=0 ) { +/* Treat as NOP */ + goto out;
Given that there is a different unconditional BC opcode, I would expect to never see rt=0 at all. There's no point in special casing it. And it would seem that all of the "goto out" cases miss setting MIPS_HFLAG_FBNSLOT.
r~
PATCH 19/35 target/mips: Implement nanoMIPS LLWP/SCWP pair
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Implement nanoMIPS LLWP and SCWP instruction pair.
--- linux-user/mips/cpu_loop.c | 25 ++++++++--- target/mips/cpu.h | 2 + target/mips/helper.h | 2 + target/mips/op_helper.c | 35 +++++++++++++++ target/mips/translate.c | 107 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 5 deletions(-)
linux-user/mips/cpu_loop.c +20 -5
@@ -397,10 +397,13 @@ static int do_store_exclusive(CPUMIPSState *env)target_ulong addr;target_ulong page_addr;target_ulong val; +uint32_t val_wp =0 ; +uint32_t llnewval_wp =0 ;int flags;int segv =0 ;int reg;int d; +int wp; addr = env->lladdr; page_addr = addr &TARGET_PAGE_MASK ;
@@ -412,19 +415,31 @@ static int do_store_exclusive(CPUMIPSState *env) }else { reg = env->llreg &0x1f ; d = (env->llreg &0x20 ) !=0 ; -if (d) { - segv =get_user_s64 (val, addr); + wp = (env->llreg &0x40 ) !=0 ; +if (!wp) { +if (d) { + segv =get_user_s64 (val, addr); + }else { + segv =get_user_s32 (val, addr); + } }else { segv =get_user_s32 (val, addr); + segv |=get_user_s32 (val_wp, addr); + llnewval_wp = env->llnewval_wp; }if (!segv) { -if (val != env->llval) { +if (val != env->llval && val_wp == llnewval_wp) { env->active_tc.gpr[reg] =0 ; }else { -if (d) { - segv =put_user_u64 (env->llnewval, addr); +if (!wp) { +if (d) { + segv =put_user_u64 (env->llnewval, addr); + }else { + segv =put_user_u32 (env->llnewval, addr); + } }else { segv =put_user_u32 (env->llnewval, addr); + segv |=put_user_u32 (env->llnewval_wp, addr +4 ); }if (!segv) { env->active_tc.gpr[reg] =1 ;
target/mips/cpu.h +2 -0
@@ -486,6 +486,8 @@ struct CPUMIPSState {uint64_t lladdr;target_ulong llval;target_ulong llnewval; +uint32_t llval_wp; +uint32_t llnewval_wp;target_ulong llreg;uint64_t CP0_LLAddr_rw_bitmask;int CP0_LLAddr_shift;
target/mips/helper.h +2 -0
@@ -14,6 +14,8 @@ DEF_HELPER_4(swr, void, env, tl, tl, int)#ifndef CONFIG_USER_ONLY DEF_HELPER_3(ll, tl, env, tl, int) DEF_HELPER_4(sc, tl, env, tl, tl, int) +DEF_HELPER_5(llwp, void, env, tl, i32, i32, i32) +DEF_HELPER_4(scwp, tl, env, tl, i64, int)#ifdef TARGET_MIPS64 DEF_HELPER_3(lld, tl, env, tl, int)DEF_HELPER_4 (scd, tl, env, tl, tl, int)
target/mips/op_helper.c +35 -0
@@ -284,6 +284,19 @@ HELPER_LD_ATOMIC(lld, ld, 0x7)#endif #undef HELPER_LD_ATOMIC +void helper_llwp (CPUMIPSState *env,target_ulong addr,uint32_t reg1, +uint32_t reg2,uint32_t mem_idx) +{ +if (addr &0x7 ) { + env->CP0_BadVAddr = addr; +do_raise_exception (env, EXCP_AdEL,GETPC ()); + } + env->lladdr =do_translate_address (env, addr,0 ,GETPC ()); + env->active_tc.gpr[reg1] = env->llval =do_lw (env, addr, mem_idx,GETPC ()); + env->active_tc.gpr[reg2] = env->llval_wp =do_lw (env, addr +4 , mem_idx, +GETPC ()); +} +#define HELPER_ST_ATOMIC (name, ld_insn, st_insn, almask) \ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \ target_ulong arg2, int mem_idx) \
@@ -308,6 +321,28 @@ HELPER_ST_ATOMIC(sc, lw, sw, 0x3) HELPER_ST_ATOMIC(scd, ld, sd, 0x7)#endif #undef HELPER_ST_ATOMIC + +target_ulong helper_scwp (CPUMIPSState *env,target_ulong addr, +uint64_t data,int mem_idx) +{ +uint32_t tmp; +uint32_t tmp2; + +if (addr &0x7 ) { + env->CP0_BadVAddr = addr; +do_raise_exception (env, EXCP_AdES,GETPC ()); + } +if (do_translate_address (env, addr,1 ,GETPC ()) == env->lladdr) { + tmp =do_lw (env, addr, mem_idx,GETPC ()); + tmp2 =do_lw (env, addr +4 , mem_idx,GETPC ()); +if (tmp == env->llval && tmp2 == env->llval_wp) { +do_sw (env, addr, (uint32_t ) data, mem_idx,GETPC ()); +do_sw (env, addr +4 , (uint32_t ) *(&data +4 ), mem_idx,GETPC ()); +return 1 ; + } + } +return 0 ; +}#endif #ifdef TARGET_WORDS_BIGENDIAN
target/mips/translate.c +107 -0
143 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 19/35] target/mips: Implement nanoMIPS LLWP/SCWP pair
target/mips/op_helper.c HELPER_LD_ATOMIC(lld, ld, 0x7) · line 298
Quoted 12 lines · Yongbok Kim
target/mips/op_helper.c +12
-0+void helper_llwp (CPUMIPSState *env,target_ulong addr,uint32_t reg1, +uint32_t reg2,uint32_t mem_idx) +{ +if (addr &0x7 ) { + env->CP0_BadVAddr = addr; +do_raise_exception (env, EXCP_AdEL,GETPC ()); + } + env->lladdr =do_translate_address (env, addr,0 ,GETPC ()); + env->active_tc.gpr[reg1] = env->llval =do_lw (env, addr, mem_idx,GETPC ()); + env->active_tc.gpr[reg2] = env->llval_wp =do_lw (env, addr +4 , mem_idx, +GETPC ()); +}
Performing two loads is a mistake. You need to perform one single 64-bit load in order for this to be atomic. There is also no point in performing such out of line.
Quoted 6 lines
target/mips/op_helper.c +6
-0+target_ulong helper_scwp (CPUMIPSState *env,target_ulong addr, +uint64_t data,int mem_idx) +{ +uint32_t tmp; +uint32_t tmp2; +
target/mips/op_helper.c HELPER_ST_ATOMIC(sc, lw, sw, 0x3) · line 340
Quoted 10 lines
target/mips/op_helper.c +10
-0+if (addr &0x7 ) { + env->CP0_BadVAddr = addr; +do_raise_exception (env, EXCP_AdES,GETPC ()); + } +if (do_translate_address (env, addr,1 ,GETPC ()) == env->lladdr) { + tmp =do_lw (env, addr, mem_idx,GETPC ()); + tmp2 =do_lw (env, addr +4 , mem_idx,GETPC ()); +if (tmp == env->llval && tmp2 == env->llval_wp) { +do_sw (env, addr, (uint32_t ) data, mem_idx,GETPC ()); +do_sw (env, addr +4 , (uint32_t ) *(&data +4 ), mem_idx,GETPC ());
This must use a 64-bit atomic_cmpxchg.
This can also be done inline with
tcg_gen_atomic_cmpxchg_i64.
r~
PATCH 20/35 target/mips: Fix not to update BadVAddr in Debug Mode
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
BadVaddr shouldn't be updated in Debug Mode
--- target/mips/helper.c | 4 +++- target/mips/op_helper.c | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-)
target/mips/helper.c +3 -1
@@ -502,7 +502,9 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,break ; }/* Raise exception */ - env->CP0_BadVAddr = address; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = address; + } env->CP0_Context = (env->CP0_Context & ~0x007fffff ) | ((address >>9 ) &0x007ffff0 ); env->CP0_EntryHi = (env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask) |
target/mips/op_helper.c +15 -5
@@ -271,7 +271,9 @@ static inline hwaddr do_translate_address(CPUMIPSState *env, target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ { \ if (arg & almask) { \ - env->CP0_BadVAddr = arg; \ + if (!(env->hflags & MIPS_HFLAG_DM)) { \ + env->CP0_BadVAddr = arg; \ + } \ do_raise_exception(env, EXCP_AdEL, GETPC()); \ } \ env->lladdr = do_translate_address(env, arg, 0, GETPC()); \
@@ -288,7 +290,9 @@ void helper_llwp(CPUMIPSState *env, target_ulong addr, uint32_t reg1, uint32_t reg2, uint32_t mem_idx) {if (addr &0x7 ) { - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }do_raise_exception (env, EXCP_AdEL,GETPC ()); } env->lladdr =do_translate_address (env, addr,0 ,GETPC ());
@@ -304,7 +308,9 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \target_long tmp; \ \if (arg2 & almask) { \ - env->CP0_BadVAddr = arg2; \ +if (!(env->hflags &MIPS_HFLAG_DM )) { \ + env->CP0_BadVAddr = arg2; \ + } \do_raise_exception (env, EXCP_AdES,GETPC ()); \ } \if (do_translate_address (env, arg2,1 ,GETPC ()) == env->lladdr) { \
@@ -329,7 +335,9 @@ target_ulong helper_scwp(CPUMIPSState *env, target_ulong addr,uint32_t tmp2;if (addr &0x7 ) { - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }do_raise_exception (env, EXCP_AdES,GETPC ()); }if (do_translate_address (env, addr,1 ,GETPC ()) == env->lladdr) {
@@ -2472,7 +2480,9 @@ void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,int error_code =0 ;int excp; - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }if (access_type ==MMU_DATA_STORE ) { excp = EXCP_AdES;
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 20/35] target/mips: Fix not to update BadVAddr in Debug Mode
Quoted 3 lines · Yongbok Kim
From: Yongbok Kim <[email protected]>
BadVaddr shouldn't be updated in Debug Mode
Long-standing issue!
Quoted 2 lines
Signed-off-by Yongbok Kim <[email protected]>
Quoted 80 lines
--- target/mips/helper.c | 4 +++- target/mips/op_helper.c | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-)target/mips/helper.c +3
-1@@ -502,7 +502,9 @@ static void raise_mmu_exception(CPUMIPSState *env, target_ulong address,break ; }/* Raise exception */ - env->CP0_BadVAddr = address; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = address; + } env->CP0_Context = (env->CP0_Context & ~0x007fffff ) | ((address >>9 ) &0x007ffff0 ); env->CP0_EntryHi = (env->CP0_EntryHi & env->CP0_EntryHi_ASID_mask) |target/mips/op_helper.c +15
-5@@ -271,7 +271,9 @@ static inline hwaddr do_translate_address(CPUMIPSState *env, target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ { \ if (arg & almask) { \ - env->CP0_BadVAddr = arg; \ + if (!(env->hflags & MIPS_HFLAG_DM)) { \ + env->CP0_BadVAddr = arg; \ + } \ do_raise_exception(env, EXCP_AdEL, GETPC()); \ } \ env->lladdr = do_translate_address(env, arg, 0, GETPC()); \@@ -288,7 +290,9 @@ void helper_llwp(CPUMIPSState *env, target_ulong addr, uint32_t reg1, uint32_t reg2, uint32_t mem_idx) {if (addr &0x7 ) { - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }do_raise_exception (env, EXCP_AdEL,GETPC ()); } env->lladdr =do_translate_address (env, addr,0 ,GETPC ());@@ -304,7 +308,9 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg1, \target_long tmp; \ \if (arg2 & almask) { \ - env->CP0_BadVAddr = arg2; \ +if (!(env->hflags &MIPS_HFLAG_DM )) { \ + env->CP0_BadVAddr = arg2; \ + } \do_raise_exception (env, EXCP_AdES,GETPC ()); \ } \if (do_translate_address (env, arg2,1 ,GETPC ()) == env->lladdr) { \@@ -329,7 +335,9 @@ target_ulong helper_scwp(CPUMIPSState *env, target_ulong addr,uint32_t tmp2;if (addr &0x7 ) { - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }do_raise_exception (env, EXCP_AdES,GETPC ()); }if (do_translate_address (env, addr,1 ,GETPC ()) == env->lladdr) {@@ -2472,7 +2480,9 @@ void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,int error_code =0 ;int excp; - env->CP0_BadVAddr = addr; +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = addr; + }if (access_type ==MMU_DATA_STORE ) { excp = EXCP_AdES;
PATCH 21/35 target/mips: Add nanoMIPS rotx instruction
In reply to Yongbok KimFrom: Matthew Fortune <[email protected]>
Added a helper for rotx based on the pseudocode from the arch spec.
--- target/mips/helper.h | 2 ++ target/mips/op_helper.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ target/mips/translate.c | 15 ++++++++ 3 files changed, 111 insertions(+)
target/mips/helper.h +2 -0
@@ -42,6 +42,8 @@ DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(dbitswap, TCG_CALL_NO_RWG_SE, tl, tl)#endif +DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32) +#ifndef CONFIG_USER_ONLY /* CP0 helpers */ DEF_HELPER_1 (mfc0_mvpcontrol, tl, env)
target/mips/op_helper.c +94 -0
100 lines not on this page · raw message
target/mips/translate.c +15 -0
@@ -17581,6 +17581,21 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) }break ;case NM_P_ROTX : +if (rt !=0 ) { +TCGv t0 =tcg_temp_new (); +TCGv_i32 shift =tcg_const_i32 (extract32 (ctx->opcode,0 ,5 )); +TCGv_i32 shiftx =tcg_const_i32 (extract32 (ctx->opcode,7 ,4 ) + <<1 ); +TCGv_i32 stripe =tcg_const_i32 ((ctx->opcode >>6 ) &1 ); + +gen_load_gpr (t0, rs); +gen_helper_rotx (cpu_gpr[rt], t0, shift, shiftx, stripe); +tcg_temp_free (t0); + +tcg_temp_free_i32 (shift); +tcg_temp_free_i32 (shiftx); +tcg_temp_free_i32 (stripe); + }break ;case NM_P_INS :switch (((ctx->opcode >>10 ) &2 ) | ((ctx->opcode >>5 ) &1 )) {
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 21/35] target/mips: Add nanoMIPS rotx instruction
Quoted 6 lines · Yongbok Kim
case
NM_P_ROTX:target/mips/translate.c +5
-0+if (rt !=0 ) { +TCGv t0 =tcg_temp_new (); +TCGv_i32 shift =tcg_const_i32 (extract32 (ctx->opcode,0 ,5 )); +TCGv_i32 shiftx =tcg_const_i32 (extract32 (ctx->opcode,7 ,4 ) + <<1 );
target/mips/translate.c static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) · line 17598
Quoted 10 lines
target/mips/translate.c +10
-0+TCGv_i32 stripe =tcg_const_i32 ((ctx->opcode >>6 ) &1 ); + +gen_load_gpr (t0, rs); +gen_helper_rotx (cpu_gpr[rt], t0, shift, shiftx, stripe); +tcg_temp_free (t0); + +tcg_temp_free_i32 (shift); +tcg_temp_free_i32 (shiftx); +tcg_temp_free_i32 (stripe); + }
It would be worth your while to recognize the special case of BYTEREVW.
But otherwise
r~
PATCH 22/35 target/mips: Fix data type for offset
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Offset can be larger than 16 bit from nanoMIPS, and immediate field can be larger than 16 bits as well.
--- target/mips/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/mips/translate.c +4 -4
@@ -2114,7 +2114,7 @@ OP_ST_ATOMIC(scd,st64,ld64,0x7);#undef OP_ST_ATOMICstatic void gen_base_offset_addr (DisasContext *ctx,TCGv addr, -int base,int16_t offset) +int base,int offset) {if (base ==0 ) {tcg_gen_movi_tl (addr, offset);
@@ -2142,7 +2142,7 @@ static target_ulong pc_relative_pc (DisasContext *ctx)/* Load */ static void gen_ld (DisasContext *ctx,uint32_t opc, -int rt,int base,int16_t offset) +int rt,int base,int offset) {TCGv t0, t1, t2;int mem_idx = ctx->mem_idx;
@@ -2377,7 +2377,7 @@ static void gen_llwp(DisasContext *ctx, uint32_t base, int16_t offset,/* Store */ static void gen_st (DisasContext *ctx,uint32_t opc,int rt, -int base,int16_t offset) +int base,int offset) {TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();
@@ -2602,7 +2602,7 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,/* Arithmetic with immediate operand */ static void gen_arith_imm (DisasContext *ctx,uint32_t opc, -int rt,int rs,int16_t imm) +int rt,int rs,int imm) {target_ulong uimm = (target_long )imm;/* Sign extend to 32/64 bits */
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 22/35] target/mips: Fix data type for offset
Quoted 6 lines · Yongbok Kim
From: Yongbok Kim <[email protected]>
Offset can be larger than 16 bit from nanoMIPS, and immediate field can be larger than 16 bits as well.
Signed-off-by Yongbok Kim <[email protected]>
Quoted 45 lines
--- target/mips/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/mips/translate.c +4
-4@@ -2114,7 +2114,7 @@ OP_ST_ATOMIC(scd,st64,ld64,0x7);#undef OP_ST_ATOMICstatic void gen_base_offset_addr (DisasContext *ctx,TCGv addr, -int base,int16_t offset) +int base,int offset) {if (base ==0 ) {tcg_gen_movi_tl (addr, offset);@@ -2142,7 +2142,7 @@ static target_ulong pc_relative_pc (DisasContext *ctx)/* Load */ static void gen_ld (DisasContext *ctx,uint32_t opc, -int rt,int base,int16_t offset) +int rt,int base,int offset) {TCGv t0, t1, t2;int mem_idx = ctx->mem_idx;@@ -2377,7 +2377,7 @@ static void gen_llwp(DisasContext *ctx, uint32_t base, int16_t offset,/* Store */ static void gen_st (DisasContext *ctx,uint32_t opc,int rt, -int base,int16_t offset) +int base,int offset) {TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();@@ -2602,7 +2602,7 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,/* Arithmetic with immediate operand */ static void gen_arith_imm (DisasContext *ctx,uint32_t opc, -int rt,int rs,int16_t imm) +int rt,int rs,int imm) {target_ulong uimm = (target_long )imm;/* Sign extend to 32/64 bits */
Re: [Qemu-devel] [PATCH 22/35] target/mips: Fix data type for offset
In reply to Yongbok KimQuoted 6 lines
From: Yongbok Kim <[email protected]>
Offset can be larger than 16 bit from nanoMIPS, and immediate field can be larger than 16 bits as well.
Signed-off-by Yongbok Kim <[email protected]>
Quoted 46 lines
--- target/mips/translate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/mips/translate.c +4
-5@@ -2114,7 +2114,7 @@ OP_ST_ATOMIC(scd,st64,ld64,0x7);#undef OP_ST_ATOMICstatic void gen_base_offset_addr (DisasContext *ctx,TCGv addr, -int base,int16_t offset) +int base,int offset) {if (base ==0 ) {tcg_gen_movi_tl (addr, offset);@@ -2142,7 +2142,7 @@ static target_ulong pc_relative_pc (DisasContext *ctx)/* Load */ static void gen_ld (DisasContext *ctx,uint32_t opc, -int rt,int base,int16_t offset) +int rt,int base,int offset) {TCGv t0, t1, t2;int mem_idx = ctx->mem_idx;@@ -2377,7 +2377,7 @@ static void gen_llwp(DisasContext *ctx, uint32_t base, int16_t offset,/* Store */ static void gen_st (DisasContext *ctx,uint32_t opc,int rt, -int base,int16_t offset) +int base,int offset) {TCGv t0 =tcg_temp_new ();TCGv t1 =tcg_temp_new ();@@ -2602,7 +2602,7 @@ static void gen_cop1_ldst(DisasContext *ctx, uint32_t op, int rt,/* Arithmetic with immediate operand */ static void gen_arith_imm (DisasContext *ctx,uint32_t opc, -int rt,int rs,int16_t imm) +int rt,int rs,int imm) {target_ulong uimm = (target_long )imm;/* Sign extend to 32/64 bits */ --1.9.1
PATCH 23/35 target/mips: Update BadInstr{P} regs on nanoMIPS
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Update BadInstr{P} registers on nanoMIPS
--- target/mips/helper.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
target/mips/helper.c +22 -1
@@ -683,7 +683,28 @@ static void set_hflags_for_handler (CPUMIPSState *env)static inline void set_badinstr_registers (CPUMIPSState *env) {if (env->hflags &MIPS_HFLAG_M16 ) { -/* TODO: add BadInstr support for microMIPS */ +uint32_t instr; +if (!(env->insn_flags &ISA_NANOMIPS32 )) { +/* TODO: add BadInstr support for pre-nanoMIPS */ +return ; + } +if (env->CP0_Config3 & (1 <<CP0C3_BI )) { + instr = (cpu_lduw_code (env, env->active_tc.PC)) <<16 ; +if ((env->insn_flags &ISA_NANOMIPS32 ) && + ((instr &0x10000000 ) ==0 )) { + instr |=cpu_lduw_code (env, env->active_tc.PC +2 ); + } + env->CP0_BadInstr = instr; + } +if ((env->CP0_Config3 & (1 <<CP0C3_BP )) && + (env->hflags &MIPS_HFLAG_BMASK )) { +if (!(env->hflags &MIPS_HFLAG_B16 )) { + env->CP0_BadInstrP =cpu_ldl_code (env, env->active_tc.PC -4 ); + }else { + env->CP0_BadInstrP = + (cpu_lduw_code (env, env->active_tc.PC -2 )) <<16 ; + } + }return ; }if (env->CP0_Config3 & (1 <<CP0C3_BI )) {
Signature · 1 line
1.9.1
PATCH 24/35 target/mips: Add nanoMIPS CP0_BadInstrX register
In reply to Yongbok KimFrom: Stefan Markovic <[email protected]>
Add nanoMIPS CP0_BadInstrX register
--- target/mips/cpu.h | 1 + target/mips/helper.c | 6 ++++++ target/mips/machine.c | 1 + target/mips/translate.c | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+)
target/mips/cpu.h +1 -0
@@ -323,6 +323,7 @@ struct CPUMIPSState {target_ulong CP0_BadVAddr;uint32_t CP0_BadInstr;uint32_t CP0_BadInstrP; +uint32_t CP0_BadInstrX;int32_t CP0_Count;target_ulong CP0_EntryHi;#define CP0EnHi_EHINV 10
target/mips/helper.c +6 -0
@@ -695,6 +695,12 @@ static inline void set_badinstr_registers(CPUMIPSState *env) instr |=cpu_lduw_code (env, env->active_tc.PC +2 ); } env->CP0_BadInstr = instr; + +if ((env->insn_flags &ISA_NANOMIPS32 ) && + ((instr &0xFC000000 ) ==0x60000000 )) { + instr =cpu_lduw_code (env, env->active_tc.PC +4 ) <<16 ; + env->CP0_BadInstrX = instr; + } }if ((env->CP0_Config3 & (1 <<CP0C3_BP )) && (env->hflags &MIPS_HFLAG_BMASK )) {
target/mips/machine.c +1 -0
@@ -266,6 +266,7 @@ const VMStateDescription vmstate_mips_cpu = {VMSTATE_UINTTL (env.CP0_BadVAddr,MIPSCPU ),VMSTATE_UINT32 (env.CP0_BadInstr,MIPSCPU ),VMSTATE_UINT32 (env.CP0_BadInstrP,MIPSCPU ), +VMSTATE_UINT32 (env.CP0_BadInstrX,MIPSCPU ),VMSTATE_INT32 (env.CP0_Count,MIPSCPU ),VMSTATE_UINTTL (env.CP0_EntryHi,MIPSCPU ), VMSTATE_INT32(env.CP0_Compare, MIPSCPU),
target/mips/translate.c +18 -0
@@ -5429,6 +5429,11 @@ static void gen_mfc0(DisasContext *ctx, TCGv arg, int reg, int sel)gen_mfc0_load32 (arg, offsetof(CPUMIPSState , CP0_BadInstrP)); rn ="BadInstrP" ;break ; +case 3 : +CP0_CHECK (ctx->bi); +gen_mfc0_load32 (arg, offsetof(CPUMIPSState , CP0_BadInstrX)); + rn ="BadInstrX" ; +break ;default : goto cp0_unimplemented; }
@@ -6098,6 +6103,10 @@ static void gen_mtc0(DisasContext *ctx, TCGv arg, int reg, int sel)/* ignored */ rn ="BadInstrP" ;break ; +case 3 : +/* ignored */ + rn ="BadInstrX" ; +break ;default : goto cp0_unimplemented; }
@@ -6781,6 +6790,11 @@ static void gen_dmfc0(DisasContext *ctx, TCGv arg, int reg, int sel)gen_mfc0_load32 (arg, offsetof(CPUMIPSState , CP0_BadInstrP)); rn ="BadInstrP" ;break ; +case 3 : +CP0_CHECK (ctx->bi); +gen_mfc0_load32 (arg, offsetof(CPUMIPSState , CP0_BadInstrX)); + rn ="BadInstrX" ; +break ;default : goto cp0_unimplemented; }
@@ -7433,6 +7447,10 @@ static void gen_dmtc0(DisasContext *ctx, TCGv arg, int reg, int sel)/* ignored */ rn ="BadInstrP" ;break ; +case 3 : +/* ignored */ + rn ="BadInstrX" ; +break ;default : goto cp0_unimplemented; }
Signature · 1 line
1.9.1
PATCH 25/35 target/mips: Config3.ISAOnExc is read only in nanoMIPS
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Config3.ISAOnExc is read only in nanoMIPS
--- target/mips/op_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/mips/op_helper.c +2 -1
@@ -1734,7 +1734,8 @@ void helper_mtc0_config2(CPUMIPSState *env, target_ulong arg1)void helper_mtc0_config3 (CPUMIPSState *env,target_ulong arg1) { -if (env->insn_flags &ASE_MICROMIPS ) { +if ((env->insn_flags &ASE_MICROMIPS ) && + !(env->insn_flags &ISA_NANOMIPS32 )) { env->CP0_Config3 = (env->CP0_Config3 & ~(1 <<CP0C3_ISA_ON_EXC )) | (arg1 & (1 <<CP0C3_ISA_ON_EXC )); }
Signature · 1 line
1.9.1
PATCH 26/35 target/mips: Fix nanoMIPS exception_resume_pc
In reply to Yongbok KimFrom: James Hogan <[email protected]>
We shouldn't set the ISA bit in CP0_EPC for nanoMIPS.
--- target/mips/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/mips/helper.c +2 -1
@@ -656,7 +656,8 @@ target_ulong exception_resume_pc (CPUMIPSState *env)target_ulong bad_pc;target_ulong isa_mode; - isa_mode = !!(env->hflags &MIPS_HFLAG_M16 ); + isa_mode = env->hflags &MIPS_HFLAG_M16 && + !(env->insn_flags &ISA_NANOMIPS32 ); bad_pc = env->active_tc.PC | isa_mode;if (env->hflags &MIPS_HFLAG_BMASK ) {/* If the exception was raised from a delay slot, come back to
Signature · 1 line
1.9.1
PATCH 27/35 target/mips: Fix nanoMIPS set_hflags_for_handler
In reply to Yongbok KimFrom: James Hogan <[email protected]>
We shouldn't clear M16 mode when entering an interrupt on nanoMIPS, otherwise we'll start interpreting the code as normal MIPS code.
--- target/mips/helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/mips/helper.c +3 -0
@@ -671,6 +671,9 @@ target_ulong exception_resume_pc (CPUMIPSState *env)#if !defined(CONFIG_USER_ONLY )static void set_hflags_for_handler (CPUMIPSState *env) { +if (env->insn_flags &ISA_NANOMIPS32 ) { +return ; + }/* Exception handlers are entered in 32-bit mode. */ env->hflags &= ~(MIPS_HFLAG_M16 );/* ...except that microMIPS lets you choose. */
Signature · 1 line
1.9.1
PATCH 28/35 target/mips: Fix nanoMIPS set_pc
In reply to Yongbok KimFrom: James Hogan <[email protected]>
ERET and ERETNC shouldn't clear MIPS_HFLAG_M16 for nanoMIPS since there is no ISA bit, so fix set_pc() to skip the hflags update.
--- target/mips/op_helper.c | 4 ++++ 1 file changed, 4 insertions(+)
target/mips/op_helper.c +4 -0
@@ -2432,6 +2432,10 @@ static void debug_post_eret(CPUMIPSState *env)static void set_pc (CPUMIPSState *env,target_ulong error_pc) { env->active_tc.PC = error_pc & ~(target_ulong )1 ; +if (env->insn_flags &ISA_NANOMIPS32 ) { +/* Don't clear MIPS_HFLAG_M16 */ +return ; + }if (error_pc &1 ) { env->hflags |=MIPS_HFLAG_M16 ; }else {
Signature · 1 line
1.9.1
PATCH 29/35 target/mips: Fix ERET/ERETNC can cause ADEL exception
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Fix ERET/ERETNC can cause ADEL exception
--- target/mips/op_helper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
target/mips/op_helper.c +10 -1
@@ -2434,6 +2434,13 @@ static void set_pc(CPUMIPSState *env, target_ulong error_pc) env->active_tc.PC = error_pc & ~(target_ulong )1 ;if (env->insn_flags &ISA_NANOMIPS32 ) {/* Don't clear MIPS_HFLAG_M16 */ +if (error_pc &1 ) { +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = error_pc; + } + env->active_tc.PC = error_pc; +do_raise_exception (env, EXCP_AdEL,0 ); + }return ; }if (error_pc &1 ) {
@@ -2471,10 +2478,12 @@ void helper_eretnc(CPUMIPSState *env)void helper_deret (CPUMIPSState *env) {debug_pre_eret (env); -set_pc (env, env->CP0_DEPC); env->hflags &= ~MIPS_HFLAG_DM ;compute_hflags (env); + +set_pc (env, env->CP0_DEPC); +debug_post_eret (env); }#endif /* !CONFIG_USER_ONLY */
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 29/35] target/mips: Fix ERET/ERETNC can cause ADEL exception
Quoted 28 lines · Yongbok Kim
From: Yongbok Kim <[email protected]>
Fix ERET/ERETNC can cause ADEL exception
Signed-off-by Yongbok Kim <[email protected]>--- target/mips/op_helper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)target/mips/op_helper.c +7
-0@@ -2434,6 +2434,13 @@ static void set_pc(CPUMIPSState *env, target_ulong error_pc) env->active_tc.PC = error_pc & ~(target_ulong )1 ;if (env->insn_flags &ISA_NANOMIPS32 ) {/* Don't clear MIPS_HFLAG_M16 */ +if (error_pc &1 ) { +if (!(env->hflags &MIPS_HFLAG_DM )) { + env->CP0_BadVAddr = error_pc; + } + env->active_tc.PC = error_pc; +do_raise_exception (env, EXCP_AdEL,0 ); + }return ; }if (error_pc &1 ) {
target/mips/op_helper.c void helper_eretnc(CPUMIPSState *env) · line 2485
Quoted 9 lines
target/mips/op_helper.c +2
-1@@ -2471,10 +2478,12 @@ void helper_eretnc(CPUMIPSState *env)void helper_deret (CPUMIPSState *env) {debug_pre_eret (env); -set_pc (env, env->CP0_DEPC); env->hflags &= ~MIPS_HFLAG_DM ;compute_hflags (env); + +set_pc (env, env->CP0_DEPC);
Now set_pc() uses MIPS_HFLAG_DM, so it makes sens to call it _after_ updating env->hflags. Correct.
Quoted 5 lines
target/mips/op_helper.c +1
-0+ debug_post_eret(env); }#endif /* !CONFIG_USER_ONLY */
PATCH 30/35 hw/mips: Add basic nanoMIPS boot code
In reply to Yongbok KimFrom: Matthew Fortune <[email protected]>
Added very very basic R7 boot code but this is hacked in unconditionally currently.
Yongbok:
Fix to use right boot loader
--- hw/mips/mips_malta.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++----- include/elf.h | 1 + 2 files changed, 70 insertions(+), 6 deletions(-)
hw/mips/mips_malta.c +69 -6
@@ -619,6 +619,58 @@ static void network_init(PCIBus *pci_bus)a2 - 32-bit address of the environment variables table a3 - RAM size in bytes */ +static void write_bootloader_nanomips (uint8_t *base,int64_t run_addr, +int64_t kernel_entry) +{ +uint16_t *p; + +/* Small bootloader */ + p = (uint16_t *)base; + +#define NM_HI1 (VAL ) (((VAL) >> 16) & 0x1f) +#define NM_HI2 (VAL ) \ + (((VAL) & 0xf000) | (((VAL) >> 19) & 0xffc) | (((VAL) >> 31) & 0x1)) +#define NM_LO (VAL ) ((VAL) & 0xfff) + +stw_p (p++,0x2800 );stw_p (p++,0x001c );/* bc to_here */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ + +/* to_here: */ +stw_p (p++,0x0080 );stw_p (p++,0x0002 );/* li a0,2 */ +stw_p (p++,0xe3a0 |NM_HI1 (ENVP_ADDR -64 )); +stw_p (p++,NM_HI2 (ENVP_ADDR -64 )); +/* lui sp,%hi(ENVP_ADDR - 64) */ +stw_p (p++,0x83bd );stw_p (p++,NM_LO (ENVP_ADDR -64 )); +/* ori sp,sp,%lo(ENVP_ADDR - 64) */ +stw_p (p++,0xe0a0 |NM_HI1 (ENVP_ADDR )); +stw_p (p++,NM_HI2 (ENVP_ADDR )); +/* lui a1,%hi(ENVP_ADDR) */ +stw_p (p++,0x80a5 );stw_p (p++,NM_LO (ENVP_ADDR )); +/* ori a1,a1,%lo(ENVP_ADDR) */ +stw_p (p++,0xe0c0 |NM_HI1 (ENVP_ADDR +8 )); +stw_p (p++,NM_HI2 (ENVP_ADDR +8 )); +/* lui a2,%hi(ENVP_ADDR + 8) */ +stw_p (p++,0x80c6 );stw_p (p++,NM_LO (ENVP_ADDR +8 )); +/* ori a2,a2,%lo(ENVP_ADDR + 8) */ +stw_p (p++,0xe0e0 |NM_HI1 (loaderparams.ram_low_size)); +stw_p (p++,NM_HI2 (loaderparams.ram_low_size)); +/* lui a3,%hi(loaderparams.ram_low_size) */ +stw_p (p++,0x80e7 );stw_p (p++,NM_LO (loaderparams.ram_low_size)); +/* ori a3,a3,%lo(loaderparams.ram_low_size) */ +stw_p (p++,0xe320 |NM_HI1 (kernel_entry)); +stw_p (p++,NM_HI2 (kernel_entry)); +/* lui t9,%hi(kernel_entry) */ +stw_p (p++,0x8339 );stw_p (p++,NM_LO (kernel_entry)); +/* ori t9,t9,%lo(kernel_entry) */ +stw_p (p++,0x4bf9 );stw_p (p++,0x0000 ); +/* jalrc t8 */ +}static void write_bootloader (uint8_t *base,int64_t run_addr,int64_t kernel_entry)
@@ -812,10 +864,16 @@ static int64_t load_kernel (void)NULL , (uint64_t *)&kernel_entry,NULL , (uint64_t *)&kernel_high, big_endian, EM_MIPS, 1, 0);if (kernel_size <0 ) { -error_report ("could not load kernel '%s': %s" , - loaderparams.kernel_filename, -load_elf_strerror (kernel_size)); -exit (1 ); + kernel_size =load_elf (loaderparams.kernel_filename, + cpu_mips_kseg0_to_phys,NULL , + (uint64_t *)&kernel_entry,NULL , + (uint64_t *)&kernel_high, big_endian,EM_NANOMIPS ,1 ,0 ); +if (kernel_size <0 ) { +error_report ("could not load kernel '%s': %s" , + loaderparams.kernel_filename, +load_elf_strerror (kernel_size)); +exit (1 ); + } }/* Check where the kernel has been linked */
@@ -1093,8 +1151,13 @@ void mips_malta_init(MachineState *machine) loaderparams.initrd_filename = initrd_filename; kernel_entry =load_kernel (); -write_bootloader (memory_region_get_ram_ptr (bios), - bootloader_run_addr, kernel_entry); +if (!cpu_supports_isa (machine->cpu_type,ISA_NANOMIPS32 )) { +write_bootloader (memory_region_get_ram_ptr (bios), + bootloader_run_addr, kernel_entry); + }else { +write_bootloader_nanomips (memory_region_get_ram_ptr (bios), + bootloader_run_addr, kernel_entry); + }if (kvm_enabled ()) {/* Write the bootloader code @ the end of RAM, 1MB reserved */ write_bootloader(memory_region_get_ram_ptr(ram_low_preio) +
include/elf.h +1 -0
@@ -121,6 +121,7 @@ typedef int64_t Elf64_Sxword;#define EM_RISCV 243/* RISC-V */ +#define EM_NANOMIPS 249/* MIPS Tech nanoMIPS */ /* * This is an interim value that we will use until the committee comes * up with a final number.
Signature · 1 line
1.9.1
PATCH 31/35 mips_malta: Setup GT64120 BARs in nanoMIPS bootloader
In reply to Yongbok KimFrom: Paul Burton <[email protected]>
Setup the GT64120 BARs in the nanoMIPS bootloader, in the same way that they are setup in the MIPS32 bootloader. This is necessary for Linux to be able to access peripherals, including the UART.
--- hw/mips/mips_malta.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
hw/mips/mips_malta.c +73 -0
@@ -663,6 +663,79 @@ static void write_bootloader_nanomips(uint8_t *base, int64_t run_addr,/* lui a3,%hi(loaderparams.ram_low_size) */ stw_p (p++,0x80e7 );stw_p (p++,NM_LO (loaderparams.ram_low_size));/* ori a3,a3,%lo(loaderparams.ram_low_size) */ + +/* Load BAR registers as done by YAMON */ +stw_p (p++,0xe040 );stw_p (p++,0x0681 ); +/* lui t1, %hi(0xb4000000) */ +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0be1 ); +/* lui t0, %hi(0xdf000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x00df ); +/* addiu[32] t0, $0, 0xdf */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9068 ); +/* sw t0, 0x68(t1) */ + +stw_p (p++,0xe040 );stw_p (p++,0x077d ); +/* lui t1, %hi(0xbbe00000) */ +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0801 ); +/* lui t0, %hi(0xc0000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x00c0 ); +/* addiu[32] t0, $0, 0xc0 */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9048 ); +/* sw t0, 0x48(t1) */ +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0800 ); +/* lui t0, %hi(0x40000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x0040 ); +/* addiu[32] t0, $0, 0x40 */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9050 ); +/* sw t0, 0x50(t1) */ + +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0001 ); +/* lui t0, %hi(0x80000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x0080 ); +/* addiu[32] t0, $0, 0x80 */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9058 ); +/* sw t0, 0x58(t1) */ +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x07e0 ); +/* lui t0, %hi(0x3f000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x003f ); +/* addiu[32] t0, $0, 0x3f */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9060 ); +/* sw t0, 0x60(t1) */ + +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0821 ); +/* lui t0, %hi(0xc1000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x00c1 ); +/* addiu[32] t0, $0, 0xc1 */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9080 ); +/* sw t0, 0x80(t1) */ +#ifdef TARGET_WORDS_BIGENDIAN +stw_p (p++,0xe020 );stw_p (p++,0x0bc0 ); +/* lui t0, %hi(0x5e000000) */ +#else +stw_p (p++,0x0020 );stw_p (p++,0x005e ); +/* addiu[32] t0, $0, 0x5e */ +#endif +stw_p (p++,0x8422 );stw_p (p++,0x9088 ); +/* sw t0, 0x88(t1) */ +stw_p (p++,0xe320 |NM_HI1 (kernel_entry));stw_p (p++,NM_HI2 (kernel_entry));/* lui t9,%hi(kernel_entry) */
Signature · 1 line
1.9.1
PATCH 32/35 hw/mips: Fix semihosting argument passing for nanoMIPS bare metal
In reply to Yongbok KimFrom: Stefan Markovic <[email protected]>
Fix semihosting argument passing for nanoMIPS bare metal
--- hw/mips/mips_malta.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/mips/mips_malta.c +6 -1
@@ -642,7 +642,12 @@ static void write_bootloader_nanomips(uint8_t *base, int64_t run_addr,stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ /* to_here: */ -stw_p (p++,0x0080 );stw_p (p++,0x0002 );/* li a0,2 */ +if (semihosting_get_argc ()) { +/* Preserve a0 content as arguments have been passed */ +stw_p (p++,0x8000 );stw_p (p++,0xc000 );/* nop */ + }else { +stw_p (p++,0x0080 );stw_p (p++,0x0002 );/* li a0,2 */ + }stw_p (p++,0xe3a0 |NM_HI1 (ENVP_ADDR -64 ));stw_p (p++,NM_HI2 (ENVP_ADDR -64 ));/* lui sp,%hi(ENVP_ADDR - 64) */
Signature · 1 line
1.9.1
PATCH 33/35 target/mips: Fix gdbstub to read/write 64 bit FP registers
In reply to Yongbok KimFrom: Yongbok Kim <[email protected]>
Fix gdbstub to read/write 64 bit FP registers
--- target/mips/gdbstub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/mips/gdbstub.c +2 -1
@@ -39,7 +39,7 @@ int mips_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)return gdb_get_regl (mem_buf, (int32_t )env->active_fpu.fcr0);default :if (env->CP0_Status & (1 << CP0St_FR)) { -return gdb_get_regl (mem_buf, +return gdb_get_reg64 (mem_buf, env->active_fpu.fpr[n -38 ].d); }else { return gdb_get_regl(mem_buf,
@@ -100,6 +100,7 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)break ;default :if (env->CP0_Status & (1 << CP0St_FR)) { +uint64_t tmp =ldq_p (mem_buf); env->active_fpu.fpr[n -38 ].d = tmp; }else { env->active_fpu.fpr[n -38 ].w[FP_ENDIAN_IDX ] = tmp;
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 33/35] target/mips: Fix gdbstub to read/write 64 bit FP registers
Quoted 5 lines
From: Yongbok Kim <[email protected]>
Fix gdbstub to read/write 64 bit FP registers
Signed-off-by Yongbok Kim <[email protected]>
Quoted 27 lines
--- target/mips/gdbstub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/mips/gdbstub.c +2
-2@@ -39,7 +39,7 @@ int mips_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)return gdb_get_regl (mem_buf, (int32_t )env->active_fpu.fcr0);default :if (env->CP0_Status & (1 << CP0St_FR)) { -return gdb_get_regl (mem_buf, +return gdb_get_reg64 (mem_buf, env->active_fpu.fpr[n -38 ].d); }else { return gdb_get_regl(mem_buf,@@ -100,6 +100,7 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)break ;default :if (env->CP0_Status & (1 << CP0St_FR)) { +uint64_t tmp =ldq_p (mem_buf); env->active_fpu.fpr[n -38 ].d = tmp; }else { env->active_fpu.fpr[n -38 ].w[FP_ENDIAN_IDX ] = tmp; --1.9.1
PATCH 34/35 target/mips: Disable gdbstub nanoMIPS ISA bit
In reply to Yongbok KimFrom: James Hogan <[email protected]>
nanoMIPS has no ISA bit in the PC, so remove the handling of the low bit of the PC in the MIPS gdbstub for nanoMIPS. This prevents the PC being read as e.g. 0xbfc00001, and prevents writing to the PC clearing MIPS_HFLAG_M16.
--- target/mips/gdbstub.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
target/mips/gdbstub.c +8 -5
@@ -60,7 +60,8 @@ int mips_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)return gdb_get_regl (mem_buf, (int32_t )env->CP0_Cause);case 37 :return gdb_get_regl (mem_buf, env->active_tc.PC | - !!(env->hflags &MIPS_HFLAG_M16 )); + (!(env->insn_flags &ISA_NANOMIPS32 ) && + env->hflags &MIPS_HFLAG_M16 ));case 72 :return gdb_get_regl (mem_buf,0 );/* fp */ case 89 :
@@ -131,10 +132,12 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)break ;case 37 : env->active_tc.PC = tmp & ~(target_ulong )1 ; -if (tmp &1 ) { - env->hflags |=MIPS_HFLAG_M16 ; - }else { - env->hflags &= ~(MIPS_HFLAG_M16 ); +if (!(env->insn_flags &ISA_NANOMIPS32 )) { +if (tmp &1 ) { + env->hflags |=MIPS_HFLAG_M16 ; + }else { + env->hflags &= ~(MIPS_HFLAG_M16 ); + } }break ;case 72 :/* fp, ignored */
Signature · 1 line
1.9.1
PATCH 35/35 target/mips: Add I7200 CPU
In reply to Yongbok KimFrom: Stefan Markovic <[email protected]>
Add I7200 CPU
Reference:
https://www.mips.com/products/warrior/i-class-i7200-multiprocessor-core/
--- target/mips/translate_init.inc.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
target/mips/translate_init.inc.c +37 -0
@@ -449,6 +449,43 @@ const mips_def_t mips_defs[] = .insn_flags = CPU_MIPS32R6 | ASE_MICROMIPS, .mmu_type = MMU_TYPE_R4000, }, + { + .name = "I7200", + .CP0_PRid = 0x00010000, + .CP0_Config0 =MIPS_CONFIG0 | (1 <<CP0C0_MM ) | (0x2 <<CP0C0_AR ) | + (MMU_TYPE_R4000 << CP0C0_MT), + .CP0_Config1 =MIPS_CONFIG1 | (15 <<CP0C1_MMU ) | (2 <<CP0C1_IS ) | + (4 <<CP0C1_IL ) | (3 <<CP0C1_IA ) | (2 <<CP0C1_DS ) | + (4 <<CP0C1_DL ) | (3 <<CP0C1_DA ) | (1 <<CP0C1_PC ) | + (1 << CP0C1_WR) | (1 << CP0C1_EP), + .CP0_Config2 = MIPS_CONFIG2, + .CP0_Config3 =MIPS_CONFIG3 | (1 <<CP0C3_CMGCR ) | (1 <<CP0C3_BI ) | + (3 <<CP0C3_MMAR ) | (1 <<CP0C3_ISA_ON_EXC ) | + (1 <<CP0C3_ISA ) | (1 <<CP0C3_ULRI ) | + (1 <<CP0C3_RXI ) | + (1 << CP0C3_VInt) | (1U << CP0C3_M) | (1 << CP0C3_MT), + .CP0_Config4 =MIPS_CONFIG4 | (0xfc << CP0C4_KScrExist) | + (2 << CP0C4_IE) | (1U << CP0C4_M), + .CP0_Config5 = MIPS_CONFIG5 | (1 << CP0C5_MVH) | (1 << CP0C5_LLB), + .CP0_Config5_rw_bitmask = (1 <<CP0C5_SBRI ) | (1 <<CP0C5_FRE ) | + (1 << CP0C5_UFE), + .CP0_LLAddr_rw_bitmask = 0, + .CP0_LLAddr_shift = 0, + .SYNCI_Step = 32, + .CCRes = 2, + .CP0_Status_rw_bitmask = 0x3058FF1F, + .CP0_PageGrain = (1 <<CP0PG_IEC ) | (1 <<CP0PG_XIE ) | + (1U << CP0PG_RIE), + .CP0_PageGrain_rw_bitmask = 0, + .CP1_fcr0 = (1 <<FCR0_FREP ) | (1 <<FCR0_HAS2008 ) | (1 <<FCR0_F64 ) | + (1 <<FCR0_L ) | (1 <<FCR0_W ) | (1 <<FCR0_D ) | + (1 << FCR0_S) | (0x02 << FCR0_PRID) | (0x0 << FCR0_REV), + .CP1_fcr31 = (1 << FCR31_ABS2008) | (1 << FCR31_NAN2008), + .SEGBITS = 32, + .PABITS = 32, + .insn_flags = CPU_NANOMIPS32 | ASE_MICROMIPS, + .mmu_type =MMU_TYPE_R4000 , + }, #if defined(TARGET_MIPS64) { .name = "R4000",
Signature · 1 line
1.9.1
Hi Yongbok,
Quoted 5 lines · Yongbok Kim
This series of patches is implementing recently announced nanoMIPS on QEMU. nanoMIPS is a variable length ISA containing 16, 32 and 48 bit wide instructions. It is designed to be portable at assembly level with other MIPS and microMIPS code, but contains a number of changes which enhance code density and efficiency.
[...]
I noticed various patches use the imgtec.com domain.
In commit 94d973bdaac Paul Burton wrote:
MIPS will soon no longer be a part of Imagination Technologies & as such the @imgtec.com address will soon cease to function.
Your's got updated in 0eb4e1f33a4, and James in a7a2d7d2a04.
Assuming this is rebase using previous internal patches, shouldn't you update those addresses to your new domain? Else the checkpatch.pl script will continue to extract imgtec.com addresses from commits.
Regards,
Phil.
Quoted 20 lines
From: Philippe Mathieu-Daudé <[email protected]> on behalf of Philippe Mathieu-Daudé <[email protected]>
Sent: Friday, June 22, 2018 6:26 AM
To: Yongbok Kim; James Hogan
Cc: [email protected]; Aleksandar Markovic; Paul Burton; Stefan Markovic; Matthew Fortune; [email protected]; Paul Burton
Subject: Re: [Qemu-devel] [PATCH 00/35] nanoMIPSHi Yongbok,
Quoted 5 lines · Yongbok Kim
This series of patches is implementing recently announced nanoMIPS on QEMU. nanoMIPS is a variable length ISA containing 16, 32 and 48 bit wide instructions. It is designed to be portable at assembly level with other MIPS and microMIPS code, but contains a number of changes which enhance code density and efficiency.
[...]
I noticed various patches use the imgtec.com domain.
In commit
94d973bdaacPaul Burton wrote:
Quoted 8 lines
MIPS will soon no longer be a part of Imagination Technologies & as such the @imgtec.com address will soon cease to function.
Your's got updated in
0eb4e1f33a4, and James ina7a2d7d2a04.Assuming this is rebase using previous internal patches, shouldn't you update those addresses to your new domain? Else the checkpatch.pl script will continue to extract imgtec.com addresses from commits.
Thanks for spotting this, Philippe! It probably slipped through the cracks.
If nobody objects, while integrating/applying, I am going to change all instances of "@imgtec.com" to "@mips.com" for this series.
Some of the patches might have been developed while the company was part of Imagination Technologies - however, I think it is reasonable to use email addresses at the moment of submitting changes to this list. This gets complicated if, for example, a person leaves the company before his/her email address changes, but I think, in this case, using "@mips.com" is appropriate for all involved persons.
Regards,
Aleksandar
Quoted 4 lines
Regards,
Phil.
Hi Aleksandar,
Quoted 29 lines · Aleksandar Markovic
Quoted 20 lines
From: Philippe Mathieu-Daudé <[email protected]> on behalf of Philippe Mathieu-Daudé <[email protected]>
Sent: Friday, June 22, 2018 6:26 AM
To: Yongbok Kim; James Hogan
Cc: [email protected]; Aleksandar Markovic; Paul Burton; Stefan Markovic; Matthew Fortune; [email protected]; Paul Burton
Subject: Re: [Qemu-devel] [PATCH 00/35] nanoMIPSHi Yongbok,
Quoted 5 lines · Yongbok Kim
This series of patches is implementing recently announced nanoMIPS on QEMU. nanoMIPS is a variable length ISA containing 16, 32 and 48 bit wide instructions. It is designed to be portable at assembly level with other MIPS and microMIPS code, but contains a number of changes which enhance code density and efficiency.
[...]
I noticed various patches use the imgtec.com domain.
In commit
94d973bdaacPaul Burton wrote:Quoted 8 lines
MIPS will soon no longer be a part of Imagination Technologies & as such the @imgtec.com address will soon cease to function.
Your's got updated in
0eb4e1f33a4, and James ina7a2d7d2a04.Assuming this is rebase using previous internal patches, shouldn't you update those addresses to your new domain? Else the checkpatch.pl script will continue to extract imgtec.com addresses from commits.
Quoted 5 lines
Thanks for spotting this, Philippe! It probably slipped through the cracks.
If nobody objects, while integrating/applying, I am going to change all instances of "@imgtec.com" to "@mips.com" for this series.
Some of the patches might have been developed while the company was part of Imagination Technologies - however, I think it is reasonable to use email addresses at the moment of submitting changes to this list. This gets complicated if, for example, a person leaves the company before his/her email address changes, but I think, in this case, using "@mips.com" is appropriate for all involved persons.
Well, since imgtec.com entries are in .mailmap, and get_maintainer.pl parses it, maybe there is a bug in the script.
The 'From' is used for the git author, and IMO should be @mips.com.
To respect Imagination Technologies efforts, can this work?
Technologies
This shouldn't break scripts. However not all names fit in less than 80 characters...
Quoted 9 lines
Regards,
Aleksandar
Quoted 4 lines
Regards,
Phil.
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Aleksandar Markovic
If nobody objects, while integrating/applying, I am going to change all instances of "@imgtec.com" to "@mips.com" for this series.
Some of the patches might have been developed while the company was part of Imagination Technologies - however, I think it is reasonable to use email addresses at the moment of submitting changes to this list. This gets complicated if, for example, a person leaves the company before his/her email address changes, but I think, in this case, using "@mips.com" is appropriate for all involved persons.
Well, since imgtec.com entries are in .mailmap, and get_maintainer.pl parses it, maybe there is a bug in the script.
Quoted 6 lines
The 'From' is used for the git author, and IMO should be @mips.com.
To respect Imagination Technologies efforts, can this work?
Signed-off-by James Hogan <[email protected]> for ImaginationTechnologies
That seems a bit weird to me. I would stick with just using the mips addresses.
thanks
-- PMM
Thanks!
I gave "reviewed-by" to five patches (01, 02, 13, 22, and 33) that actually fix or improve pre-nanoMIPS code segments (all these issues exist regardless of nanoMIPS support). I am going to integrate them via pull request next week separately, before the whole nanoMIPS series. Apart from fixing the issues, this will simplify nanoMIPS series, making it easier to understand/review.
For the rest of the patches, I am going to wait for v2.
Aleksandar
________________________________
From: Yongbok Kim
Sent: Wednesday, June 20, 2018 2:05 PM
To: [email protected]
Cc: [email protected]; Aleksandar Markovic; James Hogan; Paul Burton; Matthew Fortune; Stefan Markovic
Subject: [PATCH 00/35] nanoMIPS
This series of patches is implementing recently announced nanoMIPS on QEMU. nanoMIPS is a variable length ISA containing 16, 32 and 48 bit wide instructions. It is designed to be portable at assembly level with other MIPS and microMIPS code, but contains a number of changes which enhance code density and efficiency.
Most of nanoMIPS instructions exist in another MIPS ISAs. Therefore the large portion of patches is decoding nanoMIPS opcodes.
More patches will be added later after this.
For more information please refer following link.
https://www.mips.com/products/architectures/nanomips/
James Hogan (5):
target/mips: Implement nanoMIPS EXTW instruction target/mips: Fix nanoMIPS exception_resume_pc target/mips: Fix nanoMIPS set_hflags_for_handler target/mips: Fix nanoMIPS set_pc target/mips: Disable gdbstub nanoMIPS ISA bit
Matthew Fortune (4):
target/mips: Add nanoMIPS save and restore
target/mips: Add has_isa_mode
target/mips: Add nanoMIPS rotx instruction
hw/mips: Add basic nanoMIPS boot code
Paul Burton (1):
mips_malta: Setup GT64120 BARs in nanoMIPS bootloader
Stefan Markovic (3):
target/mips: Add nanoMIPS CP0_BadInstrX register hw/mips: Fix semihosting argument passing for nanoMIPS bare metal target/mips: Add I7200 CPU
Yongbok Kim (22):
target/mips: Raise a RI when given fs is n/a from CTC1 target/mips: Fix microMIPS on reset
target/mips: Add nanoMIPS OPCODE table target/mips: Add decode_nanomips_opc() target/mips: Add nanoMIPS 16bit ld/st instructions target/mips: Add nanoMIPS pool16c instructions target/mips: Add nanoMIPS 32bit instructions target/mips: Add nanoMIPS 48bit instructions target/mips: Add nanoMIPS pool32f instructions target/mips: Add nanoMIPS pool32a0 instructions target/mips: Add nanoMIPS pool32axf instructions target/mips: Update gen_flt_ldst()
target/mips: Add nanoMIPS p_lsx instructions target/mips: Add nanoMIPS load store instructions target/mips: Add nanoMIPS branch instructions target/mips: Implement nanoMIPS LLWP/SCWP pair target/mips: Fix not to update BadVAddr in Debug Mode target/mips: Fix data type for offset target/mips: Update BadInstr{P} regs on nanoMIPS target/mips: Config3.ISAOnExc is read only in nanoMIPS target/mips: Fix ERET/ERETNC can cause ADEL exception target/mips: Fix gdbstub to read/write 64 bit FP registers
hw/mips/mips_malta.c | 153 +- include/elf.h | 1 + linux-user/mips/cpu_loop.c | 25 +- target/mips/cpu.h | 3 + target/mips/gdbstub.c | 16 +- target/mips/helper.c | 39 +- target/mips/helper.h | 4 + target/mips/machine.c | 1 + target/mips/mips-defs.h | 4 + target/mips/op_helper.c | 166 ++- target/mips/translate.c | 3017 +++++++++++++++++++++++++++++++++++++- target/mips/translate_init.inc.c | 37 + 12 files changed, 3408 insertions(+), 58 deletions(-)
--
1.9.1