Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/compiler-rt/stack_limits.S
6162 views
1
.globl emscripten_stack_init
2
.globl emscripten_stack_set_limits
3
.globl emscripten_stack_get_free
4
.globl emscripten_stack_get_base
5
.globl emscripten_stack_get_end
6
7
#ifdef __wasm64__
8
#define PTR i64
9
#define ALIGN 3
10
#define PTRSTORE .int64
11
#else
12
#define PTR i32
13
#define ALIGN 2
14
#define PTRSTORE .int32
15
#endif
16
17
.globaltype __stack_pointer, PTR
18
19
.section .globals,"",@
20
21
# TODO(sbc): It would be nice if these were initialized directly
22
# using PTR.const rather than using the `emscripten_stack_init`
23
.globaltype __stack_end, PTR
24
__stack_end:
25
.globaltype __stack_base, PTR
26
__stack_base:
27
28
.section .text,"",@
29
30
emscripten_stack_get_base:
31
.functype emscripten_stack_get_base () -> (PTR)
32
global.get __stack_base
33
end_function
34
35
emscripten_stack_get_end:
36
.functype emscripten_stack_get_end () -> (PTR)
37
global.get __stack_end
38
end_function
39
40
emscripten_stack_init:
41
# Initialize __stack_end and __stack_base.
42
# This must be called before emscripten_stack_get_end,
43
# emscripten_stack_get_base, or emscripten_stack_get_free are called
44
.functype emscripten_stack_init () -> ()
45
46
# What llvm calls __stack_high is the high address from where it grows
47
# downwards. We call this the stack base here in emscripten.
48
#ifdef __PIC__
49
global.get __stack_high@GOT
50
#else
51
PTR.const __stack_high
52
#endif
53
global.set __stack_base
54
55
# What llvm calls __stack_low is that end of the stack
56
#ifdef __PIC__
57
global.get __stack_low@GOT
58
#else
59
PTR.const __stack_low
60
#endif
61
# Align up to 16 bytes
62
PTR.const 0xf
63
PTR.add
64
PTR.const -0x10
65
PTR.and
66
global.set __stack_end
67
68
end_function
69
70
emscripten_stack_set_limits:
71
.functype emscripten_stack_set_limits (PTR, PTR) -> ()
72
local.get 0
73
global.set __stack_base
74
local.get 1
75
global.set __stack_end
76
end_function
77
78
emscripten_stack_get_free:
79
.functype emscripten_stack_get_free () -> (PTR)
80
global.get __stack_pointer
81
global.get __stack_end
82
PTR.sub
83
end_function
84
85
# Add emscripten_stack_init to static ctors
86
.section .init_array.1,"",@
87
.p2align ALIGN
88
PTRSTORE emscripten_stack_init
89
90