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