| //===----------------------------------------------------------------------===// | |
| // | |
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| // See https://llvm.org/LICENSE.txt for license information. | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| // | |
| //===----------------------------------------------------------------------===// | |
| /// | |
| /// \file | |
| /// Arm bare-metal hermetic test utilities. | |
| /// | |
| //===----------------------------------------------------------------------===// | |
| #include "ArmAArch64BaremetalCommonTestUtils.h" | |
| #include "hdr/stdint_proxy.h" | |
| #if defined(__thumb__) // T32 | |
| #if defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' | |
| #define SEMIHOST_INSTRUCTION "bkpt #0xAB" | |
| #else | |
| #define SEMIHOST_INSTRUCTION "svc 0xab" | |
| #endif | |
| #else // A32 | |
| #define SEMIHOST_INSTRUCTION "svc 0x123456" | |
| #endif | |
| namespace { | |
| long semihosting_call(int val, const void *ptr) { | |
| register long v __asm__("r0") = val; | |
| register const void *p __asm__("r1") = ptr; | |
| __asm__ __volatile__(SEMIHOST_INSTRUCTION | |
| : "+r"(v), "+r"(p) | |
| : | |
| : "memory", "cc"); | |
| return v; | |
| } | |
| } // namespace | |
| extern "C" { | |
| [[noreturn]] void __llvm_libc_exit(int status) { | |
| uint32_t semihosting_status = (status == 0) ? ADP_Stopped_ApplicationExit | |
| : ADP_Stopped_RunTimeErrorUnknown; | |
| semihosting_call(SYS_EXIT, | |
| reinterpret_cast<const void *>(semihosting_status)); | |
| __builtin_unreachable(); // This semihosting call does not return. | |
| } | |
| } // extern "C" |