QEMU 在启动源代码来自 OSDev wiki 的简单自制操作系统内核时不输出任何内容

问题描述 投票:0回答:0

我正在尝试启动代码为osdev.org的内核,但无论我如何尝试,我都无法获得正确的输出。

我用QEMU这样引导内核:

qemu-system-i386 -kernel myos.elf -serial stdio

而且它没有输出“你好,内核世界! “ 内核应该输出:

$ qemu-system-i386 -kernel myos.elf -serial stdio
VNC server running on 127.0.0.1:5900


如上图,QEMU只输出

VNC server running on 127.0.0.1:5900

然后我尝试用gdb调试内核,但是gdb告诉我刚一连接gdb遥控器就关闭了

# at the first terminal
$ qemu-system-i386 -s -S -kernel myos.elf -serial stdio
VNC server running on 127.0.0.1:5900


# at the another terminal
$PREFIX/bin/i686-elf-gdb ./myos.elf 
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=i686-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./myos.elf...
(gdb) target remote 127.0.0.1:5900
Remote debugging using 127.0.0.1:5900
Remote connection closed
(gdb) 

我尝试使用选项

-d int
看看发生了什么:

$ qemu-system-i386 -d int -kernel myos.elf -serial stdio
VNC server running on 127.0.0.1:5900
SMM: enter
EAX=00000001 EBX=00000000 ECX=02000000 EDX=02000628
ESI=0000000b EDI=02000000 EBP=00014c00 ESP=00006c5c
EIP=000eae92 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00cf9b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f61e0 00000037
IDT=     000f621e 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000080 CCD=00000001 CCO=LOGICB
EFER=0000000000000000
SMM: after RSM
EAX=00000001 EBX=00000000 ECX=02000000 EDX=02000628
ESI=0000000b EDI=02000000 EBP=00014c00 ESP=00006c5c
EIP=000eae92 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f61e0 00000037
IDT=     000f621e 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00000000 CCO=EFLAGS
EFER=0000000000000000
Servicing hardware INT=0x08
...

我把这些消息给chatgpt看,她告诉我

Servicing hardware INT=0x08
意味着内核运行良好这意味着它不能输出任何东西......

在 VMware 上使用 Ubuntu22.04,我自己编译了所需的工具(binutils、gdb、gcc、qemu、grub)

我的代码与 https://wiki.osdev.org/Bare_Bones 给出的代码相同。我尝试了 https://wiki.osdev.org/User:Zesterer/Bare_Bones 的代码,但失败了也是。

如果你能找出问题所在,我将非常感激,如果你能给出一个简单的解释,我将非常高兴。

ubuntu operating-system gdb kernel qemu
© www.soinside.com 2019 - 2024. All rights reserved.