^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2012 Regents of the University of California
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2017 SiFive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/csr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #if !IS_ENABLED(CONFIG_PREEMPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .set resume_kernel, restore_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ENTRY(handle_exception)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * If coming from userspace, preserve the user thread pointer and load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * the kernel thread pointer. If we came from the kernel, the scratch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * register will contain 0, and we should continue on the current TP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) csrrw tp, CSR_SCRATCH, tp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) bnez tp, _save_context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) _restore_kernel_tpsp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) csrr tp, CSR_SCRATCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) REG_S sp, TASK_TI_KERNEL_SP(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) _save_context:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) REG_S sp, TASK_TI_USER_SP(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) REG_L sp, TASK_TI_KERNEL_SP(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) addi sp, sp, -(PT_SIZE_ON_STACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) REG_S x1, PT_RA(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) REG_S x3, PT_GP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) REG_S x5, PT_T0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) REG_S x6, PT_T1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) REG_S x7, PT_T2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) REG_S x8, PT_S0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) REG_S x9, PT_S1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) REG_S x10, PT_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) REG_S x11, PT_A1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) REG_S x12, PT_A2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) REG_S x13, PT_A3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) REG_S x14, PT_A4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) REG_S x15, PT_A5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) REG_S x16, PT_A6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) REG_S x17, PT_A7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) REG_S x18, PT_S2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) REG_S x19, PT_S3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) REG_S x20, PT_S4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) REG_S x21, PT_S5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) REG_S x22, PT_S6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) REG_S x23, PT_S7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) REG_S x24, PT_S8(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) REG_S x25, PT_S9(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) REG_S x26, PT_S10(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) REG_S x27, PT_S11(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) REG_S x28, PT_T3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) REG_S x29, PT_T4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) REG_S x30, PT_T5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) REG_S x31, PT_T6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Disable user-mode memory access as it should only be set in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * actual user copy routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * Disable the FPU to detect illegal usage of floating point in kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) li t0, SR_SUM | SR_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) REG_L s0, TASK_TI_USER_SP(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) csrrc s1, CSR_STATUS, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) csrr s2, CSR_EPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) csrr s3, CSR_TVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) csrr s4, CSR_CAUSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) csrr s5, CSR_SCRATCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) REG_S s0, PT_SP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) REG_S s1, PT_STATUS(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) REG_S s2, PT_EPC(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) REG_S s3, PT_BADADDR(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) REG_S s4, PT_CAUSE(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) REG_S s5, PT_TP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Set the scratch register to 0, so that if a recursive exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * occurs, the exception vector knows it came from the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) csrw CSR_SCRATCH, x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* Load the global pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .option push
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .option norelax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) la gp, __global_pointer$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .option pop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) call __trace_hardirqs_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #ifdef CONFIG_CONTEXT_TRACKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* If previous state is in user mode, call context_tracking_user_exit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) li a0, SR_PP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) and a0, s1, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bnez a0, skip_context_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) call context_tracking_user_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) skip_context_tracking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * MSB of cause differentiates between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * interrupts and exceptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) bge s4, zero, 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) la ra, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Handle interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) move a0, sp /* pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) la a1, handle_arch_irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) REG_L a1, (a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) jr a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Exceptions run with interrupts enabled or disabled depending on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * state of SR_PIE in m/sstatus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) andi t0, s1, SR_PIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) beqz t0, 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) call __trace_hardirqs_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) csrs CSR_STATUS, SR_IE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) la ra, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Handle syscalls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) li t0, EXC_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) beq s4, t0, handle_syscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Handle other exceptions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) slli t0, s4, RISCV_LGPTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) la t1, excp_vect_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) la t2, excp_vect_table_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) move a0, sp /* pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) add t0, t1, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* Check if exception code lies within bounds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) bgeu t0, t2, 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) REG_L t0, 0(t0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) jr t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) tail do_trap_unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) handle_syscall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #ifdef CONFIG_RISCV_M_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * When running is M-Mode (no MMU config), MPIE does not get set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * As a result, we need to force enable interrupts here because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * handle_exception did not do set SR_IE as it always sees SR_PIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * being cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) csrs CSR_STATUS, SR_IE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Recover a0 - a7 for system calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) REG_L a0, PT_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) REG_L a1, PT_A1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) REG_L a2, PT_A2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) REG_L a3, PT_A3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) REG_L a4, PT_A4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) REG_L a5, PT_A5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) REG_L a6, PT_A6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) REG_L a7, PT_A7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* save the initial A0 value (needed in signal handlers) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) REG_S a0, PT_ORIG_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Advance SEPC to avoid executing the original
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * scall instruction on sret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) addi s2, s2, 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) REG_S s2, PT_EPC(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Trace syscalls, but only if requested by the user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) REG_L t0, TASK_TI_FLAGS(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) andi t0, t0, _TIF_SYSCALL_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bnez t0, handle_syscall_trace_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) check_syscall_nr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Check to make sure we don't jump to a bogus syscall number. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) li t0, __NR_syscalls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) la s0, sys_ni_syscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * Syscall number held in a7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * If syscall number is above allowed value, redirect to ni_syscall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) bgeu a7, t0, 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Call syscall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) la s0, sys_call_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) slli t0, a7, RISCV_LGPTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) add s0, s0, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) REG_L s0, 0(s0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) jalr s0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ret_from_syscall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Set user a0 to kernel a0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) REG_S a0, PT_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * We didn't execute the actual syscall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Seccomp already set return value for the current task pt_regs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * (If it was configured with SECCOMP_RET_ERRNO/TRACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ret_from_syscall_rejected:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Trace syscalls, but only if requested by the user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) REG_L t0, TASK_TI_FLAGS(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) andi t0, t0, _TIF_SYSCALL_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bnez t0, handle_syscall_trace_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ret_from_exception:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) REG_L s0, PT_STATUS(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) csrc CSR_STATUS, SR_IE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) call __trace_hardirqs_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #ifdef CONFIG_RISCV_M_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* the MPP value is too large to be used as an immediate arg for addi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) li t0, SR_MPP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) and s0, s0, t0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) andi s0, s0, SR_SPP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) bnez s0, resume_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) resume_userspace:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Interrupts must be disabled here so flags are checked atomically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) REG_L s0, TASK_TI_FLAGS(tp) /* current_thread_info->flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) andi s1, s0, _TIF_WORK_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) bnez s1, work_pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_CONTEXT_TRACKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) call context_tracking_user_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* Save unwound kernel stack pointer in thread_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) addi s0, sp, PT_SIZE_ON_STACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) REG_S s0, TASK_TI_KERNEL_SP(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Save TP into the scratch register , so we can find the kernel data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * structures again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) csrw CSR_SCRATCH, tp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) restore_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) REG_L s1, PT_STATUS(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) andi t0, s1, SR_PIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) beqz t0, 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) call __trace_hardirqs_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) j 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) call __trace_hardirqs_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) REG_L a0, PT_STATUS(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * The current load reservation is effectively part of the processor's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * state, in the sense that load reservations cannot be shared between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * different hart contexts. We can't actually save and restore a load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * reservation, so instead here we clear any existing reservation --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * it's always legal for implementations to clear load reservations at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * any point (as long as the forward progress guarantee is kept, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * we'll ignore that here).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Dangling load reservations can be the result of taking a trap in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * middle of an LR/SC sequence, but can also be the result of a taken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * forward branch around an SC -- which is how we implement CAS. As a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * result we need to clear reservations between the last CAS and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * jump back to the new context. While it is unlikely the store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * completes, implementations are allowed to expand reservations to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * arbitrarily large.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) REG_L a2, PT_EPC(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) REG_SC x0, a2, PT_EPC(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) csrw CSR_STATUS, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) csrw CSR_EPC, a2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) REG_L x1, PT_RA(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) REG_L x3, PT_GP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) REG_L x4, PT_TP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) REG_L x5, PT_T0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) REG_L x6, PT_T1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) REG_L x7, PT_T2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) REG_L x8, PT_S0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) REG_L x9, PT_S1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) REG_L x10, PT_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) REG_L x11, PT_A1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) REG_L x12, PT_A2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) REG_L x13, PT_A3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) REG_L x14, PT_A4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) REG_L x15, PT_A5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) REG_L x16, PT_A6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) REG_L x17, PT_A7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) REG_L x18, PT_S2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) REG_L x19, PT_S3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) REG_L x20, PT_S4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) REG_L x21, PT_S5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) REG_L x22, PT_S6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) REG_L x23, PT_S7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) REG_L x24, PT_S8(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) REG_L x25, PT_S9(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) REG_L x26, PT_S10(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) REG_L x27, PT_S11(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) REG_L x28, PT_T3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) REG_L x29, PT_T4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) REG_L x30, PT_T5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) REG_L x31, PT_T6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) REG_L x2, PT_SP(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #ifdef CONFIG_RISCV_M_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) mret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) sret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) #if IS_ENABLED(CONFIG_PREEMPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) resume_kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) REG_L s0, TASK_TI_PREEMPT_COUNT(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) bnez s0, restore_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) REG_L s0, TASK_TI_FLAGS(tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) andi s0, s0, _TIF_NEED_RESCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) beqz s0, restore_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) call preempt_schedule_irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) j restore_all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) work_pending:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* Enter slow path for supplementary processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) la ra, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) andi s1, s0, _TIF_NEED_RESCHED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) bnez s1, work_resched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) work_notifysig:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* Handle pending signals and notify-resume requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) csrs CSR_STATUS, SR_IE /* Enable interrupts for do_notify_resume() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) move a0, sp /* pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) move a1, s0 /* current_thread_info->flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) tail do_notify_resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) work_resched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) tail schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* Slow paths for ptrace. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) handle_syscall_trace_enter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) move a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) call do_syscall_trace_enter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) move t0, a0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) REG_L a0, PT_A0(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) REG_L a1, PT_A1(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) REG_L a2, PT_A2(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) REG_L a3, PT_A3(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) REG_L a4, PT_A4(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) REG_L a5, PT_A5(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) REG_L a6, PT_A6(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) REG_L a7, PT_A7(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) bnez t0, ret_from_syscall_rejected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) j check_syscall_nr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) handle_syscall_trace_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) move a0, sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) call do_syscall_trace_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) j ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) END(handle_exception)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) ENTRY(ret_from_fork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) la ra, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) tail schedule_tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ENDPROC(ret_from_fork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ENTRY(ret_from_kernel_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) call schedule_tail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* Call fn(arg) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) la ra, ret_from_exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) move a0, s1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) jr s0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) ENDPROC(ret_from_kernel_thread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * Integer register context switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * The callee-saved registers must be saved and restored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * a0: previous task_struct (must be preserved across the switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * a1: next task_struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * The value of a0 and a1 must be preserved by this function, as that's how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * arguments are passed to schedule_tail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ENTRY(__switch_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* Save context into prev->thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) li a4, TASK_THREAD_RA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) add a3, a0, a4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) add a4, a1, a4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) REG_S ra, TASK_THREAD_RA_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) REG_S sp, TASK_THREAD_SP_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) REG_S s0, TASK_THREAD_S0_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) REG_S s1, TASK_THREAD_S1_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) REG_S s2, TASK_THREAD_S2_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) REG_S s3, TASK_THREAD_S3_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) REG_S s4, TASK_THREAD_S4_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) REG_S s5, TASK_THREAD_S5_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) REG_S s6, TASK_THREAD_S6_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) REG_S s7, TASK_THREAD_S7_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) REG_S s8, TASK_THREAD_S8_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) REG_S s9, TASK_THREAD_S9_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) REG_S s10, TASK_THREAD_S10_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) REG_S s11, TASK_THREAD_S11_RA(a3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* Restore context from next->thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) REG_L ra, TASK_THREAD_RA_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) REG_L sp, TASK_THREAD_SP_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) REG_L s0, TASK_THREAD_S0_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) REG_L s1, TASK_THREAD_S1_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) REG_L s2, TASK_THREAD_S2_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) REG_L s3, TASK_THREAD_S3_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) REG_L s4, TASK_THREAD_S4_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) REG_L s5, TASK_THREAD_S5_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) REG_L s6, TASK_THREAD_S6_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) REG_L s7, TASK_THREAD_S7_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) REG_L s8, TASK_THREAD_S8_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) REG_L s9, TASK_THREAD_S9_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) REG_L s10, TASK_THREAD_S10_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) REG_L s11, TASK_THREAD_S11_RA(a4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* Swap the CPU entry around. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) lw a3, TASK_TI_CPU(a0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) lw a4, TASK_TI_CPU(a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sw a3, TASK_TI_CPU(a1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) sw a4, TASK_TI_CPU(a0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* The offset of thread_info in task_struct is zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) move tp, a1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) ENDPROC(__switch_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #define do_page_fault do_trap_unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) .section ".rodata"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) .align LGREG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* Exception vector table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) ENTRY(excp_vect_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) RISCV_PTR do_trap_insn_misaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) RISCV_PTR do_trap_insn_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) RISCV_PTR do_trap_insn_illegal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) RISCV_PTR do_trap_break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) RISCV_PTR do_trap_load_misaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) RISCV_PTR do_trap_load_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) RISCV_PTR do_trap_store_misaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) RISCV_PTR do_trap_store_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) RISCV_PTR do_trap_ecall_u /* system call, gets intercepted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) RISCV_PTR do_trap_ecall_s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) RISCV_PTR do_trap_unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) RISCV_PTR do_trap_ecall_m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) RISCV_PTR do_page_fault /* instruction page fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) RISCV_PTR do_page_fault /* load page fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) RISCV_PTR do_trap_unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) RISCV_PTR do_page_fault /* store page fault */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) excp_vect_table_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) END(excp_vect_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ENTRY(__user_rt_sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) li a7, __NR_rt_sigreturn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) scall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) END(__user_rt_sigreturn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) #endif