locore.s revision 48005
14Srgrimes/*-
24Srgrimes * Copyright (c) 1990 The Regents of the University of California.
34Srgrimes * All rights reserved.
44Srgrimes *
54Srgrimes * This code is derived from software contributed to Berkeley by
64Srgrimes * William Jolitz.
74Srgrimes *
84Srgrimes * Redistribution and use in source and binary forms, with or without
94Srgrimes * modification, are permitted provided that the following conditions
104Srgrimes * are met:
114Srgrimes * 1. Redistributions of source code must retain the above copyright
124Srgrimes *    notice, this list of conditions and the following disclaimer.
134Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
144Srgrimes *    notice, this list of conditions and the following disclaimer in the
154Srgrimes *    documentation and/or other materials provided with the distribution.
164Srgrimes * 3. All advertising materials mentioning features or use of this software
174Srgrimes *    must display the following acknowledgement:
184Srgrimes *	This product includes software developed by the University of
194Srgrimes *	California, Berkeley and its contributors.
204Srgrimes * 4. Neither the name of the University nor the names of its contributors
214Srgrimes *    may be used to endorse or promote products derived from this software
224Srgrimes *    without specific prior written permission.
234Srgrimes *
244Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
254Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
264Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
274Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
284Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
294Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
304Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
314Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
324Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
334Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
344Srgrimes * SUCH DAMAGE.
354Srgrimes *
36556Srgrimes *	from: @(#)locore.s	7.3 (Berkeley) 5/13/91
3748005Sbde *	$Id: locore.s,v 1.123 1999/06/01 18:19:39 jlemon Exp $
3815392Sphk *
39757Sdg *		originally from: locore.s, by William F. Jolitz
40757Sdg *
41757Sdg *		Substantially rewritten by David Greenman, Rod Grimes,
4215392Sphk *			Bruce Evans, Wolfgang Solfrank, Poul-Henning Kamp
4315392Sphk *			and many others.
444Srgrimes */
454Srgrimes
4614835Sbde#include "apm.h"
4732358Seivind#include "opt_bootp.h"
4813228Swollman#include "opt_ddb.h"
4937272Sjmg#include "opt_nfsroot.h"
5018702Sjkh#include "opt_userconfig.h"
5114835Sbde
5214835Sbde#include <sys/syscall.h>
535908Sbde#include <sys/reboot.h>
544Srgrimes
5514835Sbde#include <machine/asmacros.h>
5614835Sbde#include <machine/cputypes.h>
5714835Sbde#include <machine/psl.h>
5815543Sphk#include <machine/pmap.h>
5914835Sbde#include <machine/specialreg.h>
6014835Sbde
6114835Sbde#include "assym.s"
6214835Sbde
634Srgrimes/*
64757Sdg *	XXX
65757Sdg *
664Srgrimes * Note: This version greatly munged to avoid various assembler errors
674Srgrimes * that may be fixed in newer versions of gas. Perhaps newer versions
684Srgrimes * will have more pleasant appearance.
694Srgrimes */
704Srgrimes
71200Sdg/*
724Srgrimes * PTmap is recursive pagemap at top of virtual address space.
734Srgrimes * Within PTmap, the page directory can be found (third indirection).
744Srgrimes */
753861Sbde	.globl	_PTmap,_PTD,_PTDpde
7615543Sphk	.set	_PTmap,(PTDPTDI << PDRSHIFT)
7715543Sphk	.set	_PTD,_PTmap + (PTDPTDI * PAGE_SIZE)
78757Sdg	.set	_PTDpde,_PTD + (PTDPTDI * PDESIZE)
79592Srgrimes
803861Sbde/*
814Srgrimes * APTmap, APTD is the alternate recursive pagemap.
824Srgrimes * It's used when modifying another process's page tables.
834Srgrimes */
84592Srgrimes	.globl	_APTmap,_APTD,_APTDpde
85592Srgrimes	.set	_APTmap,APTDPTDI << PDRSHIFT
8615543Sphk	.set	_APTD,_APTmap + (APTDPTDI * PAGE_SIZE)
87757Sdg	.set	_APTDpde,_PTD + (APTDPTDI * PDESIZE)
884Srgrimes
894Srgrimes/*
90556Srgrimes * Globals
91556Srgrimes */
92556Srgrimes	.data
9314835Sbde	ALIGN_DATA		/* just to be sure */
94134Sdg
9525083Sjdp	.globl	HIDENAME(tmpstk)
9613729Sdg	.space	0x2000		/* space for tmpstk - temporary stack */
9725083SjdpHIDENAME(tmpstk):
983842Sdg
993861Sbde	.globl	_boothowto,_bootdev
100134Sdg
10115565Sphk	.globl	_cpu,_cpu_vendor,_cpu_id,_bootinfo
1026308Sphk	.globl	_cpu_high, _cpu_feature
1032783Ssos
10446129Sluoqi_cpu:		.long	0			/* are we 386, 386sx, or 486 */
1052216Sbde_cpu_id:	.long	0			/* stepping ID */
1066308Sphk_cpu_high:	.long	0			/* highest arg to CPUID */
1076308Sphk_cpu_feature:	.long	0			/* features */
1082216Sbde_cpu_vendor:	.space	20			/* CPU origin code */
1095908Sbde_bootinfo:	.space	BOOTINFO_SIZE		/* bootinfo that we can handle */
1104Srgrimes
111757Sdg_KERNend:	.long	0			/* phys addr end of kernel (just after bss) */
11215428Sphkphysfree:	.long	0			/* phys addr of next free page */
113757Sdg
11426812Speter#ifdef SMP
11546129Sluoqi		.globl	_cpu0prvpage
11625164Spetercpu0pp:		.long	0			/* phys addr cpu0 private pg */
11746129Sluoqi_cpu0prvpage:	.long	0			/* relocated version */
11825164Speter
11946129Sluoqi		.globl	_SMPpt
12046129SluoqiSMPptpa:	.long	0			/* phys addr SMP page table */
12146129Sluoqi_SMPpt:		.long	0			/* relocated version */
12226812Speter#endif /* SMP */
12325164Speter
1243861Sbde	.globl	_IdlePTD
125757Sdg_IdlePTD:	.long	0			/* phys addr of kernel PTD */
1263861Sbde
12726812Speter#ifdef SMP
12826812Speter	.globl	_KPTphys
12926812Speter#endif
130757Sdg_KPTphys:	.long	0			/* phys addr of kernel page tables */
1314Srgrimes
132757Sdg	.globl	_proc0paddr
133757Sdg_proc0paddr:	.long	0			/* address of proc 0 address space */
13424693Speterp0upa:		.long	0			/* phys addr of proc0's UPAGES */
135134Sdg
13637889Sjlemonvm86phystk:	.long	0			/* PA of vm86/bios stack */
13737889Sjlemon
13834840Sjlemon	.globl	_vm86paddr, _vm86pa
13934840Sjlemon_vm86paddr:	.long	0			/* address of vm86 region */
14034840Sjlemon_vm86pa:	.long	0			/* phys addr of vm86 region */
14134840Sjlemon
14215428Sphk#ifdef BDE_DEBUGGER
14315428Sphk	.globl	_bdb_exists			/* flag to indicate BDE debugger is present */
14415428Sphk_bdb_exists:	.long	0
14515428Sphk#endif
146718Swollman
14743434Skato#ifdef PC98
14843434Skato	.globl	_pc98_system_parameter
14943434Skato_pc98_system_parameter:
15043434Skato	.space	0x240
15143434Skato#endif
15215428Sphk
15315392Sphk/**********************************************************************
15415392Sphk *
15515392Sphk * Some handy macros
15615392Sphk *
157556Srgrimes */
158134Sdg
15915392Sphk#define R(foo) ((foo)-KERNBASE)
16015392Sphk
16115392Sphk#define ALLOCPAGES(foo) \
16215392Sphk	movl	R(physfree), %esi ; \
16315543Sphk	movl	$((foo)*PAGE_SIZE), %eax ; \
16415392Sphk	addl	%esi, %eax ; \
16515392Sphk	movl	%eax, R(physfree) ; \
16615392Sphk	movl	%esi, %edi ; \
16715543Sphk	movl	$((foo)*PAGE_SIZE),%ecx ; \
16815392Sphk	xorl	%eax,%eax ; \
16915428Sphk	cld ; \
17015428Sphk	rep ; \
17115428Sphk	stosb
17215392Sphk
173134Sdg/*
17415392Sphk * fillkpt
17515565Sphk *	eax = page frame address
17615565Sphk *	ebx = index into page table
17715392Sphk *	ecx = how many pages to map
17815565Sphk * 	base = base address of page dir/table
17915565Sphk *	prot = protection bits
180134Sdg */
18115565Sphk#define	fillkpt(base, prot)		  \
18219621Sdyson	shll	$2,%ebx			; \
18319621Sdyson	addl	base,%ebx		; \
18419621Sdyson	orl	$PG_V,%eax		; \
18519621Sdyson	orl	prot,%eax		; \
18615565Sphk1:	movl	%eax,(%ebx)		; \
18715565Sphk	addl	$PAGE_SIZE,%eax		; /* increment physical address */ \
18815565Sphk	addl	$4,%ebx			; /* next pte */ \
18915428Sphk	loop	1b
19015392Sphk
19115565Sphk/*
19215565Sphk * fillkptphys(prot)
19315565Sphk *	eax = physical address
19415565Sphk *	ecx = how many pages to map
19515565Sphk *	prot = protection bits
19615565Sphk */
19715565Sphk#define	fillkptphys(prot)		  \
19815565Sphk	movl	%eax, %ebx		; \
19915565Sphk	shrl	$PAGE_SHIFT, %ebx	; \
20015565Sphk	fillkpt(R(_KPTphys), prot)
20115565Sphk
20215392Sphk	.text
20315392Sphk/**********************************************************************
20415392Sphk *
20515392Sphk * This is where the bootblocks start us, set the ball rolling...
20615392Sphk *
20715392Sphk */
2081321SdgNON_GPROF_ENTRY(btext)
2094Srgrimes
21024112Skato#ifdef PC98
21124112Skato	/* save SYSTEM PARAMETER for resume (NS/T or other) */
21243434Skato	movl	$0xa1400,%esi
21343434Skato	movl	$R(_pc98_system_parameter),%edi
21443434Skato	movl	$0x0240,%ecx
21524112Skato	cld
21624112Skato	rep
21724112Skato	movsb
21824112Skato#else	/* IBM-PC */
21915428Sphk#ifdef BDE_DEBUGGER
22015428Sphk#ifdef BIOS_STEALS_3K
22115428Sphk	cmpl	$0x0375c339,0x95504
22215428Sphk#else
22315428Sphk	cmpl	$0x0375c339,0x96104	/* XXX - debugger signature */
22415428Sphk#endif
22515428Sphk	jne	1f
22615428Sphk	movb	$1,R(_bdb_exists)
22715428Sphk1:
22815428Sphk#endif
22940179Skato#endif	/* PC98 */
23015428Sphk
23115392Sphk/* Tell the bios to warmboot next time */
23215392Sphk	movw	$0x1234,0x472
23315392Sphk
23415428Sphk/* Set up a real frame in case the double return in newboot is executed. */
2353384Srgrimes	pushl	%ebp
2363384Srgrimes	movl	%esp, %ebp
2373384Srgrimes
23815392Sphk/* Don't trust what the BIOS gives for eflags. */
2395603Sbde	pushl	$PSL_KERNEL
2402486Sdg	popfl
24115428Sphk
24215428Sphk/*
24315428Sphk * Don't trust what the BIOS gives for %fs and %gs.  Trust the bootstrap
24415428Sphk * to set %cs, %ds, %es and %ss.
24515428Sphk */
24615428Sphk	mov	%ds, %ax
2474217Sphk	mov	%ax, %fs
2484217Sphk	mov	%ax, %gs
2494217Sphk
25015392Sphk	call	recover_bootinfo
25115392Sphk
25215428Sphk/* Get onto a stack that we can trust. */
25315428Sphk/*
25415428Sphk * XXX this step is delayed in case recover_bootinfo needs to return via
25515428Sphk * the old stack, but it need not be, since recover_bootinfo actually
25615428Sphk * returns via the old frame.
25715428Sphk */
25825083Sjdp	movl	$R(HIDENAME(tmpstk)),%esp
25915392Sphk
26024112Skato#ifdef PC98
26143447Skato	/* pc98_machine_type & M_EPSON_PC98 */
26243447Skato	testb	$0x02,R(_pc98_system_parameter)+220
26324112Skato	jz	3f
26443447Skato	/* epson_machine_id <= 0x0b */
26543447Skato	cmpb	$0x0b,R(_pc98_system_parameter)+224
26624112Skato	ja	3f
26724112Skato
26824112Skato	/* count up memory */
26924112Skato	movl	$0x100000,%eax		/* next, talley remaining memory */
27024112Skato	movl	$0xFFF-0x100,%ecx
27124112Skato1:	movl	0(%eax),%ebx		/* save location to check */
27224112Skato	movl	$0xa55a5aa5,0(%eax)	/* write test pattern */
27324112Skato	cmpl	$0xa55a5aa5,0(%eax)	/* does not check yet for rollover */
27424112Skato	jne	2f
27524112Skato	movl	%ebx,0(%eax)		/* restore memory */
27624112Skato	addl	$PAGE_SIZE,%eax
27724112Skato	loop	1b
27824112Skato2:	subl	$0x100000,%eax
27924112Skato	shrl	$17,%eax
28043447Skato	movb	%al,R(_pc98_system_parameter)+1
28124112Skato3:
28224112Skato#endif
28324112Skato
28415392Sphk	call	identify_cpu
28515392Sphk
28615392Sphk/* clear bss */
28715428Sphk/*
28817120Sbde * XXX this should be done a little earlier.
28915428Sphk *
29017120Sbde * XXX we don't check that there is memory for our bss and page tables
29117120Sbde * before using it.
29215428Sphk *
29315428Sphk * XXX the boot program somewhat bogusly clears the bss.  We still have
29415428Sphk * to do it in case we were unzipped by kzipboot.  Then the boot program
29515428Sphk * only clears kzipboot's bss.
29615428Sphk *
29715428Sphk * XXX the gdt and idt are still somewhere in the boot program.  We
29815428Sphk * depend on the convention that the boot program is below 1MB and we
29915428Sphk * are above 1MB to keep the gdt and idt  away from the bss and page
30017120Sbde * tables.  The idt is only used if BDE_DEBUGGER is enabled.
30115428Sphk */
30215392Sphk	movl	$R(_end),%ecx
30315392Sphk	movl	$R(_edata),%edi
30415392Sphk	subl	%edi,%ecx
30515392Sphk	xorl	%eax,%eax
30615428Sphk	cld
30715428Sphk	rep
30815428Sphk	stosb
30915392Sphk
31015392Sphk#if NAPM > 0
31115428Sphk#endif
31215392Sphk
31315392Sphk	call	create_pagetables
31415392Sphk
31527993Sdyson/*
31627993Sdyson * If the CPU has support for VME, turn it on.
31727993Sdyson */
31827993Sdyson	testl	$CPUID_VME, R(_cpu_feature)
31927993Sdyson	jz	1f
32027993Sdyson	movl	%cr4, %eax
32127993Sdyson	orl	$CR4_VME, %eax
32227993Sdyson	movl	%eax, %cr4
32327993Sdyson1:
32427993Sdyson
32515428Sphk#ifdef BDE_DEBUGGER
32615428Sphk/*
32715428Sphk * Adjust as much as possible for paging before enabling paging so that the
32815428Sphk * adjustments can be traced.
32915428Sphk */
33015428Sphk	call	bdb_prepare_paging
33115428Sphk#endif
33215428Sphk
33315392Sphk/* Now enable paging */
33415392Sphk	movl	R(_IdlePTD), %eax
33515392Sphk	movl	%eax,%cr3			/* load ptd addr into mmu */
33615392Sphk	movl	%cr0,%eax			/* get control word */
33715392Sphk	orl	$CR0_PE|CR0_PG,%eax		/* enable paging */
33815392Sphk	movl	%eax,%cr0			/* and let's page NOW! */
33915392Sphk
34015428Sphk#ifdef BDE_DEBUGGER
34115428Sphk/*
34215428Sphk * Complete the adjustments for paging so that we can keep tracing through
34317120Sbde * initi386() after the low (physical) addresses for the gdt and idt become
34415428Sphk * invalid.
34515428Sphk */
34615428Sphk	call	bdb_commit_paging
34715428Sphk#endif
34815428Sphk
34915428Sphk	pushl	$begin				/* jump to high virtualized address */
35015392Sphk	ret
35115392Sphk
35215392Sphk/* now running relocated at KERNBASE where the system is linked to run */
35315392Sphkbegin:
35415392Sphk	/* set up bootstrap stack */
35524691Speter	movl	_proc0paddr,%esp	/* location of in-kernel pages */
35624691Speter	addl	$UPAGES*PAGE_SIZE,%esp	/* bootstrap stack end location */
35715392Sphk	xorl	%eax,%eax			/* mark end of frames */
35815392Sphk	movl	%eax,%ebp
35915392Sphk	movl	_proc0paddr,%eax
36015392Sphk	movl	_IdlePTD, %esi
36115392Sphk	movl	%esi,PCB_CR3(%eax)
36215392Sphk
36315392Sphk	movl	physfree, %esi
36415392Sphk	pushl	%esi				/* value of first for init386(first) */
36515392Sphk	call	_init386			/* wire 386 chip for unix operation */
36615392Sphk	popl	%esi
36715392Sphk
36815392Sphk	.globl	__ucodesel,__udatasel
36915392Sphk
37015392Sphk	pushl	$0				/* unused */
37115392Sphk	pushl	__udatasel			/* ss */
37215392Sphk	pushl	$0				/* esp - filled in by execve() */
37315392Sphk	pushl	$PSL_USER			/* eflags (IOPL 0, int enab) */
37415392Sphk	pushl	__ucodesel			/* cs */
37515392Sphk	pushl	$0				/* eip - filled in by execve() */
37646129Sluoqi	subl	$(13*4),%esp			/* space for rest of registers */
37715392Sphk
37815392Sphk	pushl	%esp				/* call main with frame pointer */
37946823Speter	call	_mi_startup			/* autoconfiguration, mountroot etc */
38015392Sphk
38124691Speter	hlt		/* never returns to here */
38215392Sphk
38324691Speter/*
38424691Speter * When starting init, call this to configure the process for user
38524691Speter * mode.  This will be inherited by other processes.
38624691Speter */
38724691SpeterNON_GPROF_ENTRY(prepare_usermode)
38815392Sphk	/*
38924112Skato	 * Now we've run main() and determined what cpu-type we are, we can
39015392Sphk	 * enable write protection and alignment checking on i486 cpus and
39115392Sphk	 * above.
39215392Sphk	 */
39315392Sphk#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
39415392Sphk	cmpl    $CPUCLASS_386,_cpu_class
39515392Sphk	je	1f
39615392Sphk	movl	%cr0,%eax			/* get control word */
39715392Sphk	orl	$CR0_WP|CR0_AM,%eax		/* enable i486 features */
39815392Sphk	movl	%eax,%cr0			/* and do it */
39915428Sphk1:
40015392Sphk#endif
40115392Sphk	/*
40215392Sphk	 * on return from main(), we are process 1
40315392Sphk	 * set up address space and stack so that we can 'return' to user mode
40415392Sphk	 */
40515392Sphk	movl	__ucodesel,%eax
40615392Sphk	movl	__udatasel,%ecx
40715392Sphk
40846129Sluoqi#if 0	/* ds/es/fs are in trap frame */
40915392Sphk	movl	%cx,%ds
41046129Sluoqi	movl	%cx,%es
41146129Sluoqi	movl	%cx,%fs
41224691Speter#endif
41315392Sphk	movl	%cx,%gs				/* and ds to gs */
41424691Speter	ret					/* goto user! */
41515392Sphk
41624691Speter
41715392Sphk#define LCALL(x,y)	.byte 0x9a ; .long y ; .word x
41815392Sphk
41915392Sphk/*
42015392Sphk * Signal trampoline, copied to top of user stack
42115392Sphk */
42215392SphkNON_GPROF_ENTRY(sigcode)
42315392Sphk	call	SIGF_HANDLER(%esp)
42415392Sphk	lea	SIGF_SC(%esp),%eax		/* scp (the call may have clobbered the */
42515392Sphk						/* copy at 8(%esp)) */
42615392Sphk	pushl	%eax
42715392Sphk	pushl	%eax				/* junk to fake return address */
42815392Sphk	movl	$SYS_sigreturn,%eax		/* sigreturn() */
42915392Sphk	LCALL(0x7,0)				/* enter kernel with args on stack */
43015392Sphk	hlt					/* never gets here */
43125083Sjdp	ALIGN_TEXT
43215392Sphk_esigcode:
43315392Sphk
43415392Sphk	.data
43515392Sphk	.globl	_szsigcode
43615392Sphk_szsigcode:
43715392Sphk	.long	_esigcode-_sigcode
43815428Sphk	.text
43915392Sphk
44015392Sphk/**********************************************************************
44115392Sphk *
44215392Sphk * Recover the bootinfo passed to us from the boot program
44315392Sphk *
44415392Sphk */
44515392Sphkrecover_bootinfo:
44615392Sphk	/*
4473284Srgrimes	 * This code is called in different ways depending on what loaded
4483284Srgrimes	 * and started the kernel.  This is used to detect how we get the
4493284Srgrimes	 * arguments from the other code and what we do with them.
4503284Srgrimes	 *
4513284Srgrimes	 * Old disk boot blocks:
4523284Srgrimes	 *	(*btext)(howto, bootdev, cyloffset, esym);
4533284Srgrimes	 *	[return address == 0, and can NOT be returned to]
4543284Srgrimes	 *	[cyloffset was not supported by the FreeBSD boot code
4553284Srgrimes	 *	 and always passed in as 0]
4563284Srgrimes	 *	[esym is also known as total in the boot code, and
4573284Srgrimes	 *	 was never properly supported by the FreeBSD boot code]
4583284Srgrimes	 *
4593284Srgrimes	 * Old diskless netboot code:
4603284Srgrimes	 *	(*btext)(0,0,0,0,&nfsdiskless,0,0,0);
4613284Srgrimes	 *	[return address != 0, and can NOT be returned to]
4623284Srgrimes	 *	If we are being booted by this code it will NOT work,
4633284Srgrimes	 *	so we are just going to halt if we find this case.
4643284Srgrimes	 *
4653284Srgrimes	 * New uniform boot code:
4663284Srgrimes	 *	(*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
4673284Srgrimes	 *	[return address != 0, and can be returned to]
4683284Srgrimes	 *
4693284Srgrimes	 * There may seem to be a lot of wasted arguments in here, but
4703384Srgrimes	 * that is so the newer boot code can still load very old kernels
4713384Srgrimes	 * and old boot code can load new kernels.
4724Srgrimes	 */
4733284Srgrimes
4743284Srgrimes	/*
4753284Srgrimes	 * The old style disk boot blocks fake a frame on the stack and
4763284Srgrimes	 * did an lret to get here.  The frame on the stack has a return
4773284Srgrimes	 * address of 0.
4783284Srgrimes	 */
4793384Srgrimes	cmpl	$0,4(%ebp)
48015392Sphk	je	olddiskboot
4813284Srgrimes
4823284Srgrimes	/*
4833284Srgrimes	 * We have some form of return address, so this is either the
4843284Srgrimes	 * old diskless netboot code, or the new uniform code.  That can
48515428Sphk	 * be detected by looking at the 5th argument, if it is 0
48615428Sphk	 * we are being booted by the new uniform boot code.
4873284Srgrimes	 */
4883384Srgrimes	cmpl	$0,24(%ebp)
48915392Sphk	je	newboot
4903284Srgrimes
4913284Srgrimes	/*
4923284Srgrimes	 * Seems we have been loaded by the old diskless boot code, we
4933284Srgrimes	 * don't stand a chance of running as the diskless structure
4943284Srgrimes	 * changed considerably between the two, so just halt.
4953284Srgrimes	 */
4963284Srgrimes	 hlt
4973284Srgrimes
4983284Srgrimes	/*
4993384Srgrimes	 * We have been loaded by the new uniform boot code.
50015428Sphk	 * Let's check the bootinfo version, and if we do not understand
5013384Srgrimes	 * it we return to the loader with a status of 1 to indicate this error
5023284Srgrimes	 */
50315392Sphknewboot:
5043384Srgrimes	movl	28(%ebp),%ebx		/* &bootinfo.version */
5055908Sbde	movl	BI_VERSION(%ebx),%eax
5063384Srgrimes	cmpl	$1,%eax			/* We only understand version 1 */
5073384Srgrimes	je	1f
5083384Srgrimes	movl	$1,%eax			/* Return status */
5093384Srgrimes	leave
51015428Sphk	/*
51115428Sphk	 * XXX this returns to our caller's caller (as is required) since
51215428Sphk	 * we didn't set up a frame and our caller did.
51315428Sphk	 */
5143384Srgrimes	ret
5153284Srgrimes
5163384Srgrimes1:
5173284Srgrimes	/*
5183384Srgrimes	 * If we have a kernelname copy it in
5193384Srgrimes	 */
5205908Sbde	movl	BI_KERNELNAME(%ebx),%esi
5213384Srgrimes	cmpl	$0,%esi
5229344Sdg	je	2f			/* No kernelname */
5239344Sdg	movl	$MAXPATHLEN,%ecx	/* Brute force!!! */
52415926Sphk	movl	$R(_kernelname),%edi
5259344Sdg	cmpb	$'/',(%esi)		/* Make sure it starts with a slash */
5269344Sdg	je	1f
5279344Sdg	movb	$'/',(%edi)
5289344Sdg	incl	%edi
5299344Sdg	decl	%ecx
5309344Sdg1:
5313384Srgrimes	cld
5323384Srgrimes	rep
5333384Srgrimes	movsb
5343384Srgrimes
5359344Sdg2:
53615428Sphk	/*
5375908Sbde	 * Determine the size of the boot loader's copy of the bootinfo
5385908Sbde	 * struct.  This is impossible to do properly because old versions
5395908Sbde	 * of the struct don't contain a size field and there are 2 old
5405908Sbde	 * versions with the same version number.
5414600Sphk	 */
5425908Sbde	movl	$BI_ENDCOMMON,%ecx	/* prepare for sizeless version */
5435908Sbde	testl	$RB_BOOTINFO,8(%ebp)	/* bi_size (and bootinfo) valid? */
5445908Sbde	je	got_bi_size		/* no, sizeless version */
5455908Sbde	movl	BI_SIZE(%ebx),%ecx
5465908Sbdegot_bi_size:
5475908Sbde
54815428Sphk	/*
5495908Sbde	 * Copy the common part of the bootinfo struct
5505908Sbde	 */
5514600Sphk	movl	%ebx,%esi
55215926Sphk	movl	$R(_bootinfo),%edi
5535908Sbde	cmpl	$BOOTINFO_SIZE,%ecx
5545908Sbde	jbe	got_common_bi_size
5554600Sphk	movl	$BOOTINFO_SIZE,%ecx
5565908Sbdegot_common_bi_size:
5574600Sphk	cld
5584600Sphk	rep
5594600Sphk	movsb
5604600Sphk
56138063Smsmith#ifdef NFS_ROOT
56225837Stegge#ifndef BOOTP_NFSV3
5633384Srgrimes	/*
5643384Srgrimes	 * If we have a nfs_diskless structure copy it in
5653384Srgrimes	 */
5665908Sbde	movl	BI_NFS_DISKLESS(%ebx),%esi
5673384Srgrimes	cmpl	$0,%esi
56815428Sphk	je	olddiskboot
56915926Sphk	movl	$R(_nfs_diskless),%edi
5703384Srgrimes	movl	$NFSDISKLESS_SIZE,%ecx
5713384Srgrimes	cld
5723384Srgrimes	rep
5733384Srgrimes	movsb
57415926Sphk	movl	$R(_nfs_diskless_valid),%edi
5753795Sphk	movl	$1,(%edi)
5763406Sdg#endif
57725837Stegge#endif
5783384Srgrimes
5793384Srgrimes	/*
5803284Srgrimes	 * The old style disk boot.
5813284Srgrimes	 *	(*btext)(howto, bootdev, cyloffset, esym);
5823384Srgrimes	 * Note that the newer boot code just falls into here to pick
5833384Srgrimes	 * up howto and bootdev, cyloffset and esym are no longer used
5843284Srgrimes	 */
58515392Sphkolddiskboot:
5863384Srgrimes	movl	8(%ebp),%eax
58715926Sphk	movl	%eax,R(_boothowto)
5883384Srgrimes	movl	12(%ebp),%eax
58915926Sphk	movl	%eax,R(_bootdev)
5902783Ssos
59115392Sphk	ret
5923258Sdg
5931321Sdg
59415392Sphk/**********************************************************************
59515392Sphk *
59615392Sphk * Identify the CPU and initialize anything special about it
59715392Sphk *
59815392Sphk */
59915392Sphkidentify_cpu:
60015392Sphk
6011998Swollman	/* Try to toggle alignment check flag; does not exist on 386. */
6021998Swollman	pushfl
6031998Swollman	popl	%eax
6041998Swollman	movl	%eax,%ecx
6051998Swollman	orl	$PSL_AC,%eax
6061998Swollman	pushl	%eax
6071998Swollman	popfl
6081998Swollman	pushfl
6091998Swollman	popl	%eax
6101998Swollman	xorl	%ecx,%eax
6111998Swollman	andl	$PSL_AC,%eax
6121998Swollman	pushl	%ecx
6131998Swollman	popfl
6141998Swollman
6151998Swollman	testl	%eax,%eax
61624112Skato	jnz	try486
61724112Skato
61824112Skato	/* NexGen CPU does not have aligment check flag. */
61924112Skato	pushfl
62024112Skato	movl	$0x5555, %eax
62124112Skato	xorl	%edx, %edx
62224112Skato	movl	$2, %ecx
62324112Skato	clc
62424112Skato	divl	%ecx
62524112Skato	jz	trynexgen
62624112Skato	popfl
62715926Sphk	movl	$CPU_386,R(_cpu)
62813081Sdg	jmp	3f
6291998Swollman
63024112Skatotrynexgen:
63127424Skato	popfl
63224112Skato	movl	$CPU_NX586,R(_cpu)
63324112Skato	movl	$0x4778654e,R(_cpu_vendor)	# store vendor string
63424112Skato	movl	$0x72446e65,R(_cpu_vendor+4)
63524112Skato	movl	$0x6e657669,R(_cpu_vendor+8)
63624112Skato	movl	$0,R(_cpu_vendor+12)
63724112Skato	jmp	3f
63824112Skato
63924112Skatotry486:	/* Try to toggle identification flag; does not exist on early 486s. */
6401998Swollman	pushfl
6411998Swollman	popl	%eax
6421998Swollman	movl	%eax,%ecx
6431998Swollman	xorl	$PSL_ID,%eax
6441998Swollman	pushl	%eax
6451998Swollman	popfl
6461998Swollman	pushfl
6471998Swollman	popl	%eax
6481998Swollman	xorl	%ecx,%eax
6491998Swollman	andl	$PSL_ID,%eax
6501998Swollman	pushl	%ecx
6511998Swollman	popfl
6521998Swollman
6531998Swollman	testl	%eax,%eax
65424112Skato	jnz	trycpuid
65515926Sphk	movl	$CPU_486,R(_cpu)
6562495Spst
65724112Skato	/*
65824112Skato	 * Check Cyrix CPU
65924112Skato	 * Cyrix CPUs do not change the undefined flags following
66024112Skato	 * execution of the divide instruction which divides 5 by 2.
66124112Skato	 *
66224112Skato	 * Note: CPUID is enabled on M2, so it passes another way.
66324112Skato	 */
66424112Skato	pushfl
66524112Skato	movl	$0x5555, %eax
66624112Skato	xorl	%edx, %edx
66724112Skato	movl	$2, %ecx
66824112Skato	clc
66924112Skato	divl	%ecx
67024112Skato	jnc	trycyrix
67124112Skato	popfl
67224112Skato	jmp	3f		/* You may use Intel CPU. */
6732495Spst
67424112Skatotrycyrix:
67524112Skato	popfl
67624112Skato	/*
67724112Skato	 * IBM Bluelighting CPU also doesn't change the undefined flags.
67824112Skato	 * Because IBM doesn't disclose the information for Bluelighting
67924112Skato	 * CPU, we couldn't distinguish it from Cyrix's (including IBM
68024112Skato	 * brand of Cyrix CPUs).
68124112Skato	 */
68215926Sphk	movl	$0x69727943,R(_cpu_vendor)	# store vendor string
68324112Skato	movl	$0x736e4978,R(_cpu_vendor+4)
68424112Skato	movl	$0x64616574,R(_cpu_vendor+8)
68513014Sdg	jmp	3f
6861998Swollman
68724112Skatotrycpuid:	/* Use the `cpuid' instruction. */
6881998Swollman	xorl	%eax,%eax
6896308Sphk	.byte	0x0f,0xa2			# cpuid 0
69015926Sphk	movl	%eax,R(_cpu_high)		# highest capability
69115926Sphk	movl	%ebx,R(_cpu_vendor)		# store vendor string
69215926Sphk	movl	%edx,R(_cpu_vendor+4)
69315926Sphk	movl	%ecx,R(_cpu_vendor+8)
69415926Sphk	movb	$0,R(_cpu_vendor+12)
6951998Swollman
6961998Swollman	movl	$1,%eax
6976308Sphk	.byte	0x0f,0xa2			# cpuid 1
69815926Sphk	movl	%eax,R(_cpu_id)			# store cpu_id
69915926Sphk	movl	%edx,R(_cpu_feature)		# store cpu_feature
7006308Sphk	rorl	$8,%eax				# extract family type
7011998Swollman	andl	$15,%eax
7021998Swollman	cmpl	$5,%eax
7031998Swollman	jae	1f
7041998Swollman
7051998Swollman	/* less than Pentium; must be 486 */
70615926Sphk	movl	$CPU_486,R(_cpu)
70713000Sdg	jmp	3f
70813000Sdg1:
70913000Sdg	/* a Pentium? */
71013000Sdg	cmpl	$5,%eax
71113000Sdg	jne	2f
71215926Sphk	movl	$CPU_586,R(_cpu)
71313000Sdg	jmp	3f
714556Srgrimes2:
71513000Sdg	/* Greater than Pentium...call it a Pentium Pro */
71615926Sphk	movl	$CPU_686,R(_cpu)
71713000Sdg3:
71815392Sphk	ret
719556Srgrimes
7204Srgrimes
72115392Sphk/**********************************************************************
722570Srgrimes *
72315428Sphk * Create the first page directory and its page tables.
72415392Sphk *
725570Srgrimes */
726570Srgrimes
72715392Sphkcreate_pagetables:
72815392Sphk
72919621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
73019621Sdyson	jz	1f
73119621Sdyson	movl	%cr4, %eax
73219621Sdyson	orl	$CR4_PGE, %eax
73319621Sdyson	movl	%eax, %cr4
73419621Sdyson1:
73519621Sdyson
73615428Sphk/* Find end of kernel image (rounded up to a page boundary). */
73715392Sphk	movl	$R(_end),%esi
7384Srgrimes
73940081Smsmith/* include symbols if loaded and useful */
7405908Sbde#ifdef DDB
74115392Sphk	movl	R(_bootinfo+BI_ESYMTAB),%edi
7425908Sbde	testl	%edi,%edi
74315428Sphk	je	over_symalloc
7445908Sbde	movl	%edi,%esi
7455908Sbde	movl	$KERNBASE,%edi
74615392Sphk	addl	%edi,R(_bootinfo+BI_SYMTAB)
74715392Sphk	addl	%edi,R(_bootinfo+BI_ESYMTAB)
74815428Sphkover_symalloc:
7495908Sbde#endif
7505908Sbde
75140081Smsmith/* If we are told where the end of the kernel space is, believe it. */
75240081Smsmith	movl	R(_bootinfo+BI_KERNEND),%edi
75340081Smsmith	testl	%edi,%edi
75440081Smsmith	je	no_kernend
75540081Smsmith	movl	%edi,%esi
75640081Smsmithno_kernend:
75740081Smsmith
75815565Sphk	addl	$PAGE_MASK,%esi
75915565Sphk	andl	$~PAGE_MASK,%esi
76015392Sphk	movl	%esi,R(_KERNend)	/* save end of kernel */
76115428Sphk	movl	%esi,R(physfree)	/* next free page is at end of kernel */
762608Srgrimes
76315392Sphk/* Allocate Kernel Page Tables */
76415392Sphk	ALLOCPAGES(NKPT)
76515392Sphk	movl	%esi,R(_KPTphys)
766757Sdg
76715392Sphk/* Allocate Page Table Directory */
76815392Sphk	ALLOCPAGES(1)
76915392Sphk	movl	%esi,R(_IdlePTD)
7704Srgrimes
77115392Sphk/* Allocate UPAGES */
77215392Sphk	ALLOCPAGES(UPAGES)
77317120Sbde	movl	%esi,R(p0upa)
77415392Sphk	addl	$KERNBASE, %esi
77515392Sphk	movl	%esi, R(_proc0paddr)
7764Srgrimes
77737889Sjlemon	ALLOCPAGES(1)			/* vm86/bios stack */
77837889Sjlemon	movl	%esi,R(vm86phystk)
77937889Sjlemon
78037889Sjlemon	ALLOCPAGES(3)			/* pgtable + ext + IOPAGES */
78134840Sjlemon	movl	%esi,R(_vm86pa)
78234840Sjlemon	addl	$KERNBASE, %esi
78334840Sjlemon	movl	%esi, R(_vm86paddr)
78434840Sjlemon
78526812Speter#ifdef SMP
78625164Speter/* Allocate cpu0's private data page */
78725164Speter	ALLOCPAGES(1)
78825164Speter	movl	%esi,R(cpu0pp)
78925164Speter	addl	$KERNBASE, %esi
79025164Speter	movl	%esi, R(_cpu0prvpage)	/* relocated to KVM space */
79125164Speter
79246129Sluoqi/* Allocate SMP page table page */
79325164Speter	ALLOCPAGES(1)
79446129Sluoqi	movl	%esi,R(SMPptpa)
79525164Speter	addl	$KERNBASE, %esi
79646129Sluoqi	movl	%esi, R(_SMPpt)		/* relocated to KVM space */
79726812Speter#endif	/* SMP */
79825164Speter
79915392Sphk/* Map read-only from zero to the end of the kernel text section */
80015565Sphk	xorl	%eax, %eax
80115428Sphk#ifdef BDE_DEBUGGER
80215428Sphk/* If the debugger is present, actually map everything read-write. */
80315428Sphk	cmpl	$0,R(_bdb_exists)
80415428Sphk	jne	map_read_write
80515428Sphk#endif
80619621Sdyson	xorl	%edx,%edx
80727484Sdyson
80827484Sdyson#if !defined(SMP)
80919621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
81019621Sdyson	jz	2f
81119621Sdyson	orl	$PG_G,%edx
81227484Sdyson#endif
81319621Sdyson
81419621Sdyson2:	movl	$R(_etext),%ecx
81515565Sphk	addl	$PAGE_MASK,%ecx
81615565Sphk	shrl	$PAGE_SHIFT,%ecx
81719621Sdyson	fillkptphys(%edx)
818757Sdg
81915392Sphk/* Map read-write, data, bss and symbols */
82015565Sphk	movl	$R(_etext),%eax
82115694Sphk	addl	$PAGE_MASK, %eax
82215694Sphk	andl	$~PAGE_MASK, %eax
82315428Sphkmap_read_write:
82419621Sdyson	movl	$PG_RW,%edx
82527484Sdyson#if !defined(SMP)
82619621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
82719621Sdyson	jz	1f
82819621Sdyson	orl	$PG_G,%edx
82927484Sdyson#endif
83019621Sdyson
83119621Sdyson1:	movl	R(_KERNend),%ecx
832757Sdg	subl	%eax,%ecx
83315543Sphk	shrl	$PAGE_SHIFT,%ecx
83419621Sdyson	fillkptphys(%edx)
835757Sdg
83615428Sphk/* Map page directory. */
83715392Sphk	movl	R(_IdlePTD), %eax
83815392Sphk	movl	$1, %ecx
83919621Sdyson	fillkptphys($PG_RW)
840757Sdg
84117120Sbde/* Map proc0's UPAGES in the physical way ... */
84217120Sbde	movl	R(p0upa), %eax
84315392Sphk	movl	$UPAGES, %ecx
84419621Sdyson	fillkptphys($PG_RW)
8454Srgrimes
84615565Sphk/* Map ISA hole */
84715565Sphk	movl	$ISA_HOLE_START, %eax
84815565Sphk	movl	$ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
84922130Sdg	fillkptphys($PG_RW)
85015565Sphk
85134840Sjlemon/* Map space for the vm86 region */
85237889Sjlemon	movl	R(vm86phystk), %eax
85334840Sjlemon	movl	$4, %ecx
85434840Sjlemon	fillkptphys($PG_RW)
85534840Sjlemon
85634840Sjlemon/* Map page 0 into the vm86 page table */
85734840Sjlemon	movl	$0, %eax
85834840Sjlemon	movl	$0, %ebx
85934840Sjlemon	movl	$1, %ecx
86034840Sjlemon	fillkpt(R(_vm86pa), $PG_RW|PG_U)
86134840Sjlemon
86234840Sjlemon/* ...likewise for the ISA hole */
86334840Sjlemon	movl	$ISA_HOLE_START, %eax
86434840Sjlemon	movl	$ISA_HOLE_START>>PAGE_SHIFT, %ebx
86534840Sjlemon	movl	$ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
86634840Sjlemon	fillkpt(R(_vm86pa), $PG_RW|PG_U)
86734840Sjlemon
86826812Speter#ifdef SMP
86926812Speter/* Map cpu0's private page into global kmem (4K @ cpu0prvpage) */
87025164Speter	movl	R(cpu0pp), %eax
87125164Speter	movl	$1, %ecx
87225164Speter	fillkptphys($PG_RW)
87325164Speter
87446129Sluoqi/* Map SMP page table page into global kmem FWIW */
87546129Sluoqi	movl	R(SMPptpa), %eax
87625164Speter	movl	$1, %ecx
87725164Speter	fillkptphys($PG_RW)
87825164Speter
87946129Sluoqi/* Map the private page into the SMP page table */
88025164Speter	movl	R(cpu0pp), %eax
88125164Speter	movl	$0, %ebx		/* pte offset = 0 */
88225164Speter	movl	$1, %ecx		/* one private page coming right up */
88346129Sluoqi	fillkpt(R(SMPptpa), $PG_RW)
88425164Speter
88526812Speter/* ... and put the page table table in the pde. */
88646129Sluoqi	movl	R(SMPptpa), %eax
88725164Speter	movl	$MPPTDI, %ebx
88825164Speter	movl	$1, %ecx
88925164Speter	fillkpt(R(_IdlePTD), $PG_RW)
89034840Sjlemon
89134840Sjlemon/* Fakeup VA for the local apic to allow early traps. */
89234840Sjlemon	ALLOCPAGES(1)
89334840Sjlemon	movl	%esi, %eax
89446129Sluoqi	movl	$(NPTEPG-1), %ebx	/* pte offset = NTEPG-1 */
89534840Sjlemon	movl	$1, %ecx		/* one private pt coming right up */
89646129Sluoqi	fillkpt(R(SMPptpa), $PG_RW)
89734840Sjlemon
89834840Sjlemon/* Initialize mp lock to allow early traps */
89934840Sjlemon	movl	$1, R(_mp_lock)
90026812Speter#endif	/* SMP */
90125164Speter
90215392Sphk/* install a pde for temporary double map of bottom of VA */
90315392Sphk	movl	R(_KPTphys), %eax
90415565Sphk	xorl	%ebx, %ebx
90515565Sphk	movl	$1, %ecx
90619621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9074Srgrimes
90815392Sphk/* install pde's for pt's */
90915392Sphk	movl	R(_KPTphys), %eax
91015565Sphk	movl	$KPTDI, %ebx
91115565Sphk	movl	$NKPT, %ecx
91219621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9134Srgrimes
91415392Sphk/* install a pde recursively mapping page directory as a page table */
91515565Sphk	movl	R(_IdlePTD), %eax
91615565Sphk	movl	$PTDPTDI, %ebx
91715565Sphk	movl	$1,%ecx
91819621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9194Srgrimes
9204Srgrimes	ret
92115428Sphk
92215428Sphk#ifdef BDE_DEBUGGER
92315428Sphkbdb_prepare_paging:
92415428Sphk	cmpl	$0,R(_bdb_exists)
92515428Sphk	je	bdb_prepare_paging_exit
92615428Sphk
92715428Sphk	subl	$6,%esp
92815428Sphk
92915428Sphk	/*
93015428Sphk	 * Copy and convert debugger entries from the bootstrap gdt and idt
93115428Sphk	 * to the kernel gdt and idt.  Everything is still in low memory.
93215428Sphk	 * Tracing continues to work after paging is enabled because the
93315428Sphk	 * low memory addresses remain valid until everything is relocated.
93415428Sphk	 * However, tracing through the setidt() that initializes the trace
93515428Sphk	 * trap will crash.
93615428Sphk	 */
93715428Sphk	sgdt	(%esp)
93815428Sphk	movl	2(%esp),%esi		/* base address of bootstrap gdt */
93915428Sphk	movl	$R(_gdt),%edi
94015428Sphk	movl	%edi,2(%esp)		/* prepare to load kernel gdt */
94115428Sphk	movl	$8*18/4,%ecx
94215428Sphk	cld
94315428Sphk	rep				/* copy gdt */
94415428Sphk	movsl
94515428Sphk	movl	$R(_gdt),-8+2(%edi)	/* adjust gdt self-ptr */
94615428Sphk	movb	$0x92,-8+5(%edi)
94715428Sphk	lgdt	(%esp)
94815428Sphk
94915428Sphk	sidt	(%esp)
95015428Sphk	movl	2(%esp),%esi		/* base address of current idt */
95115428Sphk	movl	8+4(%esi),%eax		/* convert dbg descriptor to ... */
95215428Sphk	movw	8(%esi),%ax
95315428Sphk	movl	%eax,R(bdb_dbg_ljmp+1)	/* ... immediate offset ... */
95415428Sphk	movl	8+2(%esi),%eax
95515428Sphk	movw	%ax,R(bdb_dbg_ljmp+5)	/* ... and selector for ljmp */
95615428Sphk	movl	24+4(%esi),%eax		/* same for bpt descriptor */
95715428Sphk	movw	24(%esi),%ax
95815428Sphk	movl	%eax,R(bdb_bpt_ljmp+1)
95915428Sphk	movl	24+2(%esi),%eax
96015428Sphk	movw	%ax,R(bdb_bpt_ljmp+5)
96148005Sbde	movl	R(_idt),%edi
96215428Sphk	movl	%edi,2(%esp)		/* prepare to load kernel idt */
96315428Sphk	movl	$8*4/4,%ecx
96415428Sphk	cld
96515428Sphk	rep				/* copy idt */
96615428Sphk	movsl
96715428Sphk	lidt	(%esp)
96815428Sphk
96915428Sphk	addl	$6,%esp
97015428Sphk
97115428Sphkbdb_prepare_paging_exit:
97215428Sphk	ret
97315428Sphk
97415428Sphk/* Relocate debugger gdt entries and gdt and idt pointers. */
97515428Sphkbdb_commit_paging:
97615428Sphk	cmpl	$0,_bdb_exists
97715428Sphk	je	bdb_commit_paging_exit
97815428Sphk
97915428Sphk	movl	$_gdt+8*9,%eax		/* adjust slots 9-17 */
98015428Sphk	movl	$9,%ecx
98115428Sphkreloc_gdt:
98215428Sphk	movb	$KERNBASE>>24,7(%eax)	/* top byte of base addresses, was 0, */
98315428Sphk	addl	$8,%eax			/* now KERNBASE>>24 */
98415428Sphk	loop	reloc_gdt
98515428Sphk
98615428Sphk	subl	$6,%esp
98715428Sphk	sgdt	(%esp)
98815428Sphk	addl	$KERNBASE,2(%esp)
98915428Sphk	lgdt	(%esp)
99015428Sphk	sidt	(%esp)
99115428Sphk	addl	$KERNBASE,2(%esp)
99215428Sphk	lidt	(%esp)
99315428Sphk	addl	$6,%esp
99415428Sphk
99515428Sphk	int	$3
99615428Sphk
99715428Sphkbdb_commit_paging_exit:
99815428Sphk	ret
99915428Sphk
100015428Sphk#endif /* BDE_DEBUGGER */
1001