+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2009-2013, ARM Ltd. All rights reserved.\r
+; This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution. The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php.\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ EXPORT SetJump\r
+ EXPORT InternalLongJump\r
+ AREA BaseLib_LowLevel, CODE, READONLY\r
+\r
+#define GPR_LAYOUT \\r
+ REG_PAIR (x19, x20, #0); \\r
+ REG_PAIR (x21, x22, #16); \\r
+ REG_PAIR (x23, x24, #32); \\r
+ REG_PAIR (x25, x26, #48); \\r
+ REG_PAIR (x27, x28, #64); \\r
+ REG_PAIR (x29, x30, #80);/*FP, LR*/ \\r
+ REG_ONE (x16, #96) /*IP0*/\r
+\r
+#define FPR_LAYOUT \\r
+ REG_PAIR ( d8, d9, #112); \\r
+ REG_PAIR (d10, d11, #128); \\r
+ REG_PAIR (d12, d13, #144); \\r
+ REG_PAIR (d14, d15, #160);\r
+\r
+;/**\r
+; Saves the current CPU context that can be restored with a call to LongJump() and returns 0.#\r
+;\r
+; Saves the current CPU context in the buffer specified by JumpBuffer and returns 0. The initial\r
+; call to SetJump() must always return 0. Subsequent calls to LongJump() cause a non-zero\r
+; value to be returned by SetJump().\r
+;\r
+; If JumpBuffer is NULL, then ASSERT().\r
+; For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r
+;\r
+; @param JumpBuffer A pointer to CPU context buffer.\r
+;\r
+;**/\r
+;\r
+;UINTN\r
+;EFIAPI\r
+;SetJump (\r
+; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer // X0\r
+; );\r
+;\r
+SetJump\r
+ mov x16, sp // use IP0 so save SP\r
+#define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS]\r
+#define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS]\r
+ GPR_LAYOUT\r
+ FPR_LAYOUT\r
+#undef REG_PAIR\r
+#undef REG_ONE\r
+ mov w0, #0\r
+ ret\r
+\r
+;/**\r
+; Restores the CPU context that was saved with SetJump().#\r
+;\r
+; Restores the CPU context from the buffer specified by JumpBuffer.\r
+; This function never returns to the caller.\r
+; Instead is resumes execution based on the state of JumpBuffer.\r
+;\r
+; @param JumpBuffer A pointer to CPU context buffer.\r
+; @param Value The value to return when the SetJump() context is restored.\r
+;\r
+;**/\r
+;VOID\r
+;EFIAPI\r
+;InternalLongJump (\r
+; IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, // X0\r
+; IN UINTN Value // X1\r
+; );\r
+;\r
+InternalLongJump\r
+#define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS]\r
+#define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS]\r
+ GPR_LAYOUT\r
+ FPR_LAYOUT\r
+#undef REG_PAIR\r
+#undef REG_ONE\r
+ mov sp, x16\r
+ cmp w1, #0\r
+ mov w0, #1\r
+ beq exit\r
+ mov w0, w1\r
+exit\r
+ // use br not ret, as ret is guaranteed to mispredict\r
+ br x30\r
+\r
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r
+\r
+ END\r
+\r