aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-08-04 20:23:16 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-08-04 21:01:32 -0700
commit0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca (patch)
treeeb93c4db28c463d98cf520e3235e7357f870c0e8 /com32/modules
parenta6b80d3e8a356a55b4365c5e402e502843bbff8c (diff)
parent8e01231be41fd889bcb71604dbda511688ed0f38 (diff)
downloadsyslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.tar.gz
syslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.tar.xz
syslinux.git-0b19aba1d072ab3a2d9f528d7f0042dc8bc9e0ca.zip
Merge commit 'hpa/master' into for-erwan
Conflicts: com32/cmenu/libmenu/com32io.h com32/gplinclude/dmi/dmi.h com32/gplinclude/dmi/dmi_base_board.h com32/gplinclude/dmi/dmi_memory.h com32/gplinclude/dmi/dmi_system.h com32/gpllib/dmi/dmi.c com32/gpllib/dmi/dmi_memory.c com32/include/sys/pci.h com32/lib/pci/scan.c com32/modules/Makefile Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Diffstat (limited to 'com32/modules')
-rw-r--r--com32/modules/Makefile3
-rw-r--r--com32/modules/chain.c1139
-rw-r--r--com32/modules/cmd.c4
-rw-r--r--com32/modules/config.c16
-rw-r--r--com32/modules/cpuidtest.c130
-rw-r--r--com32/modules/dmi_utils.c65
-rw-r--r--com32/modules/dmitest.c277
-rw-r--r--com32/modules/elf.c367
-rw-r--r--com32/modules/ethersel.c252
-rw-r--r--com32/modules/i386-elf.h237
-rw-r--r--com32/modules/ifcpu64.c111
-rw-r--r--com32/modules/kbdmap.c58
-rw-r--r--com32/modules/linux.c321
-rw-r--r--com32/modules/mb_header.h90
-rw-r--r--com32/modules/mb_info.h217
-rw-r--r--com32/modules/mboot.c1083
-rw-r--r--com32/modules/meminfo.c154
-rw-r--r--com32/modules/pcitest.c146
-rw-r--r--com32/modules/pmload.c248
-rw-r--r--com32/modules/reboot.c15
-rw-r--r--com32/modules/sanboot.c142
-rw-r--r--com32/modules/sdi.c255
-rw-r--r--com32/modules/vesainfo.c93
-rw-r--r--com32/modules/vpdtest.c46
24 files changed, 1934 insertions, 3535 deletions
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index 76604214..c93d3afc 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -18,8 +18,7 @@
topdir = ../..
include ../MCONFIG
-MODULES = chain.c32 config.c32 ethersel.c32 mboot.c32 dmitest.c32 \
- cpuidtest.c32 disk.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
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index ead908f2..bdeb82d5 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -74,89 +74,89 @@
#define SECTOR 512 /* bytes/sector */
static struct options {
- const char *loadfile;
- uint16_t keeppxe;
- uint16_t seg;
- bool swap;
- bool hide;
+ const char *loadfile;
+ uint16_t keeppxe;
+ uint16_t seg;
+ bool swap;
+ bool hide;
} opt;
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
/*
* Call int 13h, but with retry on failure. Especially floppies need this.
*/
-static int int13_retry(const com32sys_t *inreg, com32sys_t *outreg)
+static int int13_retry(const com32sys_t * inreg, com32sys_t * outreg)
{
- int retry = 6; /* Number of retries */
- com32sys_t tmpregs;
+ int retry = 6; /* Number of retries */
+ com32sys_t tmpregs;
- if ( !outreg ) outreg = &tmpregs;
+ if (!outreg)
+ outreg = &tmpregs;
- while ( retry-- ) {
- __intcall(0x13, inreg, outreg);
- if ( !(outreg->eflags.l & EFLAGS_CF) )
- return 0; /* CF=0, OK */
- }
+ while (retry--) {
+ __intcall(0x13, inreg, outreg);
+ if (!(outreg->eflags.l & EFLAGS_CF))
+ return 0; /* CF=0, OK */
+ }
- return -1; /* Error */
+ return -1; /* Error */
}
/*
* Query disk parameters and EBIOS availability for a particular disk.
*/
struct diskinfo {
- int disk;
- int ebios; /* EBIOS supported on this disk */
- int cbios; /* CHS geometry is valid */
- int head;
- int sect;
+ int disk;
+ int ebios; /* EBIOS supported on this disk */
+ int cbios; /* CHS geometry is valid */
+ int head;
+ int sect;
} disk_info;
static int get_disk_params(int disk)
{
- static com32sys_t getparm, parm, getebios, ebios;
+ static com32sys_t getparm, parm, getebios, ebios;
- disk_info.disk = disk;
- disk_info.ebios = disk_info.cbios = 0;
+ disk_info.disk = disk;
+ disk_info.ebios = disk_info.cbios = 0;
- /* Get EBIOS support */
- getebios.eax.w[0] = 0x4100;
- getebios.ebx.w[0] = 0x55aa;
- getebios.edx.b[0] = disk;
- getebios.eflags.b[0] = 0x3; /* CF set */
+ /* Get EBIOS support */
+ getebios.eax.w[0] = 0x4100;
+ getebios.ebx.w[0] = 0x55aa;
+ getebios.edx.b[0] = disk;
+ getebios.eflags.b[0] = 0x3; /* CF set */
- __intcall(0x13, &getebios, &ebios);
+ __intcall(0x13, &getebios, &ebios);
- if ( !(ebios.eflags.l & EFLAGS_CF) &&
- ebios.ebx.w[0] == 0xaa55 &&
- (ebios.ecx.b[0] & 1) ) {
- disk_info.ebios = 1;
- }
+ if (!(ebios.eflags.l & EFLAGS_CF) &&
+ ebios.ebx.w[0] == 0xaa55 && (ebios.ecx.b[0] & 1)) {
+ disk_info.ebios = 1;
+ }
- /* Get disk parameters -- really only useful for
- hard disks, but if we have a partitioned floppy
- it's actually our best chance... */
- getparm.eax.b[1] = 0x08;
- getparm.edx.b[0] = disk;
+ /* Get disk parameters -- really only useful for
+ hard disks, but if we have a partitioned floppy
+ it's actually our best chance... */
+ getparm.eax.b[1] = 0x08;
+ getparm.edx.b[0] = disk;
- __intcall(0x13, &getparm, &parm);
+ __intcall(0x13, &getparm, &parm);
- if ( parm.eflags.l & EFLAGS_CF )
- return disk_info.ebios ? 0 : -1;
+ if (parm.eflags.l & EFLAGS_CF)
+ return disk_info.ebios ? 0 : -1;
- disk_info.head = parm.edx.b[1]+1;
- disk_info.sect = parm.ecx.b[0] & 0x3f;
- if ( disk_info.sect == 0 ) {
- disk_info.sect = 1;
- } else {
- disk_info.cbios = 1; /* Valid geometry */
- }
+ disk_info.head = parm.edx.b[1] + 1;
+ disk_info.sect = parm.ecx.b[0] & 0x3f;
+ if (disk_info.sect == 0) {
+ disk_info.sect = 1;
+ } else {
+ disk_info.cbios = 1; /* Valid geometry */
+ }
- return 0;
+ return 0;
}
/*
@@ -164,177 +164,180 @@ static int get_disk_params(int disk)
* Uses the disk number and information from disk_info.
*/
struct ebios_dapa {
- uint16_t len;
- uint16_t count;
- uint16_t off;
- uint16_t seg;
- uint64_t lba;
+ uint16_t len;
+ uint16_t count;
+ uint16_t off;
+ uint16_t seg;
+ uint64_t lba;
};
static void *read_sector(unsigned int lba)
{
- com32sys_t inreg;
- struct ebios_dapa *dapa = __com32.cs_bounce;
- void *buf = (char *)__com32.cs_bounce + SECTOR;
- void *data;
-
- memset(&inreg, 0, sizeof inreg);
-
- if ( disk_info.ebios ) {
- dapa->len = sizeof(*dapa);
- dapa->count = 1; /* 1 sector */
- dapa->off = OFFS(buf);
- dapa->seg = SEG(buf);
- dapa->lba = lba;
-
- inreg.esi.w[0] = OFFS(dapa);
- inreg.ds = SEG(dapa);
- inreg.edx.b[0] = disk_info.disk;
- inreg.eax.b[1] = 0x42; /* Extended read */
- } else {
- unsigned int c, h, s, t;
-
- if ( !disk_info.cbios ) {
- /* We failed to get the geometry */
-
- if ( lba )
- return NULL; /* Can only read MBR */
-
- s = 1; h = 0; c = 0;
+ com32sys_t inreg;
+ struct ebios_dapa *dapa = __com32.cs_bounce;
+ void *buf = (char *)__com32.cs_bounce + SECTOR;
+ void *data;
+
+ memset(&inreg, 0, sizeof inreg);
+
+ if (disk_info.ebios) {
+ dapa->len = sizeof(*dapa);
+ dapa->count = 1; /* 1 sector */
+ dapa->off = OFFS(buf);
+ dapa->seg = SEG(buf);
+ dapa->lba = lba;
+
+ inreg.esi.w[0] = OFFS(dapa);
+ inreg.ds = SEG(dapa);
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.eax.b[1] = 0x42; /* Extended read */
} else {
- s = (lba % disk_info.sect) + 1;
- t = lba / disk_info.sect; /* Track = head*cyl */
- h = t % disk_info.head;
- c = t / disk_info.head;
+ unsigned int c, h, s, t;
+
+ if (!disk_info.cbios) {
+ /* We failed to get the geometry */
+
+ if (lba)
+ return NULL; /* Can only read MBR */
+
+ s = 1;
+ h = 0;
+ c = 0;
+ } else {
+ s = (lba % disk_info.sect) + 1;
+ t = lba / disk_info.sect; /* Track = head*cyl */
+ h = t % disk_info.head;
+ c = t / disk_info.head;
+ }
+
+ if (s > 63 || h > 256 || c > 1023)
+ return NULL;
+
+ inreg.eax.w[0] = 0x0201; /* Read one sector */
+ inreg.ecx.b[1] = c & 0xff;
+ inreg.ecx.b[0] = s + (c >> 6);
+ inreg.edx.b[1] = h;
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.ebx.w[0] = OFFS(buf);
+ inreg.es = SEG(buf);
}
- if ( s > 63 || h > 256 || c > 1023 )
- return NULL;
-
- inreg.eax.w[0] = 0x0201; /* Read one sector */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = s + (c >> 6);
- inreg.edx.b[1] = h;
- inreg.edx.b[0] = disk_info.disk;
- inreg.ebx.w[0] = OFFS(buf);
- inreg.es = SEG(buf);
- }
-
- if (int13_retry(&inreg, NULL))
- return NULL;
+ if (int13_retry(&inreg, NULL))
+ return NULL;
- data = malloc(SECTOR);
- if (data)
- memcpy(data, buf, SECTOR);
- return data;
+ data = malloc(SECTOR);
+ if (data)
+ memcpy(data, buf, SECTOR);
+ return data;
}
static int write_sector(unsigned int lba, const void *data)
{
- com32sys_t inreg;
- struct ebios_dapa *dapa = __com32.cs_bounce;
- void *buf = (char *)__com32.cs_bounce + SECTOR;
-
- memcpy(buf, data, SECTOR);
- memset(&inreg, 0, sizeof inreg);
-
- if ( disk_info.ebios ) {
- dapa->len = sizeof(*dapa);
- dapa->count = 1; /* 1 sector */
- dapa->off = OFFS(buf);
- dapa->seg = SEG(buf);
- dapa->lba = lba;
-
- inreg.esi.w[0] = OFFS(dapa);
- inreg.ds = SEG(dapa);
- inreg.edx.b[0] = disk_info.disk;
- inreg.eax.w[0] = 0x4300; /* Extended write */
- } else {
- unsigned int c, h, s, t;
-
- if ( !disk_info.cbios ) {
- /* We failed to get the geometry */
-
- if ( lba )
- return -1; /* Can only write MBR */
-
- s = 1; h = 0; c = 0;
+ com32sys_t inreg;
+ struct ebios_dapa *dapa = __com32.cs_bounce;
+ void *buf = (char *)__com32.cs_bounce + SECTOR;
+
+ memcpy(buf, data, SECTOR);
+ memset(&inreg, 0, sizeof inreg);
+
+ if (disk_info.ebios) {
+ dapa->len = sizeof(*dapa);
+ dapa->count = 1; /* 1 sector */
+ dapa->off = OFFS(buf);
+ dapa->seg = SEG(buf);
+ dapa->lba = lba;
+
+ inreg.esi.w[0] = OFFS(dapa);
+ inreg.ds = SEG(dapa);
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.eax.w[0] = 0x4300; /* Extended write */
} else {
- s = (lba % disk_info.sect) + 1;
- t = lba / disk_info.sect; /* Track = head*cyl */
- h = t % disk_info.head;
- c = t / disk_info.head;
+ unsigned int c, h, s, t;
+
+ if (!disk_info.cbios) {
+ /* We failed to get the geometry */
+
+ if (lba)
+ return -1; /* Can only write MBR */
+
+ s = 1;
+ h = 0;
+ c = 0;
+ } else {
+ s = (lba % disk_info.sect) + 1;
+ t = lba / disk_info.sect; /* Track = head*cyl */
+ h = t % disk_info.head;
+ c = t / disk_info.head;
+ }
+
+ if (s > 63 || h > 256 || c > 1023)
+ return -1;
+
+ inreg.eax.w[0] = 0x0301; /* Write one sector */
+ inreg.ecx.b[1] = c & 0xff;
+ inreg.ecx.b[0] = s + (c >> 6);
+ inreg.edx.b[1] = h;
+ inreg.edx.b[0] = disk_info.disk;
+ inreg.ebx.w[0] = OFFS(buf);
+ inreg.es = SEG(buf);
}
- if ( s > 63 || h > 256 || c > 1023 )
- return -1;
-
- inreg.eax.w[0] = 0x0301; /* Write one sector */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = s + (c >> 6);
- inreg.edx.b[1] = h;
- inreg.edx.b[0] = disk_info.disk;
- inreg.ebx.w[0] = OFFS(buf);
- inreg.es = SEG(buf);
- }
-
- if (int13_retry(&inreg, NULL))
- return -1;
+ if (int13_retry(&inreg, NULL))
+ return -1;
- return 0; /* ok */
+ return 0; /* ok */
}
static int write_verify_sector(unsigned int lba, const void *buf)
{
- char *rb;
- int rv;
-
- rv = write_sector(lba, buf);
- if (rv)
- return rv; /* Write failure */
- rb = read_sector(lba);
- if (!rb)
- return -1; /* Readback failure */
- rv = memcmp(buf, rb, SECTOR);
- free(rb);
- return rv ? -1 : 0;
+ char *rb;
+ int rv;
+
+ rv = write_sector(lba, buf);
+ if (rv)
+ return rv; /* Write failure */
+ rb = read_sector(lba);
+ if (!rb)
+ return -1; /* Readback failure */
+ rv = memcmp(buf, rb, SECTOR);
+ free(rb);
+ return rv ? -1 : 0;
}
/* Search for a specific drive, based on the MBR signature; bytes
440-443. */
static int find_disk(uint32_t mbr_sig)
{
- int drive;
- bool is_me;
- char *buf;
-
- for (drive = 0x80; drive <= 0xff; drive++) {
- if (get_disk_params(drive))
- continue; /* Drive doesn't exist */
- if (!(buf = read_sector(0)))
- continue; /* Cannot read sector */
- is_me = (*(uint32_t *)((char *)buf + 440) == mbr_sig);
- free(buf);
- if (is_me)
- return drive;
- }
- return -1;
+ int drive;
+ bool is_me;
+ char *buf;
+
+ for (drive = 0x80; drive <= 0xff; drive++) {
+ if (get_disk_params(drive))
+ continue; /* Drive doesn't exist */
+ if (!(buf = read_sector(0)))
+ continue; /* Cannot read sector */
+ is_me = (*(uint32_t *) ((char *)buf + 440) == mbr_sig);
+ free(buf);
+ if (is_me)
+ return drive;
+ }
+ return -1;
}
/* A DOS partition table entry */
struct part_entry {
- uint8_t active_flag; /* 0x80 if "active" */
- uint8_t start_head;
- uint8_t start_sect;
- uint8_t start_cyl;
- uint8_t ostype;
- uint8_t end_head;
- uint8_t end_sect;
- uint8_t end_cyl;
- uint32_t start_lba;
- uint32_t length;
-} __attribute__((packed));
-
+ uint8_t active_flag; /* 0x80 if "active" */
+ uint8_t start_head;
+ uint8_t start_sect;
+ uint8_t start_cyl;
+ uint8_t ostype;
+ uint8_t end_head;
+ uint8_t end_sect;
+ uint8_t end_cyl;
+ uint32_t start_lba;
+ uint32_t length;
+} __attribute__ ((packed));
/* Search for a logical partition. Logical partitions are actually implemented
as recursive partition tables; theoretically they're supposed to form a
@@ -347,425 +350,429 @@ struct part_entry {
int nextpart; /* Number of the next logical partition */
-static struct part_entry *
-find_logical_partition(int whichpart, char *table, struct part_entry *self,
- struct part_entry *root)
+static struct part_entry *find_logical_partition(int whichpart, char *table,
+ struct part_entry *self,
+ struct part_entry *root)
{
- static struct part_entry ltab_entry;
- struct part_entry *ptab = (struct part_entry *)(table + 0x1be);
- struct part_entry *found;
- char *sector;
+ static struct part_entry ltab_entry;
+ struct part_entry *ptab = (struct part_entry *)(table + 0x1be);
+ struct part_entry *found;
+ char *sector;
+
+ int i;
- int i;
+ if (*(uint16_t *) (table + 0x1fe) != 0xaa55)
+ return NULL; /* Signature missing */
- if ( *(uint16_t *)(table + 0x1fe) != 0xaa55 )
- return NULL; /* Signature missing */
+ /* We are assumed to already having enumerated all the data partitions
+ in this table if this is the MBR. For MBR, self == NULL. */
- /* We are assumed to already having enumerated all the data partitions
- in this table if this is the MBR. For MBR, self == NULL. */
+ if (self) {
+ /* Scan the data partitions. */
- if ( self ) {
- /* Scan the data partitions. */
+ for (i = 0; i < 4; i++) {
+ if (ptab[i].ostype == 0x00 || ptab[i].ostype == 0x05 ||
+ ptab[i].ostype == 0x0f || ptab[i].ostype == 0x85)
+ continue; /* Skip empty or extended partitions */
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( ptab[i].ostype == 0x00 || ptab[i].ostype == 0x05 ||
- ptab[i].ostype == 0x0f || ptab[i].ostype == 0x85 )
- continue; /* Skip empty or extended partitions */
+ if (!ptab[i].length)
+ continue;
- if ( !ptab[i].length )
- continue;
+ /* Adjust the offset to account for the extended partition itself */
+ ptab[i].start_lba += self->start_lba;
- /* Adjust the offset to account for the extended partition itself */
- ptab[i].start_lba += self->start_lba;
+ /* Sanity check entry: must not extend outside the extended partition.
+ This is necessary since some OSes put crap in some entries. */
+ if (ptab[i].start_lba + ptab[i].length <= self->start_lba ||
+ ptab[i].start_lba >= self->start_lba + self->length)
+ continue;
- /* Sanity check entry: must not extend outside the extended partition.
- This is necessary since some OSes put crap in some entries. */
- if ( ptab[i].start_lba + ptab[i].length <= self->start_lba ||
- ptab[i].start_lba >= self->start_lba + self->length )
- continue;
+ /* OK, it's a data partition. Is it the one we're looking for? */
+ if (nextpart++ == whichpart) {
+ memcpy(&ltab_entry, &ptab[i], sizeof ltab_entry);
+ return &ltab_entry;
+ }
+ }
+ }
- /* OK, it's a data partition. Is it the one we're looking for? */
- if ( nextpart++ == whichpart ) {
- memcpy(&ltab_entry, &ptab[i], sizeof ltab_entry);
- return &ltab_entry;
- }
+ /* Scan the extended partitions. */
+ for (i = 0; i < 4; i++) {
+ if (ptab[i].ostype != 0x05 &&
+ ptab[i].ostype != 0x0f && ptab[i].ostype != 0x85)
+ continue; /* Skip empty or data partitions */
+
+ if (!ptab[i].length)
+ continue;
+
+ /* Adjust the offset to account for the extended partition itself */
+ if (root)
+ ptab[i].start_lba += root->start_lba;
+
+ /* Sanity check entry: must not extend outside the extended partition.
+ This is necessary since some OSes put crap in some entries. */
+ if (root)
+ if (ptab[i].start_lba + ptab[i].length <= root->start_lba ||
+ ptab[i].start_lba >= root->start_lba + root->length)
+ continue;
+
+ /* Process this partition */
+ if (!(sector = read_sector(ptab[i].start_lba)))
+ continue; /* Read error, must be invalid */
+
+ found = find_logical_partition(whichpart, sector, &ptab[i],
+ root ? root : &ptab[i]);
+ free(sector);
+ if (found)
+ return found;
}
- }
-
- /* Scan the extended partitions. */
- for ( i = 0 ; i < 4 ; i++ ) {
- if ( ptab[i].ostype != 0x05 &&
- ptab[i].ostype != 0x0f && ptab[i].ostype != 0x85 )
- continue; /* Skip empty or data partitions */
-
- if ( !ptab[i].length )
- continue;
-
- /* Adjust the offset to account for the extended partition itself */
- if ( root )
- ptab[i].start_lba += root->start_lba;
-
- /* Sanity check entry: must not extend outside the extended partition.
- This is necessary since some OSes put crap in some entries. */
- if ( root )
- if ( ptab[i].start_lba + ptab[i].length <= root->start_lba ||
- ptab[i].start_lba >= root->start_lba + root->length )
- continue;
-
- /* Process this partition */
- if ( !(sector = read_sector(ptab[i].start_lba)) )
- continue; /* Read error, must be invalid */
-
- found = find_logical_partition(whichpart, sector, &ptab[i],
- root ? root : &ptab[i]);
- free(sector);
- if (found)
- return found;
- }
-
- /* If we get here, there ain't nothing... */
- return NULL;
+
+ /* If we get here, there ain't nothing... */
+ return NULL;
}
static void do_boot(void *boot_sector, size_t boot_size,
struct syslinux_rm_regs *regs)
{
- uint16_t * const bios_fbm = (uint16_t *)0x413;
- addr_t dosmem = *bios_fbm << 10; /* Technically a low bound */
- struct syslinux_memmap *mmap;
- struct syslinux_movelist *mlist = NULL;
- addr_t endimage;
- uint8_t driveno = regs->edx.b[0];
- uint8_t swapdrive = driveno & 0x80;
- int i;
- addr_t loadbase = opt.seg ? (opt.seg << 4) : 0x7c00;
-
- mmap = syslinux_memory_map();
-
- if (!mmap) {
- error("Cannot read system memory map");
+ uint16_t *const bios_fbm = (uint16_t *) 0x413;
+ addr_t dosmem = *bios_fbm << 10; /* Technically a low bound */
+ struct syslinux_memmap *mmap;
+ struct syslinux_movelist *mlist = NULL;
+ addr_t endimage;
+ uint8_t driveno = regs->edx.b[0];
+ uint8_t swapdrive = driveno & 0x80;
+ int i;
+ addr_t loadbase = opt.seg ? (opt.seg << 4) : 0x7c00;
+
+ mmap = syslinux_memory_map();
+
+ if (!mmap) {
+ error("Cannot read system memory map");
+ return;
+ }
+
+ /* Nothing below 0x7c00, much simpler... */
+
+ if (boot_size >= dosmem - loadbase)
+ goto too_big;
+
+ endimage = loadbase + boot_size;
+
+ if (syslinux_add_movelist
+ (&mlist, loadbase, (addr_t) boot_sector, boot_size))
+ goto enomem;
+
+ if (opt.swap && driveno != swapdrive) {
+ static const uint8_t swapstub_master[] = {
+ /* The actual swap code */
+ 0x53, /* 00: push bx */
+ 0x0f, 0xb6, 0xda, /* 01: movzx bx,dl */
+ 0x2e, 0x8a, 0x57, 0x60, /* 04: mov dl,[cs:bx+0x60] */
+ 0x5b, /* 08: pop bx */
+ 0xea, 0, 0, 0, 0, /* 09: jmp far 0:0 */
+ 0x90, 0x90, /* 0E: nop; nop */
+ /* Code to install this in the right location */
+ /* Entry with DS = CS; ES = SI = 0; CX = 256 */
+ 0x26, 0x66, 0x8b, 0x7c, 0x4c, /* 10: mov edi,[es:si+4*0x13] */
+ 0x66, 0x89, 0x3e, 0x0a, 0x00, /* 15: mov [0x0A],edi */
+ 0x26, 0x8b, 0x3e, 0x13, 0x04, /* 1A: mov di,[es:0x413] */
+ 0x4f, /* 1F: dec di */
+ 0x26, 0x89, 0x3e, 0x13, 0x04, /* 20: mov [es:0x413],di */
+ 0x66, 0xc1, 0xe7, 0x16, /* 25: shl edi,16+6 */
+ 0x26, 0x66, 0x89, 0x7c, 0x4c, /* 29: mov [es:si+4*0x13],edi */
+ 0x66, 0xc1, 0xef, 0x10, /* 2E: shr edi,16 */
+ 0x8e, 0xc7, /* 32: mov es,di */
+ 0x31, 0xff, /* 34: xor di,di */
+ 0xf3, 0x66, 0xa5, /* 36: rep movsd */
+ 0xbe, 0, 0, /* 39: mov si,0 */
+ 0xbf, 0, 0, /* 3C: mov di,0 */
+ 0x8e, 0xde, /* 3F: mov ds,si */
+ 0x8e, 0xc7, /* 41: mov es,di */
+ 0x66, 0xb9, 0, 0, 0, 0, /* 43: mov ecx,0 */
+ 0x66, 0xbe, 0, 0, 0, 0, /* 49: mov esi,0 */
+ 0x66, 0xbf, 0, 0, 0, 0, /* 4F: mov edi,0 */
+ 0xea, 0, 0, 0, 0, /* 55: jmp 0:0 */
+ /* pad out to segment boundary */
+ 0x90, 0x90, /* 5A: ... */
+ 0x90, 0x90, 0x90, 0x90, /* 5C: ... */
+ };
+ static uint8_t swapstub[1024];
+ uint8_t *p;
+
+ /* Note: we can't rely on either INT 13h nor the dosmem
+ vector to be correct at this stage, so we have to use an
+ installer stub to put things in the right place.
+ Round the installer location to a 1K boundary so the only
+ possible overlap is the identity mapping. */
+ endimage = (endimage + 1023) & ~1023;
+
+ /* Create swap stub */
+ memcpy(swapstub, swapstub_master, sizeof swapstub_master);
+ *(uint16_t *) & swapstub[0x3a] = regs->ds;
+ *(uint16_t *) & swapstub[0x3d] = regs->es;
+ *(uint32_t *) & swapstub[0x45] = regs->ecx.l;
+ *(uint32_t *) & swapstub[0x4b] = regs->esi.l;
+ *(uint32_t *) & swapstub[0x51] = regs->edi.l;
+ *(uint16_t *) & swapstub[0x56] = regs->ip;
+ *(uint16_t *) & swapstub[0x58] = regs->cs;
+ p = &swapstub[sizeof swapstub_master];
+
+ /* Mapping table; start out with identity mapping everything */
+ for (i = 0; i < 256; i++)
+ p[i] = i;
+
+ /* And the actual swap */
+ p[driveno] = swapdrive;
+ p[swapdrive] = driveno;
+
+ /* Adjust registers */
+ regs->ds = regs->cs = endimage >> 4;
+ regs->es = regs->esi.l = 0;
+ regs->ecx.l = sizeof swapstub >> 2;
+ regs->ip = 0x10; /* Installer offset */
+ regs->ebx.b[0] = regs->edx.b[0] = swapdrive;
+
+ if (syslinux_add_movelist(&mlist, endimage, (addr_t) swapstub,
+ sizeof swapstub))
+ goto enomem;
+
+ endimage += sizeof swapstub;
+ }
+
+ /* Tell the shuffler not to muck with this area... */
+ syslinux_add_memmap(&mmap, endimage, 0xa0000 - endimage, SMT_RESERVED);
+
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, regs);
+ error("Chainboot failed!\n");
return;
- }
-
- /* Nothing below 0x7c00, much simpler... */
-
- if (boot_size >= dosmem - loadbase)
- goto too_big;
-
- endimage = loadbase + boot_size;
-
- if (syslinux_add_movelist(&mlist, loadbase, (addr_t)boot_sector, boot_size))
- goto enomem;
-
- if (opt.swap && driveno != swapdrive) {
- static const uint8_t swapstub_master[] = {
- /* The actual swap code */
- 0x53, /* 00: push bx */
- 0x0f,0xb6,0xda, /* 01: movzx bx,dl */
- 0x2e,0x8a,0x57,0x60, /* 04: mov dl,[cs:bx+0x60] */
- 0x5b, /* 08: pop bx */
- 0xea,0,0,0,0, /* 09: jmp far 0:0 */
- 0x90,0x90, /* 0E: nop; nop */
- /* Code to install this in the right location */
- /* Entry with DS = CS; ES = SI = 0; CX = 256 */
- 0x26,0x66,0x8b,0x7c,0x4c, /* 10: mov edi,[es:si+4*0x13] */
- 0x66,0x89,0x3e,0x0a,0x00, /* 15: mov [0x0A],edi */
- 0x26,0x8b,0x3e,0x13,0x04, /* 1A: mov di,[es:0x413] */
- 0x4f, /* 1F: dec di */
- 0x26,0x89,0x3e,0x13,0x04, /* 20: mov [es:0x413],di */
- 0x66,0xc1,0xe7,0x16, /* 25: shl edi,16+6 */
- 0x26,0x66,0x89,0x7c,0x4c, /* 29: mov [es:si+4*0x13],edi */
- 0x66,0xc1,0xef,0x10, /* 2E: shr edi,16 */
- 0x8e,0xc7, /* 32: mov es,di */
- 0x31,0xff, /* 34: xor di,di */
- 0xf3,0x66,0xa5, /* 36: rep movsd */
- 0xbe,0,0, /* 39: mov si,0 */
- 0xbf,0,0, /* 3C: mov di,0 */
- 0x8e,0xde, /* 3F: mov ds,si */
- 0x8e,0xc7, /* 41: mov es,di */
- 0x66,0xb9,0,0,0,0, /* 43: mov ecx,0 */
- 0x66,0xbe,0,0,0,0, /* 49: mov esi,0 */
- 0x66,0xbf,0,0,0,0, /* 4F: mov edi,0 */
- 0xea,0,0,0,0, /* 55: jmp 0:0 */
- /* pad out to segment boundary */
- 0x90,0x90, /* 5A: ... */
- 0x90,0x90,0x90,0x90, /* 5C: ... */
- };
- static uint8_t swapstub[1024];
- uint8_t *p;
-
- /* Note: we can't rely on either INT 13h nor the dosmem
- vector to be correct at this stage, so we have to use an
- installer stub to put things in the right place.
- Round the installer location to a 1K boundary so the only
- possible overlap is the identity mapping. */
- endimage = (endimage + 1023) & ~1023;
-
- /* Create swap stub */
- memcpy(swapstub, swapstub_master, sizeof swapstub_master);
- *(uint16_t *)&swapstub[0x3a] = regs->ds;
- *(uint16_t *)&swapstub[0x3d] = regs->es;
- *(uint32_t *)&swapstub[0x45] = regs->ecx.l;
- *(uint32_t *)&swapstub[0x4b] = regs->esi.l;
- *(uint32_t *)&swapstub[0x51] = regs->edi.l;
- *(uint16_t *)&swapstub[0x56] = regs->ip;
- *(uint16_t *)&swapstub[0x58] = regs->cs;
- p = &swapstub[sizeof swapstub_master];
-
- /* Mapping table; start out with identity mapping everything */
- for (i = 0; i < 256; i++)
- p[i] = i;
-
- /* And the actual swap */
- p[driveno] = swapdrive;
- p[swapdrive] = driveno;
-
- /* Adjust registers */
- regs->ds = regs->cs = endimage >> 4;
- regs->es = regs->esi.l = 0;
- regs->ecx.l = sizeof swapstub >> 2;
- regs->ip = 0x10; /* Installer offset */
- regs->ebx.b[0] = regs->edx.b[0] = swapdrive;
-
- if (syslinux_add_movelist(&mlist, endimage, (addr_t)swapstub,
- sizeof swapstub))
- goto enomem;
-
- endimage += sizeof swapstub;
- }
-
- /* Tell the shuffler not to muck with this area... */
- syslinux_add_memmap(&mmap, endimage, 0xa0000-endimage, SMT_RESERVED);
-
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_rm(mlist, mmap, opt.keeppxe, regs);
- error("Chainboot failed!\n");
- return;
too_big:
- error("Loader file too large");
- return;
+ error("Loader file too large");
+ return;
enomem:
- error("Out of memory");
- return;
+ error("Out of memory");
+ return;
}
static int hide_unhide(char *mbr, int part)
{
- int i;
- struct part_entry *pt;
- const uint16_t mask = (1 << 0x01)|(1 << 0x04)|(1 << 0x06)|(1 << 0x07)|
- (1 << 0x0b)|(1 << 0x0c)|(1 << 0x0e);
- uint8_t t;
- bool write_back = false;
-
- for (i = 1; i <= 4; i++) {
- pt = (struct part_entry *)&mbr[0x1be + 16*(i-1)];
- t = pt->ostype;
- if ((t <= 0x1f) && ((mask >> (t & ~0x10)) & 1)) {
- /* It's a hideable partition type */
- if (i == part)
- t &= ~0x10; /* unhide */
- else
- t |= 0x10; /* hide */
+ int i;
+ struct part_entry *pt;
+ const uint16_t mask =
+ (1 << 0x01) | (1 << 0x04) | (1 << 0x06) | (1 << 0x07) | (1 << 0x0b) | (1
+ <<
+ 0x0c)
+ | (1 << 0x0e);
+ uint8_t t;
+ bool write_back = false;
+
+ for (i = 1; i <= 4; i++) {
+ pt = (struct part_entry *)&mbr[0x1be + 16 * (i - 1)];
+ t = pt->ostype;
+ if ((t <= 0x1f) && ((mask >> (t & ~0x10)) & 1)) {
+ /* It's a hideable partition type */
+ if (i == part)
+ t &= ~0x10; /* unhide */
+ else
+ t |= 0x10; /* hide */
+ }
+ if (t != pt->ostype) {
+ write_back = true;
+ pt->ostype = t;
+ }
}
- if (t != pt->ostype) {
- write_back = true;
- pt->ostype = t;
- }
- }
- if (write_back)
- return write_verify_sector(0, mbr);
+ if (write_back)
+ return write_verify_sector(0, mbr);
- return 0; /* ok */
+ return 0; /* ok */
}
int main(int argc, char *argv[])
{
- char *mbr, *p;
- void *boot_sector = NULL;
- struct part_entry *partinfo;
- struct syslinux_rm_regs regs;
- char *drivename, *partition;
- int hd, drive, whichpart;
- int i;
- size_t boot_size = SECTOR;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- drivename = "boot";
- partition = NULL;
-
- /* Prepare the register set */
- memset(&regs, 0, sizeof regs);
-
- for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], "file=", 5)) {
- opt.loadfile = argv[i]+5;
- } else if (!strncmp(argv[i], "seg=", 4)) {
- uint32_t segval = strtoul(argv[i]+4, NULL, 0);
- if (segval < 0x50 || segval > 0x9f000) {
- error("Invalid segment");
- goto bail;
- }
- opt.seg = segval;
- } else if (!strncmp(argv[i], "ntldr=", 6)) {
- opt.seg = 0x2000; /* NTLDR wants this address */
- opt.loadfile = argv[i]+6;
- } else if (!strncmp(argv[i], "freedos=", 8)) {
- opt.seg = 0x60; /* FREEDOS wants this address */
- opt.loadfile = argv[i]+8;
- } else if (!strncmp(argv[i], "msdos=", 6) ||
- !strncmp(argv[i], "pcdos=", 6)) {
- opt.seg = 0x70; /* MS-DOS 2.0+ wants this address */
- opt.loadfile = argv[i]+6;
- } else if (!strcmp(argv[i], "swap")) {
- opt.swap = true;
- } else if (!strcmp(argv[i], "hide")) {
- opt.hide = true;
- } else if (!strcmp(argv[i], "keeppxe")) {
- opt.keeppxe = 3;
- } else if (((argv[i][0] == 'h' || argv[i][0] == 'f') && argv[i][1] == 'd')
- || !strncmp(argv[i], "mbr:", 4)
- || !strncmp(argv[i], "mbr=", 4)
- || !strcmp(argv[i], "boot") || !strncmp(argv[i], "boot,", 5)) {
- drivename = argv[i];
- p = strchr(drivename, ',');
- if (p) {
- *p = '\0';
- partition = p+1;
- } else if (argv[i+1] && argv[i+1][0] >= '0' && argv[i+1][0] <= '9') {
- partition = argv[++i];
- }
+ char *mbr, *p;
+ void *boot_sector = NULL;
+ struct part_entry *partinfo;
+ struct syslinux_rm_regs regs;
+ char *drivename, *partition;
+ int hd, drive, whichpart;
+ int i;
+ size_t boot_size = SECTOR;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ drivename = "boot";
+ partition = NULL;
+
+ /* Prepare the register set */
+ memset(&regs, 0, sizeof regs);
+
+ for (i = 1; i < argc; i++) {
+ if (!strncmp(argv[i], "file=", 5)) {
+ opt.loadfile = argv[i] + 5;
+ } else if (!strncmp(argv[i], "seg=", 4)) {
+ uint32_t segval = strtoul(argv[i] + 4, NULL, 0);
+ if (segval < 0x50 || segval > 0x9f000) {
+ error("Invalid segment");
+ goto bail;
+ }
+ opt.seg = segval;
+ } else if (!strncmp(argv[i], "ntldr=", 6)) {
+ opt.seg = 0x2000; /* NTLDR wants this address */
+ opt.loadfile = argv[i] + 6;
+ } else if (!strncmp(argv[i], "freedos=", 8)) {
+ opt.seg = 0x60; /* FREEDOS wants this address */
+ opt.loadfile = argv[i] + 8;
+ } else if (!strncmp(argv[i], "msdos=", 6) ||
+ !strncmp(argv[i], "pcdos=", 6)) {
+ opt.seg = 0x70; /* MS-DOS 2.0+ wants this address */
+ opt.loadfile = argv[i] + 6;
+ } else if (!strcmp(argv[i], "swap")) {
+ opt.swap = true;
+ } else if (!strcmp(argv[i], "hide")) {
+ opt.hide = true;
+ } else if (!strcmp(argv[i], "keeppxe")) {
+ opt.keeppxe = 3;
+ } else
+ if (((argv[i][0] == 'h' || argv[i][0] == 'f') && argv[i][1] == 'd')
+ || !strncmp(argv[i], "mbr:", 4)
+ || !strncmp(argv[i], "mbr=", 4)
+ || !strcmp(argv[i], "boot") || !strncmp(argv[i], "boot,", 5)) {
+ drivename = argv[i];
+ p = strchr(drivename, ',');
+ if (p) {
+ *p = '\0';
+ partition = p + 1;
+ } else if (argv[i + 1] && argv[i + 1][0] >= '0'
+ && argv[i + 1][0] <= '9') {
+ partition = argv[++i];
+ }
+ } else {
+ error
+ ("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n");
+ goto bail;
+ }
+ }
+
+ if (opt.seg) {
+ regs.es = regs.cs = regs.ss = regs.ds = regs.fs = regs.gs = opt.seg;
+ } else {
+ regs.ip = regs.esp.l = 0x7c00;
+ }
+
+ hd = 0;
+ if (!strncmp(drivename, "mbr", 3)) {
+ drive = find_disk(strtoul(drivename + 4, NULL, 0));
+ if (drive == -1) {
+ error("Unable to find requested MBR signature\n");
+ goto bail;
+ }
+ } else if ((drivename[0] == 'h' || drivename[0] == 'f') &&
+ drivename[1] == 'd') {
+ hd = drivename[0] == 'h';
+ drivename += 2;
+ drive = (hd ? 0x80 : 0) | strtoul(drivename, NULL, 0);
+ } else if (!strcmp(drivename, "boot")) {
+ const union syslinux_derivative_info *sdi;
+ sdi = syslinux_derivative_info();
+ if (sdi->c.filesystem == SYSLINUX_FS_PXELINUX)
+ drive = 0x80; /* Boot drive not available */
+ else
+ drive = sdi->disk.drive_number;
} else {
- error("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n");
- goto bail;
+ error("Unparsable drive specification\n");
+ goto bail;
}
- }
-
- if (opt.seg) {
- regs.es = regs.cs = regs.ss = regs.ds = regs.fs = regs.gs = opt.seg;
- } else {
- regs.ip = regs.esp.l = 0x7c00;
- }
-
- drivename = argv[1];
- partition = argv[2]; /* Possibly null */
-
- hd = 0;
- if ( !strncmp(drivename, "mbr", 3) ) {
- drive = find_disk(strtoul(drivename+4, NULL, 0));
- if (drive == -1) {
- error("Unable to find requested MBR signature\n");
- goto bail;
+
+ /* DOS kernels want the drive number in BL instead of DL. Indulge them. */
+ regs.ebx.b[0] = regs.edx.b[0] = drive;
+
+ whichpart = 0; /* Default */
+
+ if (partition)
+ whichpart = strtoul(partition, NULL, 0);
+
+ if (!(drive & 0x80) && whichpart) {
+ error("Warning: Partitions of floppy devices may not work\n");
}
- } else if ((drivename[0] == 'h' || drivename[0] == 'f') &&
- drivename[1] == 'd') {
- hd = drivename[0] == 'h';
- drivename += 2;
- drive = (hd ? 0x80 : 0) | strtoul(drivename, NULL, 0);
- } else if (!strcmp(drivename, "boot")) {
- const union syslinux_derivative_info *sdi;
- sdi = syslinux_derivative_info();
- if (sdi->c.filesystem == SYSLINUX_FS_PXELINUX ||
- sdi->c.filesystem == SYSLINUX_FS_ISOLINUX)
- drive = 0x80; /* Boot drive not available */
- else
- drive = sdi->disk.drive_number;
- } else {
- error("Unparsable drive specification\n");
- goto bail;
- }
-
- /* DOS kernels want the drive number in BL instead of DL. Indulge them. */
- regs.ebx.b[0] = regs.edx.b[0] = drive;
-
- whichpart = 0; /* Default */
-
- if ( partition )
- whichpart = strtoul(partition, NULL, 0);
-
- if ( !(drive & 0x80) && whichpart ) {
- error("Warning: Partitions of floppy devices may not work\n");
- }
-
- /* Get the disk geometry and disk access setup */
- if ( get_disk_params(drive) ) {
- error("Cannot get disk parameters\n");
- goto bail;
- }
-
- /* Get MBR */
- if ( !(mbr = read_sector(0)) ) {
- error("Cannot read Master Boot Record\n");
- goto bail;
- }
-
- if (opt.hide) {
- if (whichpart < 1 || whichpart > 4)
- error("WARNING: hide specified without a non-primary partition\n");
- if (hide_unhide(mbr, whichpart))
- error("WARNING: failed to write MBR for 'hide'\n");
- }
-
- if ( whichpart == 0 ) {
- /* Boot the MBR */
-
- partinfo = NULL;
- boot_sector = mbr;
- } else if ( whichpart <= 4 ) {
- /* Boot a primary partition */
-
- partinfo = &((struct part_entry *)(mbr + 0x1be))[whichpart-1];
- if ( partinfo->ostype == 0 ) {
- error("Invalid primary partition\n");
- goto bail;
+
+ /* Get the disk geometry and disk access setup */
+ if (get_disk_params(drive)) {
+ error("Cannot get disk parameters\n");
+ goto bail;
}
- } else {
- /* Boot a logical partition */
- nextpart = 5;
- partinfo = find_logical_partition(whichpart, mbr, NULL, NULL);
+ /* Get MBR */
+ if (!(mbr = read_sector(0))) {
+ error("Cannot read Master Boot Record\n");
+ goto bail;
+ }
- if ( !partinfo || partinfo->ostype == 0 ) {
- error("Requested logical partition not found\n");
- goto bail;
+ if (opt.hide) {
+ if (whichpart < 1 || whichpart > 4)
+ error("WARNING: hide specified without a non-primary partition\n");
+ if (hide_unhide(mbr, whichpart))
+ error("WARNING: failed to write MBR for 'hide'\n");
}
- }
-
- /* Do the actual chainloading */
- if (opt.loadfile) {
- fputs("Loading the boot file...\n", stdout);
- if ( loadfile(opt.loadfile, &boot_sector, &boot_size) ) {
- error("Failed to load the boot file\n");
- goto bail;
+
+ if (whichpart == 0) {
+ /* Boot the MBR */
+
+ partinfo = NULL;
+ boot_sector = mbr;
+ } else if (whichpart <= 4) {
+ /* Boot a primary partition */
+
+ partinfo = &((struct part_entry *)(mbr + 0x1be))[whichpart - 1];
+ if (partinfo->ostype == 0) {
+ error("Invalid primary partition\n");
+ goto bail;
+ }
+ } else {
+ /* Boot a logical partition */
+
+ nextpart = 5;
+ partinfo = find_logical_partition(whichpart, mbr, NULL, NULL);
+
+ if (!partinfo || partinfo->ostype == 0) {
+ error("Requested logical partition not found\n");
+ goto bail;
+ }
}
- } else if (partinfo) {
- /* Actually read the boot sector */
- /* Pick the first buffer that isn't already in use */
- if ( !(boot_sector = read_sector(partinfo->start_lba)) ) {
- error("Cannot read boot sector\n");
- goto bail;
+
+ /* Do the actual chainloading */
+ if (opt.loadfile) {
+ fputs("Loading the boot file...\n", stdout);
+ if (loadfile(opt.loadfile, &boot_sector, &boot_size)) {
+ error("Failed to load the boot file\n");
+ goto bail;
+ }
+ } else if (partinfo) {
+ /* Actually read the boot sector */
+ /* Pick the first buffer that isn't already in use */
+ if (!(boot_sector = read_sector(partinfo->start_lba))) {
+ error("Cannot read boot sector\n");
+ goto bail;
+ }
}
- }
- if (!opt.loadfile) {
- if (*(uint16_t *)((char *)boot_sector+boot_size-2) != 0xaa55) {
- error("Boot sector signature not found (unbootable disk/partition?)\n");
- goto bail;
+ if (!opt.loadfile) {
+ if (*(uint16_t *) ((char *)boot_sector + boot_size - 2) != 0xaa55) {
+ error
+ ("Boot sector signature not found (unbootable disk/partition?)\n");
+ goto bail;
+ }
}
- }
- if (partinfo) {
- /* 0x7BE is the canonical place for the first partition entry. */
- regs.esi.w[0] = 0x7be;
- memcpy((char *)0x7be, partinfo, sizeof(*partinfo));
- }
+ if (partinfo) {
+ /* 0x7BE is the canonical place for the first partition entry. */
+ regs.esi.w[0] = 0x7be;
+ memcpy((char *)0x7be, partinfo, sizeof(*partinfo));
+ }
- do_boot(boot_sector, boot_size, &regs);
+ do_boot(boot_sector, boot_size, &regs);
bail:
- return 255;
+ return 255;
}
diff --git a/com32/modules/cmd.c b/com32/modules/cmd.c
index 1a7f0ffe..c614552c 100644
--- a/com32/modules/cmd.c
+++ b/com32/modules/cmd.c
@@ -20,6 +20,6 @@
int main(void)
{
- syslinux_run_command(__com32.cs_cmdline);
- return -1;
+ syslinux_run_command(__com32.cs_cmdline);
+ return -1;
}
diff --git a/com32/modules/config.c b/com32/modules/config.c
index 214e3eae..fb6cb867 100644
--- a/com32/modules/config.c
+++ b/com32/modules/config.c
@@ -24,15 +24,15 @@
int main(int argc, char *argv[])
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc != 2) {
- fprintf(stderr, "Usage: config <filename>\n");
- return 1;
- }
+ if (argc != 2) {
+ fprintf(stderr, "Usage: config <filename>\n");
+ return 1;
+ }
- syslinux_run_kernel_image(argv[1], "", 0, IMAGE_TYPE_CONFIG);
+ syslinux_run_kernel_image(argv[1], "", 0, IMAGE_TYPE_CONFIG);
- fprintf(stderr, "config: %s: failed to load (missing file?)\n", argv[1]);
- return 1;
+ fprintf(stderr, "config: %s: failed to load (missing file?)\n", argv[1]);
+ return 1;
}
diff --git a/com32/modules/cpuidtest.c b/com32/modules/cpuidtest.c
index cf07f207..bfc1c190 100644
--- a/com32/modules/cpuidtest.c
+++ b/com32/modules/cpuidtest.c
@@ -41,58 +41,94 @@ char display_line;
int main(void)
{
- s_cpu cpu;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ s_cpu cpu;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- for (;;) {
+ for (;;) {
detect_cpu(&cpu);
- printf("Vendor = %s\n",cpu.vendor);
- printf("Model = %s\n",cpu.model);
- printf("Vendor ID = %d\n",cpu.vendor_id);
- printf("Family = %d\n",cpu.family);
- printf("Model ID = %d\n",cpu.model_id);
- printf("Stepping = %d\n",cpu.stepping);
+ printf("Vendor = %s\n", cpu.vendor);
+ printf("Model = %s\n", cpu.model);
+ printf("Vendor ID = %d\n", cpu.vendor_id);
+ printf("Family = %d\n", cpu.family);
+ printf("Model ID = %d\n", cpu.model_id);
+ printf("Stepping = %d\n", cpu.stepping);
printf("Flags = ");
- if (cpu.flags.fpu) printf("fpu ");
- if (cpu.flags.vme) printf("vme ");
- if (cpu.flags.de) printf("de ");
- if (cpu.flags.pse) printf("pse ");
- if (cpu.flags.tsc) printf("tsc ");
- if (cpu.flags.msr) printf("msr ");
- if (cpu.flags.pae) printf("pae ");
- if (cpu.flags.mce) printf("mce ");
- if (cpu.flags.cx8) printf("cx8 ");
- if (cpu.flags.apic) printf("apic ");
- if (cpu.flags.sep) printf("sep ");
- if (cpu.flags.mtrr) printf("mtrr ");
- if (cpu.flags.pge) printf("pge ");
- if (cpu.flags.mca) printf("mca ");
- if (cpu.flags.cmov) printf("cmov ");
- if (cpu.flags.pat) printf("pat ");
- if (cpu.flags.pse_36) printf("pse_36 ");
- if (cpu.flags.psn) printf("psn ");
- if (cpu.flags.clflsh) printf("clflsh ");
- if (cpu.flags.dts) printf("dts ");
- if (cpu.flags.acpi) printf("acpi ");
- if (cpu.flags.mmx) printf("mmx ");
- if (cpu.flags.sse) printf("sse ");
- if (cpu.flags.sse2) printf("sse2 ");
- if (cpu.flags.ss) printf("ss ");
- if (cpu.flags.htt) printf("ht ");
- if (cpu.flags.acc) printf("acc ");
- if (cpu.flags.syscall) printf("syscall ");
- if (cpu.flags.mp) printf("mp ");
- if (cpu.flags.nx) printf("nx ");
- if (cpu.flags.mmxext) printf("mmxext ");
- if (cpu.flags.lm) printf("lm ");
- if (cpu.flags.nowext) printf("3dnowext ");
- if (cpu.flags.now) printf("3dnow! ");
+ if (cpu.flags.fpu)
+ printf("fpu ");
+ if (cpu.flags.vme)
+ printf("vme ");
+ if (cpu.flags.de)
+ printf("de ");
+ if (cpu.flags.pse)
+ printf("pse ");
+ if (cpu.flags.tsc)
+ printf("tsc ");
+ if (cpu.flags.msr)
+ printf("msr ");
+ if (cpu.flags.pae)
+ printf("pae ");
+ if (cpu.flags.mce)
+ printf("mce ");
+ if (cpu.flags.cx8)
+ printf("cx8 ");
+ if (cpu.flags.apic)
+ printf("apic ");
+ if (cpu.flags.sep)
+ printf("sep ");
+ if (cpu.flags.mtrr)
+ printf("mtrr ");
+ if (cpu.flags.pge)
+ printf("pge ");
+ if (cpu.flags.mca)
+ printf("mca ");
+ if (cpu.flags.cmov)
+ printf("cmov ");
+ if (cpu.flags.pat)
+ printf("pat ");
+ if (cpu.flags.pse_36)
+ printf("pse_36 ");
+ if (cpu.flags.psn)
+ printf("psn ");
+ if (cpu.flags.clflsh)
+ printf("clflsh ");
+ if (cpu.flags.dts)
+ printf("dts ");
+ if (cpu.flags.acpi)
+ printf("acpi ");
+ if (cpu.flags.mmx)
+ printf("mmx ");
+ if (cpu.flags.sse)
+ printf("sse ");
+ if (cpu.flags.sse2)
+ printf("sse2 ");
+ if (cpu.flags.ss)
+ printf("ss ");
+ if (cpu.flags.htt)
+ printf("ht ");
+ if (cpu.flags.acc)
+ printf("acc ");
+ if (cpu.flags.syscall)
+ printf("syscall ");
+ if (cpu.flags.mp)
+ printf("mp ");
+ if (cpu.flags.nx)
+ printf("nx ");
+ if (cpu.flags.mmxext)
+ printf("mmxext ");
+ if (cpu.flags.lm)
+ printf("lm ");
+ if (cpu.flags.nowext)
+ printf("3dnowext ");
+ if (cpu.flags.now)
+ printf("3dnow! ");
printf("\n");
printf("SMP = ");
- if (cpu.flags.smp) printf("yes\n");
- else printf("no\n");
+ if (cpu.flags.smp)
+ printf("yes\n");
+ else
+ printf("no\n");
break;
- }
+ }
- return 0;
+ return 0;
}
diff --git a/com32/modules/dmi_utils.c b/com32/modules/dmi_utils.c
index e0baa873..93cb265c 100644
--- a/com32/modules/dmi_utils.c
+++ b/com32/modules/dmi_utils.c
@@ -29,40 +29,43 @@
#include "stdio.h"
#include "dmi/dmi.h"
-void display_bios_characteristics(s_dmi *dmi) {
-int i;
- for (i=0;i<BIOS_CHAR_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_strings[i]);
- }
- }
- for (i=0;i<BIOS_CHAR_X1_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics_x1))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_x1_strings[i]);
- }
- }
+void display_bios_characteristics(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < BIOS_CHAR_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_strings[i]);
+ }
+ }
+ for (i = 0; i < BIOS_CHAR_X1_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics_x1))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_x1_strings[i]);
+ }
+ }
- for (i=0;i<BIOS_CHAR_X2_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->bios.characteristics_x2))[i] == true) {
- moreprintf("\t\t%s\n", bios_charac_x2_strings[i]);
- }
- }
+ for (i = 0; i < BIOS_CHAR_X2_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->bios.characteristics_x2))[i] == true) {
+ moreprintf("\t\t%s\n", bios_charac_x2_strings[i]);
+ }
+ }
}
-void display_base_board_features(s_dmi *dmi) {
-int i;
- for (i=0;i<BASE_BOARD_NB_ELEMENTS; i++) {
- if (((bool *)(& dmi->base_board.features))[i] == true) {
- moreprintf("\t\t%s\n", base_board_features_strings[i]);
- }
- }
+void display_base_board_features(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < BASE_BOARD_NB_ELEMENTS; i++) {
+ if (((bool *) (&dmi->base_board.features))[i] == true) {
+ moreprintf("\t\t%s\n", base_board_features_strings[i]);
+ }
+ }
}
-void display_processor_flags(s_dmi *dmi) {
-int i;
- for (i=0;i<PROCESSOR_FLAGS_ELEMENTS; i++) {
- if (((bool *)(& dmi->processor.cpu_flags))[i] == true) {
- moreprintf("\t\t%s\n", cpu_flags_strings[i]);
- }
- }
+void display_processor_flags(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < PROCESSOR_FLAGS_ELEMENTS; i++) {
+ if (((bool *) (&dmi->processor.cpu_flags))[i] == true) {
+ moreprintf("\t\t%s\n", cpu_flags_strings[i]);
+ }
+ }
}
diff --git a/com32/modules/dmitest.c b/com32/modules/dmitest.c
index 07febc51..d85b3127 100644
--- a/com32/modules/dmitest.c
+++ b/com32/modules/dmitest.c
@@ -39,164 +39,177 @@
char display_line;
-void display_memory(s_dmi *dmi) {
- int i;
- for (i=0;i<dmi->memory_count;i++) {
- moreprintf("Memory Bank %d\n",i);
- moreprintf("\tForm Factor : %s\n",dmi->memory[i].form_factor);
- moreprintf("\tType : %s\n",dmi->memory[i].type);
- moreprintf("\tType Detail : %s\n",dmi->memory[i].type_detail);
- moreprintf("\tSpeed : %s\n",dmi->memory[i].speed);
- moreprintf("\tSize : %s\n",dmi->memory[i].size);
- moreprintf("\tDevice Set : %s\n",dmi->memory[i].device_set);
- moreprintf("\tDevice Loc. : %s\n",dmi->memory[i].device_locator);
- moreprintf("\tBank Locator : %s\n",dmi->memory[i].bank_locator);
- moreprintf("\tTotal Width : %s\n",dmi->memory[i].total_width);
- moreprintf("\tData Width : %s\n",dmi->memory[i].data_width);
- moreprintf("\tError : %s\n",dmi->memory[i].error);
- moreprintf("\tVendor : %s\n",dmi->memory[i].manufacturer);
- moreprintf("\tSerial : %s\n",dmi->memory[i].serial);
- moreprintf("\tAsset Tag : %s\n",dmi->memory[i].asset_tag);
- moreprintf("\tPart Number : %s\n",dmi->memory[i].part_number);
- }
+void display_memory(s_dmi * dmi)
+{
+ int i;
+ for (i = 0; i < dmi->memory_count; i++) {
+ moreprintf("Memory Bank %d\n", i);
+ moreprintf("\tForm Factor : %s\n", dmi->memory[i].form_factor);
+ moreprintf("\tType : %s\n", dmi->memory[i].type);
+ moreprintf("\tType Detail : %s\n", dmi->memory[i].type_detail);
+ moreprintf("\tSpeed : %s\n", dmi->memory[i].speed);
+ moreprintf("\tSize : %s\n", dmi->memory[i].size);
+ moreprintf("\tDevice Set : %s\n", dmi->memory[i].device_set);
+ moreprintf("\tDevice Loc. : %s\n", dmi->memory[i].device_locator);
+ moreprintf("\tBank Locator : %s\n", dmi->memory[i].bank_locator);
+ moreprintf("\tTotal Width : %s\n", dmi->memory[i].total_width);
+ moreprintf("\tData Width : %s\n", dmi->memory[i].data_width);
+ moreprintf("\tError : %s\n", dmi->memory[i].error);
+ moreprintf("\tVendor : %s\n", dmi->memory[i].manufacturer);
+ moreprintf("\tSerial : %s\n", dmi->memory[i].serial);
+ moreprintf("\tAsset Tag : %s\n", dmi->memory[i].asset_tag);
+ moreprintf("\tPart Number : %s\n", dmi->memory[i].part_number);
+ }
}
-void display_battery(s_dmi *dmi) {
- moreprintf("Battery\n");
- moreprintf("\tVendor : %s\n",dmi->battery.manufacturer);
- moreprintf("\tManufacture Date : %s\n",dmi->battery.manufacture_date);
- moreprintf("\tSerial : %s\n",dmi->battery.serial);
- moreprintf("\tName : %s\n",dmi->battery.name);
- moreprintf("\tChemistry : %s\n",dmi->battery.chemistry);
- moreprintf("\tDesign Capacity : %s\n",dmi->battery.design_capacity);
- moreprintf("\tDesign Voltage : %s\n",dmi->battery.design_voltage);
- moreprintf("\tSBDS : %s\n",dmi->battery.sbds);
- moreprintf("\tSBDS Manufact. Date : %s\n",dmi->battery.sbds_manufacture_date);
- moreprintf("\tSBDS Chemistry : %s\n",dmi->battery.sbds_chemistry);
- moreprintf("\tMaximum Error : %s\n",dmi->battery.maximum_error);
- moreprintf("\tOEM Info : %s\n",dmi->battery.oem_info);
+void display_battery(s_dmi * dmi)
+{
+ moreprintf("Battery\n");
+ moreprintf("\tVendor : %s\n", dmi->battery.manufacturer);
+ moreprintf("\tManufacture Date : %s\n", dmi->battery.manufacture_date);
+ moreprintf("\tSerial : %s\n", dmi->battery.serial);
+ moreprintf("\tName : %s\n", dmi->battery.name);
+ moreprintf("\tChemistry : %s\n", dmi->battery.chemistry);
+ moreprintf("\tDesign Capacity : %s\n", dmi->battery.design_capacity);
+ moreprintf("\tDesign Voltage : %s\n", dmi->battery.design_voltage);
+ moreprintf("\tSBDS : %s\n", dmi->battery.sbds);
+ moreprintf("\tSBDS Manufact. Date : %s\n",
+ dmi->battery.sbds_manufacture_date);
+ moreprintf("\tSBDS Chemistry : %s\n", dmi->battery.sbds_chemistry);
+ moreprintf("\tMaximum Error : %s\n", dmi->battery.maximum_error);
+ moreprintf("\tOEM Info : %s\n", dmi->battery.oem_info);
}
-void display_bios(s_dmi *dmi) {
- moreprintf("BIOS\n");
- moreprintf("\tVendor: %s\n",dmi->bios.vendor);
- moreprintf("\tVersion: %s\n",dmi->bios.version);
- moreprintf("\tRelease: %s\n",dmi->bios.release_date);
- moreprintf("\tBios Revision %s\n",dmi->bios.bios_revision);
- moreprintf("\tFirmware Revision %s\n",dmi->bios.firmware_revision);
- moreprintf("\tAddress: 0x%04X0\n",dmi->bios.address);
- moreprintf("\tRuntime address: %u %s\n",dmi->bios.runtime_size,dmi->bios.runtime_size_unit);
- moreprintf("\tRom size: %u %s\n",dmi->bios.rom_size,dmi->bios.rom_size_unit);
- display_bios_characteristics(dmi);
+void display_bios(s_dmi * dmi)
+{
+ moreprintf("BIOS\n");
+ moreprintf("\tVendor: %s\n", dmi->bios.vendor);
+ moreprintf("\tVersion: %s\n", dmi->bios.version);
+ moreprintf("\tRelease: %s\n", dmi->bios.release_date);
+ moreprintf("\tBios Revision %s\n", dmi->bios.bios_revision);
+ moreprintf("\tFirmware Revision %s\n", dmi->bios.firmware_revision);
+ moreprintf("\tAddress: 0x%04X0\n", dmi->bios.address);
+ moreprintf("\tRuntime address: %u %s\n", dmi->bios.runtime_size,
+ dmi->bios.runtime_size_unit);
+ moreprintf("\tRom size: %u %s\n", dmi->bios.rom_size,
+ dmi->bios.rom_size_unit);
+ display_bios_characteristics(dmi);
}
-void display_system(s_dmi *dmi) {
- moreprintf("\nSystem\n");
- moreprintf("\tManufacturer %s\n",dmi->system.manufacturer);
- moreprintf("\tProduct Name %s\n",dmi->system.product_name);
- moreprintf("\tVersion %s\n",dmi->system.version);
- moreprintf("\tSerial %s\n",dmi->system.serial);
- moreprintf("\tUUID %s\n",dmi->system.uuid);
- moreprintf("\tWakeup Type %s\n",dmi->system.wakeup_type);
- moreprintf("\tSKU Number %s\n",dmi->system.sku_number);
- moreprintf("\tFamily %s\n",dmi->system.family);
+void display_system(s_dmi * dmi)
+{
+ moreprintf("\nSystem\n");
+ moreprintf("\tManufacturer %s\n", dmi->system.manufacturer);
+ moreprintf("\tProduct Name %s\n", dmi->system.product_name);
+ moreprintf("\tVersion %s\n", dmi->system.version);
+ moreprintf("\tSerial %s\n", dmi->system.serial);
+ moreprintf("\tUUID %s\n", dmi->system.uuid);
+ moreprintf("\tWakeup Type %s\n", dmi->system.wakeup_type);
+ moreprintf("\tSKU Number %s\n", dmi->system.sku_number);
+ moreprintf("\tFamily %s\n", dmi->system.family);
}
-void display_base_board(s_dmi *dmi) {
- moreprintf("Base board\n");
- moreprintf("\tManufacturer %s\n",dmi->base_board.manufacturer);
- moreprintf("\tProduct Name %s\n",dmi->base_board.product_name);
- moreprintf("\tVersion %s\n",dmi->base_board.version);
- moreprintf("\tSerial %s\n",dmi->base_board.serial);
- moreprintf("\tAsset Tag %s\n",dmi->base_board.asset_tag);
- moreprintf("\tLocation %s\n",dmi->base_board.location);
- moreprintf("\tType %s\n",dmi->base_board.type);
- display_base_board_features(dmi);
+void display_base_board(s_dmi * dmi)
+{
+ moreprintf("Base board\n");
+ moreprintf("\tManufacturer %s\n", dmi->base_board.manufacturer);
+ moreprintf("\tProduct Name %s\n", dmi->base_board.product_name);
+ moreprintf("\tVersion %s\n", dmi->base_board.version);
+ moreprintf("\tSerial %s\n", dmi->base_board.serial);
+ moreprintf("\tAsset Tag %s\n", dmi->base_board.asset_tag);
+ moreprintf("\tLocation %s\n", dmi->base_board.location);
+ moreprintf("\tType %s\n", dmi->base_board.type);
+ display_base_board_features(dmi);
}
-void display_chassis(s_dmi *dmi) {
- moreprintf("\nChassis\n");
- moreprintf("\tManufacturer %s\n",dmi->chassis.manufacturer);
- moreprintf("\tType %s\n",dmi->chassis.type);
- moreprintf("\tLock %s\n",dmi->chassis.lock);
- moreprintf("\tVersion %s\n",dmi->chassis.version);
- moreprintf("\tSerial %s\n",dmi->chassis.serial);
- moreprintf("\tAsset Tag %s\n",dmi->chassis.asset_tag);
- moreprintf("\tBoot up state %s\n",dmi->chassis.boot_up_state);
- moreprintf("\tPower supply state %s\n",dmi->chassis.power_supply_state);
- moreprintf("\tThermal state %s\n",dmi->chassis.thermal_state);
- moreprintf("\tSecurity Status %s\n",dmi->chassis.security_status);
- moreprintf("\tOEM Information %s\n",dmi->chassis.oem_information);
- moreprintf("\tHeight %u\n",dmi->chassis.height);
- moreprintf("\tNB Power Cords %u\n",dmi->chassis.nb_power_cords);
+void display_chassis(s_dmi * dmi)
+{
+ moreprintf("\nChassis\n");
+ moreprintf("\tManufacturer %s\n", dmi->chassis.manufacturer);
+ moreprintf("\tType %s\n", dmi->chassis.type);
+ moreprintf("\tLock %s\n", dmi->chassis.lock);
+ moreprintf("\tVersion %s\n", dmi->chassis.version);
+ moreprintf("\tSerial %s\n", dmi->chassis.serial);
+ moreprintf("\tAsset Tag %s\n", dmi->chassis.asset_tag);
+ moreprintf("\tBoot up state %s\n", dmi->chassis.boot_up_state);
+ moreprintf("\tPower supply state %s\n", dmi->chassis.power_supply_state);
+ moreprintf("\tThermal state %s\n", dmi->chassis.thermal_state);
+ moreprintf("\tSecurity Status %s\n", dmi->chassis.security_status);
+ moreprintf("\tOEM Information %s\n", dmi->chassis.oem_information);
+ moreprintf("\tHeight %u\n", dmi->chassis.height);
+ moreprintf("\tNB Power Cords %u\n", dmi->chassis.nb_power_cords);
}
-void display_cpu(s_dmi *dmi) {
- moreprintf("\nCPU\n");
- moreprintf("\tSocket Designation %s\n",dmi->processor.socket_designation);
- moreprintf("\tType %s\n",dmi->processor.type);
- moreprintf("\tFamily %s\n",dmi->processor.family);
- moreprintf("\tManufacturer %s\n",dmi->processor.manufacturer);
- moreprintf("\tVersion %s\n",dmi->processor.version);
- moreprintf("\tExternal Clock %u\n",dmi->processor.external_clock);
- moreprintf("\tMax Speed %u\n",dmi->processor.max_speed);
- moreprintf("\tCurrent Speed %u\n",dmi->processor.current_speed);
- moreprintf("\tCpu Type %u\n",dmi->processor.signature.type);
- moreprintf("\tCpu Family %u\n",dmi->processor.signature.family);
- moreprintf("\tCpu Model %u\n",dmi->processor.signature.model);
- moreprintf("\tCpu Stepping %u\n",dmi->processor.signature.stepping);
- moreprintf("\tCpu Minor Stepping %u\n",dmi->processor.signature.minor_stepping);
- moreprintf("\tVoltage %f\n",dmi->processor.voltage);
- moreprintf("\tStatus %s\n",dmi->processor.status);
- moreprintf("\tUpgrade %s\n",dmi->processor.upgrade);
- moreprintf("\tCache L1 Handle %s\n",dmi->processor.cache1);
- moreprintf("\tCache L2 Handle %s\n",dmi->processor.cache2);
- moreprintf("\tCache L3 Handle %s\n",dmi->processor.cache3);
- moreprintf("\tSerial %s\n",dmi->processor.serial);
- moreprintf("\tPart Number %s\n",dmi->processor.part_number);
- moreprintf("\tID %s\n",dmi->processor.id);
- display_processor_flags(dmi);
+void display_cpu(s_dmi * dmi)
+{
+ moreprintf("\nCPU\n");
+ moreprintf("\tSocket Designation %s\n", dmi->processor.socket_designation);
+ moreprintf("\tType %s\n", dmi->processor.type);
+ moreprintf("\tFamily %s\n", dmi->processor.family);
+ moreprintf("\tManufacturer %s\n", dmi->processor.manufacturer);
+ moreprintf("\tVersion %s\n", dmi->processor.version);
+ moreprintf("\tExternal Clock %u\n", dmi->processor.external_clock);
+ moreprintf("\tMax Speed %u\n", dmi->processor.max_speed);
+ moreprintf("\tCurrent Speed %u\n", dmi->processor.current_speed);
+ moreprintf("\tCpu Type %u\n", dmi->processor.signature.type);
+ moreprintf("\tCpu Family %u\n", dmi->processor.signature.family);
+ moreprintf("\tCpu Model %u\n", dmi->processor.signature.model);
+ moreprintf("\tCpu Stepping %u\n", dmi->processor.signature.stepping);
+ moreprintf("\tCpu Minor Stepping %u\n",
+ dmi->processor.signature.minor_stepping);
+ moreprintf("\tVoltage %f\n", dmi->processor.voltage);
+ moreprintf("\tStatus %s\n", dmi->processor.status);
+ moreprintf("\tUpgrade %s\n", dmi->processor.upgrade);
+ moreprintf("\tCache L1 Handle %s\n", dmi->processor.cache1);
+ moreprintf("\tCache L2 Handle %s\n", dmi->processor.cache2);
+ moreprintf("\tCache L3 Handle %s\n", dmi->processor.cache3);
+ moreprintf("\tSerial %s\n", dmi->processor.serial);
+ moreprintf("\tPart Number %s\n", dmi->processor.part_number);
+ moreprintf("\tID %s\n", dmi->processor.id);
+ display_processor_flags(dmi);
}
int main(void)
{
- char buffer[1024];
- s_dmi dmi;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ char buffer[1024];
+ s_dmi dmi;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- if (dmi_iterate(&dmi) == -ENODMITABLE) {
+ if (dmi_iterate(&dmi) == -ENODMITABLE) {
printf("No DMI Structure found\n");
return -1;
- } else {
- printf("DMI %d.%d present.\n",dmi.dmitable.major_version,dmi.dmitable.minor_version);
- printf("%d structures occupying %d bytes.\n",dmi.dmitable.num, dmi.dmitable.len);
- printf("DMI table at 0x%08X.\n",dmi.dmitable.base);
- }
-
+ } else {
+ printf("DMI %d.%d present.\n", dmi.dmitable.major_version,
+ dmi.dmitable.minor_version);
+ printf("%d structures occupying %d bytes.\n", dmi.dmitable.num,
+ dmi.dmitable.len);
+ printf("DMI table at 0x%08X.\n", dmi.dmitable.base);
+ }
- parse_dmitable(&dmi);
+ parse_dmitable(&dmi);
- for (;;) {
- printf("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n");
- printf("dmi: ");
- fgets(buffer, sizeof buffer, stdin);
- if ( !strncmp(buffer, "exit", 4) )
- break;
- if ( !strncmp(buffer, "system", 6) )
+ for (;;) {
+ printf
+ ("Available commands are system, chassis, base_board, cpu, bios, memory, battery, all, exit\n");
+ printf("dmi: ");
+ fgets(buffer, sizeof buffer, stdin);
+ if (!strncmp(buffer, "exit", 4))
+ break;
+ if (!strncmp(buffer, "system", 6))
display_system(&dmi);
- if ( !strncmp(buffer, "chassis", 6) )
+ if (!strncmp(buffer, "chassis", 6))
display_chassis(&dmi);
- if ( !strncmp(buffer, "base_board", 10) )
+ if (!strncmp(buffer, "base_board", 10))
display_base_board(&dmi);
- if ( !strncmp(buffer, "cpu", 3) )
+ if (!strncmp(buffer, "cpu", 3))
display_cpu(&dmi);
- if ( !strncmp(buffer, "bios", 4) )
+ if (!strncmp(buffer, "bios", 4))
display_bios(&dmi);
- if ( !strncmp(buffer, "memory", 6) )
+ if (!strncmp(buffer, "memory", 6))
display_memory(&dmi);
- if ( !strncmp(buffer, "battery", 7) )
+ if (!strncmp(buffer, "battery", 7))
display_battery(&dmi);
- if ( !strncmp(buffer, "all", 3) ) {
+ if (!strncmp(buffer, "all", 3)) {
display_bios(&dmi);
display_system(&dmi);
display_chassis(&dmi);
@@ -204,8 +217,8 @@ int main(void)
display_cpu(&dmi);
display_memory(&dmi);
display_battery(&dmi);
+ }
}
- }
- return 0;
+ return 0;
}
diff --git a/com32/modules/elf.c b/com32/modules/elf.c
index 9e4a18c7..d53d936c 100644
--- a/com32/modules/elf.c
+++ b/com32/modules/elf.c
@@ -59,234 +59,235 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int boot_elf(void *ptr, size_t len, char **argv)
{
- char *cptr = ptr;
- Elf32_Ehdr *eh = ptr;
- Elf32_Phdr *ph;
- unsigned int i;
- struct syslinux_movelist *ml = NULL;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_pm_regs regs;
- int argc;
- addr_t argsize;
- char **argp;
- addr_t lstart, llen;
- char *stack_frame = NULL;
- addr_t stack_frame_size;
- addr_t stack_pointer;
- uint32_t *spp;
- char *sfp;
- addr_t sfa;
-
- memset(&regs, 0, sizeof regs);
-
- /*
- * Note: mmap is the memory map (containing free and zeroed regions)
- * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
- * track ourselves which target memory ranges have already been
- * allocated.
- */
-
- if ( len < sizeof(Elf32_Ehdr) )
- goto bail;
-
- /* Must be ELF, 32-bit, littleendian, version 1 */
- if ( memcmp(eh->e_ident, "\x7f""ELF\1\1\1", 6) )
- goto bail;
-
- /* Is this a worthwhile test? In particular x86-64 normally
- would imply ELF64 support, which we could do as long as
- the addresses are 32-bit addresses, and entry is 32 bits.
- 64-bit addresses would take a lot more work. */
- if ( eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
- eh->e_machine != EM_X86_64 )
- goto bail;
-
- if ( eh->e_version != EV_CURRENT )
- goto bail;
-
- if ( eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len )
- goto bail;
-
- if ( eh->e_phentsize < sizeof(Elf32_Phdr) )
- goto bail;
-
- if ( !eh->e_phnum )
- goto bail;
-
- if ( eh->e_phoff+eh->e_phentsize*eh->e_phnum > len )
- goto bail;
-
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
+ char *cptr = ptr;
+ Elf32_Ehdr *eh = ptr;
+ Elf32_Phdr *ph;
+ unsigned int i;
+ struct syslinux_movelist *ml = NULL;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_pm_regs regs;
+ int argc;
+ addr_t argsize;
+ char **argp;
+ addr_t lstart, llen;
+ char *stack_frame = NULL;
+ addr_t stack_frame_size;
+ addr_t stack_pointer;
+ uint32_t *spp;
+ char *sfp;
+ addr_t sfa;
+
+ memset(&regs, 0, sizeof regs);
+
+ /*
+ * Note: mmap is the memory map (containing free and zeroed regions)
+ * needed by syslinux_shuffle_boot_pm(); amap is a map where we keep
+ * track ourselves which target memory ranges have already been
+ * allocated.
+ */
+
+ if (len < sizeof(Elf32_Ehdr))
+ goto bail;
-#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
-#endif
+ /* Must be ELF, 32-bit, littleendian, version 1 */
+ if (memcmp(eh->e_ident, "\x7f" "ELF\1\1\1", 6))
+ goto bail;
- ph = (Elf32_Phdr *)(cptr+eh->e_phoff);
+ /* Is this a worthwhile test? In particular x86-64 normally
+ would imply ELF64 support, which we could do as long as
+ the addresses are 32-bit addresses, and entry is 32 bits.
+ 64-bit addresses would take a lot more work. */
+ if (eh->e_machine != EM_386 && eh->e_machine != EM_486 &&
+ eh->e_machine != EM_X86_64)
+ goto bail;
- for (i = 0; i < eh->e_phnum; i++) {
- if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
- /* This loads at p_paddr, which is arguably the correct semantics.
- The SysV spec says that SysV loads at p_vaddr (and thus Linux does,
- too); that is, however, a major brainfuckage in the spec. */
- addr_t addr = ph->p_paddr;
- addr_t msize = ph->p_memsz;
- addr_t dsize = min(msize, ph->p_filesz);
+ if (eh->e_version != EV_CURRENT)
+ goto bail;
- dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
- addr, dsize, msize);
+ if (eh->e_ehsize < sizeof(Elf32_Ehdr) || eh->e_ehsize >= len)
+ goto bail;
- if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
- addr, msize);
- goto bail; /* Memory region unavailable */
- }
+ if (eh->e_phentsize < sizeof(Elf32_Phdr))
+ goto bail;
- /* Mark this region as allocated in the available map */
- if (syslinux_add_memmap(&amap, addr, dsize, SMT_ALLOC))
+ if (!eh->e_phnum)
goto bail;
- if (ph->p_filesz) {
- /* Data present region. Create a move entry for it. */
- if (syslinux_add_movelist(&ml, addr, (addr_t)cptr+ph->p_offset,
- dsize))
- goto bail;
- }
- if (msize > dsize) {
- /* Zero-filled region. Mark as a zero region in the memory map. */
- if (syslinux_add_memmap(&mmap, addr+dsize, msize-dsize, SMT_ZERO))
- goto bail;
- }
- } else {
- /* Ignore this program header */
- }
+ if (eh->e_phoff + eh->e_phentsize * eh->e_phnum > len)
+ goto bail;
- ph = (Elf32_Phdr *)((char *)ph + eh->e_phentsize);
- }
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
- /* Create the invocation record (initial stack frame) */
+#if DEBUG
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
+#endif
- argsize = argc = 0;
- for (argp = argv; *argp; argp++) {
- dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
- argc++;
- argsize += strlen(*argp)+1;
- }
+ ph = (Elf32_Phdr *) (cptr + eh->e_phoff);
+
+ for (i = 0; i < eh->e_phnum; i++) {
+ if (ph->p_type == PT_LOAD || ph->p_type == PT_PHDR) {
+ /* This loads at p_paddr, which is arguably the correct semantics.
+ The SysV spec says that SysV loads at p_vaddr (and thus Linux does,
+ too); that is, however, a major brainfuckage in the spec. */
+ addr_t addr = ph->p_paddr;
+ addr_t msize = ph->p_memsz;
+ addr_t dsize = min(msize, ph->p_filesz);
+
+ dprintf("Segment at 0x%08x data 0x%08x len 0x%08x\n",
+ addr, dsize, msize);
+
+ if (syslinux_memmap_type(amap, addr, msize) != SMT_FREE) {
+ printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ addr, msize);
+ goto bail; /* Memory region unavailable */
+ }
+
+ /* Mark this region as allocated in the available map */
+ if (syslinux_add_memmap(&amap, addr, dsize, SMT_ALLOC))
+ goto bail;
+
+ if (ph->p_filesz) {
+ /* Data present region. Create a move entry for it. */
+ if (syslinux_add_movelist
+ (&ml, addr, (addr_t) cptr + ph->p_offset, dsize))
+ goto bail;
+ }
+ if (msize > dsize) {
+ /* Zero-filled region. Mark as a zero region in the memory map. */
+ if (syslinux_add_memmap
+ (&mmap, addr + dsize, msize - dsize, SMT_ZERO))
+ goto bail;
+ }
+ } else {
+ /* Ignore this program header */
+ }
+
+ ph = (Elf32_Phdr *) ((char *)ph + eh->e_phentsize);
+ }
- /* We need the argument strings, argument pointers,
- argc, plus four zero-word terminators. */
- stack_frame_size = argsize + argc*sizeof(char *) + 5*sizeof(long);
- stack_frame_size = (stack_frame_size+15) & ~15;
- stack_frame = calloc(stack_frame_size, 1);
- if (!stack_frame)
- goto bail;
+ /* Create the invocation record (initial stack frame) */
+
+ argsize = argc = 0;
+ for (argp = argv; *argp; argp++) {
+ dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
+ argc++;
+ argsize += strlen(*argp) + 1;
+ }
+
+ /* We need the argument strings, argument pointers,
+ argc, plus four zero-word terminators. */
+ stack_frame_size = argsize + argc * sizeof(char *) + 5 * sizeof(long);
+ stack_frame_size = (stack_frame_size + 15) & ~15;
+ stack_frame = calloc(stack_frame_size, 1);
+ if (!stack_frame)
+ goto bail;
#if DEBUG
- dprintf("Right before syslinux_memmap_largest()...\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Right before syslinux_memmap_largest()...\n");
+ syslinux_dump_memmap(stdout, amap);
#endif
- if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
- goto bail; /* NO free memory?! */
+ if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
+ goto bail; /* NO free memory?! */
- if (llen < stack_frame_size+MIN_STACK+16)
- goto bail; /* Insufficient memory */
+ if (llen < stack_frame_size + MIN_STACK + 16)
+ goto bail; /* Insufficient memory */
- /* Initial stack pointer address */
- stack_pointer = (lstart+llen-stack_frame_size) & ~15;
+ /* Initial stack pointer address */
+ stack_pointer = (lstart + llen - stack_frame_size) & ~15;
- dprintf("Stack frame at 0x%08x len 0x%08x\n",
- stack_pointer, stack_frame_size);
+ dprintf("Stack frame at 0x%08x len 0x%08x\n",
+ stack_pointer, stack_frame_size);
- /* Create the stack frame. sfp is the pointer in current memory for
- the next argument string, sfa is the address in its final resting place.
- spp is the pointer into the argument array in current memory. */
- spp = (uint32_t *)stack_frame;
- sfp = stack_frame + argc*sizeof(char *) + 5*sizeof(long);
- sfa = stack_pointer + argc*sizeof(char *) + 5*sizeof(long);
+ /* Create the stack frame. sfp is the pointer in current memory for
+ the next argument string, sfa is the address in its final resting place.
+ spp is the pointer into the argument array in current memory. */
+ spp = (uint32_t *) stack_frame;
+ sfp = stack_frame + argc * sizeof(char *) + 5 * sizeof(long);
+ sfa = stack_pointer + argc * sizeof(char *) + 5 * sizeof(long);
- *spp++ = argc;
- for (argp = argv; *argp; argp++) {
- int bytes = strlen(*argp) + 1; /* Including final null */
- *spp++ = sfa;
- memcpy(sfp, *argp, bytes);
- sfp += bytes;
- sfa += bytes;
- }
- /* Zero fields are aready taken care of by calloc() */
+ *spp++ = argc;
+ for (argp = argv; *argp; argp++) {
+ int bytes = strlen(*argp) + 1; /* Including final null */
+ *spp++ = sfa;
+ memcpy(sfp, *argp, bytes);
+ sfp += bytes;
+ sfa += bytes;
+ }
+ /* Zero fields are aready taken care of by calloc() */
- /* ... and we'll want to move it into the right place... */
+ /* ... and we'll want to move it into the right place... */
#if DEBUG
- if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
- != SMT_FREE) {
- dprintf("Stack frame area not free (how did that happen?)!\n");
- goto bail; /* Memory region unavailable */
- }
+ if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
+ != SMT_FREE) {
+ dprintf("Stack frame area not free (how did that happen?)!\n");
+ goto bail; /* Memory region unavailable */
+ }
#endif
- if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
- goto bail;
+ if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
+ goto bail;
- if (syslinux_add_movelist(&ml, stack_pointer, (addr_t)stack_frame,
- stack_frame_size))
- goto bail;
+ if (syslinux_add_movelist(&ml, stack_pointer, (addr_t) stack_frame,
+ stack_frame_size))
+ goto bail;
- memset(&regs, 0, sizeof regs);
- regs.eip = eh->e_entry;
- regs.esp = stack_pointer;
+ memset(&regs, 0, sizeof regs);
+ regs.eip = eh->e_entry;
+ regs.esp = stack_pointer;
#if DEBUG
- dprintf("Final memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Final memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
- dprintf("Final available map:\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Final available map:\n");
+ syslinux_dump_memmap(stdout, amap);
- dprintf("Movelist:\n");
- syslinux_dump_movelist(stdout, ml);
+ dprintf("Movelist:\n");
+ syslinux_dump_movelist(stdout, ml);
#endif
- /* This should not return... */
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
+ /* This should not return... */
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
- bail:
- if (stack_frame)
- free(stack_frame);
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
+bail:
+ if (stack_frame)
+ free(stack_frame);
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
- return -1;
+ return -1;
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
+ void *data;
+ size_t data_len;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 2) {
- error("Usage: elf.c32 elf_file arguments...\n");
- return 1;
- }
+ if (argc < 2) {
+ error("Usage: elf.c32 elf_file arguments...\n");
+ return 1;
+ }
- if (zloadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
- }
+ if (zloadfile(argv[1], &data, &data_len)) {
+ error("Unable to load file\n");
+ return 1;
+ }
- boot_elf(data, data_len, &argv[1]);
- error("Invalid ELF file or insufficient memory\n");
- return 1;
+ boot_elf(data, data_len, &argv[1]);
+ error("Invalid ELF file or insufficient memory\n");
+ return 1;
}
diff --git a/com32/modules/ethersel.c b/com32/modules/ethersel.c
index 9bd445c0..f586e836 100644
--- a/com32/modules/ethersel.c
+++ b/com32/modules/ethersel.c
@@ -44,13 +44,12 @@
# define dprintf(...) ((void)0)
#endif
-static char *
-skipspace(char *p)
+static char *skipspace(char *p)
{
- while ( *p && *p <= ' ' )
- p++;
+ while (*p && *p <= ' ')
+ p++;
- return p;
+ return p;
}
#define MAX_LINE 512
@@ -58,155 +57,154 @@ skipspace(char *p)
/* Check to see if we are at a certain keyword (case insensitive) */
static int looking_at(const char *line, const char *kwd)
{
- const char *p = line;
- const char *q = kwd;
+ const char *p = line;
+ const char *q = kwd;
- while ( *p && *q && ((*p^*q) & ~0x20) == 0 ) {
- p++;
- q++;
- }
+ while (*p && *q && ((*p ^ *q) & ~0x20) == 0) {
+ p++;
+ q++;
+ }
- if ( *q )
- return 0; /* Didn't see the keyword */
+ if (*q)
+ return 0; /* Didn't see the keyword */
- return *p <= ' '; /* Must be EOL or whitespace */
+ return *p <= ' '; /* Must be EOL or whitespace */
}
-static char *
-get_did(char *p, uint32_t *idptr, uint32_t *maskptr)
+static char *get_did(char *p, uint32_t * idptr, uint32_t * maskptr)
{
- unsigned long vid, did, m1, m2;
-
- *idptr = -1;
- *maskptr = 0xffffffff;
-
- vid = strtoul(p, &p, 16);
- if ( *p != ':' )
- return p; /* Bogus ID */
- did = strtoul(p+1, &p, 16);
-
- *idptr = (did << 16) + vid;
-
- if ( *p == '/' ) {
- m1 = strtoul(p+1, &p, 16);
- if ( *p != ':' ) {
- *maskptr = (m1 << 16) | 0xffff;
- } else {
- m2 = strtoul(p+1, &p, 16);
- *maskptr = (m1 << 16) | m2;
+ unsigned long vid, did, m1, m2;
+
+ *idptr = -1;
+ *maskptr = 0xffffffff;
+
+ vid = strtoul(p, &p, 16);
+ if (*p != ':')
+ return p; /* Bogus ID */
+ did = strtoul(p + 1, &p, 16);
+
+ *idptr = (did << 16) + vid;
+
+ if (*p == '/') {
+ m1 = strtoul(p + 1, &p, 16);
+ if (*p != ':') {
+ *maskptr = (m1 << 16) | 0xffff;
+ } else {
+ m2 = strtoul(p + 1, &p, 16);
+ *maskptr = (m1 << 16) | m2;
+ }
}
- }
- return p;
+ return p;
}
-static char *
-get_rid_range(char *p, uint8_t *rid_min, uint8_t *rid_max)
+static char *get_rid_range(char *p, uint8_t * rid_min, uint8_t * rid_max)
{
- unsigned long r0, r1;
+ unsigned long r0, r1;
- p = skipspace(p+3);
+ p = skipspace(p + 3);
- r0 = strtoul(p, &p, 16);
- if ( *p == '-' ) {
- r1 = strtoul(p+1, &p, 16);
- } else {
- r1 = r0;
- }
+ r0 = strtoul(p, &p, 16);
+ if (*p == '-') {
+ r1 = strtoul(p + 1, &p, 16);
+ } else {
+ r1 = r0;
+ }
- *rid_min = r0;
- *rid_max = r1;
+ *rid_min = r0;
+ *rid_max = r1;
- return p;
+ return p;
}
-static struct match *
-parse_config(const char *filename)
+static struct match *parse_config(const char *filename)
{
- char line[MAX_LINE], *p;
- FILE *f;
- struct match *list = NULL;
- struct match **ep = &list;
- struct match *m;
-
- if ( !filename )
- filename = syslinux_config_file();
-
- f = fopen(filename, "r");
- if ( !f )
- return list;
-
- while ( fgets(line, sizeof line, f) ) {
- p = skipspace(line);
-
- if ( !looking_at(p, "#") )
- continue;
- p = skipspace(p+1);
-
- if ( !looking_at(p, "dev") )
- continue;
- p = skipspace(p+3);
-
- m = malloc(sizeof(struct match));
- if ( !m )
- continue;
-
- memset(m, 0, sizeof *m);
- m->rid_max = 0xff;
-
- for(;;) {
- p = skipspace(p);
-
- if ( looking_at(p, "did") ) {
- p = get_did(p+3, &m->did, &m->did_mask);
- } else if ( looking_at(p, "sid") ) {
- p = get_did(p+3, &m->sid, &m->sid_mask);
- } else if ( looking_at(p, "rid") ) {
- p = get_rid_range(p+3, &m->rid_min, &m->rid_max);
- } else {
- char *e;
-
- e = strchr(p, '\n');
- if ( *e ) *e = '\0';
- e = strchr(p, '\r');
- if ( *e ) *e = '\0';
-
- m->filename = strdup(p);
- if ( !m->filename )
- m->did = -1;
- break; /* Done with this line */
- }
+ char line[MAX_LINE], *p;
+ FILE *f;
+ struct match *list = NULL;
+ struct match **ep = &list;
+ struct match *m;
+
+ if (!filename)
+ filename = syslinux_config_file();
+
+ f = fopen(filename, "r");
+ if (!f)
+ return list;
+
+ while (fgets(line, sizeof line, f)) {
+ p = skipspace(line);
+
+ if (!looking_at(p, "#"))
+ continue;
+ p = skipspace(p + 1);
+
+ if (!looking_at(p, "dev"))
+ continue;
+ p = skipspace(p + 3);
+
+ m = malloc(sizeof(struct match));
+ if (!m)
+ continue;
+
+ memset(m, 0, sizeof *m);
+ m->rid_max = 0xff;
+
+ for (;;) {
+ p = skipspace(p);
+
+ if (looking_at(p, "did")) {
+ p = get_did(p + 3, &m->did, &m->did_mask);
+ } else if (looking_at(p, "sid")) {
+ p = get_did(p + 3, &m->sid, &m->sid_mask);
+ } else if (looking_at(p, "rid")) {
+ p = get_rid_range(p + 3, &m->rid_min, &m->rid_max);
+ } else {
+ char *e;
+
+ e = strchr(p, '\n');
+ if (*e)
+ *e = '\0';
+ e = strchr(p, '\r');
+ if (*e)
+ *e = '\0';
+
+ m->filename = strdup(p);
+ if (!m->filename)
+ m->did = -1;
+ break; /* Done with this line */
+ }
+ }
+
+ dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n",
+ m->did, m->did_mask, m->sid, m->sid_mask,
+ m->rid_min, m->rid_max, m->filename);
+
+ *ep = m;
+ ep = &m->next;
}
- dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n",
- m->did, m->did_mask, m->sid, m->sid_mask,
- m->rid_min, m->rid_max, m->filename);
-
- *ep = m;
- ep = &m->next;
- }
-
- return list;
+ return list;
}
int main(int argc, char *argv[])
{
- struct match *list, *match;
- struct pci_domain *pci_domain;
+ struct match *list, *match;
+ struct pci_domain *pci_domain;
- openconsole(&dev_null_r, &dev_stdcon_w);
- pci_domain = pci_scan();
+ openconsole(&dev_null_r, &dev_stdcon_w);
+ pci_domain = pci_scan();
- if (pci_domain) {
- list = parse_config(argc < 2 ? NULL : argv[1]);
+ if (pci_domain) {
+ list = parse_config(argc < 2 ? NULL : argv[1]);
- match = find_pci_device(pci_domain, list);
+ match = find_pci_device(pci_domain, list);
- if ( match )
- syslinux_run_command(match->filename);
- }
+ if (match)
+ syslinux_run_command(match->filename);
+ }
- /* On error, return to the command line */
- fputs("Error: no recognized network card found!\n", stderr);
- return 1;
+ /* On error, return to the command line */
+ fputs("Error: no recognized network card found!\n", stderr);
+ return 1;
}
diff --git a/com32/modules/i386-elf.h b/com32/modules/i386-elf.h
deleted file mode 100644
index 04ddf391..00000000
--- a/com32/modules/i386-elf.h
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2001,2002 Free Software Foundation, Inc.
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/* 32-bit data types */
-
-typedef unsigned long Elf32_Addr;
-typedef unsigned short Elf32_Half;
-typedef unsigned long Elf32_Off;
-typedef signed long Elf32_Sword;
-typedef unsigned long Elf32_Word;
-/* "unsigned char" already exists */
-
-/* ELF header */
-typedef struct
-{
-
-#define EI_NIDENT 16
-
- /* first four characters are defined below */
-#define EI_MAG0 0
-#define ELFMAG0 0x7f
-#define EI_MAG1 1
-#define ELFMAG1 'E'
-#define EI_MAG2 2
-#define ELFMAG2 'L'
-#define EI_MAG3 3
-#define ELFMAG3 'F'
-
-#define EI_CLASS 4 /* data sizes */
-#define ELFCLASS32 1 /* i386 -- up to 32-bit data sizes present */
-
-#define EI_DATA 5 /* data type and ordering */
-#define ELFDATA2LSB 1 /* i386 -- LSB 2's complement */
-
-#define EI_VERSION 6 /* version number. "e_version" must be the same */
-#define EV_CURRENT 1 /* current version number */
-
-#define EI_OSABI 7 /* operating system/ABI indication */
-#define ELFOSABI_FREEBSD 9
-
-#define EI_ABIVERSION 8 /* ABI version */
-
-#define EI_PAD 9 /* from here in is just padding */
-
-#define EI_BRAND 8 /* start of OS branding (This is
- obviously illegal against the ELF
- standard.) */
-
- unsigned char e_ident[EI_NIDENT]; /* basic identification block */
-
-#define ET_EXEC 2 /* we only care about executable types */
- Elf32_Half e_type; /* file types */
-
-#define EM_386 3 /* i386 -- obviously use this one */
- Elf32_Half e_machine; /* machine types */
- Elf32_Word e_version; /* use same as "EI_VERSION" above */
- Elf32_Addr e_entry; /* entry point of the program */
- Elf32_Off e_phoff; /* program header table file offset */
- Elf32_Off e_shoff; /* section header table file offset */
- Elf32_Word e_flags; /* flags */
- Elf32_Half e_ehsize; /* elf header size in bytes */
- Elf32_Half e_phentsize; /* program header entry size */
- Elf32_Half e_phnum; /* number of entries in program header */
- Elf32_Half e_shentsize; /* section header entry size */
- Elf32_Half e_shnum; /* number of entries in section header */
-
-#define SHN_UNDEF 0
-#define SHN_LORESERVE 0xff00
-#define SHN_LOPROC 0xff00
-#define SHN_HIPROC 0xff1f
-#define SHN_ABS 0xfff1
-#define SHN_COMMON 0xfff2
-#define SHN_HIRESERVE 0xffff
- Elf32_Half e_shstrndx; /* section header table index */
-}
-Elf32_Ehdr;
-
-
-#define BOOTABLE_I386_ELF(h) \
- ((h.e_ident[EI_MAG0] == ELFMAG0) & (h.e_ident[EI_MAG1] == ELFMAG1) \
- & (h.e_ident[EI_MAG2] == ELFMAG2) & (h.e_ident[EI_MAG3] == ELFMAG3) \
- & (h.e_ident[EI_CLASS] == ELFCLASS32) & (h.e_ident[EI_DATA] == ELFDATA2LSB) \
- & (h.e_ident[EI_VERSION] == EV_CURRENT) & (h.e_type == ET_EXEC) \
- & (h.e_machine == EM_386) & (h.e_version == EV_CURRENT))
-
-/* section table - ? */
-typedef struct
-{
- Elf32_Word sh_name; /* Section name (string tbl index) */
- Elf32_Word sh_type; /* Section type */
- Elf32_Word sh_flags; /* Section flags */
- Elf32_Addr sh_addr; /* Section virtual addr at execution */
- Elf32_Off sh_offset; /* Section file offset */
- Elf32_Word sh_size; /* Section size in bytes */
- Elf32_Word sh_link; /* Link to another section */
- Elf32_Word sh_info; /* Additional section information */
- Elf32_Word sh_addralign; /* Section alignment */
- Elf32_Word sh_entsize; /* Entry size if section holds table */
-}
-Elf32_Shdr;
-
-/* symbol table - page 4-25, figure 4-15 */
-typedef struct
-{
- Elf32_Word st_name;
- Elf32_Addr st_value;
- Elf32_Word st_size;
- unsigned char st_info;
- unsigned char st_other;
- Elf32_Half st_shndx;
-}
-Elf32_Sym;
-
-/* symbol type and binding attributes - page 4-26 */
-
-#define ELF32_ST_BIND(i) ((i) >> 4)
-#define ELF32_ST_TYPE(i) ((i) & 0xf)
-#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
-
-/* symbol binding - page 4-26, figure 4-16 */
-
-#define STB_LOCAL 0
-#define STB_GLOBAL 1
-#define STB_WEAK 2
-#define STB_LOPROC 13
-#define STB_HIPROC 15
-
-/* symbol types - page 4-28, figure 4-17 */
-
-#define STT_NOTYPE 0
-#define STT_OBJECT 1
-#define STT_FUNC 2
-#define STT_SECTION 3
-#define STT_FILE 4
-#define STT_LOPROC 13
-#define STT_HIPROC 15
-
-
-/* Macros to split/combine relocation type and symbol page 4-32 */
-
-#define ELF32_R_SYM(__i) ((__i)>>8)
-#define ELF32_R_TYPE(__i) ((unsigned char) (__i))
-#define ELF32_R_INFO(__s, __t) (((__s)<<8) + (unsigned char) (__t))
-
-
-/* program header - page 5-2, figure 5-1 */
-
-typedef struct
-{
- Elf32_Word p_type;
- Elf32_Off p_offset;
- Elf32_Addr p_vaddr;
- Elf32_Addr p_paddr;
- Elf32_Word p_filesz;
- Elf32_Word p_memsz;
- Elf32_Word p_flags;
- Elf32_Word p_align;
-}
-Elf32_Phdr;
-
-/* segment types - page 5-3, figure 5-2 */
-
-#define PT_NULL 0
-#define PT_LOAD 1
-#define PT_DYNAMIC 2
-#define PT_INTERP 3
-#define PT_NOTE 4
-#define PT_SHLIB 5
-#define PT_PHDR 6
-
-#define PT_LOPROC 0x70000000
-#define PT_HIPROC 0x7fffffff
-
-/* segment permissions - page 5-6 */
-
-#define PF_X 0x1
-#define PF_W 0x2
-#define PF_R 0x4
-#define PF_MASKPROC 0xf0000000
-
-
-/* dynamic structure - page 5-15, figure 5-9 */
-
-typedef struct
-{
- Elf32_Sword d_tag;
- union
- {
- Elf32_Word d_val;
- Elf32_Addr d_ptr;
- }
- d_un;
-}
-Elf32_Dyn;
-
-/* Dynamic array tags - page 5-16, figure 5-10. */
-
-#define DT_NULL 0
-#define DT_NEEDED 1
-#define DT_PLTRELSZ 2
-#define DT_PLTGOT 3
-#define DT_HASH 4
-#define DT_STRTAB 5
-#define DT_SYMTAB 6
-#define DT_RELA 7
-#define DT_RELASZ 8
-#define DT_RELAENT 9
-#define DT_STRSZ 10
-#define DT_SYMENT 11
-#define DT_INIT 12
-#define DT_FINI 13
-#define DT_SONAME 14
-#define DT_RPATH 15
-#define DT_SYMBOLIC 16
-#define DT_REL 17
-#define DT_RELSZ 18
-#define DT_RELENT 19
-#define DT_PLTREL 20
-#define DT_DEBUG 21
-#define DT_TEXTREL 22
-#define DT_JMPREL 23
diff --git a/com32/modules/ifcpu64.c b/com32/modules/ifcpu64.c
index c5979191..634a3c5b 100644
--- a/com32/modules/ifcpu64.c
+++ b/com32/modules/ifcpu64.c
@@ -38,86 +38,85 @@
static bool __constfunc cpu_has_cpuid(void)
{
- return cpu_has_eflag(X86_EFLAGS_ID);
+ return cpu_has_eflag(X86_EFLAGS_ID);
}
static bool __constfunc cpu_has_level(uint32_t level)
{
- uint32_t group;
- uint32_t limit;
+ uint32_t group;
+ uint32_t limit;
- if (!cpu_has_cpuid())
- return false;
+ if (!cpu_has_cpuid())
+ return false;
- group = level & 0xffff0000;
- limit = cpuid_eax(group);
+ group = level & 0xffff0000;
+ limit = cpuid_eax(group);
- if ((limit & 0xffff0000) != group)
- return false;
+ if ((limit & 0xffff0000) != group)
+ return false;
- if (level > limit)
- return false;
+ if (level > limit)
+ return false;
- return true;
+ return true;
}
/* This only supports feature groups 0 and 1, corresponding to the
Intel and AMD EDX bit vectors. We can add more later if need be. */
static bool __constfunc cpu_has_feature(int x)
{
- uint32_t level = ((x & 1) << 31) | 1;
+ uint32_t level = ((x & 1) << 31) | 1;
- return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
+ return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
}
/* XXX: this really should be librarized */
static void boot_args(char **args)
{
- int len = 0;
- char **pp;
- const char *p;
- char c, *q, *str;
-
- for (pp = args; *pp; pp++)
- len += strlen(*pp);
-
- q = str = alloca(len+1);
- for (pp = args; *pp; pp++) {
- p = *pp;
- while ((c = *p++))
- *q++ = c;
- }
- *q = '\0';
-
- if (!str[0])
- syslinux_run_default();
- else
- syslinux_run_command(str);
+ int len = 0;
+ char **pp;
+ const char *p;
+ char c, *q, *str;
+
+ for (pp = args; *pp; pp++)
+ len += strlen(*pp);
+
+ q = str = alloca(len + 1);
+ for (pp = args; *pp; pp++) {
+ p = *pp;
+ while ((c = *p++))
+ *q++ = c;
+ }
+ *q = '\0';
+
+ if (!str[0])
+ syslinux_run_default();
+ else
+ syslinux_run_command(str);
}
int main(int argc, char *argv[])
{
- char **args[3];
- int i;
- int n;
-
- args[0] = &argv[1];
- n = 1;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "--")) {
- argv[i] = NULL;
- args[n++] = &argv[i+1];
+ char **args[3];
+ int i;
+ int n;
+
+ args[0] = &argv[1];
+ n = 1;
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--")) {
+ argv[i] = NULL;
+ args[n++] = &argv[i + 1];
+ }
+ if (n >= 3)
+ break;
}
- if (n >= 3)
- break;
- }
- while (n < 3) {
- args[n] = args[n-1];
- n++;
- }
-
- boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
- cpu_has_feature(X86_FEATURE_PAE) ? args[1] :
- args[2]);
- return -1;
+ while (n < 3) {
+ args[n] = args[n - 1];
+ n++;
+ }
+
+ boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
+ cpu_has_feature(X86_FEATURE_PAE) ? args[1] : args[2]);
+ return -1;
}
diff --git a/com32/modules/kbdmap.c b/com32/modules/kbdmap.c
index 7e36a35d..f1c736d5 100644
--- a/com32/modules/kbdmap.c
+++ b/com32/modules/kbdmap.c
@@ -18,37 +18,37 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int main(int argc, char *argv[])
{
- const struct syslinux_keyboard_map * const kmap = syslinux_keyboard_map();
- size_t map_size;
- void *kbdmap;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- if (argc != 2) {
- error("Usage: kbdmap mapfile\n");
- return 1;
- }
-
- if (kmap->version != 1) {
- error("Syslinux core version mismatch\n");
- return 1;
- }
-
- if (loadfile(argv[1], &kbdmap, &map_size)) {
- error("Keyboard map file load error\n");
- return 1;
- }
-
- if (map_size != kmap->length) {
- error("Keyboard map file format error\n");
- return 1;
- }
-
- memcpy(kmap->map, kbdmap, map_size);
- return 0;
+ const struct syslinux_keyboard_map *const kmap = syslinux_keyboard_map();
+ size_t map_size;
+ void *kbdmap;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc != 2) {
+ error("Usage: kbdmap mapfile\n");
+ return 1;
+ }
+
+ if (kmap->version != 1) {
+ error("Syslinux core version mismatch\n");
+ return 1;
+ }
+
+ if (loadfile(argv[1], &kbdmap, &map_size)) {
+ error("Keyboard map file load error\n");
+ return 1;
+ }
+
+ if (map_size != kmap->length) {
+ error("Keyboard map file format error\n");
+ return 1;
+ }
+
+ memcpy(kmap->map, kbdmap, map_size);
+ return 0;
}
diff --git a/com32/modules/linux.c b/com32/modules/linux.c
index a2edd10b..b902ebc5 100644
--- a/com32/modules/linux.c
+++ b/com32/modules/linux.c
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ * Copyright 2009 Intel Corporation; author: H. Peter Anvin
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -37,6 +38,7 @@
* Usage: linux.c32 [-dhcpinfo] kernel arguments...
*/
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -51,207 +53,164 @@ const char *progname = "linux.c32";
(which should include the final =; do not use for boolean arguments) */
static char *find_argument(char **argv, const char *argument)
{
- int la = strlen(argument);
- char **arg;
- char *ptr = NULL;
+ int la = strlen(argument);
+ char **arg;
+ char *ptr = NULL;
- for (arg = argv; *arg; arg++) {
- if (!memcmp(*arg, argument, la))
- ptr = *arg + la;
- }
+ for (arg = argv; *arg; arg++) {
+ if (!memcmp(*arg, argument, la))
+ ptr = *arg + la;
+ }
- return ptr;
+ return ptr;
}
-/* Get a value with a potential suffix (k/m/g/t/p/e) */
-static unsigned long long suffix_number(const char *str)
+/* Search for a boolean argument; return its position, or 0 if not present */
+static int find_boolean(char **argv, const char *argument)
{
- char *ep;
- unsigned long long v;
- int shift;
-
- v = strtoull(str, &ep, 0);
- switch (*ep|0x20) {
- case 'k':
- shift = 10;
- break;
- case 'm':
- shift = 20;
- break;
- case 'g':
- shift = 30;
- break;
- case 't':
- shift = 40;
- break;
- case 'p':
- shift = 50;
- break;
- case 'e':
- shift = 60;
- break;
- default:
- shift = 0;
- break;
- }
- v <<= shift;
-
- return v;
-}
+ char **arg;
-/* Truncate to 32 bits, with saturate */
-static inline uint32_t saturate32(unsigned long long v)
-{
- return (v > 0xffffffff) ? 0xffffffff : (uint32_t)v;
+ for (arg = argv; *arg; arg++) {
+ if (!strcmp(*arg, argument))
+ return (arg - argv) + 1;
+ }
+
+ return 0;
}
/* Stitch together the command line from a set of argv's */
static char *make_cmdline(char **argv)
{
- char **arg;
- size_t bytes;
- char *cmdline, *p;
-
- bytes = 1; /* Just in case we have a zero-entry cmdline */
- for (arg = argv; *arg; arg++) {
- bytes += strlen(*arg)+1;
- }
-
- p = cmdline = malloc(bytes);
- if (!cmdline)
- return NULL;
-
- for (arg = argv; *arg; arg++) {
- int len = strlen(*arg);
- memcpy(p, *arg, len);
- p[len] = ' ';
- p += len+1;
- }
-
- if (p > cmdline)
- p--; /* Remove the last space */
- *p = '\0';
-
- return cmdline;
+ char **arg;
+ size_t bytes;
+ char *cmdline, *p;
+
+ bytes = 1; /* Just in case we have a zero-entry cmdline */
+ for (arg = argv; *arg; arg++) {
+ bytes += strlen(*arg) + 1;
+ }
+
+ p = cmdline = malloc(bytes);
+ if (!cmdline)
+ return NULL;
+
+ for (arg = argv; *arg; arg++) {
+ int len = strlen(*arg);
+ memcpy(p, *arg, len);
+ p[len] = ' ';
+ p += len + 1;
+ }
+
+ if (p > cmdline)
+ p--; /* Remove the last space */
+ *p = '\0';
+
+ return cmdline;
}
int main(int argc, char *argv[])
{
- uint32_t mem_limit = 0;
- uint16_t video_mode = 0;
- const char *kernel_name;
- struct initramfs *initramfs;
- char *cmdline;
- char *boot_image;
- void *kernel_data;
- size_t kernel_len;
- int opt_dhcpinfo = 0;
- void *dhcpdata;
- size_t dhcplen;
- char **argp, *arg, *p;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- (void)argc;
- argp = argv+1;
-
- while ((arg = *argp) && arg[0] == '-') {
- if (!strcmp("-dhcpinfo", arg)) {
- opt_dhcpinfo = 1;
- } else {
- fprintf(stderr, "%s: unknown option: %s\n", progname, arg);
- return 1;
+ const char *kernel_name;
+ struct initramfs *initramfs;
+ char *cmdline;
+ char *boot_image;
+ void *kernel_data;
+ size_t kernel_len;
+ bool opt_dhcpinfo = false;
+ bool opt_quiet = false;
+ void *dhcpdata;
+ size_t dhcplen;
+ char **argp, *arg, *p;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ (void)argc;
+ argp = argv + 1;
+
+ while ((arg = *argp) && arg[0] == '-') {
+ if (!strcmp("-dhcpinfo", arg)) {
+ opt_dhcpinfo = true;
+ } else {
+ fprintf(stderr, "%s: unknown option: %s\n", progname, arg);
+ return 1;
+ }
+ argp++;
}
- argp++;
- }
- if (!arg) {
- fprintf(stderr, "%s: missing kernel name\n", progname);
- return 1;
- }
-
- kernel_name = arg;
-
- printf("Loading %s... ", kernel_name);
- if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
- printf("failed!\n");
- goto bail;
- }
- printf("ok\n");
-
- boot_image = malloc(strlen(kernel_name)+12);
- if (!boot_image)
- goto bail;
-
- strcpy(boot_image, "BOOT_IMAGE=");
- strcpy(boot_image+11, kernel_name);
-
- /* argp now points to the kernel name, and the command line follows.
- Overwrite the kernel name with the BOOT_IMAGE= argument, and thus
- we have the final argument. */
- *argp = boot_image;
-
- cmdline = make_cmdline(argp);
- if (!cmdline)
- goto bail;
-
- /* Initialize the initramfs chain */
- initramfs = initramfs_init();
- if (!initramfs)
- goto bail;
-
- /* Look for specific command-line arguments we care about */
- if ((arg = find_argument(argp, "mem=")))
- mem_limit = saturate32(suffix_number(arg));
-
- if ((arg = find_argument(argp, "vga="))) {
- switch (arg[0] | 0x20) {
- case 'a': /* "ask" */
- video_mode = 0xfffd;
- break;
- case 'e': /* "ext" */
- video_mode = 0xfffe;
- break;
- case 'n': /* "normal" */
- video_mode = 0xffff;
- break;
- default:
- video_mode = strtoul(arg, NULL, 0);
- break;
+ if (!arg) {
+ fprintf(stderr, "%s: missing kernel name\n", progname);
+ return 1;
}
- }
- if ((arg = find_argument(argp, "initrd="))) {
- do {
- p = strchr(arg, ',');
- if (p)
- *p = '\0';
+ kernel_name = arg;
- printf("Loading %s... ", arg);
- if (initramfs_load_archive(initramfs, arg)) {
+ boot_image = malloc(strlen(kernel_name) + 12);
+ if (!boot_image)
+ goto bail;
+ strcpy(boot_image, "BOOT_IMAGE=");
+ strcpy(boot_image + 11, kernel_name);
+ /* argp now points to the kernel name, and the command line follows.
+ Overwrite the kernel name with the BOOT_IMAGE= argument, and thus
+ we have the final argument. */
+ *argp = boot_image;
+
+ if (find_boolean(argp, "quiet"))
+ opt_quiet = true;
+
+ if (!opt_quiet)
+ printf("Loading %s... ", kernel_name);
+ if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
+ if (opt_quiet)
+ printf("Loading %s ", kernel_name);
printf("failed!\n");
goto bail;
- }
- printf("ok\n");
-
- if (p)
- *p++ = ',';
- } while ((arg = p));
- }
-
- /* Append the DHCP info */
- if (opt_dhcpinfo &&
- !pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
- if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen,
- "/dhcpinfo.dat", 0, 0755))
- goto bail;
- }
-
- /* This should not return... */
- syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline,
- video_mode, mem_limit);
-
- bail:
- fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
- return 1;
+ }
+ if (!opt_quiet)
+ printf("ok\n");
+
+ cmdline = make_cmdline(argp);
+ if (!cmdline)
+ goto bail;
+
+ /* Initialize the initramfs chain */
+ initramfs = initramfs_init();
+ if (!initramfs)
+ goto bail;
+
+ if ((arg = find_argument(argp, "initrd="))) {
+ do {
+ p = strchr(arg, ',');
+ if (p)
+ *p = '\0';
+
+ if (!opt_quiet)
+ printf("Loading %s... ", arg);
+ if (initramfs_load_archive(initramfs, arg)) {
+ if (opt_quiet)
+ printf("Loading %s ", kernel_name);
+ printf("failed!\n");
+ goto bail;
+ }
+ if (!opt_quiet)
+ printf("ok\n");
+
+ if (p)
+ *p++ = ',';
+ } while ((arg = p));
+ }
+
+ /* Append the DHCP info */
+ if (opt_dhcpinfo &&
+ !pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
+ if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen,
+ "/dhcpinfo.dat", 0, 0755))
+ goto bail;
+ }
+
+ /* This should not return... */
+ syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
+
+bail:
+ fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
+ return 1;
}
diff --git a/com32/modules/mb_header.h b/com32/modules/mb_header.h
deleted file mode 100644
index 4215323f..00000000
--- a/com32/modules/mb_header.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000 Free Software Foundation, Inc.
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * MultiBoot Header description
- */
-
-struct multiboot_header
-{
- /* Must be MULTIBOOT_MAGIC - see below. */
- unsigned magic;
-
- /* Feature flags - see below. */
- unsigned flags;
-
- /*
- * Checksum
- *
- * The above fields plus this one must equal 0 mod 2^32.
- */
- unsigned checksum;
-
- /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
- unsigned header_addr;
- unsigned load_addr;
- unsigned load_end_addr;
- unsigned bss_end_addr;
- unsigned entry_addr;
-
- /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
- unsigned mode_type;
- unsigned width;
- unsigned height;
- unsigned depth;
-};
-
-/*
- * The entire multiboot_header must be contained
- * within the first MULTIBOOT_SEARCH bytes of the kernel image.
- */
-#define MULTIBOOT_SEARCH 8192
-#define MULTIBOOT_FOUND(addr, len) \
- (! ((addr) & 0x3) \
- && (len) >= 12 \
- && *((int *) (addr)) == MULTIBOOT_MAGIC \
- && ! (*((unsigned *) (addr)) + *((unsigned *) (addr + 4)) \
- + *((unsigned *) (addr + 8))) \
- && (! (MULTIBOOT_AOUT_KLUDGE & *((int *) (addr + 4))) || (len) >= 32) \
- && (! (MULTIBOOT_VIDEO_MODE & *((int *) (addr + 4))) || (len) >= 48))
-
-/* Magic value identifying the multiboot_header. */
-#define MULTIBOOT_MAGIC 0x1BADB002
-
-/*
- * Features flags for 'flags'.
- * If a boot loader sees a flag in MULTIBOOT_MUSTKNOW set
- * and it doesn't understand it, it must fail.
- */
-#define MULTIBOOT_MUSTKNOW 0x0000FFFF
-
-/* currently unsupported flags... this is a kind of version number. */
-#define MULTIBOOT_UNSUPPORTED 0x0000FFF8
-
-/* Align all boot modules on i386 page (4KB) boundaries. */
-#define MULTIBOOT_PAGE_ALIGN 0x00000001
-
-/* Must pass memory information to OS. */
-#define MULTIBOOT_MEMORY_INFO 0x00000002
-
-/* Must pass video information to OS. */
-#define MULTIBOOT_VIDEO_MODE 0x00000004
-
-/* This flag indicates the use of the address fields in the header. */
-#define MULTIBOOT_AOUT_KLUDGE 0x00010000
diff --git a/com32/modules/mb_info.h b/com32/modules/mb_info.h
deleted file mode 100644
index 91a1392b..00000000
--- a/com32/modules/mb_info.h
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2000 Free Software Foundation, Inc.
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/*
- * The structure type "mod_list" is used by the "multiboot_info" structure.
- */
-
-struct mod_list
-{
- /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
- unsigned long mod_start;
- unsigned long mod_end;
-
- /* Module command line */
- unsigned long cmdline;
-
- /* padding to take it to 16 bytes (must be zero) */
- unsigned long pad;
-};
-
-
-/*
- * INT-15, AX=E820 style "AddressRangeDescriptor"
- * ...with a "size" parameter on the front which is the structure size - 4,
- * pointing to the next one, up until the full buffer length of the memory
- * map has been reached.
- */
-
-struct AddrRangeDesc
-{
- unsigned long size;
- unsigned long long BaseAddr;
- unsigned long long Length;
- unsigned long Type;
-
- /* unspecified optional padding... */
-};
-
-/* usable memory "Type", all others are reserved. */
-#define MB_ARD_MEMORY 1
-
-
-/* Drive Info structure. */
-struct drive_info
-{
- /* The size of this structure. */
- unsigned long size;
-
- /* The BIOS drive number. */
- unsigned char drive_number;
-
- /* The access mode (see below). */
- unsigned char drive_mode;
-
- /* The BIOS geometry. */
- unsigned short drive_cylinders;
- unsigned char drive_heads;
- unsigned char drive_sectors;
-
- /* The array of I/O ports used for the drive. */
- unsigned short drive_ports[0];
-};
-
-/* Drive Mode. */
-#define MB_DI_CHS_MODE 0
-#define MB_DI_LBA_MODE 1
-
-
-/* APM BIOS info. */
-struct apm_info
-{
- unsigned short version;
- unsigned short cseg;
- unsigned long offset;
- unsigned short cseg_16;
- unsigned short dseg_16;
- unsigned short cseg_len;
- unsigned short cseg_16_len;
- unsigned short dseg_16_len;
-};
-
-
-/*
- * MultiBoot Info description
- *
- * This is the struct passed to the boot image. This is done by placing
- * its address in the EAX register.
- */
-
-struct multiboot_info
-{
- /* MultiBoot info version number */
- unsigned long flags;
-
- /* Available memory from BIOS */
- unsigned long mem_lower;
- unsigned long mem_upper;
-
- /* "root" partition */
- unsigned long boot_device;
-
- /* Kernel command line */
- unsigned long cmdline;
-
- /* Boot-Module list */
- unsigned long mods_count;
- unsigned long mods_addr;
-
- union
- {
- struct
- {
- /* (a.out) Kernel symbol table info */
- unsigned long tabsize;
- unsigned long strsize;
- unsigned long addr;
- unsigned long pad;
- }
- a;
-
- struct
- {
- /* (ELF) Kernel section header table */
- unsigned long num;
- unsigned long size;
- unsigned long addr;
- unsigned long shndx;
- }
- e;
- }
- syms;
-
- /* Memory Mapping buffer */
- unsigned long mmap_length;
- unsigned long mmap_addr;
-
- /* Drive Info buffer */
- unsigned long drives_length;
- unsigned long drives_addr;
-
- /* ROM configuration table */
- unsigned long config_table;
-
- /* Boot Loader Name */
- unsigned long boot_loader_name;
-
- /* APM table */
- unsigned long apm_table;
-
- /* Video */
- unsigned long vbe_control_info;
- unsigned long vbe_mode_info;
- unsigned short vbe_mode;
- unsigned short vbe_interface_seg;
- unsigned short vbe_interface_off;
- unsigned short vbe_interface_len;
-};
-
-/*
- * Flags to be set in the 'flags' parameter above
- */
-
-/* is there basic lower/upper memory information? */
-#define MB_INFO_MEMORY 0x00000001
-/* is there a boot device set? */
-#define MB_INFO_BOOTDEV 0x00000002
-/* is the command-line defined? */
-#define MB_INFO_CMDLINE 0x00000004
-/* are there modules to do something with? */
-#define MB_INFO_MODS 0x00000008
-
-/* These next two are mutually exclusive */
-
-/* is there a symbol table loaded? */
-#define MB_INFO_AOUT_SYMS 0x00000010
-/* is there an ELF section header table? */
-#define MB_INFO_ELF_SHDR 0x00000020
-
-/* is there a full memory map? */
-#define MB_INFO_MEM_MAP 0x00000040
-
-/* Is there drive info? */
-#define MB_INFO_DRIVE_INFO 0x00000080
-
-/* Is there a config table? */
-#define MB_INFO_CONFIG_TABLE 0x00000100
-
-/* Is there a boot loader name? */
-#define MB_INFO_BOOT_LOADER_NAME 0x00000200
-
-/* Is there a APM table? */
-#define MB_INFO_APM_TABLE 0x00000400
-
-/* Is there video information? */
-#define MB_INFO_VIDEO_INFO 0x00000800
-
-/*
- * The following value must be present in the EAX register.
- */
-
-#define MULTIBOOT_VALID 0x2BADB002
diff --git a/com32/modules/mboot.c b/com32/modules/mboot.c
deleted file mode 100644
index edcb88e6..00000000
--- a/com32/modules/mboot.c
+++ /dev/null
@@ -1,1083 +0,0 @@
-/*
- * mboot.c
- *
- * Loader for Multiboot-compliant kernels and modules.
- *
- * Copyright (C) 2005 Tim Deegan <Tim.Deegan@cl.cam.ac.uk>
- * Parts based on GNU GRUB, Copyright 2000 Free Software Foundation, Inc.
- * Parts based on SYSLINUX, Copyright 1994-2008 H. Peter Anvin.
- * Thanks to Ram Yalamanchili for the ELF section-header loading.
- *
- * 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; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-#include <console.h>
-#include <zlib.h>
-#include <com32.h>
-#include <syslinux/pxe.h>
-
-#include "i386-elf.h"
-#include "mb_info.h"
-#include "mb_header.h"
-
-#include <klibc/compiler.h> /* For __constructor */
-
-#define MIN(_x, _y) (((_x)<(_y))?(_x):(_y))
-#define MAX(_x, _y) (((_x)>(_y))?(_x):(_y))
-
-/* Define this for some more printout */
-#undef DEBUG
-
-/* Memory magic numbers */
-#define STACK_SIZE 0x20000 /* XXX Could be much smaller */
-#define MALLOC_SIZE 0x100000 /* XXX Could be much smaller */
-#define MIN_RUN_ADDR 0x10000 /* Lowest address we'll consider using */
-#define MEM_HOLE_START 0xa0000 /* Memory hole runs from 640k ... */
-#define MEM_HOLE_END 0x100000 /* ... to 1MB */
-#define X86_PAGE_SIZE 0x1000
-#define DHCP_ACK_SIZE 2048 /* Maximum size of the DHCP ACK package.
- Probably too large since we're interested
- in the first bunch of bytes only. */
-
-size_t __stack_size = STACK_SIZE; /* How much stack we'll use */
-extern void *__mem_end; /* Start of malloc() heap */
-extern char _end[]; /* End of static data */
-
-/* Pointer to free memory for loading into: load area is between here
- * and section_addr */
-static char *next_load_addr;
-
-/* Memory map for run-time */
-typedef struct section section_t;
-struct section {
- size_t dest; /* Start of run-time allocation */
- char *src; /* Current location of data for memmove(),
- * or NULL for bzero() */
- size_t size; /* Length of allocation */
-};
-static char *section_addr;
-static int section_count;
-
-static size_t max_run_addr; /* Highest address we'll consider using */
-static size_t next_mod_run_addr; /* Where the next module will be put */
-
-/* File loads are in units of this much */
-#define LOAD_CHUNK 0x20000
-
-/* Layout of the input to the 32-bit lidt instruction */
-struct lidt_operand {
- unsigned int limit:16;
- unsigned int base:32;
-} __attribute__((packed));
-
-/* Magic strings */
-static const char version_string[] = "COM32 Multiboot loader v0.2";
-static const char copyright_string[] = "Copyright (C) 2005-2006 Tim Deegan.";
-static const char module_separator[] = "---";
-
-
-/*
- * Start of day magic, run from __start during library init.
- */
-
-static void __constructor check_version(void)
- /* Check the SYSLINUX version. Docs say we should be OK from v2.08,
- * but in fact we crash on anything below v2.12 (when libc came in). */
-{
- com32sys_t regs_in, regs_out;
- const char *p, *too_old = "Fatal: SYSLINUX image is too old; "
- "mboot.c32 needs at least version 2.12.\r\n";
-
- memset(&regs_in, 0, sizeof(regs_in));
- regs_in.eax.l = 0x0001; /* "Get version" */
- __intcall(0x22, &regs_in, &regs_out);
- if (regs_out.ecx.w[0] >= 0x020c) return;
-
- /* Pointless: on older versions this print fails too. :( */
- for (p = too_old ; *p ; p++) {
- memset(&regs_in, 0, sizeof(regs_in));
- regs_in.eax.b[1] = 0x02; /* "Write character" */
- regs_in.edx.b[0] = *p;
- __intcall(0x21, &regs_in, &regs_out);
- }
-
- __intcall(0x20, &regs_in, &regs_out); /* "Terminate program" */
-}
-
-
-static void __constructor grab_memory(void)
- /* Runs before init_memory_arena() (com32/lib/malloc.c) to let
- * the malloc() code know how much space it's allowed to use.
- * We don't use malloc() directly, but some of the library code
- * does (zlib, for example). */
-{
- /* Find the stack pointer */
- register char * sp;
- asm volatile("movl %%esp, %0" : "=r" (sp));
-
- /* Initialize the allocation of *run-time* memory: don't let ourselves
- * overwrite the stack during the relocation later. */
- max_run_addr = (size_t) sp - (MALLOC_SIZE + STACK_SIZE);
-
- /* Move the end-of-memory marker: malloc() will use only memory
- * above __mem_end and below the stack. We will load files starting
- * at the old __mem_end and working towards the new one, and allocate
- * section descriptors at the top of that area, working down. */
- next_load_addr = __mem_end;
- section_addr = sp - (MALLOC_SIZE + STACK_SIZE);
- section_count = 0;
-
- /* But be careful not to move it the wrong direction if memory is
- * tight. Instead we'll fail more gracefully later, when we try to
- * load a file and find that next_load_addr > section_addr. */
- __mem_end = MAX(section_addr, next_load_addr);
-}
-
-
-
-
-/*
- * Run-time memory map functions: allocating and recording allocations.
- */
-
-static int cmp_sections(const void *a, const void *b)
- /* For sorting section descriptors by destination address */
-{
- const section_t *sa = a;
- const section_t *sb = b;
- if (sa->dest < sb->dest) return -1;
- if (sa->dest > sb->dest) return 1;
- return 0;
-}
-
-
-static void add_section(size_t dest, char *src, size_t size)
- /* Adds something to the list of sections to relocate. */
-{
- section_t *sec;
-
-#ifdef DEBUG
- printf("SECTION: %#8.8x --> %#8.8x (%#x)\n", (size_t) src, dest, size);
-#endif
-
- section_addr -= sizeof (section_t);
- if (section_addr < next_load_addr) {
- printf("Fatal: out of memory allocating section descriptor.\n");
- exit(1);
- }
- sec = (section_t *) section_addr;
- section_count++;
-
- sec->src = src;
- sec->dest = dest;
- sec->size = size;
-
- /* Keep the list sorted */
- qsort(sec, section_count, sizeof (section_t), cmp_sections);
-}
-
-
-static size_t place_low_section(size_t size, size_t align)
- /* Find a space in the run-time memory map, below 640K */
-{
- int i;
- size_t start;
- section_t *sections = (section_t *) section_addr;
-
- start = MIN_RUN_ADDR;
- start = (start + (align-1)) & ~(align-1);
-
- /* Section list is sorted by destination, so can do this in one pass */
- for (i = 0; i < section_count; i++) {
- if (sections[i].dest < start + size) {
- /* Hit the bottom of this section */
- start = sections[i].dest + sections[i].size;
- start = (start + (align-1)) & ~(align-1);
- }
- }
- if (start + size < MEM_HOLE_START) return start;
- else return 0;
-}
-
-
-static size_t place_module_section(size_t size, size_t align)
- /* Find a space in the run-time memory map for this module. */
-{
- /* Ideally we'd run through the sections looking for a free space
- * like place_low_section() does, but some OSes (Xen, at least)
- * assume that the bootloader has loaded all the modules
- * consecutively, above the kernel. So, what we actually do is
- * keep a pointer to the highest address allocated so far, and
- * always allocate modules there. */
-
- size_t start = next_mod_run_addr;
- start = (start + (align-1)) & ~(align-1);
-
- if (start + size > max_run_addr) return 0;
-
- next_mod_run_addr = start + size;
- return start;
-}
-
-
-static void place_kernel_section(size_t start, size_t size)
- /* Allocate run-time space for part of the kernel, checking for
- * sanity. We assume the kernel isn't broken enough to have
- * overlapping segments. */
-{
- /* We always place modules above the kernel */
- next_mod_run_addr = MAX(next_mod_run_addr, start + size);
-
- if (start > max_run_addr || start + size > max_run_addr) {
- /* Overruns the end of memory */
- printf("Fatal: kernel loads too high (%#8.8x+%#x > %#8.8x).\n",
- start, size, max_run_addr);
- exit(1);
- }
- if (start >= MEM_HOLE_END) {
- /* Above the memory hole: easy */
-#ifdef DEBUG
- printf("Placed kernel section (%#8.8x+%#x)\n", start, size);
-#endif
- return;
- }
- if (start >= MEM_HOLE_START) {
- /* In the memory hole. Not so good */
- printf("Fatal: kernel load address (%#8.8x) is in the memory hole.\n",
- start);
- exit(1);
- }
- if (start + size > MEM_HOLE_START) {
- /* Too big for low memory */
- printf("Fatal: kernel (%#8.8x+%#x) runs into the memory hole.\n",
- start, size);
- exit(1);
- }
- if (start < MIN_RUN_ADDR) {
- /* Loads too low */
- printf("Fatal: kernel load address (%#8.8x) is too low (<%#8.8x).\n",
- start, MIN_RUN_ADDR);
- exit(1);
- }
- /* Kernel loads below the memory hole: OK */
-#ifdef DEBUG
- printf("Placed kernel section (%#8.8x+%#x)\n", start, size);
-#endif
-}
-
-
-static void reorder_sections(void)
- /* Reorders sections into a safe order, where no relocation
- * overwrites the source of a later one. */
-{
- section_t *secs = (section_t *) section_addr;
- section_t tmp;
- int i, j, tries;
-
-#ifdef DEBUG
- printf("Relocations:\n");
- for (i = 0; i < section_count ; i++) {
- printf(" %#8.8x --> %#8.8x (%#x)\n",
- (size_t)secs[i].src, secs[i].dest, secs[i].size);
- }
-#endif
-
- for (i = 0; i < section_count; i++) {
- tries = 0;
- scan_again:
- for (j = i + 1 ; j < section_count; j++) {
- if (secs[j].src != NULL
- && secs[i].dest + secs[i].size > (size_t) secs[j].src
- && secs[i].dest < (size_t) secs[j].src + secs[j].size) {
- /* Would overwrite the source of the later move */
- if (++tries > section_count) {
- /* Deadlock! */
- /* XXX Try to break deadlocks? */
- printf("Fatal: circular dependence in relocations.\n");
- exit(1);
- }
- /* Swap these sections (using struct copies) */
- tmp = secs[i]; secs[i] = secs[j]; secs[j] = tmp;
- /* Start scanning again from the new secs[i]... */
- goto scan_again;
- }
- }
- }
-
-#ifdef DEBUG
- printf("Relocations:\n");
- for (i = 0; i < section_count ; i++) {
- printf(" %#8.8x --> %#8.8x (%#x)\n",
- (size_t)secs[i].src, secs[i].dest, secs[i].size);
- }
-#endif
-}
-
-
-static void init_mmap(struct multiboot_info *mbi)
- /* Get a full memory map from the BIOS to pass to the kernel. */
-{
- com32sys_t regs_in, regs_out;
- struct AddrRangeDesc *e820;
- int e820_slots;
- size_t mem_lower, mem_upper, run_addr, mmap_size;
- register size_t sp;
-
- /* Default values for mem_lower and mem_upper in case the BIOS won't
- * tell us: 640K, and all memory up to the stack. */
- asm volatile("movl %%esp, %0" : "=r" (sp));
- mem_upper = (sp - MEM_HOLE_END) / 1024;
- mem_lower = (MEM_HOLE_START) / 1024;
-
-#ifdef DEBUG
- printf("Requesting memory map from BIOS:\n");
-#endif
-
- /* Ask the BIOS for the full memory map of the machine. We'll
- * build it in Multiboot format (i.e. with size fields) in the
- * bounce buffer, and then allocate some high memory to keep it in
- * until boot time. */
- e820 = __com32.cs_bounce;
- e820_slots = 0;
- regs_out.ebx.l = 0;
-
- while(((void *)(e820 + 1)) < __com32.cs_bounce + __com32.cs_bounce_size)
- {
- memset(e820, 0, sizeof (*e820));
- memset(&regs_in, 0, sizeof regs_in);
- e820->size = sizeof(*e820) - sizeof(e820->size);
-
- /* Ask the BIOS to fill in this descriptor */
- regs_in.eax.l = 0xe820; /* "Get system memory map" */
- regs_in.ebx.l = regs_out.ebx.l; /* Continuation value from last call */
- regs_in.ecx.l = 20; /* Size of buffer to write into */
- regs_in.edx.l = 0x534d4150; /* "SMAP" */
- regs_in.es = SEG(&e820->BaseAddr);
- regs_in.edi.w[0] = OFFS(&e820->BaseAddr);
- __intcall(0x15, &regs_in, &regs_out);
-
- if ((regs_out.eflags.l & EFLAGS_CF) != 0 && regs_out.ebx.l != 0)
- break; /* End of map */
-
- if (((regs_out.eflags.l & EFLAGS_CF) != 0 && regs_out.ebx.l == 0)
- || (regs_out.eax.l != 0x534d4150))
- {
- /* Error */
- printf("Error %x reading E820 memory map: %s.\n",
- (int) regs_out.eax.b[0],
- (regs_out.eax.b[0] == 0x80) ? "invalid command" :
- (regs_out.eax.b[0] == 0x86) ? "not supported" :
- "unknown error");
- break;
- }
-
- /* Success */
-#ifdef DEBUG
- printf(" %#16.16Lx -- %#16.16Lx : ",
- e820->BaseAddr, e820->BaseAddr + e820->Length);
- switch (e820->Type) {
- case 1: printf("Available\n"); break;
- case 2: printf("Reserved\n"); break;
- case 3: printf("ACPI Reclaim\n"); break;
- case 4: printf("ACPI NVS\n"); break;
- default: printf("? (Reserved)\n"); break;
- }
-#endif
-
- if (e820->Type == 1) {
- if (e820->BaseAddr == 0) {
- mem_lower = MIN(MEM_HOLE_START, e820->Length) / 1024;
- } else if (e820->BaseAddr == MEM_HOLE_END) {
- mem_upper = MIN(0xfff00000, e820->Length) / 1024;
- }
- }
-
- /* Move to next slot */
- e820++;
- e820_slots++;
-
- /* Done? */
- if (regs_out.ebx.l == 0)
- break;
- }
-
- /* Record the simple information in the MBI */
- mbi->flags |= MB_INFO_MEMORY;
- mbi->mem_lower = mem_lower;
- mbi->mem_upper = mem_upper;
-
- /* Record the full memory map in the MBI */
- if (e820_slots != 0) {
- mmap_size = e820_slots * sizeof(*e820);
- /* Where will it live at run time? */
- run_addr = place_low_section(mmap_size, 1);
- if (run_addr == 0) {
- printf("Fatal: can't find space for the e820 mmap.\n");
- exit(1);
- }
- /* Where will it live now? */
- e820 = (struct AddrRangeDesc *) next_load_addr;
- if (next_load_addr + mmap_size > section_addr) {
- printf("Fatal: out of memory storing the e820 mmap.\n");
- exit(1);
- }
- next_load_addr += mmap_size;
- /* Copy it out of the bounce buffer */
- memcpy(e820, __com32.cs_bounce, mmap_size);
- /* Remember to copy it again at run time */
- add_section(run_addr, (char *) e820, mmap_size);
- /* Record it in the MBI */
- mbi->flags |= MB_INFO_MEM_MAP;
- mbi->mmap_length = mmap_size;
- mbi->mmap_addr = run_addr;
- }
-}
-
-
-
-
-/*
- * Code for loading and parsing files.
- */
-
-static void load_file(char *filename, char **startp, size_t *sizep)
- /* Load a file into memory. Returns where it is and how big via
- * startp and sizep */
-{
- gzFile fp;
- char *start;
- int bsize;
-
- printf("Loading %s.", filename);
-
- start = next_load_addr;
- startp[0] = start;
- sizep[0] = 0;
-
- /* Open the file */
- if ((fp = gzopen(filename, "r")) == NULL) {
- printf("\nFatal: cannot open %s\n", filename);
- exit(1);
- }
-
- while (next_load_addr + LOAD_CHUNK <= section_addr) {
- bsize = gzread(fp, next_load_addr, LOAD_CHUNK);
- printf("%s",".");
-
- if (bsize < 0) {
- printf("\nFatal: read error in %s\n", filename);
- gzclose(fp);
- exit(1);
- }
-
- next_load_addr += bsize;
- sizep[0] += bsize;
-
- if (bsize < LOAD_CHUNK) {
- printf("%s","\n");
- gzclose(fp);
- return;
- }
- }
-
- /* Running out of memory. Try and use up the last bit */
- if (section_addr > next_load_addr) {
- bsize = gzread(fp, next_load_addr, section_addr - next_load_addr);
- printf("%s",".");
- } else {
- bsize = 0;
- }
-
- if (bsize < 0) {
- gzclose(fp);
- printf("\nFatal: read error in %s\n", filename);
- exit(1);
- }
-
- next_load_addr += bsize;
- sizep[0] += bsize;
-
- if (!gzeof(fp)) {
- gzclose(fp);
- printf("\nFatal: out of memory reading %s\n", filename);
- exit(1);
- }
-
- printf("%s","\n");
- gzclose(fp);
- return;
-}
-
-
-static size_t load_kernel(struct multiboot_info *mbi, char *cmdline)
- /* Load a multiboot/elf32 kernel and allocate run-time memory for it.
- * Returns the kernel's entry address. */
-{
- unsigned int i;
- char *load_addr; /* Where the image was loaded */
- size_t load_size; /* How big it is */
- char *seg_addr; /* Where a segment was loaded */
- size_t seg_size, bss_size; /* How big it is */
- size_t run_addr, run_size; /* Where it should be put */
- size_t shdr_run_addr;
- char *p;
- Elf32_Ehdr *ehdr;
- Elf32_Phdr *phdr;
- Elf32_Shdr *shdr;
- struct multiboot_header *mbh;
-
- printf("Kernel: %s\n", cmdline);
-
- load_addr = 0;
- load_size = 0;
- p = strchr(cmdline, ' ');
- if (p != NULL) *p = 0;
- load_file(cmdline, &load_addr, &load_size);
- if (load_size < 12) {
- printf("Fatal: %s is too short to be a multiboot kernel.",
- cmdline);
- exit(1);
- }
- if (p != NULL) *p = ' ';
-
-
- /* Look for a multiboot header in the first 8k of the file */
- for (i = 0; i <= MIN(load_size - 12, MULTIBOOT_SEARCH - 12); i += 4)
- {
- mbh = (struct multiboot_header *)(load_addr + i);
- if (mbh->magic != MULTIBOOT_MAGIC
- || ((mbh->magic+mbh->flags+mbh->checksum) & 0xffffffff))
- {
- /* Not a multiboot header */
- continue;
- }
- if (mbh->flags & (MULTIBOOT_UNSUPPORTED | MULTIBOOT_VIDEO_MODE)) {
- /* Requires options we don't support */
- printf("Fatal: Kernel requires multiboot options "
- "that I don't support: %#x.\n",
- mbh->flags & (MULTIBOOT_UNSUPPORTED|MULTIBOOT_VIDEO_MODE));
- exit(1);
- }
-
- /* This kernel will do: figure out where all the pieces will live */
-
- /* Look for a bootable ELF32 header */
- if ((load_size > sizeof(Elf32_Ehdr) &&
- BOOTABLE_I386_ELF((*((Elf32_Ehdr *) load_addr))))) {
-
- ehdr = (Elf32_Ehdr *)load_addr;
- if (ehdr->e_phoff + ehdr->e_phnum*sizeof (*phdr) > load_size) {
- printf("Fatal: malformed ELF header overruns EOF.\n");
- exit(1);
- }
- if (ehdr->e_phnum <= 0) {
- printf("Fatal: ELF kernel has no program headers.\n");
- exit(1);
- }
-
-#ifdef DEBUG
- printf("Using ELF header.\n");
-#endif
-
- if (ehdr->e_type != ET_EXEC
- || ehdr->e_version != EV_CURRENT
- || ehdr->e_phentsize != sizeof (Elf32_Phdr)) {
- printf("Warning: funny-looking ELF header.\n");
- }
- phdr = (Elf32_Phdr *)(load_addr + ehdr->e_phoff);
-
- /* Obey the program headers to load the kernel */
- for(i = 0; i < ehdr->e_phnum; i++) {
-
- /* How much is in this segment? */
- run_size = phdr[i].p_memsz;
- if (phdr[i].p_type != PT_LOAD)
- seg_size = 0;
- else
- seg_size = (size_t)phdr[i].p_filesz;
-
- /* Where is it in the loaded file? */
- seg_addr = load_addr + phdr[i].p_offset;
- if (seg_addr + seg_size > load_addr + load_size) {
- printf("Fatal: ELF load segment runs off the "
- "end of the file.\n");
- exit(1);
- }
-
- /* Skip segments that don't take up any memory */
- if (run_size == 0) continue;
-
- /* Place the segment where it wants to be */
- run_addr = phdr[i].p_paddr;
- place_kernel_section(run_addr, run_size);
-
- /* Put it on the relocation list */
- if (seg_size < run_size) {
- /* Set up the kernel BSS too */
- if (seg_size > 0)
- add_section(run_addr, seg_addr, seg_size);
- bss_size = run_size - seg_size;
- add_section(run_addr + seg_size, NULL, bss_size);
- } else {
- /* No BSS */
- add_section(run_addr, seg_addr, run_size);
- }
- }
-
- if (ehdr->e_shoff != 0) {
-#ifdef DEBUG
- printf("Loading ELF section table.\n");
-#endif
- /* Section Header */
- shdr = (Elf32_Shdr *)(load_addr + ehdr->e_shoff);
-
- /* Section Header Table size */
- run_size = ehdr->e_shentsize * ehdr->e_shnum;
- shdr_run_addr = place_module_section(run_size, 0x1000);
- if (shdr_run_addr == 0) {
- printf("Warning: Not enough memory to load the "
- "section table.\n");
- return ehdr->e_entry;
- }
- add_section(shdr_run_addr, (void*) shdr, run_size);
-
- /* Load section tables not loaded thru program segments */
- for (i = 0; i < ehdr->e_shnum; i++) {
- /* This case is when this section is already included in
- * program header or it's 0 size, so no need to load */
- if (shdr[i].sh_addr != 0 || !shdr[i].sh_size)
- continue;
-
- if (shdr[i].sh_addralign == 0)
- shdr[i].sh_addralign = 1;
-
- run_addr = place_module_section(shdr[i].sh_size,
- shdr[i].sh_addralign);
- if (run_addr == 0) {
- printf("Warning: Not enough memory to load "
- "section %d.\n", i);
- return ehdr->e_entry;
- }
- shdr[i].sh_addr = run_addr;
- add_section(run_addr,
- (void*) (shdr[i].sh_offset + load_addr),
- shdr[i].sh_size);
- }
-
- mbi->flags |= MB_INFO_ELF_SHDR;
- mbi->syms.e.num = ehdr->e_shnum;
- mbi->syms.e.size = ehdr->e_shentsize;
- mbi->syms.e.shndx = ehdr->e_shstrndx;
- mbi->syms.e.addr = shdr_run_addr;
-#ifdef DEBUG
- printf("Section information: shnum: %lu, entSize: %lu, "
- "shstrndx: %lu, addr: 0x%lx\n",
- mbi->syms.e.num, mbi->syms.e.size,
- mbi->syms.e.shndx, mbi->syms.e.addr);
-#endif
- }
-
- /* Done! */
- return ehdr->e_entry;
- } else
-
- /* Does the MB header specify load addresses? */
- if (mbh->flags & MULTIBOOT_AOUT_KLUDGE) {
-
- /* Use the offsets in the multiboot header */
-#ifdef DEBUG
- printf("Using multiboot header.\n");
-#endif
-
- /* Where is the code in the loaded file? */
- seg_addr = ((char *)mbh) - (mbh->header_addr - mbh->load_addr);
-
- /* How much code is there? */
- run_addr = mbh->load_addr;
- if (mbh->load_end_addr != 0)
- seg_size = mbh->load_end_addr - mbh->load_addr;
- else
- seg_size = load_size - (seg_addr - load_addr);
-
- /* How much memory will it take up? */
- if (mbh->bss_end_addr != 0)
- run_size = mbh->bss_end_addr - mbh->load_addr;
- else
- run_size = seg_size;
-
- if (seg_size > run_size) {
- printf("Fatal: can't put %i bytes of kernel into %i bytes "
- "of memory.\n", seg_size, run_size);
- exit(1);
- }
- if (seg_addr + seg_size > load_addr + load_size) {
- printf("Fatal: multiboot load segment runs off the "
- "end of the file.\n");
- exit(1);
- }
-
- /* Does it fit where it wants to be? */
- place_kernel_section(run_addr, run_size);
-
- /* Put it on the relocation list */
- if (seg_size < run_size) {
- /* Set up the kernel BSS too */
- if (seg_size > 0)
- add_section(run_addr, seg_addr, seg_size);
- bss_size = run_size - seg_size;
- add_section(run_addr + seg_size, NULL, bss_size);
- } else {
- /* No BSS */
- add_section(run_addr, seg_addr, run_size);
- }
-
- /* Done. */
- return mbh->entry_addr;
- }
- }
-
- /* This is not a multiboot kernel */
- printf("Fatal: not a multiboot kernel.\n");
- exit(1);
-}
-
-
-
-static void load_module(struct mod_list *mod, char *cmdline)
- /* Load a multiboot module and allocate a memory area for it */
-{
- char *load_addr, *p;
- size_t load_size, run_addr;
-
- printf("Module: %s\n", cmdline);
-
- load_addr = 0;
- load_size = 0;
- p = strchr(cmdline, ' ');
- if (p != NULL) *p = 0;
- load_file(cmdline, &load_addr, &load_size);
- if (p != NULL) *p = ' ';
-
- /* Decide where it's going to live */
- run_addr = place_module_section(load_size, X86_PAGE_SIZE);
- if (run_addr == 0) {
- printf("Fatal: can't find space for this module.\n");
- exit(1);
- }
- add_section(run_addr, load_addr, load_size);
-
- /* Remember where we put it */
- mod->mod_start = run_addr;
- mod->mod_end = run_addr + load_size;
- mod->pad = 0;
-
-#ifdef DEBUG
- printf("Placed module (%#8.8x+%#x)\n", run_addr, load_size);
-#endif
-}
-
-
-
-
-/*
- * Code for shuffling sections into place and booting the new kernel
- */
-
-static void trampoline_start(section_t *secs, int sec_count,
- size_t mbi_run_addr, size_t entry)
- /* Final shuffle-and-boot code. Running on the stack; no external code
- * or data can be relied on. */
-{
- int i;
- struct lidt_operand idt;
-
- /* SYSLINUX has set up SS, DS and ES as 32-bit 0--4G data segments,
- * but doesn't specify FS and GS. Multiboot wants them all to be
- * the same, so we'd better do that before we overwrite the GDT. */
- asm volatile("movl %ds, %ecx; movl %ecx, %fs; movl %ecx, %gs");
-
- /* Turn off interrupts */
- asm volatile("cli");
-
- /* SYSLINUX has set up an IDT at 0x100000 that does all the
- * comboot calls, and we're about to overwrite it. The Multiboot
- * spec says that the kernel must set up its own IDT before turning
- * on interrupts, but it's still entitled to use BIOS calls, so we'll
- * put the IDT back to the BIOS one at the base of memory. */
- idt.base = 0;
- idt.limit = 0x800;
- asm volatile("lidt %0" : : "m" (idt));
-
- /* Now, shuffle the sections */
- for (i = 0; i < sec_count; i++) {
- if (secs[i].src == NULL) {
- /* asm bzero() code from com32/lib/memset.c */
- char *q = (char *) secs[i].dest;
- size_t nl = secs[i].size >> 2;
- asm volatile("rep ; stosl ; movl %3,%0 ; rep ; stosb"
- : "+c" (nl), "+D" (q)
- : "a" (0x0U), "r" (secs[i].size & 3));
- } else {
- /* asm memmove() code from com32/lib/memmove.c */
- const char *p = secs[i].src;
- char *q = (char *) secs[i].dest;
- size_t n = secs[i].size;
- if ( q < p ) {
- asm volatile("rep ; movsb"
- : "+c" (n), "+S" (p), "+D" (q));
- } else {
- p += (n-1);
- q += (n-1);
- asm volatile("std ; rep ; movsb ; cld"
- : "+c" (n), "+S" (p), "+D" (q));
- }
- }
- }
-
- /* Now set up the last tiny bit of Multiboot environment.
- * A20 is already enabled.
- * CR0 already has PG cleared and PE set.
- * EFLAGS already has VM and IF cleared.
- * ESP is the kernels' problem.
- * GDTR is the kernel's problem.
- * CS is already a 32-bit, 0--4G code segments.
- * DS, ES, FS and GS are already 32-bit, 0--4G data segments.
- *
- * EAX must be 0x2badb002 and EBX must point to the MBI when we jump. */
-
- asm volatile ("jmp %*%2"
- : : "a" (0x2badb002), "b" (mbi_run_addr), "cdSDm" (entry));
-}
-static void trampoline_end(void) {}
-
-
-static void boot(size_t mbi_run_addr, size_t entry)
- /* Tidy up SYSLINUX, shuffle memory and boot the kernel */
-{
- com32sys_t regs;
- section_t *tr_sections;
- void (*trampoline)(section_t *, int, size_t, size_t);
- size_t trampoline_size;
-
- /* Make sure the relocations are safe. */
- reorder_sections();
-
- /* Copy the shuffle-and-boot code and the array of relocations
- * onto the memory we previously used for malloc() heap. This is
- * safe because it's not the source or the destination of any
- * copies, and there'll be no more library calls after the copy. */
-
- tr_sections = ((section_t *) section_addr) + section_count;
- trampoline = (void *) (tr_sections + section_count);
- trampoline_size = (void *)&trampoline_end - (void *)&trampoline_start;
-
-#ifdef DEBUG
- printf("tr_sections: %p\n"
- "trampoline: %p\n"
- "trampoline_size: %#8.8x\n"
- "max_run_addr: %#8.8x\n",
- tr_sections, trampoline, trampoline_size, max_run_addr);
-#endif
-
- printf("Booting: MBI=%#8.8x, entry=%#8.8x\n", mbi_run_addr, entry);
-
- memmove(tr_sections, section_addr, section_count * sizeof (section_t));
- memmove(trampoline, trampoline_start, trampoline_size);
-
- /* Tell SYSLINUX to clean up */
- memset(&regs, 0, sizeof regs);
- regs.eax.l = 0x000c; /* "Perform final cleanup" */
- regs.edx.l = 0; /* "Normal cleanup" */
- __intcall(0x22, &regs, NULL);
-
- /* Into the unknown */
- trampoline(tr_sections, section_count, mbi_run_addr, entry);
-}
-
-
-int main(int argc, char **argv)
- /* Parse the command-line and invoke loaders */
-{
- struct multiboot_info *mbi;
- struct mod_list *modp;
- int modules, num_append_args;
- int mbi_reloc_offset;
- char *p;
- size_t mbi_run_addr, mbi_size, entry;
- int i;
- bool opt_solaris = false;
- void *dhcpdata;
- size_t dhcplen;
-
- /* Say hello */
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- printf("%s. %s\n", version_string, copyright_string);
-
- /* This is way too ugly. */
- if (!strcmp("-solaris", argv[1])) {
- opt_solaris = true;
- argv[1] = argv[0];
- argv = &argv[1];
- argc -= 1;
- }
-
- if (argc < 2 || !strcmp(argv[1], module_separator)) {
- printf("Fatal: No kernel filename!\n");
- exit(1);
- }
-
-#ifdef DEBUG
- printf("_end: %p\n"
- "argv[1]: %p\n"
- "next_load_addr: %p\n"
- "section_addr %p\n"
- "__mem_end: %p\n"
- "argv[0]: %p\n",
- &_end, argv[1], next_load_addr, section_addr, __mem_end, argv[0]);
-#endif
-
- /* How much space will the MBI need? */
- modules = 0;
- mbi_size = sizeof(struct multiboot_info) + strlen(version_string) + 5;
- for (i = 1 ; i < argc ; i++) {
- if (!strcmp(argv[i], module_separator)) {
- modules++;
- mbi_size += sizeof(struct mod_list) + 1;
- } else {
- mbi_size += strlen(argv[i]) + 1;
- }
- }
- if (opt_solaris)
- mbi_size += DHCP_ACK_SIZE;
-
- /* Allocate space in the load buffer for the MBI, all the command
- * lines, and all the module details. */
- mbi = (struct multiboot_info *)next_load_addr;
- next_load_addr += mbi_size;
- if (next_load_addr > section_addr) {
- printf("Fatal: out of memory allocating for boot metadata.\n");
- exit(1);
- }
- memset(mbi, 0, sizeof (struct multiboot_info));
- p = (char *)(mbi + 1);
- mbi->flags = MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME;
-
- /* Figure out the memory map.
- * N.B. Must happen before place_section() is called */
- init_mmap(mbi);
-
- mbi_run_addr = place_low_section(mbi_size, 4);
- if (mbi_run_addr == 0) {
- printf("Fatal: can't find space for the MBI!\n");
- exit(1);
- }
- mbi_reloc_offset = (size_t)mbi - mbi_run_addr;
- add_section(mbi_run_addr, (void *)mbi, mbi_size);
-
- /* Module info structs */
- modp = (struct mod_list *) (((size_t)p + 3) & ~3);
- if (modules > 0) mbi->flags |= MB_INFO_MODS;
- mbi->mods_count = modules;
- mbi->mods_addr = ((size_t)modp) - mbi_reloc_offset;
- p = (char *)(modp + modules);
-
- /* Append cmdline args show up in the beginning, append these
- * to kernel cmdline later on */
- for (i = 1; i < argc; i++) {
- if (strchr(argv[i], '=') != NULL) {
- continue;
- }
- break;
- }
-
- /* Command lines: first kernel, then modules */
- mbi->cmdline = ((size_t)p) - mbi_reloc_offset;
- modules = 0;
- num_append_args = i-1;
-
- for (; i < argc ; i++) {
- if (!strcmp(argv[i], module_separator)) {
- /* Add append args to kernel cmdline */
- if (modules == 0 && num_append_args) {
- int j;
- for (j = 1; j < num_append_args+1; j++) {
- strcpy(p, argv[j]);
- p += strlen(argv[j]);
- *p++ = ' ';
- }
- }
- *p++ = '\0';
- modp[modules++].cmdline = ((size_t)p) - mbi_reloc_offset;
- } else {
- strcpy(p, argv[i]);
- p += strlen(argv[i]);
- *p++ = ' ';
- }
- }
- *p++ = '\0';
-
- /* Bootloader ID */
- strcpy(p, version_string);
- mbi->boot_loader_name = ((size_t)p) - mbi_reloc_offset;
- p += strlen(version_string) + 1;
-
- if (opt_solaris) {
- printf("Solaris DHCP passing enabled... ");
- /* Try to get the DHCP ACK packet from PXE */
- if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK,
- &dhcpdata, &dhcplen)) {
- /* Solaris expects the DHCP ACK packet to be passed in the drives_*
- structure. However, the flags field must indicate that the
- drives_structure is not being used.
- Furthermore, the boot_device must be set to 0x20ffffff
- */
- dhcplen = MIN(dhcplen, DHCP_ACK_SIZE);
- memcpy(p, dhcpdata, dhcplen);
- mbi->drives_addr = ((size_t)p) - mbi_reloc_offset;
- mbi->drives_length = dhcplen;
- mbi->flags &= ~MB_INFO_DRIVE_INFO;
- p += dhcplen;
-
- mbi->boot_device = 0x20ffffff;
- mbi->flags |= MB_INFO_BOOTDEV;
- printf("ok\n");
- } else {
- printf("not found.\n");
- }
- }
-
- /* Now, do all the loading, and boot it */
- entry = load_kernel(mbi, (char *)(mbi->cmdline + mbi_reloc_offset));
- for (i=0; i<modules; i++) {
- load_module(&(modp[i]), (char *)(modp[i].cmdline + mbi_reloc_offset));
- }
- boot(mbi_run_addr, entry);
-
- return 1;
-}
-
-/*
- * EOF
- */
diff --git a/com32/modules/meminfo.c b/com32/modules/meminfo.c
index 4f2b3725..6e24f355 100644
--- a/com32/modules/meminfo.c
+++ b/com32/modules/meminfo.c
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2008 H. Peter Anvin - All Rights Reserved
+ * Copyright 2009 Intel Corporation; author: H. Peter Anvin
*
* 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
@@ -22,99 +23,104 @@
#include <com32.h>
struct e820_data {
- uint64_t base;
- uint64_t len;
- uint32_t type;
- uint32_t extattr;
-} __attribute__((packed));
-
-static const char * const e820_types[] = {
- "usable",
- "reserved",
- "ACPI reclaim",
- "ACPI NVS",
- "unusable",
+ uint64_t base;
+ uint64_t len;
+ uint32_t type;
+ uint32_t extattr;
+} __attribute__ ((packed));
+
+static const char *const e820_types[] = {
+ "usable",
+ "reserved",
+ "ACPI reclaim",
+ "ACPI NVS",
+ "unusable",
};
static void dump_e820(void)
{
- com32sys_t ireg, oreg;
- struct e820_data ed;
- uint32_t type;
-
- memset(&ireg, 0, sizeof ireg);
-
- ireg.eax.w[0] = 0xe820;
- ireg.edx.l = 0x534d4150;
- ireg.ecx.l = sizeof(struct e820_data);
- ireg.edi.w[0] = OFFS(__com32.cs_bounce);
- ireg.es = SEG(__com32.cs_bounce);
-
- memset(&ed, 0, sizeof ed);
- ed.extattr = 1;
-
- do {
- memcpy(__com32.cs_bounce, &ed, sizeof ed);
-
- __intcall(0x15, &ireg, &oreg);
- if (oreg.eflags.l & EFLAGS_CF ||
- oreg.eax.l != 0x534d4150 ||
- oreg.ecx.l < 20)
- break;
-
- memcpy(&ed, __com32.cs_bounce, sizeof ed);
-
- if (oreg.ecx.l < 24)
- ed.extattr = 1;
-
- /* ebx base length end type */
- printf("%8x %016llx %016llx %016llx %d [%x]",
- ireg.ebx.l, ed.base, ed.len, ed.base+ed.len, ed.type, ed.extattr);
-
- type = ed.type - 1;
- if (type < sizeof(e820_types)/sizeof(e820_types[0]))
- printf(" %s", e820_types[type]);
-
- putchar('\n');
-
- ireg.ebx.l = oreg.ebx.l;
- } while (ireg.ebx.l);
+ com32sys_t ireg, oreg;
+ struct e820_data ed;
+ uint32_t type;
+
+ memset(&ireg, 0, sizeof ireg);
+
+ ireg.eax.w[0] = 0xe820;
+ ireg.edx.l = 0x534d4150;
+ ireg.ecx.l = sizeof(struct e820_data);
+ ireg.edi.w[0] = OFFS(__com32.cs_bounce);
+ ireg.es = SEG(__com32.cs_bounce);
+
+ memset(&ed, 0, sizeof ed);
+ ed.extattr = 1;
+
+ do {
+ memcpy(__com32.cs_bounce, &ed, sizeof ed);
+
+ __intcall(0x15, &ireg, &oreg);
+ if (oreg.eflags.l & EFLAGS_CF ||
+ oreg.eax.l != 0x534d4150 || oreg.ecx.l < 20)
+ break;
+
+ memcpy(&ed, __com32.cs_bounce, sizeof ed);
+
+ if (oreg.ecx.l >= 24) {
+ /* ebx base length end type */
+ printf("%8x %016llx %016llx %016llx %d [%x]",
+ ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type,
+ ed.extattr);
+ } else {
+ /* ebx base length end */
+ printf("%8x %016llx %016llx %016llx %d [-]",
+ ireg.ebx.l, ed.base, ed.len, ed.base + ed.len, ed.type);
+ ed.extattr = 1;
+ }
+
+ type = ed.type - 1;
+ if (type < sizeof(e820_types) / sizeof(e820_types[0]))
+ printf(" %s", e820_types[type]);
+
+ putchar('\n');
+
+ ireg.ebx.l = oreg.ebx.l;
+ } while (ireg.ebx.l);
}
static void dump_legacy(void)
{
- com32sys_t ireg, oreg;
- uint16_t dosram = *(uint16_t *)0x413;
- struct { uint16_t offs, seg; } * const ivt = (void *)0;
+ com32sys_t ireg, oreg;
+ uint16_t dosram = *(uint16_t *) 0x413;
+ struct {
+ uint16_t offs, seg;
+ } *const ivt = (void *)0;
- memset(&ireg, 0, sizeof ireg);
+ memset(&ireg, 0, sizeof ireg);
- __intcall(0x12, &ireg, &oreg);
+ __intcall(0x12, &ireg, &oreg);
- printf("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n",
- ivt[0x15].seg, ivt[0x15].offs,
- dosram, dosram << 10,
- oreg.eax.w[0], oreg.eax.w[0] << 10);
+ printf
+ ("INT 15h = %04x:%04x DOS RAM: %dK (0x%05x) INT 12h: %dK (0x%05x)\n",
+ ivt[0x15].seg, ivt[0x15].offs, dosram, dosram << 10, oreg.eax.w[0],
+ oreg.eax.w[0] << 10);
- ireg.eax.b[1] = 0x88;
- __intcall(0x15, &ireg, &oreg);
+ ireg.eax.b[1] = 0x88;
+ __intcall(0x15, &ireg, &oreg);
- printf("INT 15 88: 0x%04x (%uK) ",
- oreg.eax.w[0], oreg.eax.w[0]);
+ printf("INT 15 88: 0x%04x (%uK) ", oreg.eax.w[0], oreg.eax.w[0]);
- ireg.eax.w[0] = 0xe801;
- __intcall(0x15, &ireg, &oreg);
+ ireg.eax.w[0] = 0xe801;
+ __intcall(0x15, &ireg, &oreg);
- printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n",
- oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
+ printf("INT 15 E801: 0x%04x (%uK) 0x%04x (%uK)\n",
+ oreg.ecx.w[0], oreg.ecx.w[0], oreg.edx.w[0], oreg.edx.w[0] << 6);
}
int main(void)
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- dump_legacy();
- dump_e820();
+ dump_legacy();
+ dump_e820();
- return 0;
+ return 0;
}
diff --git a/com32/modules/pcitest.c b/com32/modules/pcitest.c
index 8b97fbea..4e483083 100644
--- a/com32/modules/pcitest.c
+++ b/com32/modules/pcitest.c
@@ -46,7 +46,7 @@
# define dprintf(...) ((void)0)
#endif
-char display_line=0;
+char display_line = 0;
#define moreprintf(...) \
do { \
display_line++; \
@@ -59,90 +59,100 @@ char display_line=0;
printf ( __VA_ARGS__); \
} while (0);
-void display_pci_devices(struct pci_domain *pci_domain) {
- struct pci_device *pci_device;
- char kernel_modules [LINUX_KERNEL_MODULE_SIZE*MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+void display_pci_devices(struct pci_domain *pci_domain)
+{
+ struct pci_device *pci_device;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- for_each_pci_func(pci_device, pci_domain) {
+ for_each_pci_func(pci_device, pci_domain) {
- memset(kernel_modules,0,sizeof kernel_modules);
+ memset(kernel_modules, 0, sizeof kernel_modules);
/* printf("PCI: found %d kernel modules for %04x:%04x[%04x:%04x]\n",
pci_device->dev_info->linux_kernel_module_count,
pci_device->vendor, pci_device->product,
pci_device->sub_vendor, pci_device->sub_product);
*/
- for (int i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) {
- if (i>0) {
- strncat(kernel_modules," | ",3);
- }
- strncat(kernel_modules, pci_device->dev_info->linux_kernel_module[i],LINUX_KERNEL_MODULE_SIZE-1);
+ for (int i = 0; i < pci_device->dev_info->linux_kernel_module_count;
+ i++) {
+ if (i > 0) {
+ strncat(kernel_modules, " | ", 3);
+ }
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[i],
+ LINUX_KERNEL_MODULE_SIZE - 1);
}
moreprintf("%04x:%04x[%04x:%04x]: %s\n",
- pci_device->vendor, pci_device->product,
- pci_device->sub_vendor, pci_device->sub_product,
- pci_device->dev_info->class_name);
-
- moreprintf(" Vendor Name : %s\n", pci_device->dev_info->vendor_name);
- moreprintf(" Product Name : %s\n", pci_device->dev_info->product_name);
- moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus, __pci_slot, __pci_func);
- moreprintf(" Kernel modules : %s\n\n",kernel_modules);
- }
+ pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor, pci_device->sub_product,
+ pci_device->dev_info->class_name);
+
+ moreprintf(" Vendor Name : %s\n",
+ pci_device->dev_info->vendor_name);
+ moreprintf(" Product Name : %s\n",
+ pci_device->dev_info->product_name);
+ moreprintf(" PCI bus position : %02x:%02x.%01x\n", __pci_bus,
+ __pci_slot, __pci_func);
+ moreprintf(" Kernel modules : %s\n\n", kernel_modules);
+ }
}
int main(int argc, char *argv[])
{
- struct pci_domain *pci_domain;
- int return_code=0;
- int nb_pci_devices=0;
+ struct pci_domain *pci_domain;
+ int return_code = 0;
+ int nb_pci_devices = 0;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- /* Scanning to detect pci buses and devices */
- printf("PCI: Scanning PCI BUS\n");
- pci_domain = pci_scan();
- if (!pci_domain) {
+ /* Scanning to detect pci buses and devices */
+ printf("PCI: Scanning PCI BUS\n");
+ pci_domain = pci_scan();
+ if (!pci_domain) {
printf("PCI: no devices found!\n");
return 1;
- }
-
- struct pci_device *pci_device;
- for_each_pci_func(pci_device, pci_domain) {
- nb_pci_devices++;
- }
-
- printf("PCI: %d PCI devices found\n",nb_pci_devices);
-
-
- printf("PCI: Looking for device name\n");
- /* Assigning product & vendor name for each device*/
- return_code=get_name_from_pci_ids(pci_domain,"pci.ids");
- if (return_code == -ENOPCIIDS) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
- printf("PCI: PCI Device names can't be computed.\n");
- }
-
- printf("PCI: Resolving class names\n");
- /* Assigning class name for each device*/
- return_code=get_class_name_from_pci_ids(pci_domain,"pci.ids");
- if (return_code == -ENOPCIIDS) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
- printf("PCI: PCI class names can't be computed.\n");
- }
-
- printf("PCI: Looking for Kernel modules\n");
- /* Detecting which kernel module should match each device */
- return_code=get_module_name_from_pcimap(pci_domain,"modules.pcimap");
- if (return_code == -ENOMODULESPCIMAP) {
- printf("PCI: ERROR !\n");
- printf("PCI: Unable to open modules.pcimap in the same directory as pcitest.c32.\n");
- printf("PCI: Kernel Module names can't be computed.\n");
- }
-
- /* display the pci devices we found */
- display_pci_devices(pci_domain);
- return 0;
+ }
+
+ struct pci_device *pci_device;
+ for_each_pci_func(pci_device, pci_domain) {
+ nb_pci_devices++;
+ }
+
+ printf("PCI: %d PCI devices found\n", nb_pci_devices);
+
+ printf("PCI: Looking for device name\n");
+ /* Assigning product & vendor name for each device */
+ return_code = get_name_from_pci_ids(pci_domain, "pci.ids");
+ if (return_code == -ENOPCIIDS) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
+ printf("PCI: PCI Device names can't be computed.\n");
+ }
+
+ printf("PCI: Resolving class names\n");
+ /* Assigning class name for each device */
+ return_code = get_class_name_from_pci_ids(pci_domain, "pci.ids");
+ if (return_code == -ENOPCIIDS) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open pci.ids in the same directory as pcitest.c32.\n");
+ printf("PCI: PCI class names can't be computed.\n");
+ }
+
+ printf("PCI: Looking for Kernel modules\n");
+ /* Detecting which kernel module should match each device */
+ return_code = get_module_name_from_pcimap(pci_domain, "modules.pcimap");
+ if (return_code == -ENOMODULESPCIMAP) {
+ printf("PCI: ERROR !\n");
+ printf
+ ("PCI: Unable to open modules.pcimap in the same directory as pcitest.c32.\n");
+ printf("PCI: Kernel Module names can't be computed.\n");
+ }
+
+ /* display the pci devices we found */
+ display_pci_devices(pci_domain);
+ return 0;
}
diff --git a/com32/modules/pmload.c b/com32/modules/pmload.c
index b45cf5f1..7a0e193f 100644
--- a/com32/modules/pmload.c
+++ b/com32/modules/pmload.c
@@ -61,170 +61,170 @@
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
int boot_raw(void *ptr, size_t len, addr_t where, char **argv)
{
- struct syslinux_movelist *ml = NULL;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_pm_regs regs;
- int argc;
- addr_t argsize;
- char **argp;
- addr_t lstart, llen;
- char *stack_frame = NULL;
- addr_t stack_frame_size;
- addr_t stack_pointer;
- uint32_t *spp;
- char *sfp;
- addr_t sfa;
-
- memset(&regs, 0, sizeof regs);
-
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
+ struct syslinux_movelist *ml = NULL;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_pm_regs regs;
+ int argc;
+ addr_t argsize;
+ char **argp;
+ addr_t lstart, llen;
+ char *stack_frame = NULL;
+ addr_t stack_frame_size;
+ addr_t stack_pointer;
+ uint32_t *spp;
+ char *sfp;
+ addr_t sfa;
+
+ memset(&regs, 0, sizeof regs);
+
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
#if DEBUG
- dprintf("Initial memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Initial memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
#endif
- dprintf("Segment at 0x%08x len 0x%08x\n", where, len);
+ dprintf("Segment at 0x%08x len 0x%08x\n", where, len);
- if (syslinux_memmap_type(amap, where, len) != SMT_FREE) {
- printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
+ if (syslinux_memmap_type(amap, where, len) != SMT_FREE) {
+ printf("Memory segment at 0x%08x (len 0x%08x) is unavailable\n",
where, len);
- goto bail; /* Memory region unavailable */
- }
-
- /* Mark this region as allocated in the available map */
- if (syslinux_add_memmap(&amap, where, len, SMT_ALLOC))
- goto bail;
-
- /* Data present region. Create a move entry for it. */
- if (syslinux_add_movelist(&ml, where, (addr_t)ptr, len))
- goto bail;
-
- /* Create the invocation record (initial stack frame) */
-
- argsize = argc = 0;
- for (argp = argv; *argp; argp++) {
- dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
- argc++;
- argsize += strlen(*argp)+1;
- }
-
- /* We need the argument strings, argument pointers,
- argc, plus four zero-word terminators. */
- stack_frame_size = argsize + argc*sizeof(char *) + 5*sizeof(long);
- stack_frame_size = (stack_frame_size+15) & ~15;
- stack_frame = calloc(stack_frame_size, 1);
- if (!stack_frame)
- goto bail;
+ goto bail; /* Memory region unavailable */
+ }
+
+ /* Mark this region as allocated in the available map */
+ if (syslinux_add_memmap(&amap, where, len, SMT_ALLOC))
+ goto bail;
+
+ /* Data present region. Create a move entry for it. */
+ if (syslinux_add_movelist(&ml, where, (addr_t) ptr, len))
+ goto bail;
+
+ /* Create the invocation record (initial stack frame) */
+
+ argsize = argc = 0;
+ for (argp = argv; *argp; argp++) {
+ dprintf("argv[%2d] = \"%s\"\n", argc, *argp);
+ argc++;
+ argsize += strlen(*argp) + 1;
+ }
+
+ /* We need the argument strings, argument pointers,
+ argc, plus four zero-word terminators. */
+ stack_frame_size = argsize + argc * sizeof(char *) + 5 * sizeof(long);
+ stack_frame_size = (stack_frame_size + 15) & ~15;
+ stack_frame = calloc(stack_frame_size, 1);
+ if (!stack_frame)
+ goto bail;
#if DEBUG
- dprintf("Right before syslinux_memmap_largest()...\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Right before syslinux_memmap_largest()...\n");
+ syslinux_dump_memmap(stdout, amap);
#endif
- if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
- goto bail; /* NO free memory?! */
+ if (syslinux_memmap_largest(amap, SMT_FREE, &lstart, &llen))
+ goto bail; /* NO free memory?! */
- if (llen < stack_frame_size+MIN_STACK+16)
- goto bail; /* Insufficient memory */
+ if (llen < stack_frame_size + MIN_STACK + 16)
+ goto bail; /* Insufficient memory */
- /* Initial stack pointer address */
- stack_pointer = (lstart+llen-stack_frame_size) & ~15;
+ /* Initial stack pointer address */
+ stack_pointer = (lstart + llen - stack_frame_size) & ~15;
- dprintf("Stack frame at 0x%08x len 0x%08x\n",
- stack_pointer, stack_frame_size);
+ dprintf("Stack frame at 0x%08x len 0x%08x\n",
+ stack_pointer, stack_frame_size);
- /* Create the stack frame. sfp is the pointer in current memory for
- the next argument string, sfa is the address in its final resting place.
- spp is the pointer into the argument array in current memory. */
- spp = (uint32_t *)stack_frame;
- sfp = stack_frame + argc*sizeof(char *) + 5*sizeof(long);
- sfa = stack_pointer + argc*sizeof(char *) + 5*sizeof(long);
+ /* Create the stack frame. sfp is the pointer in current memory for
+ the next argument string, sfa is the address in its final resting place.
+ spp is the pointer into the argument array in current memory. */
+ spp = (uint32_t *) stack_frame;
+ sfp = stack_frame + argc * sizeof(char *) + 5 * sizeof(long);
+ sfa = stack_pointer + argc * sizeof(char *) + 5 * sizeof(long);
- *spp++ = argc;
- for (argp = argv; *argp; argp++) {
- int bytes = strlen(*argp) + 1; /* Including final null */
- *spp++ = sfa;
- memcpy(sfp, *argp, bytes);
- sfp += bytes;
- sfa += bytes;
- }
- /* Zero fields are aready taken care of by calloc() */
+ *spp++ = argc;
+ for (argp = argv; *argp; argp++) {
+ int bytes = strlen(*argp) + 1; /* Including final null */
+ *spp++ = sfa;
+ memcpy(sfp, *argp, bytes);
+ sfp += bytes;
+ sfa += bytes;
+ }
+ /* Zero fields are aready taken care of by calloc() */
- /* ... and we'll want to move it into the right place... */
+ /* ... and we'll want to move it into the right place... */
#if DEBUG
- if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
- != SMT_FREE) {
- dprintf("Stack frame area not free (how did that happen?)!\n");
- goto bail; /* Memory region unavailable */
- }
+ if (syslinux_memmap_type(amap, stack_pointer, stack_frame_size)
+ != SMT_FREE) {
+ dprintf("Stack frame area not free (how did that happen?)!\n");
+ goto bail; /* Memory region unavailable */
+ }
#endif
- if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
- goto bail;
+ if (syslinux_add_memmap(&amap, stack_pointer, stack_frame_size, SMT_ALLOC))
+ goto bail;
- if (syslinux_add_movelist(&ml, stack_pointer, (addr_t)stack_frame,
- stack_frame_size))
- goto bail;
+ if (syslinux_add_movelist(&ml, stack_pointer, (addr_t) stack_frame,
+ stack_frame_size))
+ goto bail;
- memset(&regs, 0, sizeof regs);
- regs.eip = where;
- regs.esp = stack_pointer;
+ memset(&regs, 0, sizeof regs);
+ regs.eip = where;
+ regs.esp = stack_pointer;
#if DEBUG
- dprintf("Final memory map:\n");
- syslinux_dump_memmap(stdout, mmap);
+ dprintf("Final memory map:\n");
+ syslinux_dump_memmap(stdout, mmap);
- dprintf("Final available map:\n");
- syslinux_dump_memmap(stdout, amap);
+ dprintf("Final available map:\n");
+ syslinux_dump_memmap(stdout, amap);
- dprintf("Movelist:\n");
- syslinux_dump_movelist(stdout, ml);
+ dprintf("Movelist:\n");
+ syslinux_dump_movelist(stdout, ml);
#endif
- /* This should not return... */
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
+ /* This should not return... */
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_pm(ml, mmap, 0, &regs);
- bail:
- if (stack_frame)
- free(stack_frame);
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
+bail:
+ if (stack_frame)
+ free(stack_frame);
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
- return -1;
+ return -1;
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
- addr_t where;
+ void *data;
+ size_t data_len;
+ addr_t where;
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 3) {
- error("Usage: pmload.c32 bin_file address arguments...\n");
- return 1;
- }
+ if (argc < 3) {
+ error("Usage: pmload.c32 bin_file address arguments...\n");
+ return 1;
+ }
- where = strtoul(argv[2], NULL, 0);
+ where = strtoul(argv[2], NULL, 0);
- if (loadfile(argv[1], &data, &data_len)) {
- error("Unable to load file\n");
- return 1;
- }
+ if (loadfile(argv[1], &data, &data_len)) {
+ error("Unable to load file\n");
+ return 1;
+ }
- boot_raw(data, data_len, where, &argv[1]);
- error("Failed to boot, probably insufficient memory\n");
- return 1;
+ boot_raw(data, data_len, where, &argv[1]);
+ error("Failed to boot, probably insufficient memory\n");
+ return 1;
}
diff --git a/com32/modules/reboot.c b/com32/modules/reboot.c
index f5056759..a6d56474 100644
--- a/com32/modules/reboot.c
+++ b/com32/modules/reboot.c
@@ -3,14 +3,13 @@
int main(int argc, char *argv[])
{
- int warm = 0;
- int i;
+ int warm = 0;
+ int i;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-w") ||
- !strcmp(argv[i], "--warm"))
- warm = 1;
- }
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--warm"))
+ warm = 1;
+ }
- syslinux_reboot(warm);
+ syslinux_reboot(warm);
}
diff --git a/com32/modules/sanboot.c b/com32/modules/sanboot.c
index b8bfe25e..eee9f44c 100644
--- a/com32/modules/sanboot.c
+++ b/com32/modules/sanboot.c
@@ -26,115 +26,115 @@
#include <syslinux/config.h>
struct segoff16 {
- uint16_t offs, seg;
+ 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;
+ 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;
+ 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 */
+ 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;
+ 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);
+ 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);
+ __intcall(0x22, &reg, &reg);
- if (reg.eflags.l & EFLAGS_CF)
- return false; /* Cannot invoke PXE stack */
+ if (reg.eflags.l & EFLAGS_CF)
+ return false; /* Cannot invoke PXE stack */
- if (reg.eax.w[0] || fca->Status)
- return false; /* PXE failure */
+ if (reg.eax.w[0] || fca->Status)
+ return false; /* PXE failure */
- if (fca->Magic != 0xe9c17b20)
- return false; /* Incorrect magic */
+ if (fca->Magic != 0xe9c17b20)
+ return false; /* Incorrect magic */
- if (fca->Size < sizeof *fca)
- return false; /* Short return */
+ if (fca->Size < sizeof *fca)
+ return false; /* Short return */
- if (!(fca->APIMask & (1 << 5)))
- return false; /* No FILE EXEC */
+ if (!(fca->APIMask & (1 << 5)))
+ return false; /* No FILE EXEC */
- return true;
+ return true;
}
struct s_PXENV_FILE_EXEC {
- uint16_t Status;
- struct segoff16 Command;
+ uint16_t Status;
+ struct segoff16 Command;
};
static void sanboot(const char **args)
{
- char *q;
- struct s_PXENV_FILE_EXEC *fx;
- com32sys_t reg;
+ char *q;
+ struct s_PXENV_FILE_EXEC *fx;
+ com32sys_t reg;
- memset(&reg, 0, sizeof reg);
+ memset(&reg, 0, sizeof reg);
- fx = __com32.cs_bounce;
- q = (char *)(fx+1);
+ fx = __com32.cs_bounce;
+ q = (char *)(fx + 1);
- fx->Status = 1;
- fx->Command.offs = OFFS(q);
- fx->Command.seg = SEG(q);
+ fx->Status = 1;
+ fx->Command.offs = OFFS(q);
+ fx->Command.seg = SEG(q);
- q = stpcpy(q, "sanboot");
+ q = stpcpy(q, "sanboot");
- while (*args) {
- *q++ = ' ';
- q = stpcpy(q, *args);
- args++;
- }
+ while (*args) {
+ *q++ = ' ';
+ q = stpcpy(q, *args);
+ args++;
+ }
- 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);
+ 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);
+ __intcall(0x22, &reg, &reg);
- /* This should not return... */
+ /* This should not return... */
}
int main(int argc, const char *argv[])
{
- openconsole(&dev_null_r, &dev_stdcon_w);
+ openconsole(&dev_null_r, &dev_stdcon_w);
- if (argc < 2) {
- printf("Usage: sanboot rootpath\n");
- return 1;
- }
+ if (argc < 2) {
+ printf("Usage: sanboot rootpath\n");
+ return 1;
+ }
- if (!is_gpxe()) {
- printf("sanboot: gPXE API not detected\n");
- return 1;
- }
+ if (!is_gpxe()) {
+ printf("sanboot: gPXE API not detected\n");
+ return 1;
+ }
- sanboot(argv+1);
+ sanboot(argv + 1);
- /* sanboot() should not return... */
- printf("SAN boot failed.\n");
- return 1;
+ /* sanboot() should not return... */
+ printf("SAN boot failed.\n");
+ return 1;
}
diff --git a/com32/modules/sdi.c b/com32/modules/sdi.c
index 7c898591..4b882b39 100644
--- a/com32/modules/sdi.c
+++ b/com32/modules/sdi.c
@@ -1,6 +1,7 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2008 H. Peter Anvin - All Rights Reserved
+ * Copyright 2009 Intel Corporation; author: H. Peter Anvin
*
* 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
@@ -42,114 +43,108 @@
typedef uint8_t guid_t[16];
struct SDIHeader {
- uint32_t Signature;
- char Version[4];
- uint64_t MDBtype;
- uint64_t BootCodeOffset;
- uint64_t BootCodeSize;
- uint64_t VendorID;
- uint64_t DeviceID;
- guid_t DeviceModel;
- uint64_t DeviceRole;
- uint64_t Reserved1;
- guid_t RuntimeGUID;
- uint64_t RuntimeOEMrev;
- uint64_t Reserved2;
- uint64_t PageAlignment; /* BLOB alignment value in pages */
- uint64_t Reserved3[48];
- uint64_t Checksum;
+ uint32_t Signature;
+ char Version[4];
+ uint64_t MDBtype;
+ uint64_t BootCodeOffset;
+ uint64_t BootCodeSize;
+ uint64_t VendorID;
+ uint64_t DeviceID;
+ guid_t DeviceModel;
+ uint64_t DeviceRole;
+ uint64_t Reserved1;
+ guid_t RuntimeGUID;
+ uint64_t RuntimeOEMrev;
+ uint64_t Reserved2;
+ uint64_t PageAlignment; /* BLOB alignment value in pages */
+ uint64_t Reserved3[48];
+ uint64_t Checksum;
};
-#define SDI_LOAD_ADDR (16 << 20) /* 16 MB */
+#define SDI_LOAD_ADDR (16 << 20) /* 16 MB */
#define SDI_SIGNATURE ('$' + ('S' << 8) + ('D' << 16) + ('I' << 24))
static inline void error(const char *msg)
{
- fputs(msg, stderr);
+ fputs(msg, stderr);
}
static int boot_sdi(void *ptr, size_t len)
{
- const struct SDIHeader *hdr = ptr;
- struct syslinux_memmap *mmap = NULL, *amap = NULL;
- struct syslinux_rm_regs regs;
- struct syslinux_movelist *ml = NULL;
- char *boot_blob;
-
- /* **** Basic sanity checking **** */
- if (hdr->Signature != SDI_SIGNATURE) {
- fputs("No $SDI signature in file\n", stdout);
- goto bail;
- }
- if (memcmp(hdr->Version, "0001", 4)) {
- int i;
- fputs("Warning: unknown SDI version: ", stdout);
- for (i = 0; i < 4; i++)
- putchar(hdr->Version[i]);
- putchar('\n');
- /* Then try anyway... */
- }
-
- /* **** Setup **** */
- mmap = syslinux_memory_map();
- amap = syslinux_dup_memmap(mmap);
- if (!mmap || !amap)
- goto bail;
-
- /* **** Map the BOOT BLOB to 0x7c00 **** */
- if (!hdr->BootCodeOffset) {
- fputs("No BOOT BLOB in image\n", stdout);
- goto bail;
- }
- if (!hdr->BootCodeSize) {
- fputs("BOOT BLOB is empty\n", stdout);
- goto bail;
- }
- if (len < hdr->BootCodeOffset + hdr->BootCodeSize) {
- fputs("BOOT BLOB extends beyond file\n", stdout);
- goto bail;
- }
-
- if (syslinux_memmap_type(amap, 0x7c00, hdr->BootCodeSize) != SMT_FREE) {
- fputs("BOOT BLOB too large for memory\n", stdout);
- goto bail;
- }
- if (syslinux_add_memmap(&amap, 0x7c00, hdr->BootCodeSize, SMT_ALLOC))
- goto bail;
-
- /* The shuffle library doesn't handle duplication well... */
- boot_blob = malloc(hdr->BootCodeSize);
- if (!boot_blob)
- goto bail;
- memcpy(boot_blob, (char *)ptr + hdr->BootCodeOffset, hdr->BootCodeSize);
-
- if (syslinux_add_movelist(&ml, 0x7c00, (addr_t)boot_blob, hdr->BootCodeSize))
- goto bail;
-
- /* **** Map the entire image to SDI_LOAD_ADDR **** */
- if (syslinux_memmap_type(amap, SDI_LOAD_ADDR, len) != SMT_FREE) {
- fputs("Image too large for memory\n", stdout);
- goto bail;
- }
- if (syslinux_add_memmap(&amap, SDI_LOAD_ADDR, len, SMT_ALLOC))
- goto bail;
- if (syslinux_add_movelist(&ml, SDI_LOAD_ADDR, (addr_t)ptr, len))
- goto bail;
-
- /* **** Set up registers **** */
- memset(&regs, 0, sizeof regs);
- regs.ip = 0x7c00;
- regs.esp.l = 0x7c00;
- regs.edx.l = SDI_LOAD_ADDR | 0x41;
-
- fputs("Booting...\n", stdout);
- syslinux_shuffle_boot_rm(ml, mmap, 0, &regs);
-
- bail:
- syslinux_free_memmap(amap);
- syslinux_free_memmap(mmap);
- syslinux_free_movelist(ml);
- return -1;
+ const struct SDIHeader *hdr = ptr;
+ struct syslinux_memmap *mmap = NULL, *amap = NULL;
+ struct syslinux_rm_regs regs;
+ struct syslinux_movelist *ml = NULL;
+ char *boot_blob;
+
+ /* **** Basic sanity checking **** */
+ if (hdr->Signature != SDI_SIGNATURE) {
+ fputs("No $SDI signature in file\n", stdout);
+ goto bail;
+ }
+ if (memcmp(hdr->Version, "0001", 4)) {
+ int i;
+ fputs("Warning: unknown SDI version: ", stdout);
+ for (i = 0; i < 4; i++)
+ putchar(hdr->Version[i]);
+ putchar('\n');
+ /* Then try anyway... */
+ }
+
+ /* **** Setup **** */
+ mmap = syslinux_memory_map();
+ amap = syslinux_dup_memmap(mmap);
+ if (!mmap || !amap)
+ goto bail;
+
+ /* **** Map the BOOT BLOB to 0x7c00 **** */
+ if (!hdr->BootCodeOffset) {
+ fputs("No BOOT BLOB in image\n", stdout);
+ goto bail;
+ }
+ if (!hdr->BootCodeSize) {
+ fputs("BOOT BLOB is empty\n", stdout);
+ goto bail;
+ }
+ if (len < hdr->BootCodeOffset + hdr->BootCodeSize) {
+ fputs("BOOT BLOB extends beyond file\n", stdout);
+ goto bail;
+ }
+
+ if (syslinux_memmap_type(amap, 0x7c00, hdr->BootCodeSize) != SMT_FREE) {
+ fputs("BOOT BLOB too large for memory\n", stdout);
+ goto bail;
+ }
+ if (syslinux_add_memmap(&amap, 0x7c00, hdr->BootCodeSize, SMT_ALLOC))
+ goto bail;
+ if (syslinux_add_movelist(&ml, 0x7c00, (addr_t) ptr + hdr->BootCodeOffset,
+ hdr->BootCodeSize))
+ goto bail;
+
+ /* **** Map the entire image to SDI_LOAD_ADDR **** */
+ if (syslinux_memmap_type(amap, SDI_LOAD_ADDR, len) != SMT_FREE) {
+ fputs("Image too large for memory\n", stdout);
+ goto bail;
+ }
+ if (syslinux_add_memmap(&amap, SDI_LOAD_ADDR, len, SMT_ALLOC))
+ goto bail;
+ if (syslinux_add_movelist(&ml, SDI_LOAD_ADDR, (addr_t) ptr, len))
+ goto bail;
+
+ /* **** Set up registers **** */
+ memset(&regs, 0, sizeof regs);
+ regs.ip = 0x7c00;
+ regs.esp.l = 0x7c00;
+ regs.edx.l = SDI_LOAD_ADDR | 0x41;
+
+ fputs("Booting...\n", stdout);
+ syslinux_shuffle_boot_rm(ml, mmap, 0, &regs);
+
+bail:
+ syslinux_free_memmap(amap);
+ syslinux_free_memmap(mmap);
+ syslinux_free_movelist(ml);
+ return -1;
}
/*
@@ -158,42 +153,42 @@ static int boot_sdi(void *ptr, size_t len)
*/
int has_valid_header(unsigned char *header)
{
- unsigned char checksum;
- unsigned int i;
+ unsigned char checksum;
+ unsigned int i;
- checksum = 0;
- for (i = 0; i < sizeof(struct SDIHeader); i++)
- checksum += header[i];
- return (!checksum);
+ checksum = 0;
+ for (i = 0; i < sizeof(struct SDIHeader); i++)
+ checksum += header[i];
+ return (!checksum);
}
int main(int argc, char *argv[])
{
- void *data;
- size_t data_len;
-
- openconsole(&dev_null_r, &dev_stdcon_w);
-
- if (argc != 2) {
- error("Usage: sdi.c32 sdi_file\n");
- return 1;
- }
-
- fputs("Loading ", stdout);
- fputs(argv[1], stdout);
- fputs("... ", stdout);
- if (zloadfile(argv[1], &data, &data_len)) {
- error("failed!\n");
+ void *data;
+ size_t data_len;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if (argc != 2) {
+ error("Usage: sdi.c32 sdi_file\n");
+ return 1;
+ }
+
+ fputs("Loading ", stdout);
+ fputs(argv[1], stdout);
+ fputs("... ", stdout);
+ if (zloadfile(argv[1], &data, &data_len)) {
+ error("failed!\n");
+ return 1;
+ }
+ fputs("ok\n", stdout);
+
+ if (!has_valid_header(data)) {
+ error("SDI header is corrupted\n");
+ return 1;
+ }
+
+ boot_sdi(data, data_len);
+ error("Invalid SDI file or insufficient memory\n");
return 1;
- }
- fputs("ok\n", stdout);
-
- if (!has_valid_header(data)) {
- error("SDI header is corrupted\n");
- return 1;
- }
-
- boot_sdi(data, data_len);
- error("Invalid SDI file or insufficient memory\n");
- return 1;
}
diff --git a/com32/modules/vesainfo.c b/com32/modules/vesainfo.c
index a1f00299..00181e47 100644
--- a/com32/modules/vesainfo.c
+++ b/com32/modules/vesainfo.c
@@ -14,70 +14,69 @@
/* Wait for a keypress */
static void wait_key(void)
{
- char ch;
- while (fread(&ch, 1, 1, stdin) == 0)
- ;
+ char ch;
+ while (fread(&ch, 1, 1, stdin) == 0) ;
}
static void print_modes(void)
{
- static com32sys_t rm;
- struct vesa_general_info *gi;
- struct vesa_mode_info *mi;
- uint16_t mode, *mode_ptr;
- int lines;
+ static com32sys_t rm;
+ struct vesa_general_info *gi;
+ struct vesa_mode_info *mi;
+ uint16_t mode, *mode_ptr;
+ int lines;
- /* Allocate space in the bounce buffer for these structures */
- gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
- mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
+ /* Allocate space in the bounce buffer for these structures */
+ gi = &((struct vesa_info *)__com32.cs_bounce)->gi;
+ mi = &((struct vesa_info *)__com32.cs_bounce)->mi;
- gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
- rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
- rm.edi.w[0] = OFFS(gi);
- rm.es = SEG(gi);
- __intcall(0x10, &rm, &rm);
+ gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */
+ rm.eax.w[0] = 0x4F00; /* Get SVGA general information */
+ rm.edi.w[0] = OFFS(gi);
+ rm.es = SEG(gi);
+ __intcall(0x10, &rm, &rm);
- if ( rm.eax.w[0] != 0x004F ) {
- printf("No VESA BIOS detected\n");
- return;
- } else if ( gi->signature != VESA_MAGIC ) {
- printf("VESA information structure has bad magic, trying anyway...\n");
- }
+ if (rm.eax.w[0] != 0x004F) {
+ printf("No VESA BIOS detected\n");
+ return;
+ } else if (gi->signature != VESA_MAGIC) {
+ printf("VESA information structure has bad magic, trying anyway...\n");
+ }
- printf("VBE version %d.%d\n"
- "Mode attrib h_res v_res bpp layout rpos gpos bpos\n",
- (gi->version >> 8) & 0xff, gi->version & 0xff);
+ printf("VBE version %d.%d\n"
+ "Mode attrib h_res v_res bpp layout rpos gpos bpos\n",
+ (gi->version >> 8) & 0xff, gi->version & 0xff);
- lines = 1;
+ lines = 1;
- mode_ptr = GET_PTR(gi->video_mode_ptr);
+ mode_ptr = GET_PTR(gi->video_mode_ptr);
- while ((mode = *mode_ptr++) != 0xFFFF) {
- if (++lines >= 23) {
- wait_key();
- lines = 0;
- }
+ while ((mode = *mode_ptr++) != 0xFFFF) {
+ if (++lines >= 23) {
+ wait_key();
+ lines = 0;
+ }
- rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
- rm.ecx.w[0] = mode;
- rm.edi.w[0] = OFFS(mi);
- rm.es = SEG(mi);
- __intcall(0x10, &rm, &rm);
+ rm.eax.w[0] = 0x4F01; /* Get SVGA mode information */
+ rm.ecx.w[0] = mode;
+ rm.edi.w[0] = OFFS(mi);
+ rm.es = SEG(mi);
+ __intcall(0x10, &rm, &rm);
- /* Must be a supported mode */
- if ( rm.eax.w[0] != 0x004f )
- continue;
+ /* Must be a supported mode */
+ if (rm.eax.w[0] != 0x004f)
+ continue;
- printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n",
- mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp,
- mi->memory_layout, mi->rpos, mi->gpos, mi->bpos);
- }
+ printf("0x%04x 0x%04x %5u %5u %3u %6u %4u %4u %4u\n",
+ mode, mi->mode_attr, mi->h_res, mi->v_res, mi->bpp,
+ mi->memory_layout, mi->rpos, mi->gpos, mi->bpos);
+ }
}
int main(void)
{
- openconsole(&dev_rawcon_r, &dev_stdcon_w);
+ openconsole(&dev_rawcon_r, &dev_stdcon_w);
- print_modes();
- return 0;
+ print_modes();
+ return 0;
}
diff --git a/com32/modules/vpdtest.c b/com32/modules/vpdtest.c
index 81a9faeb..5950b2c4 100644
--- a/com32/modules/vpdtest.c
+++ b/com32/modules/vpdtest.c
@@ -39,30 +39,32 @@
int main(void)
{
- char buffer[1024];
- s_vpd vpd;
- openconsole(&dev_stdcon_r, &dev_stdcon_w);
+ char buffer[1024];
+ s_vpd vpd;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
- if (vpd_decode(&vpd) == -ENOVPDTABLE) {
+ if (vpd_decode(&vpd) == -ENOVPDTABLE) {
printf("No VPD Structure found\n");
return -1;
- } else {
- printf("VPD present at address : 0x%s\n",vpd.base_address);
- }
- if (strlen(vpd.bios_build_id)>0)
- printf("Bios Build ID : %s\n",vpd.bios_build_id);
- if (strlen(vpd.bios_release_date)>0)
- printf("Bios Release Date : %s\n",vpd.bios_release_date);
- if (strlen(vpd.bios_version)>0)
- printf("Bios Version : %s\n",vpd.bios_version);
- if (strlen(vpd.default_flash_filename)>0)
- printf("Default Flash Filename : %s\n",vpd.default_flash_filename);
- if (strlen(vpd.box_serial_number)>0)
- printf("Box Serial Number : %s\n",vpd.box_serial_number);
- if (strlen(vpd.motherboard_serial_number)>0)
- printf("Motherboard Serial Number : %s\n",vpd.motherboard_serial_number);
- if (strlen(vpd.machine_type_model)>0)
- printf("Machine Type/Model : %s\n",vpd.machine_type_model);
+ } else {
+ printf("VPD present at address : 0x%s\n", vpd.base_address);
+ }
+ if (strlen(vpd.bios_build_id) > 0)
+ printf("Bios Build ID : %s\n", vpd.bios_build_id);
+ if (strlen(vpd.bios_release_date) > 0)
+ printf("Bios Release Date : %s\n", vpd.bios_release_date);
+ if (strlen(vpd.bios_version) > 0)
+ printf("Bios Version : %s\n", vpd.bios_version);
+ if (strlen(vpd.default_flash_filename) > 0)
+ printf("Default Flash Filename : %s\n",
+ vpd.default_flash_filename);
+ if (strlen(vpd.box_serial_number) > 0)
+ printf("Box Serial Number : %s\n", vpd.box_serial_number);
+ if (strlen(vpd.motherboard_serial_number) > 0)
+ printf("Motherboard Serial Number : %s\n",
+ vpd.motherboard_serial_number);
+ if (strlen(vpd.machine_type_model) > 0)
+ printf("Machine Type/Model : %s\n", vpd.machine_type_model);
- return 0;
+ return 0;
}