From 4936474c2cb47528deaeb1b0e8ebca1ffb5b8426 Mon Sep 17 00:00:00 2001 From: Adrian Herrera Date: Fri, 15 Nov 2019 10:55:36 +0000 Subject: [PATCH] arch-arm: Semihosting, specify files root dir This patch adds an option to "ArmSemihosting" which allows for specifying an optional search path for host files. Previously, behaviour was fixed to search in the directory from where the gem5 binary was run from. Change-Id: I57b932b38d022f132af78857104633d7bfdd1442 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23903 Reviewed-by: Ciro Santilli Maintainer: Giacomo Travaglini Tested-by: kokoro --- src/arch/arm/ArmSemihosting.py | 4 +++- src/arch/arm/semihosting.cc | 7 ++++++- src/arch/arm/semihosting.hh | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/arch/arm/ArmSemihosting.py b/src/arch/arm/ArmSemihosting.py index a804aa8ab..6052f1d6b 100644 --- a/src/arch/arm/ArmSemihosting.py +++ b/src/arch/arm/ArmSemihosting.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 ARM Limited +# Copyright (c) 2018, 2019 ARM Limited # All rights reserved. # # The license below extends only to copyright in the software and shall @@ -52,6 +52,8 @@ class ArmSemihosting(SimObject): "Standard output (stdout for gem5's terminal)") stderr = Param.String("stderr", "Standard error (stderr for gem5's terminal)") + files_root_dir = Param.String("", + "Host root directory for files handled by Semihosting") mem_reserve = Param.MemorySize("32MB", "Amount of memory to reserve at the start of the address map. This " diff --git a/src/arch/arm/semihosting.cc b/src/arch/arm/semihosting.cc index 2fe5373b8..a0c865d8b 100644 --- a/src/arch/arm/semihosting.cc +++ b/src/arch/arm/semihosting.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited + * Copyright (c) 2018, 2019 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -138,6 +138,9 @@ ArmSemihosting::ArmSemihosting(const ArmSemihostingParams *p) timeBase([p]{ struct tm t = p->time; return mkutctime(&t); }()), tickShift(calcTickShift()), semiErrno(0), + filesRootDir(!p->files_root_dir.empty() && + p->files_root_dir.back() != '/' ? + p->files_root_dir + '/' : p->files_root_dir), stdin(getSTDIO("stdin", p->stdin, "r")), stdout(getSTDIO("stdout", p->stdout, "w")), stderr(p->stderr == p->stdout ? @@ -291,6 +294,8 @@ ArmSemihosting::callOpen(ThreadContext *tc, bool aarch64, return retError(EINVAL); std::string fname = readString(tc, name_base, name_size); + if (!fname.empty() && fname.front() != '/') + fname = filesRootDir + fname; std::unique_ptr file = FileBase::create(*this, fname, mode); diff --git a/src/arch/arm/semihosting.hh b/src/arch/arm/semihosting.hh index a9c11933f..2ae31827e 100644 --- a/src/arch/arm/semihosting.hh +++ b/src/arch/arm/semihosting.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited + * Copyright (c) 2018, 2019 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -243,6 +243,7 @@ class ArmSemihosting : public SimObject FILE *file; }; + std::string filesRootDir; std::vector> files; FILE *stdin; FILE *stdout; -- 2.30.2