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 static EFI_STATUS test_exit_bs(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab){ 9 EFI_STATUS status; 10 struct efi_boot_memmap *map; 11 12 status = efi_get_memory_map(&map, false); 13 if (status != EFI_SUCCESS) 14 return status; 15 efi_debug("before priv_func\n"); 16 17 efi_debug("map->map_size: %d\n", map->map_size); 18 efi_debug("before ExitBootServices, handle=%p, map_key=%p\n", image_handle, 19 map->map_key); 20 21 status = efi_bs_call(ExitBootServices, image_handle, map->map_key); 22 23 efi_debug("after ExitBootServices, status: %d\n", status); 24 25 while(1); 26 } 27 28 EFI_STATUS 29 efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) 30 { 31 EFI_STATUS status; 32 EFI_LOADED_IMAGE *loaded_image = NULL; 33 /* addr/point and size pairs for memory management*/ 34 char *cmdline_ptr = NULL; 35 36 InitializeLib(image_handle, systab); 37 38 print_dragonstub_banner(); 39 40 efi_info("EFI env initialized\n"); 41 42 /* 43 * Get a handle to the loaded image protocol. This is used to get 44 * information about the running image, such as size and the command 45 * line. 46 */ 47 status = uefi_call_wrapper(BS->OpenProtocol, 6, image_handle, 48 &LoadedImageProtocol, (void **)&loaded_image, 49 image_handle, NULL, 50 EFI_OPEN_PROTOCOL_GET_PROTOCOL); 51 52 if (EFI_ERROR(status)) { 53 efi_err("Could not open loaded image protocol: %d\n", status); 54 return status; 55 } 56 57 efi_info("Loaded image protocol opened\n"); 58 59 status = efi_handle_cmdline(loaded_image, &cmdline_ptr); 60 61 if (EFI_ERROR(status)) { 62 efi_err("Could not get command line: %d\n", status); 63 return status; 64 } 65 if (cmdline_ptr == NULL) 66 efi_warn("Command line is NULL\n"); 67 else 68 efi_info("Command line: %s\n", cmdline_ptr); 69 70 71 72 struct payload_info payload; 73 status = find_payload(image_handle, loaded_image, &payload); 74 if (EFI_ERROR(status)) { 75 efi_err("Could not find payload, efi error code: %d\n", status); 76 return status; 77 } 78 efi_info("Booting DragonOS kernel...\n"); 79 efi_stub_common(image_handle, loaded_image, &payload, cmdline_ptr); 80 efi_todo("Boot DragonOS kernel"); 81 82 return EFI_SUCCESS; 83 } 84 85 /// @brief Print thr DragonStub banner 86 void print_dragonstub_banner(void) 87 { 88 efi_printk( 89 " ____ ____ _ _ \n"); 90 efi_printk( 91 "| _ \\ _ __ __ _ __ _ ___ _ __ / ___|| |_ _ _| |__ \n"); 92 efi_printk( 93 "| | | | '__/ _` |/ _` |/ _ \\| '_ \\\\___ \\| __| | | | '_ \\ \n"); 94 efi_printk( 95 "| |_| | | | (_| | (_| | (_) | | | |___) | |_| |_| | |_) |\n"); 96 efi_printk( 97 "|____/|_| \\__,_|\\__, |\\___/|_| |_|____/ \\__|\\__,_|_.__/ \n"); 98 efi_printk( 99 " |___/ \n"); 100 101 efi_printk("\n@Copyright 2022-2023 DragonOS Community.\n"); 102 efi_printk( 103 "\nDragonStub official repo: https://github.com/DragonOS-Community/DragonStub\n"); 104 efi_printk("\nDragonStub is licensed under GPLv2\n\n"); 105 } 106