summaryrefslogtreecommitdiff
path: root/Core/CPU/IPF/IpfCpuCore.s
blob: d3b7c62fddfa8d974c4f67aa1812d224c8bafecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//++
// Copyright (c) 2004, Intel Corporation                                                         
// All rights reserved. This program and the accompanying materials                          
// are licensed and made available under the terms and conditions of the BSD License         
// which accompanies this distribution.  The full text of the license may be found at        
// http://opensource.org/licenses/bsd-license.php                                            
//                                                                                           
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
// 
//  Module Name:
//
//    IpfCpuCore.s
//
//  Abstract:
//    IPF Specific assembly routines
//
//-- 

.file  "IpfCpuCore.s"

#include  "IpfMacro.i"
#include  "IpfCpuCore.i"

//----------------------------------------------------------------------------------
// This module supports terminating CAR (Cache As RAM) stage. It copies all the
// CAR data into real RAM and then makes a stack switch.

// EFI_STATUS
// SwitchCoreStacks (
//   IN VOID  *EntryPoint,
//   IN UINTN CopySize,
//   IN VOID  *OldBase,
//   IN VOID  *NewBase
//   IN UINTN NewSP, OPTIONAL
//   IN UINTN NewBSP OPTIONAL
//   )
// EFI_STATUS
// SwitchCoreStacks (
//   IN VOID  *EntryPointForContinuationFunction,
//   IN UINTN StartupDescriptor,
//   IN VOID  PEICorePointer,
//   IN UINTN NewSP
//   )
//----------------------------------------------------------------------------------
PROCEDURE_ENTRY (SwitchCoreStacks)

        NESTED_SETUP (4,2,0,0)

        // first save all stack registers in GPRs.
        mov     r13 = in0;;             // this is a pointer to the PLABEL of the continuation function.  
        ld8     r16 = [r13],8;;         // r16 = address of continuation function from the PLABEL
        ld8     gp = [r13];;            // gp  = gp of continuation function from the PLABEL
        mov     b1 = r16;;

        // save the parameters in r5, r6. these 2 seemed to be preserved across PAL calls
        mov     r5 = in1;;              // this is the parameter1 to pass to the continuation function
        mov     r6 = in2;;              // this is the parameter2 to pass to the continuation function
        dep     r6=0,r6,63,1;;          // zero the bit 63.

        mov     r8 = in3;;              // new stack pointer.

        // r8 has the sp, this is 128K stack size, from this we will reserve 16K for the bspstore 
        movl    r15 = PEI_BSP_STORE_SIZE;;
        sub     r8 = r8, r15;;
        add     r15 = (GuardBand),r8;;  // some little buffer, now r15 will be our bspstore

        // save the bspstore value to r4, save sp value to r7
        mov     r4  = r15
        mov     r7  = r8
        mov     r16 = r8;;              // will be the new sp in uncache mode
      

        alloc   r11=0,0,0,0;;           // Set 0-size frame
        flushrs;;

        mov     r21 = RSC_KERNEL_DISABLED;; // for rse disable             
        mov     ar.rsc = r21;;          // turn off RSE                

        add     sp = r0, r16            // transfer to the EFI stack
        mov     ar.bspstore = r15       // switch to EFI BSP        
        invala                          // change of ar.bspstore needs invala.     
      
        mov     r19 = RSC_KERNEL_LAZ;;  // RSC enabled, Lazy mode
        mov     ar.rsc = r19;;          // turn rse on, in kernel mode 
                
//-----------------------------------------------------------------------------------
// Save here the meaningful stuff for next few lines and then make the PAL call.
// Make PAL call to terminate the CAR status.
        // AVL: do this only for recovery check call...

        mov     r28=ar.k3;;
        dep     r2 = r28,r0,0,8;;       // Extract Function bits from GR20.
        cmp.eq  p6,p7 = RecoveryFn,r2;; // Is it Recovery check  
        (p7)  br.sptk.few DoneCARTermination; // if not, don't terminate car..

TerminateCAR::

        mov     r28 = ip;;
        add     r28 = (DoneCARTerminationPALCall - TerminateCAR),r28;;
        mov     b0 = r28

        mov     r8 = ar.k5;;
        mov     b6 = r8
        mov     r28 = 0x208

        mov     r29 = r0
        mov     r30 = r0
        mov     r31 = r0
        mov     r8 = r0;;
        br.sptk.few b6;;                // Call PAL-A call.

DoneCARTerminationPALCall::

// don't check error in soft sdv, it is always returning -1 for this call for some reason
#if SOFT_SDV
#else
ReturnToPEIMain::
        cmp.eq  p6,p7 = r8,r0;;
        //
        // dead loop if the PAL call failed, we have the CAR on but the stack is now pointing to memory
        //
        (p7) br.sptk.few ReturnToPEIMain;; 
        //
        // PAL call successed,now the stack are in memory so come into cache mode 
        // instead of uncache mode
        //

        alloc   r11=0,0,0,0;;           // Set 0-size frame
        flushrs;;
     
        mov     r21 = RSC_KERNEL_DISABLED;; // for rse disable             
        mov     ar.rsc = r21;;          // turn off RSE                
    
        dep     r6 = 0,r6,63,1          // zero the bit 63                               
        dep     r7 = 0,r7,63,1          // zero the bit 63    
        dep     r4 = 0,r4,63,1;;        // zero the bit 63   
        add     sp = r0, r7             // transfer to the EFI stack in cache mode    
        mov     ar.bspstore = r4        // switch to EFI BSP        
        invala                          // change of ar.bspstore needs invala.     
    
        mov     r19 = RSC_KERNEL_LAZ;;  // RSC enabled, Lazy mode
        mov     ar.rsc = r19;;          // turn rse on, in kernel mode

#endif

DoneCARTermination::                                                                    

        // allocate a stack frame:                  
        alloc   r11=0,2,2,0 ;;          // alloc  outs going to ensuing DXE IPL service
                                                                                                // on the new stack
        mov     out0 = r5;;
        mov     out1 = r6;;        

        mov     r16 = b1;;
        mov     b6 = r16;;
        br.call.sptk.few b0=b6;;        // Call the continuation function

        NESTED_RETURN

PROCEDURE_EXIT(SwitchCoreStacks)
//-----------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
//++
// GetHandOffStatus
//
// This routine is called by all processors simultaneously, to get some hand-off
// status that has been captured by IPF dispatcher and recorded in kernel registers.
//
// Arguments : 
//
// On Entry :  None.
//
// Return Value: Lid, R20Status.
// 
//--
//----------------------------------------------------------------------------------
PROCEDURE_ENTRY (GetHandOffStatus)
        
        NESTED_SETUP (0,2+0,0,0)

        mov     r8 = ar.k6              // Health Status (Self test params)
        mov     r9 = ar.k4              // LID bits
        mov     r10 = ar.k3;;           // SAL_E entry state
     #if (PI_SPECIFICATION_VERSION < 0x00010000)
        mov     r11 = ar.k7             // Return address to PAL
     #else
        mov     r11 = ar.k1             // Return address to PAL     
     #endif   
        
        NESTED_RETURN
PROCEDURE_EXIT (GetHandOffStatus)
//----------------------------------------------------------------------------------