Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/fiber/src/stackswitch/s390x.S
1693 views
1
// A WORD OF CAUTION
2
//
3
// This entire file basically needs to be kept in sync with itself. It's not
4
// really possible to modify just one bit of this file without understanding
5
// all the other bits. Documentation tries to reference various bits here and
6
// there but try to make sure to read over everything before tweaking things!
7
//
8
// Also at this time this file is heavily based off the x86_64 file, so you'll
9
// probably want to read that one as well.
10
11
.text
12
13
#define CONCAT2(a, b) a ## b
14
#define CONCAT(a, b) CONCAT2(a , b)
15
#define VERSIONED_SYMBOL(a) CONCAT(a, VERSIONED_SUFFIX)
16
#define GLOBL(fnname) .globl VERSIONED_SYMBOL(fnname)
17
#define HIDDEN(fnname) .hidden VERSIONED_SYMBOL(fnname)
18
#define TYPE(fnname) .type VERSIONED_SYMBOL(fnname),@function
19
#define FUNCTION(fnname) VERSIONED_SYMBOL(fnname)
20
#define SIZE(fnname) .size VERSIONED_SYMBOL(fnname),.-VERSIONED_SYMBOL(fnname)
21
22
// fn(top_of_stack(%x0): *mut u8)
23
HIDDEN(wasmtime_fiber_switch)
24
GLOBL(wasmtime_fiber_switch)
25
.p2align 2
26
TYPE(wasmtime_fiber_switch)
27
FUNCTION(wasmtime_fiber_switch):
28
// Save all callee-saved registers on the stack since we're assuming
29
// they're clobbered as a result of the stack switch.
30
stmg %r6, %r15, 48(%r15)
31
aghi %r15, -64
32
std %f8, 0(%r15)
33
std %f9, 8(%r15)
34
std %f10, 16(%r15)
35
std %f11, 24(%r15)
36
std %f12, 32(%r15)
37
std %f13, 40(%r15)
38
std %f14, 48(%r15)
39
std %f15, 56(%r15)
40
41
// Load our previously saved stack pointer to resume to, and save off our
42
// current stack pointer on where to come back to eventually.
43
lg %r1, -16(%r2)
44
stg %r15, -16(%r2)
45
46
// Switch to the new stack and restore all our callee-saved registers after
47
// the switch and return to our new stack.
48
ld %f8, 0(%r1)
49
ld %f9, 8(%r1)
50
ld %f10, 16(%r1)
51
ld %f11, 24(%r1)
52
ld %f12, 32(%r1)
53
ld %f13, 40(%r1)
54
ld %f14, 48(%r1)
55
ld %f15, 56(%r1)
56
lmg %r6, %r15, 112(%r1)
57
br %r14
58
SIZE(wasmtime_fiber_switch)
59
60
// fn(
61
// top_of_stack(%x0): *mut u8,
62
// entry_point(%x1): extern fn(*mut u8, *mut u8),
63
// entry_arg0(%x2): *mut u8,
64
// )
65
HIDDEN(wasmtime_fiber_init)
66
GLOBL(wasmtime_fiber_init)
67
.p2align 2
68
TYPE(wasmtime_fiber_init)
69
FUNCTION(wasmtime_fiber_init):
70
larl %r1, FUNCTION(wasmtime_fiber_start)
71
stg %r1, -48(%r2) // wasmtime_fiber_start - restored into %r14
72
stg %r2, -112(%r2) // top_of_stack - restored into %r6
73
stg %r3, -104(%r2) // entry_point - restored into %r7
74
stg %r4, -96(%r2) // entry_arg0 - restored into %r8
75
aghi %r2, -160 // 160 bytes register save area
76
stg %r2, 120(%r2) // bottom of register save area - restored into %r15
77
78
// `wasmtime_fiber_switch` has a 64 byte stack.
79
aghi %r2, -64
80
stg %r2, 208(%r2)
81
br %r14
82
SIZE(wasmtime_fiber_init)
83
84
.p2align 2
85
TYPE(wasmtime_fiber_start)
86
FUNCTION(wasmtime_fiber_start):
87
.cfi_startproc simple
88
.cfi_def_cfa_offset 0
89
90
// See the x86_64 file for more commentary on what these CFI directives are
91
// doing. Like over there note that the relative offsets to registers here
92
// match the frame layout in `wasmtime_fiber_switch`.
93
.cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \
94
7, /* the byte length of this expression */ \
95
0x7f, 0x90, 0x1, /* DW_OP_breg15 0x90 */ \
96
0x06, /* DW_OP_deref */ \
97
0x23, 0xe0, 0x1 /* DW_OP_plus_uconst 0xe0 */
98
99
.cfi_rel_offset 6, -112
100
.cfi_rel_offset 7, -104
101
.cfi_rel_offset 8, -96
102
.cfi_rel_offset 9, -88
103
.cfi_rel_offset 10, -80
104
.cfi_rel_offset 11, -72
105
.cfi_rel_offset 12, -64
106
.cfi_rel_offset 13, -56
107
.cfi_rel_offset 14, -48
108
.cfi_rel_offset 15, -40
109
110
// Load our two arguments prepared by `wasmtime_fiber_init`.
111
lgr %r2, %r8 // entry_arg0
112
lgr %r3, %r6 // top_of_stack
113
114
// ... and then we call the function! Note that this is a function call so
115
// our frame stays on the stack to backtrace through.
116
basr %r14, %r7 // entry_point
117
// .. technically we shouldn't get here, so just trap.
118
.word 0x0000
119
.cfi_endproc
120
SIZE(wasmtime_fiber_start)
121
122
// Mark that we don't need executable stack.
123
.section .note.GNU-stack,"",%progbits
124
125