blob: 07a3866c65f7c267565db2ce138288f83482ba4d [file] [edit]
//===----------------------------------------------------------------------===//
//
// 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
/// AArch64 bare-metal hermetic test utilities.
///
//===----------------------------------------------------------------------===//
#include "ArmAArch64BaremetalCommonTestUtils.h"
#include "hdr/stdint_proxy.h"
#define SEMIHOST_INSTRUCTION "hlt #0xF000"
namespace {
long semihosting_call(int val, const void *ptr) {
register long v __asm__("x0") = val;
register const void *p __asm__("x1") = ptr;
__asm__ __volatile__(SEMIHOST_INSTRUCTION
: "+r"(v), "+r"(p)
:
: "memory", "cc");
return v;
}
} // namespace
extern "C" {
[[noreturn]] void __llvm_libc_exit(int status) {
const struct {
uint64_t code;
int64_t status;
} args = {static_cast<uint64_t>(ADP_Stopped_ApplicationExit),
static_cast<int64_t>(status)};
semihosting_call(SYS_EXIT, reinterpret_cast<const void *>(&args));
__builtin_unreachable(); // This semihosting call does not return.
}
} // extern "C"