Skip to content

Commit

Permalink
Implement -cheri-trace-format
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
arichardson committed Jan 27, 2017
1 parent d590744 commit 963396d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
7 changes: 7 additions & 0 deletions qemu-options.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,13 @@ STEXI
@item -bc @var{count}
Set GDB breakpoint in <count> instructions after start.
ETEXI
DEF("cheri-trace-format", HAS_ARG, QEMU_OPTION_cheri_trace_format, \
"-cheri-trace-format [text|cvtrace] Select CHERI trace mode.\n", QEMU_ARCH_ALL)
STEXI
@item -cheri-trace-format @var{type}
Set CHERI trace format to <type> (text or cvtrace)
ETEXI
#endif
Expand Down
23 changes: 9 additions & 14 deletions target-mips/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3523,12 +3523,7 @@ target_ulong helper_cscc_addr(CPUMIPSState *env, uint32_t cs, uint32_t cb)
return (target_ulong)addr;
}

#ifdef CHERI_DEFAULT_CVTRACE
#define CHERI_DEFAULT_TRACE_FLAG CPU_LOG_CVTRACE
#else
#define CHERI_DEFAULT_TRACE_FLAG CPU_LOG_INSTR
#endif

extern int cl_default_trace_format;

#define USER_TRACE_DEBUG 0
#if USER_TRACE_DEBUG
Expand All @@ -3546,10 +3541,10 @@ void helper_instr_start(CPUMIPSState *env, target_ulong pc)
user_trace_dbg("Delaying tracing request at 0x%lx "
"until next switch to user mode, ASID %lu\n",
pc, env->CP0_EntryHi & 0xFF);
env->trace_level_before_suspend = CHERI_DEFAULT_TRACE_FLAG;
env->trace_level_before_suspend = cl_default_trace_format;
env->tracing_suspended = true;
} else {
qemu_set_log(qemu_loglevel | CHERI_DEFAULT_TRACE_FLAG);
qemu_set_log(qemu_loglevel | cl_default_trace_format);
user_trace_dbg("Switching on tracing @ 0x%lx ASID %lu\n",
pc, env->CP0_EntryHi & 0xFF);
env->tracing_suspended = false;
Expand All @@ -3561,7 +3556,7 @@ void helper_instr_stop(CPUMIPSState *env, target_ulong pc)
{
user_trace_dbg("Switching off tracing @ 0x%lx ASID %lu\n",
pc, env->CP0_EntryHi & 0xFF);
qemu_set_log(qemu_loglevel & ~CHERI_DEFAULT_TRACE_FLAG);
qemu_set_log(qemu_loglevel & ~cl_default_trace_format);
/* Make sure a kernel -> user switch does not turn on tracing */
env->trace_level_before_suspend = 0;
env->tracing_suspended = false;
Expand All @@ -3576,8 +3571,8 @@ void helper_instr_start_user_mode_only(CPUMIPSState *env, target_ulong pc)
env->user_only_tracing_enabled = true;
/* Disable tracing if we are not currently in user mode */
if (!IN_USERSPACE(env)) {
env->trace_level_before_suspend = qemu_loglevel & CHERI_DEFAULT_TRACE_FLAG;
qemu_set_log(qemu_loglevel & ~CHERI_DEFAULT_TRACE_FLAG);
env->trace_level_before_suspend = qemu_loglevel & cl_default_trace_format;
qemu_set_log(qemu_loglevel & ~cl_default_trace_format);
env->tracing_suspended = true;
} else {
env->tracing_suspended = false;
Expand Down Expand Up @@ -3653,7 +3648,7 @@ void helper_cheri_debug_message(struct CPUMIPSState* env, uint64_t pc)
uint32_t mode = qemu_loglevel & (CPU_LOG_CVTRACE | CPU_LOG_INSTR);
if (!mode && env->tracing_suspended) {
/* Always print these messages even if user-space only tracing is on */
mode = CHERI_DEFAULT_TRACE_FLAG;
mode = cl_default_trace_format;
}
if (!mode) {
return;
Expand Down Expand Up @@ -5605,9 +5600,9 @@ static void update_tracing_on_mode_change(CPUMIPSState *env, const char* new_mod
/* When changing from user mode to kernel mode disable tracing */
user_trace_dbg("%s -> %s: 0x%lx ASID %lu -- switching off tracing \n",
env->last_mode, new_mode, env->active_tc.PC, env->CP0_EntryHi & 0xFF);
env->trace_level_before_suspend = qemu_loglevel & CHERI_DEFAULT_TRACE_FLAG;
env->trace_level_before_suspend = qemu_loglevel & cl_default_trace_format;
env->tracing_suspended = true;
qemu_set_log(qemu_loglevel & ~CHERI_DEFAULT_TRACE_FLAG);
qemu_set_log(qemu_loglevel & ~cl_default_trace_format);
} else if (strcmp(new_mode, TRACE_MODE_USER) == 0) {
/* When changing back to user mode restore instruction tracing */
assert(!IN_USERSPACE(env));
Expand Down
1 change: 1 addition & 0 deletions target-mips/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4583,6 +4583,7 @@ static void gen_logic_imm(DisasContext *ctx, uint32_t opc,
MIPS_DEBUG("NOP");
#ifdef TARGET_CHERI
if (opc == OPC_ORI && rs == 0) {
// XXXAR: do we really want this early return in CVTRACE mode?
#ifndef CHERI_DEFAULT_CVTRACE
/* Don't mix with CheriVis tracing. */
if (qemu_loglevel_mask(CPU_LOG_CVTRACE))
Expand Down
18 changes: 18 additions & 0 deletions vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ uint8_t qemu_extra_params_fw[2];

int icount_align_option;

#ifdef CONFIG_CHERI
#ifdef CHERI_DEFAULT_CVTRACE
int cl_default_trace_format = CPU_LOG_CVTRACE;
#else
int cl_default_trace_format = CPU_LOG_INSTR;
#endif
#endif

/* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the
* little-endian "wire format" described in the SMBIOS 2.6 specification.
*/
Expand Down Expand Up @@ -3878,6 +3886,16 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_breakpoint:
cl_breakpoint = strtoull(optarg, NULL, 0);
break;
case QEMU_OPTION_cheri_trace_format:
if (strcmp(optarg, "text") == 0)
cl_default_trace_format = CPU_LOG_INSTR;
else if (strcmp(optarg, "cvtrace") == 0)
cl_default_trace_format = CPU_LOG_CVTRACE;
else {
printf("Invalid choice for cheri-trace-format: '%s'\n", optarg);
exit(1);
}
break;
case QEMU_OPTION_breakcount:
cl_breakcount = strtoull(optarg, NULL, 0);
break;
Expand Down

0 comments on commit 963396d

Please sign in to comment.