Simplified boot script.

This commit is contained in:
neviyn 2017-10-21 17:11:36 +01:00
parent eee9b56f86
commit c05bcbec88

68
boot.s
View File

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