blob: 20e991df302f53b10b4ac40603b945359a9744fb [file] [log] [blame]
Andrew Walbran474c4392019-09-11 13:57:17 +01001// SPDX-License-Identifier: Apache-2.0
2/*
3 * Copyright 2019 The Hafnium Authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "hf/call.h"
19#include "hf/types.h"
20
21int64_t hf_call(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3)
22{
23 register uint64_t r0 __asm__("x0") = arg0;
24 register uint64_t r1 __asm__("x1") = arg1;
25 register uint64_t r2 __asm__("x2") = arg2;
26 register uint64_t r3 __asm__("x3") = arg3;
27
28 /*
29 * We currently implement SMCCC 1.0, which specifies that the callee can
30 * use x4–x17 as scratch registers. If we move to SMCCC 1.1 then this
31 * will change.
32 */
33 __asm__ volatile(
34 "hvc #0"
35 : /* Output registers, also used as inputs ('+' constraint). */
36 "+r"(r0), "+r"(r1), "+r"(r2), "+r"(r3)
37 :
38 : /* Clobber registers. */
39 "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13",
40 "x14", "x15", "x16", "x17");
41
42 return r0;
43}