1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // using frame size $-4 means do not save LR on stack.
8 TEXT _rt0_arm(SB),7,$-4
11 // copy arguments forward on an even stack
12 // use R13 instead of SP to avoid linker rewriting the offsets
13 MOVW 0(R13), R0 // argc
14 MOVW $4(R13), R1 // argv
15 SUB $128, R13 // plenty of scratch
17 MOVW R0, 120(R13) // save argc, argv away
20 // set up m and g registers
28 // create istack out of the OS stack
29 MOVW $(-8192+104)(R13), R0
30 MOVW R0, g_stackguard(g) // (w 104b guard)
31 MOVW R13, g_stackbase(g)
32 BL emptyfunc(SB) // fault if stack check is wrong
45 // create a new goroutine to start program
46 MOVW $mainstart(SB), R0
51 MOVW.W R0, -4(R13) // push $0 as guard
53 MOVW $12(R13), R13 // pop args and LR
60 MOVW R0, (R1) // fail hard
61 B _dep_dummy(SB) // Never reached
64 TEXT mainstart(SB),7,$4
73 MOVW R0, (R1) // fail hard
76 // TODO(kaib): remove these once i actually understand how the linker removes symbols
77 // pull in dummy dependencies
78 TEXT _dep_dummy(SB),7,$0
86 TEXT breakpoint(SB),7,$0
95 // uintptr gosave(Gobuf*)
96 // save state in Gobuf; setjmp
97 TEXT gosave(SB), 7, $-4
100 MOVW LR, gobuf_pc(R0)
102 MOVW $0, R0 // return 0
105 // void gogo(Gobuf*, uintptr)
106 // restore state from Gobuf; longjmp
107 TEXT gogo(SB), 7, $-4
108 MOVW 0(FP), R1 // gobuf
109 MOVW 4(FP), R0 // return 2nd arg
111 MOVW 0(g), R2 // make sure g != nil
112 MOVW gobuf_sp(R1), SP // restore SP
113 MOVW gobuf_pc(R1), PC
115 // void gogocall(Gobuf*, void (*fn)(void))
116 // restore state from Gobuf but then call fn.
117 // (call fn, returning to state in Gobuf)
118 // using frame size $-4 means do not save LR on stack.
119 TEXT gogocall(SB), 7, $-4
123 MOVW 0(g), R2 // make sure g != nil
124 MOVW gobuf_sp(R0), SP // restore SP
125 MOVW gobuf_pc(R0), LR
129 * support for morestack
132 // Called during function prolog when more stack is needed.
136 // NB. we do not save R0 because the we've forced 5c to pass all arguments
138 // using frame size $-4 means do not save LR on stack.
139 TEXT ·morestack(SB),7,$-4
140 // Cannot grow scheduler stack (m->g0).
147 MOVW R1, m_moreframe(m)
148 MOVW R2, m_moreargs(m)
151 // Set m->morebuf to f's caller.
152 MOVW R3, (m_morebuf+gobuf_pc)(m) // f's caller's PC
153 MOVW SP, (m_morebuf+gobuf_sp)(m) // f's caller's SP
154 MOVW SP, m_morefp(m) // f's caller's SP
155 MOVW g, (m_morebuf+gobuf_g)(m)
157 // Set m->morepc to f's PC.
160 // Call newstack on m's scheduling stack.
162 MOVW (m_sched+gobuf_sp)(m), SP
165 // Called from reflection library. Mimics morestack,
166 // reuses stack growth code to create a frame
167 // with the desired args running the desired function.
169 // func call(fn *byte, arg *byte, argsize uint32).
170 TEXT reflect·call(SB), 7, $-4
171 // Save our caller's state as the PC and SP to
172 // restore when returning from f.
173 MOVW LR, (m_morebuf+gobuf_pc)(m) // our caller's PC
174 MOVW SP, (m_morebuf+gobuf_sp)(m) // our caller's SP
175 MOVW g, (m_morebuf+gobuf_g)(m)
177 // Set up morestack arguments to call f on a new stack.
178 // We set f's frame size to 1, as a hint to newstack
179 // that this is a call from reflect·call.
180 // If it turns out that f needs a larger frame than
181 // the default stack, f's usual stack growth prolog will
182 // allocate a new segment (and recopy the arguments).
184 MOVW 8(SP), R1 // arg frame
185 MOVW 12(SP), R2 // arg size
187 MOVW R0, m_morepc(m) // f's PC
188 MOVW R1, m_morefp(m) // argument frame pointer
189 MOVW R2, m_moreargs(m) // f's argument size
191 MOVW R3, m_moreframe(m) // f's frame size
193 // Call newstack on m's scheduling stack.
195 MOVW (m_sched+gobuf_sp)(m), SP
198 // Return point when leaving stack.
199 // using frame size $-4 means do not save LR on stack.
200 TEXT ·lessstack(SB), 7, $-4
201 // Save return value in m->cret
204 // Call oldstack on m's scheduling stack.
206 MOVW (m_sched+gobuf_sp)(m), SP
209 // void jmpdefer(fn, sp);
210 // called from deferreturn.
211 // 1. grab stored LR for caller
212 // 2. sub 4 bytes to get back to BL deferreturn
214 TEXT jmpdefer(SB), 7, $0
216 MOVW $-4(LR), LR // BL deferreturn
219 MOVW $-4(R1), SP // correct for sp pointing to arg0, past stored lr
222 TEXT ·memclr(SB),7,$20
228 MOVW m, -8(SP) // Save m and g
231 MOVW -8(SP), m // Restore m and g, memset clobbers them
235 TEXT ·getcallerpc+0(SB),7,$-4
239 TEXT ·setcallerpc+0(SB),7,$-4
244 // runcgo(void(*fn)(void*), void *arg)
245 // Just call fn(arg), but first align the stack
246 // appropriately for the gcc ABI.
247 // TODO(kaib): figure out the arm-gcc ABI
248 TEXT runcgo(SB),7,$16
251 // MOVL arg+4(FP), BX
253 // ANDL $~15, SP // alignment for gcc ABI
260 TEXT emptyfunc(SB),0,$0
267 // callString(f, arg, out)
268 // call Go f(arg), which returns a string, and store in out
269 TEXT callString(SB), 7, $24