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