1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * Invoke the gPXE "sanboot" command, if available.
26 #include <syslinux/config.h>
32 struct s_PXENV_FILE_CHECK_API {
41 static bool is_gpxe(void)
43 const struct syslinux_version *sv;
45 struct s_PXENV_FILE_CHECK_API *fca;
47 sv = syslinux_version();
48 if (sv->filesystem != SYSLINUX_FS_PXELINUX)
49 return false; /* Not PXELINUX */
51 fca = __com32.cs_bounce;
52 memset(fca, 0, sizeof *fca);
53 fca->Size = sizeof *fca;
54 fca->Magic = 0x91d447b2;
56 memset(®, 0, sizeof reg);
57 reg.eax.w[0] = 0x0009;
58 reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */
59 reg.edi.w[0] = OFFS(fca);
62 __intcall(0x22, ®, ®);
64 if (reg.eflags.l & EFLAGS_CF)
65 return false; /* Cannot invoke PXE stack */
67 if (reg.eax.w[0] || fca->Status)
68 return false; /* PXE failure */
70 if (fca->Magic != 0xe9c17b20)
71 return false; /* Incorrect magic */
73 if (fca->Size < sizeof *fca)
74 return false; /* Short return */
76 if (!(fca->APIMask & (1 << 5)))
77 return false; /* No FILE EXEC */
82 struct s_PXENV_FILE_EXEC {
84 struct segoff16 Command;
87 static void sanboot(const char **args)
90 struct s_PXENV_FILE_EXEC *fx;
93 memset(®, 0, sizeof reg);
95 fx = __com32.cs_bounce;
99 fx->Command.offs = OFFS(q);
100 fx->Command.seg = SEG(q);
102 q = stpcpy(q, "sanboot");
106 q = stpcpy(q, *args);
110 memset(®, 0, sizeof reg);
111 reg.eax.w[0] = 0x0009;
112 reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
113 reg.edi.w[0] = OFFS(fx);
116 __intcall(0x22, ®, ®);
118 /* This should not return... */
121 int main(int argc, const char *argv[])
123 openconsole(&dev_null_r, &dev_stdcon_w);
126 printf("Usage: sanboot rootpath\n");
131 printf("sanboot: gPXE API not detected\n");
137 /* sanboot() should not return... */
138 printf("SAN boot failed.\n");