-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboot.S
192 lines (144 loc) · 2.46 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#define MULTIBOOT_MAGIC 0x1badb002
#define MULTIBOOT_FLAGS 0x0
#define MULTIBOOT_CHECKSUM -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS)
#define STACK_SIZE (4096 * 2)
.section .boot, "awx"
.align 0x10
.long MULTIBOOT_MAGIC
.long MULTIBOOT_FLAGS
.long MULTIBOOT_CHECKSUM
.text
.globl _start
_start:
/* loading idt and gdt */
lidt idt_descr
lgdt gdt_descr
ljmp $0x8, $1f
1:
mov $0x10, %eax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movl $(stack_bsp + STACK_SIZE), %esp
/* first argument: multiboot */
push %ebx
call main
cli
1:
hlt
jmp 1b
.section .rodata
.align 0x10
.globl idt_descr
idt_descr:
.word 0
.long 0
.align 0x10
gdt_descr:
.word 0x8*5 - 1
.long gdt
.align 0x10
gdt:
/* 0 */
.quad 0
/* boot CS = 0x8 */
.word 0xffff
.word 0x0000
.byte 0x00
.byte 0x9a
.byte 0xcf
.byte 0x00
/* boot DS = 0x10 */
.word 0xffff
.word 0x0000
.byte 0x00
.byte 0x92
.byte 0xcf
.byte 0x00
/* rm CS = 0x18 */
.word 0xffff
.word 0
.byte 0
.byte 0x9a
.byte 0x8f
.byte 0
/* rm DS = 0x20 */
.word 0xffff
.word 0
.byte 0
.byte 0x92
.byte 0x8f
.bss
.p2align 4
.globl stack_bsp
.comm stack_bsp, STACK_SIZE
#define M(addr) (addr - apboot + 0x7000)
.text
.globl apboot, apbootend, stack_ptr
.align 0x10
.code16
apboot:
_apboot:
cli
xor %ax, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %ss
mov $0x7000, %sp
lgdt M(gdt_descr_tmp)
mov %cr0, %eax
or $0x1, %eax
mov %eax, %cr0
ljmp $0x8, $M(1f)
1:
.code32
mov $0x10, %eax
mov %ax, %ds
mov %ax, %es
mov %ax, %ss
mov $0x7000, %esp
lidtl idt_descr
lgdt gdt_descr
ljmpl $0x8, $1f
1:
mov $0x10, %eax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movl stack_ptr, %esp
addl $STACK_SIZE, %esp
pushl stack_ptr
call cpu_ap_main
cli
1:
hlt
jmp 1b
stack_ptr:
.long 0x0
.align 0x10
gdt_descr_tmp:
.short 0x8*3 - 1
.long M(gdt_tmp)
.align 0x10
gdt_tmp:
/* 0 */
.quad 0
/* boot CS = 0x8 */
.word 0xffff
.word 0x0000
.byte 0x00
.byte 0x9a
.byte 0xcf
.byte 0x00
/* boot DS = 0x10 */
.word 0xffff
.word 0x0000
.byte 0x00
.byte 0x92
.byte 0xcf
.byte 0x00
_apbootend:
apbootend:
.globl dummyf
dummyf:
ret