dragon_stub-main.c 2.3 KB

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