summaryrefslogtreecommitdiff
path: root/mit-pthreads/machdep/syscall-alpha-netbsd-1.3.S
blob: 61435a729d75c9fe92d7a0131fc33c030e09507f (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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <machine/asm.h>
#define	CHMK()		call_pal 0x83
#define COMPAT_43
#include <sys/syscall.h>
#ifndef __CONCAT
#include <sys/cdefs.h>
#endif
#define	CONCAT		__CONCAT

#undef SYSCALL

/* Kernel syscall interface:
   Input:
	v0 - system call number
	a* - arguments, as in C
   Output:
	a3 - zero iff successful
	v0 - errno value on failure, else result

   This macro is similar to SYSCALL in asm.h, but not completely.
   There's room for optimization, if we assume this will continue to
   be assembled as one file.

   This macro expansions does not include the return instruction.
   If there's no other work to be done, use something like:
	SYSCALL(foo) ; ret
   If there is other work to do (in fork, maybe?), do it after the
   SYSCALL invocation.  */

#define SYSCALL(x) \
	.align	4					;\
	.globl	CONCAT(machdep_sys_,x)			;\
	.ent	CONCAT(machdep_sys_,x), 0		;\
CONCAT(machdep_sys_,x):					;\
	.frame	sp,0,ra					;\
	ldiq	v0, CONCAT(SYS_,x)			;\
	CHMK()						;\
	beq	a3, CONCAT(Lsys_noerr_,x)		;\
	br	gp, CONCAT(Lsys_err_,x)			;\
CONCAT(Lsys_err_,x):					;\
	/* Load gp so we can find cerror to jump to.  */;\
	ldgp	gp, 0(gp)				;\
	jmp	zero, machdep_cerror			;\
CONCAT(Lsys_noerr_,x):

#define XSYSCALL(x)	SYSCALL(x) ; RET ; .end CONCAT(machdep_sys_,x)

	.globl	machdep_cerror 
machdep_cerror:
	br	t0, Lmachdep_cerror_setgp
Lmachdep_cerror_setgp:
	ldgp	gp, 0(t0)
	stl	v0, errno
#if 0
	ldiq	v0, -1
#else
	subq	zero, v0, v0
#endif
	RET

/* The fork system call is special...  */
SYSCALL(fork)
	cmovne	a4, 0, v0
	RET
	.end	machdep_sys_fork

/* The pipe system call is special... */
SYSCALL(pipe)
	stl	v0, 0(a0)
	stl	a4, 4(a0)
	mov	zero, v0
	RET
	.end	machdep_sys_pipe

#ifndef SYS___sigsuspend14
/* The sigsuspend system call is special... */
	.align 4
	.globl machdep_sys_sigsuspend
	.ent machdep_sys_sigsuspend, 0
machdep_sys_sigsuspend:
	ldl	a0, 0(a0)		/* pass *mask instead of mask */
	ldiq	v0, SYS_sigsuspend
	CHMK()
	mov	zero, v0		/* shouldn't need; just in case... */
	RET
	.end 	machdep_sys_sigsuspend
#endif /* SYS_sigsuspend14 */

#ifndef SYS___sigprocmask14
/* The sigprocmask system call is special... */
	.align 4
	.globl machdep_sys_sigprocmask
	.ent machdep_sys_sigprocmask, 0
machdep_sys_sigprocmask:
	mov	a2, a5			/* safe */
	cmoveq	a1, 1, a0		/* if set == NULL, how = SIG_BLOCK */
	beq	a1, Ldoit		/* and set = 0, and do it. */
	ldl	a1, 0(a1)		/* load the set from *set */
Ldoit:	ldiq	v0, SYS_sigprocmask
	CHMK()
	beq	a5, Lret		/* if they don't want old mask, done */	
	stl	v0, 0(a5)		/* otherwise, give it to them. */
Lret:	mov	zero, v0
	RET
	.end	machdep_sys_sigprocmask
#endif /* SYS_sigprocmask14 */

/* More stuff ... */
	.align 4
	.global __machdep_save_int_state
	.ent __machdep_save_int_state, 0
__machdep_save_int_state:
	.frame	sp, 16, ra
	ldgp	gp, 0(t12)
	lda	sp, -16(sp)
	stq	ra, 0(sp)

	/* save integer registers */
	stq	ra, ( 0 * 8)(a0)		/* return address */
	stq	s0, ( 1 * 8)(a0)		/* callee-saved registers */
	stq	s1, ( 2 * 8)(a0)
	stq	s2, ( 3 * 8)(a0)
	stq	s3, ( 4 * 8)(a0)
	stq	s4, ( 5 * 8)(a0)
	stq	s5, ( 6 * 8)(a0)
	stq	s6, ( 7 * 8)(a0)
	stq	sp, ( 9 * 8)(a0)
	stq	ra, ( 8 * 8)(a0)		/* RA on return */
	stq	pv, (10 * 8)(a0)		/* and PV; we restore it */

	mov	zero, v0
	lda	sp, 16(sp)
	RET
	.end __machdep_save_int_state

	.align 4
	.global __machdep_restore_int_state
	.ent __machdep_restore_int_state, 0
__machdep_restore_int_state:
	.frame	sp, 16, ra
	ldgp	gp, 0(t12)
	lda	sp, -16(sp)
	stq	ra, 0(sp)

	/* restore integer registers */
	ldq	t0, ( 0 * 8)(a0)		/* return address */
	ldq	s0, ( 1 * 8)(a0)		/* callee-saved registers */
	ldq	s1, ( 2 * 8)(a0)
	ldq	s2, ( 3 * 8)(a0)
	ldq	s3, ( 4 * 8)(a0)
	ldq	s4, ( 5 * 8)(a0)
	ldq	s5, ( 6 * 8)(a0)
	ldq	s6, ( 7 * 8)(a0)
	ldq	ra, ( 8 * 8)(a0)		/* RA after return */
	ldq	sp, ( 9 * 8)(a0)
	ldq	pv, (10 * 8)(a0)		/* and PV; we restore it */

	ldiq    v0, 1
	ret     zero,(t0),1
	.end __machdep_restore_int_state

	.align 4
	.global __machdep_save_fp_state
	.ent __machdep_save_fp_state, 0
__machdep_save_fp_state:
	.frame	sp, 16, ra
	ldgp	gp, 0(t12)
	lda	sp, -16(sp)
	stq	ra, 0(sp)

	/* save FP registers */
	stt	fs0, (0 * 8)(a0)		/* callee-saved registers */
	stt	fs1, (1 * 8)(a0)
	stt	fs2, (2 * 8)(a0)
	stt	fs3, (3 * 8)(a0)
	stt	fs4, (4 * 8)(a0)
	stt	fs5, (5 * 8)(a0)
	stt	fs6, (6 * 8)(a0)
	stt	fs7, (7 * 8)(a0)
	mf_fpcr ft0 				/* and FP control reg */
	stt	ft0, (8 * 8)(a0)

	lda	sp, 16(sp)
	RET
	.end __machdep_save_fp_state

	.align 4
	.global __machdep_restore_fp_state
	.ent __machdep_restore_fp_state, 0
__machdep_restore_fp_state:
	.frame	sp, 16, ra
	ldgp	gp, 0(t12)
	lda	sp, -16(sp)
	stq	ra, 0(sp)

	/* restore FP registers */
	ldt	fs0, (0 * 8)(a0)		/* callee-saved registers */
	ldt	fs1, (1 * 8)(a0)
	ldt	fs2, (2 * 8)(a0)
	ldt	fs3, (3 * 8)(a0)
	ldt	fs4, (4 * 8)(a0)
	ldt	fs5, (5 * 8)(a0)
	ldt	fs6, (6 * 8)(a0)
	ldt	fs7, (7 * 8)(a0)
	ldt	ft0, (8 * 8)(a0)
	mt_fpcr ft0 				/* and FP control reg */

	lda	sp, 16(sp)
	RET
	.end __machdep_restore_fp_state

/* For fstat() we actually syscall fstat13. */
	.align	4
	.globl	machdep_sys_fstat
	.ent	machdep_sys_fstat, 0
machdep_sys_fstat:
	.frame	sp,0,ra
	ldiq	v0, SYS___fstat13
	CHMK()
	beq	a3, Lsys_noerr_fstat
	br	gp, Lsys_err_fstat
Lsys_err_fstat:
	/* Load gp so we can find cerror to jump to.  */
	ldgp	gp, 0(gp)
	jmp	zero, machdep_cerror
Lsys_noerr_fstat:
	RET
	.end machdep_sys_fstat