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