Received: from eggs.gnu.org ([2001:4830:134:3::10]:60884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1by99L-0004Na-8O for qemu-devel@nongnu.org; Sat, 22 Oct 2016 23:08:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1by99I-0003ah-3K for qemu-devel@nongnu.org; Sat, 22 Oct 2016 23:08:39 -0400 Received: from mail-out.m-online.net ([2001:a60:0:28:0:1:25:1]:43681) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1by99H-0003Zv-Pt for qemu-devel@nongnu.org; Sat, 22 Oct 2016 23:08:36 -0400 References: <20161019032935.6717-1-marex@denx.de> <20161020134401.3703-1-marex@denx.de> From: Marek Vasut Message-ID: <73051219-52a0-5506-e18d-3eb316c63b36@denx.de> Date: Sun, 23 Oct 2016 05:01:38 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V5 2/7] nios2: Add architecture emulation support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson , qemu-devel@nongnu.org Cc: Chris Wulff , Jeff Da Silva , Ley Foon Tan , Sandra Loosemore , Yves Vandervennet On 10/20/2016 04:35 PM, Richard Henderson wrote: > On 10/20/2016 06:44 AM, Marek Vasut wrote: >> +typedef struct Nios2Instruction { >> + void (*handler)(DisasContext *dc, uint32_t code, TCGMemOp >> flags); >> + uint32_t flags; >> +} Nios2Instruction; > > I gave you some bad advice wrt the type of flags beforehand. I had > failed to divine that it was also used for EXCP_* and TCG_COND_*. I > think you were right the first time with unsigned. > > My bad, sorry. I undid the change, thanks. >> +/* Load instructions */ >> +static void gen_ldx(DisasContext *dc, uint32_t code, TCGMemOp flags) >> +{ >> + I_TYPE(instr, code); >> + >> + TCGv addr = tcg_temp_new(); >> + TCGv data = tcg_temp_new(); >> + tcg_gen_addi_tl(addr, load_gpr(dc, instr.a), instr.imm16s); >> + tcg_gen_qemu_ld_tl(data, addr, dc->mem_idx, flags); >> + >> + /* >> + * WARNING: Loads into R_ZERO are ignored, but we must generate the >> + * memory access itself to emulate the CPU precisely. Load >> + * from a protected page to R_ZERO will cause SIGSEGV on >> + * the Nios2 CPU. >> + */ >> + if (likely(instr.b != R_ZERO)) { >> + tcg_gen_mov_tl(dc->cpu_R[instr.b], data); >> + } > > Consider > > TCGv data; > > if (unlikely(instr.b == R_ZERO)) { > /* The writeback to R_ZERO is ignored, but we must generate the > * memory access itself to emulate the CPU precisely. Load from > * a protected page to R_ZERO will cause SIGSEGV on the Nios2 CPU. > */ > data = tcg_temp_new(); > } else { > data = dc->cpu_R[instr.b]; > } > > tcg_gen_qemu_ld_tl(data, addr, dc->mem_idx, flags); > > if (unlikely(instr.b == R_ZERO)) { > tcg_temp_free(data); > } > > so that you don't require the mov opcode. > > That's really what I do on Alpha with dest_gpr. OK >> +#define gen_r_div(fname, >> insn) \ >> +static void (fname)(DisasContext *dc, uint32_t code, TCGMemOp >> flags) \ >> +{ >> \ >> + R_TYPE(instr, >> (code)); \ >> + if (likely(instr.c != R_ZERO)) >> { \ >> + TCGv val = >> tcg_const_tl(0); \ >> + tcg_gen_setcond_tl(TCG_COND_EQ, val, load_gpr((dc), instr.b), >> val); \ >> + tcg_gen_or_tl(val, val, load_gpr((dc), >> instr.b)); \ >> + tcg_gen_##insn((dc)->cpu_R[instr.c], load_gpr((dc), instr.a), >> val); \ >> + >> tcg_temp_free(val); \ >> + >> } \ >> +} >> + >> +gen_r_div(divs, div_tl) > > For signed division, you have to protect against 0x80000000 / -1 as > well, which raises an overflow exception on the x86 host. You mean similar to what mips does on OPC_DIV vs OPC_DIVU , right ? >> + /* Set up instruction counts */ >> + num_insns = 0; >> + max_insns = tb->cflags & CF_COUNT_MASK; >> + if (max_insns == 0) { >> + max_insns = CF_COUNT_MASK; >> + } >> + if (max_insns > TCG_MAX_INSNS) { >> + max_insns = TCG_MAX_INSNS; >> + } >> + next_page_start = (tb->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; > ... >> + } while (!dc->is_jmp && >> + !tcg_op_buf_full() && >> + !cs->singlestep_enabled && >> + !singlestep && >> + dc->pc < next_page_start && >> + num_insns < max_insns); > > Consider > > if (cs->singlestep_enabled || singlestep) { > max_insns = 1; > } else { > int page_insns = (TARGET_PAGE_SIZE - (tb->pc & TARGET_PAGE_MASK)) / 4; > max_insns = tb->cflags & CF_COUNT_MASK; > if (max_insns == 0) { > max_insns = CF_COUNT_MASK; > } > if (max_insns > page_insns) { > max_insns = page_insns; > } > if (max_insns > TCG_MAX_INSNS) { > max_insns = TCG_MAX_INSNS; > } > } > > so that we collapse the last 4 loop conditions into: num_insns < max_insns. OK, fixed. >> + /* End off the block */ >> + gen_tb_end(tb, num_insns); >> + >> + /* Mark instruction starts for the final generated instruction */ >> + tb->size = dc->pc - tb->pc; >> + tb->icount = num_insns; > > No CPU_LOG_TB_IN_ASM disassembly? I thought patch 1 added a nios2 > disassembler. Nope, I removed it in V4, maybe i misunderstood the review comment? " > + /* Dump the CPU state to the log */ > + if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { > + qemu_log("--------------\n"); > + log_cpu_state(cs, 0); > + } Cpu state is dumped by -d cpu generically. " -- Best regards, Marek Vasut