Annotation of XNU/osfmk/ppc/atomic_switch.s, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: #include       <ppc/asm.h>
                     23: #include       <ppc/proc_reg.h>
                     24: #include       <ppc/exception.h>
                     25: #include       <mach/ppc/vm_param.h>
                     26: #include       <assym.s>
                     27: 
                     28: /*
                     29: ** Blue Box Fast Trap entry
                     30: **
                     31: ** The registers at entry are as hw_exceptions left them. Which means
                     32: ** that the Blue Box data area is pointed to be R26.
                     33: **
                     34: ** We exit here through the fast path exit point in hw_exceptions.  That means that
                     35: ** upon exit, R4 must not change.  It is the savearea with the current user context
                     36: ** to restore.
                     37: **
                     38: ** Input registers are:
                     39: ** r4  = Current context savearea (do not modify)
                     40: ** r9  = THREAD_TOP_ACT pointer
                     41: ** r24 = Offset into Call Descriptor table
                     42: ** r26 = base of ACT_MACH_BDA in kernel address space
                     43: **
                     44: **
                     45: */
                     46: 
                     47: ENTRY(atomic_switch_trap, TAG_NO_FRAME_USED)
                     48: 
                     49: /*
                     50: ** functions 0-13, 15 -> Call PseudoKernel
                     51: **                        14 -> Exit PseudoKernel
                     52: */
                     53: 
                     54:                        cmplwi  cr7,r24,BBEXITTRAP*PKTDSIZE     ; Is this an exit?
                     55:                        add             r24,r24,r26                                     ; Point to the actual entry offset+base
                     56:                        beq             cr7,.L_ExitPseudoKernel         ; Yes...
                     57: 
                     58: /******************************************************************************
                     59:  * void                 CallPseudoKernel        ( void )
                     60:  *
                     61:  * This op provides a means of invoking the BlueBox PseudoKernel from a
                     62:  * system (68k) or native (PPC) context while changing BlueBox interruption
                     63:  * state atomically. As an added bonus, this op leaves the user state 
                     64:  * registers intact. 
                     65:  *
                     66:  * This op is invoked from the Emulator Trap dispatch table.  The kernel is
                     67:  * aware of starting address of this table.  It uses the users PC (SS_SRR0) 
                     68:  * and the Trap dispatch table address to verify the trap exception as a 
                     69:  * atomic_switch trap.  If a trap exception is verified as a atomic_switch
                     70:  * we enter here with the following registers loaded.
                     71:  *
                     72:  * Input registers are:
                     73:  * r4  = Current context savearea (do not modify)
                     74:  * r24 = Offset into PseudoKernel Trap Descriptor table
                     75:  * r26 = Base address of BlueBox Data in kernel address space 
                     76:  *
                     77:  ********************************************************************************/
                     78: 
                     79:                        lwz             r8,BDA_INTCONTROLWORD(r26)      ; Get the interruption control word (ICW)
                     80:                        lis             r9,SYSCONTEXTSTATE                      ; Load system context constant
                     81:                        rlwinm  r7,r8,0,INTSTATEMASK_B,INTSTATEMASK_E   ; extract the current state from interruption control word
                     82:                        lwz             r6,BDA_PKTD_NEWSTATE(r24)       ; Get the new context state
                     83:                        cmplw   r7,r9                                           ; test for entry from system context
                     84:                        rlwimi  r8,r6,0,INTSTATEMASK_B,INTSTATEMASK_E ; insert the new state into interruption control word
                     85:                        lwz             r7,savecr(r4)                           ; Get the CR at interruption time
                     86:                        bne             .L_CallFromAlternateContext     ; We were in the alternate context...
                     87:                        rlwimi  r8,r7,32-INTCR2TOBACKUPSHIFT,INTBACKUPCR2MASK_B,INTBACKUPCR2MASK_E
                     88:                                                                                                ; remove old backup CR2 and insert live CR2 into backup CR2 position    
                     89: 
                     90: .L_CallFromAlternateContext:
                     91:                        lwz             r5,saver2(r4)                           ; Get live R2
                     92:                        lwz             r6,BDA_PKTD_PC(r24)                     ; Get the PC
                     93:                        lwz             r7,savesrr1(r4)                         ; Get the interrupt-time MSR value
                     94:                        stw             r8,BDA_INTCONTROLWORD(r26)      ; update interruption control word
                     95:                        rlwinm  r7,r7,0,MSR_FE1_BIT,MSR_FE0_BIT         ; Clear BE and SE bits
                     96:                        stw             r5,BDA_PKTD_REG(r24)            ; Save R2 into call descriptor
                     97:                        stw             r6,savesrr0(r4)                         ; Set the new instruction address
                     98:                        stw     r7,savesrr1(r4)                         ; Set the updated msr
                     99:                        b               EXT(fastexit)                           ; Go back and take the fast path exit...
                    100: 
                    101: 
                    102: /*******************************************************************************
                    103:  * void ExitPseudoKernel ( ExitPseudoKernelDescriptorPtr exitDescriptor )
                    104:  *
                    105:  * This op provides a means of exiting from the BlueBox PseudoKernel to a
                    106:  * user context while changing the BlueBox interruption state atomically.
                    107:  * It also allows the MSR's FE0,BE,SE and FE1 bits to updated for the user
                    108:  * and completes the PPC register loading.
                    109:  *
                    110:  * Input registers are:
                    111:  * r4  = Current context savearea (do not modify)
                    112:  * r24 = Offset into PseudoKernel Trap Descriptor table
                    113:  * r26 = Base address of BlueBox Data in kernel address space 
                    114:  *
                    115: *********************************************************************************/
                    116: 
                    117: .L_ExitPseudoKernel:
                    118:                        lwz             r9,savesrr1(r4)                         ; Pick up the old MSR value     
                    119:                        lwz             r8,savecr(r4)                           ; Get the live CR value
                    120:                        lwz             r7,BDA_PKTD_NEWSTATE(r24)       ; Get the new state
                    121:                        lis             r0,SYSCONTEXTSTATE                      ; Get the system context constant
                    122:                        lwz             r10,BDA_INTCONTROLWORD(r26)     ; Get Interruption Control Word (ICW)
                    123:                        lwz             r6,BDA_PKTD_PC(r24)                     ; Get the brand-new spanking clean inst address
                    124:                        cmplw   r7,r0                                           ; Are we going system context?
                    125:                        lwz             r5,BDA_PKTD_MSR(r24)            ; Pick up new MSR state
                    126:                        rlwimi  r10,r7,0,INTSTATEMASK_B,INTSTATEMASK_E
                    127:                                                                                                ; Insert the new state into interruption control word
                    128:                        beq             .L_ExitToSystemContext          ; We are going to system context...
                    129:                        lwz             r7,BDA_TESTINTMASK(r26)         ; Get the pending interrupt mask
                    130:                        lwz             r14,BDA_PKTD_INTPENDINGPC(r26)  ; Get the interruption exit address
                    131:                        and.    r7,r10,r7                                       ; test for pending interrupt in backup cr2
                    132:                        beq             .L_ExitUpdateRuptControlWord    ; and enter alternate context if none pending
                    133:                        mr              r6,r14                                          ; otherwise, introduce entry abort pc
                    134:                        b               .L_ExitNoUpdateRuptControlWord  ; and prepare to reenter pseudokernel
                    135: 
                    136: .L_ExitToSystemContext:
                    137:                        rlwimi  r8,r10,INTCR2TOBACKUPSHIFT,INTCR2MASK_B,INTCR2MASK_E
                    138:                                                                                                ; remove old CR2 and insert backup CR2 into live CR2 position   
                    139: .L_ExitUpdateRuptControlWord:
                    140:                        rlwimi  r9,r5,0,MSR_FE0_BIT,MSR_FE1_BIT ; Insert FE0, BE, SE and FE1 into MSR
                    141:                        stw             r10,BDA_INTCONTROLWORD(r26)     ; update the interrupt control word
                    142: 
                    143: .L_ExitNoUpdateRuptControlWord:
                    144:                        lwz             r7,BDA_PKTD_REG(r24)            ; Get the new CTR
                    145:                        stw             r6,savesrr0(r4)                         ; Set the new PC
                    146:                        stw             r7,savectr(r4)                          ; Set the new CTR
                    147:                        stw             r8,savecr(r4)                           ; Set the new CR
                    148:                        stw             r9,savesrr1(r4)                         ; Set the new MSR
                    149: 
                    150:                        b               EXT(fastexit)                           ; Go back and take the fast path exit...
                    151: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.