aboutsummaryrefslogtreecommitdiff
path: root/src/lib/libc/setjmp.s
blob: 164cc5b478255a0da4ab1150662a9428fce1bb0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[GLOBAL setjmp]
setjmp:
	; Store general purpose registers
	; (in new stack frame)
	mov [esp+4], eax
	mov [esp+8], ebx
	mov [esp+12], ecx
	mov [esp+16], edx
	mov [esp+20], edi
	mov [esp+24], esi
	mov [esp+28], ebp
	mov [esp+32], esp

	; Store flags
	pushf
	pop eax
	mov [esp+36], eax

	; Store return address
	mov eax, [esp]
	mov [esp+40], eax

	; return 0
	xor eax, eax
	ret


[GLOBAL longjmp]
longjmp:
	; on previous stack, resume return address
	mov eax, [esp+32]
	mov ebx, [esp+40]
	mov [eax], ebx

	; resume flags
	mov eax, [esp+36]
	push eax
	popf

	; load return value in eax
	mov eax, [esp+44]
	; resume geneal purpose registers, except eax/esp
	mov ebx, [esp+8]
	mov ecx, [esp+12]
	mov edx, [esp+16]
	mov edi, [esp+20]
	mov esi, [esp+24]
	mov ebp, [esp+28]

	; resume previous esp
	mov esp, [esp+32]
	; return as if we were the setjmp call
	ret