Annotation of src/sys/arch/sparc/sparc/locore.s, Revision 1.158
1.158 ! thorpej 1: /* $NetBSD: locore.s,v 1.157 2002/06/11 11:37:01 uwe Exp $ */
1.70 mrg 2:
1.1 deraadt 3: /*
1.52 pk 4: * Copyright (c) 1996 Paul Kranenburg
5: * Copyright (c) 1996
1.55 abrown 6: * The President and Fellows of Harvard College. All rights reserved.
1.1 deraadt 7: * Copyright (c) 1992, 1993
8: * The Regents of the University of California. All rights reserved.
9: *
10: * This software was developed by the Computer Systems Engineering group
11: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
12: * contributed to Berkeley.
13: *
14: * All advertising materials mentioning features or use of this software
15: * must display the following acknowledgement:
16: * This product includes software developed by the University of
17: * California, Lawrence Berkeley Laboratory.
1.52 pk 18: * This product includes software developed by Harvard University.
1.1 deraadt 19: *
20: * Redistribution and use in source and binary forms, with or without
21: * modification, are permitted provided that the following conditions
22: * are met:
23: * 1. Redistributions of source code must retain the above copyright
24: * notice, this list of conditions and the following disclaimer.
25: * 2. Redistributions in binary form must reproduce the above copyright
26: * notice, this list of conditions and the following disclaimer in the
27: * documentation and/or other materials provided with the distribution.
28: * 3. All advertising materials mentioning features or use of this software
29: * must display the following acknowledgement:
30: * This product includes software developed by the University of
31: * California, Berkeley and its contributors.
1.52 pk 32: * This product includes software developed by Harvard University.
33: * This product includes software developed by Paul Kranenburg.
1.1 deraadt 34: * 4. Neither the name of the University nor the names of its contributors
35: * may be used to endorse or promote products derived from this software
36: * without specific prior written permission.
37: *
38: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
39: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
42: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48: * SUCH DAMAGE.
49: *
1.10 deraadt 50: * @(#)locore.s 8.4 (Berkeley) 12/10/93
1.1 deraadt 51: */
52:
1.85 jonathan 53: #include "opt_ddb.h"
1.140 pk 54: #include "opt_kgdb.h"
1.84 thorpej 55: #include "opt_compat_svr4.h"
1.116 christos 56: #include "opt_compat_sunos.h"
1.97 pk 57: #include "opt_multiprocessor.h"
1.134 pk 58: #include "opt_lockdebug.h"
1.80 mrg 59:
1.47 mycroft 60: #include "assym.h"
1.52 pk 61: #include <machine/param.h>
1.111 pk 62: #include <machine/asm.h>
1.1 deraadt 63: #include <sparc/sparc/intreg.h>
64: #include <sparc/sparc/timerreg.h>
1.52 pk 65: #include <sparc/sparc/vaddrs.h>
1.1 deraadt 66: #ifdef notyet
67: #include <sparc/dev/zsreg.h>
68: #endif
69: #include <machine/ctlreg.h>
70: #include <machine/psl.h>
71: #include <machine/signal.h>
72: #include <machine/trap.h>
1.92 pk 73: #include <sys/syscall.h>
1.1 deraadt 74:
75: /*
76: * GNU assembler does not understand `.empty' directive; Sun assembler
77: * gripes about labels without it. To allow cross-compilation using
78: * the Sun assembler, and because .empty directives are useful documentation,
79: * we use this trick.
80: */
81: #ifdef SUN_AS
82: #define EMPTY .empty
83: #else
84: #define EMPTY /* .empty */
85: #endif
86:
87: /* use as needed to align things on longword boundaries */
1.52 pk 88: #define _ALIGN .align 4
1.1 deraadt 89:
90: /*
91: * CCFSZ (C Compiler Frame SiZe) is the size of a stack frame required if
92: * a function is to call C code. It should be just 64, but Sun defined
93: * their frame with space to hold arguments 0 through 5 (plus some junk),
1.63 pk 94: * and varargs routines (such as printf) demand this, and gcc uses this
1.1 deraadt 95: * area at times anyway.
96: */
97: #define CCFSZ 96
98:
99: /*
100: * A handy macro for maintaining instrumentation counters.
101: * Note that this clobbers %o0 and %o1. Normal usage is
102: * something like:
103: * foointr:
104: * TRAP_SETUP(...) ! makes %o registers safe
1.111 pk 105: * INCR(cnt+V_FOO) ! count a foo
1.1 deraadt 106: */
107: #define INCR(what) \
108: sethi %hi(what), %o0; \
109: ld [%o0 + %lo(what)], %o1; \
110: inc %o1; \
111: st %o1, [%o0 + %lo(what)]
112:
113: /*
114: * Another handy macro: load one register window, given `base' address.
115: * This can be either a simple register (e.g., %sp) or include an initial
116: * offset (e.g., %g6 + PCB_RW).
117: */
118: #define LOADWIN(addr) \
119: ldd [addr], %l0; \
120: ldd [addr + 8], %l2; \
121: ldd [addr + 16], %l4; \
122: ldd [addr + 24], %l6; \
123: ldd [addr + 32], %i0; \
124: ldd [addr + 40], %i2; \
125: ldd [addr + 48], %i4; \
126: ldd [addr + 56], %i6
127:
128: /*
129: * To return from trap we need the two-instruction sequence
130: * `jmp %l1; rett %l2', which is defined here for convenience.
131: */
132: #define RETT jmp %l1; rett %l2
133:
134: .data
135: /*
136: * The interrupt stack.
137: *
138: * This is the very first thing in the data segment, and therefore has
139: * the lowest kernel stack address. We count on this in the interrupt
140: * trap-frame setup code, since we may need to switch from the kernel
141: * stack to the interrupt stack (iff we are not already on the interrupt
142: * stack). One sethi+cmp is all we need since this is so carefully
143: * arranged.
1.98 pk 144: *
145: * In SMP kernels, each CPU has its own interrupt stack and the computation
146: * to determine whether we're already on the interrupt stack is slightly
147: * more time consuming (see INTR_SETUP() below).
1.1 deraadt 148: */
1.111 pk 149: .globl _C_LABEL(intstack)
150: .globl _C_LABEL(eintstack)
151: _C_LABEL(intstack):
1.98 pk 152: .skip INT_STACK_SIZE ! 16k = 128 128-byte stack frames
1.111 pk 153: _C_LABEL(eintstack):
1.1 deraadt 154:
1.101 pk 155: _EINTSTACKP = CPUINFO_VA + CPUINFO_EINTSTACK
156:
1.1 deraadt 157: /*
1.131 thorpej 158: * CPUINFO_VA is a CPU-local virtual address; cpi->ci_self is a global
159: * virtual address for the same structure. It must be stored in p->p_cpu
160: * upon context switch.
161: */
162: _CISELFP = CPUINFO_VA + CPUINFO_SELF
1.142 mrg 163: _CIFLAGS = CPUINFO_VA + CPUINFO_FLAGS
1.131 thorpej 164:
165: /*
1.1 deraadt 166: * When a process exits and its u. area goes away, we set cpcb to point
167: * to this `u.', leaving us with something to use for an interrupt stack,
168: * and letting all the register save code have a pcb_uw to examine.
169: * This is also carefully arranged (to come just before u0, so that
170: * process 0's kernel stack can quietly overrun into it during bootup, if
171: * we feel like doing that).
172: */
1.111 pk 173: .globl _C_LABEL(idle_u)
174: _C_LABEL(idle_u):
1.13 deraadt 175: .skip USPACE
1.99 pk 176: /*
177: * On SMP kernels, there's an idle u-area for each CPU and we must
178: * read its location from cpuinfo.
179: */
1.111 pk 180: IDLE_UP = CPUINFO_VA + CPUINFO_IDLE_U
1.1 deraadt 181:
182: /*
183: * Process 0's u.
184: *
185: * This must be aligned on an 8 byte boundary.
186: */
1.111 pk 187: .globl _C_LABEL(u0)
188: _C_LABEL(u0): .skip USPACE
1.1 deraadt 189: estack0:
190:
191: #ifdef KGDB
192: /*
193: * Another item that must be aligned, easiest to put it here.
194: */
195: KGDB_STACK_SIZE = 2048
1.111 pk 196: .globl _C_LABEL(kgdb_stack)
197: _C_LABEL(kgdb_stack):
1.1 deraadt 198: .skip KGDB_STACK_SIZE ! hope this is enough
199: #endif
200:
201: /*
1.111 pk 202: * cpcb points to the current pcb (and hence u. area).
1.1 deraadt 203: * Initially this is the special one.
204: */
1.111 pk 205: cpcb = CPUINFO_VA + CPUINFO_CURPCB
1.1 deraadt 206:
1.111 pk 207: /* curproc points to the current process that has the CPU */
208: curproc = CPUINFO_VA + CPUINFO_CURPROC
1.104 pk 209:
1.52 pk 210: /*
1.111 pk 211: * cputyp is the current cpu type, used to distinguish between
1.13 deraadt 212: * the many variations of different sun4* machines. It contains
213: * the value CPU_SUN4, CPU_SUN4C, or CPU_SUN4M.
1.9 deraadt 214: */
1.111 pk 215: .globl _C_LABEL(cputyp)
216: _C_LABEL(cputyp):
1.9 deraadt 217: .word 1
1.52 pk 218:
1.18 deraadt 219: #if defined(SUN4C) || defined(SUN4M)
1.111 pk 220: cputypval:
1.18 deraadt 221: .asciz "sun4c"
222: .ascii " "
1.111 pk 223: cputypvar:
1.37 pk 224: .asciz "compatible"
1.52 pk 225: _ALIGN
1.18 deraadt 226: #endif
227:
1.13 deraadt 228: /*
229: * There variables are pointed to by the cpp symbols PGSHIFT, NBPG,
230: * and PGOFSET.
231: */
1.111 pk 232: .globl _C_LABEL(pgshift), _C_LABEL(nbpg), _C_LABEL(pgofset)
233: _C_LABEL(pgshift):
1.52 pk 234: .word 0
1.111 pk 235: _C_LABEL(nbpg):
1.52 pk 236: .word 0
1.111 pk 237: _C_LABEL(pgofset):
1.52 pk 238: .word 0
239:
1.111 pk 240: .globl _C_LABEL(trapbase)
241: _C_LABEL(trapbase):
1.52 pk 242: .word 0
1.9 deraadt 243:
1.75 pk 244: #if 0
1.9 deraadt 245: #if defined(SUN4M)
246: _mapme:
247: .asciz "0 0 f8000000 15c6a0 map-pages"
248: #endif
1.75 pk 249: #endif
1.9 deraadt 250:
1.158 ! thorpej 251: #if !defined(SUN4D)
! 252: sun4d_notsup:
! 253: .asciz "cr .( NetBSD/sparc: this kernel does not support the sun4d) cr"
! 254: #endif
1.9 deraadt 255: #if !defined(SUN4M)
256: sun4m_notsup:
1.20 deraadt 257: .asciz "cr .( NetBSD/sparc: this kernel does not support the sun4m) cr"
1.9 deraadt 258: #endif
1.13 deraadt 259: #if !defined(SUN4C)
1.9 deraadt 260: sun4c_notsup:
1.20 deraadt 261: .asciz "cr .( NetBSD/sparc: this kernel does not support the sun4c) cr"
1.13 deraadt 262: #endif
263: #if !defined(SUN4)
264: sun4_notsup:
1.20 deraadt 265: ! the extra characters at the end are to ensure the zs fifo drains
266: ! before we halt. Sick, eh?
267: .asciz "NetBSD/sparc: this kernel does not support the sun4\n\r \b"
1.9 deraadt 268: #endif
1.52 pk 269: _ALIGN
1.9 deraadt 270:
1.1 deraadt 271: .text
272:
273: /*
1.26 deraadt 274: * The first thing in the real text segment is the trap vector table,
275: * which must be aligned on a 4096 byte boundary. The text segment
276: * starts beyond page 0 of KERNBASE so that there is a red zone
277: * between user and kernel space. Since the boot ROM loads us at
1.119 christos 278: * PROM_LOADADDR, it is far easier to start at KERNBASE+PROM_LOADADDR than to
1.26 deraadt 279: * buck the trend. This is two or four pages in (depending on if
280: * pagesize is 8192 or 4096). We place two items in this area:
1.75 pk 281: * the message buffer (phys addr 0) and the cpu_softc structure for
282: * the first processor in the system (phys addr 0x2000).
283: * Because the message buffer is in our "red zone" between user and
1.26 deraadt 284: * kernel space we remap it in configure() to another location and
285: * invalidate the mapping at KERNBASE.
286: */
287:
1.1 deraadt 288: /*
289: * Each trap has room for four instructions, of which one perforce must
290: * be a branch. On entry the hardware has copied pc and npc to %l1 and
291: * %l2 respectively. We use two more to read the psr into %l0, and to
292: * put the trap type value into %l3 (with a few exceptions below).
293: * We could read the trap type field of %tbr later in the code instead,
294: * but there is no need, and that would require more instructions
295: * (read+mask, vs 1 `mov' here).
296: *
297: * I used to generate these numbers by address arithmetic, but gas's
298: * expression evaluator has about as much sense as your average slug
299: * (oddly enough, the code looks about as slimy too). Thus, all the
300: * trap numbers are given as arguments to the trap macros. This means
301: * there is one line per trap. Sigh.
302: *
303: * Note that only the local registers may be used, since the trap
304: * window is potentially the last window. Its `in' registers are
305: * the previous window's outs (as usual), but more important, its
306: * `out' registers may be in use as the `topmost' window's `in' registers.
307: * The global registers are of course verboten (well, until we save
308: * them away).
309: *
310: * Hardware interrupt vectors can be `linked'---the linkage is to regular
311: * C code---or rewired to fast in-window handlers. The latter are good
312: * for unbuffered hardware like the Zilog serial chip and the AMD audio
313: * chip, where many interrupts can be handled trivially with pseudo-DMA or
314: * similar. Only one `fast' interrupt can be used per level, however, and
315: * direct and `fast' interrupts are incompatible. Routines in intr.c
316: * handle setting these, with optional paranoia.
317: */
318:
319: /* regular vectored traps */
320: #define VTRAP(type, label) \
321: mov (type), %l3; b label; mov %psr, %l0; nop
322:
323: /* hardware interrupts (can be linked or made `fast') */
1.52 pk 324: #define HARDINT44C(lev) \
1.111 pk 325: mov (lev), %l3; b _C_LABEL(sparc_interrupt44c); mov %psr, %l0; nop
1.52 pk 326:
327: /* hardware interrupts (can be linked or made `fast') */
328: #define HARDINT4M(lev) \
1.111 pk 329: mov (lev), %l3; b _C_LABEL(sparc_interrupt4m); mov %psr, %l0; nop
1.1 deraadt 330:
331: /* software interrupts (may not be made direct, sorry---but you
332: should not be using them trivially anyway) */
1.52 pk 333: #define SOFTINT44C(lev, bit) \
334: mov (lev), %l3; mov (bit), %l4; b softintr_sun44c; mov %psr, %l0
335:
336: /* There's no SOFTINT4M(): both hard and soft vector the same way */
1.1 deraadt 337:
338: /* traps that just call trap() */
339: #define TRAP(type) VTRAP(type, slowtrap)
340:
341: /* architecturally undefined traps (cause panic) */
342: #define UTRAP(type) VTRAP(type, slowtrap)
343:
344: /* software undefined traps (may be replaced) */
345: #define STRAP(type) VTRAP(type, slowtrap)
346:
347: /* breakpoint acts differently under kgdb */
348: #ifdef KGDB
349: #define BPT VTRAP(T_BREAKPOINT, bpt)
1.52 pk 350: #define BPT_KGDB_EXEC VTRAP(T_KGDB_EXEC, bpt)
351: #else
352: #define BPT TRAP(T_BREAKPOINT)
353: #define BPT_KGDB_EXEC TRAP(T_KGDB_EXEC)
354: #endif
355:
356: /* special high-speed 1-instruction-shaved-off traps (get nothing in %l3) */
1.122 christos 357: #define SYSCALL b _C_LABEL(_syscall); mov %psr, %l0; nop; nop
1.52 pk 358: #define WINDOW_OF b window_of; mov %psr, %l0; nop; nop
359: #define WINDOW_UF b window_uf; mov %psr, %l0; nop; nop
360: #ifdef notyet
361: #define ZS_INTERRUPT b zshard; mov %psr, %l0; nop; nop
362: #else
363: #define ZS_INTERRUPT44C HARDINT44C(12)
364: #define ZS_INTERRUPT4M HARDINT4M(12)
365: #endif
366:
1.111 pk 367: .globl _ASM_LABEL(start), _C_LABEL(kernel_text)
368: _C_LABEL(kernel_text) = start ! for kvm_mkdb(8)
369: _ASM_LABEL(start):
1.52 pk 370: /*
371: * Put sun4 traptable first, since it needs the most stringent aligment (8192)
372: */
373: #if defined(SUN4)
374: trapbase_sun4:
375: /* trap 0 is special since we cannot receive it */
376: b dostart; nop; nop; nop ! 00 = reset (fake)
377: VTRAP(T_TEXTFAULT, memfault_sun4) ! 01 = instr. fetch fault
378: TRAP(T_ILLINST) ! 02 = illegal instruction
379: TRAP(T_PRIVINST) ! 03 = privileged instruction
380: TRAP(T_FPDISABLED) ! 04 = fp instr, but EF bit off in psr
381: WINDOW_OF ! 05 = window overflow
382: WINDOW_UF ! 06 = window underflow
383: TRAP(T_ALIGN) ! 07 = address alignment error
384: VTRAP(T_FPE, fp_exception) ! 08 = fp exception
385: VTRAP(T_DATAFAULT, memfault_sun4) ! 09 = data fetch fault
386: TRAP(T_TAGOF) ! 0a = tag overflow
387: UTRAP(0x0b)
388: UTRAP(0x0c)
389: UTRAP(0x0d)
390: UTRAP(0x0e)
391: UTRAP(0x0f)
392: UTRAP(0x10)
393: SOFTINT44C(1, IE_L1) ! 11 = level 1 interrupt
394: HARDINT44C(2) ! 12 = level 2 interrupt
395: HARDINT44C(3) ! 13 = level 3 interrupt
396: SOFTINT44C(4, IE_L4) ! 14 = level 4 interrupt
397: HARDINT44C(5) ! 15 = level 5 interrupt
398: SOFTINT44C(6, IE_L6) ! 16 = level 6 interrupt
399: HARDINT44C(7) ! 17 = level 7 interrupt
400: HARDINT44C(8) ! 18 = level 8 interrupt
401: HARDINT44C(9) ! 19 = level 9 interrupt
402: HARDINT44C(10) ! 1a = level 10 interrupt
403: HARDINT44C(11) ! 1b = level 11 interrupt
404: ZS_INTERRUPT44C ! 1c = level 12 (zs) interrupt
405: HARDINT44C(13) ! 1d = level 13 interrupt
406: HARDINT44C(14) ! 1e = level 14 interrupt
407: VTRAP(15, nmi_sun4) ! 1f = nonmaskable interrupt
408: UTRAP(0x20)
409: UTRAP(0x21)
410: UTRAP(0x22)
411: UTRAP(0x23)
412: TRAP(T_CPDISABLED) ! 24 = coprocessor instr, EC bit off in psr
413: UTRAP(0x25)
414: UTRAP(0x26)
415: UTRAP(0x27)
416: TRAP(T_CPEXCEPTION) ! 28 = coprocessor exception
417: UTRAP(0x29)
418: UTRAP(0x2a)
419: UTRAP(0x2b)
420: UTRAP(0x2c)
421: UTRAP(0x2d)
422: UTRAP(0x2e)
423: UTRAP(0x2f)
424: UTRAP(0x30)
425: UTRAP(0x31)
426: UTRAP(0x32)
427: UTRAP(0x33)
428: UTRAP(0x34)
429: UTRAP(0x35)
430: UTRAP(0x36)
431: UTRAP(0x37)
432: UTRAP(0x38)
433: UTRAP(0x39)
434: UTRAP(0x3a)
435: UTRAP(0x3b)
436: UTRAP(0x3c)
437: UTRAP(0x3d)
438: UTRAP(0x3e)
439: UTRAP(0x3f)
440: UTRAP(0x40)
441: UTRAP(0x41)
442: UTRAP(0x42)
443: UTRAP(0x43)
444: UTRAP(0x44)
445: UTRAP(0x45)
446: UTRAP(0x46)
447: UTRAP(0x47)
448: UTRAP(0x48)
449: UTRAP(0x49)
450: UTRAP(0x4a)
451: UTRAP(0x4b)
452: UTRAP(0x4c)
453: UTRAP(0x4d)
454: UTRAP(0x4e)
455: UTRAP(0x4f)
456: UTRAP(0x50)
457: UTRAP(0x51)
458: UTRAP(0x52)
459: UTRAP(0x53)
460: UTRAP(0x54)
461: UTRAP(0x55)
462: UTRAP(0x56)
463: UTRAP(0x57)
464: UTRAP(0x58)
465: UTRAP(0x59)
466: UTRAP(0x5a)
467: UTRAP(0x5b)
468: UTRAP(0x5c)
469: UTRAP(0x5d)
470: UTRAP(0x5e)
471: UTRAP(0x5f)
472: UTRAP(0x60)
473: UTRAP(0x61)
474: UTRAP(0x62)
475: UTRAP(0x63)
476: UTRAP(0x64)
477: UTRAP(0x65)
478: UTRAP(0x66)
479: UTRAP(0x67)
480: UTRAP(0x68)
481: UTRAP(0x69)
482: UTRAP(0x6a)
483: UTRAP(0x6b)
484: UTRAP(0x6c)
485: UTRAP(0x6d)
486: UTRAP(0x6e)
487: UTRAP(0x6f)
488: UTRAP(0x70)
489: UTRAP(0x71)
490: UTRAP(0x72)
491: UTRAP(0x73)
492: UTRAP(0x74)
493: UTRAP(0x75)
494: UTRAP(0x76)
495: UTRAP(0x77)
496: UTRAP(0x78)
497: UTRAP(0x79)
498: UTRAP(0x7a)
499: UTRAP(0x7b)
500: UTRAP(0x7c)
501: UTRAP(0x7d)
502: UTRAP(0x7e)
503: UTRAP(0x7f)
504: SYSCALL ! 80 = sun syscall
505: BPT ! 81 = pseudo breakpoint instruction
506: TRAP(T_DIV0) ! 82 = divide by zero
507: TRAP(T_FLUSHWIN) ! 83 = flush windows
508: TRAP(T_CLEANWIN) ! 84 = provide clean windows
509: TRAP(T_RANGECHECK) ! 85 = ???
510: TRAP(T_FIXALIGN) ! 86 = fix up unaligned accesses
511: TRAP(T_INTOF) ! 87 = integer overflow
512: SYSCALL ! 88 = svr4 syscall
513: SYSCALL ! 89 = bsd syscall
514: BPT_KGDB_EXEC ! 8a = enter kernel gdb on kernel startup
515: STRAP(0x8b)
516: STRAP(0x8c)
517: STRAP(0x8d)
518: STRAP(0x8e)
519: STRAP(0x8f)
520: STRAP(0x90)
521: STRAP(0x91)
522: STRAP(0x92)
523: STRAP(0x93)
524: STRAP(0x94)
525: STRAP(0x95)
526: STRAP(0x96)
527: STRAP(0x97)
528: STRAP(0x98)
529: STRAP(0x99)
530: STRAP(0x9a)
531: STRAP(0x9b)
532: STRAP(0x9c)
533: STRAP(0x9d)
534: STRAP(0x9e)
535: STRAP(0x9f)
536: STRAP(0xa0)
537: STRAP(0xa1)
538: STRAP(0xa2)
539: STRAP(0xa3)
540: STRAP(0xa4)
541: STRAP(0xa5)
542: STRAP(0xa6)
543: STRAP(0xa7)
544: STRAP(0xa8)
545: STRAP(0xa9)
546: STRAP(0xaa)
547: STRAP(0xab)
548: STRAP(0xac)
549: STRAP(0xad)
550: STRAP(0xae)
551: STRAP(0xaf)
552: STRAP(0xb0)
553: STRAP(0xb1)
554: STRAP(0xb2)
555: STRAP(0xb3)
556: STRAP(0xb4)
557: STRAP(0xb5)
558: STRAP(0xb6)
559: STRAP(0xb7)
560: STRAP(0xb8)
561: STRAP(0xb9)
562: STRAP(0xba)
563: STRAP(0xbb)
564: STRAP(0xbc)
565: STRAP(0xbd)
566: STRAP(0xbe)
567: STRAP(0xbf)
568: STRAP(0xc0)
569: STRAP(0xc1)
570: STRAP(0xc2)
571: STRAP(0xc3)
572: STRAP(0xc4)
573: STRAP(0xc5)
574: STRAP(0xc6)
575: STRAP(0xc7)
576: STRAP(0xc8)
577: STRAP(0xc9)
578: STRAP(0xca)
579: STRAP(0xcb)
580: STRAP(0xcc)
581: STRAP(0xcd)
582: STRAP(0xce)
583: STRAP(0xcf)
584: STRAP(0xd0)
585: STRAP(0xd1)
586: STRAP(0xd2)
587: STRAP(0xd3)
588: STRAP(0xd4)
589: STRAP(0xd5)
590: STRAP(0xd6)
591: STRAP(0xd7)
592: STRAP(0xd8)
593: STRAP(0xd9)
594: STRAP(0xda)
595: STRAP(0xdb)
596: STRAP(0xdc)
597: STRAP(0xdd)
598: STRAP(0xde)
599: STRAP(0xdf)
600: STRAP(0xe0)
601: STRAP(0xe1)
602: STRAP(0xe2)
603: STRAP(0xe3)
604: STRAP(0xe4)
605: STRAP(0xe5)
606: STRAP(0xe6)
607: STRAP(0xe7)
608: STRAP(0xe8)
609: STRAP(0xe9)
610: STRAP(0xea)
611: STRAP(0xeb)
612: STRAP(0xec)
613: STRAP(0xed)
614: STRAP(0xee)
615: STRAP(0xef)
616: STRAP(0xf0)
617: STRAP(0xf1)
618: STRAP(0xf2)
619: STRAP(0xf3)
620: STRAP(0xf4)
621: STRAP(0xf5)
622: STRAP(0xf6)
623: STRAP(0xf7)
624: STRAP(0xf8)
625: STRAP(0xf9)
626: STRAP(0xfa)
627: STRAP(0xfb)
628: STRAP(0xfc)
629: STRAP(0xfd)
630: STRAP(0xfe)
631: STRAP(0xff)
632: #endif
633:
634: #if defined(SUN4C)
635: trapbase_sun4c:
636: /* trap 0 is special since we cannot receive it */
637: b dostart; nop; nop; nop ! 00 = reset (fake)
638: VTRAP(T_TEXTFAULT, memfault_sun4c) ! 01 = instr. fetch fault
639: TRAP(T_ILLINST) ! 02 = illegal instruction
640: TRAP(T_PRIVINST) ! 03 = privileged instruction
641: TRAP(T_FPDISABLED) ! 04 = fp instr, but EF bit off in psr
642: WINDOW_OF ! 05 = window overflow
643: WINDOW_UF ! 06 = window underflow
644: TRAP(T_ALIGN) ! 07 = address alignment error
645: VTRAP(T_FPE, fp_exception) ! 08 = fp exception
646: VTRAP(T_DATAFAULT, memfault_sun4c) ! 09 = data fetch fault
647: TRAP(T_TAGOF) ! 0a = tag overflow
648: UTRAP(0x0b)
649: UTRAP(0x0c)
650: UTRAP(0x0d)
651: UTRAP(0x0e)
652: UTRAP(0x0f)
653: UTRAP(0x10)
654: SOFTINT44C(1, IE_L1) ! 11 = level 1 interrupt
655: HARDINT44C(2) ! 12 = level 2 interrupt
656: HARDINT44C(3) ! 13 = level 3 interrupt
657: SOFTINT44C(4, IE_L4) ! 14 = level 4 interrupt
658: HARDINT44C(5) ! 15 = level 5 interrupt
659: SOFTINT44C(6, IE_L6) ! 16 = level 6 interrupt
660: HARDINT44C(7) ! 17 = level 7 interrupt
661: HARDINT44C(8) ! 18 = level 8 interrupt
662: HARDINT44C(9) ! 19 = level 9 interrupt
663: HARDINT44C(10) ! 1a = level 10 interrupt
664: HARDINT44C(11) ! 1b = level 11 interrupt
665: ZS_INTERRUPT44C ! 1c = level 12 (zs) interrupt
666: HARDINT44C(13) ! 1d = level 13 interrupt
667: HARDINT44C(14) ! 1e = level 14 interrupt
668: VTRAP(15, nmi_sun4c) ! 1f = nonmaskable interrupt
669: UTRAP(0x20)
670: UTRAP(0x21)
671: UTRAP(0x22)
672: UTRAP(0x23)
673: TRAP(T_CPDISABLED) ! 24 = coprocessor instr, EC bit off in psr
674: UTRAP(0x25)
675: UTRAP(0x26)
676: UTRAP(0x27)
677: TRAP(T_CPEXCEPTION) ! 28 = coprocessor exception
678: UTRAP(0x29)
679: UTRAP(0x2a)
680: UTRAP(0x2b)
681: UTRAP(0x2c)
682: UTRAP(0x2d)
683: UTRAP(0x2e)
684: UTRAP(0x2f)
685: UTRAP(0x30)
686: UTRAP(0x31)
687: UTRAP(0x32)
688: UTRAP(0x33)
689: UTRAP(0x34)
690: UTRAP(0x35)
691: UTRAP(0x36)
692: UTRAP(0x37)
693: UTRAP(0x38)
694: UTRAP(0x39)
695: UTRAP(0x3a)
696: UTRAP(0x3b)
697: UTRAP(0x3c)
698: UTRAP(0x3d)
699: UTRAP(0x3e)
700: UTRAP(0x3f)
701: UTRAP(0x40)
702: UTRAP(0x41)
703: UTRAP(0x42)
704: UTRAP(0x43)
705: UTRAP(0x44)
706: UTRAP(0x45)
707: UTRAP(0x46)
708: UTRAP(0x47)
709: UTRAP(0x48)
710: UTRAP(0x49)
711: UTRAP(0x4a)
712: UTRAP(0x4b)
713: UTRAP(0x4c)
714: UTRAP(0x4d)
715: UTRAP(0x4e)
716: UTRAP(0x4f)
717: UTRAP(0x50)
718: UTRAP(0x51)
719: UTRAP(0x52)
720: UTRAP(0x53)
721: UTRAP(0x54)
722: UTRAP(0x55)
723: UTRAP(0x56)
724: UTRAP(0x57)
725: UTRAP(0x58)
726: UTRAP(0x59)
727: UTRAP(0x5a)
728: UTRAP(0x5b)
729: UTRAP(0x5c)
730: UTRAP(0x5d)
731: UTRAP(0x5e)
732: UTRAP(0x5f)
733: UTRAP(0x60)
734: UTRAP(0x61)
735: UTRAP(0x62)
736: UTRAP(0x63)
737: UTRAP(0x64)
738: UTRAP(0x65)
739: UTRAP(0x66)
740: UTRAP(0x67)
741: UTRAP(0x68)
742: UTRAP(0x69)
743: UTRAP(0x6a)
744: UTRAP(0x6b)
745: UTRAP(0x6c)
746: UTRAP(0x6d)
747: UTRAP(0x6e)
748: UTRAP(0x6f)
749: UTRAP(0x70)
750: UTRAP(0x71)
751: UTRAP(0x72)
752: UTRAP(0x73)
753: UTRAP(0x74)
754: UTRAP(0x75)
755: UTRAP(0x76)
756: UTRAP(0x77)
757: UTRAP(0x78)
758: UTRAP(0x79)
759: UTRAP(0x7a)
760: UTRAP(0x7b)
761: UTRAP(0x7c)
762: UTRAP(0x7d)
763: UTRAP(0x7e)
764: UTRAP(0x7f)
765: SYSCALL ! 80 = sun syscall
766: BPT ! 81 = pseudo breakpoint instruction
767: TRAP(T_DIV0) ! 82 = divide by zero
768: TRAP(T_FLUSHWIN) ! 83 = flush windows
769: TRAP(T_CLEANWIN) ! 84 = provide clean windows
770: TRAP(T_RANGECHECK) ! 85 = ???
771: TRAP(T_FIXALIGN) ! 86 = fix up unaligned accesses
772: TRAP(T_INTOF) ! 87 = integer overflow
773: SYSCALL ! 88 = svr4 syscall
774: SYSCALL ! 89 = bsd syscall
775: BPT_KGDB_EXEC ! 8a = enter kernel gdb on kernel startup
776: STRAP(0x8b)
777: STRAP(0x8c)
778: STRAP(0x8d)
779: STRAP(0x8e)
780: STRAP(0x8f)
781: STRAP(0x90)
782: STRAP(0x91)
783: STRAP(0x92)
784: STRAP(0x93)
785: STRAP(0x94)
786: STRAP(0x95)
787: STRAP(0x96)
788: STRAP(0x97)
789: STRAP(0x98)
790: STRAP(0x99)
791: STRAP(0x9a)
792: STRAP(0x9b)
793: STRAP(0x9c)
794: STRAP(0x9d)
795: STRAP(0x9e)
796: STRAP(0x9f)
797: STRAP(0xa0)
798: STRAP(0xa1)
799: STRAP(0xa2)
800: STRAP(0xa3)
801: STRAP(0xa4)
802: STRAP(0xa5)
803: STRAP(0xa6)
804: STRAP(0xa7)
805: STRAP(0xa8)
806: STRAP(0xa9)
807: STRAP(0xaa)
808: STRAP(0xab)
809: STRAP(0xac)
810: STRAP(0xad)
811: STRAP(0xae)
812: STRAP(0xaf)
813: STRAP(0xb0)
814: STRAP(0xb1)
815: STRAP(0xb2)
816: STRAP(0xb3)
817: STRAP(0xb4)
818: STRAP(0xb5)
819: STRAP(0xb6)
820: STRAP(0xb7)
821: STRAP(0xb8)
822: STRAP(0xb9)
823: STRAP(0xba)
824: STRAP(0xbb)
825: STRAP(0xbc)
826: STRAP(0xbd)
827: STRAP(0xbe)
828: STRAP(0xbf)
829: STRAP(0xc0)
830: STRAP(0xc1)
831: STRAP(0xc2)
832: STRAP(0xc3)
833: STRAP(0xc4)
834: STRAP(0xc5)
835: STRAP(0xc6)
836: STRAP(0xc7)
837: STRAP(0xc8)
838: STRAP(0xc9)
839: STRAP(0xca)
840: STRAP(0xcb)
841: STRAP(0xcc)
842: STRAP(0xcd)
843: STRAP(0xce)
844: STRAP(0xcf)
845: STRAP(0xd0)
846: STRAP(0xd1)
847: STRAP(0xd2)
848: STRAP(0xd3)
849: STRAP(0xd4)
850: STRAP(0xd5)
851: STRAP(0xd6)
852: STRAP(0xd7)
853: STRAP(0xd8)
854: STRAP(0xd9)
855: STRAP(0xda)
856: STRAP(0xdb)
857: STRAP(0xdc)
858: STRAP(0xdd)
859: STRAP(0xde)
860: STRAP(0xdf)
861: STRAP(0xe0)
862: STRAP(0xe1)
863: STRAP(0xe2)
864: STRAP(0xe3)
865: STRAP(0xe4)
866: STRAP(0xe5)
867: STRAP(0xe6)
868: STRAP(0xe7)
869: STRAP(0xe8)
870: STRAP(0xe9)
871: STRAP(0xea)
872: STRAP(0xeb)
873: STRAP(0xec)
874: STRAP(0xed)
875: STRAP(0xee)
876: STRAP(0xef)
877: STRAP(0xf0)
878: STRAP(0xf1)
879: STRAP(0xf2)
880: STRAP(0xf3)
881: STRAP(0xf4)
882: STRAP(0xf5)
883: STRAP(0xf6)
884: STRAP(0xf7)
885: STRAP(0xf8)
886: STRAP(0xf9)
887: STRAP(0xfa)
888: STRAP(0xfb)
889: STRAP(0xfc)
890: STRAP(0xfd)
891: STRAP(0xfe)
892: STRAP(0xff)
1.1 deraadt 893: #endif
894:
1.52 pk 895: #if defined(SUN4M)
896: trapbase_sun4m:
1.1 deraadt 897: /* trap 0 is special since we cannot receive it */
898: b dostart; nop; nop; nop ! 00 = reset (fake)
1.52 pk 899: VTRAP(T_TEXTFAULT, memfault_sun4m) ! 01 = instr. fetch fault
1.1 deraadt 900: TRAP(T_ILLINST) ! 02 = illegal instruction
901: TRAP(T_PRIVINST) ! 03 = privileged instruction
902: TRAP(T_FPDISABLED) ! 04 = fp instr, but EF bit off in psr
903: WINDOW_OF ! 05 = window overflow
904: WINDOW_UF ! 06 = window underflow
905: TRAP(T_ALIGN) ! 07 = address alignment error
906: VTRAP(T_FPE, fp_exception) ! 08 = fp exception
1.52 pk 907: VTRAP(T_DATAFAULT, memfault_sun4m) ! 09 = data fetch fault
1.1 deraadt 908: TRAP(T_TAGOF) ! 0a = tag overflow
909: UTRAP(0x0b)
910: UTRAP(0x0c)
911: UTRAP(0x0d)
912: UTRAP(0x0e)
913: UTRAP(0x0f)
914: UTRAP(0x10)
1.52 pk 915: HARDINT4M(1) ! 11 = level 1 interrupt
916: HARDINT4M(2) ! 12 = level 2 interrupt
917: HARDINT4M(3) ! 13 = level 3 interrupt
918: HARDINT4M(4) ! 14 = level 4 interrupt
919: HARDINT4M(5) ! 15 = level 5 interrupt
920: HARDINT4M(6) ! 16 = level 6 interrupt
921: HARDINT4M(7) ! 17 = level 7 interrupt
922: HARDINT4M(8) ! 18 = level 8 interrupt
923: HARDINT4M(9) ! 19 = level 9 interrupt
924: HARDINT4M(10) ! 1a = level 10 interrupt
925: HARDINT4M(11) ! 1b = level 11 interrupt
926: ZS_INTERRUPT4M ! 1c = level 12 (zs) interrupt
927: HARDINT4M(13) ! 1d = level 13 interrupt
928: HARDINT4M(14) ! 1e = level 14 interrupt
929: VTRAP(15, nmi_sun4m) ! 1f = nonmaskable interrupt
1.1 deraadt 930: UTRAP(0x20)
931: UTRAP(0x21)
932: UTRAP(0x22)
933: UTRAP(0x23)
1.25 deraadt 934: TRAP(T_CPDISABLED) ! 24 = coprocessor instr, EC bit off in psr
1.1 deraadt 935: UTRAP(0x25)
936: UTRAP(0x26)
937: UTRAP(0x27)
1.25 deraadt 938: TRAP(T_CPEXCEPTION) ! 28 = coprocessor exception
1.1 deraadt 939: UTRAP(0x29)
940: UTRAP(0x2a)
1.52 pk 941: VTRAP(T_STOREBUFFAULT, memfault_sun4m) ! 2b = SuperSPARC store buffer fault
1.1 deraadt 942: UTRAP(0x2c)
943: UTRAP(0x2d)
944: UTRAP(0x2e)
945: UTRAP(0x2f)
946: UTRAP(0x30)
947: UTRAP(0x31)
948: UTRAP(0x32)
949: UTRAP(0x33)
950: UTRAP(0x34)
951: UTRAP(0x35)
1.25 deraadt 952: UTRAP(0x36)
1.1 deraadt 953: UTRAP(0x37)
954: UTRAP(0x38)
955: UTRAP(0x39)
956: UTRAP(0x3a)
957: UTRAP(0x3b)
958: UTRAP(0x3c)
959: UTRAP(0x3d)
960: UTRAP(0x3e)
961: UTRAP(0x3f)
1.25 deraadt 962: UTRAP(0x40)
1.1 deraadt 963: UTRAP(0x41)
964: UTRAP(0x42)
965: UTRAP(0x43)
966: UTRAP(0x44)
967: UTRAP(0x45)
968: UTRAP(0x46)
969: UTRAP(0x47)
970: UTRAP(0x48)
971: UTRAP(0x49)
972: UTRAP(0x4a)
973: UTRAP(0x4b)
974: UTRAP(0x4c)
975: UTRAP(0x4d)
976: UTRAP(0x4e)
977: UTRAP(0x4f)
978: UTRAP(0x50)
979: UTRAP(0x51)
980: UTRAP(0x52)
981: UTRAP(0x53)
982: UTRAP(0x54)
983: UTRAP(0x55)
984: UTRAP(0x56)
985: UTRAP(0x57)
986: UTRAP(0x58)
987: UTRAP(0x59)
988: UTRAP(0x5a)
989: UTRAP(0x5b)
990: UTRAP(0x5c)
991: UTRAP(0x5d)
992: UTRAP(0x5e)
993: UTRAP(0x5f)
994: UTRAP(0x60)
995: UTRAP(0x61)
996: UTRAP(0x62)
997: UTRAP(0x63)
998: UTRAP(0x64)
999: UTRAP(0x65)
1000: UTRAP(0x66)
1001: UTRAP(0x67)
1002: UTRAP(0x68)
1003: UTRAP(0x69)
1004: UTRAP(0x6a)
1005: UTRAP(0x6b)
1006: UTRAP(0x6c)
1007: UTRAP(0x6d)
1008: UTRAP(0x6e)
1009: UTRAP(0x6f)
1010: UTRAP(0x70)
1011: UTRAP(0x71)
1012: UTRAP(0x72)
1013: UTRAP(0x73)
1014: UTRAP(0x74)
1015: UTRAP(0x75)
1016: UTRAP(0x76)
1017: UTRAP(0x77)
1018: UTRAP(0x78)
1019: UTRAP(0x79)
1020: UTRAP(0x7a)
1021: UTRAP(0x7b)
1022: UTRAP(0x7c)
1023: UTRAP(0x7d)
1024: UTRAP(0x7e)
1025: UTRAP(0x7f)
1.3 deraadt 1026: SYSCALL ! 80 = sun syscall
1.1 deraadt 1027: BPT ! 81 = pseudo breakpoint instruction
1028: TRAP(T_DIV0) ! 82 = divide by zero
1029: TRAP(T_FLUSHWIN) ! 83 = flush windows
1030: TRAP(T_CLEANWIN) ! 84 = provide clean windows
1031: TRAP(T_RANGECHECK) ! 85 = ???
1032: TRAP(T_FIXALIGN) ! 86 = fix up unaligned accesses
1033: TRAP(T_INTOF) ! 87 = integer overflow
1.33 christos 1034: SYSCALL ! 88 = svr4 syscall
1.1 deraadt 1035: SYSCALL ! 89 = bsd syscall
1.33 christos 1036: BPT_KGDB_EXEC ! 8a = enter kernel gdb on kernel startup
1.1 deraadt 1037: STRAP(0x8b)
1038: STRAP(0x8c)
1039: STRAP(0x8d)
1040: STRAP(0x8e)
1041: STRAP(0x8f)
1042: STRAP(0x90)
1043: STRAP(0x91)
1044: STRAP(0x92)
1045: STRAP(0x93)
1046: STRAP(0x94)
1047: STRAP(0x95)
1048: STRAP(0x96)
1049: STRAP(0x97)
1050: STRAP(0x98)
1051: STRAP(0x99)
1052: STRAP(0x9a)
1053: STRAP(0x9b)
1054: STRAP(0x9c)
1055: STRAP(0x9d)
1056: STRAP(0x9e)
1057: STRAP(0x9f)
1058: STRAP(0xa0)
1059: STRAP(0xa1)
1060: STRAP(0xa2)
1061: STRAP(0xa3)
1062: STRAP(0xa4)
1063: STRAP(0xa5)
1064: STRAP(0xa6)
1065: STRAP(0xa7)
1066: STRAP(0xa8)
1067: STRAP(0xa9)
1068: STRAP(0xaa)
1069: STRAP(0xab)
1070: STRAP(0xac)
1071: STRAP(0xad)
1072: STRAP(0xae)
1073: STRAP(0xaf)
1074: STRAP(0xb0)
1075: STRAP(0xb1)
1076: STRAP(0xb2)
1077: STRAP(0xb3)
1078: STRAP(0xb4)
1079: STRAP(0xb5)
1080: STRAP(0xb6)
1081: STRAP(0xb7)
1082: STRAP(0xb8)
1083: STRAP(0xb9)
1084: STRAP(0xba)
1085: STRAP(0xbb)
1086: STRAP(0xbc)
1087: STRAP(0xbd)
1088: STRAP(0xbe)
1089: STRAP(0xbf)
1090: STRAP(0xc0)
1091: STRAP(0xc1)
1092: STRAP(0xc2)
1093: STRAP(0xc3)
1094: STRAP(0xc4)
1095: STRAP(0xc5)
1096: STRAP(0xc6)
1097: STRAP(0xc7)
1098: STRAP(0xc8)
1099: STRAP(0xc9)
1100: STRAP(0xca)
1101: STRAP(0xcb)
1102: STRAP(0xcc)
1103: STRAP(0xcd)
1104: STRAP(0xce)
1105: STRAP(0xcf)
1106: STRAP(0xd0)
1107: STRAP(0xd1)
1108: STRAP(0xd2)
1109: STRAP(0xd3)
1110: STRAP(0xd4)
1111: STRAP(0xd5)
1112: STRAP(0xd6)
1113: STRAP(0xd7)
1114: STRAP(0xd8)
1115: STRAP(0xd9)
1116: STRAP(0xda)
1117: STRAP(0xdb)
1118: STRAP(0xdc)
1119: STRAP(0xdd)
1120: STRAP(0xde)
1121: STRAP(0xdf)
1122: STRAP(0xe0)
1123: STRAP(0xe1)
1124: STRAP(0xe2)
1125: STRAP(0xe3)
1126: STRAP(0xe4)
1127: STRAP(0xe5)
1128: STRAP(0xe6)
1129: STRAP(0xe7)
1130: STRAP(0xe8)
1131: STRAP(0xe9)
1132: STRAP(0xea)
1133: STRAP(0xeb)
1134: STRAP(0xec)
1135: STRAP(0xed)
1136: STRAP(0xee)
1137: STRAP(0xef)
1138: STRAP(0xf0)
1139: STRAP(0xf1)
1140: STRAP(0xf2)
1141: STRAP(0xf3)
1142: STRAP(0xf4)
1143: STRAP(0xf5)
1144: STRAP(0xf6)
1145: STRAP(0xf7)
1146: STRAP(0xf8)
1147: STRAP(0xf9)
1148: STRAP(0xfa)
1149: STRAP(0xfb)
1150: STRAP(0xfc)
1151: STRAP(0xfd)
1152: STRAP(0xfe)
1153: STRAP(0xff)
1.52 pk 1154: #endif
1.1 deraadt 1155:
1.20 deraadt 1156: /*
1.52 pk 1157: * Pad the trap table to max page size.
1158: * Trap table size is 0x100 * 4instr * 4byte/instr = 4096 bytes;
1159: * need to .skip 4096 to pad to page size iff. the number of trap tables
1160: * defined above is odd.
1.20 deraadt 1161: */
1.65 mycroft 1162: #if (defined(SUN4) + defined(SUN4C) + defined(SUN4M)) % 2 == 1
1.20 deraadt 1163: .skip 4096
1.52 pk 1164: #endif
1.20 deraadt 1165:
1.98 pk 1166: #ifdef DEBUG
1.1 deraadt 1167: /*
1168: * A hardware red zone is impossible. We simulate one in software by
1169: * keeping a `red zone' pointer; if %sp becomes less than this, we panic.
1170: * This is expensive and is only enabled when debugging.
1171: */
1.97 pk 1172:
1.99 pk 1173: /* `redzone' is located in the per-CPU information structure */
1.97 pk 1174: _redzone = CPUINFO_VA + CPUINFO_REDZONE
1175: .data
1.1 deraadt 1176: #define REDSTACK 2048 /* size of `panic: stack overflow' region */
1177: _redstack:
1178: .skip REDSTACK
1179: .text
1180: Lpanic_red:
1181: .asciz "stack overflow"
1.52 pk 1182: _ALIGN
1.1 deraadt 1183:
1184: /* set stack pointer redzone to base+minstack; alters base */
1185: #define SET_SP_REDZONE(base, tmp) \
1186: add base, REDSIZE, base; \
1187: sethi %hi(_redzone), tmp; \
1188: st base, [tmp + %lo(_redzone)]
1189:
1190: /* variant with a constant */
1191: #define SET_SP_REDZONE_CONST(const, tmp1, tmp2) \
1192: set (const) + REDSIZE, tmp1; \
1193: sethi %hi(_redzone), tmp2; \
1194: st tmp1, [tmp2 + %lo(_redzone)]
1195:
1.97 pk 1196: /* variant with a variable & offset */
1197: #define SET_SP_REDZONE_VAR(var, offset, tmp1, tmp2) \
1198: sethi %hi(var), tmp1; \
1199: ld [tmp1 + %lo(var)], tmp1; \
1200: sethi %hi(offset), tmp2; \
1201: add tmp1, tmp2, tmp1; \
1202: SET_SP_REDZONE(tmp1, tmp2)
1203:
1.1 deraadt 1204: /* check stack pointer against redzone (uses two temps) */
1205: #define CHECK_SP_REDZONE(t1, t2) \
1206: sethi %hi(_redzone), t1; \
1207: ld [t1 + %lo(_redzone)], t2; \
1208: cmp %sp, t2; /* if sp >= t2, not in red zone */ \
1209: bgeu 7f; nop; /* and can continue normally */ \
1210: /* move to panic stack */ \
1211: st %g0, [t1 + %lo(_redzone)]; \
1212: set _redstack + REDSTACK - 96, %sp; \
1213: /* prevent panic() from lowering ipl */ \
1.121 christos 1214: sethi %hi(_C_LABEL(panicstr)), t2; \
1.1 deraadt 1215: set Lpanic_red, t2; \
1.121 christos 1216: st t2, [t1 + %lo(_C_LABEL(panicstr))]; \
1.1 deraadt 1217: rd %psr, t1; /* t1 = splhigh() */ \
1218: or t1, PSR_PIL, t2; \
1219: wr t2, 0, %psr; \
1220: wr t2, PSR_ET, %psr; /* turn on traps */ \
1221: nop; nop; nop; \
1.4 deraadt 1222: save %sp, -CCFSZ, %sp; /* preserve current window */ \
1.1 deraadt 1223: sethi %hi(Lpanic_red), %o0; \
1.121 christos 1224: call _C_LABEL(panic); or %o0, %lo(Lpanic_red), %o0; \
1.1 deraadt 1225: 7:
1226:
1227: #else
1228:
1229: #define SET_SP_REDZONE(base, tmp)
1230: #define SET_SP_REDZONE_CONST(const, t1, t2)
1.98 pk 1231: #define SET_SP_REDZONE_VAR(var, offset, t1, t2)
1.1 deraadt 1232: #define CHECK_SP_REDZONE(t1, t2)
1.97 pk 1233: #endif /* DEBUG */
1.1 deraadt 1234:
1235: /*
1236: * The window code must verify user stack addresses before using them.
1237: * A user stack pointer is invalid if:
1238: * - it is not on an 8 byte boundary;
1239: * - its pages (a register window, being 64 bytes, can occupy
1240: * two pages) are not readable or writable.
1241: * We define three separate macros here for testing user stack addresses.
1242: *
1243: * PTE_OF_ADDR locates a PTE, branching to a `bad address'
1244: * handler if the stack pointer points into the hole in the
1245: * address space (i.e., top 3 bits are not either all 1 or all 0);
1246: * CMP_PTE_USER_READ compares the located PTE against `user read' mode;
1247: * CMP_PTE_USER_WRITE compares the located PTE against `user write' mode.
1248: * The compares give `equal' if read or write is OK.
1249: *
1250: * Note that the user stack pointer usually points into high addresses
1251: * (top 3 bits all 1), so that is what we check first.
1252: *
1253: * The code below also assumes that PTE_OF_ADDR is safe in a delay
1254: * slot; it is, at it merely sets its `pte' register to a temporary value.
1255: */
1.52 pk 1256: #if defined(SUN4) || defined(SUN4C)
1.1 deraadt 1257: /* input: addr, output: pte; aux: bad address label */
1.52 pk 1258: #define PTE_OF_ADDR4_4C(addr, pte, bad, page_offset) \
1.1 deraadt 1259: sra addr, PG_VSHIFT, pte; \
1260: cmp pte, -1; \
1.13 deraadt 1261: be,a 1f; andn addr, page_offset, pte; \
1.1 deraadt 1262: tst pte; \
1263: bne bad; EMPTY; \
1.13 deraadt 1264: andn addr, page_offset, pte; \
1.1 deraadt 1265: 1:
1266:
1267: /* input: pte; output: condition codes */
1.52 pk 1268: #define CMP_PTE_USER_READ4_4C(pte) \
1.1 deraadt 1269: lda [pte] ASI_PTE, pte; \
1270: srl pte, PG_PROTSHIFT, pte; \
1271: andn pte, (PG_W >> PG_PROTSHIFT), pte; \
1272: cmp pte, PG_PROTUREAD
1273:
1274: /* input: pte; output: condition codes */
1.52 pk 1275: #define CMP_PTE_USER_WRITE4_4C(pte) \
1.1 deraadt 1276: lda [pte] ASI_PTE, pte; \
1277: srl pte, PG_PROTSHIFT, pte; \
1278: cmp pte, PG_PROTUWRITE
1.9 deraadt 1279: #endif
1.1 deraadt 1280:
1281: /*
1.52 pk 1282: * The Sun4M does not have the memory hole that the 4C does. Thus all
1283: * we need to do here is clear the page offset from addr.
1284: */
1285: #if defined(SUN4M)
1286: #define PTE_OF_ADDR4M(addr, pte, bad, page_offset) \
1287: andn addr, page_offset, pte
1288:
1.94 pk 1289: /*
1290: * After obtaining the PTE through ASI_SRMMUFP, we read the Sync Fault
1291: * Status register. This is necessary on Hypersparcs which stores and
1292: * locks the fault address and status registers if the translation
1293: * fails (thanks to Chris Torek for finding this quirk).
1294: */
1.59 pk 1295: /* note: pmap currently does not use the PPROT_R_R and PPROT_RW_RW cases */
1.94 pk 1296: #define CMP_PTE_USER_READ4M(pte, tmp) \
1.52 pk 1297: or pte, ASI_SRMMUFP_L3, pte; \
1298: lda [pte] ASI_SRMMUFP, pte; \
1.94 pk 1299: set SRMMU_SFSR, tmp; \
1.58 pk 1300: and pte, (SRMMU_TETYPE | SRMMU_PROT_MASK), pte; \
1.59 pk 1301: cmp pte, (SRMMU_TEPTE | PPROT_RWX_RWX); \
1.94 pk 1302: be 8f; \
1303: lda [tmp] ASI_SRMMU, %g0; \
1.59 pk 1304: cmp pte, (SRMMU_TEPTE | PPROT_RX_RX); \
1305: 8:
1.52 pk 1306:
1.58 pk 1307:
1308: /* note: PTE bit 4 set implies no user writes */
1.94 pk 1309: #define CMP_PTE_USER_WRITE4M(pte, tmp) \
1.52 pk 1310: or pte, ASI_SRMMUFP_L3, pte; \
1311: lda [pte] ASI_SRMMUFP, pte; \
1.94 pk 1312: set SRMMU_SFSR, tmp; \
1313: lda [tmp] ASI_SRMMU, %g0; \
1.58 pk 1314: and pte, (SRMMU_TETYPE | 0x14), pte; \
1315: cmp pte, (SRMMU_TEPTE | PPROT_WRITE)
1.52 pk 1316: #endif /* 4m */
1317:
1318: #if defined(SUN4M) && !(defined(SUN4C) || defined(SUN4))
1.64 pk 1319:
1.62 pk 1320: #define PTE_OF_ADDR(addr, pte, bad, page_offset, label) \
1321: PTE_OF_ADDR4M(addr, pte, bad, page_offset)
1.94 pk 1322: #define CMP_PTE_USER_WRITE(pte, tmp, label) CMP_PTE_USER_WRITE4M(pte,tmp)
1323: #define CMP_PTE_USER_READ(pte, tmp, label) CMP_PTE_USER_READ4M(pte,tmp)
1.64 pk 1324:
1.52 pk 1325: #elif (defined(SUN4C) || defined(SUN4)) && !defined(SUN4M)
1.64 pk 1326:
1.62 pk 1327: #define PTE_OF_ADDR(addr, pte, bad, page_offset,label) \
1328: PTE_OF_ADDR4_4C(addr, pte, bad, page_offset)
1329: #define CMP_PTE_USER_WRITE(pte, tmp, label) CMP_PTE_USER_WRITE4_4C(pte)
1330: #define CMP_PTE_USER_READ(pte, tmp, label) CMP_PTE_USER_READ4_4C(pte)
1.64 pk 1331:
1.52 pk 1332: #else /* both defined, ugh */
1.64 pk 1333:
1.62 pk 1334: #define PTE_OF_ADDR(addr, pte, bad, page_offset, label) \
1335: label: b,a 2f; \
1336: PTE_OF_ADDR4M(addr, pte, bad, page_offset); \
1337: b,a 3f; \
1338: 2: \
1339: PTE_OF_ADDR4_4C(addr, pte, bad, page_offset); \
1340: 3:
1.52 pk 1341:
1.62 pk 1342: #define CMP_PTE_USER_READ(pte, tmp, label) \
1343: label: b,a 1f; \
1.94 pk 1344: CMP_PTE_USER_READ4M(pte,tmp); \
1.62 pk 1345: b,a 2f; \
1346: 1: \
1347: CMP_PTE_USER_READ4_4C(pte); \
1348: 2:
1.52 pk 1349:
1.62 pk 1350: #define CMP_PTE_USER_WRITE(pte, tmp, label) \
1351: label: b,a 1f; \
1.94 pk 1352: CMP_PTE_USER_WRITE4M(pte,tmp); \
1.62 pk 1353: b,a 2f; \
1354: 1: \
1355: CMP_PTE_USER_WRITE4_4C(pte); \
1356: 2:
1.52 pk 1357: #endif
1358:
1359:
1360: /*
1.1 deraadt 1361: * The calculations in PTE_OF_ADDR and CMP_PTE_USER_* are rather slow:
1362: * in particular, according to Gordon Irlam of the University of Adelaide
1363: * in Australia, these consume at least 18 cycles on an SS1 and 37 on an
1364: * SS2. Hence, we try to avoid them in the common case.
1365: *
1366: * A chunk of 64 bytes is on a single page if and only if:
1367: *
1.13 deraadt 1368: * ((base + 64 - 1) & ~(NBPG-1)) == (base & ~(NBPG-1))
1.1 deraadt 1369: *
1370: * Equivalently (and faster to test), the low order bits (base & 4095) must
1371: * be small enough so that the sum (base + 63) does not carry out into the
1372: * upper page-address bits, i.e.,
1373: *
1.13 deraadt 1374: * (base & (NBPG-1)) < (NBPG - 63)
1.1 deraadt 1375: *
1376: * so we allow testing that here. This macro is also assumed to be safe
1377: * in a delay slot (modulo overwriting its temporary).
1378: */
1.13 deraadt 1379: #define SLT_IF_1PAGE_RW(addr, tmp, page_offset) \
1380: and addr, page_offset, tmp; \
1381: sub page_offset, 62, page_offset; \
1382: cmp tmp, page_offset
1.1 deraadt 1383:
1384: /*
1385: * Every trap that enables traps must set up stack space.
1386: * If the trap is from user mode, this involves switching to the kernel
1387: * stack for the current process, and we must also set cpcb->pcb_uw
1388: * so that the window overflow handler can tell user windows from kernel
1389: * windows.
1390: *
1391: * The number of user windows is:
1392: *
1393: * cpcb->pcb_uw = (cpcb->pcb_wim - 1 - CWP) % nwindows
1394: *
1395: * (where pcb_wim = log2(current %wim) and CWP = low 5 bits of %psr).
1396: * We compute this expression by table lookup in uwtab[CWP - pcb_wim],
1397: * which has been set up as:
1398: *
1399: * for i in [-nwin+1 .. nwin-1]
1400: * uwtab[i] = (nwin - 1 - i) % nwin;
1401: *
1402: * (If you do not believe this works, try it for yourself.)
1403: *
1404: * We also keep one or two more tables:
1405: *
1406: * for i in 0..nwin-1
1407: * wmask[i] = 1 << ((i + 1) % nwindows);
1408: *
1409: * wmask[CWP] tells whether a `rett' would return into the invalid window.
1410: */
1411: .data
1412: .skip 32 ! alignment byte & negative indicies
1413: uwtab: .skip 32 ! u_char uwtab[-31..31];
1414: wmask: .skip 32 ! u_char wmask[0..31];
1415:
1416: .text
1417: /*
1418: * Things begin to grow uglier....
1419: *
1420: * Each trap handler may (always) be running in the trap window.
1421: * If this is the case, it cannot enable further traps until it writes
1422: * the register windows into the stack (or, if the stack is no good,
1423: * the current pcb).
1424: *
1425: * ASSUMPTIONS: TRAP_SETUP() is called with:
1426: * %l0 = %psr
1427: * %l1 = return pc
1428: * %l2 = return npc
1429: * %l3 = (some value that must not be altered)
1430: * which means we have 4 registers to work with.
1431: *
1432: * The `stackspace' argument is the number of stack bytes to allocate
1433: * for register-saving, and must be at least -64 (and typically more,
1434: * for global registers and %y).
1435: *
1436: * Trapframes should use -CCFSZ-80. (80 = sizeof(struct trapframe);
1437: * see trap.h. This basically means EVERYONE. Interrupt frames could
1438: * get away with less, but currently do not.)
1439: *
1440: * The basic outline here is:
1441: *
1442: * if (trap came from kernel mode) {
1443: * if (we are in the trap window)
1444: * save it away;
1445: * %sp = %fp - stackspace;
1446: * } else {
1447: * compute the number of user windows;
1448: * if (we are in the trap window)
1449: * save it away;
1450: * %sp = (top of kernel stack) - stackspace;
1451: * }
1452: *
1453: * Again, the number of user windows is:
1454: *
1455: * cpcb->pcb_uw = (cpcb->pcb_wim - 1 - CWP) % nwindows
1456: *
1457: * (where pcb_wim = log2(current %wim) and CWP is the low 5 bits of %psr),
1458: * and this is computed as `uwtab[CWP - pcb_wim]'.
1459: *
1460: * NOTE: if you change this code, you will have to look carefully
1461: * at the window overflow and underflow handlers and make sure they
1462: * have similar changes made as needed.
1463: */
1464: #define CALL_CLEAN_TRAP_WINDOW \
1465: sethi %hi(clean_trap_window), %l7; \
1466: jmpl %l7 + %lo(clean_trap_window), %l4; \
1467: mov %g7, %l7 /* save %g7 in %l7 for clean_trap_window */
1468:
1469: #define TRAP_SETUP(stackspace) \
1470: rd %wim, %l4; \
1471: mov 1, %l5; \
1472: sll %l5, %l0, %l5; \
1473: btst PSR_PS, %l0; \
1474: bz 1f; \
1475: btst %l5, %l4; \
1476: /* came from kernel mode; cond codes indicate trap window */ \
1477: bz,a 3f; \
1478: add %fp, stackspace, %sp; /* want to just set %sp */ \
1479: CALL_CLEAN_TRAP_WINDOW; /* but maybe need to clean first */ \
1480: b 3f; \
1481: add %fp, stackspace, %sp; \
1482: 1: \
1483: /* came from user mode: compute pcb_nw */ \
1.111 pk 1484: sethi %hi(cpcb), %l6; \
1485: ld [%l6 + %lo(cpcb)], %l6; \
1.1 deraadt 1486: ld [%l6 + PCB_WIM], %l5; \
1487: and %l0, 31, %l4; \
1488: sub %l4, %l5, %l5; \
1489: set uwtab, %l4; \
1490: ldub [%l4 + %l5], %l5; \
1491: st %l5, [%l6 + PCB_UW]; \
1492: /* cond codes still indicate whether in trap window */ \
1493: bz,a 2f; \
1.13 deraadt 1494: sethi %hi(USPACE+(stackspace)), %l5; \
1.1 deraadt 1495: /* yes, in trap window; must clean it */ \
1496: CALL_CLEAN_TRAP_WINDOW; \
1.111 pk 1497: sethi %hi(cpcb), %l6; \
1498: ld [%l6 + %lo(cpcb)], %l6; \
1.13 deraadt 1499: sethi %hi(USPACE+(stackspace)), %l5; \
1.1 deraadt 1500: 2: \
1501: /* trap window is (now) clean: set %sp */ \
1.13 deraadt 1502: or %l5, %lo(USPACE+(stackspace)), %l5; \
1.1 deraadt 1503: add %l6, %l5, %sp; \
1504: SET_SP_REDZONE(%l6, %l5); \
1505: 3: \
1506: CHECK_SP_REDZONE(%l6, %l5)
1507:
1508: /*
1509: * Interrupt setup is almost exactly like trap setup, but we need to
1510: * go to the interrupt stack if (a) we came from user mode or (b) we
1511: * came from kernel mode on the kernel stack.
1512: */
1.142 mrg 1513: #if defined(MULTIPROCESSOR)
1.98 pk 1514: /*
1515: * SMP kernels: read `eintstack' from cpuinfo structure. Since the
1516: * location of the interrupt stack is not known in advance, we need
1517: * to check the current %fp against both ends of the stack space.
1518: */
1.97 pk 1519: #define INTR_SETUP(stackspace) \
1520: rd %wim, %l4; \
1521: mov 1, %l5; \
1522: sll %l5, %l0, %l5; \
1523: btst PSR_PS, %l0; \
1524: bz 1f; \
1525: btst %l5, %l4; \
1526: /* came from kernel mode; cond codes still indicate trap window */ \
1527: bz,a 0f; \
1.101 pk 1528: sethi %hi(_EINTSTACKP), %l7; \
1.97 pk 1529: CALL_CLEAN_TRAP_WINDOW; \
1.101 pk 1530: sethi %hi(_EINTSTACKP), %l7; \
1.97 pk 1531: 0: /* now if not intstack > %fp >= eintstack, we were on the kernel stack */ \
1.101 pk 1532: ld [%l7 + %lo(_EINTSTACKP)], %l7; \
1.97 pk 1533: cmp %fp, %l7; \
1534: bge,a 3f; /* %fp >= eintstack */ \
1535: add %l7, stackspace, %sp; /* so switch to intstack */ \
1536: sethi %hi(INT_STACK_SIZE), %l6; \
1.98 pk 1537: sub %l7, %l6, %l6; \
1538: cmp %fp, %l6; \
1.97 pk 1539: blu,a 3f; /* %fp < intstack */ \
1540: add %l7, stackspace, %sp; /* so switch to intstack */ \
1541: b 4f; \
1542: add %fp, stackspace, %sp; /* else stay on intstack */ \
1543: 1: \
1544: /* came from user mode: compute pcb_nw */ \
1.111 pk 1545: sethi %hi(cpcb), %l6; \
1546: ld [%l6 + %lo(cpcb)], %l6; \
1.97 pk 1547: ld [%l6 + PCB_WIM], %l5; \
1548: and %l0, 31, %l4; \
1549: sub %l4, %l5, %l5; \
1550: set uwtab, %l4; \
1551: ldub [%l4 + %l5], %l5; \
1552: st %l5, [%l6 + PCB_UW]; \
1553: /* cond codes still indicate whether in trap window */ \
1554: bz,a 2f; \
1.101 pk 1555: sethi %hi(_EINTSTACKP), %l7; \
1.97 pk 1556: /* yes, in trap window; must save regs */ \
1557: CALL_CLEAN_TRAP_WINDOW; \
1.101 pk 1558: sethi %hi(_EINTSTACKP), %l7; \
1.97 pk 1559: 2: \
1.101 pk 1560: ld [%l7 + %lo(_EINTSTACKP)], %l7; \
1.97 pk 1561: add %l7, stackspace, %sp; \
1562: 3: \
1.101 pk 1563: SET_SP_REDZONE_VAR(_EINTSTACKP, -INT_STACK_SIZE, %l6, %l5); \
1.97 pk 1564: 4: \
1565: CHECK_SP_REDZONE(%l6, %l5)
1.98 pk 1566:
1.97 pk 1567: #else /* MULTIPROCESSOR */
1.98 pk 1568:
1.1 deraadt 1569: #define INTR_SETUP(stackspace) \
1570: rd %wim, %l4; \
1571: mov 1, %l5; \
1572: sll %l5, %l0, %l5; \
1573: btst PSR_PS, %l0; \
1574: bz 1f; \
1575: btst %l5, %l4; \
1576: /* came from kernel mode; cond codes still indicate trap window */ \
1577: bz,a 0f; \
1.111 pk 1578: sethi %hi(_C_LABEL(eintstack)), %l7; \
1.1 deraadt 1579: CALL_CLEAN_TRAP_WINDOW; \
1.111 pk 1580: sethi %hi(_C_LABEL(eintstack)), %l7; \
1.1 deraadt 1581: 0: /* now if %fp >= eintstack, we were on the kernel stack */ \
1582: cmp %fp, %l7; \
1583: bge,a 3f; \
1584: add %l7, stackspace, %sp; /* so switch to intstack */ \
1585: b 4f; \
1586: add %fp, stackspace, %sp; /* else stay on intstack */ \
1587: 1: \
1588: /* came from user mode: compute pcb_nw */ \
1.111 pk 1589: sethi %hi(cpcb), %l6; \
1590: ld [%l6 + %lo(cpcb)], %l6; \
1.1 deraadt 1591: ld [%l6 + PCB_WIM], %l5; \
1592: and %l0, 31, %l4; \
1593: sub %l4, %l5, %l5; \
1594: set uwtab, %l4; \
1595: ldub [%l4 + %l5], %l5; \
1596: st %l5, [%l6 + PCB_UW]; \
1597: /* cond codes still indicate whether in trap window */ \
1598: bz,a 2f; \
1.111 pk 1599: sethi %hi(_C_LABEL(eintstack)), %l7; \
1.1 deraadt 1600: /* yes, in trap window; must save regs */ \
1601: CALL_CLEAN_TRAP_WINDOW; \
1.111 pk 1602: sethi %hi(_C_LABEL(eintstack)), %l7; \
1.1 deraadt 1603: 2: \
1604: add %l7, stackspace, %sp; \
1605: 3: \
1.111 pk 1606: SET_SP_REDZONE_CONST(_C_LABEL(intstack), %l6, %l5); \
1.1 deraadt 1607: 4: \
1608: CHECK_SP_REDZONE(%l6, %l5)
1.97 pk 1609: #endif /* MULTIPROCESSOR */
1.1 deraadt 1610:
1611: /*
1612: * Handler for making the trap window shiny clean.
1613: *
1614: * On entry:
1615: * cpcb->pcb_nw = number of user windows
1616: * %l0 = %psr
1617: * %l1 must not be clobbered
1618: * %l2 must not be clobbered
1619: * %l3 must not be clobbered
1620: * %l4 = address for `return'
1621: * %l7 = saved %g7 (we put this in a delay slot above, to save work)
1622: *
1623: * On return:
1624: * %wim has changed, along with cpcb->pcb_wim
1625: * %g7 has been restored
1626: *
1627: * Normally, we push only one window.
1628: */
1629: clean_trap_window:
1630: mov %g5, %l5 ! save %g5
1631: mov %g6, %l6 ! ... and %g6
1632: /* mov %g7, %l7 ! ... and %g7 (already done for us) */
1.111 pk 1633: sethi %hi(cpcb), %g6 ! get current pcb
1634: ld [%g6 + %lo(cpcb)], %g6
1.1 deraadt 1635:
1636: /* Figure out whether it is a user window (cpcb->pcb_uw > 0). */
1637: ld [%g6 + PCB_UW], %g7
1638: deccc %g7
1639: bge ctw_user
1640: save %g0, %g0, %g0 ! in any case, enter window to save
1641:
1642: /* The window to be pushed is a kernel window. */
1643: std %l0, [%sp + (0*8)]
1644: ctw_merge:
1645: std %l2, [%sp + (1*8)]
1646: std %l4, [%sp + (2*8)]
1647: std %l6, [%sp + (3*8)]
1648: std %i0, [%sp + (4*8)]
1649: std %i2, [%sp + (5*8)]
1650: std %i4, [%sp + (6*8)]
1651: std %i6, [%sp + (7*8)]
1652:
1653: /* Set up new window invalid mask, and update cpcb->pcb_wim. */
1654: rd %psr, %g7 ! g7 = (junk << 5) + new_cwp
1655: mov 1, %g5 ! g5 = 1 << new_cwp;
1656: sll %g5, %g7, %g5
1657: wr %g5, 0, %wim ! setwim(g5);
1658: and %g7, 31, %g7 ! cpcb->pcb_wim = g7 & 31;
1.111 pk 1659: sethi %hi(cpcb), %g6 ! re-get current pcb
1660: ld [%g6 + %lo(cpcb)], %g6
1.1 deraadt 1661: st %g7, [%g6 + PCB_WIM]
1662: nop
1663: restore ! back to trap window
1664:
1665: mov %l5, %g5 ! restore g5
1666: mov %l6, %g6 ! ... and g6
1667: jmp %l4 + 8 ! return to caller
1668: mov %l7, %g7 ! ... and g7
1669: /* NOTREACHED */
1670:
1671: ctw_user:
1672: /*
1673: * The window to be pushed is a user window.
1674: * We must verify the stack pointer (alignment & permissions).
1675: * See comments above definition of PTE_OF_ADDR.
1676: */
1677: st %g7, [%g6 + PCB_UW] ! cpcb->pcb_uw--;
1678: btst 7, %sp ! if not aligned,
1679: bne ctw_invalid ! choke on it
1680: EMPTY
1.13 deraadt 1681:
1.111 pk 1682: sethi %hi(_C_LABEL(pgofset)), %g6 ! trash %g6=curpcb
1683: ld [%g6 + %lo(_C_LABEL(pgofset))], %g6
1.62 pk 1684: PTE_OF_ADDR(%sp, %g7, ctw_invalid, %g6, NOP_ON_4M_1)
1685: CMP_PTE_USER_WRITE(%g7, %g5, NOP_ON_4M_2) ! likewise if not writable
1.1 deraadt 1686: bne ctw_invalid
1687: EMPTY
1.52 pk 1688: /* Note side-effect of SLT_IF_1PAGE_RW: decrements %g6 by 62 */
1.13 deraadt 1689: SLT_IF_1PAGE_RW(%sp, %g7, %g6)
1.1 deraadt 1690: bl,a ctw_merge ! all ok if only 1
1691: std %l0, [%sp]
1692: add %sp, 7*8, %g5 ! check last addr too
1.154 thorpej 1693: add %g6, 62, %g6 /* restore %g6 to `pgofset' */
1.62 pk 1694: PTE_OF_ADDR(%g5, %g7, ctw_invalid, %g6, NOP_ON_4M_3)
1695: CMP_PTE_USER_WRITE(%g7, %g6, NOP_ON_4M_4)
1.1 deraadt 1696: be,a ctw_merge ! all ok: store <l0,l1> and merge
1697: std %l0, [%sp]
1698:
1699: /*
1700: * The window we wanted to push could not be pushed.
1701: * Instead, save ALL user windows into the pcb.
1702: * We will notice later that we did this, when we
1703: * get ready to return from our trap or syscall.
1704: *
1705: * The code here is run rarely and need not be optimal.
1706: */
1707: ctw_invalid:
1708: /*
1709: * Reread cpcb->pcb_uw. We decremented this earlier,
1710: * so it is off by one.
1711: */
1.111 pk 1712: sethi %hi(cpcb), %g6 ! re-get current pcb
1713: ld [%g6 + %lo(cpcb)], %g6
1.13 deraadt 1714:
1.1 deraadt 1715: ld [%g6 + PCB_UW], %g7 ! (number of user windows) - 1
1716: add %g6, PCB_RW, %g5
1717:
1718: /* save g7+1 windows, starting with the current one */
1719: 1: ! do {
1720: std %l0, [%g5 + (0*8)] ! rw->rw_local[0] = l0;
1721: std %l2, [%g5 + (1*8)] ! ...
1722: std %l4, [%g5 + (2*8)]
1723: std %l6, [%g5 + (3*8)]
1724: std %i0, [%g5 + (4*8)]
1725: std %i2, [%g5 + (5*8)]
1726: std %i4, [%g5 + (6*8)]
1727: std %i6, [%g5 + (7*8)]
1728: deccc %g7 ! if (n > 0) save(), rw++;
1729: bge,a 1b ! } while (--n >= 0);
1730: save %g5, 64, %g5
1731:
1732: /* stash sp for bottommost window */
1733: st %sp, [%g5 + 64 + (7*8)]
1734:
1735: /* set up new wim */
1736: rd %psr, %g7 ! g7 = (junk << 5) + new_cwp;
1737: mov 1, %g5 ! g5 = 1 << new_cwp;
1738: sll %g5, %g7, %g5
1739: wr %g5, 0, %wim ! wim = g5;
1740: and %g7, 31, %g7
1741: st %g7, [%g6 + PCB_WIM] ! cpcb->pcb_wim = new_cwp;
1742:
1743: /* fix up pcb fields */
1744: ld [%g6 + PCB_UW], %g7 ! n = cpcb->pcb_uw;
1745: add %g7, 1, %g5
1746: st %g5, [%g6 + PCB_NSAVED] ! cpcb->pcb_nsaved = n + 1;
1747: st %g0, [%g6 + PCB_UW] ! cpcb->pcb_uw = 0;
1748:
1749: /* return to trap window */
1750: 1: deccc %g7 ! do {
1751: bge 1b ! restore();
1752: restore ! } while (--n >= 0);
1753:
1754: mov %l5, %g5 ! restore g5, g6, & g7, and return
1755: mov %l6, %g6
1756: jmp %l4 + 8
1757: mov %l7, %g7
1758: /* NOTREACHED */
1759:
1760:
1761: /*
1762: * Each memory access (text or data) fault, from user or kernel mode,
1763: * comes here. We read the error register and figure out what has
1764: * happened.
1765: *
1766: * This cannot be done from C code since we must not enable traps (and
1767: * hence may not use the `save' instruction) until we have decided that
1768: * the error is or is not an asynchronous one that showed up after a
1769: * synchronous error, but which must be handled before the sync err.
1770: *
1771: * Most memory faults are user mode text or data faults, which can cause
1772: * signal delivery or ptracing, for which we must build a full trapframe.
1773: * It does not seem worthwhile to work to avoid this in the other cases,
1774: * so we store all the %g registers on the stack immediately.
1775: *
1776: * On entry:
1777: * %l0 = %psr
1778: * %l1 = return pc
1779: * %l2 = return npc
1780: * %l3 = T_TEXTFAULT or T_DATAFAULT
1781: *
1782: * Internal:
1783: * %l4 = %y, until we call mem_access_fault (then onto trapframe)
1784: * %l5 = IE_reg_addr, if async mem error
1785: *
1786: */
1.52 pk 1787:
1788: #if defined(SUN4)
1789: memfault_sun4:
1.1 deraadt 1790: TRAP_SETUP(-CCFSZ-80)
1.111 pk 1791: INCR(_C_LABEL(uvmexp)+V_FAULTS) ! cnt.v_faults++ (clobbers %o0,%o1)
1.1 deraadt 1792:
1793: st %g1, [%sp + CCFSZ + 20] ! save g1
1794: rd %y, %l4 ! save y
1795:
1.19 deraadt 1796: /*
1797: * registers:
1798: * memerr.ctrl = memory error control reg., error if 0x80 set
1799: * memerr.vaddr = address of memory error
1800: * buserr = basically just like sun4c sync error reg but
1801: * no SER_WRITE bit (have to figure out from code).
1802: */
1.111 pk 1803: set _C_LABEL(par_err_reg), %o0 ! memerr ctrl addr -- XXX mapped?
1.20 deraadt 1804: ld [%o0], %o0 ! get it
1.19 deraadt 1805: std %g2, [%sp + CCFSZ + 24] ! save g2, g3
1806: ld [%o0], %o1 ! memerr ctrl register
1807: inc 4, %o0 ! now VA of memerr vaddr register
1808: std %g4, [%sp + CCFSZ + 32] ! (sneak g4,g5 in here)
1809: ld [%o0], %o2 ! memerr virt addr
1810: st %g0, [%o0] ! NOTE: this clears latching!!!
1811: btst ME_REG_IERR, %o1 ! memory error?
1812: ! XXX this value may not be correct
1813: ! as I got some parity errors and the
1814: ! correct bits were not on?
1815: std %g6, [%sp + CCFSZ + 40]
1.52 pk 1816: bz,a 0f ! no, just a regular fault
1.19 deraadt 1817: wr %l0, PSR_ET, %psr ! (and reenable traps)
1818:
1819: /* memory error = death for now XXX */
1820: clr %o3
1821: clr %o4
1.111 pk 1822: call _C_LABEL(memerr4_4c) ! memerr(0, ser, sva, 0, 0)
1.19 deraadt 1823: clr %o0
1.111 pk 1824: call _C_LABEL(prom_halt)
1.19 deraadt 1825: nop
1826:
1.52 pk 1827: 0:
1.19 deraadt 1828: /*
1829: * have to make SUN4 emulate SUN4C. 4C code expects
1830: * SER in %o1 and the offending VA in %o2, everything else is ok.
1831: * (must figure out if SER_WRITE should be set)
1832: */
1833: set AC_BUS_ERR, %o0 ! bus error register
1834: cmp %l3, T_TEXTFAULT ! text fault always on PC
1.50 pk 1835: be normal_mem_fault ! go
1.21 deraadt 1836: lduba [%o0] ASI_CONTROL, %o1 ! get its value
1.19 deraadt 1837:
1838: #define STORE_BIT 21 /* bit that indicates a store instruction for sparc */
1839: ld [%l1], %o3 ! offending instruction in %o3 [l1=pc]
1840: srl %o3, STORE_BIT, %o3 ! get load/store bit (wont fit simm13)
1841: btst 1, %o3 ! test for store operation
1842:
1843: bz normal_mem_fault ! if (z) is a load (so branch)
1844: sethi %hi(SER_WRITE), %o5 ! damn SER_WRITE wont fit simm13
1845: ! or %lo(SER_WRITE), %o5, %o5! not necessary since %lo is zero
1846: or %o5, %o1, %o1 ! set SER_WRITE
1847: #if defined(SUN4C) || defined(SUN4M)
1.52 pk 1848: ba,a normal_mem_fault
1849: !!nop ! XXX make efficient later
1.19 deraadt 1850: #endif /* SUN4C || SUN4M */
1851: #endif /* SUN4 */
1.52 pk 1852:
1853: memfault_sun4c:
1854: #if defined(SUN4C)
1855: TRAP_SETUP(-CCFSZ-80)
1.111 pk 1856: INCR(_C_LABEL(uvmexp)+V_FAULTS) ! cnt.v_faults++ (clobbers %o0,%o1)
1.52 pk 1857:
1858: st %g1, [%sp + CCFSZ + 20] ! save g1
1859: rd %y, %l4 ! save y
1860:
1861: /*
1862: * We know about the layout of the error registers here.
1863: * addr reg
1864: * ---- ---
1865: * a AC_SYNC_ERR
1866: * a+4 AC_SYNC_VA
1867: * a+8 AC_ASYNC_ERR
1868: * a+12 AC_ASYNC_VA
1869: */
1.19 deraadt 1870:
1.1 deraadt 1871: #if AC_SYNC_ERR + 4 != AC_SYNC_VA || \
1872: AC_SYNC_ERR + 8 != AC_ASYNC_ERR || AC_SYNC_ERR + 12 != AC_ASYNC_VA
1873: help help help ! I, I, I wanna be a lifeguard
1874: #endif
1875: set AC_SYNC_ERR, %o0
1876: std %g2, [%sp + CCFSZ + 24] ! save g2, g3
1877: lda [%o0] ASI_CONTROL, %o1 ! sync err reg
1878: inc 4, %o0
1879: std %g4, [%sp + CCFSZ + 32] ! (sneak g4,g5 in here)
1880: lda [%o0] ASI_CONTROL, %o2 ! sync virt addr
1881: btst SER_MEMERR, %o1 ! memory error?
1882: std %g6, [%sp + CCFSZ + 40]
1883: bz,a normal_mem_fault ! no, just a regular fault
1884: wr %l0, PSR_ET, %psr ! (and reenable traps)
1885:
1886: /*
1887: * We got a synchronous memory error. It could be one that
1888: * happened because there were two stores in a row, and the
1889: * first went into the write buffer, and the second caused this
1890: * synchronous trap; so there could now be a pending async error.
1891: * This is in fact the case iff the two va's differ.
1892: */
1893: inc 4, %o0
1894: lda [%o0] ASI_CONTROL, %o3 ! async err reg
1895: inc 4, %o0
1896: lda [%o0] ASI_CONTROL, %o4 ! async virt addr
1897: cmp %o2, %o4
1898: be,a 1f ! no, not an async err
1899: wr %l0, PSR_ET, %psr ! (and reenable traps)
1900:
1901: /*
1902: * Handle the async error; ignore the sync error for now
1903: * (we may end up getting it again, but so what?).
1904: * This code is essentially the same as that at `nmi' below,
1905: * but the register usage is different and we cannot merge.
1906: */
1.62 pk 1907: sethi %hi(INTRREG_VA), %l5 ! ienab_bic(IE_ALLIE);
1908: ldub [%l5 + %lo(INTRREG_VA)], %o0
1.1 deraadt 1909: andn %o0, IE_ALLIE, %o0
1.62 pk 1910: stb %o0, [%l5 + %lo(INTRREG_VA)]
1.1 deraadt 1911:
1912: /*
1913: * Now reenable traps and call C code.
1914: * %o1 through %o4 still hold the error reg contents.
1915: * If memerr() returns, return from the trap.
1916: */
1917: wr %l0, PSR_ET, %psr
1.111 pk 1918: call _C_LABEL(memerr4_4c) ! memerr(0, ser, sva, aer, ava)
1.1 deraadt 1919: clr %o0
1920:
1921: ld [%sp + CCFSZ + 20], %g1 ! restore g1 through g7
1922: wr %l0, 0, %psr ! and disable traps, 3 instr delay
1923: ldd [%sp + CCFSZ + 24], %g2
1924: ldd [%sp + CCFSZ + 32], %g4
1925: ldd [%sp + CCFSZ + 40], %g6
1926: /* now safe to set IE_ALLIE again */
1.62 pk 1927: ldub [%l5 + %lo(INTRREG_VA)], %o1
1.1 deraadt 1928: or %o1, IE_ALLIE, %o1
1.62 pk 1929: stb %o1, [%l5 + %lo(INTRREG_VA)]
1.1 deraadt 1930: b return_from_trap
1931: wr %l4, 0, %y ! restore y
1932:
1933: /*
1934: * Trap was a synchronous memory error.
1935: * %o1 through %o4 still hold the error reg contents.
1936: */
1937: 1:
1.111 pk 1938: call _C_LABEL(memerr4_4c) ! memerr(1, ser, sva, aer, ava)
1.1 deraadt 1939: mov 1, %o0
1940:
1941: ld [%sp + CCFSZ + 20], %g1 ! restore g1 through g7
1942: ldd [%sp + CCFSZ + 24], %g2
1943: ldd [%sp + CCFSZ + 32], %g4
1944: ldd [%sp + CCFSZ + 40], %g6
1945: wr %l4, 0, %y ! restore y
1946: b return_from_trap
1947: wr %l0, 0, %psr
1948: /* NOTREACHED */
1.52 pk 1949: #endif /* SUN4C */
1950:
1951: #if defined(SUN4M)
1952: memfault_sun4m:
1.94 pk 1953: ! DANGER: we use the fact that %lo(CPUINFO_VA) is zero
1954: .if CPUINFO_VA & 0x1fff
1955: BARF
1956: .endif
1957: sethi %hi(CPUINFO_VA), %l4
1958: ld [%l4 + %lo(CPUINFO_VA+CPUINFO_GETSYNCFLT)], %l5
1959: jmpl %l5, %l7
1960: or %l4, %lo(CPUINFO_SYNCFLTDUMP), %l4
1.52 pk 1961: TRAP_SETUP(-CCFSZ-80)
1.111 pk 1962: INCR(_C_LABEL(uvmexp)+V_FAULTS) ! cnt.v_faults++ (clobbers %o0,%o1)
1.52 pk 1963:
1964: st %g1, [%sp + CCFSZ + 20] ! save g1
1965: rd %y, %l4 ! save y
1966:
1967: std %g2, [%sp + CCFSZ + 24] ! save g2, g3
1.62 pk 1968: std %g4, [%sp + CCFSZ + 32] ! save g4, g5
1.94 pk 1969: std %g6, [%sp + CCFSZ + 40] ! sneak in g6, g7
1.52 pk 1970:
1.94 pk 1971: ! retrieve sync fault status/address
1972: sethi %hi(CPUINFO_VA+CPUINFO_SYNCFLTDUMP), %o0
1973: ld [%o0 + %lo(CPUINFO_VA+CPUINFO_SYNCFLTDUMP)], %o1
1974: ld [%o0 + %lo(CPUINFO_VA+CPUINFO_SYNCFLTDUMP+4)], %o2
1.52 pk 1975:
1976: wr %l0, PSR_ET, %psr ! reenable traps
1977:
1978: /* Finish stackframe, call C trap handler */
1979: std %l0, [%sp + CCFSZ + 0] ! set tf.tf_psr, tf.tf_pc
1980: mov %l3, %o0 ! (argument: type)
1981: st %l2, [%sp + CCFSZ + 8] ! set tf.tf_npc
1982: st %l4, [%sp + CCFSZ + 12] ! set tf.tf_y
1983: std %i0, [%sp + CCFSZ + 48] ! tf.tf_out[0], etc
1984: std %i2, [%sp + CCFSZ + 56]
1985: std %i4, [%sp + CCFSZ + 64]
1986: std %i6, [%sp + CCFSZ + 72]
1.111 pk 1987: ! mem_access_fault(type,sfsr,sfva,&tf);
1988: call _C_LABEL(mem_access_fault4m)
1.94 pk 1989: add %sp, CCFSZ, %o3 ! (argument: &tf)
1.52 pk 1990:
1991: ldd [%sp + CCFSZ + 0], %l0 ! load new values
1992: ldd [%sp + CCFSZ + 8], %l2
1993: wr %l3, 0, %y
1994: ld [%sp + CCFSZ + 20], %g1
1995: ldd [%sp + CCFSZ + 24], %g2
1996: ldd [%sp + CCFSZ + 32], %g4
1997: ldd [%sp + CCFSZ + 40], %g6
1998: ldd [%sp + CCFSZ + 48], %i0
1999: ldd [%sp + CCFSZ + 56], %i2
2000: ldd [%sp + CCFSZ + 64], %i4
2001: ldd [%sp + CCFSZ + 72], %i6
2002:
2003: b return_from_trap ! go return
2004: wr %l0, 0, %psr ! (but first disable traps again)
2005: #endif /* SUN4M */
1.1 deraadt 2006:
2007: normal_mem_fault:
2008: /*
2009: * Trap was some other error; call C code to deal with it.
2010: * Must finish trap frame (psr,pc,npc,%y,%o0..%o7) in case
2011: * we decide to deliver a signal or ptrace the process.
2012: * %g1..%g7 were already set up above.
2013: */
2014: std %l0, [%sp + CCFSZ + 0] ! set tf.tf_psr, tf.tf_pc
2015: mov %l3, %o0 ! (argument: type)
2016: st %l2, [%sp + CCFSZ + 8] ! set tf.tf_npc
2017: st %l4, [%sp + CCFSZ + 12] ! set tf.tf_y
2018: mov %l1, %o3 ! (argument: pc)
2019: std %i0, [%sp + CCFSZ + 48] ! tf.tf_out[0], etc
2020: std %i2, [%sp + CCFSZ + 56]
2021: mov %l0, %o4 ! (argument: psr)
2022: std %i4, [%sp + CCFSZ + 64]
2023: std %i6, [%sp + CCFSZ + 72]
1.111 pk 2024: call _C_LABEL(mem_access_fault)! mem_access_fault(type, ser, sva,
1.1 deraadt 2025: ! pc, psr, &tf);
2026: add %sp, CCFSZ, %o5 ! (argument: &tf)
2027:
2028: ldd [%sp + CCFSZ + 0], %l0 ! load new values
2029: ldd [%sp + CCFSZ + 8], %l2
2030: wr %l3, 0, %y
2031: ld [%sp + CCFSZ + 20], %g1
2032: ldd [%sp + CCFSZ + 24], %g2
2033: ldd [%sp + CCFSZ + 32], %g4
2034: ldd [%sp + CCFSZ + 40], %g6
2035: ldd [%sp + CCFSZ + 48], %i0
2036: ldd [%sp + CCFSZ + 56], %i2
2037: ldd [%sp + CCFSZ + 64], %i4
2038: ldd [%sp + CCFSZ + 72], %i6
2039:
2040: b return_from_trap ! go return
2041: wr %l0, 0, %psr ! (but first disable traps again)
2042:
2043:
2044: /*
2045: * fp_exception has to check to see if we are trying to save
2046: * the FP state, and if so, continue to save the FP state.
2047: *
2048: * We do not even bother checking to see if we were in kernel mode,
2049: * since users have no access to the special_fp_store instruction.
2050: *
2051: * This whole idea was stolen from Sprite.
2052: */
2053: fp_exception:
2054: set special_fp_store, %l4 ! see if we came from the special one
2055: cmp %l1, %l4 ! pc == special_fp_store?
2056: bne slowtrap ! no, go handle per usual
2057: EMPTY
2058: sethi %hi(savefpcont), %l4 ! yes, "return" to the special code
2059: or %lo(savefpcont), %l4, %l4
2060: jmp %l4
2061: rett %l4 + 4
2062:
2063: /*
2064: * slowtrap() builds a trap frame and calls trap().
2065: * This is called `slowtrap' because it *is*....
2066: * We have to build a full frame for ptrace(), for instance.
2067: *
2068: * Registers:
2069: * %l0 = %psr
2070: * %l1 = return pc
2071: * %l2 = return npc
2072: * %l3 = trap code
2073: */
2074: slowtrap:
2075: TRAP_SETUP(-CCFSZ-80)
2076: /*
2077: * Phew, ready to enable traps and call C code.
2078: */
2079: mov %l3, %o0 ! put type in %o0 for later
2080: Lslowtrap_reenter:
2081: wr %l0, PSR_ET, %psr ! traps on again
2082: std %l0, [%sp + CCFSZ] ! tf.tf_psr = psr; tf.tf_pc = ret_pc;
2083: rd %y, %l3
2084: std %l2, [%sp + CCFSZ + 8] ! tf.tf_npc = return_npc; tf.tf_y = %y;
2085: st %g1, [%sp + CCFSZ + 20]
2086: std %g2, [%sp + CCFSZ + 24]
2087: std %g4, [%sp + CCFSZ + 32]
2088: std %g6, [%sp + CCFSZ + 40]
2089: std %i0, [%sp + CCFSZ + 48]
2090: mov %l0, %o1 ! (psr)
2091: std %i2, [%sp + CCFSZ + 56]
2092: mov %l1, %o2 ! (pc)
2093: std %i4, [%sp + CCFSZ + 64]
2094: add %sp, CCFSZ, %o3 ! (&tf)
1.111 pk 2095: call _C_LABEL(trap) ! trap(type, psr, pc, &tf)
1.1 deraadt 2096: std %i6, [%sp + CCFSZ + 72]
2097:
2098: ldd [%sp + CCFSZ], %l0 ! load new values
2099: ldd [%sp + CCFSZ + 8], %l2
2100: wr %l3, 0, %y
2101: ld [%sp + CCFSZ + 20], %g1
2102: ldd [%sp + CCFSZ + 24], %g2
2103: ldd [%sp + CCFSZ + 32], %g4
2104: ldd [%sp + CCFSZ + 40], %g6
2105: ldd [%sp + CCFSZ + 48], %i0
2106: ldd [%sp + CCFSZ + 56], %i2
2107: ldd [%sp + CCFSZ + 64], %i4
2108: ldd [%sp + CCFSZ + 72], %i6
2109: b return_from_trap
2110: wr %l0, 0, %psr
2111:
2112: /*
2113: * Do a `software' trap by re-entering the trap code, possibly first
2114: * switching from interrupt stack to kernel stack. This is used for
2115: * scheduling and signal ASTs (which generally occur from softclock or
2116: * tty or net interrupts) and register window saves (which might occur
2117: * from anywhere).
2118: *
2119: * The current window is the trap window, and it is by definition clean.
2120: * We enter with the trap type in %o0. All we have to do is jump to
2121: * Lslowtrap_reenter above, but maybe after switching stacks....
2122: */
2123: softtrap:
1.142 mrg 2124: #if defined(MULTIPROCESSOR)
1.97 pk 2125: /*
2126: * The interrupt stack is not at a fixed location
2127: * and %sp must be checked against both ends.
2128: */
1.101 pk 2129: sethi %hi(_EINTSTACKP), %l7
2130: ld [%l7 + %lo(_EINTSTACKP)], %l7
1.97 pk 2131: cmp %sp, %l7
2132: bge Lslowtrap_reenter
2133: EMPTY
2134: set INT_STACK_SIZE, %l6
2135: sub %l7, %l6, %l7
2136: cmp %sp, %l7
2137: blu Lslowtrap_reenter
2138: EMPTY
2139: #else
1.111 pk 2140: sethi %hi(_C_LABEL(eintstack)), %l7
1.1 deraadt 2141: cmp %sp, %l7
2142: bge Lslowtrap_reenter
2143: EMPTY
1.97 pk 2144: #endif
1.111 pk 2145: sethi %hi(cpcb), %l6
2146: ld [%l6 + %lo(cpcb)], %l6
1.13 deraadt 2147: set USPACE-CCFSZ-80, %l5
1.1 deraadt 2148: add %l6, %l5, %l7
2149: SET_SP_REDZONE(%l6, %l5)
2150: b Lslowtrap_reenter
2151: mov %l7, %sp
2152:
2153: #ifdef KGDB
2154: /*
2155: * bpt is entered on all breakpoint traps.
2156: * If this is a kernel breakpoint, we do not want to call trap().
2157: * Among other reasons, this way we can set breakpoints in trap().
2158: */
2159: bpt:
2160: btst PSR_PS, %l0 ! breakpoint from kernel?
2161: bz slowtrap ! no, go do regular trap
2162: nop
2163:
1.137 mrg 2164: /* XXXSMP */
1.1 deraadt 2165: /*
2166: * Build a trap frame for kgdb_trap_glue to copy.
2167: * Enable traps but set ipl high so that we will not
2168: * see interrupts from within breakpoints.
2169: */
2170: TRAP_SETUP(-CCFSZ-80)
2171: or %l0, PSR_PIL, %l4 ! splhigh()
2172: wr %l4, 0, %psr ! the manual claims that this
2173: wr %l4, PSR_ET, %psr ! song and dance is necessary
2174: std %l0, [%sp + CCFSZ + 0] ! tf.tf_psr, tf.tf_pc
2175: mov %l3, %o0 ! trap type arg for kgdb_trap_glue
2176: rd %y, %l3
2177: std %l2, [%sp + CCFSZ + 8] ! tf.tf_npc, tf.tf_y
2178: rd %wim, %l3
2179: st %l3, [%sp + CCFSZ + 16] ! tf.tf_wim (a kgdb-only r/o field)
2180: st %g1, [%sp + CCFSZ + 20] ! tf.tf_global[1]
2181: std %g2, [%sp + CCFSZ + 24] ! etc
2182: std %g4, [%sp + CCFSZ + 32]
2183: std %g6, [%sp + CCFSZ + 40]
2184: std %i0, [%sp + CCFSZ + 48] ! tf.tf_in[0..1]
2185: std %i2, [%sp + CCFSZ + 56] ! etc
2186: std %i4, [%sp + CCFSZ + 64]
2187: std %i6, [%sp + CCFSZ + 72]
2188:
2189: /*
2190: * Now call kgdb_trap_glue(); if it returns, call trap().
2191: */
2192: mov %o0, %l3 ! gotta save trap type
1.111 pk 2193: call _C_LABEL(kgdb_trap_glue)! kgdb_trap_glue(type, &trapframe)
1.1 deraadt 2194: add %sp, CCFSZ, %o1 ! (&trapframe)
2195:
2196: /*
2197: * Use slowtrap to call trap---but first erase our tracks
2198: * (put the registers back the way they were).
2199: */
2200: mov %l3, %o0 ! slowtrap will need trap type
2201: ld [%sp + CCFSZ + 12], %l3
2202: wr %l3, 0, %y
2203: ld [%sp + CCFSZ + 20], %g1
2204: ldd [%sp + CCFSZ + 24], %g2
2205: ldd [%sp + CCFSZ + 32], %g4
2206: b Lslowtrap_reenter
2207: ldd [%sp + CCFSZ + 40], %g6
2208:
2209: /*
2210: * Enter kernel breakpoint. Write all the windows (not including the
2211: * current window) into the stack, so that backtrace works. Copy the
2212: * supplied trap frame to the kgdb stack and switch stacks.
2213: *
2214: * kgdb_trap_glue(type, tf0)
2215: * int type;
2216: * struct trapframe *tf0;
2217: */
1.111 pk 2218: _ENTRY(_C_LABEL(kgdb_trap_glue))
1.1 deraadt 2219: save %sp, -CCFSZ, %sp
2220:
1.111 pk 2221: call _C_LABEL(write_all_windows)
1.1 deraadt 2222: mov %sp, %l4 ! %l4 = current %sp
2223:
2224: /* copy trapframe to top of kgdb stack */
1.127 pk 2225: set _C_LABEL(kgdb_stack) + KGDB_STACK_SIZE - 80, %l0
1.1 deraadt 2226: ! %l0 = tfcopy -> end_of_kgdb_stack
2227: mov 80, %l1
2228: 1: ldd [%i1], %l2
2229: inc 8, %i1
2230: deccc 8, %l1
2231: std %l2, [%l0]
2232: bg 1b
2233: inc 8, %l0
2234:
2235: #ifdef DEBUG
2236: /* save old red zone and then turn it off */
2237: sethi %hi(_redzone), %l7
2238: ld [%l7 + %lo(_redzone)], %l6
2239: st %g0, [%l7 + %lo(_redzone)]
2240: #endif
2241: /* switch to kgdb stack */
2242: add %l0, -CCFSZ-80, %sp
2243:
2244: /* if (kgdb_trap(type, tfcopy)) kgdb_rett(tfcopy); */
2245: mov %i0, %o0
1.111 pk 2246: call _C_LABEL(kgdb_trap)
1.1 deraadt 2247: add %l0, -80, %o1
2248: tst %o0
2249: bnz,a kgdb_rett
2250: add %l0, -80, %g1
2251:
2252: /*
2253: * kgdb_trap() did not handle the trap at all so the stack is
2254: * still intact. A simple `restore' will put everything back,
2255: * after we reset the stack pointer.
2256: */
2257: mov %l4, %sp
2258: #ifdef DEBUG
2259: st %l6, [%l7 + %lo(_redzone)] ! restore red zone
2260: #endif
2261: ret
2262: restore
2263:
2264: /*
2265: * Return from kgdb trap. This is sort of special.
2266: *
2267: * We know that kgdb_trap_glue wrote the window above it, so that we will
2268: * be able to (and are sure to have to) load it up. We also know that we
2269: * came from kernel land and can assume that the %fp (%i6) we load here
2270: * is proper. We must also be sure not to lower ipl (it is at splhigh())
2271: * until we have traps disabled, due to the SPARC taking traps at the
2272: * new ipl before noticing that PSR_ET has been turned off. We are on
2273: * the kgdb stack, so this could be disastrous.
2274: *
2275: * Note that the trapframe argument in %g1 points into the current stack
2276: * frame (current window). We abandon this window when we move %g1->tf_psr
2277: * into %psr, but we will not have loaded the new %sp yet, so again traps
2278: * must be disabled.
2279: */
2280: kgdb_rett:
2281: rd %psr, %g4 ! turn off traps
2282: wr %g4, PSR_ET, %psr
2283: /* use the three-instruction delay to do something useful */
2284: ld [%g1], %g2 ! pick up new %psr
2285: ld [%g1 + 12], %g3 ! set %y
2286: wr %g3, 0, %y
2287: #ifdef DEBUG
2288: st %l6, [%l7 + %lo(_redzone)] ! and restore red zone
2289: #endif
2290: wr %g0, 0, %wim ! enable window changes
2291: nop; nop; nop
2292: /* now safe to set the new psr (changes CWP, leaves traps disabled) */
2293: wr %g2, 0, %psr ! set rett psr (including cond codes)
2294: /* 3 instruction delay before we can use the new window */
2295: /*1*/ ldd [%g1 + 24], %g2 ! set new %g2, %g3
2296: /*2*/ ldd [%g1 + 32], %g4 ! set new %g4, %g5
2297: /*3*/ ldd [%g1 + 40], %g6 ! set new %g6, %g7
2298:
2299: /* now we can use the new window */
2300: mov %g1, %l4
2301: ld [%l4 + 4], %l1 ! get new pc
2302: ld [%l4 + 8], %l2 ! get new npc
2303: ld [%l4 + 20], %g1 ! set new %g1
2304:
2305: /* set up returnee's out registers, including its %sp */
2306: ldd [%l4 + 48], %i0
2307: ldd [%l4 + 56], %i2
2308: ldd [%l4 + 64], %i4
2309: ldd [%l4 + 72], %i6
2310:
2311: /* load returnee's window, making the window above it be invalid */
2312: restore
2313: restore %g0, 1, %l1 ! move to inval window and set %l1 = 1
2314: rd %psr, %l0
2315: sll %l1, %l0, %l1
2316: wr %l1, 0, %wim ! %wim = 1 << (%psr & 31)
1.111 pk 2317: sethi %hi(cpcb), %l1
2318: ld [%l1 + %lo(cpcb)], %l1
1.1 deraadt 2319: and %l0, 31, %l0 ! CWP = %psr & 31;
2320: st %l0, [%l1 + PCB_WIM] ! cpcb->pcb_wim = CWP;
2321: save %g0, %g0, %g0 ! back to window to reload
2322: LOADWIN(%sp)
2323: save %g0, %g0, %g0 ! back to trap window
2324: /* note, we have not altered condition codes; safe to just rett */
2325: RETT
2326: #endif
2327:
2328: /*
2329: * syscall() builds a trap frame and calls syscall().
2330: * sun_syscall is same but delivers sun system call number
2331: * XXX should not have to save&reload ALL the registers just for
2332: * ptrace...
2333: */
1.122 christos 2334: _C_LABEL(_syscall):
1.1 deraadt 2335: TRAP_SETUP(-CCFSZ-80)
2336: wr %l0, PSR_ET, %psr
2337: std %l0, [%sp + CCFSZ + 0] ! tf_psr, tf_pc
2338: rd %y, %l3
2339: std %l2, [%sp + CCFSZ + 8] ! tf_npc, tf_y
2340: st %g1, [%sp + CCFSZ + 20] ! tf_g[1]
2341: std %g2, [%sp + CCFSZ + 24] ! tf_g[2], tf_g[3]
2342: std %g4, [%sp + CCFSZ + 32] ! etc
2343: std %g6, [%sp + CCFSZ + 40]
2344: mov %g1, %o0 ! (code)
2345: std %i0, [%sp + CCFSZ + 48]
2346: add %sp, CCFSZ, %o1 ! (&tf)
2347: std %i2, [%sp + CCFSZ + 56]
2348: mov %l1, %o2 ! (pc)
2349: std %i4, [%sp + CCFSZ + 64]
1.111 pk 2350: call _C_LABEL(syscall) ! syscall(code, &tf, pc, suncompat)
1.1 deraadt 2351: std %i6, [%sp + CCFSZ + 72]
2352: ! now load em all up again, sigh
2353: ldd [%sp + CCFSZ + 0], %l0 ! new %psr, new pc
2354: ldd [%sp + CCFSZ + 8], %l2 ! new npc, new %y
2355: wr %l3, 0, %y
1.51 pk 2356: /* see `proc_trampoline' for the reason for this label */
2357: return_from_syscall:
1.1 deraadt 2358: ld [%sp + CCFSZ + 20], %g1
2359: ldd [%sp + CCFSZ + 24], %g2
2360: ldd [%sp + CCFSZ + 32], %g4
2361: ldd [%sp + CCFSZ + 40], %g6
2362: ldd [%sp + CCFSZ + 48], %i0
2363: ldd [%sp + CCFSZ + 56], %i2
2364: ldd [%sp + CCFSZ + 64], %i4
2365: ldd [%sp + CCFSZ + 72], %i6
2366: b return_from_trap
2367: wr %l0, 0, %psr
2368:
2369: /*
2370: * Interrupts. Software interrupts must be cleared from the software
2371: * interrupt enable register. Rather than calling ienab_bic for each,
2372: * we do them in-line before enabling traps.
2373: *
2374: * After preliminary setup work, the interrupt is passed to each
2375: * registered handler in turn. These are expected to return nonzero if
2376: * they took care of the interrupt. If a handler claims the interrupt,
2377: * we exit (hardware interrupts are latched in the requestor so we'll
2378: * just take another interrupt in the unlikely event of simultaneous
2379: * interrupts from two different devices at the same level). If we go
2380: * through all the registered handlers and no one claims it, we report a
2381: * stray interrupt. This is more or less done as:
2382: *
2383: * for (ih = intrhand[intlev]; ih; ih = ih->ih_next)
2384: * if ((*ih->ih_fun)(ih->ih_arg ? ih->ih_arg : &frame))
2385: * return;
2386: * strayintr(&frame);
2387: *
2388: * Software interrupts are almost the same with three exceptions:
2389: * (1) we clear the interrupt from the software interrupt enable
2390: * register before calling any handler (we have to clear it first
2391: * to avoid an interrupt-losing race),
2392: * (2) we always call all the registered handlers (there is no way
2393: * to tell if the single bit in the software interrupt register
2394: * represents one or many requests)
2395: * (3) we never announce a stray interrupt (because of (1), another
2396: * interrupt request can come in while we're in the handler. If
1.52 pk 2397: * the handler deals with everything for both the original & the
1.1 deraadt 2398: * new request, we'll erroneously report a stray interrupt when
2399: * we take the software interrupt for the new request.
2400: *
2401: * Inputs:
2402: * %l0 = %psr
2403: * %l1 = return pc
2404: * %l2 = return npc
2405: * %l3 = interrupt level
2406: * (software interrupt only) %l4 = bits to clear in interrupt register
2407: *
2408: * Internal:
2409: * %l4, %l5: local variables
2410: * %l6 = %y
2411: * %l7 = %g1
2412: * %g2..%g7 go to stack
2413: *
2414: * An interrupt frame is built in the space for a full trapframe;
2415: * this contains the psr, pc, npc, and interrupt level.
2416: */
1.52 pk 2417: softintr_sun44c:
1.62 pk 2418: sethi %hi(INTRREG_VA), %l6
2419: ldub [%l6 + %lo(INTRREG_VA)], %l5
1.1 deraadt 2420: andn %l5, %l4, %l5
1.62 pk 2421: stb %l5, [%l6 + %lo(INTRREG_VA)]
1.52 pk 2422:
2423: softintr_common:
1.1 deraadt 2424: INTR_SETUP(-CCFSZ-80)
2425: std %g2, [%sp + CCFSZ + 24] ! save registers
1.111 pk 2426: INCR(_C_LABEL(uvmexp)+V_INTR) ! cnt.v_intr++; (clobbers %o0,%o1)
1.1 deraadt 2427: mov %g1, %l7
2428: rd %y, %l6
2429: std %g4, [%sp + CCFSZ + 32]
2430: andn %l0, PSR_PIL, %l4 ! %l4 = psr & ~PSR_PIL |
2431: sll %l3, 8, %l5 ! intlev << IPLSHIFT
2432: std %g6, [%sp + CCFSZ + 40]
2433: or %l5, %l4, %l4 ! ;
2434: wr %l4, 0, %psr ! the manual claims this
2435: wr %l4, PSR_ET, %psr ! song and dance is necessary
2436: std %l0, [%sp + CCFSZ + 0] ! set up intrframe/clockframe
2437: sll %l3, 2, %l5
1.111 pk 2438: set _C_LABEL(intrcnt), %l4 ! intrcnt[intlev]++;
1.1 deraadt 2439: ld [%l4 + %l5], %o0
2440: std %l2, [%sp + CCFSZ + 8]
2441: inc %o0
2442: st %o0, [%l4 + %l5]
1.111 pk 2443: set _C_LABEL(intrhand), %l4 ! %l4 = intrhand[intlev];
1.1 deraadt 2444: ld [%l4 + %l5], %l4
2445: b 3f
2446: st %fp, [%sp + CCFSZ + 16]
2447:
2448: 1: ld [%l4], %o1
2449: ld [%l4 + 4], %o0
2450: tst %o0
2451: bz,a 2f
2452: add %sp, CCFSZ, %o0
2453: 2: jmpl %o1, %o7 ! (void)(*ih->ih_fun)(...)
2454: ld [%l4 + 8], %l4 ! and ih = ih->ih_next
2455: 3: tst %l4 ! while ih != NULL
2456: bnz 1b
2457: nop
2458: mov %l7, %g1
2459: wr %l6, 0, %y
2460: ldd [%sp + CCFSZ + 24], %g2
2461: ldd [%sp + CCFSZ + 32], %g4
2462: ldd [%sp + CCFSZ + 40], %g6
2463: b return_from_trap
2464: wr %l0, 0, %psr
2465:
2466: /*
1.52 pk 2467: * _sparc_interrupt{44c,4m} is exported for paranoia checking
2468: * (see intr.c).
1.1 deraadt 2469: */
1.52 pk 2470: #if defined(SUN4M)
1.111 pk 2471: _ENTRY(_C_LABEL(sparc_interrupt4m))
1.149 uwe 2472: #if !defined(MSIIEP) /* "normal" sun4m */
1.52 pk 2473: mov 1, %l4
1.96 pk 2474: sethi %hi(CPUINFO_VA+CPUINFO_INTREG), %l6
2475: ld [%l6 + %lo(CPUINFO_VA+CPUINFO_INTREG)], %l6
2476: ld [%l6 + ICR_PI_PEND_OFFSET], %l5 ! get pending interrupts
2477: sll %l4, %l3, %l4 ! test SOFTINT bit
1.52 pk 2478: andcc %l5, %l4, %g0
1.111 pk 2479: bne sparc_interrupt_common
1.52 pk 2480: nop
2481:
2482: ! a soft interrupt; clear bit in interrupt-pending register
2483: sll %l4, 16, %l5
1.96 pk 2484: st %l5, [%l6 + ICR_PI_CLR_OFFSET]
1.52 pk 2485: b,a softintr_common
1.149 uwe 2486: #else /* MSIIEP */
2487: sethi %hi(MSIIEP_PCIC_VA), %l6
2488: mov 1, %l4
2489: ld [%l6 + PCIC_PROC_IPR_REG], %l5 ! get pending interrupts
2490: sll %l4, %l3, %l4
2491: btst %l4, %l5 ! has pending hw intr at this level?
2492: bnz sparc_interrupt_common
2493: nop
2494:
2495: ! a soft interrupt; clear its bit in softintr clear register
2496: b softintr_common
2497: sth %l4, [%l6 + PCIC_SOFT_INTR_CLEAR_REG]
2498: #endif /* MSIIEP */
2499: #endif /* SUN4M */
1.52 pk 2500:
1.111 pk 2501: _ENTRY(_C_LABEL(sparc_interrupt44c))
2502: sparc_interrupt_common:
1.1 deraadt 2503: INTR_SETUP(-CCFSZ-80)
2504: std %g2, [%sp + CCFSZ + 24] ! save registers
1.111 pk 2505: INCR(_C_LABEL(uvmexp)+V_INTR) ! cnt.v_intr++; (clobbers %o0,%o1)
1.1 deraadt 2506: mov %g1, %l7
2507: rd %y, %l6
2508: std %g4, [%sp + CCFSZ + 32]
2509: andn %l0, PSR_PIL, %l4 ! %l4 = psr & ~PSR_PIL |
2510: sll %l3, 8, %l5 ! intlev << IPLSHIFT
2511: std %g6, [%sp + CCFSZ + 40]
2512: or %l5, %l4, %l4 ! ;
2513: wr %l4, 0, %psr ! the manual claims this
2514: wr %l4, PSR_ET, %psr ! song and dance is necessary
2515: std %l0, [%sp + CCFSZ + 0] ! set up intrframe/clockframe
2516: sll %l3, 2, %l5
1.111 pk 2517: set _C_LABEL(intrcnt), %l4 ! intrcnt[intlev]++;
1.1 deraadt 2518: ld [%l4 + %l5], %o0
2519: std %l2, [%sp + CCFSZ + 8] ! set up intrframe/clockframe
2520: inc %o0
2521: st %o0, [%l4 + %l5]
1.111 pk 2522: set _C_LABEL(intrhand), %l4 ! %l4 = intrhand[intlev];
1.1 deraadt 2523: ld [%l4 + %l5], %l4
1.137 mrg 2524:
2525: #if defined(MULTIPROCESSOR) && defined(SUN4M) /* XXX */
2526: call _C_LABEL(intr_lock_kernel)
2527: nop
2528: #endif
2529:
1.1 deraadt 2530: b 3f
2531: st %fp, [%sp + CCFSZ + 16]
2532:
2533: 1: ld [%l4], %o1
2534: ld [%l4 + 4], %o0
2535: tst %o0
2536: bz,a 2f
2537: add %sp, CCFSZ, %o0
2538: 2: jmpl %o1, %o7 ! handled = (*ih->ih_fun)(...)
2539: ld [%l4 + 8], %l4 ! and ih = ih->ih_next
2540: tst %o0
2541: bnz 4f ! if (handled) break
2542: nop
2543: 3: tst %l4
2544: bnz 1b ! while (ih)
2545: nop
1.76 pk 2546:
2547: /* Unhandled interrupts while cold cause IPL to be raised to `high' */
1.111 pk 2548: sethi %hi(_C_LABEL(cold)), %o0
2549: ld [%o0 + %lo(_C_LABEL(cold))], %o0
1.76 pk 2550: tst %o0 ! if (cold) {
2551: bnz,a 4f ! splhigh();
2552: or %l0, 0xf00, %l0 ! } else
2553:
1.111 pk 2554: call _C_LABEL(strayintr) ! strayintr(&intrframe)
1.1 deraadt 2555: add %sp, CCFSZ, %o0
2556: /* all done: restore registers and go return */
1.137 mrg 2557: 4:
2558: #if defined(MULTIPROCESSOR) && defined(SUN4M) /* XXX */
2559: call _C_LABEL(intr_unlock_kernel)
2560: nop
2561: #endif
2562: mov %l7, %g1
1.1 deraadt 2563: wr %l6, 0, %y
2564: ldd [%sp + CCFSZ + 24], %g2
2565: ldd [%sp + CCFSZ + 32], %g4
2566: ldd [%sp + CCFSZ + 40], %g6
2567: b return_from_trap
2568: wr %l0, 0, %psr
2569:
2570: #ifdef notyet
2571: /*
2572: * Level 12 (ZS serial) interrupt. Handle it quickly, schedule a
2573: * software interrupt, and get out. Do the software interrupt directly
2574: * if we would just take it on the way out.
2575: *
2576: * Input:
2577: * %l0 = %psr
2578: * %l1 = return pc
2579: * %l2 = return npc
2580: * Internal:
2581: * %l3 = zs device
2582: * %l4, %l5 = temporary
2583: * %l6 = rr3 (or temporary data) + 0x100 => need soft int
2584: * %l7 = zs soft status
2585: */
2586: zshard:
2587: #endif /* notyet */
2588:
2589: /*
2590: * Level 15 interrupt. An async memory error has occurred;
2591: * take care of it (typically by panicking, but hey...).
2592: * %l0 = %psr
2593: * %l1 = return pc
2594: * %l2 = return npc
2595: * %l3 = 15 * 4 (why? just because!)
2596: *
2597: * Internal:
2598: * %l4 = %y
2599: * %l5 = %g1
2600: * %l6 = %g6
2601: * %l7 = %g7
2602: * g2, g3, g4, g5 go to stack
2603: *
2604: * This code is almost the same as that in mem_access_fault,
2605: * except that we already know the problem is not a `normal' fault,
2606: * and that we must be extra-careful with interrupt enables.
2607: */
1.52 pk 2608:
2609: #if defined(SUN4)
2610: nmi_sun4:
1.1 deraadt 2611: INTR_SETUP(-CCFSZ-80)
1.111 pk 2612: INCR(_C_LABEL(uvmexp)+V_INTR) ! cnt.v_intr++; (clobbers %o0,%o1)
1.1 deraadt 2613: /*
2614: * Level 15 interrupts are nonmaskable, so with traps off,
2615: * disable all interrupts to prevent recursion.
2616: */
1.62 pk 2617: sethi %hi(INTRREG_VA), %o0
2618: ldub [%o0 + %lo(INTRREG_VA)], %o1
1.157 uwe 2619: andn %o1, IE_ALLIE, %o1
1.62 pk 2620: stb %o1, [%o0 + %lo(INTRREG_VA)]
1.1 deraadt 2621: wr %l0, PSR_ET, %psr ! okay, turn traps on again
2622:
2623: std %g2, [%sp + CCFSZ + 0] ! save g2, g3
2624: rd %y, %l4 ! save y
2625:
1.19 deraadt 2626: std %g4, [%sp + CCFSZ + 8] ! save g4, g5
2627: mov %g1, %l5 ! save g1, g6, g7
2628: mov %g6, %l6
2629: mov %g7, %l7
2630: #if defined(SUN4C) || defined(SUN4M)
1.52 pk 2631: b,a nmi_common
1.19 deraadt 2632: #endif /* SUN4C || SUN4M */
1.52 pk 2633: #endif
2634:
2635: #if defined(SUN4C)
2636: nmi_sun4c:
2637: INTR_SETUP(-CCFSZ-80)
1.111 pk 2638: INCR(_C_LABEL(uvmexp)+V_INTR) ! cnt.v_intr++; (clobbers %o0,%o1)
1.52 pk 2639: /*
2640: * Level 15 interrupts are nonmaskable, so with traps off,
2641: * disable all interrupts to prevent recursion.
2642: */
1.62 pk 2643: sethi %hi(INTRREG_VA), %o0
2644: ldub [%o0 + %lo(INTRREG_VA)], %o1
1.157 uwe 2645: andn %o1, IE_ALLIE, %o1
1.62 pk 2646: stb %o1, [%o0 + %lo(INTRREG_VA)]
1.52 pk 2647: wr %l0, PSR_ET, %psr ! okay, turn traps on again
2648:
2649: std %g2, [%sp + CCFSZ + 0] ! save g2, g3
2650: rd %y, %l4 ! save y
2651:
2652: ! must read the sync error register too.
1.1 deraadt 2653: set AC_SYNC_ERR, %o0
2654: lda [%o0] ASI_CONTROL, %o1 ! sync err reg
2655: inc 4, %o0
2656: lda [%o0] ASI_CONTROL, %o2 ! sync virt addr
2657: std %g4, [%sp + CCFSZ + 8] ! save g4,g5
2658: mov %g1, %l5 ! save g1,g6,g7
2659: mov %g6, %l6
2660: mov %g7, %l7
2661: inc 4, %o0
2662: lda [%o0] ASI_CONTROL, %o3 ! async err reg
2663: inc 4, %o0
2664: lda [%o0] ASI_CONTROL, %o4 ! async virt addr
1.52 pk 2665: #if defined(SUN4M)
2666: !!b,a nmi_common
2667: #endif /* SUN4M */
2668: #endif /* SUN4C */
2669:
2670: nmi_common:
1.1 deraadt 2671: ! and call C code
1.111 pk 2672: call _C_LABEL(memerr4_4c) ! memerr(0, ser, sva, aer, ava)
1.95 pk 2673: clr %o0
1.1 deraadt 2674:
2675: mov %l5, %g1 ! restore g1 through g7
2676: ldd [%sp + CCFSZ + 0], %g2
2677: ldd [%sp + CCFSZ + 8], %g4
2678: wr %l0, 0, %psr ! re-disable traps
2679: mov %l6, %g6
2680: mov %l7, %g7
2681:
2682: ! set IE_ALLIE again (safe, we disabled traps again above)
1.62 pk 2683: sethi %hi(INTRREG_VA), %o0
2684: ldub [%o0 + %lo(INTRREG_VA)], %o1
1.1 deraadt 2685: or %o1, IE_ALLIE, %o1
1.62 pk 2686: stb %o1, [%o0 + %lo(INTRREG_VA)]
1.1 deraadt 2687: b return_from_trap
2688: wr %l4, 0, %y ! restore y
2689:
1.52 pk 2690: #if defined(SUN4M)
2691: nmi_sun4m:
2692: INTR_SETUP(-CCFSZ-80)
1.111 pk 2693: INCR(_C_LABEL(uvmexp)+V_INTR) ! cnt.v_intr++; (clobbers %o0,%o1)
1.94 pk 2694:
2695: /* Read the Pending Interrupts register */
1.96 pk 2696: sethi %hi(CPUINFO_VA+CPUINFO_INTREG), %l6
2697: ld [%l6 + %lo(CPUINFO_VA+CPUINFO_INTREG)], %l6
2698: ld [%l6 + ICR_PI_PEND_OFFSET], %l5 ! get pending interrupts
2699:
1.111 pk 2700: set _C_LABEL(nmi_soft), %o3 ! assume a softint
1.105 pk 2701: set PINTR_IC, %o1 ! hard lvl 15 bit
2702: sethi %hi(PINTR_SINTRLEV(15)), %o0 ! soft lvl 15 bit
1.94 pk 2703: btst %o0, %l5 ! soft level 15?
1.101 pk 2704: bnz,a 1f !
1.105 pk 2705: mov %o0, %o1 ! shift int clear bit to SOFTINT 15
2706:
1.154 thorpej 2707: set _C_LABEL(nmi_hard), %o3 /* it's a hardint; switch handler */
1.94 pk 2708:
1.52 pk 2709: /*
2710: * Level 15 interrupts are nonmaskable, so with traps off,
2711: * disable all interrupts to prevent recursion.
2712: */
2713: sethi %hi(ICR_SI_SET), %o0
1.101 pk 2714: set SINTR_MA, %o2
2715: st %o2, [%o0 + %lo(ICR_SI_SET)]
1.142 mrg 2716: #if defined(MULTIPROCESSOR) && defined(DDB)
2717: b 2f
2718: clr %o0
2719: #endif
1.52 pk 2720:
1.101 pk 2721: 1:
1.142 mrg 2722: #if defined(MULTIPROCESSOR) && defined(DDB)
2723: /*
2724: * Setup a trapframe for nmi_soft; this might be an IPI telling
2725: * us to pause, so lets save some state for DDB to get at.
2726: */
2727: std %l0, [%sp + CCFSZ] ! tf.tf_psr = psr; tf.tf_pc = ret_pc;
2728: rd %y, %l3
2729: std %l2, [%sp + CCFSZ + 8] ! tf.tf_npc = return_npc; tf.tf_y = %y;
2730: st %g1, [%sp + CCFSZ + 20]
2731: std %g2, [%sp + CCFSZ + 24]
2732: std %g4, [%sp + CCFSZ + 32]
2733: std %g6, [%sp + CCFSZ + 40]
2734: std %i0, [%sp + CCFSZ + 48]
2735: std %i2, [%sp + CCFSZ + 56]
2736: std %i4, [%sp + CCFSZ + 64]
2737: std %i6, [%sp + CCFSZ + 72]
2738: add %sp, CCFSZ, %o0
2739: 2:
2740: #else
2741: clr %o0
2742: #endif
1.105 pk 2743: /*
2744: * Now clear the NMI. Apparently, we must allow some time
2745: * to let the bits sink in..
2746: */
1.96 pk 2747: st %o1, [%l6 + ICR_PI_CLR_OFFSET]
1.105 pk 2748: nop; nop; nop;
2749: ld [%l6 + ICR_PI_PEND_OFFSET], %g0 ! drain register!?
2750: nop; nop; nop;
1.52 pk 2751:
2752: wr %l0, PSR_ET, %psr ! okay, turn traps on again
2753:
1.142 mrg 2754: std %g2, [%sp + CCFSZ + 80] ! save g2, g3
1.52 pk 2755: rd %y, %l4 ! save y
1.142 mrg 2756: std %g4, [%sp + CCFSZ + 88] ! save g4,g5
1.52 pk 2757:
2758: /* Finish stackframe, call C trap handler */
2759: mov %g1, %l5 ! save g1,g6,g7
2760: mov %g6, %l6
2761:
1.142 mrg 2762: jmpl %o3, %o7 ! nmi_hard(0) or nmi_soft(&tf)
2763: mov %g7, %l7
1.105 pk 2764:
1.52 pk 2765: mov %l5, %g1 ! restore g1 through g7
1.142 mrg 2766: ldd [%sp + CCFSZ + 80], %g2
2767: ldd [%sp + CCFSZ + 88], %g4
1.52 pk 2768: wr %l0, 0, %psr ! re-disable traps
2769: mov %l6, %g6
2770: mov %l7, %g7
2771:
1.105 pk 2772: !cmp %o0, 0 ! was this a soft nmi
2773: !be 4f
1.154 thorpej 2774: /* XXX - we need to unblock `mask all ints' only on a hard nmi */
1.101 pk 2775:
1.52 pk 2776: ! enable interrupts again (safe, we disabled traps again above)
2777: sethi %hi(ICR_SI_CLR), %o0
2778: set SINTR_MA, %o1
2779: st %o1, [%o0 + %lo(ICR_SI_CLR)]
2780:
1.101 pk 2781: 4:
1.52 pk 2782: b return_from_trap
2783: wr %l4, 0, %y ! restore y
2784: #endif /* SUN4M */
2785:
2786: #ifdef GPROF
2787: .globl window_of, winof_user
2788: .globl window_uf, winuf_user, winuf_ok, winuf_invalid
2789: .globl return_from_trap, rft_kernel, rft_user, rft_invalid
2790: .globl softtrap, slowtrap
1.122 christos 2791: .globl clean_trap_window, _C_LABEL(_syscall)
1.52 pk 2792: #endif
1.1 deraadt 2793:
2794: /*
2795: * Window overflow trap handler.
2796: * %l0 = %psr
2797: * %l1 = return pc
2798: * %l2 = return npc
2799: */
2800: window_of:
2801: #ifdef TRIVIAL_WINDOW_OVERFLOW_HANDLER
2802: /* a trivial version that assumes %sp is ok */
2803: /* (for testing only!) */
2804: save %g0, %g0, %g0
2805: std %l0, [%sp + (0*8)]
2806: rd %psr, %l0
2807: mov 1, %l1
2808: sll %l1, %l0, %l0
2809: wr %l0, 0, %wim
2810: std %l2, [%sp + (1*8)]
2811: std %l4, [%sp + (2*8)]
2812: std %l6, [%sp + (3*8)]
2813: std %i0, [%sp + (4*8)]
2814: std %i2, [%sp + (5*8)]
2815: std %i4, [%sp + (6*8)]
2816: std %i6, [%sp + (7*8)]
2817: restore
2818: RETT
2819: #else
2820: /*
2821: * This is similar to TRAP_SETUP, but we do not want to spend
2822: * a lot of time, so we have separate paths for kernel and user.
2823: * We also know for sure that the window has overflowed.
2824: */
2825: btst PSR_PS, %l0
2826: bz winof_user
2827: sethi %hi(clean_trap_window), %l7
2828:
2829: /*
2830: * Overflow from kernel mode. Call clean_trap_window to
2831: * do the dirty work, then just return, since we know prev
2832: * window is valid. clean_trap_windows might dump all *user*
2833: * windows into the pcb, but we do not care: there is at
2834: * least one kernel window (a trap or interrupt frame!)
2835: * above us.
2836: */
2837: jmpl %l7 + %lo(clean_trap_window), %l4
2838: mov %g7, %l7 ! for clean_trap_window
2839:
2840: wr %l0, 0, %psr ! put back the @%*! cond. codes
2841: nop ! (let them settle in)
2842: RETT
2843:
2844: winof_user:
2845: /*
2846: * Overflow from user mode.
2847: * If clean_trap_window dumps the registers into the pcb,
2848: * rft_user will need to call trap(), so we need space for
2849: * a trap frame. We also have to compute pcb_nw.
2850: *
2851: * SHOULD EXPAND IN LINE TO AVOID BUILDING TRAP FRAME ON
2852: * `EASY' SAVES
2853: */
1.111 pk 2854: sethi %hi(cpcb), %l6
2855: ld [%l6 + %lo(cpcb)], %l6
1.1 deraadt 2856: ld [%l6 + PCB_WIM], %l5
2857: and %l0, 31, %l3
2858: sub %l3, %l5, %l5 /* l5 = CWP - pcb_wim */
2859: set uwtab, %l4
2860: ldub [%l4 + %l5], %l5 /* l5 = uwtab[l5] */
2861: st %l5, [%l6 + PCB_UW]
2862: jmpl %l7 + %lo(clean_trap_window), %l4
2863: mov %g7, %l7 ! for clean_trap_window
1.111 pk 2864: sethi %hi(cpcb), %l6
2865: ld [%l6 + %lo(cpcb)], %l6
1.13 deraadt 2866: set USPACE-CCFSZ-80, %l5
1.1 deraadt 2867: add %l6, %l5, %sp /* over to kernel stack */
2868: CHECK_SP_REDZONE(%l6, %l5)
2869:
2870: /*
2871: * Copy return_from_trap far enough to allow us
2872: * to jump directly to rft_user_or_recover_pcb_windows
2873: * (since we know that is where we are headed).
2874: */
2875: ! and %l0, 31, %l3 ! still set (clean_trap_window
2876: ! leaves this register alone)
2877: set wmask, %l6
2878: ldub [%l6 + %l3], %l5 ! %l5 = 1 << ((CWP + 1) % nwindows)
2879: b rft_user_or_recover_pcb_windows
2880: rd %wim, %l4 ! (read %wim first)
2881: #endif /* end `real' version of window overflow trap handler */
2882:
2883: /*
2884: * Window underflow trap handler.
2885: * %l0 = %psr
2886: * %l1 = return pc
2887: * %l2 = return npc
2888: *
2889: * A picture:
2890: *
2891: * T R I X
2892: * 0 0 0 1 0 0 0 (%wim)
2893: * [bit numbers increase towards the right;
2894: * `restore' moves right & `save' moves left]
2895: *
2896: * T is the current (Trap) window, R is the window that attempted
2897: * a `Restore' instruction, I is the Invalid window, and X is the
2898: * window we want to make invalid before we return.
2899: *
2900: * Since window R is valid, we cannot use rft_user to restore stuff
2901: * for us. We have to duplicate its logic. YUCK.
2902: *
2903: * Incidentally, TRIX are for kids. Silly rabbit!
2904: */
2905: window_uf:
2906: #ifdef TRIVIAL_WINDOW_UNDERFLOW_HANDLER
2907: wr %g0, 0, %wim ! allow us to enter I
2908: restore ! to R
2909: nop
2910: nop
2911: restore ! to I
2912: restore %g0, 1, %l1 ! to X
2913: rd %psr, %l0
2914: sll %l1, %l0, %l0
2915: wr %l0, 0, %wim
2916: save %g0, %g0, %g0 ! back to I
2917: LOADWIN(%sp)
2918: save %g0, %g0, %g0 ! back to R
2919: save %g0, %g0, %g0 ! back to T
2920: RETT
2921: #else
2922: wr %g0, 0, %wim ! allow us to enter I
2923: btst PSR_PS, %l0
2924: restore ! enter window R
2925: bz winuf_user
2926: restore ! enter window I
2927:
2928: /*
2929: * Underflow from kernel mode. Just recover the
2930: * registers and go (except that we have to update
2931: * the blasted user pcb fields).
2932: */
2933: restore %g0, 1, %l1 ! enter window X, then set %l1 to 1
2934: rd %psr, %l0 ! cwp = %psr & 31;
2935: and %l0, 31, %l0
2936: sll %l1, %l0, %l1 ! wim = 1 << cwp;
2937: wr %l1, 0, %wim ! setwim(wim);
1.111 pk 2938: sethi %hi(cpcb), %l1
2939: ld [%l1 + %lo(cpcb)], %l1
1.1 deraadt 2940: st %l0, [%l1 + PCB_WIM] ! cpcb->pcb_wim = cwp;
2941: save %g0, %g0, %g0 ! back to window I
2942: LOADWIN(%sp)
2943: save %g0, %g0, %g0 ! back to R
2944: save %g0, %g0, %g0 ! and then to T
2945: wr %l0, 0, %psr ! fix those cond codes....
2946: nop ! (let them settle in)
2947: RETT
2948:
2949: winuf_user:
2950: /*
2951: * Underflow from user mode.
2952: *
2953: * We cannot use rft_user (as noted above) because
2954: * we must re-execute the `restore' instruction.
2955: * Since it could be, e.g., `restore %l0,0,%l0',
2956: * it is not okay to touch R's registers either.
2957: *
2958: * We are now in window I.
2959: */
2960: btst 7, %sp ! if unaligned, it is invalid
2961: bne winuf_invalid
2962: EMPTY
2963:
1.111 pk 2964: sethi %hi(_C_LABEL(pgofset)), %l4
2965: ld [%l4 + %lo(_C_LABEL(pgofset))], %l4
1.62 pk 2966: PTE_OF_ADDR(%sp, %l7, winuf_invalid, %l4, NOP_ON_4M_5)
2967: CMP_PTE_USER_READ(%l7, %l5, NOP_ON_4M_6) ! if first page not readable,
1.1 deraadt 2968: bne winuf_invalid ! it is invalid
2969: EMPTY
1.13 deraadt 2970: SLT_IF_1PAGE_RW(%sp, %l7, %l4) ! first page is readable
1.1 deraadt 2971: bl,a winuf_ok ! if only one page, enter window X
2972: restore %g0, 1, %l1 ! and goto ok, & set %l1 to 1
2973: add %sp, 7*8, %l5
1.13 deraadt 2974: add %l4, 62, %l4
1.62 pk 2975: PTE_OF_ADDR(%l5, %l7, winuf_invalid, %l4, NOP_ON_4M_7)
2976: CMP_PTE_USER_READ(%l7, %l5, NOP_ON_4M_8) ! check second page too
1.1 deraadt 2977: be,a winuf_ok ! enter window X and goto ok
2978: restore %g0, 1, %l1 ! (and then set %l1 to 1)
2979:
2980: winuf_invalid:
2981: /*
2982: * We were unable to restore the window because %sp
2983: * is invalid or paged out. Return to the trap window
2984: * and call trap(T_WINUF). This will save R to the user
2985: * stack, then load both R and I into the pcb rw[] area,
2986: * and return with pcb_nsaved set to -1 for success, 0 for
2987: * failure. `Failure' indicates that someone goofed with the
2988: * trap registers (e.g., signals), so that we need to return
2989: * from the trap as from a syscall (probably to a signal handler)
2990: * and let it retry the restore instruction later. Note that
2991: * window R will have been pushed out to user space, and thus
2992: * be the invalid window, by the time we get back here. (We
2993: * continue to label it R anyway.) We must also set %wim again,
2994: * and set pcb_uw to 1, before enabling traps. (Window R is the
2995: * only window, and it is a user window).
2996: */
2997: save %g0, %g0, %g0 ! back to R
2998: save %g0, 1, %l4 ! back to T, then %l4 = 1
1.111 pk 2999: sethi %hi(cpcb), %l6
3000: ld [%l6 + %lo(cpcb)], %l6
1.1 deraadt 3001: st %l4, [%l6 + PCB_UW] ! pcb_uw = 1
3002: ld [%l6 + PCB_WIM], %l5 ! get log2(%wim)
3003: sll %l4, %l5, %l4 ! %l4 = old %wim
3004: wr %l4, 0, %wim ! window I is now invalid again
1.13 deraadt 3005: set USPACE-CCFSZ-80, %l5
1.1 deraadt 3006: add %l6, %l5, %sp ! get onto kernel stack
3007: CHECK_SP_REDZONE(%l6, %l5)
3008:
3009: /*
3010: * Okay, call trap(T_WINUF, psr, pc, &tf).
3011: * See `slowtrap' above for operation.
3012: */
3013: wr %l0, PSR_ET, %psr
3014: std %l0, [%sp + CCFSZ + 0] ! tf.tf_psr, tf.tf_pc
3015: rd %y, %l3
3016: std %l2, [%sp + CCFSZ + 8] ! tf.tf_npc, tf.tf_y
3017: mov T_WINUF, %o0
3018: st %g1, [%sp + CCFSZ + 20] ! tf.tf_global[1]
3019: mov %l0, %o1
3020: std %g2, [%sp + CCFSZ + 24] ! etc
3021: mov %l1, %o2
3022: std %g4, [%sp + CCFSZ + 32]
3023: add %sp, CCFSZ, %o3
3024: std %g6, [%sp + CCFSZ + 40]
3025: std %i0, [%sp + CCFSZ + 48] ! tf.tf_out[0], etc
3026: std %i2, [%sp + CCFSZ + 56]
3027: std %i4, [%sp + CCFSZ + 64]
1.111 pk 3028: call _C_LABEL(trap) ! trap(T_WINUF, pc, psr, &tf)
1.1 deraadt 3029: std %i6, [%sp + CCFSZ + 72] ! tf.tf_out[6]
3030:
3031: ldd [%sp + CCFSZ + 0], %l0 ! new psr, pc
3032: ldd [%sp + CCFSZ + 8], %l2 ! new npc, %y
3033: wr %l3, 0, %y
3034: ld [%sp + CCFSZ + 20], %g1
3035: ldd [%sp + CCFSZ + 24], %g2
3036: ldd [%sp + CCFSZ + 32], %g4
3037: ldd [%sp + CCFSZ + 40], %g6
3038: ldd [%sp + CCFSZ + 48], %i0 ! %o0 for window R, etc
3039: ldd [%sp + CCFSZ + 56], %i2
3040: ldd [%sp + CCFSZ + 64], %i4
3041: wr %l0, 0, %psr ! disable traps: test must be atomic
3042: ldd [%sp + CCFSZ + 72], %i6
1.111 pk 3043: sethi %hi(cpcb), %l6
3044: ld [%l6 + %lo(cpcb)], %l6
1.1 deraadt 3045: ld [%l6 + PCB_NSAVED], %l7 ! if nsaved is -1, we have our regs
3046: tst %l7
3047: bl,a 1f ! got them
3048: wr %g0, 0, %wim ! allow us to enter windows R, I
3049: b,a return_from_trap
3050:
3051: /*
3052: * Got 'em. Load 'em up.
3053: */
3054: 1:
3055: mov %g6, %l3 ! save %g6; set %g6 = cpcb
3056: mov %l6, %g6
3057: st %g0, [%g6 + PCB_NSAVED] ! and clear magic flag
3058: restore ! from T to R
3059: restore ! from R to I
3060: restore %g0, 1, %l1 ! from I to X, then %l1 = 1
3061: rd %psr, %l0 ! cwp = %psr;
3062: sll %l1, %l0, %l1
3063: wr %l1, 0, %wim ! make window X invalid
3064: and %l0, 31, %l0
3065: st %l0, [%g6 + PCB_WIM] ! cpcb->pcb_wim = cwp;
3066: nop ! unnecessary? old wim was 0...
3067: save %g0, %g0, %g0 ! back to I
3068: LOADWIN(%g6 + PCB_RW + 64) ! load from rw[1]
3069: save %g0, %g0, %g0 ! back to R
3070: LOADWIN(%g6 + PCB_RW) ! load from rw[0]
3071: save %g0, %g0, %g0 ! back to T
3072: wr %l0, 0, %psr ! restore condition codes
3073: mov %l3, %g6 ! fix %g6
3074: RETT
3075:
3076: /*
3077: * Restoring from user stack, but everything has checked out
3078: * as good. We are now in window X, and %l1 = 1. Window R
3079: * is still valid and holds user values.
3080: */
3081: winuf_ok:
3082: rd %psr, %l0
3083: sll %l1, %l0, %l1
3084: wr %l1, 0, %wim ! make this one invalid
1.111 pk 3085: sethi %hi(cpcb), %l2
3086: ld [%l2 + %lo(cpcb)], %l2
1.1 deraadt 3087: and %l0, 31, %l0
3088: st %l0, [%l2 + PCB_WIM] ! cpcb->pcb_wim = cwp;
3089: save %g0, %g0, %g0 ! back to I
3090: LOADWIN(%sp)
3091: save %g0, %g0, %g0 ! back to R
3092: save %g0, %g0, %g0 ! back to T
3093: wr %l0, 0, %psr ! restore condition codes
3094: nop ! it takes three to tangle
3095: RETT
3096: #endif /* end `real' version of window underflow trap handler */
3097:
3098: /*
3099: * Various return-from-trap routines (see return_from_trap).
3100: */
3101:
3102: /*
3103: * Return from trap, to kernel.
3104: * %l0 = %psr
3105: * %l1 = return pc
3106: * %l2 = return npc
3107: * %l4 = %wim
3108: * %l5 = bit for previous window
3109: */
3110: rft_kernel:
3111: btst %l5, %l4 ! if (wim & l5)
3112: bnz 1f ! goto reload;
3113: wr %l0, 0, %psr ! but first put !@#*% cond codes back
3114:
3115: /* previous window is valid; just rett */
3116: nop ! wait for cond codes to settle in
3117: RETT
3118:
3119: /*
3120: * Previous window is invalid.
3121: * Update %wim and then reload l0..i7 from frame.
3122: *
3123: * T I X
3124: * 0 0 1 0 0 (%wim)
3125: * [see picture in window_uf handler]
3126: *
3127: * T is the current (Trap) window, I is the Invalid window,
3128: * and X is the window we want to make invalid. Window X
3129: * currently has no useful values.
3130: */
3131: 1:
3132: wr %g0, 0, %wim ! allow us to enter window I
3133: nop; nop; nop ! (it takes a while)
3134: restore ! enter window I
3135: restore %g0, 1, %l1 ! enter window X, then %l1 = 1
3136: rd %psr, %l0 ! CWP = %psr & 31;
3137: and %l0, 31, %l0
3138: sll %l1, %l0, %l1 ! wim = 1 << CWP;
3139: wr %l1, 0, %wim ! setwim(wim);
1.111 pk 3140: sethi %hi(cpcb), %l1
3141: ld [%l1 + %lo(cpcb)], %l1
1.1 deraadt 3142: st %l0, [%l1 + PCB_WIM] ! cpcb->pcb_wim = l0 & 31;
3143: save %g0, %g0, %g0 ! back to window I
3144: LOADWIN(%sp)
3145: save %g0, %g0, %g0 ! back to window T
3146: /*
3147: * Note that the condition codes are still set from
3148: * the code at rft_kernel; we can simply return.
3149: */
3150: RETT
3151:
3152: /*
3153: * Return from trap, to user. Checks for scheduling trap (`ast') first;
3154: * will re-enter trap() if set. Note that we may have to switch from
3155: * the interrupt stack to the kernel stack in this case.
3156: * %l0 = %psr
3157: * %l1 = return pc
3158: * %l2 = return npc
3159: * %l4 = %wim
3160: * %l5 = bit for previous window
3161: * %l6 = cpcb
3162: * If returning to a valid window, just set psr and return.
3163: */
3164: rft_user:
1.111 pk 3165: ! sethi %hi(_C_LABEL(want_ast)), %l7 ! (done below)
3166: ld [%l7 + %lo(_C_LABEL(want_ast))], %l7
1.1 deraadt 3167: tst %l7 ! want AST trap?
3168: bne,a softtrap ! yes, re-enter trap with type T_AST
3169: mov T_AST, %o0
3170:
3171: btst %l5, %l4 ! if (wim & l5)
3172: bnz 1f ! goto reload;
3173: wr %l0, 0, %psr ! restore cond codes
3174: nop ! (three instruction delay)
3175: RETT
3176:
3177: /*
3178: * Previous window is invalid.
3179: * Before we try to load it, we must verify its stack pointer.
3180: * This is much like the underflow handler, but a bit easier
3181: * since we can use our own local registers.
3182: */
3183: 1:
3184: btst 7, %fp ! if unaligned, address is invalid
3185: bne rft_invalid
3186: EMPTY
3187:
1.111 pk 3188: sethi %hi(_C_LABEL(pgofset)), %l3
3189: ld [%l3 + %lo(_C_LABEL(pgofset))], %l3
1.62 pk 3190: PTE_OF_ADDR(%fp, %l7, rft_invalid, %l3, NOP_ON_4M_9)
3191: CMP_PTE_USER_READ(%l7, %l5, NOP_ON_4M_10) ! try first page
1.1 deraadt 3192: bne rft_invalid ! no good
3193: EMPTY
1.13 deraadt 3194: SLT_IF_1PAGE_RW(%fp, %l7, %l3)
1.1 deraadt 3195: bl,a rft_user_ok ! only 1 page: ok
3196: wr %g0, 0, %wim
3197: add %fp, 7*8, %l5
1.13 deraadt 3198: add %l3, 62, %l3
1.62 pk 3199: PTE_OF_ADDR(%l5, %l7, rft_invalid, %l3, NOP_ON_4M_11)
3200: CMP_PTE_USER_READ(%l7, %l5, NOP_ON_4M_12) ! check 2nd page too
1.1 deraadt 3201: be,a rft_user_ok
3202: wr %g0, 0, %wim
3203:
3204: /*
3205: * The window we wanted to pull could not be pulled. Instead,
3206: * re-enter trap with type T_RWRET. This will pull the window
3207: * into cpcb->pcb_rw[0] and set cpcb->pcb_nsaved to -1, which we
3208: * will detect when we try to return again.
3209: */
3210: rft_invalid:
3211: b softtrap
3212: mov T_RWRET, %o0
3213:
3214: /*
3215: * The window we want to pull can be pulled directly.
3216: */
3217: rft_user_ok:
3218: ! wr %g0, 0, %wim ! allow us to get into it
3219: wr %l0, 0, %psr ! fix up the cond codes now
3220: nop; nop; nop
3221: restore ! enter window I
3222: restore %g0, 1, %l1 ! enter window X, then %l1 = 1
3223: rd %psr, %l0 ! l0 = (junk << 5) + CWP;
3224: sll %l1, %l0, %l1 ! %wim = 1 << CWP;
3225: wr %l1, 0, %wim
1.111 pk 3226: sethi %hi(cpcb), %l1
3227: ld [%l1 + %lo(cpcb)], %l1
1.1 deraadt 3228: and %l0, 31, %l0
3229: st %l0, [%l1 + PCB_WIM] ! cpcb->pcb_wim = l0 & 31;
3230: save %g0, %g0, %g0 ! back to window I
3231: LOADWIN(%sp) ! suck hard
3232: save %g0, %g0, %g0 ! back to window T
3233: RETT
3234:
3235: /*
3236: * Return from trap. Entered after a
3237: * wr %l0, 0, %psr
3238: * which disables traps so that we can rett; registers are:
3239: *
3240: * %l0 = %psr
3241: * %l1 = return pc
3242: * %l2 = return npc
3243: *
3244: * (%l3..%l7 anything).
3245: *
3246: * If we are returning to user code, we must:
3247: * 1. Check for register windows in the pcb that belong on the stack.
3248: * If there are any, reenter trap with type T_WINOF.
3249: * 2. Make sure the register windows will not underflow. This is
3250: * much easier in kernel mode....
3251: */
3252: return_from_trap:
3253: ! wr %l0, 0, %psr ! disable traps so we can rett
3254: ! (someone else did this already)
3255: and %l0, 31, %l5
3256: set wmask, %l6
3257: ldub [%l6 + %l5], %l5 ! %l5 = 1 << ((CWP + 1) % nwindows)
3258: btst PSR_PS, %l0 ! returning to userland?
3259: bnz rft_kernel ! no, go return to kernel
3260: rd %wim, %l4 ! (read %wim in any case)
3261:
3262: rft_user_or_recover_pcb_windows:
3263: /*
3264: * (entered with %l4=%wim, %l5=wmask[cwp]; %l0..%l2 as usual)
3265: *
3266: * check cpcb->pcb_nsaved:
3267: * if 0, do a `normal' return to user (see rft_user);
3268: * if > 0, cpcb->pcb_rw[] holds registers to be copied to stack;
3269: * if -1, cpcb->pcb_rw[0] holds user registers for rett window
3270: * from an earlier T_RWRET pseudo-trap.
3271: */
1.111 pk 3272: sethi %hi(cpcb), %l6
3273: ld [%l6 + %lo(cpcb)], %l6
1.1 deraadt 3274: ld [%l6 + PCB_NSAVED], %l7
3275: tst %l7
3276: bz,a rft_user
1.111 pk 3277: sethi %hi(_C_LABEL(want_ast)), %l7 ! first instr of rft_user
1.1 deraadt 3278:
3279: bg,a softtrap ! if (pcb_nsaved > 0)
3280: mov T_WINOF, %o0 ! trap(T_WINOF);
3281:
3282: /*
3283: * To get here, we must have tried to return from a previous
3284: * trap and discovered that it would cause a window underflow.
3285: * We then must have tried to pull the registers out of the
3286: * user stack (from the address in %fp==%i6) and discovered
3287: * that it was either unaligned or not loaded in memory, and
3288: * therefore we ran a trap(T_RWRET), which loaded one set of
3289: * registers into cpcb->pcb_pcb_rw[0] (if it had killed the
3290: * process due to a bad stack, we would not be here).
3291: *
3292: * We want to load pcb_rw[0] into the previous window, which
3293: * we know is currently invalid. In other words, we want
3294: * %wim to be 1 << ((cwp + 2) % nwindows).
3295: */
3296: wr %g0, 0, %wim ! enable restores
3297: mov %g6, %l3 ! save g6 in l3
3298: mov %l6, %g6 ! set g6 = &u
3299: st %g0, [%g6 + PCB_NSAVED] ! clear cpcb->pcb_nsaved
3300: restore ! enter window I
3301: restore %g0, 1, %l1 ! enter window X, then %l1 = 1
3302: rd %psr, %l0
3303: sll %l1, %l0, %l1 ! %wim = 1 << CWP;
3304: wr %l1, 0, %wim
3305: and %l0, 31, %l0
3306: st %l0, [%g6 + PCB_WIM] ! cpcb->pcb_wim = CWP;
3307: nop ! unnecessary? old wim was 0...
3308: save %g0, %g0, %g0 ! back to window I
3309: LOADWIN(%g6 + PCB_RW)
3310: save %g0, %g0, %g0 ! back to window T (trap window)
3311: wr %l0, 0, %psr ! cond codes, cond codes everywhere
3312: mov %l3, %g6 ! restore g6
3313: RETT
3314:
3315: ! exported end marker for kernel gdb
1.111 pk 3316: .globl _C_LABEL(endtrapcode)
3317: _C_LABEL(endtrapcode):
1.1 deraadt 3318:
3319: /*
3320: * init_tables(nwin) int nwin;
3321: *
3322: * Set up the uwtab and wmask tables.
3323: * We know nwin > 1.
3324: */
3325: init_tables:
3326: /*
3327: * for (i = -nwin, j = nwin - 2; ++i < 0; j--)
3328: * uwtab[i] = j;
3329: * (loop runs at least once)
3330: */
3331: set uwtab, %o3
3332: sub %g0, %o0, %o1 ! i = -nwin + 1
3333: inc %o1
3334: add %o0, -2, %o2 ! j = nwin - 2;
3335: 0:
3336: stb %o2, [%o3 + %o1] ! uwtab[i] = j;
3337: 1:
3338: inccc %o1 ! ++i < 0?
3339: bl 0b ! yes, continue loop
3340: dec %o2 ! in any case, j--
3341:
3342: /*
3343: * (i now equals 0)
3344: * for (j = nwin - 1; i < nwin; i++, j--)
3345: * uwtab[i] = j;
3346: * (loop runs at least twice)
3347: */
3348: sub %o0, 1, %o2 ! j = nwin - 1
3349: 0:
3350: stb %o2, [%o3 + %o1] ! uwtab[i] = j
3351: inc %o1 ! i++
3352: 1:
3353: cmp %o1, %o0 ! i < nwin?
3354: bl 0b ! yes, continue
3355: dec %o2 ! in any case, j--
3356:
3357: /*
3358: * We observe that, for i in 0..nwin-2, (i+1)%nwin == i+1;
3359: * for i==nwin-1, (i+1)%nwin == 0.
3360: * To avoid adding 1, we run i from 1 to nwin and set
3361: * wmask[i-1].
3362: *
3363: * for (i = j = 1; i < nwin; i++) {
3364: * j <<= 1; (j now == 1 << i)
3365: * wmask[i - 1] = j;
3366: * }
3367: * (loop runs at least once)
3368: */
3369: set wmask - 1, %o3
3370: mov 1, %o1 ! i = 1;
3371: mov 2, %o2 ! j = 2;
3372: 0:
3373: stb %o2, [%o3 + %o1] ! (wmask - 1)[i] = j;
3374: inc %o1 ! i++
3375: cmp %o1, %o0 ! i < nwin?
3376: bl,a 0b ! yes, continue
3377: sll %o2, 1, %o2 ! (and j <<= 1)
3378:
3379: /*
3380: * Now i==nwin, so we want wmask[i-1] = 1.
3381: */
3382: mov 1, %o2 ! j = 1;
3383: retl
3384: stb %o2, [%o3 + %o1] ! (wmask - 1)[i] = j;
3385:
1.13 deraadt 3386: #ifdef SUN4
3387: /*
3388: * getidprom(struct idprom *, sizeof(struct idprom))
3389: */
1.111 pk 3390: _ENTRY(_C_LABEL(getidprom))
1.13 deraadt 3391: set AC_IDPROM, %o2
3392: 1: lduba [%o2] ASI_CONTROL, %o3
3393: stb %o3, [%o0]
3394: inc %o0
3395: inc %o2
3396: dec %o1
3397: cmp %o1, 0
3398: bne 1b
3399: nop
3400: retl
3401: nop
3402: #endif
3403:
1.1 deraadt 3404: dostart:
1.32 pk 3405: /*
3406: * Startup.
3407: *
3408: * We have been loaded in low RAM, at some address which
1.119 christos 3409: * is page aligned (PROM_LOADADDR actually) rather than where we
3410: * want to run (KERNBASE+PROM_LOADADDR). Until we get everything set,
1.32 pk 3411: * we have to be sure to use only pc-relative addressing.
3412: */
3413:
1.27 pk 3414: /*
1.117 christos 3415: * We now use the bootinfo method to pass arguments, and the new
1.153 pk 3416: * magic number indicates that. A pointer to the kernel top, i.e.
3417: * the first address after the load kernel image (including DDB
3418: * symbols, if any) is passed in %o4[0] and the bootinfo structure
3419: * is passed in %o4[1].
3420: *
3421: * A magic number is passed in %o5 to allow for bootloaders
3422: * that know nothing about the bootinfo structure or previous
3423: * DDB symbol loading conventions.
1.117 christos 3424: *
3425: * For compatibility with older versions, we check for DDB arguments
1.153 pk 3426: * if the older magic number is there. The loader passes `kernel_top'
3427: * (previously known as `esym') in %o4.
3428: *
1.40 pk 3429: * Note: we don't touch %o1-%o3; SunOS bootloaders seem to use them
3430: * for their own mirky business.
1.73 pk 3431: *
1.153 pk 3432: * Pre-NetBSD 1.3 bootblocks had KERNBASE compiled in, and used it
3433: * to compute the value of `kernel_top' (previously known as `esym').
3434: * In order to successfully boot a kernel built with a different value
3435: * for KERNBASE using old bootblocks, we fixup `kernel_top' here by
3436: * the difference between KERNBASE and the old value (known to be
3437: * 0xf8000000) compiled into pre-1.3 bootblocks.
1.27 pk 3438: */
1.117 christos 3439: set KERNBASE, %l4
3440:
3441: set 0x44444232, %l3 ! bootinfo magic
3442: cmp %o5, %l3
3443: bne 1f
1.118 pk 3444: nop
3445:
3446: /* The loader has passed to us a `bootinfo' structure */
1.153 pk 3447: ld [%o4], %l3 ! 1st word is kernel_top
3448: add %l3, %l4, %o5 ! relocate: + KERNBASE
3449: sethi %hi(_C_LABEL(kernel_top) - KERNBASE), %l3 ! and store it
3450: st %o5, [%l3 + %lo(_C_LABEL(kernel_top) - KERNBASE)]
1.120 pk 3451:
3452: ld [%o4 + 4], %l3 ! 2nd word is bootinfo
1.117 christos 3453: add %l3, %l4, %o5 ! relocate
3454: sethi %hi(_C_LABEL(bootinfo) - KERNBASE), %l3 ! store bootinfo
3455: st %o5, [%l3 + %lo(_C_LABEL(bootinfo) - KERNBASE)]
1.153 pk 3456: b,a 4f
1.117 christos 3457:
1.118 pk 3458: 1:
1.153 pk 3459: #ifdef DDB
1.120 pk 3460: /* Check for old-style DDB loader magic */
1.153 pk 3461: set 0x44444231, %l3 ! Is it DDB_MAGIC1?
1.117 christos 3462: cmp %o5, %l3
1.118 pk 3463: be,a 2f
3464: clr %l4 ! if DDB_MAGIC1, clear %l4
1.115 christos 3465:
1.153 pk 3466: set 0x44444230, %l3 ! Is it DDB_MAGIC0?
3467: cmp %o5, %l3 ! if so, need to relocate %o4
1.154 thorpej 3468: bne 3f /* if not, there's no bootloader info */
1.73 pk 3469:
1.118 pk 3470: ! note: %l4 set to KERNBASE above.
1.73 pk 3471: set 0xf8000000, %l5 ! compute correction term:
3472: sub %l5, %l4, %l4 ! old KERNBASE (0xf8000000 ) - KERNBASE
3473:
1.117 christos 3474: 2:
1.40 pk 3475: tst %o4 ! do we have the symbols?
1.117 christos 3476: bz 3f
1.73 pk 3477: sub %o4, %l4, %o4 ! apply compat correction
1.153 pk 3478: sethi %hi(_C_LABEL(kernel_top) - KERNBASE), %l3 ! and store it
3479: st %o4, [%l3 + %lo(_C_LABEL(kernel_top) - KERNBASE)]
3480: b,a 4f
1.117 christos 3481: 3:
1.27 pk 3482: #endif
1.13 deraadt 3483: /*
1.153 pk 3484: * The boot loader did not pass in a value for `kernel_top';
3485: * let it default to `end'.
3486: */
3487: set end, %o4
3488: sethi %hi(_C_LABEL(kernel_top) - KERNBASE), %l3 ! store kernel_top
3489: st %o4, [%l3 + %lo(_C_LABEL(kernel_top) - KERNBASE)]
3490:
3491: 4:
3492:
3493: /*
1.13 deraadt 3494: * Sun4 passes in the `load address'. Although possible, its highly
3495: * unlikely that OpenBoot would place the prom vector there.
3496: */
1.119 christos 3497: set PROM_LOADADDR, %g7
1.17 pk 3498: cmp %o0, %g7
1.50 pk 3499: be is_sun4
1.14 deraadt 3500: nop
3501:
1.158 ! thorpej 3502: #if defined(SUN4C) || defined(SUN4M) || defined(SUN4D)
1.144 uwe 3503: /*
3504: * Be prepared to get OF client entry in either %o0 or %o3.
1.158 ! thorpej 3505: * XXX Will this ever trip on sun4d? Let's hope not!
1.144 uwe 3506: */
3507: cmp %o0, 0
3508: be is_openfirm
3509: nop
3510:
3511: mov %o0, %g7 ! save romp passed by boot code
1.9 deraadt 3512:
1.109 pk 3513: /* First, check `romp->pv_magic' */
3514: ld [%g7 + PV_MAGIC], %o0 ! v = pv->pv_magic
3515: set OBP_MAGIC, %o1
3516: cmp %o0, %o1 ! if ( v != OBP_MAGIC) {
1.144 uwe 3517: bne is_sun4m ! assume this is an OPENFIRM machine
1.109 pk 3518: nop ! }
3519:
1.13 deraadt 3520: /*
1.158 ! thorpej 3521: * are we on a sun4c or a sun4m or a sun4d?
1.13 deraadt 3522: */
1.28 deraadt 3523: ld [%g7 + PV_NODEOPS], %o4 ! node = pv->pv_nodeops->no_nextnode(0)
3524: ld [%o4 + NO_NEXTNODE], %o4
1.18 deraadt 3525: call %o4
3526: mov 0, %o0 ! node
1.37 pk 3527:
3528: mov %o0, %l0
1.111 pk 3529: set cputypvar-KERNBASE, %o1 ! name = "compatible"
3530: set cputypval-KERNBASE, %o2 ! buffer ptr (assume buffer long enough)
1.28 deraadt 3531: ld [%g7 + PV_NODEOPS], %o4 ! (void)pv->pv_nodeops->no_getprop(...)
3532: ld [%o4 + NO_GETPROP], %o4
1.18 deraadt 3533: call %o4
3534: nop
1.111 pk 3535: set cputypval-KERNBASE, %o2 ! buffer ptr
1.18 deraadt 3536: ldub [%o2 + 4], %o0 ! which is it... "sun4c", "sun4m", "sun4d"?
3537: cmp %o0, 'c'
1.50 pk 3538: be is_sun4c
1.13 deraadt 3539: nop
1.18 deraadt 3540: cmp %o0, 'm'
1.50 pk 3541: be is_sun4m
1.18 deraadt 3542: nop
1.158 ! thorpej 3543: cmp %o0, 'd'
! 3544: be is_sun4d
! 3545: nop
! 3546: #endif /* SUN4C || SUN4M || SUN4D */
1.18 deraadt 3547:
1.158 ! thorpej 3548: /*
! 3549: * Don't know what type of machine this is; just halt back
! 3550: * out to the PROM.
! 3551: */
1.28 deraadt 3552: ld [%g7 + PV_HALT], %o1 ! by this kernel, then halt
1.18 deraadt 3553: call %o1
3554: nop
3555:
1.109 pk 3556: is_openfirm:
1.144 uwe 3557: ! OF client entry in %o3 (kernel booted directly by PROM?)
3558: mov %o3, %g7
1.109 pk 3559: /* FALLTHROUGH to sun4m case */
3560:
1.18 deraadt 3561: is_sun4m:
1.13 deraadt 3562: #if defined(SUN4M)
1.52 pk 3563: set trapbase_sun4m, %g6
1.13 deraadt 3564: mov SUN4CM_PGSHIFT, %g5
3565: b start_havetype
3566: mov CPU_SUN4M, %g4
3567: #else
1.9 deraadt 3568: set sun4m_notsup-KERNBASE, %o0
1.28 deraadt 3569: ld [%g7 + PV_EVAL], %o1
1.9 deraadt 3570: call %o1 ! print a message saying that the
3571: nop ! sun4m architecture is not supported
1.158 ! thorpej 3572: ld [%g7 + PV_HALT], %o1 ! by this kernel, then halt
! 3573: call %o1
! 3574: nop
! 3575: /*NOTREACHED*/
! 3576: #endif
! 3577: is_sun4d:
! 3578: #if defined(SUN4D)
! 3579: set trapbase_sun4d, %g6
! 3580: mov SUN4CM_PGSHIFT, %g5
! 3581: b start_havetype
! 3582: mov CPU_SUN4D, %g4
! 3583: #else
! 3584: set sun4d_notsup-KERNBASE, %o0
! 3585: ld [%g7 + PV_EVAL], %o1
! 3586: call %o1 ! print a message saying that the
! 3587: nop ! sun4d architecture is not supported
1.28 deraadt 3588: ld [%g7 + PV_HALT], %o1 ! by this kernel, then halt
1.9 deraadt 3589: call %o1
3590: nop
1.13 deraadt 3591: /*NOTREACHED*/
3592: #endif
3593: is_sun4c:
3594: #if defined(SUN4C)
1.52 pk 3595: set trapbase_sun4c, %g6
1.13 deraadt 3596: mov SUN4CM_PGSHIFT, %g5
3597:
3598: set AC_CONTEXT, %g1 ! paranoia: set context to kernel
3599: stba %g0, [%g1] ASI_CONTROL
3600:
3601: b start_havetype
3602: mov CPU_SUN4C, %g4 ! XXX CPU_SUN4
1.9 deraadt 3603: #else
3604: set sun4c_notsup-KERNBASE, %o0
1.28 deraadt 3605:
3606: ld [%g7 + PV_ROMVEC_VERS], %o1
3607: cmp %o1, 0
3608: bne 1f
3609: nop
3610:
3611: ! stupid version 0 rom interface is pv_eval(int length, char *string)
3612: mov %o0, %o1
3613: 2: ldub [%o0], %o4
3614: bne 2b
3615: inc %o0
3616: dec %o0
3617: sub %o0, %o1, %o0
3618:
3619: 1: ld [%g7 + PV_EVAL], %o2
3620: call %o2 ! print a message saying that the
1.9 deraadt 3621: nop ! sun4c architecture is not supported
1.28 deraadt 3622: ld [%g7 + PV_HALT], %o1 ! by this kernel, then halt
1.9 deraadt 3623: call %o1
3624: nop
1.13 deraadt 3625: /*NOTREACHED*/
1.9 deraadt 3626: #endif
1.13 deraadt 3627: is_sun4:
3628: #if defined(SUN4)
1.52 pk 3629: set trapbase_sun4, %g6
1.13 deraadt 3630: mov SUN4_PGSHIFT, %g5
1.1 deraadt 3631:
1.13 deraadt 3632: set AC_CONTEXT, %g1 ! paranoia: set context to kernel
3633: stba %g0, [%g1] ASI_CONTROL
3634:
3635: b start_havetype
1.14 deraadt 3636: mov CPU_SUN4, %g4
1.13 deraadt 3637: #else
1.14 deraadt 3638: set PROM_BASE, %g7
3639:
1.13 deraadt 3640: set sun4_notsup-KERNBASE, %o0
1.28 deraadt 3641: ld [%g7 + OLDMON_PRINTF], %o1
1.13 deraadt 3642: call %o1 ! print a message saying that the
3643: nop ! sun4 architecture is not supported
1.28 deraadt 3644: ld [%g7 + OLDMON_HALT], %o1 ! by this kernel, then halt
1.13 deraadt 3645: call %o1
3646: nop
3647: /*NOTREACHED*/
3648: #endif
3649:
3650: start_havetype:
1.1 deraadt 3651: /*
3652: * Step 1: double map low RAM (addresses [0.._end-start-1])
3653: * to KERNBASE (addresses [KERNBASE.._end-1]). None of these
3654: * are `bad' aliases (since they are all on segment boundaries)
3655: * so we do not have to worry about cache aliasing.
3656: *
3657: * We map in another couple of segments just to have some
3658: * more memory (512K, actually) guaranteed available for
3659: * bootstrap code (pmap_bootstrap needs memory to hold MMU
1.39 pk 3660: * and context data structures). Note: this is only relevant
3661: * for 2-level MMU sun4/sun4c machines.
1.1 deraadt 3662: */
3663: clr %l0 ! lowva
3664: set KERNBASE, %l1 ! highva
1.153 pk 3665:
3666: sethi %hi(_C_LABEL(kernel_top) - KERNBASE), %o0
3667: ld [%o0 + %lo(_C_LABEL(kernel_top) - KERNBASE)], %o1
3668: set (2 << 18), %o2 ! add slack for sun4c MMU
3669: add %o1, %o2, %l2 ! last va that must be remapped
3670:
1.13 deraadt 3671: /*
3672: * Need different initial mapping functions for different
3673: * types of machines.
3674: */
3675: #if defined(SUN4C)
3676: cmp %g4, CPU_SUN4C
1.9 deraadt 3677: bne 1f
1.14 deraadt 3678: set 1 << 18, %l3 ! segment size in bytes
1.1 deraadt 3679: 0:
3680: lduba [%l0] ASI_SEGMAP, %l4 ! segmap[highva] = segmap[lowva];
3681: stba %l4, [%l1] ASI_SEGMAP
3682: add %l3, %l1, %l1 ! highva += segsiz;
3683: cmp %l1, %l2 ! done?
1.34 pk 3684: blu 0b ! no, loop
1.1 deraadt 3685: add %l3, %l0, %l0 ! (and lowva += segsz)
1.135 pk 3686: b,a startmap_done
1.52 pk 3687: 1:
1.13 deraadt 3688: #endif /* SUN4C */
1.135 pk 3689:
1.13 deraadt 3690: #if defined(SUN4)
3691: cmp %g4, CPU_SUN4
3692: bne 2f
1.114 pk 3693: #if defined(SUN4_MMU3L)
1.34 pk 3694: set AC_IDPROM+1, %l3
3695: lduba [%l3] ASI_CONTROL, %l3
3696: cmp %l3, 0x24 ! XXX - SUN4_400
3697: bne no_3mmu
1.133 pk 3698: nop
1.135 pk 3699:
3700: /*
3701: * Three-level sun4 MMU.
3702: * Double-map by duplicating a single region entry (which covers
3703: * 16MB) corresponding to the kernel's virtual load address.
3704: */
1.34 pk 3705: add %l0, 2, %l0 ! get to proper half-word in RG space
3706: add %l1, 2, %l1
3707: lduha [%l0] ASI_REGMAP, %l4 ! regmap[highva] = regmap[lowva];
3708: stha %l4, [%l1] ASI_REGMAP
1.135 pk 3709: b,a startmap_done
1.34 pk 3710: no_3mmu:
3711: #endif
1.135 pk 3712:
3713: /*
3714: * Three-level sun4 MMU.
3715: * Double-map by duplicating the required number of segment
3716: * entries corresponding to the kernel's virtual load address.
3717: */
3718: set 1 << 18, %l3 ! segment size in bytes
1.13 deraadt 3719: 0:
3720: lduha [%l0] ASI_SEGMAP, %l4 ! segmap[highva] = segmap[lowva];
3721: stha %l4, [%l1] ASI_SEGMAP
3722: add %l3, %l1, %l1 ! highva += segsiz;
3723: cmp %l1, %l2 ! done?
1.34 pk 3724: blu 0b ! no, loop
1.13 deraadt 3725: add %l3, %l0, %l0 ! (and lowva += segsz)
1.37 pk 3726: b,a startmap_done
1.52 pk 3727: 2:
1.13 deraadt 3728: #endif /* SUN4 */
1.135 pk 3729:
1.9 deraadt 3730: #if defined(SUN4M)
1.13 deraadt 3731: cmp %g4, CPU_SUN4M ! skip for sun4m!
3732: bne 3f
3733:
1.37 pk 3734: /*
1.38 pk 3735: * The OBP guarantees us a 16MB mapping using a level 1 PTE at
1.135 pk 3736: * the start of the memory bank in which we were loaded. All we
3737: * have to do is copy the entry.
3738: * Also, we must check to see if we have a TI Viking in non-mbus mode,
3739: * and if so do appropriate flipping and turning off traps before
1.38 pk 3740: * we dork with MMU passthrough. -grrr
1.37 pk 3741: */
3742:
1.38 pk 3743: sethi %hi(0x40000000), %o1 ! TI version bit
3744: rd %psr, %o0
3745: andcc %o0, %o1, %g0
3746: be remap_notvik ! is non-TI normal MBUS module
3747: lda [%g0] ASI_SRMMU, %o0 ! load MMU
3748: andcc %o0, 0x800, %g0
3749: bne remap_notvik ! It is a viking MBUS module
3750: nop
3751:
3752: /*
3753: * Ok, we have a non-Mbus TI Viking, a MicroSparc.
3754: * In this scenerio, in order to play with the MMU
3755: * passthrough safely, we need turn off traps, flip
3756: * the AC bit on in the mmu status register, do our
3757: * passthroughs, then restore the mmu reg and %psr
3758: */
3759: rd %psr, %o4 ! saved here till done
3760: andn %o4, 0x20, %o5
3761: wr %o5, 0x0, %psr
3762: nop; nop; nop;
3763: set SRMMU_CXTPTR, %o0
3764: lda [%o0] ASI_SRMMU, %o0 ! get context table ptr
3765: sll %o0, 4, %o0 ! make physical
3766: lda [%g0] ASI_SRMMU, %o3 ! hold mmu-sreg here
3767: /* 0x8000 is AC bit in Viking mmu-ctl reg */
3768: set 0x8000, %o2
3769: or %o3, %o2, %o2
3770: sta %o2, [%g0] ASI_SRMMU ! AC bit on
1.135 pk 3771:
1.38 pk 3772: lda [%o0] ASI_BYPASS, %o1
3773: srl %o1, 4, %o1
3774: sll %o1, 8, %o1 ! get phys addr of l1 entry
3775: lda [%o1] ASI_BYPASS, %l4
3776: srl %l1, 22, %o2 ! note: 22 == RGSHIFT - 2
3777: add %o1, %o2, %o1
3778: sta %l4, [%o1] ASI_BYPASS
1.135 pk 3779:
1.38 pk 3780: sta %o3, [%g0] ASI_SRMMU ! restore mmu-sreg
3781: wr %o4, 0x0, %psr ! restore psr
1.37 pk 3782: b,a startmap_done
1.38 pk 3783:
3784: /*
3785: * The following is generic and should work on all
3786: * Mbus based SRMMU's.
3787: */
3788: remap_notvik:
3789: set SRMMU_CXTPTR, %o0
3790: lda [%o0] ASI_SRMMU, %o0 ! get context table ptr
3791: sll %o0, 4, %o0 ! make physical
3792: lda [%o0] ASI_BYPASS, %o1
3793: srl %o1, 4, %o1
3794: sll %o1, 8, %o1 ! get phys addr of l1 entry
3795: lda [%o1] ASI_BYPASS, %l4
3796: srl %l1, 22, %o2 ! note: 22 == RGSHIFT - 2
3797: add %o1, %o2, %o1
3798: sta %l4, [%o1] ASI_BYPASS
1.52 pk 3799: !b,a startmap_done
1.38 pk 3800:
1.52 pk 3801: 3:
1.9 deraadt 3802: #endif /* SUN4M */
1.13 deraadt 3803: ! botch! We should blow up.
3804:
3805: startmap_done:
1.1 deraadt 3806: /*
3807: * All set, fix pc and npc. Once we are where we should be,
3808: * we can give ourselves a stack and enable traps.
3809: */
1.9 deraadt 3810: set 1f, %g1
3811: jmp %g1
1.1 deraadt 3812: nop
3813: 1:
1.111 pk 3814: sethi %hi(_C_LABEL(cputyp)), %o0 ! what type of cpu we are on
3815: st %g4, [%o0 + %lo(_C_LABEL(cputyp))]
1.9 deraadt 3816:
1.111 pk 3817: sethi %hi(_C_LABEL(pgshift)), %o0 ! pgshift = log2(nbpg)
3818: st %g5, [%o0 + %lo(_C_LABEL(pgshift))]
1.13 deraadt 3819:
3820: mov 1, %o0 ! nbpg = 1 << pgshift
3821: sll %o0, %g5, %g5
1.111 pk 3822: sethi %hi(_C_LABEL(nbpg)), %o0 ! nbpg = bytes in a page
3823: st %g5, [%o0 + %lo(_C_LABEL(nbpg))]
1.13 deraadt 3824:
3825: sub %g5, 1, %g5
1.111 pk 3826: sethi %hi(_C_LABEL(pgofset)), %o0 ! page offset = bytes in a page - 1
3827: st %g5, [%o0 + %lo(_C_LABEL(pgofset))]
1.13 deraadt 3828:
1.9 deraadt 3829: rd %psr, %g3 ! paranoia: make sure ...
3830: andn %g3, PSR_ET, %g3 ! we have traps off
3831: wr %g3, 0, %psr ! so that we can fiddle safely
3832: nop; nop; nop
3833:
3834: wr %g0, 0, %wim ! make sure we can set psr
3835: nop; nop; nop
3836: wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
3837: nop; nop; nop
3838:
3839: wr %g0, 2, %wim ! set initial %wim (w1 invalid)
3840: mov 1, %g1 ! set pcb_wim (log2(%wim) = 1)
1.111 pk 3841: sethi %hi(_C_LABEL(u0) + PCB_WIM), %g2
3842: st %g1, [%g2 + %lo(_C_LABEL(u0) + PCB_WIM)]
1.9 deraadt 3843:
1.1 deraadt 3844: set USRSTACK - CCFSZ, %fp ! as if called from user code
3845: set estack0 - CCFSZ - 80, %sp ! via syscall(boot_me_up) or somesuch
3846: rd %psr, %l0
3847: wr %l0, PSR_ET, %psr
1.9 deraadt 3848: nop; nop; nop
1.1 deraadt 3849:
1.52 pk 3850: /* Export actual trapbase */
1.111 pk 3851: sethi %hi(_C_LABEL(trapbase)), %o0
3852: st %g6, [%o0+%lo(_C_LABEL(trapbase))]
1.52 pk 3853:
1.117 christos 3854: #ifdef notdef
1.1 deraadt 3855: /*
3856: * Step 2: clear BSS. This may just be paranoia; the boot
3857: * loader might already do it for us; but what the hell.
3858: */
3859: set _edata, %o0 ! bzero(edata, end - edata)
3860: set _end, %o1
1.111 pk 3861: call _C_LABEL(bzero)
1.1 deraadt 3862: sub %o1, %o0, %o1
1.117 christos 3863: #endif
1.1 deraadt 3864:
3865: /*
3866: * Stash prom vectors now, after bzero, as it lives in bss
3867: * (which we just zeroed).
3868: * This depends on the fact that bzero does not use %g7.
3869: */
1.111 pk 3870: sethi %hi(_C_LABEL(romp)), %l0
3871: st %g7, [%l0 + %lo(_C_LABEL(romp))]
1.1 deraadt 3872:
3873: /*
3874: * Step 3: compute number of windows and set up tables.
3875: * We could do some of this later.
3876: */
3877: save %sp, -64, %sp
3878: rd %psr, %g1
3879: restore
3880: and %g1, 31, %g1 ! want just the CWP bits
3881: add %g1, 1, %o0 ! compute nwindows
1.111 pk 3882: sethi %hi(_C_LABEL(nwindows)), %o1 ! may as well tell everyone
1.1 deraadt 3883: call init_tables
1.111 pk 3884: st %o0, [%o1 + %lo(_C_LABEL(nwindows))]
1.1 deraadt 3885:
1.148 pk 3886: #if defined(SUN4) || defined(SUN4C)
1.29 deraadt 3887: /*
1.148 pk 3888: * Some sun4/sun4c models have fewer than 8 windows. For extra
1.29 deraadt 3889: * speed, we do not need to save/restore those windows
3890: * The save/restore code has 7 "save"'s followed by 7
3891: * "restore"'s -- we "nop" out the last "save" and first
3892: * "restore"
3893: */
3894: cmp %o0, 8
1.50 pk 3895: be 1f
1.29 deraadt 3896: noplab: nop
1.148 pk 3897: sethi %hi(noplab), %l0
3898: ld [%l0 + %lo(noplab)], %l1
1.29 deraadt 3899: set wb1, %l0
3900: st %l1, [%l0 + 6*4]
3901: st %l1, [%l0 + 7*4]
3902: 1:
3903: #endif
3904:
1.62 pk 3905: #if ((defined(SUN4) || defined(SUN4C)) && defined(SUN4M))
3906:
3907: /*
3908: * Patch instructions at specified labels that start
3909: * per-architecture code-paths.
3910: */
3911: Lgandul: nop
3912:
3913: #define MUNGE(label) \
3914: sethi %hi(label), %o0; \
3915: st %l0, [%o0 + %lo(label)]
3916:
3917: sethi %hi(Lgandul), %o0
3918: ld [%o0 + %lo(Lgandul)], %l0 ! %l0 = NOP
3919:
3920: cmp %g4, CPU_SUN4M
3921: bne,a 1f
3922: nop
3923:
3924: ! this should be automated!
3925: MUNGE(NOP_ON_4M_1)
3926: MUNGE(NOP_ON_4M_2)
3927: MUNGE(NOP_ON_4M_3)
3928: MUNGE(NOP_ON_4M_4)
3929: MUNGE(NOP_ON_4M_5)
3930: MUNGE(NOP_ON_4M_6)
3931: MUNGE(NOP_ON_4M_7)
3932: MUNGE(NOP_ON_4M_8)
3933: MUNGE(NOP_ON_4M_9)
3934: MUNGE(NOP_ON_4M_10)
3935: MUNGE(NOP_ON_4M_11)
3936: MUNGE(NOP_ON_4M_12)
3937: MUNGE(NOP_ON_4M_13)
3938: MUNGE(NOP_ON_4M_14)
1.152 pk 3939: MUNGE(NOP_ON_4M_15)
1.62 pk 3940: b,a 2f
3941:
3942: 1:
1.68 mycroft 3943: MUNGE(NOP_ON_4_4C_1)
1.62 pk 3944:
3945: 2:
3946:
3947: #undef MUNGE
3948: #endif
3949:
1.1 deraadt 3950: /*
3951: * Step 4: change the trap base register, now that our trap handlers
3952: * will function (they need the tables we just set up).
1.52 pk 3953: * This depends on the fact that bzero does not use %g6.
1.1 deraadt 3954: */
1.52 pk 3955: wr %g6, 0, %tbr
1.9 deraadt 3956: nop; nop; nop ! paranoia
1.37 pk 3957:
1.98 pk 3958:
3959: /* Clear `cpuinfo' */
3960: sethi %hi(CPUINFO_VA), %o0 ! bzero(&cpuinfo, NBPG)
3961: sethi %hi(CPUINFO_STRUCTSIZE), %o1
1.111 pk 3962: call _C_LABEL(bzero)
1.98 pk 3963: add %o1, %lo(CPUINFO_STRUCTSIZE), %o1
3964:
1.131 thorpej 3965: /*
3966: * Initialize `cpuinfo' fields which are needed early. Note
3967: * we make the cpuinfo self-reference at the local VA for now.
3968: * It may be changed to reference a global VA later.
3969: */
1.111 pk 3970: set _C_LABEL(u0), %o0 ! cpuinfo.curpcb = u0;
3971: sethi %hi(cpcb), %l0
3972: st %o0, [%l0 + %lo(cpcb)]
1.98 pk 3973:
1.132 pk 3974: sethi %hi(CPUINFO_VA), %o0 ! cpuinfo.ci_self = &cpuinfo;
1.131 thorpej 3975: sethi %hi(_CISELFP), %l0
3976: st %o0, [%l0 + %lo(_CISELFP)]
3977:
1.111 pk 3978: set _C_LABEL(eintstack), %o0 ! cpuinfo.eintstack= _eintstack;
1.101 pk 3979: sethi %hi(_EINTSTACKP), %l0
3980: st %o0, [%l0 + %lo(_EINTSTACKP)]
1.1 deraadt 3981:
3982: /*
1.11 deraadt 3983: * Ready to run C code; finish bootstrap.
1.1 deraadt 3984: */
1.111 pk 3985: call _C_LABEL(bootstrap)
1.1 deraadt 3986: nop
1.11 deraadt 3987:
3988: /*
3989: * Call main. This returns to us after loading /sbin/init into
3990: * user space. (If the exec fails, main() does not return.)
3991: */
1.111 pk 3992: call _C_LABEL(main)
1.11 deraadt 3993: clr %o0 ! our frame arg is ignored
1.89 pk 3994: /*NOTREACHED*/
3995:
1.145 mrg 3996: #if defined(MULTIPROCESSOR)
1.89 pk 3997: /*
3998: * Entry point for non-boot CPUs in MP systems.
3999: */
1.111 pk 4000: .globl _C_LABEL(cpu_hatch)
4001: _C_LABEL(cpu_hatch):
1.89 pk 4002: rd %psr, %g3 ! paranoia: make sure ...
4003: andn %g3, PSR_ET, %g3 ! we have traps off
4004: wr %g3, 0, %psr ! so that we can fiddle safely
4005: nop; nop; nop
4006:
4007: wr %g0, 0, %wim ! make sure we can set psr
4008: nop; nop; nop
4009: wr %g0, PSR_S|PSR_PS|PSR_PIL, %psr ! set initial psr
4010: nop; nop; nop
4011:
4012: wr %g0, 2, %wim ! set initial %wim (w1 invalid)
4013:
4014: /* Initialize Trap Base register */
1.111 pk 4015: sethi %hi(_C_LABEL(trapbase)), %o0
4016: ld [%o0+%lo(_C_LABEL(trapbase))], %g6
1.89 pk 4017: wr %g6, 0, %tbr
4018: nop; nop; nop ! paranoia
4019:
4020: /* Set up a stack */
4021: set USRSTACK - CCFSZ, %fp ! as if called from user code
1.111 pk 4022: sethi %hi(_C_LABEL(cpu_hatchstack)), %o0
4023: ld [%o0+%lo(_C_LABEL(cpu_hatchstack))], %o0
1.102 pk 4024: set USPACE - CCFSZ - 80, %sp
4025: add %sp, %o0, %sp
1.89 pk 4026:
4027: /* Enable traps */
4028: rd %psr, %l0
4029: wr %l0, PSR_ET, %psr
4030: nop; nop; nop
4031:
4032: /* Call C code */
1.111 pk 4033: sethi %hi(_C_LABEL(cpu_hatch_sc)), %o0
4034: call _C_LABEL(cpu_setup)
4035: ld [%o0+%lo(_C_LABEL(cpu_hatch_sc))], %o0
1.89 pk 4036:
1.145 mrg 4037: /* Wait for go_smp_cpus to go */
4038: set _C_LABEL(go_smp_cpus), %l1
1.142 mrg 4039: ld [%l1], %l0
4040: 1:
1.145 mrg 4041: cmp %l0, %g0
1.142 mrg 4042: be 1b
4043: ld [%l1], %l0
4044:
1.145 mrg 4045: #if 0 /* doesn't quite work yet */
4046:
1.142 mrg 4047: set _C_LABEL(proc0), %g3 ! p = proc0
4048: sethi %hi(_C_LABEL(sched_whichqs)), %g2
4049: sethi %hi(cpcb), %g6
4050: sethi %hi(curproc), %g7
4051: st %g0, [%g7 + %lo(curproc)] ! curproc = NULL;
4052:
4053: mov PSR_S|PSR_ET, %g1 ! oldpsr = PSR_S | PSR_ET;
4054: sethi %hi(IDLE_UP), %g5
4055: ld [%g5 + %lo(IDLE_UP)], %g5
4056: st %g5, [%g6 + %lo(cpcb)] ! cpcb = &idle_u
4057: set USPACE-CCFSZ, %o1
4058: add %g5, %o1, %sp ! set new %sp
4059:
4060: #ifdef DEBUG
4061: mov %g5, %o2 ! %o2 = _idle_u
4062: SET_SP_REDZONE(%o2, %o1)
4063: #endif /* DEBUG */
4064:
4065: b idle_enter_no_schedlock
4066: clr %g4 ! lastproc = NULL;
4067: #else
1.89 pk 4068: /* Idle here .. */
1.102 pk 4069: rd %psr, %l0
4070: andn %l0, PSR_PIL, %l0 ! psr &= ~PSR_PIL;
4071: wr %l0, 0, %psr ! (void) spl0();
4072: nop; nop; nop
1.89 pk 4073: 9: ba 9b
4074: nop
1.51 pk 4075: /*NOTREACHED*/
1.142 mrg 4076: #endif
1.145 mrg 4077:
4078: #endif /* MULTIPROCESSOR */
1.1 deraadt 4079:
1.141 mrg 4080: #include "sigcode_state.s"
1.122 christos 4081:
1.111 pk 4082: .globl _C_LABEL(sigcode)
4083: .globl _C_LABEL(esigcode)
4084: _C_LABEL(sigcode):
1.1 deraadt 4085:
1.122 christos 4086: SAVE_STATE
4087:
1.1 deraadt 4088: ldd [%fp + 64], %o0 ! sig, code
4089: ld [%fp + 76], %o3 ! arg3
4090: call %g1 ! (*sa->sa_handler)(sig,code,scp,arg3)
4091: add %fp, 64 + 16, %o2 ! scp
4092:
1.122 christos 4093: RESTORE_STATE
1.1 deraadt 4094:
1.92 pk 4095: ! get registers back & set syscall #
4096: restore %g0, SYS___sigreturn14, %g1
1.1 deraadt 4097: add %sp, 64 + 16, %o0 ! compute scp
4098: t ST_SYSCALL ! sigreturn(scp)
4099: ! sigreturn does not return unless it fails
4100: mov SYS_exit, %g1 ! exit(errno)
4101: t ST_SYSCALL
1.111 pk 4102: _C_LABEL(esigcode):
1.1 deraadt 4103:
4104: /*
4105: * Primitives
1.52 pk 4106: */
1.1 deraadt 4107:
1.63 pk 4108: /*
4109: * General-purpose NULL routine.
4110: */
4111: ENTRY(sparc_noop)
4112: retl
4113: nop
1.1 deraadt 4114:
4115: /*
1.24 deraadt 4116: * getfp() - get stack frame pointer
4117: */
4118: ENTRY(getfp)
4119: retl
4120: mov %fp, %o0
4121:
4122: /*
1.1 deraadt 4123: * copyinstr(fromaddr, toaddr, maxlength, &lencopied)
4124: *
4125: * Copy a null terminated string from the user address space into
4126: * the kernel address space.
4127: */
4128: ENTRY(copyinstr)
4129: ! %o0 = fromaddr, %o1 = toaddr, %o2 = maxlen, %o3 = &lencopied
1.126 chs 4130: mov %o1, %o5 ! save = toaddr;
4131: tst %o2 ! maxlen == 0?
4132: beq,a Lcstoolong ! yes, return ENAMETOOLONG
4133: sethi %hi(cpcb), %o4
4134:
1.1 deraadt 4135: set KERNBASE, %o4
4136: cmp %o0, %o4 ! fromaddr < KERNBASE?
1.126 chs 4137: blu Lcsdocopy ! yes, go do it
4138: sethi %hi(cpcb), %o4 ! (first instr of copy)
1.1 deraadt 4139:
4140: b Lcsdone ! no, return EFAULT
4141: mov EFAULT, %o0
4142:
4143: /*
4144: * copyoutstr(fromaddr, toaddr, maxlength, &lencopied)
4145: *
4146: * Copy a null terminated string from the kernel
4147: * address space to the user address space.
4148: */
4149: ENTRY(copyoutstr)
4150: ! %o0 = fromaddr, %o1 = toaddr, %o2 = maxlen, %o3 = &lencopied
1.126 chs 4151: mov %o1, %o5 ! save = toaddr;
4152: tst %o2 ! maxlen == 0?
4153: beq,a Lcstoolong ! yes, return ENAMETOOLONG
4154: sethi %hi(cpcb), %o4
4155:
1.1 deraadt 4156: set KERNBASE, %o4
4157: cmp %o1, %o4 ! toaddr < KERNBASE?
1.126 chs 4158: blu Lcsdocopy ! yes, go do it
1.111 pk 4159: sethi %hi(cpcb), %o4 ! (first instr of copy)
1.1 deraadt 4160:
4161: b Lcsdone ! no, return EFAULT
4162: mov EFAULT, %o0
4163:
4164: Lcsdocopy:
1.111 pk 4165: ! sethi %hi(cpcb), %o4 ! (done earlier)
4166: ld [%o4 + %lo(cpcb)], %o4 ! catch faults
1.138 chs 4167: set Lcsdone, %g1
1.126 chs 4168: st %g1, [%o4 + PCB_ONFAULT]
1.1 deraadt 4169:
4170: ! XXX should do this in bigger chunks when possible
4171: 0: ! loop:
4172: ldsb [%o0], %g1 ! c = *fromaddr;
4173: tst %g1
4174: stb %g1, [%o1] ! *toaddr++ = c;
4175: be 1f ! if (c == NULL)
4176: inc %o1 ! goto ok;
4177: deccc %o2 ! if (--len > 0) {
1.126 chs 4178: bgu 0b ! fromaddr++;
1.1 deraadt 4179: inc %o0 ! goto loop;
4180: ! }
1.126 chs 4181: Lcstoolong: !
1.1 deraadt 4182: b Lcsdone ! error = ENAMETOOLONG;
4183: mov ENAMETOOLONG, %o0 ! goto done;
4184: 1: ! ok:
4185: clr %o0 ! error = 0;
4186: Lcsdone: ! done:
4187: sub %o1, %o5, %o1 ! len = to - save;
4188: tst %o3 ! if (lencopied)
4189: bnz,a 3f
4190: st %o1, [%o3] ! *lencopied = len;
4191: 3:
4192: retl ! cpcb->pcb_onfault = 0;
4193: st %g0, [%o4 + PCB_ONFAULT]! return (error);
4194:
4195: /*
4196: * copystr(fromaddr, toaddr, maxlength, &lencopied)
4197: *
4198: * Copy a null terminated string from one point to another in
4199: * the kernel address space. (This is a leaf procedure, but
4200: * it does not seem that way to the C compiler.)
4201: */
4202: ENTRY(copystr)
4203: mov %o1, %o5 ! to0 = to;
1.126 chs 4204: tst %o2 ! if (maxlength == 0)
4205: beq,a 2f !
4206: mov ENAMETOOLONG, %o0 ! ret = ENAMETOOLONG; goto done;
4207:
1.1 deraadt 4208: 0: ! loop:
4209: ldsb [%o0], %o4 ! c = *from;
4210: tst %o4
4211: stb %o4, [%o1] ! *to++ = c;
4212: be 1f ! if (c == 0)
4213: inc %o1 ! goto ok;
4214: deccc %o2 ! if (--len > 0) {
1.126 chs 4215: bgu,a 0b ! from++;
1.1 deraadt 4216: inc %o0 ! goto loop;
4217: b 2f ! }
4218: mov ENAMETOOLONG, %o0 ! ret = ENAMETOOLONG; goto done;
4219: 1: ! ok:
4220: clr %o0 ! ret = 0;
4221: 2:
4222: sub %o1, %o5, %o1 ! len = to - to0;
4223: tst %o3 ! if (lencopied)
4224: bnz,a 3f
4225: st %o1, [%o3] ! *lencopied = len;
4226: 3:
4227: retl
4228: nop
4229:
1.52 pk 4230: /*
1.1 deraadt 4231: * Copyin(src, dst, len)
4232: *
4233: * Copy specified amount of data from user space into the kernel.
4234: */
4235: ENTRY(copyin)
4236: set KERNBASE, %o3
4237: cmp %o0, %o3 ! src < KERNBASE?
4238: blu,a Ldocopy ! yes, can try it
1.111 pk 4239: sethi %hi(cpcb), %o3
1.1 deraadt 4240:
4241: /* source address points into kernel space: return EFAULT */
4242: retl
4243: mov EFAULT, %o0
4244:
4245: /*
4246: * Copyout(src, dst, len)
4247: *
4248: * Copy specified amount of data from kernel to user space.
4249: * Just like copyin, except that the `dst' addresses are user space
4250: * rather than the `src' addresses.
4251: */
4252: ENTRY(copyout)
4253: set KERNBASE, %o3
4254: cmp %o1, %o3 ! dst < KERBASE?
4255: blu,a Ldocopy
1.111 pk 4256: sethi %hi(cpcb), %o3
1.1 deraadt 4257:
4258: /* destination address points into kernel space: return EFAULT */
4259: retl
4260: mov EFAULT, %o0
4261:
4262: /*
4263: * ******NOTE****** this depends on bcopy() not using %g7
4264: */
4265: Ldocopy:
1.111 pk 4266: ! sethi %hi(cpcb), %o3
4267: ld [%o3 + %lo(cpcb)], %o3
1.1 deraadt 4268: set Lcopyfault, %o4
4269: mov %o7, %g7 ! save return address
1.111 pk 4270: call _C_LABEL(bcopy) ! bcopy(src, dst, len)
1.1 deraadt 4271: st %o4, [%o3 + PCB_ONFAULT]
4272:
1.111 pk 4273: sethi %hi(cpcb), %o3
4274: ld [%o3 + %lo(cpcb)], %o3
1.1 deraadt 4275: st %g0, [%o3 + PCB_ONFAULT]
4276: jmp %g7 + 8
4277: clr %o0 ! return 0
4278:
4279: ! Copyin or copyout fault. Clear cpcb->pcb_onfault and return EFAULT.
4280: ! Note that although we were in bcopy, there is no state to clean up;
4281: ! the only special thing is that we have to return to [g7 + 8] rather than
4282: ! [o7 + 8].
4283: Lcopyfault:
1.111 pk 4284: sethi %hi(cpcb), %o3
4285: ld [%o3 + %lo(cpcb)], %o3
1.1 deraadt 4286: jmp %g7 + 8
1.138 chs 4287: st %g0, [%o3 + PCB_ONFAULT]
1.1 deraadt 4288:
4289:
4290: /*
4291: * Write all user windows presently in the CPU back to the user's stack.
4292: * We just do `save' instructions until pcb_uw == 0.
4293: *
4294: * p = cpcb;
4295: * nsaves = 0;
4296: * while (p->pcb_uw > 0)
4297: * save(), nsaves++;
4298: * while (--nsaves >= 0)
4299: * restore();
4300: */
4301: ENTRY(write_user_windows)
1.111 pk 4302: sethi %hi(cpcb), %g6
4303: ld [%g6 + %lo(cpcb)], %g6
1.1 deraadt 4304: b 2f
4305: clr %g5
4306: 1:
4307: save %sp, -64, %sp
4308: 2:
4309: ld [%g6 + PCB_UW], %g7
4310: tst %g7
4311: bg,a 1b
4312: inc %g5
4313: 3:
4314: deccc %g5
4315: bge,a 3b
4316: restore
4317: retl
4318: nop
4319:
4320:
1.111 pk 4321: .comm _C_LABEL(want_resched),4
4322: .comm _C_LABEL(want_ast),4
1.1 deraadt 4323: /*
4324: * Masterpaddr is the p->p_addr of the last process on the processor.
4325: * XXX masterpaddr is almost the same as cpcb
4326: * XXX should delete this entirely
4327: */
1.111 pk 4328: .comm _C_LABEL(masterpaddr), 4
1.1 deraadt 4329:
4330: /*
4331: * Switch statistics (for later tweaking):
4332: * nswitchdiff = p1 => p2 (i.e., chose different process)
1.10 deraadt 4333: * nswitchexit = number of calls to switchexit()
1.111 pk 4334: * cnt.v_swtch = total calls to swtch+swtchexit
1.1 deraadt 4335: */
1.111 pk 4336: .comm _C_LABEL(nswitchdiff), 4
4337: .comm _C_LABEL(nswitchexit), 4
1.1 deraadt 4338:
4339: /*
1.10 deraadt 4340: * REGISTER USAGE IN cpu_switch AND switchexit:
1.1 deraadt 4341: * This is split into two phases, more or less
4342: * `before we locate a new proc' and `after'.
4343: * Some values are the same in both phases.
4344: * Note that the %o0-registers are not preserved across
4345: * the psr change when entering a new process, since this
4346: * usually changes the CWP field (hence heavy usage of %g's).
4347: *
4348: * %g1 = oldpsr (excluding ipl bits)
1.111 pk 4349: * %g2 = %hi(whichqs); newpsr
1.1 deraadt 4350: * %g3 = p
4351: * %g4 = lastproc
4352: * %g5 = <free>; newpcb
1.111 pk 4353: * %g6 = %hi(cpcb)
4354: * %g7 = %hi(curproc)
1.1 deraadt 4355: * %o0 = tmp 1
4356: * %o1 = tmp 2
4357: * %o2 = tmp 3
4358: * %o3 = tmp 4; whichqs; vm
4359: * %o4 = tmp 4; which; sswap
4360: * %o5 = tmp 5; q; <free>
4361: */
4362:
4363: /*
1.134 pk 4364: * When calling external functions from cpu_switch() and idle(), we must
4365: * preserve the global registers mentioned above across the call. We also
4366: * set up a stack frame since we will be running in our caller's frame
4367: * in cpu_switch().
4368: */
4369: #define SAVE_GLOBALS_AND_CALL(name) \
4370: save %sp, -CCFSZ, %sp; \
4371: mov %g1, %i0; \
4372: mov %g2, %i1; \
4373: mov %g3, %i2; \
4374: mov %g4, %i3; \
4375: mov %g6, %i4; \
4376: call _C_LABEL(name); \
4377: mov %g7, %i5; \
4378: mov %i5, %g7; \
4379: mov %i4, %g6; \
4380: mov %i3, %g4; \
4381: mov %i2, %g3; \
4382: mov %i1, %g2; \
4383: mov %i0, %g1; \
4384: restore
4385:
4386:
4387: /*
1.10 deraadt 4388: * switchexit is called only from cpu_exit() before the current process
1.88 thorpej 4389: * has freed its vmspace and kernel stack; we must schedule them to be
4390: * freed. (curproc is already NULL.)
1.1 deraadt 4391: *
4392: * We lay the process to rest by changing to the `idle' kernel stack,
4393: * and note that the `last loaded process' is nonexistent.
4394: */
1.10 deraadt 4395: ENTRY(switchexit)
1.88 thorpej 4396: mov %o0, %g2 ! save proc for exit2() call
1.1 deraadt 4397:
4398: /*
4399: * Change pcb to idle u. area, i.e., set %sp to top of stack
1.111 pk 4400: * and %psr to PSR_S|PSR_ET, and set cpcb to point to idle_u.
1.128 pk 4401: * Once we have left the old stack, we can call exit2() to
1.1 deraadt 4402: * destroy it. Call it any sooner and the register windows
4403: * go bye-bye.
4404: */
1.99 pk 4405: #if defined(MULTIPROCESSOR)
1.111 pk 4406: sethi %hi(IDLE_UP), %g5
4407: ld [%g5 + %lo(IDLE_UP)], %g5
1.99 pk 4408: #else
1.111 pk 4409: set _C_LABEL(idle_u), %g5
1.99 pk 4410: #endif
1.111 pk 4411: sethi %hi(cpcb), %g6
1.1 deraadt 4412: mov 1, %g7
4413: wr %g0, PSR_S, %psr ! change to window 0, traps off
4414: wr %g0, 2, %wim ! and make window 1 the trap window
1.111 pk 4415: st %g5, [%g6 + %lo(cpcb)] ! cpcb = &idle_u
1.1 deraadt 4416: st %g7, [%g5 + PCB_WIM] ! idle_u.pcb_wim = log2(2) = 1
1.100 pk 4417: #if defined(MULTIPROCESSOR)
4418: set USPACE-CCFSZ, %o1 !
4419: add %g5, %o1, %sp ! set new %sp
4420: #else
1.111 pk 4421: set _C_LABEL(idle_u) + USPACE-CCFSZ, %sp ! set new %sp
1.100 pk 4422: #endif
4423:
1.1 deraadt 4424: #ifdef DEBUG
1.99 pk 4425: mov %g5, %l6 ! %l6 = _idle_u
1.1 deraadt 4426: SET_SP_REDZONE(%l6, %l5)
4427: #endif
1.137 mrg 4428:
1.1 deraadt 4429: wr %g0, PSR_S|PSR_ET, %psr ! and then enable traps
1.111 pk 4430: call _C_LABEL(exit2) ! exit2(p)
1.88 thorpej 4431: mov %g2, %o0
1.1 deraadt 4432:
4433: /*
1.10 deraadt 4434: * Now fall through to `the last switch'. %g6 was set to
1.128 pk 4435: * %hi(cpcb), but may have been clobbered in exit2(),
1.1 deraadt 4436: * so all the registers described below will be set here.
4437: *
4438: * REGISTER USAGE AT THIS POINT:
4439: * %g1 = oldpsr (excluding ipl bits)
1.111 pk 4440: * %g2 = %hi(whichqs)
1.1 deraadt 4441: * %g4 = lastproc
1.111 pk 4442: * %g6 = %hi(cpcb)
4443: * %g7 = %hi(curproc)
1.1 deraadt 4444: * %o0 = tmp 1
4445: * %o1 = tmp 2
4446: * %o3 = whichqs
4447: */
4448:
1.111 pk 4449: INCR(_C_LABEL(nswitchexit)) ! nswitchexit++;
4450: INCR(_C_LABEL(uvmexp)+V_SWTCH) ! cnt.v_switch++;
1.1 deraadt 4451:
4452: mov PSR_S|PSR_ET, %g1 ! oldpsr = PSR_S | PSR_ET;
1.130 thorpej 4453: sethi %hi(_C_LABEL(sched_whichqs)), %g2
1.1 deraadt 4454: clr %g4 ! lastproc = NULL;
1.111 pk 4455: sethi %hi(cpcb), %g6
4456: sethi %hi(curproc), %g7
1.134 pk 4457: st %g0, [%g7 + %lo(curproc)] ! curproc = NULL;
4458: b,a idle_enter_no_schedlock
1.1 deraadt 4459: /* FALLTHROUGH */
4460:
1.147 pk 4461:
4462: /* Macro used for register window flushing in the context switch code */
4463: #define SAVE save %sp, -64, %sp
4464:
1.1 deraadt 4465: /*
1.10 deraadt 4466: * When no processes are on the runq, switch
1.52 pk 4467: * idles here waiting for something to come ready.
1.1 deraadt 4468: * The registers are set up as noted above.
4469: */
1.134 pk 4470: idle:
1.142 mrg 4471: #if defined(MULTIPROCESSOR)
4472: /*
4473: * Change pcb to idle u. area, i.e., set %sp to top of stack
4474: * and %psr to PSR_S, and set cpcb to point to idle_u.
4475: */
4476: /* XXX: FIXME
4477: * 7 of each:
4478: */
4479: SAVE; SAVE; SAVE; SAVE; SAVE; SAVE; SAVE
4480: restore; restore; restore; restore; restore; restore; restore
4481:
4482: sethi %hi(IDLE_UP), %g5
4483: ld [%g5 + %lo(IDLE_UP)], %g5
4484: rd %psr, %g1 ! oldpsr = %psr;
4485: andn %g1, PSR_PIL|PSR_PS, %g1! oldpsr &= ~(PSR_PIL|PSR_PS);
4486: and %g1, PSR_S|PSR_ET, %g1 ! oldpsr |= PSR_S|PSR_ET;
4487: st %g5, [%g6 + %lo(cpcb)] ! cpcb = &idle_u
4488: set USPACE-CCFSZ, %o1
4489: add %g5, %o1, %sp ! set new %sp
4490: clr %g4 ! lastproc = NULL;
4491:
4492: #ifdef DEBUG
4493: mov %g5, %o2 ! %o2 = _idle_u
4494: SET_SP_REDZONE(%o2, %o1)
4495: #endif /* DEBUG */
4496: #endif /* MULTIPROCESSOR */
4497:
1.134 pk 4498: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
4499: /* Release the scheduler lock */
4500: SAVE_GLOBALS_AND_CALL(sched_unlock_idle)
4501: #endif
1.142 mrg 4502:
1.134 pk 4503: idle_enter_no_schedlock:
1.151 uwe 4504: wr %g1, 0, %psr ! spl0();
1.111 pk 4505: 1: ! spin reading whichqs until nonzero
1.130 thorpej 4506: ld [%g2 + %lo(_C_LABEL(sched_whichqs))], %o3
1.1 deraadt 4507: tst %o3
1.134 pk 4508: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
4509: bnz,a idle_leave
4510: #else
1.1 deraadt 4511: bnz,a Lsw_scan
1.134 pk 4512: #endif
1.151 uwe 4513: ! NB: annulled delay slot (executed when we leave the idle loop)
1.134 pk 4514: wr %g1, PSR_PIL, %psr ! (void) splhigh();
1.128 pk 4515:
4516: ! Check uvm.page_idle_zero
4517: sethi %hi(_C_LABEL(uvm) + UVM_PAGE_IDLE_ZERO), %o3
4518: ld [%o3 + %lo(_C_LABEL(uvm) + UVM_PAGE_IDLE_ZERO)], %o3
4519: tst %o3
4520: bz 1b
4521: nop
4522:
1.134 pk 4523: SAVE_GLOBALS_AND_CALL(uvm_pageidlezero)
4524: b,a 1b
1.128 pk 4525:
1.134 pk 4526: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
4527: idle_leave:
4528: /* Before we leave the idle loop, detain the scheduler lock */
1.154 thorpej 4529: nop;nop;nop; /* just wrote to %psr; delay before doing a `save' */
1.134 pk 4530: SAVE_GLOBALS_AND_CALL(sched_lock_idle)
4531: b,a Lsw_scan
4532: #endif
1.1 deraadt 4533:
4534: Lsw_panic_rq:
4535: sethi %hi(1f), %o0
1.111 pk 4536: call _C_LABEL(panic)
1.1 deraadt 4537: or %lo(1f), %o0, %o0
4538: Lsw_panic_wchan:
4539: sethi %hi(2f), %o0
1.111 pk 4540: call _C_LABEL(panic)
1.1 deraadt 4541: or %lo(2f), %o0, %o0
4542: Lsw_panic_srun:
4543: sethi %hi(3f), %o0
1.111 pk 4544: call _C_LABEL(panic)
1.1 deraadt 4545: or %lo(3f), %o0, %o0
1.10 deraadt 4546: 1: .asciz "switch rq"
4547: 2: .asciz "switch wchan"
4548: 3: .asciz "switch SRUN"
1.52 pk 4549: _ALIGN
1.1 deraadt 4550:
4551: /*
1.10 deraadt 4552: * cpu_switch() picks a process to run and runs it, saving the current
1.1 deraadt 4553: * one away. On the assumption that (since most workstations are
4554: * single user machines) the chances are quite good that the new
4555: * process will turn out to be the current process, we defer saving
4556: * it here until we have found someone to load. If that someone
4557: * is the current process we avoid both store and load.
4558: *
1.10 deraadt 4559: * cpu_switch() is always entered at splstatclock or splhigh.
1.1 deraadt 4560: *
4561: * IT MIGHT BE WORTH SAVING BEFORE ENTERING idle TO AVOID HAVING TO
4562: * SAVE LATER WHEN SOMEONE ELSE IS READY ... MUST MEASURE!
4563: */
1.111 pk 4564: .globl _C_LABEL(__ffstab)
1.10 deraadt 4565: ENTRY(cpu_switch)
1.1 deraadt 4566: /*
4567: * REGISTER USAGE AT THIS POINT:
4568: * %g1 = oldpsr (excluding ipl bits)
1.111 pk 4569: * %g2 = %hi(whichqs)
1.1 deraadt 4570: * %g3 = p
4571: * %g4 = lastproc
4572: * %g5 = tmp 0
1.111 pk 4573: * %g6 = %hi(cpcb)
4574: * %g7 = %hi(curproc)
1.1 deraadt 4575: * %o0 = tmp 1
4576: * %o1 = tmp 2
4577: * %o2 = tmp 3
4578: * %o3 = tmp 4, then at Lsw_scan, whichqs
4579: * %o4 = tmp 5, then at Lsw_scan, which
4580: * %o5 = tmp 6, then at Lsw_scan, q
4581: */
1.142 mrg 4582: mov %o0, %g4 ! lastproc = p;
1.130 thorpej 4583: sethi %hi(_C_LABEL(sched_whichqs)), %g2 ! set up addr regs
1.111 pk 4584: sethi %hi(cpcb), %g6
4585: ld [%g6 + %lo(cpcb)], %o0
1.134 pk 4586: std %o6, [%o0 + PCB_SP] ! cpcb->pcb_<sp,pc> = <sp,pc>;
4587: rd %psr, %g1 ! oldpsr = %psr;
4588: st %g1, [%o0 + PCB_PSR] ! cpcb->pcb_psr = oldpsr;
4589: andn %g1, PSR_PIL, %g1 ! oldpsr &= ~PSR_PIL;
1.142 mrg 4590: sethi %hi(curproc), %g7
1.111 pk 4591: st %g0, [%g7 + %lo(curproc)] ! curproc = NULL;
1.1 deraadt 4592:
4593: Lsw_scan:
4594: nop; nop; nop ! paranoia
1.130 thorpej 4595: ld [%g2 + %lo(_C_LABEL(sched_whichqs))], %o3
1.1 deraadt 4596:
4597: /*
4598: * Optimized inline expansion of `which = ffs(whichqs) - 1';
4599: * branches to idle if ffs(whichqs) was 0.
4600: */
1.111 pk 4601: set _C_LABEL(__ffstab), %o2
1.1 deraadt 4602: andcc %o3, 0xff, %o1 ! byte 0 zero?
4603: bz,a 1f ! yes, try byte 1
4604: srl %o3, 8, %o0
4605: b 2f ! ffs = ffstab[byte0]; which = ffs - 1;
4606: ldsb [%o2 + %o1], %o0
4607: 1: andcc %o0, 0xff, %o1 ! byte 1 zero?
4608: bz,a 1f ! yes, try byte 2
4609: srl %o0, 8, %o0
4610: ldsb [%o2 + %o1], %o0 ! which = ffstab[byte1] + 7;
4611: b 3f
4612: add %o0, 7, %o4
4613: 1: andcc %o0, 0xff, %o1 ! byte 2 zero?
4614: bz,a 1f ! yes, try byte 3
4615: srl %o0, 8, %o0
4616: ldsb [%o2 + %o1], %o0 ! which = ffstab[byte2] + 15;
4617: b 3f
4618: add %o0, 15, %o4
4619: 1: ldsb [%o2 + %o0], %o0 ! ffs = ffstab[byte3] + 24
4620: addcc %o0, 24, %o0 ! (note that ffstab[0] == -24)
4621: bz idle ! if answer was 0, go idle
4622: EMPTY
4623: 2: sub %o0, 1, %o4 ! which = ffs(whichqs) - 1
4624: 3: /* end optimized inline expansion */
4625:
4626: /*
4627: * We found a nonempty run queue. Take its first process.
4628: */
1.130 thorpej 4629: set _C_LABEL(sched_qs), %o5 ! q = &qs[which];
1.1 deraadt 4630: sll %o4, 3, %o0
4631: add %o0, %o5, %o5
4632: ld [%o5], %g3 ! p = q->ph_link;
4633: cmp %g3, %o5 ! if (p == q)
1.10 deraadt 4634: be Lsw_panic_rq ! panic("switch rq");
1.1 deraadt 4635: EMPTY
1.10 deraadt 4636: ld [%g3], %o0 ! tmp0 = p->p_forw;
1.1 deraadt 4637: st %o0, [%o5] ! q->ph_link = tmp0;
1.10 deraadt 4638: st %o5, [%o0 + 4] ! tmp0->p_back = q;
1.1 deraadt 4639: cmp %o0, %o5 ! if (tmp0 == q)
4640: bne 1f
4641: EMPTY
4642: mov 1, %o1 ! whichqs &= ~(1 << which);
4643: sll %o1, %o4, %o1
4644: andn %o3, %o1, %o3
1.130 thorpej 4645: st %o3, [%g2 + %lo(_C_LABEL(sched_whichqs))]
1.1 deraadt 4646: 1:
4647: /*
4648: * PHASE TWO: NEW REGISTER USAGE:
4649: * %g1 = oldpsr (excluding ipl bits)
4650: * %g2 = newpsr
4651: * %g3 = p
4652: * %g4 = lastproc
4653: * %g5 = newpcb
1.111 pk 4654: * %g6 = %hi(cpcb)
4655: * %g7 = %hi(curproc)
1.1 deraadt 4656: * %o0 = tmp 1
4657: * %o1 = tmp 2
4658: * %o2 = tmp 3
4659: * %o3 = vm
4660: */
4661:
4662: /* firewalls */
4663: ld [%g3 + P_WCHAN], %o0 ! if (p->p_wchan)
4664: tst %o0
1.10 deraadt 4665: bne Lsw_panic_wchan ! panic("switch wchan");
1.1 deraadt 4666: EMPTY
4667: ldsb [%g3 + P_STAT], %o0 ! if (p->p_stat != SRUN)
4668: cmp %o0, SRUN
1.10 deraadt 4669: bne Lsw_panic_srun ! panic("switch SRUN");
1.1 deraadt 4670: EMPTY
4671:
4672: /*
4673: * Committed to running process p.
4674: * It may be the same as the one we were running before.
4675: */
1.129 thorpej 4676: mov SONPROC, %o0 ! p->p_stat = SONPROC;
4677: stb %o0, [%g3 + P_STAT]
1.131 thorpej 4678:
4679: /* p->p_cpu initialized in fork1() for single-processor */
4680: #if defined(MULTIPROCESSOR)
1.132 pk 4681: sethi %hi(_CISELFP), %o0 ! p->p_cpu = cpuinfo.ci_self;
4682: ld [%o0 + %lo(_CISELFP)], %o0
1.131 thorpej 4683: st %o0, [%g3 + P_CPU]
4684: #endif
1.129 thorpej 4685:
1.111 pk 4686: sethi %hi(_C_LABEL(want_resched)), %o0 ! want_resched = 0;
4687: st %g0, [%o0 + %lo(_C_LABEL(want_resched))]
1.134 pk 4688: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
4689: /* Done with the run queues; release the scheduler lock */
4690: SAVE_GLOBALS_AND_CALL(sched_unlock_idle)
4691: #endif
1.1 deraadt 4692: ld [%g3 + P_ADDR], %g5 ! newpcb = p->p_addr;
1.10 deraadt 4693: st %g0, [%g3 + 4] ! p->p_back = NULL;
1.1 deraadt 4694: ld [%g5 + PCB_PSR], %g2 ! newpsr = newpcb->pcb_psr;
1.111 pk 4695: st %g3, [%g7 + %lo(curproc)] ! curproc = p;
1.1 deraadt 4696:
4697: cmp %g3, %g4 ! p == lastproc?
4698: be,a Lsw_sameproc ! yes, go return 0
4699: wr %g2, 0, %psr ! (after restoring ipl)
4700:
4701: /*
4702: * Not the old process. Save the old process, if any;
4703: * then load p.
4704: */
4705: tst %g4
4706: be,a Lsw_load ! if no old process, go load
4707: wr %g1, (PIL_CLOCK << 8) | PSR_ET, %psr
4708:
1.111 pk 4709: INCR(_C_LABEL(nswitchdiff)) ! clobbers %o0,%o1
1.1 deraadt 4710: /*
4711: * save: write back all windows (including the current one).
4712: * XXX crude; knows nwindows <= 8
4713: */
1.142 mrg 4714: wb1: /* 7 of each: */
4715: SAVE; SAVE; SAVE; SAVE; SAVE; SAVE; SAVE
1.1 deraadt 4716: restore; restore; restore; restore; restore; restore; restore
4717:
4718: /*
4719: * Load the new process. To load, we must change stacks and
4720: * alter cpcb and %wim, hence we must disable traps. %psr is
4721: * currently equal to oldpsr (%g1) ^ (PIL_CLOCK << 8);
4722: * this means that PSR_ET is on. Likewise, PSR_ET is on
4723: * in newpsr (%g2), although we do not know newpsr's ipl.
4724: *
4725: * We also must load up the `in' and `local' registers.
4726: */
4727: wr %g1, (PIL_CLOCK << 8) | PSR_ET, %psr
4728: Lsw_load:
4729: ! wr %g1, (PIL_CLOCK << 8) | PSR_ET, %psr ! done above
4730: /* compute new wim */
4731: ld [%g5 + PCB_WIM], %o0
4732: mov 1, %o1
4733: sll %o1, %o0, %o0
4734: wr %o0, 0, %wim ! %wim = 1 << newpcb->pcb_wim;
1.76 pk 4735: /* Clear FP & CP enable bits, as well as the PIL field */
1.1 deraadt 4736: /* now must not change %psr for 3 more instrs */
1.76 pk 4737: /*1*/ set PSR_EF|PSR_EC|PSR_PIL, %o0
4738: /*2*/ andn %g2, %o0, %g2 ! newpsr &= ~(PSR_EF|PSR_EC|PSR_PIL);
1.1 deraadt 4739: /*3*/ nop
4740: /* set new psr, but with traps disabled */
4741: wr %g2, PSR_ET, %psr ! %psr = newpsr ^ PSR_ET;
4742: /* set new cpcb */
1.111 pk 4743: st %g5, [%g6 + %lo(cpcb)] ! cpcb = newpcb;
1.1 deraadt 4744: ldd [%g5 + PCB_SP], %o6 ! <sp,pc> = newpcb->pcb_<sp,pc>
4745: /* load window */
4746: ldd [%sp + (0*8)], %l0
4747: ldd [%sp + (1*8)], %l2
4748: ldd [%sp + (2*8)], %l4
4749: ldd [%sp + (3*8)], %l6
4750: ldd [%sp + (4*8)], %i0
4751: ldd [%sp + (5*8)], %i2
4752: ldd [%sp + (6*8)], %i4
4753: ldd [%sp + (7*8)], %i6
4754: #ifdef DEBUG
4755: mov %g5, %o0
4756: SET_SP_REDZONE(%o0, %o1)
4757: CHECK_SP_REDZONE(%o0, %o1)
4758: #endif
1.76 pk 4759: /* finally, enable traps and continue at splclock() */
4760: wr %g2, PIL_CLOCK << 8 , %psr ! psr = newpsr;
1.1 deraadt 4761:
4762: /*
4763: * Now running p. Make sure it has a context so that it
4764: * can talk about user space stuff. (Its pcb_uw is currently
4765: * zero so it is safe to have interrupts going here.)
4766: */
4767: ld [%g3 + P_VMSPACE], %o3 ! vm = p->p_vmspace;
1.71 pk 4768: ld [%o3 + VM_PMAP], %o3 ! pm = vm->vm_map.vm_pmap;
4769: ld [%o3 + PMAP_CTX], %o0 ! if (pm->pm_ctx != NULL)
1.1 deraadt 4770: tst %o0
4771: bnz,a Lsw_havectx ! goto havecontext;
1.71 pk 4772: ld [%o3 + PMAP_CTXNUM], %o0 ! load context number
1.1 deraadt 4773:
4774: /* p does not have a context: call ctx_alloc to get one */
4775: save %sp, -CCFSZ, %sp
1.111 pk 4776: call _C_LABEL(ctx_alloc) ! ctx_alloc(pm);
1.71 pk 4777: mov %i3, %o0
4778:
1.1 deraadt 4779: ret
4780: restore
4781:
4782: /* p does have a context: just switch to it */
4783: Lsw_havectx:
1.52 pk 4784: ! context is in %o0
1.103 pk 4785: ! pmap is in %o3
1.9 deraadt 4786: #if (defined(SUN4) || defined(SUN4C)) && defined(SUN4M)
1.152 pk 4787: NOP_ON_4M_15:
4788: b,a 1f
4789: b,a 2f
1.9 deraadt 4790: #endif
1.152 pk 4791: 1:
1.9 deraadt 4792: #if defined(SUN4) || defined(SUN4C)
1.1 deraadt 4793: set AC_CONTEXT, %o1
4794: retl
1.52 pk 4795: stba %o0, [%o1] ASI_CONTROL ! setcontext(vm->vm_pmap.pm_ctxnum);
1.9 deraadt 4796: #endif
1.152 pk 4797: 2:
1.9 deraadt 4798: #if defined(SUN4M)
1.86 pk 4799: /*
4800: * Flush caches that need to be flushed on context switch.
4801: * We know this is currently only necessary on the sun4m hypersparc.
4802: */
4803: set CPUINFO_VA+CPUINFO_PURE_VCACHE_FLS, %o2
4804: ld [%o2], %o2
4805: mov %o7, %g7 ! save return address
4806: jmpl %o2, %o7 ! this function must not clobber %o0 and %g7
4807: nop
4808:
1.9 deraadt 4809: set SRMMU_CXR, %o1
1.86 pk 4810: jmp %g7 + 8
1.52 pk 4811: sta %o0, [%o1] ASI_SRMMU ! setcontext(vm->vm_pmap.pm_ctxnum);
1.9 deraadt 4812: #endif
1.1 deraadt 4813:
4814: Lsw_sameproc:
4815: /*
4816: * We are resuming the process that was running at the
1.10 deraadt 4817: * call to switch(). Just set psr ipl and return.
1.1 deraadt 4818: */
4819: ! wr %g2, 0 %psr ! %psr = newpsr; (done earlier)
4820: nop
4821: retl
4822: nop
4823:
4824:
4825: /*
4826: * Snapshot the current process so that stack frames are up to date.
1.51 pk 4827: * Only used just before a crash dump.
1.1 deraadt 4828: */
4829: ENTRY(snapshot)
1.67 pk 4830: std %o6, [%o0 + PCB_SP] ! save sp
1.1 deraadt 4831: rd %psr, %o1 ! save psr
4832: st %o1, [%o0 + PCB_PSR]
4833:
4834: /*
1.10 deraadt 4835: * Just like switch(); same XXX comments apply.
1.1 deraadt 4836: * 7 of each. Minor tweak: the 7th restore is
4837: * done after a ret.
4838: */
1.51 pk 4839: SAVE; SAVE; SAVE; SAVE; SAVE; SAVE; SAVE
1.1 deraadt 4840: restore; restore; restore; restore; restore; restore; ret; restore
4841:
1.51 pk 4842:
4843: /*
1.136 pk 4844: * cpu_fork() arrange for proc_trampoline() to run after a process gets
4845: * chosen in switch(). The stack frame will contain a function pointer
4846: * in %l0, and an argument to pass to it in %l2.
1.51 pk 4847: *
4848: * If the function *(%l0) returns, we arrange for an immediate return
4849: * to user mode. This happens in two known cases: after execve(2) of init,
4850: * and when returning a child to user mode after a fork(2).
1.136 pk 4851: *
4852: * If were setting up a kernel thread, the function *(%l0) will not return.
1.51 pk 4853: */
4854: ENTRY(proc_trampoline)
1.136 pk 4855: /*
4856: * Note: cpu_fork() has set up a stack frame for us to run in,
4857: * so we can call other functions from here without using
4858: * `save ... restore'.
4859: */
1.142 mrg 4860: #if defined(MULTIPROCESSOR)
1.136 pk 4861: /* Finish setup in SMP environment: acquire locks etc. */
4862: call _C_LABEL(proc_trampoline_mp)
4863: nop
4864: #endif
4865:
1.139 pk 4866: /* Reset interrupt level */
4867: rd %psr, %o0
4868: andn %o0, PSR_PIL, %o0 ! psr &= ~PSR_PIL;
4869: wr %o0, 0, %psr ! (void) spl0();
4870: nop ! psr delay; the next 2 instructions
4871: ! can safely be made part of the
4872: ! required 3 instructions psr delay
1.136 pk 4873: call %l0
1.51 pk 4874: mov %l1, %o0
4875:
4876: /*
1.150 pk 4877: * Here we finish up as in syscall, but simplified.
4878: * cpu_fork() or sendsig() (if we took a pending signal
4879: * in child_return()) will have set the user-space return
4880: * address in tf_pc. In both cases, %npc should be %pc + 4.
1.51 pk 4881: */
4882: mov PSR_S, %l0 ! user psr (no need to load it)
4883: !?wr %g0, 2, %wim ! %wim = 2
1.150 pk 4884: ld [%sp + CCFSZ + 4], %l1 ! pc = tf->tf_pc from cpu_fork()
1.51 pk 4885: b return_from_syscall
4886: add %l1, 4, %l2 ! npc = pc+4
1.1 deraadt 4887:
4888: /*
4889: * {fu,su}{,i}{byte,word}
4890: */
1.111 pk 4891: _ENTRY(fuiword)
1.1 deraadt 4892: ENTRY(fuword)
4893: set KERNBASE, %o2
4894: cmp %o0, %o2 ! if addr >= KERNBASE...
4895: bgeu Lfsbadaddr
4896: EMPTY
4897: btst 3, %o0 ! or has low bits set...
4898: bnz Lfsbadaddr ! go return -1
4899: EMPTY
1.111 pk 4900: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
4901: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 4902: set Lfserr, %o3
4903: st %o3, [%o2 + PCB_ONFAULT]
4904: ld [%o0], %o0 ! fetch the word
4905: retl ! phew, made it, return the word
1.138 chs 4906: st %g0, [%o2 + PCB_ONFAULT]! but first clear onfault
1.1 deraadt 4907:
4908: Lfserr:
4909: st %g0, [%o2 + PCB_ONFAULT]! error in r/w, clear pcb_onfault
4910: Lfsbadaddr:
4911: retl ! and return error indicator
1.21 deraadt 4912: mov -1, %o0
1.1 deraadt 4913:
4914: /*
4915: * This is just like Lfserr, but it's a global label that allows
4916: * mem_access_fault() to check to see that we don't want to try to
4917: * page in the fault. It's used by fuswintr() etc.
4918: */
1.111 pk 4919: .globl _C_LABEL(Lfsbail)
4920: _C_LABEL(Lfsbail):
1.1 deraadt 4921: st %g0, [%o2 + PCB_ONFAULT]! error in r/w, clear pcb_onfault
4922: retl ! and return error indicator
1.21 deraadt 4923: mov -1, %o0
1.1 deraadt 4924:
4925: /*
4926: * Like fusword but callable from interrupt context.
4927: * Fails if data isn't resident.
4928: */
4929: ENTRY(fuswintr)
4930: set KERNBASE, %o2
4931: cmp %o0, %o2 ! if addr >= KERNBASE
4932: bgeu Lfsbadaddr ! return error
4933: EMPTY
1.111 pk 4934: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfsbail;
4935: ld [%o2 + %lo(cpcb)], %o2
4936: set _C_LABEL(Lfsbail), %o3
1.1 deraadt 4937: st %o3, [%o2 + PCB_ONFAULT]
4938: lduh [%o0], %o0 ! fetch the halfword
4939: retl ! made it
4940: st %g0, [%o2 + PCB_ONFAULT]! but first clear onfault
4941:
4942: ENTRY(fusword)
4943: set KERNBASE, %o2
4944: cmp %o0, %o2 ! if addr >= KERNBASE
4945: bgeu Lfsbadaddr ! return error
4946: EMPTY
1.111 pk 4947: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
4948: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 4949: set Lfserr, %o3
4950: st %o3, [%o2 + PCB_ONFAULT]
4951: lduh [%o0], %o0 ! fetch the halfword
4952: retl ! made it
4953: st %g0, [%o2 + PCB_ONFAULT]! but first clear onfault
4954:
1.111 pk 4955: _ENTRY(fuibyte)
1.1 deraadt 4956: ENTRY(fubyte)
4957: set KERNBASE, %o2
4958: cmp %o0, %o2 ! if addr >= KERNBASE
4959: bgeu Lfsbadaddr ! return error
4960: EMPTY
1.111 pk 4961: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
4962: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 4963: set Lfserr, %o3
4964: st %o3, [%o2 + PCB_ONFAULT]
4965: ldub [%o0], %o0 ! fetch the byte
4966: retl ! made it
4967: st %g0, [%o2 + PCB_ONFAULT]! but first clear onfault
4968:
1.111 pk 4969: _ENTRY(suiword)
1.1 deraadt 4970: ENTRY(suword)
4971: set KERNBASE, %o2
4972: cmp %o0, %o2 ! if addr >= KERNBASE ...
4973: bgeu Lfsbadaddr
4974: EMPTY
4975: btst 3, %o0 ! or has low bits set ...
4976: bnz Lfsbadaddr ! go return error
4977: EMPTY
1.111 pk 4978: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
4979: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 4980: set Lfserr, %o3
4981: st %o3, [%o2 + PCB_ONFAULT]
4982: st %o1, [%o0] ! store the word
4983: st %g0, [%o2 + PCB_ONFAULT]! made it, clear onfault
4984: retl ! and return 0
4985: clr %o0
4986:
4987: ENTRY(suswintr)
4988: set KERNBASE, %o2
4989: cmp %o0, %o2 ! if addr >= KERNBASE
4990: bgeu Lfsbadaddr ! go return error
4991: EMPTY
1.111 pk 4992: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfsbail;
4993: ld [%o2 + %lo(cpcb)], %o2
4994: set _C_LABEL(Lfsbail), %o3
1.1 deraadt 4995: st %o3, [%o2 + PCB_ONFAULT]
4996: sth %o1, [%o0] ! store the halfword
4997: st %g0, [%o2 + PCB_ONFAULT]! made it, clear onfault
4998: retl ! and return 0
4999: clr %o0
5000:
5001: ENTRY(susword)
5002: set KERNBASE, %o2
5003: cmp %o0, %o2 ! if addr >= KERNBASE
5004: bgeu Lfsbadaddr ! go return error
5005: EMPTY
1.111 pk 5006: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
5007: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 5008: set Lfserr, %o3
5009: st %o3, [%o2 + PCB_ONFAULT]
5010: sth %o1, [%o0] ! store the halfword
5011: st %g0, [%o2 + PCB_ONFAULT]! made it, clear onfault
5012: retl ! and return 0
5013: clr %o0
5014:
1.111 pk 5015: _ENTRY(suibyte)
1.1 deraadt 5016: ENTRY(subyte)
5017: set KERNBASE, %o2
5018: cmp %o0, %o2 ! if addr >= KERNBASE
5019: bgeu Lfsbadaddr ! go return error
5020: EMPTY
1.111 pk 5021: sethi %hi(cpcb), %o2 ! cpcb->pcb_onfault = Lfserr;
5022: ld [%o2 + %lo(cpcb)], %o2
1.1 deraadt 5023: set Lfserr, %o3
5024: st %o3, [%o2 + PCB_ONFAULT]
5025: stb %o1, [%o0] ! store the byte
5026: st %g0, [%o2 + PCB_ONFAULT]! made it, clear onfault
5027: retl ! and return 0
5028: clr %o0
5029:
5030: /* probeget and probeset are meant to be used during autoconfiguration */
5031:
5032: /*
5033: * probeget(addr, size) caddr_t addr; int size;
5034: *
5035: * Read or write a (byte,word,longword) from the given address.
5036: * Like {fu,su}{byte,halfword,word} but our caller is supposed
5037: * to know what he is doing... the address can be anywhere.
5038: *
5039: * We optimize for space, rather than time, here.
5040: */
5041: ENTRY(probeget)
5042: ! %o0 = addr, %o1 = (1,2,4)
1.111 pk 5043: sethi %hi(cpcb), %o2
5044: ld [%o2 + %lo(cpcb)], %o2 ! cpcb->pcb_onfault = Lfserr;
1.1 deraadt 5045: set Lfserr, %o5
5046: st %o5, [%o2 + PCB_ONFAULT]
5047: btst 1, %o1
5048: bnz,a 0f ! if (len & 1)
5049: ldub [%o0], %o0 ! value = *(char *)addr;
5050: 0: btst 2, %o1
5051: bnz,a 0f ! if (len & 2)
5052: lduh [%o0], %o0 ! value = *(short *)addr;
5053: 0: btst 4, %o1
5054: bnz,a 0f ! if (len & 4)
5055: ld [%o0], %o0 ! value = *(int *)addr;
5056: 0: retl ! made it, clear onfault and return
5057: st %g0, [%o2 + PCB_ONFAULT]
5058:
5059: /*
5060: * probeset(addr, size, val) caddr_t addr; int size, val;
5061: *
5062: * As above, but we return 0 on success.
5063: */
5064: ENTRY(probeset)
5065: ! %o0 = addr, %o1 = (1,2,4), %o2 = val
1.111 pk 5066: sethi %hi(cpcb), %o3
5067: ld [%o3 + %lo(cpcb)], %o3 ! cpcb->pcb_onfault = Lfserr;
1.1 deraadt 5068: set Lfserr, %o5
1.35 pk 5069: st %o5, [%o3 + PCB_ONFAULT]
1.1 deraadt 5070: btst 1, %o1
5071: bnz,a 0f ! if (len & 1)
5072: stb %o2, [%o0] ! *(char *)addr = value;
5073: 0: btst 2, %o1
5074: bnz,a 0f ! if (len & 2)
5075: sth %o2, [%o0] ! *(short *)addr = value;
5076: 0: btst 4, %o1
5077: bnz,a 0f ! if (len & 4)
5078: st %o2, [%o0] ! *(int *)addr = value;
5079: 0: clr %o0 ! made it, clear onfault and return 0
5080: retl
1.35 pk 5081: st %g0, [%o3 + PCB_ONFAULT]
1.21 deraadt 5082:
5083: /*
1.22 deraadt 5084: * int xldcontrolb(caddr_t, pcb)
5085: * %o0 %o1
1.21 deraadt 5086: *
5087: * read a byte from the specified address in ASI_CONTROL space.
5088: */
1.22 deraadt 5089: ENTRY(xldcontrolb)
1.111 pk 5090: !sethi %hi(cpcb), %o2
5091: !ld [%o2 + %lo(cpcb)], %o2 ! cpcb->pcb_onfault = Lfsbail;
1.22 deraadt 5092: or %o1, %g0, %o2 ! %o2 = %o1
1.111 pk 5093: set _C_LABEL(Lfsbail), %o5
1.21 deraadt 5094: st %o5, [%o2 + PCB_ONFAULT]
5095: lduba [%o0] ASI_CONTROL, %o0 ! read
5096: 0: retl
1.1 deraadt 5097: st %g0, [%o2 + PCB_ONFAULT]
1.78 pk 5098:
5099: /*
5100: * int fkbyte(caddr_t, pcb)
5101: * %o0 %o1
5102: *
5103: * Just like fubyte(), but for kernel space.
5104: * (currently used to work around unexplained transient bus errors
5105: * when reading the VME interrupt vector)
5106: */
5107: ENTRY(fkbyte)
5108: or %o1, %g0, %o2 ! %o2 = %o1
1.111 pk 5109: set _C_LABEL(Lfsbail), %o5
1.78 pk 5110: st %o5, [%o2 + PCB_ONFAULT]
5111: ldub [%o0], %o0 ! fetch the byte
5112: retl ! made it
5113: st %g0, [%o2 + PCB_ONFAULT]! but first clear onfault
1.1 deraadt 5114:
5115:
5116: /*
5117: * copywords(src, dst, nbytes)
5118: *
5119: * Copy `nbytes' bytes from src to dst, both of which are word-aligned;
5120: * nbytes is a multiple of four. It may, however, be zero, in which case
5121: * nothing is to be copied.
5122: */
5123: ENTRY(copywords)
5124: ! %o0 = src, %o1 = dst, %o2 = nbytes
5125: b 1f
5126: deccc 4, %o2
5127: 0:
5128: st %o3, [%o1 + %o2]
5129: deccc 4, %o2 ! while ((n -= 4) >= 0)
5130: 1:
5131: bge,a 0b ! *(int *)(dst+n) = *(int *)(src+n);
5132: ld [%o0 + %o2], %o3
5133: retl
5134: nop
5135:
5136: /*
5137: * qcopy(src, dst, nbytes)
5138: *
5139: * (q for `quad' or `quick', as opposed to b for byte/block copy)
5140: *
5141: * Just like copywords, but everything is multiples of 8.
5142: */
5143: ENTRY(qcopy)
5144: b 1f
5145: deccc 8, %o2
5146: 0:
5147: std %o4, [%o1 + %o2]
5148: deccc 8, %o2
5149: 1:
5150: bge,a 0b
5151: ldd [%o0 + %o2], %o4
5152: retl
5153: nop
5154:
5155: /*
5156: * qzero(addr, nbytes)
5157: *
5158: * Zeroes `nbytes' bytes of a quad-aligned virtual address,
5159: * where nbytes is itself a multiple of 8.
5160: */
5161: ENTRY(qzero)
5162: ! %o0 = addr, %o1 = len (in bytes)
5163: clr %g1
5164: 0:
5165: deccc 8, %o1 ! while ((n =- 8) >= 0)
5166: bge,a 0b
5167: std %g0, [%o0 + %o1] ! *(quad *)(addr + n) = 0;
5168: retl
5169: nop
5170:
5171: /*
1.83 mycroft 5172: * kernel bcopy
1.1 deraadt 5173: * Assumes regions do not overlap; has no useful return value.
5174: *
5175: * Must not use %g7 (see copyin/copyout above).
5176: */
5177:
5178: #define BCOPY_SMALL 32 /* if < 32, copy by bytes */
5179:
5180: ENTRY(bcopy)
5181: cmp %o2, BCOPY_SMALL
5182: Lbcopy_start:
5183: bge,a Lbcopy_fancy ! if >= this many, go be fancy.
5184: btst 7, %o0 ! (part of being fancy)
5185:
5186: /*
5187: * Not much to copy, just do it a byte at a time.
5188: */
5189: deccc %o2 ! while (--len >= 0)
5190: bl 1f
5191: EMPTY
5192: 0:
5193: inc %o0
5194: ldsb [%o0 - 1], %o4 ! (++dst)[-1] = *src++;
5195: stb %o4, [%o1]
5196: deccc %o2
5197: bge 0b
5198: inc %o1
5199: 1:
5200: retl
1.80 mrg 5201: nop
1.1 deraadt 5202: /* NOTREACHED */
5203:
5204: /*
5205: * Plenty of data to copy, so try to do it optimally.
5206: */
5207: Lbcopy_fancy:
5208: ! check for common case first: everything lines up.
5209: ! btst 7, %o0 ! done already
5210: bne 1f
5211: EMPTY
5212: btst 7, %o1
5213: be,a Lbcopy_doubles
5214: dec 8, %o2 ! if all lined up, len -= 8, goto bcopy_doubes
5215:
5216: ! If the low bits match, we can make these line up.
5217: 1:
5218: xor %o0, %o1, %o3 ! t = src ^ dst;
5219: btst 1, %o3 ! if (t & 1) {
5220: be,a 1f
5221: btst 1, %o0 ! [delay slot: if (src & 1)]
5222:
5223: ! low bits do not match, must copy by bytes.
5224: 0:
5225: ldsb [%o0], %o4 ! do {
5226: inc %o0 ! (++dst)[-1] = *src++;
5227: inc %o1
5228: deccc %o2
5229: bnz 0b ! } while (--len != 0);
5230: stb %o4, [%o1 - 1]
5231: retl
1.80 mrg 5232: nop
1.1 deraadt 5233: /* NOTREACHED */
5234:
5235: ! lowest bit matches, so we can copy by words, if nothing else
5236: 1:
5237: be,a 1f ! if (src & 1) {
5238: btst 2, %o3 ! [delay slot: if (t & 2)]
5239:
5240: ! although low bits match, both are 1: must copy 1 byte to align
5241: ldsb [%o0], %o4 ! *dst++ = *src++;
5242: stb %o4, [%o1]
5243: inc %o0
5244: inc %o1
5245: dec %o2 ! len--;
5246: btst 2, %o3 ! } [if (t & 2)]
5247: 1:
5248: be,a 1f ! if (t & 2) {
5249: btst 2, %o0 ! [delay slot: if (src & 2)]
5250: dec 2, %o2 ! len -= 2;
5251: 0:
5252: ldsh [%o0], %o4 ! do {
5253: sth %o4, [%o1] ! *(short *)dst = *(short *)src;
5254: inc 2, %o0 ! dst += 2, src += 2;
5255: deccc 2, %o2 ! } while ((len -= 2) >= 0);
5256: bge 0b
5257: inc 2, %o1
5258: b Lbcopy_mopb ! goto mop_up_byte;
5259: btst 1, %o2 ! } [delay slot: if (len & 1)]
5260: /* NOTREACHED */
5261:
5262: ! low two bits match, so we can copy by longwords
5263: 1:
5264: be,a 1f ! if (src & 2) {
5265: btst 4, %o3 ! [delay slot: if (t & 4)]
5266:
5267: ! although low 2 bits match, they are 10: must copy one short to align
5268: ldsh [%o0], %o4 ! (*short *)dst = *(short *)src;
5269: sth %o4, [%o1]
5270: inc 2, %o0 ! dst += 2;
5271: inc 2, %o1 ! src += 2;
5272: dec 2, %o2 ! len -= 2;
5273: btst 4, %o3 ! } [if (t & 4)]
5274: 1:
5275: be,a 1f ! if (t & 4) {
5276: btst 4, %o0 ! [delay slot: if (src & 4)]
5277: dec 4, %o2 ! len -= 4;
5278: 0:
5279: ld [%o0], %o4 ! do {
5280: st %o4, [%o1] ! *(int *)dst = *(int *)src;
5281: inc 4, %o0 ! dst += 4, src += 4;
5282: deccc 4, %o2 ! } while ((len -= 4) >= 0);
5283: bge 0b
5284: inc 4, %o1
5285: b Lbcopy_mopw ! goto mop_up_word_and_byte;
5286: btst 2, %o2 ! } [delay slot: if (len & 2)]
5287: /* NOTREACHED */
5288:
5289: ! low three bits match, so we can copy by doublewords
5290: 1:
5291: be 1f ! if (src & 4) {
5292: dec 8, %o2 ! [delay slot: len -= 8]
5293: ld [%o0], %o4 ! *(int *)dst = *(int *)src;
5294: st %o4, [%o1]
5295: inc 4, %o0 ! dst += 4, src += 4, len -= 4;
5296: inc 4, %o1
5297: dec 4, %o2 ! }
5298: 1:
5299: Lbcopy_doubles:
5300: ldd [%o0], %o4 ! do {
5301: std %o4, [%o1] ! *(double *)dst = *(double *)src;
5302: inc 8, %o0 ! dst += 8, src += 8;
5303: deccc 8, %o2 ! } while ((len -= 8) >= 0);
5304: bge Lbcopy_doubles
5305: inc 8, %o1
5306:
5307: ! check for a usual case again (save work)
5308: btst 7, %o2 ! if ((len & 7) == 0)
5309: be Lbcopy_done ! goto bcopy_done;
5310:
5311: btst 4, %o2 ! if ((len & 4)) == 0)
5312: be,a Lbcopy_mopw ! goto mop_up_word_and_byte;
5313: btst 2, %o2 ! [delay slot: if (len & 2)]
5314: ld [%o0], %o4 ! *(int *)dst = *(int *)src;
5315: st %o4, [%o1]
5316: inc 4, %o0 ! dst += 4;
5317: inc 4, %o1 ! src += 4;
5318: btst 2, %o2 ! } [if (len & 2)]
5319:
5320: 1:
5321: ! mop up trailing word (if present) and byte (if present).
5322: Lbcopy_mopw:
5323: be Lbcopy_mopb ! no word, go mop up byte
5324: btst 1, %o2 ! [delay slot: if (len & 1)]
5325: ldsh [%o0], %o4 ! *(short *)dst = *(short *)src;
5326: be Lbcopy_done ! if ((len & 1) == 0) goto done;
5327: sth %o4, [%o1]
5328: ldsb [%o0 + 2], %o4 ! dst[2] = src[2];
5329: retl
1.80 mrg 5330: stb %o4, [%o1 + 2]
1.1 deraadt 5331: /* NOTREACHED */
5332:
5333: ! mop up trailing byte (if present).
5334: Lbcopy_mopb:
5335: bne,a 1f
5336: ldsb [%o0], %o4
5337:
5338: Lbcopy_done:
5339: retl
1.80 mrg 5340: nop
1.1 deraadt 5341:
5342: 1:
5343: retl
1.80 mrg 5344: stb %o4,[%o1]
1.1 deraadt 5345: /*
5346: * ovbcopy(src, dst, len): like bcopy, but regions may overlap.
5347: */
5348: ENTRY(ovbcopy)
5349: cmp %o0, %o1 ! src < dst?
5350: bgeu Lbcopy_start ! no, go copy forwards as via bcopy
5351: cmp %o2, BCOPY_SMALL! (check length for doublecopy first)
5352:
5353: /*
5354: * Since src comes before dst, and the regions might overlap,
5355: * we have to do the copy starting at the end and working backwards.
5356: */
5357: add %o2, %o0, %o0 ! src += len
5358: add %o2, %o1, %o1 ! dst += len
5359: bge,a Lback_fancy ! if len >= BCOPY_SMALL, go be fancy
5360: btst 3, %o0
5361:
5362: /*
5363: * Not much to copy, just do it a byte at a time.
5364: */
5365: deccc %o2 ! while (--len >= 0)
5366: bl 1f
5367: EMPTY
5368: 0:
5369: dec %o0 ! *--dst = *--src;
5370: ldsb [%o0], %o4
5371: dec %o1
5372: deccc %o2
5373: bge 0b
5374: stb %o4, [%o1]
5375: 1:
5376: retl
5377: nop
5378:
5379: /*
5380: * Plenty to copy, try to be optimal.
5381: * We only bother with word/halfword/byte copies here.
5382: */
5383: Lback_fancy:
5384: ! btst 3, %o0 ! done already
5385: bnz 1f ! if ((src & 3) == 0 &&
5386: btst 3, %o1 ! (dst & 3) == 0)
5387: bz,a Lback_words ! goto words;
5388: dec 4, %o2 ! (done early for word copy)
5389:
5390: 1:
5391: /*
5392: * See if the low bits match.
5393: */
5394: xor %o0, %o1, %o3 ! t = src ^ dst;
5395: btst 1, %o3
5396: bz,a 3f ! if (t & 1) == 0, can do better
5397: btst 1, %o0
5398:
5399: /*
5400: * Nope; gotta do byte copy.
5401: */
5402: 2:
5403: dec %o0 ! do {
5404: ldsb [%o0], %o4 ! *--dst = *--src;
5405: dec %o1
5406: deccc %o2 ! } while (--len != 0);
5407: bnz 2b
5408: stb %o4, [%o1]
5409: retl
5410: nop
5411:
5412: 3:
5413: /*
5414: * Can do halfword or word copy, but might have to copy 1 byte first.
5415: */
5416: ! btst 1, %o0 ! done earlier
5417: bz,a 4f ! if (src & 1) { /* copy 1 byte */
5418: btst 2, %o3 ! (done early)
5419: dec %o0 ! *--dst = *--src;
5420: ldsb [%o0], %o4
5421: dec %o1
5422: stb %o4, [%o1]
5423: dec %o2 ! len--;
5424: btst 2, %o3 ! }
5425:
5426: 4:
5427: /*
5428: * See if we can do a word copy ((t&2) == 0).
5429: */
5430: ! btst 2, %o3 ! done earlier
5431: bz,a 6f ! if (t & 2) == 0, can do word copy
5432: btst 2, %o0 ! (src&2, done early)
5433:
5434: /*
5435: * Gotta do halfword copy.
5436: */
5437: dec 2, %o2 ! len -= 2;
5438: 5:
5439: dec 2, %o0 ! do {
5440: ldsh [%o0], %o4 ! src -= 2;
5441: dec 2, %o1 ! dst -= 2;
5442: deccc 2, %o0 ! *(short *)dst = *(short *)src;
5443: bge 5b ! } while ((len -= 2) >= 0);
5444: sth %o4, [%o1]
5445: b Lback_mopb ! goto mop_up_byte;
5446: btst 1, %o2 ! (len&1, done early)
5447:
5448: 6:
5449: /*
5450: * We can do word copies, but we might have to copy
5451: * one halfword first.
5452: */
5453: ! btst 2, %o0 ! done already
5454: bz 7f ! if (src & 2) {
5455: dec 4, %o2 ! (len -= 4, done early)
5456: dec 2, %o0 ! src -= 2, dst -= 2;
5457: ldsh [%o0], %o4 ! *(short *)dst = *(short *)src;
5458: dec 2, %o1
5459: sth %o4, [%o1]
5460: dec 2, %o2 ! len -= 2;
5461: ! }
5462:
5463: 7:
5464: Lback_words:
5465: /*
5466: * Do word copies (backwards), then mop up trailing halfword
5467: * and byte if any.
5468: */
5469: ! dec 4, %o2 ! len -= 4, done already
5470: 0: ! do {
5471: dec 4, %o0 ! src -= 4;
5472: dec 4, %o1 ! src -= 4;
5473: ld [%o0], %o4 ! *(int *)dst = *(int *)src;
5474: deccc 4, %o2 ! } while ((len -= 4) >= 0);
5475: bge 0b
5476: st %o4, [%o1]
5477:
5478: /*
5479: * Check for trailing shortword.
5480: */
5481: btst 2, %o2 ! if (len & 2) {
5482: bz,a 1f
5483: btst 1, %o2 ! (len&1, done early)
5484: dec 2, %o0 ! src -= 2, dst -= 2;
5485: ldsh [%o0], %o4 ! *(short *)dst = *(short *)src;
5486: dec 2, %o1
5487: sth %o4, [%o1] ! }
5488: btst 1, %o2
5489:
5490: /*
5491: * Check for trailing byte.
5492: */
5493: 1:
5494: Lback_mopb:
5495: ! btst 1, %o2 ! (done already)
5496: bnz,a 1f ! if (len & 1) {
5497: ldsb [%o0 - 1], %o4 ! b = src[-1];
5498: retl
5499: nop
5500: 1:
5501: retl ! dst[-1] = b;
5502: stb %o4, [%o1 - 1] ! }
5503:
1.79 mrg 5504: /*
5505: * kcopy() is exactly like bcopy except that it set pcb_onfault such that
5506: * when a fault occurs, it is able to return -1 to indicate this to the
5507: * caller.
5508: */
5509: ENTRY(kcopy)
1.111 pk 5510: sethi %hi(cpcb), %o5 ! cpcb->pcb_onfault = Lkcerr;
5511: ld [%o5 + %lo(cpcb)], %o5
1.79 mrg 5512: set Lkcerr, %o3
1.107 mycroft 5513: ld [%o5 + PCB_ONFAULT], %g1! save current onfault handler
1.79 mrg 5514: st %o3, [%o5 + PCB_ONFAULT]
5515:
5516: cmp %o2, BCOPY_SMALL
5517: Lkcopy_start:
5518: bge,a Lkcopy_fancy ! if >= this many, go be fancy.
1.106 pk 5519: btst 7, %o0 ! (part of being fancy)
1.79 mrg 5520:
5521: /*
5522: * Not much to copy, just do it a byte at a time.
5523: */
5524: deccc %o2 ! while (--len >= 0)
1.108 mycroft 5525: bl 1f
5526: EMPTY
1.79 mrg 5527: 0:
1.107 mycroft 5528: ldsb [%o0], %o4 ! *dst++ = *src++;
1.79 mrg 5529: inc %o0
5530: stb %o4, [%o1]
5531: deccc %o2
5532: bge 0b
1.106 pk 5533: inc %o1
1.79 mrg 5534: 1:
1.106 pk 5535: st %g1, [%o5 + PCB_ONFAULT] ! restore onfault
1.79 mrg 5536: retl
1.106 pk 5537: mov 0, %o0 ! delay slot: return success
1.79 mrg 5538: /* NOTREACHED */
5539:
5540: /*
5541: * Plenty of data to copy, so try to do it optimally.
5542: */
5543: Lkcopy_fancy:
5544: ! check for common case first: everything lines up.
5545: ! btst 7, %o0 ! done already
5546: bne 1f
1.108 mycroft 5547: EMPTY
1.79 mrg 5548: btst 7, %o1
5549: be,a Lkcopy_doubles
1.106 pk 5550: dec 8, %o2 ! if all lined up, len -= 8, goto bcopy_doubes
1.79 mrg 5551:
5552: ! If the low bits match, we can make these line up.
5553: 1:
5554: xor %o0, %o1, %o3 ! t = src ^ dst;
5555: btst 1, %o3 ! if (t & 1) {
5556: be,a 1f
1.106 pk 5557: btst 1, %o0 ! [delay slot: if (src & 1)]
1.79 mrg 5558:
5559: ! low bits do not match, must copy by bytes.
5560: 0:
5561: ldsb [%o0], %o4 ! do {
1.107 mycroft 5562: inc %o0 ! *dst++ = *src++;
5563: stb %o4, [%o1]
1.79 mrg 5564: deccc %o2
5565: bnz 0b ! } while (--len != 0);
1.107 mycroft 5566: inc %o1
1.106 pk 5567: st %g1, [%o5 + PCB_ONFAULT] ! restore onfault
1.79 mrg 5568: retl
1.106 pk 5569: mov 0, %o0 ! delay slot: return success
1.79 mrg 5570: /* NOTREACHED */
5571:
5572: ! lowest bit matches, so we can copy by words, if nothing else
5573: 1:
5574: be,a 1f ! if (src & 1) {
1.106 pk 5575: btst 2, %o3 ! [delay slot: if (t & 2)]
1.79 mrg 5576:
5577: ! although low bits match, both are 1: must copy 1 byte to align
5578: ldsb [%o0], %o4 ! *dst++ = *src++;
1.107 mycroft 5579: inc %o0
1.79 mrg 5580: stb %o4, [%o1]
1.107 mycroft 5581: dec %o2 ! len--;
1.79 mrg 5582: inc %o1
5583: btst 2, %o3 ! } [if (t & 2)]
5584: 1:
5585: be,a 1f ! if (t & 2) {
1.106 pk 5586: btst 2, %o0 ! [delay slot: if (src & 2)]
1.79 mrg 5587: dec 2, %o2 ! len -= 2;
5588: 0:
5589: ldsh [%o0], %o4 ! do {
1.107 mycroft 5590: inc 2, %o0 ! dst += 2, src += 2;
1.79 mrg 5591: sth %o4, [%o1] ! *(short *)dst = *(short *)src;
5592: deccc 2, %o2 ! } while ((len -= 2) >= 0);
5593: bge 0b
1.106 pk 5594: inc 2, %o1
1.79 mrg 5595: b Lkcopy_mopb ! goto mop_up_byte;
1.106 pk 5596: btst 1, %o2 ! } [delay slot: if (len & 1)]
1.79 mrg 5597: /* NOTREACHED */
5598:
5599: ! low two bits match, so we can copy by longwords
5600: 1:
5601: be,a 1f ! if (src & 2) {
1.106 pk 5602: btst 4, %o3 ! [delay slot: if (t & 4)]
1.79 mrg 5603:
5604: ! although low 2 bits match, they are 10: must copy one short to align
5605: ldsh [%o0], %o4 ! (*short *)dst = *(short *)src;
1.107 mycroft 5606: inc 2, %o0 ! dst += 2;
1.79 mrg 5607: sth %o4, [%o1]
1.107 mycroft 5608: dec 2, %o2 ! len -= 2;
1.79 mrg 5609: inc 2, %o1 ! src += 2;
5610: btst 4, %o3 ! } [if (t & 4)]
5611: 1:
5612: be,a 1f ! if (t & 4) {
1.106 pk 5613: btst 4, %o0 ! [delay slot: if (src & 4)]
1.79 mrg 5614: dec 4, %o2 ! len -= 4;
5615: 0:
5616: ld [%o0], %o4 ! do {
1.107 mycroft 5617: inc 4, %o0 ! dst += 4, src += 4;
1.79 mrg 5618: st %o4, [%o1] ! *(int *)dst = *(int *)src;
5619: deccc 4, %o2 ! } while ((len -= 4) >= 0);
5620: bge 0b
1.106 pk 5621: inc 4, %o1
1.79 mrg 5622: b Lkcopy_mopw ! goto mop_up_word_and_byte;
1.106 pk 5623: btst 2, %o2 ! } [delay slot: if (len & 2)]
1.79 mrg 5624: /* NOTREACHED */
5625:
5626: ! low three bits match, so we can copy by doublewords
5627: 1:
5628: be 1f ! if (src & 4) {
1.106 pk 5629: dec 8, %o2 ! [delay slot: len -= 8]
1.79 mrg 5630: ld [%o0], %o4 ! *(int *)dst = *(int *)src;
1.107 mycroft 5631: inc 4, %o0 ! dst += 4, src += 4, len -= 4;
1.79 mrg 5632: st %o4, [%o1]
1.107 mycroft 5633: dec 4, %o2 ! }
1.79 mrg 5634: inc 4, %o1
5635: 1:
5636: Lkcopy_doubles:
5637: ! swap %o4 with %o2 during doubles copy, since %o5 is verboten
5638: mov %o2, %o4
5639: Lkcopy_doubles2:
5640: ldd [%o0], %o2 ! do {
1.107 mycroft 5641: inc 8, %o0 ! dst += 8, src += 8;
1.79 mrg 5642: std %o2, [%o1] ! *(double *)dst = *(double *)src;
5643: deccc 8, %o4 ! } while ((len -= 8) >= 0);
5644: bge Lkcopy_doubles2
5645: inc 8, %o1
5646: mov %o4, %o2 ! restore len
5647:
5648: ! check for a usual case again (save work)
5649: btst 7, %o2 ! if ((len & 7) == 0)
5650: be Lkcopy_done ! goto bcopy_done;
5651:
1.106 pk 5652: btst 4, %o2 ! if ((len & 4)) == 0)
1.79 mrg 5653: be,a Lkcopy_mopw ! goto mop_up_word_and_byte;
1.106 pk 5654: btst 2, %o2 ! [delay slot: if (len & 2)]
1.79 mrg 5655: ld [%o0], %o4 ! *(int *)dst = *(int *)src;
1.107 mycroft 5656: inc 4, %o0 ! dst += 4;
1.79 mrg 5657: st %o4, [%o1]
5658: inc 4, %o1 ! src += 4;
5659: btst 2, %o2 ! } [if (len & 2)]
5660:
5661: 1:
5662: ! mop up trailing word (if present) and byte (if present).
5663: Lkcopy_mopw:
5664: be Lkcopy_mopb ! no word, go mop up byte
1.106 pk 5665: btst 1, %o2 ! [delay slot: if (len & 1)]
1.79 mrg 5666: ldsh [%o0], %o4 ! *(short *)dst = *(short *)src;
5667: be Lkcopy_done ! if ((len & 1) == 0) goto done;
1.106 pk 5668: sth %o4, [%o1]
1.79 mrg 5669: ldsb [%o0 + 2], %o4 ! dst[2] = src[2];
5670: stb %o4, [%o1 + 2]
1.106 pk 5671: st %g1, [%o5 + PCB_ONFAULT]! restore onfault
1.79 mrg 5672: retl
1.106 pk 5673: mov 0, %o0 ! delay slot: return success
1.79 mrg 5674: /* NOTREACHED */
5675:
5676: ! mop up trailing byte (if present).
5677: Lkcopy_mopb:
5678: bne,a 1f
1.106 pk 5679: ldsb [%o0], %o4
1.79 mrg 5680:
5681: Lkcopy_done:
1.106 pk 5682: st %g1, [%o5 + PCB_ONFAULT] ! restore onfault
1.79 mrg 5683: retl
1.106 pk 5684: mov 0, %o0 ! delay slot: return success
1.108 mycroft 5685: /* NOTREACHED */
1.79 mrg 5686:
5687: 1:
1.107 mycroft 5688: stb %o4, [%o1]
5689: st %g1, [%o5 + PCB_ONFAULT] ! restore onfault
1.79 mrg 5690: retl
1.107 mycroft 5691: mov 0, %o0 ! delay slot: return success
1.108 mycroft 5692: /* NOTREACHED */
1.107 mycroft 5693:
1.79 mrg 5694: Lkcerr:
1.107 mycroft 5695: retl
1.138 chs 5696: st %g1, [%o5 + PCB_ONFAULT] ! restore onfault
1.108 mycroft 5697: /* NOTREACHED */
1.1 deraadt 5698:
5699: /*
5700: * savefpstate(f) struct fpstate *f;
5701: *
5702: * Store the current FPU state. The first `st %fsr' may cause a trap;
5703: * our trap handler knows how to recover (by `returning' to savefpcont).
5704: */
5705: ENTRY(savefpstate)
5706: rd %psr, %o1 ! enable FP before we begin
5707: set PSR_EF, %o2
5708: or %o1, %o2, %o1
5709: wr %o1, 0, %psr
5710: /* do some setup work while we wait for PSR_EF to turn on */
5711: set FSR_QNE, %o5 ! QNE = 0x2000, too big for immediate
5712: clr %o3 ! qsize = 0;
5713: nop ! (still waiting for PSR_EF)
5714: special_fp_store:
5715: st %fsr, [%o0 + FS_FSR] ! f->fs_fsr = getfsr();
5716: /*
5717: * Even if the preceding instruction did not trap, the queue
5718: * is not necessarily empty: this state save might be happening
5719: * because user code tried to store %fsr and took the FPU
5720: * from `exception pending' mode to `exception' mode.
5721: * So we still have to check the blasted QNE bit.
5722: * With any luck it will usually not be set.
5723: */
5724: ld [%o0 + FS_FSR], %o4 ! if (f->fs_fsr & QNE)
5725: btst %o5, %o4
5726: bnz Lfp_storeq ! goto storeq;
5727: std %f0, [%o0 + FS_REGS + (4*0)] ! f->fs_f0 = etc;
5728: Lfp_finish:
5729: st %o3, [%o0 + FS_QSIZE] ! f->fs_qsize = qsize;
5730: std %f2, [%o0 + FS_REGS + (4*2)]
5731: std %f4, [%o0 + FS_REGS + (4*4)]
5732: std %f6, [%o0 + FS_REGS + (4*6)]
5733: std %f8, [%o0 + FS_REGS + (4*8)]
5734: std %f10, [%o0 + FS_REGS + (4*10)]
5735: std %f12, [%o0 + FS_REGS + (4*12)]
5736: std %f14, [%o0 + FS_REGS + (4*14)]
5737: std %f16, [%o0 + FS_REGS + (4*16)]
5738: std %f18, [%o0 + FS_REGS + (4*18)]
5739: std %f20, [%o0 + FS_REGS + (4*20)]
5740: std %f22, [%o0 + FS_REGS + (4*22)]
5741: std %f24, [%o0 + FS_REGS + (4*24)]
5742: std %f26, [%o0 + FS_REGS + (4*26)]
5743: std %f28, [%o0 + FS_REGS + (4*28)]
5744: retl
5745: std %f30, [%o0 + FS_REGS + (4*30)]
5746:
5747: /*
5748: * Store the (now known nonempty) FP queue.
5749: * We have to reread the fsr each time in order to get the new QNE bit.
5750: */
5751: Lfp_storeq:
5752: add %o0, FS_QUEUE, %o1 ! q = &f->fs_queue[0];
5753: 1:
5754: std %fq, [%o1 + %o3] ! q[qsize++] = fsr_qfront();
5755: st %fsr, [%o0 + FS_FSR] ! reread fsr
5756: ld [%o0 + FS_FSR], %o4 ! if fsr & QNE, loop
5757: btst %o5, %o4
5758: bnz 1b
5759: inc 8, %o3
5760: b Lfp_finish ! set qsize and finish storing fregs
5761: srl %o3, 3, %o3 ! (but first fix qsize)
5762:
5763: /*
5764: * The fsr store trapped. Do it again; this time it will not trap.
5765: * We could just have the trap handler return to the `st %fsr', but
5766: * if for some reason it *does* trap, that would lock us into a tight
5767: * loop. This way we panic instead. Whoopee.
5768: */
5769: savefpcont:
5770: b special_fp_store + 4 ! continue
5771: st %fsr, [%o0 + FS_FSR] ! but first finish the %fsr store
5772:
5773: /*
5774: * Load FPU state.
5775: */
5776: ENTRY(loadfpstate)
5777: rd %psr, %o1 ! enable FP before we begin
5778: set PSR_EF, %o2
5779: or %o1, %o2, %o1
5780: wr %o1, 0, %psr
5781: nop; nop; nop ! paranoia
5782: ldd [%o0 + FS_REGS + (4*0)], %f0
5783: ldd [%o0 + FS_REGS + (4*2)], %f2
5784: ldd [%o0 + FS_REGS + (4*4)], %f4
5785: ldd [%o0 + FS_REGS + (4*6)], %f6
5786: ldd [%o0 + FS_REGS + (4*8)], %f8
5787: ldd [%o0 + FS_REGS + (4*10)], %f10
5788: ldd [%o0 + FS_REGS + (4*12)], %f12
5789: ldd [%o0 + FS_REGS + (4*14)], %f14
5790: ldd [%o0 + FS_REGS + (4*16)], %f16
5791: ldd [%o0 + FS_REGS + (4*18)], %f18
5792: ldd [%o0 + FS_REGS + (4*20)], %f20
5793: ldd [%o0 + FS_REGS + (4*22)], %f22
5794: ldd [%o0 + FS_REGS + (4*24)], %f24
5795: ldd [%o0 + FS_REGS + (4*26)], %f26
5796: ldd [%o0 + FS_REGS + (4*28)], %f28
5797: ldd [%o0 + FS_REGS + (4*30)], %f30
5798: retl
5799: ld [%o0 + FS_FSR], %fsr ! setfsr(f->fs_fsr);
5800:
5801: /*
5802: * ienab_bis(bis) int bis;
5803: * ienab_bic(bic) int bic;
5804: *
5805: * Set and clear bits in the interrupt register.
1.52 pk 5806: */
5807:
5808: #if defined(SUN4M) && (defined(SUN4) || defined(SUN4C))
1.62 pk 5809: ENTRY(ienab_bis)
5810: NOP_ON_4M_13:
1.111 pk 5811: b,a _C_LABEL(ienab_bis_4_4c)
5812: b,a _C_LABEL(ienab_bis_4m)
1.62 pk 5813:
5814: ENTRY(ienab_bic)
5815: NOP_ON_4M_14:
1.111 pk 5816: b,a _C_LABEL(ienab_bic_4_4c)
5817: b,a _C_LABEL(ienab_bic_4m)
1.62 pk 5818: #endif
1.52 pk 5819:
5820: #if defined(SUN4) || defined(SUN4C)
5821: /*
1.1 deraadt 5822: * Since there are no read-modify-write instructions for this,
5823: * and one of the interrupts is nonmaskable, we must disable traps.
5824: */
1.52 pk 5825: #if defined(SUN4M)
1.68 mycroft 5826: ENTRY(ienab_bis_4_4c)
1.52 pk 5827: #else
1.1 deraadt 5828: ENTRY(ienab_bis)
1.52 pk 5829: #endif
1.1 deraadt 5830: ! %o0 = bits to set
5831: rd %psr, %o2
5832: wr %o2, PSR_ET, %psr ! disable traps
5833: nop; nop ! 3-instr delay until ET turns off
1.62 pk 5834: sethi %hi(INTRREG_VA), %o3
5835: ldub [%o3 + %lo(INTRREG_VA)], %o4
5836: or %o4, %o0, %o4 ! *INTRREG_VA |= bis;
5837: stb %o4, [%o3 + %lo(INTRREG_VA)]
1.1 deraadt 5838: wr %o2, 0, %psr ! reenable traps
5839: nop
5840: retl
5841: nop
5842:
1.52 pk 5843: #if defined(SUN4M)
1.68 mycroft 5844: ENTRY(ienab_bic_4_4c)
1.52 pk 5845: #else
1.1 deraadt 5846: ENTRY(ienab_bic)
1.52 pk 5847: #endif
1.1 deraadt 5848: ! %o0 = bits to clear
5849: rd %psr, %o2
5850: wr %o2, PSR_ET, %psr ! disable traps
5851: nop; nop
1.62 pk 5852: sethi %hi(INTRREG_VA), %o3
5853: ldub [%o3 + %lo(INTRREG_VA)], %o4
5854: andn %o4, %o0, %o4 ! *INTRREG_VA &=~ bic;
5855: stb %o4, [%o3 + %lo(INTRREG_VA)]
1.1 deraadt 5856: wr %o2, 0, %psr ! reenable traps
5857: nop
5858: retl
5859: nop
1.52 pk 5860: #endif
5861:
5862: #if defined(SUN4M)
5863: /*
5864: * sun4m has separate registers for clearing/setting the interrupt mask.
5865: */
5866: #if defined(SUN4) || defined(SUN4C)
5867: ENTRY(ienab_bis_4m)
5868: #else
5869: ENTRY(ienab_bis)
5870: #endif
5871: set ICR_SI_SET, %o1
5872: retl
5873: st %o0, [%o1]
5874:
5875: #if defined(SUN4) || defined(SUN4C)
5876: ENTRY(ienab_bic_4m)
5877: #else
5878: ENTRY(ienab_bic)
5879: #endif
5880: set ICR_SI_CLR, %o1
5881: retl
5882: st %o0, [%o1]
5883:
5884: /*
5885: * raise(cpu, level)
5886: */
5887: ENTRY(raise)
1.149 uwe 5888: #if !defined(MSIIEP) /* normal suns */
1.52 pk 5889: ! *(ICR_PI_SET + cpu*_MAXNBPG) = PINTR_SINTRLEV(level)
5890: sethi %hi(1 << 16), %o2
5891: sll %o2, %o1, %o2
5892: set ICR_PI_SET, %o1
5893: set _MAXNBPG, %o3
5894: 1:
5895: subcc %o0, 1, %o0
5896: bpos,a 1b
5897: add %o1, %o3, %o1
5898: retl
5899: st %o2, [%o1]
1.149 uwe 5900: #else /* MSIIEP - ignore %o0, only one cpu ever */
5901: mov 1, %o2
5902: sethi %hi(MSIIEP_PCIC_VA), %o0
5903: sll %o2, %o1, %o2
5904: retl
5905: sth %o2, [%o0 + PCIC_SOFT_INTR_SET_REG]
5906: #endif
1.62 pk 5907:
5908: /*
1.94 pk 5909: * Read Synchronous Fault Status registers.
5910: * On entry: %l1 == PC, %l3 == fault type, %l4 == storage, %l7 == return address
5911: * Only use %l5 and %l6.
5912: * Note: not C callable.
5913: */
1.111 pk 5914: _ENTRY(_C_LABEL(srmmu_get_syncflt))
5915: _ENTRY(_C_LABEL(hypersparc_get_syncflt))
1.94 pk 5916: set SRMMU_SFAR, %l5
5917: lda [%l5] ASI_SRMMU, %l5 ! sync virt addr; must be read first
5918: st %l5, [%l4 + 4] ! => dump.sfva
5919: set SRMMU_SFSR, %l5
5920: lda [%l5] ASI_SRMMU, %l5 ! get sync fault status register
5921: jmp %l7 + 8 ! return to caller
5922: st %l5, [%l4] ! => dump.sfsr
5923:
1.111 pk 5924: _ENTRY(_C_LABEL(viking_get_syncflt))
5925: _ENTRY(_C_LABEL(ms1_get_syncflt))
5926: _ENTRY(_C_LABEL(swift_get_syncflt))
5927: _ENTRY(_C_LABEL(turbosparc_get_syncflt))
5928: _ENTRY(_C_LABEL(cypress_get_syncflt))
1.62 pk 5929: cmp %l3, T_TEXTFAULT
5930: be,a 1f
1.94 pk 5931: mov %l1, %l5 ! use PC if type == T_TEXTFAULT
1.62 pk 5932:
1.94 pk 5933: set SRMMU_SFAR, %l5
5934: lda [%l5] ASI_SRMMU, %l5 ! sync virt addr; must be read first
1.62 pk 5935: 1:
1.94 pk 5936: st %l5, [%l4 + 4] ! => dump.sfva
1.62 pk 5937:
1.94 pk 5938: set SRMMU_SFSR, %l5
5939: lda [%l5] ASI_SRMMU, %l5 ! get sync fault status register
5940: jmp %l7 + 8 ! return to caller
5941: st %l5, [%l4] ! => dump.sfsr
1.62 pk 5942:
1.142 mrg 5943: #if defined(MULTIPROCESSOR) && 0 /* notyet *
5944: /*
5945: * Read Synchronous Fault Status registers.
5946: * On entry: %o0 == &sfsr, %o1 == &sfar
5947: */
5948: _ENTRY(_C_LABEL(smp_get_syncflt))
5949: save %sp, -CCFSZ, %sp
5950:
5951: sethi %hi(CPUINFO_VA), %o4
5952: ld [%l4 + %lo(CPUINFO_VA+CPUINFO_GETSYNCFLT)], %o5
5953: clr %l1
5954: clr %l3
5955: jmpl %o5, %l7
5956: or %o4, %lo(CPUINFO_SYNCFLTDUMP), %l4
5957:
5958: ! load values out of the dump
5959: ld [%o4 + %lo(CPUINFO_VA+CPUINFO_SYNCFLTDUMP)], %o5
5960: st %o5, [%i0]
5961: ld [%o4 + %lo(CPUINFO_VA+CPUINFO_SYNCFLTDUMP+4)], %o5
5962: st %o5, [%i1]
5963: ret
5964: restore
5965: #endif /* MULTIPROCESSOR */
1.62 pk 5966:
1.94 pk 5967: /*
5968: * Read Asynchronous Fault Status registers.
5969: * On entry: %o0 == &afsr, %o1 == &afar
5970: * Return 0 if async register are present.
5971: */
1.111 pk 5972: _ENTRY(_C_LABEL(srmmu_get_asyncflt))
1.94 pk 5973: set SRMMU_AFAR, %o4
5974: lda [%o4] ASI_SRMMU, %o4 ! get async fault address
5975: set SRMMU_AFSR, %o3 !
5976: st %o4, [%o1]
5977: lda [%o3] ASI_SRMMU, %o3 ! get async fault status
5978: st %o3, [%o0]
5979: retl
5980: clr %o0 ! return value
1.62 pk 5981:
1.111 pk 5982: _ENTRY(_C_LABEL(cypress_get_asyncflt))
5983: _ENTRY(_C_LABEL(hypersparc_get_asyncflt))
1.94 pk 5984: set SRMMU_AFSR, %o3 ! must read status before fault on HS
5985: lda [%o3] ASI_SRMMU, %o3 ! get async fault status
5986: st %o3, [%o0]
5987: btst AFSR_AFO, %o3 ! and only read fault address
5988: bz 1f ! if valid.
5989: set SRMMU_AFAR, %o4
5990: lda [%o4] ASI_SRMMU, %o4 ! get async fault address
5991: clr %o0 ! return value
1.62 pk 5992: retl
1.94 pk 5993: st %o4, [%o1]
1.62 pk 5994: 1:
5995: retl
1.94 pk 5996: clr %o0 ! return value
1.62 pk 5997:
1.111 pk 5998: _ENTRY(_C_LABEL(no_asyncflt_regs))
1.62 pk 5999: retl
1.94 pk 6000: mov 1, %o0 ! return value
1.86 pk 6001:
1.111 pk 6002: _ENTRY(_C_LABEL(hypersparc_pure_vcache_flush))
1.86 pk 6003: /*
6004: * Flush entire on-chip instruction cache, which is
6005: * a pure vitually-indexed/virtually-tagged cache.
6006: */
6007: retl
6008: sta %g0, [%g0] ASI_HICACHECLR
1.62 pk 6009:
1.52 pk 6010: #endif /* SUN4M */
1.1 deraadt 6011:
1.149 uwe 6012: #if !defined(MSIIEP) /* normal suns */
1.1 deraadt 6013: /*
1.29 deraadt 6014: * void lo_microtime(struct timeval *tv)
1.1 deraadt 6015: *
6016: * LBL's sparc bsd 'microtime': We don't need to spl (so this routine
6017: * can be a leaf routine) and we don't keep a 'last' timeval (there
6018: * can't be two calls to this routine in a microsecond). This seems to
6019: * be about 20 times faster than the Sun code on an SS-2. - vj
6020: *
6021: * Read time values from slowest-changing to fastest-changing,
6022: * then re-read out to slowest. If the values read before
6023: * the innermost match those read after, the innermost value
6024: * is consistent with the outer values. If not, it may not
6025: * be and we must retry. Typically this loop runs only once;
6026: * occasionally it runs twice, and only rarely does it run longer.
6027: */
1.30 deraadt 6028: #if defined(SUN4)
1.29 deraadt 6029: ENTRY(lo_microtime)
1.30 deraadt 6030: #else
6031: ENTRY(microtime)
6032: #endif
1.111 pk 6033: sethi %hi(_C_LABEL(time)), %g2
1.68 mycroft 6034:
6035: #if defined(SUN4M) && !(defined(SUN4C) || defined(SUN4))
6036: sethi %hi(TIMERREG_VA+4), %g3
6037: or %g3, %lo(TIMERREG_VA+4), %g3
6038: #elif (defined(SUN4C) || defined(SUN4)) && !defined(SUN4M)
6039: sethi %hi(TIMERREG_VA), %g3
6040: or %g3, %lo(TIMERREG_VA), %g3
6041: #else
1.1 deraadt 6042: sethi %hi(TIMERREG_VA), %g3
1.62 pk 6043: or %g3, %lo(TIMERREG_VA), %g3
1.68 mycroft 6044: NOP_ON_4_4C_1:
1.62 pk 6045: add %g3, 4, %g3
1.68 mycroft 6046: #endif
1.62 pk 6047:
1.69 mycroft 6048: 2:
1.111 pk 6049: ldd [%g2+%lo(_C_LABEL(time))], %o2 ! time.tv_sec & time.tv_usec
1.62 pk 6050: ld [%g3], %o4 ! usec counter
1.111 pk 6051: ldd [%g2+%lo(_C_LABEL(time))], %g4 ! see if time values changed
1.1 deraadt 6052: cmp %g4, %o2
1.52 pk 6053: bne 2b ! if time.tv_sec changed
1.1 deraadt 6054: cmp %g5, %o3
1.52 pk 6055: bne 2b ! if time.tv_usec changed
1.1 deraadt 6056: tst %o4
6057:
1.52 pk 6058: bpos 3f ! reached limit?
1.1 deraadt 6059: srl %o4, TMR_SHIFT, %o4 ! convert counter to usec
1.111 pk 6060: sethi %hi(_C_LABEL(tick)), %g4 ! bump usec by 1 tick
6061: ld [%g4+%lo(_C_LABEL(tick))], %o1
1.1 deraadt 6062: set TMR_MASK, %g5
6063: add %o1, %o3, %o3
6064: and %o4, %g5, %o4
1.52 pk 6065: 3:
1.1 deraadt 6066: add %o4, %o3, %o3
6067: set 1000000, %g5 ! normalize usec value
6068: cmp %o3, %g5
1.52 pk 6069: bl,a 4f
1.155 uwe 6070: st %o2, [%o0]
1.1 deraadt 6071: add %o2, 1, %o2 ! overflow
6072: sub %o3, %g5, %o3
1.155 uwe 6073: st %o2, [%o0]
1.52 pk 6074: 4:
1.1 deraadt 6075: retl
6076: st %o3, [%o0+4]
1.149 uwe 6077:
6078: #else /* MSIIEP */
6079: /* XXX: uwe: can be merged with 4c/4m version above */
6080: /*
6081: * ms-IIep version of
6082: * void microtime(struct timeval *tv)
6083: *
6084: * This is similar to 4c/4m microtime. The difference is that
6085: * counter uses 31 bits and ticks every 4 CPU cycles (cpu is @100MHz)
6086: * the magic to divide by 25 is stolen from gcc
6087: */
6088: ENTRY(microtime)
6089: sethi %hi(_C_LABEL(time)), %g2
6090:
6091: sethi %hi(MSIIEP_PCIC_VA), %g3
6092: or %g3, PCIC_SCCR_REG, %g3
6093:
6094: 2:
6095: ldd [%g2+%lo(_C_LABEL(time))], %o2 ! time.tv_sec & time.tv_usec
6096: ld [%g3], %o4 ! system (timer) counter
6097: ldd [%g2+%lo(_C_LABEL(time))], %g4 ! see if time values changed
6098: cmp %g4, %o2
6099: bne 2b ! if time.tv_sec changed
6100: cmp %g5, %o3
6101: bne 2b ! if time.tv_usec changed
6102: tst %o4
6103: !! %o2 - time.tv_sec; %o3 - time.tv_usec; %o4 - timer counter
6104:
6105: !!! BEGIN ms-IIep specific code
6106: bpos 3f ! if limit not reached yet
6107: clr %g4 ! then use timer as is
6108:
1.155 uwe 6109: set 0x80000000, %g5
1.149 uwe 6110: sethi %hi(_C_LABEL(tick)), %g4
1.155 uwe 6111: bclr %g5, %o4 ! cleat limit reached flag
1.149 uwe 6112: ld [%g4+%lo(_C_LABEL(tick))], %g4
6113:
6114: !! %g4 - either 0 or tick (if timer has hit the limit)
6115: 3:
6116: inc -1, %o4 ! timer is 1-based, adjust
1.155 uwe 6117: !! divide by 25 magic stolen from a gcc output
6118: set 1374389535, %g5
1.149 uwe 6119: umul %o4, %g5, %g0
6120: rd %y, %o4
6121: srl %o4, 3, %o4
6122: add %o4, %g4, %o4 ! may be bump usec by tick
6123: !!! END ms-IIep specific code
6124:
6125: add %o3, %o4, %o3 ! add timer to time.tv_usec
6126: set 1000000, %g5 ! normalize usec value
6127: cmp %o3, %g5
1.156 uwe 6128: bl,a 4f
6129: st %o2, [%o0]
1.149 uwe 6130: inc %o2 ! overflow into tv_sec
6131: sub %o3, %g5, %o3
1.155 uwe 6132: st %o2, [%o0]
1.156 uwe 6133: 4: retl
1.155 uwe 6134: st %o3, [%o0 + 4]
1.149 uwe 6135: #endif /* MSIIEP */
1.1 deraadt 6136:
1.54 pk 6137: /*
6138: * delay function
6139: *
6140: * void delay(N) -- delay N microseconds
6141: *
6142: * Register usage: %o0 = "N" number of usecs to go (counts down to zero)
6143: * %o1 = "timerblurb" (stays constant)
6144: * %o2 = counter for 1 usec (counts down from %o1 to zero)
6145: *
6146: */
6147:
6148: ENTRY(delay) ! %o0 = n
1.57 pk 6149: subcc %o0, %g0, %g0
6150: be 2f
6151:
1.111 pk 6152: sethi %hi(_C_LABEL(timerblurb)), %o1
6153: ld [%o1 + %lo(_C_LABEL(timerblurb))], %o1 ! %o1 = timerblurb
1.53 pk 6154:
1.57 pk 6155: addcc %o1, %g0, %o2 ! %o2 = cntr (start @ %o1), clear CCs
1.54 pk 6156: ! first time through only
6157:
6158: ! delay 1 usec
6159: 1: bne 1b ! come back here if not done
6160: subcc %o2, 1, %o2 ! %o2 = %o2 - 1 [delay slot]
1.53 pk 6161:
1.54 pk 6162: subcc %o0, 1, %o0 ! %o0 = %o0 - 1
6163: bne 1b ! done yet?
6164: addcc %o1, %g0, %o2 ! reinit %o2 and CCs [delay slot]
6165: ! harmless if not branching
1.57 pk 6166: 2:
1.54 pk 6167: retl ! return
6168: nop ! [delay slot]
1.53 pk 6169:
1.60 pk 6170: #if defined(KGDB) || defined(DDB) || defined(DIAGNOSTIC)
1.1 deraadt 6171: /*
6172: * Write all windows (user or otherwise), except the current one.
6173: *
6174: * THIS COULD BE DONE IN USER CODE
6175: */
6176: ENTRY(write_all_windows)
6177: /*
6178: * g2 = g1 = nwindows - 1;
6179: * while (--g1 > 0) save();
6180: * while (--g2 > 0) restore();
6181: */
1.111 pk 6182: sethi %hi(_C_LABEL(nwindows)), %g1
6183: ld [%g1 + %lo(_C_LABEL(nwindows))], %g1
1.1 deraadt 6184: dec %g1
6185: mov %g1, %g2
6186:
6187: 1: deccc %g1
6188: bg,a 1b
6189: save %sp, -64, %sp
6190:
6191: 2: deccc %g2
6192: bg,a 2b
6193: restore
6194:
6195: retl
6196: nop
6197: #endif /* KGDB */
6198:
1.8 pk 6199: ENTRY(setjmp)
6200: std %sp, [%o0+0] ! stack pointer & return pc
6201: st %fp, [%o0+8] ! frame pointer
6202: retl
6203: clr %o0
6204:
6205: Lpanic_ljmp:
6206: .asciz "longjmp botch"
1.52 pk 6207: _ALIGN
1.8 pk 6208:
6209: ENTRY(longjmp)
6210: addcc %o1, %g0, %g6 ! compute v ? v : 1 in a global register
6211: be,a 0f
6212: mov 1, %g6
6213: 0:
6214: mov %o0, %g1 ! save a in another global register
6215: ld [%g1+8], %g7 /* get caller's frame */
6216: 1:
6217: cmp %fp, %g7 ! compare against desired frame
6218: bl,a 1b ! if below,
6219: restore ! pop frame and loop
6220: be,a 2f ! if there,
6221: ldd [%g1+0], %o2 ! fetch return %sp and pc, and get out
6222:
6223: Llongjmpbotch:
6224: ! otherwise, went too far; bomb out
6225: save %sp, -CCFSZ, %sp /* preserve current window */
6226: sethi %hi(Lpanic_ljmp), %o0
1.111 pk 6227: call _C_LABEL(panic)
1.8 pk 6228: or %o0, %lo(Lpanic_ljmp), %o0;
6229: unimp 0
6230:
6231: 2:
6232: cmp %o2, %sp ! %sp must not decrease
6233: bge,a 3f
6234: mov %o2, %sp ! it is OK, put it in place
6235: b,a Llongjmpbotch
1.52 pk 6236: 3:
1.8 pk 6237: jmp %o3 + 8 ! success, return %g6
6238: mov %g6, %o0
6239:
1.1 deraadt 6240: .data
1.153 pk 6241: .globl _C_LABEL(kernel_top)
6242: _C_LABEL(kernel_top):
1.117 christos 6243: .word 0
6244: .globl _C_LABEL(bootinfo)
6245: _C_LABEL(bootinfo):
1.8 pk 6246: .word 0
1.1 deraadt 6247:
1.111 pk 6248: .globl _C_LABEL(proc0paddr)
6249: _C_LABEL(proc0paddr):
6250: .word _C_LABEL(u0) ! KVA of proc0 uarea
1.1 deraadt 6251:
6252: /* interrupt counters XXX THESE BELONG ELSEWHERE (if anywhere) */
1.111 pk 6253: .globl _C_LABEL(intrcnt), _C_LABEL(eintrcnt)
6254: .globl _C_LABEL(intrnames), _C_LABEL(eintrnames)
6255: _C_LABEL(intrnames):
1.1 deraadt 6256: .asciz "spur"
6257: .asciz "lev1"
6258: .asciz "lev2"
6259: .asciz "lev3"
6260: .asciz "lev4"
6261: .asciz "lev5"
6262: .asciz "lev6"
6263: .asciz "lev7"
6264: .asciz "lev8"
6265: .asciz "lev9"
6266: .asciz "clock"
6267: .asciz "lev11"
6268: .asciz "lev12"
6269: .asciz "lev13"
6270: .asciz "prof"
1.111 pk 6271: _C_LABEL(eintrnames):
1.52 pk 6272: _ALIGN
1.111 pk 6273: _C_LABEL(intrcnt):
1.1 deraadt 6274: .skip 4*15
1.111 pk 6275: _C_LABEL(eintrcnt):
1.1 deraadt 6276:
1.111 pk 6277: .comm _C_LABEL(nwindows), 4
6278: .comm _C_LABEL(romp), 4
CVSweb <webmaster@jp.NetBSD.org>