Subversion Repositories Kolibri OS

Rev

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

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