dragon_stub-main.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. efi_info("Booting DragonOS kernel...\n");
  40. efi_todo("Boot DragonOS kernel");
  41. return EFI_SUCCESS;
  42. }
  43. /// @brief Print thr DragonStub banner
  44. void print_dragonstub_banner(void)
  45. {
  46. efi_printk(
  47. " ____ ____ _ _ \n");
  48. efi_printk(
  49. "| _ \\ _ __ __ _ __ _ ___ _ __ / ___|| |_ _ _| |__ \n");
  50. efi_printk(
  51. "| | | | '__/ _` |/ _` |/ _ \\| '_ \\\\___ \\| __| | | | '_ \\ \n");
  52. efi_printk(
  53. "| |_| | | | (_| | (_| | (_) | | | |___) | |_| |_| | |_) |\n");
  54. efi_printk(
  55. "|____/|_| \\__,_|\\__, |\\___/|_| |_|____/ \\__|\\__,_|_.__/ \n");
  56. efi_printk(
  57. " |___/ \n");
  58. }