diff options
author | jhb <jhb@FreeBSD.org> | 2000-03-28 01:19:53 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2000-03-28 01:19:53 +0000 |
commit | 528aa61b66be7424fac05f2fa6d1fd5fd7686cf5 (patch) | |
tree | 364e8745a006cd38befef351f673c4aee245b840 /sys/boot/i386/btx | |
parent | 5a96429bd9b5a44415f952c5f06ee1e632916e0c (diff) | |
download | FreeBSD-src-528aa61b66be7424fac05f2fa6d1fd5fd7686cf5.zip FreeBSD-src-528aa61b66be7424fac05f2fa6d1fd5fd7686cf5.tar.gz |
Mega i386 loader commit.
- Don't hard code 0x10000 as the entry point for the loader. Instead add
src/sys/boot/i386/Makefile.inc which defines a make variable with the
entry point for the loader. Move the loader's entry point up to
0x20000, which makes PXE happy.
- Don't try to use cpp to parse btxldr for the optional BTXLDR_VERBOSE,
instead use m4 to achieve this. Also, add a BTXLDR_VERBOSE knob in the
btxldr Makefile to turn this option on.
- Redo parts of cdldr's Makefile so that it now builds and installs cdboot
instead of having i386/loader/Makefile do that. Also, add in some more
variables to make the pxeldr Makefile almost identical and thus to ease
maintainability.
- Teach cdldr about the a.out format. Cdldr now parsers the a.out header
of the loader binary and relocates it based on that. The entry point of
the loader no longer has to be hardcoded into cdldr. Also, the boot
info table from mkisofs is no longer required to get a useful cdboot.
- Update the lsdev function for BIOS disks to parse other file systems
(such as DOS FAT) that we currently support. This is still buggy as
it assumes that a floppy with a DOS boot sector actually has a MBR and
parses it as such. I'll be fixing this in the future.
- The biggie: Add in support for booting off of PXE-enabled network
adapters. Currently, we use the TFTP API provided by the PXE BIOS.
Eventually we will switch to using the low-level NIC driver thus
allowing both TFTP and NFS to be used, but for now it's just TFTP.
Submitted by: ps, alfred
Testing by: Benno Rice <benno@netizen.com.au>
Diffstat (limited to 'sys/boot/i386/btx')
-rw-r--r-- | sys/boot/i386/btx/btxldr/Makefile | 16 | ||||
-rw-r--r-- | sys/boot/i386/btx/btxldr/btxldr.S | 100 | ||||
-rw-r--r-- | sys/boot/i386/btx/btxldr/btxldr.s | 100 |
3 files changed, 121 insertions, 95 deletions
diff --git a/sys/boot/i386/btx/btxldr/Makefile b/sys/boot/i386/btx/btxldr/Makefile index 33e6275..0d61889 100644 --- a/sys/boot/i386/btx/btxldr/Makefile +++ b/sys/boot/i386/btx/btxldr/Makefile @@ -1,22 +1,28 @@ # $FreeBSD$ -ORG=0x100000 -AFLAGS+= --assembler-with-cpp +M4?= m4 +M4FLAGS+= -DLOADER_ADDRESS=${LOADER_ADDRESS} + +.if defined(BTXLDR_VERBOSE) +M4FLAGS+= -DBTXLDR_VERBOSE +.endif all: btxldr btxldr: btxldr.o .if ${OBJFORMAT} == aout - ${LD} -nostdlib -N -s -T ${ORG} -o btxldr.out btxldr.o + ${LD} -nostdlib -N -s -T ${LOADER_ADDRESS} -o btxldr.out btxldr.o dd if=btxldr.out of=${.TARGET} ibs=32 skip=1 .else - ${LD} -N -e start -Ttext ${ORG} -o btxldr.out btxldr.o + ${LD} -N -e start -Ttext ${LOADER_ADDRESS} -o btxldr.out btxldr.o objcopy -S -O binary btxldr.out ${.TARGET} .endif btxldr.o: btxldr.s - ${CC} ${AFLAGS} -c -o ${.TARGET} ${.CURDIR}/btxldr.s + (cd ${.CURDIR}; ${M4} ${M4FLAGS} btxldr.s ) | \ + ${AS} ${AFLAGS} -o ${.TARGET} CLEANFILES+= btxldr btxldr.out btxldr.o +.include <${.CURDIR}/../../Makefile.inc> .include <bsd.prog.mk> diff --git a/sys/boot/i386/btx/btxldr/btxldr.S b/sys/boot/i386/btx/btxldr/btxldr.S index d506a62..a1f7ee8 100644 --- a/sys/boot/i386/btx/btxldr/btxldr.S +++ b/sys/boot/i386/btx/btxldr/btxldr.S @@ -27,7 +27,7 @@ .set MEM_ESP,0x1000 # New stack pointer .set MEM_TBL,0x5000 # BTX page tables .set MEM_ENTRY,0x9010 # BTX entry point - .set MEM_DATA,0x101000 # Data segment + .set MEM_DATA,start+0x1000 # Data segment # # Segment selectors. # @@ -57,7 +57,7 @@ # .set SIZ_STUB,0x1a # Size of stub # -# We expect to be loaded by boot2 at 0x100000. +# We expect to be loaded by boot2 at the origin defined in ./Makefile. # .globl start # @@ -69,25 +69,29 @@ start: cld # String ops inc movzwl BDA_MEM,%eax # Get base memory shll $0xa,%eax # in bytes movl %eax,%ebp # Base of user stack +ifdef(`BTXLDR_VERBOSE',` movl $m_mem,%esi # Display - call dhexout # amount of - call dputstr # base memory + call hexout # amount of + call putstr # base memory +') lgdt gdtdesc # Load new GDT # # Relocate caller's arguments. # +ifdef('BTXLDR_VERBOSE',` movl $m_esp,%esi # Display - movl %esp,%eax # caller's - call dhexout # stack - call dputstr # pointer + movl %esp,%eax # caller + call hexout # stack + call putstr # pointer movl $m_args,%esi # Format string leal 0x4(%esp,1),%ebx # First argument movl $0x6,%ecx # Count start.1: movl (%ebx),%eax # Get argument and addl $0x4,%ebx # bump pointer - call dhexout # Display it + call hexout # Display it loop start.1 # Till done - call dputstr # End message + call putstr # End message +') movl $0x48,%ecx # Allocate space subl %ecx,%ebp # for bootinfo movl 0x18(%esp,1),%esi # Source: bootinfo @@ -97,20 +101,24 @@ start.1: movl (%ebx),%eax # Get argument and rep # Copy movsb # it movl %ebp,0x18(%esp,1) # Update pointer +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_bi,%esi # Display movl %ebp,%eax # bootinfo - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') start_null_bi: movl $0x18,%ecx # Allocate space subl %ecx,%ebp # for arguments leal 0x4(%esp,1),%esi # Source movl %ebp,%edi # Destination rep # Copy movsb # them +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_args,%esi # Display movl %ebp,%eax # argument - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') # # Set up BTX kernel. # @@ -139,24 +147,32 @@ start_null_bi: movl $0x18,%ecx # Allocate space incl %edi # BTX shll $0x2,%edi # load addl $MEM_TBL,%edi # address - pushl %edi # Save + pushl %edi # Save load address movzwl 0xa(%ebx),%ecx # Image size - pushl %ecx # Save +ifdef(`BTXLDR_VERBOSE',` + pushl %ecx # Save image size +') rep # Relocate movsb # BTX movl %esi,%ebx # Keep place +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_btx,%esi # Restore popl %eax # parameters - call dhexout # and + call hexout # and +') popl %ebp # display +ifdef(`BTXLDR_VERBOSE',` movl %ebp,%eax # the - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') addl $PAG_SIZ,%ebp # Display +ifdef(`BTXLDR_VERBOSE',` movl $m_base,%esi # the movl %ebp,%eax # user - call dhexout # base - call dputstr # address + call hexout # base + call putstr # address +') # # Set up ELF-format client program. # @@ -165,24 +181,29 @@ start_null_bi: movl $0x18,%ecx # Allocate space movl $e_fmt,%esi # Display error call putstr # message start.2: jmp start.2 # Hang -start.3: movl $m_elf,%esi # Display ELF - call dputstr # message +start.3: +ifdef(`BTXLDR_VERBOSE',` + movl $m_elf,%esi # Display ELF + call putstr # message movl $m_segs,%esi # Format string +') movl $0x2,%edi # Segment count movl 0x1c(%ebx),%edx # Get e_phoff addl %ebx,%edx # To pointer movzwl 0x2c(%ebx),%ecx # Get e_phnum start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD? jne start.6 # No +ifdef(`BTXLDR_VERBOSE',` movl 0x4(%edx),%eax # Display - call dhexout # p_offset + call hexout # p_offset movl 0x8(%edx),%eax # Display - call dhexout # p_vaddr + call hexout # p_vaddr movl 0x10(%edx),%eax # Display - call dhexout # p_filesz + call hexout # p_filesz movl 0x14(%edx),%eax # Display - call dhexout # p_memsz - call dputstr # End message + call hexout # p_memsz + call putstr # End message +') pushl %esi # Save pushl %edi # working pushl %ecx # registers @@ -206,8 +227,11 @@ start.5: popl %ecx # Restore je start.7 # If none start.6: addl $0x20,%edx # To next entry loop start.4 # Till done -start.7: movl $m_done,%esi # Display done - call dputstr # message +start.7: +ifdef(`BTXLDR_VERBOSE',` + movl $m_done,%esi # Display done + call putstr # message +') movl $start.8,%esi # Real mode stub movl $MEM_STUB,%edi # Destination movl $SIZ_STUB,%ecx # Size @@ -231,10 +255,6 @@ start.9: # # Output message [ESI] followed by EAX in hex. # -dhexout: -#ifndef BTXLDR_VERBOSE - ret -#endif hexout: pushl %eax # Save call putstr # Display message popl %eax # Restore @@ -260,12 +280,6 @@ hexout.2: decl %esi # Adjust for inc # # Output zero-terminated string [ESI] to the console. # -dputstr: -#ifndef BTXLDR_VERBOSE - ret -#else - jmp putstr -#endif putstr.0: call putchr # Output char putstr: lodsb # Load char testb %al,%al # End of string? @@ -274,10 +288,6 @@ putstr: lodsb # Load char # # Output character AL to the console. # -dputchr: -#ifndef BTXLDR_VERBOSE - ret -#endif putchr: pusha # Save xorl %ecx,%ecx # Zero for loops movb $SCR_MAT,%ah # Mode/attribute @@ -356,7 +366,7 @@ gdtdesc: .word gdt.1-gdt-1 # Limit m_logo: .asciz " \nBTX loader 1.00 " m_vers: .asciz "BTX version is \0\n" e_fmt: .asciz "Error: Client format not supported\n" -#ifdef BTXLDR_VERBOSE +ifdef(`BTXLDR_VERBOSE',` m_mem: .asciz "Starting in protected mode (base mem=\0)\n" m_esp: .asciz "Arguments passed (esp=\0):\n" m_args: .asciz"<howto=" @@ -379,7 +389,7 @@ m_segs: .asciz "text segment: offset=" .asciz " filesz=" .asciz " memsz=\0\n" m_done: .asciz "Loading complete\n" -#endif +') # # Uninitialized data area. # diff --git a/sys/boot/i386/btx/btxldr/btxldr.s b/sys/boot/i386/btx/btxldr/btxldr.s index d506a62..a1f7ee8 100644 --- a/sys/boot/i386/btx/btxldr/btxldr.s +++ b/sys/boot/i386/btx/btxldr/btxldr.s @@ -27,7 +27,7 @@ .set MEM_ESP,0x1000 # New stack pointer .set MEM_TBL,0x5000 # BTX page tables .set MEM_ENTRY,0x9010 # BTX entry point - .set MEM_DATA,0x101000 # Data segment + .set MEM_DATA,start+0x1000 # Data segment # # Segment selectors. # @@ -57,7 +57,7 @@ # .set SIZ_STUB,0x1a # Size of stub # -# We expect to be loaded by boot2 at 0x100000. +# We expect to be loaded by boot2 at the origin defined in ./Makefile. # .globl start # @@ -69,25 +69,29 @@ start: cld # String ops inc movzwl BDA_MEM,%eax # Get base memory shll $0xa,%eax # in bytes movl %eax,%ebp # Base of user stack +ifdef(`BTXLDR_VERBOSE',` movl $m_mem,%esi # Display - call dhexout # amount of - call dputstr # base memory + call hexout # amount of + call putstr # base memory +') lgdt gdtdesc # Load new GDT # # Relocate caller's arguments. # +ifdef('BTXLDR_VERBOSE',` movl $m_esp,%esi # Display - movl %esp,%eax # caller's - call dhexout # stack - call dputstr # pointer + movl %esp,%eax # caller + call hexout # stack + call putstr # pointer movl $m_args,%esi # Format string leal 0x4(%esp,1),%ebx # First argument movl $0x6,%ecx # Count start.1: movl (%ebx),%eax # Get argument and addl $0x4,%ebx # bump pointer - call dhexout # Display it + call hexout # Display it loop start.1 # Till done - call dputstr # End message + call putstr # End message +') movl $0x48,%ecx # Allocate space subl %ecx,%ebp # for bootinfo movl 0x18(%esp,1),%esi # Source: bootinfo @@ -97,20 +101,24 @@ start.1: movl (%ebx),%eax # Get argument and rep # Copy movsb # it movl %ebp,0x18(%esp,1) # Update pointer +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_bi,%esi # Display movl %ebp,%eax # bootinfo - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') start_null_bi: movl $0x18,%ecx # Allocate space subl %ecx,%ebp # for arguments leal 0x4(%esp,1),%esi # Source movl %ebp,%edi # Destination rep # Copy movsb # them +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_args,%esi # Display movl %ebp,%eax # argument - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') # # Set up BTX kernel. # @@ -139,24 +147,32 @@ start_null_bi: movl $0x18,%ecx # Allocate space incl %edi # BTX shll $0x2,%edi # load addl $MEM_TBL,%edi # address - pushl %edi # Save + pushl %edi # Save load address movzwl 0xa(%ebx),%ecx # Image size - pushl %ecx # Save +ifdef(`BTXLDR_VERBOSE',` + pushl %ecx # Save image size +') rep # Relocate movsb # BTX movl %esi,%ebx # Keep place +ifdef(`BTXLDR_VERBOSE',` movl $m_rel_btx,%esi # Restore popl %eax # parameters - call dhexout # and + call hexout # and +') popl %ebp # display +ifdef(`BTXLDR_VERBOSE',` movl %ebp,%eax # the - call dhexout # relocation - call dputstr # message + call hexout # relocation + call putstr # message +') addl $PAG_SIZ,%ebp # Display +ifdef(`BTXLDR_VERBOSE',` movl $m_base,%esi # the movl %ebp,%eax # user - call dhexout # base - call dputstr # address + call hexout # base + call putstr # address +') # # Set up ELF-format client program. # @@ -165,24 +181,29 @@ start_null_bi: movl $0x18,%ecx # Allocate space movl $e_fmt,%esi # Display error call putstr # message start.2: jmp start.2 # Hang -start.3: movl $m_elf,%esi # Display ELF - call dputstr # message +start.3: +ifdef(`BTXLDR_VERBOSE',` + movl $m_elf,%esi # Display ELF + call putstr # message movl $m_segs,%esi # Format string +') movl $0x2,%edi # Segment count movl 0x1c(%ebx),%edx # Get e_phoff addl %ebx,%edx # To pointer movzwl 0x2c(%ebx),%ecx # Get e_phnum start.4: cmpl $0x1,(%edx) # Is p_type PT_LOAD? jne start.6 # No +ifdef(`BTXLDR_VERBOSE',` movl 0x4(%edx),%eax # Display - call dhexout # p_offset + call hexout # p_offset movl 0x8(%edx),%eax # Display - call dhexout # p_vaddr + call hexout # p_vaddr movl 0x10(%edx),%eax # Display - call dhexout # p_filesz + call hexout # p_filesz movl 0x14(%edx),%eax # Display - call dhexout # p_memsz - call dputstr # End message + call hexout # p_memsz + call putstr # End message +') pushl %esi # Save pushl %edi # working pushl %ecx # registers @@ -206,8 +227,11 @@ start.5: popl %ecx # Restore je start.7 # If none start.6: addl $0x20,%edx # To next entry loop start.4 # Till done -start.7: movl $m_done,%esi # Display done - call dputstr # message +start.7: +ifdef(`BTXLDR_VERBOSE',` + movl $m_done,%esi # Display done + call putstr # message +') movl $start.8,%esi # Real mode stub movl $MEM_STUB,%edi # Destination movl $SIZ_STUB,%ecx # Size @@ -231,10 +255,6 @@ start.9: # # Output message [ESI] followed by EAX in hex. # -dhexout: -#ifndef BTXLDR_VERBOSE - ret -#endif hexout: pushl %eax # Save call putstr # Display message popl %eax # Restore @@ -260,12 +280,6 @@ hexout.2: decl %esi # Adjust for inc # # Output zero-terminated string [ESI] to the console. # -dputstr: -#ifndef BTXLDR_VERBOSE - ret -#else - jmp putstr -#endif putstr.0: call putchr # Output char putstr: lodsb # Load char testb %al,%al # End of string? @@ -274,10 +288,6 @@ putstr: lodsb # Load char # # Output character AL to the console. # -dputchr: -#ifndef BTXLDR_VERBOSE - ret -#endif putchr: pusha # Save xorl %ecx,%ecx # Zero for loops movb $SCR_MAT,%ah # Mode/attribute @@ -356,7 +366,7 @@ gdtdesc: .word gdt.1-gdt-1 # Limit m_logo: .asciz " \nBTX loader 1.00 " m_vers: .asciz "BTX version is \0\n" e_fmt: .asciz "Error: Client format not supported\n" -#ifdef BTXLDR_VERBOSE +ifdef(`BTXLDR_VERBOSE',` m_mem: .asciz "Starting in protected mode (base mem=\0)\n" m_esp: .asciz "Arguments passed (esp=\0):\n" m_args: .asciz"<howto=" @@ -379,7 +389,7 @@ m_segs: .asciz "text segment: offset=" .asciz " filesz=" .asciz " memsz=\0\n" m_done: .asciz "Loading complete\n" -#endif +') # # Uninitialized data area. # |