Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002     /* SunOS's execv() call only specifies the argv argument, the
0003      * environment settings are the same as the calling processes.
0004      */
0005 sys64_execve:
0006     set sys_execve, %g1
0007     jmpl    %g1, %g0
0008      flushw
0009 
0010 sys64_execveat:
0011     set sys_execveat, %g1
0012     jmpl    %g1, %g0
0013      flushw
0014 
0015 #ifdef CONFIG_COMPAT
0016 sunos_execv:
0017     mov %g0, %o2
0018 sys32_execve:
0019     set compat_sys_execve, %g1
0020     jmpl    %g1, %g0
0021      flushw
0022 
0023 sys32_execveat:
0024     set compat_sys_execveat, %g1
0025     jmpl    %g1, %g0
0026      flushw
0027 #endif
0028 
0029     .align  32
0030 #ifdef CONFIG_COMPAT
0031 sys32_sigstack:
0032     ba,pt   %xcc, do_sys32_sigstack
0033      mov    %i6, %o2
0034 #endif
0035     .align  32
0036 #ifdef CONFIG_COMPAT
0037 sys32_sigreturn:
0038     add %sp, PTREGS_OFF, %o0
0039     call    do_sigreturn32
0040      add    %o7, 1f-.-4, %o7
0041     nop
0042 #endif
0043 sys_rt_sigreturn:
0044     add %sp, PTREGS_OFF, %o0
0045     call    do_rt_sigreturn
0046      add    %o7, 1f-.-4, %o7
0047     nop
0048 #ifdef CONFIG_COMPAT
0049 sys32_rt_sigreturn:
0050     add %sp, PTREGS_OFF, %o0
0051     call    do_rt_sigreturn32
0052      add    %o7, 1f-.-4, %o7
0053     nop
0054 #endif
0055     .align  32
0056 1:  ldx [%g6 + TI_FLAGS], %l5
0057     andcc   %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
0058     be,pt   %icc, rtrap
0059      nop
0060     call    syscall_trace_leave
0061      add    %sp, PTREGS_OFF, %o0
0062     ba,pt   %xcc, rtrap
0063      nop
0064 
0065     /* This is how fork() was meant to be done, 8 instruction entry.
0066      *
0067      * I questioned the following code briefly, let me clear things
0068      * up so you must not reason on it like I did.
0069      *
0070      * Know the fork_kpsr etc. we use in the sparc32 port?  We don't
0071      * need it here because the only piece of window state we copy to
0072      * the child is the CWP register.  Even if the parent sleeps,
0073      * we are safe because we stuck it into pt_regs of the parent
0074      * so it will not change.
0075      *
0076      * XXX This raises the question, whether we can do the same on
0077      * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim.  The
0078      * XXX answer is yes.  We stick fork_kpsr in UREG_G0 and
0079      * XXX fork_kwim in UREG_G1 (global registers are considered
0080      * XXX volatile across a system call in the sparc ABI I think
0081      * XXX if it isn't we can use regs->y instead, anyone who depends
0082      * XXX upon the Y register being preserved across a fork deserves
0083      * XXX to lose).
0084      *
0085      * In fact we should take advantage of that fact for other things
0086      * during system calls...
0087      */
0088     .align  32
0089 sys_vfork:
0090     flushw
0091     ba,pt   %xcc, sparc_vfork
0092      add    %sp, PTREGS_OFF, %o0
0093 
0094     .align  32
0095 sys_fork:
0096     flushw
0097     ba,pt   %xcc, sparc_fork
0098      add    %sp, PTREGS_OFF, %o0
0099 
0100     .align  32
0101 sys_clone:
0102     flushw
0103     ba,pt   %xcc, sparc_clone
0104      add    %sp, PTREGS_OFF, %o0
0105 
0106     .globl  ret_from_fork
0107 ret_from_fork:
0108     /* Clear current_thread_info()->new_child. */
0109     stb %g0, [%g6 + TI_NEW_CHILD]
0110     call    schedule_tail
0111      mov    %g7, %o0
0112     ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
0113     brnz,pt %o0, ret_sys_call
0114      ldx    [%g6 + TI_FLAGS], %l0
0115     ldx [%sp + PTREGS_OFF + PT_V9_G1], %l1
0116     call    %l1
0117      ldx    [%sp + PTREGS_OFF + PT_V9_G2], %o0
0118     ba,pt   %xcc, ret_sys_call
0119      mov    0, %o0
0120 
0121     .globl  sparc_exit_group
0122     .type   sparc_exit_group,#function
0123 sparc_exit_group:
0124     sethi   %hi(sys_exit_group), %g7
0125     ba,pt   %xcc, 1f
0126      or %g7, %lo(sys_exit_group), %g7
0127     .size   sparc_exit_group,.-sparc_exit_group
0128 
0129     .globl  sparc_exit
0130     .type   sparc_exit,#function
0131 sparc_exit:
0132     sethi   %hi(sys_exit), %g7
0133     or  %g7, %lo(sys_exit), %g7
0134 1:  rdpr    %pstate, %g2
0135     wrpr    %g2, PSTATE_IE, %pstate
0136     rdpr    %otherwin, %g1
0137     rdpr    %cansave, %g3
0138     add %g3, %g1, %g3
0139     wrpr    %g3, 0x0, %cansave
0140     wrpr    %g0, 0x0, %otherwin
0141     wrpr    %g2, 0x0, %pstate
0142     jmpl    %g7, %g0
0143      stb    %g0, [%g6 + TI_WSAVED]
0144     .size   sparc_exit,.-sparc_exit
0145 
0146 linux_sparc_ni_syscall:
0147     sethi   %hi(sys_ni_syscall), %l7
0148     ba,pt   %xcc, 4f
0149      or %l7, %lo(sys_ni_syscall), %l7
0150 
0151 linux_syscall_trace32:
0152     call    syscall_trace_enter
0153      add    %sp, PTREGS_OFF, %o0
0154     brnz,pn %o0, 3f
0155      mov    -ENOSYS, %o0
0156 
0157     /* Syscall tracing can modify the registers.  */
0158     ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
0159     sethi   %hi(sys_call_table32), %l7
0160     ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
0161     or  %l7, %lo(sys_call_table32), %l7
0162     ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
0163     ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
0164     ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
0165     ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
0166     ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
0167 
0168     cmp %g1, NR_syscalls
0169     bgeu,pn %xcc, 3f
0170      mov    -ENOSYS, %o0
0171 
0172     sll %g1, 2, %l4
0173     srl %i0, 0, %o0
0174     lduw    [%l7 + %l4], %l7
0175     srl %i4, 0, %o4
0176     srl %i1, 0, %o1
0177     srl %i2, 0, %o2
0178     ba,pt   %xcc, 5f
0179      srl    %i3, 0, %o3
0180 
0181 linux_syscall_trace:
0182     call    syscall_trace_enter
0183      add    %sp, PTREGS_OFF, %o0
0184     brnz,pn %o0, 3f
0185      mov    -ENOSYS, %o0
0186 
0187     /* Syscall tracing can modify the registers.  */
0188     ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
0189     sethi   %hi(sys_call_table64), %l7
0190     ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0
0191     or  %l7, %lo(sys_call_table64), %l7
0192     ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1
0193     ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2
0194     ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3
0195     ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4
0196     ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5
0197 
0198     cmp %g1, NR_syscalls
0199     bgeu,pn %xcc, 3f
0200      mov    -ENOSYS, %o0
0201 
0202     sll %g1, 2, %l4
0203     mov %i0, %o0
0204     lduw    [%l7 + %l4], %l7
0205     mov %i1, %o1
0206     mov %i2, %o2
0207     mov %i3, %o3
0208     b,pt    %xcc, 2f
0209      mov    %i4, %o4
0210 
0211 
0212     /* Linux 32-bit system calls enter here... */
0213     .align  32
0214     .globl  linux_sparc_syscall32
0215 linux_sparc_syscall32:
0216     /* Direct access to user regs, much faster. */
0217     cmp %g1, NR_syscalls            ! IEU1  Group
0218     bgeu,pn %xcc, linux_sparc_ni_syscall        ! CTI
0219      srl    %i0, 0, %o0             ! IEU0
0220     sll %g1, 2, %l4             ! IEU0  Group
0221     srl %i4, 0, %o4             ! IEU1
0222     lduw    [%l7 + %l4], %l7            ! Load
0223     srl %i1, 0, %o1             ! IEU0  Group
0224     ldx [%g6 + TI_FLAGS], %l0       ! Load
0225 
0226     srl %i3, 0, %o3             ! IEU0
0227     srl %i2, 0, %o2             ! IEU0  Group
0228     andcc   %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
0229     bne,pn  %icc, linux_syscall_trace32     ! CTI
0230      mov    %i0, %l5                ! IEU1
0231 5:  call    %l7                 ! CTI   Group brk forced
0232      srl    %i5, 0, %o5             ! IEU1
0233     ba,pt   %xcc, 3f
0234      sra    %o0, 0, %o0
0235 
0236     /* Linux native system calls enter here... */
0237     .align  32
0238     .globl  linux_sparc_syscall
0239 linux_sparc_syscall:
0240     /* Direct access to user regs, much faster. */
0241     cmp %g1, NR_syscalls            ! IEU1  Group
0242     bgeu,pn %xcc, linux_sparc_ni_syscall        ! CTI
0243      mov    %i0, %o0                ! IEU0
0244     sll %g1, 2, %l4             ! IEU0  Group
0245     mov %i1, %o1                ! IEU1
0246     lduw    [%l7 + %l4], %l7            ! Load
0247 4:  mov %i2, %o2                ! IEU0  Group
0248     ldx [%g6 + TI_FLAGS], %l0       ! Load
0249 
0250     mov %i3, %o3                ! IEU1
0251     mov %i4, %o4                ! IEU0  Group
0252     andcc   %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
0253     bne,pn  %icc, linux_syscall_trace       ! CTI   Group
0254      mov    %i0, %l5                ! IEU0
0255 2:  call    %l7                 ! CTI   Group brk forced
0256      mov    %i5, %o5                ! IEU0
0257     nop
0258 
0259 3:  stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
0260 ret_sys_call:
0261     ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
0262     mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
0263     sllx    %g2, 32, %g2
0264 
0265     cmp %o0, -ERESTART_RESTARTBLOCK
0266     bgeu,pn %xcc, 1f
0267      andcc  %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
0268     ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
0269 
0270 2:
0271     /* System call success, clear Carry condition code. */
0272     andn    %g3, %g2, %g3
0273 3:
0274     stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]  
0275     bne,pn  %icc, linux_syscall_trace2
0276      add    %l1, 0x4, %l2           ! npc = npc+4
0277     stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
0278     ba,pt   %xcc, rtrap
0279      stx    %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
0280 
0281 1:
0282     /* Check if force_successful_syscall_return()
0283      * was invoked.
0284      */
0285     ldub    [%g6 + TI_SYS_NOERROR], %l2
0286     brnz,pn %l2, 2b
0287      ldx    [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
0288     /* System call failure, set Carry condition code.
0289      * Also, get abs(errno) to return to the process.
0290      */
0291     sub %g0, %o0, %o0
0292     stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
0293     ba,pt   %xcc, 3b
0294      or %g3, %g2, %g3
0295 
0296 linux_syscall_trace2:
0297     call    syscall_trace_leave
0298      add    %sp, PTREGS_OFF, %o0
0299     stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
0300     ba,pt   %xcc, rtrap
0301      stx    %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]