qemu 应该可以直接当 bootloader 用吧?

2016-11-18 21:16:52 +08:00
 linux40

我抄了 nongnu.askapache.com/grub/phcoder/multiboot.pdf 里面的 kernel ,然后:

i686-elf-gcc -c boot.S -march=i386
i686-elf-gcc -c kernel.c -march=i386
i686-elf-gcc boot.o kernel.o -o kernel -march=i386 -nostartfiles -nodefaultlibs
qemu-system-i386 kernel

结果报错说:

WARNING: Image format was not specified for 'kernel' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

是 pdf 里面的代码有什么问题吗,链接顺序错了,还是 qemu 不能当 bootloader ?

3920 次点击
所在节点    Linux
9 条回复
reus
2016-11-18 22:38:35 +08:00
警告信息已经说得很明白了,解决方法都给出了。
linux40
2016-11-18 22:48:57 +08:00
@reus 显示指定 raw 格式?可我这是个镜像文件啊?
reus
2016-11-18 22:52:41 +08:00
@linux40 你那个只是内核文件吧?要处理成镜像文件。 qemu 不包括 bootloader ,只是模拟硬件而已。参考这个: http://wiki.osdev.org/Bare_Bones
reus
2016-11-18 22:55:39 +08:00
@linux40 哦,不用, qemu 支持直接启动 multiboot 内核,用 qemu-system-i386 -kernel kernel
linux40
2016-11-18 22:58:47 +08:00
@reus 可以了,虽然执行起来有问题。。。
linux40
2016-11-18 23:01:03 +08:00
@reus 咦,不对,它说我机器错了或跟本不是内核或 BIOS 。。。
linux40
2016-11-18 23:02:07 +08:00
Trying to execute code outside RAM or ROM at 0x000a0000
linux40
2016-11-18 23:04:29 +08:00
呃, grub-file --is-x86-multiboot 返回错误,明天再看吧。。。
linux40
2016-11-19 15:25:41 +08:00
-Wl,-N -Wl,-Ttext -Wl,80100000 -Wl,--build-id=none
上面这个链接器的选项是什么意思啊,不加的话 qemu 认为无效。
我新的编译选项是-fno-builtin -nostdinc -O -g -Wall
链接选项是-nostdlib -Wl,-N -Wl,-Ttext -Wl,80100000 -Wl,--build-id=none
而且,就算 qemu 识别成功了,但运行起来有问题, qemu 卡在 Booting for ROM 不动,而且一直运行中,可能无限循环了。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/321583

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX