luxos/Kernel/loader.asm
Tiberiu Chibici 913e65b856 [GOOD] BUILD 0.1.0.450 DATE 8/29/2011 AT 10:30 AM
====================================================
+ Changed 'align 0x4' line above multiboot header in loader.asm to
'align 4'
+ Removed -e option for echo in build.sh
+ Modified build.sh for linux
+ Fixed triple fault when enabling paging
+ Fixed page faults at memory manager initialization
+ Fixed 'mem' console function
+ Added more info about page fault at crash screen
+ Added Panic() macro
+ Added verbose mode for memory manager

[ BAD] BUILD 0.1.0.390 DATE 8/27/2011 AT 10:54 PM
====================================================
+ Added stdlib routines, separated in different files
+ Rewritten physical memory manager
+ Added virtual mem manager
+ Added memory allocation/freeing
+ Added memory library
+ Added temporary allocation (at end of kernel), until paging is started
- Removed functionality from debug console function 'mem'
- Removed system.h, the one remaining function now in stdio.h
2021-09-14 18:48:57 +03:00

99 lines
1.7 KiB
NASM

bits 32
global start
; multiboot header
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
VIDEOINFO equ 1<<2
FLAGS equ MODULEALIGN | MEMINFO | VIDEOINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
align 4
section .__mbHeader
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
section .text
STACKSIZE equ 0x4000 ; that's 16k.
start:
XCHG BX, BX ; magic breakpoint
mov ecx, eax
; lgdt [trickgdt]
; mov ax, 0x10;
; mov ds, ax
; mov es, ax
; mov fs, ax
; mov gs, ax
; mov ss, ax
; jmp 0x08:HigherHalf ; NOTE: Must be absolute jump!
HigherHalf:
; Verify booted with multiboot compliant bootloader
mov esp, stack+STACKSIZE
cmp ecx, 0x2BADB002
jne .bad
push ebx
extern k_main
call k_main
; Show error message, and halt system
.bad:
extern ConsoleClear
extern ConsoleWrite
extern CommandOsver
call ConsoleClear
call CommandOsver
mov eax, [ErrorColor]
push eax
push ErrorString
call ConsoleWrite
cli
hlt
; some variables
ErrorString db 0xA, "%#! Fatal error: Not booted with multiboot compliant bootloader (e.g. GRUB).", 0x0
ErrorColor db 0x0C
; tells the assembler to include this data in the '.setup' section
section .setup
trickgdt:
dw gdt_end - gdt - 1 ; size of the GDT
dd gdt ; linear address of GDT
gdt:
dd 0, 0 ; null gate
db 0xFF, 0xFF, 0, 0, 0, 10011010b, 11001111b, 0x40 ; code selector 0x08: base 0x40000000, limit 0xFFFFFFFF, type 0x9A, granularity 0xCF
db 0xFF, 0xFF, 0, 0, 0, 10010010b, 11001111b, 0x40 ; data selector 0x10: base 0x40000000, limit 0xFFFFFFFF, type 0x92, granularity 0xCF
gdt_end:
; stack
section .bss
align 32
stack:
resb STACKSIZE ; This reserves 64KBytes of memory here