blob: 6aefe5f125f7352d23753bfa68f13456e9ed9b95 [file] [log] [blame]
Akshat Kumara72bebf2012-08-31 13:21:13 -04001// 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
Russ Cox15ced2d2014-11-11 17:06:22 -05005#include "go_asm.h"
6#include "go_tls.h"
Russ Coxcb040d52014-09-04 23:05:18 -04007#include "textflag.h"
Akshat Kumara72bebf2012-08-31 13:21:13 -04008
9// setldt(int entry, int address, int limit)
Keith Randall0273dc12013-08-07 12:20:05 -070010TEXT runtime·setldt(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040011 RET
12
Keith Randall0273dc12013-08-07 12:20:05 -070013TEXT runtime·open(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040014 MOVQ $14, BP
15 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040016 MOVL AX, ret+16(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040017 RET
18
Keith Randall0273dc12013-08-07 12:20:05 -070019TEXT runtime·pread(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040020 MOVQ $50, BP
21 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040022 MOVL AX, ret+32(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040023 RET
24
Keith Randall0273dc12013-08-07 12:20:05 -070025TEXT runtime·pwrite(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040026 MOVQ $51, BP
27 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040028 MOVL AX, ret+32(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040029 RET
30
Anthony Martin432f1822012-12-17 11:07:40 -050031// int32 _seek(int64*, int32, int64, int32)
Keith Randall0273dc12013-08-07 12:20:05 -070032TEXT _seek<>(SB),NOSPLIT,$0
Anthony Martin432f1822012-12-17 11:07:40 -050033 MOVQ $39, BP
34 SYSCALL
35 RET
36
37// int64 seek(int32, int64, int32)
Russ Cox25f6b022014-08-27 11:32:17 -040038// Convenience wrapper around _seek, the actual system call.
39TEXT runtime·seek(SB),NOSPLIT,$32
Russ Cox50199d72014-08-30 14:53:47 -040040 LEAQ ret+24(FP), AX
Russ Cox25f6b022014-08-27 11:32:17 -040041 MOVL fd+0(FP), BX
42 MOVQ offset+8(FP), CX
43 MOVL whence+16(FP), DX
44 MOVQ AX, 0(SP)
45 MOVL BX, 8(SP)
Anthony Martin432f1822012-12-17 11:07:40 -050046 MOVQ CX, 16(SP)
Russ Cox25f6b022014-08-27 11:32:17 -040047 MOVL DX, 24(SP)
Anthony Martin432f1822012-12-17 11:07:40 -050048 CALL _seek<>(SB)
49 CMPL AX, $0
50 JGE 2(PC)
Russ Cox25f6b022014-08-27 11:32:17 -040051 MOVQ $-1, ret+24(FP)
Anthony Martin432f1822012-12-17 11:07:40 -050052 RET
53
David Crawshawcea272d2015-04-13 19:37:04 -040054TEXT runtime·closefd(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040055 MOVQ $4, BP
56 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040057 MOVL AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040058 RET
59
Keith Randall0273dc12013-08-07 12:20:05 -070060TEXT runtime·exits(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040061 MOVQ $8, BP
62 SYSCALL
63 RET
64
Keith Randall0273dc12013-08-07 12:20:05 -070065TEXT runtime·brk_(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040066 MOVQ $24, BP
67 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040068 MOVQ AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040069 RET
70
Keith Randall0273dc12013-08-07 12:20:05 -070071TEXT runtime·sleep(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040072 MOVQ $17, BP
73 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040074 MOVL AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040075 RET
76
Keith Randall0273dc12013-08-07 12:20:05 -070077TEXT runtime·plan9_semacquire(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040078 MOVQ $37, BP
79 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040080 MOVL AX, ret+16(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040081 RET
82
Keith Randall0273dc12013-08-07 12:20:05 -070083TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -040084 MOVQ $52, BP
85 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040086 MOVL AX, ret+16(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -040087 RET
88
Aram Hăvărneanua84e3ad2014-07-09 12:33:42 +020089TEXT runtime·nsec(SB),NOSPLIT,$0
90 MOVQ $53, BP
91 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -040092 MOVQ AX, ret+8(FP)
Aram Hăvărneanua84e3ad2014-07-09 12:33:42 +020093 RET
94
Russ Cox13d0b822014-09-07 23:40:59 -040095// func now() (sec int64, nsec int32)
96TEXT time·now(SB),NOSPLIT,$8-12
97 CALL runtime·nanotime(SB)
98 MOVQ 0(SP), AX
99
100 // generated code for
101 // func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
102 // adapted to reduce duplication
103 MOVQ AX, CX
104 MOVQ $1360296554856532783, AX
105 MULQ CX
106 ADDQ CX, DX
107 RCRQ $1, DX
108 SHRQ $29, DX
109 MOVQ DX, sec+0(FP)
110 IMULQ $1000000000, DX
111 SUBQ DX, CX
112 MOVL CX, nsec+8(FP)
113 RET
114
Keith Randall0273dc12013-08-07 12:20:05 -0700115TEXT runtime·notify(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -0400116 MOVQ $28, BP
117 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -0400118 MOVL AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -0400119 RET
120
Keith Randall0273dc12013-08-07 12:20:05 -0700121TEXT runtime·noted(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -0400122 MOVQ $29, BP
123 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -0400124 MOVL AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -0400125 RET
126
Keith Randall0273dc12013-08-07 12:20:05 -0700127TEXT runtime·plan9_semrelease(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -0400128 MOVQ $38, BP
129 SYSCALL
Russ Cox25f6b022014-08-27 11:32:17 -0400130 MOVL AX, ret+16(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -0400131 RET
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800132
Keith Randall0273dc12013-08-07 12:20:05 -0700133TEXT runtime·rfork(SB),NOSPLIT,$0
Anthony Martin9f012e12014-09-09 17:19:01 -0700134 MOVQ $19, BP
Akshat Kumara72bebf2012-08-31 13:21:13 -0400135 SYSCALL
Anthony Martin9f012e12014-09-09 17:19:01 -0700136 MOVL AX, ret+8(FP)
Akshat Kumara72bebf2012-08-31 13:21:13 -0400137 RET
138
Anthony Martin9f012e12014-09-09 17:19:01 -0700139TEXT runtime·tstart_plan9(SB),NOSPLIT,$0
140 MOVQ newm+0(FP), CX
141 MOVQ m_g0(CX), DX
Akshat Kumara72bebf2012-08-31 13:21:13 -0400142
Anthony Martin9f012e12014-09-09 17:19:01 -0700143 // Layout new m scheduler stack on os stack.
144 MOVQ SP, AX
145 MOVQ AX, (g_stack+stack_hi)(DX)
146 SUBQ $(64*1024), AX // stack size
147 MOVQ AX, (g_stack+stack_lo)(DX)
Russ Coxe6d35112015-01-05 16:29:21 +0000148 MOVQ AX, g_stackguard0(DX)
149 MOVQ AX, g_stackguard1(DX)
Akshat Kumara72bebf2012-08-31 13:21:13 -0400150
Aram Hăvărneanudecd8102014-07-02 21:04:10 +1000151 // Initialize procid from TOS struct.
152 MOVQ _tos(SB), AX
Anthony Martin70f92862014-09-12 01:21:51 -0700153 MOVL 64(AX), AX
Anthony Martin9f012e12014-09-09 17:19:01 -0700154 MOVQ AX, m_procid(CX) // save pid as m->procid
155
156 // Finally, initialize g.
157 get_tls(BX)
158 MOVQ DX, g(BX)
159
Akshat Kumara72bebf2012-08-31 13:21:13 -0400160 CALL runtime·stackcheck(SB) // smashes AX, CX
Anthony Martin9f012e12014-09-09 17:19:01 -0700161 CALL runtime·mstart(SB)
162
163 MOVQ $0x1234, 0x1234 // not reached
Akshat Kumara72bebf2012-08-31 13:21:13 -0400164 RET
165
166// This is needed by asm_amd64.s
Keith Randall0273dc12013-08-07 12:20:05 -0700167TEXT runtime·settls(SB),NOSPLIT,$0
Akshat Kumara72bebf2012-08-31 13:21:13 -0400168 RET
Akshat Kumar23599ca2012-10-05 16:23:30 -0400169
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800170// void sigtramp(void *ureg, int8 *note)
Keith Randall0273dc12013-08-07 12:20:05 -0700171TEXT runtime·sigtramp(SB),NOSPLIT,$0
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800172 get_tls(AX)
173
Russ Cox89f185f2014-06-26 11:54:39 -0400174 // check that g exists
175 MOVQ g(AX), BX
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800176 CMPQ BX, $0
177 JNE 3(PC)
Shenghou Ma2f1ead72013-07-12 04:39:39 +0800178 CALL runtime·badsignal2(SB) // will exit
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800179 RET
180
181 // save args
182 MOVQ ureg+8(SP), CX
183 MOVQ note+16(SP), DX
184
185 // change stack
Russ Cox89f185f2014-06-26 11:54:39 -0400186 MOVQ g_m(BX), BX
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800187 MOVQ m_gsignal(BX), R10
Russ Cox8ac35be2014-09-09 14:02:37 -0400188 MOVQ (g_stack+stack_hi)(R10), BP
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800189 MOVQ BP, SP
190
191 // make room for args and g
Russ Coxf9829e92014-09-09 17:16:31 -0400192 SUBQ $128, SP
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800193
194 // save g
195 MOVQ g(AX), BP
Russ Cox9e360922014-08-27 17:38:01 -0400196 MOVQ BP, 32(SP)
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800197
198 // g = m->gsignal
199 MOVQ R10, g(AX)
200
201 // load args and call sighandler
202 MOVQ CX, 0(SP)
203 MOVQ DX, 8(SP)
204 MOVQ BP, 16(SP)
205
206 CALL runtime·sighandler(SB)
Russ Cox9e360922014-08-27 17:38:01 -0400207 MOVL 24(SP), AX
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800208
209 // restore g
210 get_tls(BX)
Russ Cox9e360922014-08-27 17:38:01 -0400211 MOVQ 32(SP), R10
Akshat Kumarc74f3c42013-01-30 02:53:56 -0800212 MOVQ R10, g(BX)
213
214 // call noted(AX)
215 MOVQ AX, 0(SP)
216 CALL runtime·noted(SB)
217 RET
218
Keith Randall0273dc12013-08-07 12:20:05 -0700219TEXT runtime·setfpmasks(SB),NOSPLIT,$8
Akshat Kumar23599ca2012-10-05 16:23:30 -0400220 STMXCSR 0(SP)
221 MOVL 0(SP), AX
222 ANDL $~0x3F, AX
223 ORL $(0x3F<<7), AX
224 MOVL AX, 0(SP)
225 LDMXCSR 0(SP)
226 RET
Akshat Kumara566dea2013-03-08 00:54:44 +0100227
228#define ERRMAX 128 /* from os_plan9.h */
229
Anthony Martinb3de7f22014-08-28 16:02:15 -0700230// void errstr(int8 *buf, int32 len)
231TEXT errstr<>(SB),NOSPLIT,$0
232 MOVQ $41, BP
233 SYSCALL
234 RET
235
236// func errstr() string
Akshat Kumara566dea2013-03-08 00:54:44 +0100237// Only used by package syscall.
238// Grab error string due to a syscall made
239// in entersyscall mode, without going
240// through the allocator (issue 4994).
Anthony Martinb3de7f22014-08-28 16:02:15 -0700241// See ../syscall/asm_plan9_amd64.s:/·Syscall/
242TEXT runtime·errstr(SB),NOSPLIT,$16-16
Akshat Kumara566dea2013-03-08 00:54:44 +0100243 get_tls(AX)
Russ Cox89f185f2014-06-26 11:54:39 -0400244 MOVQ g(AX), BX
245 MOVQ g_m(BX), BX
Akshat Kumara566dea2013-03-08 00:54:44 +0100246 MOVQ m_errstr(BX), CX
Anthony Martinb3de7f22014-08-28 16:02:15 -0700247 MOVQ CX, 0(SP)
248 MOVQ $ERRMAX, 8(SP)
249 CALL errstr<>(SB)
Akshat Kumara566dea2013-03-08 00:54:44 +0100250 CALL runtime·findnull(SB)
Anthony Martinb3de7f22014-08-28 16:02:15 -0700251 MOVQ 8(SP), AX
Russ Cox25f6b022014-08-27 11:32:17 -0400252 MOVQ AX, ret_len+8(FP)
Anthony Martinb3de7f22014-08-28 16:02:15 -0700253 MOVQ 0(SP), AX
254 MOVQ AX, ret_base+0(FP)
Akshat Kumara566dea2013-03-08 00:54:44 +0100255 RET