Browse Source

Allow pc86 bootloader to boot from more floppy drives.

When the bootloader probes the drive geometry, the BIOS can clobber the
es register.  If this happens, the bootloader loads the program to the
wrong address, and jumps off the code.  This happens with an emulated
floppy drive in Bochs or QEMU, but not with an emulated hard disk.
George Koehler 11 years ago
parent
commit
f1cdb32025
1 changed files with 6 additions and 3 deletions
  1. 6 3
      plat/pc86/boot.s

+ 6 - 3
plat/pc86/boot.s

@@ -23,7 +23,7 @@
 ! If you ever need to change the boot code, this needs adjusting. I recommend
 ! If you ever need to change the boot code, this needs adjusting. I recommend
 ! a hex editor.
 ! a hex editor.
 
 
-PADDING = 0xB9
+PADDING = 0xB7
 
 
 ! Some definitions.
 ! Some definitions.
 
 
@@ -45,8 +45,8 @@ start2:
 
 
 	mov ax, cs
 	mov ax, cs
 	mov ds, ax
 	mov ds, ax
-	mov es, ax
 	mov ss, ax
 	mov ss, ax
+	! Defer setting es until after probing the drive.
 	
 	
 	! Initialise the stack, which will start at the top of our segment and work
 	! Initialise the stack, which will start at the top of our segment and work
 	! down.
 	! down.
@@ -65,10 +65,13 @@ start2:
 	call write_string
 	call write_string
 
 
 	! Probe the drive to figure out its geometry.
 	! Probe the drive to figure out its geometry.
+	! This might clobber es.
 	
 	
-	push dx	
+	push dx
 	mov ax, 0x0800           ! service number
 	mov ax, 0x0800           ! service number
 	int 0x13
 	int 0x13
+	mov ax, cs               ! restore es
+	mov es, ax
 	pop ax
 	pop ax
 	jc cant_boot
 	jc cant_boot