From 9dbc5231dd738d97eea13f8ecf9005e5b78ea0d3 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Sun, 17 Dec 2023 13:21:21 -0600 Subject: Restructured --- src/boot/boot.s | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/boot/crti.s | 11 +++++++++++ src/boot/crtn.s | 7 +++++++ 3 files changed, 77 insertions(+) create mode 100644 src/boot/boot.s create mode 100644 src/boot/crti.s create mode 100644 src/boot/crtn.s (limited to 'src/boot') diff --git a/src/boot/boot.s b/src/boot/boot.s new file mode 100644 index 0000000..aba32ff --- /dev/null +++ b/src/boot/boot.s @@ -0,0 +1,59 @@ +MBALIGN equ 1<<0 ; Align loaded modules on page boundries */ +MBMEMINFO equ 1<<1 ; Provide memory map*/ +MBFLAGS equ MBALIGN | MBMEMINFO ; Multiboot flag field*/ +MAGIC equ 0x1BADB002 ;Lets bootloader find header*/ +CHECKSUM equ -(MAGIC + MBFLAGS) ; Proves we are multiboot via checksum*/ +CODESEG equ 0x08 +DATASEG equ 0x10 + +section .multiboot +align 4 + dd MAGIC + dd MBFLAGS + dd CHECKSUM + +section .bss +align 16 +stack_bottom: +resb 16384 +stack_top: + +section .text +global gdtr +gdtr: + dw 0 + dd 0 +global _start:function (_start.end - _start) +_start: + mov esp, stack_top + + extern get_gdtr + call get_gdtr + cli + lgdt [gdtr] + mov eax, cr0 + or al, 1 + mov cr0, eax + + call reloadSegments + + [bits 32] + extern kernel_main + call kernel_main + + + cli +.hang: hlt + jmp .hang +.end: + +reloadSegments: + JMP CODESEG:.reload_CS ; should def define a CODESEG +.reload_CS: + MOV AX, DATASEG + MOV DS, AX + MOV ES, AX ; TODO: Setup proper extra segment + MOV FS, AX ; TODO: Setup proper General purpose segments + MOV GS, AX ; ... + MOV SS, AX ; TODO: Setup proper stack segment + RET diff --git a/src/boot/crti.s b/src/boot/crti.s new file mode 100644 index 0000000..26d677a --- /dev/null +++ b/src/boot/crti.s @@ -0,0 +1,11 @@ +section .init +global _init:function +_init: + push ebp + mov ebp, esp, + +section .fini +global _fini +_fini: + push ebp + mov ebp, esp diff --git a/src/boot/crtn.s b/src/boot/crtn.s new file mode 100644 index 0000000..46f8de6 --- /dev/null +++ b/src/boot/crtn.s @@ -0,0 +1,7 @@ +section .init + pop ebp + ret + +section .fini + pop ebp + ret -- cgit v1.2.3