Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_SPARC_SYSCALL_H
0003 #define __ASM_SPARC_SYSCALL_H
0004 
0005 #include <uapi/linux/audit.h>
0006 #include <linux/kernel.h>
0007 #include <linux/compat.h>
0008 #include <linux/sched.h>
0009 #include <asm/ptrace.h>
0010 #include <asm/thread_info.h>
0011 
0012 /*
0013  * The syscall table always contains 32 bit pointers since we know that the
0014  * address of the function to be called is (way) below 4GB.  So the "int"
0015  * type here is what we want [need] for both 32 bit and 64 bit systems.
0016  */
0017 extern const unsigned int sys_call_table[];
0018 
0019 /* The system call number is given by the user in %g1 */
0020 static inline long syscall_get_nr(struct task_struct *task,
0021                   struct pt_regs *regs)
0022 {
0023     int syscall_p = pt_regs_is_syscall(regs);
0024 
0025     return (syscall_p ? regs->u_regs[UREG_G1] : -1L);
0026 }
0027 
0028 static inline void syscall_rollback(struct task_struct *task,
0029                     struct pt_regs *regs)
0030 {
0031     /* XXX This needs some thought.  On Sparc we don't
0032      * XXX save away the original %o0 value somewhere.
0033      * XXX Instead we hold it in register %l5 at the top
0034      * XXX level trap frame and pass this down to the signal
0035      * XXX dispatch code which is the only place that value
0036      * XXX ever was needed.
0037      */
0038 }
0039 
0040 #ifdef CONFIG_SPARC32
0041 static inline bool syscall_has_error(struct pt_regs *regs)
0042 {
0043     return (regs->psr & PSR_C) ? true : false;
0044 }
0045 static inline void syscall_set_error(struct pt_regs *regs)
0046 {
0047     regs->psr |= PSR_C;
0048 }
0049 static inline void syscall_clear_error(struct pt_regs *regs)
0050 {
0051     regs->psr &= ~PSR_C;
0052 }
0053 #else
0054 static inline bool syscall_has_error(struct pt_regs *regs)
0055 {
0056     return (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)) ? true : false;
0057 }
0058 static inline void syscall_set_error(struct pt_regs *regs)
0059 {
0060     regs->tstate |= (TSTATE_XCARRY | TSTATE_ICARRY);
0061 }
0062 static inline void syscall_clear_error(struct pt_regs *regs)
0063 {
0064     regs->tstate &= ~(TSTATE_XCARRY | TSTATE_ICARRY);
0065 }
0066 #endif
0067 
0068 static inline long syscall_get_error(struct task_struct *task,
0069                      struct pt_regs *regs)
0070 {
0071     long val = regs->u_regs[UREG_I0];
0072 
0073     return (syscall_has_error(regs) ? -val : 0);
0074 }
0075 
0076 static inline long syscall_get_return_value(struct task_struct *task,
0077                         struct pt_regs *regs)
0078 {
0079     long val = regs->u_regs[UREG_I0];
0080 
0081     return val;
0082 }
0083 
0084 static inline void syscall_set_return_value(struct task_struct *task,
0085                         struct pt_regs *regs,
0086                         int error, long val)
0087 {
0088     if (error) {
0089         syscall_set_error(regs);
0090         regs->u_regs[UREG_I0] = -error;
0091     } else {
0092         syscall_clear_error(regs);
0093         regs->u_regs[UREG_I0] = val;
0094     }
0095 }
0096 
0097 static inline void syscall_get_arguments(struct task_struct *task,
0098                      struct pt_regs *regs,
0099                      unsigned long *args)
0100 {
0101     int zero_extend = 0;
0102     unsigned int j;
0103     unsigned int n = 6;
0104 
0105 #ifdef CONFIG_SPARC64
0106     if (test_tsk_thread_flag(task, TIF_32BIT))
0107         zero_extend = 1;
0108 #endif
0109 
0110     for (j = 0; j < n; j++) {
0111         unsigned long val = regs->u_regs[UREG_I0 + j];
0112 
0113         if (zero_extend)
0114             args[j] = (u32) val;
0115         else
0116             args[j] = val;
0117     }
0118 }
0119 
0120 static inline int syscall_get_arch(struct task_struct *task)
0121 {
0122 #if defined(CONFIG_SPARC64) && defined(CONFIG_COMPAT)
0123     return test_tsk_thread_flag(task, TIF_32BIT)
0124         ? AUDIT_ARCH_SPARC : AUDIT_ARCH_SPARC64;
0125 #elif defined(CONFIG_SPARC64)
0126     return AUDIT_ARCH_SPARC64;
0127 #else
0128     return AUDIT_ARCH_SPARC;
0129 #endif
0130 }
0131 
0132 #endif /* __ASM_SPARC_SYSCALL_H */