Subversion Repositories Kolibri OS

Rev

Rev 9958 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9958 Rev 9977
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2020-2024. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2020-2024. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;; Version 2, or (at your option) any later version.            ;;
5
;; Version 2, or (at your option) any later version.            ;;
6
;;                                                              ;;
6
;;                                                              ;;
7
;; Written by Ivan Baravy                                       ;;
7
;; Written by Ivan Baravy                                       ;;
8
;;                                                              ;;
8
;;                                                              ;;
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
 
10
 
11
format pe64 efi
11
format pe64 efi
12
entry main
12
entry main
13
 
13
 
14
section '.text' code executable readable
14
section '.text' code executable readable
15
 
15
 
16
include '../../struct.inc'
16
include '../../struct.inc'
17
include '../../macros.inc'
17
include '../../macros.inc'
18
include '../../kglobals.inc'
18
include '../../kglobals.inc'
19
fastcall fix fstcall
19
fastcall fix fstcall
20
include 'proc64.inc'
20
include 'proc64.inc'
21
include '../../const.inc'
21
include '../../const.inc'
22
 
22
 
23
purge DQ
23
purge DQ
24
include 'uefi64.inc'
24
include 'uefi64.inc'
25
 
25
 
26
MEMORY_MAP_SIZE = 0x10000
26
MEMORY_MAP_SIZE = 0x10000
27
PROTOCOL_HANDLERS_BUFFER_SIZE = 0x100
27
PROTOCOL_HANDLERS_BUFFER_SIZE = 0x100
28
FILE_BUFFER_SIZE = 0x1000
28
FILE_BUFFER_SIZE = 0x1000
29
 
29
 
30
KERNEL_TRAMPOLINE = 0x8f80      ; just before BOOT_LO
30
KERNEL_TRAMPOLINE = 0x8f80      ; just before BOOT_LO
31
MAX_FILE_SIZE = 0x10000000
31
MAX_FILE_SIZE = 0x10000000
32
 
32
 
33
CODE_32_SELECTOR = 8
33
CODE_32_SELECTOR = 8
34
DATA_32_SELECTOR = 16
34
DATA_32_SELECTOR = 16
35
CODE_64_SELECTOR = 24
35
CODE_64_SELECTOR = 24
36
 
36
 
37
; linux/arch/x86/include/uapi/asm/e820.h
37
; linux/arch/x86/include/uapi/asm/e820.h
38
E820_RAM       = 1
38
E820_RAM       = 1
39
E820_RESERVED  = 2
39
E820_RESERVED  = 2
40
E820_ACPI      = 3
40
E820_ACPI      = 3
41
E820_NVS       = 4
41
E820_NVS       = 4
42
E820_UNUSABLE  = 5
42
E820_UNUSABLE  = 5
43
E820_PMEM      = 7
43
E820_PMEM      = 7
44
 
44
 
45
proc load_file _root, _name, _buffer, _size, _fatal
45
proc load_file _root, _name, _buffer, _size, _fatal
46
        mov     [_root], rcx
46
        mov     [_root], rcx
47
        mov     [_name], rdx
47
        mov     [_name], rdx
48
        mov     [_buffer], r8
48
        mov     [_buffer], r8
49
        mov     [_size], r9
49
        mov     [_size], r9
50
        mov     r10, [_root]
50
        mov     r10, [_root]
51
        mov     r11, [_name]
51
        mov     r11, [_name]
52
        fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
52
        fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
53
                r11, EFI_FILE_MODE_READ, 0
53
                r11, EFI_FILE_MODE_READ, 0
54
        test    eax, eax
54
        test    eax, eax
55
        jz      @f
55
        jz      @f
56
        mov     [_size], 0
56
        mov     [_size], 0
57
        cmp     [_fatal], 1
57
        cmp     [_fatal], 1
58
        jnz     .done
58
        jnz     .done
59
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
59
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
60
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
60
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
61
                msg_error_open_file
61
                msg_error_open_file
62
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
62
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
63
        mov     rdx, [_name]
63
        mov     rdx, [_name]
64
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, [_name]
64
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, [_name]
65
        jmp     $
65
        jmp     $
66
@@:
66
@@:
67
        lea     rdx, [_size]
67
        lea     rdx, [_size]
68
        mov     r8, [_buffer]
68
        mov     r8, [_buffer]
69
        mov     r10, [file_handle]
69
        mov     r10, [file_handle]
70
        fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
70
        fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
71
        mov     r10, [file_handle]
71
        mov     r10, [file_handle]
72
        fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
72
        fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
73
.done:
73
.done:
74
        call    clearbuf
74
        call    clearbuf
75
        mov     rax, [_size]
75
        mov     rax, [_size]
76
        mov     rdi, msg
76
        mov     rdi, msg
77
        call    num2dec
77
        call    num2dec
78
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
78
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
79
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
79
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
80
                msg_file_size
80
                msg_file_size
81
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
81
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
82
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
82
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
83
        mov     rax, [_size]
83
        mov     rax, [_size]
84
        ret
84
        ret
85
endp
85
endp
86
 
86
 
87
skip_whitespace:
87
skip_whitespace:
88
.next_char:
88
.next_char:
89
        cmp     byte[rsi], 0
89
        cmp     byte[rsi], 0
90
        jz      .done
90
        jz      .done
91
        cmp     byte[rsi], 0x20 ; ' '
91
        cmp     byte[rsi], 0x20 ; ' '
92
        jz      .whitespace
92
        jz      .whitespace
93
        cmp     byte[rsi], 9    ; '\t'
93
        cmp     byte[rsi], 9    ; '\t'
94
        jz      .whitespace
94
        jz      .whitespace
95
        jmp     .done
95
        jmp     .done
96
.whitespace:
96
.whitespace:
97
        inc     rsi
97
        inc     rsi
98
        jmp     .next_char
98
        jmp     .next_char
99
.done:
99
.done:
100
        ret
100
        ret
101
 
101
 
102
skip_until_newline:
102
skip_until_newline:
103
.next_char:
103
.next_char:
104
        cmp     byte[rsi], 0
104
        cmp     byte[rsi], 0
105
        jz      .done
105
        jz      .done
106
        cmp     byte[rsi], 0xd  ; '\r'
106
        cmp     byte[rsi], 0xd  ; '\r'
107
        jz      .done
107
        jz      .done
108
        cmp     byte[rsi], 0xa  ; '\n'
108
        cmp     byte[rsi], 0xa  ; '\n'
109
        jz      .done
109
        jz      .done
110
        inc     rsi
110
        inc     rsi
111
        jmp     .next_char
111
        jmp     .next_char
112
.done:
112
.done:
113
        ret
113
        ret
114
 
114
 
115
skip_newline:
115
skip_newline:
116
.next_char:
116
.next_char:
117
        cmp     byte[rsi], 0xd  ; '\r'
117
        cmp     byte[rsi], 0xd  ; '\r'
118
        jz      .newline
118
        jz      .newline
119
        cmp     byte[rsi], 0xa  ; '\n'
119
        cmp     byte[rsi], 0xa  ; '\n'
120
        jz      .newline
120
        jz      .newline
121
        jmp     .done
121
        jmp     .done
122
.newline:
122
.newline:
123
        inc     rsi
123
        inc     rsi
124
        jmp     .next_char
124
        jmp     .next_char
125
.done:
125
.done:
126
        ret
126
        ret
127
 
127
 
128
skip_line:
128
skip_line:
129
        call    skip_until_newline
129
        call    skip_until_newline
130
        call    skip_newline
130
        call    skip_newline
131
        ret
131
        ret
132
 
132
 
133
dec2bin:
133
dec2bin:
134
        mov     edx, 0
134
        xor     edx, edx
135
.next_char:
135
.next_char:
136
        movzx   eax, byte[rsi]
136
        movzx   eax, byte[rsi]
137
        test    eax, eax
137
        test    eax, eax
138
        jz      .done
138
        jz      .done
139
        sub     eax, '0'
139
        sub     eax, '0'
140
        jb      .done
140
        jb      .done
141
        cmp     eax, 9
141
        cmp     eax, 9
142
        ja      .done
142
        ja      .done
143
        inc     rsi
143
        inc     rsi
144
        imul    edx, 10
144
        imul    edx, 10
145
        add     edx, eax
145
        add     edx, eax
146
        jmp     .next_char
146
        jmp     .next_char
147
.done:
147
.done:
148
        mov     eax, edx
148
        mov     eax, edx
149
        ret
149
        ret
150
 
150
 
151
parse_option:
151
parse_option:
152
        mov     rbx, config_options-3*8
152
        mov     rbx, config_options-3*8
153
.try_next_option:
153
.try_next_option:
154
        add     rbx, 3*8
154
        add     rbx, 3*8
155
        mov     rdi, rsi
155
        mov     rdi, rsi
156
        mov     rdx, [rbx]      ; option name
156
        mov     rdx, [rbx]      ; option name
157
        test    rdx, rdx
157
        test    rdx, rdx
158
        jz      .done
158
        jz      .done
159
.next_char:
159
.next_char:
160
        cmp     byte[rdx], 0
160
        cmp     byte[rdx], 0
161
        jnz     @f
161
        jnz     @f
162
        cmp     byte[rdi], '='
162
        cmp     byte[rdi], '='
163
        jz      .opt_name_ok
163
        jz      .opt_name_ok
164
@@:
164
@@:
165
        cmp     byte[rdi], 0
165
        cmp     byte[rdi], 0
166
        jz      .done
166
        jz      .done
167
        movzx   eax, byte[rdi]
167
        movzx   eax, byte[rdi]
168
        cmp     [rdx], al
168
        cmp     [rdx], al
169
        jnz     .try_next_option
169
        jnz     .try_next_option
170
        inc     rdi
170
        inc     rdi
171
        inc     rdx
171
        inc     rdx
172
        jmp     .next_char
172
        jmp     .next_char
173
.opt_name_ok:
173
.opt_name_ok:
174
        inc     rdi
174
        inc     rdi
175
        mov     rsi, rdi
175
        mov     rsi, rdi
176
        call    qword[rbx+8]
176
        call    qword[rbx+8]
177
.done:
177
.done:
178
        ret
178
        ret
179
 
179
 
180
parse_line:
180
parse_line:
181
.next_line:
181
.next_line:
182
        cmp     byte[rsi], 0
182
        cmp     byte[rsi], 0
183
        jz      .done
183
        jz      .done
184
        cmp     byte[rsi], 0xd  ; '\r'
184
        cmp     byte[rsi], 0xd  ; '\r'
185
        jz      .skip
185
        jz      .skip
186
        cmp     byte[rsi], 0xa  ; '\n'
186
        cmp     byte[rsi], 0xa  ; '\n'
187
        jz      .skip
187
        jz      .skip
188
        cmp     byte[rsi], '#'
188
        cmp     byte[rsi], '#'
189
        jz      .skip
189
        jz      .skip
190
        call    parse_option
190
        call    parse_option
191
        call    skip_line
191
        call    skip_line
192
        jmp     .next_line
192
        jmp     .next_line
193
.skip:
193
.skip:
194
        call    skip_line
194
        call    skip_line
195
        jmp     .next_line
195
        jmp     .next_line
196
.done:
196
.done:
197
        ret
197
        ret
198
 
198
 
199
cfg_opt_func_resolution:
199
cfg_opt_func_resolution:
200
        call    dec2bin
200
        call    dec2bin
201
        xor     edx, edx
201
        xor     edx, edx
202
        mov     [rdx+BOOT_LO.x_res], ax
202
        mov     [rdx+BOOT_LO.x_res], ax
203
        cmp     byte[rsi], 'x'
203
        cmp     byte[rsi], 'x'
204
        jz      @f
204
        jz      @f
205
        cmp     byte[rsi], '*'
205
        cmp     byte[rsi], '*'
206
        jz      @f
206
        jz      @f
207
        jmp     .done
207
        jmp     .done
208
@@:
208
@@:
209
        inc     rsi
209
        inc     rsi
210
        call    dec2bin
210
        call    dec2bin
211
        xor     edx, edx
211
        xor     edx, edx
212
        mov     [rdx+BOOT_LO.y_res], ax
212
        mov     [rdx+BOOT_LO.y_res], ax
213
        mov     [cfg_opt_used_resolution], 1
213
        mov     [cfg_opt_used_resolution], 1
214
.done:
214
.done:
215
        ret
215
        ret
216
 
216
 
217
cfg_opt_func_acpi:
217
cfg_opt_func_acpi:
218
        call    dec2bin
218
        call    dec2bin
219
        mov     [cfg_opt_used_acpi], 1
219
        mov     [cfg_opt_used_acpi], 1
220
        mov     [cfg_opt_value_acpi], al
220
        mov     [cfg_opt_value_acpi], al
221
        ret
221
        ret
222
 
222
 
223
cfg_opt_func_debug_print:
223
cfg_opt_func_debug_print:
224
        call    dec2bin
224
        call    dec2bin
225
        mov     [cfg_opt_used_debug_print], 1
225
        mov     [cfg_opt_used_debug_print], 1
226
        mov     [cfg_opt_value_debug_print], al
226
        mov     [cfg_opt_value_debug_print], al
227
        ret
227
        ret
228
 
228
 
229
cfg_opt_func_launcher_start:
229
cfg_opt_func_launcher_start:
230
        call    dec2bin
230
        call    dec2bin
231
        mov     [cfg_opt_used_launcher_start], 1
231
        mov     [cfg_opt_used_launcher_start], 1
232
        mov     [cfg_opt_value_launcher_start], al
232
        mov     [cfg_opt_value_launcher_start], al
233
        ret
233
        ret
234
 
234
 
235
cfg_opt_func_mtrr:
235
cfg_opt_func_mtrr:
236
        call    dec2bin
236
        call    dec2bin
237
        mov     [cfg_opt_used_mtrr], 1
237
        mov     [cfg_opt_used_mtrr], 1
238
        mov     [cfg_opt_value_mtrr], al
238
        mov     [cfg_opt_value_mtrr], al
239
        ret
239
        ret
240
 
240
 
241
cfg_opt_func_ask_params:
241
cfg_opt_func_ask_params:
242
        call    dec2bin
242
        call    dec2bin
243
        mov     [cfg_opt_used_ask_params], 1
243
        mov     [cfg_opt_used_ask_params], 1
244
        mov     [cfg_opt_value_ask_params], al
244
        mov     [cfg_opt_value_ask_params], al
245
        ret
245
        ret
246
 
246
 
247
cfg_opt_func_imgfrom:
247
cfg_opt_func_imgfrom:
248
        call    dec2bin
248
        call    dec2bin
249
        mov     [cfg_opt_used_imgfrom], 1
249
        mov     [cfg_opt_used_imgfrom], 1
250
        mov     [cfg_opt_value_imgfrom], al
250
        mov     [cfg_opt_value_imgfrom], al
251
        ret
251
        ret
252
 
252
 
253
cfg_opt_func_syspath:
253
cfg_opt_func_syspath:
254
        mov     rdi, cfg_opt_value_syspath
254
        mov     rdi, cfg_opt_value_syspath
255
.next_char:
255
.next_char:
256
        movzx   eax, byte[rsi]
256
        movzx   eax, byte[rsi]
257
        cmp     al, 0xd ; \r
257
        cmp     al, 0xd ; \r
258
        jz      .done
258
        jz      .done
259
        cmp     al, 0xa ; \n
259
        cmp     al, 0xa ; \n
260
        jz      .done
260
        jz      .done
261
        inc     rsi
261
        inc     rsi
262
        stosb
262
        stosb
263
        jmp     .next_char
263
        jmp     .next_char
264
.done:
264
.done:
265
        mov     byte[rdi], 0
265
        mov     byte[rdi], 0
266
        ret
266
        ret
267
 
267
 
268
proc parse_config uses rbx rsi rdi, _buffer
268
proc parse_config uses rbx rsi rdi, _buffer
269
        mov     rsi, rcx
269
        mov     rsi, rcx
270
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
270
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
271
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
271
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
272
                msg_parsing_config
272
                msg_parsing_config
273
.next_line:
273
.next_line:
274
        call    parse_line
274
        call    parse_line
275
        cmp     byte[rsi], 0
275
        cmp     byte[rsi], 0
276
        jnz     .next_line
276
        jnz     .next_line
277
        ret
277
        ret
278
endp
278
endp
279
 
279
 
280
proc read_options_from_config
280
proc read_options_from_config
281
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
281
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
282
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], \
282
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], \
283
                lip_guid, lip_interface
283
                lip_guid, lip_interface
284
        test    eax, eax
284
        test    eax, eax
285
        jz      @f
285
        jz      @f
286
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
286
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
287
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
287
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
288
                msg_error_efi_lip_handle
288
                msg_error_efi_lip_handle
289
        jmp     $
289
        jmp     $
290
@@:
290
@@:
291
        mov     r11, [lip_interface]
291
        mov     r11, [lip_interface]
292
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
292
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
293
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], \
293
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], \
294
                [r11+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
294
                [r11+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
295
                sfsp_interface
295
                sfsp_interface
296
        test    eax, eax
296
        test    eax, eax
297
        jz      @f
297
        jz      @f
298
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
298
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
299
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
299
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
300
                msg_error_lip_dev_sfsp
300
                msg_error_lip_dev_sfsp
301
        jmp     $
301
        jmp     $
302
@@:
302
@@:
303
        mov     r10, [sfsp_interface]
303
        mov     r10, [sfsp_interface]
304
        fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
304
        fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
305
                [sfsp_interface], esp_root
305
                [sfsp_interface], esp_root
306
        test    eax, eax
306
        test    eax, eax
307
        jz      @f
307
        jz      @f
308
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
308
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
309
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
309
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
310
                msg_error_sfsp_openvolume
310
                msg_error_sfsp_openvolume
311
        jmp     $
311
        jmp     $
312
@@:
312
@@:
313
        fstcall load_file, [esp_root], file_name, KERNEL_BASE, \
313
        fstcall load_file, [esp_root], file_name, KERNEL_BASE, \
314
                FILE_BUFFER_SIZE, 0     ; not fatal
314
                FILE_BUFFER_SIZE, 0     ; not fatal
315
 
315
 
316
        test    eax, eax
316
        test    eax, eax
317
        jz      @f
317
        jz      @f
318
        fstcall parse_config, KERNEL_BASE
318
        fstcall parse_config, KERNEL_BASE
319
@@:
319
@@:
320
 
320
 
321
.error:
321
.error:
322
        ret
322
        ret
323
endp
323
endp
324
 
324
 
325
proc print_vmode uses rax rbx rcx rdx rsi rdi
325
proc print_vmode uses rax rbx rcx rdx rsi rdi
326
        mov     r10, rcx
326
        mov     r10, rcx
327
        call    clearbuf
327
        call    clearbuf
328
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
328
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
329
        mov     rdi, msg
329
        mov     rdi, msg
330
        call    num2dec
330
        call    num2dec
331
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
331
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
332
        mov     rdi, msg+8*2
332
        mov     rdi, msg+8*2
333
        call    num2dec
333
        call    num2dec
334
 
334
 
335
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat]
335
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat]
336
        mov     rdi, msg+16*2
336
        mov     rdi, msg+16*2
337
        call    num2dec
337
        call    num2dec
338
 
338
 
339
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
339
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
340
        mov     rdi, msg+24*2
340
        mov     rdi, msg+24*2
341
        call    num2dec
341
        call    num2dec
342
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
342
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
343
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
343
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
344
        ret
344
        ret
345
endp
345
endp
346
 
346
 
347
proc find_vmode_index_by_resolution
347
proc find_vmode_index_by_resolution
348
        mov     [cfg_opt_used_resolution], 1
348
        mov     [cfg_opt_used_resolution], 1
349
        mov     [cfg_opt_value_vmode], 0
349
        mov     [cfg_opt_value_vmode], 0
350
.next_mode:
350
.next_mode:
351
        movzx   edx, [cfg_opt_value_vmode]
351
        movzx   edx, [cfg_opt_value_vmode]
352
        mov     r10, [gop_interface]
352
        mov     r10, [gop_interface]
353
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
353
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
354
                rdx, gop_info_size, gop_info
354
                rdx, gop_info_size, gop_info
355
        cmp     rax, EFI_SUCCESS
355
        cmp     rax, EFI_SUCCESS
356
        jnz     .error
356
        jnz     .error
357
        mov     rcx, [gop_info]
357
        mov     rcx, [gop_info]
358
        fstcall print_vmode
358
        fstcall print_vmode
359
        ; PixelBlueGreenRedReserved8BitPerColor
359
        ; PixelBlueGreenRedReserved8BitPerColor
360
        cmp     [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1
360
        cmp     [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1
361
        jnz     .skip_mode
361
        jnz     .skip_mode
362
        xor     edx, edx
362
        xor     edx, edx
363
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
363
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
364
        cmp     ax, [rdx+BOOT_LO.x_res]
364
        cmp     ax, [rdx+BOOT_LO.x_res]
365
        jnz     .skip_mode
365
        jnz     .skip_mode
366
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
366
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
367
        cmp     ax, [rdx+BOOT_LO.y_res]
367
        cmp     ax, [rdx+BOOT_LO.y_res]
368
        jnz     .skip_mode
368
        jnz     .skip_mode
369
        jmp     .done
369
        jmp     .done
370
.skip_mode:
370
.skip_mode:
371
        inc     [cfg_opt_value_vmode]
371
        inc     [cfg_opt_value_vmode]
372
        movzx   eax, [cfg_opt_value_vmode]
372
        movzx   eax, [cfg_opt_value_vmode]
373
        mov     rcx, [gop_interface]
373
        mov     rcx, [gop_interface]
374
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
374
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
375
        cmp     eax, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
375
        cmp     eax, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
376
        jnz     .next_mode
376
        jnz     .next_mode
377
        mov     [cfg_opt_used_resolution], 0
377
        mov     [cfg_opt_used_resolution], 0
378
        mov     [cfg_opt_value_ask_params], 1
378
        mov     [cfg_opt_value_ask_params], 1
379
 
379
 
380
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
380
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
381
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
381
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
382
                msg_error_no_such_vmode
382
                msg_error_no_such_vmode
383
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
383
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
384
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
384
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
385
                msg_error
385
                msg_error
386
        jmp     $
386
        jmp     $
387
.error:
387
.error:
388
.done:
388
.done:
389
        ret
389
        ret
390
endp
390
endp
391
 
391
 
392
ask_for_params:
392
ask_for_params:
393
        jmp     $
393
        jmp     $
394
 
394
 
395
proc detect_pci_config
395
proc detect_pci_config
396
        fstcall get_protocol_interface, pcirbiop_guid
396
        fstcall get_protocol_interface, pcirbiop_guid
397
        mov     [pcirbiop_interface], rax
397
        mov     [pcirbiop_interface], rax
398
        mov     r10, rax
398
        mov     r10, rax
399
        fstcall [r10+EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Configuration], r10, \
399
        fstcall [r10+EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Configuration], r10, \
400
                pcirbiop_resources
400
                pcirbiop_resources
401
;        fstcall dump_pci_resources
401
;        fstcall dump_pci_resources
402
        fstcall get_last_pci_bus
402
        fstcall get_last_pci_bus
403
        call    clearbuf
403
        call    clearbuf
404
        movzx   eax, [pci_last_bus]
404
        movzx   eax, [pci_last_bus]
405
        mov     rdi, msg
405
        mov     rdi, msg
406
        call    num2hex
406
        call    num2hex
407
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
407
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
408
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
408
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
409
                msg_pci_last_bus
409
                msg_pci_last_bus
410
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
410
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
411
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
411
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
412
        ret
412
        ret
413
endp
413
endp
414
 
414
 
415
proc get_last_pci_bus
415
proc get_last_pci_bus
416
        mov     rsi, [pcirbiop_resources]
416
        mov     rsi, [pcirbiop_resources]
417
.next_resource:
417
.next_resource:
418
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type], \
418
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type], \
419
                EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
419
                EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
420
        jz      .not_found
420
        jz      .not_found
421
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
421
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
422
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType], \
422
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType], \
423
                EFI_RESOURCE_TYPE.BUS
423
                EFI_RESOURCE_TYPE.BUS
424
        jz      .found
424
        jz      .found
425
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
425
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
426
        lea     rsi, [rsi+rax+3]
426
        lea     rsi, [rsi+rax+3]
427
        jmp     .next_resource
427
        jmp     .next_resource
428
.found:
428
.found:
429
        mov     [pci_last_bus], al
429
        mov     [pci_last_bus], al
430
.not_found:
430
.not_found:
431
        ret
431
        ret
432
endp
432
endp
433
 
433
 
434
proc main _efi_handle, _efi_table
434
proc main _efi_handle, _efi_table
435
        mov     [efi_handle], rcx
435
        mov     [efi_handle], rcx
436
        mov     [efi_table], rdx
436
        mov     [efi_table], rdx
437
        mov     rbx, rdx
437
        mov     rbx, rdx
438
 
438
 
439
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
439
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
440
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rcx, 1
440
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rcx, 1
441
        test    eax, eax
441
        test    eax, eax
442
        jnz     $       ; what can I do here?
442
        jnz     $       ; what can I do here?
443
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
443
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
444
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
444
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
445
                msg_u4k_loaded
445
                msg_u4k_loaded
446
 
446
 
447
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
447
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
448
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
448
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
449
                msg_detect_pci_config
449
                msg_detect_pci_config
450
        fstcall detect_pci_config
450
        fstcall detect_pci_config
451
 
451
 
452
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
452
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
453
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
453
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
454
                msg_read_options
454
                msg_read_options
455
        fstcall read_options_from_config
455
        fstcall read_options_from_config
456
 
456
 
457
        ; read kernel file
457
        ; read kernel file
458
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
458
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
459
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
459
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
460
                msg_load_kernel
460
                msg_load_kernel
461
        fstcall load_file, [esp_root], kernel_name, KERNEL_BASE, \
461
        fstcall load_file, [esp_root], kernel_name, KERNEL_BASE, \
462
                MAX_FILE_SIZE, 1 ; fatal
462
                MAX_FILE_SIZE, 1 ; fatal
463
 
463
 
464
        ; read ramdisk image
464
        ; read ramdisk image
465
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
465
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
466
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
466
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
467
                msg_load_ramdisk
467
                msg_load_ramdisk
468
        fstcall load_file, [esp_root], ramdisk_name, RAMDISK_BASE, \
468
        fstcall load_file, [esp_root], ramdisk_name, RAMDISK_BASE, \
469
                MAX_FILE_SIZE, 1 ; fatal
469
                MAX_FILE_SIZE, 1 ; fatal
470
 
470
 
471
        ; alloc buffer for devices.dat
471
        ; alloc buffer for devices.dat
472
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
472
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
473
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
473
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
474
                msg_alloc_devicesdat
474
                msg_alloc_devicesdat
475
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
475
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
476
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], \
476
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], \
477
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
477
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
478
                devicesdat_data
478
                devicesdat_data
479
        cmp     eax, EFI_SUCCESS
479
        cmp     eax, EFI_SUCCESS
480
        jnz     .error
480
        jnz     .error
481
 
481
 
482
        ; read devices.dat
482
        ; read devices.dat
483
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
483
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
484
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
484
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
485
                msg_load_devicesdat
485
                msg_load_devicesdat
486
 
486
 
487
        fstcall load_file, [esp_root], devicesdat_name, [devicesdat_data], \
487
        fstcall load_file, [esp_root], devicesdat_name, [devicesdat_data], \
488
                [devicesdat_size], 0    ; not fatal
488
                [devicesdat_size], 0    ; not fatal
489
        mov     [devicesdat_size], rax
489
        mov     [devicesdat_size], rax
490
 
490
 
491
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
491
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
492
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
492
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
493
                msg_locate_gop_interface
493
                msg_locate_gop_interface
494
 
494
 
495
        fstcall get_protocol_interface, gop_guid
495
        fstcall get_protocol_interface, gop_guid
496
        mov     [gop_interface], rax
496
        mov     [gop_interface], rax
497
 
497
 
498
        fstcall find_rsdp
498
        fstcall find_rsdp
499
 
499
 
500
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
500
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
501
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
501
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
502
                msg_acpi_tables_done
502
                msg_acpi_tables_done
503
 
503
 
504
        cmp     [cfg_opt_used_resolution], 0
504
        cmp     [cfg_opt_used_resolution], 0
505
        jz      .not_used_resolution
505
        jz      .not_used_resolution
506
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
506
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
507
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
507
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
508
                msg_opt_resolution
508
                msg_opt_resolution
509
        call    clearbuf
509
        call    clearbuf
510
        xor     edx, edx
510
        xor     edx, edx
511
        movzx   eax, [rdx+BOOT_LO.x_res]
511
        movzx   eax, [rdx+BOOT_LO.x_res]
512
        mov     rdi, msg
512
        mov     rdi, msg
513
        call    num2dec
513
        call    num2dec
514
        xor     edx, edx
514
        xor     edx, edx
515
        movzx   eax, [rdx+BOOT_LO.y_res]
515
        movzx   eax, [rdx+BOOT_LO.y_res]
516
        mov     rdi, msg+8*2
516
        mov     rdi, msg+8*2
517
        call    num2dec
517
        call    num2dec
518
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
518
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
519
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
519
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
520
        fstcall find_vmode_index_by_resolution
520
        fstcall find_vmode_index_by_resolution
521
.not_used_resolution:
521
.not_used_resolution:
522
        cmp     [cfg_opt_used_debug_print], 0
522
        cmp     [cfg_opt_used_debug_print], 0
523
        jz      .not_used_debug_print
523
        jz      .not_used_debug_print
524
        movzx   eax, [cfg_opt_value_debug_print]
524
        movzx   eax, [cfg_opt_value_debug_print]
525
        xor     edx, edx
525
        xor     edx, edx
526
        mov     [rdx+BOOT_LO.debug_print], al
526
        mov     [rdx+BOOT_LO.debug_print], al
527
.not_used_debug_print:
527
.not_used_debug_print:
528
 
528
 
529
        cmp     [cfg_opt_value_ask_params], 0
529
        cmp     [cfg_opt_value_ask_params], 0
530
        jz      @f
530
        jz      @f
531
        call    ask_for_params
531
        call    ask_for_params
532
@@:
532
@@:
533
 
533
 
534
        movzx   edx, [cfg_opt_value_vmode]
534
        movzx   edx, [cfg_opt_value_vmode]
535
        mov     r10, [gop_interface]
535
        mov     r10, [gop_interface]
536
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode], [gop_interface], rdx
536
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode], [gop_interface], rdx
537
        test    eax, eax
537
        test    eax, eax
538
        jz      @f
538
        jz      @f
539
        call    clearbuf
539
        call    clearbuf
540
        mov     rdi, msg
540
        mov     rdi, msg
541
        call    num2hex
541
        call    num2hex
542
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
542
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
543
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
543
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
544
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
544
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
545
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
545
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
546
                msg_error
546
                msg_error
547
        jmp     $
547
        jmp     $
548
@@:
548
@@:
549
 
549
 
550
        mov     rcx, [gop_interface]
550
        mov     rcx, [gop_interface]
551
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
551
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
552
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
552
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
553
        mov     [fb_base], rdi
553
        mov     [fb_base], rdi
554
 
554
 
555
        mov     edx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
555
        mov     edx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
556
        mov     r10, [gop_interface]
556
        mov     r10, [gop_interface]
557
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
557
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
558
                rdx, gop_info_size, gop_info
558
                rdx, gop_info_size, gop_info
559
        test    eax, eax
559
        test    eax, eax
560
        jz      @f
560
        jz      @f
561
        jmp     .error
561
        jmp     .error
562
@@:
562
@@:
563
        mov     rcx, [gop_info]
563
        mov     rcx, [gop_info]
564
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
564
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
565
        xor     rdx, rdx
565
        xor     rdx, rdx
566
        mov     [rdx+BOOT_LO.x_res], ax
566
        mov     [rdx+BOOT_LO.x_res], ax
567
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
567
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
568
        mov     [rdx+BOOT_LO.y_res], ax
568
        mov     [rdx+BOOT_LO.y_res], ax
569
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
569
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
570
        shl     eax, 2
570
        shl     eax, 2
571
        mov     [rdx+BOOT_LO.pitch], ax
571
        mov     [rdx+BOOT_LO.pitch], ax
572
 
572
 
573
        mov     [rdx+BOOT_LO.pci_data.access_mechanism], 1
573
        mov     [rdx+BOOT_LO.pci_data.access_mechanism], 1
574
        movzx   eax, [pci_last_bus]
574
        movzx   eax, [pci_last_bus]
575
        mov     [rdx+BOOT_LO.pci_data.last_bus], al
575
        mov     [rdx+BOOT_LO.pci_data.last_bus], al
576
        mov     [rdx+BOOT_LO.pci_data.version], 0x0300  ; PCI 3.0
576
        mov     [rdx+BOOT_LO.pci_data.version], 0x0300  ; PCI 3.0
577
        mov     [rdx+BOOT_LO.pci_data.pm_entry], 0
577
        mov     [rdx+BOOT_LO.pci_data.pm_entry], 0
578
 
578
 
579
        ; kernel
579
        ; kernel
580
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
580
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
581
;                450000/0x1000, EFI_ALLOCATE_ADDRESS
581
;                450000/0x1000, EFI_ALLOCATE_ADDRESS
582
 
582
 
583
        ; ramdisk
583
        ; ramdisk
584
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
584
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
585
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
585
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
586
 
586
 
587
        fstcall calc_memmap
587
        fstcall calc_memmap
588
;        fstcall dump_memmap
588
;        fstcall dump_memmap
589
 
589
 
590
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
590
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
591
        fstcall [r10+EFI_BOOT_SERVICES.ExitBootServices], [efi_handle], \
591
        fstcall [r10+EFI_BOOT_SERVICES.ExitBootServices], [efi_handle], \
592
                [memory_map_key]
592
                [memory_map_key]
593
        fstcall halt_on_error
593
        fstcall halt_on_error
594
 
594
 
595
        cli
595
        cli
596
 
596
 
597
        xor     edx, edx
597
        xor     edx, edx
598
        xor     esi, esi
598
        xor     esi, esi
599
        mov     [rsi+BOOT_LO.bpp], 32
599
        mov     [rsi+BOOT_LO.bpp], 32
600
        mov     [rsi+BOOT_LO.vesa_mode], dx
600
        mov     [rsi+BOOT_LO.vesa_mode], dx
601
        mov     [rsi+BOOT_LO.bank_switch], edx
601
        mov     [rsi+BOOT_LO.bank_switch], edx
602
        mov     rdi, [fb_base]
602
        mov     rdi, [fb_base]
603
        mov     [rsi+BOOT_LO.lfb], edi
603
        mov     [rsi+BOOT_LO.lfb], edi
604
 
604
 
605
        movzx   eax, [cfg_opt_value_mtrr]
605
        movzx   eax, [cfg_opt_value_mtrr]
606
        mov     [rsi+BOOT_LO.mtrr], al
606
        mov     [rsi+BOOT_LO.mtrr], al
607
 
607
 
608
        movzx   eax, [cfg_opt_value_launcher_start]
608
        movzx   eax, [cfg_opt_value_launcher_start]
609
        mov     [rsi+BOOT_LO.launcher_start], al
609
        mov     [rsi+BOOT_LO.launcher_start], al
610
 
610
 
611
        movzx   eax, [cfg_opt_value_debug_print]
611
        movzx   eax, [cfg_opt_value_debug_print]
612
        mov     [rsi+BOOT_LO.debug_print], al
612
        mov     [rsi+BOOT_LO.debug_print], al
613
 
613
 
614
        mov     [rsi+BOOT_LO.dma], dl
614
        mov     [rsi+BOOT_LO.dma], dl
615
        mov     [rsi+BOOT_LO.apm_entry], edx
615
        mov     [rsi+BOOT_LO.apm_entry], edx
616
        mov     [rsi+BOOT_LO.apm_version], dx
616
        mov     [rsi+BOOT_LO.apm_version], dx
617
        mov     [rsi+BOOT_LO.apm_flags], dx
617
        mov     [rsi+BOOT_LO.apm_flags], dx
618
        mov     [rsi+BOOT_LO.apm_code_32], dx
618
        mov     [rsi+BOOT_LO.apm_code_32], dx
619
        mov     [rsi+BOOT_LO.apm_code_16], dx
619
        mov     [rsi+BOOT_LO.apm_code_16], dx
620
        mov     [rsi+BOOT_LO.apm_data_16], dx
620
        mov     [rsi+BOOT_LO.apm_data_16], dx
621
        mov     [rsi+BOOT_LO.bios_hd_cnt], dl
621
        mov     [rsi+BOOT_LO.bios_hd_cnt], dl
622
 
622
 
623
        movzx   eax, [cfg_opt_value_imgfrom]
623
        movzx   eax, [cfg_opt_value_imgfrom]
624
        mov     [rsi+BOOT_LO.rd_load_from], al
624
        mov     [rsi+BOOT_LO.rd_load_from], al
625
 
625
 
626
        mov     eax, dword[devicesdat_size]
626
        mov     eax, dword[devicesdat_size]
627
        mov     [rdx+BOOT_LO.devicesdat_size], eax
627
        mov     [rdx+BOOT_LO.devicesdat_size], eax
628
        mov     eax, dword[devicesdat_data]
628
        mov     eax, dword[devicesdat_data]
629
        mov     [rdx+BOOT_LO.devicesdat_data], eax
629
        mov     [rdx+BOOT_LO.devicesdat_data], eax
630
 
630
 
631
        mov     rsi, cfg_opt_value_syspath
631
        mov     rsi, cfg_opt_value_syspath
632
        mov     rdi, BOOT_LO.syspath
632
        mov     rdi, BOOT_LO.syspath
633
        mov     ecx, 0x17
633
        mov     ecx, 0x17
634
        rep movsb
634
        rep movsb
635
 
635
 
636
        ; kernel trampoline
636
        ; kernel trampoline
637
        mov     rsi, kernel_trampoline
637
        mov     rsi, kernel_trampoline
638
        mov     rdi, KERNEL_TRAMPOLINE
638
        mov     rdi, KERNEL_TRAMPOLINE
639
        mov     ecx, kernel_trampoline.size
639
        mov     ecx, kernel_trampoline.size
640
        rep movsb
640
        rep movsb
641
 
641
 
642
        mov     rax, GDTR
642
        mov     rax, GDTR
643
        lgdt    [cs:rax]
643
        lgdt    [cs:rax]
644
 
644
 
645
        mov     ax, DATA_32_SELECTOR
645
        mov     ax, DATA_32_SELECTOR
646
        mov     ds, ax
646
        mov     ds, ax
647
        mov     es, ax
647
        mov     es, ax
648
        mov     fs, ax
648
        mov     fs, ax
649
        mov     gs, ax
649
        mov     gs, ax
650
        mov     ss, ax
650
        mov     ss, ax
651
 
651
 
652
        push    CODE_32_SELECTOR
652
        push    CODE_32_SELECTOR
653
        mov     rax, KERNEL_TRAMPOLINE
653
        mov     rax, KERNEL_TRAMPOLINE
654
        push    rax
654
        push    rax
655
        retf
655
        retf
656
 
656
 
657
.error:
657
.error:
658
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
658
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
659
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
659
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
660
                msg_error
660
                msg_error
661
        jmp     $
661
        jmp     $
662
endp
662
endp
663
 
663
 
664
proc halt_on_error
664
proc halt_on_error
665
        test    eax, eax
665
        test    eax, eax
666
        jz      @f
666
        jz      @f
667
        call    clearbuf
667
        call    clearbuf
668
        mov     rdi, msg
668
        mov     rdi, msg
669
        call    num2hex
669
        call    num2hex
670
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
670
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
671
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
671
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
672
                msg_error
672
                msg_error
673
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
673
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
674
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
674
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
675
        jmp     $
675
        jmp     $
676
@@:
676
@@:
677
        ret
677
        ret
678
endp
678
endp
679
 
679
 
680
proc get_protocol_interface uses rsi rdi, _guid
680
proc get_protocol_interface uses rsi rdi, _guid
681
locals
681
locals
682
        .status dq ?
682
        .status dq ?
683
endl
683
endl
684
        mov     [_guid], rcx
684
        mov     [_guid], rcx
685
        mov     [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
685
        mov     [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
686
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
686
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
687
        fstcall [r10+EFI_BOOT_SERVICES.LocateHandle], \
687
        fstcall [r10+EFI_BOOT_SERVICES.LocateHandle], \
688
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
688
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
689
                prot_handlers_buffer_size, prot_handlers_buffer
689
                prot_handlers_buffer_size, prot_handlers_buffer
690
        mov     [.status], rax
690
        mov     [.status], rax
691
 
691
 
692
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
692
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
693
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
693
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
694
                msg_protocol_buffer_size
694
                msg_protocol_buffer_size
695
        call    clearbuf
695
        call    clearbuf
696
        mov     rax, [prot_handlers_buffer_size]
696
        mov     rax, [prot_handlers_buffer_size]
697
        mov     rdi, msg
697
        mov     rdi, msg
698
        call    num2hex
698
        call    num2hex
699
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
699
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
700
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
700
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
701
 
701
 
702
        mov     rax, [.status]
702
        mov     rax, [.status]
703
        test    eax, eax
703
        test    eax, eax
704
        jz      @f
704
        jz      @f
705
        call    clearbuf
705
        call    clearbuf
706
        mov     rdi, msg
706
        mov     rdi, msg
707
        call    num2hex
707
        call    num2hex
708
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
708
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
709
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
709
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
710
                msg_error
710
                msg_error
711
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
711
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
712
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
712
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
713
        jmp     $
713
        jmp     $
714
@@:
714
@@:
715
 
715
 
716
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
716
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
717
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
717
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
718
                msg_look_for_handler
718
                msg_look_for_handler
719
 
719
 
720
        mov     rsi, prot_handlers_buffer
720
        mov     rsi, prot_handlers_buffer
721
.try_next_handle:
721
.try_next_handle:
722
        mov     rax, rsi
722
        mov     rax, rsi
723
        mov     rcx, prot_handlers_buffer
723
        mov     rcx, prot_handlers_buffer
724
        sub     rax, rcx
724
        sub     rax, rcx
725
        cmp     rax, [prot_handlers_buffer_size]
725
        cmp     rax, [prot_handlers_buffer_size]
726
        jb      @f
726
        jb      @f
727
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
727
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
728
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
728
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
729
                msg_error_out_of_handlers
729
                msg_error_out_of_handlers
730
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
730
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
731
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
731
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
732
                msg_error
732
                msg_error
733
        jmp     $
733
        jmp     $
734
@@:
734
@@:
735
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
735
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
736
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
736
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
737
                msg_query_handler
737
                msg_query_handler
738
 
738
 
739
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
739
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
740
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], qword[rsi], [_guid], \
740
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], qword[rsi], [_guid], \
741
                prot_interface
741
                prot_interface
742
;mov rax, 0x8000_0000_0000_0003
742
;mov rax, 0x8000_0000_0000_0003
743
        test    eax, eax
743
        test    eax, eax
744
        jz      @f
744
        jz      @f
745
        call    clearbuf
745
        call    clearbuf
746
        mov     rdi, msg
746
        mov     rdi, msg
747
        call    num2hex
747
        call    num2hex
748
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
748
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
749
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
749
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
750
 
750
 
751
        add     rsi, 8
751
        add     rsi, 8
752
        jmp     .try_next_handle
752
        jmp     .try_next_handle
753
@@:
753
@@:
754
        mov     rax, [prot_interface]
754
        mov     rax, [prot_interface]
755
        ret
755
        ret
756
endp
756
endp
757
 
757
 
758
 
758
 
759
proc find_rsdp uses rsi rdi
759
proc find_rsdp uses rsi rdi
760
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
760
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
761
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
761
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
762
                msg_look_for_rsdp
762
                msg_look_for_rsdp
763
 
763
 
764
        mov     rdi, [rbx+EFI_SYSTEM_TABLE.ConfigurationTable]
764
        mov     rdi, [rbx+EFI_SYSTEM_TABLE.ConfigurationTable]
765
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.NumberOfTableEntries]
765
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.NumberOfTableEntries]
766
        mov     rax, 0x11d3e4f18868e871
766
        mov     rax, 0x11d3e4f18868e871
767
        mov     rdx, 0x81883cc7800022bc
767
        mov     rdx, 0x81883cc7800022bc
768
.next_table:
768
.next_table:
769
        dec     ecx
769
        dec     ecx
770
        js      .all_tables_done
770
        js      .all_tables_done
771
        cmp     [rdi+0], rax
771
        cmp     [rdi+0], rax
772
        jnz     .not_acpi20
772
        jnz     .not_acpi20
773
        cmp     [rdi+8], rdx
773
        cmp     [rdi+8], rdx
774
        jnz     .not_acpi20
774
        jnz     .not_acpi20
775
        mov     rax, [rdi+16]
775
        mov     rax, [rdi+16]
776
        mov     rdx, BOOT_LO.acpi_rsdp
776
        mov     rdx, BOOT_LO.acpi_rsdp
777
        mov     [rdx], eax
777
        mov     [rdx], eax
778
        jmp     .all_tables_done
778
        jmp     .all_tables_done
779
.not_acpi20:
779
.not_acpi20:
780
        add     rdi, 24
780
        add     rdi, 24
781
        jmp     .next_table
781
        jmp     .next_table
782
.all_tables_done:
782
.all_tables_done:
783
        ret
783
        ret
784
endp
784
endp
785
 
785
 
786
proc dump_pci_resources uses rsi rdi
786
proc dump_pci_resources uses rsi rdi
787
        xor     eax, eax
787
        xor     eax, eax
788
        mov     rsi, [pcirbiop_resources]
788
        mov     rsi, [pcirbiop_resources]
789
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
789
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
790
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
790
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
791
                msg_dump_pci_resources
791
                msg_dump_pci_resources
792
.next_resource:
792
.next_resource:
793
        call    clearbuf
793
        call    clearbuf
794
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
794
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
795
        cmp     eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
795
        cmp     eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
796
        jz      .done
796
        jz      .done
797
        mov     rdi, msg
797
        mov     rdi, msg
798
        call    num2hex
798
        call    num2hex
799
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
799
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
800
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
800
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
801
        call    clearbuf
801
        call    clearbuf
802
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
802
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
803
        mov     rdi, msg
803
        mov     rdi, msg
804
        call    num2dec
804
        call    num2dec
805
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMinimum]
805
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMinimum]
806
        mov     rdi, msg+2*2
806
        mov     rdi, msg+2*2
807
        call    num2hex
807
        call    num2hex
808
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
808
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
809
        mov     rdi, msg+19*2
809
        mov     rdi, msg+19*2
810
        call    num2hex
810
        call    num2hex
811
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.TranslationOffset]
811
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.TranslationOffset]
812
        mov     rdi, msg+36*2
812
        mov     rdi, msg+36*2
813
        call    num2hex
813
        call    num2hex
814
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
814
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
815
        mov     rdi, msg+53*2
815
        mov     rdi, msg+53*2
816
        call    num2hex
816
        call    num2hex
817
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
817
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
818
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
818
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
819
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
819
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
820
        add     eax, 3
820
        add     eax, 3
821
        add     rsi, rax
821
        add     rsi, rax
822
        jmp     .next_resource
822
        jmp     .next_resource
823
.done:
823
.done:
824
        ret
824
        ret
825
endp
825
endp
826
 
826
 
827
proc calc_memmap uses rsi rdi
827
proc calc_memmap uses rsi rdi
828
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
828
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
829
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
829
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
830
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
830
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
831
        call    halt_on_error
831
        call    halt_on_error
832
 
832
 
833
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
833
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
834
        fstcall [r10+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
834
        fstcall [r10+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
835
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
835
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
836
        call    halt_on_error
836
        call    halt_on_error
837
 
837
 
838
        mov     rdi, BOOT_LO.memmap_blocks
838
        mov     rdi, BOOT_LO.memmap_blocks
839
        mov     dword[rdi-4], 0 ; memmap_block_cnt
839
        mov     dword[rdi-4], 0 ; memmap_block_cnt
840
        mov     rsi, [memory_map]
840
        mov     rsi, [memory_map]
841
        mov     r10, rsi
841
        mov     r10, rsi
842
        add     r10, [memory_map_size]
842
        add     r10, [memory_map_size]
843
.next_descr:
843
.next_descr:
844
        fstcall add_uefi_memmap
844
        fstcall add_uefi_memmap
845
        add     rsi, [descriptor_size]
845
        add     rsi, [descriptor_size]
846
        cmp     rsi, r10
846
        cmp     rsi, r10
847
        jb      .next_descr
847
        jb      .next_descr
848
        ret
848
        ret
849
endp
849
endp
850
 
850
 
851
proc dump_memmap uses rsi rdi
851
proc dump_memmap uses rsi rdi
852
        xor     eax, eax
852
        xor     eax, eax
853
        mov     rsi, BOOT_LO.memmap_blocks
853
        mov     rsi, BOOT_LO.memmap_blocks
854
        mov     r12, [rax+BOOT_LO.memmap_block_cnt]
854
        mov     r12, [rax+BOOT_LO.memmap_block_cnt]
855
 
855
 
856
        call    clearbuf
856
        call    clearbuf
857
        mov     eax, ebx
857
        mov     eax, ebx
858
        mov     rdi, msg
858
        mov     rdi, msg
859
        call    num2dec
859
        call    num2dec
860
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
860
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
861
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
861
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
862
                msg_memmap
862
                msg_memmap
863
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
863
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
864
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
864
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
865
        call    clearbuf
865
        call    clearbuf
866
.next_mapping:
866
.next_mapping:
867
        dec     r12d
867
        dec     r12d
868
        js      .done
868
        js      .done
869
        mov     rax, rsi
869
        mov     rax, rsi
870
        mov     rcx, BOOT_LO.memmap_blocks
870
        mov     rcx, BOOT_LO.memmap_blocks
871
        sub     rax, rcx
871
        sub     rax, rcx
872
        mov     ecx, sizeof.e820entry
872
        mov     ecx, sizeof.e820entry
873
        xor     edx, edx
873
        xor     edx, edx
874
        div     ecx
874
        div     ecx
875
        mov     rdi, msg
875
        mov     rdi, msg
876
        call    num2dec
876
        call    num2dec
877
        mov     rax, [rsi+e820entry.addr]
877
        mov     rax, [rsi+e820entry.addr]
878
        mov     rdi, msg+4*2
878
        mov     rdi, msg+4*2
879
        call    num2hex
879
        call    num2hex
880
        mov     rax, [rsi+e820entry.size]
880
        mov     rax, [rsi+e820entry.size]
881
        mov     rdi, msg+24*2
881
        mov     rdi, msg+24*2
882
        call    num2hex
882
        call    num2hex
883
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
883
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
884
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
884
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
885
        add     rsi, sizeof.e820entry
885
        add     rsi, sizeof.e820entry
886
        jmp     .next_mapping
886
        jmp     .next_mapping
887
.done:
887
.done:
888
        ret
888
        ret
889
endp
889
endp
890
 
890
 
891
; linux/arch/x86/platform/efi/efi.c
891
; linux/arch/x86/platform/efi/efi.c
892
; do_add_efi_memmap
892
; do_add_efi_memmap
893
proc add_uefi_memmap
893
proc add_uefi_memmap
894
        xor     eax, eax
894
        xor     eax, eax
895
        cmp     [rax+BOOT_LO.memmap_block_cnt], MAX_MEMMAP_BLOCKS
895
        cmp     [rax+BOOT_LO.memmap_block_cnt], MAX_MEMMAP_BLOCKS
896
        jz      .done
896
        jz      .done
897
 
897
 
898
        mov     rax, [rsi+EFI_MEMORY_DESCRIPTOR.PhysicalStart]
898
        mov     rax, [rsi+EFI_MEMORY_DESCRIPTOR.PhysicalStart]
899
        mov     [rdi+e820entry.addr], rax
899
        mov     [rdi+e820entry.addr], rax
900
 
900
 
901
        mov     rax, [rsi+EFI_MEMORY_DESCRIPTOR.NumberOfPages]
901
        mov     rax, [rsi+EFI_MEMORY_DESCRIPTOR.NumberOfPages]
902
        shl     rax, 12
902
        shl     rax, 12
903
        mov     [rdi+e820entry.size], rax
903
        mov     [rdi+e820entry.size], rax
904
 
904
 
905
        mov     ecx, [rsi+EFI_MEMORY_DESCRIPTOR.Type]
905
        mov     ecx, [rsi+EFI_MEMORY_DESCRIPTOR.Type]
906
        cmp     ecx, EFI_LOADER_CODE
906
        cmp     ecx, EFI_LOADER_CODE
907
        jz      .mem_ram_if_wb
907
        jz      .mem_ram_if_wb
908
        cmp     ecx, EFI_LOADER_DATA
908
        cmp     ecx, EFI_LOADER_DATA
909
        jz      .mem_ram_if_wb
909
        jz      .mem_ram_if_wb
910
        cmp     ecx, EFI_BOOT_SERVICES_CODE
910
        cmp     ecx, EFI_BOOT_SERVICES_CODE
911
        jz      .mem_ram_if_wb
911
        jz      .mem_ram_if_wb
912
        cmp     ecx, EFI_BOOT_SERVICES_DATA
912
        cmp     ecx, EFI_BOOT_SERVICES_DATA
913
        jz      .mem_ram_if_wb
913
        jz      .mem_ram_if_wb
914
        cmp     ecx, EFI_CONVENTIONAL_MEMORY
914
        cmp     ecx, EFI_CONVENTIONAL_MEMORY
915
        jz      .mem_ram_if_wb
915
        jz      .mem_ram_if_wb
916
        cmp     ecx, EFI_ACPI_RECLAIM_MEMORY
916
        cmp     ecx, EFI_ACPI_RECLAIM_MEMORY
917
        mov     eax, E820_ACPI
917
        mov     eax, E820_ACPI
918
        jz      .type_done
918
        jz      .type_done
919
        cmp     ecx, EFI_ACPI_MEMORY_NVS
919
        cmp     ecx, EFI_ACPI_MEMORY_NVS
920
        mov     eax, E820_NVS
920
        mov     eax, E820_NVS
921
        jz      .type_done
921
        jz      .type_done
922
        cmp     ecx, EFI_UNUSABLE_MEMORY
922
        cmp     ecx, EFI_UNUSABLE_MEMORY
923
        mov     eax, E820_UNUSABLE
923
        mov     eax, E820_UNUSABLE
924
        jz      .type_done
924
        jz      .type_done
925
        cmp     ecx, EFI_PERSISTENT_MEMORY
925
        cmp     ecx, EFI_PERSISTENT_MEMORY
926
        mov     eax, E820_PMEM
926
        mov     eax, E820_PMEM
927
        jz      .type_done
927
        jz      .type_done
928
        jmp     .reserved
928
        jmp     .reserved
929
.mem_ram_if_wb:
929
.mem_ram_if_wb:
930
        test    [rsi+EFI_MEMORY_DESCRIPTOR.Attribute], dword EFI_MEMORY_WB
930
        test    [rsi+EFI_MEMORY_DESCRIPTOR.Attribute], dword EFI_MEMORY_WB
931
        mov     eax, E820_RAM
931
        mov     eax, E820_RAM
932
        jnz     .type_done
932
        jnz     .type_done
933
.reserved:
933
.reserved:
934
        mov     eax, E820_RESERVED
934
        mov     eax, E820_RESERVED
935
.type_done:
935
.type_done:
936
        mov     [rdi+e820entry.type], eax
936
        mov     [rdi+e820entry.type], eax
937
        cmp     eax, E820_RAM
937
        cmp     eax, E820_RAM
938
        jnz     @f
938
        jnz     @f
939
        xor     eax, eax
939
        xor     eax, eax
940
        inc     [rax+BOOT_LO.memmap_block_cnt]
940
        inc     [rax+BOOT_LO.memmap_block_cnt]
941
        add     rdi, sizeof.e820entry
941
        add     rdi, sizeof.e820entry
942
@@:
942
@@:
943
.done:
943
.done:
944
        ret
944
        ret
945
endp
945
endp
946
 
946
 
947
num2dec:
947
num2dec:
948
        push    rbx rcx rdx rdi
948
        push    rbx rcx rdx rdi
949
 
949
 
950
        xor     ecx, ecx
950
        xor     ecx, ecx
951
        mov     ebx, 10
951
        mov     ebx, 10
952
.next_digit:
952
.next_digit:
953
        xor     edx, edx
953
        xor     edx, edx
954
        div     ebx
954
        div     ebx
955
        push    rdx
955
        push    rdx
956
        inc     ecx
956
        inc     ecx
957
        test    eax, eax
957
        test    eax, eax
958
        jnz     .next_digit
958
        jnz     .next_digit
959
 
959
 
960
.next_char:
960
.next_char:
961
        pop     rax
961
        pop     rax
962
        add     eax, '0'
962
        add     eax, '0'
963
        stosw
963
        stosw
964
        loop    .next_char
964
        loop    .next_char
965
 
965
 
966
        pop     rdi rdx rcx rbx
966
        pop     rdi rdx rcx rbx
967
        ret
967
        ret
968
 
968
 
969
 
969
 
970
num2hex:
970
num2hex:
971
        push    rbx rcx rdx rdi
971
        push    rbx rcx rdx rdi
972
 
972
 
973
        xchg    rdx, rax
973
        xchg    rdx, rax
974
        mov     ecx, 16
974
        mov     ecx, 16
975
.next_tetra:
975
.next_tetra:
976
        rol     rdx, 4
976
        rol     rdx, 4
977
        movzx   eax, dl
977
        movzx   eax, dl
978
        and     eax, 0x0f
978
        and     eax, 0x0f
979
        movzx   eax, byte[hex_abc+eax]
979
        movzx   eax, byte[hex_abc+eax]
980
        stosw
980
        stosw
981
        loop    .next_tetra
981
        loop    .next_tetra
982
 
982
 
983
        pop     rdi rdx rcx rbx
983
        pop     rdi rdx rcx rbx
984
        ret
984
        ret
985
 
985
 
986
clearbuf:
986
clearbuf:
987
        push    rcx rdi
987
        push    rcx rdi
988
        mov     eax, ' '
988
        mov     eax, ' '
989
        mov     ecx, 79
989
        mov     ecx, 79
990
        mov     rdi, msg
990
        mov     rdi, msg
991
        rep stosw
991
        rep stosw
992
        pop     rdi rcx
992
        pop     rdi rcx
993
        ret
993
        ret
994
 
994
 
995
use32
995
use32
996
kernel_trampoline:
996
kernel_trampoline:
997
org KERNEL_TRAMPOLINE
997
org KERNEL_TRAMPOLINE
998
        mov     eax, cr0
998
        mov     eax, cr0
999
        and     eax, not CR0_PG
999
        and     eax, not CR0_PG
1000
        mov     cr0, eax
1000
        mov     cr0, eax
1001
 
1001
 
1002
        mov     ecx, MSR_AMD_EFER
1002
        mov     ecx, MSR_AMD_EFER
1003
        rdmsr
1003
        rdmsr
1004
        btr     eax, 8                  ; LME
1004
        btr     eax, 8                  ; LME
1005
        wrmsr
1005
        wrmsr
1006
 
1006
 
1007
        mov     eax, cr4
1007
        mov     eax, cr4
1008
        and     eax, not CR4_PAE
1008
        and     eax, not CR4_PAE
1009
        mov     cr4, eax
1009
        mov     cr4, eax
1010
 
1010
 
1011
        mov     eax, KERNEL_BASE
1011
        mov     eax, KERNEL_BASE
1012
        ; add the 32-bit entry point
1012
        ; add the 32-bit entry point
1013
        add     eax, [eax+kernel_header.b32_offset]
1013
        add     eax, [eax+kernel_header.b32_offset]
1014
        push    eax
1014
        push    eax
1015
        retn
1015
        retn
1016
 
1016
 
1017
align 16
1017
align 16
1018
GDTR:
1018
GDTR:
1019
        dw 4*8-1
1019
        dw 4*8-1
1020
        dq GDT
1020
        dq GDT
1021
align 16
1021
align 16
1022
GDT:
1022
GDT:
1023
        dw 0, 0, 0, 0
1023
        dw 0, 0, 0, 0
1024
        dw 0FFFFh,0,9A00h,0CFh          ; 32-bit code
1024
        dw 0FFFFh,0,9A00h,0CFh          ; 32-bit code
1025
        dw 0FFFFh,0,9200h,0CFh          ; flat data
1025
        dw 0FFFFh,0,9200h,0CFh          ; flat data
1026
        dw 0FFFFh,0,9A00h,0AFh          ; 64-bit code
1026
        dw 0FFFFh,0,9A00h,0AFh          ; 64-bit code
1027
assert $ < BOOT_LO
1027
assert $ < BOOT_LO
1028
kernel_trampoline.size = $ - KERNEL_TRAMPOLINE
1028
kernel_trampoline.size = $ - KERNEL_TRAMPOLINE
1029
 
1029
 
1030
section '.rodata' data readable
1030
section '.rodata' data readable
1031
gop_guid        db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
1031
gop_guid        db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
1032
lip_guid        db EFI_LOADED_IMAGE_PROTOCOL_GUID
1032
lip_guid        db EFI_LOADED_IMAGE_PROTOCOL_GUID
1033
sfsp_guid       db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
1033
sfsp_guid       db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
1034
pcirbiop_guid   db EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID
1034
pcirbiop_guid   db EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID
1035
 
1035
 
1036
file_name       du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
1036
file_name       du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
1037
kernel_name     du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
1037
kernel_name     du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
1038
ramdisk_name    du '\EFI\KOLIBRIOS\KOLIBRI.IMG',0
1038
ramdisk_name    du '\EFI\KOLIBRIOS\KOLIBRI.IMG',0
1039
devicesdat_name du '\EFI\KOLIBRIOS\DEVICES.DAT',0
1039
devicesdat_name du '\EFI\KOLIBRIOS\DEVICES.DAT',0
1040
 
1040
 
1041
config_options  dq cfg_opt_name_resolution, cfg_opt_func_resolution, \
1041
config_options  dq cfg_opt_name_resolution, cfg_opt_func_resolution, \
1042
                   cfg_opt_cmnt_resolution, \
1042
                   cfg_opt_cmnt_resolution, \
1043
                   cfg_opt_name_acpi,  cfg_opt_func_acpi, cfg_opt_cmnt_acpi, \
1043
                   cfg_opt_name_acpi,  cfg_opt_func_acpi, cfg_opt_cmnt_acpi, \
1044
                   cfg_opt_name_debug_print, cfg_opt_func_debug_print, \
1044
                   cfg_opt_name_debug_print, cfg_opt_func_debug_print, \
1045
                   cfg_opt_cmnt_debug_print, \
1045
                   cfg_opt_cmnt_debug_print, \
1046
                   cfg_opt_name_launcher_start, cfg_opt_func_launcher_start, \
1046
                   cfg_opt_name_launcher_start, cfg_opt_func_launcher_start, \
1047
                   cfg_opt_cmnt_launcher_start, \
1047
                   cfg_opt_cmnt_launcher_start, \
1048
                   cfg_opt_name_mtrr,  cfg_opt_func_mtrr, cfg_opt_cmnt_mtrr, \
1048
                   cfg_opt_name_mtrr,  cfg_opt_func_mtrr, cfg_opt_cmnt_mtrr, \
1049
                   cfg_opt_name_ask_params,  cfg_opt_func_ask_params, \
1049
                   cfg_opt_name_ask_params,  cfg_opt_func_ask_params, \
1050
                   cfg_opt_cmnt_ask_params, \
1050
                   cfg_opt_cmnt_ask_params, \
1051
                   cfg_opt_name_imgfrom, cfg_opt_func_imgfrom, \
1051
                   cfg_opt_name_imgfrom, cfg_opt_func_imgfrom, \
1052
                   cfg_opt_cmnt_imgfrom, \
1052
                   cfg_opt_cmnt_imgfrom, \
1053
                   cfg_opt_name_syspath, cfg_opt_func_syspath, \
1053
                   cfg_opt_name_syspath, cfg_opt_func_syspath, \
1054
                   cfg_opt_cmnt_syspath, \
1054
                   cfg_opt_cmnt_syspath, \
1055
                   0
1055
                   0
1056
 
1056
 
1057
cfg_opt_name_resolution     db "resolution",0
1057
cfg_opt_name_resolution     db "resolution",0
1058
cfg_opt_name_acpi           db "acpi",0
1058
cfg_opt_name_acpi           db "acpi",0
1059
cfg_opt_name_debug_print    db "debug_print",0
1059
cfg_opt_name_debug_print    db "debug_print",0
1060
cfg_opt_name_launcher_start db "launcher_start",0
1060
cfg_opt_name_launcher_start db "launcher_start",0
1061
cfg_opt_name_mtrr           db "mtrr",0
1061
cfg_opt_name_mtrr           db "mtrr",0
1062
cfg_opt_name_ask_params     db "ask_params",0
1062
cfg_opt_name_ask_params     db "ask_params",0
1063
cfg_opt_name_imgfrom        db "imgfrom",0
1063
cfg_opt_name_imgfrom        db "imgfrom",0
1064
cfg_opt_name_syspath        db "syspath",0
1064
cfg_opt_name_syspath        db "syspath",0
1065
 
1065
 
1066
cfg_opt_cmnt_resolution     db "# Graphic mode",0
1066
cfg_opt_cmnt_resolution     db "# Graphic mode",0
1067
cfg_opt_cmnt_acpi           db "# ACPI settings",0xa, \
1067
cfg_opt_cmnt_acpi           db "# ACPI settings",0xa, \
1068
                               "#   0: don't use",0xa, \
1068
                               "#   0: don't use",0xa, \
1069
                               "#   1: parse ACPI tables",0xa, \
1069
                               "#   1: parse ACPI tables",0xa, \
1070
                               "#   2: + call _PIC method",0xa, \
1070
                               "#   2: + call _PIC method",0xa, \
1071
                               "#   3: + get APIC interrupts",0xa,0
1071
                               "#   3: + get APIC interrupts",0xa,0
1072
cfg_opt_cmnt_debug_print    db "# Duplicate debug output to the screen",0
1072
cfg_opt_cmnt_debug_print    db "# Duplicate debug output to the screen",0
1073
cfg_opt_cmnt_launcher_start db "# Start LAUNCHER app after kernel is loaded",0
1073
cfg_opt_cmnt_launcher_start db "# Start LAUNCHER app after kernel is loaded",0
1074
cfg_opt_cmnt_mtrr           db "# Configure MTRR's",0
1074
cfg_opt_cmnt_mtrr           db "# Configure MTRR's",0
1075
cfg_opt_cmnt_ask_params     db "# Interrupt booting to ask the user for boot", \
1075
cfg_opt_cmnt_ask_params     db "# Interrupt booting to ask the user for boot", \
1076
                               " params",0
1076
                               " params",0
1077
cfg_opt_cmnt_imgfrom        db "# Where to load ramdisk image from",0
1077
cfg_opt_cmnt_imgfrom        db "# Where to load ramdisk image from",0
1078
cfg_opt_cmnt_syspath        db "# Path to /sys directory",0
1078
cfg_opt_cmnt_syspath        db "# Path to /sys directory",0
1079
 
1079
 
1080
msg_u4k_loaded            du "uefi64kos loaded",13,10,0
1080
msg_u4k_loaded            du "uefi64kos loaded",13,10,0
1081
msg_detect_pci_config     du "Detect PCI configuration",13,10,0
1081
msg_detect_pci_config     du "Detect PCI configuration",13,10,0
1082
msg_dump_pci_resources    du "Dump PCI resources",13,10,0
1082
msg_dump_pci_resources    du "Dump PCI resources",13,10,0
1083
msg_pci_last_bus          du "Last PCI bus",13,10,0
1083
msg_pci_last_bus          du "Last PCI bus",13,10,0
1084
msg_read_options          du "Read options from config file",13,10,0
1084
msg_read_options          du "Read options from config file",13,10,0
1085
msg_file_size             du "File size:",13,10,0
1085
msg_file_size             du "File size:",13,10,0
1086
msg_parsing_config        du "Parsing config file",13,10,0
1086
msg_parsing_config        du "Parsing config file",13,10,0
1087
msg_load_kernel           du "Load kernel",13,10,0
1087
msg_load_kernel           du "Load kernel",13,10,0
1088
msg_load_ramdisk          du "Load ramdisk",13,10,0
1088
msg_load_ramdisk          du "Load ramdisk",13,10,0
1089
msg_load_devicesdat       du "Load DEVICES.DAT",13,10,0
1089
msg_load_devicesdat       du "Load DEVICES.DAT",13,10,0
1090
msg_alloc_devicesdat      du "Allocate memory for DEVICES.DAT",13,10,0
1090
msg_alloc_devicesdat      du "Allocate memory for DEVICES.DAT",13,10,0
1091
msg_locate_gop_interface  du "Locate GOP interface",13,10,0
1091
msg_locate_gop_interface  du "Locate GOP interface",13,10,0
1092
msg_look_for_handler      du "Look for protocol handler",13,10,0
1092
msg_look_for_handler      du "Look for protocol handler",13,10,0
1093
msg_query_handler         du "Query handler",13,10,0
1093
msg_query_handler         du "Query handler",13,10,0
1094
msg_query_vmode           du "Query vmode",13,10,0
1094
msg_query_vmode           du "Query vmode",13,10,0
1095
msg_vmode_found           du "Video mode found",13,10,0
1095
msg_vmode_found           du "Video mode found",13,10,0
1096
msg_look_for_rsdp         du "Look for RSDP",13,10,0
1096
msg_look_for_rsdp         du "Look for RSDP",13,10,0
1097
msg_rsdp_found            du "RSDP found",13,10,0
1097
msg_rsdp_found            du "RSDP found",13,10,0
1098
msg_acpi_tables_done      du "ACPI tables done",13,10,0
1098
msg_acpi_tables_done      du "ACPI tables done",13,10,0
1099
msg_ask_for_params        du "Ask for params",13,10,0
1099
msg_ask_for_params        du "Ask for params",13,10,0
1100
msg_set_graphic_mode      du "Set graphic mode",13,10,0
1100
msg_set_graphic_mode      du "Set graphic mode",13,10,0
1101
msg_success               du "Success!",13,10,0
1101
msg_success               du "Success!",13,10,0
1102
msg_protocol_buffer_size  du "Protocol buffer size",13,10,0
1102
msg_protocol_buffer_size  du "Protocol buffer size",13,10,0
1103
msg_opt_resolution        du "Option resolution: ",0
1103
msg_opt_resolution        du "Option resolution: ",0
1104
msg_memmap                du "Memmap",13,10,0
1104
msg_memmap                du "Memmap",13,10,0
1105
msg_error                 du "Error!",13,10,0
1105
msg_error                 du "Error!",13,10,0
1106
msg_error_efi_lip_handle  du "efi_handle can't handle LIP",13,10,0
1106
msg_error_efi_lip_handle  du "efi_handle can't handle LIP",13,10,0
1107
msg_error_lip_dev_sfsp    du "LIP device handle can't handle SFSP",13,10,0
1107
msg_error_lip_dev_sfsp    du "LIP device handle can't handle SFSP",13,10,0
1108
msg_error_sfsp_openvolume du "SFSP OpenVolume failed",13,10,0
1108
msg_error_sfsp_openvolume du "SFSP OpenVolume failed",13,10,0
1109
msg_error_no_such_vmode   du "No such vmode",13,10,0
1109
msg_error_no_such_vmode   du "No such vmode",13,10,0
1110
msg_error_out_of_handlers du "Out of handlers",13,10,0
1110
msg_error_out_of_handlers du "Out of handlers",13,10,0
1111
msg_error_open_file       du "Error: can't open file ",0
1111
msg_error_open_file       du "Error: can't open file ",0
1112
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1112
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1113
msg                       du 79 dup " ",13,10,0
1113
msg                       du 79 dup " ",13,10,0
1114
msg_debug                 du "Debug ",13,10,0
1114
msg_debug                 du "Debug ",13,10,0
1115
 
1115
 
1116
section '.data' data readable writeable
1116
section '.data' data readable writeable
1117
efi_handle  dq 0
1117
efi_handle  dq 0
1118
efi_table   dq 0
1118
efi_table   dq 0
1119
 
1119
 
1120
fb_base         dq 0
1120
fb_base         dq 0
1121
 
1121
 
1122
gop_interface   dq 0
1122
gop_interface   dq 0
1123
gop_info_size   dq 0
1123
gop_info_size   dq 0
1124
gop_info        dq 0
1124
gop_info        dq 0
1125
 
1125
 
1126
lip_interface   dq 0
1126
lip_interface   dq 0
1127
 
1127
 
1128
sfsp_interface  dq 0
1128
sfsp_interface  dq 0
1129
 
1129
 
1130
pci_last_bus db 254
1130
pci_last_bus db 254
1131
 
1131
 
1132
cfg_opt_used_resolution     db 0
1132
cfg_opt_used_resolution     db 0
1133
cfg_opt_used_acpi           db 0
1133
cfg_opt_used_acpi           db 0
1134
cfg_opt_used_debug_print    db 0
1134
cfg_opt_used_debug_print    db 0
1135
cfg_opt_used_launcher_start db 0
1135
cfg_opt_used_launcher_start db 0
1136
cfg_opt_used_mtrr           db 0
1136
cfg_opt_used_mtrr           db 0
1137
cfg_opt_used_ask_params     db 0
1137
cfg_opt_used_ask_params     db 0
1138
cfg_opt_used_imgfrom        db 0
1138
cfg_opt_used_imgfrom        db 0
1139
cfg_opt_used_syspath        db 0
1139
cfg_opt_used_syspath        db 0
1140
 
1140
 
1141
cfg_opt_value_vmode          db 0
1141
cfg_opt_value_vmode          db 0
1142
cfg_opt_value_acpi           db 0
1142
cfg_opt_value_acpi           db 0
1143
cfg_opt_value_debug_print    db 0
1143
cfg_opt_value_debug_print    db 0
1144
cfg_opt_value_launcher_start db 1
1144
cfg_opt_value_launcher_start db 1
1145
cfg_opt_value_mtrr           db 0
1145
cfg_opt_value_mtrr           db 0
1146
cfg_opt_value_ask_params     db 0
1146
cfg_opt_value_ask_params     db 0
1147
cfg_opt_value_imgfrom        db RD_LOAD_FROM_MEMORY
1147
cfg_opt_value_imgfrom        db RD_LOAD_FROM_MEMORY
1148
cfg_opt_value_syspath        db "/RD/1",0
1148
cfg_opt_value_syspath        db "/RD/1",0
1149
                             rb 20
1149
                             rb 20
1150
 
1150
 
1151
memory_map_key  dq 0
1151
memory_map_key  dq 0
1152
descriptor_size dq 0
1152
descriptor_size dq 0
1153
descriptor_ver  dq 0
1153
descriptor_ver  dq 0
1154
memory_map_size dq MEMORY_MAP_SIZE
1154
memory_map_size dq MEMORY_MAP_SIZE
1155
 
1155
 
1156
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1156
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1157
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
1157
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
1158
 
1158
 
1159
devicesdat_data dq 0xffffffff
1159
devicesdat_data dq 0xffffffff
1160
devicesdat_size dq 0x1000
1160
devicesdat_size dq 0x1000
1161
 
1161
 
1162
hex_abc db '0123456789ABCDEF'
1162
hex_abc db '0123456789ABCDEF'
1163
 
1163
 
1164
section '.bss' data readable writeable discardable
1164
section '.bss' data readable writeable discardable
1165
prot_handlers_buffer_size dq ?
1165
prot_handlers_buffer_size dq ?
1166
prot_interface  dq ?
1166
prot_interface  dq ?
1167
esp_root        dq ?
1167
esp_root        dq ?
1168
file_handle     dq ?
1168
file_handle     dq ?
1169
pcirbiop_interface dq ?
1169
pcirbiop_interface dq ?
1170
pcirbiop_resources dq ?
1170
pcirbiop_resources dq ?
1171
efi_fs_info EFI_FILE_SYSTEM_INFO
1171
efi_fs_info EFI_FILE_SYSTEM_INFO
1172
memory_map      dq ?
1172
memory_map      dq ?
1173
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1173
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1174
pcirbio_buffer  rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1174
pcirbio_buffer  rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1175
 
1175
 
1176
section '.reloc' fixups data discardable
1176
section '.reloc' fixups data discardable