| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved. |
| 4 |
* Copyright 2010 Tilera Corporation. All Rights Reserved. |
| 5 |
* Copyright 2015 Regents of the University of California, Berkeley |
| 6 |
* |
| 7 |
* See asm-generic/syscall.h for descriptions of what we must do here. |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef _ASM_RISCV_SYSCALL_H |
| 11 |
#define _ASM_RISCV_SYSCALL_H |
| 12 |
|
| 13 |
#include <asm/hwprobe.h> |
| 14 |
#include <uapi/linux/audit.h> |
| 15 |
#include <linux/sched.h> |
| 16 |
#include <linux/err.h> |
| 17 |
|
| 18 |
/* The array of function pointers for syscalls. */ |
| 19 |
extern void * const sys_call_table[]; |
| 20 |
extern void * const compat_sys_call_table[]; |
| 21 |
|
| 22 |
/* |
| 23 |
* Only the low 32 bits of orig_a0 are meaningful, so we return int. |
| 24 |
* This importantly ignores the high bits on 64-bit, so comparisons |
| 25 |
* sign-extend the low 32 bits. |
| 26 |
*/ |
| 27 |
static inline int syscall_get_nr(struct task_struct *task, |
| 28 |
struct pt_regs *regs) |
| 29 |
{ |
| 30 |
return regs->a7; |
| 31 |
} |
| 32 |
|
| 33 |
static inline void syscall_set_nr(struct task_struct *task, |
| 34 |
struct pt_regs *regs, |
| 35 |
int nr) |
| 36 |
{ |
| 37 |
regs->a7 = nr; |
| 38 |
} |
| 39 |
|
| 40 |
static inline void syscall_rollback(struct task_struct *task, |
| 41 |
struct pt_regs *regs) |
| 42 |
{ |
| 43 |
regs->a0 = regs->orig_a0; |
| 44 |
} |
| 45 |
|
| 46 |
static inline long syscall_get_error(struct task_struct *task, |
| 47 |
struct pt_regs *regs) |
| 48 |
{ |
| 49 |
unsigned long error = regs->a0; |
| 50 |
|
| 51 |
return IS_ERR_VALUE(error) ? error : 0; |
| 52 |
} |
| 53 |
|
| 54 |
static inline long syscall_get_return_value(struct task_struct *task, |
| 55 |
struct pt_regs *regs) |
| 56 |
{ |
| 57 |
return regs->a0; |
| 58 |
} |
| 59 |
|
| 60 |
static inline void syscall_set_return_value(struct task_struct *task, |
| 61 |
struct pt_regs *regs, |
| 62 |
int error, long val) |
| 63 |
{ |
| 64 |
regs->a0 = (long) error ?: val; |
| 65 |
} |
| 66 |
|
| 67 |
static inline void syscall_get_arguments(struct task_struct *task, |
| 68 |
struct pt_regs *regs, |
| 69 |
unsigned long *args) |
| 70 |
{ |
| 71 |
args[0] = regs->orig_a0; |
| 72 |
args[1] = regs->a1; |
| 73 |
args[2] = regs->a2; |
| 74 |
args[3] = regs->a3; |
| 75 |
args[4] = regs->a4; |
| 76 |
args[5] = regs->a5; |
| 77 |
} |
| 78 |
|
| 79 |
static inline void syscall_set_arguments(struct task_struct *task, |
| 80 |
struct pt_regs *regs, |
| 81 |
const unsigned long *args) |
| 82 |
{ |
| 83 |
regs->orig_a0 = args[0]; |
| 84 |
regs->a1 = args[1]; |
| 85 |
regs->a2 = args[2]; |
| 86 |
regs->a3 = args[3]; |
| 87 |
regs->a4 = args[4]; |
| 88 |
regs->a5 = args[5]; |
| 89 |
} |
| 90 |
|
| 91 |
static inline int syscall_get_arch(struct task_struct *task) |
| 92 |
{ |
| 93 |
#ifdef CONFIG_64BIT |
| 94 |
return AUDIT_ARCH_RISCV64; |
| 95 |
#else |
| 96 |
return AUDIT_ARCH_RISCV32; |
| 97 |
#endif |
| 98 |
} |
| 99 |
|
| 100 |
typedef long (*syscall_t)(const struct pt_regs *); |
| 101 |
static inline void syscall_handler(struct pt_regs *regs, ulong syscall) |
| 102 |
{ |
| 103 |
syscall_t fn; |
| 104 |
|
| 105 |
#ifdef CONFIG_COMPAT |
| 106 |
if ((regs->status & SR_UXL) == SR_UXL_32) |
| 107 |
fn = compat_sys_call_table[syscall]; |
| 108 |
else |
| 109 |
#endif |
| 110 |
fn = sys_call_table[syscall]; |
| 111 |
|
| 112 |
regs->a0 = fn(regs); |
| 113 |
} |
| 114 |
|
| 115 |
static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) |
| 116 |
{ |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); |
| 121 |
|
| 122 |
asmlinkage long sys_riscv_hwprobe(struct riscv_hwprobe *, size_t, size_t, |
| 123 |
unsigned long *, unsigned int); |
| 124 |
#endif /* _ASM_RISCV_SYSCALL_H */ |