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