• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2008 H. Peter Anvin - All Rights Reserved
4  *
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.
10  *
11  * ----------------------------------------------------------------------- */
12 
13 /*
14  * gpxecmd.c
15  *
16  * Invoke an arbitrary gPXE command, if available.
17  */
18 
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 
26 #include <sys/gpxe.h>
27 #include <syslinux/pxe_api.h>
28 
29 struct segoff16 {
30     uint16_t offs, seg;
31 };
32 
33 struct s_PXENV_FILE_EXEC {
34     uint16_t Status;
35     struct segoff16 Command;
36 };
37 
gpxecmd(const char ** args)38 static void gpxecmd(const char **args)
39 {
40     char *q;
41     struct s_PXENV_FILE_EXEC *fx;
42 
43     fx = lmalloc(sizeof *fx);
44     if (!fx)
45 	return;
46 
47     q = (char *)(fx + 1);
48 
49     fx->Status = 1;
50     fx->Command.offs = OFFS(q);
51     fx->Command.seg = SEG(q);
52 
53     while (*args) {
54 	q = stpcpy(q, *args);
55 	*q++ = ' ';
56 	args++;
57     }
58     *--q = '\0';
59 
60     pxe_call(PXENV_FILE_EXEC, fx);
61 
62     /* This should not return... */
63 }
64 
main(int argc,const char * argv[])65 int main(int argc, const char *argv[])
66 {
67     if (argc < 2) {
68 	printf("Usage: gpxecmd command...\n");
69 	return 1;
70     }
71 
72     if (!is_gpxe()) {
73 	printf("gpxecmd: gPXE API not detected\n");
74 	return 1;
75     }
76 
77     gpxecmd(argv + 1);
78 
79     return 0;
80 }
81