Code: Select all
#include "boot.h"
.code32
.globl start
.type start, @function
.extern kernel_main
.type kernel_main, @function
.bss
.comm stack, STACK_SIZE
.section .mboot
.align 4
.long MBOOT_HEADER_MAGIC
.long MBOOT_HEADER_FLAGS
.long MBOOT_CHECKSUM
.text
start:
movl $(stack + STACK_SIZE) , %esp
cli
call kernel_main
sti
hlt
jmp .
Code: Select all
#ifndef _BOOT_H_
#define _BOOT_H_
#define MBOOT_PAGE_ALIGN 1<<0
#define MBOOT_MEM_INFO 1<<1
#define MBOOT_HEADER_MAGIC 0x1BADB002
#define MBOOT_HEADER_FLAGS MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
#define MBOOT_CHECKSUM -( MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
#define STACK_SIZE 0x4000
#endif /* _BOOT_H_ */
Code: Select all
ENTRY(start)
OUTPUT_ARCH(i386)
OUTPUT_FORMAT("elf32-i386")
SECTIONS
{
. = 1M;
.mboot ALIGN(4K) :
{
*(.mboot)
}
.text ALIGN(4K) :
{
*(.text)
*(.rodata)
}
.data ALIGN(4K) :
{
*(.data)
}
.bss ALIGN(4K) :
{
*(.bss)
}
}
Code: Select all
qemu -kernel kernel.bin -monitor stdio