diff options
author | Tobias Weingartner <weingart@cvs.openbsd.org> | 2010-07-02 00:36:53 +0000 |
---|---|---|
committer | Tobias Weingartner <weingart@cvs.openbsd.org> | 2010-07-02 00:36:53 +0000 |
commit | 685d6be3a2d189b4a76502e5e07f6b1196738555 (patch) | |
tree | 3d66f0e4417ffe957c48808b9289ffc812fecd9e /sys | |
parent | 8b3d71903ef4c8cce2f0a6afcf7cf5cad2bacd52 (diff) |
Add ability to limit memory presented to kernel with
'machine memory =128M' style commands. Thanks to
phessler for finding a small man page niggle. Bumped
version strings to a nice round fraction, and make them
the same across the board. Easier to identify boot
binary versions that way.
ok thib@, tedu@, phessler@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/stand/boot/boot.8 | 20 | ||||
-rw-r--r-- | sys/arch/amd64/stand/boot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/stand/cdboot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/stand/libsa/cmd_i386.c | 36 | ||||
-rw-r--r-- | sys/arch/amd64/stand/libsa/libsa.h | 3 | ||||
-rw-r--r-- | sys/arch/amd64/stand/libsa/memprobe.c | 24 | ||||
-rw-r--r-- | sys/arch/amd64/stand/pxeboot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/boot/boot.8 | 20 | ||||
-rw-r--r-- | sys/arch/i386/stand/boot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/cdboot/conf.c | 4 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/cmd_i386.c | 36 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/libsa.h | 3 | ||||
-rw-r--r-- | sys/arch/i386/stand/libsa/memprobe.c | 24 | ||||
-rw-r--r-- | sys/arch/i386/stand/pxeboot/conf.c | 4 |
14 files changed, 152 insertions, 38 deletions
diff --git a/sys/arch/amd64/stand/boot/boot.8 b/sys/arch/amd64/stand/boot/boot.8 index 861ca76cdae..09c86713b52 100644 --- a/sys/arch/amd64/stand/boot/boot.8 +++ b/sys/arch/amd64/stand/boot/boot.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: boot.8,v 1.11 2009/02/16 23:58:05 sthen Exp $ +.\" $OpenBSD: boot.8,v 1.12 2010/07/02 00:36:52 weingart Exp $ .\" .\" Copyright (c) 1997-2001 Michael Shalayeff .\" All rights reserved. @@ -25,7 +25,7 @@ .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" -.Dd $Mdocdate: February 16 2009 $ +.Dd $Mdocdate: July 2 2010 $ .Dt BOOT 8 amd64 .Os .Sh NAME @@ -209,9 +209,10 @@ Otherwise the arguments specify how to modify the memory configuration. They take the form of: .Pp +.Dl =<size>[KMG] .Dl [+-]<size>@<address> .Pp -Meaning to add(+) or exempt(-) the amount of memory specified by +Meaning to add(+), exempt(-) or limit(=) the amount of memory specified by .Ar <size> at the location specified by .Ar <address> . @@ -220,11 +221,20 @@ decimal, or hexadecimal numbers, as accepted by the .Xr strtoul 3 routine. .Pp +The limit(=) option simply ignores any memory above the given +memory limit. +This is usefull for testing kernels in an artificially +constrained memory situation. +For example, the following limits the kernel to using only +memory below 64M: +.Bd -unfilled -offset indent +machine mem =64M +.Ed +.Pp Memory segments are not required to be adjacent to each other; the only requirement is that there is real physical memory under the range added. -The following example -adds 32M of memory right after the first 16M: +The following example adds 32M of memory right after the first 16M: .Bd -unfilled -offset indent machine mem +0x2000000@0x1000000 .Ed diff --git a/sys/arch/amd64/stand/boot/conf.c b/sys/arch/amd64/stand/boot/conf.c index f79deb6a09c..af78cf082de 100644 --- a/sys/arch/amd64/stand/boot/conf.c +++ b/sys/arch/amd64/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.13 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.14 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -41,7 +41,7 @@ #include <biosdev.h> #include <dev/cons.h> -const char version[] = "3.01"; +const char version[] = "3.14"; int debug = 1; diff --git a/sys/arch/amd64/stand/cdboot/conf.c b/sys/arch/amd64/stand/cdboot/conf.c index cd26ad30624..c1fffd2f13e 100644 --- a/sys/arch/amd64/stand/cdboot/conf.c +++ b/sys/arch/amd64/stand/cdboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.13 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.14 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -42,7 +42,7 @@ #include <biosdev.h> #include <dev/cons.h> -const char version[] = "2.01"; +const char version[] = "3.14"; int debug = 1; diff --git a/sys/arch/amd64/stand/libsa/cmd_i386.c b/sys/arch/amd64/stand/libsa/cmd_i386.c index 3dd3cecf46b..ea6c5f636b0 100644 --- a/sys/arch/amd64/stand/libsa/cmd_i386.c +++ b/sys/arch/amd64/stand/libsa/cmd_i386.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd_i386.c,v 1.2 2006/09/18 21:15:33 mpf Exp $ */ +/* $OpenBSD: cmd_i386.c,v 1.3 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1997-1999 Michael Shalayeff @@ -152,11 +152,32 @@ Xmemory(void) p = cmd.argv[i]; size = strtoll(p + 1, &p, 0); - if (*p && *p == '@') - addr = strtoll(p + 1, NULL, 0); - else - addr = 0; - if (addr == 0 && (*p != '@' || size == 0)) { + /* Size the size */ + switch(*p) { + case 'G': + size *= 1024; + case 'M': + size *= 1024; + case 'K': + size *= 1024; + p++; + } + + /* Handle (possibly non-existant) address part */ + switch(*p) { + case '@': + addr = strtoll(p + 1, NULL, 0); + break; + + /* Adjust address if we don't need it */ + default: + if (cmd.argv[i][0] == '=') + addr = -1; + else + addr = 0; + } + + if (addr == 0 || size == 0) { printf ("bad language\n"); return 0; } else { @@ -167,6 +188,9 @@ Xmemory(void) case '+': mem_add(addr, addr + size); break; + case '=': + mem_limit(size); + break; default : printf ("bad OP\n"); return 0; diff --git a/sys/arch/amd64/stand/libsa/libsa.h b/sys/arch/amd64/stand/libsa/libsa.h index 5ac8d7b5be8..32cd2fa2fbb 100644 --- a/sys/arch/amd64/stand/libsa/libsa.h +++ b/sys/arch/amd64/stand/libsa/libsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libsa.h,v 1.5 2007/04/28 19:23:10 deraadt Exp $ */ +/* $OpenBSD: libsa.h,v 1.6 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1996-1999 Michael Shalayeff @@ -52,6 +52,7 @@ void apmfixmem(void); void dump_biosmem(bios_memmap_t *); int mem_add(long long, long long); int mem_delete(long long, long long); +int mem_limit(long long); void mem_pass(void); void devboot(dev_t, char *); diff --git a/sys/arch/amd64/stand/libsa/memprobe.c b/sys/arch/amd64/stand/libsa/memprobe.c index 6ea02157c16..72224813324 100644 --- a/sys/arch/amd64/stand/libsa/memprobe.c +++ b/sys/arch/amd64/stand/libsa/memprobe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memprobe.c,v 1.6 2009/11/30 16:33:20 canacar Exp $ */ +/* $OpenBSD: memprobe.c,v 1.7 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1997-1999 Michael Shalayeff @@ -390,6 +390,28 @@ dump_biosmem(bios_memmap_t *tm) } int +mem_limit(long long ml) +{ + register bios_memmap_t *p; + + for (p = bios_memmap; p->type != BIOS_MAP_END; p++) { + register int64_t sp = p->addr, ep = p->addr + p->size; + + if (p->type != BIOS_MAP_FREE) + continue; + + /* Wholy above limit, nuke it */ + if ((sp >= ml) && (ep >= ml)) { + bcopy (p + 1, p, (char *)bios_memmap + + sizeof(bios_memmap) - (char *)p); + } else if ((sp < ml) && (ep >= ml)) { + p->size -= (ep - ml); + } + } + return 0; +} + +int mem_delete(long long sa, long long ea) { register bios_memmap_t *p; diff --git a/sys/arch/amd64/stand/pxeboot/conf.c b/sys/arch/amd64/stand/pxeboot/conf.c index 3a15193e1a2..31b7a9bbb77 100644 --- a/sys/arch/amd64/stand/pxeboot/conf.c +++ b/sys/arch/amd64/stand/pxeboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.17 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.18 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -44,7 +44,7 @@ #include "pxeboot.h" #include "pxe_net.h" -const char version[] = "2.02"; +const char version[] = "3.14"; int debug = 0; #undef _TEST diff --git a/sys/arch/i386/stand/boot/boot.8 b/sys/arch/i386/stand/boot/boot.8 index 34ed527f29f..9e4bc12ffc7 100644 --- a/sys/arch/i386/stand/boot/boot.8 +++ b/sys/arch/i386/stand/boot/boot.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: boot.8,v 1.48 2009/02/16 23:58:05 sthen Exp $ +.\" $OpenBSD: boot.8,v 1.49 2010/07/02 00:36:52 weingart Exp $ .\" .\" Copyright (c) 1997-2001 Michael Shalayeff .\" All rights reserved. @@ -25,7 +25,7 @@ .\" THE POSSIBILITY OF SUCH DAMAGE. .\" .\" -.Dd $Mdocdate: February 16 2009 $ +.Dd $Mdocdate: July 2 2010 $ .Dt BOOT 8 i386 .Os .Sh NAME @@ -209,9 +209,10 @@ Otherwise the arguments specify how to modify the memory configuration. They take the form of: .Pp +.Dl =<size>[KMG] .Dl [+-]<size>@<address> .Pp -Meaning to add(+) or exempt(-) the amount of memory specified by +Meaning to add(+), exempt(-) or limit(=) the amount of memory specified by .Ar <size> at the location specified by .Ar <address> . @@ -220,11 +221,20 @@ decimal, or hexadecimal numbers, as accepted by the .Xr strtoul 3 routine. .Pp +The limit(=) option simply ignores any memory above the given +memory limit. +This is usefull for testing kernels in an artificially +constrained memory situation. +For example, the following limits the kernel to using only +memory below 64M: +.Bd -unfilled -offset indent +machine mem =64M +.Ed +.Pp Memory segments are not required to be adjacent to each other; the only requirement is that there is real physical memory under the range added. -The following example -adds 32M of memory right after the first 16M: +The following example adds 32M of memory right after the first 16M: .Bd -unfilled -offset indent machine mem +0x2000000@0x1000000 .Ed diff --git a/sys/arch/i386/stand/boot/conf.c b/sys/arch/i386/stand/boot/conf.c index dd06827a90d..6812ab4680e 100644 --- a/sys/arch/i386/stand/boot/conf.c +++ b/sys/arch/i386/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.39 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.40 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -42,7 +42,7 @@ #include <dev/cons.h> #include "debug.h" -const char version[] = "3.02"; +const char version[] = "3.14"; int debug = 1; diff --git a/sys/arch/i386/stand/cdboot/conf.c b/sys/arch/i386/stand/cdboot/conf.c index 7c30d06302b..165f1199e0f 100644 --- a/sys/arch/i386/stand/cdboot/conf.c +++ b/sys/arch/i386/stand/cdboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.11 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.12 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -43,7 +43,7 @@ #include <dev/cons.h> #include "debug.h" -const char version[] = "2.02"; +const char version[] = "3.14"; int debug = 1; #undef _TEST diff --git a/sys/arch/i386/stand/libsa/cmd_i386.c b/sys/arch/i386/stand/libsa/cmd_i386.c index 790866d40f7..67d4c2f40f8 100644 --- a/sys/arch/i386/stand/libsa/cmd_i386.c +++ b/sys/arch/i386/stand/libsa/cmd_i386.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd_i386.c,v 1.29 2006/09/18 21:14:15 mpf Exp $ */ +/* $OpenBSD: cmd_i386.c,v 1.30 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1997-1999 Michael Shalayeff @@ -155,11 +155,32 @@ Xmemory(void) p = cmd.argv[i]; size = strtoll(p + 1, &p, 0); - if (*p && *p == '@') - addr = strtoll(p + 1, NULL, 0); - else - addr = 0; - if (addr == 0 && (*p != '@' || size == 0)) { + /* Size the size */ + switch(*p) { + case 'G': + size *= 1024; + case 'M': + size *= 1024; + case 'K': + size *= 1024; + p++; + } + + /* Handle (possibly non-existant) address part */ + switch(*p) { + case '@': + addr = strtoll(p + 1, NULL, 0); + break; + + /* Adjust address if we don't need it */ + default: + if (cmd.argv[i][0] == '=') + addr = -1; + else + addr = 0; + } + + if (addr == 0 || size == 0) { printf("bad language\n"); return 0; } else { @@ -170,6 +191,9 @@ Xmemory(void) case '+': mem_add(addr, addr + size); break; + case '=': + mem_limit(size); + break; default : printf("bad OP\n"); return 0; diff --git a/sys/arch/i386/stand/libsa/libsa.h b/sys/arch/i386/stand/libsa/libsa.h index 56dea3b79c6..76bf1e02fd8 100644 --- a/sys/arch/i386/stand/libsa/libsa.h +++ b/sys/arch/i386/stand/libsa/libsa.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libsa.h,v 1.44 2007/04/27 10:08:34 tom Exp $ */ +/* $OpenBSD: libsa.h,v 1.45 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1996-1999 Michael Shalayeff @@ -56,6 +56,7 @@ void apmfixmem(void); void dump_biosmem(bios_memmap_t *); int mem_add(long long, long long); int mem_delete(long long, long long); +int mem_limit(long long); void mem_pass(void); void devboot(dev_t, char *); diff --git a/sys/arch/i386/stand/libsa/memprobe.c b/sys/arch/i386/stand/libsa/memprobe.c index b6d504fe73e..063f048e440 100644 --- a/sys/arch/i386/stand/libsa/memprobe.c +++ b/sys/arch/i386/stand/libsa/memprobe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memprobe.c,v 1.46 2009/11/30 16:33:20 canacar Exp $ */ +/* $OpenBSD: memprobe.c,v 1.47 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 1997-1999 Michael Shalayeff @@ -383,6 +383,28 @@ dump_biosmem(bios_memmap_t *tm) } int +mem_limit(long long ml) +{ + register bios_memmap_t *p; + + for (p = bios_memmap; p->type != BIOS_MAP_END; p++) { + register int64_t sp = p->addr, ep = p->addr + p->size; + + if (p->type != BIOS_MAP_FREE) + continue; + + /* Wholy above limit, nuke it */ + if ((sp >= ml) && (ep >= ml)) { + bcopy (p + 1, p, (char *)bios_memmap + + sizeof(bios_memmap) - (char *)p); + } else if ((sp < ml) && (ep >= ml)) { + p->size -= (ep - ml); + } + } + return 0; +} + +int mem_delete(long long sa, long long ea) { register bios_memmap_t *p; diff --git a/sys/arch/i386/stand/pxeboot/conf.c b/sys/arch/i386/stand/pxeboot/conf.c index 9ef52e122ef..e9479f2e8d2 100644 --- a/sys/arch/i386/stand/pxeboot/conf.c +++ b/sys/arch/i386/stand/pxeboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.16 2008/04/19 23:20:22 weingart Exp $ */ +/* $OpenBSD: conf.c,v 1.17 2010/07/02 00:36:52 weingart Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -45,7 +45,7 @@ #include "pxeboot.h" #include "pxe_net.h" -const char version[] = "2.03"; +const char version[] = "3.14"; int debug = 1; #undef _TEST |