public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][EXTBOOT] Fix read drive parameters to solve Grub Error 18
@ 2008-03-04 17:44 Anthony Liguori
  2008-03-05  7:06 ` Avi Kivity
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony Liguori @ 2008-03-04 17:44 UTC (permalink / raw)
  To: kvm-devel; +Cc: Anthony Liguori, Avi Kivity

In certain circumstances, the calculated CHS can result in a total number of
sectors that is less than the actual number of sectors.  I'm not entirely
sure why this upsets grub, but it seems to be the source of the Grub Error 18
that sometimes occurs when using extboot.

The solution is to implement the read drive parameters function and return the
actual numbers of sectors.  This requires changing the QEMU <=> extboot
interface as this was not previously passed to extboot.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/extboot/extboot.S b/extboot/extboot.S
index 584d36d..9eb9333 100644
--- a/extboot/extboot.S
+++ b/extboot/extboot.S
@@ -351,7 +351,7 @@ disk_reset:
 	sub $1, %ax
 	mov %ax, 4(%bp)
 
-	alloca $8
+	alloca $16
 
 	movw $0, 0(%bx) /* read c,h,s */
 	push %bx
@@ -426,7 +426,7 @@ read_disk_drive_parameters:
 	push %bx
 
 	/* allocate memory for packet, pointer gets returned in bx */
-	alloca $8
+	alloca $16
 
 	/* issue command */
 	movw $0, 0(%bx) /* cmd = 0, read c,h,s */
@@ -481,7 +481,7 @@ alternate_disk_reset:
 
 read_disk_drive_size:
 	push %bx
-	alloca $8
+	alloca $16
 
 	movw $0, 0(%bx) /* cmd = 0, read c,h,s */
 	push %bx
@@ -572,29 +572,20 @@ extended_write_sectors:
 	extended_read_write_sectors $0x02
 
 get_extended_drive_parameters:
-	mov $1, %ah
-	stc
-	ret
-#if 0
-	/* this function is seriously borked */
-1:
 	push %ax
 	push %bp
 	push %cx
 	push %dx
 
-	allocbpa $8
+	allocbpa $16
 
 	movw $0, 0(%bp) /* read c,h,s */
 	push %bp
 	call send_command
 	add $2, %sp
 
-	/* check the size of the passed in data */
-	cmpw $26, 0(%si)
-	mov 0(%si), %ax
-	dump %ax
-	jle 0b
+	/* write size */
+	movw $26, 0(%si)
 
 	/* set flags to 2 */
 	movw $2, 2(%si)
@@ -617,46 +608,19 @@ get_extended_drive_parameters:
 	xor %ax, %ax
 	mov %ax, 14(%si)
 
-	/* calculate total sectors */
-
-	/* cx:dx = cylinders */
-	mov 2(%bp), %dx
-	xor %cx, %cx
-
-	/* *= heads */
-	push 4(%bp)
-	push $0
-	push %dx
-	push %cx
-	call mul32
-	add $8, %sp
-
-	/* *= sectors */
-	push 6(%bp)
-	push $0
-	push %dx
-	push %cx
-	call mul32
-	add $8, %sp
-
-	/* total number of sectors */
-	mov %dx, 16(%si)
-	mov %cx, 18(%si)
-	xor %ax, %ax
+	/* set total number of sectors */
+	mov 8(%bp), %ax
+	mov %ax, 16(%si)
+	mov 10(%bp), %ax
+	mov %ax, 18(%si)
+	mov 12(%bp), %ax
 	mov %ax, 20(%si)
+	mov 14(%bp), %ax
 	mov %ax, 22(%si)
 
 	/* number of bytes per sector */
 	movw $512, 24(%si)
 
-	/* optional segmention:offset to EDD config */
-	cmpw $30, 0(%si)
-	jl 1f
-
-	movw $0xFFFF, 26(%si)
-	movw $0xFFFF, 28(%si)
-
-1:
 	freebpa
 
 	pop %dx
@@ -667,7 +631,6 @@ get_extended_drive_parameters:
 	mov $0, %ah
 	clc
 	ret
-#endif
 
 terminate_disk_emulation:
 	mov $1, %ah
diff --git a/qemu/hw/extboot.c b/qemu/hw/extboot.c
index 8759895..056fb59 100644
--- a/qemu/hw/extboot.c
+++ b/qemu/hw/extboot.c
@@ -26,6 +26,7 @@ union extboot_cmd
 	uint16_t cylinders;
 	uint16_t heads;
 	uint16_t sectors;
+	uint64_t nb_sectors;
     } query_geometry;
     struct {
 	uint16_t type;
@@ -75,6 +76,7 @@ static void extboot_write_cmd(void *opaque, uint32_t addr, uint32_t value)
     union extboot_cmd *cmd = (void *)(phys_ram_base + ((value & 0xFFFF) << 4));
     BlockDriverState *bs = opaque;
     int cylinders, heads, sectors, err;
+    int64_t nb_sectors;
 
     get_translated_chs(bs, &cylinders, &heads, &sectors);
 
@@ -88,9 +90,11 @@ static void extboot_write_cmd(void *opaque, uint32_t addr, uint32_t value)
 
     switch (cmd->type) {
     case 0x00:
+	bdrv_get_geometry(bs, &nb_sectors);
 	cmd->query_geometry.cylinders = cylinders;
 	cmd->query_geometry.heads = heads;
 	cmd->query_geometry.sectors = sectors;
+	cmd->query_geometry.nb_sectors = nb_sectors;
 	cpu_physical_memory_set_dirty((value & 0xFFFF) << 4);
 	break;
     case 0x01:

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-03-05  7:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-04 17:44 [PATCH][EXTBOOT] Fix read drive parameters to solve Grub Error 18 Anthony Liguori
2008-03-05  7:06 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox