forked from auracaster/openocd
nds32: support multi-target debugging
Change-Id: If767f646b234dbcdb01946e5d13a3a6a29df2d78 Signed-off-by: Hsiangkai Wang <hsiangkai@gmail.com> Reviewed-on: http://openocd.zylin.com/1581 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
This commit is contained in:
committed by
Spencer Oliver
parent
18c40eb9e5
commit
24dd226e89
@@ -395,7 +395,7 @@ static const struct reg_arch_type nds32_reg_access_type_64 = {
|
||||
static struct reg_cache *nds32_build_reg_cache(struct target *target,
|
||||
struct nds32 *nds32)
|
||||
{
|
||||
struct reg_cache *cache = malloc(sizeof(struct reg_cache));
|
||||
struct reg_cache *cache = calloc(sizeof(struct reg_cache), 1);
|
||||
struct reg *reg_list = calloc(TOTAL_REG_NUM, sizeof(struct reg));
|
||||
struct nds32_reg *reg_arch_info = calloc(TOTAL_REG_NUM, sizeof(struct nds32_reg));
|
||||
int i;
|
||||
@@ -423,7 +423,7 @@ static struct reg_cache *nds32_build_reg_cache(struct target *target,
|
||||
reg_list[i].size = nds32_reg_size(i);
|
||||
reg_list[i].arch_info = ®_arch_info[i];
|
||||
|
||||
reg_list[i].reg_data_type = malloc(sizeof(struct reg_data_type));
|
||||
reg_list[i].reg_data_type = calloc(sizeof(struct reg_data_type), 1);
|
||||
|
||||
if (FD0 <= reg_arch_info[i].num && reg_arch_info[i].num <= FD31) {
|
||||
reg_list[i].value = &(reg_arch_info[i].value_64);
|
||||
@@ -1649,6 +1649,15 @@ int nds32_init_arch_info(struct target *target, struct nds32 *nds32)
|
||||
nds32->active_syscall_id = NDS32_SYSCALL_UNDEFINED;
|
||||
nds32->virtual_hosting_errno = 0;
|
||||
nds32->virtual_hosting_ctrl_c = false;
|
||||
nds32->attached = false;
|
||||
|
||||
nds32->syscall_break.asid = 0;
|
||||
nds32->syscall_break.length = 4;
|
||||
nds32->syscall_break.set = 0;
|
||||
nds32->syscall_break.orig_instr = NULL;
|
||||
nds32->syscall_break.next = NULL;
|
||||
nds32->syscall_break.unique_id = 0x515CAll + target->target_number;
|
||||
nds32->syscall_break.linked_BRP = 0;
|
||||
|
||||
nds32_reg_init();
|
||||
|
||||
@@ -2187,27 +2196,21 @@ int nds32_assert_reset(struct target *target)
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static uint32_t nds32_backup_edm_ctl;
|
||||
static bool gdb_attached;
|
||||
|
||||
static int nds32_gdb_attach(struct nds32 *nds32)
|
||||
{
|
||||
LOG_DEBUG("nds32_gdb_attach");
|
||||
LOG_DEBUG("nds32_gdb_attach, target coreid: %d", nds32->target->coreid);
|
||||
|
||||
if (gdb_attached == false) {
|
||||
if (nds32->attached == false) {
|
||||
|
||||
if (nds32->keep_target_edm_ctl) {
|
||||
/* backup target EDM_CTL */
|
||||
struct aice_port_s *aice = target_to_aice(nds32->target);
|
||||
aice_read_debug_reg(aice, NDS_EDM_SR_EDM_CTL, &nds32_backup_edm_ctl);
|
||||
aice_read_debug_reg(aice, NDS_EDM_SR_EDM_CTL, &nds32->backup_edm_ctl);
|
||||
}
|
||||
|
||||
target_halt(nds32->target);
|
||||
|
||||
/* turn on polling */
|
||||
jtag_poll_set_enabled(true);
|
||||
|
||||
gdb_attached = true;
|
||||
nds32->attached = true;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
@@ -2218,7 +2221,7 @@ static int nds32_gdb_detach(struct nds32 *nds32)
|
||||
LOG_DEBUG("nds32_gdb_detach");
|
||||
bool backup_virtual_hosting_setting;
|
||||
|
||||
if (gdb_attached) {
|
||||
if (nds32->attached) {
|
||||
|
||||
backup_virtual_hosting_setting = nds32->virtual_hosting;
|
||||
/* turn off virtual hosting before resume as gdb-detach */
|
||||
@@ -2229,13 +2232,10 @@ static int nds32_gdb_detach(struct nds32 *nds32)
|
||||
if (nds32->keep_target_edm_ctl) {
|
||||
/* restore target EDM_CTL */
|
||||
struct aice_port_s *aice = target_to_aice(nds32->target);
|
||||
aice_write_debug_reg(aice, NDS_EDM_SR_EDM_CTL, nds32_backup_edm_ctl);
|
||||
aice_write_debug_reg(aice, NDS_EDM_SR_EDM_CTL, nds32->backup_edm_ctl);
|
||||
}
|
||||
|
||||
/* turn off polling */
|
||||
jtag_poll_set_enabled(false);
|
||||
|
||||
gdb_attached = false;
|
||||
nds32->attached = false;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
@@ -2245,7 +2245,12 @@ static int nds32_callback_event_handler(struct target *target,
|
||||
enum target_event event, void *priv)
|
||||
{
|
||||
int retval = ERROR_OK;
|
||||
struct nds32 *nds32 = priv;
|
||||
int target_number = *(int *)priv;
|
||||
|
||||
if (target_number != target->target_number)
|
||||
return ERROR_OK;
|
||||
|
||||
struct nds32 *nds32 = target_to_nds32(target);
|
||||
|
||||
switch (event) {
|
||||
case TARGET_EVENT_GDB_ATTACH:
|
||||
@@ -2266,11 +2271,9 @@ int nds32_init(struct nds32 *nds32)
|
||||
/* Initialize anything we can set up without talking to the target */
|
||||
nds32->memory.access_channel = NDS_MEMORY_ACC_CPU;
|
||||
|
||||
/* turn off polling by default */
|
||||
jtag_poll_set_enabled(false);
|
||||
|
||||
/* register event callback */
|
||||
target_register_event_callback(nds32_callback_event_handler, nds32);
|
||||
target_register_event_callback(nds32_callback_event_handler,
|
||||
&(nds32->target->target_number));
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
@@ -2467,7 +2470,7 @@ int nds32_profiling(struct target *target, uint32_t *samples,
|
||||
iteration = max_num_samples;
|
||||
|
||||
int pc_regnum = nds32->register_map(nds32, PC);
|
||||
aice->port->api->profiling(10, iteration, pc_regnum, samples, num_samples);
|
||||
aice_profiling(aice, 10, iteration, pc_regnum, samples, num_samples);
|
||||
|
||||
register_cache_invalidate(nds32->core_cache);
|
||||
|
||||
|
||||
@@ -296,6 +296,8 @@ struct nds32 {
|
||||
/** Record syscall ID for other operations to do special processing for target */
|
||||
int active_syscall_id;
|
||||
|
||||
struct breakpoint syscall_break;
|
||||
|
||||
/** Flag reporting whether global stop is active. */
|
||||
bool global_stop;
|
||||
|
||||
@@ -309,6 +311,9 @@ struct nds32 {
|
||||
* handler, it should be true. */
|
||||
bool keep_target_edm_ctl;
|
||||
|
||||
/* Value of $EDM_CTL before target enters debug mode */
|
||||
uint32_t backup_edm_ctl;
|
||||
|
||||
/** always use word-aligned address to access memory */
|
||||
bool word_access_mem;
|
||||
|
||||
@@ -346,6 +351,9 @@ struct nds32 {
|
||||
* hardware breakpoints or not in ROM */
|
||||
bool auto_convert_hw_bp;
|
||||
|
||||
/* Flag to indicate the target is attached by debugger or not */
|
||||
bool attached;
|
||||
|
||||
/** Backpointer to the target. */
|
||||
struct target *target;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ int aice_read_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t *val)
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->read_reg_64(num, val);
|
||||
return aice->port->api->read_reg_64(aice->coreid, num, val);
|
||||
}
|
||||
|
||||
int aice_write_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t val)
|
||||
@@ -41,17 +41,7 @@ int aice_write_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t val)
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->write_reg_64(num, val);
|
||||
}
|
||||
|
||||
int aice_select_target(struct aice_port_s *aice, uint32_t target_id)
|
||||
{
|
||||
if (aice->port->api->select_target == NULL) {
|
||||
LOG_WARNING("Not implemented: %s", __func__);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->select_target(target_id);
|
||||
return aice->port->api->write_reg_64(aice->coreid, num, val);
|
||||
}
|
||||
|
||||
int aice_read_tlb(struct aice_port_s *aice, uint32_t virtual_address,
|
||||
@@ -62,7 +52,7 @@ int aice_read_tlb(struct aice_port_s *aice, uint32_t virtual_address,
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->read_tlb(virtual_address, physical_address);
|
||||
return aice->port->api->read_tlb(aice->coreid, virtual_address, physical_address);
|
||||
}
|
||||
|
||||
int aice_cache_ctl(struct aice_port_s *aice, uint32_t subtype, uint32_t address)
|
||||
@@ -72,7 +62,7 @@ int aice_cache_ctl(struct aice_port_s *aice, uint32_t subtype, uint32_t address)
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->cache_ctl(subtype, address);
|
||||
return aice->port->api->cache_ctl(aice->coreid, subtype, address);
|
||||
}
|
||||
|
||||
int aice_set_retry_times(struct aice_port_s *aice, uint32_t a_retry_times)
|
||||
@@ -92,7 +82,7 @@ int aice_program_edm(struct aice_port_s *aice, char *command_sequence)
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->program_edm(command_sequence);
|
||||
return aice->port->api->program_edm(aice->coreid, command_sequence);
|
||||
}
|
||||
|
||||
int aice_set_command_mode(struct aice_port_s *aice,
|
||||
@@ -114,7 +104,7 @@ int aice_execute(struct aice_port_s *aice, uint32_t *instructions,
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->execute(instructions, instruction_num);
|
||||
return aice->port->api->execute(aice->coreid, instructions, instruction_num);
|
||||
}
|
||||
|
||||
int aice_set_custom_srst_script(struct aice_port_s *aice, const char *script)
|
||||
@@ -156,3 +146,15 @@ int aice_set_count_to_check_dbger(struct aice_port_s *aice, uint32_t count_to_ch
|
||||
|
||||
return aice->port->api->set_count_to_check_dbger(count_to_check);
|
||||
}
|
||||
|
||||
int aice_profiling(struct aice_port_s *aice, uint32_t interval, uint32_t iteration,
|
||||
uint32_t reg_no, uint32_t *samples, uint32_t *num_samples)
|
||||
{
|
||||
if (aice->port->api->profiling == NULL) {
|
||||
LOG_WARNING("Not implemented: %s", __func__);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
return aice->port->api->profiling(aice->coreid, interval, iteration,
|
||||
reg_no, samples, num_samples);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
int aice_read_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t *val);
|
||||
int aice_write_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t val);
|
||||
int aice_select_target(struct aice_port_s *aice, uint32_t target_id);
|
||||
int aice_read_tlb(struct aice_port_s *aice, uint32_t virtual_address,
|
||||
uint32_t *physical_address);
|
||||
int aice_cache_ctl(struct aice_port_s *aice, uint32_t subtype, uint32_t address);
|
||||
@@ -38,6 +37,8 @@ int aice_set_custom_srst_script(struct aice_port_s *aice, const char *script);
|
||||
int aice_set_custom_trst_script(struct aice_port_s *aice, const char *script);
|
||||
int aice_set_custom_restart_script(struct aice_port_s *aice, const char *script);
|
||||
int aice_set_count_to_check_dbger(struct aice_port_s *aice, uint32_t count_to_check);
|
||||
int aice_profiling(struct aice_port_s *aice, uint32_t interval, uint32_t iteration,
|
||||
uint32_t reg_no, uint32_t *samples, uint32_t *num_samples);
|
||||
|
||||
static inline int aice_open(struct aice_port_s *aice, struct aice_port_param_s *param)
|
||||
{
|
||||
@@ -57,70 +58,70 @@ static inline int aice_reset(struct aice_port_s *aice)
|
||||
static inline int aice_assert_srst(struct aice_port_s *aice,
|
||||
enum aice_srst_type_s srst)
|
||||
{
|
||||
return aice->port->api->assert_srst(srst);
|
||||
return aice->port->api->assert_srst(aice->coreid, srst);
|
||||
}
|
||||
|
||||
static inline int aice_run(struct aice_port_s *aice)
|
||||
{
|
||||
return aice->port->api->run();
|
||||
return aice->port->api->run(aice->coreid);
|
||||
}
|
||||
|
||||
static inline int aice_halt(struct aice_port_s *aice)
|
||||
{
|
||||
return aice->port->api->halt();
|
||||
return aice->port->api->halt(aice->coreid);
|
||||
}
|
||||
|
||||
static inline int aice_step(struct aice_port_s *aice)
|
||||
{
|
||||
return aice->port->api->step();
|
||||
return aice->port->api->step(aice->coreid);
|
||||
}
|
||||
|
||||
static inline int aice_read_register(struct aice_port_s *aice, uint32_t num,
|
||||
uint32_t *val)
|
||||
{
|
||||
return aice->port->api->read_reg(num, val);
|
||||
return aice->port->api->read_reg(aice->coreid, num, val);
|
||||
}
|
||||
|
||||
static inline int aice_write_register(struct aice_port_s *aice, uint32_t num,
|
||||
uint32_t val)
|
||||
{
|
||||
return aice->port->api->write_reg(num, val);
|
||||
return aice->port->api->write_reg(aice->coreid, num, val);
|
||||
}
|
||||
|
||||
static inline int aice_read_debug_reg(struct aice_port_s *aice, uint32_t addr,
|
||||
uint32_t *val)
|
||||
{
|
||||
return aice->port->api->read_debug_reg(addr, val);
|
||||
return aice->port->api->read_debug_reg(aice->coreid, addr, val);
|
||||
}
|
||||
|
||||
static inline int aice_write_debug_reg(struct aice_port_s *aice, uint32_t addr,
|
||||
const uint32_t val)
|
||||
{
|
||||
return aice->port->api->write_debug_reg(addr, val);
|
||||
return aice->port->api->write_debug_reg(aice->coreid, addr, val);
|
||||
}
|
||||
|
||||
static inline int aice_read_mem_unit(struct aice_port_s *aice, uint32_t addr,
|
||||
uint32_t size, uint32_t count, uint8_t *buffer)
|
||||
{
|
||||
return aice->port->api->read_mem_unit(addr, size, count, buffer);
|
||||
return aice->port->api->read_mem_unit(aice->coreid, addr, size, count, buffer);
|
||||
}
|
||||
|
||||
static inline int aice_write_mem_unit(struct aice_port_s *aice, uint32_t addr,
|
||||
uint32_t size, uint32_t count, const uint8_t *buffer)
|
||||
{
|
||||
return aice->port->api->write_mem_unit(addr, size, count, buffer);
|
||||
return aice->port->api->write_mem_unit(aice->coreid, addr, size, count, buffer);
|
||||
}
|
||||
|
||||
static inline int aice_read_mem_bulk(struct aice_port_s *aice, uint32_t addr,
|
||||
uint32_t length, uint8_t *buffer)
|
||||
{
|
||||
return aice->port->api->read_mem_bulk(addr, length, buffer);
|
||||
return aice->port->api->read_mem_bulk(aice->coreid, addr, length, buffer);
|
||||
}
|
||||
|
||||
static inline int aice_write_mem_bulk(struct aice_port_s *aice, uint32_t addr,
|
||||
uint32_t length, const uint8_t *buffer)
|
||||
{
|
||||
return aice->port->api->write_mem_bulk(addr, length, buffer);
|
||||
return aice->port->api->write_mem_bulk(aice->coreid, addr, length, buffer);
|
||||
}
|
||||
|
||||
static inline int aice_idcode(struct aice_port_s *aice, uint32_t *idcode,
|
||||
@@ -132,7 +133,7 @@ static inline int aice_idcode(struct aice_port_s *aice, uint32_t *idcode,
|
||||
static inline int aice_state(struct aice_port_s *aice,
|
||||
enum aice_target_state_s *state)
|
||||
{
|
||||
return aice->port->api->state(state);
|
||||
return aice->port->api->state(aice->coreid, state);
|
||||
}
|
||||
|
||||
static inline int aice_set_jtag_clock(struct aice_port_s *aice, uint32_t a_clock)
|
||||
@@ -143,19 +144,19 @@ static inline int aice_set_jtag_clock(struct aice_port_s *aice, uint32_t a_clock
|
||||
static inline int aice_memory_access(struct aice_port_s *aice,
|
||||
enum nds_memory_access a_access)
|
||||
{
|
||||
return aice->port->api->memory_access(a_access);
|
||||
return aice->port->api->memory_access(aice->coreid, a_access);
|
||||
}
|
||||
|
||||
static inline int aice_memory_mode(struct aice_port_s *aice,
|
||||
enum nds_memory_select mem_select)
|
||||
{
|
||||
return aice->port->api->memory_mode(mem_select);
|
||||
return aice->port->api->memory_mode(aice->coreid, mem_select);
|
||||
}
|
||||
|
||||
static inline int aice_set_data_endian(struct aice_port_s *aice,
|
||||
enum aice_target_endian target_data_endian)
|
||||
{
|
||||
return aice->port->api->set_data_endian(target_data_endian);
|
||||
return aice->port->api->set_data_endian(aice->coreid, target_data_endian);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,18 +29,6 @@
|
||||
#include "nds32_aice.h"
|
||||
#include "nds32_v3_common.h"
|
||||
|
||||
static struct breakpoint syscall_breakpoint = {
|
||||
0x80,
|
||||
0,
|
||||
4,
|
||||
BKPT_SOFT,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
0x515CA11,
|
||||
0,
|
||||
};
|
||||
|
||||
static struct nds32_v3_common_callback *v3_common_callback;
|
||||
|
||||
static int nds32_v3_register_mapping(struct nds32 *nds32, int reg_no)
|
||||
@@ -90,17 +78,18 @@ static int nds32_v3_debug_entry(struct nds32 *nds32, bool enable_watchpoint)
|
||||
if (enable_watchpoint)
|
||||
CHECK_RETVAL(v3_common_callback->deactivate_hardware_watchpoint(nds32->target));
|
||||
|
||||
struct breakpoint *syscall_break = &(nds32->syscall_break);
|
||||
if (nds32->virtual_hosting) {
|
||||
if (syscall_breakpoint.set) {
|
||||
if (syscall_break->set) {
|
||||
/** disable virtual hosting */
|
||||
|
||||
/* remove breakpoint at syscall entry */
|
||||
target_remove_breakpoint(nds32->target, &syscall_breakpoint);
|
||||
syscall_breakpoint.set = 0;
|
||||
target_remove_breakpoint(nds32->target, syscall_break);
|
||||
syscall_break->set = 0;
|
||||
|
||||
uint32_t value_pc;
|
||||
nds32_get_mapped_reg(nds32, PC, &value_pc);
|
||||
if (value_pc == syscall_breakpoint.address)
|
||||
if (value_pc == syscall_break->address)
|
||||
/** process syscall for virtual hosting */
|
||||
nds32->hit_syscall = true;
|
||||
}
|
||||
@@ -218,10 +207,12 @@ static int nds32_v3_leave_debug_state(struct nds32 *nds32, bool enable_watchpoin
|
||||
}
|
||||
|
||||
/* insert breakpoint at syscall entry */
|
||||
syscall_breakpoint.address = syscall_address;
|
||||
syscall_breakpoint.type = BKPT_SOFT;
|
||||
syscall_breakpoint.set = 1;
|
||||
target_add_breakpoint(target, &syscall_breakpoint);
|
||||
struct breakpoint *syscall_break = &(nds32->syscall_break);
|
||||
|
||||
syscall_break->address = syscall_address;
|
||||
syscall_break->type = BKPT_SOFT;
|
||||
syscall_break->set = 1;
|
||||
target_add_breakpoint(target, syscall_break);
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
|
||||
Reference in New Issue
Block a user