* [Qemu-devel] [PATCH] linuxboot: compute initrd loading address
@ 2014-10-06 14:49 Paolo Bonzini
2014-10-07 8:46 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2014-10-06 14:49 UTC (permalink / raw)
To: qemu-devel; +Cc: jsnow, agraf, mst
Even though hw/i386/pc.c tries to compute a valid loading address for the
initrd, close to the top of RAM, this does not take into account other
data that is malloced into that memory by SeaBIOS.
Luckily we can easily look at the memory map to find out how much memory is
used up there. This patch places the initrd in the first four gigabytes,
below the first hole (as returned by INT 15h, AX=e801h).
Without this patch:
[ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
[ 0.000000] RAMDISK: [mem 0x0710a000-0x07fd7fff]
With this patch:
[ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
[ 0.000000] RAMDISK: [mem 0x07112000-0x07fdffff]
So linuxboot is able to use the 64k that were added as padding for
QEMU <= 2.1.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
pc-bios/optionrom/linuxboot.S | 47 ++++++++++++++++++++++++++++++++++++++----
pc-bios/optionrom/optionrom.h | 21 ++++++++++++++++---
3 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/pc-bios/linuxboot.bin b/pc-bios/linuxboot.bin
index e7c36694f997c3c34f7f4af3c2923bd2ef6094e7..130103fb739228a6869aaf1b174b9d20c13378fc 100644
GIT binary patch
delta 168
zcmZqRXyBNj#e9V6<V4+-#yc2a7@jn|bXJt}WGM&drBas8gPpg4G+*OE29`Ab?LX5F
zKIeMP(|Cx15y<-m<Oxh}WRz3ZJf7D0oZ-X&|7o31)0*E19C!O5&XCq~0;uRf+QA1b
zX{>7|eo$aa3kRw;nk>i|IC(Q;0c%?4;T_@=t7IoTF$qbirKj~bOE57or0rk;0)C|f
SJtz7Oyqvi?nJI*kF&F^X7ev$m
delta 107
zcmZqRXyBNj#azSGI8k@yWCKP?#+1okj0#LU*e5$O$xYtNXvD|`VlnOD22!$<yBUQi
zzh^99+93|&DjwV+!H~8~fR%ya{VqY)Kk1)y(snQa0l(6Lo)disUOwEsnkj^F@&_gl
G#(w~}wj;0r
diff --git a/pc-bios/optionrom/linuxboot.S b/pc-bios/optionrom/linuxboot.S
index 748c831..5bc0af0 100644
--- a/pc-bios/optionrom/linuxboot.S
+++ b/pc-bios/optionrom/linuxboot.S
@@ -76,14 +76,45 @@ boot_kernel:
copy_kernel:
+ /* Compute initrd address */
+ mov $0xe801, %ax
+ xor %cx, %cx
+ xor %dx, %dx
+ int $0x15
+
+ /* Output could be in AX/BX or CX/DX */
+ or %cx, %cx
+ jnz 1f
+ or %dx, %dx
+ jnz 1f
+ mov %ax, %cx
+ mov %bx, %dx
+1:
+
+ or %dx, %dx
+ jnz 2f
+ addw $1024, %cx /* add 1 MB */
+ movzwl %cx, %edi
+ shll $10, %edi /* convert to bytes */
+ jmp 3f
+
+2:
+ addw $16777216 >> 16, %dx /* add 16 MB */
+ movzwl %dx, %edi
+ shll $16, %edi /* convert to bytes */
+
+3:
+ read_fw FW_CFG_INITRD_SIZE
+ subl %eax, %edi
+ andl $-4096, %edi /* EDI = start of initrd */
/* We need to load the kernel into memory we can't access in 16 bit
mode, so let's get into 32 bit mode, write the kernel and jump
back again. */
/* Reserve space on the stack for our GDT descriptor. */
- mov %esp, %ebp
- sub $16, %esp
+ mov %esp, %ebp
+ sub $16, %esp
/* Now create the GDT descriptor */
movw $((3 * 8) - 1), -16(%bp)
@@ -108,10 +139,18 @@ copy_kernel:
/* We're now running in 16-bit CS, but 32-bit ES! */
/* Load kernel and initrd */
+ pushl %edi
+ read_fw_blob_addr32_edi(FW_CFG_INITRD)
read_fw_blob_addr32(FW_CFG_KERNEL)
- read_fw_blob_addr32(FW_CFG_INITRD)
read_fw_blob_addr32(FW_CFG_CMDLINE)
- read_fw_blob_addr32(FW_CFG_SETUP)
+
+ read_fw FW_CFG_SETUP_ADDR
+ mov %eax, %edi
+ mov %eax, %ebx
+ read_fw_blob_addr32_edi(FW_CFG_SETUP)
+
+ /* Update the header with the initrd address we chose above */
+ popl %es:0x218(%ebx)
/* And now jump into Linux! */
mov $0, %eax
diff --git a/pc-bios/optionrom/optionrom.h b/pc-bios/optionrom/optionrom.h
index ce43608..f1a9021 100644
--- a/pc-bios/optionrom/optionrom.h
+++ b/pc-bios/optionrom/optionrom.h
@@ -51,8 +51,6 @@
.endm
#define read_fw_blob_pre(var) \
- read_fw var ## _ADDR; \
- mov %eax, %edi; \
read_fw var ## _SIZE; \
mov %eax, %ecx; \
mov $var ## _DATA, %ax; \
@@ -68,6 +66,8 @@
* Clobbers: %eax, %edx, %es, %ecx, %edi
*/
#define read_fw_blob(var) \
+ read_fw var ## _ADDR; \
+ mov %eax, %edi; \
read_fw_blob_pre(var); \
/* old as(1) doesn't like this insn so emit the bytes instead: \
rep insb (%dx), %es:(%edi); \
@@ -80,7 +80,22 @@
*
* Clobbers: %eax, %edx, %es, %ecx, %edi
*/
-#define read_fw_blob_addr32(var) \
+#define read_fw_blob_addr32(var) \
+ read_fw var ## _ADDR; \
+ mov %eax, %edi; \
+ read_fw_blob_pre(var); \
+ /* old as(1) doesn't like this insn so emit the bytes instead: \
+ addr32 rep insb (%dx), %es:(%edi); \
+ */ \
+ .dc.b 0x67,0xf3,0x6c
+
+/*
+ * Read a blob from the fw_cfg device in forced addr32 mode, address is in %edi.
+ * Requires _SIZE and _DATA values for the parameter.
+ *
+ * Clobbers: %eax, %edx, %edi, %es, %ecx
+ */
+#define read_fw_blob_addr32_edi(var) \
read_fw_blob_pre(var); \
/* old as(1) doesn't like this insn so emit the bytes instead: \
addr32 rep insb (%dx), %es:(%edi); \
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linuxboot: compute initrd loading address
2014-10-06 14:49 [Qemu-devel] [PATCH] linuxboot: compute initrd loading address Paolo Bonzini
@ 2014-10-07 8:46 ` Michael S. Tsirkin
2014-10-07 10:10 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2014-10-07 8:46 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: jsnow, qemu-devel, agraf
On Mon, Oct 06, 2014 at 04:49:57PM +0200, Paolo Bonzini wrote:
> Even though hw/i386/pc.c tries to compute a valid loading address for the
> initrd, close to the top of RAM, this does not take into account other
> data that is malloced into that memory by SeaBIOS.
>
> Luckily we can easily look at the memory map to find out how much memory is
> used up there. This patch places the initrd in the first four gigabytes,
> below the first hole (as returned by INT 15h, AX=e801h).
>
> Without this patch:
> [ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
> [ 0.000000] RAMDISK: [mem 0x0710a000-0x07fd7fff]
>
> With this patch:
> [ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
> [ 0.000000] RAMDISK: [mem 0x07112000-0x07fdffff]
>
> So linuxboot is able to use the 64k that were added as padding for
> QEMU <= 2.1.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
OK, and we need something similar for multiboot.S?
Also - can we drop FW_CFG_INITRD_ADDR and the patching
in load_linux now (unless running a compat machine type)?
> ---
> pc-bios/linuxboot.bin | Bin 1024 -> 1024 bytes
> pc-bios/optionrom/linuxboot.S | 47 ++++++++++++++++++++++++++++++++++++++----
> pc-bios/optionrom/optionrom.h | 21 ++++++++++++++++---
> 3 files changed, 61 insertions(+), 7 deletions(-)
>
> diff --git a/pc-bios/linuxboot.bin b/pc-bios/linuxboot.bin
> index e7c36694f997c3c34f7f4af3c2923bd2ef6094e7..130103fb739228a6869aaf1b174b9d20c13378fc 100644
> GIT binary patch
> delta 168
> zcmZqRXyBNj#e9V6<V4+-#yc2a7@jn|bXJt}WGM&drBas8gPpg4G+*OE29`Ab?LX5F
> zKIeMP(|Cx15y<-m<Oxh}WRz3ZJf7D0oZ-X&|7o31)0*E19C!O5&XCq~0;uRf+QA1b
> zX{>7|eo$aa3kRw;nk>i|IC(Q;0c%?4;T_@=t7IoTF$qbirKj~bOE57or0rk;0)C|f
> SJtz7Oyqvi?nJI*kF&F^X7ev$m
>
> delta 107
> zcmZqRXyBNj#azSGI8k@yWCKP?#+1okj0#LU*e5$O$xYtNXvD|`VlnOD22!$<yBUQi
> zzh^99+93|&DjwV+!H~8~fR%ya{VqY)Kk1)y(snQa0l(6Lo)disUOwEsnkj^F@&_gl
> G#(w~}wj;0r
>
> diff --git a/pc-bios/optionrom/linuxboot.S b/pc-bios/optionrom/linuxboot.S
> index 748c831..5bc0af0 100644
> --- a/pc-bios/optionrom/linuxboot.S
> +++ b/pc-bios/optionrom/linuxboot.S
> @@ -76,14 +76,45 @@ boot_kernel:
>
>
> copy_kernel:
> + /* Compute initrd address */
> + mov $0xe801, %ax
> + xor %cx, %cx
> + xor %dx, %dx
> + int $0x15
> +
> + /* Output could be in AX/BX or CX/DX */
> + or %cx, %cx
> + jnz 1f
> + or %dx, %dx
> + jnz 1f
> + mov %ax, %cx
> + mov %bx, %dx
> +1:
> +
> + or %dx, %dx
> + jnz 2f
> + addw $1024, %cx /* add 1 MB */
> + movzwl %cx, %edi
> + shll $10, %edi /* convert to bytes */
> + jmp 3f
> +
> +2:
> + addw $16777216 >> 16, %dx /* add 16 MB */
> + movzwl %dx, %edi
> + shll $16, %edi /* convert to bytes */
> +
> +3:
> + read_fw FW_CFG_INITRD_SIZE
> + subl %eax, %edi
> + andl $-4096, %edi /* EDI = start of initrd */
>
> /* We need to load the kernel into memory we can't access in 16 bit
> mode, so let's get into 32 bit mode, write the kernel and jump
> back again. */
>
> /* Reserve space on the stack for our GDT descriptor. */
> - mov %esp, %ebp
> - sub $16, %esp
> + mov %esp, %ebp
> + sub $16, %esp
>
> /* Now create the GDT descriptor */
> movw $((3 * 8) - 1), -16(%bp)
> @@ -108,10 +139,18 @@ copy_kernel:
> /* We're now running in 16-bit CS, but 32-bit ES! */
>
> /* Load kernel and initrd */
> + pushl %edi
> + read_fw_blob_addr32_edi(FW_CFG_INITRD)
> read_fw_blob_addr32(FW_CFG_KERNEL)
> - read_fw_blob_addr32(FW_CFG_INITRD)
> read_fw_blob_addr32(FW_CFG_CMDLINE)
> - read_fw_blob_addr32(FW_CFG_SETUP)
> +
> + read_fw FW_CFG_SETUP_ADDR
> + mov %eax, %edi
> + mov %eax, %ebx
> + read_fw_blob_addr32_edi(FW_CFG_SETUP)
> +
> + /* Update the header with the initrd address we chose above */
> + popl %es:0x218(%ebx)
>
> /* And now jump into Linux! */
> mov $0, %eax
> diff --git a/pc-bios/optionrom/optionrom.h b/pc-bios/optionrom/optionrom.h
> index ce43608..f1a9021 100644
> --- a/pc-bios/optionrom/optionrom.h
> +++ b/pc-bios/optionrom/optionrom.h
> @@ -51,8 +51,6 @@
> .endm
>
> #define read_fw_blob_pre(var) \
> - read_fw var ## _ADDR; \
> - mov %eax, %edi; \
> read_fw var ## _SIZE; \
> mov %eax, %ecx; \
> mov $var ## _DATA, %ax; \
> @@ -68,6 +66,8 @@
> * Clobbers: %eax, %edx, %es, %ecx, %edi
> */
> #define read_fw_blob(var) \
> + read_fw var ## _ADDR; \
> + mov %eax, %edi; \
> read_fw_blob_pre(var); \
> /* old as(1) doesn't like this insn so emit the bytes instead: \
> rep insb (%dx), %es:(%edi); \
> @@ -80,7 +80,22 @@
> *
> * Clobbers: %eax, %edx, %es, %ecx, %edi
> */
> -#define read_fw_blob_addr32(var) \
> +#define read_fw_blob_addr32(var) \
> + read_fw var ## _ADDR; \
> + mov %eax, %edi; \
> + read_fw_blob_pre(var); \
> + /* old as(1) doesn't like this insn so emit the bytes instead: \
> + addr32 rep insb (%dx), %es:(%edi); \
> + */ \
> + .dc.b 0x67,0xf3,0x6c
> +
> +/*
> + * Read a blob from the fw_cfg device in forced addr32 mode, address is in %edi.
> + * Requires _SIZE and _DATA values for the parameter.
> + *
> + * Clobbers: %eax, %edx, %edi, %es, %ecx
> + */
> +#define read_fw_blob_addr32_edi(var) \
> read_fw_blob_pre(var); \
> /* old as(1) doesn't like this insn so emit the bytes instead: \
> addr32 rep insb (%dx), %es:(%edi); \
> --
> 2.1.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] linuxboot: compute initrd loading address
2014-10-07 8:46 ` Michael S. Tsirkin
@ 2014-10-07 10:10 ` Paolo Bonzini
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2014-10-07 10:10 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: jsnow, qemu-devel, agraf
Il 07/10/2014 10:46, Michael S. Tsirkin ha scritto:
> On Mon, Oct 06, 2014 at 04:49:57PM +0200, Paolo Bonzini wrote:
>> Even though hw/i386/pc.c tries to compute a valid loading address for the
>> initrd, close to the top of RAM, this does not take into account other
>> data that is malloced into that memory by SeaBIOS.
>>
>> Luckily we can easily look at the memory map to find out how much memory is
>> used up there. This patch places the initrd in the first four gigabytes,
>> below the first hole (as returned by INT 15h, AX=e801h).
>>
>> Without this patch:
>> [ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
>> [ 0.000000] RAMDISK: [mem 0x0710a000-0x07fd7fff]
>>
>> With this patch:
>> [ 0.000000] init_memory_mapping: [mem 0x07000000-0x07fdffff]
>> [ 0.000000] RAMDISK: [mem 0x07112000-0x07fdffff]
>>
>> So linuxboot is able to use the 64k that were added as padding for
>> QEMU <= 2.1.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>
> OK, and we need something similar for multiboot.S?
No, FW_CFG_INITRD_ADDR is in low memory for multiboot.S (0x9500,
compile-time constant). Modules (passed via -initrd for a multiboot
-kernel) are part of FW_CFG_KERNEL_DATA.
> Also - can we drop FW_CFG_INITRD_ADDR and the patching
> in load_linux now (unless running a compat machine type)?
You answered your question---it's needed for compat machine types.
Note however that there is no patching. FW_CFG_SETUP_DATA is a data
structure that is prepared from scratch by load_linux. It is linuxboot
that patches it.
All in all it's simpler to not make it conditional at all. It's part of
the ABI (and linuxboot is free to only use 95% of the agreed interface).
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-10-07 10:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-06 14:49 [Qemu-devel] [PATCH] linuxboot: compute initrd loading address Paolo Bonzini
2014-10-07 8:46 ` Michael S. Tsirkin
2014-10-07 10:10 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).