diff --git a/boot.s b/boot.s index bda89a0..21f0c4f 100644 --- a/boot.s +++ b/boot.s @@ -1,58 +1,32 @@ -global start -extern kernel_main ; Allow main() to be called from the assembly code -extern start_ctors, end_ctors, start_dtors, end_dtors - -MODULEALIGN equ 1<<0 -MEMINFO equ 1<<1 -FLAGS equ MODULEALIGN | MEMINFO -MAGIC equ 0x1BADB002 -CHECKSUM equ -(MAGIC + FLAGS) - -section .text ; Next is the Grub Multiboot Header - +; http://wiki.osdev.org/Bare_Bones_with_NASM +MBALIGN equ 1<<0 ; align loaded modules on page boundaries +MEMINFO equ 1<<1 ; provide memory map +FLAGS equ MBALIGN | MEMINFO ; this is the Multiboot 'flag' field +MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header +CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot + +section .multiboot align 4 -MultiBootHeader: - dd MAGIC - dd FLAGS - dd CHECKSUM - -STACKSIZE equ 0x4000 ; 16 KiB if you're wondering - -static_ctors_loop: - mov ebx, start_ctors - jmp .test -.body: - call [ebx] - add ebx,4 -.test: - cmp ebx, end_ctors - jb .body - -start: - mov esp, STACKSIZE+stack - - push eax - push ebx - - call kernel_main - -static_dtors_loop: - mov ebx, start_dtors - jmp .test -.body: - call [ebx] - add ebx,4 -.test: - cmp ebx, end_dtors - jb .body - - -cpuhalt: - hlt - jmp cpuhalt - + dd MAGIC + dd FLAGS + dd CHECKSUM + section .bss -align 32 - -stack: - resb STACKSIZE +align 16 +stack_bottom: +resb 16384 ; 16 KiB +stack_top: + +section .text +global _start:function (_start.end - _start) +_start: + + mov esp, stack_top + + extern kernel_main + call kernel_main + + cli +.hang: hlt + jmp .hang +.end: