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