I think so, here is the code:egos wrote:Do you use Multiboot header in your executable module? If so, check for its location within the first 8 Kbytes.
build.sh(compiling using cygwin):
Code: Select all
#!/bin/sh
build=temp_build
compiler=i586-elf-gcc
linker=i586-elf-ld
opt="-Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I./kernel/include -c -fno-strict-aliasing -fno-common -fno-stack-protector"
echo "Building..."
echo "============================================="
echo "--Building C files..."
$compiler $opt -o $build/main.o ./kernel/main.c
$compiler $opt -o $build/console.o ./kernel/drivers/console.c
$compiler $opt -o $build/gdt.o ./kernel/gdt.c
$compiler $opt -o $build/idt.o ./kernel/idt.c
$compiler $opt -o $build/isrs.o ./kernel/isrs.c
$compiler $opt -o $build/irq.o ./kernel/irq.c
$compiler $opt -o $build/timer.o ./kernel/timer.c
$compiler $opt -o $build/keyboard.o ./kernel/drivers/keyboard.c
echo "--Building ASM files..."
nasm -f elf ./kernel/loader.asm -o $build/loader.o
echo "--Linking files..."
$linker -T linker.ld $build/*.o
echo "--Cleaning up temporary files..."
rm $build/*.o
echo "--Putting on floppy image..."
mount A: /mnt/floppy
cp kernel.bin /mnt/floppy/
echo "============================================="
echo "Build completed!"
Code: Select all
ENTRY (loader)
OUTPUT ("kernel.bin")
addr = 0x100000;
SECTIONS
{
.text addr :
ALIGN(0x1000)
{
*(.text*);
*(.rodata*);
}
.data :
ALIGN(0x1000)
{
*(.data*);
}
.bss :
ALIGN(0x1000)
{
*(.bss*);
}
}
Code: Select all
bits 32
global loader
global magic
extern kmain
; Multiboot header
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
FLAGS equ MODULEALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
MultibootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
STACKSIZE equ 0x4000 ; 16KB
loader:
cmp eax, 0x2BADB002 ; verify booted with grub
jne .bad
mov esp, STACKSIZE + stack
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
push ebx
call kmain
;cli ; clear interrupts
;mov eax, cr0 ; set bit 0 in cr0--enter pmode
;or eax, 1
;mov cr0, eax
;cli
;hlt
.bad:
cli
hlt
align 4
stack:
TIMES STACKSIZE db 0
...
Code: Select all
...
void kmain(void* MultibootHeader)
{
...
for(;;);
}