在Grub2中引导自定义内核

时间:2013-06-30 10:58:36

标签: assembly x86 osdev multiboot

我想用Grub2启动自定义内核。我使用旧的(grub 1)多引导头:

.set flags, 0x0
.set magic, 0x1badb002
.set checksum, -(magic + flags)

.align 4
.long magic
.long flags
.long checksum

...

movl %eax, magic

但它不适用于Grub2,所以我搜索了新的Multiboot规范并找到它:http://bzr.savannah.gnu.org/lh/grub/branches/multiboot2/annotate/head:/doc/multiboot2.h (这不是一个真正的规范,它只是一个头文件)

所以,现在我正在使用这个多引导头:

.set flags, 0x0
.set magic, 0xe85250d6
.set magic_the_second, 0x36d76289
.set checksum, -(magic + flags)

.align 4
.long magic
.long flags
.long checksum

...

movl %eax, magic_the_second

但它也不起作用:     没有多重引导标题

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

Multiboot 2使用与原始多重引导不同的结构(即,它使用标记结构)。

这是我的一个旧项目的示例标题:

    # multiboot 2 header (see http://download-mirror.savannah.gnu.org/releases/grub/phcoder/multiboot.pdf)
    .balign 8
mbhdr:
    .long 0xe85250d6 # magic
    .long 0 # architecture (i386, 32-bit)
    .long .LhdrEnd-mbhdr # header length
    .long -(.LhdrEnd-mbhdr+0xe85250d6) # checksum
    # tags
    # module align
    .word 6 # type
    .word 0 # flags
    .long 8 # size in bytes (spec says 12?)
    .balign 8
    # loader entry
    .word 3
    .word 0
    .long 12
    .long entry
    .balign 8
    # console flags
    .word 4
    .word 0
    .long 12
    .long 0x03 # EGA text support, require console
    .balign 8
    # info request 
    .word 1
    .word 0
    .long 4*6+8
    .long 5 # BIOS boot device
    .long 1 # command line
    .long 3 # modules
    .long 9 # ELF symbols
    .long 6 # memory map
    .long 10 # APM table
    .balign 8
    # address info
    .word 2 # type
    .word 0 # flags
    .long 24 # size
    .long mbhdr # header load addr
    .long 0x100000 # load addr
    .long 0 # load end addr (entire file)
    .long 0 # BSS end addr (no BSS)
    .balign 8
    # terminating tag
    .word 0
    .word 0
    .long 8
.LhdrEnd: