Skip to content

Commit cfb00b4

Browse files
author
Tim Hutt
committed
Implement Zicbom, Zicboz (cbo.flush, cbo.inval, cbo.zero)
Note that Zicbop (prefetch hints) does not need to be implemented because all it does is label some existing base instructions as prefetch hints. Also I have not wired up the enable flags to the emulators because it is rather tedious (and will hopefully be replaced by riscv-config at some point).
1 parent 16077e1 commit cfb00b4

23 files changed

+279
-24
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ SAIL_DEFAULT_INST += riscv_insts_vext_mem.sail
5555
SAIL_DEFAULT_INST += riscv_insts_vext_mask.sail
5656
SAIL_DEFAULT_INST += riscv_insts_vext_vm.sail
5757
SAIL_DEFAULT_INST += riscv_insts_vext_red.sail
58+
SAIL_DEFAULT_INST += riscv_insts_zicbom.sail
59+
SAIL_DEFAULT_INST += riscv_insts_zicboz.sail
5860

5961
SAIL_SEQ_INST = $(SAIL_DEFAULT_INST) riscv_jalr_seq.sail
6062
SAIL_RMEM_INST = $(SAIL_DEFAULT_INST) riscv_jalr_rmem.sail riscv_insts_rmem.sail

c_emulator/riscv_platform.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ mach_bits plat_rom_size(unit u)
102102
return rv_rom_size;
103103
}
104104

105+
mach_bits plat_cache_block_size_exp()
106+
{
107+
return rv_cache_block_size_exp;
108+
}
109+
105110
// Provides entropy for the scalar cryptography extension.
106111
mach_bits plat_get_16_random_bits()
107112
{

c_emulator/riscv_platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ bool within_phys_mem(mach_bits, sail_int);
2424
mach_bits plat_rom_base(unit);
2525
mach_bits plat_rom_size(unit);
2626

27+
mach_bits plat_cache_block_size_exp(unit);
28+
2729
// Provides entropy for the scalar cryptography extension.
2830
mach_bits plat_get_16_random_bits();
2931

c_emulator/riscv_platform_impl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ uint64_t rv_ram_size = UINT64_C(0x4000000);
2525
uint64_t rv_rom_base = UINT64_C(0x1000);
2626
uint64_t rv_rom_size = UINT64_C(0x100);
2727

28+
uint64_t rv_cache_block_size_exp = UINT64_C(6);
29+
2830
// Provides entropy for the scalar cryptography extension.
2931
uint64_t rv_16_random_bits(void)
3032
{

c_emulator/riscv_platform_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern uint64_t rv_ram_size;
2929
extern uint64_t rv_rom_base;
3030
extern uint64_t rv_rom_size;
3131

32+
extern uint64_t rv_cache_block_size_exp;
33+
3234
// Provides entropy for the scalar cryptography extension.
3335
extern uint64_t rv_16_random_bits(void);
3436

c_emulator/riscv_sim.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const char *RV32ISA = "RV32IMAC";
5353
#define OPT_ENABLE_WRITABLE_FIOM 1001
5454
#define OPT_PMP_COUNT 1002
5555
#define OPT_PMP_GRAIN 1003
56-
#define OPT_ENABLE_ZCB 10014
56+
#define OPT_ENABLE_ZCB 1004
57+
#define OPT_CACHE_BLOCK_SIZE_EXP 1005
5758

5859
static bool do_dump_dts = false;
5960
static bool do_show_times = false;
@@ -150,6 +151,7 @@ static struct option options[] = {
150151
#ifdef SAILCOV
151152
{"sailcov-file", required_argument, 0, 'c' },
152153
#endif
154+
{"cache-block-size-exp", required_argument, 0, OPT_CACHE_BLOCK_SIZE_EXP},
153155
{0, 0, 0, 0 }
154156
};
155157

@@ -243,6 +245,7 @@ static int process_args(int argc, char **argv)
243245
uint64_t ram_size = 0;
244246
uint64_t pmp_count = 0;
245247
uint64_t pmp_grain = 0;
248+
uint64_t block_size_exp = 0;
246249
while (true) {
247250
c = getopt_long(argc, argv,
248251
"a"
@@ -405,6 +408,18 @@ static int process_args(int argc, char **argv)
405408
case OPT_TRACE_OUTPUT:
406409
trace_log_path = optarg;
407410
fprintf(stderr, "using %s for trace output.\n", trace_log_path);
411+
case OPT_CACHE_BLOCK_SIZE_EXP:
412+
block_size_exp = atol(optarg);
413+
if (block_size_exp <= 12) {
414+
fprintf(stderr,
415+
"setting cache-block-size-exp to 2^%" PRIu64 " = %u B\n",
416+
block_size_exp, 1 << block_size_exp);
417+
rv_cache_block_size_exp = block_size_exp;
418+
} else {
419+
fprintf(stderr, "invalid cache-block-size-exp '%s' provided.\n",
420+
optarg);
421+
exit(1);
422+
}
408423
break;
409424
case '?':
410425
print_usage(argv[0], 1);

handwritten_support/riscv_extras.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ val plat_rom_size : unit -> bitvector
185185
let plat_rom_size () = []
186186
declare ocaml target_rep function plat_rom_size = `Platform.rom_size`
187187

188+
val plat_cache_block_size_exp : unit -> bitvector
189+
let plat_cache_block_size_exp () = []
190+
declare ocaml target_rep function plat_cache_block_size_exp = `Platform.cache_block_size_exp`
191+
188192
val plat_clint_base : unit -> bitvector
189193
let plat_clint_base () = []
190194
declare ocaml target_rep function plat_clint_base = `Platform.clint_base`

handwritten_support/riscv_extras_sequential.lem

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ val plat_rom_size : forall 'a. Size 'a => unit -> bitvector 'a
173173
let plat_rom_size () = wordFromInteger 0
174174
declare ocaml target_rep function plat_rom_size = `Platform.rom_size`
175175

176+
val plat_cache_block_size_exp : unit -> integer
177+
let plat_cache_block_size_exp () = wordFromInteger 0
178+
declare ocaml target_rep function plat_cache_block_size_exp = `Platform.cache_block_size_exp`
179+
176180
val plat_clint_base : forall 'a. Size 'a => unit -> bitvector 'a
177181
let plat_clint_base () = wordFromInteger 0
178182
declare ocaml target_rep function plat_clint_base = `Platform.clint_base`

model/prelude_mem.sail

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@
2424
because it means width argument can be fast native integer. It
2525
would be even better if it could be <= 8 bytes so that data can
2626
also be a 64-bit int but CHERI needs 128-bit accesses for
27-
capabilities and SIMD / vector instructions will also need more. */
28-
type max_mem_access : Int = 16
27+
capabilities and SIMD / vector instructions will also need more.
28+
29+
The specific value does not matter (if it is >8) since anything up
30+
to 2^64-1 will result in a native int being used for the width type.
31+
32+
4096 was chosen because it is a page size, and a reasonable maximum
33+
for cbo.zero.
34+
*/
35+
type max_mem_access : Int = 4096
2936

3037
val write_ram = {lem: "write_ram", coq: "write_ram"} : forall 'n, 0 < 'n <= max_mem_access . (write_kind, xlenbits, int('n), bits(8 * 'n), mem_meta) -> bool
3138
function write_ram(wk, addr, width, data, meta) = {

model/riscv_addr_checks.sail

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type ext_data_addr_error = unit
5454

5555
/* Default data addr is just base register + immediate offset (may be zero).
5656
Extensions might override and add additional checks. */
57-
function ext_data_get_addr(base : regidx, offset : xlenbits, acc : AccessType(ext_access_type), width : word_width)
57+
function ext_data_get_addr(base : regidx, offset : xlenbits, acc : AccessType(ext_access_type), width : range(0, max_mem_access))
5858
-> Ext_DataAddr_Check(ext_data_addr_error) =
5959
let addr = X(base) + offset in
6060
Ext_DataAddr_OK(addr)

0 commit comments

Comments
 (0)