-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added implementations of default callbacks for trace printing in risc…
…v_default_callbacks.c
- Loading branch information
1 parent
7dcbd56
commit acbdacc
Showing
5 changed files
with
53 additions
and
75 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
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,54 +1,85 @@ | ||
#include "riscv_config.h" | ||
#include <stdlib.h> | ||
|
||
int zmem_write_callback_default(long unsigned int addr, long int width, lbits value); | ||
int zmem_read_callback_default(const char *type, long unsigned int addr, | ||
long int width, lbits value); | ||
int zxreg_write_callback_default(long unsigned int reg, long unsigned int value); | ||
int zfreg_write_callback_default(long unsigned int reg, long unsigned int value); | ||
int zcsr_write_callback_default(long unsigned int reg, long unsigned int value); | ||
int zcsr_read_callback_default(long unsigned int reg, long unsigned int value); | ||
int zvreg_write_callback_default(long unsigned int reg, lbits value); | ||
|
||
/* The model assumes that these functions do not change the state of the model. | ||
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) | ||
zmem_write_callback_default(addr, width, value); | ||
if (config_print_mem_access) { | ||
char *lbits_data = get_lbits_data(value); | ||
printf("mem[0x%lX] <- 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) | ||
zmem_read_callback_default(type, addr, width, value); | ||
if (config_print_mem_access) { | ||
char *lbits_data = get_lbits_data(value); | ||
printf("mem[%s,0x%lX] -> 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) | ||
zxreg_write_callback_default(reg, value); | ||
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) | ||
zfreg_write_callback_default(reg, value); | ||
printf("f%d <- 0x%.16lX\n", reg, value); | ||
} | ||
|
||
int csr_write_callback(unsigned reg, uint64_t value) { | ||
if (config_print_reg) | ||
zcsr_write_callback_default(reg, 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) | ||
zcsr_read_callback_default(reg, 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%lX\n", csr_name, value); | ||
KILL(sail_string)(&csr_name); | ||
} | ||
} | ||
|
||
int vreg_write_callback(unsigned reg, lbits value) { | ||
if (config_print_reg) | ||
zvreg_write_callback_default(reg, 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
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