Handle most of the address fixups during bootstrap with a macro.

This commit is contained in:
mycroft 1995-06-02 18:14:04 +00:00
parent c86cba88fe
commit d4e9fde6e5

View File

@ -1,4 +1,4 @@
/* $NetBSD: locore.s,v 1.132 1995/05/07 03:16:16 mycroft Exp $ */ /* $NetBSD: locore.s,v 1.133 1995/06/02 18:14:04 mycroft Exp $ */
#undef DIAGNOSTIC #undef DIAGNOSTIC
#define DIAGNOSTIC #define DIAGNOSTIC
@ -161,6 +161,9 @@ _proc0paddr: .long 0
.space 512 .space 512
tmpstk: tmpstk:
#define RELOC(x) ((x) - KERNBASE)
.text .text
.globl start .globl start
start: movw $0x1234,0x472 # warm boot start: movw $0x1234,0x472 # warm boot
@ -171,16 +174,16 @@ start: movw $0x1234,0x472 # warm boot
* (If we want to hold onto /boot, it's physical %esp up to _end.) * (If we want to hold onto /boot, it's physical %esp up to _end.)
*/ */
movl 4(%esp),%eax movl 4(%esp),%eax
movl %eax,_boothowto-KERNBASE movl %eax,RELOC(_boothowto)
movl 8(%esp),%eax movl 8(%esp),%eax
movl %eax,_bootdev-KERNBASE movl %eax,RELOC(_bootdev)
movl 12(%esp),%eax movl 12(%esp),%eax
movl %eax,_cyloffset-KERNBASE movl %eax,RELOC(_cyloffset)
movl 16(%esp),%eax movl 16(%esp),%eax
testl %eax,%eax testl %eax,%eax
jz 1f jz 1f
addl $(KERNBASE),%eax addl $KERNBASE,%eax
1: movl %eax,_esym-KERNBASE 1: movl %eax,RELOC(_esym)
/* First, reset the PSL. */ /* First, reset the PSL. */
pushl $PSL_MBO pushl $PSL_MBO
@ -204,7 +207,7 @@ try386: /* Try to toggle alignment check flag; does not exist on 386. */
testl %eax,%eax testl %eax,%eax
jnz try486 jnz try486
movl $CPU_386,_cpu-KERNBASE movl $CPU_386,RELOC(_cpu)
jmp 2f jmp 2f
try486: /* Try to toggle identification flag; does not exist on early 486s. */ try486: /* Try to toggle identification flag; does not exist on early 486s. */
@ -223,7 +226,7 @@ try486: /* Try to toggle identification flag; does not exist on early 486s. */
testl %eax,%eax testl %eax,%eax
jnz try586 jnz try586
is486: movl $CPU_486,_cpu-KERNBASE is486: movl $CPU_486,RELOC(_cpu)
/* /*
* Check for Cyrix CPU by seeing if the flags change during a divide. * Check for Cyrix CPU by seeing if the flags change during a divide.
@ -242,9 +245,9 @@ is486: movl $CPU_486,_cpu-KERNBASE
testl $0x8d5,%eax # only check C|PF|AF|Z|N|V testl $0x8d5,%eax # only check C|PF|AF|Z|N|V
jne 2f # yes; must not be Cyrix CPU jne 2f # yes; must not be Cyrix CPU
movl $CPU_486DLC,_cpu-KERNBASE # set CPU type movl $CPU_486DLC,RELOC(_cpu) # set CPU type
movl $0x69727943,_cpu_vendor-KERNBASE # store vendor string movl $0x69727943,RELOC(_cpu_vendor) # store vendor string
movw $0x0078,_cpu_vendor-KERNBASE+4 movb $0x78,RELOC(_cpu_vendor)+4
#ifndef CYRIX_CACHE_WORKS #ifndef CYRIX_CACHE_WORKS
/* Disable caching of the ISA hole only. */ /* Disable caching of the ISA hole only. */
@ -308,10 +311,9 @@ is486: movl $CPU_486,_cpu-KERNBASE
try586: /* Use the `cpuid' instruction. */ try586: /* Use the `cpuid' instruction. */
xorl %eax,%eax xorl %eax,%eax
cpuid cpuid
movl %ebx,_cpu_vendor-KERNBASE # store vendor string movl %ebx,RELOC(_cpu_vendor) # store vendor string
movl %edx,_cpu_vendor-KERNBASE+4 movl %edx,RELOC(_cpu_vendor)+4
movl %ecx,_cpu_vendor-KERNBASE+8 movl %ecx,RELOC(_cpu_vendor)+8
movb $0,_cpu_vendor-KERNBASE+12
movl $1,%eax movl $1,%eax
cpuid cpuid
@ -319,7 +321,7 @@ try586: /* Use the `cpuid' instruction. */
andl $15,%eax andl $15,%eax
cmpl $5,%eax cmpl $5,%eax
jb is486 # less than a Pentium jb is486 # less than a Pentium
movl $CPU_586,_cpu-KERNBASE movl $CPU_586,RELOC(_cpu)
2: 2:
/* /*
@ -334,7 +336,7 @@ try586: /* Use the `cpuid' instruction. */
* Oops, the gdt is in the carcass of the boot program so clearing * Oops, the gdt is in the carcass of the boot program so clearing
* the rest of memory is still not possible. * the rest of memory is still not possible.
*/ */
movl $(tmpstk-KERNBASE),%esp # bootstrap stack end location movl $RELOC(tmpstk),%esp # bootstrap stack end location
/* /*
* Virtual address space of kernel: * Virtual address space of kernel:
@ -349,7 +351,7 @@ try586: /* Use the `cpuid' instruction. */
#define TABLESIZE ((2+UPAGES+NKPDE) * NBPG) #define TABLESIZE ((2+UPAGES+NKPDE) * NBPG)
/* Clear the BSS. */ /* Clear the BSS. */
movl $(_edata-KERNBASE),%edi movl $RELOC(_edata),%edi
movl $(((_end-_edata)+3)>>2),%ecx movl $(((_end-_edata)+3)>>2),%ecx
xorl %eax,%eax xorl %eax,%eax
cld cld
@ -357,10 +359,10 @@ try586: /* Use the `cpuid' instruction. */
stosl stosl
/* Find end of kernel image. */ /* Find end of kernel image. */
movl $(_end-KERNBASE),%edi movl $RELOC(_end),%edi
#if defined(DDB) && !defined(SYMTAB_SPACE) #if defined(DDB) && !defined(SYMTAB_SPACE)
/* Save the symbols (if loaded). */ /* Save the symbols (if loaded). */
movl _esym-KERNBASE,%eax movl RELOC(_esym),%eax
testl %eax,%eax testl %eax,%eax
jz 1f jz 1f
subl $KERNBASE,%eax subl $KERNBASE,%eax
@ -398,11 +400,11 @@ try586: /* Use the `cpuid' instruction. */
* Build initial page tables. * Build initial page tables.
*/ */
/* Calculate end of text segment, rounded to a page. */ /* Calculate end of text segment, rounded to a page. */
leal (_etext-KERNBASE+PGOFSET),%edx leal (RELOC(_etext)+PGOFSET),%edx
andl $~PGOFSET,%edx andl $~PGOFSET,%edx
/* Skip over the first 1MB. */ /* Skip over the first 1MB. */
movl $(KERNTEXTOFF-KERNBASE),%eax movl $RELOC(KERNTEXTOFF),%eax
movl %eax,%ecx movl %eax,%ecx
shrl $PGSHIFT,%ecx shrl $PGSHIFT,%ecx
leal (SYSMAP)(%esi,%ecx,4),%ebx leal (SYSMAP)(%esi,%ecx,4),%ebx
@ -433,7 +435,7 @@ try586: /* Use the `cpuid' instruction. */
/* Map proc 0's kernel stack into user page table page. */ /* Map proc 0's kernel stack into user page table page. */
movl $UPAGES,%ecx # for this many pte s, movl $UPAGES,%ecx # for this many pte s,
leal (PROC0STACK+KERNBASE)(%esi),%edx leal (PROC0STACK+KERNBASE)(%esi),%edx
movl %edx,_proc0paddr-KERNBASE # remember VA for 0th process init movl %edx,RELOC(_proc0paddr) # remember VA for 0th process init
leal (PROC0STACK+PG_V|PG_KW)(%esi),%eax # physical address in proc 0 leal (PROC0STACK+PG_V|PG_KW)(%esi),%eax # physical address in proc 0
leal (PROC0STACKMAP+NBPG-UPAGES*4)(%esi),%ebx # physical address of stack pt in proc 0 leal (PROC0STACKMAP+NBPG-UPAGES*4)(%esi),%ebx # physical address of stack pt in proc 0
fillkpt fillkpt