Code: Select all
/* kernel.c */
#define MULTIBOOT_HEADER_MAGIC 0x1badb002
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2badb002
#define MULTIBOOT_PAGE_ALIGN 0x00000001
#define MULTIBOOT_MEMORY_INFO 0x00000002
#define MULTIBOOT_VIDEO_MODE 0x00000004
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
#define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE)
typedef unsigned long int dword;
typedef struct {
dword magic;
dword flags;
dword checksum;
dword header_addr;
dword load_addr;
dword load_end_addr;
dword bss_end_addr;
dword entry_addr;
} __attribute__ ((aligned (4))) multiboot_t;
void kernel();
void _start() { kernel(); }
void kernel() {
for(;;);
}
multiboot_t multiboot = {
MULTIBOOT_HEADER_MAGIC,
MULTIBOOT_HEADER_FLAGS,
-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS),
0x100800,
0x100000,
0x200000,
0x200000,
0x100000
};
Code: Select all
# gcc -O0 -fno-stack-protector -ffreestanding -Wall -c kernel.c -o kernel.o
# ld -Ttext=0x100000 -Tdata=0x100800 --oformat=binary kernel.o -o kernel.bin
# mbchk kernel.bin
kernel.bin: The Multiboot header is found at the offset 2048.
kernel.bin: Page alignment is turned off.
kernel.bin: Memory information is turned on.
kernel.bin: Address fields is turned on.
kernel.bin: All checks passed.
Code: Select all
# dd if=/dev/zero of=floppy.img bs=1024 count=1440
# losetup /dev/loop0 floppy.img
# mkfs -q /dev/loop0
# mount /dev/loop0 /mnt/fdd/
# mkdir -p /mnt/fdd/boot/grub
# cp /boot/grub/stage[12] /mnt/fdd/boot/grub/
# cp kernel.bin /mnt/fdd/
# grub --device-map=/dev/null
grub> device (fd0) /dev/loop0
grub> root (fd0)Unknown partition table signature
grub> setup (fd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... no
Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst "... succeeded
Done.
grub> quit
# umount /mnt/fdd/
# losetup -d /dev/loop0
What's wrong in my code, please help.