Commit c8926d14 authored by Heythem Bouhaja's avatar Heythem Bouhaja Committed by Øyvind Harboe
Browse files

cortex_a hybrid & context breakpoints

parent e175f027
...@@ -72,6 +72,7 @@ int breakpoint_add_internal(struct target *target, uint32_t address, uint32_t le ...@@ -72,6 +72,7 @@ int breakpoint_add_internal(struct target *target, uint32_t address, uint32_t le
(*breakpoint_p) = malloc(sizeof(struct breakpoint)); (*breakpoint_p) = malloc(sizeof(struct breakpoint));
(*breakpoint_p)->address = address; (*breakpoint_p)->address = address;
(*breakpoint_p)->asid = 0;
(*breakpoint_p)->length = length; (*breakpoint_p)->length = length;
(*breakpoint_p)->type = type; (*breakpoint_p)->type = type;
(*breakpoint_p)->set = 0; (*breakpoint_p)->set = 0;
...@@ -107,6 +108,117 @@ fail: ...@@ -107,6 +108,117 @@ fail:
return ERROR_OK; return ERROR_OK;
} }
int context_breakpoint_add_internal(struct target *target, uint32_t asid, uint32_t length, enum breakpoint_type type)
{
struct breakpoint *breakpoint = target->breakpoints;
struct breakpoint **breakpoint_p = &target->breakpoints;
int retval;
int n;
n = 0;
while (breakpoint)
{
n++;
if (breakpoint->asid == asid)
{
/* FIXME don't assume "same address" means "same
* breakpoint" ... check all the parameters before
* succeeding.
*/
LOG_DEBUG("Duplicate Breakpoint asid: 0x%08" PRIx32 " (BP %d)",
asid, breakpoint->unique_id );
return -1;
}
breakpoint_p = &breakpoint->next;
breakpoint = breakpoint->next;
}
(*breakpoint_p) = malloc(sizeof(struct breakpoint));
(*breakpoint_p)->address = 0;
(*breakpoint_p)->asid = asid;
(*breakpoint_p)->length = length;
(*breakpoint_p)->type = type;
(*breakpoint_p)->set = 0;
(*breakpoint_p)->orig_instr = malloc(length);
(*breakpoint_p)->next = NULL;
(*breakpoint_p)->unique_id = bpwp_unique_id++;
retval = target_add_context_breakpoint(target, *breakpoint_p);
if (retval != ERROR_OK)
{
LOG_ERROR("could not add breakpoint");
free((*breakpoint_p)->orig_instr);
free(*breakpoint_p);
*breakpoint_p = NULL;
return retval;
}
LOG_DEBUG("added %s Context breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %d)",
breakpoint_type_strings[(*breakpoint_p)->type],
(*breakpoint_p)->asid, (*breakpoint_p)->length,
(*breakpoint_p)->unique_id );
return ERROR_OK;
}
int hybrid_breakpoint_add_internal(struct target *target, uint32_t address, uint32_t asid, uint32_t length, enum breakpoint_type type)
{
struct breakpoint *breakpoint = target->breakpoints;
struct breakpoint **breakpoint_p = &target->breakpoints;
int retval;
int n;
n = 0;
while (breakpoint)
{
n++;
if ((breakpoint->asid == asid) && (breakpoint->address == address)) {
/* FIXME don't assume "same address" means "same
* breakpoint" ... check all the parameters before
* succeeding.
*/
LOG_DEBUG("Duplicate Hybrid Breakpoint asid: 0x%08" PRIx32 " (BP %d)",
asid, breakpoint->unique_id );
return -1;
}
else if ((breakpoint->address == address) && (breakpoint->asid == 0))
{
LOG_DEBUG("Duplicate Breakpoint IVA: 0x%08" PRIx32 " (BP %d)",
address, breakpoint->unique_id );
return -1;
}
breakpoint_p = &breakpoint->next;
breakpoint = breakpoint->next;
}
(*breakpoint_p) = malloc(sizeof(struct breakpoint));
(*breakpoint_p)->address = address;
(*breakpoint_p)->asid = asid;
(*breakpoint_p)->length = length;
(*breakpoint_p)->type = type;
(*breakpoint_p)->set = 0;
(*breakpoint_p)->orig_instr = malloc(length);
(*breakpoint_p)->next = NULL;
(*breakpoint_p)->unique_id = bpwp_unique_id++;
retval = target_add_hybrid_breakpoint(target, *breakpoint_p);
if (retval != ERROR_OK)
{
LOG_ERROR("could not add breakpoint");
free((*breakpoint_p)->orig_instr);
free(*breakpoint_p);
*breakpoint_p = NULL;
return retval;
}
LOG_DEBUG("added %s Hybrid breakpoint at address 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %d)",
breakpoint_type_strings[(*breakpoint_p)->type],
(*breakpoint_p)->address, (*breakpoint_p)->length,
(*breakpoint_p)->unique_id );
return ERROR_OK;
}
int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enum breakpoint_type type) int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enum breakpoint_type type)
{ {
...@@ -128,6 +240,50 @@ int retval = ERROR_OK; ...@@ -128,6 +240,50 @@ int retval = ERROR_OK;
else else
return(breakpoint_add_internal(target, address, length, type)); return(breakpoint_add_internal(target, address, length, type));
}
int context_breakpoint_add(struct target *target, uint32_t asid, uint32_t length, enum breakpoint_type type)
{
int retval = ERROR_OK;
if (target->smp)
{
struct target_list *head;
struct target *curr;
head = target->head;
while(head != (struct target_list*)NULL)
{
curr = head->target;
retval = context_breakpoint_add_internal(curr, asid,length, type);
if (retval != ERROR_OK) return retval;
head = head->next;
}
return retval;
}
else
return(context_breakpoint_add_internal(target, asid, length, type));
}
int hybrid_breakpoint_add(struct target *target, uint32_t address, uint32_t asid, uint32_t length, enum breakpoint_type type)
{
int retval = ERROR_OK;
if (target->smp)
{
struct target_list *head;
struct target *curr;
head = target->head;
while(head != (struct target_list*)NULL)
{
curr = head->target;
retval = hybrid_breakpoint_add_internal(curr, address, asid, length, type);
if (retval != ERROR_OK) return retval;
head = head->next;
}
return retval;
}
else
return(hybrid_breakpoint_add_internal(target, address, asid, length, type));
} }
/* free up a breakpoint */ /* free up a breakpoint */
...@@ -162,7 +318,11 @@ void breakpoint_remove_internal(struct target *target, uint32_t address) ...@@ -162,7 +318,11 @@ void breakpoint_remove_internal(struct target *target, uint32_t address)
while (breakpoint) while (breakpoint)
{ {
if (breakpoint->address == address) if ((breakpoint->address == address) && (breakpoint->asid == 0))
break;
else if ((breakpoint->address == 0) && (breakpoint->asid == address))
break;
else if ((breakpoint->address == address) && (breakpoint->asid != 0))
break; break;
breakpoint = breakpoint->next; breakpoint = breakpoint->next;
} }
......
...@@ -38,12 +38,14 @@ enum watchpoint_rw ...@@ -38,12 +38,14 @@ enum watchpoint_rw
struct breakpoint struct breakpoint
{ {
uint32_t address; uint32_t address;
uint32_t asid;
int length; int length;
enum breakpoint_type type; enum breakpoint_type type;
int set; int set;
uint8_t *orig_instr; uint8_t *orig_instr;
struct breakpoint *next; struct breakpoint *next;
int unique_id; uint32_t unique_id;
int linked_BRP;
}; };
struct watchpoint struct watchpoint
...@@ -61,6 +63,10 @@ struct watchpoint ...@@ -61,6 +63,10 @@ struct watchpoint
void breakpoint_clear_target(struct target *target); void breakpoint_clear_target(struct target *target);
int breakpoint_add(struct target *target, int breakpoint_add(struct target *target,
uint32_t address, uint32_t length, enum breakpoint_type type); uint32_t address, uint32_t length, enum breakpoint_type type);
int context_breakpoint_add(struct target *target,
uint32_t asid, uint32_t length, enum breakpoint_type type);
int hybrid_breakpoint_add(struct target *target,
uint32_t address, uint32_t asid, uint32_t length, enum breakpoint_type type);
void breakpoint_remove(struct target *target, uint32_t address); void breakpoint_remove(struct target *target, uint32_t address);
struct breakpoint* breakpoint_find(struct target *target, uint32_t address); struct breakpoint* breakpoint_find(struct target *target, uint32_t address);
......
...@@ -53,6 +53,10 @@ static int cortex_a8_debug_entry(struct target *target); ...@@ -53,6 +53,10 @@ static int cortex_a8_debug_entry(struct target *target);
static int cortex_a8_restore_context(struct target *target, bool bpwp); static int cortex_a8_restore_context(struct target *target, bool bpwp);
static int cortex_a8_set_breakpoint(struct target *target, static int cortex_a8_set_breakpoint(struct target *target,
struct breakpoint *breakpoint, uint8_t matchmode); struct breakpoint *breakpoint, uint8_t matchmode);
static int cortex_a8_set_context_breakpoint(struct target *target,
struct breakpoint *breakpoint, uint8_t matchmode);
static int cortex_a8_set_hybrid_breakpoint(struct target *target,
struct breakpoint *breakpoint);
static int cortex_a8_unset_breakpoint(struct target *target, static int cortex_a8_unset_breakpoint(struct target *target,
struct breakpoint *breakpoint); struct breakpoint *breakpoint);
static int cortex_a8_dap_read_coreregister_u32(struct target *target, static int cortex_a8_dap_read_coreregister_u32(struct target *target,
...@@ -1422,6 +1426,141 @@ static int cortex_a8_set_breakpoint(struct target *target, ...@@ -1422,6 +1426,141 @@ static int cortex_a8_set_breakpoint(struct target *target,
return ERROR_OK; return ERROR_OK;
} }
static int cortex_a8_set_context_breakpoint(struct target *target,
struct breakpoint *breakpoint, uint8_t matchmode)
{
int retval = ERROR_FAIL;
int brp_i=0;
uint32_t control;
uint8_t byte_addr_select = 0x0F;
struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target);
struct armv7a_common *armv7a = &cortex_a8->armv7a_common;
struct cortex_a8_brp * brp_list = cortex_a8->brp_list;
if (breakpoint->set)
{
LOG_WARNING("breakpoint already set");
return retval ;
}
/*check available context BRPs*/
while ((brp_list[brp_i].used || (brp_list[brp_i].type!=BRP_CONTEXT)) && (brp_i < cortex_a8->brp_num))
brp_i++ ;
if (brp_i >= cortex_a8->brp_num)
{
LOG_ERROR("ERROR Can not find free Breakpoint Register Pair");
return ERROR_FAIL;
}
breakpoint->set = brp_i + 1;
control = ((matchmode & 0x7) << 20)
| (byte_addr_select << 5)
| (3 << 1) | 1;
brp_list[brp_i].used = 1;
brp_list[brp_i].value = (breakpoint->asid);
brp_list[brp_i].control = control;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].value);
if(retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].control);
if(retval != ERROR_OK)
return retval;
LOG_DEBUG("brp %i control 0x%0" PRIx32 " value 0x%0" PRIx32, brp_i,
brp_list[brp_i].control,
brp_list[brp_i].value);
return ERROR_OK;
}
static int cortex_a8_set_hybrid_breakpoint(struct target *target, struct breakpoint *breakpoint)
{
int retval = ERROR_FAIL;
int brp_1=0; //holds the contextID pair
int brp_2=0; // holds the IVA pair
uint32_t control_CTX, control_IVA;
uint8_t CTX_byte_addr_select = 0x0F;
uint8_t IVA_byte_addr_select = 0x0F;
uint8_t CTX_machmode = 0x03;
uint8_t IVA_machmode = 0x01;
struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target);
struct armv7a_common *armv7a = &cortex_a8->armv7a_common;
struct cortex_a8_brp * brp_list = cortex_a8->brp_list;
if (breakpoint->set)
{
LOG_WARNING("breakpoint already set");
return retval ;
}
/*check available context BRPs*/
while ((brp_list[brp_1].used || (brp_list[brp_1].type!=BRP_CONTEXT)) && (brp_1 < cortex_a8->brp_num))
brp_1++ ;
printf("brp(CTX) found num: %d \n",brp_1);
if (brp_1 >= cortex_a8->brp_num)
{
LOG_ERROR("ERROR Can not find free Breakpoint Register Pair");
return ERROR_FAIL;
}
while ((brp_list[brp_2].used || (brp_list[brp_2].type!=BRP_NORMAL)) && (brp_2 < cortex_a8->brp_num))
brp_2++ ;
printf("brp(IVA) found num: %d \n",brp_2);
if (brp_2 >= cortex_a8->brp_num)
{
LOG_ERROR("ERROR Can not find free Breakpoint Register Pair");
return ERROR_FAIL;
}
breakpoint->set = brp_1 + 1;
breakpoint->linked_BRP= brp_2;
control_CTX = ((CTX_machmode & 0x7) << 20)
| (brp_2 << 16)
| (0 << 14)
| (CTX_byte_addr_select << 5)
| (3 << 1) | 1;
brp_list[brp_1].used = 1;
brp_list[brp_1].value = (breakpoint->asid);
brp_list[brp_1].control = control_CTX;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_1].BRPn,
brp_list[brp_1].value);
if (retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_1].BRPn,
brp_list[brp_1].control);
if( retval != ERROR_OK )
return retval;
control_IVA = ((IVA_machmode & 0x7) << 20)
| (brp_1 << 16)
| (IVA_byte_addr_select << 5)
| (3 << 1) | 1;
brp_list[brp_2].used = 1;
brp_list[brp_2].value = (breakpoint->address & 0xFFFFFFFC);
brp_list[brp_2].control = control_IVA;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_2].BRPn,
brp_list[brp_2].value);
if (retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_2].BRPn,
brp_list[brp_2].control);
if (retval != ERROR_OK )
return retval;
return ERROR_OK;
}
static int cortex_a8_unset_breakpoint(struct target *target, struct breakpoint *breakpoint) static int cortex_a8_unset_breakpoint(struct target *target, struct breakpoint *breakpoint)
{ {
int retval; int retval;
...@@ -1437,27 +1576,81 @@ static int cortex_a8_unset_breakpoint(struct target *target, struct breakpoint * ...@@ -1437,27 +1576,81 @@ static int cortex_a8_unset_breakpoint(struct target *target, struct breakpoint *
if (breakpoint->type == BKPT_HARD) if (breakpoint->type == BKPT_HARD)
{ {
int brp_i = breakpoint->set - 1; if ((breakpoint->address != 0) && (breakpoint->asid != 0))
if ((brp_i < 0) || (brp_i >= cortex_a8->brp_num))
{ {
LOG_DEBUG("Invalid BRP number in breakpoint"); int brp_i = breakpoint->set - 1;
int brp_j = breakpoint->linked_BRP;
if ((brp_i < 0) || (brp_i >= cortex_a8->brp_num))
{
LOG_DEBUG("Invalid BRP number in breakpoint");
return ERROR_OK;
}
LOG_DEBUG("rbp %i control 0x%0" PRIx32 " value 0x%0" PRIx32, brp_i,
brp_list[brp_i].control, brp_list[brp_i].value);
brp_list[brp_i].used = 0;
brp_list[brp_i].value = 0;
brp_list[brp_i].control = 0;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].control);
if (retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].value);
if (retval != ERROR_OK)
return retval;
if ((brp_j < 0) || (brp_j >= cortex_a8->brp_num))
{
LOG_DEBUG("Invalid BRP number in breakpoint");
return ERROR_OK;
}
LOG_DEBUG("rbp %i control 0x%0" PRIx32 " value 0x%0" PRIx32, brp_j,
brp_list[brp_j].control, brp_list[brp_j].value);
brp_list[brp_j].used = 0;
brp_list[brp_j].value = 0;
brp_list[brp_j].control = 0;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_j].BRPn,
brp_list[brp_j].control);
if (retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_j].BRPn,
brp_list[brp_j].value);
if (retval != ERROR_OK)
return retval;
breakpoint->linked_BRP = 0;
breakpoint->set = 0;
return ERROR_OK; return ERROR_OK;
} }
LOG_DEBUG("rbp %i control 0x%0" PRIx32 " value 0x%0" PRIx32, brp_i, else
brp_list[brp_i].control, brp_list[brp_i].value); {
brp_list[brp_i].used = 0; int brp_i = breakpoint->set - 1;
brp_list[brp_i].value = 0; if ((brp_i < 0) || (brp_i >= cortex_a8->brp_num))
brp_list[brp_i].control = 0; {
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base LOG_DEBUG("Invalid BRP number in breakpoint");
+ CPUDBG_BCR_BASE + 4 * brp_list[brp_i].BRPn, return ERROR_OK;
brp_list[brp_i].control); }
if (retval != ERROR_OK) LOG_DEBUG("rbp %i control 0x%0" PRIx32 " value 0x%0" PRIx32, brp_i,
return retval; brp_list[brp_i].control, brp_list[brp_i].value);
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base brp_list[brp_i].used = 0;
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_i].BRPn, brp_list[brp_i].value = 0;
brp_list[brp_i].value); brp_list[brp_i].control = 0;
if (retval != ERROR_OK) retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
return retval; + CPUDBG_BCR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].control);
if (retval != ERROR_OK)
return retval;
retval = cortex_a8_dap_write_memap_register_u32(target, armv7a->debug_base
+ CPUDBG_BVR_BASE + 4 * brp_list[brp_i].BRPn,
brp_list[brp_i].value);
if (retval != ERROR_OK)
return retval;
breakpoint->set = 0;
return ERROR_OK;
}
} }
else else
{ {
...@@ -1501,6 +1694,41 @@ static int cortex_a8_add_breakpoint(struct target *target, ...@@ -1501,6 +1694,41 @@ static int cortex_a8_add_breakpoint(struct target *target,
return cortex_a8_set_breakpoint(target, breakpoint, 0x00); /* Exact match */ return cortex_a8_set_breakpoint(target, breakpoint, 0x00); /* Exact match */
} }
static int cortex_a8_add_context_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target);
if ((breakpoint->type == BKPT_HARD) && (cortex_a8->brp_num_available < 1))
{
LOG_INFO("no hardware breakpoint available");
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
if (breakpoint->type == BKPT_HARD)
cortex_a8->brp_num_available--;
return cortex_a8_set_context_breakpoint(target, breakpoint, 0x02); /* asid match */
}
static int cortex_a8_add_hybrid_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target);
if ((breakpoint->type == BKPT_HARD) && (cortex_a8->brp_num_available < 1))
{
LOG_INFO("no hardware breakpoint available");
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
}
if (breakpoint->type == BKPT_HARD)
cortex_a8->brp_num_available--;
return cortex_a8_set_hybrid_breakpoint(target, breakpoint); /* ??? */
}
static int cortex_a8_remove_breakpoint(struct target *target, struct breakpoint *breakpoint) static int cortex_a8_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
{ {
struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target); struct cortex_a8_common *cortex_a8 = target_to_cortex_a8(target);
...@@ -2546,6 +2774,8 @@ struct target_type cortexa8_target = { ...@@ -2546,6 +2774,8 @@ struct target_type cortexa8_target = {
.run_algorithm = armv4_5_run_algorithm, .run_algorithm = armv4_5_run_algorithm,
.add_breakpoint = cortex_a8_add_breakpoint, .add_breakpoint = cortex_a8_add_breakpoint,
.add_context_breakpoint = cortex_a8_add_context_breakpoint,
.add_hybrid_breakpoint = cortex_a8_add_hybrid_breakpoint,
.remove_breakpoint = cortex_a8_remove_breakpoint, .remove_breakpoint = cortex_a8_remove_breakpoint,
.add_watchpoint = NULL, .add_watchpoint = NULL,
.remove_watchpoint = NULL, .remove_watchpoint = NULL,
......
...@@ -772,6 +772,27 @@ int target_add_breakpoint(struct target *target, ...@@ -772,6 +772,27 @@ int target_add_breakpoint(struct target *target,
} }
return target->type->add_breakpoint(target, breakpoint); return target->type->add_breakpoint(target, breakpoint);
} }
int target_add_context_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted", target->cmd_name);
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_context_breakpoint(target, breakpoint);
}
int target_add_hybrid_breakpoint(struct target *target,
struct breakpoint *breakpoint)
{
if (target->state != TARGET_HALTED) {
LOG_WARNING("target %s is not halted", target->cmd_name);
return ERROR_TARGET_NOT_HALTED;
}
return target->type->add_hybrid_breakpoint(target, breakpoint);
}
int target_remove_breakpoint(struct target *target, int target_remove_breakpoint(struct target *target,
struct breakpoint *breakpoint) struct breakpoint *breakpoint)
{ {
...@@ -2919,7 +2940,7 @@ static int handle_bp_command_list(struct command_context *cmd_ctx) ...@@ -2919,7 +2940,7 @@ static int handle_bp_command_list(struct command_context *cmd_ctx)
{ {