Question

I've created a C kernel, and I'm loading the kernel in the QEMU emulator. But when I load the kernel, it seems to crash QEMU and it complains that it can't access the kvm folder. Does it mean that kvm is missing, or that I'm not as an administrator; because I logged in as a root administrator. Here is the error information, that originated from the Terminal:

danny@ubuntu:~/Desktop$ sudo qemu -kernel os.bin
open /dev/kvm: No such file or directory
Could not initialize KVM, will disable KVM support
pci_add_option_rom: failed to find romfile "pxe-rtl8139.bin"
qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000

EAX=00004500 EBX=00000000 ECX=00000000 EDX=00000000
ESI=00000000 EDI=00000000 EBP=00000000 ESP=00009fe0
EIP=0000fdfb EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =9000 00090000 ffffffff 00cf9300
CS =9020 00090200 0000ffff 00009b0f
SS =9000 00090000 0000ffff 00009300
DS =9000 00090000 0000ffff 00009300
FS =9000 00090000 0000ffff 00009300
GS =9000 00090000 0000ffff 00009300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     000cba40 00000017
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00004500 CCD=00004546 CCO=ADDB    
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
Aborted

The error also seems to show information, that seems to be NASM registers, and it complains that it couldn't find a ROM file. So could anyone please tell me what I'm doing wrong, I'd appreciate your time, and effort.

Was it helpful?

Solution

The suggestion made by Ben Voigt is not your problem. I have the exact same output when I run my kernel and it doesn't cause any problems.

The reason QEMU aborts is the following:

qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000

This means your kernel tries to execute code from an invalid memory location. Thus, it's a bug in your kernel and has nothing to do with QEMU.

Edit: Just a hint on where your bug may be. Looking at your register dump, it is clear that the last executed instruction is just below 640K (at 0x9fffb). On my machine, QEMU reports all memory between 637K and 1M as unavailable. You always have to be careful not to use unavailable memory. A safe bet is to just stay below 637K until you are able to get a memory map and know what memory you can use.

OTHER TIPS

Firstly if there is no kvm, ie, u must "modprobe kvm" and "modprobe kvm_intel" (or modprobe kvm_amd" if you are on AMD-based processor), to load the kvm kernel module before using qemu. But when qemu detected there is no kvm loaded, meaning /dev/kvm is not present, then it will still go ahead with the execution, except there is no hardware virtualization (see http://en.wikipedia.org/wiki/X86_virtualization).

Neither is the option rom ("pxe-rtl8139.bin") the showstopper, I think, which is why it still continue execution (see Qemu source code):

./hw/pci.c:
        error_report("%s: failed to find romfile \"%s\"",

But the main error in your case is the address 0xa000:

"Trying to execute code outside RAM or ROM at 0x000a0000"

And that is illegal - as the address higher than 0xa0000 is called the memory hole. Refer to the diagram in:

http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf

which describe the task needed in writing a bootloader (see page 15 for the description on memory hole).

    static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong addr)
{
    int mmu_idx, page_index, pd;
    void *p;

    page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
    mmu_idx = cpu_mmu_index(env1);
    if (unlikely(env1->tlb_table[mmu_idx][page_index].addr_code !=
                 (addr & TARGET_PAGE_MASK))) {
        ldub_code(addr);
    }
    pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK;
    if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
        cpu_abort(env1, "Trying to execute code outside RAM or ROM at 0x" TARGET_FMT_lx "\n", addr);
    }
    p = (void *)((uintptr_t)addr + env1->tlb_table[mmu_idx][page_index].addend);
    return qemu_ram_addr_from_host_nofail(p);
}

And as u can see, the error is a serious "cpu_abort()" serious error. Essentially, in page 5 of the CMU's bootloader article above 0xa0000 is the highest address u can access during realmode bootup.

You need to fix this:

pci_add_option_rom: failed to find romfile "pxe-rtl8139.bin"

Either provide the necessary file (re-install qemu?) or change the VM configuration and remove the network card. The virtual network can't operate without this file.

I think, You should point to valid bzImage instead of os.bin. Personally I use kvm -kernel arch/x86/boot/bzImage.

There are two nice tutorials

http://softperience.eu/wiki/Wiki.jsp?page=Developing%20Linux%20Kernel%20with%20Netbeans

http://softperience.eu/wiki/Wiki.jsp?page=Advanced%20Linux%20Kernel%20Developing%20with%20Netbeansw

with few nice tricks

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