Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:26

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  systrap.S
0005  *
0006  *  This file contains emulated system calls using software trap 0.
0007  *  The following calls are supported:
0008  *
0009  *    + SYS_exit  (halt)
0010  *    + SYS_irqdis  (disable interrupts)
0011  *    + SYS_irqset  (set interrupt level)
0012  * 
0013  *  COPYRIGHT (c) 2010. Gedare Bloom.
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <rtems/asm.h>
0038 #include "sparc64-syscall.h"
0039 
0040 
0041 .seg    "text"
0042 /*
0043  *  system call
0044  *
0045  *  On entry:
0046  *      g4[AG | GL=1] = tstate (from trap table)
0047  *      g2[AG | GL=1] = trap vector # (256)
0048  *      g3[AG | GL=1] = address of SYM(syscall)
0049  *      g4[AG | GL-1] = system call id
0050  *    if arch = sun4v:
0051  *      We need to back to GL-1 to read the system call id. 
0052  *   on sun4u:
0053  *      We need to go back to the normal globals to read the system call id.
0054  *    
0055  *    First thing is to return to the previous set of globals, so 
0056  *    that the system call id can be read.  The syscall code needs 
0057  *    to re-read tstate.
0058  *
0059  *    syscall should only ever be entered by ta 0 being called explicitly
0060  *    by a function that knows what is happening.  This means the syscall
0061  *    code can safely use any scratch registers and the %o registers.
0062  */
0063 
0064 
0065 PUBLIC(syscall)
0066 
0067   
0068   SYM(syscall):
0069     mov   %g0, %g4  ! clear %g4 at this GL
0070 #if defined (SUN4U)
0071     rdpr  %pstate, %g1
0072     andn  %g1, SPARC_PSTATE_AG_MASK, %g1
0073     wrpr  %g1, %g0, %pstate                 ! go to regular globals
0074 #elif defined (SUN4V)
0075     rdpr  %gl, %g1
0076     dec   %g1
0077     wrpr  %g0, %g1, %gl                     ! go back to GL = GL - 1
0078 #endif
0079 
0080     subcc %g4, 2, %g0                     
0081     bne   3f
0082     rdpr  %tstate, %g5                      ! re-read tstate, use delay slot
0083 
0084     ! syscall 2, disable interrupts
0085     rdpr  %pil, %g1
0086     and   %g5, SPARC_TSTATE_IE_MASK, %o0
0087     or    %o0, %g1, %o0                     ! return TSTATE_IE | PIL
0088     wrpr  %g0, 0xf, %pil                    ! set PIL to 15
0089     andn  %g5, SPARC_TSTATE_IE_MASK, %g1
0090     wrpr  %g0, %g1, %tstate                 ! disable interrupts in trap state
0091     ba,a  9f
0092 
0093     3:  ! syscall 3, enable interrupts
0094     subcc %g4, 3, %g0                     
0095     bne   1f
0096     and   %o0, 0xf, %g1
0097     wrpr  %g0, %g1, %pil                    ! restore PIL
0098 !    and   %o0, SPARC_TSTATE_IE_MASK, %g1
0099 !    or    %g5, %g1, %g1                     ! restore saved IE
0100     or    %g5, SPARC_TSTATE_IE_MASK, %g1    ! restore IE (safe?)
0101     wrpr  %g0, %g1, %tstate     
0102     ba,a  9f
0103 
0104     1:          
0105     ba,a  1b                                ! spin. taking a trap here -> htrap
0106 
0107     9:                                      ! leave
0108     mov  0, %g4                             ! clear %g4
0109     DONE
0110 
0111 PUBLIC(sparc_disable_interrupts)
0112 
0113   SYM(sparc_disable_interrupts):
0114     mov  SYS_irqdis, %g4
0115     ta  0
0116 #if 0
0117     rdpr  %pstate, %g5
0118     rdpr  %pil, %g1
0119     and   %g5, SPARC_PSTATE_IE_MASK, %o0
0120     or    %o0, %g1, %o0                     ! return PSTATE_IE | PIL
0121     wrpr  %g0, 0xf, %pil                    ! set PIL to 15
0122     andn  %g5, SPARC_PSTATE_IE_MASK, %g1
0123     wrpr  %g0, %g1, %pstate                 ! disable interrupts
0124 #endif
0125     retl  
0126     nop
0127 
0128 PUBLIC(sparc_enable_interrupts)
0129 
0130   SYM(sparc_enable_interrupts):
0131     mov  SYS_irqen, %g4
0132     ta  0
0133 #if 0
0134     rdpr  %pstate, %g5
0135     and   %o0, 0xf, %g1
0136     wrpr  %g0, %g1, %pil                    ! restore PIL
0137     and   %o0, SPARC_PSTATE_IE_MASK, %g1
0138     or    %g5, %g1, %g1                     ! restore saved IE
0139 !    or    %g5, SPARC_PSTATE_IE_MASK, %g1    ! set IE regardless of old (safe?)
0140     wrpr  %g0, %g1, %pstate
0141 #endif
0142     retl  
0143     nop
0144 
0145     /* end of file */