1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 ; This is separated from processor.c to allow this functions to be built with /O1
19 ;------------------------------------------------------------------------------
25 ; Routine Description:
26 ; This allows the caller to switch the stack and goes to the new entry point
29 ; EntryPoint - Pointer to the location to enter // rcx
30 ; Parameter - Parameter to pass in // rdx
31 ; NewStack - New Location of the stack // r8
32 ; NewBsp - New BSP // r9 - not used
35 ; Nothing. Goes to the Entry Point passing in the new parameters
37 SwitchStacks PROC PUBLIC
40 ; 1) leave 4 registers space
41 ; 2) let it 16 bytes aligned after call
43 and r8w, 0fff0h ; do not assume 16 bytes aligned
45 mov rsp, r8 ; rsp = NewStack
46 mov r10, rcx ; save EntryPoint
47 mov rcx, rdx ; Arg1 = Parameter
48 call r10 ; r10 = copy of EntryPoint
50 ; no ret as we have a new stack and we jumped to the new location
58 EFI_WARN_RETURN_FROM_LONG_JUMP equ 5
61 ; Generated by h2inc run manually
63 _EFI_JUMP_BUFFER STRUCT 2t
78 EFI_JUMP_BUFFER TYPEDEF _EFI_JUMP_BUFFER
84 ; This routine implements the x64 variant of the SetJump call. Its
85 ; responsibility is to store system state information for a possible
86 ; subsequent LongJump.
90 ; Pointer to CPU context save buffer.
98 ; TransferControlLongJump (
99 ; IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This,
100 ; IN EFI_JUMP_BUFFER *Jump
106 PUBLIC TransferControlSetJump
107 TransferControlSetJump PROC
108 mov (EFI_JUMP_BUFFER PTR [rdx])._rbx, rbx
109 mov (EFI_JUMP_BUFFER PTR [rdx])._rsp, rsp
110 mov (EFI_JUMP_BUFFER PTR [rdx])._rbp, rbp
111 mov (EFI_JUMP_BUFFER PTR [rdx])._rdi, rdi
112 mov (EFI_JUMP_BUFFER PTR [rdx])._rsi, rsi
113 mov (EFI_JUMP_BUFFER PTR [rdx])._r10, r10
114 mov (EFI_JUMP_BUFFER PTR [rdx])._r11, r11
115 mov (EFI_JUMP_BUFFER PTR [rdx])._r12, r12
116 mov (EFI_JUMP_BUFFER PTR [rdx])._r13, r13
117 mov (EFI_JUMP_BUFFER PTR [rdx])._r14, r14
118 mov (EFI_JUMP_BUFFER PTR [rdx])._r15, r15
119 mov rax, QWORD PTR [rsp+0]
120 mov (EFI_JUMP_BUFFER PTR [rdx])._rip, rax
124 TransferControlSetJump ENDP
129 ; TransferControlLongJump (
130 ; IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL *This, // rcx
131 ; IN EFI_JUMP_BUFFER *Jump // rdx
135 PUBLIC TransferControlLongJump
136 TransferControlLongJump PROC
137 ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
138 mov rax, EFI_WARN_RETURN_FROM_LONG_JUMP
139 mov rbx, (EFI_JUMP_BUFFER PTR [rdx])._rbx
140 mov rsp, (EFI_JUMP_BUFFER PTR [rdx])._rsp
141 mov rbp, (EFI_JUMP_BUFFER PTR [rdx])._rbp
142 mov rdi, (EFI_JUMP_BUFFER PTR [rdx])._rdi
143 mov rsi, (EFI_JUMP_BUFFER PTR [rdx])._rsi
144 mov r10, (EFI_JUMP_BUFFER PTR [rdx])._r10
145 mov r11, (EFI_JUMP_BUFFER PTR [rdx])._r11
146 mov r12, (EFI_JUMP_BUFFER PTR [rdx])._r12
147 mov r13, (EFI_JUMP_BUFFER PTR [rdx])._r13
148 mov r14, (EFI_JUMP_BUFFER PTR [rdx])._r14
149 mov r15, (EFI_JUMP_BUFFER PTR [rdx])._r15
150 add rsp, 8 ;pop the eip
151 jmp QWORD PTR (EFI_JUMP_BUFFER PTR [rdx])._rip
152 ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
153 mov rax, EFI_WARN_RETURN_FROM_LONG_JUMP
155 TransferControlLongJump ENDP