[syslinux] [PATCH 19/23] com32/chain: rely more on addr_t, replace ADDR*

Michal Soltys soltys at ziu.info
Mon Nov 5 16:32:53 PST 2012


Whenever the computation imply use of that type, even if it's just
uint32_t.

Add dosmax (using 40:13) and dosmin (0x500) instead of separate ADDR*
and dosmem (in do_boot()).

Signed-off-by: Michal Soltys <soltys at ziu.info>
---
 com32/chain/chain.c   |   10 ++++------
 com32/chain/options.c |   23 ++++++++++++++++-------
 com32/chain/options.h |   16 +++++++---------
 com32/chain/utility.h |    5 +++++
 4 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index 38e647c..748c8c0 100644
--- a/com32/chain/chain.c
+++ b/com32/chain/chain.c
@@ -155,8 +155,6 @@ ok:
 
 static void do_boot(struct data_area *data, int ndata)
 {
-    uint16_t *const bios_fbm = (uint16_t *) 0x413;
-    addr_t dosmem = (addr_t)(*bios_fbm << 10);	/* Technically a low bound */
     struct syslinux_memmap *mmap;
     struct syslinux_movelist *mlist = NULL;
     addr_t endimage;
@@ -176,7 +174,7 @@ static void do_boot(struct data_area *data, int ndata)
 	if (data[i].base + data[i].size > endimage)
 	    endimage = data[i].base + data[i].size;
     }
-    if (endimage > dosmem)
+    if (endimage > dosmax)
 	goto too_big;
 
     for (i = 0; i < ndata; i++) {
@@ -222,7 +220,7 @@ static void do_boot(struct data_area *data, int ndata)
 	static uint8_t swapstub[1024];
 	uint8_t *p;
 
-	/* Note: we can't rely on either INT 13h nor the dosmem
+	/* Note: we can't rely on either INT 13h nor the dosmax
 	   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
@@ -530,7 +528,7 @@ int main(int argc, char *argv[])
 	    error("Couldn't read the boot file.");
 	    goto bail;
 	}
-	if (fdat.base + fdat.size - 1 > ADDRMAX) {
+	if (fdat.base + fdat.size > dosmax) {
 	    error("The boot file is too big to load at this address.");
 	    goto bail;
 	}
@@ -541,7 +539,7 @@ int main(int argc, char *argv[])
 	sdat.base = (opt.sseg << 4) + opt.soff;
 	sdat.size = iter->di.bps;
 
-	if (sdat.base + sdat.size - 1 > ADDRMAX) {
+	if (sdat.base + sdat.size > dosmax) {
 	    error("The sector cannot be loaded at such high address.");
 	    goto bail;
 	}
diff --git a/com32/chain/options.c b/com32/chain/options.c
index 4df2459..5d76219 100644
--- a/com32/chain/options.c
+++ b/com32/chain/options.c
@@ -28,6 +28,7 @@
  *
  * ----------------------------------------------------------------------- */
 
+#include <syslinux/movebits.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -38,14 +39,17 @@
 
 struct options opt;
 
-static int soi_s2n(char *ptr, unsigned int *seg,
-		       unsigned int *off,
-		       unsigned int *ip,
-		       unsigned int def)
+static int soi_s2n(char *ptr,
+			addr_t *seg,
+			addr_t *off,
+			addr_t *ip,
+			addr_t def)
 {
-    unsigned int segval = 0, offval, ipval, val;
+    addr_t segval, offval, ipval, val;
     char *p;
 
+    /* defaults */
+    segval = 0;
     offval = def;
     ipval = def;
 
@@ -55,16 +59,21 @@ static int soi_s2n(char *ptr, unsigned int *seg,
     if (p[0] == ':' && p[1] && p[1] != ':')
 	ipval = strtoul(p+1, NULL, 0);
 
+    /* verify if load address is within [dosmin, dosmax) */
     val = (segval << 4) + offval;
 
-    if (val < ADDRMIN || val > ADDRMAX) {
+    if (val < dosmin || val >= dosmax) {
 	error("Invalid seg:off:* address specified.");
 	goto bail;
     }
 
+    /*
+     * verify if jump address is within [dosmin, dosmax) and offset is 16bit
+     * sane
+     */
     val = (segval << 4) + ipval;
 
-    if (ipval > 0xFFFE || val < ADDRMIN || val > ADDRMAX) {
+    if (ipval > 0xFFFE || val < dosmin || val >= dosmax) {
 	error("Invalid seg:*:ip address specified.");
 	goto bail;
     }
diff --git a/com32/chain/options.h b/com32/chain/options.h
index db33df3..008c9cb 100644
--- a/com32/chain/options.h
+++ b/com32/chain/options.h
@@ -33,21 +33,19 @@
 
 #include <stdint.h>
 #include <syslinux/bootrm.h>
-
-#define ADDRMAX 0x9EFFFu
-#define ADDRMIN 0x500u
+#include <syslinux/movebits.h>
 
 struct options {
     const char *drivename;
     const char *partition;
     const char *file;
     const char *grubcfg;
-    unsigned int fseg;
-    unsigned int foff;
-    unsigned int fip;
-    unsigned int sseg;
-    unsigned int soff;
-    unsigned int sip;
+    addr_t fseg;
+    addr_t foff;
+    addr_t fip;
+    addr_t sseg;
+    addr_t soff;
+    addr_t sip;
     int hide;
     int relax;
     int prefmbr;
diff --git a/com32/chain/utility.h b/com32/chain/utility.h
index a5b06cc..49c7946 100644
--- a/com32/chain/utility.h
+++ b/com32/chain/utility.h
@@ -34,6 +34,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <syslinux/disk.h>
+#include <syslinux/movebits.h>
 
 #define bpbUNK	0
 #define bpbV20	1
@@ -50,6 +51,10 @@
 #define l2c_cadd 1
 #define l2c_cmax 2
 
+/* first usable and first unusable offsets */
+#define dosmin ((addr_t)0x500u)
+#define dosmax ((addr_t)(*(uint16_t *) 0x413 << 10))
+
 void wait_key(void);
 void lba2chs(disk_chs *dst, const struct disk_info *di, uint64_t lba, int mode);
 uint32_t get_file_lba(const char *filename);
-- 
1.7.10.4




More information about the Syslinux mailing list