locore.s revision 43447
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
3743447Skato *	$Id: locore.s,v 1.119 1999/01/30 15:38:47 kato 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"
5130265Speter#include "opt_vm86.h"
5214835Sbde
5314835Sbde#include <sys/syscall.h>
545908Sbde#include <sys/reboot.h>
554Srgrimes
5614835Sbde#include <machine/asmacros.h>
5714835Sbde#include <machine/cputypes.h>
5814835Sbde#include <machine/psl.h>
5915543Sphk#include <machine/pmap.h>
6014835Sbde#include <machine/specialreg.h>
6114835Sbde
6214835Sbde#include "assym.s"
6314835Sbde
644Srgrimes/*
65757Sdg *	XXX
66757Sdg *
674Srgrimes * Note: This version greatly munged to avoid various assembler errors
684Srgrimes * that may be fixed in newer versions of gas. Perhaps newer versions
694Srgrimes * will have more pleasant appearance.
704Srgrimes */
714Srgrimes
72200Sdg/*
734Srgrimes * PTmap is recursive pagemap at top of virtual address space.
744Srgrimes * Within PTmap, the page directory can be found (third indirection).
754Srgrimes */
763861Sbde	.globl	_PTmap,_PTD,_PTDpde
7715543Sphk	.set	_PTmap,(PTDPTDI << PDRSHIFT)
7815543Sphk	.set	_PTD,_PTmap + (PTDPTDI * PAGE_SIZE)
79757Sdg	.set	_PTDpde,_PTD + (PTDPTDI * PDESIZE)
80592Srgrimes
813861Sbde/*
824Srgrimes * APTmap, APTD is the alternate recursive pagemap.
834Srgrimes * It's used when modifying another process's page tables.
844Srgrimes */
85592Srgrimes	.globl	_APTmap,_APTD,_APTDpde
86592Srgrimes	.set	_APTmap,APTDPTDI << PDRSHIFT
8715543Sphk	.set	_APTD,_APTmap + (APTDPTDI * PAGE_SIZE)
88757Sdg	.set	_APTDpde,_PTD + (APTDPTDI * PDESIZE)
894Srgrimes
904Srgrimes/*
91556Srgrimes * Globals
92556Srgrimes */
93556Srgrimes	.data
9414835Sbde	ALIGN_DATA		/* just to be sure */
95134Sdg
9625083Sjdp	.globl	HIDENAME(tmpstk)
9713729Sdg	.space	0x2000		/* space for tmpstk - temporary stack */
9825083SjdpHIDENAME(tmpstk):
993842Sdg
1003861Sbde	.globl	_boothowto,_bootdev
101134Sdg
10215565Sphk	.globl	_cpu,_cpu_vendor,_cpu_id,_bootinfo
1036308Sphk	.globl	_cpu_high, _cpu_feature
1042783Ssos
105757Sdg_cpu:	.long	0				/* are we 386, 386sx, or 486 */
1062216Sbde_cpu_id:	.long	0			/* stepping ID */
1076308Sphk_cpu_high:	.long	0			/* highest arg to CPUID */
1086308Sphk_cpu_feature:	.long	0			/* features */
1092216Sbde_cpu_vendor:	.space	20			/* CPU origin code */
1105908Sbde_bootinfo:	.space	BOOTINFO_SIZE		/* bootinfo that we can handle */
1114Srgrimes
112757Sdg_KERNend:	.long	0			/* phys addr end of kernel (just after bss) */
11315428Sphkphysfree:	.long	0			/* phys addr of next free page */
114757Sdg
11526812Speter#ifdef SMP
11625164Spetercpu0pp:		.long	0			/* phys addr cpu0 private pg */
11725164Spetercpu0pt:		.long	0			/* phys addr cpu0 private pt */
11825164Speter
11925164Speter		.globl	_cpu0prvpage,_cpu0prvpt
12025164Speter_cpu0prvpage:	.long	0			/* relocated version */
12125164Speter_cpu0prvpt:	.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
13634840Sjlemon#ifdef VM86
13737889Sjlemonvm86phystk:	.long	0			/* PA of vm86/bios stack */
13837889Sjlemon
13934840Sjlemon	.globl	_vm86paddr, _vm86pa
14034840Sjlemon_vm86paddr:	.long	0			/* address of vm86 region */
14134840Sjlemon_vm86pa:	.long	0			/* phys addr of vm86 region */
14234840Sjlemon#endif
14334840Sjlemon
14415428Sphk#ifdef BDE_DEBUGGER
14515428Sphk	.globl	_bdb_exists			/* flag to indicate BDE debugger is present */
14615428Sphk_bdb_exists:	.long	0
14715428Sphk#endif
148718Swollman
14943434Skato#ifdef PC98
15043434Skato	.globl	_pc98_system_parameter
15143434Skato_pc98_system_parameter:
15243434Skato	.space	0x240
15343434Skato#endif
15415428Sphk
15515392Sphk/**********************************************************************
15615392Sphk *
15715392Sphk * Some handy macros
15815392Sphk *
159556Srgrimes */
160134Sdg
16115392Sphk#define R(foo) ((foo)-KERNBASE)
16215392Sphk
16315392Sphk#define ALLOCPAGES(foo) \
16415392Sphk	movl	R(physfree), %esi ; \
16515543Sphk	movl	$((foo)*PAGE_SIZE), %eax ; \
16615392Sphk	addl	%esi, %eax ; \
16715392Sphk	movl	%eax, R(physfree) ; \
16815392Sphk	movl	%esi, %edi ; \
16915543Sphk	movl	$((foo)*PAGE_SIZE),%ecx ; \
17015392Sphk	xorl	%eax,%eax ; \
17115428Sphk	cld ; \
17215428Sphk	rep ; \
17315428Sphk	stosb
17415392Sphk
175134Sdg/*
17615392Sphk * fillkpt
17715565Sphk *	eax = page frame address
17815565Sphk *	ebx = index into page table
17915392Sphk *	ecx = how many pages to map
18015565Sphk * 	base = base address of page dir/table
18115565Sphk *	prot = protection bits
182134Sdg */
18315565Sphk#define	fillkpt(base, prot)		  \
18419621Sdyson	shll	$2,%ebx			; \
18519621Sdyson	addl	base,%ebx		; \
18619621Sdyson	orl	$PG_V,%eax		; \
18719621Sdyson	orl	prot,%eax		; \
18815565Sphk1:	movl	%eax,(%ebx)		; \
18915565Sphk	addl	$PAGE_SIZE,%eax		; /* increment physical address */ \
19015565Sphk	addl	$4,%ebx			; /* next pte */ \
19115428Sphk	loop	1b
19215392Sphk
19315565Sphk/*
19415565Sphk * fillkptphys(prot)
19515565Sphk *	eax = physical address
19615565Sphk *	ecx = how many pages to map
19715565Sphk *	prot = protection bits
19815565Sphk */
19915565Sphk#define	fillkptphys(prot)		  \
20015565Sphk	movl	%eax, %ebx		; \
20115565Sphk	shrl	$PAGE_SHIFT, %ebx	; \
20215565Sphk	fillkpt(R(_KPTphys), prot)
20315565Sphk
20415392Sphk	.text
20515392Sphk/**********************************************************************
20615392Sphk *
20715392Sphk * This is where the bootblocks start us, set the ball rolling...
20815392Sphk *
20915392Sphk */
2101321SdgNON_GPROF_ENTRY(btext)
2114Srgrimes
21224112Skato#ifdef PC98
21324112Skato	/* save SYSTEM PARAMETER for resume (NS/T or other) */
21443434Skato	movl	$0xa1400,%esi
21543434Skato	movl	$R(_pc98_system_parameter),%edi
21643434Skato	movl	$0x0240,%ecx
21724112Skato	cld
21824112Skato	rep
21924112Skato	movsb
22024112Skato#else	/* IBM-PC */
22115428Sphk#ifdef BDE_DEBUGGER
22215428Sphk#ifdef BIOS_STEALS_3K
22315428Sphk	cmpl	$0x0375c339,0x95504
22415428Sphk#else
22515428Sphk	cmpl	$0x0375c339,0x96104	/* XXX - debugger signature */
22615428Sphk#endif
22715428Sphk	jne	1f
22815428Sphk	movb	$1,R(_bdb_exists)
22915428Sphk1:
23015428Sphk#endif
23140179Skato#endif	/* PC98 */
23215428Sphk
23315392Sphk/* Tell the bios to warmboot next time */
23415392Sphk	movw	$0x1234,0x472
23515392Sphk
23615428Sphk/* Set up a real frame in case the double return in newboot is executed. */
2373384Srgrimes	pushl	%ebp
2383384Srgrimes	movl	%esp, %ebp
2393384Srgrimes
24015392Sphk/* Don't trust what the BIOS gives for eflags. */
2415603Sbde	pushl	$PSL_KERNEL
2422486Sdg	popfl
24315428Sphk
24415428Sphk/*
24515428Sphk * Don't trust what the BIOS gives for %fs and %gs.  Trust the bootstrap
24615428Sphk * to set %cs, %ds, %es and %ss.
24715428Sphk */
24815428Sphk	mov	%ds, %ax
2494217Sphk	mov	%ax, %fs
2504217Sphk	mov	%ax, %gs
2514217Sphk
25215392Sphk	call	recover_bootinfo
25315392Sphk
25415428Sphk/* Get onto a stack that we can trust. */
25515428Sphk/*
25615428Sphk * XXX this step is delayed in case recover_bootinfo needs to return via
25715428Sphk * the old stack, but it need not be, since recover_bootinfo actually
25815428Sphk * returns via the old frame.
25915428Sphk */
26025083Sjdp	movl	$R(HIDENAME(tmpstk)),%esp
26115392Sphk
26224112Skato#ifdef PC98
26343447Skato	/* pc98_machine_type & M_EPSON_PC98 */
26443447Skato	testb	$0x02,R(_pc98_system_parameter)+220
26524112Skato	jz	3f
26643447Skato	/* epson_machine_id <= 0x0b */
26743447Skato	cmpb	$0x0b,R(_pc98_system_parameter)+224
26824112Skato	ja	3f
26924112Skato
27024112Skato	/* count up memory */
27124112Skato	movl	$0x100000,%eax		/* next, talley remaining memory */
27224112Skato	movl	$0xFFF-0x100,%ecx
27324112Skato1:	movl	0(%eax),%ebx		/* save location to check */
27424112Skato	movl	$0xa55a5aa5,0(%eax)	/* write test pattern */
27524112Skato	cmpl	$0xa55a5aa5,0(%eax)	/* does not check yet for rollover */
27624112Skato	jne	2f
27724112Skato	movl	%ebx,0(%eax)		/* restore memory */
27824112Skato	addl	$PAGE_SIZE,%eax
27924112Skato	loop	1b
28024112Skato2:	subl	$0x100000,%eax
28124112Skato	shrl	$17,%eax
28243447Skato	movb	%al,R(_pc98_system_parameter)+1
28324112Skato3:
28424112Skato#endif
28524112Skato
28615392Sphk	call	identify_cpu
28715392Sphk
28815392Sphk/* clear bss */
28915428Sphk/*
29017120Sbde * XXX this should be done a little earlier.
29115428Sphk *
29217120Sbde * XXX we don't check that there is memory for our bss and page tables
29317120Sbde * before using it.
29415428Sphk *
29515428Sphk * XXX the boot program somewhat bogusly clears the bss.  We still have
29615428Sphk * to do it in case we were unzipped by kzipboot.  Then the boot program
29715428Sphk * only clears kzipboot's bss.
29815428Sphk *
29915428Sphk * XXX the gdt and idt are still somewhere in the boot program.  We
30015428Sphk * depend on the convention that the boot program is below 1MB and we
30115428Sphk * are above 1MB to keep the gdt and idt  away from the bss and page
30217120Sbde * tables.  The idt is only used if BDE_DEBUGGER is enabled.
30315428Sphk */
30415392Sphk	movl	$R(_end),%ecx
30515392Sphk	movl	$R(_edata),%edi
30615392Sphk	subl	%edi,%ecx
30715392Sphk	xorl	%eax,%eax
30815428Sphk	cld
30915428Sphk	rep
31015428Sphk	stosb
31115392Sphk
31215392Sphk#if NAPM > 0
31336596Smsmith#ifndef VM86
31415428Sphk/*
31515428Sphk * XXX it's not clear that APM can live in the current environonment.
31615428Sphk * Only pc-relative addressing works.
31715428Sphk */
31815428Sphk	call	_apm_setup
31915428Sphk#endif
32036596Smsmith#endif
32115392Sphk
32215392Sphk	call	create_pagetables
32315392Sphk
32427993Sdyson#ifdef VM86
32527993Sdyson/*
32627993Sdyson * If the CPU has support for VME, turn it on.
32727993Sdyson */
32827993Sdyson	testl	$CPUID_VME, R(_cpu_feature)
32927993Sdyson	jz	1f
33027993Sdyson	movl	%cr4, %eax
33127993Sdyson	orl	$CR4_VME, %eax
33227993Sdyson	movl	%eax, %cr4
33327993Sdyson1:
33427993Sdyson#endif /* VM86 */
33527993Sdyson
33615428Sphk#ifdef BDE_DEBUGGER
33715428Sphk/*
33815428Sphk * Adjust as much as possible for paging before enabling paging so that the
33915428Sphk * adjustments can be traced.
34015428Sphk */
34115428Sphk	call	bdb_prepare_paging
34215428Sphk#endif
34315428Sphk
34415392Sphk/* Now enable paging */
34515392Sphk	movl	R(_IdlePTD), %eax
34615392Sphk	movl	%eax,%cr3			/* load ptd addr into mmu */
34715392Sphk	movl	%cr0,%eax			/* get control word */
34815392Sphk	orl	$CR0_PE|CR0_PG,%eax		/* enable paging */
34915392Sphk	movl	%eax,%cr0			/* and let's page NOW! */
35015392Sphk
35115428Sphk#ifdef BDE_DEBUGGER
35215428Sphk/*
35315428Sphk * Complete the adjustments for paging so that we can keep tracing through
35417120Sbde * initi386() after the low (physical) addresses for the gdt and idt become
35515428Sphk * invalid.
35615428Sphk */
35715428Sphk	call	bdb_commit_paging
35815428Sphk#endif
35915428Sphk
36015428Sphk	pushl	$begin				/* jump to high virtualized address */
36115392Sphk	ret
36215392Sphk
36315392Sphk/* now running relocated at KERNBASE where the system is linked to run */
36415392Sphkbegin:
36515392Sphk	/* set up bootstrap stack */
36624691Speter	movl	_proc0paddr,%esp	/* location of in-kernel pages */
36724691Speter	addl	$UPAGES*PAGE_SIZE,%esp	/* bootstrap stack end location */
36815392Sphk	xorl	%eax,%eax			/* mark end of frames */
36915392Sphk	movl	%eax,%ebp
37015392Sphk	movl	_proc0paddr,%eax
37115392Sphk	movl	_IdlePTD, %esi
37215392Sphk	movl	%esi,PCB_CR3(%eax)
37335072Speter	movl	$_proc0,_curproc
37415392Sphk
37515392Sphk	movl	physfree, %esi
37615392Sphk	pushl	%esi				/* value of first for init386(first) */
37715392Sphk	call	_init386			/* wire 386 chip for unix operation */
37815392Sphk	popl	%esi
37915392Sphk
38015392Sphk	.globl	__ucodesel,__udatasel
38115392Sphk
38215392Sphk	pushl	$0				/* unused */
38315392Sphk	pushl	__udatasel			/* ss */
38415392Sphk	pushl	$0				/* esp - filled in by execve() */
38515392Sphk	pushl	$PSL_USER			/* eflags (IOPL 0, int enab) */
38615392Sphk	pushl	__ucodesel			/* cs */
38715392Sphk	pushl	$0				/* eip - filled in by execve() */
38815392Sphk	subl	$(12*4),%esp			/* space for rest of registers */
38915392Sphk
39015392Sphk	pushl	%esp				/* call main with frame pointer */
39115392Sphk	call	_main				/* autoconfiguration, mountroot etc */
39215392Sphk
39324691Speter	hlt		/* never returns to here */
39415392Sphk
39524691Speter/*
39624691Speter * When starting init, call this to configure the process for user
39724691Speter * mode.  This will be inherited by other processes.
39824691Speter */
39924691SpeterNON_GPROF_ENTRY(prepare_usermode)
40015392Sphk	/*
40124112Skato	 * Now we've run main() and determined what cpu-type we are, we can
40215392Sphk	 * enable write protection and alignment checking on i486 cpus and
40315392Sphk	 * above.
40415392Sphk	 */
40515392Sphk#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)
40615392Sphk	cmpl    $CPUCLASS_386,_cpu_class
40715392Sphk	je	1f
40815392Sphk	movl	%cr0,%eax			/* get control word */
40915392Sphk	orl	$CR0_WP|CR0_AM,%eax		/* enable i486 features */
41015392Sphk	movl	%eax,%cr0			/* and do it */
41115428Sphk1:
41215392Sphk#endif
41315392Sphk	/*
41415392Sphk	 * on return from main(), we are process 1
41515392Sphk	 * set up address space and stack so that we can 'return' to user mode
41615392Sphk	 */
41715392Sphk	movl	__ucodesel,%eax
41815392Sphk	movl	__udatasel,%ecx
41915392Sphk
42024691Speter#if 0
42115392Sphk	movl	%cx,%ds
42224691Speter#endif
42315392Sphk	movl	%cx,%es
42415392Sphk	movl	%ax,%fs				/* double map cs to fs */
42515392Sphk	movl	%cx,%gs				/* and ds to gs */
42624691Speter	ret					/* goto user! */
42715392Sphk
42824691Speter
42915392Sphk#define LCALL(x,y)	.byte 0x9a ; .long y ; .word x
43015392Sphk
43115392Sphk/*
43215392Sphk * Signal trampoline, copied to top of user stack
43315392Sphk */
43415392SphkNON_GPROF_ENTRY(sigcode)
43515392Sphk	call	SIGF_HANDLER(%esp)
43615392Sphk	lea	SIGF_SC(%esp),%eax		/* scp (the call may have clobbered the */
43715392Sphk						/* copy at 8(%esp)) */
43815392Sphk	pushl	%eax
43915392Sphk	pushl	%eax				/* junk to fake return address */
44015392Sphk	movl	$SYS_sigreturn,%eax		/* sigreturn() */
44115392Sphk	LCALL(0x7,0)				/* enter kernel with args on stack */
44215392Sphk	hlt					/* never gets here */
44325083Sjdp	ALIGN_TEXT
44415392Sphk_esigcode:
44515392Sphk
44615392Sphk	.data
44715392Sphk	.globl	_szsigcode
44815392Sphk_szsigcode:
44915392Sphk	.long	_esigcode-_sigcode
45015428Sphk	.text
45115392Sphk
45215392Sphk/**********************************************************************
45315392Sphk *
45415392Sphk * Recover the bootinfo passed to us from the boot program
45515392Sphk *
45615392Sphk */
45715392Sphkrecover_bootinfo:
45815392Sphk	/*
4593284Srgrimes	 * This code is called in different ways depending on what loaded
4603284Srgrimes	 * and started the kernel.  This is used to detect how we get the
4613284Srgrimes	 * arguments from the other code and what we do with them.
4623284Srgrimes	 *
4633284Srgrimes	 * Old disk boot blocks:
4643284Srgrimes	 *	(*btext)(howto, bootdev, cyloffset, esym);
4653284Srgrimes	 *	[return address == 0, and can NOT be returned to]
4663284Srgrimes	 *	[cyloffset was not supported by the FreeBSD boot code
4673284Srgrimes	 *	 and always passed in as 0]
4683284Srgrimes	 *	[esym is also known as total in the boot code, and
4693284Srgrimes	 *	 was never properly supported by the FreeBSD boot code]
4703284Srgrimes	 *
4713284Srgrimes	 * Old diskless netboot code:
4723284Srgrimes	 *	(*btext)(0,0,0,0,&nfsdiskless,0,0,0);
4733284Srgrimes	 *	[return address != 0, and can NOT be returned to]
4743284Srgrimes	 *	If we are being booted by this code it will NOT work,
4753284Srgrimes	 *	so we are just going to halt if we find this case.
4763284Srgrimes	 *
4773284Srgrimes	 * New uniform boot code:
4783284Srgrimes	 *	(*btext)(howto, bootdev, 0, 0, 0, &bootinfo)
4793284Srgrimes	 *	[return address != 0, and can be returned to]
4803284Srgrimes	 *
4813284Srgrimes	 * There may seem to be a lot of wasted arguments in here, but
4823384Srgrimes	 * that is so the newer boot code can still load very old kernels
4833384Srgrimes	 * and old boot code can load new kernels.
4844Srgrimes	 */
4853284Srgrimes
4863284Srgrimes	/*
4873284Srgrimes	 * The old style disk boot blocks fake a frame on the stack and
4883284Srgrimes	 * did an lret to get here.  The frame on the stack has a return
4893284Srgrimes	 * address of 0.
4903284Srgrimes	 */
4913384Srgrimes	cmpl	$0,4(%ebp)
49215392Sphk	je	olddiskboot
4933284Srgrimes
4943284Srgrimes	/*
4953284Srgrimes	 * We have some form of return address, so this is either the
4963284Srgrimes	 * old diskless netboot code, or the new uniform code.  That can
49715428Sphk	 * be detected by looking at the 5th argument, if it is 0
49815428Sphk	 * we are being booted by the new uniform boot code.
4993284Srgrimes	 */
5003384Srgrimes	cmpl	$0,24(%ebp)
50115392Sphk	je	newboot
5023284Srgrimes
5033284Srgrimes	/*
5043284Srgrimes	 * Seems we have been loaded by the old diskless boot code, we
5053284Srgrimes	 * don't stand a chance of running as the diskless structure
5063284Srgrimes	 * changed considerably between the two, so just halt.
5073284Srgrimes	 */
5083284Srgrimes	 hlt
5093284Srgrimes
5103284Srgrimes	/*
5113384Srgrimes	 * We have been loaded by the new uniform boot code.
51215428Sphk	 * Let's check the bootinfo version, and if we do not understand
5133384Srgrimes	 * it we return to the loader with a status of 1 to indicate this error
5143284Srgrimes	 */
51515392Sphknewboot:
5163384Srgrimes	movl	28(%ebp),%ebx		/* &bootinfo.version */
5175908Sbde	movl	BI_VERSION(%ebx),%eax
5183384Srgrimes	cmpl	$1,%eax			/* We only understand version 1 */
5193384Srgrimes	je	1f
5203384Srgrimes	movl	$1,%eax			/* Return status */
5213384Srgrimes	leave
52215428Sphk	/*
52315428Sphk	 * XXX this returns to our caller's caller (as is required) since
52415428Sphk	 * we didn't set up a frame and our caller did.
52515428Sphk	 */
5263384Srgrimes	ret
5273284Srgrimes
5283384Srgrimes1:
5293284Srgrimes	/*
5303384Srgrimes	 * If we have a kernelname copy it in
5313384Srgrimes	 */
5325908Sbde	movl	BI_KERNELNAME(%ebx),%esi
5333384Srgrimes	cmpl	$0,%esi
5349344Sdg	je	2f			/* No kernelname */
5359344Sdg	movl	$MAXPATHLEN,%ecx	/* Brute force!!! */
53615926Sphk	movl	$R(_kernelname),%edi
5379344Sdg	cmpb	$'/',(%esi)		/* Make sure it starts with a slash */
5389344Sdg	je	1f
5399344Sdg	movb	$'/',(%edi)
5409344Sdg	incl	%edi
5419344Sdg	decl	%ecx
5429344Sdg1:
5433384Srgrimes	cld
5443384Srgrimes	rep
5453384Srgrimes	movsb
5463384Srgrimes
5479344Sdg2:
54815428Sphk	/*
5495908Sbde	 * Determine the size of the boot loader's copy of the bootinfo
5505908Sbde	 * struct.  This is impossible to do properly because old versions
5515908Sbde	 * of the struct don't contain a size field and there are 2 old
5525908Sbde	 * versions with the same version number.
5534600Sphk	 */
5545908Sbde	movl	$BI_ENDCOMMON,%ecx	/* prepare for sizeless version */
5555908Sbde	testl	$RB_BOOTINFO,8(%ebp)	/* bi_size (and bootinfo) valid? */
5565908Sbde	je	got_bi_size		/* no, sizeless version */
5575908Sbde	movl	BI_SIZE(%ebx),%ecx
5585908Sbdegot_bi_size:
5595908Sbde
56015428Sphk	/*
5615908Sbde	 * Copy the common part of the bootinfo struct
5625908Sbde	 */
5634600Sphk	movl	%ebx,%esi
56415926Sphk	movl	$R(_bootinfo),%edi
5655908Sbde	cmpl	$BOOTINFO_SIZE,%ecx
5665908Sbde	jbe	got_common_bi_size
5674600Sphk	movl	$BOOTINFO_SIZE,%ecx
5685908Sbdegot_common_bi_size:
5694600Sphk	cld
5704600Sphk	rep
5714600Sphk	movsb
5724600Sphk
57338063Smsmith#ifdef NFS_ROOT
57425837Stegge#ifndef BOOTP_NFSV3
5753384Srgrimes	/*
5763384Srgrimes	 * If we have a nfs_diskless structure copy it in
5773384Srgrimes	 */
5785908Sbde	movl	BI_NFS_DISKLESS(%ebx),%esi
5793384Srgrimes	cmpl	$0,%esi
58015428Sphk	je	olddiskboot
58115926Sphk	movl	$R(_nfs_diskless),%edi
5823384Srgrimes	movl	$NFSDISKLESS_SIZE,%ecx
5833384Srgrimes	cld
5843384Srgrimes	rep
5853384Srgrimes	movsb
58615926Sphk	movl	$R(_nfs_diskless_valid),%edi
5873795Sphk	movl	$1,(%edi)
5883406Sdg#endif
58925837Stegge#endif
5903384Srgrimes
5913384Srgrimes	/*
5923284Srgrimes	 * The old style disk boot.
5933284Srgrimes	 *	(*btext)(howto, bootdev, cyloffset, esym);
5943384Srgrimes	 * Note that the newer boot code just falls into here to pick
5953384Srgrimes	 * up howto and bootdev, cyloffset and esym are no longer used
5963284Srgrimes	 */
59715392Sphkolddiskboot:
5983384Srgrimes	movl	8(%ebp),%eax
59915926Sphk	movl	%eax,R(_boothowto)
6003384Srgrimes	movl	12(%ebp),%eax
60115926Sphk	movl	%eax,R(_bootdev)
6022783Ssos
60315392Sphk	ret
6043258Sdg
6051321Sdg
60615392Sphk/**********************************************************************
60715392Sphk *
60815392Sphk * Identify the CPU and initialize anything special about it
60915392Sphk *
61015392Sphk */
61115392Sphkidentify_cpu:
61215392Sphk
6131998Swollman	/* Try to toggle alignment check flag; does not exist on 386. */
6141998Swollman	pushfl
6151998Swollman	popl	%eax
6161998Swollman	movl	%eax,%ecx
6171998Swollman	orl	$PSL_AC,%eax
6181998Swollman	pushl	%eax
6191998Swollman	popfl
6201998Swollman	pushfl
6211998Swollman	popl	%eax
6221998Swollman	xorl	%ecx,%eax
6231998Swollman	andl	$PSL_AC,%eax
6241998Swollman	pushl	%ecx
6251998Swollman	popfl
6261998Swollman
6271998Swollman	testl	%eax,%eax
62824112Skato	jnz	try486
62924112Skato
63024112Skato	/* NexGen CPU does not have aligment check flag. */
63124112Skato	pushfl
63224112Skato	movl	$0x5555, %eax
63324112Skato	xorl	%edx, %edx
63424112Skato	movl	$2, %ecx
63524112Skato	clc
63624112Skato	divl	%ecx
63724112Skato	jz	trynexgen
63824112Skato	popfl
63915926Sphk	movl	$CPU_386,R(_cpu)
64013081Sdg	jmp	3f
6411998Swollman
64224112Skatotrynexgen:
64327424Skato	popfl
64424112Skato	movl	$CPU_NX586,R(_cpu)
64524112Skato	movl	$0x4778654e,R(_cpu_vendor)	# store vendor string
64624112Skato	movl	$0x72446e65,R(_cpu_vendor+4)
64724112Skato	movl	$0x6e657669,R(_cpu_vendor+8)
64824112Skato	movl	$0,R(_cpu_vendor+12)
64924112Skato	jmp	3f
65024112Skato
65124112Skatotry486:	/* Try to toggle identification flag; does not exist on early 486s. */
6521998Swollman	pushfl
6531998Swollman	popl	%eax
6541998Swollman	movl	%eax,%ecx
6551998Swollman	xorl	$PSL_ID,%eax
6561998Swollman	pushl	%eax
6571998Swollman	popfl
6581998Swollman	pushfl
6591998Swollman	popl	%eax
6601998Swollman	xorl	%ecx,%eax
6611998Swollman	andl	$PSL_ID,%eax
6621998Swollman	pushl	%ecx
6631998Swollman	popfl
6641998Swollman
6651998Swollman	testl	%eax,%eax
66624112Skato	jnz	trycpuid
66715926Sphk	movl	$CPU_486,R(_cpu)
6682495Spst
66924112Skato	/*
67024112Skato	 * Check Cyrix CPU
67124112Skato	 * Cyrix CPUs do not change the undefined flags following
67224112Skato	 * execution of the divide instruction which divides 5 by 2.
67324112Skato	 *
67424112Skato	 * Note: CPUID is enabled on M2, so it passes another way.
67524112Skato	 */
67624112Skato	pushfl
67724112Skato	movl	$0x5555, %eax
67824112Skato	xorl	%edx, %edx
67924112Skato	movl	$2, %ecx
68024112Skato	clc
68124112Skato	divl	%ecx
68224112Skato	jnc	trycyrix
68324112Skato	popfl
68424112Skato	jmp	3f		/* You may use Intel CPU. */
6852495Spst
68624112Skatotrycyrix:
68724112Skato	popfl
68824112Skato	/*
68924112Skato	 * IBM Bluelighting CPU also doesn't change the undefined flags.
69024112Skato	 * Because IBM doesn't disclose the information for Bluelighting
69124112Skato	 * CPU, we couldn't distinguish it from Cyrix's (including IBM
69224112Skato	 * brand of Cyrix CPUs).
69324112Skato	 */
69415926Sphk	movl	$0x69727943,R(_cpu_vendor)	# store vendor string
69524112Skato	movl	$0x736e4978,R(_cpu_vendor+4)
69624112Skato	movl	$0x64616574,R(_cpu_vendor+8)
69713014Sdg	jmp	3f
6981998Swollman
69924112Skatotrycpuid:	/* Use the `cpuid' instruction. */
7001998Swollman	xorl	%eax,%eax
7016308Sphk	.byte	0x0f,0xa2			# cpuid 0
70215926Sphk	movl	%eax,R(_cpu_high)		# highest capability
70315926Sphk	movl	%ebx,R(_cpu_vendor)		# store vendor string
70415926Sphk	movl	%edx,R(_cpu_vendor+4)
70515926Sphk	movl	%ecx,R(_cpu_vendor+8)
70615926Sphk	movb	$0,R(_cpu_vendor+12)
7071998Swollman
7081998Swollman	movl	$1,%eax
7096308Sphk	.byte	0x0f,0xa2			# cpuid 1
71015926Sphk	movl	%eax,R(_cpu_id)			# store cpu_id
71115926Sphk	movl	%edx,R(_cpu_feature)		# store cpu_feature
7126308Sphk	rorl	$8,%eax				# extract family type
7131998Swollman	andl	$15,%eax
7141998Swollman	cmpl	$5,%eax
7151998Swollman	jae	1f
7161998Swollman
7171998Swollman	/* less than Pentium; must be 486 */
71815926Sphk	movl	$CPU_486,R(_cpu)
71913000Sdg	jmp	3f
72013000Sdg1:
72113000Sdg	/* a Pentium? */
72213000Sdg	cmpl	$5,%eax
72313000Sdg	jne	2f
72415926Sphk	movl	$CPU_586,R(_cpu)
72513000Sdg	jmp	3f
726556Srgrimes2:
72713000Sdg	/* Greater than Pentium...call it a Pentium Pro */
72815926Sphk	movl	$CPU_686,R(_cpu)
72913000Sdg3:
73015392Sphk	ret
731556Srgrimes
7324Srgrimes
73315392Sphk/**********************************************************************
734570Srgrimes *
73515428Sphk * Create the first page directory and its page tables.
73615392Sphk *
737570Srgrimes */
738570Srgrimes
73915392Sphkcreate_pagetables:
74015392Sphk
74119621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
74219621Sdyson	jz	1f
74319621Sdyson	movl	%cr4, %eax
74419621Sdyson	orl	$CR4_PGE, %eax
74519621Sdyson	movl	%eax, %cr4
74619621Sdyson1:
74719621Sdyson
74815428Sphk/* Find end of kernel image (rounded up to a page boundary). */
74915392Sphk	movl	$R(_end),%esi
7504Srgrimes
75140081Smsmith/* include symbols if loaded and useful */
7525908Sbde#ifdef DDB
75315392Sphk	movl	R(_bootinfo+BI_ESYMTAB),%edi
7545908Sbde	testl	%edi,%edi
75515428Sphk	je	over_symalloc
7565908Sbde	movl	%edi,%esi
7575908Sbde	movl	$KERNBASE,%edi
75815392Sphk	addl	%edi,R(_bootinfo+BI_SYMTAB)
75915392Sphk	addl	%edi,R(_bootinfo+BI_ESYMTAB)
76015428Sphkover_symalloc:
7615908Sbde#endif
7625908Sbde
76340081Smsmith/* If we are told where the end of the kernel space is, believe it. */
76440081Smsmith	movl	R(_bootinfo+BI_KERNEND),%edi
76540081Smsmith	testl	%edi,%edi
76640081Smsmith	je	no_kernend
76740081Smsmith	movl	%edi,%esi
76840081Smsmithno_kernend:
76940081Smsmith
77015565Sphk	addl	$PAGE_MASK,%esi
77115565Sphk	andl	$~PAGE_MASK,%esi
77215392Sphk	movl	%esi,R(_KERNend)	/* save end of kernel */
77315428Sphk	movl	%esi,R(physfree)	/* next free page is at end of kernel */
774608Srgrimes
77515392Sphk/* Allocate Kernel Page Tables */
77615392Sphk	ALLOCPAGES(NKPT)
77715392Sphk	movl	%esi,R(_KPTphys)
778757Sdg
77915392Sphk/* Allocate Page Table Directory */
78015392Sphk	ALLOCPAGES(1)
78115392Sphk	movl	%esi,R(_IdlePTD)
7824Srgrimes
78315392Sphk/* Allocate UPAGES */
78415392Sphk	ALLOCPAGES(UPAGES)
78517120Sbde	movl	%esi,R(p0upa)
78615392Sphk	addl	$KERNBASE, %esi
78715392Sphk	movl	%esi, R(_proc0paddr)
7884Srgrimes
78934840Sjlemon#ifdef VM86
79037889Sjlemon	ALLOCPAGES(1)			/* vm86/bios stack */
79137889Sjlemon	movl	%esi,R(vm86phystk)
79237889Sjlemon
79337889Sjlemon	ALLOCPAGES(3)			/* pgtable + ext + IOPAGES */
79434840Sjlemon	movl	%esi,R(_vm86pa)
79534840Sjlemon	addl	$KERNBASE, %esi
79634840Sjlemon	movl	%esi, R(_vm86paddr)
79734840Sjlemon#endif /* VM86 */
79834840Sjlemon
79926812Speter#ifdef SMP
80025164Speter/* Allocate cpu0's private data page */
80125164Speter	ALLOCPAGES(1)
80225164Speter	movl	%esi,R(cpu0pp)
80325164Speter	addl	$KERNBASE, %esi
80425164Speter	movl	%esi, R(_cpu0prvpage)	/* relocated to KVM space */
80525164Speter
80625164Speter/* Allocate cpu0's private page table for mapping priv page, apic, etc */
80725164Speter	ALLOCPAGES(1)
80825164Speter	movl	%esi,R(cpu0pt)
80925164Speter	addl	$KERNBASE, %esi
81025164Speter	movl	%esi, R(_cpu0prvpt)	/* relocated to KVM space */
81126812Speter#endif	/* SMP */
81225164Speter
81315392Sphk/* Map read-only from zero to the end of the kernel text section */
81415565Sphk	xorl	%eax, %eax
81515428Sphk#ifdef BDE_DEBUGGER
81615428Sphk/* If the debugger is present, actually map everything read-write. */
81715428Sphk	cmpl	$0,R(_bdb_exists)
81815428Sphk	jne	map_read_write
81915428Sphk#endif
82019621Sdyson	xorl	%edx,%edx
82127484Sdyson
82227484Sdyson#if !defined(SMP)
82319621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
82419621Sdyson	jz	2f
82519621Sdyson	orl	$PG_G,%edx
82627484Sdyson#endif
82719621Sdyson
82819621Sdyson2:	movl	$R(_etext),%ecx
82915565Sphk	addl	$PAGE_MASK,%ecx
83015565Sphk	shrl	$PAGE_SHIFT,%ecx
83119621Sdyson	fillkptphys(%edx)
832757Sdg
83315392Sphk/* Map read-write, data, bss and symbols */
83415565Sphk	movl	$R(_etext),%eax
83515694Sphk	addl	$PAGE_MASK, %eax
83615694Sphk	andl	$~PAGE_MASK, %eax
83715428Sphkmap_read_write:
83819621Sdyson	movl	$PG_RW,%edx
83927484Sdyson#if !defined(SMP)
84019621Sdyson	testl	$CPUID_PGE, R(_cpu_feature)
84119621Sdyson	jz	1f
84219621Sdyson	orl	$PG_G,%edx
84327484Sdyson#endif
84419621Sdyson
84519621Sdyson1:	movl	R(_KERNend),%ecx
846757Sdg	subl	%eax,%ecx
84715543Sphk	shrl	$PAGE_SHIFT,%ecx
84819621Sdyson	fillkptphys(%edx)
849757Sdg
85015428Sphk/* Map page directory. */
85115392Sphk	movl	R(_IdlePTD), %eax
85215392Sphk	movl	$1, %ecx
85319621Sdyson	fillkptphys($PG_RW)
854757Sdg
85517120Sbde/* Map proc0's UPAGES in the physical way ... */
85617120Sbde	movl	R(p0upa), %eax
85715392Sphk	movl	$UPAGES, %ecx
85819621Sdyson	fillkptphys($PG_RW)
8594Srgrimes
86015565Sphk/* Map ISA hole */
86115565Sphk	movl	$ISA_HOLE_START, %eax
86215565Sphk	movl	$ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
86322130Sdg	fillkptphys($PG_RW)
86415565Sphk
86534840Sjlemon#ifdef VM86
86634840Sjlemon/* Map space for the vm86 region */
86737889Sjlemon	movl	R(vm86phystk), %eax
86834840Sjlemon	movl	$4, %ecx
86934840Sjlemon	fillkptphys($PG_RW)
87034840Sjlemon
87134840Sjlemon/* Map page 0 into the vm86 page table */
87234840Sjlemon	movl	$0, %eax
87334840Sjlemon	movl	$0, %ebx
87434840Sjlemon	movl	$1, %ecx
87534840Sjlemon	fillkpt(R(_vm86pa), $PG_RW|PG_U)
87634840Sjlemon
87734840Sjlemon/* ...likewise for the ISA hole */
87834840Sjlemon	movl	$ISA_HOLE_START, %eax
87934840Sjlemon	movl	$ISA_HOLE_START>>PAGE_SHIFT, %ebx
88034840Sjlemon	movl	$ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx
88134840Sjlemon	fillkpt(R(_vm86pa), $PG_RW|PG_U)
88234840Sjlemon#endif /* VM86 */
88334840Sjlemon
88426812Speter#ifdef SMP
88526812Speter/* Map cpu0's private page into global kmem (4K @ cpu0prvpage) */
88625164Speter	movl	R(cpu0pp), %eax
88725164Speter	movl	$1, %ecx
88825164Speter	fillkptphys($PG_RW)
88925164Speter
89026812Speter/* Map cpu0's private page table into global kmem FWIW */
89125164Speter	movl	R(cpu0pt), %eax
89225164Speter	movl	$1, %ecx
89325164Speter	fillkptphys($PG_RW)
89425164Speter
89526812Speter/* Map the private page into the private page table into private space */
89625164Speter	movl	R(cpu0pp), %eax
89725164Speter	movl	$0, %ebx		/* pte offset = 0 */
89825164Speter	movl	$1, %ecx		/* one private page coming right up */
89925164Speter	fillkpt(R(cpu0pt), $PG_RW)
90025164Speter
90126812Speter/* Map the page table page into private space */
90226812Speter	movl	R(cpu0pt), %eax
90325164Speter	movl	$1, %ebx		/* pte offset = 1 */
90426812Speter	movl	$1, %ecx		/* one private pt coming right up */
90526812Speter	fillkpt(R(cpu0pt), $PG_RW)
90625164Speter
90726812Speter/* ... and put the page table table in the pde. */
90825164Speter	movl	R(cpu0pt), %eax
90925164Speter	movl	$MPPTDI, %ebx
91025164Speter	movl	$1, %ecx
91125164Speter	fillkpt(R(_IdlePTD), $PG_RW)
91234840Sjlemon
91334840Sjlemon/* Fakeup VA for the local apic to allow early traps. */
91434840Sjlemon	ALLOCPAGES(1)
91534840Sjlemon	movl	%esi, %eax
91634840Sjlemon	movl	$2, %ebx		/* pte offset = 2 */
91734840Sjlemon	movl	$1, %ecx		/* one private pt coming right up */
91834840Sjlemon	fillkpt(R(cpu0pt), $PG_RW)
91934840Sjlemon
92034840Sjlemon/* Initialize mp lock to allow early traps */
92134840Sjlemon	movl	$1, R(_mp_lock)
92234840Sjlemon
92335072Speter/* Initialize my_idlePTD to IdlePTD */
92434840Sjlemon	movl	R(cpu0pp), %eax
92534840Sjlemon	movl	R(_IdlePTD), %ecx
92635072Speter	movl	%ecx,GD_MY_IDLEPTD(%eax)
92739702Stegge/* Initialize IdlePTDS[0] */
92839702Stegge	addl	$KERNBASE, %ecx
92939702Stegge	movl	%ecx, R(CNAME(IdlePTDS))
93034840Sjlemon
93126812Speter#endif	/* SMP */
93225164Speter
93315392Sphk/* install a pde for temporary double map of bottom of VA */
93415392Sphk	movl	R(_KPTphys), %eax
93515565Sphk	xorl	%ebx, %ebx
93615565Sphk	movl	$1, %ecx
93719621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9384Srgrimes
93915392Sphk/* install pde's for pt's */
94015392Sphk	movl	R(_KPTphys), %eax
94115565Sphk	movl	$KPTDI, %ebx
94215565Sphk	movl	$NKPT, %ecx
94319621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9444Srgrimes
94515392Sphk/* install a pde recursively mapping page directory as a page table */
94615565Sphk	movl	R(_IdlePTD), %eax
94715565Sphk	movl	$PTDPTDI, %ebx
94815565Sphk	movl	$1,%ecx
94919621Sdyson	fillkpt(R(_IdlePTD), $PG_RW)
9504Srgrimes
9514Srgrimes	ret
95215428Sphk
95315428Sphk#ifdef BDE_DEBUGGER
95415428Sphkbdb_prepare_paging:
95515428Sphk	cmpl	$0,R(_bdb_exists)
95615428Sphk	je	bdb_prepare_paging_exit
95715428Sphk
95815428Sphk	subl	$6,%esp
95915428Sphk
96015428Sphk	/*
96115428Sphk	 * Copy and convert debugger entries from the bootstrap gdt and idt
96215428Sphk	 * to the kernel gdt and idt.  Everything is still in low memory.
96315428Sphk	 * Tracing continues to work after paging is enabled because the
96415428Sphk	 * low memory addresses remain valid until everything is relocated.
96515428Sphk	 * However, tracing through the setidt() that initializes the trace
96615428Sphk	 * trap will crash.
96715428Sphk	 */
96815428Sphk	sgdt	(%esp)
96915428Sphk	movl	2(%esp),%esi		/* base address of bootstrap gdt */
97015428Sphk	movl	$R(_gdt),%edi
97115428Sphk	movl	%edi,2(%esp)		/* prepare to load kernel gdt */
97215428Sphk	movl	$8*18/4,%ecx
97315428Sphk	cld
97415428Sphk	rep				/* copy gdt */
97515428Sphk	movsl
97615428Sphk	movl	$R(_gdt),-8+2(%edi)	/* adjust gdt self-ptr */
97715428Sphk	movb	$0x92,-8+5(%edi)
97815428Sphk	lgdt	(%esp)
97915428Sphk
98015428Sphk	sidt	(%esp)
98115428Sphk	movl	2(%esp),%esi		/* base address of current idt */
98215428Sphk	movl	8+4(%esi),%eax		/* convert dbg descriptor to ... */
98315428Sphk	movw	8(%esi),%ax
98415428Sphk	movl	%eax,R(bdb_dbg_ljmp+1)	/* ... immediate offset ... */
98515428Sphk	movl	8+2(%esi),%eax
98615428Sphk	movw	%ax,R(bdb_dbg_ljmp+5)	/* ... and selector for ljmp */
98715428Sphk	movl	24+4(%esi),%eax		/* same for bpt descriptor */
98815428Sphk	movw	24(%esi),%ax
98915428Sphk	movl	%eax,R(bdb_bpt_ljmp+1)
99015428Sphk	movl	24+2(%esi),%eax
99115428Sphk	movw	%ax,R(bdb_bpt_ljmp+5)
99215428Sphk	movl	$R(_idt),%edi
99315428Sphk	movl	%edi,2(%esp)		/* prepare to load kernel idt */
99415428Sphk	movl	$8*4/4,%ecx
99515428Sphk	cld
99615428Sphk	rep				/* copy idt */
99715428Sphk	movsl
99815428Sphk	lidt	(%esp)
99915428Sphk
100015428Sphk	addl	$6,%esp
100115428Sphk
100215428Sphkbdb_prepare_paging_exit:
100315428Sphk	ret
100415428Sphk
100515428Sphk/* Relocate debugger gdt entries and gdt and idt pointers. */
100615428Sphkbdb_commit_paging:
100715428Sphk	cmpl	$0,_bdb_exists
100815428Sphk	je	bdb_commit_paging_exit
100915428Sphk
101015428Sphk	movl	$_gdt+8*9,%eax		/* adjust slots 9-17 */
101115428Sphk	movl	$9,%ecx
101215428Sphkreloc_gdt:
101315428Sphk	movb	$KERNBASE>>24,7(%eax)	/* top byte of base addresses, was 0, */
101415428Sphk	addl	$8,%eax			/* now KERNBASE>>24 */
101515428Sphk	loop	reloc_gdt
101615428Sphk
101715428Sphk	subl	$6,%esp
101815428Sphk	sgdt	(%esp)
101915428Sphk	addl	$KERNBASE,2(%esp)
102015428Sphk	lgdt	(%esp)
102115428Sphk	sidt	(%esp)
102215428Sphk	addl	$KERNBASE,2(%esp)
102315428Sphk	lidt	(%esp)
102415428Sphk	addl	$6,%esp
102515428Sphk
102615428Sphk	int	$3
102715428Sphk
102815428Sphkbdb_commit_paging_exit:
102915428Sphk	ret
103015428Sphk
103115428Sphk#endif /* BDE_DEBUGGER */
1032