dragon_stub-main.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "dragonstub/riscv64.h"
  2. #include <efi.h>
  3. #include <efilib.h>
  4. #include <dragonstub/printk.h>
  5. #include <dragonstub/dragonstub.h>
  6. void print_dragonstub_banner(void);
  7. EFI_STATUS
  8. efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
  9. {
  10. EFI_STATUS status;
  11. EFI_LOADED_IMAGE *loaded_image = NULL;
  12. /* addr/point and size pairs for memory management*/
  13. char *cmdline_ptr = NULL;
  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 = efi_bs_call(HandleProtocol, image_handle, &LoadedImageProtocol,
  22. (void *)&loaded_image);
  23. if (EFI_ERROR(status)) {
  24. efi_err("Could not open loaded image protocol: %d\n", status);
  25. return status;
  26. }
  27. efi_info("Loaded image protocol opened\n");
  28. status = efi_handle_cmdline(loaded_image, &cmdline_ptr);
  29. if (EFI_ERROR(status)) {
  30. efi_err("Could not get command line: %d\n", status);
  31. return status;
  32. }
  33. if (cmdline_ptr == NULL)
  34. efi_warn("Command line is NULL\n");
  35. else
  36. efi_info("Command line: %s\n", cmdline_ptr);
  37. struct payload_info payload;
  38. status = find_payload(image_handle, loaded_image, &payload);
  39. if (EFI_ERROR(status)) {
  40. efi_err("Could not find payload, efi error code: %d\n", status);
  41. return status;
  42. }
  43. efi_info("Booting DragonOS kernel...\n");
  44. efi_stub_common(image_handle, loaded_image, &payload, cmdline_ptr);
  45. efi_todo("Boot DragonOS kernel");
  46. return EFI_SUCCESS;
  47. }
  48. /// @brief Print thr DragonStub banner
  49. void print_dragonstub_banner(void)
  50. {
  51. efi_printk(
  52. " ____ ____ _ _ \n");
  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("\n@Copyright 2022-2023 DragonOS Community.\n");
  64. efi_printk(
  65. "\nDragonStub official repo: https://github.com/DragonOS-Community/DragonStub\n");
  66. efi_printk("\nDragonStub is licensed under GPLv2\n\n");
  67. }