aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/riscv64/semicall.h
blob: f8c88f32dc5898be7c55dd892acf5b35d005fc8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Semihosting Tests - RiscV64 Helper
 *
 * Copyright (c) 2021
 * Written by Alex Bennée <alex.bennee@linaro.org>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

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"
        ".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));
    return t;
}