Subversion Repositories Kolibri OS

Rev

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

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