GRUB Trouble

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Guest

GRUB Trouble

Post by Guest »

Apparently my kernel does no have a multiboot header (according to mbchk) but I'm sure I put it there! Any help?

Here is the beginning of my startup code:

Code: Select all

[BITS 32]
[EXTERN kmain]
[GLOBAL entry]

MULTIBOOT_PAGE_ALIGN   equ 1<<0
MULTIBOOT_MEMORY_INFO  equ 1<<1
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
CHECKSUM               equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

section .text
align 4
mboot:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM
entry:
   mov esp, stack
   lgdt [GDT_DESC]



   ;; REFRESH SEGMENT REGISTERS & SETUP STACK
   mov ax, GDT_DATA
   mov ds, eax
   mov ss, eax
   mov es, eax
   mov fs, eax
   mov gs, eax
   
   ;; SWITCH TO 32 BIT INSTRUCTION SET
   ;; flush all 16 bit instructions out of the pipe
   ;; by issueing a long jump
   jmp dword GDT_CODE:bit32_clearpipe
   bit32_clearpipe:
   
   push ebx
   call kmain
   hlt
and my linker script:

Code: Select all

OUTPUT_FORMAT("elf32-i386")
OUTPUT(kernel.elf)
ENTRY(entry)
virt = 0x100000;
phys = 0x100000; /* 1 meg */
SECTIONS
{   .text virt : AT(phys)
    {   code = .;
        *(.text)
        . = ALIGN(4096); 
    }
    .data :  AT(phys + (data - code))
    {   data = .;
         *(.data)
         . = ALIGN(4096); 
    }
    .bss :  AT(phys + (bss - code))
    {   bss = .;
        *(.bss)
        *(COMMON)
        . = ALIGN(4096); 
    }
    end = .; 
}

and my build script:

Code: Select all

#!/bin/bash

clear
cd ..
# -Wall -W : show all warnings
# -I./include/ : get all include files from include
# -ffreestanding : don't use any lib-implemented builtins
# -Wno-unused-parameter : don't ***** about unused parameters
# -c : don't link
CFLAGS="-Wno-unused-parameter -Wall -W -I./include/ -ffreestanding -c"

# the echos should tell you enough about the modules
echo "Assembling Kernel Entry Code..."
echo "Assembling Hardware Interrupt Support..."
nasm -o start.o -f elf boot/start.asm

echo "Compiling kmain()..."
gcc $CFLAGS kernel/kmain.c -o kmain.o

echo "Compiling Port I/O Module..."
gcc $CFLAGS -o ports.o kernel/ports.c

echo "Compiling Text Video Driver..."
gcc $CFLAGS -o tvid.o kernel/tvid.c

echo "Compiling Kernel Library..."
gcc $CFLAGS -o lib.o lib/lib.c

echo "Compiling Interrupt Module..."
gcc $CFLAGS -o interrupts.o kernel/interrupts.c
gcc $CFLAGS -o irq.o kernel/irq.c

echo "Compiling Floppy Detection Module..."
gcc $CFLAGS -o floppy.o kernel/floppy.c

echo "Compiling System Clock..."
gcc $CFLAGS -Wno-unused-parameter -o timer.o kernel/timer.c

echo "Compiling Keyboard Modules..."
gcc $CFLAGS -Wno-unused-parameter -o kbd.o kernel/kbd.c

echo "Compiling Real Time Clock..."
gcc $CFLAGS -Wno-unused-parameter -o rtc.o kernel/rtc.c

echo "Compiling Memory Management Modules..."
gcc $CFLAGS -o mm.o mm/mm.c

# add additional C files here

echo "Linking Kernel..."
# link files, use buid/link.ld as the linker script
# put additional object files after kmain.o
ld -T build/link.ld --cref -Map kernel.map kmain.o ports.o tvid.o lib.o interrupts.o floppy.o irq.o timer.o kbd.o rtc.o mm.o start.o

gzip kernel.elf

mv kernel.elf.gz /boot/kernelgz

echo "Cleaning Up Binaries..."
# Clean up binaries
rm kmain.o ports.o tvid.o lib.o rtc.o mm.o start.o
rm interrupts.o floppy.o irq.o timer.o kbd.o

# Add any other things to clean up here

# Done
exit 0


mystran

Re:GRUB Trouble

Post by mystran »

You have to have the multiboot header within 8k from the beginning of your kernel. Easiest thing is to either give the object file containing the header as first file to linker, or put the multiboot header in a special section (I use section called .startup) and put that as first thing in your linker script.

You are putting the startup code as the last thing, so it probably won't fit within 8k, and so it doesn't work.
Post Reply