-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathriscv_platform.cpp
82 lines (69 loc) · 1.66 KB
/
riscv_platform.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "sail.h"
#include "rts.h"
#include "riscv_prelude.h"
#include "riscv_platform.h"
#include "riscv_platform_impl.h"
#include "riscv_sail.h"
#ifdef DEBUG_RESERVATION
#include <stdio.h>
#include <inttypes.h>
#define RESERVATION_DBG(args...) fprintf(stderr, args)
#else
#define RESERVATION_DBG(args...)
#endif
/* This file contains the definitions of the C externs of Sail model. */
static mach_bits reservation = 0;
static bool reservation_valid = false;
// Provides entropy for the scalar cryptography extension.
mach_bits plat_get_16_random_bits(unit)
{
return rv_16_random_bits();
}
unit load_reservation(sbits addr)
{
reservation = addr.bits;
reservation_valid = true;
RESERVATION_DBG("reservation <- %0" PRIx64 "\n", reservation);
return UNIT;
}
bool speculate_conditional(unit)
{
return true;
}
static mach_bits check_mask()
{
return (zxlen_val == 32) ? 0x00000000FFFFFFFF : -1;
}
bool match_reservation(sbits addr)
{
mach_bits mask = check_mask();
bool ret = reservation_valid && (reservation & mask) == (addr.bits & mask);
RESERVATION_DBG("reservation(%c): %0" PRIx64 ", key=%0" PRIx64 ": %s\n",
reservation_valid ? 'v' : 'i', reservation, addr,
ret ? "ok" : "fail");
return ret;
}
unit cancel_reservation(unit)
{
RESERVATION_DBG("reservation <- none\n");
reservation_valid = false;
return UNIT;
}
unit plat_term_write(mach_bits s)
{
char c = s & 0xff;
plat_term_write_impl(c);
return UNIT;
}
mach_bits plat_htif_tohost(unit)
{
return rv_htif_tohost;
}
bool sys_enable_experimental_extensions(unit)
{
return rv_enable_experimental_extensions;
}
unit memea(mach_bits, sail_int)
{
return UNIT;
}