3 Commits

Author SHA1 Message Date
9f7aa79b99 saving current changes 2026-01-25 14:24:20 +00:00
f2cc45d169 other changes 2026-01-20 18:05:54 +00:00
b9b318b4f5 added compilable TLB bypass need to fix assert
run time error
2026-01-20 18:04:13 +00:00
33 changed files with 2912 additions and 6412 deletions

2
.gitignore vendored
View File

@@ -7,6 +7,7 @@ build_dir
obj_dir
elf_to_hex
Mem.hex
exe*
*.log
Tests/Logs
*_edited.v
@@ -22,4 +23,3 @@ src_SSITH_P3/Verilog_RTL_sim
**/TagTableStructure.bsv
**/GenerateHPMVector.bsv
**/StatCounters.bsv
test.txt

29
Tests/elf_to_hex/Makefile Normal file
View File

@@ -0,0 +1,29 @@
# Makefile to create an elf_to_hex executable.
# The executable creates mem-hex files containing 32-Byte words
CC = gcc
# the LIBERARY path needs to be set for Apple devices, e.g.,
# LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"
uname_S := $(shell uname -s)
CFLAGS = -g -o elf_to_hex elf_to_hex.c -lelf
ifeq ($(uname_S), Darwin)
CC = clang++
APPLE_FLAGS = -L /opt/homebrew/lib -I /opt/homebrew/include/libelf -I /opt/homebrew/include
endif
elf_to_hex: elf_to_hex.c
$(CC) $(CFLAGS) $(APPLE_FLAGS)
# ================================================================
.PHONY: clean
clean:
rm -f *~
.PHONY: full_clean
full_clean:
rm -f *~ elf_to_hex

View File

@@ -0,0 +1,12 @@
Copyright (c) 2018 Bluespec, Inc. All Rights Reserved
This standalone C program takes two command-line arguments, and ELF
filename and a Mem Hex filename. It reads the ELF file and writes out
the Mem Hex file.
It assumes a memory that is:
- 16 MiB or 256 MiB (see C file)
- Each word is 32 bytes (256 bits)
- It starts at byte address 0x_8000_0000
All of these can be changed by editing the C file.

View File

@@ -0,0 +1,382 @@
// Copyright (c) 2013-2018 Bluespec, Inc. All Rights Reserved
// This program reads an ELF file and outputs a Verilog hex memory
// image file (suitable for reading using $readmemh).
// Modifications for CHERI as well as compiling on APPLE devices:
/*-
* Copyright (c) 2022 Jonathan Woodruff
* Copyright (c) 2022 Franz Fuchs
* All rights reserved.
*
* This software was developed by the University of Cambridge
* Department of Computer Science and Technology under the
* SIPP (Secure IoT Processor Platform with Remote Attestation)
* project funded by EPSRC: EP/S030868/1
*
* @BERI_LICENSE_HEADER_START@
*
* Licensed to BERI Open Systems C.I.C. (BERI) under one or more contributor
* license agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership. BERI licenses this
* file to you under the BERI Hardware-Software License, Version 1.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.beri-open-systems.org/legal/license-1-0.txt
*
* Unless required by applicable law or agreed to in writing, Work distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @BERI_LICENSE_HEADER_END@
*/
// ================================================================
// Standard C includes
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
#include <gelf.h>
#ifdef __APPLE__
#include <vector>
#endif
// ================================================================
// Memory buffer into which we load the ELF file before
// writing it back out to the output file.
// 1 Gigabyte size
// #define MAX_MEM_SIZE (((uint64_t) 0x400) * ((uint64_t) 0x400) * ((uint64_t) 0x400))
#define MAX_MEM_SIZE ((uint64_t) 0x90000000)
#define BASE_ADDR_B 0x80000000lu
// For 16 MB memory at 0x_8000_0000
#define MIN_MEM_ADDR_16MB BASE_ADDR_B
#define MAX_MEM_ADDR_16MB (BASE_ADDR_B + 0x1000000lu)
// For 1 GB memory at 0x_8000_0000
#define MIN_MEM_ADDR_1GB BASE_ADDR_B
#define MAX_MEM_ADDR_1GB (BASE_ADDR_B + 0x40000000lu)
uint8_t *mem_buf;
// Features of the ELF binary
int bitwidth;
uint64_t min_addr;
uint64_t max_addr;
uint64_t pc_start; // Addr of label '_start'
uint64_t pc_exit; // Addr of label 'exit'
uint64_t tohost_addr; // Addr of label 'tohost'
// ================================================================
// Load an ELF file.
void c_mem_load_elf (char *elf_filename,
const char *start_symbol,
const char *exit_symbol,
const char *tohost_symbol)
{
int fd;
// int n_initialized = 0;
Elf *e;
// Default start, exit and tohost symbols
if (start_symbol == NULL)
start_symbol = "_start";
if (exit_symbol == NULL)
exit_symbol = "exit";
if (tohost_symbol == NULL)
tohost_symbol = "tohost";
// Verify the elf library version
if (elf_version (EV_CURRENT) == EV_NONE) {
fprintf (stderr, "ERROR: c_mem_load_elf: Failed to initialize the libelfg library!\n");
exit (1);
}
// Open the file for reading
fd = open (elf_filename, O_RDONLY, 0);
if (fd < 0) {
fprintf (stderr, "ERROR: c_mem_load_elf: could not open elf input file: %s\n", elf_filename);
exit (1);
}
// Initialize the Elf pointer with the open file
e = elf_begin (fd, ELF_C_READ, NULL);
if (e == NULL) {
fprintf (stderr, "ERROR: c_mem_load_elf: elf_begin() initialization failed!\n");
exit (1);
}
// Verify that the file is an ELF file
if (elf_kind (e) != ELF_K_ELF) {
elf_end (e);
fprintf (stderr, "ERROR: c_mem_load_elf: specified file '%s' is not an ELF file!\n", elf_filename);
exit (1);
}
// Get the ELF header
GElf_Ehdr ehdr;
if (gelf_getehdr (e, & ehdr) == NULL) {
elf_end (e);
fprintf (stderr, "ERROR: c_mem_load_elf: get_getehdr() failed: %s\n", elf_errmsg(-1));
exit (1);
}
// Is this a 32b or 64 ELF?
if (gelf_getclass (e) == ELFCLASS32) {
fprintf (stdout, "c_mem_load_elf: %s is a 32-bit ELF file\n", elf_filename);
bitwidth = 32;
}
else if (gelf_getclass (e) == ELFCLASS64) {
fprintf (stdout, "c_mem_load_elf: %s is a 64-bit ELF file\n", elf_filename);
bitwidth = 64;
}
else {
fprintf (stderr, "ERROR: c_mem_load_elf: ELF file '%s' is not 32b or 64b\n", elf_filename);
elf_end (e);
exit (1);
}
// Verify we are dealing with a RISC-V ELF
if (ehdr.e_machine != 243) { // EM_RISCV is not defined, but this returns 243 when used with a valid elf file.
elf_end (e);
fprintf (stderr, "ERROR: c_mem_load_elf: %s is not a RISC-V ELF file\n", elf_filename);
exit (1);
}
// Verify we are dealing with a little endian ELF
if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) {
elf_end (e);
fprintf (stderr,
"ERROR: c_mem_load_elf: %s is a big-endian 64-bit RISC-V executable which is not supported\n",
elf_filename);
exit (1);
}
// Grab the string section index
size_t shstrndx;
shstrndx = ehdr.e_shstrndx;
// Iterate through each of the sections looking for code that should be loaded
Elf_Scn *scn = 0;
GElf_Shdr shdr;
min_addr = 0xFFFFFFFFFFFFFFFFllu;
max_addr = 0x0000000000000000llu;
pc_start = 0xFFFFFFFFFFFFFFFFllu;
pc_exit = 0xFFFFFFFFFFFFFFFFllu;
tohost_addr = 0xFFFFFFFFFFFFFFFFllu;
while ((scn = elf_nextscn (e,scn)) != NULL) {
// get the header information for this section
gelf_getshdr (scn, & shdr);
char *sec_name = elf_strptr (e, shstrndx, shdr.sh_name);
fprintf (stdout, "Section %-16s: ", sec_name);
Elf_Data *data = 0;
// If we find a code/data section, load it into the model
if ( ((shdr.sh_type == SHT_PROGBITS)
|| (shdr.sh_type == SHT_NOBITS)
|| (shdr.sh_type == SHT_INIT_ARRAY)
|| (shdr.sh_type == SHT_FINI_ARRAY))
&& ((shdr.sh_flags & SHF_WRITE)
|| (shdr.sh_flags & SHF_ALLOC)
|| (shdr.sh_flags & SHF_EXECINSTR))) {
data = elf_getdata (scn, data);
// n_initialized += data->d_size;
if (shdr.sh_addr < min_addr)
min_addr = shdr.sh_addr;
if (max_addr < (shdr.sh_addr + data->d_size - 1)) // shdr.sh_size + 4))
max_addr = shdr.sh_addr + data->d_size - 1; // shdr.sh_size + 4;
if (max_addr >= MAX_MEM_SIZE) {
fprintf (stdout, "INTERNAL ERROR: max_addr (0x%0" PRIx64 ") > buffer size (0x%0" PRIx64 ")\n",
max_addr, MAX_MEM_SIZE);
fprintf (stdout, " Please increase the #define in this program, recompile, and run again\n");
fprintf (stdout, " Abandoning this run\n");
exit (1);
}
if (shdr.sh_type != SHT_NOBITS && shdr.sh_addr!=0) {
memcpy (& (mem_buf [shdr.sh_addr-MIN_MEM_ADDR_1GB]), data->d_buf, data->d_size);
}
fprintf (stdout, "addr %16" PRIx64 " to addr %16" PRIx64 "; size 0x%8lx (= %0ld) bytes\n",
shdr.sh_addr, shdr.sh_addr + data->d_size, data->d_size, data->d_size);
}
// If we find the symbol table, search for symbols of interest
else if (shdr.sh_type == SHT_SYMTAB) {
fprintf (stdout, "Searching for addresses of '%s', '%s' and '%s' symbols\n",
start_symbol, exit_symbol, tohost_symbol);
// Get the section data
data = elf_getdata (scn, data);
// Get the number of symbols in this section
int symbols = shdr.sh_size / shdr.sh_entsize;
// search for the uart_default symbols we need to potentially modify.
GElf_Sym sym;
int i;
for (i = 0; i < symbols; ++i) {
// get the symbol data
gelf_getsym (data, i, &sym);
// get the name of the symbol
char *name = elf_strptr (e, shdr.sh_link, sym.st_name);
// Look for, and remember PC of the start symbol
if (strcmp (name, start_symbol) == 0) {
pc_start = sym.st_value;
}
// Look for, and remember PC of the exit symbol
else if (strcmp (name, exit_symbol) == 0) {
pc_exit = sym.st_value;
}
// Look for, and remember addr of 'tohost' symbol
else if (strcmp (name, tohost_symbol) == 0) {
tohost_addr = sym.st_value;
}
}
FILE *fp_symbol_table = fopen ("symbol_table.txt", "w");
if (fp_symbol_table != NULL) {
fprintf (stdout, "Writing symbols to: symbol_table.txt\n");
if (pc_start == -1)
fprintf (stdout, " No '_start' label found\n");
else
fprintf (fp_symbol_table, "_start 0x%0" PRIx64 "\n", pc_start);
if (pc_exit == -1)
fprintf (stdout, " No 'exit' label found\n");
else
fprintf (fp_symbol_table, "exit 0x%0" PRIx64 "\n", pc_exit);
if (tohost_addr == -1)
fprintf (stdout, " No 'tohost' symbol found\n");
else
fprintf (fp_symbol_table, "tohost 0x%0" PRIx64 "\n", tohost_addr);
fclose (fp_symbol_table);
}
}
else {
fprintf (stdout, "Ignored\n");
}
}
elf_end (e);
fprintf (stdout, "Min addr: %16" PRIx64 " (hex)\n", min_addr);
fprintf (stdout, "Max addr: %16" PRIx64 " (hex)\n", max_addr);
}
// ================================================================
// Write out from word containing addr1 to word containing addr2
void write_mem_hex_file (FILE *fp, uint64_t addr1, uint64_t addr2)
{
const uint64_t bits_per_raw_mem_word = 256;
uint64_t bytes_per_raw_mem_word = bits_per_raw_mem_word / 8; // 32
uint64_t raw_mem_word_align_mask = (~ ((uint64_t) (bytes_per_raw_mem_word - 1)));
fprintf (stdout, "Subtracting 0x%08" PRIx64 " base from addresses\n", BASE_ADDR_B);
// Align the start and end addrs to raw mem words
uint64_t a1 = (addr1 & raw_mem_word_align_mask);
uint64_t a2 = ((addr2 + bytes_per_raw_mem_word - 1) & raw_mem_word_align_mask);
fprintf (fp, "@%07" PRIx64 " // raw_mem addr; byte addr: %08" PRIx64 "\n",
((a1 - BASE_ADDR_B) / bytes_per_raw_mem_word),
a1 - BASE_ADDR_B);
uint64_t addr;
for (addr = a1; addr < a2; addr += bytes_per_raw_mem_word) {
for (int j = (bytes_per_raw_mem_word - 1); j >= 0; j--)
fprintf (fp, "%02x", mem_buf [addr+j-MIN_MEM_ADDR_1GB]);
fprintf (fp, " // raw_mem addr %08" PRIx64 "; byte addr %08" PRIx64 "\n",
((addr - BASE_ADDR_B) / bytes_per_raw_mem_word),
(addr - BASE_ADDR_B));
}
// Write last word, if necessary, to avoid warnings about missing locations
if (addr < (MAX_MEM_ADDR_1GB - bytes_per_raw_mem_word)) {
addr = MAX_MEM_ADDR_1GB - bytes_per_raw_mem_word;
fprintf (fp, "@%07" PRIx64 " // last raw_mem addr; byte addr: %08" PRIx64 "\n",
((addr - BASE_ADDR_B) / bytes_per_raw_mem_word),
addr - BASE_ADDR_B);
for (int j = (bytes_per_raw_mem_word - 1); j >= 0; j--)
fprintf (fp, "%02x", 0);
fprintf (fp, " // raw_mem addr %08" PRIx64 "; byte addr %08" PRIx64 "\n",
((addr - BASE_ADDR_B) / bytes_per_raw_mem_word),
(addr - BASE_ADDR_B));
}
}
// ================================================================
void print_usage (FILE *fp, int argc, char *argv [])
{
fprintf (fp, "Usage:\n");
fprintf (fp, " %s --help\n", argv [0]);
fprintf (fp, " %s <ELF filename> <mem hex filename>\n", argv [0]);
fprintf (fp, "Reads ELF file and writes a Verilog Hex Memory image file\n");
fprintf (fp, "ELF file should have addresses within this range:\n");
fprintf (fp, "< Max: 0x%8" PRIx64 "\n", MAX_MEM_ADDR_1GB);
fprintf (fp, ">= Min: 0x%8" PRIx64 "\n", MIN_MEM_ADDR_1GB);
}
// ================================================================
int main (int argc, char *argv [])
{
if ((argc == 2) && (strcmp (argv [1], "--help") == 0)) {
print_usage (stdout, argc, argv);
return 0;
}
else if (argc != 3) {
print_usage (stderr, argc, argv);
return 1;
}
// Zero out the memory buffer before loading the ELF file
mem_buf = (uint8_t *)(calloc(MAX_MEM_SIZE, sizeof(uint8_t)));
if (mem_buf == NULL) {
fprintf (stderr, "ERROR: unable to allocate %lxMB for mem_buf\n", MAX_MEM_SIZE / 1024 / 1024);
return 1;
}
c_mem_load_elf (argv [1], "_start", "exit", "tohost");
if ((min_addr < BASE_ADDR_B) || (MAX_MEM_ADDR_1GB <= max_addr)) {
print_usage (stderr, argc, argv);
exit (1);
}
FILE *fp_out = fopen (argv [2], "w");
if (fp_out == NULL) {
fprintf (stderr, "ERROR: unable to open file '%s' for output\n", argv [2]);
return 1;
}
fprintf (stdout, "Writing mem hex to file '%s'\n", argv [2]);
write_mem_hex_file (fp_out, BASE_ADDR_B, max_addr);
// write_mem_hex_file (fp_out, BASE_ADDR_B, MAX_MEM_ADDR_1GB);
free(mem_buf);
fclose (fp_out);
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,164 +0,0 @@
#include "riscv_test.h"
#if __riscv_xlen == 64
# define STORE sd
# define LOAD ld
# define REGBYTES 8
#else
# define STORE sw
# define LOAD lw
# define REGBYTES 4
#endif
#define STACK_TOP (_end + RISCV_PGSIZE * 4)
.section ".text.init","ax",@progbits
.globl _start
.align 2
_start:
j handle_reset
/* NMI vector */
.align 2
nmi_vector:
j wtf
.align 2
trap_vector:
j wtf
handle_reset:
li x1, 0
li x2, 0
li x3, 0
li x4, 0
li x5, 0
li x6, 0
li x7, 0
li x8, 0
li x9, 0
li x10, 0
li x11, 0
li x12, 0
li x13, 0
li x14, 0
li x15, 0
li x16, 0
li x17, 0
li x18, 0
li x19, 0
li x20, 0
li x21, 0
li x22, 0
li x23, 0
li x24, 0
li x25, 0
li x26, 0
li x27, 0
li x28, 0
li x29, 0
li x30, 0
li x31, 0
INIT_RNMI
la t0, trap_vector
csrw mtvec, t0
la sp, STACK_TOP - SIZEOF_TRAPFRAME_T
csrr t0, mhartid
slli t0, t0, 12
add sp, sp, t0
csrw mscratch, sp
call extra_boot
la a0, userstart
j vm_boot
.globl pop_tf
pop_tf:
LOAD t0,33*REGBYTES(a0)
csrw sepc,t0
LOAD x1,1*REGBYTES(a0)
LOAD x2,2*REGBYTES(a0)
LOAD x3,3*REGBYTES(a0)
LOAD x4,4*REGBYTES(a0)
LOAD x5,5*REGBYTES(a0)
LOAD x6,6*REGBYTES(a0)
LOAD x7,7*REGBYTES(a0)
LOAD x8,8*REGBYTES(a0)
LOAD x9,9*REGBYTES(a0)
LOAD x11,11*REGBYTES(a0)
LOAD x12,12*REGBYTES(a0)
LOAD x13,13*REGBYTES(a0)
LOAD x14,14*REGBYTES(a0)
LOAD x15,15*REGBYTES(a0)
LOAD x16,16*REGBYTES(a0)
LOAD x17,17*REGBYTES(a0)
LOAD x18,18*REGBYTES(a0)
LOAD x19,19*REGBYTES(a0)
LOAD x20,20*REGBYTES(a0)
LOAD x21,21*REGBYTES(a0)
LOAD x22,22*REGBYTES(a0)
LOAD x23,23*REGBYTES(a0)
LOAD x24,24*REGBYTES(a0)
LOAD x25,25*REGBYTES(a0)
LOAD x26,26*REGBYTES(a0)
LOAD x27,27*REGBYTES(a0)
LOAD x28,28*REGBYTES(a0)
LOAD x29,29*REGBYTES(a0)
LOAD x30,30*REGBYTES(a0)
LOAD x31,31*REGBYTES(a0)
LOAD a0,10*REGBYTES(a0)
sret
.global trap_entry
.align 2
trap_entry:
csrrw sp, sscratch, sp
# save gprs
STORE x1,1*REGBYTES(sp)
STORE x3,3*REGBYTES(sp)
STORE x4,4*REGBYTES(sp)
STORE x5,5*REGBYTES(sp)
STORE x6,6*REGBYTES(sp)
STORE x7,7*REGBYTES(sp)
STORE x8,8*REGBYTES(sp)
STORE x9,9*REGBYTES(sp)
STORE x10,10*REGBYTES(sp)
STORE x11,11*REGBYTES(sp)
STORE x12,12*REGBYTES(sp)
STORE x13,13*REGBYTES(sp)
STORE x14,14*REGBYTES(sp)
STORE x15,15*REGBYTES(sp)
STORE x16,16*REGBYTES(sp)
STORE x17,17*REGBYTES(sp)
STORE x18,18*REGBYTES(sp)
STORE x19,19*REGBYTES(sp)
STORE x20,20*REGBYTES(sp)
STORE x21,21*REGBYTES(sp)
STORE x22,22*REGBYTES(sp)
STORE x23,23*REGBYTES(sp)
STORE x24,24*REGBYTES(sp)
STORE x25,25*REGBYTES(sp)
STORE x26,26*REGBYTES(sp)
STORE x27,27*REGBYTES(sp)
STORE x28,28*REGBYTES(sp)
STORE x29,29*REGBYTES(sp)
STORE x30,30*REGBYTES(sp)
STORE x31,31*REGBYTES(sp)
csrrw t0,sscratch,sp
STORE t0,2*REGBYTES(sp)
# get sr, epc, badvaddr, cause
csrr t0,sstatus
STORE t0,32*REGBYTES(sp)
csrr t0,sepc
STORE t0,33*REGBYTES(sp)
csrr t0,stval
STORE t0,34*REGBYTES(sp)
csrr t0,scause
STORE t0,35*REGBYTES(sp)
move a0, sp
j handle_trap

View File

@@ -1,16 +0,0 @@
OUTPUT_ARCH( "riscv" )
ENTRY(_start)
SECTIONS
{
. = 0x80000000;
.text.init : { *(.text.init) }
. = ALIGN(0x1000);
.tohost : { *(.tohost) }
. = ALIGN(0x1000);
.text : { *(.text) }
. = ALIGN(0x1000);
.data : { *(.data) }
.bss : { *(.bss) }
_end = .;
}

View File

@@ -1,98 +0,0 @@
// See LICENSE for license details.
#ifndef _ENV_VIRTUAL_SINGLE_CORE_H
#define _ENV_VIRTUAL_SINGLE_CORE_H
#include "../p/riscv_test.h"
//-----------------------------------------------------------------------
// Begin Macro
//-----------------------------------------------------------------------
#undef RVTEST_FP_ENABLE
#define RVTEST_FP_ENABLE fssr x0
#undef RVTEST_VECTOR_ENABLE
#define RVTEST_VECTOR_ENABLE \
csrwi fcsr, 0; \
csrwi vcsr, 0;
#undef RVTEST_ZVE32X_ENABLE
#define RVTEST_ZVE32X_ENABLE \
csrwi vcsr, 0;
#undef RVTEST_CODE_BEGIN
#define RVTEST_CODE_BEGIN \
.text; \
.global extra_boot; \
extra_boot: \
EXTRA_INIT \
ret; \
.global trap_filter; \
trap_filter: \
FILTER_TRAP \
li a0, 0; \
ret; \
.global pf_filter; \
pf_filter: \
FILTER_PAGE_FAULT \
li a0, 0; \
ret; \
.global userstart; \
userstart: \
init
//-----------------------------------------------------------------------
// Pass/Fail Macro
//-----------------------------------------------------------------------
#undef RVTEST_PASS
#define RVTEST_PASS li a0, 1; scall
#undef RVTEST_FAIL
#define RVTEST_FAIL sll a0, TESTNUM, 1; 1:beqz a0, 1b; or a0, a0, 1; scall;
//-----------------------------------------------------------------------
// Data Section Macro
//-----------------------------------------------------------------------
#undef RVTEST_DATA_END
#define RVTEST_DATA_END
//-----------------------------------------------------------------------
// Supervisor mode definitions and macros
//-----------------------------------------------------------------------
#ifndef LFSR_BITS
#define LFSR_BITS 6
#endif
#define MAX_TEST_PAGES ((1 << LFSR_BITS)-1) // this must be the period of the LFSR below
#define LFSR_NEXT(x) (((((x)^((x)>>1)) & 1) << (LFSR_BITS-1)) | ((x) >> 1))
#define PGSHIFT 12
#define PGSIZE (1UL << PGSHIFT)
#define SIZEOF_TRAPFRAME_T ((__riscv_xlen / 8) * 36)
#ifndef __ASSEMBLER__
typedef unsigned long pte_t;
#define LEVELS (sizeof(pte_t) == sizeof(uint64_t) ? 3 : 2)
#define PTIDXBITS (PGSHIFT - (sizeof(pte_t) == 8 ? 3 : 2))
#define VPN_BITS (PTIDXBITS * LEVELS)
#define VA_BITS (VPN_BITS + PGSHIFT)
#define PTES_PER_PT (1UL << RISCV_PGLEVEL_BITS)
#define MEGAPAGE_SIZE (PTES_PER_PT * PGSIZE)
typedef struct
{
long gpr[32];
long sr;
long epc;
long badvaddr;
long cause;
} trapframe_t;
#endif
#endif

View File

@@ -1,295 +0,0 @@
// See LICENSE for license details.
#ifndef _ENV_PHYSICAL_SINGLE_CORE_H
#define _ENV_PHYSICAL_SINGLE_CORE_H
#include "../encoding.h"
//-----------------------------------------------------------------------
// Begin Macro
//-----------------------------------------------------------------------
#define RVTEST_RV64U \
.macro init; \
.endm
#define RVTEST_RV64UF \
.macro init; \
RVTEST_FP_ENABLE; \
.endm
#define RVTEST_RV64UV \
.macro init; \
RVTEST_VECTOR_ENABLE; \
.endm
#define RVTEST_RV64UVX \
.macro init; \
RVTEST_ZVE32X_ENABLE; \
.endm
#define RVTEST_RV32U \
.macro init; \
.endm
#define RVTEST_RV32UF \
.macro init; \
RVTEST_FP_ENABLE; \
.endm
#define RVTEST_RV32UV \
.macro init; \
RVTEST_VECTOR_ENABLE; \
.endm
#define RVTEST_RV32UVX \
.macro init; \
RVTEST_ZVE32X_ENABLE; \
.endm
#define RVTEST_RV64M \
.macro init; \
RVTEST_ENABLE_MACHINE; \
.endm
#define RVTEST_RV64S \
.macro init; \
RVTEST_ENABLE_SUPERVISOR; \
.endm
#define RVTEST_RV32M \
.macro init; \
RVTEST_ENABLE_MACHINE; \
.endm
#define RVTEST_RV32S \
.macro init; \
RVTEST_ENABLE_SUPERVISOR; \
.endm
#if __riscv_xlen == 64
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
#else
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
#endif
#define INIT_XREG \
li x1, 0; \
li x2, 0; \
li x3, 0; \
li x4, 0; \
li x5, 0; \
li x6, 0; \
li x7, 0; \
li x8, 0; \
li x9, 0; \
li x10, 0; \
li x11, 0; \
li x12, 0; \
li x13, 0; \
li x14, 0; \
li x15, 0; \
li x16, 0; \
li x17, 0; \
li x18, 0; \
li x19, 0; \
li x20, 0; \
li x21, 0; \
li x22, 0; \
li x23, 0; \
li x24, 0; \
li x25, 0; \
li x26, 0; \
li x27, 0; \
li x28, 0; \
li x29, 0; \
li x30, 0; \
li x31, 0;
#define INIT_PMP \
la t0, 1f; \
csrw mtvec, t0; \
/* Set up a PMP to permit all accesses */ \
li t0, (1 << (31 + (__riscv_xlen / 64) * (53 - 31))) - 1; \
csrw pmpaddr0, t0; \
li t0, PMP_NAPOT | PMP_R | PMP_W | PMP_X; \
csrw pmpcfg0, t0; \
.align 2; \
1:
#define INIT_RNMI \
la t0, 1f; \
csrw mtvec, t0; \
csrwi CSR_MNSTATUS, MNSTATUS_NMIE; \
.align 2; \
1:
#define INIT_SATP \
la t0, 1f; \
csrw mtvec, t0; \
csrwi satp, 0; \
.align 2; \
1:
#define DELEGATE_NO_TRAPS \
csrwi mie, 0; \
la t0, 1f; \
csrw mtvec, t0; \
csrwi medeleg, 0; \
csrwi mideleg, 0; \
.align 2; \
1:
#define RVTEST_ENABLE_SUPERVISOR \
li a0, MSTATUS_MPP & (MSTATUS_MPP >> 1); \
csrs mstatus, a0; \
li a0, SIP_SSIP | SIP_STIP; \
csrs mideleg, a0; \
#define RVTEST_ENABLE_MACHINE \
li a0, MSTATUS_MPP; \
csrs mstatus, a0; \
#define RVTEST_FP_ENABLE \
li a0, MSTATUS_FS & (MSTATUS_FS >> 1); \
csrs mstatus, a0; \
csrwi fcsr, 0
#define RVTEST_VECTOR_ENABLE \
li a0, (MSTATUS_VS & (MSTATUS_VS >> 1)) | \
(MSTATUS_FS & (MSTATUS_FS >> 1)); \
csrs mstatus, a0; \
csrwi fcsr, 0; \
csrwi vcsr, 0;
#define RVTEST_ZVE32X_ENABLE \
li a0, (MSTATUS_VS & (MSTATUS_VS >> 1)); \
csrs mstatus, a0; \
csrwi vcsr, 0;
#define RISCV_MULTICORE_DISABLE \
csrr a0, mhartid; \
1: bnez a0, 1b
#define EXTRA_TVEC_USER
#define EXTRA_TVEC_MACHINE
#define EXTRA_INIT
#define EXTRA_INIT_TIMER
#define FILTER_TRAP
#define FILTER_PAGE_FAULT
#define INTERRUPT_HANDLER j other_exception /* No interrupts should occur */
#define RVTEST_CODE_BEGIN \
.section .text.init; \
.align 6; \
.weak stvec_handler; \
.weak mtvec_handler; \
.globl _start; \
_start: \
/* reset vector */ \
j reset_vector; \
.align 2; \
trap_vector: \
/* test whether the test came from pass/fail */ \
csrr t5, mcause; \
li t6, CAUSE_USER_ECALL; \
beq t5, t6, write_tohost; \
li t6, CAUSE_SUPERVISOR_ECALL; \
beq t5, t6, write_tohost; \
li t6, CAUSE_MACHINE_ECALL; \
beq t5, t6, write_tohost; \
/* if an mtvec_handler is defined, jump to it */ \
la t5, mtvec_handler; \
beqz t5, 1f; \
jr t5; \
/* was it an interrupt or an exception? */ \
1: csrr t5, mcause; \
bgez t5, handle_exception; \
INTERRUPT_HANDLER; \
handle_exception: \
/* we don't know how to handle whatever the exception was */ \
other_exception: \
/* some unhandlable exception occurred */ \
1: ori TESTNUM, TESTNUM, 1337; \
write_tohost: \
sw TESTNUM, tohost, t5; \
sw zero, tohost + 4, t5; \
j write_tohost; \
reset_vector: \
INIT_XREG; \
RISCV_MULTICORE_DISABLE; \
INIT_RNMI; \
INIT_SATP; \
INIT_PMP; \
DELEGATE_NO_TRAPS; \
li TESTNUM, 0; \
la t0, trap_vector; \
csrw mtvec, t0; \
CHECK_XLEN; \
/* if an stvec_handler is defined, delegate exceptions to it */ \
la t0, stvec_handler; \
beqz t0, 1f; \
csrw stvec, t0; \
li t0, (1 << CAUSE_LOAD_PAGE_FAULT) | \
(1 << CAUSE_STORE_PAGE_FAULT) | \
(1 << CAUSE_FETCH_PAGE_FAULT) | \
(1 << CAUSE_MISALIGNED_FETCH) | \
(1 << CAUSE_USER_ECALL) | \
(1 << CAUSE_BREAKPOINT); \
csrw medeleg, t0; \
1: csrwi mstatus, 0; \
init; \
EXTRA_INIT; \
EXTRA_INIT_TIMER; \
la t0, 1f; \
csrw mepc, t0; \
csrr a0, mhartid; \
mret; \
1:
//-----------------------------------------------------------------------
// End Macro
//-----------------------------------------------------------------------
#define RVTEST_CODE_END \
unimp
//-----------------------------------------------------------------------
// Pass/Fail Macro
//-----------------------------------------------------------------------
#define RVTEST_PASS \
fence; \
li TESTNUM, 1; \
li a7, 93; \
li a0, 0; \
ecall
#define TESTNUM gp
#define RVTEST_FAIL \
fence; \
1: beqz TESTNUM, 1b; \
sll TESTNUM, TESTNUM, 1; \
or TESTNUM, TESTNUM, 1; \
li a7, 93; \
addi a0, TESTNUM, 0; \
ecall
//-----------------------------------------------------------------------
// Data Section Macro
//-----------------------------------------------------------------------
#define EXTRA_DATA
#define RVTEST_DATA_BEGIN \
EXTRA_DATA \
.pushsection .tohost,"aw",@progbits; \
.align 6; .global tohost; tohost: .dword 0; .size tohost, 8; \
.align 6; .global fromhost; fromhost: .dword 0; .size fromhost, 8;\
.popsection; \
.align 4; .global begin_signature; begin_signature:
#define RVTEST_DATA_END .align 4; .global end_signature; end_signature:
#endif

View File

@@ -1,114 +0,0 @@
#include <string.h>
#include <stdint.h>
#include <ctype.h>
void* memcpy(void* dest, const void* src, size_t len)
{
if ((((uintptr_t)dest | (uintptr_t)src | len) & (sizeof(uintptr_t)-1)) == 0) {
const uintptr_t* s = src;
uintptr_t *d = dest;
while (d < (uintptr_t*)(dest + len))
*d++ = *s++;
} else {
const char* s = src;
char *d = dest;
while (d < (char*)(dest + len))
*d++ = *s++;
}
return dest;
}
void* memset(void* dest, int byte, size_t len)
{
if ((((uintptr_t)dest | len) & (sizeof(uintptr_t)-1)) == 0) {
uintptr_t word = byte & 0xFF;
word |= word << 8;
word |= word << 16;
word |= word << 16 << 16;
uintptr_t *d = dest;
while (d < (uintptr_t*)(dest + len))
*d++ = word;
} else {
char *d = dest;
while (d < (char*)(dest + len))
*d++ = byte;
}
return dest;
}
size_t strlen(const char *s)
{
const char *p = s;
while (*p)
p++;
return p - s;
}
int strcmp(const char* s1, const char* s2)
{
unsigned char c1, c2;
do {
c1 = *s1++;
c2 = *s2++;
} while (c1 != 0 && c1 == c2);
return c1 - c2;
}
int memcmp(const void* s1, const void* s2, size_t n)
{
if ((((uintptr_t)s1 | (uintptr_t)s2) & (sizeof(uintptr_t)-1)) == 0) {
const uintptr_t* u1 = s1;
const uintptr_t* u2 = s2;
const uintptr_t* end = u1 + (n / sizeof(uintptr_t));
while (u1 < end) {
if (*u1 != *u2)
break;
u1++;
u2++;
}
n -= (const void*)u1 - s1;
s1 = u1;
s2 = u2;
}
while (n--) {
unsigned char c1 = *(const unsigned char*)s1++;
unsigned char c2 = *(const unsigned char*)s2++;
if (c1 != c2)
return c1 - c2;
}
return 0;
}
char* strcpy(char* dest, const char* src)
{
char* d = dest;
while ((*d++ = *src++))
;
return dest;
}
long atol(const char* str)
{
long res = 0;
int sign = 0;
while (*str == ' ')
str++;
if (*str == '-' || *str == '+') {
sign = *str == '-';
str++;
}
while (*str) {
res *= 10;
res += *str++ - '0';
}
return sign ? -res : res;
}

View File

@@ -1,300 +0,0 @@
// See LICENSE for license details.
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "riscv_test.h"
#define SYS_write 64
# define SATP_MODE_CHOICE SATP_MODE_SV39
void trap_entry();
void pop_tf(trapframe_t*);
extern volatile uint64_t tohost;
extern volatile uint64_t fromhost;
static void do_tohost(uint64_t tohost_value)
{
while (tohost)
fromhost = 0;
tohost = tohost_value;
}
#define pa2kva(pa) ((void*)(pa) - DRAM_BASE - MEGAPAGE_SIZE)
#define uva2kva(pa) ((void*)(pa) - MEGAPAGE_SIZE)
#define flush_page(addr) asm volatile ("sfence.vma %0" : : "r" (addr) : "memory")
static uint64_t lfsr63(uint64_t x)
{
uint64_t bit = (x ^ (x >> 1)) & 1;
return (x >> 1) | (bit << 62);
}
static void cputchar(int x)
{
#if __riscv_xlen == 32
// HTIF devices are not supported on RV32, so proxy a write system call
volatile uint64_t syscall_struct[8];
volatile int buff = x;
syscall_struct[0] = SYS_write;
syscall_struct[1] = 1;
syscall_struct[2] = (uintptr_t)&buff;
syscall_struct[3] = 1;
do_tohost((uintptr_t)&syscall_struct);
// Wait for response as struct has to be read by HTIF
while(!fromhost);
#else
do_tohost(0x0101000000000000 | (unsigned char)x);
#endif
}
static void cputstring(const char* s)
{
while (*s)
cputchar(*s++);
}
static void terminate(int code)
{
do_tohost(code);
while (1);
}
void wtf()
{
terminate(841);
}
#define stringify1(x) #x
#define stringify(x) stringify1(x)
#define assert(x) do { \
if (x) break; \
cputstring("Assertion failed: " stringify(x) "\n"); \
terminate(3); \
} while(0)
#define l1pt pt[0]
#define user_l2pt pt[1]
# define NPT 4
# define kernel_l2pt pt[2]
# define user_llpt pt[3]
pte_t pt[NPT][PTES_PER_PT] __attribute__((aligned(PGSIZE)));
typedef struct { pte_t addr; void* next; } freelist_t;
freelist_t user_mapping[MAX_TEST_PAGES];
freelist_t freelist_nodes[MAX_TEST_PAGES];
freelist_t *freelist_head, *freelist_tail;
void printhex(uint64_t x)
{
char str[17];
for (int i = 0; i < 16; i++)
{
str[15-i] = (x & 0xF) + ((x & 0xF) < 10 ? '0' : 'a'-10);
x >>= 4;
}
str[16] = 0;
cputstring(str);
}
static void evict(unsigned long addr)
{
assert(addr >= PGSIZE && addr < MAX_TEST_PAGES * PGSIZE);
addr = addr/PGSIZE*PGSIZE;
freelist_t* node = &user_mapping[addr/PGSIZE];
if (node->addr)
{
// check accessed and dirty bits
assert(user_llpt[addr/PGSIZE] & PTE_A);
uintptr_t sstatus = set_csr(sstatus, SSTATUS_SUM);
if (memcmp((void*)addr, uva2kva(addr), PGSIZE)) {
assert(user_llpt[addr/PGSIZE] & PTE_D);
memcpy(uva2kva(addr), (void*)addr, PGSIZE);
}
write_csr(sstatus, sstatus);
user_mapping[addr/PGSIZE].addr = 0;
if (freelist_tail == 0)
freelist_head = freelist_tail = node;
else
{
freelist_tail->next = node;
freelist_tail = node;
}
}
}
extern int pf_filter(uintptr_t addr, uintptr_t *pte, int *copy);
extern int trap_filter(trapframe_t *tf);
void handle_fault(uintptr_t addr, uintptr_t cause)
{
uintptr_t filter_encodings = 0;
int copy_page = 1;
assert(addr >= PGSIZE && addr < MAX_TEST_PAGES * PGSIZE);
addr = addr/PGSIZE*PGSIZE;
if (user_llpt[addr/PGSIZE]) {
if (!(user_llpt[addr/PGSIZE] & PTE_A)) {
user_llpt[addr/PGSIZE] |= PTE_A;
} else {
assert(!(user_llpt[addr/PGSIZE] & PTE_D) && cause == CAUSE_STORE_PAGE_FAULT);
user_llpt[addr/PGSIZE] |= PTE_D;
}
flush_page(addr);
return;
}
freelist_t* node = freelist_head;
assert(node);
freelist_head = node->next;
if (freelist_head == freelist_tail)
freelist_tail = 0;
uintptr_t new_pte = (node->addr >> PGSHIFT << PTE_PPN_SHIFT) | PTE_V | PTE_U | PTE_R | PTE_W | PTE_X;
if (pf_filter(addr, &filter_encodings, &copy_page)) {
new_pte = (node->addr >> PGSHIFT << PTE_PPN_SHIFT) | filter_encodings;
}
user_llpt[addr/PGSIZE] = new_pte | PTE_A | PTE_D;
flush_page(addr);
assert(user_mapping[addr/PGSIZE].addr == 0);
user_mapping[addr/PGSIZE] = *node;
uintptr_t sstatus = set_csr(sstatus, SSTATUS_SUM);
memcpy((void*)addr, uva2kva(addr), PGSIZE);
write_csr(sstatus, sstatus);
user_llpt[addr/PGSIZE] = new_pte;
flush_page(addr);
asm volatile ("fence.i");
}
void handle_trap(trapframe_t* tf)
{
if (trap_filter(tf)) {
pop_tf(tf);
}
if (tf->cause == CAUSE_USER_ECALL)
{
int n = tf->gpr[10];
for (long i = 1; i < MAX_TEST_PAGES; i++)
evict(i*PGSIZE);
terminate(n);
}
else if (tf->cause == CAUSE_ILLEGAL_INSTRUCTION)
{
assert(tf->epc % 4 == 0);
int* fssr;
asm ("jal %0, 1f; fssr x0; 1:" : "=r"(fssr));
if (*(int*)tf->epc == *fssr)
terminate(1); // FP test on non-FP hardware. "succeed."
else
assert(!"illegal instruction");
tf->epc += 4;
}
else if (tf->cause == CAUSE_FETCH_PAGE_FAULT || tf->cause == CAUSE_LOAD_PAGE_FAULT || tf->cause == CAUSE_STORE_PAGE_FAULT)
handle_fault(tf->badvaddr, tf->cause);
else
assert(!"unexpected exception");
pop_tf(tf);
}
static void coherence_torture()
{
// cause coherence misses without affecting program semantics
uint64_t random = ENTROPY;
while (1) {
uintptr_t paddr = DRAM_BASE + ((random % (2 * (MAX_TEST_PAGES + 1) * PGSIZE)) & -4);
#ifdef __riscv_atomic
if (random & 1) // perform a no-op write
asm volatile ("amoadd.w zero, zero, (%0)" :: "r"(paddr));
else // perform a read
#endif
asm volatile ("lw zero, (%0)" :: "r"(paddr));
random = lfsr63(random);
}
}
void vm_boot(uintptr_t test_addr)
{
uint64_t random = ENTROPY;
if (read_csr(mhartid) > 0)
coherence_torture();
_Static_assert(SIZEOF_TRAPFRAME_T == sizeof(trapframe_t), "???");
#if (MAX_TEST_PAGES > PTES_PER_PT) || (DRAM_BASE % MEGAPAGE_SIZE) != 0
# error
#endif
// map user to lowermost megapage
l1pt[0] = ((pte_t)user_l2pt >> PGSHIFT << PTE_PPN_SHIFT) | PTE_V;
// map kernel to uppermost megapage
l1pt[PTES_PER_PT-1] = ((pte_t)kernel_l2pt >> PGSHIFT << PTE_PPN_SHIFT) | PTE_V;
kernel_l2pt[PTES_PER_PT-1] = (DRAM_BASE/RISCV_PGSIZE << PTE_PPN_SHIFT) | PTE_V | PTE_R | PTE_W | PTE_X | PTE_A | PTE_D;
user_l2pt[0] = ((pte_t)user_llpt >> PGSHIFT << PTE_PPN_SHIFT) | PTE_V;
uintptr_t vm_choice = SATP_MODE_CHOICE;
uintptr_t satp_value = ((uintptr_t)l1pt >> PGSHIFT)
| (vm_choice * (SATP_MODE & ~(SATP_MODE<<1)));
write_csr(satp, satp_value);
if (read_csr(satp) != satp_value)
assert(!"unsupported satp mode");
flush_page(DRAM_BASE);
// Set up PMPs if present, ignoring illegal instruction trap if not.
uintptr_t pmpc = PMP_NAPOT | PMP_R | PMP_W | PMP_X;
uintptr_t pmpa = ((uintptr_t)1 << (__riscv_xlen == 32 ? 31 : 53)) - 1;
asm volatile ("la t0, 1f\n\t"
"csrrw t0, mtvec, t0\n\t"
"csrw pmpaddr0, %1\n\t"
"csrw pmpcfg0, %0\n\t"
".align 2\n\t"
"1: csrw mtvec, t0"
: : "r" (pmpc), "r" (pmpa) : "t0");
// set up supervisor trap handling
write_csr(stvec, pa2kva(trap_entry));
write_csr(sscratch, pa2kva(read_csr(mscratch)));
write_csr(medeleg,
(1 << CAUSE_USER_ECALL) |
(1 << CAUSE_FETCH_PAGE_FAULT) |
(1 << CAUSE_LOAD_PAGE_FAULT) |
(1 << CAUSE_STORE_PAGE_FAULT));
// FPU on; accelerator on; vector unit on
write_csr(mstatus, MSTATUS_FS | MSTATUS_XS | MSTATUS_VS);
write_csr(mie, 0);
random = 1 + (random % MAX_TEST_PAGES);
freelist_head = pa2kva((void*)&freelist_nodes[0]);
freelist_tail = pa2kva(&freelist_nodes[MAX_TEST_PAGES-1]);
for (long i = 0; i < MAX_TEST_PAGES; i++)
{
freelist_nodes[i].addr = DRAM_BASE + (MAX_TEST_PAGES + random)*PGSIZE;
freelist_nodes[i].next = pa2kva(&freelist_nodes[i+1]);
random = LFSR_NEXT(random);
}
freelist_nodes[MAX_TEST_PAGES-1].next = 0;
trapframe_t tf;
memset(&tf, 0, sizeof(tf));
tf.epc = test_addr - DRAM_BASE;
pop_tf(&tf);
}

View File

@@ -1,37 +0,0 @@
.section .bss
.align 6 # 64-byte alignment helps bounds encoding
buffer:
.space 64
.section .text
.globl _start
_start:
# ------------------------------------------------------------
# 1. Create capability to buffer using DDC (c0)
# ------------------------------------------------------------
la t0, buffer
cincoffset c1, c0, t0 # c1 -> buffer capability
# ------------------------------------------------------------
# 2. Set bounds to first 16 bytes
# ------------------------------------------------------------
li t1, 16
csetbounds c2, c1, t1 # c2 = bounded capability
# ------------------------------------------------------------
# 3. Store value 0x42 into buffer[0] using capability
# ------------------------------------------------------------
li t2, 0x42
csb t2, 0(c2) # capability store byte
# ------------------------------------------------------------
# 4. Load the value back from buffer[0]
# ------------------------------------------------------------
clbu t3, 0(c2) # t3 should now contain 0x42
# ------------------------------------------------------------
# 5. Infinite loop (bare-metal halt)
# ------------------------------------------------------------
1:
j 1b

Binary file not shown.

View File

@@ -1,177 +0,0 @@
.option norvc
.option norelax
# ==================================================
# Constants
# ==================================================
.equ PTE_V, 0x001
.equ PTE_R, 0x002
.equ PTE_W, 0x004
.equ PTE_X, 0x008
.equ PTE_A, 0x040
.equ PTE_D, 0x080
.equ SATP_MODE_SV39, (8 << 60)
# ==================================================
# Text
# ==================================================
.section .text
.globl _start
_start:
# only hart 0
csrr a0, mhartid
bnez a0, hang
# install trap vector (required)
la t0, trap_vector
csrw stvec, t0
# --------------------------------------------------
# Build page tables (Sv39 identity map 1 GiB)
# --------------------------------------------------
# root_pt[0] -> l1_pt
la t0, l1_pt
srli t0, t0, 12
slli t0, t0, 10
ori t0, t0, PTE_V
la t1, root_pt
sd t0, 0(t1)
# l1_pt[0] -> l0_pt
la t0, l0_pt
srli t0, t0, 12
slli t0, t0, 10
ori t0, t0, PTE_V
la t1, l1_pt
sd t0, 0(t1)
# l0_pt[0] = 1GiB RWX identity leaf
li t0, (PTE_V|PTE_R|PTE_W|PTE_X|PTE_A|PTE_D)
la t1, l0_pt
sd t0, 0(t1)
# --------------------------------------------------
# Enable Sv39
# --------------------------------------------------
la t0, root_pt
srli t0, t0, 12
li t1, SATP_MODE_SV39
or t0, t0, t1
csrw satp, t0
# sfence.vma zero, zero
# --------------------------------------------------
# Init allocator
# --------------------------------------------------
la t0, heap_base
la t1, heap_ptr
sd t0, 0(t1)
la t0, free_list
sd zero, 0(t0)
# --------------------------------------------------
# Allocate free reuse test
# --------------------------------------------------
li a0, 16
call alloc
mv s1, a0
li t0, 0x1122334455667788
sd t0, 0(s1)
mv a0, s1
call free
li a0, 16
call alloc
mv s2, a0
ld t1, 0(s2)
li t0, 0x1122334455667788
bne t1, t0, hang
# success
la t0, tohost
li t1, 1
sd t1, 0(t0)
hang:
wfi
j hang
# ==================================================
# Minimal trap handler (required)
# ==================================================
.align 2
trap_vector:
csrr t0, scause
j hang
# ==================================================
# alloc(size)
# ==================================================
.globl alloc
alloc:
la t0, free_list
ld t1, 0(t0)
beqz t1, alloc_bump
ld t2, 0(t1)
sd t2, 0(t0)
addi a0, t1, 8
ret
alloc_bump:
la t0, heap_ptr
ld t1, 0(t0)
addi t2, a0, 8
add t3, t1, t2
la t4, heap_end
bgtu t3, t4, hang
sd t3, 0(t0)
addi a0, t1, 8
ret
# ==================================================
# free(ptr)
# ==================================================
.globl free
free:
addi t0, a0, -8
la t1, free_list
ld t2, 0(t1)
sd t2, 0(t0)
sd t0, 0(t1)
ret
# ==================================================
# Data (NO .bss)
# ==================================================
.section .data
.align 3
.globl tohost
.globl fromhost
tohost: .dword 0
fromhost: .dword 0
.globl heap_ptr
.globl free_list
heap_ptr: .dword 0
free_list: .dword 0
.align 12
heap_base:
.zero 4096
heap_end:
.align 12
root_pt: .zero 4096
.align 12
l1_pt: .zero 4096
.align 12
l0_pt: .zero 4096

View File

@@ -1,4 +1,3 @@
scp Tests/isa/MemoryAllocator.S home:/home/akilan/Documents/cheri/riscv/riscv/bin
./riscv64-unknown-elf-gcc -nostdlib -nostartfiles -Wl,-Ttext=0x80000000 Page.S -o Page.o
./riscv64-unknown-elf-objcopy --remove-section .bss Page.o Page
# Copy file

Binary file not shown.

View File

@@ -0,0 +1,43 @@
make -C ../../Tests/elf_to_hex
make[1]: Entering directory '/Users/akilan/Documents/Cheri/Test/Reverse/Test/Toooba/Tests/elf_to_hex'
make[1]: 'elf_to_hex' is up to date.
make[1]: Leaving directory '/Users/akilan/Documents/Cheri/Test/Reverse/Test/Toooba/Tests/elf_to_hex'
../../Tests/elf_to_hex/elf_to_hex ../../Tests/isa/rv64ui-p-add Mem.hex
c_mem_load_elf: ../../Tests/isa/rv64ui-p-add is a 64-bit ELF file
Section .text.init : addr 80000000 to addr 80000644; size 0x 644 (= 1604) bytes
Section .tohost : addr 80001000 to addr 80001048; size 0x 48 (= 72) bytes
Section .riscv.attributes: Ignored
Section .symtab : Searching for addresses of '_start', 'exit' and 'tohost' symbols
Writing symbols to: symbol_table.txt
No 'exit' label found
Section .strtab : Ignored
Section .shstrtab : Ignored
Min addr: 80000000 (hex)
Max addr: 80001047 (hex)
Writing mem hex to file 'Mem.hex'
Subtracting 0x80000000 base from addresses
./exe_HW_sim +v1 +tohost
================================================================
Bluespec RISC-V standalone system simulation v1.2
Copyright (c) 2017-2018 Bluespec, Inc. All Rights Reserved.
================================================================
2: top.dut_soc_top.rl_reset_start_initial ...
---- allocated socket for RVFI_DII
---- RVFI_DII_PORT environment variable not defined, using default port 5001 instead
---- RVFI_DII socket listening on port 5001
req addr: 'h0000000000000000, zeroed_0_start: 'h0000000000000000-'h0000000000040000, zeroed_1_start: 'h0000000001f80000-'h0000000001fffff8
req addr: 'h0000000000000000, zeroed_0_start: 'h0000000000000000-'h0000000000040000, zeroed_1_start: 'h0000000001f80000-'h0000000001fffff8
74: Mem_Controller.set_addr_map: addr_base 0x80000000 addr_lim 0xc0000000
SoC address map:
Boot ROM: 0x1000 .. 0x2000
Mem0 Controller: 0x80000000 .. 0xc0000000
UART0: 0xc0000000 .. 0xc0000080
74: top.dut_soc_top.rl_reset_complete_initial
INFO: watch_tohost 1, tohost_addr = 0x80001000, fromhost_addr = 0x0
75: top.dut_soc_top.method start (tohost 80001000, fromhost 0)
101: top.dut_soc_top.rl_step_0, n = 0, do_release
101: top.dut_soc_top do_release(restartRunning: True, to_host_addr: 0)
101: top.dut_soc_top.proc.method start: startpc 80000000, tohostAddr 0, fromhostAddr 0
102: top.dut_soc_top.rl_ctrl_req
102: top.dut_soc_top.proc.method start: startpc 80000000, tohostAddr 80001000, fromhostAddr 0
102: top.dut_soc_top do_release(restartRunning: True, to_host_addr: 80001000)

View File

@@ -0,0 +1,134 @@
@0000000 // raw_mem addr; byte addr: 00000000
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000000; byte addr 00000000
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000001; byte addr 00000020
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000002; byte addr 00000040
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000003; byte addr 00000060
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000004; byte addr 00000080
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000005; byte addr 000000a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000006; byte addr 000000c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000007; byte addr 000000e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000008; byte addr 00000100
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000009; byte addr 00000120
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000a; byte addr 00000140
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000b; byte addr 00000160
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000c; byte addr 00000180
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000d; byte addr 000001a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000e; byte addr 000001c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000000f; byte addr 000001e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000010; byte addr 00000200
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000011; byte addr 00000220
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000012; byte addr 00000240
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000013; byte addr 00000260
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000014; byte addr 00000280
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000015; byte addr 000002a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000016; byte addr 000002c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000017; byte addr 000002e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000018; byte addr 00000300
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000019; byte addr 00000320
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001a; byte addr 00000340
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001b; byte addr 00000360
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001c; byte addr 00000380
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001d; byte addr 000003a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001e; byte addr 000003c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000001f; byte addr 000003e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000020; byte addr 00000400
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000021; byte addr 00000420
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000022; byte addr 00000440
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000023; byte addr 00000460
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000024; byte addr 00000480
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000025; byte addr 000004a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000026; byte addr 000004c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000027; byte addr 000004e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000028; byte addr 00000500
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000029; byte addr 00000520
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002a; byte addr 00000540
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002b; byte addr 00000560
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002c; byte addr 00000580
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002d; byte addr 000005a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002e; byte addr 000005c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000002f; byte addr 000005e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000030; byte addr 00000600
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000031; byte addr 00000620
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000032; byte addr 00000640
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000033; byte addr 00000660
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000034; byte addr 00000680
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000035; byte addr 000006a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000036; byte addr 000006c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000037; byte addr 000006e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000038; byte addr 00000700
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000039; byte addr 00000720
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003a; byte addr 00000740
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003b; byte addr 00000760
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003c; byte addr 00000780
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003d; byte addr 000007a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003e; byte addr 000007c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000003f; byte addr 000007e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000040; byte addr 00000800
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000041; byte addr 00000820
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000042; byte addr 00000840
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000043; byte addr 00000860
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000044; byte addr 00000880
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000045; byte addr 000008a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000046; byte addr 000008c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000047; byte addr 000008e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000048; byte addr 00000900
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000049; byte addr 00000920
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004a; byte addr 00000940
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004b; byte addr 00000960
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004c; byte addr 00000980
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004d; byte addr 000009a0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004e; byte addr 000009c0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000004f; byte addr 000009e0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000050; byte addr 00000a00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000051; byte addr 00000a20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000052; byte addr 00000a40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000053; byte addr 00000a60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000054; byte addr 00000a80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000055; byte addr 00000aa0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000056; byte addr 00000ac0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000057; byte addr 00000ae0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000058; byte addr 00000b00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000059; byte addr 00000b20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005a; byte addr 00000b40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005b; byte addr 00000b60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005c; byte addr 00000b80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005d; byte addr 00000ba0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005e; byte addr 00000bc0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000005f; byte addr 00000be0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000060; byte addr 00000c00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000061; byte addr 00000c20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000062; byte addr 00000c40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000063; byte addr 00000c60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000064; byte addr 00000c80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000065; byte addr 00000ca0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000066; byte addr 00000cc0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000067; byte addr 00000ce0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000068; byte addr 00000d00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000069; byte addr 00000d20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006a; byte addr 00000d40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006b; byte addr 00000d60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006c; byte addr 00000d80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006d; byte addr 00000da0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006e; byte addr 00000dc0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000006f; byte addr 00000de0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000070; byte addr 00000e00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000071; byte addr 00000e20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000072; byte addr 00000e40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000073; byte addr 00000e60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000074; byte addr 00000e80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000075; byte addr 00000ea0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000076; byte addr 00000ec0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000077; byte addr 00000ee0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000078; byte addr 00000f00
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000079; byte addr 00000f20
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007a; byte addr 00000f40
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007b; byte addr 00000f60
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007c; byte addr 00000f80
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007d; byte addr 00000fa0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007e; byte addr 00000fc0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 0000007f; byte addr 00000fe0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000080; byte addr 00001000
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000081; byte addr 00001020
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 00000082; byte addr 00001040
@07fffff // last raw_mem addr; byte addr: 0fffffe0
0000000000000000000000000000000000000000000000000000000000000000 // raw_mem addr 007fffff; byte addr 0fffffe0

View File

@@ -8,14 +8,11 @@ ARCH ?= RV64ACDFIMSUxCHERI
BSC_COMPILATION_FLAGS += -verbose
# Default ISA test
# TEST ?= rv64ui-p-add
TEST ?= rv64um-v-mulw
TEST ?= rv64ui-p-add
# TEST ?= rv64um-v-mulw
# TEST ?= Page
# TEST ?= PageReadWrite
# TEST ?= CheriPage
# TEST ?= MemoryAllocator
# TEST = rv64ui-v-blt
# TEST = string
#================================================================
# Parameter settings for MIT RISCY, setup paths etc. for Include_Common

View File

@@ -1,12 +0,0 @@
#!/bin/sh
BLUESPECDIR=`echo 'puts $env(BLUESPECDIR)' | bluetcl`
for arg in $@
do
if (test "$arg" = "-h")
then
exec $BLUESPECDIR/tcllib/bluespec/bluesim.tcl $0.so mkTop_HW_Side --script_name `basename $0` -h
fi
done
exec $BLUESPECDIR/tcllib/bluespec/bluesim.tcl $0.so mkTop_HW_Side --script_name `basename $0` --creation_time 1770243680 "$@"

File diff suppressed because it is too large Load Diff

View File

@@ -109,7 +109,7 @@ benchmarks:
# ================================================================
# Generate Bluespec CHERI tag controller source file
CAPSIZE = 128
CAPSIZE = 128
TAGS_STRUCT = 0 64
TAGS_ALIGN = 32
.PHONY: tagsparams

0
builds/test.txt Normal file
View File

View File

@@ -228,4 +228,4 @@ Bit #(3) f3_AMO_CAP = w_SIZE_CAP;
Bit #(XLEN) otype_unsealed_ext = -1;
Bit #(XLEN) otype_sentry_ext = -2;
Bit #(XLEN) otype_res0_ext = -3;
Bit #(XLEN) otype_res1_ext = -4;
Bit #(XLEN) otype_res1_ext = -4;

View File

@@ -320,7 +320,7 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
// pipeline fifos
let dispToRegQ <- mkMemDispToRegFifo;
let regToExeQ <- mkMemRegToExeFifo;
// let trollToExeQ <- mkMemRegToExeFifo;
let trollToExeQ <- mkMemRegToExeFifo;
// wire to recv bypass
Vector#(TMul#(2, AluExeNum), RWire#(Tuple2#(PhyRIndx, CapPipe))) bypassWire <- replicateM(mkRWire);
@@ -531,14 +531,7 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
if(x.regs.src1 matches tagged Valid .src1 &&& src1 != 0) begin
rVal1 <- readRFBypass(src1, regsReady.src1, inIfc.rf_rd1(src1), bypassWire);
end
if (x.ddc_offset) begin
$display("calling set address");
rVal1 = setAddr(ddc, getAddr(rVal1)).value;
end
else begin
$display("no called set address");
end
$display("outside if and else");
if (x.ddc_offset) rVal1 = setAddr(ddc, getAddr(rVal1)).value;
// get rVal2 (check bypass)
CapPipe rVal2 = nullCap;
@@ -605,88 +598,159 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
endrule
rule doExeMem;
$display("do exe");
regToExeQ.deq;
let regToExe = regToExeQ.first;
let x = regToExe.data;
// trollToExeQ.enq(regToExe);
// ==============================
if(verbose) $display("%t : [doExeMem] ", $time, fshow(regToExe));
// if(verbose) $display("%t : [doExeMem] ", $time, fshow(regToExe));
let shiftBE = DataMemAccess(x.shiftBEData);
if (x.origBE == TagMemAccess) begin
// // Moved to the next stage
// // let shiftBE = DataMemAccess(x.shiftBEData);
// // if (x.origBE == TagMemAccess) begin
// // shiftBE = TagMemAccess;
// // end
// CapPipe ddc = cast(inIfc.scaprf_rd(scrAddrDDC));
// // get size of the access
// Bit#(TAdd#(CacheUtils::LogCLineNumMemDataBytes,1)) accessByteCount = zeroExtend(pack(countOnes(pack(x.origBE.DataMemAccess))));
// if (x.origBE == TagMemAccess) begin
// accessByteCount = fromInteger(valueOf(CacheUtils::CLineNumMemDataBytes));
// end
// `ifdef KONATA
// $display("KONATAE\t%0d\t%0d\t0\tMem2", cur_cycle, x.u_id);
// $display("KONATAS\t%0d\t%0d\t0\tMem3", cur_cycle, x.u_id);
// $fflush;
// `endif
// Make our own versions where this is passed as a queue to
// the next stage and processed there:
// We only need
// - x.mem_func(Maybe to see if it's a load ?)
// - x (We can get the hardware permissions, cap_mem permission, prepareBoundsCheck)
// - We will assume a one on one mapping with offset with a delta value of 1 (Hardcoded
// for just testing)
trollToExeQ.enq(regToExe);
// go to next stage by sending to TLB
// dTlb.procReq(DTlbReq {
// inst: MemExeToFinish {
// mem_func: x.mem_func,
// tag: x.tag,
// ldstq_tag: x.ldstq_tag,
// shiftedBE: shiftBE,
// vaddr: x.vaddr,
// `ifdef INCLUDE_TANDEM_VERIF
// store_data: x.rVal2,
// store_data_BE: origBE,
// `endif
// misaligned: memAddrMisaligned(getAddr(x.vaddr), x.origBE),
// capStore: isValidCap(x.rVal2) && x.origBE == DataMemAccess(unpack(~0)),
// allowCapLoad: getHardPerms(x.rVal1).permitLoadCap && x.origBE == DataMemAccess(unpack(~0)),
// capException: capChecksMem(x.rVal1, x.rVal2, x.cap_checks, x.mem_func, x.origBE),
// check: prepareBoundsCheck(x.rVal1, x.rVal2, almightyCap/*ToDo: pcc*/,
// ddc, getAddr(x.vaddr), accessByteCount, x.cap_checks)
// `ifdef KONATA
// , u_id: x.u_id
// `endif
// },
// specBits: regToExe.spec_bits
// });
// When the DTLB proq request is called
// Could be only 1 at a time but let's assume there are plenty
// We assume there is queue of requests (|,|,|,|), We assume these run while other instructions
// are getting executed (When Proq response is called one by one from the queue responses with
// physical addresses are being executed to be stored or read from memory).
endrule
rule doFinishMem;
// Over here we are reducing the tracing surface area to ensure
// It's easier to write a TLB bypasser.
let regToExe = trollToExeQ.first;
// Let's check if lol access data can be found in the
// the previous stage.
let lol = regToExe.data;
// =============================
// dTlb.deqProcResp;
// let dTlbResp = dTlb.procResp;
// Assumtion instruction related can be passed on
// from the previous stage.
// let tlbresp = dTlbResp.inst;
// let {paddr, expCause, allowCapPTE} = dTlbResp.resp;
// Assuming physcial address is virtual address just for testing
let paddr = getAddr(lol.vaddr);
// These are just assumtions for testing
// let expCause = dTlb.Invalid;
let allowCapPTE = True;
if(verbose) $display("%t : [doFinishMem] ", $time, fshow(regToExe));
// Moved to the next stage
let shiftBE = DataMemAccess(lol.shiftBEData);
if (lol.origBE == TagMemAccess) begin
shiftBE = TagMemAccess;
end
CapPipe ddc = cast(inIfc.scaprf_rd(scrAddrDDC));
// get size of the access
Bit#(TAdd#(CacheUtils::LogCLineNumMemDataBytes,1)) accessByteCount = zeroExtend(pack(countOnes(pack(x.origBE.DataMemAccess))));
if (x.origBE == TagMemAccess) begin
accessByteCount = fromInteger(valueOf(CacheUtils::CLineNumMemDataBytes));
end
// Bit#(TAdd#(CacheUtils::LogCLineNumMemDataBytes,1)) accessByteCount = zeroExtend(pack(countOnes(pack(x.origBE.DataMemAccess))));
// if (x.origBE == TagMemAccess) begin
// accessByteCount = fromInteger(valueOf(CacheUtils::CLineNumMemDataBytes));
// end
`ifdef KONATA
$display("KONATAE\t%0d\t%0d\t0\tMem2", cur_cycle, x.u_id);
$display("KONATAS\t%0d\t%0d\t0\tMem3", cur_cycle, x.u_id);
$fflush;
`endif
// go to next stage by sending to TLB
dTlb.procReq(DTlbReq {
inst: MemExeToFinish {
mem_func: x.mem_func,
tag: x.tag,
ldstq_tag: x.ldstq_tag,
shiftedBE: shiftBE,
vaddr: x.vaddr,
`ifdef INCLUDE_TANDEM_VERIF
store_data: x.rVal2,
store_data_BE: origBE,
`endif
misaligned: memAddrMisaligned(getAddr(x.vaddr), x.origBE),
capStore: isValidCap(x.rVal2) && x.origBE == DataMemAccess(unpack(~0)),
allowCapLoad: getHardPerms(x.rVal1).permitLoadCap && x.origBE == DataMemAccess(unpack(~0)),
capException: capChecksMem(x.rVal1, x.rVal2, x.cap_checks, x.mem_func, x.origBE),
check: prepareBoundsCheck(x.rVal1, x.rVal2, almightyCap/*ToDo: pcc*/,
ddc, getAddr(x.vaddr), accessByteCount, x.cap_checks)
`ifdef KONATA
, u_id: x.u_id
`endif
},
specBits: regToExe.spec_bits
});
endrule
rule doFinishMem;
$display("do finish mem");
// trollToExeQ.deq;
// let regToExe = trollToExeQ.first;
// let lol = regToExe.data;
// =============================
dTlb.deqProcResp;
let dTlbResp = dTlb.procResp;
let x = dTlbResp.inst;
let {paddr, expCause, allowCapPTE} = dTlbResp.resp;
// paddr = getAddr(lol.vaddr);
// expCause = False;
// allowCapPTE = True;
// Capability checks computed early over instead of the previous stage
// This will resolve:
// - .check
// - .capException
// - .allowCapLoad
// - .capStore
// get access byte count
// get size of the access
Bit#(TAdd#(CacheUtils::LogCLineNumMemDataBytes,1)) accessByteCount = zeroExtend(pack(countOnes(pack(lol.origBE.DataMemAccess))));
if (lol.origBE == TagMemAccess) begin
accessByteCount = fromInteger(valueOf(CacheUtils::CLineNumMemDataBytes));
end
let check = prepareBoundsCheck(lol.rVal1, lol.rVal2, almightyCap/*ToDo: pcc*/,ddc, getAddr(lol.vaddr), accessByteCount, lol.cap_checks);
let capException = capChecksMem(lol.rVal1, lol.rVal2, lol.cap_checks, lol.mem_func, lol.origBE);
let allowCapLoad = getHardPerms(lol.rVal1).permitLoadCap && lol.origBE == DataMemAccess(unpack(~0));
// (TODO) Still need to pass the:
// (done) tag
// (done) ldstq_tag
// (done) shiftedBE
Maybe#(Trap) cause = Invalid;
if (expCause matches tagged Valid .c) cause = Valid(Exception(c));
// if (expCause matches tagged Valid .c) cause = Valid(Exception(c));
if(verbose) $display("%t : [doFinishMem] ", $time, fshow(dTlbResp));
if(isValid(cause) && verbose) $display(" [doFinishMem - dTlb response] PAGEFAULT!");
// if(verbose) $display("%t : [doFinishMem] ", $time, fshow(dTlbResp));
$display("Bypassing TLB");
// if(isValid(cause) && verbose) $display(" [doFinishMem - dTlb response] PAGEFAULT!");
Data store_data = ?;
ByteEn store_data_BE = ?;
`ifdef INCLUDE_TANDEM_VERIF
store_data = x.store_data;
store_data_BE = x.store_data_BE;
`endif
// `ifdef INCLUDE_TANDEM_VERIF
// store_data = tlbresp.store_data;
// store_data_BE = tlbresp.store_data_BE;
// `endif
let misaligned = memAddrMisaligned(getAddr(lol.vaddr), lol.origBE);
// check misalignment
if(!isValid(cause) && x.misaligned) begin
case(x.mem_func)
if(!isValid(cause) && misaligned) begin
case(lol.mem_func)
Ld, Lr: begin
cause = Valid(Exception(excLoadAddrMisaligned));
end
@@ -696,25 +760,25 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
endcase
end
`ifdef RVFI_DII
// TestRIG expects us throw an access fault for any memory access outside of a 8 MiB memory at 0x8000000.
if (!isValid(cause) && (paddr < 'h80000000 || paddr >= 'h80800000)) begin
case(x.mem_func)
Ld, Lr: begin
cause = Valid(Exception(excLoadAccessFault));
end
default: begin
cause = Valid(Exception(excStoreAccessFault));
end
endcase
end
`endif
// `ifdef RVFI_DII
// // TestRIG expects us throw an access fault for any memory access outside of a 8 MiB memory at 0x8000000.
// if (!isValid(cause) && (paddr < 'h80000000 || paddr >= 'h80800000)) begin
// case(tlbresp.mem_func)
// Ld, Lr: begin
// cause = Valid(Exception(excLoadAccessFault));
// end
// default: begin
// cause = Valid(Exception(excStoreAccessFault));
// end
// endcase
// end
// `endif
// check if addr is MMIO (only valid in case of no page fault)
Bool isMMIO = inIfc.isMMIOAddr(paddr);
// raise access fault in case of MMIO Lr/Sc
if(!isValid(cause) && isMMIO) begin
case(x.mem_func)
case(lol.mem_func)
Lr: begin
cause = Valid(Exception(excLoadAccessFault));
end
@@ -726,40 +790,42 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
// update ROB (access at commit and non-mmio st done can only be true
// when there is no exceptio)
Bool isLrScAmo = (case(x.mem_func)
Bool isLrScAmo = (case(lol.mem_func)
Lr, Sc, Amo: True;
default: False;
endcase);
if (x.check matches tagged Valid .check &&& x.capException matches tagged Invalid) begin
if (check matches tagged Valid .check &&& capException matches tagged Invalid) begin
if (!( (check.check_low >= check.authority_base) &&
(check.check_inclusive ? (check.check_high <= check.authority_top )
: (check.check_high < check.authority_top ))))
x.capException = Valid(CSR_XCapCause{cheri_exc_reg: check.authority_idx, cheri_exc_code: cheriExcLengthViolation});
capException = Valid(CSR_XCapCause{cheri_exc_reg: check.authority_idx, cheri_exc_code: cheriExcLengthViolation});
end
if (x.capException matches tagged Valid .c) cause = Valid(CapException(c));
if (capException matches tagged Valid .c) cause = Valid(CapException(c));
Bool access_at_commit = !isValid(cause) && (isMMIO || isLrScAmo);
Bool non_mmio_st_done = !isValid(cause) && !isMMIO && x.mem_func == St;
inIfc.rob_setExecuted_doFinishMem(x.tag, getAddr(x.vaddr),
`ifdef INCLUDE_TANDEM_VERIF
store_data, store_data_BE,
`endif
// Bool access_at_commit = True;
Bool non_mmio_st_done = !isValid(cause) && !isMMIO && lol.mem_func == St;
// Bool non_mmio_st_done = !isMMIO && lol.mem_func == St;
inIfc.rob_setExecuted_doFinishMem(lol.tag, getAddr(lol.vaddr),
// `ifdef INCLUDE_TANDEM_VERIF
// store_data, store_data_BE,
// `endif
access_at_commit, non_mmio_st_done
`ifdef RVFI
, ExtraTraceBundle{
regWriteData: memData[pack(x.ldstq_tag)],
memByteEn: unpack(truncate(pack(x.shiftedBE.DataMemAccess) >> getAddr(x.vaddr)[3:0]))
}
`endif
// , ExtraTraceBundle{
// regWriteData: memData[pack(tlbresp.ldstq_tag)],
// memByteEn: unpack(truncate(pack(tlbresp.shiftedBE.DataMemAccess) >> getAddr(tlbresp.vaddr)[3:0]))
// }
// `endif
);
let pc = inIfc.rob_getPC(x.tag);
let pc = inIfc.rob_getPC(lol.tag);
`ifdef PERFORMANCE_MONITORING
`ifdef CONTRACTS_VERIFY
function Bool is_16b_inst (Bit #(n) inst);
return (inst [1:0] != 2'b11);
endfunction
let ppc = inIfc.rob_getPredPC(x.tag);
let inst = inIfc.rob_getOrig_Inst(x.tag);
let ppc = inIfc.rob_getPredPC(lol.tag);
let inst = inIfc.rob_getOrig_Inst(lol.tag);
let validPc = is_16b_inst(inst) ? addPc(pc,2) : addPc(pc,4);
if(cause matches tagged Valid .c &&& (ppc != validPc)) begin
EventsTransExe events_trans = unpack(0);
@@ -769,28 +835,33 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
`endif
`endif
`ifdef KONATA
$display("KONATAE\t%0d\t%0d\t0\tMem3", cur_cycle, x.u_id);
$display("KONATAS\t%0d\t%0d\t0\tMem4", cur_cycle, x.u_id);
$fflush;
`endif
// `ifdef KONATA
// $display("KONATAE\t%0d\t%0d\t0\tMem3", cur_cycle, tlbresp.u_id);
// $display("KONATAS\t%0d\t%0d\t0\tMem4", cur_cycle, tlbresp.u_id);
// $fflush;
// `endif
// Try me!
// if (x.mem_func == St) begin
// paddr = 256;
// end
// update LSQ
// Important bit that updates memory ?
// LSQUpdateAddrResult updRes <- lsq.updateAddr(
// lol.ldstq_tag, cause, allowCapLoad && allowCapPTE, paddr, isMMIO, shiftBE
// );
LSQUpdateAddrResult updRes <- lsq.updateAddr(
x.ldstq_tag, cause, x.allowCapLoad && allowCapPTE, paddr, isMMIO, x.shiftedBE
lol.ldstq_tag, cause, allowCapLoad && allowCapPTE, paddr, isMMIO, shiftBE
);
// issue non-MMIO Ld which has no exception and is not waiting for
// wrong path resp
if (x.mem_func == Ld && !isMMIO &&
if (lol.mem_func == Ld && !isMMIO &&
!isValid(cause) && !updRes.waitWPResp
&& !updRes.delayIssue) begin
LdQTag ldTag = ?;
if(x.ldstq_tag matches tagged Ld .t) begin
if(lol.ldstq_tag matches tagged Ld .t) begin
ldTag = t;
end
else begin
@@ -799,7 +870,7 @@ module mkMemExePipeline#(MemExeInput inIfc)(MemExePipeline);
issueLd.wset(LSQIssueLdInfo {
tag: ldTag,
paddr: paddr,
shiftedBE: x.shiftedBE,
shiftedBE: shiftBE,
pcHash: hash(getAddr(pc))
});
end

View File

@@ -562,7 +562,6 @@ module mkDTlb#(
// bare mode
pendWait[idx] <= None;
pendResp[idx] <= tuple3(r.addr, Invalid, True);
$display("bare mode");
if(verbose) $display("DTLB %m req (bare): ", fshow(r));
end

View File

@@ -1003,7 +1003,6 @@ function DecodeResult decode(Instruction inst, Bool cap_mode);
regs.src1 = Valid(tagged Gpr rs1);
regs.src2 = Valid(tagged Gpr rs2);
dInst.capFunc = CapModify (SetBounds (SetBoundsRounding));
// TODOD Add the delta function under this
end
f7_cap_CSetBoundsExact: begin
legalInst = True;

View File

@@ -218,18 +218,7 @@ function CapPipe specialRWALU(CapPipe cap, CapPipe oldCap, SpecialRWFunc scrType
return res;
endfunction
function Tuple2#(Data, Bool) extractType(CapPipe a)
provisos (
CHERICap::CHERICap#(
CHERICC_Fat::CapPipe, // capT
OTypeW, // otypeW
FlagsW, // flgW
CapAddrW, // addrW
CapW, // inMemW
TSub#(MW,3), // maskableW
Delta // delta
)
);
function Tuple2#(Data, Bool) extractType(CapPipe a);
if (getKind(a) == UNSEALED) return tuple2(otype_unsealed_ext, True);
else if (getKind(a) == SENTRY ) return tuple2(otype_sentry_ext, True);
else if (getKind(a) == RES0 ) return tuple2(otype_res0_ext, True);
@@ -252,7 +241,6 @@ function CapPipe capModify(CapPipe a, CapPipe b, CapModifyFunc func);
new_hard_perms.global = new_hard_perms.global && getHardPerms(b).global;
Bool unsealIllegal = !isValidCap(b) || getKind(b) != UNSEALED || getKind(a) == UNSEALED || a_res || getAddr(b) != a_type || !getHardPerms(b).permitUnseal || !isInBounds(b, False);
Bool buildCapIllegal = !isValidCap(b) || getKind(b) != UNSEALED || !isDerivable(a) || (getPerms(a) & getPerms(b)) != getPerms(a) || getBase(a) < getBase(b) || getTop(a) > getTop(b); // XXX needs optimisation
// TODO: Delta handler function
CapPipe res = (case(func) matches
tagged ModifyOffset .offsetOp :
modifyOffset(a_mut, getAddr(b), offsetOp == IncOffset).value;
@@ -285,9 +273,7 @@ function CapPipe capModify(CapPipe a, CapPipe b, CapModifyFunc func);
tagged FromPtr :
(getAddr(a) == 0 ? nullCap : setAddr(b_mut, getAddr(a)).value);
tagged SetHigh:
//fromMem(tuple2(False, {getAddr(b), getAddr(a)}));
capFromAddrs(a,b);
// getTruncatedTuple(getAddr(b))
fromMem(tuple2(False, {getAddr(b), getAddr(a)}));
tagged BuildCap :
setKind(setValidCap(a_mut, !buildCapIllegal), getKind(a)==SENTRY ? SENTRY : UNSEALED);
tagged Move :
@@ -299,39 +285,6 @@ function CapPipe capModify(CapPipe a, CapPipe b, CapModifyFunc func);
return res;
endfunction
// function CapPipe capFromAddrs (CapPipe a, CapPipe b)
// provisos (
// CHERICap#(CapPipe, o, f, addrW, CapW, m, d)
// );
// // Get full serialized capability of 'a'
// match {.tag, .rawA} = toMem(a); // rawA : Bit#(inMemW)
// // Replace low addrW bits with address from b
// Bit#(addrW) newAddr = getAddr(b);
// Bit#(inMemW) newRaw =
// { rawA[CapW-1 : addrW] // keep upper metadata
// , newAddr // replace address field
// };
// return fromMem(tuple2(tag, newRaw));
// endfunction
function CapPipe capFromAddrs(capT a, capT b)
provisos (CHERICap#(capT, a, b, 64, d, e, f)); // exact instance
// Extract addresses
Bit#(64) addrA = getAddr(a);
Bit#(64) addrB = getAddr(b);
// Extra bits to reach inMemW = 180
Bit#(52) extra = 0; // can be zeros or delta bits if needed
// Concatenate explicitly typed
Bit#(180) rawBits = {addrB, addrA, extra};
return fromMem(tuple2(False, rawBits));
endfunction
(* noinline *)
function Data capInspect(CapPipe a, CapPipe b, CapInspectFunc func);
Data res = (case(func) matches
@@ -370,17 +323,6 @@ function Data capInspect(CapPipe a, CapPipe b, CapInspectFunc func);
return res;
endfunction
// function CapPipe getTruncatedTuple(AddrType a, AddrType b)
// provisos (
// Add#(a__, b__, 180) // Defines that a__ + b__ must equal 180
// );
// // Use a list literal or a Tuple constructor
// let address_bits = { getAddr(b), getAddr(a) };
// return fromMem(tuple2(False, address_bits));
// endfunction
function CapPipe capALU(CapPipe a, CapPipe b, CapFunc func);
CapPipe res = (case (func) matches
tagged CapInspect .x:

View File

@@ -310,7 +310,7 @@ typedef enum {
} ModifyOffsetFunc deriving(Bits, Eq, FShow);
typedef enum {
SetBoundsExact, SetBoundsRounding, CRRL, CRAM, SetDelta
SetBoundsExact, SetBoundsRounding, CRRL, CRAM
} SetBoundsFunc deriving(Bits, Eq, FShow);
typedef enum {
@@ -336,8 +336,6 @@ typedef enum {
typedef union tagged {
ModifyOffsetFunc ModifyOffset;
SetBoundsFunc SetBounds;
// TODOD: Delta add type here
// SetDeltaFunc SetDelta;
SpecialRWFunc SpecialRW;
AddrSource SetAddr;
void Seal;
@@ -1070,7 +1068,7 @@ function Fmt showInst(Instruction inst);
return ret;
endfunction
function x addPc(x cap, Bit#(12) inc) provisos (Add#(f, 12, c), CHERICap::CHERICap#(x, a, b, c, d, e, f)) = setAddrUnsafe(cap, getAddr(cap) + signExtend(inc));
function x addPc(x cap, Bit#(12) inc) provisos (Add#(f, 12, c), CHERICap::CHERICap#(x, a, b, c, d, e)) = setAddrUnsafe(cap, getAddr(cap) + signExtend(inc));
`ifdef PERFORMANCE_MONITORING
typedef 8 Report_Width;

View File

@@ -49,11 +49,6 @@ import RVFI_DII_Types::*;
typedef 64 AddrSz;
typedef Bit#(AddrSz) Addr;
// typedef struct {
// Vector#(2, Data) data;
// Bit#(52) padding;
// } MemData deriving (Bits);
typedef 64 DataSz;
typedef Bit#(DataSz) Data;
typedef TDiv#(DataSz, 8) DataBytes;
@@ -65,7 +60,6 @@ typedef struct {
function tag_t getTag(TaggedData#(tag_t, data_t) td) = td.tag;
function data_t getData(TaggedData#(tag_t, data_t) td) = td.data;
typedef Vector#(2, Data) MemData;
// typedef Bit#(180) MemData;
typedef Bool MemTag;
typedef SizeOf#(MemData) MemDataSz;
typedef TDiv#(MemDataSz, 8) MemDataBytes;

12
test.txt Normal file
View File

@@ -0,0 +1,12 @@
Let me know if this message works well on behalf of all of us.
Hi Jan,
This is a very small gesture from Jose, Mathews, Yukang and Akilan. We have transferred 200 pounds equally contributed by all of us. As you are moving in and settling into your new place, we hope this can help you and Samantha cover certain expenses like buying furniture or for your very efficient interrail travel pass in the near future.
We will definetely miss the german embassy in Slatefort. Happy new year in advance from all of us!
Regards,
Jose, Mathews, Yukang and Akilan
(Your UK representation of transportation
reform)