diff --git a/sys/arch/riscv/include/locore.h b/sys/arch/riscv/include/locore.h index 57a7a389d11b..6cbb2d92fe0f 100644 --- a/sys/arch/riscv/include/locore.h +++ b/sys/arch/riscv/include/locore.h @@ -1,4 +1,4 @@ -/* $NetBSD: locore.h,v 1.12 2023/05/07 12:41:48 skrll Exp $ */ +/* $NetBSD: locore.h,v 1.13 2024/05/02 18:18:17 skrll Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -126,8 +126,8 @@ fpu_valid_p(lwp_t *l) void __syncicache(const void *, size_t); -int cpu_set_onfault(struct faultbuf *, register_t) __returns_twice; -void cpu_jump_onfault(struct trapframe *, const struct faultbuf *); +int cpu_set_onfault(struct faultbuf *) __returns_twice; +void cpu_jump_onfault(struct trapframe *, const struct faultbuf *, int); static inline void cpu_unset_onfault(void) diff --git a/sys/arch/riscv/riscv/cpu_switch.S b/sys/arch/riscv/riscv/cpu_switch.S index 9999fa917b2b..d2de7cb19263 100644 --- a/sys/arch/riscv/riscv/cpu_switch.S +++ b/sys/arch/riscv/riscv/cpu_switch.S @@ -1,4 +1,4 @@ -/* $NetBSD: cpu_switch.S,v 1.5 2023/05/07 12:41:48 skrll Exp $ */ +/* $NetBSD: cpu_switch.S,v 1.6 2024/05/02 18:18:17 skrll Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -459,7 +459,7 @@ END(cpu_exception_handler) /* * int - * cpu_set_onfault(struct faultbuf *fb, register_t retval) + * cpu_set_onfault(struct faultbuf *fb) */ ENTRY_NP(cpu_set_onfault) REG_S ra, FB_RA(a0) @@ -476,7 +476,6 @@ ENTRY_NP(cpu_set_onfault) REG_S s10, FB_S10(a0) REG_S s11, FB_S11(a0) REG_S sp, FB_SP(a0) - REG_S a1, FB_A0(a0) PTR_S a0, L_MD_ONFAULT(tp) li a0, 0 ret diff --git a/sys/arch/riscv/riscv/trap.c b/sys/arch/riscv/riscv/trap.c index 49d432bfa36c..ff7f3c7c588c 100644 --- a/sys/arch/riscv/riscv/trap.c +++ b/sys/arch/riscv/riscv/trap.c @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.25 2024/04/01 16:24:01 skrll Exp $ */ +/* $NetBSD: trap.c,v 1.26 2024/05/02 18:18:17 skrll Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #define __PMAP_PRIVATE #define __UFETCHSTORE_PRIVATE -__RCSID("$NetBSD: trap.c,v 1.25 2024/04/01 16:24:01 skrll Exp $"); +__RCSID("$NetBSD: trap.c,v 1.26 2024/05/02 18:18:17 skrll Exp $"); #include @@ -90,10 +90,11 @@ static const char * const causenames[] = { [CAUSE_STORE_PAGE_FAULT] = "store page fault", }; + void -cpu_jump_onfault(struct trapframe *tf, const struct faultbuf *fb) +cpu_jump_onfault(struct trapframe *tf, const struct faultbuf *fb, int error) { - tf->tf_a0 = fb->fb_reg[FB_A0]; + tf->tf_a0 = error; tf->tf_ra = fb->fb_reg[FB_RA]; tf->tf_s0 = fb->fb_reg[FB_S0]; tf->tf_s1 = fb->fb_reg[FB_S1]; @@ -131,7 +132,7 @@ copyin(const void *uaddr, void *kaddr, size_t len) return EFAULT; csr_sstatus_set(SR_SUM); - if ((error = cpu_set_onfault(&fb, EFAULT)) == 0) { + if ((error = cpu_set_onfault(&fb)) == 0) { memcpy(kaddr, uaddr, len); cpu_unset_onfault(); } @@ -159,7 +160,7 @@ copyout(const void *kaddr, void *uaddr, size_t len) return EFAULT; csr_sstatus_set(SR_SUM); - if ((error = cpu_set_onfault(&fb, EFAULT)) == 0) { + if ((error = cpu_set_onfault(&fb)) == 0) { memcpy(uaddr, kaddr, len); cpu_unset_onfault(); } @@ -174,7 +175,7 @@ kcopy(const void *kfaddr, void *kdaddr, size_t len) struct faultbuf fb; int error; - if ((error = cpu_set_onfault(&fb, EFAULT)) == 0) { + if ((error = cpu_set_onfault(&fb)) == 0) { memcpy(kdaddr, kfaddr, len); cpu_unset_onfault(); } @@ -204,7 +205,7 @@ copyinstr(const void *uaddr, void *kaddr, size_t len, size_t *done) return EFAULT; csr_sstatus_set(SR_SUM); - if ((error = cpu_set_onfault(&fb, EFAULT)) == 0) { + if ((error = cpu_set_onfault(&fb)) == 0) { retlen = strlcpy(kaddr, uaddr, len); cpu_unset_onfault(); if (retlen >= len) { @@ -240,7 +241,7 @@ copyoutstr(const void *kaddr, void *uaddr, size_t len, size_t *done) return EFAULT; csr_sstatus_set(SR_SUM); - if ((error = cpu_set_onfault(&fb, EFAULT)) == 0) { + if ((error = cpu_set_onfault(&fb)) == 0) { retlen = strlcpy(uaddr, kaddr, len); cpu_unset_onfault(); if (retlen >= len) { @@ -517,7 +518,7 @@ trap_pagefault(struct trapframe *tf, register_t epc, register_t status, return false; } - cpu_jump_onfault(tf, fb); + cpu_jump_onfault(tf, fb, error); return true; } @@ -672,7 +673,7 @@ fetch_user_data(const void *uaddr, void *valp, size_t size) if (__predict_false(uva > VM_MAXUSER_ADDRESS - size)) return EFAULT; - if ((error = cpu_set_onfault(&fb, EFAULT)) != 0) + if ((error = cpu_set_onfault(&fb)) != 0) return error; csr_sstatus_set(SR_SUM); @@ -737,7 +738,7 @@ store_user_data(void *uaddr, const void *valp, size_t size) if (__predict_false(uva > VM_MAXUSER_ADDRESS - size)) return EFAULT; - if ((error = cpu_set_onfault(&fb, EFAULT)) != 0) + if ((error = cpu_set_onfault(&fb)) != 0) return error; csr_sstatus_set(SR_SUM);