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