Skip to content

Instantly share code, notes, and snippets.

@orumin
Last active December 28, 2019 18:01
Show Gist options
  • Select an option

  • Save orumin/8c4e88193f6930ff48a6c35aab3e66e6 to your computer and use it in GitHub Desktop.

Select an option

Save orumin/8c4e88193f6930ff48a6c35aab3e66e6 to your computer and use it in GitHub Desktop.
boot windows OS from NetBSD boot loader
diff --git a/sys/stand/efiboot/boot.c b/sys/stand/efiboot/boot.c
index fab2dc2ef4e2..760c82646257 100644
--- a/sys/stand/efiboot/boot.c
+++ b/sys/stand/efiboot/boot.c
@@ -84,6 +84,7 @@ int set_bootfile(const char *);
int set_bootargs(const char *);
void command_boot(char *);
+void command_loadwin(char *);
void command_dev(char *);
void command_dtb(char *);
void command_plist(char *);
@@ -101,6 +102,7 @@ void command_quit(char *);
const struct boot_command commands[] = {
{ "boot", command_boot, "boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
+ { "loadwin", command_loadwin, "boot Windows OS" },
{ "dev", command_dev, "dev" },
{ "dtb", command_dtb, "dtb [dev:][filename]" },
{ "plist", command_plist, "plist [dev:][filename]" },
@@ -149,6 +151,12 @@ command_boot(char *arg)
exec_netbsd(kernel, bootargs);
}
+void
+command_loadwin(char *arg)
+{
+ exec_windows();
+}
+
void
command_dev(char *arg)
{
diff --git a/sys/stand/efiboot/efiboot.c b/sys/stand/efiboot/efiboot.c
index e375027707ba..8f12a4bd384b 100644
--- a/sys/stand/efiboot/efiboot.c
+++ b/sys/stand/efiboot/efiboot.c
@@ -248,3 +248,29 @@ efi_progress(const char *fmt, ...)
vprintf(fmt, ap);
va_end(ap);
}
+
+void
+exec_windows(void)
+{
+ EFI_STATUS status;
+ EFI_DEVICE_PATH path;
+ EFI_HANDLE windowsBootManager;
+
+ path = FileDevicePath(efi_li->DeviceHandle, L"\\EFI\\Microsoft\\Boot\\bootmgfw.efi");
+ if (path == NULL) {
+ printf("WARNING: cannot find Windows Boot Manager\n");
+ return;
+ }
+
+ status = uefi_call_wrapper(BS->LoadImage, 6, false, IH, path, NULL, 0, &windowsBootManager);
+ if (EFI_ERROR(status)) {
+ printf("WARNING: cannot load Windows Boot Manager\n");
+ return;
+ }
+
+ status = uefi_call_wrapper(BS->StartImage, 3, windowsBootManager, NULL, NULL);
+ uefi_call_wrapper(BS->UnloadImage, 1, windowsBootManager);
+ FreePool(path);
+
+ return;
+}
diff --git a/sys/stand/efiboot/efiboot.h b/sys/stand/efiboot/efiboot.h
index d3f84c047714..40afb52c9997 100644
--- a/sys/stand/efiboot/efiboot.h
+++ b/sys/stand/efiboot/efiboot.h
@@ -78,6 +78,7 @@ void efi_cleanup(void);
void efi_exit(void);
void efi_delay(int);
void efi_reboot(void);
+void exec_windows(void);
extern int howto;
extern prop_dictionary_t efibootplist;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment