Annotation of src/sys/arch/i386/i386/locore.S, Revision 1.40
1.40 ! yamt 1: /* $NetBSD$ */
1.1 fvdl 2:
3: /*-
1.32 mycroft 4: * Copyright (c) 1998, 2000, 2004 The NetBSD Foundation, Inc.
1.1 fvdl 5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
8: * by Charles M. Hannum.
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 the NetBSD
21: * Foundation, Inc. and its contributors.
22: * 4. Neither the name of The NetBSD Foundation nor the names of its
23: * contributors may be used to endorse or promote products derived
24: * from this software without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: * POSSIBILITY OF SUCH DAMAGE.
37: */
38:
39: /*-
40: * Copyright (c) 1990 The Regents of the University of California.
41: * All rights reserved.
42: *
43: * This code is derived from software contributed to Berkeley by
44: * William Jolitz.
45: *
46: * Redistribution and use in source and binary forms, with or without
47: * modification, are permitted provided that the following conditions
48: * are met:
49: * 1. Redistributions of source code must retain the above copyright
50: * notice, this list of conditions and the following disclaimer.
51: * 2. Redistributions in binary form must reproduce the above copyright
52: * notice, this list of conditions and the following disclaimer in the
53: * documentation and/or other materials provided with the distribution.
1.12 agc 54: * 3. Neither the name of the University nor the names of its contributors
1.1 fvdl 55: * may be used to endorse or promote products derived from this software
56: * without specific prior written permission.
57: *
58: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68: * SUCH DAMAGE.
69: *
70: * @(#)locore.s 7.3 (Berkeley) 5/13/91
71: */
72:
1.18 christos 73: #include "opt_compat_netbsd.h"
74: #include "opt_compat_oldboot.h"
1.1 fvdl 75: #include "opt_cputype.h"
76: #include "opt_ddb.h"
77: #include "opt_ipkdb.h"
1.18 christos 78: #include "opt_lockdebug.h"
1.1 fvdl 79: #include "opt_multiprocessor.h"
80: #include "opt_realmem.h"
1.18 christos 81: #include "opt_user_ldt.h"
82: #include "opt_vm86.h"
1.1 fvdl 83:
84: #include "npx.h"
85: #include "assym.h"
86: #include "apm.h"
87: #include "lapic.h"
88: #include "ioapic.h"
1.8 fvdl 89: #include "ksyms.h"
1.1 fvdl 90:
91: #include <sys/errno.h>
92: #include <sys/syscall.h>
93:
94: #include <machine/cputypes.h>
95: #include <machine/segments.h>
96: #include <machine/specialreg.h>
97: #include <machine/trap.h>
98:
99: #if NLAPIC > 0
100: #include <machine/i82489reg.h>
101: #endif
102:
1.37 jmmv 103: #include <machine/multiboot.h>
104:
1.1 fvdl 105: /* LINTSTUB: include <sys/types.h> */
106: /* LINTSTUB: include <machine/cpu.h> */
107: /* LINTSTUB: include <sys/systm.h> */
108:
109: #include <machine/asm.h>
110:
111: #if defined(MULTIPROCESSOR)
1.30 junyoung 112:
1.5 thorpej 113: #define SET_CURLWP(lwp,cpu) \
1.1 fvdl 114: movl CPUVAR(SELF),cpu ; \
1.5 thorpej 115: movl lwp,CPUVAR(CURLWP) ; \
116: movl cpu,L_CPU(lwp)
1.30 junyoung 117:
1.1 fvdl 118: #else
119:
1.5 thorpej 120: #define SET_CURLWP(lwp,tcpu) movl lwp,CPUVAR(CURLWP)
121: #define GET_CURLWP(reg) movl CPUVAR(CURLWP),reg
1.1 fvdl 122:
123: #endif
124:
125: #define SET_CURPCB(reg) movl reg,CPUVAR(CURPCB)
1.24 yamt 126:
1.1 fvdl 127: #define CLEAR_RESCHED(reg) movl reg,CPUVAR(RESCHED)
128:
129: /* XXX temporary kluge; these should not be here */
130: /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
131: #include <dev/isa/isareg.h>
132:
133:
134: /* Disallow old names for REALBASEMEM */
135: #ifdef BIOSBASEMEM
136: #error BIOSBASEMEM option deprecated; use REALBASEMEM only if memory size reported by latest boot block is incorrect
137: #endif
138:
139: /* Disallow old names for REALEXTMEM */
140: #ifdef EXTMEM_SIZE
141: #error EXTMEM_SIZE option deprecated; use REALEXTMEM only if memory size reported by latest boot block is incorrect
142: #endif
143: #ifdef BIOSEXTMEM
144: #error BIOSEXTMEM option deprecated; use REALEXTMEM only if memory size reported by latest boot block is incorrect
145: #endif
146:
147: #include <machine/frameasm.h>
148:
149:
150: #ifdef MULTIPROCESSOR
151: #include <machine/i82489reg.h>
152: #endif
1.30 junyoung 153:
1.1 fvdl 154: /*
155: * Initialization
156: */
157: .data
158:
159: .globl _C_LABEL(cpu)
1.38 jmmv 160: .globl _C_LABEL(esym)
161: .globl _C_LABEL(atdevbase)
1.40 ! yamt 162: .globl _C_LABEL(proc0uarea),_C_LABEL(PDPpaddr)
1.1 fvdl 163: .globl _C_LABEL(gdt)
164: #ifdef I586_CPU
165: .globl _C_LABEL(idt)
166: #endif
1.30 junyoung 167: .globl _C_LABEL(lapic_tpr)
168:
1.1 fvdl 169: #if NLAPIC > 0
170: #ifdef __ELF__
1.7 thorpej 171: .align PAGE_SIZE
1.1 fvdl 172: #else
173: .align 12
174: #endif
175: .globl _C_LABEL(local_apic), _C_LABEL(lapic_id)
176: _C_LABEL(local_apic):
177: .space LAPIC_ID
1.30 junyoung 178: _C_LABEL(lapic_id):
1.1 fvdl 179: .long 0x00000000
180: .space LAPIC_TPRI-(LAPIC_ID+4)
1.30 junyoung 181: _C_LABEL(lapic_tpr):
1.1 fvdl 182: .space LAPIC_PPRI-LAPIC_TPRI
1.30 junyoung 183: _C_LABEL(lapic_ppr):
1.1 fvdl 184: .space LAPIC_ISR-LAPIC_PPRI
185: _C_LABEL(lapic_isr):
1.7 thorpej 186: .space PAGE_SIZE-LAPIC_ISR
1.1 fvdl 187: #else
1.30 junyoung 188: _C_LABEL(lapic_tpr):
1.1 fvdl 189: .long 0
190: #endif
1.30 junyoung 191:
1.1 fvdl 192:
193: _C_LABEL(cpu): .long 0 # are we 386, 386sx, or 486,
194: # or Pentium, or..
195: _C_LABEL(atdevbase): .long 0 # location of start of iomem in virtual
1.40 ! yamt 196: _C_LABEL(proc0uarea): .long 0
1.31 junyoung 197: _C_LABEL(PDPpaddr): .long 0 # paddr of PDP, for libkvm
1.30 junyoung 198:
1.1 fvdl 199: .space 512
200: tmpstk:
201:
202:
1.35 yamt 203: #define _RELOC(x) ((x) - KERNBASE)
1.1 fvdl 204: #define RELOC(x) _RELOC(_C_LABEL(x))
205:
206: .text
207: .globl _C_LABEL(kernel_text)
208: .set _C_LABEL(kernel_text),KERNTEXTOFF
209:
210: .globl start
211: start: movw $0x1234,0x472 # warm boot
212:
1.37 jmmv 213: #if defined(MULTIBOOT)
214: jmp 1f
215:
216: .align 4
217: .globl Multiboot_Header
218: _C_LABEL(Multiboot_Header):
219: #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_HEADER_WANT_MEMORY | \
220: MULTIBOOT_HEADER_HAS_ADDR)
221: .long MULTIBOOT_HEADER_MAGIC
222: .long MULTIBOOT_HEADER_FLAGS
223: .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
224: .long RELOC(Multiboot_Header)
225: .long RELOC(start)
226: .long RELOC(_edata)
227: .long RELOC(_end) + MULTIBOOT_SYMTAB_SPACE
228: .long RELOC(start)
229:
230: 1:
231: /* Check if we are being executed by a Multiboot-compliant boot
232: * loader. */
233: cmpl $MULTIBOOT_INFO_MAGIC,%eax
234: jne 1f
235:
236: /* Indeed, a multiboot-compliat boot loader executed us. We copy
237: * the received Multiboot information structure into kernel's data
238: * space to process it later -- after we are relocated. It will
239: * be safer to run complex C code than doing it at this point. */
240: pushl %ebx # Address of Multiboot information
241: call _C_LABEL(multiboot_pre_reloc)
242: addl $4,%esp
1.38 jmmv 243: jmp 2f
1.37 jmmv 244: #endif
245:
246: 1:
1.1 fvdl 247: /*
1.38 jmmv 248: * At this point, we know that a NetBSD-specific boot loader
249: * booted this kernel. The stack carries the following parameters:
250: * (boothowto, [bootdev], bootinfo, esym, biosbasemem, biosextmem),
251: * 4 bytes each.
1.1 fvdl 252: */
1.38 jmmv 253: addl $4,%esp # Discard return address to boot loader
254: call _C_LABEL(native_loader)
255: addl $24,%esp
1.1 fvdl 256:
257: 2:
258: /* First, reset the PSL. */
259: pushl $PSL_MBO
260: popfl
261:
262: /* Clear segment registers; always null in proc0. */
263: xorl %eax,%eax
264: movw %ax,%fs
265: movw %ax,%gs
266: decl %eax
267: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
268:
269: /* Find out our CPU type. */
270:
271: try386: /* Try to toggle alignment check flag; does not exist on 386. */
272: pushfl
273: popl %eax
274: movl %eax,%ecx
275: orl $PSL_AC,%eax
276: pushl %eax
277: popfl
278: pushfl
279: popl %eax
280: xorl %ecx,%eax
281: andl $PSL_AC,%eax
282: pushl %ecx
283: popfl
284:
285: testl %eax,%eax
286: jnz try486
287:
288: /*
289: * Try the test of a NexGen CPU -- ZF will not change on a DIV
290: * instruction on a NexGen, it will on an i386. Documented in
291: * Nx586 Processor Recognition Application Note, NexGen, Inc.
292: */
293: movl $0x5555,%eax
294: xorl %edx,%edx
295: movl $2,%ecx
296: divl %ecx
297: jnz is386
298:
299: isnx586:
300: /*
301: * Don't try cpuid, as Nx586s reportedly don't support the
302: * PSL_ID bit.
303: */
304: movl $CPU_NX586,RELOC(cpu)
305: jmp 2f
306:
307: is386:
308: movl $CPU_386,RELOC(cpu)
309: jmp 2f
310:
311: try486: /* Try to toggle identification flag; does not exist on early 486s. */
312: pushfl
313: popl %eax
314: movl %eax,%ecx
315: xorl $PSL_ID,%eax
316: pushl %eax
317: popfl
318: pushfl
319: popl %eax
320: xorl %ecx,%eax
321: andl $PSL_ID,%eax
322: pushl %ecx
323: popfl
324:
325: testl %eax,%eax
326: jnz try586
327: is486: movl $CPU_486,RELOC(cpu)
328: /*
329: * Check Cyrix CPU
330: * Cyrix CPUs do not change the undefined flags following
331: * execution of the divide instruction which divides 5 by 2.
332: *
333: * Note: CPUID is enabled on M2, so it passes another way.
334: */
335: pushfl
336: movl $0x5555, %eax
337: xorl %edx, %edx
338: movl $2, %ecx
339: clc
340: divl %ecx
341: jnc trycyrix486
342: popfl
343: jmp 2f
344: trycyrix486:
345: movl $CPU_6x86,RELOC(cpu) # set CPU type
346: /*
347: * Check for Cyrix 486 CPU by seeing if the flags change during a
348: * divide. This is documented in the Cx486SLC/e SMM Programmer's
349: * Guide.
350: */
351: xorl %edx,%edx
352: cmpl %edx,%edx # set flags to known state
353: pushfl
354: popl %ecx # store flags in ecx
355: movl $-1,%eax
356: movl $4,%ebx
357: divl %ebx # do a long division
358: pushfl
359: popl %eax
360: xorl %ecx,%eax # are the flags different?
361: testl $0x8d5,%eax # only check C|PF|AF|Z|N|V
362: jne 2f # yes; must be Cyrix 6x86 CPU
363: movl $CPU_486DLC,RELOC(cpu) # set CPU type
364:
365: #ifndef CYRIX_CACHE_WORKS
366: /* Disable caching of the ISA hole only. */
367: invd
368: movb $CCR0,%al # Configuration Register index (CCR0)
369: outb %al,$0x22
370: inb $0x23,%al
371: orb $(CCR0_NC1|CCR0_BARB),%al
372: movb %al,%ah
373: movb $CCR0,%al
374: outb %al,$0x22
375: movb %ah,%al
376: outb %al,$0x23
377: invd
378: #else /* CYRIX_CACHE_WORKS */
379: /* Set cache parameters */
380: invd # Start with guaranteed clean cache
381: movb $CCR0,%al # Configuration Register index (CCR0)
382: outb %al,$0x22
383: inb $0x23,%al
384: andb $~CCR0_NC0,%al
385: #ifndef CYRIX_CACHE_REALLY_WORKS
386: orb $(CCR0_NC1|CCR0_BARB),%al
387: #else
388: orb $CCR0_NC1,%al
389: #endif
390: movb %al,%ah
391: movb $CCR0,%al
392: outb %al,$0x22
393: movb %ah,%al
394: outb %al,$0x23
395: /* clear non-cacheable region 1 */
396: movb $(NCR1+2),%al
397: outb %al,$0x22
398: movb $NCR_SIZE_0K,%al
399: outb %al,$0x23
400: /* clear non-cacheable region 2 */
401: movb $(NCR2+2),%al
402: outb %al,$0x22
403: movb $NCR_SIZE_0K,%al
404: outb %al,$0x23
405: /* clear non-cacheable region 3 */
406: movb $(NCR3+2),%al
407: outb %al,$0x22
408: movb $NCR_SIZE_0K,%al
409: outb %al,$0x23
410: /* clear non-cacheable region 4 */
411: movb $(NCR4+2),%al
412: outb %al,$0x22
413: movb $NCR_SIZE_0K,%al
414: outb %al,$0x23
415: /* enable caching in CR0 */
416: movl %cr0,%eax
417: andl $~(CR0_CD|CR0_NW),%eax
418: movl %eax,%cr0
419: invd
420: #endif /* CYRIX_CACHE_WORKS */
421:
422: jmp 2f
423:
424: try586: /* Use the `cpuid' instruction. */
425: xorl %eax,%eax
426: cpuid
427: movl %eax,RELOC(cpu_info_primary)+CPU_INFO_LEVEL
428:
429: 2:
430: /*
431: * Finished with old stack; load new %esp now instead of later so we
432: * can trace this code without having to worry about the trace trap
433: * clobbering the memory test or the zeroing of the bss+bootstrap page
434: * tables.
435: *
436: * The boot program should check:
437: * text+data <= &stack_variable - more_space_for_stack
438: * text+data+bss+pad+space_for_page_tables <= end_of_memory
439: * Oops, the gdt is in the carcass of the boot program so clearing
440: * the rest of memory is still not possible.
441: */
442: movl $_RELOC(tmpstk),%esp # bootstrap stack end location
443:
444: /*
445: * Virtual address space of kernel:
446: *
1.30 junyoung 447: * text | data | bss | [syms] | page dir | proc0 kstack
1.1 fvdl 448: * 0 1 2 3
449: */
1.7 thorpej 450: #define PROC0PDIR ((0) * PAGE_SIZE)
451: #define PROC0STACK ((1) * PAGE_SIZE)
452: #define SYSMAP ((1+UPAGES) * PAGE_SIZE)
453: #define TABLESIZE ((1+UPAGES) * PAGE_SIZE) /* + nkpde * PAGE_SIZE */
1.1 fvdl 454:
455: /* Find end of kernel image. */
456: movl $RELOC(end),%edi
1.8 fvdl 457: #if (NKSYMS || defined(DDB) || defined(LKM)) && !defined(SYMTAB_SPACE)
1.1 fvdl 458: /* Save the symbols (if loaded). */
459: movl RELOC(esym),%eax
460: testl %eax,%eax
461: jz 1f
1.35 yamt 462: subl $KERNBASE,%eax
1.1 fvdl 463: movl %eax,%edi
464: 1:
465: #endif
466:
467: /* Calculate where to start the bootstrap tables. */
468: movl %edi,%esi # edi = esym ? esym : end
469: addl $PGOFSET,%esi # page align up
470: andl $~PGOFSET,%esi
471:
472: /*
473: * Calculate the size of the kernel page table directory, and
1.29 mycroft 474: * how many entries it will have. Adjust nkpde to the actual
475: * kernel size automatically. Account for the bootstrap tables,
476: * round up, and add an extra 4MB.
1.1 fvdl 477: */
1.29 mycroft 478: leal TABLESIZE+NBPD+PDOFSET(%edi),%eax
479: shrl $PDSHIFT,%eax
1.1 fvdl 480: movl RELOC(nkpde),%ecx # get nkpde
1.29 mycroft 481: cmpl %ecx,%eax
482: jb 1f
483: movl %eax,%ecx
484: 1: cmpl $NKPTP_MIN,%ecx # larger than min?
1.1 fvdl 485: jge 1f
486: movl $NKPTP_MIN,%ecx # set at min
487: jmp 2f
488: 1: cmpl $NKPTP_MAX,%ecx # larger than max?
489: jle 2f
490: movl $NKPTP_MAX,%ecx
1.29 mycroft 491: 2: movl %ecx,RELOC(nkpde)
1.1 fvdl 492:
493: /* Clear memory for bootstrap tables. */
494: shll $PGSHIFT,%ecx
495: addl $TABLESIZE,%ecx
496: addl %esi,%ecx # end of tables
497: subl %edi,%ecx # size of tables
498: shrl $2,%ecx
499: xorl %eax,%eax
500: cld
501: rep
502: stosl
503:
504: /*
505: * fillkpt
506: * eax = pte (page frame | control | status)
507: * ebx = page table address
508: * ecx = number of pages to map
509: */
510: #define fillkpt \
511: 1: movl %eax,(%ebx) ; \
1.7 thorpej 512: addl $PAGE_SIZE,%eax ; /* increment physical address */ \
1.1 fvdl 513: addl $4,%ebx ; /* next pte */ \
514: loop 1b ;
515:
516: /*
517: * Build initial page tables.
518: */
519: /* Calculate end of text segment, rounded to a page. */
520: leal (RELOC(etext)+PGOFSET),%edx
521: andl $~PGOFSET,%edx
1.30 junyoung 522:
1.1 fvdl 523: /* Skip over the first 1MB. */
524: movl $_RELOC(KERNTEXTOFF),%eax
525: movl %eax,%ecx
526: shrl $PGSHIFT,%ecx
527: leal (SYSMAP)(%esi,%ecx,4),%ebx
528:
529: /* Map the kernel text read-only. */
530: movl %edx,%ecx
531: subl %eax,%ecx
532: shrl $PGSHIFT,%ecx
533: orl $(PG_V|PG_KR),%eax
534: fillkpt
535:
536: /* Map the data, BSS, and bootstrap tables read-write. */
537: leal (PG_V|PG_KW)(%edx),%eax
538: movl RELOC(nkpde),%ecx
539: shll $PGSHIFT,%ecx
540: addl $TABLESIZE,%ecx
541: addl %esi,%ecx # end of tables
542: subl %edx,%ecx # subtract end of text
543: shrl $PGSHIFT,%ecx
544: fillkpt
545:
546: /* Map ISA I/O memory. */
547: movl $(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax # having these bits set
548: movl $(IOM_SIZE>>PGSHIFT),%ecx # for this many pte s,
549: fillkpt
550:
551: /*
552: * Construct a page table directory.
553: */
554: /* Install PDEs for temporary double map of kernel. */
555: movl RELOC(nkpde),%ecx # for this many pde s,
556: leal (PROC0PDIR+0*4)(%esi),%ebx # which is where temp maps!
557: leal (SYSMAP+PG_V|PG_KW)(%esi),%eax # pte for KPT in proc 0,
558: fillkpt
559:
560: /* Map kernel PDEs. */
561: movl RELOC(nkpde),%ecx # for this many pde s,
562: leal (PROC0PDIR+PDSLOT_KERN*4)(%esi),%ebx # kernel pde offset
563: leal (SYSMAP+PG_V|PG_KW)(%esi),%eax # pte for KPT in proc 0,
564: fillkpt
565:
566: /* Install a PDE recursively mapping page directory as a page table! */
567: leal (PROC0PDIR+PG_V|PG_KW)(%esi),%eax # pte for ptd
568: movl %eax,(PROC0PDIR+PDSLOT_PTE*4)(%esi) # recursive PD slot
569:
1.31 junyoung 570: /* Save phys. addr of PDP, for libkvm. */
571: movl %esi,RELOC(PDPpaddr)
1.1 fvdl 572:
573: /* Load base of page directory and enable mapping. */
574: movl %esi,%eax # phys address of ptd in proc 0
575: movl %eax,%cr3 # load ptd addr into mmu
576: movl %cr0,%eax # get control word
577: # enable paging & NPX emulation
578: orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP),%eax
579: movl %eax,%cr0 # and let's page NOW!
580:
581: pushl $begin # jump to high mem
582: ret
583:
584: begin:
1.35 yamt 585: /* Now running relocated at KERNBASE. Remove double mapping. */
1.1 fvdl 586: movl _C_LABEL(nkpde),%ecx # for this many pde s,
587: leal (PROC0PDIR+0*4)(%esi),%ebx # which is where temp maps!
1.35 yamt 588: addl $(KERNBASE), %ebx # now use relocated address
1.1 fvdl 589: 1: movl $0,(%ebx)
590: addl $4,%ebx # next pde
591: loop 1b
592:
593: /* Relocate atdevbase. */
594: movl _C_LABEL(nkpde),%edx
595: shll $PGSHIFT,%edx
1.35 yamt 596: addl $(TABLESIZE+KERNBASE),%edx
1.1 fvdl 597: addl %esi,%edx
598: movl %edx,_C_LABEL(atdevbase)
599:
600: /* Set up bootstrap stack. */
1.35 yamt 601: leal (PROC0STACK+KERNBASE)(%esi),%eax
1.40 ! yamt 602: movl %eax,_C_LABEL(proc0uarea)
! 603: leal (KSTACK_SIZE-FRAMESIZE)(%eax),%esp
! 604: movl %esi,(KSTACK_SIZE+PCB_CR3)(%eax) # pcb->pcb_cr3
1.1 fvdl 605: xorl %ebp,%ebp # mark end of frames
606:
1.37 jmmv 607: #if defined(MULTIBOOT)
608: /* It is now safe to parse the Multiboot information structure
609: * we saved before from C code. Note that we cannot delay its
610: * parsing any more because initgdt (called below) needs to make
611: * use of this information. */
612: call _C_LABEL(multiboot_post_reloc)
613: #endif
614:
1.1 fvdl 615: subl $NGDT*8, %esp # space for temporary gdt
616: pushl %esp
617: call _C_LABEL(initgdt)
618: addl $4,%esp
1.30 junyoung 619:
1.1 fvdl 620: movl _C_LABEL(nkpde),%eax
621: shll $PGSHIFT,%eax
622: addl $TABLESIZE,%eax
623: addl %esi,%eax # skip past stack and page tables
624:
625: pushl %eax
626: call _C_LABEL(init386) # wire 386 chip for unix operation
627: addl $4+NGDT*8,%esp # pop temporary gdt
628:
629: #ifdef SAFARI_FIFO_HACK
630: movb $5,%al
631: movw $0x37b,%dx
632: outb %al,%dx
633: movw $0x37f,%dx
634: inb %dx,%al
635: movb %al,%cl
636:
637: orb $1,%cl
638:
639: movb $5,%al
640: movw $0x37b,%dx
641: outb %al,%dx
642: movw $0x37f,%dx
643: movb %cl,%al
644: outb %al,%dx
645: #endif /* SAFARI_FIFO_HACK */
646:
647: call _C_LABEL(main)
648:
649: /*
650: * void proc_trampoline(void);
651: * This is a trampoline function pushed onto the stack of a newly created
652: * process in order to do some additional setup. The trampoline is entered by
653: * cpu_switch()ing to the process, so we abuse the callee-saved registers used
654: * by cpu_switch() to store the information about the stub to call.
655: * NOTE: This function does not have a normal calling sequence!
656: */
657: /* LINTSTUB: Func: void proc_trampoline(void) */
658: NENTRY(proc_trampoline)
659: #ifdef MULTIPROCESSOR
660: call _C_LABEL(proc_trampoline_mp)
661: #endif
662: movl $IPL_NONE,CPUVAR(ILEVEL)
663: pushl %ebx
664: call *%esi
665: addl $4,%esp
1.24 yamt 666: DO_DEFERRED_SWITCH(%eax)
1.1 fvdl 667: INTRFASTEXIT
668: /* NOTREACHED */
669:
670: /*****************************************************************************/
1.16 christos 671: #ifdef COMPAT_16
1.1 fvdl 672: /*
673: * Signal trampoline; copied to top of user stack.
674: */
675: /* LINTSTUB: Var: char sigcode[1], esigcode[1]; */
676: NENTRY(sigcode)
677: /*
678: * Handler has returned here as if we called it. The sigcontext
679: * is on the stack after the 3 args "we" pushed.
680: */
681: leal 12(%esp),%eax # get pointer to sigcontext
682: movl %eax,4(%esp) # put it in the argument slot
683: # fake return address already there
1.17 christos 684: movl $SYS_compat_16___sigreturn14,%eax
1.1 fvdl 685: int $0x80 # enter kernel with args on stack
686: movl $SYS_exit,%eax
687: int $0x80 # exit if sigreturn fails
688: .globl _C_LABEL(esigcode)
689: _C_LABEL(esigcode):
1.16 christos 690: #endif
1.1 fvdl 691:
692: /*****************************************************************************/
693:
694: /*
695: * The following is i386-specific nonsense.
696: */
697:
698: /*
699: * void lgdt(struct region_descriptor *rdp);
700: * Load a new GDT pointer (and do any necessary cleanup).
701: * XXX It's somewhat questionable whether reloading all the segment registers
702: * is necessary, since the actual descriptor data is not changed except by
703: * process creation and exit, both of which clean up via task switches. OTOH,
704: * this only happens at run time when the GDT is resized.
705: */
706: /* LINTSTUB: Func: void lgdt(struct region_descriptor *rdp) */
707: NENTRY(lgdt)
708: /* Reload the descriptor table. */
709: movl 4(%esp),%eax
710: lgdt (%eax)
711: /* Flush the prefetch queue. */
712: jmp 1f
713: nop
714: 1: /* Reload "stale" selectors. */
715: movl $GSEL(GDATA_SEL, SEL_KPL),%eax
716: movw %ax,%ds
717: movw %ax,%es
718: movw %ax,%gs
719: movw %ax,%ss
720: movl $GSEL(GCPU_SEL, SEL_KPL),%eax
721: movw %ax,%fs
722: /* Reload code selector by doing intersegment return. */
723: popl %eax
724: pushl $GSEL(GCODE_SEL, SEL_KPL)
725: pushl %eax
726: lret
727:
728: /*****************************************************************************/
729:
730: /*
731: * These functions are primarily used by DDB.
732: */
733:
734: /* LINTSTUB: Func: int setjmp (label_t *l) */
735: ENTRY(setjmp)
736: movl 4(%esp),%eax
737: movl %ebx,(%eax) # save ebx
738: movl %esp,4(%eax) # save esp
739: movl %ebp,8(%eax) # save ebp
740: movl %esi,12(%eax) # save esi
741: movl %edi,16(%eax) # save edi
742: movl (%esp),%edx # get rta
743: movl %edx,20(%eax) # save eip
744: xorl %eax,%eax # return (0);
745: ret
746:
747: /* LINTSTUB: Func: void longjmp (label_t *l) */
748: ENTRY(longjmp)
749: movl 4(%esp),%eax
750: movl (%eax),%ebx # restore ebx
751: movl 4(%eax),%esp # restore esp
752: movl 8(%eax),%ebp # restore ebp
753: movl 12(%eax),%esi # restore esi
754: movl 16(%eax),%edi # restore edi
755: movl 20(%eax),%edx # get rta
756: movl %edx,(%esp) # put in return frame
757: xorl %eax,%eax # return (1);
758: incl %eax
759: ret
760:
761: /*****************************************************************************/
762:
763: .globl _C_LABEL(sched_whichqs),_C_LABEL(sched_qs)
764: .globl _C_LABEL(uvmexp),_C_LABEL(panic)
765:
766: #ifdef DIAGNOSTIC
767: NENTRY(switch_error)
768: pushl $1f
769: call _C_LABEL(panic)
770: /* NOTREACHED */
771: 1: .asciz "cpu_switch"
772: #endif /* DIAGNOSTIC */
773:
774: /*
1.5 thorpej 775: * void cpu_switch(struct lwp *)
1.39 skrll 776: * Find a runnable lwp and switch to it. Wait if necessary. If the new
777: * lwp is the same as the old one, we short-circuit the context save and
1.1 fvdl 778: * restore.
1.30 junyoung 779: *
1.1 fvdl 780: * Note that the stack frame layout is known to "struct switchframe"
1.30 junyoung 781: * in <machine/frame.h> and to the code in cpu_fork() which initializes
1.5 thorpej 782: * it for a new lwp.
1.1 fvdl 783: */
784: ENTRY(cpu_switch)
785: pushl %ebx
786: pushl %esi
787: pushl %edi
788:
789: #ifdef DEBUG
790: cmpl $IPL_SCHED,CPUVAR(ILEVEL)
791: jae 1f
1.5 thorpej 792: pushl $2f
1.1 fvdl 793: call _C_LABEL(panic)
794: /* NOTREACHED */
1.5 thorpej 795: 2: .asciz "not splsched() in cpu_switch!"
1.30 junyoung 796: 1:
1.1 fvdl 797: #endif /* DEBUG */
1.30 junyoung 798:
1.5 thorpej 799: movl 16(%esp),%esi # current
1.1 fvdl 800:
801: /*
1.5 thorpej 802: * Clear curlwp so that we don't accumulate system time while idle.
803: * This also insures that schedcpu() will move the old lwp to
1.1 fvdl 804: * the correct queue if it happens to get called from the spllower()
805: * below and changes the priority. (See corresponding comment in
806: * userret()).
807: */
1.5 thorpej 808: movl $0,CPUVAR(CURLWP)
1.1 fvdl 809: /*
1.5 thorpej 810: * First phase: find new lwp.
1.1 fvdl 811: *
812: * Registers:
813: * %eax - queue head, scratch, then zero
814: * %ebx - queue number
815: * %ecx - cached value of whichqs
1.5 thorpej 816: * %edx - next lwp in queue
817: * %esi - old lwp
818: * %edi - new lwp
1.1 fvdl 819: */
820:
1.5 thorpej 821: /* Look for new lwp. */
1.1 fvdl 822: cli # splhigh doesn't do a cli
823: movl _C_LABEL(sched_whichqs),%ecx
824: bsfl %ecx,%ebx # find a full q
825: jnz switch_dequeue
826:
827: /*
828: * idling: save old context.
829: *
830: * Registers:
831: * %eax, %ecx - scratch
1.5 thorpej 832: * %esi - old lwp, then old pcb
1.1 fvdl 833: * %edi - idle pcb
834: */
835:
836: pushl %esi
1.24 yamt 837: call _C_LABEL(pmap_deactivate2) # pmap_deactivate(oldproc)
1.1 fvdl 838: addl $4,%esp
839:
1.5 thorpej 840: movl L_ADDR(%esi),%esi
1.1 fvdl 841:
842: /* Save stack pointers. */
843: movl %esp,PCB_ESP(%esi)
844: movl %ebp,PCB_EBP(%esi)
845:
846: /* Find idle PCB for this CPU */
847: #ifndef MULTIPROCESSOR
1.5 thorpej 848: movl $_C_LABEL(lwp0),%ebx
849: movl L_ADDR(%ebx),%edi
850: movl L_MD_TSS_SEL(%ebx),%edx
1.1 fvdl 851: #else
852: movl CPUVAR(IDLE_PCB),%edi
853: movl CPUVAR(IDLE_TSS_SEL),%edx
854: #endif
1.5 thorpej 855: movl $0,CPUVAR(CURLWP) /* In case we fault... */
1.1 fvdl 856:
857: /* Restore the idle context (avoid interrupts) */
858: cli
859:
860: /* Restore stack pointers. */
861: movl PCB_ESP(%edi),%esp
862: movl PCB_EBP(%edi),%ebp
863:
864: /* Switch TSS. Reset "task busy" flag before loading. */
1.26 yamt 865: movl %cr3,%eax
866: movl %eax,PCB_CR3(%edi)
1.1 fvdl 867: #ifdef MULTIPROCESSOR
868: movl CPUVAR(GDT),%eax
869: #else
870: movl _C_LABEL(gdt),%eax
871: #endif
872: andl $~0x0200,4-SEL_KPL(%eax,%edx,1)
873: ltr %dx
874:
875: /* We're always in the kernel, so we don't need the LDT. */
876:
877: /* Restore cr0 (including FPU state). */
878: movl PCB_CR0(%edi),%ecx
879: movl %ecx,%cr0
880:
881: /* Record new pcb. */
882: SET_CURPCB(%edi)
883:
884: xorl %esi,%esi
885: sti
1.30 junyoung 886: idle_unlock:
887: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
1.1 fvdl 888: call _C_LABEL(sched_unlock_idle)
889: #endif
890: /* Interrupts are okay again. */
1.2 fvdl 891: pushl $IPL_NONE # spl0()
1.1 fvdl 892: call _C_LABEL(Xspllower) # process pending interrupts
1.2 fvdl 893: addl $4,%esp
1.1 fvdl 894: jmp idle_start
1.30 junyoung 895: idle_zero:
1.1 fvdl 896: sti
897: call _C_LABEL(uvm_pageidlezero)
898: cli
899: cmpl $0,_C_LABEL(sched_whichqs)
900: jnz idle_exit
901: idle_loop:
902: /* Try to zero some pages. */
903: movl _C_LABEL(uvm)+UVM_PAGE_IDLE_ZERO,%ecx
904: testl %ecx,%ecx
905: jnz idle_zero
906: sti
907: hlt
908: NENTRY(mpidle)
1.30 junyoung 909: idle_start:
1.1 fvdl 910: cli
911: cmpl $0,_C_LABEL(sched_whichqs)
912: jz idle_loop
1.30 junyoung 913: idle_exit:
1.1 fvdl 914: movl $IPL_HIGH,CPUVAR(ILEVEL) # splhigh
1.14 fvdl 915: sti
1.30 junyoung 916: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
1.1 fvdl 917: call _C_LABEL(sched_lock_idle)
918: #endif
919: movl _C_LABEL(sched_whichqs),%ecx
920: bsfl %ecx,%ebx
921: jz idle_unlock
922:
1.30 junyoung 923: switch_dequeue:
924: /*
1.1 fvdl 925: * we're running at splhigh(), but it's otherwise okay to take
1.30 junyoung 926: * interrupts here.
1.1 fvdl 927: */
928: sti
929: leal _C_LABEL(sched_qs)(,%ebx,8),%eax # select q
930:
1.5 thorpej 931: movl L_FORW(%eax),%edi # unlink from front of process q
1.1 fvdl 932: #ifdef DIAGNOSTIC
933: cmpl %edi,%eax # linked to self (i.e. nothing queued)?
934: je _C_LABEL(switch_error) # not possible
935: #endif /* DIAGNOSTIC */
1.5 thorpej 936: movl L_FORW(%edi),%edx
937: movl %edx,L_FORW(%eax)
938: movl %eax,L_BACK(%edx)
1.1 fvdl 939:
940: cmpl %edx,%eax # q empty?
941: jne 3f
942:
943: btrl %ebx,%ecx # yes, clear to indicate empty
944: movl %ecx,_C_LABEL(sched_whichqs) # update q status
945:
946: 3: /* We just did it. */
947: xorl %eax,%eax
948: CLEAR_RESCHED(%eax)
949:
1.5 thorpej 950: switch_resume:
1.1 fvdl 951: #ifdef DIAGNOSTIC
1.5 thorpej 952: cmpl %eax,L_WCHAN(%edi) # Waiting for something?
1.1 fvdl 953: jne _C_LABEL(switch_error) # Yes; shouldn't be queued.
1.5 thorpej 954: cmpb $LSRUN,L_STAT(%edi) # In run state?
1.1 fvdl 955: jne _C_LABEL(switch_error) # No; shouldn't be queued.
956: #endif /* DIAGNOSTIC */
957:
1.5 thorpej 958: /* Isolate lwp. XXX Is this necessary? */
959: movl %eax,L_BACK(%edi)
1.1 fvdl 960:
1.5 thorpej 961: /* Record new lwp. */
962: movb $LSONPROC,L_STAT(%edi) # l->l_stat = LSONPROC
963: SET_CURLWP(%edi,%ecx)
1.1 fvdl 964:
1.5 thorpej 965: /* Skip context switch if same lwp. */
1.10 fvdl 966: xorl %ebx,%ebx
1.1 fvdl 967: cmpl %edi,%esi
968: je switch_return
969:
1.5 thorpej 970: /* If old lwp exited, don't bother. */
1.1 fvdl 971: testl %esi,%esi
972: jz switch_exited
973:
974: /*
975: * Second phase: save old context.
976: *
977: * Registers:
978: * %eax, %ecx - scratch
1.5 thorpej 979: * %esi - old lwp, then old pcb
980: * %edi - new lwp
1.1 fvdl 981: */
982:
983: pushl %esi
1.24 yamt 984: call _C_LABEL(pmap_deactivate2) # pmap_deactivate(oldproc)
1.1 fvdl 985: addl $4,%esp
986:
1.5 thorpej 987: movl L_ADDR(%esi),%esi
1.1 fvdl 988:
989: /* Save stack pointers. */
990: movl %esp,PCB_ESP(%esi)
991: movl %ebp,PCB_EBP(%esi)
992:
993: switch_exited:
994: /*
995: * Third phase: restore saved context.
996: *
997: * Registers:
998: * %eax, %ebx, %ecx, %edx - scratch
999: * %esi - new pcb
1.5 thorpej 1000: * %edi - new lwp
1.1 fvdl 1001: */
1002:
1003: /* No interrupts while loading new state. */
1004: cli
1.5 thorpej 1005: movl L_ADDR(%edi),%esi
1.1 fvdl 1006:
1007: /* Restore stack pointers. */
1008: movl PCB_ESP(%esi),%esp
1009: movl PCB_EBP(%esi),%ebp
1010:
1011: #if 0
1012: /* Don't bother with the rest if switching to a system process. */
1.5 thorpej 1013: testl $P_SYSTEM,L_FLAG(%edi); XXX NJWLWP lwp's don't have P_SYSTEM!
1.1 fvdl 1014: jnz switch_restored
1015: #endif
1016:
1.26 yamt 1017: /* Switch TSS. Reset "task busy" flag before loading. */
1018: movl %cr3,%eax
1019: movl %eax,PCB_CR3(%esi) /* XXX should be done by pmap_activate? */
1.1 fvdl 1020: #ifdef MULTIPROCESSOR
1021: movl CPUVAR(GDT),%eax
1.30 junyoung 1022: #else
1.1 fvdl 1023: /* Load TSS info. */
1024: movl _C_LABEL(gdt),%eax
1025: #endif
1.5 thorpej 1026: movl L_MD_TSS_SEL(%edi),%edx
1.1 fvdl 1027:
1028: andl $~0x0200,4(%eax,%edx, 1)
1029: ltr %dx
1030:
1031: pushl %edi
1032: call _C_LABEL(pmap_activate) # pmap_activate(p)
1033: addl $4,%esp
1034:
1035: #if 0
1036: switch_restored:
1037: #endif
1038: /* Restore cr0 (including FPU state). */
1039: movl PCB_CR0(%esi),%ecx
1040: #ifdef MULTIPROCESSOR
1.30 junyoung 1041: /*
1.22 wiz 1042: * If our floating point registers are on a different CPU,
1.1 fvdl 1043: * clear CR0_TS so we'll trap rather than reuse bogus state.
1044: */
1045: movl PCB_FPCPU(%esi),%ebx
1046: cmpl CPUVAR(SELF),%ebx
1047: jz 1f
1048: orl $CR0_TS,%ecx
1.30 junyoung 1049: 1:
1050: #endif
1.1 fvdl 1051: movl %ecx,%cr0
1052:
1053: /* Record new pcb. */
1054: SET_CURPCB(%esi)
1055:
1056: /* Interrupts are okay again. */
1057: sti
1058:
1059: /*
1060: * Check for restartable atomic sequences (RAS)
1061: */
1.5 thorpej 1062: movl CPUVAR(CURLWP),%edi
1063: movl L_PROC(%edi),%esi
1.20 dsl 1064: cmpl $0,P_RASLIST(%esi)
1065: jne 2f
1.1 fvdl 1066: 1:
1.10 fvdl 1067: movl $1,%ebx
1.1 fvdl 1068:
1069: switch_return:
1.30 junyoung 1070: #if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
1.1 fvdl 1071: call _C_LABEL(sched_unlock_idle)
1072: #endif
1.28 yamt 1073: cmpl $0,CPUVAR(IPENDING)
1074: jz 3f
1.2 fvdl 1075: pushl $IPL_NONE # spl0()
1.1 fvdl 1076: call _C_LABEL(Xspllower) # process pending interrupts
1.2 fvdl 1077: addl $4,%esp
1.28 yamt 1078: 3:
1.1 fvdl 1079: movl $IPL_HIGH,CPUVAR(ILEVEL) # splhigh()
1.9 fvdl 1080:
1081: movl %ebx,%eax
1.30 junyoung 1082:
1.1 fvdl 1083: popl %edi
1084: popl %esi
1085: popl %ebx
1086: ret
1.20 dsl 1087:
1088: 2: # check RAS list
1089: movl L_MD_REGS(%edi),%ebx
1090: movl TF_EIP(%ebx),%eax
1091: pushl %eax
1092: pushl %esi
1093: call _C_LABEL(ras_lookup)
1094: addl $8,%esp
1095: cmpl $-1,%eax
1096: je 1b
1097: movl %eax,TF_EIP(%ebx)
1098: jmp 1b
1.1 fvdl 1099:
1100: /*
1.5 thorpej 1101: * void cpu_switchto(struct lwp *current, struct lwp *next)
1102: * Switch to the specified next LWP.
1103: */
1104: ENTRY(cpu_switchto)
1105: pushl %ebx
1106: pushl %esi
1107: pushl %edi
1108:
1109: #ifdef DEBUG
1110: cmpl $IPL_SCHED,CPUVAR(ILEVEL)
1111: jae 1f
1112: pushl $2f
1113: call _C_LABEL(panic)
1114: /* NOTREACHED */
1115: 2: .asciz "not splsched() in cpu_switchto!"
1116: 1:
1117: #endif /* DEBUG */
1118:
1119: movl 16(%esp),%esi # current
1120: movl 20(%esp),%edi # next
1121:
1122: /*
1123: * Clear curlwp so that we don't accumulate system time while idle.
1124: * This also insures that schedcpu() will move the old process to
1125: * the correct queue if it happens to get called from the spllower()
1126: * below and changes the priority. (See corresponding comment in
1127: * usrret()).
1128: *
1129: * XXX Is this necessary? We know we won't go idle.
1130: */
1131: movl $0,CPUVAR(CURLWP)
1132:
1133: /*
1134: * We're running at splhigh(), but it's otherwise okay to take
1135: * interrupts here.
1136: */
1137: sti
1138:
1139: /* Jump into the middle of cpu_switch */
1140: xorl %eax,%eax
1141: jmp switch_resume
1142:
1143: /*
1.21 jdolecek 1144: * void cpu_exit(struct lwp *l)
1.30 junyoung 1145: * Switch to the appropriate idle context (lwp0's if uniprocessor; the CPU's
1146: * if multiprocessor) and deallocate the address space and kernel stack for p.
1.1 fvdl 1147: * Then jump into cpu_switch(), as if we were in the idle proc all along.
1148: */
1149: #ifndef MULTIPROCESSOR
1.5 thorpej 1150: .globl _C_LABEL(lwp0)
1.1 fvdl 1151: #endif
1.21 jdolecek 1152: /* LINTSTUB: Func: void cpu_exit(struct lwp *l) */
1153: ENTRY(cpu_exit)
1.1 fvdl 1154: movl 4(%esp),%edi # old process
1155: #ifndef MULTIPROCESSOR
1.5 thorpej 1156: movl $_C_LABEL(lwp0),%ebx
1157: movl L_ADDR(%ebx),%esi
1158: movl L_MD_TSS_SEL(%ebx),%edx
1.1 fvdl 1159: #else
1160: movl CPUVAR(IDLE_PCB),%esi
1161: movl CPUVAR(IDLE_TSS_SEL),%edx
1162: #endif
1163: /* In case we fault... */
1.5 thorpej 1164: movl $0,CPUVAR(CURLWP)
1.1 fvdl 1165:
1166: /* Restore the idle context. */
1167: cli
1168:
1169: /* Restore stack pointers. */
1170: movl PCB_ESP(%esi),%esp
1171: movl PCB_EBP(%esi),%ebp
1172:
1.26 yamt 1173: /* Switch TSS. Reset "task busy" flag before loading. */
1174: movl %cr3,%eax
1175: movl %eax,PCB_CR3(%esi)
1.1 fvdl 1176: #ifdef MULTIPROCESSOR
1177: movl CPUVAR(GDT),%eax
1.30 junyoung 1178: #else
1.1 fvdl 1179: /* Load TSS info. */
1180: movl _C_LABEL(gdt),%eax
1181: #endif
1182:
1183: andl $~0x0200,4-SEL_KPL(%eax,%edx,1)
1184: ltr %dx
1185:
1186: /* We're always in the kernel, so we don't need the LDT. */
1187:
1188: /* Restore cr0 (including FPU state). */
1189: movl PCB_CR0(%esi),%ecx
1190: movl %ecx,%cr0
1191:
1192: /* Record new pcb. */
1193: SET_CURPCB(%esi)
1194:
1195: /* Interrupts are okay again. */
1196: sti
1197:
1198: /*
1.21 jdolecek 1199: * Schedule the dead LWP's stack to be freed.
1.1 fvdl 1200: */
1.21 jdolecek 1201: pushl %edi
1202: call _C_LABEL(lwp_exit2)
1.1 fvdl 1203: addl $4,%esp
1204:
1205: /* Jump into cpu_switch() with the right state. */
1206: xorl %esi,%esi
1.5 thorpej 1207: movl %esi,CPUVAR(CURLWP)
1.1 fvdl 1208: jmp idle_start
1209:
1210: /*
1211: * void savectx(struct pcb *pcb);
1212: * Update pcb, saving current processor state.
1213: */
1214: /* LINTSTUB: Func: void savectx(struct pcb *pcb) */
1215: ENTRY(savectx)
1216: movl 4(%esp),%edx # edx = p->p_addr
1.30 junyoung 1217:
1.1 fvdl 1218: /* Save stack pointers. */
1219: movl %esp,PCB_ESP(%edx)
1220: movl %ebp,PCB_EBP(%edx)
1221:
1222: ret
1223:
1224: /*
1225: * Old call gate entry for syscall
1226: */
1227: /* LINTSTUB: Var: char Xosyscall[1]; */
1228: IDTVEC(osyscall)
1229: /* Set eflags in trap frame. */
1230: pushfl
1231: popl 8(%esp)
1232: pushl $7 # size of instruction for restart
1233: jmp syscall1
1234:
1235: /*
1236: * Trap gate entry for syscall
1237: */
1238: /* LINTSTUB: Var: char Xsyscall[1]; */
1239: IDTVEC(syscall)
1240: pushl $2 # size of instruction for restart
1241: syscall1:
1242: pushl $T_ASTFLT # trap # for doing ASTs
1243: INTRENTRY
1244:
1245: #ifdef DIAGNOSTIC
1.24 yamt 1246: cmpl $0, CPUVAR(WANT_PMAPLOAD)
1247: jz 1f
1248: pushl $6f
1249: call _C_LABEL(printf)
1250: addl $4, %esp
1251: 1:
1.1 fvdl 1252: movl CPUVAR(ILEVEL),%ebx
1253: testl %ebx,%ebx
1254: jz 1f
1255: pushl $5f
1256: call _C_LABEL(printf)
1257: addl $4,%esp
1258: #ifdef DDB
1259: int $3
1260: #endif
1.30 junyoung 1261: 1:
1.1 fvdl 1262: #endif /* DIAGNOSTIC */
1.5 thorpej 1263: movl CPUVAR(CURLWP),%edx
1264: movl %esp,L_MD_REGS(%edx) # save pointer to frame
1265: movl L_PROC(%edx),%edx
1.15 fvdl 1266: pushl %esp
1.1 fvdl 1267: call *P_MD_SYSCALL(%edx) # get pointer to syscall() function
1.15 fvdl 1268: addl $4,%esp
1.27 yamt 1269: .Lsyscall_checkast:
1.24 yamt 1270: /* Check for ASTs on exit to user mode. */
1.1 fvdl 1271: cli
1.5 thorpej 1272: CHECK_ASTPENDING(%eax)
1.1 fvdl 1273: je 1f
1274: /* Always returning to user mode here. */
1.5 thorpej 1275: CLEAR_ASTPENDING(%eax)
1.1 fvdl 1276: sti
1277: /* Pushed T_ASTFLT into tf_trapno on entry. */
1.15 fvdl 1278: pushl %esp
1.1 fvdl 1279: call _C_LABEL(trap)
1.15 fvdl 1280: addl $4,%esp
1.27 yamt 1281: jmp .Lsyscall_checkast /* re-check ASTs */
1.24 yamt 1282: 1: CHECK_DEFERRED_SWITCH(%eax)
1283: jnz 9f
1.1 fvdl 1284: #ifndef DIAGNOSTIC
1.24 yamt 1285: INTRFASTEXIT
1.1 fvdl 1286: #else /* DIAGNOSTIC */
1.24 yamt 1287: cmpl $IPL_NONE,CPUVAR(ILEVEL)
1.1 fvdl 1288: jne 3f
1289: INTRFASTEXIT
1290: 3: sti
1291: pushl $4f
1292: call _C_LABEL(printf)
1293: addl $4,%esp
1294: #ifdef DDB
1295: int $3
1296: #endif /* DDB */
1297: movl $IPL_NONE,CPUVAR(ILEVEL)
1298: jmp 2b
1299: 4: .asciz "WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
1.30 junyoung 1300: 5: .asciz "WARNING: SPL NOT ZERO ON SYSCALL ENTRY\n"
1301: 6: .asciz "WARNING: WANT PMAPLOAD ON SYSCALL ENTRY\n"
1.1 fvdl 1302: #endif /* DIAGNOSTIC */
1.24 yamt 1303: 9: sti
1304: call _C_LABEL(pmap_load)
1.27 yamt 1305: jmp .Lsyscall_checkast /* re-check ASTs */
1.1 fvdl 1306:
1307: #if NNPX > 0
1308: /*
1309: * Special interrupt handlers. Someday intr0-intr15 will be used to count
1310: * interrupts. We'll still need a special exception 16 handler. The busy
1311: * latch stuff in probintr() can be moved to npxprobe().
1312: */
1313:
1314: /* LINTSTUB: Func: void probeintr(void) */
1315: NENTRY(probeintr)
1316: ss
1317: incl _C_LABEL(npx_intrs_while_probing)
1318: pushl %eax
1319: movb $0x20,%al # EOI (asm in strings loses cpp features)
1320: outb %al,$0xa0 # IO_ICU2
1321: outb %al,$0x20 # IO_ICU1
1322: movb $0,%al
1323: outb %al,$0xf0 # clear BUSY# latch
1324: popl %eax
1325: iret
1326:
1327: /* LINTSTUB: Func: void probetrap(void) */
1328: NENTRY(probetrap)
1329: ss
1330: incl _C_LABEL(npx_traps_while_probing)
1331: fnclex
1332: iret
1333:
1334: /* LINTSTUB: Func: int npx586bug1(int a, int b) */
1335: NENTRY(npx586bug1)
1336: fildl 4(%esp) # x
1337: fildl 8(%esp) # y
1338: fld %st(1)
1339: fdiv %st(1),%st # x/y
1340: fmulp %st,%st(1) # (x/y)*y
1341: fsubrp %st,%st(1) # x-(x/y)*y
1342: pushl $0
1343: fistpl (%esp)
1344: popl %eax
1345: ret
1346: #endif /* NNPX > 0 */
CVSweb <webmaster@jp.NetBSD.org>