aboutsummaryrefslogtreecommitdiff
path: root/src/boot/boot.S
blob: e3830eb906a363c25bba0e6542c436e3c7cd11c2 (plain)
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
.extern bringelle
.extern gdt_memcpy
.globl  _start
.text

.set MB_MAGIC, 0x1BADB002
.set MB_FLAGS, 0x00010000
.set MB_CHECKSUM, -(MB_MAGIC+MB_FLAGS)
.set MB_HEADER_ADDR, mb_header
.set MB_LOAD_ADDR, mb_header
.set MB_LOAD_END_ADDR, 0x0
.set MB_BSS_END_ADDR, 0x0
.set MB_ENTRY_ADDR, _start

mb_header:
.align 4
.long MB_MAGIC
.long MB_FLAGS
.long MB_CHECKSUM
.long MB_HEADER_ADDR
.long MB_LOAD_ADDR
.long MB_LOAD_END_ADDR
.long MB_BSS_END_ADDR
.long MB_ENTRY_ADDR

_start:

# Copy GDT into memory then load its register
call gdt_memcpy
lgdtl (GDTR)

# Update all segments register
# with the new GDT offset
movw $0x10, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs

# Update code segment
ljmp $0x08, $cs_new
cs_new:

# Update stack segment
movw $0x18, %ax
movw %ax, %ss
movl $0x20000,%esp

# Start kernel main function
call bringelle