-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.s
More file actions
51 lines (41 loc) · 2.33 KB
/
loader.s
File metadata and controls
51 lines (41 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
; =============================================================================
; os
; AlexSafatli
;
; Oct 2015
;
; Entry Point for Initializing Kernel
; =============================================================================
global loader ; entry symbol for ELF file
; =============================================================================
MAGIC_NUMBER equ 0x1BADB002 ; magic number constant for multiboot
BOOT_MEM_INFO equ 1 << 1 ; provides kernel with memory info
FLAGS equ BOOT_MEM_INFO ; multiboot flags
CHECKSUM equ -(MAGIC_NUMBER + FLAGS) ; calculate checksum
; (magic number+checksum+flags should = 0)
KERNEL_STACK_SIZE equ 4096 ; size of stack for kernel in bytes (~4MB)
; =============================================================================
extern kernel_init ; kernel initialization entry point in C
;
section .text ; start of text (code)
align 4 ; code must be 4 byte aligned
dd MAGIC_NUMBER ; write magic number
dd FLAGS ; write flags
dd CHECKSUM ; checksum
; =============================================================================
loader: ; entry point
cli ; stop all interrupts until initialized
mov eax, 0xCAFEBABE ; place 0xCAFEBABE into eax register
mov esp, kernel_stack + KERNEL_STACK_SIZE
; make stack register point to stack
call kernel_init ; initialize kernel
.loop: ;
jmp .loop ; loop forever
; =============================================================================
section .bss ; start of bss
; (block started by symbol -
; statically allocated variables)
align 4 ; code must be 4 byte aligned
kernel_stack: ; label points to beginning of memory
resb KERNEL_STACK_SIZE ; reserve the stack
; EOF =========================================================================