Adding upstream version 4.02+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / sanboot.c
blob46df6bc3b6e4b1083ceaf1c55142d04560a30bd5
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 * ----------------------------------------------------------------------- */
14 * sanboot.c
16 * Invoke the gPXE "sanboot" command, if available.
19 #include <alloca.h>
20 #include <inttypes.h>
21 #include <stdio.h>
22 #include <console.h>
23 #include <com32.h>
24 #include <string.h>
25 #include <sys/gpxe.h>
27 struct segoff16 {
28 uint16_t offs, seg;
31 struct s_PXENV_FILE_EXEC {
32 uint16_t Status;
33 struct segoff16 Command;
36 static void sanboot(const char **args)
38 char *q;
39 struct s_PXENV_FILE_EXEC *fx;
40 com32sys_t reg;
42 memset(&reg, 0, sizeof reg);
44 fx = __com32.cs_bounce;
45 q = (char *)(fx + 1);
47 fx->Status = 1;
48 fx->Command.offs = OFFS(q);
49 fx->Command.seg = SEG(q);
51 q = stpcpy(q, "sanboot");
53 while (*args) {
54 *q++ = ' ';
55 q = stpcpy(q, *args);
56 args++;
59 memset(&reg, 0, sizeof reg);
60 reg.eax.w[0] = 0x0009;
61 reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
62 reg.edi.w[0] = OFFS(fx);
63 reg.es = SEG(fx);
65 __intcall(0x22, &reg, &reg);
67 /* This should not return... */
70 int main(int argc, const char *argv[])
72 openconsole(&dev_null_r, &dev_stdcon_w);
74 if (argc < 2) {
75 printf("Usage: sanboot rootpath\n");
76 return 1;
79 if (!is_gpxe()) {
80 printf("sanboot: gPXE API not detected\n");
81 return 1;
84 sanboot(argv + 1);
86 /* sanboot() should not return... */
87 printf("SAN boot failed.\n");
88 return 1;