162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __ASM_SPARC_SYSCALL_H 362306a36Sopenharmony_ci#define __ASM_SPARC_SYSCALL_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <uapi/linux/audit.h> 662306a36Sopenharmony_ci#include <linux/kernel.h> 762306a36Sopenharmony_ci#include <linux/compat.h> 862306a36Sopenharmony_ci#include <linux/sched.h> 962306a36Sopenharmony_ci#include <asm/ptrace.h> 1062306a36Sopenharmony_ci#include <asm/thread_info.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* 1362306a36Sopenharmony_ci * The syscall table always contains 32 bit pointers since we know that the 1462306a36Sopenharmony_ci * address of the function to be called is (way) below 4GB. So the "int" 1562306a36Sopenharmony_ci * type here is what we want [need] for both 32 bit and 64 bit systems. 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ciextern const unsigned int sys_call_table[]; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* The system call number is given by the user in %g1 */ 2062306a36Sopenharmony_cistatic inline long syscall_get_nr(struct task_struct *task, 2162306a36Sopenharmony_ci struct pt_regs *regs) 2262306a36Sopenharmony_ci{ 2362306a36Sopenharmony_ci int syscall_p = pt_regs_is_syscall(regs); 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci return (syscall_p ? regs->u_regs[UREG_G1] : -1L); 2662306a36Sopenharmony_ci} 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task, 2962306a36Sopenharmony_ci struct pt_regs *regs) 3062306a36Sopenharmony_ci{ 3162306a36Sopenharmony_ci /* XXX This needs some thought. On Sparc we don't 3262306a36Sopenharmony_ci * XXX save away the original %o0 value somewhere. 3362306a36Sopenharmony_ci * XXX Instead we hold it in register %l5 at the top 3462306a36Sopenharmony_ci * XXX level trap frame and pass this down to the signal 3562306a36Sopenharmony_ci * XXX dispatch code which is the only place that value 3662306a36Sopenharmony_ci * XXX ever was needed. 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_ci} 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#ifdef CONFIG_SPARC32 4162306a36Sopenharmony_cistatic inline bool syscall_has_error(struct pt_regs *regs) 4262306a36Sopenharmony_ci{ 4362306a36Sopenharmony_ci return (regs->psr & PSR_C) ? true : false; 4462306a36Sopenharmony_ci} 4562306a36Sopenharmony_cistatic inline void syscall_set_error(struct pt_regs *regs) 4662306a36Sopenharmony_ci{ 4762306a36Sopenharmony_ci regs->psr |= PSR_C; 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_cistatic inline void syscall_clear_error(struct pt_regs *regs) 5062306a36Sopenharmony_ci{ 5162306a36Sopenharmony_ci regs->psr &= ~PSR_C; 5262306a36Sopenharmony_ci} 5362306a36Sopenharmony_ci#else 5462306a36Sopenharmony_cistatic inline bool syscall_has_error(struct pt_regs *regs) 5562306a36Sopenharmony_ci{ 5662306a36Sopenharmony_ci return (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)) ? true : false; 5762306a36Sopenharmony_ci} 5862306a36Sopenharmony_cistatic inline void syscall_set_error(struct pt_regs *regs) 5962306a36Sopenharmony_ci{ 6062306a36Sopenharmony_ci regs->tstate |= (TSTATE_XCARRY | TSTATE_ICARRY); 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_cistatic inline void syscall_clear_error(struct pt_regs *regs) 6362306a36Sopenharmony_ci{ 6462306a36Sopenharmony_ci regs->tstate &= ~(TSTATE_XCARRY | TSTATE_ICARRY); 6562306a36Sopenharmony_ci} 6662306a36Sopenharmony_ci#endif 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task, 6962306a36Sopenharmony_ci struct pt_regs *regs) 7062306a36Sopenharmony_ci{ 7162306a36Sopenharmony_ci long val = regs->u_regs[UREG_I0]; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci return (syscall_has_error(regs) ? -val : 0); 7462306a36Sopenharmony_ci} 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task, 7762306a36Sopenharmony_ci struct pt_regs *regs) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci long val = regs->u_regs[UREG_I0]; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci return val; 8262306a36Sopenharmony_ci} 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task, 8562306a36Sopenharmony_ci struct pt_regs *regs, 8662306a36Sopenharmony_ci int error, long val) 8762306a36Sopenharmony_ci{ 8862306a36Sopenharmony_ci if (error) { 8962306a36Sopenharmony_ci syscall_set_error(regs); 9062306a36Sopenharmony_ci regs->u_regs[UREG_I0] = -error; 9162306a36Sopenharmony_ci } else { 9262306a36Sopenharmony_ci syscall_clear_error(regs); 9362306a36Sopenharmony_ci regs->u_regs[UREG_I0] = val; 9462306a36Sopenharmony_ci } 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task, 9862306a36Sopenharmony_ci struct pt_regs *regs, 9962306a36Sopenharmony_ci unsigned long *args) 10062306a36Sopenharmony_ci{ 10162306a36Sopenharmony_ci int zero_extend = 0; 10262306a36Sopenharmony_ci unsigned int j; 10362306a36Sopenharmony_ci unsigned int n = 6; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#ifdef CONFIG_SPARC64 10662306a36Sopenharmony_ci if (test_tsk_thread_flag(task, TIF_32BIT)) 10762306a36Sopenharmony_ci zero_extend = 1; 10862306a36Sopenharmony_ci#endif 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci for (j = 0; j < n; j++) { 11162306a36Sopenharmony_ci unsigned long val = regs->u_regs[UREG_I0 + j]; 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci if (zero_extend) 11462306a36Sopenharmony_ci args[j] = (u32) val; 11562306a36Sopenharmony_ci else 11662306a36Sopenharmony_ci args[j] = val; 11762306a36Sopenharmony_ci } 11862306a36Sopenharmony_ci} 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task) 12162306a36Sopenharmony_ci{ 12262306a36Sopenharmony_ci#if defined(CONFIG_SPARC64) && defined(CONFIG_COMPAT) 12362306a36Sopenharmony_ci return test_tsk_thread_flag(task, TIF_32BIT) 12462306a36Sopenharmony_ci ? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64; 12562306a36Sopenharmony_ci#elif defined(CONFIG_SPARC64) 12662306a36Sopenharmony_ci return AUDIT_ARCH_SPARC64; 12762306a36Sopenharmony_ci#else 12862306a36Sopenharmony_ci return AUDIT_ARCH_SPARC; 12962306a36Sopenharmony_ci#endif 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif /* __ASM_SPARC_SYSCALL_H */ 133