| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
#ifndef __ASM_SPARC_SYSCALL_H |
| 3 |
#define __ASM_SPARC_SYSCALL_H |
| 4 |
|
| 5 |
#include <uapi/linux/audit.h> |
| 6 |
#include <linux/kernel.h> |
| 7 |
#include <linux/compat.h> |
| 8 |
#include <linux/sched.h> |
| 9 |
#include <asm/ptrace.h> |
| 10 |
#include <asm/thread_info.h> |
| 11 |
|
| 12 |
/* |
| 13 |
* The syscall table always contains 32 bit pointers since we know that the |
| 14 |
* address of the function to be called is (way) below 4GB. So the "int" |
| 15 |
* type here is what we want [need] for both 32 bit and 64 bit systems. |
| 16 |
*/ |
| 17 |
extern const unsigned int sys_call_table[]; |
| 18 |
|
| 19 |
/* The system call number is given by the user in %g1 */ |
| 20 |
static inline long syscall_get_nr(struct task_struct *task, |
| 21 |
struct pt_regs *regs) |
| 22 |
{ |
| 23 |
int syscall_p = pt_regs_is_syscall(regs); |
| 24 |
|
| 25 |
return (syscall_p ? regs->u_regs[UREG_G1] : -1L); |
| 26 |
} |
| 27 |
|
| 28 |
static inline void syscall_set_nr(struct task_struct *task, |
| 29 |
struct pt_regs *regs, |
| 30 |
int nr) |
| 31 |
{ |
| 32 |
/* |
| 33 |
* Unlike syscall_get_nr(), syscall_set_nr() can be called only when |
| 34 |
* the target task is stopped for tracing on entering syscall, so |
| 35 |
* there is no need to have the same check syscall_get_nr() has. |
| 36 |
*/ |
| 37 |
regs->u_regs[UREG_G1] = nr; |
| 38 |
} |
| 39 |
|
| 40 |
static inline void syscall_rollback(struct task_struct *task, |
| 41 |
struct pt_regs *regs) |
| 42 |
{ |
| 43 |
/* XXX This needs some thought. On Sparc we don't |
| 44 |
* XXX save away the original %o0 value somewhere. |
| 45 |
* XXX Instead we hold it in register %l5 at the top |
| 46 |
* XXX level trap frame and pass this down to the signal |
| 47 |
* XXX dispatch code which is the only place that value |
| 48 |
* XXX ever was needed. |
| 49 |
*/ |
| 50 |
} |
| 51 |
|
| 52 |
#ifdef CONFIG_SPARC32 |
| 53 |
static inline bool syscall_has_error(struct pt_regs *regs) |
| 54 |
{ |
| 55 |
return (regs->psr & PSR_C) ? true : false; |
| 56 |
} |
| 57 |
static inline void syscall_set_error(struct pt_regs *regs) |
| 58 |
{ |
| 59 |
regs->psr |= PSR_C; |
| 60 |
} |
| 61 |
static inline void syscall_clear_error(struct pt_regs *regs) |
| 62 |
{ |
| 63 |
regs->psr &= ~PSR_C; |
| 64 |
} |
| 65 |
#else |
| 66 |
static inline bool syscall_has_error(struct pt_regs *regs) |
| 67 |
{ |
| 68 |
return (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)) ? true : false; |
| 69 |
} |
| 70 |
static inline void syscall_set_error(struct pt_regs *regs) |
| 71 |
{ |
| 72 |
regs->tstate |= (TSTATE_XCARRY | TSTATE_ICARRY); |
| 73 |
} |
| 74 |
static inline void syscall_clear_error(struct pt_regs *regs) |
| 75 |
{ |
| 76 |
regs->tstate &= ~(TSTATE_XCARRY | TSTATE_ICARRY); |
| 77 |
} |
| 78 |
#endif |
| 79 |
|
| 80 |
static inline long syscall_get_error(struct task_struct *task, |
| 81 |
struct pt_regs *regs) |
| 82 |
{ |
| 83 |
long val = regs->u_regs[UREG_I0]; |
| 84 |
|
| 85 |
return (syscall_has_error(regs) ? -val : 0); |
| 86 |
} |
| 87 |
|
| 88 |
static inline long syscall_get_return_value(struct task_struct *task, |
| 89 |
struct pt_regs *regs) |
| 90 |
{ |
| 91 |
long val = regs->u_regs[UREG_I0]; |
| 92 |
|
| 93 |
return val; |
| 94 |
} |
| 95 |
|
| 96 |
static inline void syscall_set_return_value(struct task_struct *task, |
| 97 |
struct pt_regs *regs, |
| 98 |
int error, long val) |
| 99 |
{ |
| 100 |
if (error) { |
| 101 |
syscall_set_error(regs); |
| 102 |
regs->u_regs[UREG_I0] = -error; |
| 103 |
} else { |
| 104 |
syscall_clear_error(regs); |
| 105 |
regs->u_regs[UREG_I0] = val; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
static inline void syscall_get_arguments(struct task_struct *task, |
| 110 |
struct pt_regs *regs, |
| 111 |
unsigned long *args) |
| 112 |
{ |
| 113 |
int zero_extend = 0; |
| 114 |
unsigned int j; |
| 115 |
unsigned int n = 6; |
| 116 |
|
| 117 |
#ifdef CONFIG_SPARC64 |
| 118 |
if (test_tsk_thread_flag(task, TIF_32BIT)) |
| 119 |
zero_extend = 1; |
| 120 |
#endif |
| 121 |
|
| 122 |
for (j = 0; j < n; j++) { |
| 123 |
unsigned long val = regs->u_regs[UREG_I0 + j]; |
| 124 |
|
| 125 |
if (zero_extend) |
| 126 |
args[j] = (u32) val; |
| 127 |
else |
| 128 |
args[j] = val; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
static inline void syscall_set_arguments(struct task_struct *task, |
| 133 |
struct pt_regs *regs, |
| 134 |
const unsigned long *args) |
| 135 |
{ |
| 136 |
unsigned int i; |
| 137 |
|
| 138 |
for (i = 0; i < 6; i++) |
| 139 |
regs->u_regs[UREG_I0 + i] = args[i]; |
| 140 |
} |
| 141 |
|
| 142 |
static inline int syscall_get_arch(struct task_struct *task) |
| 143 |
{ |
| 144 |
#if defined(CONFIG_SPARC64) && defined(CONFIG_COMPAT) |
| 145 |
return test_tsk_thread_flag(task, TIF_32BIT) |
| 146 |
? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64; |
| 147 |
#elif defined(CONFIG_SPARC64) |
| 148 |
return AUDIT_ARCH_SPARC64; |
| 149 |
#else |
| 150 |
return AUDIT_ARCH_SPARC; |
| 151 |
#endif |
| 152 |
} |
| 153 |
|
| 154 |
#endif /* __ASM_SPARC_SYSCALL_H */ |