Assembler kernel with multiboot
Posted: Wed Oct 14, 2009 8:46 am
Hello, I recently started out testing some osdev, first with some C tutorials, but have now decided to create my kernel in assembly and load it with grub.
It assemblies fine with NASM (nasm -f bin -o kernel.bin kernel.asm) but it won't boot with grub, I get a "Error 13: Invalid or unsupported executable format"
Can anyone take a quick look I can't figure out what I am doing wrong, I have checked some other assembler kernels thats multiboot but can't figure out what I'm doing wrong, code follows.
File: constants.asm
File: kernel.asm
It assemblies fine with NASM (nasm -f bin -o kernel.bin kernel.asm) but it won't boot with grub, I get a "Error 13: Invalid or unsupported executable format"
Can anyone take a quick look I can't figure out what I am doing wrong, I have checked some other assembler kernels thats multiboot but can't figure out what I'm doing wrong, code follows.
File: constants.asm
Code: Select all
; asmsyntax=nasm
;;;;;;;;;;;;;;;;;;;;;;;; MULTIBOOT
MB_MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MB_MEMINFO equ 1<<1 ; provide memory map
MB_AOUT equ 1<<16
MB_FLAGS equ MB_MODULEALIGN | MB_MEMINFO | MB_AOUT ; this is the Multiboot 'flag' field
MB_MAGIC equ 0x1badb002 ; 'magic number' lets bootloader find the header
MB_CHECKSUM equ -(MB_MAGIC + MB_FLAGS) ; checksum required
;;;;;;;;;;;;;;;;;;;;;;;; KERNEL STUFF
STACKSIZE equ 0x4000 ; set size for stack, 16k stack
;;;;;;;;;;;;;;;;;;;;;;;; OTHER STUFF
VIDEO_MEMORY equ 0xb8000
Code: Select all
; asmsyntax=nasm
ORG 0x100000
BITS 32
CPU 386
%include "constants.asm" ; Alot of constants for making things easier.
MultiBootHeader:
dd MB_MAGIC
dd MB_FLAGS
dd MB_CHECKSUM
dd MultiBootHeader
dd kernel_start
dd kernel_end
dd kernel_end
dd kernel_start
kernel_start:
mov esp, 0x1ffffc ; set up the stack
push eax ; pass Multiboot magic number
push ebx ; pass Multiboot info structure
mov [0xb8000], dword 0x07690748
cli
hang:
hlt ; halt machine should kernel return
jmp hang
kernel_end: