aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Soltys <soltys@ziu.info>2013-02-14 16:51:46 +0100
committerMichal Soltys <soltys@ziu.info>2013-02-14 16:53:05 +0100
commitd9976c5f4230aa0bcc6f6572091bd2732bf35db9 (patch)
treefaf76f1f6af0cf348b19d8e13fa5e9529daeae40
parent9729a776507e811040ebb65699312b4620546ba3 (diff)
downloadsyslinux-d9976c5f4230aa0bcc6f6572091bd2732bf35db9.tar.gz
syslinux-d9976c5f4230aa0bcc6f6572091bd2732bf35db9.tar.xz
syslinux-d9976c5f4230aa0bcc6f6572091bd2732bf35db9.zip
com32/chain: rely more on addr_t, replace ADDR*
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@ziu.info>
-rw-r--r--com32/chain/chain.c10
-rw-r--r--com32/chain/options.c23
-rw-r--r--com32/chain/options.h16
-rw-r--r--com32/chain/utility.h5
4 files changed, 32 insertions, 22 deletions
diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index 87dea378..0c83a5a2 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 70f50697..531caf82 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 a53f38bf..7b625826 100644
--- a/com32/chain/options.h
+++ b/com32/chain/options.h
@@ -33,9 +33,7 @@
#include <stdint.h>
#include <syslinux/bootrm.h>
-
-#define ADDRMAX 0x9EFFFu
-#define ADDRMIN 0x500u
+#include <syslinux/movebits.h>
enum {HIDE_OFF = 0, HIDE_ON = 1, HIDE_EXT = 2, HIDE_REV = 4};
@@ -44,12 +42,12 @@ struct options {
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 08442aef..c9d46525 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
@@ -48,6 +49,10 @@
/* see utility.c for details */
enum {L2C_CNUL, L2C_CADD, L2C_CMAX};
+/* 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);