summaryrefslogtreecommitdiff
path: root/com32
diff options
context:
space:
mode:
authorMichal Soltys <soltys@ziu.info>2010-10-25 12:30:19 +0200
committerMichal Soltys <soltys@ziu.info>2010-10-25 12:54:00 +0200
commitbf72d12c6116df8b8a88cc66adcbb46053c4a3f5 (patch)
tree56e41feba7fcfb23220ed2f4b6bd3c880e03d16c /com32
parentf0618a1eab06703fc66e6815e4a9e0b8aac1bc8b (diff)
downloadsyslinux-bf72d12c6116df8b8a88cc66adcbb46053c4a3f5.tar.gz
com32/chain: minor fixes and cleanups
- make sure opt.maps implies opt.sect, and simplify conditions throughout the files - move structure opt -> options.c - adjust #includes - omitted values in seg= and sect= are assumed 0 in all cases now - mangler_handover(): eax for gpt handover set only for iterated disks - rename parse_args() -> opt_parse_args() - rename mangler_common() -> mangler_init() - add opt_set_defs() - if mmapped sector would conflict with the file, turn off mmapping instead of bailing out - update temporary chain.txt to reflect changes + other fixups Signed-off-by: Michal Soltys <soltys@ziu.info>
Diffstat (limited to 'com32')
-rw-r--r--com32/chain/chain.c55
-rw-r--r--com32/chain/chain.h6
-rw-r--r--com32/chain/mangle.c6
-rw-r--r--com32/chain/mangle.h7
-rw-r--r--com32/chain/options.c30
-rw-r--r--com32/chain/options.h11
6 files changed, 64 insertions, 51 deletions
diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index 99eed0eb..f0d14971 100644
--- a/com32/chain/chain.c
+++ b/com32/chain/chain.c
@@ -41,8 +41,6 @@
#include "partiter.h"
#include "mangle.h"
-struct options opt;
-
static int fixed_cnt = 128; /* see comments in main() */
static int overlap(const struct data_area *a, const struct data_area *b)
@@ -496,38 +494,28 @@ bail:
int main(int argc, char *argv[])
{
struct part_iter *iter = NULL;
-
void *sbck = NULL;
struct data_area fdat, hdat, sdat, data[3];
int ndata = 0;
console_ansi_raw();
-/* openconsole(&dev_null_r, &dev_stdcon_w);*/
- /* Prepare and set defaults */
memset(&fdat, 0, sizeof(fdat));
memset(&hdat, 0, sizeof(hdat));
memset(&sdat, 0, sizeof(sdat));
- memset(&opt, 0, sizeof(opt));
- opt.sect = true; /* by def. load sector */
- opt.maps = true; /* by def. map sector */
- opt.hand = true; /* by def. prepare handover */
- opt.chain = true; /* by def. do chainload */
- opt.foff = opt.soff = opt.fip = opt.sip = 0x7C00;
- opt.drivename = "boot";
-#ifdef DEBUG
- opt.warn = true;
-#endif
- /* Parse arguments */
- if (parse_args(argc, argv))
+ opt_set_defs();
+ if (opt_parse_args(argc, argv))
goto bail;
+
#if 0
/* Get max fixed disk number */
fixed_cnt = *(uint8_t *)(0x475);
/*
- * hmm, looks like we can't do that
+ * hmm, looks like we can't do that -
+ * some bioses/vms just set it to 1
+ * and go on living happily
* any better options than hardcoded 0x80 - 0xFF ?
*/
#endif
@@ -563,21 +551,20 @@ int main(int argc, char *argv[])
error("The sector cannot be loaded at such high address.\n");
goto bail;
}
- if (opt.file && opt.maps && overlap(&fdat, &sdat)) {
- error("WARNING: The sector won't be loaded, as it would conflict with the boot file.\n");
- opt.sect = false;
- } else {
- if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) {
- error("Couldn't read the sector.\n");
+ if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) {
+ error("Couldn't read the sector.\n");
+ goto bail;
+ }
+ if (opt.save) {
+ if (!(sbck = malloc(sdat.size))) {
+ error("Couldn't allocate cmp-buf for option 'save'.\n");
goto bail;
}
- if (opt.save) {
- if (!(sbck = malloc(sdat.size))) {
- error("Couldn't allocate cmp-buf for option 'save'.\n");
- goto bail;
- }
- memcpy(sbck, sdat.data, sdat.size);
- }
+ memcpy(sbck, sdat.data, sdat.size);
+ }
+ if (opt.file && opt.maps && overlap(&fdat, &sdat)) {
+ error("WARNING: The sector won't be mmapped, as it would conflict with the boot file.\n");
+ opt.maps = false;
}
}
@@ -587,7 +574,7 @@ int main(int argc, char *argv[])
goto bail;
/* Verify possible conflicts */
if ( ( opt.file && overlap(&fdat, &hdat)) ||
- ( opt.sect && overlap(&sdat, &hdat) && opt.maps) ) {
+ ( opt.maps && overlap(&sdat, &hdat)) ) {
error("WARNING: Handover area won't be prepared,\n"
"as it would conflict with the boot file and/or the sector.\n");
opt.hand = false;
@@ -596,7 +583,7 @@ int main(int argc, char *argv[])
/* Adjust registers */
- mangler_common(iter);
+ mangler_init(iter);
mangler_handover(iter, &hdat);
mangler_grldr(iter);
@@ -634,7 +621,7 @@ int main(int argc, char *argv[])
if (opt.file)
memcpy(data + ndata++, &fdat, sizeof(fdat));
- if (opt.sect && opt.maps)
+ if (opt.maps)
memcpy(data + ndata++, &sdat, sizeof(sdat));
if (opt.hand)
memcpy(data + ndata++, &hdat, sizeof(hdat));
diff --git a/com32/chain/chain.h b/com32/chain/chain.h
index 67144753..fc481bc6 100644
--- a/com32/chain/chain.h
+++ b/com32/chain/chain.h
@@ -1,9 +1,7 @@
#ifndef _COM32_CHAIN_CHAIN_H
#define _COM32_CHAIN_CHAIN_H
-#include <stdint.h>
-#include <syslinux/bootrm.h>
-#include "options.h"
+#include <syslinux/movebits.h>
struct data_area {
void *data;
@@ -11,8 +9,6 @@ struct data_area {
addr_t size;
};
-extern struct options opt;
-
#endif
/* vim: set ts=8 sts=4 sw=4 noet: */
diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c
index e4d4be36..c32cd5c8 100644
--- a/com32/chain/mangle.c
+++ b/com32/chain/mangle.c
@@ -392,7 +392,7 @@ int mangles_cmldr(struct data_area *data)
}
/* Set common registers */
-int mangler_common(const struct part_iter *iter)
+int mangler_init(const struct part_iter *iter)
{
/* Set initial registry values */
if (opt.file) {
@@ -415,7 +415,7 @@ int mangler_common(const struct part_iter *iter)
/* ds:si & ds:bp */
int mangler_handover(const struct part_iter *iter, const struct data_area *data)
{
- if (opt.sect && opt.file && opt.maps && !opt.hptr) {
+ if (opt.file && opt.maps && !opt.hptr) {
opt.regs.esi.l = opt.regs.ebp.l = opt.soff;
opt.regs.ds = (uint16_t)opt.sseg;
opt.regs.eax.l = 0;
@@ -423,7 +423,7 @@ int mangler_handover(const struct part_iter *iter, const struct data_area *data)
/* base is really 0x7be */
opt.regs.esi.l = opt.regs.ebp.l = data->base;
opt.regs.ds = 0;
- if (iter->type == typegpt)
+ if (iter->index && iter->type == typegpt) /* must be iterated and GPT */
opt.regs.eax.l = 0x54504721; /* '!GPT' */
else
opt.regs.eax.l = 0;
diff --git a/com32/chain/mangle.h b/com32/chain/mangle.h
index eff24b98..4e097933 100644
--- a/com32/chain/mangle.h
+++ b/com32/chain/mangle.h
@@ -4,21 +4,26 @@
#include "chain.h"
#include "partiter.h"
+/* file's manglers */
int manglef_isolinux(struct data_area *data);
int manglef_grub(const struct part_iter *iter, struct data_area *data);
int manglef_bpb(const struct part_iter *iter, struct data_area *data);
/* int manglef_drmk(struct data_area *data);*/
+/* sector's manglers */
int mangles_bpb(const struct part_iter *iter, struct data_area *data);
int mangles_save(const struct part_iter *iter, const struct data_area *data, void *org);
int mangles_cmldr(struct data_area *data);
+/* sector + file's manglers */
int manglesf_bss(struct data_area *sec, struct data_area *fil);
-int mangler_common(const struct part_iter *iter);
+/* registers' manglers */
+int mangler_init(const struct part_iter *iter);
int mangler_handover(const struct part_iter *iter, const struct data_area *data);
int mangler_grldr(const struct part_iter *iter);
+/* partition layout's manglers */
int manglepe_mbrchshide(struct part_iter *miter);
#endif
diff --git a/com32/chain/options.c b/com32/chain/options.c
index 37b9f114..288fe770 100644
--- a/com32/chain/options.c
+++ b/com32/chain/options.c
@@ -6,7 +6,9 @@
#include "utility.h"
#include "options.h"
-int soi_s2n(char *ptr, unsigned int *seg,
+struct options opt;
+
+static int soi_s2n(char *ptr, unsigned int *seg,
unsigned int *off,
unsigned int *ip,
unsigned int def)
@@ -49,7 +51,7 @@ bail:
return -1;
}
-void usage(void)
+static void usage(void)
{
unsigned int i;
static const char key[] = "Press any key...\n";
@@ -116,7 +118,21 @@ Usage:\n\
}
}
-int parse_args(int argc, char *argv[])
+void opt_set_defs(void)
+{
+ memset(&opt, 0, sizeof(opt));
+ opt.sect = true; /* by def. load sector */
+ opt.maps = true; /* by def. map sector */
+ opt.hand = true; /* by def. prepare handover */
+ opt.chain = true; /* by def. do chainload */
+ opt.foff = opt.soff = opt.fip = opt.sip = 0x7C00;
+ opt.drivename = "boot";
+#ifdef DEBUG
+ opt.warn = true;
+#endif
+}
+
+int opt_parse_args(int argc, char *argv[])
{
int i;
unsigned int v;
@@ -250,12 +266,13 @@ int parse_args(int argc, char *argv[])
} else if (!strncmp(argv[i], "sect=", 5) ||
!strcmp(argv[i], "sect")) {
if (argv[i][4]) {
- if (soi_s2n(argv[i] + 5, &opt.sseg, &opt.soff, &opt.sip, 0x7c00))
+ if (soi_s2n(argv[i] + 5, &opt.sseg, &opt.soff, &opt.sip, 0))
goto bail;
}
opt.sect = true;
} else if (!strcmp(argv[i], "nosect")) {
opt.sect = false;
+ opt.maps = false;
} else if (!strcmp(argv[i], "save")) {
opt.save = true;
} else if (!strcmp(argv[i], "nosave")) {
@@ -331,6 +348,11 @@ int parse_args(int argc, char *argv[])
goto bail;
}
+ if (opt.maps && !opt.sect) {
+ error("Option 'maps' requires option 'sect'.\n");
+ goto bail;
+ }
+
return 0;
bail:
return -1;
diff --git a/com32/chain/options.h b/com32/chain/options.h
index bc244f60..17c6a739 100644
--- a/com32/chain/options.h
+++ b/com32/chain/options.h
@@ -1,6 +1,9 @@
#ifndef _COM32_CHAIN_OPTIONS_H
#define _COM32_CHAIN_OPTIONS_H
+#include <stdint.h>
+#include <syslinux/bootrm.h>
+
struct options {
unsigned int fseg;
unsigned int foff;
@@ -34,10 +37,10 @@ struct options {
struct syslinux_rm_regs regs;
};
-int soi_s2n(char *ptr, unsigned int *seg, unsigned int *off,
- unsigned int *ip, unsigned int def);
-void usage(void);
-int parse_args(int argc, char *argv[]);
+extern struct options opt;
+
+void opt_set_defs(void);
+int opt_parse_args(int argc, char *argv[]);
#endif