Skip to content

Commit

Permalink
stdout formating changes for messages. clean-up. nearly ready (ready?…
Browse files Browse the repository at this point in the history
…) for a pull-request?
  • Loading branch information
billmcspadden-riscv committed Aug 15, 2022
1 parent 260e497 commit 516c906
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 55 deletions.
12 changes: 6 additions & 6 deletions c_emulator/riscv_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ char *sailcov_file = NULL;
#endif

static struct option options[] = {
{"mtval-has-illegal-inst-bits", no_argument, 0, 'i'},
// {"mtval-has-illegal-inst-bits", no_argument, 0, 'i'},
{"device-tree-blob", required_argument, 0, 'b'},
{"terminal-log", required_argument, 0, 't'},
{"show-times", required_argument, 0, 'p'},
Expand Down Expand Up @@ -219,7 +219,7 @@ char *process_args(int argc, char **argv)
c = getopt_long(argc, argv,
"a"
"I"
"i"
// "i"
"s"
"p"
"b:"
Expand Down Expand Up @@ -257,10 +257,10 @@ char *process_args(int argc, char **argv)
case 'a':
report_arch();
break;
case 'i':
fprintf(stderr, "enabling storing illegal instruction bits in mtval.\n");
rv_mtval_has_illegal_inst_bits = true;
break;
// case 'i':
// fprintf(stderr, "enabling storing illegal instruction bits in mtval.\n");
// rv_mtval_has_illegal_inst_bits = true;
// break;
case 's':
do_dump_dts = true;
break;
Expand Down
65 changes: 29 additions & 36 deletions c_emulator/rv_cfg_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ============================================================================
// Filename: rv_cfg_func.c
//
// Description: Functions to be called by Sail to get values from a yaml file.
// Description: Functions to be called by Sail and C to get values from a yaml file.
//
// Author(s): Bill McSpadden ([email protected])
//
Expand Down Expand Up @@ -71,37 +71,40 @@ rv_cfg_c_configure(void)
rv_enable_dirty_update = rv_cfg_c_ext_enable(RV_ISA, "Ssptead"); //TODO: Use this, ....
//rv_enable_dirty_update = rv_cfg_c_bool_c("/hart0/pte_dirty_update_enable"); // .... not this

rv_enable_misaligned = rv_cfg_c_bool("/hart0/hw_data_misaligned_support");
rv_enable_misaligned = rv_cfg_c_bool("/hart0/hw_data_misaligned_support");

rv_enable_pmp = (
(rv_cfg_c_bool("/hart0/pmpaddr0/rv32/accessible") ) ||
(rv_cfg_c_bool("/hart0/pmpaddr0/rv64/accessible") )
) ;
rv_enable_pmp = (
(rv_cfg_c_bool("/hart0/pmpaddr0/rv32/accessible") ) ||
(rv_cfg_c_bool("/hart0/pmpaddr0/rv64/accessible") )
) ;

rv_ram_size = rv_cfg_c_int("/ram_size") << 20; // Convert to MBs
rv_reset_address = rv_cfg_c_int("/reset/address");
rv_ram_size = rv_cfg_c_int("/ram_size") << 20; // Convert to MBs
rv_reset_address = rv_cfg_c_int("/reset/address");

rv_enable_writable_misa = rv_cfg_c_path_exists("/hart0/misa/rv32/extensions/type/warl");
rv_enable_writable_misa = rv_cfg_c_path_exists("/hart0/misa/rv32/extensions/type/warl");
rv_mtval_has_illegal_inst_bits = rv_cfg_c_bool("/hart0/mtval/has_illegal_inst_bits");

// ====================================================================
// Print out the configuration that you just pulled out from the
// RISCV-Config files. Print it out in terms of the Golden Model
// variables that are used in Sail.
//#define CFG_STRING_FMT "%-32s"
#define CFG_STRING_FMT "%-48s"
// printf("%s: '%s'\n", "RV_ISA: ", RV_ISA);
// printf("%-48s '%s'\n", "RV_ISA: ", RV_ISA);
printf(CFG_STRING_FMT "'%s'\n", "RV_ISA: ", RV_ISA);
printf(CFG_STRING_FMT "%s\n", "C ext support (rv_enable_rvc): " , rv_enable_rvc ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "F/D ext support (rv_enable_fdext):", rv_enable_fdext ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "N ext support (rv_enable_next): ", rv_enable_next ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "Zfinx ext support (rv_enable_zfinx): ", rv_enable_zfinx ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "enable misaligned support (rv_enable_misaligned): ", rv_enable_misaligned ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "enable pmp support (rv_enable_pmp): ", rv_enable_pmp ? "true" : "false");
printf(CFG_STRING_FMT "%ld MB\n", "ram size (rv_ram_size): ", rv_ram_size >> 20);
printf(CFG_STRING_FMT "0x%lx\n", "reset address (rv_reset_address, zPC): ", rv_reset_address);
printf(CFG_STRING_FMT "%s\n", "PTE dirty update enable (rv_enable_dirty_update): ", rv_enable_dirty_update ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "writable misa (rv_enable_writable_misa): ", rv_enable_writable_misa ? "true" : "false");
#define CFG_STRING_FMT "%-56s"
printf("=================================================================================\n");
printf("Start: RISC-V Golden Model configuration values.....\n");
printf(CFG_STRING_FMT "'%s'\n", "RV_ISA: ", RV_ISA);
printf(CFG_STRING_FMT "%s\n", "C ext support (rv_enable_rvc): " , rv_enable_rvc ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "F/D ext support (rv_enable_fdext):", rv_enable_fdext ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "N ext support (rv_enable_next): ", rv_enable_next ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "Zfinx ext support (rv_enable_zfinx): ", rv_enable_zfinx ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "enable misaligned support (rv_enable_misaligned): ", rv_enable_misaligned ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "enable pmp support (rv_enable_pmp): ", rv_enable_pmp ? "true" : "false");
printf(CFG_STRING_FMT "%ld MB\n", "ram size (rv_ram_size): ", rv_ram_size >> 20);
printf(CFG_STRING_FMT "0x%lx\n", "reset address (rv_reset_address, zPC): ", rv_reset_address);
printf(CFG_STRING_FMT "%s\n", "PTE dirty update enable (rv_enable_dirty_update): ", rv_enable_dirty_update ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "writable misa (rv_enable_writable_misa): ", rv_enable_writable_misa ? "true" : "false");
printf(CFG_STRING_FMT "%s\n", "mtval: illegal inst (rv_mtval_has_illegal_inst_bits): ", rv_mtval_has_illegal_inst_bits ? "true" : "false");
printf("End: RISC-V Golden Model configuration values.....\n");
printf("=================================================================================\n");

// ====================================
// Error checking of configuration.
Expand Down Expand Up @@ -249,9 +252,7 @@ rv_cfg_c_ext_enable(char * isa_str, char * ext_pattern)
match_data, /* block for storing the result */
NULL); /* use default match context */

// printf("%s, %d: rc: %d\n", __FILE__, __LINE__, rc);

if ((rc == 0) || (rc == -1))
if ((rc == 0) || (rc == -1)) // Does not match
{
return(0);
}
Expand All @@ -265,8 +266,6 @@ rv_cfg_c_ext_enable(char * isa_str, char * ext_pattern)
__FILE__, __LINE__, rc, ext_pattern, isa_str);
exit(1);
}


}

// ============================================================================
Expand Down Expand Up @@ -352,8 +351,6 @@ rv_cfg_c_int(char * key_str)
if (count == 1)
{
free(tmp_str);
printf("%s, %d: value found, 0x%x, in %s\n", __FILE__, __LINE__, yaml_val_int, rv_cfg_enum2doc_a[i].filename);
//fy_emit_document_to_fp(fyd, FYECF_DEFAULT | FYECF_SORT_KEYS, stdout);
return(yaml_val_int);
}
free(tmp_str);
Expand Down Expand Up @@ -399,11 +396,8 @@ rv_cfg_c_string(char * key_str)
if (count == 1)
{
free(tmp_str);
printf("%s, %d: value found, '%s', in %s\n", __FILE__, __LINE__, yaml_val_string, rv_cfg_enum2doc_a[i].filename);
ret_str_ptr = malloc(strlen(yaml_val_string)); // TODO: where should this be freed?
strcpy(ret_str_ptr, yaml_val_string);
// ret_str_ptr = yaml_val_string;
//fy_emit_document_to_fp(fyd, FYECF_DEFAULT | FYECF_SORT_KEYS, stdout);
return(ret_str_ptr);
}
free(tmp_str);
Expand Down Expand Up @@ -449,8 +443,7 @@ rv_cfg_s_string(sail_string s, char * yaml_key_str)
return(1);
}



// ============================================================================
unit
rv_cfg_s_dump_yaml(char *yaml_filename)
{
Expand Down
21 changes: 10 additions & 11 deletions c_emulator/rv_cfg_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>


// ==================================================
// Function prototypes just for the C side of things.
// The items in this section should only be used on
// the C side of the simulator.
// typedefs and structs

// Keep these in linear order as they are used as indices
// into an array where the index is the enum.
// Keep these in monotonically increasing linear order
// as they are used as indices into an array where the
// index is the enum.
typedef enum
{
RV_CFG_ISA = 0,
Expand All @@ -51,6 +49,11 @@ typedef struct rv_cfg_enum2doc_tt
char * filename;
} rv_cfg_enum2doc_t;

// ==================================================
// Function prototypes just for the C side of things.
// The items in this section should only be used on
// the C side of the simulator.

int rv_cfg_c_init(void);
char * rv_cfg_c_get_string(rv_cfg_e e);
rv_cfg_e rv_cfg_c_get_enum(char * s);
Expand All @@ -73,14 +76,10 @@ bool rv_cfg_c_path_exists(char * path);
// function's return value. "return values" are done
// by passing a pointer to a return value struct, which
// is the first element in the function's argument list.
//
// TODO: make the return value of type void.

//INT_RET_TYPE rv_cfg_int(sail_int *, char *, unit); // TODO: find out why unit is sometimes required, sometimes not INT_RET_TYPE rv_cfg_int(sail_int *, char *);

int rv_cfg_s_int(sail_int *, char *);
int rv_cfg_s_string(sail_string , char *);
int rv_cfg_s_bool(sail_string , char *);
bool rv_cfg_s_bool(sail_string , char *);
unit rv_cfg_s_dump_yaml(char *);

//#endif
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ hart0: &hart0
accessible: false
mtval:
reset-val: 0x0
has_illegal_inst_bits : false
rv32:
accessible: true
rv64:
Expand Down
5 changes: 3 additions & 2 deletions model/rv_cfg_func_sigs.sail
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@


/* functions for accessing RISC-V Config data */
val rv_cfg_int = { c: "rv_cfg_s_int" } : string -> int
val rv_cfg_int = { c: "rv_cfg_s_int" } : string -> int
val rv_cfg_string = { c: "rv_cfg_s_string" } : string -> string
val rv_cfg_bool = { c: "rv_cfg_s_bool" } : string -> int
//val rv_cfg_bool = { c: "rv_cfg_s_bool" } : string -> int
val rv_cfg_bool = { c: "rv_cfg_s_bool" } : string -> bool



0 comments on commit 516c906

Please sign in to comment.