-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathloader.s
74 lines (56 loc) · 1.31 KB
/
loader.s
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;
; Adapted from osdev.org's Bare Bones tutorial http://wiki.osdev.org/Bare_Bones
;
global loader
global magic
global mbd
global gdt_flush
global idt_flush
extern goose_main
; Multiboot stuff
MODULEALIGN equ 1<<0
MEMINFO equ 1<<1
FLAGS equ MODULEALIGN | MEMINFO
MAGIC equ 0x1BADB002
CHECKSUM equ -(MAGIC + FLAGS)
section .multiboot
align 4
dd MAGIC
dd FLAGS
dd CHECKSUM
STACKSIZE equ 0x4000 ; Define our stack size at 16k
section .text
loader:
mov esp, stack + STACKSIZE ; Setup stack pointer
mov [magic], eax
mov [mbd], ebx
; fpu init early on
fninit
sti
call goose_main
cli
.exit:
.hang:
hlt
jmp .hang
gdt_flush:
mov eax, [esp+4] ; Get the pointer to the GDT, passed as a parameter.
lgdt [eax] ; Load the new GDT pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax ; Load all data segment selectors
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:.flush ; 0x08 is the offset to our code segment: Far jump!
.flush:
ret
idt_flush:
mov eax, [esp+4] ; Get the pointer to the IDT, passed as a parameter.
lidt [eax] ; Load the IDT pointer.
ret
section .bss
align 4
magic: resd 1
mbd: resd 1
stack: resb STACKSIZE ; Reserve 16k for stack