aboutsummaryrefslogtreecommitdiff
path: root/src/boot/boot.S
blob: 469cc829771433db1a7a4a5155e51dab2f052758 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
.globl  _start
.globl MB_INFO
.extern bringelle
.extern gdt_memcpy
.extern mb_load_fb_tag

.section .multiboot

.set MB_MAGIC, 0xE85250D6
.set MB_ARCH, 0x00000000
.set MB_HEADER_LENGTH, (mb_header_end-mb_header_start)
.set MB_CHECKSUM, -(MB_MAGIC+MB_ARCH+MB_HEADER_LENGTH)

mb_header_start:
.align 8
.int MB_MAGIC
.int MB_ARCH
.int MB_HEADER_LENGTH
.int MB_CHECKSUM
# ----------- Address tag
.align 8
.short 2
.short 0 # Not optional
.int 24  # Size
.int mb_header_start # header_addr
.int mb_header_start # load_addr
.int 0x0 # load_end_addr
.int 0x0 # bss_end_addr
# ----------- Addr tag
.align 8
.short 0x3
.short 0
.int 12
.int _start
# ----------- End tag
.align 8
.int 0x0
.int 0x8
mb_header_end:

.section .text

MB_INFO:
 .int 0xABCDEF # Will contains the Multiboot2 information data structure address

_start:
mov %ebx, (MB_INFO)

# 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 $0x50000,%esp

# Start kernel main function
call bringelle