aboutsummaryrefslogtreecommitdiffhomepage
path: root/guest
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2021-05-26 00:21:06 +0200
committerjohannst <johannes.stoelp@gmail.com>2021-05-26 00:21:06 +0200
commit786a195f8e81d4f7c0af2a82b9d458361d424a71 (patch)
treec0df3de9a71e3ae1db1cdf4a59cde6d1accadf33 /guest
downloadmini-kvm-rs-786a195f8e81d4f7c0af2a82b9d458361d424a71.tar.gz
mini-kvm-rs-786a195f8e81d4f7c0af2a82b9d458361d424a71.zip
minimal KVM abstraction + real mode guest example
Diffstat (limited to 'guest')
-rw-r--r--guest/Makefile8
-rw-r--r--guest/guest.ld9
-rw-r--r--guest/guest16.S21
3 files changed, 38 insertions, 0 deletions
diff --git a/guest/Makefile b/guest/Makefile
new file mode 100644
index 0000000..e3f1e1b
--- /dev/null
+++ b/guest/Makefile
@@ -0,0 +1,8 @@
+guest16: guest.ld guest16.S
+ $(CC) $(CFLAGS) -m16 -o $@ -nostdlib -ffreestanding -Wpedantic -Wall -Wextra -Werror -T guest.ld guest16.S
+
+disasm: guest16
+ objdump -D -b binary -m i8086 -M intel $^
+
+clean:
+ $(RM) guest16
diff --git a/guest/guest.ld b/guest/guest.ld
new file mode 100644
index 0000000..5c81da9
--- /dev/null
+++ b/guest/guest.ld
@@ -0,0 +1,9 @@
+OUTPUT_FORMAT(binary)
+
+SECTIONS {
+ .boot : { *(.boot) }
+ .text : { *(.text) }
+ .data : { *(.data) }
+ .rodata : { *(.rodata) }
+ /DISCARD/ : { *(.*) }
+}
diff --git a/guest/guest16.S b/guest/guest16.S
new file mode 100644
index 0000000..7f0be0e
--- /dev/null
+++ b/guest/guest16.S
@@ -0,0 +1,21 @@
+.code16
+.intel_syntax noprefix
+
+.section .boot, "ax", @progbits
+ // Trigger `KVM_EXIT_IO:KVM_EXIT_IO_OUT` by writing string to output port.
+ mov dx, 0x1000 // Output port.
+ lea si, [msg] // Address of string.
+ mov cx, [msg_len] // Len of string.
+ rep outsb dx, ds:[si] // Write out string bytes.
+
+ // Trigger `KVM_EXIT_MMIO` by writing to non mapped physical address.
+ mov byte ptr ds:[0x2000], 0xaa
+
+ // Trigger `KVM_EXIT_HLT`.
+ hlt
+
+.section .rodata, "a", @progbits
+msg:
+ .asciz "Hello from Real Mode!\n"
+msg_len:
+ .byte .-msg