]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/SetJump.c
67d0571ecf5505d7ca510e633492559d538bacc0
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / SetJump.c
1 /** @file
2 Implementation of SetJump() on IA-32.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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 common header file for this module.
17 //
18 #include <BaseLibInternals.h>
19
20 /**
21 Worker function that checks ASSERT condition for JumpBuffer
22
23 Checks ASSERT condition for JumpBuffer.
24
25 If JumpBuffer is NULL, then ASSERT().
26 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
27
28 @param JumpBuffer A pointer to CPU context buffer.
29
30 **/
31 VOID
32 EFIAPI
33 InternalAssertJumpBuffer (
34 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
35 );
36
37 /**
38 Saves the current CPU context that can be restored with a call to LongJump()
39 and returns 0.
40
41 Saves the current CPU context in the buffer specified by JumpBuffer and
42 returns 0. The initial call to SetJump() must always return 0. Subsequent
43 calls to LongJump() cause a non-zero value to be returned by SetJump().
44
45 If JumpBuffer is NULL, then ASSERT().
46 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
47
48 @param JumpBuffer A pointer to CPU context buffer.
49
50 @retval 0 Indicates a return from SetJump().
51
52 **/
53 _declspec (naked)
54 UINTN
55 EFIAPI
56 SetJump (
57 OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
58 )
59 {
60 _asm {
61 push [esp + 4]
62 call InternalAssertJumpBuffer
63 pop ecx
64 pop ecx
65 mov edx, [esp]
66 mov [edx], ebx
67 mov [edx + 4], esi
68 mov [edx + 8], edi
69 mov [edx + 12], ebp
70 mov [edx + 16], esp
71 mov [edx + 20], ecx
72 xor eax, eax
73 jmp ecx
74 }
75 }
76