加载内核时 QEMU 崩溃

发布于 2024-10-10 15:00:42 字数 1773 浏览 0 评论 0 原文

我已经创建了一个 C 内核,并且正在 QEMU 模拟器中加载该内核。但是当我加载内核时,QEMU 似乎崩溃了,并且它抱怨无法访问 kvm 文件夹。是否意味着kvm丢失,或者我不是管理员;因为我是以 root 管理员身份登录的。这是来自终端的错误信息:

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

该错误似乎还显示了信息,似乎是 NASM 寄存器,并且它抱怨找不到 ROM 文件。所以有人可以告诉我我做错了什么吗,我会感谢你的时间和努力。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落□心尘 2024-10-17 15:00:42

Ben Voigt 提出的建议不是你的问题。当我运行内核时,我有完全相同的输出,并且不会引起任何问题。

QEMU 中止的原因如下:

qemu:致命:尝试在 RAM 或 ROM 之外的 0x000a0000 处执行代码

这意味着您的内核尝试从无效的内存位置执行代码。因此,这是内核中的一个错误,与 QEMU 无关。

编辑:只是提示您的错误可能在哪里。查看寄存器转储,很明显最后执行的指令略低于 640K(位于 0x9fffb)。在我的机器上,QEMU 将 637K 到 1M 之间的所有内存报告为不可用。您必须始终小心,不要使用不可用的内存。一个安全的选择是保持在 637K 以下,直到您能够获得内存映射并知道您可以使用哪些内存。

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.

z祗昰~ 2024-10-17 15:00:42

首先,如果没有kvm,即在使用qemu之前,您必须“modprobe kvm”和“modprobe kvm_intel”(或者modprobe kvm_amd”,如果您使用的是基于AMD的处理器)来加载kvm内核模块。但是当qemu检测到那里时没有加载 kvm,意味着 /dev/kvm 不存在,那么它仍然会继续执行,除了没有硬件虚拟化(参见 http://en.wikipedia.org/wiki/X86_virtualization)。

选项 rom (“pxe-rtl8139.bin”) 也不是阻碍因素,我想想,这就是为什么它仍然继续执行(参见Qemu源代码):

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

但是你的情况的主要错误是地址0xa000:

“尝试在RAM或ROM之外的0x000a0000处执行代码

”是非法的 - 因为高于 0xa0000 的地址称为内存漏洞。请参阅以下图表:

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

描述了编写引导加载程序所需的任务(请参阅第 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);
}

正如你所看到的,该错误是一个严重的“cpu_abort()”严重错误。本质上,在 CMU 的上面的引导加载程序文章的第 5 页 0xa0000 是实模式启动期间可以访问的最高地址。

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.

疧_╮線 2024-10-17 15:00:42

你需要解决这个问题:

pci_add_option_rom:找不到 rom 文件“pxe-rtl8139.bin”

要么提供必要的文件(重新安装 qemu?),要么更改 VM 配置并删除网卡。如果没有此文件,虚拟网络将无法运行。

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.

抽个烟儿 2024-10-17 15:00:42

我认为,您应该指向有效的 bzImage 而不是 os.bin。我个人使用 kvm -kernel arch/x86/boot/bzImage。

有两个很好的教程

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

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

有一些不错的技巧

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文