Subversion Repositories Kolibri OS

Rev

Rev 8656 | Rev 9253 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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