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
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
section .bss
align 16
stack_bottom:
resb 16384 ; 16 KiB
stack_top:
static_ctors_loop:
mov ebx, start_ctors
jmp .test
.body:
call [ebx]
add ebx,4
.test:
cmp ebx, end_ctors
jb .body
section .text
global _start:function (_start.end - _start)
_start:
start:
mov esp, STACKSIZE+stack
push eax
push ebx
mov esp, stack_top
extern kernel_main
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
section .bss
align 32
stack:
resb STACKSIZE
cli
.hang: hlt
jmp .hang
.end: