aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules/sanboot.c
blob: ff55f68e9c7f4d04f48638316e0b60957ab50c87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2008 H. Peter Anvin - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * sanboot.c
 *
 * Invoke the gPXE "sanboot" command, if available.
 */

#include <alloca.h>
#include <inttypes.h>
#include <stdio.h>
#include <console.h>
#include <com32.h>
#include <string.h>

#include <sys/gpxe.h>
#include <syslinux/pxe_api.h>

struct segoff16 {
    uint16_t offs, seg;
};

struct s_PXENV_FILE_EXEC {
    uint16_t Status;
    struct segoff16 Command;
};

static void sanboot(const char **args)
{
    char *q;
    struct s_PXENV_FILE_EXEC *fx;

    fx = lmalloc(sizeof *fx);
    if (!fx)
	return;

    q = (char *)(fx + 1);

    fx->Status = 1;
    fx->Command.offs = OFFS(q);
    fx->Command.seg = SEG(q);

    q = stpcpy(q, "sanboot");

    while (*args) {
	*q++ = ' ';
	q = stpcpy(q, *args);
	args++;
    }

    pxe_call(PXENV_FILE_EXEC, fx);

    /* This should not return... */
}

int main(int argc, const char *argv[])
{
    if (argc < 2) {
	printf("Usage: sanboot rootpath\n");
	return 1;
    }

    if (!is_gpxe()) {
	printf("sanboot: gPXE API not detected\n");
	return 1;
    }

    sanboot(argv + 1);

    /* sanboot() should not return... */
    printf("SAN boot failed.\n");
    return 1;
}