b66192eeb42596813e3978744a6e11c831b364da
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Ipf / IpfCpuCore.s
1 //
2 // Include common header file for this module.
3 //
4 #include "CommonHeader.h"
5
6 //++
7 // Copyright (c) 2006, Intel Corporation
8 // All rights reserved. This program and the accompanying materials
9 // are licensed and made available under the terms and conditions of the BSD License
10 // which accompanies this distribution. The full text of the license may be found at
11 // http://opensource.org/licenses/bsd-license.php
12 //
13 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 //
16 // Module Name:
17 //
18 // IpfCpuCore.s
19 //
20 // Abstract:
21 // IPF Specific assembly routines
22 //
23 //--
24
25 .file "IpfCpuCore.s"
26
27 #include "IpfMacro.i"
28 #include "Ipf/IpfCpuCore.i"
29
30 //----------------------------------------------------------------------------------
31 // This module supports terminating CAR (Cache As RAM) stage. It copies all the
32 // CAR data into real RAM and then makes a stack switch.
33
34 // EFI_STATUS
35 // SwitchCoreStacks (
36 // IN VOID *EntryPoint,
37 // IN UINTN CopySize,
38 // IN VOID *OldBase,
39 // IN VOID *NewBase
40 // IN UINTN NewSP, OPTIONAL
41 // IN UINTN NewBSP OPTIONAL
42 // )
43 // EFI_STATUS
44 // SwitchCoreStacks (
45 // IN VOID *EntryPointForContinuationFunction,
46 // IN UINTN StartupDescriptor,
47 // IN VOID PEICorePointer,
48 // IN UINTN NewSP
49 // )
50 //----------------------------------------------------------------------------------
51 PROCEDURE_ENTRY (SwitchCoreStacks)
52
53 NESTED_SETUP (4,2,0,0)
54
55 // first save all stack registers in GPRs.
56 mov r13 = in0;; // this is a pointer to the PLABEL of the continuation function.
57 ld8 r16 = [r13],8;; // r16 = address of continuation function from the PLABEL
58 ld8 gp = [r13];; // gp = gp of continuation function from the PLABEL
59 mov b1 = r16;;
60
61 // save the parameters in r5, r6. these 2 seemed to be preserved across PAL calls
62 mov r5 = in1;; // this is the parameter1 to pass to the continuation function
63 mov r6 = in2;; // this is the parameter2 to pass to the continuation function
64 dep r6=0,r6,63,1;; // zero the bit 63.
65
66 mov r8 = in3;; // new stack pointer.
67
68 // r8 has the sp, this is 128K stack size, from this we will reserve 16K for the bspstore
69 movl r15 = PEI_BSP_STORE_SIZE;;
70 sub r8 = r8, r15;;
71 add r15 = (GuardBand),r8;; // some little buffer, now r15 will be our bspstore
72
73 // save the bspstore value to r4, save sp value to r7
74 mov r4 = r15
75 mov r7 = r8
76 mov r16 = r8;; // will be the new sp in uncache mode
77
78
79 alloc r11=0,0,0,0;; // Set 0-size frame
80 flushrs;;
81
82 mov r21 = RSC_KERNEL_DISABLED;; // for rse disable
83 mov ar.rsc = r21;; // turn off RSE
84
85 add sp = r0, r16 // transfer to the EFI stack
86 mov ar.bspstore = r15 // switch to EFI BSP
87 invala // change of ar.bspstore needs invala.
88
89 mov r19 = RSC_KERNEL_LAZ;; // RSC enabled, Lazy mode
90 mov ar.rsc = r19;; // turn rse on, in kernel mode
91
92 //-----------------------------------------------------------------------------------
93 // Save here the meaningful stuff for next few lines and then make the PAL call.
94 // Make PAL call to terminate the CAR status.
95 // AVL: do this only for recovery check call...
96
97 mov r28=ar.k3;;
98 dep r2 = r28,r0,0,8;; // Extract Function bits from GR20.
99 cmp.eq p6,p7 = RecoveryFn,r2;; // Is it Recovery check
100 (p7) br.sptk.few DoneCARTermination; // if not, don't terminate car..
101
102 TerminateCAR::
103
104 mov r28 = ip;;
105 add r28 = (DoneCARTerminationPALCall - TerminateCAR),r28;;
106 mov b0 = r28
107
108 mov r8 = ar.k5;;
109 mov b6 = r8
110 mov r28 = 0x208
111
112 mov r29 = r0
113 mov r30 = r0
114 mov r31 = r0
115 mov r8 = r0;;
116 br.sptk.few b6;; // Call PAL-A call.
117
118 DoneCARTerminationPALCall::
119
120 // don't check error in soft sdv, it is always returning -1 for this call for some reason
121 #if SOFT_SDV
122 #else
123 ReturnToPEIMain::
124 cmp.eq p6,p7 = r8,r0;;
125 //
126 // dead loop if the PAL call failed, we have the CAR on but the stack is now pointing to memory
127 //
128 (p7) br.sptk.few ReturnToPEIMain;;
129 //
130 // PAL call successed,now the stack are in memory so come into cache mode
131 // instead of uncache mode
132 //
133
134 alloc r11=0,0,0,0;; // Set 0-size frame
135 flushrs;;
136
137 mov r21 = RSC_KERNEL_DISABLED;; // for rse disable
138 mov ar.rsc = r21;; // turn off RSE
139
140 dep r6 = 0,r6,63,1 // zero the bit 63
141 dep r7 = 0,r7,63,1 // zero the bit 63
142 dep r4 = 0,r4,63,1;; // zero the bit 63
143 add sp = r0, r7 // transfer to the EFI stack in cache mode
144 mov ar.bspstore = r4 // switch to EFI BSP
145 invala // change of ar.bspstore needs invala.
146
147 mov r19 = RSC_KERNEL_LAZ;; // RSC enabled, Lazy mode
148 mov ar.rsc = r19;; // turn rse on, in kernel mode
149
150 #endif
151
152 DoneCARTermination::
153
154 // allocate a stack frame:
155 alloc r11=0,2,2,0 ;; // alloc outs going to ensuing DXE IPL service
156 // on the new stack
157 mov out0 = r5;;
158 mov out1 = r6;;
159
160 mov r16 = b1;;
161 mov b6 = r16;;
162 br.call.sptk.few b0=b6;; // Call the continuation function
163
164 NESTED_RETURN
165
166 PROCEDURE_EXIT(SwitchCoreStacks)
167 //-----------------------------------------------------------------------------------
168
169 //---------------------------------------------------------------------------------
170 //++
171 // GetHandOffStatus
172 //
173 // This routine is called by all processors simultaneously, to get some hand-off
174 // status that has been captured by IPF dispatcher and recorded in kernel registers.
175 //
176 // Arguments :
177 //
178 // On Entry : None.
179 //
180 // Return Value: Lid, R20Status.
181 //
182 //--
183 //----------------------------------------------------------------------------------
184 PROCEDURE_ENTRY (GetHandOffStatus)
185
186 NESTED_SETUP (0,2+0,0,0)
187
188 mov r8 = ar.k6 // Health Status (Self test params)
189 mov r9 = ar.k4 // LID bits
190 mov r10 = ar.k3;; // SAL_E entry state
191 mov r11 = ar.k7 // Return address to PAL
192
193 NESTED_RETURN
194 PROCEDURE_EXIT (GetHandOffStatus)
195 //----------------------------------------------------------------------------------
196
197