Skip to content

Add "--with-max-memory-bytes", to limit the used memory #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 17 additions & 13 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
Expand All @@ -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
Expand Down Expand Up @@ -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}'
Expand Down Expand Up @@ -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=* \
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -4093,6 +4083,20 @@ if test "x$enable_print_device_tree" == "xyes"; then :
$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"
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 15 additions & 1 deletion machine/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down