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