-
Notifications
You must be signed in to change notification settings - Fork 2
/
boot.S
60 lines (45 loc) · 1.16 KB
/
boot.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
# boot.S - start point for the kernel after GRUB gives us control
# vim:ts=4 noexpandtab
#define ASM 1
#include "multiboot.h"
#include "x86_desc.h"
.text
# Multiboot header (required for GRUB to boot us)
.long MULTIBOOT_HEADER_MAGIC
.long MULTIBOOT_HEADER_FLAGS
.long -(MULTIBOOT_HEADER_MAGIC+MULTIBOOT_HEADER_FLAGS)
# Entrypoint to the kernel
.globl start, _start
.align 4
start:
_start:
# Make sure interrupts are off
cli
jmp continue
continue:
# Load the GDT
lgdt gdt_desc_ptr # load gdt
lidt idt_desc_ptr # load idt
# Load CS with the new descriptor value
ljmp $KERNEL_CS, $keep_going
keep_going:
# Set up ESP so we can have an initial stack
movl $0x800000, %esp
# Set up the rest of the segment selector registers
movw $KERNEL_DS, %cx
movw %cx, %ss
movw %cx, %ds
movw %cx, %es
movw %cx, %fs
movw %cx, %gs
# Push the parameters that entry() expects (see kernel.c):
# eax = multiboot magic
# ebx = address of multiboot info struct
pushl %ebx
pushl %eax
# Jump to the C entrypoint to the kernel.
call entry
# We'll never get back here, but we put in a hlt anyway.
halt:
hlt
jmp halt