-
Notifications
You must be signed in to change notification settings - Fork 0
/
head64.S
64 lines (52 loc) · 1001 Bytes
/
head64.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
// Copyright (c) 2023 Wang Baisheng <[email protected]>, Wang Shenghan. All Rights Reserved.
#include "include/segment.h"
.text
.code64
.globl gdt
.globl ret_from_kernel
.globl task0_stack
.globl idle_task_entry
start64:
lgdt gdtr
lidt idtr
// setup seg
mov $KERNEL_DS, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
// setup stack
mov $task0_stack, %rsp
pushq $main
ret
gdt:
.quad 0x0000000000000000 /* reserved */
.quad 0x00209a0000000000 /* kernel cs */
.quad 0x0000920000000000 /* kernel ds */
.quad 0x0000000000000000 /* user32 cs */
.quad 0x0000f20000000000 /* user ds */
.quad 0x0020fa0000000000 /* user64 cs */
.fill 64 - 6, 8, 0
gdt_end:
gdtr:
.word gdt_end - gdt
.quad gdt
idtr:
.word 16 * 256
.quad idt_table
// 4kb
.fill 4096, 1, 0
task0_stack:
ret_from_kernel:
mov $USER_DS, %rax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
iretq
idle_task_entry:
1:
sti
hlt
jmp 1b