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