diff options
author | rnordier <rnordier@FreeBSD.org> | 1998-11-08 15:36:35 +0000 |
---|---|---|
committer | rnordier <rnordier@FreeBSD.org> | 1998-11-08 15:36:35 +0000 |
commit | 040db5b721b3675b8704bc732d5a12fd787e9bae (patch) | |
tree | 4077a757170bbbf58cdb7718462ea20b90ac187d /sys/boot/i386/boot2 | |
parent | ed31c0e42c68d25c0677c288695549d32c405eac (diff) | |
download | FreeBSD-src-040db5b721b3675b8704bc732d5a12fd787e9bae.zip FreeBSD-src-040db5b721b3675b8704bc732d5a12fd787e9bae.tar.gz |
boot1: Eliminate EDD detection and optional use of disk packet
interface. Do some general consistency fixes and space optimizations.
Use of some freed-up space to defend against possible BIOS misfeatures.
boot2: Revise disk read interface to provide for boot1 changes. Free
up space for this.
Diffstat (limited to 'sys/boot/i386/boot2')
-rw-r--r-- | sys/boot/i386/boot2/Makefile | 5 | ||||
-rw-r--r-- | sys/boot/i386/boot2/boot1.S | 164 | ||||
-rw-r--r-- | sys/boot/i386/boot2/boot1.m4 | 3 | ||||
-rw-r--r-- | sys/boot/i386/boot2/boot1.s | 164 | ||||
-rw-r--r-- | sys/boot/i386/boot2/boot2.c | 13 |
5 files changed, 155 insertions, 194 deletions
diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile index b7823bf..d3711b0 100644 --- a/sys/boot/i386/boot2/Makefile +++ b/sys/boot/i386/boot2/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.8 1998/10/20 20:20:48 rnordier Exp $ +# $Id: Makefile,v 1.9 1998/11/05 20:52:25 rnordier Exp $ PROG= boot2 NOMAN= @@ -11,7 +11,6 @@ CLEANFILES+= boot1 boot1.out boot1.o \ M4?= m4 -B1INT13X?= 0 B2SIOPRT?= 0x3f8 B2SIOFMT?= 0x3 B2SIODIV?= 0xc @@ -42,7 +41,7 @@ boot1.out: boot1.o ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o boot1.o: boot1.m4 boot1.s - (cd ${.CURDIR}; ${M4} -DFLAGS=${B1INT13X} boot1.m4 boot1.s) | \ + (cd ${.CURDIR}; ${M4} boot1.m4 boot1.s) | \ ${AS} ${AFLAGS} -o ${.TARGET} boot2: boot2.ldr boot2.bin diff --git a/sys/boot/i386/boot2/boot1.S b/sys/boot/i386/boot2/boot1.S index 99397a3..66812ab 100644 --- a/sys/boot/i386/boot2/boot1.S +++ b/sys/boot/i386/boot2/boot1.S @@ -13,11 +13,10 @@ # purpose. # -# $Id: boot1.s,v 1.3 1998/10/27 20:19:24 rnordier Exp $ +# $Id: boot1.s,v 1.4 1998/11/05 20:52:25 rnordier Exp $ .set MEM_REL,0x600 # Relocation address .set MEM_ARG,0x800 # Arguments - .set MEM_PKT,0x810 # Disk packet .set MEM_ORG,0x7c00 # Origin .set MEM_BUF,0x8c00 # Load area .set MEM_BTX,0x9000 # BTX start @@ -38,59 +37,58 @@ start: jmp main # Start recognizably .org 0x4,0x90 -xread: pushl %cs # Address - popl %ds # data -xread.1: movwir(MEM_PKT,_si) # Packet - movbr1(_al,0x2,_si_) # Blocks to read - o16 # Transfer - movwr1(_bx,0x4,_si_) # buffer - o16 # LBA - movwr1(_cx,0x8,_si_) # address +# External read from disk + +xread: pushl %ecx # Set + pushl %eax # LBA + pushl %es # Set transfer + pushl %ebx # buffer + pushl %edx # Set count:drive callwi(read) # Read from disk - lret # To caller + popl %edx # Pop + popl %ebx # all + popl %es # registers + popl %eax # we + popl %ecx # pushed + lret # To far caller + +# Bootstrap main: cld # String ops inc - xorl %eax,%eax # Zero - movl %ax,%es # Address - movl %ax,%ds # data - movl %ax,%ss # Set up + xorl %ecx,%ecx # Zero + movl %cx,%es # Address + movl %cx,%ds # data + movl %cx,%ss # Set up movwir(start,_sp) # stack movl %esp,%esi # Source movwir(MEM_REL,_di) # Destination - movwir(0x100,_cx) # Word count + incb %ch # Word count rep # Copy movsl # code - movb $0x10,%cl # Words to clear - rep # Zero - stosl # them - movbi1(0x10,-0x10,_di_) # Set packet size + movwir(part4,_si) # Partition cmpb $0x80,%dl # Hard drive? jb main.4 # No - movwir(part4,_si) # Read master - movb $0x1,%al # boot - callwi(nread) # record - xorl %eax,%eax # Pass number + movb $0x1,%dh # Block count + callwi(nread) # Read MBR + movwir(0x1,_cx) # Two passes main.1: movwir(MEM_BUF+PRT_OFF,_si) # Partition table movb $0x1,%dh # Partition main.2: cmpbi1(PRT_BSD,0x4,_si_) # Our partition type? jne main.3 # No + jecxz main.5 # If second pass tstbi0(0x80,_si_) # Active? jnz main.5 # Yes - testb %al,%al # Second pass? - jnz main.5 # Yes main.3: addl $0x10,%esi # Next entry incb %dh # Partition - cmpb $0x1+PRT_NUM,%dh # Done? - jb main.2 # No - incl %eax # Pass - cmpb $0x2,%al # Done? - jb main.1 # No + cmpb $0x1+PRT_NUM,%dh # In table? + jb main.2 # Yes + decl %ecx # Do two + jecxz main.1 # passes movwir(msg_part,_si) # Message jmp error # Error main.4: xorl %edx,%edx # Partition:drive - movwir(part4,_si) # Partition pointer main.5: movwrm(_dx,MEM_ARG) # Save args - movb $0x10,%al # Sector count + movb $0x10,%dh # Sector count callwi(nread) # Read disk movwir(MEM_BTX,_bx) # BTX movw1r(0xa,_bx_,_si) # Point past @@ -123,21 +121,20 @@ seta20.2: inb $0x64,%al # Get status sti # Enable interrupts ret # To caller -# Read from disk +# Local read from disk -nread: xorw %bx,%bx # Transfer - movb $MEM_BUF>>0x8,%bh # buffer - o16 # LBA - movw1r(0x8,_si_,_cx) # address +nread: movwir(MEM_BUF,_bx) # Transfer buffer + movw1r(0x8,_si_,_ax) # Get + movw1r(0xa,_si_,_cx) # LBA pushl %cs # Read from - callwi(xread.1) # disk + callwi(xread) # disk jnc return # If success movwir(msg_read,_si) # Message # Error exit error: callwi(putstr) # Display message - movwir(msg_boot,_si) # Display + movwir(prompt,_si) # Display callwi(putstr) # prompt xorb %ah,%ah # BIOS: Get int $0x16 # keypress @@ -152,42 +149,24 @@ putstr: lodsb # Get char testb %al,%al # End of string? jne putstr.0 # No -return: ret # Generic return +ereturn: movb $0x1,%ah # Invalid + stc # argument +return: ret # To caller # Read from disk -read: tstbim(0x80,MEM_REL+flags-start)# Extensions enabled? - jz read.3 # No - testb %dh,%dh # Try for extensions? - jz read.3 # No - movwir(0x55aa,_bx) # Magic +read: movl %esp,%ebp # Address stack frame pushl %edx # Save - movb $0x41,%ah # BIOS: Check - int $0x13 # extensions present - popl %edx # Restore - jc read.3 # If error - cmpwir(0xaa55,_bx) # Magic? - jne read.3 # No - testb $0x1,%cl # Packet interface? - jz read.3 # No - movb $0x42,%ah # BIOS: Extended - int $0x13 # read - ret # To caller - -read.1: movb $0x1,%ah # Invalid - stc # parameter -read.2: ret # To caller - -read.3: pushl %edx # Save movb $0x8,%ah # BIOS: Get drive int $0x13 # parameters movb %dh,%ch # Max head number popl %edx # Restore - jc read.2 # If error + jc return # If error andb $0x3f,%cl # Sectors per track - jz read.1 # If zero + jz ereturn # If zero + cli # Disable interrupts o16 # Get - movw1r(0x8,_si_,_ax) # LBA + movw1r(0x8,_bp_,_ax) # LBA pushl %edx # Save movzbw %cl,%bx # Divide by xorw %dx,%dx # sectors @@ -195,13 +174,14 @@ read.3: pushl %edx # Save movb %ch,%bl # Max head number movb %dl,%ch # Sector number incl %ebx # Divide by - xorb %dl,%dl # number of - divw %bx,%ax # heads + xorb %dl,%dl # number + divw %bx,%ax # of heads movb %dl,%bh # Head number popl %edx # Restore o16 # Cylinder number cmpl $0x3ff,%eax # supportable? - ja read.1 # No + sti # Enable interrupts + ja ereturn # No xchgb %al,%ah # Set up cylinder rorb $0x2,%al # number orb %ch,%al # Merge @@ -209,39 +189,39 @@ read.3: pushl %edx # Save xchgl %eax,%ecx # number movb %bh,%dh # Head number subb %ah,%al # Sectors this track - movb1r(0x2,_si_,_ah) # Blocks to read + movb1r(0x3,_bp_,_ah) # Blocks to read cmpb %ah,%al # To read - jb read.4 # this + jb read.1 # this movb %ah,%al # track -read.4: movwir(0x5,_bp) # Try count -read.5: lesw1r(0x4,_si_,_bx) # Transfer buffer +read.1: movwir(0x5,_di) # Try count +read.2: lesw1r(0x4,_bp_,_bx) # Transfer buffer pushl %eax # Save - movb $0x2,%ah # BIOS: Conventional - int $0x13 # read + movb $0x2,%ah # BIOS: Read + int $0x13 # from disk popl %ebx # Restore - jnc read.6 # If success - decl %ebp # Retry? - jz read.7 # No + jnc read.3 # If success + decl %edi # Retry? + jz read.5 # No xorb %ah,%ah # BIOS: Reset int $0x13 # disk system - movl %ebx,%eax # Block count - jmp read.5 # Continue -read.6: movzbw %bl,%ax # Sectors read - o16 # Adjust - addwr1(_ax,0x8,_si_) # LBA, - shlb %bl # buffer - addbr1(_bl,0x5,_si_) # pointer, - subbr1(_al,0x2,_si_) # block count - ja read.3 # If not done -read.7: ret # To caller + xchgl %ebx,%eax # Block count + jmp read.2 # Continue +read.3: movzbl %bl,%eax # Sectors read + addwr1(_ax,0x8,_bp_) # Adjust + jnc read.4 # LBA, + incw1(0xa,_bp_) # transfer +read.4: shlb %bl # buffer + addbr1(_bl,0x5,_bp_) # pointer, + subbr1(_al,0x3,_bp_) # block count + ja read # If not done +read.5: ret # To caller # Messages -msg_read: .asciz "Read error" -msg_part: .asciz "No bootable partition" -msg_boot: .asciz "\r\nHit return to reboot: " +msg_read: .asciz "Read" +msg_part: .asciz "Boot" -flags: .byte FLAGS # Flags +prompt: .asciz " error\r\nHit return: " .org PRT_OFF,0x90 diff --git a/sys/boot/i386/boot2/boot1.m4 b/sys/boot/i386/boot2/boot1.m4 index b16de41..06bdc97 100644 --- a/sys/boot/i386/boot2/boot1.m4 +++ b/sys/boot/i386/boot2/boot1.m4 @@ -13,7 +13,7 @@ # purpose. # -# $Id: boot1.m4,v 1.1.1.1 1998/10/12 21:16:26 rnordier Exp $ +# $Id: boot1.m4,v 1.2 1998/11/05 20:52:25 rnordier Exp $ define(_al,0x0)dnl define(_cl,0x1)dnl @@ -61,3 +61,4 @@ define(callwi,`.byte 0xe8; .word $1 - . - 0x2')dnl define(jmpnwi,`.byte 0xe9; .word $1 - . - 0x2')dnl define(tstbi0,`.byte 0xf6; .byte $2; .byte $1')dnl define(tstbim,`.byte 0xf6; .byte 0x6; .word $2; .byte $1')dnl +define(incw1,`.byte 0xff; .byte 0x40 | $2; .byte $1')dnl diff --git a/sys/boot/i386/boot2/boot1.s b/sys/boot/i386/boot2/boot1.s index 99397a3..66812ab 100644 --- a/sys/boot/i386/boot2/boot1.s +++ b/sys/boot/i386/boot2/boot1.s @@ -13,11 +13,10 @@ # purpose. # -# $Id: boot1.s,v 1.3 1998/10/27 20:19:24 rnordier Exp $ +# $Id: boot1.s,v 1.4 1998/11/05 20:52:25 rnordier Exp $ .set MEM_REL,0x600 # Relocation address .set MEM_ARG,0x800 # Arguments - .set MEM_PKT,0x810 # Disk packet .set MEM_ORG,0x7c00 # Origin .set MEM_BUF,0x8c00 # Load area .set MEM_BTX,0x9000 # BTX start @@ -38,59 +37,58 @@ start: jmp main # Start recognizably .org 0x4,0x90 -xread: pushl %cs # Address - popl %ds # data -xread.1: movwir(MEM_PKT,_si) # Packet - movbr1(_al,0x2,_si_) # Blocks to read - o16 # Transfer - movwr1(_bx,0x4,_si_) # buffer - o16 # LBA - movwr1(_cx,0x8,_si_) # address +# External read from disk + +xread: pushl %ecx # Set + pushl %eax # LBA + pushl %es # Set transfer + pushl %ebx # buffer + pushl %edx # Set count:drive callwi(read) # Read from disk - lret # To caller + popl %edx # Pop + popl %ebx # all + popl %es # registers + popl %eax # we + popl %ecx # pushed + lret # To far caller + +# Bootstrap main: cld # String ops inc - xorl %eax,%eax # Zero - movl %ax,%es # Address - movl %ax,%ds # data - movl %ax,%ss # Set up + xorl %ecx,%ecx # Zero + movl %cx,%es # Address + movl %cx,%ds # data + movl %cx,%ss # Set up movwir(start,_sp) # stack movl %esp,%esi # Source movwir(MEM_REL,_di) # Destination - movwir(0x100,_cx) # Word count + incb %ch # Word count rep # Copy movsl # code - movb $0x10,%cl # Words to clear - rep # Zero - stosl # them - movbi1(0x10,-0x10,_di_) # Set packet size + movwir(part4,_si) # Partition cmpb $0x80,%dl # Hard drive? jb main.4 # No - movwir(part4,_si) # Read master - movb $0x1,%al # boot - callwi(nread) # record - xorl %eax,%eax # Pass number + movb $0x1,%dh # Block count + callwi(nread) # Read MBR + movwir(0x1,_cx) # Two passes main.1: movwir(MEM_BUF+PRT_OFF,_si) # Partition table movb $0x1,%dh # Partition main.2: cmpbi1(PRT_BSD,0x4,_si_) # Our partition type? jne main.3 # No + jecxz main.5 # If second pass tstbi0(0x80,_si_) # Active? jnz main.5 # Yes - testb %al,%al # Second pass? - jnz main.5 # Yes main.3: addl $0x10,%esi # Next entry incb %dh # Partition - cmpb $0x1+PRT_NUM,%dh # Done? - jb main.2 # No - incl %eax # Pass - cmpb $0x2,%al # Done? - jb main.1 # No + cmpb $0x1+PRT_NUM,%dh # In table? + jb main.2 # Yes + decl %ecx # Do two + jecxz main.1 # passes movwir(msg_part,_si) # Message jmp error # Error main.4: xorl %edx,%edx # Partition:drive - movwir(part4,_si) # Partition pointer main.5: movwrm(_dx,MEM_ARG) # Save args - movb $0x10,%al # Sector count + movb $0x10,%dh # Sector count callwi(nread) # Read disk movwir(MEM_BTX,_bx) # BTX movw1r(0xa,_bx_,_si) # Point past @@ -123,21 +121,20 @@ seta20.2: inb $0x64,%al # Get status sti # Enable interrupts ret # To caller -# Read from disk +# Local read from disk -nread: xorw %bx,%bx # Transfer - movb $MEM_BUF>>0x8,%bh # buffer - o16 # LBA - movw1r(0x8,_si_,_cx) # address +nread: movwir(MEM_BUF,_bx) # Transfer buffer + movw1r(0x8,_si_,_ax) # Get + movw1r(0xa,_si_,_cx) # LBA pushl %cs # Read from - callwi(xread.1) # disk + callwi(xread) # disk jnc return # If success movwir(msg_read,_si) # Message # Error exit error: callwi(putstr) # Display message - movwir(msg_boot,_si) # Display + movwir(prompt,_si) # Display callwi(putstr) # prompt xorb %ah,%ah # BIOS: Get int $0x16 # keypress @@ -152,42 +149,24 @@ putstr: lodsb # Get char testb %al,%al # End of string? jne putstr.0 # No -return: ret # Generic return +ereturn: movb $0x1,%ah # Invalid + stc # argument +return: ret # To caller # Read from disk -read: tstbim(0x80,MEM_REL+flags-start)# Extensions enabled? - jz read.3 # No - testb %dh,%dh # Try for extensions? - jz read.3 # No - movwir(0x55aa,_bx) # Magic +read: movl %esp,%ebp # Address stack frame pushl %edx # Save - movb $0x41,%ah # BIOS: Check - int $0x13 # extensions present - popl %edx # Restore - jc read.3 # If error - cmpwir(0xaa55,_bx) # Magic? - jne read.3 # No - testb $0x1,%cl # Packet interface? - jz read.3 # No - movb $0x42,%ah # BIOS: Extended - int $0x13 # read - ret # To caller - -read.1: movb $0x1,%ah # Invalid - stc # parameter -read.2: ret # To caller - -read.3: pushl %edx # Save movb $0x8,%ah # BIOS: Get drive int $0x13 # parameters movb %dh,%ch # Max head number popl %edx # Restore - jc read.2 # If error + jc return # If error andb $0x3f,%cl # Sectors per track - jz read.1 # If zero + jz ereturn # If zero + cli # Disable interrupts o16 # Get - movw1r(0x8,_si_,_ax) # LBA + movw1r(0x8,_bp_,_ax) # LBA pushl %edx # Save movzbw %cl,%bx # Divide by xorw %dx,%dx # sectors @@ -195,13 +174,14 @@ read.3: pushl %edx # Save movb %ch,%bl # Max head number movb %dl,%ch # Sector number incl %ebx # Divide by - xorb %dl,%dl # number of - divw %bx,%ax # heads + xorb %dl,%dl # number + divw %bx,%ax # of heads movb %dl,%bh # Head number popl %edx # Restore o16 # Cylinder number cmpl $0x3ff,%eax # supportable? - ja read.1 # No + sti # Enable interrupts + ja ereturn # No xchgb %al,%ah # Set up cylinder rorb $0x2,%al # number orb %ch,%al # Merge @@ -209,39 +189,39 @@ read.3: pushl %edx # Save xchgl %eax,%ecx # number movb %bh,%dh # Head number subb %ah,%al # Sectors this track - movb1r(0x2,_si_,_ah) # Blocks to read + movb1r(0x3,_bp_,_ah) # Blocks to read cmpb %ah,%al # To read - jb read.4 # this + jb read.1 # this movb %ah,%al # track -read.4: movwir(0x5,_bp) # Try count -read.5: lesw1r(0x4,_si_,_bx) # Transfer buffer +read.1: movwir(0x5,_di) # Try count +read.2: lesw1r(0x4,_bp_,_bx) # Transfer buffer pushl %eax # Save - movb $0x2,%ah # BIOS: Conventional - int $0x13 # read + movb $0x2,%ah # BIOS: Read + int $0x13 # from disk popl %ebx # Restore - jnc read.6 # If success - decl %ebp # Retry? - jz read.7 # No + jnc read.3 # If success + decl %edi # Retry? + jz read.5 # No xorb %ah,%ah # BIOS: Reset int $0x13 # disk system - movl %ebx,%eax # Block count - jmp read.5 # Continue -read.6: movzbw %bl,%ax # Sectors read - o16 # Adjust - addwr1(_ax,0x8,_si_) # LBA, - shlb %bl # buffer - addbr1(_bl,0x5,_si_) # pointer, - subbr1(_al,0x2,_si_) # block count - ja read.3 # If not done -read.7: ret # To caller + xchgl %ebx,%eax # Block count + jmp read.2 # Continue +read.3: movzbl %bl,%eax # Sectors read + addwr1(_ax,0x8,_bp_) # Adjust + jnc read.4 # LBA, + incw1(0xa,_bp_) # transfer +read.4: shlb %bl # buffer + addbr1(_bl,0x5,_bp_) # pointer, + subbr1(_al,0x3,_bp_) # block count + ja read # If not done +read.5: ret # To caller # Messages -msg_read: .asciz "Read error" -msg_part: .asciz "No bootable partition" -msg_boot: .asciz "\r\nHit return to reboot: " +msg_read: .asciz "Read" +msg_part: .asciz "Boot" -flags: .byte FLAGS # Flags +prompt: .asciz " error\r\nHit return: " .org PRT_OFF,0x90 diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c index 03aa3b2..db6f1fc 100644 --- a/sys/boot/i386/boot2/boot2.c +++ b/sys/boot/i386/boot2/boot2.c @@ -14,7 +14,7 @@ */ /* - * $Id: boot2.c,v 1.12 1998/10/17 11:25:05 rnordier Exp $ + * $Id: boot2.c,v 1.13 1998/10/27 20:16:36 rnordier Exp $ */ #include <sys/param.h> @@ -297,7 +297,7 @@ load(const char *fname) addr = hdr.eh.e_entry & 0xffffff; } bootinfo.bi_esymtab = VTOP(p); - printf("]\nentry=0x%x\n", addr); + printf("]\n"); bootinfo.bi_kernelname = VTOP(fname); __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK), MAKEBOOTDEV(dsk.type, 0, dsk.slice, dsk.unit, dsk.part), @@ -748,10 +748,11 @@ drvread(void *buf, unsigned lba, unsigned nblk) printf("%c\b", c = c << 8 | c >> 24); v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS; v86.addr = 0x604; - v86.eax = nblk; - v86.ebx = VTOPSEG(buf) << 16 | VTOPOFF(buf); - v86.ecx = lba; - v86.edx = 0x100 | dsk.drive; + v86.es = VTOPSEG(buf); + v86.eax = lba; + v86.ebx = VTOPOFF(buf); + v86.ecx = lba >> 16; + v86.edx = nblk << 8 | dsk.drive; v86int(); v86.ctl = V86_FLAGS; if (V86_CY(v86.efl)) { |