V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
linux40
V2EX  ›  Linux

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

  •  
  •   linux40 · 2016-11-18 21:16:52 +08:00 · 3903 次点击
    这是一个创建于 2686 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我抄了 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 ?

    第 1 条附言  ·  2016-11-19 15:28:47 +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 不动,而且一直运行中,可能无限循环了。。。
    9 条回复    2016-11-19 15:25:41 +08:00
    reus
        1
    reus  
       2016-11-18 22:38:35 +08:00
    警告信息已经说得很明白了,解决方法都给出了。
    linux40
        2
    linux40  
    OP
       2016-11-18 22:48:57 +08:00
    @reus 显示指定 raw 格式?可我这是个镜像文件啊?
    reus
        3
    reus  
       2016-11-18 22:52:41 +08:00
    @linux40 你那个只是内核文件吧?要处理成镜像文件。 qemu 不包括 bootloader ,只是模拟硬件而已。参考这个: http://wiki.osdev.org/Bare_Bones
    reus
        4
    reus  
       2016-11-18 22:55:39 +08:00   ❤️ 1
    @linux40 哦,不用, qemu 支持直接启动 multiboot 内核,用 qemu-system-i386 -kernel kernel
    linux40
        5
    linux40  
    OP
       2016-11-18 22:58:47 +08:00
    @reus 可以了,虽然执行起来有问题。。。
    linux40
        6
    linux40  
    OP
       2016-11-18 23:01:03 +08:00
    @reus 咦,不对,它说我机器错了或跟本不是内核或 BIOS 。。。
    linux40
        7
    linux40  
    OP
       2016-11-18 23:02:07 +08:00
    Trying to execute code outside RAM or ROM at 0x000a0000
    linux40
        8
    linux40  
    OP
       2016-11-18 23:04:29 +08:00
    呃, grub-file --is-x86-multiboot 返回错误,明天再看吧。。。
    linux40
        9
    linux40  
    OP
       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 不动,而且一直运行中,可能无限循环了。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3251 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:43 · PVG 19:43 · LAX 04:43 · JFK 07:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.