Annotation of src/sys/arch/i386/i386/locore.S, Revision 1.65
1.65 ! skrll 1: /* $NetBSD: locore.S,v 1.64 2008/01/20 12:43:00 skrll Exp $ */
1.53 yamt 2:
3: /*
4: * Copyright-o-rama!
5: */
6:
7: /*
1.62 bouyer 8: * Copyright (c) 2006 Manuel Bouyer.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by Manuel Bouyer.
21: * 4. The name of the author may not be used to endorse or promote products
22: * derived from this software without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34: *
35: */
36:
37: /*
1.53 yamt 38: * Copyright (c) 2001 Wasabi Systems, Inc.
39: * All rights reserved.
40: *
41: * Written by Frank van der Linden for Wasabi Systems, Inc.
42: *
43: * Redistribution and use in source and binary forms, with or without
44: * modification, are permitted provided that the following conditions
45: * are met:
46: * 1. Redistributions of source code must retain the above copyright
47: * notice, this list of conditions and the following disclaimer.
48: * 2. Redistributions in binary form must reproduce the above copyright
49: * notice, this list of conditions and the following disclaimer in the
50: * documentation and/or other materials provided with the distribution.
51: * 3. All advertising materials mentioning features or use of this software
52: * must display the following acknowledgement:
53: * This product includes software developed for the NetBSD Project by
54: * Wasabi Systems, Inc.
55: * 4. The name of Wasabi Systems, Inc. may not be used to endorse
56: * or promote products derived from this software without specific prior
57: * written permission.
58: *
59: * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
60: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
63: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69: * POSSIBILITY OF SUCH DAMAGE.
70: */
71:
1.1 fvdl 72:
73: /*-
1.48 yamt 74: * Copyright (c) 1998, 2000, 2004, 2006, 2007 The NetBSD Foundation, Inc.
1.1 fvdl 75: * All rights reserved.
76: *
77: * This code is derived from software contributed to The NetBSD Foundation
78: * by Charles M. Hannum.
79: *
80: * Redistribution and use in source and binary forms, with or without
81: * modification, are permitted provided that the following conditions
82: * are met:
83: * 1. Redistributions of source code must retain the above copyright
84: * notice, this list of conditions and the following disclaimer.
85: * 2. Redistributions in binary form must reproduce the above copyright
86: * notice, this list of conditions and the following disclaimer in the
87: * documentation and/or other materials provided with the distribution.
88: * 3. All advertising materials mentioning features or use of this software
89: * must display the following acknowledgement:
90: * This product includes software developed by the NetBSD
91: * Foundation, Inc. and its contributors.
92: * 4. Neither the name of The NetBSD Foundation nor the names of its
93: * contributors may be used to endorse or promote products derived
94: * from this software without specific prior written permission.
95: *
96: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
97: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
98: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
99: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
100: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
101: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
102: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
103: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
104: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
105: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106: * POSSIBILITY OF SUCH DAMAGE.
107: */
108:
109: /*-
110: * Copyright (c) 1990 The Regents of the University of California.
111: * All rights reserved.
112: *
113: * This code is derived from software contributed to Berkeley by
114: * William Jolitz.
115: *
116: * Redistribution and use in source and binary forms, with or without
117: * modification, are permitted provided that the following conditions
118: * are met:
119: * 1. Redistributions of source code must retain the above copyright
120: * notice, this list of conditions and the following disclaimer.
121: * 2. Redistributions in binary form must reproduce the above copyright
122: * notice, this list of conditions and the following disclaimer in the
123: * documentation and/or other materials provided with the distribution.
1.12 agc 124: * 3. Neither the name of the University nor the names of its contributors
1.1 fvdl 125: * may be used to endorse or promote products derived from this software
126: * without specific prior written permission.
127: *
128: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
129: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
130: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
131: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
132: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
133: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
134: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
135: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
136: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
137: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
138: * SUCH DAMAGE.
139: *
140: * @(#)locore.s 7.3 (Berkeley) 5/13/91
141: */
142:
1.59 lukem 143: #include <machine/asm.h>
1.65 ! skrll 144: __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.64 2008/01/20 12:43:00 skrll Exp $");
1.59 lukem 145:
1.18 christos 146: #include "opt_compat_oldboot.h"
1.1 fvdl 147: #include "opt_ddb.h"
148: #include "opt_realmem.h"
1.18 christos 149: #include "opt_vm86.h"
1.62 bouyer 150: #include "opt_xen.h"
1.1 fvdl 151:
152: #include "npx.h"
153: #include "assym.h"
154: #include "lapic.h"
155: #include "ioapic.h"
1.8 fvdl 156: #include "ksyms.h"
1.1 fvdl 157:
158: #include <sys/errno.h>
159: #include <sys/syscall.h>
160:
161: #include <machine/cputypes.h>
162: #include <machine/segments.h>
163: #include <machine/specialreg.h>
164: #include <machine/trap.h>
165: #include <machine/i82489reg.h>
1.48 yamt 166: #include <machine/frameasm.h>
167: #include <machine/i82489reg.h>
1.62 bouyer 168: #ifndef XEN
169: #include <machine/multiboot.h>
170: #endif
1.1 fvdl 171:
172: /* XXX temporary kluge; these should not be here */
173: /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
174: #include <dev/isa/isareg.h>
175:
1.62 bouyer 176: #ifdef XEN
177: /*
178: * Xen guest identifier and loader selection
179: */
180: .section __xen_guest
181: #ifdef XEN3
182: .ascii "GUEST_OS=netbsd,GUEST_VER=3.0,XEN_VER=xen-3.0"
183: #if defined(DOM0OPS) || !defined(XEN_COMPAT_030001)
184: .ascii ",VIRT_BASE=0xc0000000" /* KERNBASE */
185: .ascii ",ELF_PADDR_OFFSET=0xc0000000" /* KERNBASE */
186: #else
187: .ascii ",VIRT_BASE=0xc0100000" /* KERNTEXTOFF */
188: .ascii ",ELF_PADDR_OFFSET=0xc0100000" /* KERNTEXTOFF */
189: #endif
190: .ascii ",VIRT_ENTRY=0xc0100000" /* KERNTEXTOFF */
191: #if !defined(XEN_COMPAT_030001)
192: .ascii ",HYPERCALL_PAGE=0x00000101"
193: /* (???+HYPERCALL_PAGE_OFFSET)/PAGE_SIZE) */
194: #endif
195: #else /* !XEN3 */
196: .ascii "GUEST_OS=netbsd,GUEST_VER=2.0,XEN_VER=2.0"
197: #endif /* XEN3 */
198: .ascii ",LOADER=generic"
199: #if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE)
200: .ascii ",BSD_SYMTAB=yes"
201: #endif
202: .byte 0
203: #endif
204:
1.1 fvdl 205: /*
206: * Initialization
207: */
208: .data
209:
210: .globl _C_LABEL(cpu)
1.38 jmmv 211: .globl _C_LABEL(esym)
212: .globl _C_LABEL(atdevbase)
1.40 yamt 213: .globl _C_LABEL(proc0uarea),_C_LABEL(PDPpaddr)
1.1 fvdl 214: .globl _C_LABEL(gdt)
215: .globl _C_LABEL(idt)
1.30 junyoung 216: .globl _C_LABEL(lapic_tpr)
217:
1.1 fvdl 218: #if NLAPIC > 0
219: #ifdef __ELF__
1.7 thorpej 220: .align PAGE_SIZE
1.1 fvdl 221: #else
222: .align 12
223: #endif
224: .globl _C_LABEL(local_apic), _C_LABEL(lapic_id)
225: _C_LABEL(local_apic):
226: .space LAPIC_ID
1.30 junyoung 227: _C_LABEL(lapic_id):
1.1 fvdl 228: .long 0x00000000
229: .space LAPIC_TPRI-(LAPIC_ID+4)
1.30 junyoung 230: _C_LABEL(lapic_tpr):
1.1 fvdl 231: .space LAPIC_PPRI-LAPIC_TPRI
1.30 junyoung 232: _C_LABEL(lapic_ppr):
1.1 fvdl 233: .space LAPIC_ISR-LAPIC_PPRI
234: _C_LABEL(lapic_isr):
1.7 thorpej 235: .space PAGE_SIZE-LAPIC_ISR
1.1 fvdl 236: #else
1.30 junyoung 237: _C_LABEL(lapic_tpr):
1.1 fvdl 238: .long 0
239: #endif
1.30 junyoung 240:
1.48 yamt 241: _C_LABEL(cpu): .long 0 # are we 80486, Pentium, or..
1.1 fvdl 242: _C_LABEL(atdevbase): .long 0 # location of start of iomem in virtual
1.40 yamt 243: _C_LABEL(proc0uarea): .long 0
1.31 junyoung 244: _C_LABEL(PDPpaddr): .long 0 # paddr of PDP, for libkvm
1.53 yamt 245: _C_LABEL(tablesize): .long 0
1.30 junyoung 246:
1.63 bouyer 247: .space 512
1.1 fvdl 248: tmpstk:
249:
1.62 bouyer 250: #ifndef XEN
1.35 yamt 251: #define _RELOC(x) ((x) - KERNBASE)
1.62 bouyer 252: #else
253: #define _RELOC(x) ((x))
254: #endif /* XEN */
1.1 fvdl 255: #define RELOC(x) _RELOC(_C_LABEL(x))
256:
257: .text
258: .globl _C_LABEL(kernel_text)
259: .set _C_LABEL(kernel_text),KERNTEXTOFF
260:
261: .globl start
1.62 bouyer 262: #ifndef XEN
1.1 fvdl 263: start: movw $0x1234,0x472 # warm boot
264:
1.37 jmmv 265: #if defined(MULTIBOOT)
266: jmp 1f
267:
268: .align 4
269: .globl Multiboot_Header
270: _C_LABEL(Multiboot_Header):
1.44 jmmv 271: #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_HEADER_WANT_MEMORY)
1.37 jmmv 272: .long MULTIBOOT_HEADER_MAGIC
273: .long MULTIBOOT_HEADER_FLAGS
274: .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
275:
276: 1:
277: /* Check if we are being executed by a Multiboot-compliant boot
278: * loader. */
279: cmpl $MULTIBOOT_INFO_MAGIC,%eax
280: jne 1f
281:
1.43 mrg 282: /*
283: * Indeed, a multiboot-compliant boot loader executed us. We copy
1.37 jmmv 284: * the received Multiboot information structure into kernel's data
285: * space to process it later -- after we are relocated. It will
1.43 mrg 286: * be safer to run complex C code than doing it at this point.
287: */
1.37 jmmv 288: pushl %ebx # Address of Multiboot information
289: call _C_LABEL(multiboot_pre_reloc)
290: addl $4,%esp
1.38 jmmv 291: jmp 2f
1.37 jmmv 292: #endif
293:
294: 1:
1.1 fvdl 295: /*
1.38 jmmv 296: * At this point, we know that a NetBSD-specific boot loader
297: * booted this kernel. The stack carries the following parameters:
1.41 jmmv 298: * (boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem),
1.38 jmmv 299: * 4 bytes each.
1.1 fvdl 300: */
1.38 jmmv 301: addl $4,%esp # Discard return address to boot loader
302: call _C_LABEL(native_loader)
303: addl $24,%esp
1.1 fvdl 304:
305: 2:
306: /* First, reset the PSL. */
307: pushl $PSL_MBO
308: popfl
309:
310: /* Clear segment registers; always null in proc0. */
311: xorl %eax,%eax
312: movw %ax,%fs
313: movw %ax,%gs
314: decl %eax
315: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
316:
317: /* Find out our CPU type. */
318:
319: try386: /* Try to toggle alignment check flag; does not exist on 386. */
320: pushfl
321: popl %eax
322: movl %eax,%ecx
323: orl $PSL_AC,%eax
324: pushl %eax
325: popfl
326: pushfl
327: popl %eax
328: xorl %ecx,%eax
329: andl $PSL_AC,%eax
330: pushl %ecx
331: popfl
332:
333: testl %eax,%eax
334: jnz try486
335:
336: /*
337: * Try the test of a NexGen CPU -- ZF will not change on a DIV
338: * instruction on a NexGen, it will on an i386. Documented in
339: * Nx586 Processor Recognition Application Note, NexGen, Inc.
340: */
341: movl $0x5555,%eax
342: xorl %edx,%edx
343: movl $2,%ecx
344: divl %ecx
345: jnz is386
346:
347: isnx586:
348: /*
349: * Don't try cpuid, as Nx586s reportedly don't support the
350: * PSL_ID bit.
351: */
352: movl $CPU_NX586,RELOC(cpu)
353: jmp 2f
354:
355: is386:
356: movl $CPU_386,RELOC(cpu)
357: jmp 2f
358:
359: try486: /* Try to toggle identification flag; does not exist on early 486s. */
360: pushfl
361: popl %eax
362: movl %eax,%ecx
363: xorl $PSL_ID,%eax
364: pushl %eax
365: popfl
366: pushfl
367: popl %eax
368: xorl %ecx,%eax
369: andl $PSL_ID,%eax
370: pushl %ecx
371: popfl
372:
373: testl %eax,%eax
374: jnz try586
375: is486: movl $CPU_486,RELOC(cpu)
376: /*
377: * Check Cyrix CPU
378: * Cyrix CPUs do not change the undefined flags following
379: * execution of the divide instruction which divides 5 by 2.
380: *
381: * Note: CPUID is enabled on M2, so it passes another way.
382: */
383: pushfl
384: movl $0x5555, %eax
385: xorl %edx, %edx
386: movl $2, %ecx
387: clc
388: divl %ecx
389: jnc trycyrix486
390: popfl
391: jmp 2f
392: trycyrix486:
393: movl $CPU_6x86,RELOC(cpu) # set CPU type
394: /*
395: * Check for Cyrix 486 CPU by seeing if the flags change during a
396: * divide. This is documented in the Cx486SLC/e SMM Programmer's
397: * Guide.
398: */
399: xorl %edx,%edx
400: cmpl %edx,%edx # set flags to known state
401: pushfl
402: popl %ecx # store flags in ecx
403: movl $-1,%eax
404: movl $4,%ebx
405: divl %ebx # do a long division
406: pushfl
407: popl %eax
408: xorl %ecx,%eax # are the flags different?
409: testl $0x8d5,%eax # only check C|PF|AF|Z|N|V
410: jne 2f # yes; must be Cyrix 6x86 CPU
411: movl $CPU_486DLC,RELOC(cpu) # set CPU type
412:
413: #ifndef CYRIX_CACHE_WORKS
414: /* Disable caching of the ISA hole only. */
415: invd
416: movb $CCR0,%al # Configuration Register index (CCR0)
417: outb %al,$0x22
418: inb $0x23,%al
419: orb $(CCR0_NC1|CCR0_BARB),%al
420: movb %al,%ah
421: movb $CCR0,%al
422: outb %al,$0x22
423: movb %ah,%al
424: outb %al,$0x23
425: invd
426: #else /* CYRIX_CACHE_WORKS */
427: /* Set cache parameters */
428: invd # Start with guaranteed clean cache
429: movb $CCR0,%al # Configuration Register index (CCR0)
430: outb %al,$0x22
431: inb $0x23,%al
432: andb $~CCR0_NC0,%al
433: #ifndef CYRIX_CACHE_REALLY_WORKS
434: orb $(CCR0_NC1|CCR0_BARB),%al
435: #else
436: orb $CCR0_NC1,%al
437: #endif
438: movb %al,%ah
439: movb $CCR0,%al
440: outb %al,$0x22
441: movb %ah,%al
442: outb %al,$0x23
443: /* clear non-cacheable region 1 */
444: movb $(NCR1+2),%al
445: outb %al,$0x22
446: movb $NCR_SIZE_0K,%al
447: outb %al,$0x23
448: /* clear non-cacheable region 2 */
449: movb $(NCR2+2),%al
450: outb %al,$0x22
451: movb $NCR_SIZE_0K,%al
452: outb %al,$0x23
453: /* clear non-cacheable region 3 */
454: movb $(NCR3+2),%al
455: outb %al,$0x22
456: movb $NCR_SIZE_0K,%al
457: outb %al,$0x23
458: /* clear non-cacheable region 4 */
459: movb $(NCR4+2),%al
460: outb %al,$0x22
461: movb $NCR_SIZE_0K,%al
462: outb %al,$0x23
463: /* enable caching in CR0 */
464: movl %cr0,%eax
465: andl $~(CR0_CD|CR0_NW),%eax
466: movl %eax,%cr0
467: invd
468: #endif /* CYRIX_CACHE_WORKS */
469:
470: jmp 2f
471:
472: try586: /* Use the `cpuid' instruction. */
473: xorl %eax,%eax
474: cpuid
475: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
476:
477: 2:
478: /*
479: * Finished with old stack; load new %esp now instead of later so we
480: * can trace this code without having to worry about the trace trap
481: * clobbering the memory test or the zeroing of the bss+bootstrap page
482: * tables.
483: *
484: * The boot program should check:
485: * text+data <= &stack_variable - more_space_for_stack
486: * text+data+bss+pad+space_for_page_tables <= end_of_memory
487: * Oops, the gdt is in the carcass of the boot program so clearing
488: * the rest of memory is still not possible.
489: */
490: movl $_RELOC(tmpstk),%esp # bootstrap stack end location
491:
492: /*
493: * Virtual address space of kernel:
494: *
1.53 yamt 495: * text | data | bss | [syms] | page dir | proc0 kstack | L1 ptp
1.1 fvdl 496: * 0 1 2 3
497: */
1.53 yamt 498:
499: #define PROC0_PDIR_OFF 0
500: #define PROC0_STK_OFF (PROC0_PDIR_OFF + PAGE_SIZE)
501: #define PROC0_PTP1_OFF (PROC0_STK_OFF + UPAGES * PAGE_SIZE)
502:
503: /*
504: * fillkpt
505: * eax = pte (page frame | control | status)
506: * ebx = page table address
507: * ecx = number of pages to map
508: */
509:
510: #define fillkpt \
511: 1: movl %eax,(%ebx) ; /* store phys addr */ \
512: addl $4,%ebx ; /* next pte/pde */ \
513: addl $PAGE_SIZE,%eax ; /* next phys page */ \
514: loop 1b ; \
515:
1.1 fvdl 516:
517: /* Find end of kernel image. */
518: movl $RELOC(end),%edi
1.8 fvdl 519: #if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE)
1.1 fvdl 520: /* Save the symbols (if loaded). */
521: movl RELOC(esym),%eax
522: testl %eax,%eax
523: jz 1f
1.35 yamt 524: subl $KERNBASE,%eax
1.1 fvdl 525: movl %eax,%edi
526: 1:
527: #endif
528:
1.53 yamt 529: /* Compute sizes */
1.1 fvdl 530: movl %edi,%esi # edi = esym ? esym : end
531: addl $PGOFSET,%esi # page align up
532: andl $~PGOFSET,%esi
533:
1.53 yamt 534: /* nkptp[1] = (esi + ~L2_FRAME) >> L2_SHIFT + 1; */
535: movl %esi,%eax
536: addl $~L2_FRAME,%eax
537: shrl $L2_SHIFT,%eax
538: incl %eax /* one more ptp for VAs stolen by bootstrap */
539: 1: movl %eax,RELOC(nkptp)+1*4
540:
541: /* tablesize = (1 + UPAGES + nkptp) << PGSHIFT; */
542: addl $(1+UPAGES),%eax
543: shll $PGSHIFT,%eax
544: movl %eax,RELOC(tablesize)
545:
546: /* ensure that nkptp covers bootstrap tables */
547: addl %esi,%eax
548: addl $~L2_FRAME,%eax
549: shrl $L2_SHIFT,%eax
550: incl %eax
551: cmpl %eax,RELOC(nkptp)+1*4
552: jnz 1b
553:
554: /* Clear tables */
555: movl %esi,%edi
1.1 fvdl 556: xorl %eax,%eax
557: cld
1.53 yamt 558: movl RELOC(tablesize),%ecx
559: shrl $2,%ecx
1.1 fvdl 560: rep
561: stosl
562:
1.53 yamt 563: leal (PROC0_PTP1_OFF)(%esi), %ebx
1.1 fvdl 564:
565: /*
566: * Build initial page tables.
567: */
1.53 yamt 568: /*
569: * Compute &__data_start - KERNBASE. This can't be > 4G,
570: * or we can't deal with it anyway, since we can't load it in
571: * 32 bit mode. So use the bottom 32 bits.
572: */
573: movl $RELOC(__data_start),%edx
1.1 fvdl 574: andl $~PGOFSET,%edx
1.30 junyoung 575:
1.53 yamt 576: /*
577: * Skip the first MB.
578: */
1.1 fvdl 579: movl $_RELOC(KERNTEXTOFF),%eax
580: movl %eax,%ecx
1.53 yamt 581: shrl $(PGSHIFT-2),%ecx /* ((n >> PGSHIFT) << 2) for # pdes */
582: addl %ecx,%ebx
1.1 fvdl 583:
584: /* Map the kernel text read-only. */
585: movl %edx,%ecx
586: subl %eax,%ecx
587: shrl $PGSHIFT,%ecx
588: orl $(PG_V|PG_KR),%eax
589: fillkpt
590:
591: /* Map the data, BSS, and bootstrap tables read-write. */
592: leal (PG_V|PG_KW)(%edx),%eax
1.53 yamt 593: movl RELOC(tablesize),%ecx
1.1 fvdl 594: addl %esi,%ecx # end of tables
595: subl %edx,%ecx # subtract end of text
596: shrl $PGSHIFT,%ecx
597: fillkpt
598:
1.53 yamt 599: /* Map ISA I/O mem (later atdevbase) */
1.1 fvdl 600: movl $(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax # having these bits set
601: movl $(IOM_SIZE>>PGSHIFT),%ecx # for this many pte s,
602: fillkpt
603:
604: /*
605: * Construct a page table directory.
606: */
1.53 yamt 607: /* Set up top level entries for identity mapping */
608: leal (PROC0_PDIR_OFF)(%esi),%ebx
609: leal (PROC0_PTP1_OFF)(%esi),%eax
610: orl $(PG_V|PG_KW), %eax
611: movl RELOC(nkptp)+1*4,%ecx
1.1 fvdl 612: fillkpt
613:
1.53 yamt 614: /* Set up top level entries for actual kernel mapping */
615: leal (PROC0_PDIR_OFF + L2_SLOT_KERNBASE*4)(%esi),%ebx
616: leal (PROC0_PTP1_OFF)(%esi),%eax
617: orl $(PG_V|PG_KW), %eax
618: movl RELOC(nkptp)+1*4,%ecx
1.1 fvdl 619: fillkpt
620:
621: /* Install a PDE recursively mapping page directory as a page table! */
1.53 yamt 622: leal (PROC0_PDIR_OFF + PDIR_SLOT_PTE*4)(%esi),%ebx
623: leal (PROC0_PDIR_OFF)(%esi),%eax
624: orl $(PG_V|PG_KW),%eax
625: movl %eax,(%ebx)
626:
1.1 fvdl 627:
1.31 junyoung 628: /* Save phys. addr of PDP, for libkvm. */
629: movl %esi,RELOC(PDPpaddr)
1.1 fvdl 630:
1.53 yamt 631: /*
632: * Startup checklist:
633: * 1. Load %cr3 with pointer to PDIR.
634: */
1.1 fvdl 635: movl %esi,%eax # phys address of ptd in proc 0
636: movl %eax,%cr3 # load ptd addr into mmu
1.53 yamt 637:
638: /*
639: * 2. Enable paging and the rest of it.
640: */
1.1 fvdl 641: movl %cr0,%eax # get control word
642: # enable paging & NPX emulation
643: orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP),%eax
644: movl %eax,%cr0 # and let's page NOW!
645:
646: pushl $begin # jump to high mem
647: ret
648:
649: begin:
1.53 yamt 650: /*
651: * We have arrived.
652: * There's no need anymore for the identity mapping in low
653: * memory, remove it.
654: */
655: movl _C_LABEL(nkptp)+1*4,%ecx
656: leal (PROC0_PDIR_OFF)(%esi),%ebx # old, phys address of PDIR
657: addl $(KERNBASE), %ebx # new, virtual address of PDIR
1.1 fvdl 658: 1: movl $0,(%ebx)
1.53 yamt 659: addl $4,%ebx
1.1 fvdl 660: loop 1b
661:
662: /* Relocate atdevbase. */
1.53 yamt 663: movl $KERNBASE,%edx
664: addl _C_LABEL(tablesize),%edx
1.1 fvdl 665: addl %esi,%edx
666: movl %edx,_C_LABEL(atdevbase)
667:
668: /* Set up bootstrap stack. */
1.53 yamt 669: leal (PROC0_STK_OFF+KERNBASE)(%esi),%eax
1.40 yamt 670: movl %eax,_C_LABEL(proc0uarea)
671: leal (KSTACK_SIZE-FRAMESIZE)(%eax),%esp
672: movl %esi,(KSTACK_SIZE+PCB_CR3)(%eax) # pcb->pcb_cr3
1.1 fvdl 673: xorl %ebp,%ebp # mark end of frames
674:
1.37 jmmv 675: #if defined(MULTIBOOT)
676: /* It is now safe to parse the Multiboot information structure
677: * we saved before from C code. Note that we cannot delay its
678: * parsing any more because initgdt (called below) needs to make
679: * use of this information. */
680: call _C_LABEL(multiboot_post_reloc)
681: #endif
682:
1.1 fvdl 683: subl $NGDT*8, %esp # space for temporary gdt
684: pushl %esp
685: call _C_LABEL(initgdt)
686: addl $4,%esp
1.30 junyoung 687:
1.53 yamt 688: movl _C_LABEL(tablesize),%eax
1.1 fvdl 689: addl %esi,%eax # skip past stack and page tables
690:
691: pushl %eax
692: call _C_LABEL(init386) # wire 386 chip for unix operation
693: addl $4+NGDT*8,%esp # pop temporary gdt
694:
695: #ifdef SAFARI_FIFO_HACK
696: movb $5,%al
697: movw $0x37b,%dx
698: outb %al,%dx
699: movw $0x37f,%dx
700: inb %dx,%al
701: movb %al,%cl
702:
703: orb $1,%cl
704:
705: movb $5,%al
706: movw $0x37b,%dx
707: outb %al,%dx
708: movw $0x37f,%dx
709: movb %cl,%al
710: outb %al,%dx
711: #endif /* SAFARI_FIFO_HACK */
712:
713: call _C_LABEL(main)
1.62 bouyer 714: #else /* XEN */
715: start:
716: /* First, reset the PSL. */
717: pushl $PSL_MBO
718: popfl
719:
720: cld
721: #ifdef XEN3
722: movl %esp, %ebx # save start of available space
723: #else
724: movl %esi,%ebx # save start_info pointer
725: #endif
726: movl $_RELOC(tmpstk),%esp # bootstrap stack end location
727:
728: /* Clear BSS first so that there are no surprises... */
729: xorl %eax,%eax
730: movl $RELOC(__bss_start),%edi
731: movl $RELOC(_end),%ecx
732: subl %edi,%ecx
733: rep stosb
734:
735: /* Copy the necessary stuff from start_info structure. */
736: /* We need to copy shared_info early, so that sti/cli work */
737: movl $RELOC(start_info_union),%edi
738: movl $128,%ecx
739: rep movsl
740:
741: /* Clear segment registers; always null in proc0. */
742: xorl %eax,%eax
743: movw %ax,%fs
744: movw %ax,%gs
745: decl %eax
746: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
747:
748: xorl %eax,%eax
749: cpuid
750: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
751:
752: call xen_pmap_bootstrap
753: /*
754: * First avail returned by xen_pmap_bootstrap in %eax
755: */
756: movl %eax, %esi;
757: movl %esi, _C_LABEL(proc0uarea)
758:
759: #define PROC0PDIR ((0) * PAGE_SIZE)
760: #define PROC0STACK ((1) * PAGE_SIZE)
761:
762: /* Set up bootstrap stack. */
763: leal (KSTACK_SIZE-FRAMESIZE)(%eax),%esp
764: xorl %ebp,%ebp # mark end of frames
765:
766: addl $USPACE, %esi
767: subl $KERNBASE, %esi #init386 want a physical address
768: pushl %esi
769: call _C_LABEL(init386) # wire 386 chip for unix operation
770: addl $4,%esp
771: call _C_LABEL(main)
772:
773: #if defined(XEN3) && !defined(XEN_COMPAT_030001)
774: /* space for the hypercall call page */
775: #define HYPERCALL_PAGE_OFFSET 0x1000
776: .org HYPERCALL_PAGE_OFFSET
777: ENTRY(hypercall_page)
778: .skip 0x1000
779: #endif /* defined(XEN3) && !defined(XEN_COMPAT_030001) */
780:
781: /*
782: * void lgdt_finish(void);
783: * Finish load a new GDT pointer (do any necessary cleanup).
784: * XXX It's somewhat questionable whether reloading all the segment registers
785: * is necessary, since the actual descriptor data is not changed except by
786: * process creation and exit, both of which clean up via task switches. OTOH,
787: * this only happens at run time when the GDT is resized.
788: */
789: /* LINTSTUB: Func: void lgdt_finish(void) */
790: NENTRY(lgdt_finish)
791: movl $GSEL(GDATA_SEL, SEL_KPL),%eax
792: movw %ax,%ds
793: movw %ax,%es
794: movw %ax,%gs
795: movw %ax,%ss
796: movl $GSEL(GCPU_SEL, SEL_KPL),%eax
797: movw %ax,%fs
798: /* Reload code selector by doing intersegment return. */
799: popl %eax
800: pushl $GSEL(GCODE_SEL, SEL_KPL)
801: pushl %eax
802: lret
803:
804: #endif /* XEN */
1.1 fvdl 805:
806: /*
1.48 yamt 807: * void lwp_trampoline(void);
808: *
1.1 fvdl 809: * This is a trampoline function pushed onto the stack of a newly created
810: * process in order to do some additional setup. The trampoline is entered by
811: * cpu_switch()ing to the process, so we abuse the callee-saved registers used
812: * by cpu_switch() to store the information about the stub to call.
813: * NOTE: This function does not have a normal calling sequence!
814: */
1.48 yamt 815: NENTRY(lwp_trampoline)
816: pushl %ebp
817: xorl %ebp,%ebp
818: pushl %eax
819: call _C_LABEL(lwp_startup)
820: addl $8,%esp
1.1 fvdl 821: pushl %ebx
822: call *%esi
823: addl $4,%esp
1.53 yamt 824: DO_DEFERRED_SWITCH
1.1 fvdl 825: INTRFASTEXIT
826: /* NOTREACHED */
827:
828: /*
1.48 yamt 829: * sigcode()
830: *
831: * Signal trampoline; copied to top of user stack. Used only for
832: * compatibility with old releases of NetBSD.
1.1 fvdl 833: */
834: NENTRY(sigcode)
835: /*
836: * Handler has returned here as if we called it. The sigcontext
837: * is on the stack after the 3 args "we" pushed.
838: */
839: leal 12(%esp),%eax # get pointer to sigcontext
840: movl %eax,4(%esp) # put it in the argument slot
841: # fake return address already there
1.17 christos 842: movl $SYS_compat_16___sigreturn14,%eax
1.1 fvdl 843: int $0x80 # enter kernel with args on stack
844: movl $SYS_exit,%eax
845: int $0x80 # exit if sigreturn fails
846: .globl _C_LABEL(esigcode)
847: _C_LABEL(esigcode):
848:
849: /*
1.48 yamt 850: * int setjmp(label_t *)
851: *
852: * Used primarily by DDB.
1.1 fvdl 853: */
854: ENTRY(setjmp)
855: movl 4(%esp),%eax
856: movl %ebx,(%eax) # save ebx
857: movl %esp,4(%eax) # save esp
858: movl %ebp,8(%eax) # save ebp
859: movl %esi,12(%eax) # save esi
860: movl %edi,16(%eax) # save edi
861: movl (%esp),%edx # get rta
862: movl %edx,20(%eax) # save eip
1.48 yamt 863: xorl %eax,%eax # return 0
1.1 fvdl 864: ret
865:
1.48 yamt 866: /*
867: * int longjmp(label_t *)
868: *
869: * Used primarily by DDB.
870: */
1.1 fvdl 871: ENTRY(longjmp)
872: movl 4(%esp),%eax
873: movl (%eax),%ebx # restore ebx
874: movl 4(%eax),%esp # restore esp
875: movl 8(%eax),%ebp # restore ebp
876: movl 12(%eax),%esi # restore esi
877: movl 16(%eax),%edi # restore edi
878: movl 20(%eax),%edx # get rta
879: movl %edx,(%esp) # put in return frame
1.48 yamt 880: movl $1,%eax # return 1
1.1 fvdl 881: ret
882:
1.65 ! skrll 883: /*
! 884: * void dumpsys(void)
! 885: *
! 886: * Mimic cpu_switchto() for postmortem debugging.
! 887: */
1.64 skrll 888: ENTRY(dumpsys)
1.65 ! skrll 889: pushl %ebx # set up fake switchframe
! 890: pushl %esi # and save context
! 891: pushl %edi
! 892: movl %esp,_C_LABEL(dumppcb)+PCB_ESP
! 893: movl %ebp,_C_LABEL(dumppcb)+PCB_EBP
! 894: call _C_LABEL(dodumpsys) # dump!
! 895: addl $(3*4), %esp # unwind switchframe
1.64 skrll 896: ret
897:
1.1 fvdl 898: /*
1.58 ad 899: * struct lwp *cpu_switchto(struct lwp *oldlwp, struct newlwp,
900: * bool returning)
1.30 junyoung 901: *
1.48 yamt 902: * 1. if (oldlwp != NULL), save its context.
903: * 2. then, restore context of newlwp.
904: *
905: * Note that the stack frame layout is known to "struct switchframe" in
906: * <machine/frame.h> and to the code in cpu_lwp_fork() which initializes
1.5 thorpej 907: * it for a new lwp.
1.1 fvdl 908: */
1.48 yamt 909: ENTRY(cpu_switchto)
1.1 fvdl 910: pushl %ebx
911: pushl %esi
912: pushl %edi
913:
1.48 yamt 914: movl 16(%esp),%esi # oldlwp
915: movl 20(%esp),%edi # newlwp
1.58 ad 916: movl 24(%esp),%edx # returning
1.48 yamt 917: testl %esi,%esi
918: jz 1f
1.1 fvdl 919:
1.48 yamt 920: /* Save old context. */
921: movl L_ADDR(%esi),%eax
922: movl %esp,PCB_ESP(%eax)
923: movl %ebp,PCB_EBP(%eax)
924:
925: /* Switch to newlwp's stack. */
926: 1: movl L_ADDR(%edi),%ebx
927: movl PCB_EBP(%ebx),%ebp
928: movl PCB_ESP(%ebx),%esp
1.1 fvdl 929:
1.61 ad 930: /*
931: * Set curlwp. This must be globally visible in order to permit
932: * non-interlocked mutex release.
933: */
934: movl %edi,%ecx
935: xchgl %ecx,CPUVAR(CURLWP)
1.58 ad 936:
937: /* Skip the rest if returning to a pinned LWP. */
938: testl %edx,%edx
939: jnz 4f
940:
1.62 bouyer 941: #ifdef XEN
942: pushl %edi
943: call _C_LABEL(i386_switch_context)
944: addl $4,%esp
945: #else /* XEN */
1.60 yamt 946: /* Switch ring0 esp */
947: movl PCB_ESP0(%ebx),%eax
948: movl %eax,CPUVAR(ESP0)
1.1 fvdl 949:
950: /* Don't bother with the rest if switching to a system process. */
1.48 yamt 951: testl $LW_SYSTEM,L_FLAG(%edi)
952: jnz 4f
1.1 fvdl 953:
1.54 ad 954: /* Restore thread-private %fs/%gs descriptors. */
1.60 yamt 955: movl CPUVAR(GDT),%ecx
1.55 ad 956: movl PCB_FSD(%ebx), %eax
957: movl PCB_FSD+4(%ebx), %edx
1.54 ad 958: movl %eax, (GUFS_SEL*8)(%ecx)
959: movl %edx, (GUFS_SEL*8+4)(%ecx)
1.55 ad 960: movl PCB_GSD(%ebx), %eax
961: movl PCB_GSD+4(%ebx), %edx
1.54 ad 962: movl %eax, (GUGS_SEL*8)(%ecx)
963: movl %edx, (GUGS_SEL*8+4)(%ecx)
1.62 bouyer 964: #endif /* XEN */
1.54 ad 965:
1.60 yamt 966: /* Switch I/O bitmap */
967: movl PCB_IOMAP(%ebx),%eax
968: orl %eax,%eax
969: jnz,pn .Lcopy_iobitmap
970: movl $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE)
971: .Liobitmap_done:
972:
1.56 ad 973: /* Is this process using RAS (restartable atomic sequences)? */
974: movl L_PROC(%edi),%eax
975: cmpl $0,P_RASLIST(%eax)
976: jne 5f
977:
1.48 yamt 978: /*
979: * Restore cr0 (including FPU state). Raise the IPL to IPL_IPI.
980: * FPU IPIs can alter the LWP's saved cr0. Dropping the priority
981: * is deferred until mi_switch(), when cpu_switchto() returns.
982: */
1.62 bouyer 983: 2:
984: #ifndef XEN
985: movl $IPL_IPI,CPUVAR(ILEVEL)
1.48 yamt 986: movl PCB_CR0(%ebx),%ecx
987: movl %cr0,%edx
1.1 fvdl 988:
1.30 junyoung 989: /*
1.22 wiz 990: * If our floating point registers are on a different CPU,
1.48 yamt 991: * set CR0_TS so we'll trap rather than reuse bogus state.
1.1 fvdl 992: */
1.48 yamt 993: movl PCB_FPCPU(%ebx),%eax
994: cmpl CPUVAR(SELF),%eax
995: je 3f
1.1 fvdl 996: orl $CR0_TS,%ecx
1.48 yamt 997:
998: /* Reloading CR0 is very expensive - avoid if possible. */
999: 3: cmpl %edx,%ecx
1000: je 4f
1.1 fvdl 1001: movl %ecx,%cr0
1.62 bouyer 1002: #endif /* XEN */
1.1 fvdl 1003:
1.48 yamt 1004: /* Return to the new LWP, returning 'oldlwp' in %eax. */
1005: 4: movl %esi,%eax
1.1 fvdl 1006: popl %edi
1007: popl %esi
1008: popl %ebx
1009: ret
1.20 dsl 1010:
1.48 yamt 1011: /* Check for restartable atomic sequences (RAS). */
1012: 5: movl L_MD_REGS(%edi),%ecx
1013: pushl TF_EIP(%ecx)
1.20 dsl 1014: pushl %eax
1015: call _C_LABEL(ras_lookup)
1016: addl $8,%esp
1017: cmpl $-1,%eax
1.48 yamt 1018: je 2b
1.49 ad 1019: movl L_MD_REGS(%edi),%ecx
1020: movl %eax,TF_EIP(%ecx)
1.48 yamt 1021: jmp 2b
1.1 fvdl 1022:
1.60 yamt 1023: .Lcopy_iobitmap:
1024: /* Copy I/O bitmap. */
1025: movl $(IOMAPSIZE/4),%ecx
1026: pushl %esi
1027: pushl %edi
1028: movl %eax,%esi /* pcb_iomap */
1029: movl CPUVAR(SELF),%edi
1030: leal CPU_INFO_IOMAP(%edi),%edi
1031: rep
1032: movsl
1033: popl %edi
1034: popl %esi
1035: movl $((CPU_INFO_IOMAP - CPU_INFO_TSS) << 16),CPUVAR(IOBASE)
1036: jmp .Liobitmap_done
1037:
1.1 fvdl 1038: /*
1039: * void savectx(struct pcb *pcb);
1.48 yamt 1040: *
1.1 fvdl 1041: * Update pcb, saving current processor state.
1042: */
1043: ENTRY(savectx)
1.47 skrll 1044: movl 4(%esp),%edx # edx = pcb
1.1 fvdl 1045: movl %esp,PCB_ESP(%edx)
1046: movl %ebp,PCB_EBP(%edx)
1047: ret
1048:
1049: /*
1.48 yamt 1050: * osyscall()
1051: *
1.1 fvdl 1052: * Old call gate entry for syscall
1053: */
1054: IDTVEC(osyscall)
1.48 yamt 1055: pushfl # set eflags in trap frame
1.1 fvdl 1056: popl 8(%esp)
1057: pushl $7 # size of instruction for restart
1058: jmp syscall1
1059:
1060: /*
1.48 yamt 1061: * syscall()
1062: *
1.1 fvdl 1063: * Trap gate entry for syscall
1064: */
1065: IDTVEC(syscall)
1066: pushl $2 # size of instruction for restart
1067: syscall1:
1068: pushl $T_ASTFLT # trap # for doing ASTs
1069: INTRENTRY
1070:
1071: #ifdef DIAGNOSTIC
1.24 yamt 1072: cmpl $0, CPUVAR(WANT_PMAPLOAD)
1073: jz 1f
1074: pushl $6f
1075: call _C_LABEL(printf)
1076: addl $4, %esp
1077: 1:
1.1 fvdl 1078: movl CPUVAR(ILEVEL),%ebx
1079: testl %ebx,%ebx
1080: jz 1f
1081: pushl $5f
1082: call _C_LABEL(printf)
1083: addl $4,%esp
1084: #ifdef DDB
1085: int $3
1086: #endif
1.30 junyoung 1087: 1:
1.1 fvdl 1088: #endif /* DIAGNOSTIC */
1.5 thorpej 1089: movl CPUVAR(CURLWP),%edx
1090: movl %esp,L_MD_REGS(%edx) # save pointer to frame
1091: movl L_PROC(%edx),%edx
1.15 fvdl 1092: pushl %esp
1.1 fvdl 1093: call *P_MD_SYSCALL(%edx) # get pointer to syscall() function
1.15 fvdl 1094: addl $4,%esp
1.27 yamt 1095: .Lsyscall_checkast:
1.24 yamt 1096: /* Check for ASTs on exit to user mode. */
1.62 bouyer 1097: CLI(%eax)
1.5 thorpej 1098: CHECK_ASTPENDING(%eax)
1.1 fvdl 1099: je 1f
1100: /* Always returning to user mode here. */
1.5 thorpej 1101: CLEAR_ASTPENDING(%eax)
1.62 bouyer 1102: STI(%eax)
1.1 fvdl 1103: /* Pushed T_ASTFLT into tf_trapno on entry. */
1.15 fvdl 1104: pushl %esp
1.1 fvdl 1105: call _C_LABEL(trap)
1.15 fvdl 1106: addl $4,%esp
1.27 yamt 1107: jmp .Lsyscall_checkast /* re-check ASTs */
1.53 yamt 1108: 1: CHECK_DEFERRED_SWITCH
1.24 yamt 1109: jnz 9f
1.62 bouyer 1110: #ifdef XEN
1111: STIC(%eax)
1112: jz 14f
1113: call _C_LABEL(stipending)
1114: testl %eax,%eax
1115: jz 14f
1116: /* process pending interrupts */
1117: CLI(%eax)
1118: movl CPUVAR(ILEVEL), %ebx
1119: movl $.Lsyscall_resume, %esi # address to resume loop at
1120: .Lsyscall_resume:
1121: movl %ebx,%eax # get cpl
1122: movl CPUVAR(IUNMASK)(,%eax,4),%eax
1123: andl CPUVAR(IPENDING),%eax # any non-masked bits left?
1124: jz 17f
1125: bsrl %eax,%eax
1126: btrl %eax,CPUVAR(IPENDING)
1127: movl CPUVAR(ISOURCES)(,%eax,4),%eax
1128: jmp *IS_RESUME(%eax)
1129: 17: movl %ebx, CPUVAR(ILEVEL) #restore cpl
1130: jmp .Lsyscall_checkast
1131: 14:
1132: #endif /* XEN */
1.1 fvdl 1133: #ifndef DIAGNOSTIC
1.24 yamt 1134: INTRFASTEXIT
1.1 fvdl 1135: #else /* DIAGNOSTIC */
1.24 yamt 1136: cmpl $IPL_NONE,CPUVAR(ILEVEL)
1.1 fvdl 1137: jne 3f
1138: INTRFASTEXIT
1.62 bouyer 1139: 3: STI(%eax)
1.1 fvdl 1140: pushl $4f
1141: call _C_LABEL(printf)
1142: addl $4,%esp
1.58 ad 1143: pushl $IPL_NONE
1144: call _C_LABEL(spllower)
1145: addl $4,%esp
1.53 yamt 1146: jmp .Lsyscall_checkast
1.1 fvdl 1147: 4: .asciz "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
1.30 junyoung 1148: 5: .asciz "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n"
1149: 6: .asciz "WARNING: WANT PMAPLOAD ON SYSCALL ENTRY\n"
1.1 fvdl 1150: #endif /* DIAGNOSTIC */
1.62 bouyer 1151: 9: STI(%eax)
1.24 yamt 1152: call _C_LABEL(pmap_load)
1.27 yamt 1153: jmp .Lsyscall_checkast /* re-check ASTs */
1.1 fvdl 1154:
1155: #if NNPX > 0
1156: /*
1157: * Special interrupt handlers. Someday intr0-intr15 will be used to count
1158: * interrupts. We'll still need a special exception 16 handler. The busy
1159: * latch stuff in probintr() can be moved to npxprobe().
1160: */
1161:
1.48 yamt 1162: /*
1163: * void probeintr(void)
1164: */
1.1 fvdl 1165: NENTRY(probeintr)
1166: ss
1167: incl _C_LABEL(npx_intrs_while_probing)
1168: pushl %eax
1169: movb $0x20,%al # EOI (asm in strings loses cpp features)
1170: outb %al,$0xa0 # IO_ICU2
1171: outb %al,$0x20 # IO_ICU1
1172: movb $0,%al
1173: outb %al,$0xf0 # clear BUSY# latch
1174: popl %eax
1175: iret
1176:
1.48 yamt 1177: /*
1178: * void probetrap(void)
1179: */
1.1 fvdl 1180: NENTRY(probetrap)
1181: ss
1182: incl _C_LABEL(npx_traps_while_probing)
1183: fnclex
1184: iret
1185:
1.48 yamt 1186: /*
1187: * int npx586bug1(int a, int b)
1188: */
1.1 fvdl 1189: NENTRY(npx586bug1)
1190: fildl 4(%esp) # x
1191: fildl 8(%esp) # y
1192: fld %st(1)
1193: fdiv %st(1),%st # x/y
1194: fmulp %st,%st(1) # (x/y)*y
1195: fsubrp %st,%st(1) # x-(x/y)*y
1196: pushl $0
1197: fistpl (%esp)
1198: popl %eax
1199: ret
1200: #endif /* NNPX > 0 */
1.50 ad 1201:
1202: /*
1203: * void sse2_zero_page(void *pg)
1204: *
1205: * Zero a page without polluting the cache.
1206: */
1207: ENTRY(sse2_zero_page)
1208: pushl %ebp
1209: movl %esp,%ebp
1210: movl 8(%esp), %edx
1211: movl $PAGE_SIZE, %ecx
1212: xorl %eax, %eax
1213: .align 16
1214: 1:
1215: movnti %eax, 0(%edx)
1216: movnti %eax, 4(%edx)
1217: movnti %eax, 8(%edx)
1218: movnti %eax, 12(%edx)
1219: movnti %eax, 16(%edx)
1220: movnti %eax, 20(%edx)
1221: movnti %eax, 24(%edx)
1222: movnti %eax, 28(%edx)
1223: subl $32, %ecx
1224: leal 32(%edx), %edx
1225: jnz 1b
1226: sfence
1227: pop %ebp
1228: ret
1229:
1230: /*
1231: * void sse2_copy_page(void *src, void *dst)
1232: *
1233: * Copy a page without polluting the cache.
1234: */
1235: ENTRY(sse2_copy_page)
1236: pushl %ebp
1237: pushl %ebx
1238: pushl %esi
1239: pushl %edi
1240: movl 20(%esp), %esi
1241: movl 24(%esp), %edi
1242: movl $PAGE_SIZE, %ebp
1243: .align 16
1244: 1:
1245: movl 0(%esi), %eax
1246: movl 4(%esi), %ebx
1247: movl 8(%esi), %ecx
1248: movl 12(%esi), %edx
1249: movnti %eax, 0(%edi)
1250: movnti %ebx, 4(%edi)
1251: movnti %ecx, 8(%edi)
1252: movnti %edx, 12(%edi)
1253: subl $16, %ebp
1254: leal 16(%esi), %esi
1255: leal 16(%edi), %edi
1256: jnz 1b
1257: sfence
1258: popl %edi
1259: popl %esi
1260: popl %ebx
1261: popl %ebp
1262: ret
CVSweb <webmaster@jp.NetBSD.org>