Make __semi_call static inline so semicall.h can be included more
than once in a program.

Use .option push/pop rather than leaving norvc set for the rest of
the file.

Set the constraints for the asm block.

Signed-off-by: Joel Stanley <[email protected]>
---
 tests/tcg/riscv64/semicall.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tests/tcg/riscv64/semicall.h b/tests/tcg/riscv64/semicall.h
index 2fdd322af91f..34e87332de44 100644
--- a/tests/tcg/riscv64/semicall.h
+++ b/tests/tcg/riscv64/semicall.h
@@ -8,16 +8,19 @@
  */
 #include <stdint.h>
 
-uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
+static inline uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
 {
     register uintptr_t t asm("a0") = type;
     register uintptr_t a0 asm("a1") = arg0;
-    asm(".option norvc\n\t"
+    asm(".option push\n\t"
+        ".option norvc\n\t"
         ".balign 16\n\t"
         "slli zero, zero, 0x1f\n\t"
         "ebreak\n\t"
         "srai zero, zero, 0x7\n\t"
-        : "=r" (t)
-        : "r" (t), "r" (a0));
+        ".option pop\n\t"
+        : "+r" (t)          /* Output: read as input, written as return value 
*/
+        : "r" (a0)          /* Input: arg0 */
+        : "memory");        /* Clobber: may modify memory, depending on type */
     return t;
 }
-- 
2.47.3


Reply via email to