summaryrefslogtreecommitdiff
path: root/src/boot.s
blob: 71017ff85bdff8ea7b1d0d990703b4c5ee693529 (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
73
74
75
76
77
78
79
80
/* 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

.intel_syntax noprefix
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

.att_syntax

.section .text
.global _start
.type _start, @function
_start:
	mov $stack_top, %esp
	
	cli
	
.intel_syntax noprefix
	lgdt [gdt_desc] /* load GDT */
	mov ax, 0x10
	mov ds, ax
	mov ss, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	jmp 0x08:continue
.att_syntax

continue:
	call kernel_main

	cli
1:	hlt
	jmp 1b

/* The size of the _start symbol is the current location '.' minus its start. */
.size _start, . - _start