]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/SetJump.c
MdePkg/BaseLib: add attribute 'RETURNS_TWICE' to SetJump
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / SetJump.c
1 /** @file
2 Implementation of SetJump() on IA-32.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "BaseLibInternals.h"
17
18 /**
19 Worker function that checks ASSERT condition for JumpBuffer
20
21 Checks ASSERT condition for JumpBuffer.
22
23 If JumpBuffer is NULL, then ASSERT().
24 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
25
26 @param JumpBuffer A pointer to CPU context buffer.
27
28 **/
29 VOID
30 EFIAPI
31 InternalAssertJumpBuffer (
32 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
33 );
34
35 /**
36 Saves the current CPU context that can be restored with a call to LongJump()
37 and returns 0.
38
39 Saves the current CPU context in the buffer specified by JumpBuffer and
40 returns 0. The initial call to SetJump() must always return 0. Subsequent
41 calls to LongJump() cause a non-zero value to be returned by SetJump().
42
43 If JumpBuffer is NULL, then ASSERT().
44 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
45
46 @param JumpBuffer A pointer to CPU context buffer.
47
48 @retval 0 Indicates a return from SetJump().
49
50 **/
51 _declspec (naked)
52 RETURNS_TWICE
53 UINTN
54 EFIAPI
55 SetJump (
56 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
57 )
58 {
59 _asm {
60 push [esp + 4]
61 call InternalAssertJumpBuffer
62 pop ecx
63 pop ecx
64 mov edx, [esp]
65 mov [edx], ebx
66 mov [edx + 4], esi
67 mov [edx + 8], edi
68 mov [edx + 12], ebp
69 mov [edx + 16], esp
70 mov [edx + 20], ecx
71 xor eax, eax
72 jmp ecx
73 }
74 }
75