[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 17/41] linux-user/host/riscv: Improve host_signal_write
From: |
Alistair Francis |
Subject: |
Re: [PATCH v4 17/41] linux-user/host/riscv: Improve host_signal_write |
Date: |
Thu, 7 Oct 2021 07:35:34 +1000 |
On Thu, Oct 7, 2021 at 3:37 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Do not read 4 bytes before we determine the size of the insn.
> Simplify triple switches in favor of checking major opcodes.
> Include the missing cases of compact fsd and fsdsp.
>
> Cc: qemu-riscv@nongnu.org
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> linux-user/host/riscv/host-signal.h | 83 ++++++++++-------------------
> 1 file changed, 28 insertions(+), 55 deletions(-)
>
> diff --git a/linux-user/host/riscv/host-signal.h
> b/linux-user/host/riscv/host-signal.h
> index 5860dce7d7..ab06d70964 100644
> --- a/linux-user/host/riscv/host-signal.h
> +++ b/linux-user/host/riscv/host-signal.h
> @@ -17,65 +17,38 @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
>
> static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
> {
> - uint32_t insn = *(uint32_t *)host_signal_pc(uc);
> -
> /*
> - * Detect store by reading the instruction at the program
> - * counter. Note: we currently only generate 32-bit
> - * instructions so we thus only detect 32-bit stores
> + * Detect store by reading the instruction at the program counter.
> + * Do not read more than 16 bits, because we have not yet determined
> + * the size of the instruction.
> */
> - switch (((insn >> 0) & 0b11)) {
> - case 3:
> - switch (((insn >> 2) & 0b11111)) {
> - case 8:
> - switch (((insn >> 12) & 0b111)) {
> - case 0: /* sb */
> - case 1: /* sh */
> - case 2: /* sw */
> - case 3: /* sd */
> - case 4: /* sq */
> - return true;
> - default:
> - break;
> - }
> - break;
> - case 9:
> - switch (((insn >> 12) & 0b111)) {
> - case 2: /* fsw */
> - case 3: /* fsd */
> - case 4: /* fsq */
> - return true;
> - default:
> - break;
> - }
> - break;
> - default:
> - break;
> - }
> + const uint16_t *pinsn = (const uint16_t *)host_signal_pc(uc);
> + uint16_t insn = pinsn[0];
> +
> + /* 16-bit instructions */
> + switch (insn & 0xe003) {
> + case 0xa000: /* c.fsd */
> + case 0xc000: /* c.sw */
> + case 0xe000: /* c.sd (rv64) / c.fsw (rv32) */
> + case 0xa002: /* c.fsdsp */
> + case 0xc002: /* c.swsp */
> + case 0xe002: /* c.sdsp (rv64) / c.fswsp (rv32) */
> + return true;
> }
>
> - /* Check for compressed instructions */
> - switch (((insn >> 13) & 0b111)) {
> - case 7:
> - switch (insn & 0b11) {
> - case 0: /*c.sd */
> - case 2: /* c.sdsp */
> - return true;
> - default:
> - break;
> - }
> - break;
> - case 6:
> - switch (insn & 0b11) {
> - case 0: /* c.sw */
> - case 3: /* c.swsp */
> - return true;
> - default:
> - break;
> - }
> - break;
> - default:
> - break;
> + /* 32-bit instructions, major opcodes */
> + switch (insn & 0x7f) {
> + case 0x23: /* store */
> + case 0x27: /* store-fp */
> + return true;
> + case 0x2f: /* amo */
> + /*
> + * The AMO function code is in bits 25-31, unread as yet.
> + * The AMO functions are LR (read), SC (write), and the
> + * rest are all read-modify-write.
> + */
> + insn = pinsn[1];
> + return (insn >> 11) != 2; /* LR */
> }
>
> return false;
> --
> 2.25.1
>
>
- [PATCH v4 00/41] linux-user: Streamline handling of SIGSEGV, Richard Henderson, 2021/10/06
- [PATCH v4 03/41] accel/tcg: Split out handle_sigsegv_accerr_write, Richard Henderson, 2021/10/06
- [PATCH v4 04/41] accel/tcg: Fold cpu_exit_tb_from_sighandler into caller, Richard Henderson, 2021/10/06
- [PATCH v4 05/41] configure: Merge riscv32 and riscv64 host architectures, Richard Henderson, 2021/10/06
- [PATCH v4 06/41] linux-user: Reorg handling for SIGSEGV, Richard Henderson, 2021/10/06
- [PATCH v4 12/41] linux-user/host/aarch64: Populate host_signal.h, Richard Henderson, 2021/10/06
- [PATCH v4 13/41] linux-user/host/s390: Populate host_signal.h, Richard Henderson, 2021/10/06
- [PATCH v4 14/41] linux-user/host/mips: Populate host_signal.h, Richard Henderson, 2021/10/06
- [PATCH v4 16/41] target/arm: Fixup comment re handle_cpu_signal, Richard Henderson, 2021/10/06
- [PATCH v4 17/41] linux-user/host/riscv: Improve host_signal_write, Richard Henderson, 2021/10/06
- Re: [PATCH v4 17/41] linux-user/host/riscv: Improve host_signal_write,
Alistair Francis <=
- [PATCH v4 10/41] linux-user/host/sparc: Populate host_signal.h, Richard Henderson, 2021/10/06
- [PATCH v4 19/41] hw/core: Add TCGCPUOps.record_sigsegv, Richard Henderson, 2021/10/06
- [PATCH v4 26/41] target/hppa: Make hppa_cpu_tlb_fill sysemu only, Richard Henderson, 2021/10/06
- [PATCH v4 29/41] target/microblaze: Make mb_cpu_tlb_fill sysemu only, Richard Henderson, 2021/10/06
- [PATCH v4 15/41] linux-user/host/riscv: Populate host_signal.h, Richard Henderson, 2021/10/06
- [PATCH v4 18/41] linux-user/signal: Drop HOST_SIGNAL_PLACEHOLDER, Richard Henderson, 2021/10/06
- [PATCH v4 20/41] linux-user: Add cpu_loop_exit_sigsegv, Richard Henderson, 2021/10/06
- [PATCH v4 21/41] target/alpha: Implement alpha_cpu_record_sigsegv, Richard Henderson, 2021/10/06
- [PATCH v4 23/41] target/arm: Implement arm_cpu_record_sigsegv, Richard Henderson, 2021/10/06