Skip to content

Commit dfb0bfa

Browse files
guoren83palmer-dabbelt
authored andcommitted
riscv: compat: syscall: Add entry.S implementation
Implement the entry of compat_sys_call_table[] in asm. Ref to riscv-privileged spec 4.1.1 Supervisor Status Register (sstatus): BIT[32:33] = UXL[1:0]: - 1:32 - 2:64 - 3:128 Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@kernel.org> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Tested-by: Heiko Stuebner <heiko@sntech.de> Link: https://lore.kernel.org/r/20220405071314.3225832-13-guoren@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 59c10c5 commit dfb0bfa

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

arch/riscv/include/asm/csr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
#define SR_SD _AC(0x8000000000000000, UL) /* FS/XS dirty */
3737
#endif
3838

39+
#ifdef CONFIG_64BIT
40+
#define SR_UXL _AC(0x300000000, UL) /* XLEN mask for U-mode */
41+
#define SR_UXL_32 _AC(0x100000000, UL) /* XLEN = 32 for U-mode */
42+
#define SR_UXL_64 _AC(0x200000000, UL) /* XLEN = 64 for U-mode */
43+
#define SR_UXL_SHIFT 32
44+
#endif
45+
3946
/* SATP flags */
4047
#ifndef CONFIG_64BIT
4148
#define SATP_PPN _AC(0x003FFFFF, UL)

arch/riscv/kernel/entry.S

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,27 @@ check_syscall_nr:
207207
* Syscall number held in a7.
208208
* If syscall number is above allowed value, redirect to ni_syscall.
209209
*/
210-
bgeu a7, t0, 1f
210+
bgeu a7, t0, 3f
211+
#ifdef CONFIG_COMPAT
212+
REG_L s0, PT_STATUS(sp)
213+
srli s0, s0, SR_UXL_SHIFT
214+
andi s0, s0, (SR_UXL >> SR_UXL_SHIFT)
215+
li t0, (SR_UXL_32 >> SR_UXL_SHIFT)
216+
sub t0, s0, t0
217+
bnez t0, 1f
218+
219+
/* Call compat_syscall */
220+
la s0, compat_sys_call_table
221+
j 2f
222+
1:
223+
#endif
211224
/* Call syscall */
212225
la s0, sys_call_table
226+
2:
213227
slli t0, a7, RISCV_LGPTR
214228
add s0, s0, t0
215229
REG_L s0, 0(s0)
216-
1:
230+
3:
217231
jalr s0
218232

219233
ret_from_syscall:

0 commit comments

Comments
 (0)