From 3dcc3bd1cf70ff06e4e1eeb09c69e5dfdff86be4 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 23 Sep 2012 14:43:22 -0400 Subject: [PATCH] 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. --- plat/pc86/boot.s | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plat/pc86/boot.s b/plat/pc86/boot.s index d517c1e45..534809697 100644 --- a/plat/pc86/boot.s +++ b/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 -- 2.34.1