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