-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel_helpers.s
89 lines (69 loc) · 1.1 KB
/
kernel_helpers.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
# Assembly functions for our kernel
.text
# uint32_t get_gdt(gdtr_t*)
# Returns the address of the GDTR structure
# Inline assembly alternative:
#
# gdtr_t gdt;
# asm("sgdtl %0" : "=m"(gdt));
#
.globl get_gdt
get_gdt:
push %ebp
mov %esp, %ebp
# preserve %eax, although not neccessary
push %eax
mov 8(%ebp), %eax
sgdt (%eax)
# restore %eax, although not neccessary
pop %eax
mov %ebp, %esp
pop %ebp
ret
# void set_gdt(gdtr_t*, uint16_t cs_selector, uint16_t ds_selector)
.globl set_gdt
set_gdt:
push %ebp
mov %esp, %ebp
# preserve %eax, although not neccessary
push %eax
mov 8(%ebp), %eax
lgdt (%eax)
mov 16(%ebp), %eax
mov %eax, %ds
mov %eax, %es
mov %eax, %fs
mov %eax, %gs
mov %eax, %ss
pop %eax
mov %ebp, %esp
pop %ebp
# reload %cs register by doing a far return
push 16(%ebp)
push $gdt_is_set
retf
gdt_is_set:
ret
.globl get_eax
get_eax:
ret
.globl get_ebx
get_ebx:
mov %ebx, %eax
ret
.globl get_ecx
get_ecx:
mov %ecx, %eax
ret
.globl get_edx
get_edx:
mov %edx, %eax
ret
.globl get_esi
get_esi:
mov %esi, %eax
ret
.globl get_edi
get_edi:
mov %edi, %eax
ret