Text file
src/runtime/sys_plan9_amd64.s
1 // Copyright 2010 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.
4
5 #include "go_asm.h"
6 #include "go_tls.h"
7 #include "textflag.h"
8
9 TEXT runtime·open(SB),NOSPLIT,$0
10 MOVQ $14, BP
11 SYSCALL
12 MOVL AX, ret+16(FP)
13 RET
14
15 TEXT runtime·pread(SB),NOSPLIT,$0
16 MOVQ $50, BP
17 SYSCALL
18 MOVL AX, ret+32(FP)
19 RET
20
21 TEXT runtime·pwrite(SB),NOSPLIT,$0
22 MOVQ $51, BP
23 SYSCALL
24 MOVL AX, ret+32(FP)
25 RET
26
27 // int32 _seek(int64*, int32, int64, int32)
28 TEXT _seek<>(SB),NOSPLIT,$0
29 MOVQ $39, BP
30 SYSCALL
31 RET
32
33 // int64 seek(int32, int64, int32)
34 // Convenience wrapper around _seek, the actual system call.
35 TEXT runtime·seek(SB),NOSPLIT,$32
36 LEAQ ret+24(FP), AX
37 MOVL fd+0(FP), BX
38 MOVQ offset+8(FP), CX
39 MOVL whence+16(FP), DX
40 MOVQ AX, 0(SP)
41 MOVL BX, 8(SP)
42 MOVQ CX, 16(SP)
43 MOVL DX, 24(SP)
44 CALL _seek<>(SB)
45 CMPL AX, $0
46 JGE 2(PC)
47 MOVQ $-1, ret+24(FP)
48 RET
49
50 TEXT runtime·closefd(SB),NOSPLIT,$0
51 MOVQ $4, BP
52 SYSCALL
53 MOVL AX, ret+8(FP)
54 RET
55
56 TEXT runtime·exits(SB),NOSPLIT,$0
57 MOVQ $8, BP
58 SYSCALL
59 RET
60
61 TEXT runtime·brk_(SB),NOSPLIT,$0
62 MOVQ $24, BP
63 SYSCALL
64 MOVL AX, ret+8(FP)
65 RET
66
67 TEXT runtime·sleep(SB),NOSPLIT,$0
68 MOVQ $17, BP
69 SYSCALL
70 MOVL AX, ret+8(FP)
71 RET
72
73 TEXT runtime·plan9_semacquire(SB),NOSPLIT,$0
74 MOVQ $37, BP
75 SYSCALL
76 MOVL AX, ret+16(FP)
77 RET
78
79 TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
80 MOVQ $52, BP
81 SYSCALL
82 MOVL AX, ret+16(FP)
83 RET
84
85 TEXT runtime·nsec(SB),NOSPLIT,$0
86 MOVQ $53, BP
87 SYSCALL
88 MOVQ AX, ret+8(FP)
89 RET
90
91 // func walltime() (sec int64, nsec int32)
92 TEXT runtime·walltime(SB),NOSPLIT,$8-12
93 CALL runtime·nanotime1(SB)
94 MOVQ 0(SP), AX
95
96 // generated code for
97 // func f(x uint64) (uint64, uint64) { return x/1000000000, x%1000000000 }
98 // adapted to reduce duplication
99 MOVQ AX, CX
100 MOVQ $1360296554856532783, AX
101 MULQ CX
102 ADDQ CX, DX
103 RCRQ $1, DX
104 SHRQ $29, DX
105 MOVQ DX, sec+0(FP)
106 IMULQ $1000000000, DX
107 SUBQ DX, CX
108 MOVL CX, nsec+8(FP)
109 RET
110
111 TEXT runtime·notify(SB),NOSPLIT,$0
112 MOVQ $28, BP
113 SYSCALL
114 MOVL AX, ret+8(FP)
115 RET
116
117 TEXT runtime·noted(SB),NOSPLIT,$0
118 MOVQ $29, BP
119 SYSCALL
120 MOVL AX, ret+8(FP)
121 RET
122
123 TEXT runtime·plan9_semrelease(SB),NOSPLIT,$0
124 MOVQ $38, BP
125 SYSCALL
126 MOVL AX, ret+16(FP)
127 RET
128
129 TEXT runtime·rfork(SB),NOSPLIT,$0
130 MOVQ $19, BP
131 SYSCALL
132 MOVL AX, ret+8(FP)
133 RET
134
135 TEXT runtime·tstart_plan9(SB),NOSPLIT,$8
136 MOVQ newm+0(FP), CX
137 MOVQ m_g0(CX), DX
138
139 // Layout new m scheduler stack on os stack.
140 MOVQ SP, AX
141 MOVQ AX, (g_stack+stack_hi)(DX)
142 SUBQ $(64*1024), AX // stack size
143 MOVQ AX, (g_stack+stack_lo)(DX)
144 MOVQ AX, g_stackguard0(DX)
145 MOVQ AX, g_stackguard1(DX)
146
147 // Initialize procid from TOS struct.
148 MOVQ _tos(SB), AX
149 MOVL 64(AX), AX
150 MOVQ AX, m_procid(CX) // save pid as m->procid
151
152 // Finally, initialize g.
153 get_tls(BX)
154 MOVQ DX, g(BX)
155
156 CALL runtime·stackcheck(SB) // smashes AX, CX
157 CALL runtime·mstart(SB)
158
159 // Exit the thread.
160 MOVQ $0, 0(SP)
161 CALL runtime·exits(SB)
162 JMP 0(PC)
163
164 // This is needed by asm_amd64.s
165 TEXT runtime·settls(SB),NOSPLIT,$0
166 RET
167
168 // void sigtramp(void *ureg, int8 *note)
169 TEXT runtime·sigtramp(SB),NOSPLIT,$0
170 get_tls(AX)
171
172 // check that g exists
173 MOVQ g(AX), BX
174 CMPQ BX, $0
175 JNE 3(PC)
176 CALL runtime·badsignal2(SB) // will exit
177 RET
178
179 // save args
180 MOVQ ureg+0(FP), CX
181 MOVQ note+8(FP), DX
182
183 // change stack
184 MOVQ g_m(BX), BX
185 MOVQ m_gsignal(BX), R10
186 MOVQ (g_stack+stack_hi)(R10), BP
187 MOVQ BP, SP
188
189 // make room for args and g
190 SUBQ $128, SP
191
192 // save g
193 MOVQ g(AX), BP
194 MOVQ BP, 32(SP)
195
196 // g = m->gsignal
197 MOVQ R10, g(AX)
198
199 // load args and call sighandler
200 MOVQ CX, 0(SP)
201 MOVQ DX, 8(SP)
202 MOVQ BP, 16(SP)
203
204 CALL runtime·sighandler(SB)
205 MOVL 24(SP), AX
206
207 // restore g
208 get_tls(BX)
209 MOVQ 32(SP), R10
210 MOVQ R10, g(BX)
211
212 // call noted(AX)
213 MOVQ AX, 0(SP)
214 CALL runtime·noted(SB)
215 RET
216
217 TEXT runtime·setfpmasks(SB),NOSPLIT,$8
218 STMXCSR 0(SP)
219 MOVL 0(SP), AX
220 ANDL $~0x3F, AX
221 ORL $(0x3F<<7), AX
222 MOVL AX, 0(SP)
223 LDMXCSR 0(SP)
224 RET
225
226 #define ERRMAX 128 /* from os_plan9.h */
227
228 // void errstr(int8 *buf, int32 len)
229 TEXT errstr<>(SB),NOSPLIT,$0
230 MOVQ $41, BP
231 SYSCALL
232 RET
233
234 // func errstr() string
235 // Only used by package syscall.
236 // Grab error string due to a syscall made
237 // in entersyscall mode, without going
238 // through the allocator (issue 4994).
239 // See ../syscall/asm_plan9_amd64.s:/·Syscall/
240 TEXT runtime·errstr(SB),NOSPLIT,$16-16
241 get_tls(AX)
242 MOVQ g(AX), BX
243 MOVQ g_m(BX), BX
244 MOVQ (m_mOS+mOS_errstr)(BX), CX
245 MOVQ CX, 0(SP)
246 MOVQ $ERRMAX, 8(SP)
247 CALL errstr<>(SB)
248 CALL runtime·findnull(SB)
249 MOVQ 8(SP), AX
250 MOVQ AX, ret_len+8(FP)
251 MOVQ 0(SP), AX
252 MOVQ AX, ret_base+0(FP)
253 RET
254
255 // never called on this platform
256 TEXT ·sigpanictramp(SB),NOSPLIT,$0-0
257 UNDEF
258
View as plain text