From a1939ee42390e6442671aa013a03a41aac61c4f7 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Tue, 24 Oct 2006 20:53:30 +0000 Subject: [PATCH] Modified the pxe_ia32 stage 1 loader to load stage 2 at the same address as bios_ia32 stage 1 does. This allowes to actually execute the boot loader now. Need to use Ingo's remote_disk_server now for booting. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19113 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuPXE | 4 +- .../boot/platform/pxe_ia32/bios_drive.h | 1 + .../platform/pxe_ia32/platform_kernel_args.h | 1 + .../platform/pxe_ia32/platform_stage2_args.h | 1 + src/system/boot/platform/pxe_ia32/Jamfile | 19 ++++++- .../boot/platform/pxe_ia32/pxe_stage1.S | 57 ++++++++++++------- .../boot/platform/pxe_ia32/pxe_stage2.S | 11 ++-- .../ldscripts/x86/boot_loader_pxe_ia32.ld | 2 +- 8 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 headers/private/kernel/boot/platform/pxe_ia32/bios_drive.h create mode 100644 headers/private/kernel/boot/platform/pxe_ia32/platform_kernel_args.h create mode 100644 headers/private/kernel/boot/platform/pxe_ia32/platform_stage2_args.h diff --git a/build/jam/HaikuPXE b/build/jam/HaikuPXE index b847d76c9c..a4e180883c 100644 --- a/build/jam/HaikuPXE +++ b/build/jam/HaikuPXE @@ -1,4 +1,6 @@ NotFile pxehaiku ; +Depends pxehaiku : pxe_stage1.bin ; -NotFile haiku-pxe-image ; +NotFile haiku-pxe-loader ; +Depends pxehaiku : zbeos ; diff --git a/headers/private/kernel/boot/platform/pxe_ia32/bios_drive.h b/headers/private/kernel/boot/platform/pxe_ia32/bios_drive.h new file mode 100644 index 0000000000..5a79643a95 --- /dev/null +++ b/headers/private/kernel/boot/platform/pxe_ia32/bios_drive.h @@ -0,0 +1 @@ +#include "../bios_ia32/bios_drive.h" diff --git a/headers/private/kernel/boot/platform/pxe_ia32/platform_kernel_args.h b/headers/private/kernel/boot/platform/pxe_ia32/platform_kernel_args.h new file mode 100644 index 0000000000..5328cc7859 --- /dev/null +++ b/headers/private/kernel/boot/platform/pxe_ia32/platform_kernel_args.h @@ -0,0 +1 @@ +#include "../bios_ia32/platform_kernel_args.h" diff --git a/headers/private/kernel/boot/platform/pxe_ia32/platform_stage2_args.h b/headers/private/kernel/boot/platform/pxe_ia32/platform_stage2_args.h new file mode 100644 index 0000000000..abcf6ef111 --- /dev/null +++ b/headers/private/kernel/boot/platform/pxe_ia32/platform_stage2_args.h @@ -0,0 +1 @@ +#include "../bios_ia32/platform_stage2_args.h" diff --git a/src/system/boot/platform/pxe_ia32/Jamfile b/src/system/boot/platform/pxe_ia32/Jamfile index de6368514b..21cdbf53b8 100644 --- a/src/system/boot/platform/pxe_ia32/Jamfile +++ b/src/system/boot/platform/pxe_ia32/Jamfile @@ -44,6 +44,23 @@ KernelMergeObject boot_platform_pxe_ia32.o : ; +rule BuildPXEstage1 { + local bin = $(1) ; + local source = $(2) ; + + Depends $(bin) : $(source) ; + MakeLocateDebug $(bin) ; +} + + +actions BuildPXEstage1 { + rm -f $(1) + as -o $(1).o $(2) + ld --oformat binary --Ttext 0x7C00 -o $(1) $(1).o +} + +BuildPXEstage1 pxe_stage1.bin : pxe_stage1.S ; + SEARCH on [ FGristFiles $(bios_ia32_src) ] = [ FDirName $(SUBDIR) $(DOTDOT) bios_ia32 ] ; @@ -56,5 +73,5 @@ SEARCH on stage1.bin # Tell the build system to where stage1.bin can be found, so it can be used # elsewhere. -SEARCH on pxe_stage1.bin = $(SUBDIR) ; +# SEARCH on pxe_stage1.bin = $(SUBDIR) ; diff --git a/src/system/boot/platform/pxe_ia32/pxe_stage1.S b/src/system/boot/platform/pxe_ia32/pxe_stage1.S index eebe78c7b7..23c41b62eb 100644 --- a/src/system/boot/platform/pxe_ia32/pxe_stage1.S +++ b/src/system/boot/platform/pxe_ia32/pxe_stage1.S @@ -25,15 +25,13 @@ .equ PXENV_PACKET_TYPE_DHCP_ACK, 2 .equ PXENV_PACKET_TYPE_CACHED_REPLY, 3 -.equ scratchbuffer_addr_seg, 0x2000 -.equ scratchbuffer_addr_ofs, 0x0000 -.equ scratchbuffer_addr, ((scratchbuffer_addr_seg << 4) + scratchbuffer_addr_ofs) -.equ scratchbuffer_size, 15000 +.equ scratchbuffer_addr, 0x9000 +.equ scratchbuffer_addr_seg, (scratchbuffer_addr / 16) +.equ scratchbuffer_addr_ofs, (scratchbuffer_addr % 16) +.equ scratchbuffer_size, 0x7000 -// load at 1 MB -.equ load_addr, 0x100000 -.equ load_addr_seg, 0xffff -.equ load_addr_ofs, 0x0010 +.equ load_addr, 0x10000 +.equ load_size_max, 0x80000 .code16 .text @@ -237,7 +235,7 @@ _start: imull $65535, %eax movl %eax, max_fsize - // print max file size + // print max TFTP file size movw $maxfsize, %si call puts movl max_fsize, %eax @@ -245,12 +243,26 @@ _start: movw $crlf, %si call puts - // check if file is small enough + // print max stage 2 file size + movw $maxs2size, %si + call puts + movl $load_size_max, %eax + call puthex32 + movw $crlf, %si + call puts + + // check if file is small enough (TFTP limit) movl s_PXENV_TFTP_GET_FSIZE_FileSize, %eax movl max_fsize, %ebx cmpl %ebx, %eax ja err_etoobig + // check if file is small enough (address range limit) + movl s_PXENV_TFTP_GET_FSIZE_FileSize, %eax + movl $load_size_max, %ebx + cmpl %ebx, %eax + ja err_etoobig + // load data movl $load_addr, %edi read_loop: @@ -289,11 +301,11 @@ _copy_b: movb (%esi), %al jnz _copy_b _copy_done: - // print a dot every 100 packets + // print a dot every 20 packets movw pos, %ax incw %ax movw %ax, pos - cmpw $100, %ax + cmpw $20, %ax jb _no_dot xorw %ax, %ax movw %ax, pos @@ -340,7 +352,7 @@ pm_start: mov %ax, %gs mov %ax, %ss - ljmp $0x8, $0x100000 + ljmp $0x8, $load_addr .code16 stop: hlt @@ -461,11 +473,12 @@ length: .asciz ", length " loading: .asciz "Loading image file " fsizeis: .asciz "Image file size is " psizeis: .asciz "Packet size is " -maxfsize: .asciz "Maximum file size is " -etoobig: .asciz "Image file is too large, loading failed\r\n" -sizefailed: .asciz "\r\nCouldn't get image file size, loading failed\r\n" -loadfailed: .asciz "\r\nLoading image file failed\r\n" -executing: .asciz "\r\nExecuting stage 2 loader\r\n" +maxfsize: .asciz "Maximum TFTP file size is " +maxs2size: .asciz "Maximum stage 2 file size is " +etoobig: .asciz "haiku-pxe-loader file is too large, loading aborted\r\n" +sizefailed: .asciz "\r\nCouldn't get haiku-pxe-loader file size, loading failed\r\n" +loadfailed: .asciz "\r\nLoading haiku-pxe-loader (stage 2) failed\r\n" +executing: .asciz "\r\nExecuting haiku-pxe-loader (stage 2)\r\n" colon: .asciz ":" dot: .asciz "." crlf: .asciz "\r\n" @@ -538,8 +551,8 @@ s_PXENV_TFTP_OPEN: s_PXENV_TFTP_OPEN_Status: .word 0 s_PXENV_TFTP_OPEN_ServerIPAddress: .long 0 s_PXENV_TFTP_OPEN_GatewayIPAddress: .long 0 -s_PXENV_TFTP_OPEN_FileName: .asciz "haiku-pxe-image" - .fill 112 +s_PXENV_TFTP_OPEN_FileName: .asciz "haiku-pxe-loader" + .fill 111 s_PXENV_TFTP_OPEN_TFTPPort: .word (69 << 8) s_PXENV_TFTP_OPEN_PacketSize: .word 1456 @@ -547,8 +560,8 @@ s_PXENV_TFTP_GET_FSIZE: s_PXENV_TFTP_GET_FSIZE_Status: .word 0 s_PXENV_TFTP_GET_FSIZE_ServerIPAddress: .long 0 s_PXENV_TFTP_GET_FSIZE_GatewayIPAddress:.long 0 -s_PXENV_TFTP_GET_FSIZE_FileName: .asciz "haiku-pxe-image" - .fill 112 +s_PXENV_TFTP_GET_FSIZE_FileName: .asciz "haiku-pxe-loader" + .fill 111 s_PXENV_TFTP_GET_FSIZE_FileSize: .long 0 s_PXENV_TFTP_READ: diff --git a/src/system/boot/platform/pxe_ia32/pxe_stage2.S b/src/system/boot/platform/pxe_ia32/pxe_stage2.S index 320d96b50b..87fc40644f 100644 --- a/src/system/boot/platform/pxe_ia32/pxe_stage2.S +++ b/src/system/boot/platform/pxe_ia32/pxe_stage2.S @@ -5,10 +5,10 @@ */ -/** This file contains the stage 2 boot loader for the PXE (preboot execution - * environment) image. - * It gets loaded by the PXE stage1 loader to 0xffff:0010 (0x100000), and it - * starts execution in 32 bit protected mode. Entry point is at offset 0. +/** This file contains the stage 2 boot loader (haiku-pxe-loader) for the PXE + * (preboot execution environment) API + * It gets loaded by the PXE stage1 loader to 0x10000, and it starts execution + * in 32 bit protected mode. Entry point is at offset 0. * This code will directly call the entry function of the embedded ELF part * of the loader. */ @@ -24,9 +24,6 @@ pxe_start: mov $0x10000, %ebp // setup new stack mov %ebp, %esp -// stop: hlt -// jmp stop - call _start //-------------------------------------------------------------- diff --git a/src/system/ldscripts/x86/boot_loader_pxe_ia32.ld b/src/system/ldscripts/x86/boot_loader_pxe_ia32.ld index 7ab2b89e17..b108d1634a 100644 --- a/src/system/ldscripts/x86/boot_loader_pxe_ia32.ld +++ b/src/system/ldscripts/x86/boot_loader_pxe_ia32.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386) ENTRY(_start) SECTIONS { - . = 0x100000; + . = 0x10000; /* text/read-only data */ .text : { *(.text .gnu.linkonce.t.*) }