From e4c7ea67b81af4a915868a4f7babc46a53d6194c Mon Sep 17 00:00:00 2001 From: Adrian Herrera Date: Thu, 14 Nov 2019 20:41:50 +0000 Subject: [PATCH] sim: kernelExtras optional load addresses This patch provides a new "System" parameter named "kernel_extras_addrs". This allows to optionally specify fixed load addresses for the additional kernel objects. This is useful to load arbitrary blobs into memory. Change-Id: I4725763b86c29f72282d1c184d4284d90f9d3016 Reviewed-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23566 Reviewed-by: Bobby R. Bruce Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/sim/System.py | 6 ++++-- src/sim/system.cc | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/sim/System.py b/src/sim/System.py index 9928887b9..619b54ed1 100644 --- a/src/sim/System.py +++ b/src/sim/System.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017 ARM Limited +# Copyright (c) 2017, 2019 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -107,7 +107,9 @@ class System(SimObject): kernel = Param.String("", "file that contains the kernel code") kernel_addr_check = Param.Bool(True, "whether to address check on kernel (disable for baremetal)") - kernel_extras = VectorParam.String([],"Additional object files to load") + kernel_extras = VectorParam.String([], "Additional object files to load") + kernel_extras_addrs = VectorParam.Addr([], + "Load addresses for additional object files") readfile = Param.String("", "file to read startup script from") symbolfile = Param.String("", "file to get the symbols from") load_addr_mask = Param.UInt64(0xffffffffffffffff, diff --git a/src/sim/system.cc b/src/sim/system.cc index 8c438086b..97ebd1d7c 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -192,10 +192,15 @@ System::System(Params *p) // connected so it will happen in initState() } - for (const auto &obj_name : p->kernel_extras) { - inform("Loading additional kernel object: %s", obj_name); - ObjectFile *obj = createObjectFile(obj_name); - fatal_if(!obj, "Failed to additional kernel object '%s'.\n", + if (p->kernel_extras_addrs.empty()) + p->kernel_extras_addrs.resize(p->kernel_extras.size(), MaxAddr); + fatal_if(p->kernel_extras.size() != p->kernel_extras_addrs.size(), + "Additional kernel objects, not all load addresses specified\n"); + for (int ker_idx = 0; ker_idx < p->kernel_extras.size(); ker_idx++) { + const std::string &obj_name = p->kernel_extras[ker_idx]; + const bool raw = p->kernel_extras_addrs[ker_idx] != MaxAddr; + ObjectFile *obj = createObjectFile(obj_name, raw); + fatal_if(!obj, "Failed to build additional kernel object '%s'.\n", obj_name); kernelExtras.push_back(obj); } @@ -360,8 +365,16 @@ System::initState() DPRINTF(Loader, "Kernel entry = %#x\n", kernelEntry); DPRINTF(Loader, "Kernel loaded...\n"); } - for (const auto &extra_kernel : kernelExtras) - extra_kernel->buildImage().move(mapper).write(physProxy); + std::function extra_mapper; + for (auto ker_idx = 0; ker_idx < kernelExtras.size(); ker_idx++) { + const Addr load_addr = params()->kernel_extras_addrs[ker_idx]; + auto image = kernelExtras[ker_idx]->buildImage(); + if (load_addr != MaxAddr) + image = image.offset(load_addr); + else + image = image.move(mapper); + image.write(physProxy); + } } } -- 2.30.2