-
Notifications
You must be signed in to change notification settings - Fork 8
/
sys_tamago_arm.s
127 lines (103 loc) · 2.82 KB
/
sys_tamago_arm.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
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// System calls and other sys.stuff for arm, tamago
//
#include "go_asm.h"
#include "go_tls.h"
#include "textflag.h"
TEXT runtime·rt0_arm_tamago(SB),NOSPLIT|NOFRAME,$0
MOVW $0xcafebabe, R12
// set up g register
// g is R10
MOVW $runtime·g0(SB), g
MOVW $runtime·m0(SB), R8
// save m->g0 = g0
MOVW g, m_g0(R8)
// save g->m = m0
MOVW R8, g_m(g)
// create 64kB istack out of the bootstack
MOVW $(-64*1024)(R13), R0
MOVW R0, g_stackguard0(g)
MOVW R0, g_stackguard1(g)
MOVW R0, (g_stack+stack_lo)(g)
MOVW R13, (g_stack+stack_hi)(g)
BL runtime·emptyfunc(SB) // fault if stack check is wrong
BL runtime·hwinit(SB)
BL runtime·check(SB)
BL runtime·checkgoarm(SB)
BL runtime·osinit(SB)
BL runtime·schedinit(SB)
// create a new goroutine to start program
MOVW $runtime·mainPC(SB), R0
MOVW.W R0, -4(R13)
MOVW $8, R0
MOVW.W R0, -4(R13)
MOVW $0, R0
MOVW.W R0, -4(R13) // push $0 as guard
BL runtime·newproc(SB)
MOVW $12(R13), R13 // pop args and LR
// start this M
BL runtime·mstart(SB)
MOVW $1234, R0
MOVW $1000, R1
MOVW R0, (R1) // fail hard
TEXT runtime·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0
B runtime·armPublicationBarrier(SB)
// CallOnG0 calls a function (func(off int)) on g0 stack.
//
// The function arguments must be passed through the following registers
// (rather than on the frame pointer):
//
// * R0: fn argument (vector table offset)
// * R1: fn pointer
// * R2: size of stack area reserved for caller registers
// * R3: caller program counter
TEXT runtime·CallOnG0(SB),NOSPLIT|NOFRAME,$0-0
// restore SP
ADD R2, R13, R5
MOVW R5, (g_sched+gobuf_sp)(g)
// align stack pointer to fixed offset
SUB $56, R2, R4
SUB R4, R13, R13
// save LR
WORD $0xe92d4000 // stmdb r13!,{lr}
// restore PC
MOVW R3, (g_sched+gobuf_pc)(g)
// restore g
MOVW R3, (g_sched+gobuf_lr)(g)
MOVW g, (g_sched+gobuf_g)(g)
// switch to g0
MOVW g_m(g), R6
MOVW m_g0(R6), R2
MOVW R2, g
MOVW (g_sched+gobuf_sp)(R2), R3
/* make it look like mstart called systemstack on g0 */
/* to stop traceback (see runtime·systemstack) */
SUB $4, R3, R3
MOVW $runtime·mstart(SB), R4
MOVW R4, 0(R3)
MOVW R3, R13
// call handler function
MOVW R0, off+0(FP)
BL (R1)
// switch back to g
MOVW g_m(g), R1
MOVW m_curg(R1), R0
MOVW R0, g
// restore stack pointer
MOVW (g_sched+gobuf_sp)(g), R13
MOVW $0, R3
MOVW R3, (g_sched+gobuf_sp)(g)
// restore LR
MOVW (g_sched+gobuf_pc)(g), R14
// restore LR from PC
SUB $4, R13, R13 // saved LR
SUB $56, R13, R13 // saved caller registers
WORD $0xe8bd8000 // ldmia r13!,{pc}
// never called (cgo not supported)
TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0
MOVW $0, R0
MOVW R0, (R0)
RET