瀏覽代碼

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 年之前
父節點
當前提交
3dcc3bd1cf
共有 1 個文件被更改,包括 6 次插入3 次删除
  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
 ! a hex editor.
 
-PADDING = 0xB9
+PADDING = 0xB7
 
 ! Some definitions.
 
@@ -45,8 +45,8 @@ start2:
 
 	mov ax, cs
 	mov ds, ax
-	mov es, 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
 	! down.
@@ -65,10 +65,13 @@ start2:
 	call write_string
 
 	! Probe the drive to figure out its geometry.
+	! This might clobber es.
 	
-	push dx	
+	push dx
 	mov ax, 0x0800           ! service number
 	int 0x13
+	mov ax, cs               ! restore es
+	mov es, ax
 	pop ax
 	jc cant_boot