subr.S revision 1.33 1 1.33 matt /* $NetBSD: subr.S,v 1.33 2010/12/20 00:25:45 matt Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Redistribution and use in source and binary forms, with or without
8 1.1 matt * modification, are permitted provided that the following conditions
9 1.1 matt * are met:
10 1.1 matt * 1. Redistributions of source code must retain the above copyright
11 1.1 matt * notice, this list of conditions and the following disclaimer.
12 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer in the
14 1.1 matt * documentation and/or other materials provided with the distribution.
15 1.1 matt * 3. All advertising materials mentioning features or use of this software
16 1.1 matt * must display the following acknowledgement:
17 1.1 matt * This product includes software developed at Ludd, University of Lule}.
18 1.1 matt * 4. The name of the author may not be used to endorse or promote products
19 1.1 matt * derived from this software without specific prior written permission
20 1.1 matt *
21 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 matt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 matt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 matt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 matt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 matt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 matt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 matt */
32 1.1 matt
33 1.1 matt #include <machine/asm.h>
34 1.1 matt
35 1.1 matt #include "assym.h"
36 1.1 matt #include "opt_ddb.h"
37 1.1 matt #include "opt_multiprocessor.h"
38 1.1 matt #include "opt_lockdebug.h"
39 1.1 matt #include "opt_compat_netbsd.h"
40 1.1 matt #include "opt_compat_ibcs2.h"
41 1.1 matt #ifdef COMPAT_IBCS2
42 1.1 matt #include <compat/ibcs2/ibcs2_syscall.h>
43 1.1 matt #endif
44 1.1 matt #include "opt_compat_ultrix.h"
45 1.1 matt #ifdef COMPAT_ULTRIX
46 1.1 matt #include <compat/ultrix/ultrix_syscall.h>
47 1.1 matt #endif
48 1.1 matt
49 1.1 matt #define JSBENTRY(x) .globl x ; .align 2 ; x :
50 1.21 matt #define SCBENTRY(name) \
51 1.21 matt .text ; \
52 1.21 matt .align 2 ; \
53 1.21 matt .globl __CONCAT(X,name) ; \
54 1.21 matt __CONCAT(X,name):
55 1.1 matt
56 1.1 matt .text
57 1.1 matt
58 1.1 matt #ifdef KERNEL_LOADABLE_BY_MOP
59 1.1 matt /*
60 1.1 matt * This is a little tricky. The kernel is not loaded at the correct
61 1.1 matt * address, so the kernel must first be relocated, then copied, then
62 1.1 matt * jump back to the correct address.
63 1.1 matt */
64 1.1 matt /* Copy routine */
65 1.1 matt cps:
66 1.2 matt 2: movb (%r0)+,(%r1)+
67 1.2 matt cmpl %r0,%r7
68 1.1 matt bneq 2b
69 1.1 matt
70 1.2 matt 3: clrb (%r1)+
71 1.2 matt incl %r0
72 1.2 matt cmpl %r0,%r6
73 1.1 matt bneq 3b
74 1.2 matt clrl -(%sp)
75 1.2 matt movl %sp,%ap
76 1.2 matt movl $_cca,%r7
77 1.2 matt movl %r8,(%r7)
78 1.2 matt movpsl -(%sp)
79 1.2 matt pushl %r2
80 1.1 matt rei
81 1.1 matt cpe:
82 1.1 matt
83 1.1 matt /* Copy the copy routine */
84 1.2 matt 1: movab cps,%r0
85 1.2 matt movab cpe,%r1
86 1.2 matt movl $0x300000,%sp
87 1.2 matt movl %sp,%r3
88 1.2 matt 4: movb (%r0)+,(%r3)+
89 1.2 matt cmpl %r0,%r1
90 1.1 matt bneq 4b
91 1.2 matt movl %r7,%r8
92 1.1 matt /* Ok, copy routine copied, set registers and rei */
93 1.2 matt movab _edata,%r7
94 1.2 matt movab _end,%r6
95 1.2 matt movl $0x80000000,%r1
96 1.2 matt movl $0x80000200,%r0
97 1.2 matt subl3 $0x200,%r6,%r9
98 1.2 matt movab 2f,%r2
99 1.2 matt subl2 $0x200,%r2
100 1.2 matt movpsl -(%sp)
101 1.2 matt pushab 4(%sp)
102 1.1 matt rei
103 1.1 matt
104 1.1 matt /*
105 1.1 matt * First entry routine from boot. This should be in a file called locore.
106 1.1 matt */
107 1.1 matt JSBENTRY(start)
108 1.1 matt brb 1b # Netbooted starts here
109 1.1 matt #else
110 1.1 matt ASENTRY(start, 0)
111 1.1 matt #endif
112 1.2 matt 2: bisl3 $0x80000000,%r9,_C_LABEL(esym) # End of loaded code
113 1.1 matt pushl $0x1f0000 # Push a nice PSL
114 1.1 matt pushl $to # Address to jump to
115 1.1 matt rei # change to kernel stack
116 1.1 matt to: movw $0xfff,_C_LABEL(panic) # Save all regs in panic
117 1.3 matt cmpb (%ap),$3 # symbols info present?
118 1.1 matt blssu 3f # nope, skip
119 1.2 matt bisl3 $0x80000000,8(%ap),_C_LABEL(symtab_start)
120 1.1 matt # save start of symtab
121 1.2 matt movl 12(%ap),_C_LABEL(symtab_nsyms) # save number of symtab
122 1.3 matt bisl3 $0x80000000,%r9,_C_LABEL(symtab_end)
123 1.2 matt # save end of symtab
124 1.2 matt 3: addl3 _C_LABEL(esym),$0x3ff,%r0 # Round symbol table end
125 1.27 matt bicl3 $0x3ff,%r0,%r1 #
126 1.28 rmind movl %r1,_C_LABEL(lwp0)+L_PCB # lwp0 pcb, XXXuvm_lwp_getuarea
127 1.29 martin bicl3 $0x80000000,%r1,%r0 # get phys lwp0 uarea addr
128 1.2 matt mtpr %r0,$PR_PCBB # Save in IPR PCBB
129 1.27 matt addl3 $USPACE,%r1,%r0 # Get kernel stack top
130 1.2 matt mtpr %r0,$PR_KSP # put in IPR KSP
131 1.2 matt movl %r0,_C_LABEL(Sysmap) # SPT start addr after KSP
132 1.28 rmind movl _C_LABEL(lwp0)+L_PCB,%r0 # get PCB virtual address
133 1.21 matt mfpr $PR_PCBB,PCB_PADDR(%r0) # save PCB physical address
134 1.30 chs movab PCB_ONFAULT(%r0),ESP(%r0) # Save trap address in ESP
135 1.2 matt mtpr 4(%r0),$PR_ESP # Put it in ESP also
136 1.1 matt
137 1.1 matt # Set some registers in known state
138 1.28 rmind movl %r1,%r0 # get lwp0 pcb
139 1.2 matt clrl P0LR(%r0)
140 1.2 matt clrl P1LR(%r0)
141 1.1 matt mtpr $0,$PR_P0LR
142 1.1 matt mtpr $0,$PR_P1LR
143 1.2 matt movl $0x80000000,%r1
144 1.2 matt movl %r1,P0BR(%r0)
145 1.2 matt movl %r1,P1BR(%r0)
146 1.2 matt mtpr %r1,$PR_P0BR
147 1.2 matt mtpr %r1,$PR_P1BR
148 1.30 chs clrl PCB_ONFAULT(%r0)
149 1.1 matt mtpr $0,$PR_SCBB
150 1.1 matt
151 1.1 matt # Copy the RPB to its new position
152 1.1 matt #if defined(COMPAT_14)
153 1.2 matt tstl (%ap) # Any arguments?
154 1.1 matt bneq 1f # Yes, called from new boot
155 1.2 matt movl %r11,_C_LABEL(boothowto) # Howto boot (single etc...)
156 1.2 matt # movl %r10,_C_LABEL(bootdev) # uninteresting, will complain
157 1.2 matt movl %r8,_C_LABEL(avail_end) # Usable memory (from VMB)
158 1.2 matt clrl -(%sp) # Have no RPB
159 1.1 matt brb 2f
160 1.1 matt #endif
161 1.1 matt
162 1.2 matt 1: pushl 4(%ap) # Address of old rpb
163 1.1 matt 2: calls $1,_C_LABEL(_start) # Jump away.
164 1.1 matt /* NOTREACHED */
165 1.1 matt
166 1.1 matt
167 1.1 matt /*
168 1.1 matt * Signal handler code.
169 1.1 matt */
170 1.1 matt
171 1.1 matt .align 2
172 1.11 matt .globl _C_LABEL(sigcode),_C_LABEL(esigcode)
173 1.1 matt _C_LABEL(sigcode):
174 1.1 matt pushr $0x3f
175 1.2 matt subl2 $0xc,%sp
176 1.2 matt movl 0x24(%sp),%r0
177 1.2 matt calls $3,(%r0)
178 1.1 matt popr $0x3f
179 1.8 matt chmk $SYS_compat_16___sigreturn14
180 1.1 matt chmk $SYS_exit
181 1.1 matt halt
182 1.1 matt _C_LABEL(esigcode):
183 1.1 matt
184 1.1 matt #ifdef COMPAT_IBCS2
185 1.1 matt .align 2
186 1.1 matt .globl _C_LABEL(ibcs2_sigcode),_C_LABEL(ibcs2_esigcode)
187 1.1 matt _C_LABEL(ibcs2_sigcode):
188 1.1 matt pushr $0x3f
189 1.2 matt subl2 $0xc,%sp
190 1.2 matt movl 0x24(%sp),%r0
191 1.2 matt calls $3,(%r0)
192 1.1 matt popr $0x3f
193 1.8 matt chmk $SYS_compat_16___sigreturn14
194 1.1 matt chmk $SYS_exit
195 1.1 matt halt
196 1.1 matt _C_LABEL(ibcs2_esigcode):
197 1.1 matt #endif /* COMPAT_IBCS2 */
198 1.1 matt
199 1.1 matt #ifdef COMPAT_ULTRIX
200 1.1 matt .align 2
201 1.1 matt .globl _C_LABEL(ultrix_sigcode),_C_LABEL(ultrix_esigcode)
202 1.1 matt _C_LABEL(ultrix_sigcode):
203 1.1 matt pushr $0x3f
204 1.2 matt subl2 $0xc,%sp
205 1.2 matt movl 0x24(%sp),%r0
206 1.2 matt calls $3,(%r0)
207 1.1 matt popr $0x3f
208 1.1 matt chmk $ULTRIX_SYS_sigreturn
209 1.1 matt chmk $SYS_exit
210 1.1 matt halt
211 1.1 matt _C_LABEL(ultrix_esigcode):
212 1.1 matt #endif
213 1.1 matt
214 1.1 matt .align 2
215 1.1 matt .globl _C_LABEL(idsptch), _C_LABEL(eidsptch)
216 1.16 matt _C_LABEL(idsptch):
217 1.16 matt pushr $0x3f
218 1.1 matt .word 0x9f16 # jsb to absolute address
219 1.1 matt .long _C_LABEL(cmn_idsptch) # the absolute address
220 1.1 matt .long 0 # the callback interrupt routine
221 1.1 matt .long 0 # its argument
222 1.1 matt .long 0 # ptr to correspond evcnt struct
223 1.1 matt _C_LABEL(eidsptch):
224 1.1 matt
225 1.1 matt _C_LABEL(cmn_idsptch):
226 1.16 matt #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
227 1.16 matt calls $0,_C_LABEL(krnlock)
228 1.16 matt #endif
229 1.2 matt movl (%sp)+,%r0 # get pointer to idspvec
230 1.20 matt mtpr $IPL_VM,$PR_IPL # Make sure we are at IPL_VM
231 1.2 matt movl 8(%r0),%r1 # get evcnt pointer
232 1.1 matt beql 1f # no ptr, skip increment
233 1.2 matt incl EV_COUNT(%r1) # increment low longword
234 1.2 matt adwc $0,EV_COUNT+4(%r1) # add any carry to hi longword
235 1.33 matt 1: mfpr $PR_SSP, %r2 # get curlwp
236 1.33 matt movl L_CPU(%r2), %r2 # get curcpu
237 1.33 matt incl CI_NINTR(%r2) # increment ci_data.cpu_nintr
238 1.33 matt adwc $0,(CI_NINTR+4)(%r2)
239 1.16 matt #if 0
240 1.16 matt pushl %r0
241 1.16 matt movq (%r0),-(%sp)
242 1.16 matt pushab 2f
243 1.16 matt calls $3,_C_LABEL(printf)
244 1.16 matt movl (%sp)+,%r0
245 1.16 matt #endif
246 1.6 ragge pushl 4(%r0) # push argument
247 1.2 matt calls $1,*(%r0) # call interrupt routine
248 1.16 matt #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
249 1.16 matt calls $0,_C_LABEL(krnunlock)
250 1.16 matt #endif
251 1.1 matt popr $0x3f # pop registers
252 1.1 matt rei # return from interrut
253 1.16 matt #if 0
254 1.16 matt 2: .asciz "intr %p(%p)\n"
255 1.16 matt #endif
256 1.1 matt
257 1.1 matt ENTRY(badaddr,0) # Called with addr,b/w/l
258 1.2 matt mfpr $PR_IPL,%r0 # splhigh()
259 1.1 matt mtpr $IPL_HIGH,$PR_IPL
260 1.2 matt movl 4(%ap),%r2 # First argument, the address
261 1.2 matt movl 8(%ap),%r1 # Sec arg, b,w,l
262 1.2 matt pushl %r0 # Save old IPL
263 1.2 matt clrl %r3
264 1.1 matt movab 4f,_C_LABEL(memtest) # Set the return address
265 1.1 matt
266 1.2 matt caseb %r1,$1,$4 # What is the size
267 1.1 matt 1: .word 1f-1b
268 1.1 matt .word 2f-1b
269 1.1 matt .word 3f-1b # This is unused
270 1.1 matt .word 3f-1b
271 1.1 matt
272 1.2 matt 1: movb (%r2),%r1 # Test a byte
273 1.1 matt brb 5f
274 1.1 matt
275 1.2 matt 2: movw (%r2),%r1 # Test a word
276 1.1 matt brb 5f
277 1.1 matt
278 1.2 matt 3: movl (%r2),%r1 # Test a long
279 1.1 matt brb 5f
280 1.1 matt
281 1.2 matt 4: incl %r3 # Got machine chk => addr bad
282 1.2 matt 5: mtpr (%sp)+,$PR_IPL
283 1.2 matt movl %r3,%r0
284 1.1 matt ret
285 1.1 matt
286 1.1 matt #ifdef DDB
287 1.1 matt /*
288 1.1 matt * DDB is the only routine that uses setjmp/longjmp.
289 1.1 matt */
290 1.1 matt .globl _C_LABEL(setjmp), _C_LABEL(longjmp)
291 1.1 matt _C_LABEL(setjmp):.word 0
292 1.2 matt movl 4(%ap), %r0
293 1.2 matt movl 8(%fp), (%r0)
294 1.2 matt movl 12(%fp), 4(%r0)
295 1.2 matt movl 16(%fp), 8(%r0)
296 1.2 matt moval 28(%fp),12(%r0)
297 1.2 matt clrl %r0
298 1.1 matt ret
299 1.1 matt
300 1.1 matt _C_LABEL(longjmp):.word 0
301 1.2 matt movl 4(%ap), %r1
302 1.2 matt movl 8(%ap), %r0
303 1.2 matt movl (%r1), %ap
304 1.2 matt movl 4(%r1), %fp
305 1.2 matt movl 12(%r1), %sp
306 1.2 matt jmp *8(%r1)
307 1.1 matt #endif
308 1.1 matt
309 1.1 matt #if defined(MULTIPROCESSOR)
310 1.1 matt .align 2
311 1.12 he .globl _C_LABEL(vax_mp_tramp) # used to kick off multiprocessor systems.
312 1.12 he _C_LABEL(vax_mp_tramp):
313 1.1 matt ldpctx
314 1.1 matt rei
315 1.1 matt #endif
316 1.5 thorpej
317 1.22 matt .globl softint_cleanup,softint_exit,softint_process
318 1.22 matt .type softint_cleanup@function
319 1.22 matt .type softint_exit@function
320 1.22 matt .type softint_process@function
321 1.21 matt softint_cleanup:
322 1.24 matt movl L_CPU(%r0),%r1 /* get cpu_info */
323 1.21 matt incl CI_MTX_COUNT(%r1) /* increment mutex count */
324 1.21 matt clrl L_CTXSWTCH(%r0) /* clear l_ctxswtch of old lwp */
325 1.28 rmind movl L_PCB(%r0),%r1 /* get PCB of softint LWP */
326 1.21 matt softint_exit:
327 1.21 matt popr $0x3 /* restore r0 and r1 */
328 1.21 matt rei /* return from interrupt */
329 1.21 matt
330 1.21 matt softint_process:
331 1.21 matt /*
332 1.21 matt * R6 contains pinned LWP
333 1.21 matt * R7 contains ipl to dispatch with
334 1.21 matt */
335 1.21 matt movq %r6,-(%sp) /* push old lwp and ipl onto stack */
336 1.21 matt calls $2,_C_LABEL(softint_dispatch) /* dispatch it */
337 1.21 matt
338 1.21 matt /* We can use any register because ldpctx will overwrite them */
339 1.28 rmind movl L_PCB(%r6),%r3 /* get pcb */
340 1.21 matt movab softint_exit,PCB_PC(%r3)/* do a quick exit */
341 1.24 matt #ifdef MULTIPROCESSOR
342 1.24 matt movl L_CPU(%r6),%r8
343 1.24 matt movl %r6,CI_CURLWP(%r8)
344 1.24 matt #endif
345 1.21 matt
346 1.21 matt mtpr PCB_PADDR(%r3),$PR_PCBB /* restore PA of interrupted pcb */
347 1.24 matt ldpctx /* implictily updates curlwp */
348 1.21 matt rei
349 1.21 matt
350 1.21 matt
351 1.21 matt softint_common:
352 1.21 matt mfpr $PR_IPL,%r1
353 1.21 matt mtpr $IPL_HIGH,$PR_IPL /* we need to be at IPL_HIGH */
354 1.21 matt movpsl -(%sp) /* add cleanup hook */
355 1.21 matt pushab softint_cleanup
356 1.21 matt svpctx
357 1.21 matt
358 1.21 matt /* We can use any register because ldpctx will overwrite them */
359 1.24 matt mfpr $PR_SSP,%r6 /* Get curlwp */
360 1.24 matt movl L_CPU(%r6),%r8 /* get cpu_info */
361 1.21 matt movl CI_SOFTLWPS(%r8)[%r0],%r2 /* get softlwp to switch to */
362 1.28 rmind movl L_PCB(%r2),%r3 /* Get pointer to its pcb. */
363 1.24 matt movl %r6,PCB_R6(%r3) /* move old lwp into new pcb */
364 1.21 matt movl %r1,PCB_R7(%r3) /* move IPL into new pcb */
365 1.24 matt #ifdef MULTIPROCESSOR
366 1.21 matt movl %r2,CI_CURLWP(%r8) /* update ci_curlwp */
367 1.24 matt #endif
368 1.23 matt
369 1.23 matt /*
370 1.23 matt * Now reset the PCB since we no idea what state it was last in
371 1.23 matt */
372 1.23 matt movab (USPACE-TRAPFRAMELEN-CALLSFRAMELEN)(%r3),%r0
373 1.23 matt /* calculate where KSP should be */
374 1.23 matt movl %r0,KSP(%r3) /* save it as SP */
375 1.23 matt movl %r0,PCB_FP(%r3) /* and as the FP too */
376 1.23 matt movab CA_ARGNO(%r0),PCB_AP(%r3) /* update the AP as well */
377 1.23 matt movab softint_process,PCB_PC(%r3) /* and where we will start */
378 1.32 snj movl $PSL_HIGHIPL,PCB_PSL(%r3) /* Needs to be running at IPL_HIGH */
379 1.23 matt
380 1.21 matt mtpr PCB_PADDR(%r3),$PR_PCBB /* set PA of new pcb */
381 1.21 matt ldpctx /* load it */
382 1.21 matt rei /* get off interrupt stack */
383 1.21 matt
384 1.21 matt SCBENTRY(softclock)
385 1.21 matt pushr $0x3 /* save r0 and r1 */
386 1.21 matt movl $SOFTINT_CLOCK,%r0
387 1.21 matt brb softint_common
388 1.21 matt
389 1.21 matt SCBENTRY(softbio)
390 1.21 matt pushr $0x3 /* save r0 and r1 */
391 1.21 matt movl $SOFTINT_BIO,%r0
392 1.21 matt brb softint_common
393 1.21 matt
394 1.21 matt SCBENTRY(softnet)
395 1.21 matt pushr $0x3 /* save r0 and r1 */
396 1.21 matt movl $SOFTINT_NET,%r0
397 1.21 matt brb softint_common
398 1.21 matt
399 1.21 matt SCBENTRY(softserial)
400 1.21 matt pushr $0x3 /* save r0 and r1 */
401 1.21 matt movl $SOFTINT_SERIAL,%r0
402 1.21 matt brb softint_common
403 1.21 matt
404 1.17 yamt /*
405 1.17 yamt * Helper routine for cpu_lwp_fork. It get invoked by Swtchto.
406 1.17 yamt * It let's the kernel know the lwp is alive and then calls func(arg)
407 1.17 yamt * and possibly returns to sret.
408 1.17 yamt */
409 1.17 yamt ENTRY(cpu_lwp_bootstrap, 0)
410 1.17 yamt movq %r2,-(%sp) /* save func & arg */
411 1.17 yamt movq %r0,-(%sp) /* push oldl/newl */
412 1.17 yamt calls $2,_C_LABEL(lwp_startup) /* startup the lwp */
413 1.17 yamt movl (%sp)+,%r0 /* grab func */
414 1.17 yamt calls $1,(%r0) /* call it with arg */
415 1.17 yamt ret
416 1.17 yamt
417 1.17 yamt /*
418 1.17 yamt * r1 = newlwp
419 1.17 yamt * r0 = oldlwp
420 1.17 yamt */
421 1.5 thorpej JSBENTRY(Swtchto)
422 1.17 yamt /* this pops the pc and psw from the stack and puts them in the pcb. */
423 1.5 thorpej svpctx # Now on interrupt stack
424 1.5 thorpej
425 1.17 yamt /* We can know use any register because ldpctx will overwrite them */
426 1.17 yamt /* New LWP already in %r1 */
427 1.28 rmind movl L_PCB(%r1),%r3 # Get pointer to new pcb.
428 1.17 yamt movl %r0,PCB_R0(%r3) # move r0 into new pcb (return value)
429 1.21 matt #ifdef MULTIPROCESSOR
430 1.24 matt movl L_CPU(%r0), %r8 /* get cpu_info of old lwp */
431 1.24 matt movl %r8, L_CPU(%r1) /* update cpu_info of new lwp */
432 1.24 matt movl %r1,CI_CURLWP(%r8) /* update ci_curlwp */
433 1.21 matt #endif
434 1.17 yamt
435 1.21 matt mtpr PCB_PADDR(%r3),$PR_PCBB # set PA of new pcb
436 1.21 matt mtpr $IPL_HIGH,$PR_IPL /* we need to be at IPL_HIGH */
437 1.17 yamt ldpctx # load it
438 1.17 yamt /* r0 already has previous lwp */
439 1.17 yamt /* r1 already has this lwp */
440 1.17 yamt /* r2/r3 and r4/r5 restored */
441 1.17 yamt rei /* get off interrupt stack */
442 1.1 matt
443 1.1 matt #
444 1.1 matt # copy/fetch/store routines.
445 1.1 matt #
446 1.1 matt
447 1.1 matt ENTRY(copyout, 0)
448 1.26 tsutsui movl 8(%ap),%r3
449 1.1 matt blss 3f # kernel space
450 1.2 matt movl 4(%ap),%r1
451 1.1 matt brb 2f
452 1.1 matt
453 1.1 matt ENTRY(copyin, 0)
454 1.2 matt movl 4(%ap),%r1
455 1.1 matt blss 3f # kernel space
456 1.26 tsutsui movl 8(%ap),%r3
457 1.26 tsutsui 2: mfpr $PR_ESP,%r2
458 1.30 chs movab 1f,(%r2) # set pcb_onfault
459 1.26 tsutsui 4: tstw 14(%ap) # check if >= 64K
460 1.26 tsutsui bneq 5f
461 1.26 tsutsui movc3 12(%ap),(%r1),(%r3)
462 1.30 chs clrl %r0
463 1.26 tsutsui 1: mfpr $PR_ESP,%r2
464 1.30 chs clrl (%r2) # clear pcb_onfault
465 1.1 matt ret
466 1.26 tsutsui 5: movc3 $0xfffc,(%r1),(%r3)
467 1.26 tsutsui subl2 $0xfffc,12(%ap)
468 1.26 tsutsui brb 4b
469 1.1 matt
470 1.30 chs 3: movl $EFAULT,%r0
471 1.1 matt ret
472 1.1 matt
473 1.1 matt ENTRY(kcopy,0)
474 1.2 matt mfpr $PR_ESP,%r3
475 1.30 chs movl (%r3),-(%sp) # save current pcb_onfault
476 1.30 chs movab 1f,(%r3) # set pcb_onfault
477 1.2 matt movl 4(%ap),%r1
478 1.2 matt movl 8(%ap),%r2
479 1.2 matt movc3 12(%ap),(%r1), (%r2)
480 1.30 chs clrl %r0
481 1.2 matt 1: mfpr $PR_ESP,%r3
482 1.30 chs movl (%sp)+,(%r3) # restore pcb_onfault
483 1.1 matt ret
484 1.1 matt
485 1.1 matt /*
486 1.1 matt * copy{in,out}str() copies data from/to user space to/from kernel space.
487 1.1 matt * Security checks:
488 1.1 matt * 1) user space address must be < KERNBASE
489 1.1 matt * 2) the VM system will do the checks while copying
490 1.1 matt */
491 1.1 matt ENTRY(copyinstr, 0)
492 1.2 matt tstl 4(%ap) # kernel address?
493 1.1 matt bgeq 8f # no, continue
494 1.2 matt 6: movl $EFAULT,%r0
495 1.2 matt movl 16(%ap),%r2
496 1.1 matt beql 7f
497 1.2 matt clrl (%r2)
498 1.1 matt 7: ret
499 1.1 matt
500 1.1 matt ENTRY(copyoutstr, 0)
501 1.2 matt tstl 8(%ap) # kernel address?
502 1.1 matt bgeq 8f # no, continue
503 1.1 matt brb 6b # yes, return EFAULT
504 1.1 matt
505 1.1 matt ENTRY(copystr,0)
506 1.2 matt 8: movl 4(%ap),%r5 # from
507 1.2 matt movl 8(%ap),%r4 # to
508 1.2 matt movl 12(%ap),%r3 # len
509 1.2 matt movl 16(%ap),%r2 # copied
510 1.2 matt clrl %r0
511 1.2 matt mfpr $PR_ESP,%r1
512 1.30 chs movab 2f,(%r1) # set pcb_onfault
513 1.1 matt
514 1.2 matt tstl %r3 # any chars to copy?
515 1.1 matt bneq 1f # yes, jump for more
516 1.2 matt 0: tstl %r2 # save copied len?
517 1.1 matt beql 2f # no
518 1.2 matt subl3 4(%ap),%r5,(%r2) # save copied len
519 1.30 chs 2: mfpr $PR_ESP,%r1
520 1.30 chs clrl (%r1) # clear pcb_onfault
521 1.30 chs ret
522 1.1 matt
523 1.2 matt 1: movb (%r5)+,(%r4)+ # copy one char
524 1.1 matt beql 0b # jmp if last char
525 1.2 matt sobgtr %r3,1b # copy one more
526 1.2 matt movl $ENAMETOOLONG,%r0 # inform about too long string
527 1.1 matt brb 0b # out of chars
528 1.1 matt
529 1.1 matt ENTRY(subyte,0)
530 1.2 matt movl 4(%ap),%r0
531 1.1 matt blss 3f # illegal space
532 1.2 matt mfpr $PR_ESP,%r1
533 1.30 chs movab 1f,(%r1) # set pcb_onfault
534 1.2 matt movb 8(%ap),(%r0)
535 1.30 chs clrl %r0
536 1.30 chs 1: mfpr $PR_ESP,%r1
537 1.30 chs clrl (%r1) # clear pcb_onfault
538 1.1 matt ret
539 1.1 matt
540 1.1 matt ENTRY(suword,0)
541 1.2 matt movl 4(%ap),%r0
542 1.1 matt blss 3f # illegal space
543 1.2 matt mfpr $PR_ESP,%r1
544 1.30 chs movab 3f,(%r1) # set pcb_onfault
545 1.2 matt movl 8(%ap),(%r0)
546 1.30 chs clrl %r0
547 1.30 chs 1: mfpr $PR_ESP,%r1
548 1.30 chs clrl (%r1) # clear pcb_onfault
549 1.1 matt ret
550 1.1 matt
551 1.1 matt ENTRY(suswintr,0)
552 1.2 matt movl 4(%ap),%r0
553 1.1 matt blss 3f # illegal space
554 1.2 matt mfpr $PR_ESP,%r1
555 1.30 chs movab 3f,(%r1) # set pcb_onfault
556 1.2 matt movw 8(%ap),(%r0)
557 1.30 chs clrl %r0
558 1.30 chs 1: mfpr $PR_ESP,%r1
559 1.30 chs clrl (%r1) # clear pcb_onfault
560 1.1 matt ret
561 1.1 matt
562 1.2 matt 3: mnegl $1,%r0
563 1.30 chs brb 1b
564 1.1 matt
565 1.1 matt .align 2
566 1.1 matt ALTENTRY(fusword)
567 1.1 matt ENTRY(fuswintr,0)
568 1.30 chs movl 4(%ap),%r2
569 1.1 matt blss 3b
570 1.2 matt mfpr $PR_ESP,%r1
571 1.30 chs movab 3b,(%r1) # set pcb_onfault
572 1.30 chs movzwl (%r2),%r0
573 1.30 chs 1: mfpr $PR_ESP,%r1
574 1.30 chs clrl (%r1) # clear pcb_onfault
575 1.1 matt ret
576 1.1 matt
577 1.1 matt JSBENTRY(Slock)
578 1.2 matt 1: bbssi $0,(%r1),1b
579 1.1 matt rsb
580 1.1 matt
581 1.1 matt JSBENTRY(Slocktry)
582 1.2 matt clrl %r0
583 1.2 matt bbssi $0,(%r1),1f
584 1.2 matt incl %r0
585 1.1 matt 1: rsb
586 1.1 matt
587 1.1 matt JSBENTRY(Sunlock)
588 1.2 matt bbcci $0,(%r1),1f
589 1.1 matt 1: rsb
590 1.1 matt
591 1.1 matt #
592 1.1 matt # data department
593 1.1 matt #
594 1.1 matt .data
595 1.1 matt
596 1.1 matt .globl _C_LABEL(memtest)
597 1.1 matt _C_LABEL(memtest): # memory test in progress
598 1.1 matt .long 0
599