Created
November 9, 2010 07:43
-
-
Save hktechn0/668823 to your computer and use it in GitHub Desktop.
Multiboot Specification Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bits 32 | |
section .text | |
extern osmain | |
global start | |
global _start | |
global hlt_loop | |
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 | |
MULTIBOOT_HEADER_FLAGS equ 0x00000001 | |
start: | |
_start: | |
jmp multiboot_entry | |
align 4 | |
multiboot_header: | |
;; MULTIBOOT HEADER | |
dd MULTIBOOT_HEADER_MAGIC | |
dd MULTIBOOT_HEADER_FLAGS | |
dd -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) | |
multiboot_entry: | |
mov esp, stack | |
push ebx ; multiboot info structure | |
push eax ; multiboot header magic | |
call osmain | |
hlt_loop: | |
hlt | |
jmp hlt_loop | |
stack_top: | |
section .bss | |
resb 0x4000 | |
stack: nop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define VRAM_TEXT_ADDR 0x000b8000 | |
#define VRAM_TEXT_WIDTH 80 | |
#define VRAM_TEXT_HEIGHT 25 | |
typedef struct { | |
char ch; | |
char attr; | |
} char_vga; | |
void puts(char *str) | |
{ | |
char_vga *vram = (char_vga *)VRAM_TEXT_ADDR; | |
while(*str != '\0') { | |
vram->attr = 0x0f; | |
vram->ch = *(str++); | |
vram++; | |
} | |
} | |
void osmain(void) | |
{ | |
puts("Hello world!"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFLAGS = -fno-builtin -fhosted -ffreestanding -nostdlib -nodefaultlibs | |
all: | |
nasm -f elf boot.asm -o boot.o | |
gcc $(CFLAGS) -o kernel.o -c kernel.c | |
ld -Ttext=0x100000 --oformat elf32-i386 boot.o kernel.o -o os.bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment