locore.s revision 34840
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 3734840Sjlemon * $Id: locore.s,v 1.104 1998/01/31 02:53:41 eivind 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" 4818842Sbde#include "opt_cpu.h" 4913228Swollman#include "opt_ddb.h" 5032917Seivind#include "opt_nfs.h" 5118702Sjkh#include "opt_userconfig.h" 5230265Speter#include "opt_vm86.h" 5314835Sbde 5414835Sbde#include <sys/syscall.h> 555908Sbde#include <sys/reboot.h> 564Srgrimes 5714835Sbde#include <machine/asmacros.h> 5814835Sbde#include <machine/cputypes.h> 5914835Sbde#include <machine/psl.h> 6015543Sphk#include <machine/pmap.h> 6114835Sbde#include <machine/specialreg.h> 6214835Sbde 6314835Sbde#include "assym.s" 6414835Sbde 654Srgrimes/* 66757Sdg * XXX 67757Sdg * 684Srgrimes * Note: This version greatly munged to avoid various assembler errors 694Srgrimes * that may be fixed in newer versions of gas. Perhaps newer versions 704Srgrimes * will have more pleasant appearance. 714Srgrimes */ 724Srgrimes 73200Sdg/* 744Srgrimes * PTmap is recursive pagemap at top of virtual address space. 754Srgrimes * Within PTmap, the page directory can be found (third indirection). 764Srgrimes */ 773861Sbde .globl _PTmap,_PTD,_PTDpde 7815543Sphk .set _PTmap,(PTDPTDI << PDRSHIFT) 7915543Sphk .set _PTD,_PTmap + (PTDPTDI * PAGE_SIZE) 80757Sdg .set _PTDpde,_PTD + (PTDPTDI * PDESIZE) 81592Srgrimes 823861Sbde/* 834Srgrimes * APTmap, APTD is the alternate recursive pagemap. 844Srgrimes * It's used when modifying another process's page tables. 854Srgrimes */ 86592Srgrimes .globl _APTmap,_APTD,_APTDpde 87592Srgrimes .set _APTmap,APTDPTDI << PDRSHIFT 8815543Sphk .set _APTD,_APTmap + (APTDPTDI * PAGE_SIZE) 89757Sdg .set _APTDpde,_PTD + (APTDPTDI * PDESIZE) 904Srgrimes 9126812Speter#ifdef SMP 9226812Speter .globl _SMP_prvstart 9326812Speter .set _SMP_prvstart,(MPPTDI << PDRSHIFT) 9426812Speter 9526812Speter .globl _SMP_prvpage,_SMP_prvpt,_lapic,_SMP_ioapic 9628808Speter .globl _prv_CPAGE1,_prv_CPAGE2,_prv_CPAGE3 9728808Speter .globl _idlestack,_idlestack_top 9826812Speter .set _SMP_prvpage,_SMP_prvstart 9926812Speter .set _SMP_prvpt,_SMP_prvstart + PAGE_SIZE 10026812Speter .set _lapic,_SMP_prvstart + (2 * PAGE_SIZE) 10128808Speter .set _idlestack,_SMP_prvstart + (3 * PAGE_SIZE) 10231030Stegge .set _idlestack_top,_SMP_prvstart + (( 3 + UPAGES) * PAGE_SIZE) 10331030Stegge .set _prv_CPAGE1,_SMP_prvstart + ((3 + UPAGES) * PAGE_SIZE) 10431030Stegge .set _prv_CPAGE2,_SMP_prvstart + ((4 + UPAGES) * PAGE_SIZE) 10531030Stegge .set _prv_CPAGE3,_SMP_prvstart + ((5 + UPAGES) * PAGE_SIZE) 10626812Speter .set _SMP_ioapic,_SMP_prvstart + (16 * PAGE_SIZE) 10726812Speter 10826812Speter .globl _cpuid,_curproc,_curpcb,_npxproc,_runtime,_cpu_lockid 10928808Speter .globl _common_tss,_other_cpus,_my_idlePTD,_ss_tpr 11028808Speter .globl _prv_CMAP1,_prv_CMAP2,_prv_CMAP3 11129213Sfsmp .globl _inside_intr 11228808Speter .set _cpuid,_SMP_prvpage+0 /* [0] */ 11328808Speter .set _curproc,_SMP_prvpage+4 /* [1] */ 11428808Speter .set _curpcb,_SMP_prvpage+8 /* [2] */ 11528808Speter .set _npxproc,_SMP_prvpage+12 /* [3] */ 11628808Speter .set _runtime,_SMP_prvpage+16 /* [4,5] */ 11728808Speter .set _cpu_lockid,_SMP_prvpage+24 /* [6] */ 11828808Speter .set _other_cpus,_SMP_prvpage+28 /* [7] bitmap of available CPUs, 11927003Sfsmp excluding ourself */ 12028808Speter .set _my_idlePTD,_SMP_prvpage+32 /* [8] */ 12128808Speter .set _ss_tpr,_SMP_prvpage+36 /* [9] */ 12228808Speter .set _prv_CMAP1,_SMP_prvpage+40 /* [10] */ 12328808Speter .set _prv_CMAP2,_SMP_prvpage+44 /* [11] */ 12428808Speter .set _prv_CMAP3,_SMP_prvpage+48 /* [12] */ 12529213Sfsmp .set _inside_intr,_SMP_prvpage+52 /* [13] */ 12629213Sfsmp .set _common_tss,_SMP_prvpage+56 /* 102 (ie: 104) bytes long */ 12728808Speter 12829663Speter#ifdef VM86 12929663Speter .globl _common_tssd 13029663Speter .set _common_tssd,_common_tss+104 /* 8 bytes long */ 13129663Speter .globl _private_tss 13229663Speter .set _private_tss,_common_tss+112 13329663Speter .globl _my_tr 13429663Speter .set _my_tr,_common_tss+116 13529663Speter#endif 13629663Speter 13726812Speter/* Fetch the .set's for the local apic */ 13826812Speter#include "i386/i386/mp_apicdefs.s" 13926812Speter 14026812Speter#endif 14126812Speter 1424Srgrimes/* 143556Srgrimes * Globals 144556Srgrimes */ 145556Srgrimes .data 14614835Sbde ALIGN_DATA /* just to be sure */ 147134Sdg 14825083Sjdp .globl HIDENAME(tmpstk) 14913729Sdg .space 0x2000 /* space for tmpstk - temporary stack */ 15025083SjdpHIDENAME(tmpstk): 1513842Sdg 1523861Sbde .globl _boothowto,_bootdev 153134Sdg 15415565Sphk .globl _cpu,_cpu_vendor,_cpu_id,_bootinfo 1556308Sphk .globl _cpu_high, _cpu_feature 1562783Ssos 157757Sdg_cpu: .long 0 /* are we 386, 386sx, or 486 */ 1582216Sbde_cpu_id: .long 0 /* stepping ID */ 1596308Sphk_cpu_high: .long 0 /* highest arg to CPUID */ 1606308Sphk_cpu_feature: .long 0 /* features */ 1612216Sbde_cpu_vendor: .space 20 /* CPU origin code */ 1625908Sbde_bootinfo: .space BOOTINFO_SIZE /* bootinfo that we can handle */ 1634Srgrimes 164757Sdg_KERNend: .long 0 /* phys addr end of kernel (just after bss) */ 16515428Sphkphysfree: .long 0 /* phys addr of next free page */ 166757Sdg 16726812Speter#ifdef SMP 16825164Spetercpu0pp: .long 0 /* phys addr cpu0 private pg */ 16925164Spetercpu0pt: .long 0 /* phys addr cpu0 private pt */ 17025164Speter 17125164Speter .globl _cpu0prvpage,_cpu0prvpt 17225164Speter_cpu0prvpage: .long 0 /* relocated version */ 17325164Speter_cpu0prvpt: .long 0 /* relocated version */ 17426812Speter#endif /* SMP */ 17525164Speter 1763861Sbde .globl _IdlePTD 177757Sdg_IdlePTD: .long 0 /* phys addr of kernel PTD */ 1783861Sbde 17926812Speter#ifdef SMP 18026812Speter .globl _KPTphys 18126812Speter#endif 182757Sdg_KPTphys: .long 0 /* phys addr of kernel page tables */ 1834Srgrimes 184757Sdg .globl _proc0paddr 185757Sdg_proc0paddr: .long 0 /* address of proc 0 address space */ 18624693Speterp0upa: .long 0 /* phys addr of proc0's UPAGES */ 187134Sdg 18834840Sjlemon#ifdef VM86 18934840Sjlemon .globl _vm86paddr, _vm86pa 19034840Sjlemon_vm86paddr: .long 0 /* address of vm86 region */ 19134840Sjlemon_vm86pa: .long 0 /* phys addr of vm86 region */ 19234840Sjlemon#endif 19334840Sjlemon 19415428Sphk#ifdef BDE_DEBUGGER 19515428Sphk .globl _bdb_exists /* flag to indicate BDE debugger is present */ 19615428Sphk_bdb_exists: .long 0 19715428Sphk#endif 198718Swollman 19915428Sphk 20015392Sphk/********************************************************************** 20115392Sphk * 20215392Sphk * Some handy macros 20315392Sphk * 204556Srgrimes */ 205134Sdg 20615392Sphk#define R(foo) ((foo)-KERNBASE) 20715392Sphk 20815392Sphk#define ALLOCPAGES(foo) \ 20915392Sphk movl R(physfree), %esi ; \ 21015543Sphk movl $((foo)*PAGE_SIZE), %eax ; \ 21115392Sphk addl %esi, %eax ; \ 21215392Sphk movl %eax, R(physfree) ; \ 21315392Sphk movl %esi, %edi ; \ 21415543Sphk movl $((foo)*PAGE_SIZE),%ecx ; \ 21515392Sphk xorl %eax,%eax ; \ 21615428Sphk cld ; \ 21715428Sphk rep ; \ 21815428Sphk stosb 21915392Sphk 220134Sdg/* 22115392Sphk * fillkpt 22215565Sphk * eax = page frame address 22315565Sphk * ebx = index into page table 22415392Sphk * ecx = how many pages to map 22515565Sphk * base = base address of page dir/table 22615565Sphk * prot = protection bits 227134Sdg */ 22815565Sphk#define fillkpt(base, prot) \ 22919621Sdyson shll $2,%ebx ; \ 23019621Sdyson addl base,%ebx ; \ 23119621Sdyson orl $PG_V,%eax ; \ 23219621Sdyson orl prot,%eax ; \ 23315565Sphk1: movl %eax,(%ebx) ; \ 23415565Sphk addl $PAGE_SIZE,%eax ; /* increment physical address */ \ 23515565Sphk addl $4,%ebx ; /* next pte */ \ 23615428Sphk loop 1b 23715392Sphk 23815565Sphk/* 23915565Sphk * fillkptphys(prot) 24015565Sphk * eax = physical address 24115565Sphk * ecx = how many pages to map 24215565Sphk * prot = protection bits 24315565Sphk */ 24415565Sphk#define fillkptphys(prot) \ 24515565Sphk movl %eax, %ebx ; \ 24615565Sphk shrl $PAGE_SHIFT, %ebx ; \ 24715565Sphk fillkpt(R(_KPTphys), prot) 24815565Sphk 24915392Sphk .text 25015392Sphk/********************************************************************** 25115392Sphk * 25215392Sphk * This is where the bootblocks start us, set the ball rolling... 25315392Sphk * 25415392Sphk */ 2551321SdgNON_GPROF_ENTRY(btext) 2564Srgrimes 25724112Skato#ifdef PC98 25824112Skato jmp 1f 25924112Skato .globl _pc98_system_parameter 26024112Skato .org 0x400 26124112Skato_pc98_system_parameter: 26224112Skato .space 0x240 /* BIOS parameter block */ 26324112Skato1: 26424112Skato /* save SYSTEM PARAMETER for resume (NS/T or other) */ 26524112Skato movl $0xa1000,%esi 26624112Skato movl $0x100000,%edi 26724112Skato movl $0x0630,%ecx 26824112Skato cld 26924112Skato rep 27024112Skato movsb 27124112Skato#else /* IBM-PC */ 27215428Sphk#ifdef BDE_DEBUGGER 27315428Sphk#ifdef BIOS_STEALS_3K 27415428Sphk cmpl $0x0375c339,0x95504 27515428Sphk#else 27615428Sphk cmpl $0x0375c339,0x96104 /* XXX - debugger signature */ 27715428Sphk#endif 27815428Sphk jne 1f 27915428Sphk movb $1,R(_bdb_exists) 28015428Sphk1: 28115428Sphk#endif 28215428Sphk 28315392Sphk/* Tell the bios to warmboot next time */ 28415392Sphk movw $0x1234,0x472 28524112Skato#endif /* PC98 */ 28615392Sphk 28715428Sphk/* Set up a real frame in case the double return in newboot is executed. */ 2883384Srgrimes pushl %ebp 2893384Srgrimes movl %esp, %ebp 2903384Srgrimes 29115392Sphk/* Don't trust what the BIOS gives for eflags. */ 2925603Sbde pushl $PSL_KERNEL 2932486Sdg popfl 29415428Sphk 29515428Sphk/* 29615428Sphk * Don't trust what the BIOS gives for %fs and %gs. Trust the bootstrap 29715428Sphk * to set %cs, %ds, %es and %ss. 29815428Sphk */ 29915428Sphk mov %ds, %ax 3004217Sphk mov %ax, %fs 3014217Sphk mov %ax, %gs 3024217Sphk 30315392Sphk call recover_bootinfo 30415392Sphk 30515428Sphk/* Get onto a stack that we can trust. */ 30615428Sphk/* 30715428Sphk * XXX this step is delayed in case recover_bootinfo needs to return via 30815428Sphk * the old stack, but it need not be, since recover_bootinfo actually 30915428Sphk * returns via the old frame. 31015428Sphk */ 31125083Sjdp movl $R(HIDENAME(tmpstk)),%esp 31215392Sphk 31324112Skato#ifdef PC98 31424112Skato testb $0x02,0x100620 /* pc98_machine_type & M_EPSON_PC98 */ 31524112Skato jz 3f 31624112Skato cmpb $0x0b,0x100624 /* epson_machine_id <= 0x0b */ 31724112Skato ja 3f 31824112Skato 31924112Skato /* count up memory */ 32024112Skato movl $0x100000,%eax /* next, talley remaining memory */ 32124112Skato movl $0xFFF-0x100,%ecx 32224112Skato1: movl 0(%eax),%ebx /* save location to check */ 32324112Skato movl $0xa55a5aa5,0(%eax) /* write test pattern */ 32424112Skato cmpl $0xa55a5aa5,0(%eax) /* does not check yet for rollover */ 32524112Skato jne 2f 32624112Skato movl %ebx,0(%eax) /* restore memory */ 32724112Skato addl $PAGE_SIZE,%eax 32824112Skato loop 1b 32924112Skato2: subl $0x100000,%eax 33024112Skato shrl $17,%eax 33124112Skato movb %al,0x100401 33224112Skato3: 33324112Skato#endif 33424112Skato 33515392Sphk call identify_cpu 33615392Sphk 33715392Sphk/* clear bss */ 33815428Sphk/* 33917120Sbde * XXX this should be done a little earlier. 34015428Sphk * 34117120Sbde * XXX we don't check that there is memory for our bss and page tables 34217120Sbde * before using it. 34315428Sphk * 34415428Sphk * XXX the boot program somewhat bogusly clears the bss. We still have 34515428Sphk * to do it in case we were unzipped by kzipboot. Then the boot program 34615428Sphk * only clears kzipboot's bss. 34715428Sphk * 34815428Sphk * XXX the gdt and idt are still somewhere in the boot program. We 34915428Sphk * depend on the convention that the boot program is below 1MB and we 35015428Sphk * are above 1MB to keep the gdt and idt away from the bss and page 35117120Sbde * tables. The idt is only used if BDE_DEBUGGER is enabled. 35215428Sphk */ 35315392Sphk movl $R(_end),%ecx 35415392Sphk movl $R(_edata),%edi 35515392Sphk subl %edi,%ecx 35615392Sphk xorl %eax,%eax 35715428Sphk cld 35815428Sphk rep 35915428Sphk stosb 36015392Sphk 36115392Sphk#if NAPM > 0 36215428Sphk/* 36315428Sphk * XXX it's not clear that APM can live in the current environonment. 36415428Sphk * Only pc-relative addressing works. 36515428Sphk */ 36615428Sphk call _apm_setup 36715428Sphk#endif 36815392Sphk 36915392Sphk call create_pagetables 37015392Sphk 37127993Sdyson#ifdef VM86 37227993Sdyson/* 37327993Sdyson * If the CPU has support for VME, turn it on. 37427993Sdyson */ 37527993Sdyson testl $CPUID_VME, R(_cpu_feature) 37627993Sdyson jz 1f 37727993Sdyson movl %cr4, %eax 37827993Sdyson orl $CR4_VME, %eax 37927993Sdyson movl %eax, %cr4 38027993Sdyson1: 38127993Sdyson#endif /* VM86 */ 38227993Sdyson 38315428Sphk#ifdef BDE_DEBUGGER 38415428Sphk/* 38515428Sphk * Adjust as much as possible for paging before enabling paging so that the 38615428Sphk * adjustments can be traced. 38715428Sphk */ 38815428Sphk call bdb_prepare_paging 38915428Sphk#endif 39015428Sphk 39115392Sphk/* Now enable paging */ 39215392Sphk movl R(_IdlePTD), %eax 39315392Sphk movl %eax,%cr3 /* load ptd addr into mmu */ 39415392Sphk movl %cr0,%eax /* get control word */ 39515392Sphk orl $CR0_PE|CR0_PG,%eax /* enable paging */ 39615392Sphk movl %eax,%cr0 /* and let's page NOW! */ 39715392Sphk 39815428Sphk#ifdef BDE_DEBUGGER 39915428Sphk/* 40015428Sphk * Complete the adjustments for paging so that we can keep tracing through 40117120Sbde * initi386() after the low (physical) addresses for the gdt and idt become 40215428Sphk * invalid. 40315428Sphk */ 40415428Sphk call bdb_commit_paging 40515428Sphk#endif 40615428Sphk 40715428Sphk pushl $begin /* jump to high virtualized address */ 40815392Sphk ret 40915392Sphk 41015392Sphk/* now running relocated at KERNBASE where the system is linked to run */ 41115392Sphkbegin: 41215392Sphk /* set up bootstrap stack */ 41324691Speter movl _proc0paddr,%esp /* location of in-kernel pages */ 41424691Speter addl $UPAGES*PAGE_SIZE,%esp /* bootstrap stack end location */ 41515392Sphk xorl %eax,%eax /* mark end of frames */ 41615392Sphk movl %eax,%ebp 41715392Sphk movl _proc0paddr,%eax 41815392Sphk movl _IdlePTD, %esi 41915392Sphk movl %esi,PCB_CR3(%eax) 42015392Sphk 42115392Sphk movl physfree, %esi 42215392Sphk pushl %esi /* value of first for init386(first) */ 42315392Sphk call _init386 /* wire 386 chip for unix operation */ 42415392Sphk popl %esi 42515392Sphk 42615392Sphk .globl __ucodesel,__udatasel 42715392Sphk 42815392Sphk pushl $0 /* unused */ 42915392Sphk pushl __udatasel /* ss */ 43015392Sphk pushl $0 /* esp - filled in by execve() */ 43115392Sphk pushl $PSL_USER /* eflags (IOPL 0, int enab) */ 43215392Sphk pushl __ucodesel /* cs */ 43315392Sphk pushl $0 /* eip - filled in by execve() */ 43415392Sphk subl $(12*4),%esp /* space for rest of registers */ 43515392Sphk 43615392Sphk pushl %esp /* call main with frame pointer */ 43715392Sphk call _main /* autoconfiguration, mountroot etc */ 43815392Sphk 43924691Speter hlt /* never returns to here */ 44015392Sphk 44124691Speter/* 44224691Speter * When starting init, call this to configure the process for user 44324691Speter * mode. This will be inherited by other processes. 44424691Speter */ 44524691SpeterNON_GPROF_ENTRY(prepare_usermode) 44615392Sphk /* 44724112Skato * Now we've run main() and determined what cpu-type we are, we can 44815392Sphk * enable write protection and alignment checking on i486 cpus and 44915392Sphk * above. 45015392Sphk */ 45115392Sphk#if defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU) 45215392Sphk cmpl $CPUCLASS_386,_cpu_class 45315392Sphk je 1f 45415392Sphk movl %cr0,%eax /* get control word */ 45515392Sphk orl $CR0_WP|CR0_AM,%eax /* enable i486 features */ 45615392Sphk movl %eax,%cr0 /* and do it */ 45715428Sphk1: 45815392Sphk#endif 45915392Sphk /* 46015392Sphk * on return from main(), we are process 1 46115392Sphk * set up address space and stack so that we can 'return' to user mode 46215392Sphk */ 46315392Sphk movl __ucodesel,%eax 46415392Sphk movl __udatasel,%ecx 46515392Sphk 46624691Speter#if 0 46715392Sphk movl %cx,%ds 46824691Speter#endif 46915392Sphk movl %cx,%es 47015392Sphk movl %ax,%fs /* double map cs to fs */ 47115392Sphk movl %cx,%gs /* and ds to gs */ 47224691Speter ret /* goto user! */ 47315392Sphk 47424691Speter 47515392Sphk#define LCALL(x,y) .byte 0x9a ; .long y ; .word x 47615392Sphk 47715392Sphk/* 47815392Sphk * Signal trampoline, copied to top of user stack 47915392Sphk */ 48015392SphkNON_GPROF_ENTRY(sigcode) 48115392Sphk call SIGF_HANDLER(%esp) 48215392Sphk lea SIGF_SC(%esp),%eax /* scp (the call may have clobbered the */ 48315392Sphk /* copy at 8(%esp)) */ 48415392Sphk pushl %eax 48515392Sphk pushl %eax /* junk to fake return address */ 48615392Sphk movl $SYS_sigreturn,%eax /* sigreturn() */ 48715392Sphk LCALL(0x7,0) /* enter kernel with args on stack */ 48815392Sphk hlt /* never gets here */ 48925083Sjdp ALIGN_TEXT 49015392Sphk_esigcode: 49115392Sphk 49215392Sphk .data 49315392Sphk .globl _szsigcode 49415392Sphk_szsigcode: 49515392Sphk .long _esigcode-_sigcode 49615428Sphk .text 49715392Sphk 49815392Sphk/********************************************************************** 49915392Sphk * 50015392Sphk * Recover the bootinfo passed to us from the boot program 50115392Sphk * 50215392Sphk */ 50315392Sphkrecover_bootinfo: 50415392Sphk /* 5053284Srgrimes * This code is called in different ways depending on what loaded 5063284Srgrimes * and started the kernel. This is used to detect how we get the 5073284Srgrimes * arguments from the other code and what we do with them. 5083284Srgrimes * 5093284Srgrimes * Old disk boot blocks: 5103284Srgrimes * (*btext)(howto, bootdev, cyloffset, esym); 5113284Srgrimes * [return address == 0, and can NOT be returned to] 5123284Srgrimes * [cyloffset was not supported by the FreeBSD boot code 5133284Srgrimes * and always passed in as 0] 5143284Srgrimes * [esym is also known as total in the boot code, and 5153284Srgrimes * was never properly supported by the FreeBSD boot code] 5163284Srgrimes * 5173284Srgrimes * Old diskless netboot code: 5183284Srgrimes * (*btext)(0,0,0,0,&nfsdiskless,0,0,0); 5193284Srgrimes * [return address != 0, and can NOT be returned to] 5203284Srgrimes * If we are being booted by this code it will NOT work, 5213284Srgrimes * so we are just going to halt if we find this case. 5223284Srgrimes * 5233284Srgrimes * New uniform boot code: 5243284Srgrimes * (*btext)(howto, bootdev, 0, 0, 0, &bootinfo) 5253284Srgrimes * [return address != 0, and can be returned to] 5263284Srgrimes * 5273284Srgrimes * There may seem to be a lot of wasted arguments in here, but 5283384Srgrimes * that is so the newer boot code can still load very old kernels 5293384Srgrimes * and old boot code can load new kernels. 5304Srgrimes */ 5313284Srgrimes 5323284Srgrimes /* 5333284Srgrimes * The old style disk boot blocks fake a frame on the stack and 5343284Srgrimes * did an lret to get here. The frame on the stack has a return 5353284Srgrimes * address of 0. 5363284Srgrimes */ 5373384Srgrimes cmpl $0,4(%ebp) 53815392Sphk je olddiskboot 5393284Srgrimes 5403284Srgrimes /* 5413284Srgrimes * We have some form of return address, so this is either the 5423284Srgrimes * old diskless netboot code, or the new uniform code. That can 54315428Sphk * be detected by looking at the 5th argument, if it is 0 54415428Sphk * we are being booted by the new uniform boot code. 5453284Srgrimes */ 5463384Srgrimes cmpl $0,24(%ebp) 54715392Sphk je newboot 5483284Srgrimes 5493284Srgrimes /* 5503284Srgrimes * Seems we have been loaded by the old diskless boot code, we 5513284Srgrimes * don't stand a chance of running as the diskless structure 5523284Srgrimes * changed considerably between the two, so just halt. 5533284Srgrimes */ 5543284Srgrimes hlt 5553284Srgrimes 5563284Srgrimes /* 5573384Srgrimes * We have been loaded by the new uniform boot code. 55815428Sphk * Let's check the bootinfo version, and if we do not understand 5593384Srgrimes * it we return to the loader with a status of 1 to indicate this error 5603284Srgrimes */ 56115392Sphknewboot: 5623384Srgrimes movl 28(%ebp),%ebx /* &bootinfo.version */ 5635908Sbde movl BI_VERSION(%ebx),%eax 5643384Srgrimes cmpl $1,%eax /* We only understand version 1 */ 5653384Srgrimes je 1f 5663384Srgrimes movl $1,%eax /* Return status */ 5673384Srgrimes leave 56815428Sphk /* 56915428Sphk * XXX this returns to our caller's caller (as is required) since 57015428Sphk * we didn't set up a frame and our caller did. 57115428Sphk */ 5723384Srgrimes ret 5733284Srgrimes 5743384Srgrimes1: 5753284Srgrimes /* 5763384Srgrimes * If we have a kernelname copy it in 5773384Srgrimes */ 5785908Sbde movl BI_KERNELNAME(%ebx),%esi 5793384Srgrimes cmpl $0,%esi 5809344Sdg je 2f /* No kernelname */ 5819344Sdg movl $MAXPATHLEN,%ecx /* Brute force!!! */ 58215926Sphk movl $R(_kernelname),%edi 5839344Sdg cmpb $'/',(%esi) /* Make sure it starts with a slash */ 5849344Sdg je 1f 5859344Sdg movb $'/',(%edi) 5869344Sdg incl %edi 5879344Sdg decl %ecx 5889344Sdg1: 5893384Srgrimes cld 5903384Srgrimes rep 5913384Srgrimes movsb 5923384Srgrimes 5939344Sdg2: 59415428Sphk /* 5955908Sbde * Determine the size of the boot loader's copy of the bootinfo 5965908Sbde * struct. This is impossible to do properly because old versions 5975908Sbde * of the struct don't contain a size field and there are 2 old 5985908Sbde * versions with the same version number. 5994600Sphk */ 6005908Sbde movl $BI_ENDCOMMON,%ecx /* prepare for sizeless version */ 6015908Sbde testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */ 6025908Sbde je got_bi_size /* no, sizeless version */ 6035908Sbde movl BI_SIZE(%ebx),%ecx 6045908Sbdegot_bi_size: 6055908Sbde 60615428Sphk /* 6075908Sbde * Copy the common part of the bootinfo struct 6085908Sbde */ 6094600Sphk movl %ebx,%esi 61015926Sphk movl $R(_bootinfo),%edi 6115908Sbde cmpl $BOOTINFO_SIZE,%ecx 6125908Sbde jbe got_common_bi_size 6134600Sphk movl $BOOTINFO_SIZE,%ecx 6145908Sbdegot_common_bi_size: 6154600Sphk cld 6164600Sphk rep 6174600Sphk movsb 6184600Sphk 6193426Srgrimes#ifdef NFS 62025837Stegge#ifndef BOOTP_NFSV3 6213384Srgrimes /* 6223384Srgrimes * If we have a nfs_diskless structure copy it in 6233384Srgrimes */ 6245908Sbde movl BI_NFS_DISKLESS(%ebx),%esi 6253384Srgrimes cmpl $0,%esi 62615428Sphk je olddiskboot 62715926Sphk movl $R(_nfs_diskless),%edi 6283384Srgrimes movl $NFSDISKLESS_SIZE,%ecx 6293384Srgrimes cld 6303384Srgrimes rep 6313384Srgrimes movsb 63215926Sphk movl $R(_nfs_diskless_valid),%edi 6333795Sphk movl $1,(%edi) 6343406Sdg#endif 63525837Stegge#endif 6363384Srgrimes 6373384Srgrimes /* 6383284Srgrimes * The old style disk boot. 6393284Srgrimes * (*btext)(howto, bootdev, cyloffset, esym); 6403384Srgrimes * Note that the newer boot code just falls into here to pick 6413384Srgrimes * up howto and bootdev, cyloffset and esym are no longer used 6423284Srgrimes */ 64315392Sphkolddiskboot: 6443384Srgrimes movl 8(%ebp),%eax 64515926Sphk movl %eax,R(_boothowto) 6463384Srgrimes movl 12(%ebp),%eax 64715926Sphk movl %eax,R(_bootdev) 6482783Ssos 64918702Sjkh#if defined(USERCONFIG_BOOT) && defined(USERCONFIG) 65018702Sjkh movl $0x10200, %esi 65119772Sjkh movl $R(_userconfig_from_boot),%edi 65218702Sjkh movl $512,%ecx 65318702Sjkh cld 65418702Sjkh rep 65518702Sjkh movsb 65618702Sjkh#endif /* USERCONFIG_BOOT */ 65718702Sjkh 65815392Sphk ret 6593258Sdg 6601321Sdg 66115392Sphk/********************************************************************** 66215392Sphk * 66315392Sphk * Identify the CPU and initialize anything special about it 66415392Sphk * 66515392Sphk */ 66615392Sphkidentify_cpu: 66715392Sphk 6681998Swollman /* Try to toggle alignment check flag; does not exist on 386. */ 6691998Swollman pushfl 6701998Swollman popl %eax 6711998Swollman movl %eax,%ecx 6721998Swollman orl $PSL_AC,%eax 6731998Swollman pushl %eax 6741998Swollman popfl 6751998Swollman pushfl 6761998Swollman popl %eax 6771998Swollman xorl %ecx,%eax 6781998Swollman andl $PSL_AC,%eax 6791998Swollman pushl %ecx 6801998Swollman popfl 6811998Swollman 6821998Swollman testl %eax,%eax 68324112Skato jnz try486 68424112Skato 68524112Skato /* NexGen CPU does not have aligment check flag. */ 68624112Skato pushfl 68724112Skato movl $0x5555, %eax 68824112Skato xorl %edx, %edx 68924112Skato movl $2, %ecx 69024112Skato clc 69124112Skato divl %ecx 69224112Skato jz trynexgen 69324112Skato popfl 69415926Sphk movl $CPU_386,R(_cpu) 69513081Sdg jmp 3f 6961998Swollman 69724112Skatotrynexgen: 69827424Skato popfl 69924112Skato movl $CPU_NX586,R(_cpu) 70024112Skato movl $0x4778654e,R(_cpu_vendor) # store vendor string 70124112Skato movl $0x72446e65,R(_cpu_vendor+4) 70224112Skato movl $0x6e657669,R(_cpu_vendor+8) 70324112Skato movl $0,R(_cpu_vendor+12) 70424112Skato jmp 3f 70524112Skato 70624112Skatotry486: /* Try to toggle identification flag; does not exist on early 486s. */ 7071998Swollman pushfl 7081998Swollman popl %eax 7091998Swollman movl %eax,%ecx 7101998Swollman xorl $PSL_ID,%eax 7111998Swollman pushl %eax 7121998Swollman popfl 7131998Swollman pushfl 7141998Swollman popl %eax 7151998Swollman xorl %ecx,%eax 7161998Swollman andl $PSL_ID,%eax 7171998Swollman pushl %ecx 7181998Swollman popfl 7191998Swollman 7201998Swollman testl %eax,%eax 72124112Skato jnz trycpuid 72215926Sphk movl $CPU_486,R(_cpu) 7232495Spst 72424112Skato /* 72524112Skato * Check Cyrix CPU 72624112Skato * Cyrix CPUs do not change the undefined flags following 72724112Skato * execution of the divide instruction which divides 5 by 2. 72824112Skato * 72924112Skato * Note: CPUID is enabled on M2, so it passes another way. 73024112Skato */ 73124112Skato pushfl 73224112Skato movl $0x5555, %eax 73324112Skato xorl %edx, %edx 73424112Skato movl $2, %ecx 73524112Skato clc 73624112Skato divl %ecx 73724112Skato jnc trycyrix 73824112Skato popfl 73924112Skato jmp 3f /* You may use Intel CPU. */ 7402495Spst 74124112Skatotrycyrix: 74224112Skato popfl 74324112Skato /* 74424112Skato * IBM Bluelighting CPU also doesn't change the undefined flags. 74524112Skato * Because IBM doesn't disclose the information for Bluelighting 74624112Skato * CPU, we couldn't distinguish it from Cyrix's (including IBM 74724112Skato * brand of Cyrix CPUs). 74824112Skato */ 74915926Sphk movl $0x69727943,R(_cpu_vendor) # store vendor string 75024112Skato movl $0x736e4978,R(_cpu_vendor+4) 75124112Skato movl $0x64616574,R(_cpu_vendor+8) 75213014Sdg jmp 3f 7531998Swollman 75424112Skatotrycpuid: /* Use the `cpuid' instruction. */ 7551998Swollman xorl %eax,%eax 7566308Sphk .byte 0x0f,0xa2 # cpuid 0 75715926Sphk movl %eax,R(_cpu_high) # highest capability 75815926Sphk movl %ebx,R(_cpu_vendor) # store vendor string 75915926Sphk movl %edx,R(_cpu_vendor+4) 76015926Sphk movl %ecx,R(_cpu_vendor+8) 76115926Sphk movb $0,R(_cpu_vendor+12) 7621998Swollman 7631998Swollman movl $1,%eax 7646308Sphk .byte 0x0f,0xa2 # cpuid 1 76515926Sphk movl %eax,R(_cpu_id) # store cpu_id 76615926Sphk movl %edx,R(_cpu_feature) # store cpu_feature 7676308Sphk rorl $8,%eax # extract family type 7681998Swollman andl $15,%eax 7691998Swollman cmpl $5,%eax 7701998Swollman jae 1f 7711998Swollman 7721998Swollman /* less than Pentium; must be 486 */ 77315926Sphk movl $CPU_486,R(_cpu) 77413000Sdg jmp 3f 77513000Sdg1: 77613000Sdg /* a Pentium? */ 77713000Sdg cmpl $5,%eax 77813000Sdg jne 2f 77915926Sphk movl $CPU_586,R(_cpu) 78013000Sdg jmp 3f 781556Srgrimes2: 78213000Sdg /* Greater than Pentium...call it a Pentium Pro */ 78315926Sphk movl $CPU_686,R(_cpu) 78413000Sdg3: 78515392Sphk ret 786556Srgrimes 7874Srgrimes 78815392Sphk/********************************************************************** 789570Srgrimes * 79015428Sphk * Create the first page directory and its page tables. 79115392Sphk * 792570Srgrimes */ 793570Srgrimes 79415392Sphkcreate_pagetables: 79515392Sphk 79619621Sdyson testl $CPUID_PGE, R(_cpu_feature) 79719621Sdyson jz 1f 79819621Sdyson movl %cr4, %eax 79919621Sdyson orl $CR4_PGE, %eax 80019621Sdyson movl %eax, %cr4 80119621Sdyson1: 80219621Sdyson 80315428Sphk/* Find end of kernel image (rounded up to a page boundary). */ 80415392Sphk movl $R(_end),%esi 8054Srgrimes 80615392Sphk/* include symbols in "kernel image" if they are loaded and useful */ 8075908Sbde#ifdef DDB 80815392Sphk movl R(_bootinfo+BI_ESYMTAB),%edi 8095908Sbde testl %edi,%edi 81015428Sphk je over_symalloc 8115908Sbde movl %edi,%esi 8125908Sbde movl $KERNBASE,%edi 81315392Sphk addl %edi,R(_bootinfo+BI_SYMTAB) 81415392Sphk addl %edi,R(_bootinfo+BI_ESYMTAB) 81515428Sphkover_symalloc: 8165908Sbde#endif 8175908Sbde 81815565Sphk addl $PAGE_MASK,%esi 81915565Sphk andl $~PAGE_MASK,%esi 82015392Sphk movl %esi,R(_KERNend) /* save end of kernel */ 82115428Sphk movl %esi,R(physfree) /* next free page is at end of kernel */ 822608Srgrimes 82315392Sphk/* Allocate Kernel Page Tables */ 82415392Sphk ALLOCPAGES(NKPT) 82515392Sphk movl %esi,R(_KPTphys) 826757Sdg 82715392Sphk/* Allocate Page Table Directory */ 82815392Sphk ALLOCPAGES(1) 82915392Sphk movl %esi,R(_IdlePTD) 8304Srgrimes 83115392Sphk/* Allocate UPAGES */ 83215392Sphk ALLOCPAGES(UPAGES) 83317120Sbde movl %esi,R(p0upa) 83415392Sphk addl $KERNBASE, %esi 83515392Sphk movl %esi, R(_proc0paddr) 8364Srgrimes 83734840Sjlemon#ifdef VM86 83834840Sjlemon ALLOCPAGES(4) /* IOPAGES + ext + stack */ 83934840Sjlemon movl %esi,R(_vm86pa) 84034840Sjlemon addl $KERNBASE, %esi 84134840Sjlemon movl %esi, R(_vm86paddr) 84234840Sjlemon#endif /* VM86 */ 84334840Sjlemon 84426812Speter#ifdef SMP 84525164Speter/* Allocate cpu0's private data page */ 84625164Speter ALLOCPAGES(1) 84725164Speter movl %esi,R(cpu0pp) 84825164Speter addl $KERNBASE, %esi 84925164Speter movl %esi, R(_cpu0prvpage) /* relocated to KVM space */ 85025164Speter 85125164Speter/* Allocate cpu0's private page table for mapping priv page, apic, etc */ 85225164Speter ALLOCPAGES(1) 85325164Speter movl %esi,R(cpu0pt) 85425164Speter addl $KERNBASE, %esi 85525164Speter movl %esi, R(_cpu0prvpt) /* relocated to KVM space */ 85626812Speter#endif /* SMP */ 85725164Speter 85815392Sphk/* Map read-only from zero to the end of the kernel text section */ 85915565Sphk xorl %eax, %eax 86015428Sphk#ifdef BDE_DEBUGGER 86115428Sphk/* If the debugger is present, actually map everything read-write. */ 86215428Sphk cmpl $0,R(_bdb_exists) 86315428Sphk jne map_read_write 86415428Sphk#endif 86519621Sdyson xorl %edx,%edx 86627484Sdyson 86727484Sdyson#if !defined(SMP) 86819621Sdyson testl $CPUID_PGE, R(_cpu_feature) 86919621Sdyson jz 2f 87019621Sdyson orl $PG_G,%edx 87127484Sdyson#endif 87219621Sdyson 87319621Sdyson2: movl $R(_etext),%ecx 87415565Sphk addl $PAGE_MASK,%ecx 87515565Sphk shrl $PAGE_SHIFT,%ecx 87619621Sdyson fillkptphys(%edx) 877757Sdg 87815392Sphk/* Map read-write, data, bss and symbols */ 87915565Sphk movl $R(_etext),%eax 88015694Sphk addl $PAGE_MASK, %eax 88115694Sphk andl $~PAGE_MASK, %eax 88215428Sphkmap_read_write: 88319621Sdyson movl $PG_RW,%edx 88427484Sdyson#if !defined(SMP) 88519621Sdyson testl $CPUID_PGE, R(_cpu_feature) 88619621Sdyson jz 1f 88719621Sdyson orl $PG_G,%edx 88827484Sdyson#endif 88919621Sdyson 89019621Sdyson1: movl R(_KERNend),%ecx 891757Sdg subl %eax,%ecx 89215543Sphk shrl $PAGE_SHIFT,%ecx 89319621Sdyson fillkptphys(%edx) 894757Sdg 89515428Sphk/* Map page directory. */ 89615392Sphk movl R(_IdlePTD), %eax 89715392Sphk movl $1, %ecx 89819621Sdyson fillkptphys($PG_RW) 899757Sdg 90017120Sbde/* Map proc0's UPAGES in the physical way ... */ 90117120Sbde movl R(p0upa), %eax 90215392Sphk movl $UPAGES, %ecx 90319621Sdyson fillkptphys($PG_RW) 9044Srgrimes 90515565Sphk/* Map ISA hole */ 90615565Sphk movl $ISA_HOLE_START, %eax 90715565Sphk movl $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx 90822130Sdg fillkptphys($PG_RW) 90915565Sphk 91034840Sjlemon#ifdef VM86 91134840Sjlemon/* Map space for the vm86 region */ 91234840Sjlemon movl R(_vm86pa), %eax 91334840Sjlemon movl $4, %ecx 91434840Sjlemon fillkptphys($PG_RW) 91534840Sjlemon 91634840Sjlemon/* Map page 0 into the vm86 page table */ 91734840Sjlemon movl $0, %eax 91834840Sjlemon movl $0, %ebx 91934840Sjlemon movl $1, %ecx 92034840Sjlemon fillkpt(R(_vm86pa), $PG_RW|PG_U) 92134840Sjlemon 92234840Sjlemon/* ...likewise for the ISA hole */ 92334840Sjlemon movl $ISA_HOLE_START, %eax 92434840Sjlemon movl $ISA_HOLE_START>>PAGE_SHIFT, %ebx 92534840Sjlemon movl $ISA_HOLE_LENGTH>>PAGE_SHIFT, %ecx 92634840Sjlemon fillkpt(R(_vm86pa), $PG_RW|PG_U) 92734840Sjlemon#endif /* VM86 */ 92834840Sjlemon 92926812Speter#ifdef SMP 93026812Speter/* Map cpu0's private page into global kmem (4K @ cpu0prvpage) */ 93125164Speter movl R(cpu0pp), %eax 93225164Speter movl $1, %ecx 93325164Speter fillkptphys($PG_RW) 93425164Speter 93526812Speter/* Map cpu0's private page table into global kmem FWIW */ 93625164Speter movl R(cpu0pt), %eax 93725164Speter movl $1, %ecx 93825164Speter fillkptphys($PG_RW) 93925164Speter 94026812Speter/* Map the private page into the private page table into private space */ 94125164Speter movl R(cpu0pp), %eax 94225164Speter movl $0, %ebx /* pte offset = 0 */ 94325164Speter movl $1, %ecx /* one private page coming right up */ 94425164Speter fillkpt(R(cpu0pt), $PG_RW) 94525164Speter 94626812Speter/* Map the page table page into private space */ 94726812Speter movl R(cpu0pt), %eax 94825164Speter movl $1, %ebx /* pte offset = 1 */ 94926812Speter movl $1, %ecx /* one private pt coming right up */ 95026812Speter fillkpt(R(cpu0pt), $PG_RW) 95125164Speter 95226812Speter/* ... and put the page table table in the pde. */ 95325164Speter movl R(cpu0pt), %eax 95425164Speter movl $MPPTDI, %ebx 95525164Speter movl $1, %ecx 95625164Speter fillkpt(R(_IdlePTD), $PG_RW) 95734840Sjlemon 95834840Sjlemon/* Fakeup VA for the local apic to allow early traps. */ 95934840Sjlemon ALLOCPAGES(1) 96034840Sjlemon movl %esi, %eax 96134840Sjlemon movl $2, %ebx /* pte offset = 2 */ 96234840Sjlemon movl $1, %ecx /* one private pt coming right up */ 96334840Sjlemon fillkpt(R(cpu0pt), $PG_RW) 96434840Sjlemon 96534840Sjlemon/* Initialize mp lock to allow early traps */ 96634840Sjlemon movl $1, R(_mp_lock) 96734840Sjlemon 96834840Sjlemon/* Initialize curproc to &proc0 */ 96934840Sjlemon movl R(cpu0pp), %eax 97034840Sjlemon movl $CNAME(proc0), 4(%eax) 97134840Sjlemon 97234840Sjlemon/* Initialize my_idlePTD to IdlePTD */ 97334840Sjlemon movl R(_IdlePTD), %ecx 97434840Sjlemon movl %ecx,32(%eax) 97534840Sjlemon 97626812Speter#endif /* SMP */ 97725164Speter 97815392Sphk/* install a pde for temporary double map of bottom of VA */ 97915392Sphk movl R(_KPTphys), %eax 98015565Sphk xorl %ebx, %ebx 98115565Sphk movl $1, %ecx 98219621Sdyson fillkpt(R(_IdlePTD), $PG_RW) 9834Srgrimes 98415392Sphk/* install pde's for pt's */ 98515392Sphk movl R(_KPTphys), %eax 98615565Sphk movl $KPTDI, %ebx 98715565Sphk movl $NKPT, %ecx 98819621Sdyson fillkpt(R(_IdlePTD), $PG_RW) 9894Srgrimes 99015392Sphk/* install a pde recursively mapping page directory as a page table */ 99115565Sphk movl R(_IdlePTD), %eax 99215565Sphk movl $PTDPTDI, %ebx 99315565Sphk movl $1,%ecx 99419621Sdyson fillkpt(R(_IdlePTD), $PG_RW) 9954Srgrimes 9964Srgrimes ret 99715428Sphk 99815428Sphk#ifdef BDE_DEBUGGER 99915428Sphkbdb_prepare_paging: 100015428Sphk cmpl $0,R(_bdb_exists) 100115428Sphk je bdb_prepare_paging_exit 100215428Sphk 100315428Sphk subl $6,%esp 100415428Sphk 100515428Sphk /* 100615428Sphk * Copy and convert debugger entries from the bootstrap gdt and idt 100715428Sphk * to the kernel gdt and idt. Everything is still in low memory. 100815428Sphk * Tracing continues to work after paging is enabled because the 100915428Sphk * low memory addresses remain valid until everything is relocated. 101015428Sphk * However, tracing through the setidt() that initializes the trace 101115428Sphk * trap will crash. 101215428Sphk */ 101315428Sphk sgdt (%esp) 101415428Sphk movl 2(%esp),%esi /* base address of bootstrap gdt */ 101515428Sphk movl $R(_gdt),%edi 101615428Sphk movl %edi,2(%esp) /* prepare to load kernel gdt */ 101715428Sphk movl $8*18/4,%ecx 101815428Sphk cld 101915428Sphk rep /* copy gdt */ 102015428Sphk movsl 102115428Sphk movl $R(_gdt),-8+2(%edi) /* adjust gdt self-ptr */ 102215428Sphk movb $0x92,-8+5(%edi) 102315428Sphk lgdt (%esp) 102415428Sphk 102515428Sphk sidt (%esp) 102615428Sphk movl 2(%esp),%esi /* base address of current idt */ 102715428Sphk movl 8+4(%esi),%eax /* convert dbg descriptor to ... */ 102815428Sphk movw 8(%esi),%ax 102915428Sphk movl %eax,R(bdb_dbg_ljmp+1) /* ... immediate offset ... */ 103015428Sphk movl 8+2(%esi),%eax 103115428Sphk movw %ax,R(bdb_dbg_ljmp+5) /* ... and selector for ljmp */ 103215428Sphk movl 24+4(%esi),%eax /* same for bpt descriptor */ 103315428Sphk movw 24(%esi),%ax 103415428Sphk movl %eax,R(bdb_bpt_ljmp+1) 103515428Sphk movl 24+2(%esi),%eax 103615428Sphk movw %ax,R(bdb_bpt_ljmp+5) 103715428Sphk movl $R(_idt),%edi 103815428Sphk movl %edi,2(%esp) /* prepare to load kernel idt */ 103915428Sphk movl $8*4/4,%ecx 104015428Sphk cld 104115428Sphk rep /* copy idt */ 104215428Sphk movsl 104315428Sphk lidt (%esp) 104415428Sphk 104515428Sphk addl $6,%esp 104615428Sphk 104715428Sphkbdb_prepare_paging_exit: 104815428Sphk ret 104915428Sphk 105015428Sphk/* Relocate debugger gdt entries and gdt and idt pointers. */ 105115428Sphkbdb_commit_paging: 105215428Sphk cmpl $0,_bdb_exists 105315428Sphk je bdb_commit_paging_exit 105415428Sphk 105515428Sphk movl $_gdt+8*9,%eax /* adjust slots 9-17 */ 105615428Sphk movl $9,%ecx 105715428Sphkreloc_gdt: 105815428Sphk movb $KERNBASE>>24,7(%eax) /* top byte of base addresses, was 0, */ 105915428Sphk addl $8,%eax /* now KERNBASE>>24 */ 106015428Sphk loop reloc_gdt 106115428Sphk 106215428Sphk subl $6,%esp 106315428Sphk sgdt (%esp) 106415428Sphk addl $KERNBASE,2(%esp) 106515428Sphk lgdt (%esp) 106615428Sphk sidt (%esp) 106715428Sphk addl $KERNBASE,2(%esp) 106815428Sphk lidt (%esp) 106915428Sphk addl $6,%esp 107015428Sphk 107115428Sphk int $3 107215428Sphk 107315428Sphkbdb_commit_paging_exit: 107415428Sphk ret 107515428Sphk 107615428Sphk#endif /* BDE_DEBUGGER */ 1077