]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.asm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / AArch64 / SetJumpLongJump.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2009-2013, ARM Ltd. All rights reserved.
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ;------------------------------------------------------------------------------
7
8 EXPORT SetJump
9 EXPORT InternalLongJump
10 AREA BaseLib_LowLevel, CODE, READONLY
11
12 #define GPR_LAYOUT \
13 REG_PAIR (x19, x20, #0); \
14 REG_PAIR (x21, x22, #16); \
15 REG_PAIR (x23, x24, #32); \
16 REG_PAIR (x25, x26, #48); \
17 REG_PAIR (x27, x28, #64); \
18 REG_PAIR (x29, x30, #80);/*FP, LR*/ \
19 REG_ONE (x16, #96) /*IP0*/
20
21 #define FPR_LAYOUT \
22 REG_PAIR ( d8, d9, #104); \
23 REG_PAIR (d10, d11, #120); \
24 REG_PAIR (d12, d13, #136); \
25 REG_PAIR (d14, d15, #152);
26
27 ;/**
28 ; Saves the current CPU context that can be restored with a call to LongJump() and returns 0.#
29 ;
30 ; Saves the current CPU context in the buffer specified by JumpBuffer and returns 0. The initial
31 ; call to SetJump() must always return 0. Subsequent calls to LongJump() cause a non-zero
32 ; value to be returned by SetJump().
33 ;
34 ; If JumpBuffer is NULL, then ASSERT().
35 ; For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
36 ;
37 ; @param JumpBuffer A pointer to CPU context buffer.
38 ;
39 ;**/
40 ;
41 ;UINTN
42 ;EFIAPI
43 ;SetJump (
44 ; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer // X0
45 ; );
46 ;
47 SetJump
48 mov x16, sp // use IP0 so save SP
49 #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS]
50 #define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS]
51 GPR_LAYOUT
52 FPR_LAYOUT
53 #undef REG_PAIR
54 #undef REG_ONE
55 mov w0, #0
56 ret
57
58 ;/**
59 ; Restores the CPU context that was saved with SetJump().#
60 ;
61 ; Restores the CPU context from the buffer specified by JumpBuffer.
62 ; This function never returns to the caller.
63 ; Instead is resumes execution based on the state of JumpBuffer.
64 ;
65 ; @param JumpBuffer A pointer to CPU context buffer.
66 ; @param Value The value to return when the SetJump() context is restored.
67 ;
68 ;**/
69 ;VOID
70 ;EFIAPI
71 ;InternalLongJump (
72 ; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, // X0
73 ; IN UINTN Value // X1
74 ; );
75 ;
76 InternalLongJump
77 #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS]
78 #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS]
79 GPR_LAYOUT
80 FPR_LAYOUT
81 #undef REG_PAIR
82 #undef REG_ONE
83 mov sp, x16
84 cmp w1, #0
85 mov w0, #1
86 beq exit
87 mov w0, w1
88 exit
89 // use br not ret, as ret is guaranteed to mispredict
90 br x30
91
92 ASM_FUNCTION_REMOVE_IF_UNREFERENCED
93
94 END
95