-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing callbacks in sail-riscv for state-changing events #494
Open
kseniadobrovolskaya
wants to merge
3
commits into
riscv:master
Choose a base branch
from
kseniadobrovolskaya:Callbacks_for_state-changing_events
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
08ee058
Implementing callbacks in sail-riscv for state-changing events
kseniadobrovolskaya ffc1318
Added implementation of callbacks for trace printing in riscv_default…
kseniadobrovolskaya 232e5bd
Added implementations of default callbacks for trace printing in risc…
kseniadobrovolskaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -225,7 +225,7 @@ c_preserve_fns=-c_preserve _set_Misa_C | |
|
||
generated_definitions/c/riscv_model_$(ARCH).c: $(SAIL_SRCS) model/main.sail Makefile | ||
mkdir -p generated_definitions/c | ||
$(SAIL) $(SAIL_FLAGS) $(c_preserve_fns) -O -Oconstant_fold -memo_z3 -c -c_include riscv_prelude.h -c_include riscv_platform.h -c_no_main $(SAIL_SRCS) model/main.sail -o $(basename $@) | ||
$(SAIL) $(SAIL_FLAGS) $(c_preserve_fns) -O -Oconstant_fold -memo_z3 -c -c_include riscv_prelude.h -c_include riscv_platform.h -c_no_main $(SAIL_SRCS) -c_include riscv_default_callbacks.c model/main.sail -o $(basename $@) | ||
|
||
generated_definitions/c2/riscv_model_$(ARCH).c: $(SAIL_SRCS) model/main.sail Makefile | ||
mkdir -p generated_definitions/c2 | ||
|
@@ -255,13 +255,17 @@ rvfi_preserve_fns=-c_preserve rvfi_set_instr_packet \ | |
-c_preserve rvfi_get_int_data \ | ||
-c_preserve rvfi_zero_exec_packet \ | ||
-c_preserve rvfi_halt_exec_packet \ | ||
-c_preserve rvfi_write \ | ||
-c_preserve rvfi_read \ | ||
-c_preserve rvfi_mem_exception \ | ||
-c_preserve rvfi_wX \ | ||
-c_preserve print_instr_packet \ | ||
-c_preserve print_rvfi_exec | ||
|
||
# sed -i isn't posix compliant, unfortunately | ||
generated_definitions/c/riscv_rvfi_model_$(ARCH).c: $(SAIL_RVFI_SRCS) model/main.sail Makefile | ||
mkdir -p generated_definitions/c | ||
$(SAIL) $(c_preserve_fns) $(rvfi_preserve_fns) $(SAIL_FLAGS) -O -Oconstant_fold -memo_z3 -c -c_include riscv_prelude.h -c_include riscv_platform.h -c_no_main $(SAIL_RVFI_SRCS) model/main.sail -o $(basename $@) | ||
$(SAIL) $(c_preserve_fns) $(rvfi_preserve_fns) $(SAIL_FLAGS) -O -Oconstant_fold -memo_z3 -c -c_include riscv_prelude.h -c_include riscv_platform.h -c_no_main $(SAIL_RVFI_SRCS) -c_include riscv_rvfi_callbacks.c model/main.sail -o $(basename $@) | ||
sed -e '/^[[:space:]]*$$/d' $@ > [email protected] | ||
mv [email protected] $@ | ||
|
||
|
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,91 @@ | ||
#include "riscv_config.h" | ||
#include <stdlib.h> | ||
|
||
void zcsr_name_map_forwards(sail_string *rop, uint64_t); | ||
|
||
static uint8_t *get_lbits_data(lbits val) | ||
{ | ||
uint8_t *data = (uint8_t *)calloc(val.len, sizeof(uint8_t)); | ||
mpz_export(data, NULL, -1, 1, 0, 0, val.bits); | ||
return data; | ||
} | ||
|
||
/* Implementations of default callbacks for trace printing. | ||
* | ||
* The model assumes that these functions do not change the state of the model. | ||
*/ | ||
int mem_write_callback(uint64_t addr, uint64_t width, lbits value) | ||
{ | ||
if (config_print_mem_access) { | ||
char *lbits_data = get_lbits_data(value); | ||
printf("mem[0x%.16lX] <- 0x", addr); | ||
for (int i = width - 1; i >= 0; --i) | ||
printf("%02hhX", lbits_data[i]); | ||
printf("\n"); | ||
free(lbits_data); | ||
} | ||
} | ||
|
||
int mem_read_callback(const char *type, uint64_t addr, uint64_t width, | ||
lbits value) | ||
{ | ||
if (config_print_mem_access) { | ||
char *lbits_data = get_lbits_data(value); | ||
printf("mem[%s,0x%.16lX] -> 0x", type, addr); | ||
for (int i = width - 1; i >= 0; --i) | ||
printf("%02hhX", lbits_data[i]); | ||
printf("\n"); | ||
free(lbits_data); | ||
} | ||
} | ||
|
||
int mem_exception_callback(uint64_t addr, uint64_t num_of_exception) { } | ||
|
||
int xreg_write_callback(unsigned reg, uint64_t value) | ||
{ | ||
if (config_print_reg) | ||
printf("x%d <- 0x%.16lX\n", reg, value); | ||
} | ||
|
||
int freg_write_callback(unsigned reg, uint64_t value) | ||
{ | ||
/* TODO: will only print bits; should we print in floating point format? */ | ||
if (config_print_reg) | ||
printf("f%d <- 0x%.16lX\n", reg, value); | ||
} | ||
|
||
int csr_write_callback(unsigned reg, uint64_t value) | ||
{ | ||
if (config_print_reg) { | ||
sail_string csr_name; | ||
CREATE(sail_string)(&csr_name); | ||
zcsr_name_map_forwards(&csr_name, reg); | ||
printf("CSR %s <- 0x%.16lX (input: 0x%.16lX)\n", csr_name, value, value); | ||
KILL(sail_string)(&csr_name); | ||
} | ||
} | ||
|
||
int csr_read_callback(unsigned reg, uint64_t value) | ||
{ | ||
if (config_print_reg) { | ||
sail_string csr_name; | ||
CREATE(sail_string)(&csr_name); | ||
zcsr_name_map_forwards(&csr_name, reg); | ||
printf("CSR %s -> 0x%.16lX\n", csr_name, value); | ||
KILL(sail_string)(&csr_name); | ||
} | ||
} | ||
|
||
int vreg_write_callback(unsigned reg, lbits value) | ||
{ | ||
if (config_print_reg) { | ||
char *lbits_data = get_lbits_data(value); | ||
printf("v%d <- ", reg); | ||
for (int i = value.len - 1; i >= 0; --i) | ||
printf("%02hhX", lbits_data[i]); | ||
printf("\n"); | ||
free(lbits_data); | ||
} | ||
} | ||
|
||
int pc_write_callback(uint64_t value) { } |
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,38 @@ | ||
#include "riscv_config.h" | ||
|
||
int zrvfi_write(uint64_t addr, int64_t width, lbits value); | ||
int zrvfi_read(uint64_t addr, sail_int width, lbits value); | ||
int zrvfi_mem_exception(uint64_t addr); | ||
int zrvfi_wX(int64_t reg, uint64_t value); | ||
|
||
int mem_write_callback(uint64_t addr, uint64_t width, lbits value) | ||
{ | ||
if (rv_enable_callbacks) | ||
zrvfi_write(addr, width, value); | ||
} | ||
int mem_read_callback(const char *type, uint64_t addr, uint64_t width, | ||
lbits value) | ||
{ | ||
if (rv_enable_callbacks) { | ||
sail_int len; | ||
CREATE(sail_int)(&len); | ||
CONVERT_OF(sail_int, mach_int)(&len, width); | ||
zrvfi_read(addr, len, value); | ||
KILL(sail_int)(&len); | ||
} | ||
} | ||
int mem_exception_callback(uint64_t addr, uint64_t num_of_exception) | ||
{ | ||
if (rv_enable_callbacks) | ||
zrvfi_mem_exception(addr); | ||
} | ||
int xreg_write_callback(unsigned reg, uint64_t value) | ||
{ | ||
if (rv_enable_callbacks) | ||
zrvfi_wX(reg, value); | ||
} | ||
int freg_write_callback(unsigned reg, uint64_t value) { } | ||
int csr_write_callback(unsigned reg, uint64_t value) { } | ||
int csr_read_callback(unsigned reg, uint64_t value) { } | ||
int vreg_write_callback(unsigned reg, lbits value) { } | ||
int pc_write_callback(uint64_t value) { } |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default callback needs to print the register otherwise this removes tracing capabilities from the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an implementation of the callbacks for trace printing to the
riscv_types.sail
,riscv_csr_begin.sail
,riscv_vreg_type.sail
and call them from the default callbacks in theriscv_default_callbacks.c
.