-
Notifications
You must be signed in to change notification settings - Fork 0
/
uefi_ini.asm
205 lines (147 loc) · 3.31 KB
/
uefi_ini.asm
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
include 'uefi_struct.asm'
align37 16
; Èíèöèàëèçàöèÿ ïðèëîæåíèÿ. Ôóíêöèÿ äîëæíà âûçûâàòüñÿ ïåðâîé
init:
clc
or rdx, rdx
jz .badout
mov r8, EFI_SYSTEM_TABLE_SIGNATUREQ
cmp qword [rdx], r8
je @f
.badout:
xor rcx, rcx
xor rdx, rdx
stc
@@:
mov [efi_handler], rcx ; ImageHandle
mov [efi_ptr], rdx ; pointer to SystemTable EFI_SYSTEM_TABLE
mov rdx, [rdx + EFI_SYSTEM_TABLE.BootServices]
mov [BootServices], rdx
RET
align37Must 64
; Â RDX ïåðåäàòü àäðåñ âûâîäèìîé ñòðîêè
; mov rdx, BootStartString
; call Console.Write
Console:
.ResetInput:
mov rbx, [efi_ptr]
mov rbx, [rbx + EFI_SYSTEM_TABLE.ConIn]
mov rcx, rbx
mov rbx, [rbx + SIMPLE_INPUT_INTERFACE.Reset]
call uefi
RET
align37Must 16
.Write:
mov rbx, [efi_ptr]
mov rbx, [rbx + EFI_SYSTEM_TABLE.ConOut]
mov rcx, rbx
mov rbx, [rbx + SIMPLE_TEXT_OUTPUT_INTERFACE.OutputString]
call uefi
RET
align37Must 16
; while ((Status = ST->ConIn->ReadKeyStroke(ST->ConIn, &Key)) == EFI_NOT_READY);
.WaitForKey:
call Console.ResetInput
mov rbx, [efi_ptr]
mov rbx, [rbx + EFI_SYSTEM_TABLE.ConIn]
lea rdx, [rbx + SIMPLE_INPUT_INTERFACE.WaitForKey]
mov rcx, 1
test rdx, rdx
jz .error_WaitForKey
sub rsp, 16
mov r8, rsp
mov rbx, [BootServices]
mov rbx, [rbx + EFI_BOOT_SERVICES_TABLE.WaitForEvent]
; 243/173 ñòðàíèöà
call uefi
add rsp, 16
cmp rax, 0 ; EFI_SUCCESS
je .success
mov rdx, 0x8000000000000002
cmp rax, rdx ; EFI_INVALID_PARAMETER
je .invalidParameter
mov rdx, 0x8000000000000003
cmp rax, rdx ; EFI_UNSUPPORTED
je .unsupported
mov rdx, unknownstr
call Console.Write
RET
.unsupported:
mov rdx, unsupportedstr
call Console.Write
RET
.invalidParameter:
mov rdx, ipstr
call Console.Write
RET
align37Must 16
.success:
mov rdx, successstr
call Console.Write
; Ñáðàñûâàåì ïîëó÷åííîå íàæàòèå êëàâèøè, à òî îíî äàëüøå áóäåò èñïîëüçîâàíî
call Console.ResetInput
RET
.error_WaitForKey:
mov rdx, unsupportedstr
call Console.Write
RET
align37Must 16
successstr du 'success', 13, 10, 0
align37Must 16
ipstr du 'invalid parameter', 13, 10, 0
align37Must 16
unknownstr du 'unknown error code', 13, 10, 0
align37Must 16
unsupportedstr du 'unsupported', 13, 10, 0
align37Must 64
DisableWatchdogTimer:
mov rbx, [BootServices]
mov rbx, [rbx + EFI_BOOT_SERVICES_TABLE.SetWatchdogTimer]
xor rcx, rax
xor rdx, rdx
xor r8, r8
xor r9, r9
call uefi
RET
align37Must 64
; Â rbx àäðåñ òîãî, ÷òî âûçûâàåì
; Calling convention íà ñòðàíèöå 104/33
; Ïàðàìåòðû â RCX, RDX, R8 and R9
; Àäðåñ âåðøèíû ñòåêà äîëæåí áûòü âûðîâíåí íà êðàòíûé 16-òè
uefi:
; Direction flag in EFLAGs is clear
cld
mov [efi_rsp], rsp
; Âûðàâíèâàíèå ñòåêà íà àäðåñ, êðàòíûé 16-òè
and rsp, 0xFFFFFFFFFFFFFFF0
; Íå çíàþ çà÷åì. Ïîõîæå, ýòî ìåñòî äëÿ õðàíåíèÿ ðåãèñòðîâûõ ïàðàìåòðîâ â ñòåêå :)
sub rsp, 4*8
call rbx
mov rsp, [efi_rsp]
RET
align37Must 16
saveRegisters:
pop rax
push RBX
push RBP
push RDI
push RSI
push R12
push R13
push R14
push R15
push rax
RET
align37Must 16
loadRegisters:
pop rax
pop R15
pop R14
pop R13
pop R12
pop RSI
pop RDI
pop RBP
pop RBX
push rax
RET