Subversion Repositories Kolibri OS

Rev

Rev 9253 | Rev 9958 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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