Skip to content

Commit

Permalink
Merge remote branch 'genec/memdisk-maxmem-for-hpa'
Browse files Browse the repository at this point in the history
  • Loading branch information
H. Peter Anvin committed Mar 2, 2011
2 parents 051e3b6 + a028af9 commit 74ee14e
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 37 deletions.
41 changes: 41 additions & 0 deletions 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 */

2 changes: 2 additions & 0 deletions com32/lib/Makefile
Expand Up @@ -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 \
Expand Down
72 changes: 72 additions & 0 deletions 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;
}
37 changes: 1 addition & 36 deletions com32/lib/syslinux/load_linux.c
Expand Up @@ -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>
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion memdisk/Makefile
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions memdisk/ctypes.c
@@ -0,0 +1 @@
#include "../com32/lib/ctypes.c"
37 changes: 37 additions & 0 deletions memdisk/setup.c
Expand Up @@ -14,6 +14,8 @@
* ----------------------------------------------------------------------- */

#include <stdint.h>
#include <minmax.h>
#include <suffix_number.h>
#include "bda.h"
#include "dskprobe.h"
#include "e820.h"
Expand Down Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions memdisk/strntoumax.c
@@ -0,0 +1 @@
#include "../com32/lib/strntoumax.c"
1 change: 1 addition & 0 deletions memdisk/strtoull.c
@@ -0,0 +1 @@
#include "../com32/lib/strtoull.c"
1 change: 1 addition & 0 deletions memdisk/strtox.c
@@ -0,0 +1 @@
#include "../com32/lib/strtox.c"
1 change: 1 addition & 0 deletions memdisk/suffix_number.c
@@ -0,0 +1 @@
#include "../com32/lib/suffix_number.c"

0 comments on commit 74ee14e

Please sign in to comment.