mirror of
https://github.com/siemens-mobile-hacks/qemu-pmb887x.git
synced 2026-11-25 21:47:17 +00:00
debug-channel: print the PC and LR of register accesses
This commit is contained in:
parent
6f40cf35f3
commit
cc9a2a44a1
7 changed files with 88 additions and 5 deletions
|
|
@ -282,6 +282,37 @@ bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data)
|
|||
return false;
|
||||
}
|
||||
|
||||
typedef struct IOContextCache {
|
||||
uintptr_t host_pc;
|
||||
unsigned tb_flush_count;
|
||||
bool found;
|
||||
uint64_t data[INSN_START_WORDS];
|
||||
} IOContextCache;
|
||||
|
||||
static __thread IOContextCache io_context_cache;
|
||||
|
||||
bool cpu_get_io_context(CPUState *cpu, uint64_t *pc, uint64_t *lr)
|
||||
{
|
||||
IOContextCache *cache = &io_context_cache;
|
||||
unsigned tb_flush_count = qatomic_read(&tb_ctx.tb_flush_count);
|
||||
|
||||
if (!cpu->cc->tcg_ops->get_io_context) {
|
||||
return false;
|
||||
}
|
||||
if (cache->host_pc != cpu->mem_io_pc ||
|
||||
cache->tb_flush_count != tb_flush_count) {
|
||||
cache->host_pc = cpu->mem_io_pc;
|
||||
cache->tb_flush_count = tb_flush_count;
|
||||
cache->found = cpu_unwind_state_data(cpu, cache->host_pc,
|
||||
cache->data);
|
||||
}
|
||||
if (!cache->found) {
|
||||
return false;
|
||||
}
|
||||
cpu->cc->tcg_ops->get_io_context(cpu, cache->data, pc, lr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void page_init(void)
|
||||
{
|
||||
page_table_config_init();
|
||||
|
|
|
|||
|
|
@ -45,6 +45,15 @@ bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
|
|||
*/
|
||||
bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc);
|
||||
|
||||
/**
|
||||
* cpu_get_io_context:
|
||||
* @cpu: the cpu context
|
||||
* @pc: the PC of the instruction at @cpu->mem_io_pc
|
||||
* @lr: its return address
|
||||
* @return: false if @cpu->mem_io_pc is not in translated code
|
||||
*/
|
||||
bool cpu_get_io_context(CPUState *cpu, uint64_t *pc, uint64_t *lr);
|
||||
|
||||
/**
|
||||
* cpu_loop_exit_noexc:
|
||||
* @cpu: the cpu context
|
||||
|
|
|
|||
|
|
@ -93,6 +93,13 @@ struct TCGCPUOps {
|
|||
*/
|
||||
void (*restore_state_to_opc)(CPUState *cpu, const TranslationBlock *tb,
|
||||
const uint64_t *data);
|
||||
/**
|
||||
* @get_io_context: Get the PC and the return address of the
|
||||
* instruction given by the INDEX_op_start_insn arguments @data,
|
||||
* without changing the CPU state.
|
||||
*/
|
||||
void (*get_io_context)(CPUState *cpu, const uint64_t *data,
|
||||
uint64_t *pc, uint64_t *lr);
|
||||
|
||||
/** @cpu_exec_enter: Callback for cpu_exec preparation */
|
||||
void (*cpu_exec_enter)(CPUState *cpu);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@
|
|||
#include "system/runstate.h"
|
||||
#include "system/system.h"
|
||||
#include "system/debug-channel.h"
|
||||
#include "system/tcg.h"
|
||||
#include "hw/core/cpu.h"
|
||||
#ifdef CONFIG_TCG
|
||||
#include "accel/tcg/cpu-loop.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG_QUEUE_CAPACITY (64 * 1024)
|
||||
|
||||
|
|
@ -21,11 +26,25 @@ typedef struct DebugMr {
|
|||
|
||||
static Notifier debug_exit_notifier;
|
||||
|
||||
static void debug_mr_print(DebugMr *d, hwaddr addr, unsigned size,
|
||||
uint64_t value, bool is_write)
|
||||
static bool debug_get_io_context(MemTxAttrs attrs, uint64_t *pc, uint64_t *lr)
|
||||
{
|
||||
#ifdef CONFIG_TCG
|
||||
if (tcg_enabled() && current_cpu && !attrs.unspecified) {
|
||||
return cpu_get_io_context(current_cpu, pc, lr);
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
static void debug_mr_print(DebugMr *d, hwaddr addr, unsigned size,
|
||||
uint64_t value, bool is_write, MemTxAttrs attrs)
|
||||
{
|
||||
uint64_t pc = 0;
|
||||
uint64_t lr = 0;
|
||||
bool has_context = debug_get_io_context(attrs, &pc, &lr);
|
||||
|
||||
debug_channel_io(d->ch, memory_region_to_absolute_addr(d->mr, addr), size,
|
||||
value, is_write, false, 0, 0);
|
||||
value, is_write, has_context, pc, lr);
|
||||
}
|
||||
|
||||
static MemTxResult debug_mr_read(void *opaque, hwaddr addr, uint64_t *data,
|
||||
|
|
@ -40,7 +59,7 @@ static MemTxResult debug_mr_read(void *opaque, hwaddr addr, uint64_t *data,
|
|||
r = d->orig_ops->read_with_attrs(d->orig_opaque, addr, data, size,
|
||||
attrs);
|
||||
}
|
||||
debug_mr_print(d, addr, size, *data, false);
|
||||
debug_mr_print(d, addr, size, *data, false, attrs);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +69,7 @@ static MemTxResult debug_mr_write(void *opaque, hwaddr addr, uint64_t data,
|
|||
DebugMr *d = opaque;
|
||||
MemTxResult r = MEMTX_OK;
|
||||
|
||||
debug_mr_print(d, addr, size, data, true);
|
||||
debug_mr_print(d, addr, size, data, true, attrs);
|
||||
if (d->orig_ops->write) {
|
||||
d->orig_ops->write(d->orig_opaque, addr, data, size);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -126,6 +126,19 @@ void arm_restore_state_to_opc(CPUState *cs,
|
|||
}
|
||||
}
|
||||
|
||||
void arm_get_io_context(CPUState *cs, const uint64_t *data, uint64_t *pc,
|
||||
uint64_t *lr)
|
||||
{
|
||||
CPUARMState *env = cpu_env(cs);
|
||||
|
||||
*pc = data[0];
|
||||
if (tcg_cflags_has(cs, CF_PCREL)) {
|
||||
uint64_t page_pc = is_a64(env) ? env->pc : env->regs[15];
|
||||
*pc = (page_pc & TARGET_PAGE_MASK) | data[0];
|
||||
}
|
||||
*lr = is_a64(env) ? env->xregs[30] : env->regs[14];
|
||||
}
|
||||
|
||||
int arm_cpu_mmu_index(CPUState *cs, bool ifetch)
|
||||
{
|
||||
return arm_env_mmu_index(cpu_env(cs));
|
||||
|
|
@ -2594,6 +2607,7 @@ static const TCGCPUOps arm_tcg_ops = {
|
|||
.synchronize_from_tb = arm_cpu_synchronize_from_tb,
|
||||
.debug_excp_handler = arm_debug_excp_handler,
|
||||
.restore_state_to_opc = arm_restore_state_to_opc,
|
||||
.get_io_context = arm_get_io_context,
|
||||
.mmu_index = arm_cpu_mmu_index,
|
||||
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
|
|
|
|||
|
|
@ -427,6 +427,8 @@ void aarch64_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
|
|||
void arm_restore_state_to_opc(CPUState *cs,
|
||||
const TranslationBlock *tb,
|
||||
const uint64_t *data);
|
||||
void arm_get_io_context(CPUState *cs, const uint64_t *data, uint64_t *pc,
|
||||
uint64_t *lr);
|
||||
|
||||
#ifdef CONFIG_TCG
|
||||
TCGTBCPUState arm_get_tb_cpu_state(CPUState *cs);
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ static const TCGCPUOps arm_v7m_tcg_ops = {
|
|||
.synchronize_from_tb = arm_cpu_synchronize_from_tb,
|
||||
.debug_excp_handler = arm_debug_excp_handler,
|
||||
.restore_state_to_opc = arm_restore_state_to_opc,
|
||||
.get_io_context = arm_get_io_context,
|
||||
.mmu_index = arm_cpu_mmu_index,
|
||||
|
||||
#ifdef CONFIG_USER_ONLY
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue