syslinux/com32/modules/gpxecmd.c
<<
>>
Prefs
   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#include <sys/gpxe.h>
  26
  27struct segoff16 {
  28    uint16_t offs, seg;
  29};
  30
  31struct s_PXENV_FILE_EXEC {
  32    uint16_t Status;
  33    struct segoff16 Command;
  34};
  35
  36static void gpxecmd(const char **args)
  37{
  38    char *q;
  39    struct s_PXENV_FILE_EXEC *fx;
  40    com32sys_t reg;
  41
  42    memset(&reg, 0, sizeof reg);
  43
  44    fx = __com32.cs_bounce;
  45    q = (char *)(fx + 1);
  46
  47    fx->Status = 1;
  48    fx->Command.offs = OFFS(q);
  49    fx->Command.seg = SEG(q);
  50
  51    while (*args) {
  52        q = stpcpy(q, *args);
  53        *q++ = ' ';
  54        args++;
  55    }
  56    *--q = '\0';
  57
  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);
  63
  64    __intcall(0x22, &reg, &reg);
  65
  66    /* This should not return... */
  67}
  68
  69int main(int argc, const char *argv[])
  70{
  71    openconsole(&dev_null_r, &dev_stdcon_w);
  72
  73    if (argc < 2) {
  74        printf("Usage: gpxecmd command...\n");
  75        return 1;
  76    }
  77
  78    if (!is_gpxe()) {
  79        printf("gpxecmd: gPXE API not detected\n");
  80        return 1;
  81    }
  82
  83    gpxecmd(argv + 1);
  84
  85    return 0;
  86}
  87
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.