arm: Optionally enable gem5 extended semihosting calls.
authorGabe Black <gabeblack@google.com>
Wed, 26 Feb 2020 12:59:25 +0000 (04:59 -0800)
committerGabe Black <gabeblack@google.com>
Wed, 25 Mar 2020 21:09:41 +0000 (21:09 +0000)
ARM's semihosting interface defines call numbers up to 0xff to be
for standardized use, and says that custom calls should go above this
number.

This new mechanism will let the caller decide whether it wants to
enable these extended calls, or if they should be ignored and only
standard calls should be recognized.

Change-Id: I34b01a4439c8a88242971ac486e34d810b054baf
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/25947
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/arm/semihosting.cc
src/arch/arm/semihosting.hh
src/arch/arm/system.cc
src/arch/arm/system.hh

index 5ea894af34220e0578413f96f68ca1140148e1d2..b6db38af9d1b8d9c3cc1370ca28c0195cd328e44 100644 (file)
@@ -154,9 +154,14 @@ ArmSemihosting::ArmSemihosting(const ArmSemihostingParams *p)
 }
 
 void
-ArmSemihosting::call64(ThreadContext *tc)
+ArmSemihosting::call64(ThreadContext *tc, bool gem5_ops)
 {
     RegVal op = tc->readIntReg(ArmISA::INTREG_X0 & mask(32));
+    if (op > MaxStandardOp && !gem5_ops) {
+        unrecognizedCall<Abi64>(
+                tc, "Gem5 semihosting op (0x%x) disabled from here.", op);
+        return;
+    }
 
     auto it = calls.find(op);
     if (it == calls.end()) {
@@ -173,9 +178,14 @@ ArmSemihosting::call64(ThreadContext *tc)
 }
 
 void
-ArmSemihosting::call32(ThreadContext *tc)
+ArmSemihosting::call32(ThreadContext *tc, bool gem5_ops)
 {
     RegVal op = tc->readIntReg(ArmISA::INTREG_R0);
+    if (op > MaxStandardOp && !gem5_ops) {
+        unrecognizedCall<Abi32>(
+                tc, "Gem5 semihosting op (0x%x) disabled from here.", op);
+        return;
+    }
 
     auto it = calls.find(op);
     if (it == calls.end()) {
index 4a8aa2bd96df24270b81deaf3705a126bf4b16bb..9aa5b41979c3e46499ccaadce933387e8a3d3448 100644 (file)
@@ -214,9 +214,9 @@ class ArmSemihosting : public SimObject
     ArmSemihosting(const ArmSemihostingParams *p);
 
     /** Perform an Arm Semihosting call from aarch64 code. */
-    void call64(ThreadContext *tc);
+    void call64(ThreadContext *tc, bool gem5_ops);
     /** Perform an Arm Semihosting call from aarch32 code. */
-    void call32(ThreadContext *tc);
+    void call32(ThreadContext *tc, bool gem5_ops);
 
   public: // SimObject and related interfaces
     void serialize(CheckpointOut &cp) const override;
index 906cc9eda132dc61d45d9f3e752d51177e4c0185..e61402a943ee765b9a6ae4a7df1122d964540acf 100644 (file)
@@ -180,15 +180,15 @@ ArmSystem::haveSemihosting(ThreadContext *tc)
 }
 
 void
-ArmSystem::callSemihosting64(ThreadContext *tc)
+ArmSystem::callSemihosting64(ThreadContext *tc, bool gem5_ops)
 {
-    getArmSystem(tc)->semihosting->call64(tc);
+    getArmSystem(tc)->semihosting->call64(tc, gem5_ops);
 }
 
 void
-ArmSystem::callSemihosting32(ThreadContext *tc)
+ArmSystem::callSemihosting32(ThreadContext *tc, bool gem5_ops)
 {
-    getArmSystem(tc)->semihosting->call32(tc);
+    getArmSystem(tc)->semihosting->call32(tc, gem5_ops);
 }
 
 void
index ae83da07d0b35c0f69b6713c1f668937ca2ed85a..fc32d0fd3afbd809fb91ab9ce69eb21c63c3fc4b 100644 (file)
@@ -314,10 +314,10 @@ class ArmSystem : public System
     static bool haveSemihosting(ThreadContext *tc);
 
     /** Make a Semihosting call from aarch64 */
-    static void callSemihosting64(ThreadContext *tc);
+    static void callSemihosting64(ThreadContext *tc, bool gem5_ops=false);
 
     /** Make a Semihosting call from aarch32 */
-    static void callSemihosting32(ThreadContext *tc);
+    static void callSemihosting32(ThreadContext *tc, bool gem5_ops=false);
 
     /** Make a call to notify the power controller of STANDBYWFI assertion */
     static void callSetStandByWfi(ThreadContext *tc);