Adding upstream version 4.02+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / gpxecmd.c
blob057659bdb1480dcebd8ca5d054ab6585a34d724d
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 * gpxecmd.c
16 * Invoke an arbitrary gPXE 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 gpxecmd(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 while (*args) {
52 q = stpcpy(q, *args);
53 *q++ = ' ';
54 args++;
56 *--q = '\0';
58 memset(&reg, 0, sizeof reg);
59 reg.eax.w[0] = 0x0009;
60 reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
61 reg.edi.w[0] = OFFS(fx);
62 reg.es = SEG(fx);
64 __intcall(0x22, &reg, &reg);
66 /* This should not return... */
69 int main(int argc, const char *argv[])
71 openconsole(&dev_null_r, &dev_stdcon_w);
73 if (argc < 2) {
74 printf("Usage: gpxecmd command...\n");
75 return 1;
78 if (!is_gpxe()) {
79 printf("gpxecmd: gPXE API not detected\n");
80 return 1;
83 gpxecmd(argv + 1);
85 return 0;