-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
45,871 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
build*/ | ||
/*venv*/ | ||
*venv*/ | ||
|
||
*.bin | ||
*.elf | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from elftools.elf.elffile import ELFFile | ||
from elftools.elf.sections import SymbolTableSection | ||
import os | ||
|
||
def parse_test_elf(file): | ||
with open(file, "rb") as f: | ||
elf = ELFFile(f) | ||
# Enumerate the SymbolTableSection | ||
for section in elf.iter_sections(): | ||
if isinstance(section, SymbolTableSection): | ||
for i in range(section.num_symbols()): | ||
symbol = section.get_symbol(i) | ||
if symbol.name: | ||
if symbol.name.startswith("test_"): | ||
address = symbol.entry.st_value | ||
# Convert address to file offset | ||
offset = list(elf.address_offsets(address))[0] | ||
return address, offset | ||
return None, None | ||
|
||
|
||
def main(): | ||
code = "#pragma once\n\n" | ||
code += "#include <stdint.h>\n\n" | ||
tests = [] | ||
directory = "isa-tests" | ||
for file in sorted(os.listdir(directory)): | ||
if file.startswith("rv64") and not file.endswith(".dump"): | ||
path = os.path.join(directory, file) | ||
address, offset = parse_test_elf(path) | ||
if offset is None: | ||
print(f"Failed to parse {file}") | ||
continue | ||
data = f"uint8_t {file.replace('-', '_')}_data[] = {{\n" | ||
with open(path, "rb") as f: | ||
# print the bytes in hex with max 32 bytes per line | ||
for i, byte in enumerate(f.read()): | ||
data += f"0x{byte:02x}, " | ||
if i % 16 == 15: | ||
data += "\n" | ||
data += "\n};\n" | ||
code += data | ||
tests.append((file, address, offset)) | ||
|
||
code += "\n" | ||
code += "struct Test {\n" | ||
code += " const char* name;\n" | ||
code += " uint8_t* data;\n" | ||
code += " uint64_t size;\n" | ||
code += " uint64_t address;\n" | ||
code += " uint64_t offset;\n" | ||
code += "};\n\n" | ||
|
||
code += "static Test tests[] = {\n" | ||
for name, address, offset in tests: | ||
variable = f"{name.replace('-', '_')}_data" | ||
code += f" {{ \"{name}\", {variable}, sizeof({variable}), {hex(address)}, {hex(offset)} }},\n" | ||
code += "\n};\n" | ||
|
||
with open("isa-tests/data.h", "wb") as f: | ||
f.write(code.encode("utf-8")) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Compiled from https://github.com/riscv-software-src/riscv-tests |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <cstring> | ||
#include <cstddef> | ||
#include <cstdlib> | ||
|
||
#include "riscvm.h" | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc < 2) | ||
{ | ||
log("please supply a RV64I program to run!\n"); | ||
return EXIT_FAILURE; | ||
} | ||
riscvm_ptr machine = (riscvm_ptr)malloc(sizeof(riscvm)); | ||
memset(machine, 0, sizeof(riscvm)); | ||
riscvm_loadfile(machine, argv[1]); | ||
|
||
#ifdef _DEBUG | ||
g_trace = argc > 2 && _stricmp(argv[2], "--trace") == 0; | ||
if (g_trace) | ||
{ | ||
// TODO: allow custom trace file location/name | ||
machine->trace = fopen("trace.txt", "w"); | ||
} | ||
#endif // _DEBUG | ||
|
||
riscvm_run(machine); | ||
exit((int)machine->regs[reg_a0]); | ||
|
||
#ifdef _DEBUG | ||
if (g_trace) | ||
{ | ||
fclose(machine->trace); | ||
} | ||
#endif // _DEBUG | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <cstddef> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include "riscvm.h" | ||
#include "isa-tests/data.h" | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
std::vector<const char*> filter; | ||
for (int i = 1; i < argc; i++) | ||
{ | ||
filter.push_back(argv[i]); | ||
} | ||
auto total = 0; | ||
auto successful = 0; | ||
for (const auto& test : tests) | ||
{ | ||
if (!filter.empty()) | ||
{ | ||
auto allowed = false; | ||
for (const auto& white : filter) | ||
{ | ||
if (strcmp(test.name, white) == 0) | ||
{ | ||
allowed = true; | ||
break; | ||
} | ||
} | ||
if (!allowed) | ||
continue; | ||
} | ||
|
||
printf("[%s] ", test.name); | ||
if (test.size > sizeof(g_code)) | ||
{ | ||
printf("ERROR (too big)\n", test.name); | ||
continue; | ||
} | ||
total++; | ||
|
||
memset(g_code, 0, sizeof(g_code)); | ||
memcpy(g_code, test.data, test.size); | ||
riscvm vm = {}; | ||
auto self = &vm; | ||
reg_write(reg_sp, (uint64_t)&g_stack[sizeof(g_stack) - 0x10]); | ||
self->pc = (int64_t)g_code + test.offset; | ||
#ifdef _DEBUG | ||
g_trace = true; | ||
char tracename[256] = ""; | ||
sprintf(tracename, "%s.trace", test.name); | ||
self->trace = fopen(tracename, "w"); | ||
self->rebase = -self->pc + test.address; | ||
#endif // _DEBUG | ||
riscvm_run(self); | ||
#ifdef _DEBUG | ||
fclose(self->trace); | ||
#endif // _DEBUG | ||
auto status = (int)reg_read(reg_a0); | ||
if (status != 0) | ||
{ | ||
printf("FAILURE (status: %d)\n", status); | ||
} | ||
else | ||
{ | ||
successful++; | ||
printf("SUCCESS\n"); | ||
} | ||
} | ||
printf("\n%d/%d tests successful (%.2f%%)\n", successful, total, successful * 1.0f / total * 100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters