Subversion Repositories Kolibri OS

Rev

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

Rev 9227 Rev 9253
Line 42... Line 42...
42
E820_ACPI      = 3
42
E820_ACPI      = 3
43
E820_NVS       = 4
43
E820_NVS       = 4
44
E820_UNUSABLE  = 5
44
E820_UNUSABLE  = 5
45
E820_PMEM      = 7
45
E820_PMEM      = 7
Line 46... Line 46...
46
 
46
 
47
load_file:
47
proc load_file _root, _name, _buffer, _size, _fatal
48
virtual at rsp+8
48
locals
49
  .root   dq ?
49
        .status dq ?
50
  .name   dq ?
50
endl
51
  .buffer dq ?
51
        mov     [_root], rcx
52
  .size   dq ?
52
        mov     [_name], rdx
53
  .fatal  dq ?
53
        mov     [_buffer], r8
54
end virtual
54
        mov     [_size], r9
55
        mov     r10, [.root]
55
        mov     r10, [_root]
56
        mov     r11, [.name]
56
        mov     r11, [_name]
57
        fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
57
        fstcall [r10+EFI_FILE_PROTOCOL.Open], r10, file_handle, \
58
                r11, EFI_FILE_MODE_READ, 0
58
                r11, EFI_FILE_MODE_READ, 0
59
        test    eax, eax
59
        test    eax, eax
60
        jz      @f
60
        jz      @f
61
        xor     eax, eax
61
        xor     eax, eax
62
        cmp     [.fatal], 1
62
        cmp     [_fatal], 1
63
        jnz     .done
-
 
64
        mov     rbx, [efi_table]
63
        jnz     .done
65
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
64
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
66
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
65
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
67
                msg_error_open_file
-
 
68
        mov     rbx, [efi_table]
66
                msg_error_open_file
69
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
67
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
70
        mov     r10, [.name]
68
        mov     rdx, [_name]
71
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, r10
69
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, [_name]
72
        jmp     $
70
        jmp     $
Line 73... Line 71...
73
@@:
71
@@:
74
 
72
 
75
        lea     rdx, [.size]
73
        lea     rdx, [_size]
76
        mov     r8, [.buffer]
74
        mov     r8, [_buffer]
77
        mov     r10, [file_handle]
75
        mov     r10, [file_handle]
78
        fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
76
        fstcall [r10+EFI_FILE_PROTOCOL.Read], [file_handle], rdx, r8
79
        mov     r10, [file_handle]
77
        mov     r10, [file_handle]
80
        fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
78
        fstcall [r10+EFI_FILE_PROTOCOL.Close], [file_handle]
81
        mov     rax, [.size]
79
        mov     rax, [_size]
82
.done:
80
.done:
83
        push    rax
81
        mov     [.status], rax
84
        call    clearbuf
82
        call    clearbuf
85
        mov     rdi, msg
-
 
86
        call    num2dec
-
 
87
        push    rbx
83
        mov     rdi, msg
88
        mov     rbx, [efi_table]
84
        call    num2dec
89
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
85
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
90
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
91
                msg_file_size
-
 
92
        pop     rbx
-
 
93
        push    rbx
86
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
94
        mov     rbx, [efi_table]
87
                msg_file_size
95
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
88
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
96
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
89
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
97
        pop     rbx
90
        mov     rax, [.status]
Line 98... Line 91...
98
        pop     rax
91
        ret
99
        ret     8*5
92
endp
100
 
93
 
101
skip_whitespace:
94
skip_whitespace:
Line 277... Line 270...
277
        jmp     .next_char
270
        jmp     .next_char
278
.done:
271
.done:
279
        mov     byte[rdi], 0
272
        mov     byte[rdi], 0
280
        ret
273
        ret
Line 281... Line -...
281
 
-
 
282
parse_config:
-
 
283
virtual at rsp+8
-
 
284
  .buffer      dq ?
-
 
285
end virtual
274
 
286
;        mov     rsi, [.buffer]
275
proc parse_config uses rbx rsi rdi, _buffer
287
        push    rbx
-
 
288
        mov     rbx, [efi_table]
276
        mov     rsi, rcx
289
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
277
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
290
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
278
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
291
                msg_parsing_config
-
 
292
        pop     rbx
-
 
293
        mov     rsi, KERNEL_BASE
279
                msg_parsing_config
294
.next_line:
280
.next_line:
295
        call    parse_line
281
        call    parse_line
296
        cmp     byte[rsi], 0
282
        cmp     byte[rsi], 0
297
        jnz     .next_line
283
        jnz     .next_line
-
 
284
        ret
Line 298... Line 285...
298
        ret     1*8
285
endp
299
 
-
 
300
read_options_from_config:
286
 
301
        mov     rbx, [efi_table]
287
proc read_options_from_config
302
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
288
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
303
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], lip_guid, \
289
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], [efi_handle], \
304
                lip_interface
290
                lip_guid, lip_interface
305
        test    eax, eax
-
 
306
        jz      @f
-
 
307
        push    rbx
291
        test    eax, eax
308
        mov     rbx, [efi_table]
292
        jz      @f
309
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
293
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
310
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
311
                msg_error_efi_lip_handle
294
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
312
        pop     rbx
295
                msg_error_efi_lip_handle
313
        jmp     $
296
        jmp     $
314
@@:
-
 
315
        mov     r10, [lip_interface]
297
@@:
316
        mov     rbx, [efi_table]
298
        mov     r11, [lip_interface]
317
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
299
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
318
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], \
300
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], \
319
                [r10+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
301
                [r11+EFI_LOADED_IMAGE_PROTOCOL.DeviceHandle], sfsp_guid, \
320
                sfsp_interface
302
                sfsp_interface
321
        test    eax, eax
-
 
322
        jz      @f
-
 
323
        push    rbx
303
        test    eax, eax
324
        mov     rbx, [efi_table]
304
        jz      @f
325
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
305
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
326
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
327
                msg_error_lip_dev_sfsp
306
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
328
        pop     rbx
307
                msg_error_lip_dev_sfsp
329
        jmp     $
308
        jmp     $
330
@@:
309
@@:
331
        mov     r10, [sfsp_interface]
310
        mov     r10, [sfsp_interface]
332
        fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
311
        fstcall [r10+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume], \
333
                [sfsp_interface], esp_root
312
                [sfsp_interface], esp_root
334
        test    eax, eax
-
 
335
        jz      @f
-
 
336
        push    rbx
313
        test    eax, eax
337
        mov     rbx, [efi_table]
314
        jz      @f
338
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
315
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
339
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
340
                msg_error_sfsp_openvolume
316
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
341
        pop     rbx
317
                msg_error_sfsp_openvolume
342
        jmp     $
318
        jmp     $
343
@@:
319
@@:
344
        push    0 ; not fatal, i.e. it's ok to not find this file
-
 
345
        push    FILE_BUFFER_SIZE
-
 
346
        push    KERNEL_BASE
-
 
347
;        push    file_name
-
 
348
        mov     rax, file_name
-
 
349
        push    rax
-
 
Line 350... Line 320...
350
        push    [esp_root]
320
        fstcall load_file, [esp_root], file_name, KERNEL_BASE, \
351
        call    load_file
321
                FILE_BUFFER_SIZE, 0     ; not fatal
352
 
-
 
353
        test    eax, eax
322
 
354
        jz      @f
323
        test    eax, eax
Line 355... Line 324...
355
        push    KERNEL_BASE
324
        jz      @f
356
        call    parse_config
325
        fstcall parse_config, KERNEL_BASE
-
 
326
@@:
Line 357... Line -...
357
@@:
-
 
358
 
327
 
359
.error:
328
.error:
360
        ret
329
        ret
361
 
330
endp
362
print_vmode:
331
 
363
        push    rax rbx rcx rdx rsi rdi
332
proc print_vmode uses rax rbx rcx rdx rsi rdi
364
        mov     rbx, rcx
333
        mov     r10, rcx
365
        call    clearbuf
334
        call    clearbuf
366
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
335
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
Line 367... Line 336...
367
        mov     rdi, msg
336
        mov     rdi, msg
368
        call    num2dec
337
        call    num2dec
369
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
338
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
Line 370... Line 339...
370
        mov     rdi, msg+8*2
339
        mov     rdi, msg+8*2
371
        call    num2dec
340
        call    num2dec
372
 
341
 
373
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat]
-
 
374
        mov     rdi, msg+16*2
342
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat]
375
        call    num2dec
343
        mov     rdi, msg+16*2
376
 
-
 
377
        mov     eax, [rbx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
344
        call    num2dec
-
 
345
 
Line 378... Line 346...
378
        mov     rdi, msg+24*2
346
        mov     eax, [r10+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
379
        call    num2dec
347
        mov     rdi, msg+24*2
380
        mov     rbx, [efi_table]
348
        call    num2dec
381
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
349
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
382
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
350
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
383
        pop     rdi rsi rdx rcx rbx rax
351
        ret
384
        ret
352
endp
385
 
353
 
386
find_vmode_index_by_resolution:
354
proc find_vmode_index_by_resolution
387
        mov     [cfg_opt_used_resolution], 1
355
        mov     [cfg_opt_used_resolution], 1
388
        mov     [cfg_opt_value_vmode], 0
356
        mov     [cfg_opt_value_vmode], 0
389
.next_mode:
357
.next_mode:
390
        movzx   edx, [cfg_opt_value_vmode]
358
        movzx   edx, [cfg_opt_value_vmode]
391
        mov     r10, [gop_interface]
359
        mov     r10, [gop_interface]
392
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
360
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
393
                rdx, gop_info_size, gop_info
361
                rdx, gop_info_size, gop_info
394
        cmp     rax, EFI_SUCCESS
362
        cmp     rax, EFI_SUCCESS
Line 414... Line 382...
414
        cmp     eax, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
382
        cmp     eax, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
415
        jnz     .next_mode
383
        jnz     .next_mode
416
        mov     [cfg_opt_used_resolution], 0
384
        mov     [cfg_opt_used_resolution], 0
417
        mov     [cfg_opt_value_ask_params], 1
385
        mov     [cfg_opt_value_ask_params], 1
Line 418... Line -...
418
 
-
 
419
        mov     rbx, [efi_table]
386
 
420
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
387
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
421
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
388
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
422
                msg_error_no_such_vmode
-
 
423
        mov     rbx, [efi_table]
389
                msg_error_no_such_vmode
424
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
390
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
425
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
391
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
426
                msg_error
392
                msg_error
427
        jmp     $
393
        jmp     $
428
.error:
394
.error:
429
.done:
395
.done:
-
 
396
        ret
Line 430... Line 397...
430
        ret
397
endp
431
 
-
 
432
ask_for_params:
-
 
433
        ret
-
 
434
 
-
 
435
        xor     ebx, ebx
-
 
436
.next_mode:
-
 
437
        call    clearbuf
-
 
438
        mov     eax, ebx
-
 
439
        lea     rdi, [msg]
-
 
440
        call    num2dec
-
 
441
 
-
 
442
        push    rbx
-
 
443
        mov     r10, [gop_interface]
-
 
444
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
-
 
445
                rbx, gop_info_size, gop_info
-
 
446
        cmp     rax, EFI_SUCCESS
-
 
447
        jnz     .error
-
 
448
        mov     rcx, [gop_info]
-
 
449
        ; PixelBlueGreenRedReserved8BitPerColor
-
 
450
        cmp     [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelFormat], 1
-
 
451
        jnz     .skip
-
 
452
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.HorizontalResolution]
-
 
453
        lea     rdi, [msg+4*2]
-
 
454
        call    num2dec
-
 
455
        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.VerticalResolution]
-
 
456
        lea     rdi, [msg+9*2]
-
 
457
        call    num2dec
-
 
458
;        mov     eax, [rcx+EFI_GRAPHICS_OUTPUT_MODE_INFORMATION.PixelsPerScanLine]
-
 
459
;        lea     rdi, [msg+14*2]
-
 
460
;        call    num2dec
-
 
461
.skip:
-
 
462
        mov     rbx, [efi_table]
-
 
463
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
464
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
465
        cmp     rax, EFI_SUCCESS
-
 
466
        jnz     .error
-
 
467
 
-
 
468
        pop     rbx
-
 
469
        inc     rbx
-
 
470
        mov     rcx, [gop_interface]
-
 
471
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
-
 
472
        cmp     ebx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode]
-
 
473
        jnz     .next_mode
-
 
474
 
-
 
475
 
-
 
476
        mov     rbx, [efi_table]
-
 
477
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
-
 
478
        fstcall [rbx+SIMPLE_INPUT_INTERFACE.Reset], rbx, 1
-
 
479
        cmp     rax, EFI_SUCCESS
-
 
480
        jnz     .error
-
 
481
        xor     ecx, ecx
-
 
482
    @@:
-
 
483
        push    rcx
-
 
484
        mov     rbx, [efi_table]
-
 
485
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConIn]
-
 
486
        fstcall [rbx+SIMPLE_INPUT_INTERFACE.ReadKeyStroke], rbx, msg
-
 
487
        pop     rcx
-
 
488
        mov     rdx, EFI_DEVICE_ERROR
-
 
489
        cmp     rax, rdx
-
 
490
        jz      .error
-
 
491
        mov     rdx, EFI_NOT_READY
-
 
492
        cmp     rax, rdx
-
 
493
        jz      @b
-
 
494
;        cmp     rax, EFI_SUCCESS
-
 
495
        movzx   eax, word[msg+2]
-
 
496
;jmp .key_done
-
 
497
        cmp     al, 0x0D
-
 
498
        jz      .key_done
-
 
499
        imul    ecx, 10
-
 
500
        sub     eax, '0'
398
 
501
        add     ecx, eax
-
 
502
        jmp     @b
-
 
503
.key_done:
-
 
504
        mov     [cfg_opt_value_vmode], cl
-
 
505
.error:
-
 
Line 506... Line 399...
506
.done:
399
ask_for_params:
507
        ret
400
        jmp     $
508
 
401
 
509
detect_pci_config:
402
proc detect_pci_config
510
        fstcall get_protocol_interface, pcirbiop_guid
403
        fstcall get_protocol_interface, pcirbiop_guid
511
        mov     [pcirbiop_interface], rax
404
        mov     [pcirbiop_interface], rax
Line 516... Line 409...
516
        fstcall get_last_pci_bus
409
        fstcall get_last_pci_bus
517
        call    clearbuf
410
        call    clearbuf
518
        movzx   eax, [pci_last_bus]
411
        movzx   eax, [pci_last_bus]
519
        mov     rdi, msg
412
        mov     rdi, msg
520
        call    num2hex
413
        call    num2hex
521
        push    rbx
-
 
522
        mov     rbx, [efi_table]
-
 
523
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
414
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
524
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
415
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
525
                msg_pci_last_bus
416
                msg_pci_last_bus
526
        pop     rbx
-
 
527
        push    rbx
-
 
528
        mov     rbx, [efi_table]
-
 
529
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
417
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
530
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
418
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
531
        pop     rbx
-
 
532
        ret
419
        ret
-
 
420
endp
Line 533... Line 421...
533
 
421
 
534
proc get_last_pci_bus
422
proc get_last_pci_bus
535
        mov     rsi, [pcirbiop_resources]
423
        mov     rsi, [pcirbiop_resources]
536
.next_resource:
424
.next_resource:
Line 551... Line 439...
551
endp
439
endp
Line 552... Line 440...
552
 
440
 
553
proc main _efi_handle, _efi_table
441
proc main _efi_handle, _efi_table
554
        mov     [efi_handle], rcx
442
        mov     [efi_handle], rcx
-
 
443
        mov     [efi_table], rdx
Line 555... Line -...
555
        mov     [efi_table], rdx
-
 
556
 
444
        mov     rbx, rdx
557
        mov     rbx, [efi_table]
445
 
558
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
446
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
559
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rbx, 1
-
 
560
        test    eax, eax
447
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset], rcx, 1
561
        jz      @f
-
 
562
        jmp     $       ; what can I do here?
-
 
563
@@:
448
        test    eax, eax
564
        mov     rbx, [efi_table]
449
        jnz     $       ; what can I do here?
565
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
450
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 566... Line -...
566
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
567
                msg_u4k_loaded
451
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
568
 
452
                msg_u4k_loaded
569
        mov     rbx, [efi_table]
453
 
-
 
454
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 570... Line -...
570
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
571
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
572
                msg_detect_pci_config
-
 
573
 
455
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
574
        call    detect_pci_config
456
                msg_detect_pci_config
575
 
457
        fstcall detect_pci_config
576
        mov     rbx, [efi_table]
458
 
Line 577... Line 459...
577
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
459
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
578
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
579
                msg_read_options
460
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
580
        call    read_options_from_config
461
                msg_read_options
581
 
462
        fstcall read_options_from_config
582
        ; read kernel file
463
 
583
        mov     rbx, [efi_table]
464
        ; read kernel file
584
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
585
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
586
                msg_load_kernel
-
 
587
        push    1       ; fatal
-
 
588
        push    MAX_FILE_SIZE
-
 
589
        push    KERNEL_BASE
-
 
Line 590... Line 465...
590
;        push    kernel_name
465
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
591
        mov     rax, kernel_name
-
 
592
        push    rax
466
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
593
        push    [esp_root]
467
                msg_load_kernel
594
        call    load_file
468
        fstcall load_file, [esp_root], kernel_name, KERNEL_BASE, \
595
 
469
                MAX_FILE_SIZE, 1 ; fatal
596
        ; read ramdisk image
470
 
597
        mov     rbx, [efi_table]
-
 
598
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
599
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
600
                msg_load_ramdisk
-
 
601
        push    1       ; fatal
-
 
602
        push    MAX_FILE_SIZE
-
 
Line 603... Line 471...
603
        push    RAMDISK_BASE
471
        ; read ramdisk image
604
;        push    ramdisk_name
-
 
605
        mov     rax, ramdisk_name
472
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
606
        push    rax
473
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
607
        push    [esp_root]
474
                msg_load_ramdisk
608
        call    load_file
-
 
609
 
475
        fstcall load_file, [esp_root], ramdisk_name, RAMDISK_BASE, \
610
        ; alloc buffer for devices.dat
476
                MAX_FILE_SIZE, 1 ; fatal
611
        mov     rbx, [efi_table]
477
 
612
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
478
        ; alloc buffer for devices.dat
613
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
479
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
614
                msg_alloc_devicesdat
480
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
Line 615... Line 481...
615
        mov     rbx, [efi_table]
481
                msg_alloc_devicesdat
616
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
-
 
617
        fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], \
482
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
618
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
483
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], \
619
                devicesdat_data
484
                EFI_ALLOCATE_MAX_ADDRESS, EFI_RESERVED_MEMORY_TYPE, 1, \
Line 620... Line -...
620
        cmp     eax, EFI_SUCCESS
-
 
621
        jnz     .error
485
                devicesdat_data
622
 
486
        cmp     eax, EFI_SUCCESS
623
        ; read devices.dat
-
 
624
        mov     rbx, [efi_table]
-
 
625
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
626
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
627
                msg_load_devicesdat
-
 
628
 
487
        jnz     .error
Line 629... Line -...
629
        push    0 ; not fatal
-
 
630
        push    [devicesdat_size]
488
 
631
        push    [devicesdat_data]
489
        ; read devices.dat
632
;        push    devicesdat_name
490
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
Line 633... Line 491...
633
        mov     rax, devicesdat_name
491
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
634
        push    rax
492
                msg_load_devicesdat
Line 635... Line 493...
635
        push    [esp_root]
493
 
Line 636... Line -...
636
        call    load_file
-
 
637
        mov     [devicesdat_size], rax
494
        fstcall load_file, [esp_root], devicesdat_name, [devicesdat_data], \
638
 
495
                [devicesdat_size], 0    ; not fatal
639
        mov     rbx, [efi_table]
496
        mov     [devicesdat_size], rax
Line 640... Line 497...
640
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
497
 
641
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
498
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
642
                msg_locate_gop_interface
-
 
643
 
499
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
644
        fstcall get_protocol_interface, gop_guid
500
                msg_locate_gop_interface
645
        mov     [gop_interface], rax
501
 
646
 
502
        fstcall get_protocol_interface, gop_guid
647
        call    find_rsdp
503
        mov     [gop_interface], rax
648
 
504
 
649
        mov     rbx, [efi_table]
505
        fstcall find_rsdp
650
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
506
 
651
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
507
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
652
                msg_acpi_tables_done
508
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
653
 
509
                msg_acpi_tables_done
654
        cmp     [cfg_opt_used_resolution], 0
510
 
655
        jz      .not_used_resolution
-
 
656
        mov     rbx, [efi_table]
511
        cmp     [cfg_opt_used_resolution], 0
657
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
512
        jz      .not_used_resolution
658
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
513
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
659
                msg_opt_resolution
514
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
660
        call    clearbuf
515
                msg_opt_resolution
661
        xor     edx, edx
516
        call    clearbuf
662
        movzx   eax, [rdx+BOOT_LO.x_res]
517
        xor     edx, edx
663
        mov     rdi, msg
518
        movzx   eax, [rdx+BOOT_LO.x_res]
Line 689... Line 544...
689
        test    eax, eax
544
        test    eax, eax
690
        jz      @f
545
        jz      @f
691
        call    clearbuf
546
        call    clearbuf
692
        mov     rdi, msg
547
        mov     rdi, msg
693
        call    num2hex
548
        call    num2hex
694
        mov     rbx, [efi_table]
-
 
695
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
549
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
696
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
550
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
697
        mov     rbx, [efi_table]
-
 
698
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
551
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
699
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
552
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
700
                msg_error
553
                msg_error
701
        jmp     $
554
        jmp     $
702
@@:
555
@@:
Line 703... Line 556...
703
 
556
 
704
        mov     rcx, [gop_interface]
557
        mov     rcx, [gop_interface]
705
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
558
        mov     rdx, [rcx+EFI_GRAPHICS_OUTPUT_PROTOCOL.Mode]
706
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
559
        mov     rdi, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.FrameBufferBase]
Line 707... Line 560...
707
        mov     [fb_base], rdi
560
        mov     [fb_base], rdi
708
 
561
 
709
        mov     ebx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
562
        mov     edx, [rdx+EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode]
710
        mov     rax, [gop_interface]
563
        mov     r10, [gop_interface]
711
        fstcall [rax+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
564
        fstcall [r10+EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode], [gop_interface], \
712
                rbx, gop_info_size, gop_info
565
                rdx, gop_info_size, gop_info
713
        test    eax, eax
566
        test    eax, eax
714
        jz      @f
567
        jz      @f
715
        jmp     .error
568
        jmp     .error
Line 736... Line 589...
736
 
589
 
737
        ; ramdisk
590
        ; ramdisk
738
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
591
;        fstcall BootServices, AllocatePages, EFI_RESERVED_MEMORY_TYPE, \
Line 739... Line 592...
739
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
592
;                2880*512/0x1000, EFI_ALLOCATE_ADDRESS
740
 
593
 
Line 741... Line -...
741
        call    calc_memmap
-
 
742
;        fstcall dump_memmap
594
        fstcall calc_memmap
743
 
595
;        fstcall dump_memmap
744
        mov     rbx, [efi_table]
596
 
745
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
597
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
Line 746... Line 598...
746
        fstcall [rbx+EFI_BOOT_SERVICES.ExitBootServices], [efi_handle], \
598
        fstcall [r10+EFI_BOOT_SERVICES.ExitBootServices], [efi_handle], \
Line 747... Line 599...
747
                [memory_map_key]
599
                [memory_map_key]
748
        call    halt_on_error
600
        fstcall halt_on_error
749
 
601
 
750
        cli
602
        cli
751
 
603
 
752
        xor     edx, edx
604
        xor     edx, edx
753
        xor     esi, esi
605
        xor     esi, esi
Line 754... Line 606...
754
        mov     [esi+BOOT_LO.bpp], 32
606
        mov     [rsi+BOOT_LO.bpp], 32
755
        mov     [esi+BOOT_LO.vesa_mode], dx
607
        mov     [rsi+BOOT_LO.vesa_mode], dx
Line 756... Line 608...
756
        mov     [esi+BOOT_LO.bank_switch], edx
608
        mov     [rsi+BOOT_LO.bank_switch], edx
757
        mov     rdi, [fb_base]
609
        mov     rdi, [fb_base]
Line 758... Line 610...
758
        mov     [esi+BOOT_LO.lfb], edi
610
        mov     [rsi+BOOT_LO.lfb], edi
759
 
611
 
Line 760... Line 612...
760
        movzx   eax, [cfg_opt_value_mtrr]
612
        movzx   eax, [cfg_opt_value_mtrr]
761
        mov     [esi+BOOT_LO.mtrr], al
-
 
762
 
613
        mov     [rsi+BOOT_LO.mtrr], al
763
        movzx   eax, [cfg_opt_value_launcher_start]
614
 
764
        mov     [esi+BOOT_LO.launcher_start], al
615
        movzx   eax, [cfg_opt_value_launcher_start]
765
 
616
        mov     [rsi+BOOT_LO.launcher_start], al
766
        movzx   eax, [cfg_opt_value_debug_print]
617
 
767
        mov     [esi+BOOT_LO.debug_print], al
618
        movzx   eax, [cfg_opt_value_debug_print]
768
 
619
        mov     [rsi+BOOT_LO.debug_print], al
Line 769... Line 620...
769
        mov     [esi+BOOT_LO.dma], dl
620
 
770
;        mov     qword[esi+BOOT_LO.pci_data], 0
621
        mov     [rsi+BOOT_LO.dma], dl
Line 771... Line 622...
771
        mov     [esi+BOOT_LO.apm_entry], edx
622
        mov     [rsi+BOOT_LO.apm_entry], edx
772
        mov     [esi+BOOT_LO.apm_version], dx
623
        mov     [rsi+BOOT_LO.apm_version], dx
773
        mov     [esi+BOOT_LO.apm_flags], dx
624
        mov     [rsi+BOOT_LO.apm_flags], dx
774
        mov     [esi+BOOT_LO.apm_code_32], dx
625
        mov     [rsi+BOOT_LO.apm_code_32], dx
Line 809... Line 660...
809
        mov     rax, KERNEL_TRAMPOLINE
660
        mov     rax, KERNEL_TRAMPOLINE
810
        push    rax
661
        push    rax
811
        retf
662
        retf
Line 812... Line 663...
812
 
663
 
813
.error:
-
 
814
        mov     rbx, [efi_table]
664
.error:
815
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
665
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
816
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
666
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
817
                msg_error
667
                msg_error
818
        jmp     $
668
        jmp     $
Line 819... Line 669...
819
endp
669
endp
820
 
670
 
821
halt_on_error:
671
proc halt_on_error
822
        test    eax, eax
672
        test    eax, eax
823
        jz      @f
673
        jz      @f
824
        call    clearbuf
674
        call    clearbuf
825
        mov     rdi, msg
-
 
826
        call    num2hex
675
        mov     rdi, msg
827
        mov     rbx, [efi_table]
676
        call    num2hex
828
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
677
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
829
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
-
 
830
                msg_error
678
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
831
        mov     rbx, [efi_table]
679
                msg_error
832
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
680
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
833
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
681
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
834
        jmp     $
682
        jmp     $
-
 
683
@@:
Line 835... Line 684...
835
@@:
684
        ret
-
 
685
endp
-
 
686
 
-
 
687
proc get_protocol_interface uses rsi rdi, _guid
836
        ret
688
locals
837
 
689
        .status dq ?
838
proc get_protocol_interface uses rbx, _guid
-
 
839
        mov     [_guid], rcx
690
endl
840
        mov     [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
691
        mov     [_guid], rcx
841
        mov     rbx, [efi_table]
692
        mov     [prot_handlers_buffer_size], PROTOCOL_HANDLERS_BUFFER_SIZE
842
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
693
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
843
        fstcall [rbx+EFI_BOOT_SERVICES.LocateHandle], \
694
        fstcall [r10+EFI_BOOT_SERVICES.LocateHandle], \
Line 844... Line -...
844
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
-
 
845
                prot_handlers_buffer_size, prot_handlers_buffer
695
                EFI_LOCATE_SEARCH_TYPE.ByProtocol, [_guid], 0, \
846
        mov     [status], rax
696
                prot_handlers_buffer_size, prot_handlers_buffer
847
 
697
        mov     [.status], rax
848
        mov     rbx, [efi_table]
698
 
849
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
699
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
850
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
700
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
851
                msg_protocol_buffer_size
701
                msg_protocol_buffer_size
852
        call    clearbuf
-
 
853
        mov     rax, [prot_handlers_buffer_size]
702
        call    clearbuf
854
        mov     rdi, msg
703
        mov     rax, [prot_handlers_buffer_size]
Line 855... Line 704...
855
        call    num2hex
704
        mov     rdi, msg
856
        mov     rbx, [efi_table]
705
        call    num2hex
857
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
706
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
858
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
707
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
859
 
708
 
860
        mov     rax, [status]
709
        mov     rax, [.status]
861
        test    eax, eax
-
 
862
        jz      @f
710
        test    eax, eax
863
        call    clearbuf
711
        jz      @f
864
        mov     rdi, msg
712
        call    clearbuf
865
        call    num2hex
-
 
866
        mov     rbx, [efi_table]
713
        mov     rdi, msg
867
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
714
        call    num2hex
868
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
715
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
869
                msg_error
716
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
Line 870... Line -...
870
        mov     rbx, [efi_table]
-
 
871
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
717
                msg_error
872
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
718
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
873
        jmp     $
719
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
Line 874... Line 720...
874
@@:
720
        jmp     $
875
 
721
@@:
876
        mov     rbx, [efi_table]
722
 
877
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
723
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
878
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
724
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
879
                msg_look_for_handler
725
                msg_look_for_handler
880
 
726
 
881
        mov     rbx, prot_handlers_buffer
-
 
882
.try_next_handle:
-
 
883
        mov     rax, rbx
727
        mov     rsi, prot_handlers_buffer
884
        mov     rcx, prot_handlers_buffer
728
.try_next_handle:
885
        sub     rax, rcx
729
        mov     rax, rsi
886
        cmp     rax, [prot_handlers_buffer_size]
-
 
887
        jb      @f
-
 
888
        push    rbx
-
 
889
        mov     rbx, [efi_table]
730
        mov     rcx, prot_handlers_buffer
890
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
731
        sub     rax, rcx
891
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
732
        cmp     rax, [prot_handlers_buffer_size]
892
                msg_error_out_of_handlers
-
 
893
        pop     rbx
733
        jb      @f
894
        push    rbx
734
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
895
        mov     rbx, [efi_table]
-
 
896
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
897
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
735
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
898
                msg_error
736
                msg_error_out_of_handlers
899
        pop     rbx
737
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
900
        jmp     $
-
 
Line 901... Line -...
901
@@:
-
 
902
        push    rbx
-
 
903
        mov     rbx, [efi_table]
-
 
904
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
738
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
905
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
739
                msg_error
906
                msg_query_handler
740
        jmp     $
907
        pop     rbx
-
 
908
 
741
@@:
909
        mov     r10, rbx
742
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
910
        push    rbx
743
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
911
        mov     rbx, [efi_table]
744
                msg_query_handler
912
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
745
 
913
        fstcall [rbx+EFI_BOOT_SERVICES.HandleProtocol], qword[r10], [_guid], \
746
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
914
                prot_interface
-
 
915
        pop     rbx
-
 
916
;mov rax, 0x8000_0000_0000_0003
747
        fstcall [r10+EFI_BOOT_SERVICES.HandleProtocol], qword[rsi], [_guid], \
917
        test    eax, eax
748
                prot_interface
918
        jz      @f
-
 
Line 919... Line 749...
919
        call    clearbuf
749
;mov rax, 0x8000_0000_0000_0003
920
        mov     rdi, msg
750
        test    eax, eax
921
        call    num2hex
751
        jz      @f
922
        push    rbx
752
        call    clearbuf
923
        mov     rbx, [efi_table]
753
        mov     rdi, msg
924
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
754
        call    num2hex
Line 925... Line -...
925
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
926
        pop     rbx
755
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
927
 
-
 
928
        add     rbx, 8
756
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
929
        jmp     .try_next_handle
757
 
930
@@:
758
        add     rsi, 8
931
        mov     rax, [prot_interface]
-
 
Line 932... Line -...
932
        ret
-
 
933
endp
759
        jmp     .try_next_handle
934
 
760
@@:
935
 
761
        mov     rax, [prot_interface]
936
find_rsdp:
762
        ret
937
        push    rbx
763
endp
Line 960... Line 786...
960
.not_acpi20:
786
.not_acpi20:
961
        add     rdi, 24
787
        add     rdi, 24
962
        jmp     .next_table
788
        jmp     .next_table
963
.all_tables_done:
789
.all_tables_done:
964
        ret
790
        ret
-
 
791
endp
Line 965... Line 792...
965
 
792
 
966
proc dump_pci_resources
793
proc dump_pci_resources uses rsi rdi
967
        xor     eax, eax
794
        xor     eax, eax
968
        mov     rsi, [pcirbiop_resources]
-
 
969
        push    rbx
-
 
970
        mov     rbx, [efi_table]
795
        mov     rsi, [pcirbiop_resources]
971
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
796
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
972
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
797
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
973
                msg_dump_pci_resources
-
 
974
        pop     rbx
798
                msg_dump_pci_resources
975
.next_resource:
799
.next_resource:
976
        call    clearbuf
800
        call    clearbuf
977
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
801
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Type]
978
        cmp     eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
802
        cmp     eax, EFI_RESOURCE_DESCRIPTOR_TYPE.END_TAG
979
        jz      .done
803
        jz      .done
980
        mov     rdi, msg
804
        mov     rdi, msg
981
        call    num2hex
-
 
982
        push    rbx
-
 
983
        mov     rbx, [efi_table]
805
        call    num2hex
984
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
806
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
985
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
-
 
986
        pop     rbx
807
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
987
        call    clearbuf
808
        call    clearbuf
988
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
809
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.ResourceType]
989
        mov     rdi, msg
810
        mov     rdi, msg
990
        call    num2dec
811
        call    num2dec
Line 998... Line 819...
998
        mov     rdi, msg+36*2
819
        mov     rdi, msg+36*2
999
        call    num2hex
820
        call    num2hex
1000
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
821
        mov     rax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.AddressLength]
1001
        mov     rdi, msg+53*2
822
        mov     rdi, msg+53*2
1002
        call    num2hex
823
        call    num2hex
1003
        push    rbx
-
 
1004
        mov     rbx, [efi_table]
-
 
1005
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
824
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1006
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
825
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
1007
        pop     rbx
-
 
1008
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
826
        movzx   eax, [rsi+EFI_QWORD_ADDRESS_SPACE_DESCRIPTOR.Length]
1009
        add     eax, 3
827
        add     eax, 3
1010
        add     rsi, rax
828
        add     rsi, rax
1011
        jmp     .next_resource
829
        jmp     .next_resource
1012
.done:
830
.done:
1013
        ret
831
        ret
1014
endp
832
endp
Line 1015... Line 833...
1015
 
833
 
1016
calc_memmap:
-
 
1017
        mov     rbx, [efi_table]
834
proc calc_memmap uses rsi rdi
1018
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
835
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
1019
        fstcall [rbx+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
836
        fstcall [r10+EFI_BOOT_SERVICES.AllocatePages], EFI_ALLOCATE_ANY_PAGES, \
1020
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
837
                EFI_RESERVED_MEMORY_TYPE, MEMORY_MAP_SIZE/0x1000, memory_map
Line 1021... Line -...
1021
        call    halt_on_error
-
 
1022
 
838
        call    halt_on_error
1023
        mov     rbx, [efi_table]
839
 
1024
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.BootServices]
840
        mov     r10, [rbx+EFI_SYSTEM_TABLE.BootServices]
1025
        fstcall [rbx+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
841
        fstcall [r10+EFI_BOOT_SERVICES.GetMemoryMap], memory_map_size, \
Line 1026... Line 842...
1026
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
842
                [memory_map], memory_map_key, descriptor_size, descriptor_ver
1027
        call    halt_on_error
843
        call    halt_on_error
1028
 
844
 
1029
        mov     rdi, BOOT_LO.memmap_blocks
845
        mov     rdi, BOOT_LO.memmap_blocks
1030
        mov     dword[rdi-4], 0 ; memmap_block_cnt
846
        mov     dword[rdi-4], 0 ; memmap_block_cnt
1031
        mov     rsi, [memory_map]
847
        mov     rsi, [memory_map]
1032
        mov     rbx, rsi
848
        mov     r10, rsi
1033
        add     rbx, [memory_map_size]
849
        add     r10, [memory_map_size]
1034
.next_descr:
850
.next_descr:
1035
        call    add_uefi_memmap
851
        fstcall add_uefi_memmap
1036
        add     rsi, [descriptor_size]
852
        add     rsi, [descriptor_size]
-
 
853
        cmp     rsi, r10
Line 1037... Line 854...
1037
        cmp     rsi, rbx
854
        jb      .next_descr
1038
        jb      .next_descr
855
        ret
1039
        ret
856
endp
1040
 
857
 
Line 1041... Line 858...
1041
proc dump_memmap
858
proc dump_memmap uses rsi rdi
1042
        xor     eax, eax
859
        xor     eax, eax
1043
        mov     rsi, BOOT_LO.memmap_blocks
860
        mov     rsi, BOOT_LO.memmap_blocks
1044
        mov     ebx, [rax+BOOT_LO.memmap_block_cnt]
861
        mov     r12, [rax+BOOT_LO.memmap_block_cnt]
1045
 
-
 
1046
        call    clearbuf
-
 
1047
        mov     eax, ebx
862
 
1048
        mov     rdi, msg
863
        call    clearbuf
1049
        call    num2dec
864
        mov     eax, ebx
1050
        push    rbx
-
 
1051
        mov     rbx, [efi_table]
-
 
1052
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
-
 
1053
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, \
865
        mov     rdi, msg
1054
                msg_memmap
866
        call    num2dec
1055
        pop     rbx
-
 
1056
        push    rbx
867
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1057
        mov     rbx, [efi_table]
868
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, \
1058
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
869
                msg_memmap
1059
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
870
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1060
        pop     rbx
871
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
1061
        call    clearbuf
872
        call    clearbuf
1062
.next_mapping:
873
.next_mapping:
1063
        dec     ebx
874
        dec     r12d
Line 1074... Line 885...
1074
        mov     rdi, msg+4*2
885
        mov     rdi, msg+4*2
1075
        call    num2hex
886
        call    num2hex
1076
        mov     rax, [rsi+e820entry.size]
887
        mov     rax, [rsi+e820entry.size]
1077
        mov     rdi, msg+24*2
888
        mov     rdi, msg+24*2
1078
        call    num2hex
889
        call    num2hex
1079
        push    rbx
-
 
1080
        mov     rbx, [efi_table]
-
 
1081
        mov     rbx, [rbx+EFI_SYSTEM_TABLE.ConOut]
890
        mov     rcx, [rbx+EFI_SYSTEM_TABLE.ConOut]
1082
        fstcall [rbx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rbx, msg
891
        fstcall [rcx+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString], rcx, msg
1083
        pop     rbx
-
 
1084
        add     rsi, sizeof.e820entry
892
        add     rsi, sizeof.e820entry
1085
        jmp     .next_mapping
893
        jmp     .next_mapping
1086
.done:
894
.done:
1087
        ret
895
        ret
1088
endp
896
endp
Line 1089... Line 897...
1089
 
897
 
1090
; linux/arch/x86/platform/efi/efi.c
898
; linux/arch/x86/platform/efi/efi.c
1091
; do_add_efi_memmap
899
; do_add_efi_memmap
1092
add_uefi_memmap:
900
proc add_uefi_memmap
1093
        xor     eax, eax
901
        xor     eax, eax
1094
        cmp     [rax+BOOT_LO.memmap_block_cnt], MAX_MEMMAP_BLOCKS
902
        cmp     [rax+BOOT_LO.memmap_block_cnt], MAX_MEMMAP_BLOCKS
Line 1095... Line 903...
1095
        jz      .done
903
        jz      .done
Line 1139... Line 947...
1139
        inc     [rax+BOOT_LO.memmap_block_cnt]
947
        inc     [rax+BOOT_LO.memmap_block_cnt]
1140
        add     rdi, sizeof.e820entry
948
        add     rdi, sizeof.e820entry
1141
@@:
949
@@:
1142
.done:
950
.done:
1143
        ret
951
        ret
1144
 
952
endp
Line 1145... Line 953...
1145
 
953
 
1146
num2dec:
954
num2dec:
Line 1147... Line 955...
1147
        push    rax rbx rcx rdx rsi rdi
955
        push    rbx rcx rdx rdi
1148
 
956
 
1149
        xor     ecx, ecx
957
        xor     ecx, ecx
1150
        mov     ebx, 10
958
        mov     ebx, 10
Line 1160... Line 968...
1160
        pop     rax
968
        pop     rax
1161
        add     eax, '0'
969
        add     eax, '0'
1162
        stosw
970
        stosw
1163
        loop    .next_char
971
        loop    .next_char
Line 1164... Line 972...
1164
 
972
 
1165
        pop     rdi rsi rdx rcx rbx rax
973
        pop     rdi rdx rcx rbx
Line 1166... Line 974...
1166
        ret
974
        ret
1167
 
975
 
Line 1168... Line 976...
1168
 
976
 
1169
num2hex:
977
num2hex:
1170
        push    rax rbx rcx rdx rsi rdi
978
        push    rbx rcx rdx rdi
1171
 
979
 
1172
        xchg    rdx, rax
980
        xchg    rdx, rax
1173
        mov     ecx, 16
981
        mov     ecx, 16
1174
.next_tetra:
982
.next_tetra:
1175
        rol     rdx, 4
983
        rol     rdx, 4
1176
        movzx   eax, dl
984
        movzx   eax, dl
Line 1177... Line 985...
1177
        and     eax, 0x0f
985
        and     eax, 0x0f
1178
        movzx   eax, byte[hex+eax]
986
        movzx   eax, byte[hex_abc+eax]
Line 1179... Line -...
1179
        stosw
-
 
1180
        loop    .next_tetra
-
 
1181
 
987
        stosw
1182
        pop     rdi rsi rdx rcx rbx rax
988
        loop    .next_tetra
1183
        ret
989
 
1184
 
990
        pop     rdi rdx rcx rbx
1185
hex db '0123456789ABCDEF'
991
        ret
1186
 
992
 
1187
clearbuf:
993
clearbuf:
1188
        push    rax rbx rcx rdx rsi rdi
994
        push    rcx rdi
Line 1189... Line 995...
1189
        mov     eax, 0x0020
995
        mov     eax, ' '
1190
        mov     ecx, 79
996
        mov     ecx, 79
1191
        mov     rdi, msg
997
        mov     rdi, msg
Line 1307... Line 1113...
1307
msg_error_no_such_vmode   du "No such vmode",13,10,0
1113
msg_error_no_such_vmode   du "No such vmode",13,10,0
1308
msg_error_out_of_handlers du "Out of handlers",13,10,0
1114
msg_error_out_of_handlers du "Out of handlers",13,10,0
1309
msg_error_open_file       du "Error: can't open file ",0
1115
msg_error_open_file       du "Error: can't open file ",0
1310
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1116
msg_error_exit_boot_services du "Error: Exit boot services",13,10,0
1311
msg                       du 79 dup " ",13,10,0
1117
msg                       du 79 dup " ",13,10,0
-
 
1118
msg_debug                 du "Debug ",13,10,0
Line 1312... Line 1119...
1312
 
1119
 
1313
section '.data' data readable writeable
1120
section '.data' data readable writeable
1314
efi_handle  dq 0
1121
efi_handle  dq 0
1315
efi_table   dq 0
-
 
Line 1316... Line 1122...
1316
;uefi_rsptmp dq 0
1122
efi_table   dq 0
Line 1317... Line -...
1317
 
-
 
1318
fb_base         dq 0
-
 
1319
 
1123
 
1320
prot_handlers_buffer_size dq ?
1124
fb_base         dq 0
1321
prot_interface  dq ?
1125
 
Line 1322... Line 1126...
1322
gop_interface   dq 0
1126
gop_interface   dq 0
Line 1323... Line 1127...
1323
gop_info_size   dq 0
1127
gop_info_size   dq 0
Line 1324... Line -...
1324
gop_info        dq 0
-
 
1325
 
-
 
1326
lip_interface   dq 0
-
 
1327
 
-
 
1328
sfsp_interface  dq 0
-
 
1329
 
-
 
1330
esp_root        dq ?
1128
gop_info        dq 0
Line 1331... Line 1129...
1331
file_handle     dq ?
1129
 
1332
file_buffer_size dq FILE_BUFFER_SIZE-1  ; leave the last byte for \0
1130
lip_interface   dq 0
1333
 
1131
 
Line 1359... Line 1157...
1359
descriptor_ver  dq 0
1157
descriptor_ver  dq 0
1360
memory_map_size dq MEMORY_MAP_SIZE
1158
memory_map_size dq MEMORY_MAP_SIZE
Line 1361... Line 1159...
1361
 
1159
 
1362
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1160
efi_fs_info_id db EFI_FILE_SYSTEM_INFO_ID
1363
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
-
 
Line -... Line 1161...
-
 
1161
efi_fs_info_size dq sizeof.EFI_FILE_SYSTEM_INFO
-
 
1162
 
-
 
1163
devicesdat_data dq 0xffffffff
-
 
1164
devicesdat_size dq 0x1000
-
 
1165
 
-
 
1166
hex_abc db '0123456789ABCDEF'
-
 
1167
 
-
 
1168
section '.bss' data readable writeable discardable
-
 
1169
prot_handlers_buffer_size dq ?
-
 
1170
prot_interface  dq ?
-
 
1171
esp_root        dq ?
-
 
1172
file_handle     dq ?
-
 
1173
pcirbiop_interface dq ?
1364
efi_fs_info EFI_FILE_SYSTEM_INFO
1174
pcirbiop_resources dq ?
1365
 
1175
efi_fs_info EFI_FILE_SYSTEM_INFO
1366
memory_map      dq ?
-
 
1367
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
1176
memory_map      dq ?
1368
;gop_buffer      rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
-
 
1369
pcirbio_buffer  rq PROTOCOL_HANDLERS_BUFFER_SIZE/8
-
 
1370
devicesdat_data dq 0xffffffff
-
 
Line 1371... Line 1177...
1371
devicesdat_size dq 0x1000
1177
prot_handlers_buffer rq PROTOCOL_HANDLERS_BUFFER_SIZE/8