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