-
Notifications
You must be signed in to change notification settings - Fork 4
/
htif.c
48 lines (41 loc) · 1.12 KB
/
htif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#include "htif.h"
#ifdef KERNEL
volatile uint64_t tohost __attribute__((section(".htif")));
volatile uint64_t fromhost __attribute__((section(".htif")));
#endif
#define TOHOST (*(volatile uint64_t*)0x0002000)
#define FROMHOST (*(volatile uint64_t*)0x0002008)
uintptr_t syscall(uintptr_t n, uintptr_t a0, uintptr_t a1, uintptr_t a2,
uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6)
{
uint64_t th = TOHOST;
if(th) {
__builtin_trap();
while(1) {}
}
static volatile uint64_t htif_mem[8];
htif_mem[0] = n;
htif_mem[1] = a0;
htif_mem[2] = a1;
htif_mem[3] = a2;
htif_mem[4] = a3;
htif_mem[5] = a4;
htif_mem[6] = a5;
htif_mem[7] = a6;
TOHOST = (uintptr_t)htif_mem;
while(1) {
uint64_t fh = FROMHOST;
if(fh) {
FROMHOST = 0;
break;
}
}
return htif_mem[0];
}
void shutdown(int code) {
syscall(SYS_exit, code, 0, 0, 0, 0, 0, 0);
while(1) {}
}