forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cont.S
150 lines (131 loc) · 3.94 KB
/
cont.S
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
cont.S - continuations support for Xtensa call0 ABI
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
.text
.align 4
.literal_position
.global cont_yield
.type cont_yield, @function
cont_yield:
/* a1: sp */
/* a2: void* cont_ctx */
/* adjust stack and save registers */
addi a1, a1, -24
s32i a12, a1, 0
s32i a13, a1, 4
s32i a14, a1, 8
s32i a15, a1, 12
s32i a0, a1, 16
s32i a2, a1, 20
/* &cont_continue -> cont_ctx.pc_yield */
movi a3, cont_continue
s32i a3, a2, 8
/* sp -> cont_ctx.sp_yield */
s32i a1, a2, 12
/* a0 <- cont_ctx.pc_ret */
l32i a0, a2, 0
/* sp <- cont_ctx.sp_ret */
l32i a1, a2, 4
jx a0
cont_continue:
l32i a12, a1, 0
l32i a13, a1, 4
l32i a14, a1, 8
l32i a15, a1, 12
l32i a0, a1, 16
l32i a2, a1, 20
addi a1, a1, 24
ret
.size cont_yield, . - cont_yield
////////////////////////////////////////////////////
/*
The purpose of cont_wrapper is to signal to xtensa-gdb
that we want to treat this function as the outermost one.
From: binutils-gdb-xtensa/gdb/xtensa-tdep.c:2677 <https://git.io/vA8Ps>
"Special case for terminating backtrace at a function that wants to
be seen as the outermost one. Such a function will clear it's RA (A0)
register to 0 in the prologue instead of saving its original value."
*/
.text
.align 4
.literal_position
.global cont_wrapper
.type cont_wrapper, @function
cont_wrapper:
movi a0, 0
callx0 a3
movi a2, cont_norm
jx a2
.size cont_wrapper, . - cont_wrapper
////////////////////////////////////////////////////
.text
.align 4
.literal_position
.global cont_run
.type cont_run, @function
cont_run:
/* a1: sp */
/* a2: void* cont_ctx */
/* a3: void (*pfn) */
/* adjust stack and save registers */
addi a1, a1, -20
s32i a12, a1, 0
s32i a13, a1, 4
s32i a14, a1, 8
s32i a15, a1, 12
s32i a0, a1, 16
/* cont_ret -> a4 -> cont_ctx.pc_ret*/
movi a4, cont_ret
s32i a4, a2, 0
/* sp -> cont_ctx.sp_ret */
s32i a1, a2, 4
/* if cont_ctx.pc_yield != 0, goto cont_resume */
l32i a4, a2, 8
bnez a4, cont_resume
/* else */
/* set new stack*/
l32i a1, a2, 16;
/* goto pfn */
movi a2, cont_wrapper
jx a2
cont_resume:
/* a1 <- cont_ctx.sp_yield */
l32i a1, a2, 12
/* reset yield flag, 0 -> cont_ctx.pc_yield */
movi a3, 0
s32i a3, a2, 8
/* jump to saved cont_ctx.pc_yield */
movi a0, cont_ret
jx a4
cont_norm:
/* calculate pointer to cont_ctx.struct_start from sp */
l32i a2, a1, 4
/* sp <- cont_ctx.sp_ret */
l32i a1, a2, 4
/* 0 -> cont_ctx.pc_ret */
movi a4, 0
s32i a4, a2, 0
cont_ret:
/* restore registers */
l32i a12, a1, 0
l32i a13, a1, 4
l32i a14, a1, 8
l32i a15, a1, 12
l32i a0, a1, 16
/* adjust stack and return */
addi a1, a1, 20
ret
.size cont_run, . - cont_run