Skip to contentSkip to conversation

x86: realmode: fixes

PATCH Applied Nadav Amit 2 participants 6 messages Jun 26, 2020 KVM

lore
Share & tools
lore

Nadav Amit

author
#0 lore raw

cover x86: realmode: fixes

Some fixes for realmode tests.

Nadav Amit (3):
x86: realmode: initialize idtr
x86: realmode: hlt loop as fallback on exit
x86: realmode: fix lss test

 x86/realmode.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/3 x86: realmode: initialize idtr

The realmode test does not initialize the IDTR, assuming that its base is zero and its limit 0x3ff. Initialize it, as the BIOS might not set it as such.

---
 x86/realmode.c | 2 ++
 1 file changed, 2 insertions(+)
x86/realmode.c +2 -0
index 234d607..ef79f7e 100644
@@ -1799,6 +1799,7 @@ void realmode_start(void)
 unsigned long long r_gdt[] = { 0, 0x9b000000ffff, 0x93000000ffff };
 
 struct table_descr r_gdt_descr = { sizeof(r_gdt) - 1, &r_gdt };
+struct table_descr r_idt_descr = { 0x3ff, 0 };
 
 asm(
 	".section .init \n\t"
@@ -1819,6 +1820,7 @@ asm(
 	".text \n\t"
 	"start: \n\t"
 	"lgdt r_gdt_descr \n\t"
+	"lidt r_idt_descr \n\t"
 	"ljmp $8, $1f; 1: \n\t"
 	".code16gcc \n\t"
 	"mov $16, %eax \n\t"
Signature · 1 line
2.20.1
maintainer
#2 lore raw

Re: [kvm-unit-tests PATCH 1/3] x86: realmode: initialize idtr

Quoted 3 lines · Nadav Amit

The realmode test does not initialize the IDTR, assuming that its base is zero and its limit 0x3ff. Initialize it, as the BIOS might not set it as such.

Rather the bootloader: realmode.flat is started as multiboot, that is in a 32-bit protected mode environment---which includes an IDT.

Paolo

Quoted 26 lines
---
 x86/realmode.c | 2 ++
 1 file changed, 2 insertions(+)
x86/realmode.c +2 -0
index 234d607..ef79f7e 100644
@@ -1799,6 +1799,7 @@ void realmode_start(void)
 unsigned long long r_gdt[] = { 0, 0x9b000000ffff, 0x93000000ffff };
 
 struct table_descr r_gdt_descr = { sizeof(r_gdt) - 1, &r_gdt };
+struct table_descr r_idt_descr = { 0x3ff, 0 };
 
 asm(
 	".section .init \n\t"
@@ -1819,6 +1820,7 @@ asm(
 	".text \n\t"
 	"start: \n\t"
 	"lgdt r_gdt_descr \n\t"
+	"lidt r_idt_descr \n\t"
 	"ljmp $8, $1f; 1: \n\t"
 	".code16gcc \n\t"
 	"mov $16, %eax \n\t"
author
#3 lore raw

PATCH 2/3 x86: realmode: hlt loop as fallback on exit

In reply to Nadav Amit

For systems without emulated devices (e.g., bare-metal), use halt-loop when exiting the realmode test.

---
 x86/realmode.c | 4 ++++
 1 file changed, 4 insertions(+)
x86/realmode.c +4 -0
index ef79f7e..301b013 100644
@@ -115,6 +115,10 @@ static int failed;
 static void exit(int code)
 {
 	outb(code, 0xf4);
+
+	while (1) {
+		asm volatile("hlt" ::: "memory");
+	}
 }
 
 struct regs {
Signature · 1 line
2.20.1
author
#4 lore raw

PATCH 3/3 x86: realmode: fix lss test

In reply to Nadav Amit

Running lss with some random descriptor and then performing pop does not work so well. Use mov instructions instead of push/pop pair.

---
 x86/realmode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
x86/realmode.c +2 -2
index 301b013..90ecd13 100644
@@ -1378,10 +1378,10 @@ static void test_lds_lss(void)
 		outregs.eax == (unsigned long)desc.address &&
 		outregs.ebx == desc.sel);
 
-	MK_INSN(lss, "pushl %ss\n\t"
+	MK_INSN(lss, "mov %ss, %dx\n\t"
 		     "lss (%ebx), %eax\n\t"
 		     "mov %ss, %ebx\n\t"
-		     "popl %ss\n\t");
+		     "mov %dx, %ss\n\t");
 	exec_in_big_real_mode(&insn_lss);
 	report("lss", R_AX | R_BX,
 		outregs.eax == (unsigned long)desc.address &&
Signature · 1 line
2.20.1
maintainer Applied
#5 lore raw
In reply to Nadav Amit
Quoted 10 lines · Nadav Amit

Some fixes for realmode tests.

Nadav Amit (3):
x86: realmode: initialize idtr
x86: realmode: hlt loop as fallback on exit
x86: realmode: fix lss test

 x86/realmode.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Queued, thanks.

Paolo