简体   繁体   English

加载内核时QEMU崩溃

[英]QEMU Crashes When Loading Kernel

I've created a C kernel, and I'm loading the kernel in the QEMU emulator. 我已经创建了一个C内核,我正在QEMU模拟器中加载内核。 But when I load the kernel, it seems to crash QEMU and it complains that it can't access the kvm folder. 但是当我加载内核时,它似乎崩溃QEMU并且它抱怨它无法访问kvm文件夹。 Does it mean that kvm is missing, or that I'm not as an administrator; 这是否意味着缺少kvm,或者我不是管理员; because I logged in as a root administrator. 因为我以root管理员身份登录 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. 该错误似乎也显示信息,似乎是NASM寄存器,它抱怨它无法找到ROM文件。 So could anyone please tell me what I'm doing wrong, I'd appreciate your time, and effort. 所以有人可以告诉我我做错了什么,我很感激你的时间和努力。

The suggestion made by Ben Voigt is not your problem. Ben Voigt提出的建议不是你的问题。 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中止的原因如下:

qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000 qemu:致命:尝试在0x000a0000的RAM或ROM外执行代码

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. 因此,它是内核中的一个错误,与QEMU无关。

Edit: Just a hint on where your bug may be. 编辑:只是提示你的bug可能在哪里。 Looking at your register dump, it is clear that the last executed instruction is just below 640K (at 0x9fffb). 查看寄存器转储,很明显最后执行的指令刚好低于640K(在0x9fffb)。 On my machine, QEMU reports all memory between 637K and 1M as unavailable. 在我的机器上,QEMU报告637K和1M之间的所有内存都不可用。 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. 一个安全的选择是保持在637K以下,直到你能够获得一张内存映射并知道你可以使用的内存。

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 ). 首先,如果没有kvm,即你必须“modprobe kvm”和“modprobe kvm_intel”(或modprobe kvm_amd“,如果你在基于AMD的处理器上),在使用qemu之前加载kvm内核模块。但是当qemu在那里检测到没有加载kvm,意味着/ dev / kvm不存在,那么它仍将继续执行,除了没有硬件虚拟化(参见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): 选择rom(“pxe-rtl8139.bin”)也不是showstopper, 我认为 ,这就是为什么它仍然继续执行(参见Qemu源代码):

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

But the main error in your case is the address 0xa000: 但是你的主要错误是地址0xa000:

"Trying to execute code outside RAM or ROM at 0x000a0000" “尝试在0x000a0000处执行RAM或ROM外部的代码”

And that is illegal - as the address higher than 0xa0000 is called the memory hole. 这是非法的 - 因为高于0xa0000的地址称为内存空洞。 Refer to the diagram in: 请参考以下图表:

http://www.cs.cmu.edu/~410-s07/p4/p4-boot.pdf 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). 其中描述了编写引导加载程序所需的任务(有关内存孔的说明,请参见第15页)。

    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. 正如你所看到的,错误是一个严重的“cpu_abort()”严重错误。 Essentially, in page 5 of the CMU's bootloader article above 0xa0000 is the highest address u can access during realmode bootup. 基本上,在CMU 上面引导加载程序文章的第5页中 0xa0000是您在realmode启动期间可以访问的最高地址。

You need to fix this: 你需要解决这个问题:

pci_add_option_rom: failed to find romfile "pxe-rtl8139.bin" pci_add_option_rom:找不到romfile“pxe-rtl8139.bin”

Either provide the necessary file (re-install qemu?) or change the VM configuration and remove the network card. 要么提供必要的文件(重新安装qemu?),要么更改VM配置并删除网卡。 The virtual network can't operate without this file. 没有此文件,虚拟网络无法运行。

I think, You should point to valid bzImage instead of os.bin. 我想,你应该指向有效的bzImage而不是os.bin。 Personally I use kvm -kernel arch/x86/boot/bzImage. 我个人使用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=Developing%20Linux%20Kernel%20with%20Netbeans

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

with few nice tricks 几个不错的技巧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM