dragon_stub-main.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <efi.h>
  2. #include <efilib.h>
  3. #include <dragonstub/printk.h>
  4. #include <dragonstub/dragonstub.h>
  5. void print_dragonstub_banner(void);
  6. static EFI_STATUS test_exit_bs(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab){
  7. EFI_STATUS status;
  8. struct efi_boot_memmap *map;
  9. status = efi_get_memory_map(&map, false);
  10. if (status != EFI_SUCCESS)
  11. return status;
  12. efi_debug("before priv_func\n");
  13. efi_debug("map->map_size: %d\n", map->map_size);
  14. efi_debug("before ExitBootServices, handle=%p, map_key=%p\n", image_handle,
  15. map->map_key);
  16. status = efi_bs_call(ExitBootServices, image_handle, map->map_key);
  17. efi_debug("after ExitBootServices, status: %d\n", status);
  18. while(1);
  19. }
  20. EFI_STATUS
  21. efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
  22. {
  23. EFI_STATUS status;
  24. EFI_LOADED_IMAGE *loaded_image = NULL;
  25. /* addr/point and size pairs for memory management*/
  26. char *cmdline_ptr = NULL;
  27. InitializeLib(image_handle, systab);
  28. print_dragonstub_banner();
  29. efi_info("EFI env initialized\n");
  30. /*
  31. * Get a handle to the loaded image protocol. This is used to get
  32. * information about the running image, such as size and the command
  33. * line.
  34. */
  35. status = uefi_call_wrapper(BS->OpenProtocol, 6, image_handle,
  36. &LoadedImageProtocol, (void **)&loaded_image,
  37. image_handle, NULL,
  38. EFI_OPEN_PROTOCOL_GET_PROTOCOL);
  39. if (EFI_ERROR(status)) {
  40. efi_err("Could not open loaded image protocol: %d\n", status);
  41. return status;
  42. }
  43. efi_info("Loaded image protocol opened\n");
  44. status = efi_handle_cmdline(loaded_image, &cmdline_ptr);
  45. if (EFI_ERROR(status)) {
  46. efi_err("Could not get command line: %d\n", status);
  47. return status;
  48. }
  49. if (cmdline_ptr == NULL)
  50. efi_warn("Command line is NULL\n");
  51. else
  52. efi_info("Command line: %s\n", cmdline_ptr);
  53. struct payload_info payload;
  54. status = find_payload(image_handle, loaded_image, &payload);
  55. if (EFI_ERROR(status)) {
  56. efi_err("Could not find payload, efi error code: %d\n", status);
  57. return status;
  58. }
  59. efi_info("Booting DragonOS kernel...\n");
  60. efi_stub_common(image_handle, loaded_image, &payload, cmdline_ptr);
  61. efi_todo("Boot DragonOS kernel");
  62. return EFI_SUCCESS;
  63. }
  64. /// @brief Print thr DragonStub banner
  65. void print_dragonstub_banner(void)
  66. {
  67. efi_printk(
  68. " ____ ____ _ _ \n");
  69. efi_printk(
  70. "| _ \\ _ __ __ _ __ _ ___ _ __ / ___|| |_ _ _| |__ \n");
  71. efi_printk(
  72. "| | | | '__/ _` |/ _` |/ _ \\| '_ \\\\___ \\| __| | | | '_ \\ \n");
  73. efi_printk(
  74. "| |_| | | | (_| | (_| | (_) | | | |___) | |_| |_| | |_) |\n");
  75. efi_printk(
  76. "|____/|_| \\__,_|\\__, |\\___/|_| |_|____/ \\__|\\__,_|_.__/ \n");
  77. efi_printk(
  78. " |___/ \n");
  79. efi_printk("\n@Copyright 2022-2023 DragonOS Community.\n");
  80. efi_printk(
  81. "\nDragonStub official repo: https://github.com/DragonOS-Community/DragonStub\n");
  82. efi_printk("\nDragonStub is licensed under GPLv2\n\n");
  83. }