Subversion Repositories Kolibri OS

Rev

Rev 8206 | Rev 8284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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