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
|
.global rt_jump_to_address
.global rt_reset_hardware
.text
.intel_syntax noprefix
/**
@brief this function setups a stack and then jumps to
a function */
rt_jump_to_address:
mov rbx, rcx
mov rcx, rdx
push rbx
push rdx
mov rsp, r8
push rax
jmp rbx
pop rdx
pop rbx
pop rax
ret
rt_reset_hardware:
/* dont raise any interrupts. (except ofc NMIs.) */
cli
/* remap PIC */
wait_gate1:
in al,0x64
and al,2
jnz wait_gate1
mov al,0x0D1
out 0x64,al
wait_gate2:
in al,0x64
and al,2
jnz wait_gate2
mov al,0x0FE
out 0x60,al
/* trigger triple fault, by writing to cr4 */
mov rax, 0
lidt [rax]
reset_wait:
jmp reset_wait
.global boot_write_cr3
.global boot_read_cr3
boot_read_cr3:
mov rax, cr3
ret
boot_write_cr3:
mov cr3, rcx
ret
.section .text
.extern rt_wait_400ns
.global rt_out8
.global rt_out16
.global rt_out32
.global rt_in8
.global rt_in16
.global rt_in32
rt_out8:
mov al, dl
mov dx, cx
out dx, al
ret
rt_out16:
mov ax, dx
mov dx, cx
out dx, ax
ret
rt_out32:
mov eax, edx
mov edx, ecx
out dx, eax
ret
rt_in8:
mov dx, cx
in al, dx
ret
rt_in16:
mov edx, ecx
in ax, dx
ret
rt_in32:
mov rdx, rcx
in eax, dx
ret
|