Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@oweisse
Copy link
Owner

@oweisse oweisse commented Jul 23, 2019

  • Installing EFI configuration tables for ACPI20 and SMBIOS
  • Allocating EFI image code at executable 1:1 mapped constant address

Ofir Weisse added 26 commits July 1, 2019 10:28
Currently only supports extremely simple apps like HelloWorld.efi

* kexec.h - Added KEXEC_RUN_PE flag to be passed to kexec_load. This is the
* kexec.c
        - Implemented kimage_load_pe, kimage_run_pe
        - Implemented EFI hooks to generate fake EFI system table and
        fake EFI boot services.
        - Implemented naive EFI AllocatePool, FreePool
        - Implemented EFI conout to enable OutputString
EFI Boot Services:
    efi_hook_HandleProtocol:
        - prints out the protocol GUID and name
        - implemented gEfiLoadedImageProtocolGuid
        - implemented gEfiDevicePathProtocolGuid

EFI Protocols:
    gEfiLoadedImageProtocolGuid:
        - Respond with a fixed EFI_LOADED_IMAGE_PROTOCOL containing a fixd boot-device and fixed LoadOptions

    gEfiLoadedImageProtocolGuid:
        - Acceplts only BOOT_DEVICE_HANDLE, replies with a fixed windows_boot_device_path
windows_loaded_image needs to be patched during kimage_load_pe
* efi_setup_11_mapping: creates 1:1 mapping
* efi_hook_AllocatePool: now calls efi_setup_11_mapping and returns
                         "physical" address, thanks to the 1:1 mapping
* efi_hook_FreePool: Removed call to kfree, which is incompatible with
                     our new 1:1 mapping
* efi_register_mem_allocation: register new memory allocation
* efi_unregister_allocation: reclaim memory and make it EfiConventionalMemory
* efi_hook_GetMemoryMap: get current memory mappings

The current bookkepping is naive and incorrect.
TODO:
1. When allocating memory, we should seearch if blocks of
   EfiConventionalMemory are available for allocation.
2. When registerring memory, we might need to split a block of
   EfiConventionalMemory
3. When unregistering memory, we need to potentially coalsce blocks of
   EfiConventionalMemory.
This os a preparation for smarter management of mem maps.
Windows loader sets up interrupts 0x3, 0x2C, 0x2D to empty interrupt
handlers. A good fix in the future would be to make the page temporarily.
Also refactored CHAR16 to char conversion function
…them.

Implemented the following functions:

* efi_hook_LocateHandle: implemented only for gEfiBlockIoProtocolGuid. Returning 4
                         devices: raw-hard-drive and partitions 1,2,3.

* efi_handle_protocol_DevicePath: implemented for the 4 devices mentioned above

* efi_handle_protocol_BlockIO: Returns the proper EFI_BLOCK_IO_PROTOCOL, depending
                               on the handle provided. Implemented Read/write
                               callbacks whcih print log msg to screen and return
                               an erro code.

* efi_hook_CloseProtocol: empty implementation (log and return success)
see efi_block_io_read_blocks
This ensures Windows loader can access these addresses
This is crucial to support Windows loader replacing CR3 with its own
page table
This is required to allow  Winload.efi to access the system table.

* Allocate memory in a 1:1 mapped area
* Print the memory map after every memory allocation.
This is important so that the system table and other structures can be
accessible when Windows loader (either bootmg or Winload.efi) try to
access them via a Windows page table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants