LoginSignup
0
0

More than 3 years have passed since last update.

grubでkernel起動

Last updated at Posted at 2019-12-04

概要

grubが入ったフロッピーイメージでkernelの様なものを起動する。
grubは、レガシーを使用。

開発のイメージ

①コンパイルする。
②フロッピーイメージにコピーする。
③qemuで実行する。

cygwinは、elfを吐かない。

grubは、elf形式のkernelが必要。
cygwinの標準のgccでは、elf形式は、扱わない。使えない。

開発環境

debian 6.0.7 sqeeze
grub 0.96

multiboot_headerが必要。

.text
.globl _start
.code16
_start:
    movb    $0x41, %al
    movb    $0x0e, %ah
    int     $0x10
    jmp     .

上記を以下でコンパイル。

$ gcc -c -nostdlib hello.S
$ ld hello.o

以下で、フロッピーイメージにコピー。

$ mount -t vfat -o loop fd.img /mnt
$ cp a.out /mnt/boot/nano.elf
$ umount /mnt

qemuで実行。

$ qemu -fda fd.img

以下で、grubでブート。

$ root (fd0)
$ kernel /boot/nano.elf
$ boot

以下のエラーが出る。
error 13 invalid or unsaported excutable format

Screenshot-1.png

multiboot_headerのエントリーポイントが必要。

bios callは、無理。

grubは、kernelを、プロテクトモードに持っていくようで、biosが呼べない。

kernalの様なもの。

.text
.globl _start
.globl multiboot_header
.code32

_start:
    movl    $0xb8000, %ebx
    movl    $12, %ecx
    movl    $msg, %esi
loop:
    movb    (%esi), %al
    movb    $2, %ah
    movw    %ax, (%ebx)
    addl    $2, %ebx
    addl    $1, %esi
    subl    $1, %ecx
    jne     loop
    jmp     .

.data
multiboot_header:
    .align 4
    .long   0x1badb002
    .long   0x0 
    .long   -0x1badb002-0x0
msg:
    .ascii "Hello world!"

以下のMakefileで、コンパイル。

all: test4.elf
test4.elf: hello.o
    ld -e_start -Ttext=0x100000 -otest4.elf hello.o
hello.o: hello.S
    gcc -c -nostdlib hello.S

結果

ビデオラムにhello worldを吐くだけ。

Screenshot.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0