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