Subversion Repositories Kolibri OS

Rev

Rev 8656 | Rev 9253 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8656 Rev 9227
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2020. All rights reserved.      ;;
3
;; Copyright (C) KolibriOS team 2020-2021. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;; Version 2, or (at your option) any later version.            ;;
5
;; Version 2, or (at your option) any later version.            ;;
6
;;                                                              ;;
6
;;                                                              ;;
-
 
7
;; Written by Ivan Baravy                                       ;;
-
 
8
;;                                                              ;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 8... Line 10...
8
 
10
 
9
format pe64 efi
11
format pe64 efi
Line 10... Line 12...
10
entry main
12
entry main
Line 11... Line 13...
11
 
13
 
12
section '.text' code executable readable
14
section '.text' code executable readable
-
 
15
 
-
 
16
include '../../struct.inc'
-
 
17
include '../../macros.inc'
13
 
18
include '../../kglobals.inc'
Line 14... Line 19...
14
include '../../struct.inc'
19
fastcall fix fstcall
15
include '../../macros.inc'
20
include 'proc64.inc'
Line 16... Line 21...
16
include '../../const.inc'
21
include '../../const.inc'
17
 
-
 
18
purge DQ
22
 
19
include 'uefi64.inc'
23
purge DQ
Line 20... Line 24...
20
 
24
include 'uefi64.inc'
21
MEMORY_MAP_SIZE = 0x10000
25
 
22
GOP_BUFFER_SIZE = 0x100
26
MEMORY_MAP_SIZE = 0x10000
Line 46... Line 50...
46
  .name   dq ?
50
  .name   dq ?
47
  .buffer dq ?
51
  .buffer dq ?
48
  .size   dq ?
52
  .size   dq ?
49
  .fatal  dq ?
53
  .fatal  dq ?
50
end virtual
54
end virtual
-
 
55
        mov     r10, [.root]
-
 
56
        mov     r11, [.name]
51
        eficall [.root], EFI_FILE_PROTOCOL.Open, [.root], file_handle, \
57
        fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
52
                [.name], EFI_FILE_MODE_READ, 0
58
                r11, EFI_FILE_MODE_READ, 0
53
        test    eax, eax
59
        test    eax, eax
54
        jz      @f
60
        jz      @f
55
        xor     eax, eax
61
        xor     eax, eax
56
        cmp     [.fatal], 1
62
        cmp     [.fatal], 1
57
        jnz     .done
63
        jnz     .done
58
        mov     rbx, [efi_table]
64
        mov     rbx, [efi_table]
59
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
65
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
60
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
66
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
61
                msg_error_open_file
67
                msg_error_open_file
62
        mov     rbx, [efi_table]
68
        mov     rbx, [efi_table]
63
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
69
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
70
        mov     r10, [.name]
64
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
71
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, r10
65
                [.name]
-
 
66
        jmp     $
72
        jmp     $
67
@@:
73
@@:
Line 68... Line 74...
68
 
74
 
-
 
75
        lea     rdx, [.size]
-
 
76
        mov     r8, [.buffer]
69
        lea     rax, [.size]
77
        mov     r10, [file_handle]
70
        eficall [file_handle], EFI_FILE_PROTOCOL.Read, [file_handle], rax, \
78
        fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
71
                [.buffer]
79
        mov     r10, [file_handle]
72
        eficall [file_handle], EFI_FILE_PROTOCOL.Close, [file_handle]
80
        fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
73
        mov     rax, [.size]
81
        mov     rax, [.size]
74
.done:
82
.done:
75
        push    rax
83
        push    rax
76
        call    clearbuf
84
        call    clearbuf
77
        mov     rdi, msg
85
        mov     rdi, msg
78
        call    num2dec
86
        call    num2dec
79
        push    rbx
87
        push    rbx
80
        mov     rbx, [efi_table]
88
        mov     rbx, [efi_table]
81
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
89
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
82
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
90
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
83
                msg_file_size
91
                msg_file_size
84
        pop     rbx
92
        pop     rbx
85
        push    rbx
93
        push    rbx
86
        mov     rbx, [efi_table]
94
        mov     rbx, [efi_table]
87
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
95
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
88
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
96
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
89
        pop     rbx
97
        pop     rbx
90
        pop     rax
98
        pop     rax
Line 91... Line 99...
91
        ret     8*5
99
        ret     8*5
Line 277... Line 285...
277
end virtual
285
end virtual
278
;        mov     rsi, [.buffer]
286
;        mov     rsi, [.buffer]
279
        push    rbx
287
        push    rbx
280
        mov     rbx, [efi_table]
288
        mov     rbx, [efi_table]
281
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
289
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
282
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
290
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
283
                msg_parsing_config
291
                msg_parsing_config
284
        pop     rbx
292
        pop     rbx
285
        mov     rsi, KERNEL_BASE
293
        mov     rsi, KERNEL_BASE
286
.next_line:
294
.next_line:
287
        call    parse_line
295
        call    parse_line
Line 290... Line 298...
290
        ret     1*8
298
        ret     1*8
Line 291... Line 299...
291
 
299
 
292
read_options_from_config:
300
read_options_from_config:
293
        mov     rbx, [efi_table]
301
        mov     rbx, [efi_table]
294
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
302
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
295
        eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [efi_handle], lipuuid, \
303
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], lip_guid, \
296
                lip_interface
304
                lip_interface
297
        test    eax, eax
305
        test    eax, eax
298
        jz      @f
306
        jz      @f
299
        push    rbx
307
        push    rbx
300
        mov     rbx, [efi_table]
308
        mov     rbx, [efi_table]
301
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
309
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
302
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
310
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
303
                msg_error_efi_lip_handle
311
                msg_error_efi_lip_handle
304
        pop     rbx
312
        pop     rbx
305
        jmp     $
313
        jmp     $
306
@@:
314
@@:
307
        mov     rax, [lip_interface]
-
 
308
 
315
        mov     r10, [lip_interface]
309
        mov     rbx, [efi_table]
316
        mov     rbx, [efi_table]
310
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
317
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
311
        eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, \
318
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], \
312
                [rax+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfspguid, \
319
                [r10+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
313
                sfsp_interface
320
                sfsp_interface
314
        test    eax, eax
321
        test    eax, eax
315
        jz      @f
322
        jz      @f
316
        push    rbx
323
        push    rbx
317
        mov     rbx, [efi_table]
324
        mov     rbx, [efi_table]
318
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
325
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
319
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
326
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
320
                msg_error_lip_dev_sfsp
327
                msg_error_lip_dev_sfsp
321
        pop     rbx
328
        pop     rbx
322
        jmp     $
329
        jmp     $
-
 
330
@@:
323
@@:
331
        mov     r10, [sfsp_interface]
324
        eficall [sfsp_interface], EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume, \
332
        fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
325
                [sfsp_interface], esp_root
333
                [sfsp_interface], esp_root
326
        test    eax, eax
334
        test    eax, eax
327
        jz      @f
335
        jz      @f
328
        push    rbx
336
        push    rbx
329
        mov     rbx, [efi_table]
337
        mov     rbx, [efi_table]
330
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
338
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
331
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
339
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
332
                msg_error_sfsp_openvolume
340
                msg_error_sfsp_openvolume
333
        pop     rbx
341
        pop     rbx
334
        jmp     $
342
        jmp     $
335
@@:
343
@@:
Line 369... Line 377...
369
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
377
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
370
        mov     rdi, msg+24*2
378
        mov     rdi, msg+24*2
371
        call    num2dec
379
        call    num2dec
372
        mov     rbx, [efi_table]
380
        mov     rbx, [efi_table]
373
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
381
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
374
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
382
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
375
        pop     rdi rsi rdx rcx rbx rax
383
        pop     rdi rsi rdx rcx rbx rax
376
        ret
384
        ret
Line 377... Line 385...
377
 
385
 
378
find_vmode_index_by_resolution:
386
find_vmode_index_by_resolution:
379
        mov     [cfg_opt_used_resolution], 1
387
        mov     [cfg_opt_used_resolution], 1
380
        mov     [cfg_opt_value_vmode], 0
388
        mov     [cfg_opt_value_vmode], 0
381
.next_mode:
389
.next_mode:
-
 
390
        movzx   edx, [cfg_opt_value_vmode]
382
        movzx   eax, [cfg_opt_value_vmode]
391
        mov     r10, [gop_interface]
383
        eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
392
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
384
                [gop_interface], rax, gop_info_size, gop_info
393
                rdx, gop_info_size, gop_info
385
        cmp     rax, EFI_SUCCESS
394
        cmp     rax, EFI_SUCCESS
386
        jnz     .error
395
        jnz     .error
387
        mov     rcx, [gop_info]
396
        mov     rcx, [gop_info]
388
        call    print_vmode
397
        call    print_vmode
Line 407... Line 416...
407
        mov     [cfg_opt_used_resolution], 0
416
        mov     [cfg_opt_used_resolution], 0
408
        mov     [cfg_opt_value_ask_params], 1
417
        mov     [cfg_opt_value_ask_params], 1
Line 409... Line 418...
409
 
418
 
410
        mov     rbx, [efi_table]
419
        mov     rbx, [efi_table]
411
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
420
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
412
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
421
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
413
                msg_error_no_such_vmode
422
                msg_error_no_such_vmode
414
        mov     rbx, [efi_table]
423
        mov     rbx, [efi_table]
415
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
424
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
416
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
425
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
417
                msg_error
426
                msg_error
418
        jmp     $
427
        jmp     $
419
.error:
428
.error:
420
.done:
429
.done:
Line 421... Line 430...
421
        ret
430
        ret
422
 
431
 
423
ask_for_params:
-
 
424
        ret
-
 
425
        mov     rbx, [efi_table]
-
 
426
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
-
 
427
        eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [rax], gopuuid, \
-
 
Line 428... Line 432...
428
                msg_ask_for_params
432
ask_for_params:
429
        jmp     $
433
        ret
430
 
434
 
431
        xor     ebx, ebx
435
        xor     ebx, ebx
432
.next_mode:
436
.next_mode:
433
        call    clearbuf
437
        call    clearbuf
Line 434... Line 438...
434
        mov     eax, ebx
438
        mov     eax, ebx
-
 
439
        lea     rdi, [msg]
435
        lea     rdi, [msg]
440
        call    num2dec
436
        call    num2dec
441
 
437
 
442
        push    rbx
438
        push    rbx
443
        mov     r10, [gop_interface]
439
        eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
444
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
440
                [gop_interface], rbx, gop_info_size, gop_info
445
                rbx, gop_info_size, gop_info
441
        cmp     rax, EFI_SUCCESS
446
        cmp     rax, EFI_SUCCESS
Line 454... Line 459...
454
;        lea     rdi, [msg+14*2]
459
;        lea     rdi, [msg+14*2]
455
;        call    num2dec
460
;        call    num2dec
456
.skip:
461
.skip:
457
        mov     rbx, [efi_table]
462
        mov     rbx, [efi_table]
458
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
463
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
459
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
464
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
460
        cmp     rax, EFI_SUCCESS
465
        cmp     rax, EFI_SUCCESS
461
        jnz     .error
466
        jnz     .error
Line 462... Line 467...
462
 
467
 
463
        pop     rbx
468
        pop     rbx
Line 468... Line 473...
468
        jnz     .next_mode
473
        jnz     .next_mode
Line 469... Line 474...
469
 
474
 
470
 
475
 
471
        mov     rbx, [efi_table]
476
        mov     rbx, [efi_table]
472
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
477
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
473
        eficall rbx, SIMPLE_INPUT_INTERFACE.Reset, rbx, 1
478
        fstcall [rbx+SIMPLE_INPUT_INTERFACE.Reset], rbx, 1
474
        cmp     rax, EFI_SUCCESS
479
        cmp     rax, EFI_SUCCESS
475
        jnz     .error
480
        jnz     .error
476
        xor     ecx, ecx
481
        xor     ecx, ecx
477
    @@:
482
    @@:
478
        push    rcx
483
        push    rcx
479
        mov     rbx, [efi_table]
484
        mov     rbx, [efi_table]
480
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
485
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
481
        eficall rbx, SIMPLE_INPUT_INTERFACE.ReadKeyStroke, rbx, msg
486
        fstcall [rbx+SIMPLE_INPUT_INTERFACE.ReadKeyStroke], rbx, msg
482
        pop     rcx
487
        pop     rcx
483
        mov     rdx, EFI_DEVICE_ERROR
488
        mov     rdx, EFI_DEVICE_ERROR
484
        cmp     rax, rdx
489
        cmp     rax, rdx
Line 499... Line 504...
499
        mov     [cfg_opt_value_vmode], cl
504
        mov     [cfg_opt_value_vmode], cl
500
.error:
505
.error:
501
.done:
506
.done:
502
        ret
507
        ret
Line -... Line 508...
-
 
508
 
-
 
509
detect_pci_config:
-
 
510
        fstcall get_protocol_interface, pcirbiop_guid
-
 
511
        mov     [pcirbiop_interface], rax
-
 
512
        mov     r10, rax
-
 
513
        fstcall [r10+EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.Configuration], r10, \
-
 
514
                pcirbiop_resources
-
 
515
;        fstcall dump_pci_resources
-
 
516
        fstcall get_last_pci_bus
-
 
517
        call    clearbuf
-
 
518
        movzx   eax, [pci_last_bus]
-
 
519
        mov     rdi, msg
-
 
520
        call    num2hex
-
 
521
        push    rbx
-
 
522
        mov     rbx, [efi_table]
-
 
523
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
524
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
525
                msg_pci_last_bus
-
 
526
        pop     rbx
-
 
527
        push    rbx
-
 
528
        mov     rbx, [efi_table]
-
 
529
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
530
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
531
        pop     rbx
-
 
532
        ret
-
 
533
 
-
 
534
proc get_last_pci_bus
-
 
535
        mov     rsi, [pcirbiop_resources]
-
 
536
.next_resource:
-
 
537
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type], \
-
 
538
                EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
-
 
539
        jz      .not_found
-
 
540
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
-
 
541
        cmp     [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType], \
-
 
542
                EFI_RESOURCE_TYPE.BUS
-
 
543
        jz      .found
-
 
544
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
-
 
545
        lea     rsi, [rsi+rax+3]
503
 
546
        jmp     .next_resource
-
 
547
.found:
-
 
548
        mov     [pci_last_bus], al
-
 
549
.not_found:
-
 
550
        ret
-
 
551
endp
-
 
552
 
504
main:
553
proc main _efi_handle, _efi_table
505
        mov     [efi_handle], rcx
554
        mov     [efi_handle], rcx
Line 506... Line 555...
506
        mov     [efi_table], rdx
555
        mov     [efi_table], rdx
507
 
556
 
508
        mov     rbx, [efi_table]
557
        mov     rbx, [efi_table]
509
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
558
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
510
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset, rbx, 1
559
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rbx, 1
511
        test    eax, eax
560
        test    eax, eax
512
        jz      @f
561
        jz      @f
513
        jmp     $       ; what can I do here?
562
        jmp     $       ; what can I do here?
514
@@:
563
@@:
515
        mov     rbx, [efi_table]
564
        mov     rbx, [efi_table]
516
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
565
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 517... Line 566...
517
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
566
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
518
                msg_u4k_loaded
567
                msg_u4k_loaded
519
 
568
 
-
 
569
        mov     rbx, [efi_table]
-
 
570
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
571
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
572
                msg_detect_pci_config
-
 
573
 
-
 
574
        call    detect_pci_config
-
 
575
 
520
        mov     rbx, [efi_table]
576
        mov     rbx, [efi_table]
521
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
577
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 522... Line 578...
522
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
578
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
523
                msg_read_options
579
                msg_read_options
524
        call    read_options_from_config
580
        call    read_options_from_config
525
 
581
 
526
        ; read kernel file
582
        ; read kernel file
527
        mov     rbx, [efi_table]
583
        mov     rbx, [efi_table]
528
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
584
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
529
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
585
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
530
                msg_load_kernel
586
                msg_load_kernel
Line 538... Line 594...
538
        call    load_file
594
        call    load_file
Line 539... Line 595...
539
 
595
 
540
        ; read ramdisk image
596
        ; read ramdisk image
541
        mov     rbx, [efi_table]
597
        mov     rbx, [efi_table]
542
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
598
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
543
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
599
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
544
                msg_load_ramdisk
600
                msg_load_ramdisk
545
        push    1       ; fatal
601
        push    1       ; fatal
546
        push    MAX_FILE_SIZE
602
        push    MAX_FILE_SIZE
547
        push    RAMDISK_BASE
603
        push    RAMDISK_BASE
Line 552... Line 608...
552
        call    load_file
608
        call    load_file
Line 553... Line 609...
553
 
609
 
554
        ; alloc buffer for devices.dat
610
        ; alloc buffer for devices.dat
555
        mov     rbx, [efi_table]
611
        mov     rbx, [efi_table]
556
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
612
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
557
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
613
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
558
                msg_alloc_devicesdat
614
                msg_alloc_devicesdat
559
        mov     rbx, [efi_table]
615
        mov     rbx, [efi_table]
560
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
616
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
561
        eficall rbx, EFI_BOOT_SERVICES.AllocatePages, \
617
        fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], \
562
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
618
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
563
                devicesdat_data
619
                devicesdat_data
564
        cmp     eax, EFI_SUCCESS
620
        cmp     eax, EFI_SUCCESS
Line 565... Line 621...
565
        jnz     .error
621
        jnz     .error
566
 
622
 
567
        ; read devices.dat
623
        ; read devices.dat
568
        mov     rbx, [efi_table]
624
        mov     rbx, [efi_table]
569
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
625
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 570... Line 626...
570
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
626
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
571
                msg_load_devicesdat
627
                msg_load_devicesdat
572
 
628
 
Line 580... Line 636...
580
        call    load_file
636
        call    load_file
581
        mov     [devicesdat_size], rax
637
        mov     [devicesdat_size], rax
Line 582... Line 638...
582
 
638
 
583
        mov     rbx, [efi_table]
639
        mov     rbx, [efi_table]
584
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
640
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
585
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
641
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
Line 586... Line -...
586
                msg_locate_gop_handlers
-
 
587
 
-
 
588
        mov     rbx, [efi_table]
-
 
589
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
-
 
590
        eficall rbx, EFI_BOOT_SERVICES.LocateHandle, \
642
                msg_locate_gop_interface
591
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, gopuuid, 0, \
-
 
592
                gop_buffer_size, gop_buffer
-
 
593
        mov     [status], rax
-
 
594
 
-
 
595
        mov     rbx, [efi_table]
-
 
596
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
597
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
-
 
598
                msg_gop_buffer_size
-
 
599
        call    clearbuf
-
 
600
        mov     rax, [gop_buffer_size]
-
 
601
        mov     rdi, msg
-
 
602
        call    num2hex
-
 
603
        mov     rbx, [efi_table]
-
 
604
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
605
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
-
 
606
 
-
 
607
        mov     rax, [status]
-
 
608
        test    eax, eax
-
 
609
        jz      @f
-
 
610
        call    clearbuf
-
 
611
        mov     rdi, msg
-
 
612
        call    num2hex
-
 
613
        mov     rbx, [efi_table]
-
 
614
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
615
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
-
 
616
                msg_error
-
 
617
        mov     rbx, [efi_table]
-
 
618
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
619
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
-
 
620
        jmp     $
-
 
621
@@:
-
 
622
 
-
 
623
        mov     rbx, [efi_table]
-
 
624
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
625
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
-
 
626
                msg_look_for_gop_handler
-
 
627
 
-
 
628
        mov     rbx, gop_buffer
-
 
629
.next_gop_handle:
-
 
630
        mov     rax, rbx
-
 
631
        mov     rcx, gop_buffer
-
 
632
        sub     rax, rcx
-
 
633
        cmp     rax, [gop_buffer_size]
-
 
634
        jb      @f
-
 
635
        push    rbx
-
 
636
        mov     rbx, [efi_table]
-
 
637
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
638
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
-
 
639
                msg_error_out_of_handlers
-
 
640
        pop     rbx
-
 
641
        push    rbx
-
 
642
        mov     rbx, [efi_table]
-
 
643
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
644
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg_error
-
 
645
        pop     rbx
-
 
646
        jmp     $
-
 
647
@@:
-
 
648
        push    rbx
-
 
649
        mov     rbx, [efi_table]
-
 
650
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
651
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
-
 
652
                msg_query_handler
-
 
653
        pop     rbx
-
 
654
 
-
 
655
        mov     rax, rbx
-
 
656
        push    rbx
-
 
657
        mov     rbx, [efi_table]
-
 
658
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
643
 
659
        eficall rbx, EFI_BOOT_SERVICES.HandleProtocol, [rax], gopuuid, \
-
 
660
                gop_interface
-
 
661
        pop     rbx
-
 
662
;mov rax, 0x8000_0000_0000_0003
-
 
663
        test    eax, eax
-
 
664
        jz      @f
-
 
665
        call    clearbuf
-
 
666
        mov     rdi, msg
-
 
667
        call    num2hex
-
 
668
        push    rbx
-
 
669
        mov     rbx, [efi_table]
-
 
670
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
671
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
-
 
672
        pop     rbx
-
 
673
 
-
 
674
        add     rbx, 8
-
 
Line 675... Line 644...
675
        jmp     .next_gop_handle
644
        fstcall get_protocol_interface, gop_guid
Line 676... Line 645...
676
@@:
645
        mov     [gop_interface], rax
677
 
646
 
678
        call    find_rsdp
647
        call    find_rsdp
679
 
648
 
Line 680... Line 649...
680
        mov     rbx, [efi_table]
649
        mov     rbx, [efi_table]
681
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
650
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
682
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
651
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
683
                msg_acpi_tables_done
652
                msg_acpi_tables_done
684
 
653
 
685
        cmp     [cfg_opt_used_resolution], 0
654
        cmp     [cfg_opt_used_resolution], 0
686
        jz      .not_used_resolution
655
        jz      .not_used_resolution
687
        mov     rbx, [efi_table]
656
        mov     rbx, [efi_table]
688
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
657
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
689
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
658
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
Line 697... Line 666...
697
        movzx   eax, [rdx+BOOT_LO.y_res]
666
        movzx   eax, [rdx+BOOT_LO.y_res]
698
        mov     rdi, msg+8*2
667
        mov     rdi, msg+8*2
699
        call    num2dec
668
        call    num2dec
700
        mov     rbx, [efi_table]
669
        mov     rbx, [efi_table]
701
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
670
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
702
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
671
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
703
        call    find_vmode_index_by_resolution
672
        call    find_vmode_index_by_resolution
704
.not_used_resolution:
673
.not_used_resolution:
705
        cmp     [cfg_opt_used_debug_print], 0
674
        cmp     [cfg_opt_used_debug_print], 0
706
        jz      .not_used_debug_print
675
        jz      .not_used_debug_print
707
        movzx   eax, [cfg_opt_value_debug_print]
676
        movzx   eax, [cfg_opt_value_debug_print]
Line 712... Line 681...
712
        cmp     [cfg_opt_value_ask_params], 0
681
        cmp     [cfg_opt_value_ask_params], 0
713
        jz      @f
682
        jz      @f
714
        call    ask_for_params
683
        call    ask_for_params
715
@@:
684
@@:
Line 716... Line 685...
716
 
685
 
717
        movzx   ecx, [cfg_opt_value_vmode]
686
        movzx   edx, [cfg_opt_value_vmode]
718
        eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode, \
687
        mov     r10, [gop_interface]
719
                [gop_interface], rcx
688
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode], [gop_interface], rdx
720
        test    eax, eax
689
        test    eax, eax
721
        jz      @f
690
        jz      @f
722
        call    clearbuf
691
        call    clearbuf
723
        mov     rdi, msg
692
        mov     rdi, msg
724
        call    num2hex
693
        call    num2hex
725
        mov     rbx, [efi_table]
694
        mov     rbx, [efi_table]
726
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
695
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
727
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
696
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
728
        mov     rbx, [efi_table]
697
        mov     rbx, [efi_table]
729
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
698
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
730
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
699
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
731
                msg_error
700
                msg_error
732
        jmp     $
701
        jmp     $
Line 733... Line 702...
733
@@:
702
@@:
734
 
703
 
735
        mov     rcx, [gop_interface]
704
        mov     rcx, [gop_interface]
736
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
705
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
Line 737... Line 706...
737
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
706
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
-
 
707
        mov     [fb_base], rdi
738
        mov     [fb_base], rdi
708
 
739
 
709
        mov     ebx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
740
        mov     ebx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
710
        mov     rax, [gop_interface]
741
        eficall [gop_interface], EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode, \
711
        fstcall [rax+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
742
                [gop_interface], rbx, gop_info_size, gop_info
712
                rbx, gop_info_size, gop_info
743
        test    eax, eax
713
        test    eax, eax
744
        jz      @f
714
        jz      @f
Line 752... Line 722...
752
        mov     [rdx+BOOT_LO.y_res], ax
722
        mov     [rdx+BOOT_LO.y_res], ax
753
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
723
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
754
        shl     eax, 2
724
        shl     eax, 2
755
        mov     [rdx+BOOT_LO.pitch], ax
725
        mov     [rdx+BOOT_LO.pitch], ax
Line 756... Line 726...
756
 
726
 
757
        mov     byte[rdx+BOOT_LO.pci_data+0], 1    ; PCI access mechanism
727
        mov     [rdx+BOOT_LO.pci_data.access_mechanism], 1
758
        mov     byte[rdx+BOOT_LO.pci_data+1], 8    ; last bus, don't know how to count them
728
        movzx   eax, [pci_last_bus]
759
        mov     byte[rdx+BOOT_LO.pci_data+2], 0x10 ; PCI version
729
        mov     [rdx+BOOT_LO.pci_data.last_bus], al
760
        mov     byte[rdx+BOOT_LO.pci_data+3], 0x02
730
        mov     [rdx+BOOT_LO.pci_data.version], 0x0300  ; PCI 3.0
Line 761... Line 731...
761
        mov     dword[rdx+BOOT_LO.pci_data+4], 0xe3
731
        mov     [rdx+BOOT_LO.pci_data.pm_entry], 0
762
 
732
 
763
        ; kernel
733
        ; kernel
Line 764... Line 734...
764
;        eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
734
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
765
;                450000/0x1000, EFI_ALLOCATE_ADDRESS
735
;                450000/0x1000, EFI_ALLOCATE_ADDRESS
766
 
736
 
Line 767... Line 737...
767
        ; ramdisk
737
        ; ramdisk
768
;        eficall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
738
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
Line 769... Line 739...
769
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
739
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
770
 
740
 
771
        call    calc_memmap
741
        call    calc_memmap
772
;        call    dump_memmap
742
;        fstcall dump_memmap
773
 
743
 
Line 774... Line 744...
774
        mov     rbx, [efi_table]
744
        mov     rbx, [efi_table]
Line 841... Line 811...
841
        retf
811
        retf
Line 842... Line 812...
842
 
812
 
843
.error:
813
.error:
844
        mov     rbx, [efi_table]
814
        mov     rbx, [efi_table]
845
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
815
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
846
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
816
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
847
                msg_error
817
                msg_error
848
        jmp     $
818
        jmp     $
Line 849... Line 819...
849
 
819
endp
850
 
820
 
851
halt_on_error:
821
halt_on_error:
852
        test    eax, eax
822
        test    eax, eax
853
        jz      @f
823
        jz      @f
854
        call    clearbuf
824
        call    clearbuf
855
        mov     rdi, msg
825
        mov     rdi, msg
856
        call    num2hex
826
        call    num2hex
857
        mov     rbx, [efi_table]
827
        mov     rbx, [efi_table]
858
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
828
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
859
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
829
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
860
                msg_error
830
                msg_error
861
        mov     rbx, [efi_table]
831
        mov     rbx, [efi_table]
862
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
832
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
863
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
833
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
864
        jmp     $
834
        jmp     $
Line -... Line 835...
-
 
835
@@:
-
 
836
        ret
-
 
837
 
-
 
838
proc get_protocol_interface uses rbx, _guid
-
 
839
        mov     [_guid], rcx
-
 
840
        mov     [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
-
 
841
        mov     rbx, [efi_table]
-
 
842
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
-
 
843
        fstcall [rbx+EFI_BOOT_SERVICES.LocateHandle], \
-
 
844
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
-
 
845
                prot_handlers_buffer_size, prot_handlers_buffer
-
 
846
        mov     [status], rax
-
 
847
 
-
 
848
        mov     rbx, [efi_table]
-
 
849
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
850
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
851
                msg_protocol_buffer_size
-
 
852
        call    clearbuf
-
 
853
        mov     rax, [prot_handlers_buffer_size]
-
 
854
        mov     rdi, msg
-
 
855
        call    num2hex
-
 
856
        mov     rbx, [efi_table]
-
 
857
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
858
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
859
 
-
 
860
        mov     rax, [status]
-
 
861
        test    eax, eax
-
 
862
        jz      @f
-
 
863
        call    clearbuf
-
 
864
        mov     rdi, msg
-
 
865
        call    num2hex
-
 
866
        mov     rbx, [efi_table]
-
 
867
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
868
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
869
                msg_error
-
 
870
        mov     rbx, [efi_table]
-
 
871
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
872
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
873
        jmp     $
-
 
874
@@:
-
 
875
 
-
 
876
        mov     rbx, [efi_table]
-
 
877
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
878
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
879
                msg_look_for_handler
-
 
880
 
-
 
881
        mov     rbx, prot_handlers_buffer
-
 
882
.try_next_handle:
-
 
883
        mov     rax, rbx
-
 
884
        mov     rcx, prot_handlers_buffer
-
 
885
        sub     rax, rcx
-
 
886
        cmp     rax, [prot_handlers_buffer_size]
-
 
887
        jb      @f
-
 
888
        push    rbx
-
 
889
        mov     rbx, [efi_table]
-
 
890
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
891
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
892
                msg_error_out_of_handlers
-
 
893
        pop     rbx
-
 
894
        push    rbx
-
 
895
        mov     rbx, [efi_table]
-
 
896
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
897
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
898
                msg_error
-
 
899
        pop     rbx
-
 
900
        jmp     $
-
 
901
@@:
-
 
902
        push    rbx
-
 
903
        mov     rbx, [efi_table]
-
 
904
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
905
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
906
                msg_query_handler
-
 
907
        pop     rbx
-
 
908
 
-
 
909
        mov     r10, rbx
-
 
910
        push    rbx
-
 
911
        mov     rbx, [efi_table]
-
 
912
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
-
 
913
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], qword[r10], [_guid], \
-
 
914
                prot_interface
-
 
915
        pop     rbx
-
 
916
;mov rax, 0x8000_0000_0000_0003
-
 
917
        test    eax, eax
-
 
918
        jz      @f
-
 
919
        call    clearbuf
-
 
920
        mov     rdi, msg
-
 
921
        call    num2hex
-
 
922
        push    rbx
-
 
923
        mov     rbx, [efi_table]
-
 
924
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
925
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
926
        pop     rbx
-
 
927
 
-
 
928
        add     rbx, 8
-
 
929
        jmp     .try_next_handle
-
 
930
@@:
-
 
931
        mov     rax, [prot_interface]
-
 
932
        ret
865
@@:
933
endp
866
        ret
934
 
867
 
935
 
868
find_rsdp:
936
find_rsdp:
869
        push    rbx
937
        push    rbx
870
        mov     rbx, [efi_table]
938
        mov     rbx, [efi_table]
871
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
939
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 872... Line 940...
872
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
940
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
873
                msg_look_for_rsdp
941
                msg_look_for_rsdp
Line 893... Line 961...
893
        add     rdi, 24
961
        add     rdi, 24
894
        jmp     .next_table
962
        jmp     .next_table
895
.all_tables_done:
963
.all_tables_done:
896
        ret
964
        ret
Line -... Line 965...
-
 
965
 
-
 
966
proc dump_pci_resources
-
 
967
        xor     eax, eax
-
 
968
        mov     rsi, [pcirbiop_resources]
-
 
969
        push    rbx
-
 
970
        mov     rbx, [efi_table]
-
 
971
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
972
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
973
                msg_dump_pci_resources
-
 
974
        pop     rbx
-
 
975
.next_resource:
-
 
976
        call    clearbuf
-
 
977
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
-
 
978
        cmp     eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
-
 
979
        jz      .done
-
 
980
        mov     rdi, msg
-
 
981
        call    num2hex
-
 
982
        push    rbx
-
 
983
        mov     rbx, [efi_table]
-
 
984
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
985
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
986
        pop     rbx
-
 
987
        call    clearbuf
-
 
988
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
-
 
989
        mov     rdi, msg
-
 
990
        call    num2dec
-
 
991
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMinimum]
-
 
992
        mov     rdi, msg+2*2
-
 
993
        call    num2hex
-
 
994
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.RangeMaximum]
-
 
995
        mov     rdi, msg+19*2
-
 
996
        call    num2hex
-
 
997
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.TranslationOffset]
-
 
998
        mov     rdi, msg+36*2
-
 
999
        call    num2hex
-
 
1000
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
-
 
1001
        mov     rdi, msg+53*2
-
 
1002
        call    num2hex
-
 
1003
        push    rbx
-
 
1004
        mov     rbx, [efi_table]
-
 
1005
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
1006
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
1007
        pop     rbx
-
 
1008
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
-
 
1009
        add     eax, 3
-
 
1010
        add     rsi, rax
-
 
1011
        jmp     .next_resource
-
 
1012
.done:
-
 
1013
        ret
-
 
1014
endp
897
 
1015
 
898
calc_memmap:
1016
calc_memmap:
899
        mov     rbx, [efi_table]
1017
        mov     rbx, [efi_table]
900
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
1018
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
901
        eficall rbx, EFI_BOOT_SERVICES.AllocatePages, EFI_ALLOCATE_ANY_PAGES, \
1019
        fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
902
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
1020
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
Line 903... Line 1021...
903
        call    halt_on_error
1021
        call    halt_on_error
904
 
1022
 
905
        mov     rbx, [efi_table]
1023
        mov     rbx, [efi_table]
906
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
1024
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
907
        eficall rbx, EFI_BOOT_SERVICES.GetMemoryMap, memory_map_size, \
1025
        fstcall [rbx+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
Line 908... Line 1026...
908
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
1026
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
909
        call    halt_on_error
1027
        call    halt_on_error
Line 918... Line 1036...
918
        add     rsi, [descriptor_size]
1036
        add     rsi, [descriptor_size]
919
        cmp     rsi, rbx
1037
        cmp     rsi, rbx
920
        jb      .next_descr
1038
        jb      .next_descr
921
        ret
1039
        ret
Line 922... Line 1040...
922
 
1040
 
923
dump_memmap:
1041
proc dump_memmap
924
        xor     eax, eax
1042
        xor     eax, eax
925
        mov     rsi, BOOT_LO.memmap_blocks
1043
        mov     rsi, BOOT_LO.memmap_blocks
Line 926... Line 1044...
926
        mov     ebx, [rax+BOOT_LO.memmap_block_cnt]
1044
        mov     ebx, [rax+BOOT_LO.memmap_block_cnt]
Line 930... Line 1048...
930
        mov     rdi, msg
1048
        mov     rdi, msg
931
        call    num2dec
1049
        call    num2dec
932
        push    rbx
1050
        push    rbx
933
        mov     rbx, [efi_table]
1051
        mov     rbx, [efi_table]
934
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1052
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
935
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, \
1053
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
936
                msg_memmap
1054
                msg_memmap
937
        pop     rbx
1055
        pop     rbx
938
        push    rbx
1056
        push    rbx
939
        mov     rbx, [efi_table]
1057
        mov     rbx, [efi_table]
940
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1058
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
941
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
1059
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
942
        pop     rbx
1060
        pop     rbx
943
        call    clearbuf
1061
        call    clearbuf
944
.next_mapping:
1062
.next_mapping:
945
        dec     ebx
1063
        dec     ebx
946
        js      .done
1064
        js      .done
Line 959... Line 1077...
959
        mov     rdi, msg+24*2
1077
        mov     rdi, msg+24*2
960
        call    num2hex
1078
        call    num2hex
961
        push    rbx
1079
        push    rbx
962
        mov     rbx, [efi_table]
1080
        mov     rbx, [efi_table]
963
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1081
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
964
        eficall rbx, EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString, rbx, msg
1082
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
965
        pop     rbx
1083
        pop     rbx
966
        add     rsi, sizeof.e820entry
1084
        add     rsi, sizeof.e820entry
967
        jmp     .next_mapping
1085
        jmp     .next_mapping
968
.done:
1086
.done:
969
        ret
1087
        ret
970
 
1088
endp
Line 971... Line 1089...
971
 
1089
 
972
; linux/arch/x86/platform/efi/efi.c
1090
; linux/arch/x86/platform/efi/efi.c
973
; do_add_efi_memmap
1091
; do_add_efi_memmap
974
add_uefi_memmap:
1092
add_uefi_memmap:
Line 1106... Line 1224...
1106
        dw 0FFFFh,0,9A00h,0AFh          ; 64-bit code
1224
        dw 0FFFFh,0,9A00h,0AFh          ; 64-bit code
1107
assert $ < BOOT_LO
1225
assert $ < BOOT_LO
1108
kernel_trampoline.size = $ - KERNEL_TRAMPOLINE
1226
kernel_trampoline.size = $ - KERNEL_TRAMPOLINE
Line 1109... Line 1227...
1109
 
1227
 
1110
section '.rodata' data readable
1228
section '.rodata' data readable
1111
gopuuid         db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
1229
gop_guid        db EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
1112
lipuuid         db EFI_LOADED_IMAGE_PROTOCOL_GUID
1230
lip_guid        db EFI_LOADED_IMAGE_PROTOCOL_GUID
-
 
1231
sfsp_guid       db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
Line 1113... Line 1232...
1113
sfspguid        db EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID
1232
pcirbiop_guid   db EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GUID
1114
 
1233
 
1115
file_name       du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
1234
file_name       du '\EFI\KOLIBRIOS\KOLIBRI.INI',0
1116
kernel_name     du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
1235
kernel_name     du '\EFI\KOLIBRIOS\KOLIBRI.KRN',0
Line 1155... Line 1274...
1155
                               " params",0
1274
                               " params",0
1156
cfg_opt_cmnt_imgfrom        db "# Where to load ramdisk image from",0
1275
cfg_opt_cmnt_imgfrom        db "# Where to load ramdisk image from",0
1157
cfg_opt_cmnt_syspath        db "# Path to /sys directory",0
1276
cfg_opt_cmnt_syspath        db "# Path to /sys directory",0
Line 1158... Line 1277...
1158
 
1277
 
-
 
1278
msg_u4k_loaded            du "uefi64kos loaded",13,10,0
-
 
1279
msg_detect_pci_config     du "Detect PCI configuration",13,10,0
-
 
1280
msg_dump_pci_resources    du "Dump PCI resources",13,10,0
1159
msg_u4k_loaded            du "uefi64kos loaded",13,10,0
1281
msg_pci_last_bus          du "Last PCI bus",13,10,0
1160
msg_read_options          du "Read options from config file",13,10,0
1282
msg_read_options          du "Read options from config file",13,10,0
1161
msg_file_size             du "File size:",13,10,0
1283
msg_file_size             du "File size:",13,10,0
1162
msg_parsing_config        du "Parsing config file",13,10,0
1284
msg_parsing_config        du "Parsing config file",13,10,0
1163
msg_load_kernel           du "Load kernel",13,10,0
1285
msg_load_kernel           du "Load kernel",13,10,0
1164
msg_load_ramdisk          du "Load ramdisk",13,10,0
1286
msg_load_ramdisk          du "Load ramdisk",13,10,0
1165
msg_load_devicesdat       du "Load DEVICES.DAT",13,10,0
1287
msg_load_devicesdat       du "Load DEVICES.DAT",13,10,0
1166
msg_alloc_devicesdat      du "Allocate memory for DEVICES.DAT",13,10,0
1288
msg_alloc_devicesdat      du "Allocate memory for DEVICES.DAT",13,10,0
1167
msg_locate_gop_handlers   du "Locate GOP handlers",13,10,0
1289
msg_locate_gop_interface  du "Locate GOP interface",13,10,0
1168
msg_look_for_gop_handler  du "Look for GOP handler",13,10,0
1290
msg_look_for_handler      du "Look for protocol handler",13,10,0
1169
msg_query_handler         du "Query handler",13,10,0
1291
msg_query_handler         du "Query handler",13,10,0
1170
msg_query_vmode           du "Query vmode",13,10,0
1292
msg_query_vmode           du "Query vmode",13,10,0
1171
msg_vmode_found           du "Video mode found",13,10,0
1293
msg_vmode_found           du "Video mode found",13,10,0
1172
msg_look_for_rsdp         du "Look for RSDP",13,10,0
1294
msg_look_for_rsdp         du "Look for RSDP",13,10,0
1173
msg_rsdp_found            du "RSDP found",13,10,0
1295
msg_rsdp_found            du "RSDP found",13,10,0
1174
msg_acpi_tables_done      du "ACPI tables done",13,10,0
1296
msg_acpi_tables_done      du "ACPI tables done",13,10,0
1175
msg_ask_for_params        du "Ask for params",13,10,0
1297
msg_ask_for_params        du "Ask for params",13,10,0
1176
msg_set_graphic_mode      du "Set graphic mode",13,10,0
1298
msg_set_graphic_mode      du "Set graphic mode",13,10,0
1177
msg_success               du "Success!",13,10,0
1299
msg_success               du "Success!",13,10,0
1178
msg_gop_buffer_size       du "GOP buffer size",13,10,0
1300
msg_protocol_buffer_size  du "Protocol buffer size",13,10,0
1179
msg_opt_resolution        du "Option resolution: ",0
1301
msg_opt_resolution        du "Option resolution: ",0
1180
msg_memmap                du "Memmap",13,10,0
1302
msg_memmap                du "Memmap",13,10,0
1181
msg_error                 du "Error!",13,10,0
1303
msg_error                 du "Error!",13,10,0
1182
msg_error_efi_lip_handle  du "efi_handle can't handle LIP",13,10,0
1304
msg_error_efi_lip_handle  du "efi_handle can't handle LIP",13,10,0
Line 1186... Line 1308...
1186
msg_error_out_of_handlers du "Out of handlers",13,10,0
1308
msg_error_out_of_handlers du "Out of handlers",13,10,0
1187
msg_error_open_file       du "Error: can't open file ",0
1309
msg_error_open_file       du "Error: can't open file ",0
1188
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1310
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1189
msg                       du 79 dup " ",13,10,0
1311
msg                       du 79 dup " ",13,10,0
Line 1190... Line -...
1190
 
-
 
1191
 
1312
 
1192
section '.data' data readable writeable
1313
section '.data' data readable writeable
1193
efi_handle  dq 0
1314
efi_handle  dq 0
1194
efi_table   dq 0
1315
efi_table   dq 0
Line 1195... Line 1316...
1195
uefi_rsptmp dq 0
1316
;uefi_rsptmp dq 0
Line 1196... Line 1317...
1196
 
1317
 
1197
fb_base         dq 0
1318
fb_base         dq 0
1198
 
1319
 
1199
gop_buffer_size dq GOP_BUFFER_SIZE
1320
prot_handlers_buffer_size dq ?
1200
gop_handle      dq 0
1321
prot_interface  dq ?
Line 1201... Line -...
1201
gop_interface   dq 0
-
 
1202
gop_info_size   dq 0
-
 
1203
gop_info        dq 0
1322
gop_interface   dq 0
Line 1204... Line 1323...
1204
 
1323
gop_info_size   dq 0
Line 1205... Line 1324...
1205
lip_buffer_size dq LIP_BUFFER_SIZE
1324
gop_info        dq 0
1206
lip_handle      dq 0
1325
 
1207
lip_interface   dq 0
1326
lip_interface   dq 0
Line -... Line 1327...
-
 
1327
 
-
 
1328
sfsp_interface  dq 0
-
 
1329
 
-
 
1330
esp_root        dq ?
1208
 
1331
file_handle     dq ?
1209
sfsp_interface  dq 0
1332
file_buffer_size dq FILE_BUFFER_SIZE-1  ; leave the last byte for \0
1210
 
1333
 
1211
esp_root        dq ?
1334
pcirbiop_interface dq ?
1212
file_handle     dq ?
1335
pcirbiop_resources dq ?
Line 1239... Line 1362...
1239
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1362
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1240
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
1363
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
1241
efi_fs_info EFI_FILE_SYSTEM_INFO
1364
efi_fs_info EFI_FILE_SYSTEM_INFO
Line 1242... Line 1365...
1242
 
1365
 
-
 
1366
memory_map      dq ?
1243
memory_map      dq ?
1367
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
-
 
1368
;gop_buffer      rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1244
gop_buffer      rq GOP_BUFFER_SIZE/8
1369
pcirbio_buffer  rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1245
devicesdat_data dq 0xffffffff
1370
devicesdat_data dq 0xffffffff
1246
devicesdat_size dq 0x1000
1371
devicesdat_size dq 0x1000
Line 1247... Line 1372...
1247
status          dq ?
1372
status          dq ?