summaryrefslogtreecommitdiff
path: root/com32
diff options
context:
space:
mode:
Diffstat (limited to 'com32')
-rw-r--r--com32/gplinclude/cpuid.h2
-rw-r--r--com32/gpllib/cpuid.c2
-rw-r--r--com32/hdt/Makefile39
-rw-r--r--com32/hdt/README19
-rw-r--r--com32/hdt/floppy/hdt.cfg6
-rw-r--r--com32/hdt/floppy/mtools.conf2
-rw-r--r--com32/hdt/hdt-cli-cpu.c4
-rw-r--r--com32/hdt/hdt-cli-hdt.c4
-rw-r--r--com32/hdt/hdt-menu-processor.c4
-rw-r--r--com32/hdt/hdt.c4
-rw-r--r--com32/include/cpufeature.h2
-rw-r--r--com32/mboot/map.c2
-rw-r--r--com32/modules/Makefile8
-rw-r--r--com32/modules/chain.c21
-rw-r--r--com32/modules/cpuidtest.c4
-rw-r--r--com32/modules/gpxecmd.c137
16 files changed, 245 insertions, 15 deletions
diff --git a/com32/gplinclude/cpuid.h b/com32/gplinclude/cpuid.h
index f984751f..f85e6ab3 100644
--- a/com32/gplinclude/cpuid.h
+++ b/com32/gplinclude/cpuid.h
@@ -65,6 +65,8 @@ typedef struct {
bool nowext; /* AMD 3DNow! extensions */
bool now; /* 3DNow! */
bool smp; /* A smp configuration has been found */
+ bool vmx; /* Hardware virtualization */
+ bool svm; /* Secure virtual machine */
} s_cpu_flags;
typedef struct {
diff --git a/com32/gpllib/cpuid.c b/com32/gpllib/cpuid.c
index 6d464c7e..fb69cef6 100644
--- a/com32/gpllib/cpuid.c
+++ b/com32/gpllib/cpuid.c
@@ -295,6 +295,8 @@ void set_cpu_flags(struct cpuinfo_x86 *c, s_cpu * cpu)
cpu->flags.nowext = cpu_has(c, X86_FEATURE_3DNOWEXT);
cpu->flags.now = cpu_has(c, X86_FEATURE_3DNOW);
cpu->flags.smp = find_smp_config();
+ cpu->flags.vmx = cpu_has(c, X86_FEATURE_VMX);
+ cpu->flags.svm = cpu_has(c, X86_FEATURE_SVM);
}
void set_generic_info(struct cpuinfo_x86 *c, s_cpu * cpu)
diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile
index 8f8cae21..a939d7b2 100644
--- a/com32/hdt/Makefile
+++ b/com32/hdt/Makefile
@@ -27,11 +27,47 @@ TESTFILES =
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
+KERNEL_VERSION ?= $(shell uname -r)
+MODULES_ALIAS_FILE ?= /lib/modules/$(KERNEL_VERSION)/modules.alias
+MODULES_PCIMAP_FILE ?= /lib/modules/$(KERNEL_VERSION)/modules.pcimap
+ISO_DIR ?= iso
+ISOLINUX_DIR ?= isolinux
+FLOPPY_DIR ?= floppy
+PCI_IDS_FILE ?= $(PWD)/$(FLOPPY_DIR)/pci.ids
+
all: $(MODULES) $(TESTFILES)
hdt.elf : $(OBJS) $(LIBS) $(C_LIBS)
$(LD) $(LDFLAGS) -o $@ $^
+hdt.img: hdt.c32 $(FLOPPY_DIR)/hdt.cfg $(FLOPPY_DIR)/mtools.conf $(topdir)/mtools/syslinux
+ rm -f hdt.img
+ MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MFORMAT) -v HDT -f 2880 -C a:
+ $(topdir)/mtools/syslinux hdt.img
+ -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(PCI_IDS_FILE)
+ -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(PCI_IDS_FILE)
+ -[ -f $(MODULES_ALIAS_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(MODULES_ALIAS_FILE) a:
+ -[ -f $(MODULES_PCIMAP_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(MODULES_PCIMAP_FILE) a:
+ MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) hdt.c32 a:
+ @ [ -f $(PCI_IDS_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(PCI_IDS_FILE) a: || printf "\nThe $(FLOPPY_DIR)/pci.ids file is missing and can be downloaded from http://pciids.sourceforge.net and put in\nthe ./com32/hdt/$(FLOPPY_DIR) directory of the extracted Syslinux source.\n\n"
+ MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(FLOPPY_DIR)/hdt.cfg a:syslinux.cfg
+
+hdt.iso: hdt.c32 $(topdir)/core/isolinux.bin $(FLOPPY_DIR)/hdt.cfg
+ rm -rf $(ISO_DIR)
+ rm -f hdt.iso
+ mkdir -p $(ISO_DIR)/$(ISOLINUX_DIR)
+ cp $(topdir)/core/isolinux.bin $(ISO_DIR)/$(ISOLINUX_DIR)
+ cp $(FLOPPY_DIR)/hdt.cfg $(ISO_DIR)/$(ISOLINUX_DIR)/isolinux.cfg
+ cp hdt.c32 $(ISO_DIR)/$(ISOLINUX_DIR)
+ -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(ISO_DIR)/$(ISOLINUX_DIR)
+ -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(ISO_DIR)/$(ISOLINUX_DIR)
+ -[ -f $(MODULES_ALIAS_FILE) ] && cp $(MODULES_ALIAS_FILE) $(ISO_DIR)/$(ISOLINUX_DIR)
+ -[ -f $(MODULES_PCIMAP_FILE) ] && cp $(MODULES_PCIMAP_FILE) $(ISO_DIR)/$(ISOLINUX_DIR)
+ -[ ! -f $(ISO_DIR)/$(ISOLINUX_DIR)/pci.ids ] && printf "\nThe $(FLOPPY_DIR)/pci.ids file is missing and can be downloaded from http://pciids.sourceforge.net and put in\nthe ./com32/hdt/$(FLOPPY_DIR) directory of the extracted Syslinux source.\n\n"
+ $(MKISOFS) -o hdt.iso -b $(ISOLINUX_DIR)/isolinux.bin -c $(ISOLINUX_DIR)/boot.cat \
+ -no-emul-boot -boot-load-size 4 -boot-info-table \
+ $(ISO_DIR)
+
tidy dist:
rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp
@@ -39,7 +75,8 @@ clean: tidy
rm -f *.lnx
spotless: clean
- rm -f *.lss *.c32 *.com
+ rm -f *.lss *.c32 *.com hdt.img hdt.iso
+ rm -rf $(ISO_DIR)
rm -f *~ \#*
install:
diff --git a/com32/hdt/README b/com32/hdt/README
new file mode 100644
index 00000000..8e171616
--- /dev/null
+++ b/com32/hdt/README
@@ -0,0 +1,19 @@
+--------------
+Compiling HDT
+--------------
+To build HDT, you just have to do a "make" call in this directory.
+
+---------------------------
+Creating a bootable floppy
+--------------------------
+To build a bootable HDT floppy image, you can do a "make hdt.img" call.
+This will requires the mtools (http://mtools.linux.lu) to be installed.
+The script will try to pick several files from your system :
+- /lib/modules/`uname -r`/modules.alias
+- /lib/modules/`uname -r`/modules.pcimap
+- /usr/share/pci.ids or /usr/share/hwdata/pci.ids
+
+This paths can be overrided with the following command line:
+make MODULES_ALIAS_FILE=$(PWD)/floppy/modules.alias MODULES_PCIMAP_FILE=$(PWD)/floppy/modules.pcimap PCI_IDS_FILE=$(PWD)/floppy/pci.ids hdt.img
+
+If your system doesn't have pci.ids, please download it from http://pciids.sourceforge.net/ and put it into the floppy/ directory.
diff --git a/com32/hdt/floppy/hdt.cfg b/com32/hdt/floppy/hdt.cfg
new file mode 100644
index 00000000..04e30476
--- /dev/null
+++ b/com32/hdt/floppy/hdt.cfg
@@ -0,0 +1,6 @@
+DEFAULT hdt
+PROMPT 0
+
+LABEL hdt
+COM32 hdt.c32
+APPEND modules_pcimap=modules.pcimap modules_alias=modules.alias pciids=pci.ids
diff --git a/com32/hdt/floppy/mtools.conf b/com32/hdt/floppy/mtools.conf
new file mode 100644
index 00000000..adbe2c83
--- /dev/null
+++ b/com32/hdt/floppy/mtools.conf
@@ -0,0 +1,2 @@
+# Floppy image for HDT
+drive a: file="hdt.img"
diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c
index f0f0a1bb..d2b5979f 100644
--- a/com32/hdt/hdt-cli-cpu.c
+++ b/com32/hdt/hdt-cli-cpu.c
@@ -174,6 +174,10 @@ static void show_cpu(int argc __unused, char **argv __unused,
strcat(buffer1, "3dnowext ");
if (hardware->cpu.flags.now)
strcat(buffer1, "3dnow! ");
+ if (hardware->cpu.flags.svm)
+ strcat(buffer1, "svm ");
+ if (hardware->cpu.flags.vmx)
+ strcat(buffer1, "vmx ");
if (buffer1[0]) {
snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
more_printf(buffer);
diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c
index 5bebf584..b5cd5359 100644
--- a/com32/hdt/hdt-cli-hdt.c
+++ b/com32/hdt/hdt-cli-hdt.c
@@ -191,8 +191,8 @@ static void goto_menu(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
char version_string[256];
- snprintf(version_string, sizeof version_string, "%s %s by %s",
- PRODUCT_NAME, VERSION, AUTHOR);
+ snprintf(version_string, sizeof version_string, "%s %s",
+ PRODUCT_NAME, VERSION);
start_menu_mode(hardware, version_string);
return;
}
diff --git a/com32/hdt/hdt-menu-processor.c b/com32/hdt/hdt-menu-processor.c
index a30cf0f6..4e102cb5 100644
--- a/com32/hdt/hdt-menu-processor.c
+++ b/com32/hdt/hdt-menu-processor.c
@@ -231,6 +231,10 @@ void compute_processor(struct s_my_menu *menu, struct s_hardware *hardware)
strcat(buffer1, "3dnowext ");
if (hardware->cpu.flags.now)
strcat(buffer1, "3dnow! ");
+ if (hardware->cpu.flags.vmx)
+ strcat(buffer1, "vmx ");
+ if (hardware->cpu.flags.svm)
+ strcat(buffer1, "svm ");
snprintf(buffer, sizeof buffer, "Flags : %s", buffer1);
snprintf(statbuffer, sizeof statbuffer, "Flags: %s", buffer1);
add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0);
diff --git a/com32/hdt/hdt.c b/com32/hdt/hdt.c
index 93c4aae2..e10e56f5 100644
--- a/com32/hdt/hdt.c
+++ b/com32/hdt/hdt.c
@@ -48,8 +48,8 @@ int main(const int argc, const char *argv[])
const char *arg;
struct s_hardware hardware;
- snprintf(version_string, sizeof version_string, "%s %s by %s",
- PRODUCT_NAME,VERSION,AUTHOR);
+ snprintf(version_string, sizeof version_string, "%s %s",
+ PRODUCT_NAME,VERSION);
/* Opening the Syslinux console */
console_ansi_raw();
diff --git a/com32/include/cpufeature.h b/com32/include/cpufeature.h
index 2fd47579..036631a7 100644
--- a/com32/include/cpufeature.h
+++ b/com32/include/cpufeature.h
@@ -72,6 +72,7 @@
#define X86_FEATURE_XMM3 (4*32+ 0) /* Streaming SIMD Extensions-3 */
#define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */
#define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */
+#define X86_FEATURE_VMX (4*32+ 5) /* Hardware virtualization */
#define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */
#define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */
#define X86_FEATURE_CID (4*32+10) /* Context ID */
@@ -87,6 +88,7 @@
/* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
#define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
#define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */
+#define X86_FEATURE_SVM (6*32+ 2) /* Secure virtual machine */
#endif /* __ASM_I386_CPUFEATURE_H */
diff --git a/com32/mboot/map.c b/com32/mboot/map.c
index 1a788ef7..887776fe 100644
--- a/com32/mboot/map.c
+++ b/com32/mboot/map.c
@@ -127,7 +127,7 @@ int map_image(void *ptr, size_t len)
else
mbh_len = 12;
- if (i + mbh_len < len)
+ if (i + mbh_len > len)
mbh_len = 0; /* Invalid... */
else
break; /* Found something... */
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index c93d3afc..52327b61 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -18,10 +18,10 @@
topdir = ../..
include ../MCONFIG
-MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 disk.c32 \
- pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 meminfo.c32 \
- sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 kbdmap.c32 cmd.c32 \
- vpdtest.c32
+MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \
+ disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \
+ meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \
+ kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32
TESTFILES =
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index bdeb82d5..53746c85 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -446,7 +446,7 @@ static void do_boot(void *boot_sector, size_t boot_size,
mmap = syslinux_memory_map();
if (!mmap) {
- error("Cannot read system memory map");
+ error("Cannot read system memory map\n");
return;
}
@@ -547,11 +547,11 @@ static void do_boot(void *boot_sector, size_t boot_size,
return;
too_big:
- error("Loader file too large");
+ error("Loader file too large\n");
return;
enomem:
- error("Out of memory");
+ error("Out of memory\n");
return;
}
@@ -614,7 +614,7 @@ int main(int argc, char *argv[])
} else if (!strncmp(argv[i], "seg=", 4)) {
uint32_t segval = strtoul(argv[i] + 4, NULL, 0);
if (segval < 0x50 || segval > 0x9f000) {
- error("Invalid segment");
+ error("Invalid segment\n");
goto bail;
}
opt.seg = segval;
@@ -650,7 +650,18 @@ int main(int argc, char *argv[])
}
} else {
error
- ("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n");
+ ("Usage: chain.c32 hd<disk#> [<partition>] [options]\n"
+ " chain.c32 fd<disk#> [options]\n"
+ " chain.c32 mbr:<id> [<partition>] [options]\n"
+ " chain.c32 boot [<partition>] [options]\n"
+ "Options: file=<loader> load file, instead of boot sector\n"
+ " ntldr=<loader> load Windows bootloaders: NTLDR, SETUPLDR, BOOTMGR\n"
+ " freedos=<loader> load FreeDOS kernel.sys\n"
+ " msdos=<loader> load MS-DOS io.sys\n"
+ " pcdos=<loader> load PC-DOS ibmbio.com\n"
+ " seg=<segment> jump to <seg>:0000 instead of 0000:7C00\n"
+ " swap swap drive numbers, if bootdisk is not fd0/hd0\n"
+ " hide hide primary partitions, except selected partition\n");
goto bail;
}
}
diff --git a/com32/modules/cpuidtest.c b/com32/modules/cpuidtest.c
index bfc1c190..b7688852 100644
--- a/com32/modules/cpuidtest.c
+++ b/com32/modules/cpuidtest.c
@@ -121,6 +121,10 @@ int main(void)
printf("3dnowext ");
if (cpu.flags.now)
printf("3dnow! ");
+ if (cpu.flags.vmx)
+ printf("vmx ");
+ if (cpu.flags.svm)
+ printf("svm ");
printf("\n");
printf("SMP = ");
if (cpu.flags.smp)
diff --git a/com32/modules/gpxecmd.c b/com32/modules/gpxecmd.c
new file mode 100644
index 00000000..de6ffb21
--- /dev/null
+++ b/com32/modules/gpxecmd.c
@@ -0,0 +1,137 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * 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.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * gpxecmd.c
+ *
+ * Invoke an arbitrary gPXE command, if available.
+ */
+
+#include <alloca.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <console.h>
+#include <com32.h>
+#include <stdbool.h>
+#include <string.h>
+#include <syslinux/config.h>
+
+struct segoff16 {
+ uint16_t offs, seg;
+};
+
+struct s_PXENV_FILE_CHECK_API {
+ uint16_t Status;
+ uint16_t Size;
+ uint32_t Magic;
+ uint32_t Provider;
+ uint32_t APIMask;
+ uint32_t Flags;
+};
+
+static bool is_gpxe(void)
+{
+ const struct syslinux_version *sv;
+ com32sys_t reg;
+ struct s_PXENV_FILE_CHECK_API *fca;
+
+ sv = syslinux_version();
+ if (sv->filesystem != SYSLINUX_FS_PXELINUX)
+ return false; /* Not PXELINUX */
+
+ fca = __com32.cs_bounce;
+ memset(fca, 0, sizeof *fca);
+ fca->Size = sizeof *fca;
+ fca->Magic = 0x91d447b2;
+
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */
+ reg.edi.w[0] = OFFS(fca);
+ reg.es = SEG(fca);
+
+ __intcall(0x22, &reg, &reg);
+
+ if (reg.eflags.l & EFLAGS_CF)
+ return false; /* Cannot invoke PXE stack */
+
+ if (reg.eax.w[0] || fca->Status)
+ return false; /* PXE failure */
+
+ if (fca->Magic != 0xe9c17b20)
+ return false; /* Incorrect magic */
+
+ if (fca->Size < sizeof *fca)
+ return false; /* Short return */
+
+ if (!(fca->APIMask & (1 << 5)))
+ return false; /* No FILE EXEC */
+
+ return true;
+}
+
+struct s_PXENV_FILE_EXEC {
+ uint16_t Status;
+ struct segoff16 Command;
+};
+
+static void gpxecmd(const char **args)
+{
+ char *q;
+ struct s_PXENV_FILE_EXEC *fx;
+ com32sys_t reg;
+
+ memset(&reg, 0, sizeof reg);
+
+ fx = __com32.cs_bounce;
+ q = (char *)(fx + 1);
+
+ fx->Status = 1;
+ fx->Command.offs = OFFS(q);
+ fx->Command.seg = SEG(q);
+
+ while (*args) {
+ q = stpcpy(q, *args);
+ *q++ = ' ';
+ args++;
+ }
+ *--q = '\0';
+
+ memset(&reg, 0, sizeof reg);
+ reg.eax.w[0] = 0x0009;
+ reg.ebx.w[0] = 0x00e5; /* PXENV_FILE_EXEC */
+ reg.edi.w[0] = OFFS(fx);
+ reg.es = SEG(fx);
+
+ __intcall(0x22, &reg, &reg);
+
+ /* This should not return... */
+}
+
+int main(int argc, const char *argv[])
+{
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc < 2) {
+ printf("Usage: gpxecmd command...\n");
+ return 1;
+ }
+
+ if (!is_gpxe()) {
+ printf("gpxecmd: gPXE API not detected\n");
+ return 1;
+ }
+
+ gpxecmd(argv + 1);
+
+ return 0;
+}