Question

I have simple task - RUN THIS CODE "boothi.asm":

use16 
org 0x7C00 

    xor ax, ax 
    mov es, ax 
    mov ds, ax 
    mov ss, ax 
    mov sp, 0x1000 

    mov ax, 3 
    int 10h 

    mov si, mHello
    call print

die: jmp short die

mHello db 'Hello, world - i was booted!',10,13,0


print:
    cld
    pusha
.PrintChar:
    lodsb
    test al, al
    jz short .Exit
    mov ah, 0eh
    mov bl, 7
    int 10h
    jmp short .PrintChar
.Exit:
    popa
    ret

I have compile it with:

nasm -f bin boothi.asm -o boothi.bin

But i don't understand - HOW can i run it on virtual machine to test. I try to crate floppy disk image and run it with qemu like this:

dd if=/dev/zero of=disk.img bs=1024 count=1440
dd if=boothi.bin of=disk.img conv=notrunc

But on the next step -

qemu -fda disk.img -boot a

I have strange trouble-

Could not access KVM kernel module: No such file or directory
failed to initialize KVM: No such file or directory

I try to install qemu and kvm. But this error are in. But qemu try to run this code and check all devices - hard\cdrom\floppy - and write smth like "there is no sustem to load\boot". How can i test this asm code on Ubuntu?


Output of commands on my PC:

root@alena-VirtualBox:~# ls -l /dev/kvm
ls: cannot access /dev/kvm: No such file or directory
root@alena-VirtualBox:~# lsmod|grep kvm
kvm                   359488  0 
root@alena-VirtualBox:~# groups
root
root@alena-VirtualBox:~# qemu -version
No command 'qemu' found, did you mean:
 Command 'qtemu' from package 'qtemu' (universe)
 Command 'aqemu' from package 'aqemu' (universe)
qemu: command not found
root@alena-VirtualBox:~# qemu-system-i386 -version
QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice Bellard
root@alena-VirtualBox:~# cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 42
model name  : Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
stepping    : 7
microcode   : 0x616
cpu MHz     : 2469.580
cache size  : 6144 KB
fdiv_bug    : no
hlt_bug     : no
f00f_bug    : no
coma_bug    : no
fpu     : yes
fpu_exception   : yes
cpuid level : 5
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc up pni monitor ssse3 lahf_lm
bogomips    : 4939.16
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:
Was it helpful?

Solution

Looking at your assembler, you need to add a boot signature to the end of the boot sector - 0xaa55 - see http://www.nondot.org/sabre/os/files/Booting/nasmBoot.txt

I added the following two lines and your example then worked:

times 510-($-$$) db 0   ; Fill the file with 0's
dw 0AA55h               ; End the file with AA55

OTHER TIPS

If your system supports hardware virtualisation

That error message means that qemu is trying to use kvm for virtualisation and cannot access the kvm kernel device. You will probably find that the file /dev/kvm is not present.

Your host needs the kvm kernel module loaded.

You can check if the module is loaded by running:

lsmod|grep kvm

If that produces no output, you could execute the following command to load the module:

sudo modprobe kvm

If you are then able to run qemu, you can make the change persistent by adding the following line to the file /etc/modules:

kvm

Otherwise

You can check the output of /proc/cpuinfo field flags for vt or lbrv or svm, if none of those are present virtualisation may not be supported.

You may also need to first enable virtualisation in your BIOS.

If your computer does not support hardware virtualisation, this will still not work.

In which case you may need to force emulation, for example:

qemu -machine pc,accel=tcg (...other options...)

Note

This behaviour may be a function of the version of qemu and Ubuntu you are using; on Debian wheezy amd64 qemu seems to automatically fallback if kvm is not loaded.

[Edit - notes about hardware virtualisation, etc.]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top