|
1 | 1 | #include "riscv_config.h" |
| 2 | +#include <stdlib.h> |
2 | 3 |
|
3 | | -int zmem_write_callback_default(long unsigned int addr, long int width, lbits value); |
4 | | -int zmem_read_callback_default(const char *type, long unsigned int addr, |
5 | | - long int width, lbits value); |
6 | | -int zxreg_write_callback_default(long unsigned int reg, long unsigned int value); |
7 | | -int zfreg_write_callback_default(long unsigned int reg, long unsigned int value); |
8 | | -int zcsr_write_callback_default(long unsigned int reg, long unsigned int value); |
9 | | -int zcsr_read_callback_default(long unsigned int reg, long unsigned int value); |
10 | | -int zvreg_write_callback_default(long unsigned int reg, lbits value); |
| 4 | +void zcsr_name_map_forwards(sail_string *rop, uint64_t); |
11 | 5 |
|
12 | | -/* The model assumes that these functions do not change the state of the model. |
| 6 | +static uint8_t *get_lbits_data(lbits val) |
| 7 | +{ |
| 8 | + uint8_t *data = (uint8_t *)calloc(val.len, sizeof(uint8_t)); |
| 9 | + mpz_export(data, NULL, -1, 1, 0, 0, val.bits); |
| 10 | + return data; |
| 11 | +} |
| 12 | + |
| 13 | +/* Implementations of default callbacks for trace printing. |
| 14 | + * |
| 15 | + * The model assumes that these functions do not change the state of the model. |
13 | 16 | */ |
14 | | -int mem_write_callback(uint64_t addr, uint64_t width, lbits value) { |
15 | | - if (config_print_mem_access) |
16 | | - zmem_write_callback_default(addr, width, value); |
| 17 | +int mem_write_callback(uint64_t addr, uint64_t width, lbits value) |
| 18 | +{ |
| 19 | + if (config_print_mem_access) { |
| 20 | + char *lbits_data = get_lbits_data(value); |
| 21 | + printf("mem[0x%.16lX] <- 0x", addr); |
| 22 | + for (int i = width - 1; i >= 0; --i) |
| 23 | + printf("%02hhX", lbits_data[i]); |
| 24 | + printf("\n"); |
| 25 | + free(lbits_data); |
| 26 | + } |
17 | 27 | } |
18 | 28 |
|
19 | 29 | int mem_read_callback(const char *type, uint64_t addr, uint64_t width, |
20 | 30 | lbits value) |
21 | 31 | { |
22 | | - if (config_print_mem_access) |
23 | | - zmem_read_callback_default(type, addr, width, value); |
| 32 | + if (config_print_mem_access) { |
| 33 | + char *lbits_data = get_lbits_data(value); |
| 34 | + printf("mem[%s,0x%.16lX] -> 0x", type, addr); |
| 35 | + for (int i = width - 1; i >= 0; --i) |
| 36 | + printf("%02hhX", lbits_data[i]); |
| 37 | + printf("\n"); |
| 38 | + free(lbits_data); |
| 39 | + } |
24 | 40 | } |
25 | 41 |
|
26 | 42 | int mem_exception_callback(uint64_t addr, uint64_t num_of_exception) { } |
27 | 43 |
|
28 | | -int xreg_write_callback(unsigned reg, uint64_t value) { |
| 44 | +int xreg_write_callback(unsigned reg, uint64_t value) |
| 45 | +{ |
29 | 46 | if (config_print_reg) |
30 | | - zxreg_write_callback_default(reg, value); |
| 47 | + printf("x%d <- 0x%.16lX\n", reg, value); |
31 | 48 | } |
32 | 49 |
|
33 | | -int freg_write_callback(unsigned reg, uint64_t value) { |
| 50 | +int freg_write_callback(unsigned reg, uint64_t value) |
| 51 | +{ |
34 | 52 | /* TODO: will only print bits; should we print in floating point format? */ |
35 | 53 | if (config_print_reg) |
36 | | - zfreg_write_callback_default(reg, value); |
| 54 | + printf("f%d <- 0x%.16lX\n", reg, value); |
37 | 55 | } |
38 | 56 |
|
39 | | -int csr_write_callback(unsigned reg, uint64_t value) { |
40 | | - if (config_print_reg) |
41 | | - zcsr_write_callback_default(reg, value); |
| 57 | +int csr_write_callback(unsigned reg, uint64_t value) |
| 58 | +{ |
| 59 | + if (config_print_reg) { |
| 60 | + sail_string csr_name; |
| 61 | + CREATE(sail_string)(&csr_name); |
| 62 | + zcsr_name_map_forwards(&csr_name, reg); |
| 63 | + printf("CSR %s <- 0x%.16lX (input: 0x%.16lX)\n", csr_name, value, value); |
| 64 | + KILL(sail_string)(&csr_name); |
| 65 | + } |
42 | 66 | } |
43 | 67 |
|
44 | | -int csr_read_callback(unsigned reg, uint64_t value) { |
45 | | - if (config_print_reg) |
46 | | - zcsr_read_callback_default(reg, value); |
| 68 | +int csr_read_callback(unsigned reg, uint64_t value) |
| 69 | +{ |
| 70 | + if (config_print_reg) { |
| 71 | + sail_string csr_name; |
| 72 | + CREATE(sail_string)(&csr_name); |
| 73 | + zcsr_name_map_forwards(&csr_name, reg); |
| 74 | + printf("CSR %s -> 0x%.16lX\n", csr_name, value); |
| 75 | + KILL(sail_string)(&csr_name); |
| 76 | + } |
47 | 77 | } |
48 | 78 |
|
49 | | -int vreg_write_callback(unsigned reg, lbits value) { |
50 | | - if (config_print_reg) |
51 | | - zvreg_write_callback_default(reg, value); |
| 79 | +int vreg_write_callback(unsigned reg, lbits value) |
| 80 | +{ |
| 81 | + if (config_print_reg) { |
| 82 | + char *lbits_data = get_lbits_data(value); |
| 83 | + printf("v%d <- ", reg); |
| 84 | + for (int i = value.len - 1; i >= 0; --i) |
| 85 | + printf("%02hhX", lbits_data[i]); |
| 86 | + printf("\n"); |
| 87 | + free(lbits_data); |
| 88 | + } |
52 | 89 | } |
53 | 90 |
|
54 | 91 | int pc_write_callback(uint64_t value) { } |
0 commit comments