2 // Copyright (c) 2006, Intel Corporation
3 // All rights reserved. This program and the accompanying materials
4 // are licensed and made available under the terms and conditions of the BSD License
5 // which accompanies this distribution. The full text of the license may be found at
6 // http://opensource.org/licenses/bsd-license.php
8 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 // Contains an implementation of a stack switch for the Itanium-based architecture.
30 // Define hardware RSE Configuration Register
32 // RS Configuration (RSC) bit field positions
37 // RSC bits 5-15 reserved
39 #define RSC_MBZ0_V 0x3ff
41 #define RSC_LOADRS_LEN 14
42 // RSC bits 30-63 reserved
44 #define RSC_MBZ1_V 0x3ffffffffULL
48 #define RSC_MODE_LY (0x0)
50 #define RSC_MODE_SI (0x1)
52 #define RSC_MODE_LI (0x2)
54 #define RSC_MODE_EA (0x3)
56 // RSC Endian bit values
57 #define RSC_BE_LITTLE 0
60 // RSC while in kernel: enabled, little endian, pl = 0, eager mode
61 #define RSC_KERNEL ((RSC_MODE_EA<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
62 // Lazy RSC in kernel: enabled, little endian, pl = 0, lazy mode
63 #define RSC_KERNEL_LAZ ((RSC_MODE_LY<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
64 // RSE disabled: disabled, pl = 0, little endian, eager mode
65 #define RSC_KERNEL_DISABLED ((RSC_MODE_LY<<RSC_MODE) | (RSC_BE_LITTLE<<RSC_BE))
70 // VOID *ContinuationFunction,
72 // UINTN NewTopOfStack,
73 // UINTN NewBSPStore OPTIONAL
79 // ContinuationFunction - This is a pointer to the PLABEL of the function that should be called once the
80 // new stack has been created.
81 // Parameter - The parameter to pass to the continuation function
82 // NewTopOfStack - This is the new top of the memory stack for ensuing code. This is mandatory and
84 // NewBSPStore - This is the new BSP store for the ensuing code. It is optional on IA-32 and mandatory on Itanium-based platform.
88 PROCEDURE_ENTRY(SwitchStack)
91 and r16 = r34, r16;; // get new stack value in R16, 0 the last nibble.
92 mov r15 = r35;; // Get new BspStore into R15
93 mov r13 = r32;; // this is a pointer to the PLABEL of the continuation function.
94 mov r17 = r33;; // this is the parameter to pass to the continuation function
96 alloc r11=0,0,0,0 // Set 0-size frame
100 mov r21 = RSC_KERNEL_DISABLED // for rse disable
102 mov ar.rsc = r21 // turn off RSE
104 add sp = r0, r16;; // transfer to the EFI stack
105 mov ar.bspstore = r15 // switch to EFI BSP
106 invala // change of ar.bspstore needs invala.
108 mov r18 = RSC_KERNEL_LAZ // RSC enabled, Lazy mode
110 mov ar.rsc = r18 // turn rse on, in kernel mode
112 alloc r11=0,0,1,0;; // alloc 0 outs going to ensuing DXE IPL service
114 ld8 r16 = [r13],8;; // r16 = address of continuation function from the PLABEL
115 ld8 gp = [r13] // gp = gp of continuation function from the PLABEL
118 br.call.sptk.few b0=b6;; // Call the continuation function
120 PROCEDURE_EXIT(SwitchStack)