From cd3065133f9b4f4ddda6dffa4d8b0a15a925f4fb Mon Sep 17 00:00:00 2001 From: Palmer Dabbelt Date: Wed, 10 Oct 2018 17:17:50 -0700 Subject: Add "--with-max-memory-bytes", to limit the used memory I have no idea if this works, but it does at least compile. Signed-off-by: Palmer Dabbelt --- config.h.in | 3 +++ configure | 30 +++++++++++++++++------------- configure.ac | 5 +++++ machine/fdt.c | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/config.h.in b/config.h.in index dbacd78..fa453f2 100644 --- a/config.h.in +++ b/config.h.in @@ -12,6 +12,9 @@ /* Define if subproject MCPPBS_SPROJ_NORM is enabled */ #undef MACHINE_ENABLED +/* Maximum bytes of memory */ +#undef MAX_MEMORY_BYTES + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT diff --git a/configure b/configure index b001ba3..e1beee1 100755 --- a/configure +++ b/configure @@ -646,7 +646,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -672,6 +671,7 @@ enable_option_checking enable_stow with_arch enable_print_device_tree +with_max_memory_bytes enable_optional_subprojects enable_vm enable_logo @@ -733,7 +733,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -986,15 +985,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1132,7 +1122,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1285,7 +1275,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1333,6 +1322,7 @@ Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-arch Set the RISC-V architecture + --with-max-memory-bytes Limit the maximum availiable memory --with-payload Set ELF payload for bbl --with-logo Specify a better logo @@ -4095,6 +4085,20 @@ $as_echo "#define PK_PRINT_DEVICE_TREE /**/" >>confdefs.h fi + +# Check whether --with-max-memory-bytes was given. +if test "${with_max_memory_bytes+set}" = set; then : + withval=$with_max_memory_bytes; +fi + +if test "x$with_max_memory_bytes" != "xno"; then : + + +$as_echo "#define MAX_MEMORY_BYTES \"\$with_max_memory_bytes\"" >>confdefs.h + + +fi + CFLAGS="-Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -fno-PIE" LDFLAGS="$LDFLAGS -Wl,--build-id=none" diff --git a/configure.ac b/configure.ac index 917179f..f482ae9 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,11 @@ AS_IF([test "x$enable_print_device_tree" == "xyes"], [ AC_DEFINE([PK_PRINT_DEVICE_TREE],,[Define if the DTS is to be displayed]) ]) +AC_ARG_WITH([max-memory-bytes], AS_HELP_STRING([--with-max-memory-bytes], [Limit the maximum availiable memory])) +AS_IF([test "x$with_max_memory_bytes" != "xno"], [ + AC_DEFINE([MAX_MEMORY_BYTES],"$with_max_memory_bytes",[Maximum bytes of memory]) +]) + CFLAGS="-Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -fno-PIE" LDFLAGS="$LDFLAGS -Wl,--build-id=none" diff --git a/machine/fdt.c b/machine/fdt.c index e8a504f..ba94b8d 100644 --- a/machine/fdt.c +++ b/machine/fdt.c @@ -126,6 +126,15 @@ const uint32_t *fdt_get_size(const struct fdt_scan_node *node, const uint32_t *v return value; } +const uint32_t *fdt_set_size(const struct fdt_scan_node *node, uint32_t *value, uint64_t new_value) +{ + for (int cells = node->size_cells; cells > 0; --cells) { + *value++ = new_value; + new_value >>= 32; + } + return value; +} + int fdt_string_list_index(const struct fdt_scan_prop *prop, const char *str) { const char *list = (const char *)prop->value; @@ -176,9 +185,14 @@ static void mem_done(const struct fdt_scan_node *node, void *extra) while (end - value > 0) { uint64_t base, size; - value = fdt_get_address(node->parent, value, &base); + const uint32_t *size_ptr; + size_ptr = value = fdt_get_address(node->parent, value, &base); value = fdt_get_size (node->parent, value, &size); if (base <= self && self <= base + size) { mem_size = size; } +#ifdef MAX_MEMORY_BYTES + if (size > (uintptr_t)(MAX_MEMORY_BYTES)) + fdt_set_size(node->parent, (uint32_t *)size_ptr, (uintptr_t)(MAX_MEMORY_BYTES)); +#endif } assert (end == value); } -- cgit v1.1