summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/sys_plan9_386.s
blob: 1f860a96190bd6503891fdc9fcee3b9da4ba112e (plain)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright 2010 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.

#include "zasm_GOOS_GOARCH.h"

// setldt(int entry, int address, int limit)
TEXT runtime·setldt(SB),7,$0
	RET

TEXT runtime·open(SB),7,$0
	MOVL    $14, AX
	INT     $64
	RET

TEXT runtime·pread(SB),7,$0
	MOVL    $50, AX
	INT     $64
	RET

TEXT runtime·pwrite(SB),7,$0
	MOVL    $51, AX
	INT     $64
	RET

TEXT runtime·seek(SB),7,$0
	MOVL	$39, AX
	INT	$64
	CMPL	AX, $-1
	JNE	4(PC)
	MOVL	a+0(FP), CX
	MOVL	AX, 0(CX)
	MOVL	AX, 4(CX)
	RET

TEXT runtime·close(SB),7,$0
	MOVL	$4, AX
	INT	$64
	RET

TEXT runtime·exits(SB),7,$0
	MOVL    $8, AX
	INT     $64
	RET

TEXT runtime·brk_(SB),7,$0
	MOVL    $24, AX
	INT     $64
	RET

TEXT runtime·sleep(SB),7,$0
	MOVL    $17, AX
	INT     $64
	RET

TEXT runtime·plan9_semacquire(SB),7,$0
	MOVL	$37, AX
	INT	$64
	RET

TEXT runtime·plan9_tsemacquire(SB),7,$0
	MOVL	$52, AX
	INT	$64
	RET

TEXT runtime·notify(SB),7,$0
	MOVL	$28, AX
	INT	$64
	RET

TEXT runtime·noted(SB),7,$0
	MOVL	$29, AX
	INT	$64
	RET
	
TEXT runtime·plan9_semrelease(SB),7,$0
	MOVL	$38, AX
	INT	$64
	RET
	
TEXT runtime·rfork(SB),7,$0
	MOVL    $19, AX // rfork
	INT     $64

	// In parent, return.
	CMPL	AX, $0
	JEQ	2(PC)
	RET

	// In child on old stack.
	MOVL	mm+12(SP), BX	// m
	MOVL	gg+16(SP), DX	// g
	MOVL	fn+20(SP), SI	// fn

	// set SP to be on the new child stack
	MOVL	stack+8(SP), CX
	MOVL	CX, SP

	// Initialize m, g.
	get_tls(AX)
	MOVL	DX, g(AX)
	MOVL	BX, m(AX)

	// Initialize AX from TOS struct.
	MOVL	procid(AX), AX
	MOVL	AX, m_procid(BX)	// save pid as m->procid
	
	CALL	runtime·stackcheck(SB)	// smashes AX, CX
	
	MOVL	0(DX), DX	// paranoia; check they are not nil
	MOVL	0(BX), BX
	
	// more paranoia; check that stack splitting code works
	PUSHL	SI
	CALL	runtime·emptyfunc(SB)
	POPL	SI
	
	CALL	SI	// fn()
	CALL	runtime·exit(SB)
	RET

// void sigtramp(void *ureg, int8 *note)
TEXT runtime·sigtramp(SB),7,$0
	get_tls(AX)

	// check that m exists
	MOVL	m(AX), BX
	CMPL	BX, $0
	JNE	3(PC)
	CALL	runtime·badsignal(SB) // will exit
	RET

	// save args
	MOVL	ureg+4(SP), CX
	MOVL	note+8(SP), DX

	// change stack
	MOVL	m_gsignal(BX), BP
	MOVL	g_stackbase(BP), BP
	MOVL	BP, SP

	// make room for args and g
	SUBL	$16, SP

	// save g
	MOVL	g(AX), BP
	MOVL	BP, 12(SP)

	// g = m->gsignal
	MOVL	m_gsignal(BX), DI
	MOVL	DI, g(AX)

	// load args and call sighandler
	MOVL	CX, 0(SP)
	MOVL	DX, 4(SP)
	MOVL	BP, 8(SP)

	CALL	runtime·sighandler(SB)

	// restore g
	get_tls(BX)
	MOVL	12(SP), BP
	MOVL	BP, g(BX)

	// call noted(AX)
	MOVL	AX, 0(SP)
	CALL	runtime·noted(SB)
	RET

// Only used by the 64-bit runtime.
TEXT runtime·setfpmasks(SB),7,$0
	RET

#define ERRMAX 128	/* from os_plan9.h */

// func errstr() String
// Only used by package syscall.
// Grab error string due to a syscall made
// in entersyscall mode, without going
// through the allocator (issue 4994).
// See ../syscall/asm_plan9_386.s:/·Syscall/
TEXT runtime·errstr(SB),7,$0
	get_tls(AX)
	MOVL	m(AX), BX
	MOVL	m_errstr(BX), CX
	MOVL	CX, 4(SP)
	MOVL	$ERRMAX, 8(SP)
	MOVL	$41, AX
	INT	$64

	// syscall requires caller-save
	MOVL	4(SP), CX

	// push the argument
	PUSHL	CX
	CALL	runtime·findnull(SB)
	POPL	CX
	MOVL	AX, 8(SP)
	RET