@@ -1,3 +1,4 @@
+#include "kvm/bios.h"
#include "kvm/kvm.h"
#include "kvm/boot-protocol.h"
#include "kvm/e820.h"
@@ -45,7 +46,7 @@ static void setup_irq_handler(struct kvm *kvm, struct irq_handler *handler)
.offset = handler->address - MB_BIOS_BEGIN,
};
- DIE_IF((handler->address - MB_BIOS_BEGIN) > 0xffffUL);
+ DIE_IF((handler->address - MB_BIOS_BEGIN + 1) > MB_BIOS_SIZE);
interrupt_table__set(&kvm->arch.interrupt_table, &intr_desc, handler->irq);
}
@@ -75,7 +76,7 @@ static void e820_setup(struct kvm *kvm)
};
mem_map[i++] = (struct e820entry) {
.addr = MB_BIOS_BEGIN,
- .size = MB_BIOS_END - MB_BIOS_BEGIN,
+ .size = MB_BIOS_SIZE,
.type = E820_RESERVED,
};
if (kvm->ram_size < KVM_32BIT_GAP_START) {
@@ -132,16 +133,16 @@ void setup_bios(struct kvm *kvm)
* we definitely don't want any trash here
*/
p = guest_flat_to_host(kvm, BDA_START);
- memset(p, 0, BDA_END - BDA_START);
+ memset(p, 0, BDA_SIZE);
p = guest_flat_to_host(kvm, EBDA_START);
- memset(p, 0, EBDA_END - EBDA_START);
+ memset(p, 0, EBDA_SIZE);
p = guest_flat_to_host(kvm, MB_BIOS_BEGIN);
- memset(p, 0, MB_BIOS_END - MB_BIOS_BEGIN);
+ memset(p, 0, MB_BIOS_SIZE);
p = guest_flat_to_host(kvm, VGA_ROM_BEGIN);
- memset(p, 0, VGA_ROM_END - VGA_ROM_BEGIN);
+ memset(p, 0, VGA_ROM_SIZE);
/* just copy the bios rom into the place */
p = guest_flat_to_host(kvm, MB_BIOS_BEGIN);
@@ -21,9 +21,11 @@
#define BDA_START 0x00000400
#define BDA_END 0x000004ff
+#define BDA_SIZE (BDA_END - BDA_START + 1)
#define EBDA_START 0x0009fc00
#define EBDA_END 0x0009ffff
+#define EBDA_SIZE (EBDA_END - EBDA_START + 1)
#define E820_MAP_START EBDA_START
@@ -43,6 +45,7 @@
#define VGA_ROM_MODES (VGA_ROM_OEM_STRING + VGA_ROM_OEM_STRING_SIZE)
#define VGA_ROM_MODES_SIZE 32
#define VGA_ROM_END 0x000c7fff
+#define VGA_ROM_SIZE (VGA_ROM_END - VGA_ROM_BEGIN + 1)
/* we handle one page only */
#define VGA_RAM_SEG (VGA_RAM_BEGIN >> 4)
In e820_setup(), the memory region of MB_BIOS is [MB_BIOS_BEGIN, MB_BIOS_END], so its memory size should be MB_BIOS_SIZE (= MB_BIOS_END - MB_BIOS_BEGIN + 1). The same thing goes for BDA, EBDA, MB_BIOS and VGA_ROM in setup_bios(). By the way, a little change is made in setup_irq_handler() to avoid using hard coding. Changes since v1: - Adopt Will's suggestions - A little change in setup_irq_handler() Signed-off-by: Sicheng Liu <lsc2001@outlook.com> --- x86/bios.c | 13 +++++++------ x86/include/kvm/bios.h | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-)