kvm-hello-world
kvm-hello-world copied to clipboard
No real-mode output?
Notice, no output after "Testing real mode".
$make
cc -Wall -Wextra -Werror -O2 -g -c -o kvm-hello-world.o kvm-hello-world.c
as -o guest16.o guest16.s
cc -Wall -Wextra -Werror -O2 -g -m32 -ffreestanding -fno-pic -c -o guest32.o guest.c
ld -T guest.ld -m elf_i386 guest32.o -o guest32.img
ld -b binary -r guest32.img -o guest32.img.o
cc -Wall -Wextra -Werror -O2 -g -m64 -ffreestanding -fno-pic -c -o guest64.o guest.c
ld -T guest.ld guest64.o -o guest64.img
ld -b binary -r guest64.img -o guest64.img.o
ld -T payload.ld -o payload.o
cc kvm-hello-world.o payload.o -o kvm-hello-world
./kvm-hello-world
Testing real mode
./kvm-hello-world -s
Testing protected mode
Hello, world!
./kvm-hello-world -p
Testing 32-bit paging
Hello, world!
./kvm-hello-world -l
Testing 64-bit mode
Hello, world!
.code16
.global code16, code16_end
guest16:
mov $0xe9, %dx # io port 0xe9
# load the address location to bx, then data to al, then compare with null, if yes, break,
mov $message, %bx
loaddata:
mov (%bx), %al
cmpb $0,%al
jz done
out %al, (%dx)
inc %bx
jmp loaddata
done:
movw $42, %ax
movw %ax, 0x400
hlt
message:
.ascii "Hello world\n"
guest16_end: