[CRT] Improve the FILE header section. Brought to you by Adam Stachowicz. CORE-10114
[reactos.git] / reactos / lib / sdk / crt / setjmp / i386 / setjmp.s
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * PURPOSE: Implementation of _setjmp/longjmp
5 * FILE: lib/sdk/crt/setjmp/i386/setjmp.s
6 * PROGRAMMER: Ge van Geldorp (ge@gse.nl)
7 * NOTES: Implementation is not complete, see Wine source for a more
8 * complete implementation
9 */
10
11 #include <asm.inc>
12
13 #define JB_BP 0
14 #define JB_BX 1
15 #define JB_DI 2
16 #define JB_SI 3
17 #define JB_SP 4
18 #define JB_IP 5
19
20 #define PCOFF 0
21
22 #define JMPBUF 4
23
24 .code
25 /*
26 * int
27 * _setjmp(jmp_buf env);
28 *
29 * Parameters:
30 * [ESP+04h] - jmp_buf env
31 * Registers:
32 * None
33 * Returns:
34 * 0
35 * Notes:
36 * Sets up the jmp_buf
37 */
38 PUBLIC __setjmp
39 __setjmp:
40 xor eax, eax
41 mov edx, JMPBUF[esp]
42
43 /* Save registers. */
44 mov [edx + JB_BP*4], ebp /* Save caller's frame pointer. */
45 mov [edx + JB_BX*4], ebx
46 mov [edx + JB_DI*4], edi
47 mov [edx + JB_SI*4], esi
48 lea ecx, JMPBUF[esp] /* Save SP as it will be after we return. */
49 mov [edx + JB_SP*4], ecx
50 mov ecx, PCOFF[esp] /* Save PC we are returning to now. */
51 mov [edx + JB_IP*4], ecx
52 ret
53
54 /*
55 * int
56 * _setjmp3(jmp_buf env, int nb_args, ...);
57 *
58 * Parameters:
59 * [ESP+04h] - jmp_buf env
60 * Registers:
61 * None
62 * Returns:
63 * 0
64 * Notes:
65 * Sets up the jmp_buf
66 */
67 PUBLIC __setjmp3
68 __setjmp3:
69 xor eax, eax
70 mov edx, JMPBUF[esp]
71
72 /* Save registers. */
73 mov [edx + JB_BP*4], ebp /* Save caller's frame pointer. */
74 mov [edx + JB_BX*4], ebx
75 mov [edx + JB_DI*4], edi
76 mov [edx + JB_SI*4], esi
77 lea ecx, JMPBUF[esp] /* Save SP as it will be after we return. */
78 mov [edx + JB_SP*4], ecx
79 mov ecx, PCOFF[esp] /* Save PC we are returning to now. */
80 mov [edx + JB_IP*4], ecx
81 ret
82
83 /*
84 * void
85 * longjmp(jmp_buf env, int value);
86 *
87 * Parameters:
88 * [ESP+04h] - jmp_buf setup by _setjmp
89 * [ESP+08h] - int value to return
90 * Registers:
91 * None
92 * Returns:
93 * Doesn't return
94 * Notes:
95 * Non-local goto
96 */
97 PUBLIC _longjmp
98 _longjmp:
99 mov ecx, JMPBUF[esp] /* User's jmp_buf in %ecx. */
100
101 mov eax, [esp + 8] /* Second argument is return value. */
102 /* Save the return address now. */
103 mov edx, [ecx + JB_IP*4]
104 /* Restore registers. */
105 mov ebp, [ecx + JB_BP*4]
106 mov ebx, [ecx + JB_BX*4]
107 mov edi, [ecx + JB_DI*4]
108 mov esi, [ecx + JB_SI*4]
109 mov esp, [ecx + JB_SP*4]
110 /* Jump to saved PC. */
111 jmp edx
112
113 END