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
74
75
76
77
|
/* Parameters for the multiboot header */
.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
/* Allocate room for stack */
.section bss
.align 16
stack_bottom:
.skip 16384 /* 16 KiB */
stack_top:
.section .data
gdt:
null_gdt: /* null descriptor */
.quad 0x00
code_gdt:
.word 0xFFFF /* limit */
.word 0x0000 /* base */
.byte 0x00 /* base */
.byte 0x9A /* type flag (access) */
.byte 0b11001111 /* limit */
.byte 0x00 /* base */
data_gdt:
.word 0xFFFF /* limit */
.word 0x0000 /* base */
.byte 0x00 /* base */
.byte 0x92 /* type flag (access) */
.byte 0b11001111 /* limit */
.byte 0x00 /* base */
end_gdt:
gdt_desc:
.word end_gdt - gdt - 1
.int gdt
.section .text
.global _start
.type _start, @function
_start:
mov $stack_top, %esp
cli
lgdt (gdt_desc) /* load GDT */
mov $0x10, %ax
mov %ax, %ds
mov %ax, %ss
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
ljmp $0x08,$continue
continue:
push %ebx /* pointer to multiboot structure */
call kernel_main
cli
1: hlt
jmp 1b
/* The size of the _start symbol is the current location '.' minus its start. */
.size _start, . - _start
|