summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--com32/include/suffix_number.h41
-rw-r--r--com32/lib/Makefile2
-rw-r--r--com32/lib/suffix_number.c72
-rw-r--r--com32/lib/syslinux/load_linux.c37
-rw-r--r--memdisk/Makefile4
-rw-r--r--memdisk/ctypes.c1
-rw-r--r--memdisk/setup.c37
-rw-r--r--memdisk/strntoumax.c1
-rw-r--r--memdisk/strtoull.c1
-rw-r--r--memdisk/strtox.c1
-rw-r--r--memdisk/suffix_number.c1
11 files changed, 161 insertions, 37 deletions
diff --git a/com32/include/suffix_number.h b/com32/include/suffix_number.h
new file mode 100644
index 00000000..e2349b41
--- /dev/null
+++ b/com32/include/suffix_number.h
@@ -0,0 +1,41 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * suffix_number.h
+ *
+ * Definitions used to convert a string of a number with potential SI suffix
+ * to int-type.
+ */
+
+#ifndef LIBUTIL_SUFFIX_NUMBER_H
+#define LIBUTIL_SUFFIX_NUMBER_H
+
+unsigned long long suffix_number(const char *);
+
+#endif /* LIBUTIL_SUFFIX_NUMBER_H */
+
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 7bfc0dbf..48a166dd 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -33,6 +33,8 @@ LIBOBJS = \
\
dprintf.o vdprintf.o \
\
+ suffix_number.o \
+ \
sys/readdir.o getcwd.o chdir.o fdopendir.o \
\
libgcc/__ashldi3.o libgcc/__udivdi3.o \
diff --git a/com32/lib/suffix_number.c b/com32/lib/suffix_number.c
new file mode 100644
index 00000000..df073a00
--- /dev/null
+++ b/com32/lib/suffix_number.c
@@ -0,0 +1,72 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007-2009 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
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * suffix_number.c
+ *
+ * Convert a string of a number with potential SI suffix to int-type
+ */
+
+#include <stdlib.h>
+#include <suffix_number.h>
+
+/* Get a value with a potential suffix (k/m/g/t/p/e) */
+unsigned long long suffix_number(const char *str)
+{
+ 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;
+}
diff --git a/com32/lib/syslinux/load_linux.c b/com32/lib/syslinux/load_linux.c
index df793625..3ac6e5d0 100644
--- a/com32/lib/syslinux/load_linux.c
+++ b/com32/lib/syslinux/load_linux.c
@@ -38,6 +38,7 @@
#include <inttypes.h>
#include <string.h>
#include <minmax.h>
+#include <suffix_number.h>
#include <syslinux/align.h>
#include <syslinux/linux.h>
#include <syslinux/bootrm.h>
@@ -96,42 +97,6 @@ struct linux_header {
#define LOAD_HIGH 0x01
#define CAN_USE_HEAP 0x80
-/* Get a value with a potential suffix (k/m/g/t/p/e) */
-static unsigned long long suffix_number(const char *str)
-{
- 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;
-}
-
/*
* Find the last instance of a particular command line argument
* (which should include the final =; do not use for boolean arguments)
diff --git a/memdisk/Makefile b/memdisk/Makefile
index d2f20c51..92f565a4 100644
--- a/memdisk/Makefile
+++ b/memdisk/Makefile
@@ -39,10 +39,12 @@ endif
OBJS16 = init.o16 init32.o
OBJS32 = start32.o setup.o msetup.o e820func.o conio.o memcpy.o memset.o \
memmove.o unzip.o dskprobe.o eltorito.o \
+ ctypes.o strntoumax.o strtoull.o suffix_number.o \
memdisk_chs_512.o memdisk_edd_512.o \
memdisk_iso_512.o memdisk_iso_2048.o
-CSRC = setup.c msetup.c e820func.c conio.c unzip.c dskprobe.c eltorito.c
+CSRC = setup.c msetup.c e820func.c conio.c unzip.c dskprobe.c eltorito.c \
+ ctypes.c strntoumax.c strtoull.c suffix_number.c
SSRC = start32.S memcpy.S memset.S memmove.S
NASMSRC = memdisk_chs_512.asm memdisk_edd_512.asm \
memdisk_iso_512.asm memdisk_iso_2048.asm \
diff --git a/memdisk/ctypes.c b/memdisk/ctypes.c
new file mode 100644
index 00000000..f87ca055
--- /dev/null
+++ b/memdisk/ctypes.c
@@ -0,0 +1 @@
+#include "../com32/lib/ctypes.c"
diff --git a/memdisk/setup.c b/memdisk/setup.c
index 43151898..61cf420c 100644
--- a/memdisk/setup.c
+++ b/memdisk/setup.c
@@ -14,6 +14,8 @@
* ----------------------------------------------------------------------- */
#include <stdint.h>
+#include <minmax.h>
+#include <suffix_number.h>
#include "bda.h"
#include "dskprobe.h"
#include "e820.h"
@@ -705,6 +707,36 @@ static int stack_needed(void)
return v;
}
+/*
+ * Set max memory by reservation
+ * Adds reservations to data in INT15h to prevent access to the top of RAM
+ * if there's any above the point specified.
+ */
+void setmaxmem(unsigned long long restop_ull)
+{
+ uint32_t restop;
+ struct e820range *ep;
+ const int int15restype = 2;
+
+ /* insertrange() works on uint32_t */
+ restop = min(restop_ull, UINT32_MAX);
+ /* printf(" setmaxmem '%08x%08x' => %08x\n",
+ (unsigned int)(restop_ull>>32), (unsigned int)restop_ull, restop); */
+
+ for (ep = ranges; ep->type != -1U; ep++) {
+ if (ep->type == 1) { /* Only if available */
+ if (ep->start >= restop) {
+ /* printf(" %08x -> 2\n", ep->start); */
+ ep->type = int15restype;
+ } else if (ep[1].start > restop) {
+ /* printf(" +%08x =2; cut %08x\n", restop, ep->start); */
+ insertrange(restop, (ep[1].start - restop), int15restype);
+ }
+ }
+ }
+ parse_mem();
+}
+
struct real_mode_args rm_args;
/*
@@ -737,6 +769,7 @@ void setup(const struct real_mode_args *rm_args_ptr)
int no_bpt; /* No valid BPT presented */
uint32_t boot_seg = 0; /* Meaning 0000:7C00 */
uint32_t boot_len = 512; /* One sector */
+ const char *p;
/* We need to copy the rm_args into their proper place */
memcpy(&rm_args, rm_args_ptr, sizeof rm_args);
@@ -942,6 +975,10 @@ void setup(const struct real_mode_args *rm_args_ptr)
pptr->cd_pkt.geom3 = (uint8_t)(pptr->heads);
}
+ if ((p = getcmditem("mem")) != CMD_NOTFOUND) {
+ setmaxmem(suffix_number(p));
+ }
+
/* The size is given by hptr->total_size plus the size of the E820
map -- 12 bytes per range; we may need as many as 2 additional
ranges (each insertrange() can worst-case turn 1 area into 3)
diff --git a/memdisk/strntoumax.c b/memdisk/strntoumax.c
new file mode 100644
index 00000000..6fa2f357
--- /dev/null
+++ b/memdisk/strntoumax.c
@@ -0,0 +1 @@
+#include "../com32/lib/strntoumax.c"
diff --git a/memdisk/strtoull.c b/memdisk/strtoull.c
new file mode 100644
index 00000000..e2425df3
--- /dev/null
+++ b/memdisk/strtoull.c
@@ -0,0 +1 @@
+#include "../com32/lib/strtoull.c"
diff --git a/memdisk/strtox.c b/memdisk/strtox.c
new file mode 100644
index 00000000..445681f4
--- /dev/null
+++ b/memdisk/strtox.c
@@ -0,0 +1 @@
+#include "../com32/lib/strtox.c"
diff --git a/memdisk/suffix_number.c b/memdisk/suffix_number.c
new file mode 100644
index 00000000..d01c5a37
--- /dev/null
+++ b/memdisk/suffix_number.c
@@ -0,0 +1 @@
+#include "../com32/lib/suffix_number.c"