2010-11-04 08:33:10 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2008 by Spencer Oliver *
|
|
|
|
* spen@spen-soft.co.uk *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2010 by Drasko DRASKOVIC *
|
|
|
|
* drasko.draskovic@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-05-16 15:41:00 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2010-11-04 08:33:10 -05:00
|
|
|
***************************************************************************/
|
2012-02-05 06:03:04 -06:00
|
|
|
|
2010-11-04 08:33:10 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "arm946e.h"
|
|
|
|
#include "target_type.h"
|
|
|
|
#include "arm_opcodes.h"
|
|
|
|
|
|
|
|
#include "breakpoints.h"
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define _DEBUG_INSTRUCTION_EXECUTION_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NB_CACHE_WAYS 4
|
|
|
|
|
2012-07-30 18:50:09 -05:00
|
|
|
#define CP15_CTL 0x02
|
|
|
|
#define CP15_CTL_DCACHE (1<<2)
|
|
|
|
#define CP15_CTL_ICACHE (1<<12)
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* flag to give info about cache manipulation during debug :
|
|
|
|
* "0" - cache lines are invalidated "on the fly", for affected addresses.
|
2020-07-12 13:25:00 -05:00
|
|
|
* This is preferred from performance point of view.
|
2010-11-04 08:33:10 -05:00
|
|
|
* "1" - cache is invalidated and switched off on debug_entry, and switched back on on restore.
|
|
|
|
* It is kept off during debugging.
|
|
|
|
*/
|
|
|
|
static uint8_t arm946e_preserve_cache;
|
|
|
|
|
|
|
|
int arm946e_post_debug_entry(struct target *target);
|
|
|
|
void arm946e_pre_restore_context(struct target *target);
|
|
|
|
static int arm946e_read_cp15(struct target *target, int reg_addr, uint32_t *value);
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
int arm946e_init_arch_info(struct target *target,
|
|
|
|
struct arm946e_common *arm946e,
|
|
|
|
struct jtag_tap *tap)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
struct arm7_9_common *arm7_9 = &arm946e->arm7_9_common;
|
|
|
|
|
|
|
|
/* initialize arm7/arm9 specific info (including armv4_5) */
|
|
|
|
arm9tdmi_init_arch_info(target, arm7_9, tap);
|
|
|
|
|
|
|
|
arm946e->common_magic = ARM946E_COMMON_MAGIC;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ARM946E-S implements the ARMv5TE architecture which
|
|
|
|
* has the BKPT instruction, so we don't have to use a watchpoint comparator
|
|
|
|
*/
|
|
|
|
arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
|
|
|
|
arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
|
|
|
|
|
|
|
|
|
|
|
|
arm7_9->post_debug_entry = arm946e_post_debug_entry;
|
|
|
|
arm7_9->pre_restore_context = arm946e_pre_restore_context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* disabling linefills leads to lockups, so keep them enabled for now
|
|
|
|
* this doesn't affect correctness, but might affect timing issues, if
|
|
|
|
* important data is evicted from the cache during the debug session
|
|
|
|
*/
|
|
|
|
arm946e_preserve_cache = 0;
|
|
|
|
|
|
|
|
/* override hw single-step capability from ARM9TDMI */
|
2012-02-05 06:03:04 -06:00
|
|
|
/* arm7_9->has_single_step = 1; */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int arm946e_target_create(struct target *target, Jim_Interp *interp)
|
|
|
|
{
|
2012-02-05 06:03:04 -06:00
|
|
|
struct arm946e_common *arm946e = calloc(1, sizeof(struct arm946e_common));
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
arm946e_init_arch_info(target, arm946e, target->tap);
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2020-05-25 04:28:22 -05:00
|
|
|
static void arm946e_deinit_target(struct target *target)
|
|
|
|
{
|
|
|
|
struct arm *arm = target_to_arm(target);
|
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
|
|
|
|
|
|
|
arm7_9_deinit(target);
|
|
|
|
arm_free_reg_cache(arm);
|
|
|
|
free(arm946e);
|
|
|
|
}
|
|
|
|
|
2019-03-31 21:46:29 -05:00
|
|
|
static int arm946e_verify_pointer(struct command_invocation *cmd,
|
2012-02-05 06:03:04 -06:00
|
|
|
struct arm946e_common *arm946e)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
if (arm946e->common_magic != ARM946E_COMMON_MAGIC) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(cmd, "target is not an ARM946");
|
2010-11-04 08:33:10 -05:00
|
|
|
return ERROR_TARGET_INVALID;
|
|
|
|
}
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-08 14:21:31 -05:00
|
|
|
/*
|
|
|
|
* Update cp15_control_reg, saved on debug_entry.
|
|
|
|
*/
|
|
|
|
static void arm946e_update_cp15_caches(struct target *target, uint32_t value)
|
|
|
|
{
|
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
|
|
|
arm946e->cp15_control_reg = (arm946e->cp15_control_reg & ~(CP15_CTL_DCACHE|CP15_CTL_ICACHE))
|
|
|
|
| (value & (CP15_CTL_DCACHE|CP15_CTL_ICACHE));
|
|
|
|
}
|
|
|
|
|
2010-11-04 08:33:10 -05:00
|
|
|
/*
|
|
|
|
* REVISIT: The "read_cp15" and "write_cp15" commands could hook up
|
|
|
|
* to eventual mrc() and mcr() routines ... the reg_addr values being
|
|
|
|
* constructed (for CP15 only) from Opcode_1, Opcode_2, and CRn values.
|
|
|
|
* See section 7.3 of the ARM946E-S TRM.
|
|
|
|
*/
|
|
|
|
static int arm946e_read_cp15(struct target *target, int reg_addr, uint32_t *value)
|
|
|
|
{
|
|
|
|
int retval = ERROR_OK;
|
|
|
|
struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
|
|
|
|
struct arm_jtag *jtag_info = &arm7_9->jtag_info;
|
|
|
|
struct scan_field fields[3];
|
|
|
|
uint8_t reg_addr_buf = reg_addr & 0x3f;
|
|
|
|
uint8_t nr_w_buf = 0;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
|
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
2015-11-13 17:30:28 -06:00
|
|
|
retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
|
2010-11-04 08:33:10 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
fields[0].num_bits = 32;
|
|
|
|
/* REVISIT: table 7-2 shows that bits 31-31 need to be
|
|
|
|
* specified for accessing BIST registers ...
|
|
|
|
*/
|
|
|
|
fields[0].out_value = NULL;
|
|
|
|
fields[0].in_value = NULL;
|
|
|
|
|
|
|
|
fields[1].num_bits = 6;
|
|
|
|
fields[1].out_value = ®_addr_buf;
|
|
|
|
fields[1].in_value = NULL;
|
|
|
|
|
|
|
|
fields[2].num_bits = 1;
|
|
|
|
fields[2].out_value = &nr_w_buf;
|
|
|
|
fields[2].in_value = NULL;
|
|
|
|
|
|
|
|
jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
|
|
|
|
|
|
|
|
fields[0].in_value = (uint8_t *)value;
|
|
|
|
jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
|
|
|
|
|
|
|
|
jtag_add_callback(arm_le_to_h_u32, (jtag_callback_data_t)value);
|
|
|
|
|
|
|
|
#ifdef _DEBUG_INSTRUCTION_EXECUTION_
|
|
|
|
LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
|
|
|
|
#endif
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
retval = jtag_execute_queue();
|
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arm946e_write_cp15(struct target *target, int reg_addr, uint32_t value)
|
|
|
|
{
|
|
|
|
int retval = ERROR_OK;
|
|
|
|
struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
|
|
|
|
struct arm_jtag *jtag_info = &arm7_9->jtag_info;
|
|
|
|
struct scan_field fields[3];
|
|
|
|
uint8_t reg_addr_buf = reg_addr & 0x3f;
|
|
|
|
uint8_t nr_w_buf = 1;
|
|
|
|
uint8_t value_buf[4];
|
|
|
|
|
|
|
|
buf_set_u32(value_buf, 0, 32, value);
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
|
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
2015-11-13 17:30:28 -06:00
|
|
|
retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
|
2010-11-04 08:33:10 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
fields[0].num_bits = 32;
|
|
|
|
fields[0].out_value = value_buf;
|
|
|
|
fields[0].in_value = NULL;
|
|
|
|
|
|
|
|
fields[1].num_bits = 6;
|
|
|
|
fields[1].out_value = ®_addr_buf;
|
|
|
|
fields[1].in_value = NULL;
|
|
|
|
|
|
|
|
fields[2].num_bits = 1;
|
|
|
|
fields[2].out_value = &nr_w_buf;
|
|
|
|
fields[2].in_value = NULL;
|
|
|
|
|
|
|
|
jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
|
|
|
|
|
|
|
|
#ifdef _DEBUG_INSTRUCTION_EXECUTION_
|
|
|
|
LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
|
|
|
|
#endif
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
retval = jtag_execute_queue();
|
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-08 14:18:04 -05:00
|
|
|
#define GET_ICACHE_SIZE 6
|
|
|
|
#define GET_DCACHE_SIZE 18
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2012-06-08 14:18:04 -05:00
|
|
|
/*
|
|
|
|
* \param target struct target pointer
|
|
|
|
* \param idsel select GET_ICACHE_SIZE or GET_DCACHE_SIZE
|
|
|
|
* \returns cache size, given in bytes
|
|
|
|
*/
|
|
|
|
static uint32_t arm946e_cp15_get_csize(struct target *target, int idsel)
|
|
|
|
{
|
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
|
|
|
uint32_t csize = arm946e->cp15_cache_info;
|
|
|
|
if (csize == 0) {
|
|
|
|
if (arm946e_read_cp15(target, 0x01, &csize) == ERROR_OK)
|
|
|
|
arm946e->cp15_cache_info = csize;
|
|
|
|
}
|
|
|
|
if (csize & (1<<(idsel-4))) /* cache absent */
|
|
|
|
return 0;
|
|
|
|
csize = (csize >> idsel) & 0x0F;
|
|
|
|
return csize ? 1 << (12 + (csize-3)) : 0;
|
|
|
|
}
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2012-06-08 14:18:04 -05:00
|
|
|
uint32_t arm946e_invalidate_whole_dcache(struct target *target)
|
|
|
|
{
|
|
|
|
uint32_t csize = arm946e_cp15_get_csize(target, GET_DCACHE_SIZE);
|
2010-11-04 08:33:10 -05:00
|
|
|
if (csize == 0)
|
2012-06-08 14:18:04 -05:00
|
|
|
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2012-06-08 14:18:04 -05:00
|
|
|
/* One line (index) is 32 bytes (8 words) long, 4-way assoc
|
|
|
|
* ARM DDI 0201D, Section 3.3.5
|
|
|
|
*/
|
|
|
|
int nb_idx = (csize / (4*8*NB_CACHE_WAYS)); /* gives nb of lines (indexes) in the cache */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2020-07-12 13:25:00 -05:00
|
|
|
/* Loop for all segments (i.e. ways) */
|
2012-06-08 14:18:04 -05:00
|
|
|
uint32_t seg;
|
2012-02-05 06:03:04 -06:00
|
|
|
for (seg = 0; seg < NB_CACHE_WAYS; seg++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Loop for all indexes */
|
2012-06-08 14:18:04 -05:00
|
|
|
int idx;
|
2012-02-05 06:03:04 -06:00
|
|
|
for (idx = 0; idx < nb_idx; idx++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Form and write cp15 index (segment + line idx) */
|
2012-06-08 14:18:04 -05:00
|
|
|
uint32_t cp15_idx = seg << 30 | idx << 5;
|
|
|
|
int retval = arm946e_write_cp15(target, 0x3a, cp15_idx);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR writing index");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read dtag */
|
2012-06-08 14:18:04 -05:00
|
|
|
uint32_t dtag;
|
2019-12-20 16:43:55 -06:00
|
|
|
retval = arm946e_read_cp15(target, 0x16, &dtag);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
LOG_DEBUG("ERROR reading dtag");
|
|
|
|
return retval;
|
|
|
|
}
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/* Check cache line VALID bit */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!(dtag >> 4 & 0x1))
|
2010-11-04 08:33:10 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Clean data cache line */
|
|
|
|
retval = arm946e_write_cp15(target, 0x35, 0x1);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR cleaning cache line");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush data cache line */
|
|
|
|
retval = arm946e_write_cp15(target, 0x1a, 0x1);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR flushing cache line");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t arm946e_invalidate_whole_icache(struct target *target)
|
|
|
|
{
|
2012-06-08 14:18:04 -05:00
|
|
|
/* Check cache presence before flushing - avoid undefined behavior */
|
|
|
|
uint32_t csize = arm946e_cp15_get_csize(target, GET_ICACHE_SIZE);
|
|
|
|
if (csize == 0)
|
|
|
|
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
LOG_DEBUG("FLUSHING I$");
|
|
|
|
/**
|
|
|
|
* Invalidate (flush) I$
|
|
|
|
* mcr 15, 0, r0, cr7, cr5, {0}
|
|
|
|
*/
|
2012-06-08 14:18:04 -05:00
|
|
|
int retval = arm946e_write_cp15(target, 0x0f, 0x1);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR flushing I$");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int arm946e_post_debug_entry(struct target *target)
|
|
|
|
{
|
|
|
|
uint32_t ctr_reg = 0x0;
|
|
|
|
uint32_t retval = ERROR_OK;
|
2012-07-30 18:50:09 -05:00
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/* See if CACHES are enabled, and save that info
|
2012-07-30 18:50:09 -05:00
|
|
|
* in the context bits, so that arm946e_pre_restore_context() can use them */
|
2019-12-20 16:43:55 -06:00
|
|
|
arm946e_read_cp15(target, CP15_CTL, &ctr_reg);
|
2012-07-30 18:50:09 -05:00
|
|
|
|
|
|
|
/* Save control reg in the context */
|
|
|
|
arm946e->cp15_control_reg = ctr_reg;
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (arm946e_preserve_cache) {
|
2012-07-30 18:50:09 -05:00
|
|
|
if (ctr_reg & CP15_CTL_DCACHE) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Clean and flush D$ */
|
|
|
|
arm946e_invalidate_whole_dcache(target);
|
|
|
|
|
|
|
|
/* Disable D$ */
|
2012-07-30 18:50:09 -05:00
|
|
|
ctr_reg &= ~CP15_CTL_DCACHE;
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:50:09 -05:00
|
|
|
if (ctr_reg & CP15_CTL_ICACHE) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Flush I$ */
|
|
|
|
arm946e_invalidate_whole_icache(target);
|
|
|
|
|
|
|
|
/* Disable I$ */
|
2012-07-30 18:50:09 -05:00
|
|
|
ctr_reg &= ~CP15_CTL_ICACHE;
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the new configuration */
|
2012-07-30 18:50:09 -05:00
|
|
|
retval = arm946e_write_cp15(target, CP15_CTL, ctr_reg);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2010-11-04 08:33:10 -05:00
|
|
|
LOG_DEBUG("ERROR disabling cache");
|
|
|
|
return retval;
|
|
|
|
}
|
2012-02-05 06:03:04 -06:00
|
|
|
} /* if preserve_cache */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void arm946e_pre_restore_context(struct target *target)
|
|
|
|
{
|
|
|
|
uint32_t ctr_reg = 0x0;
|
|
|
|
uint32_t retval;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (arm946e_preserve_cache) {
|
2012-07-30 18:50:09 -05:00
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Get the contents of the CTR reg */
|
2019-12-20 16:43:55 -06:00
|
|
|
arm946e_read_cp15(target, CP15_CTL, &ctr_reg);
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/**
|
2012-07-30 18:50:09 -05:00
|
|
|
* Read-modify-write CP15 control
|
|
|
|
* to reenable I/D-cache operation
|
|
|
|
* NOTE: It is not possible to disable cache by CP15.
|
|
|
|
* if arm946e_preserve_cache debugging flag enabled.
|
2010-11-04 08:33:10 -05:00
|
|
|
*/
|
2012-07-30 18:50:09 -05:00
|
|
|
ctr_reg |= arm946e->cp15_control_reg & (CP15_CTL_DCACHE|CP15_CTL_ICACHE);
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/* Write the new configuration */
|
2012-07-30 18:50:09 -05:00
|
|
|
retval = arm946e_write_cp15(target, CP15_CTL, ctr_reg);
|
2010-11-04 08:33:10 -05:00
|
|
|
if (retval != ERROR_OK)
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR enabling cache");
|
2012-02-05 06:03:04 -06:00
|
|
|
} /* if preserve_cache */
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t arm946e_invalidate_dcache(struct target *target, uint32_t address,
|
2012-02-05 06:03:04 -06:00
|
|
|
uint32_t size, uint32_t count)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
uint32_t cur_addr = 0x0;
|
|
|
|
uint32_t cp15_idx, set, way, dtag;
|
|
|
|
uint32_t i = 0;
|
|
|
|
int retval;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (i = 0; i < count*size; i++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
cur_addr = address + i;
|
|
|
|
|
|
|
|
|
|
|
|
set = (cur_addr >> 5) & 0xff; /* set field is 8 bits long */
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (way = 0; way < NB_CACHE_WAYS; way++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/**
|
|
|
|
* Find if the affected address is kept in the cache.
|
|
|
|
* Because JTAG Scan Chain 15 offers limited approach,
|
|
|
|
* we have to loop through all cache ways (segments) and
|
|
|
|
* read cache tags, then compare them with with address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Form and write cp15 index (segment + line idx) */
|
|
|
|
cp15_idx = way << 30 | set << 5;
|
|
|
|
retval = arm946e_write_cp15(target, 0x3a, cp15_idx);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR writing index");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read dtag */
|
2019-12-20 16:43:55 -06:00
|
|
|
retval = arm946e_read_cp15(target, 0x16, &dtag);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
LOG_DEBUG("ERROR reading dtag");
|
|
|
|
return retval;
|
|
|
|
}
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/* Check cache line VALID bit */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!(dtag >> 4 & 0x1))
|
2010-11-04 08:33:10 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If line is valid and corresponds to affected address - invalidate it */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (dtag >> 5 == cur_addr >> 5) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Clean data cache line */
|
|
|
|
retval = arm946e_write_cp15(target, 0x35, 0x1);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR cleaning cache line");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush data cache line */
|
|
|
|
retval = arm946e_write_cp15(target, 0x1c, 0x1);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR flushing cache line");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2012-02-05 06:03:04 -06:00
|
|
|
} /* loop through all 4 ways */
|
|
|
|
} /* loop through all addresses */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t arm946e_invalidate_icache(struct target *target, uint32_t address,
|
2012-02-05 06:03:04 -06:00
|
|
|
uint32_t size, uint32_t count)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
uint32_t cur_addr = 0x0;
|
|
|
|
uint32_t cp15_idx, set, way, itag;
|
|
|
|
uint32_t i = 0;
|
|
|
|
int retval;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (i = 0; i < count*size; i++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
cur_addr = address + i;
|
|
|
|
|
|
|
|
set = (cur_addr >> 5) & 0xff; /* set field is 8 bits long */
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (way = 0; way < NB_CACHE_WAYS; way++) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Form and write cp15 index (segment + line idx) */
|
|
|
|
cp15_idx = way << 30 | set << 5;
|
|
|
|
retval = arm946e_write_cp15(target, 0x3a, cp15_idx);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR writing index");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read itag */
|
2019-12-20 16:43:55 -06:00
|
|
|
retval = arm946e_read_cp15(target, 0x17, &itag);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
LOG_DEBUG("ERROR reading itag");
|
|
|
|
return retval;
|
|
|
|
}
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
/* Check cache line VALID bit */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!(itag >> 4 & 0x1))
|
2010-11-04 08:33:10 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If line is valid and corresponds to affected address - invalidate it */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (itag >> 5 == cur_addr >> 5) {
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Flush I$ line */
|
|
|
|
retval = arm946e_write_cp15(target, 0x1d, 0x0);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK) {
|
2011-01-05 20:54:12 -06:00
|
|
|
LOG_DEBUG("ERROR flushing cache line");
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2012-02-05 06:03:04 -06:00
|
|
|
} /* way loop */
|
|
|
|
} /* addr loop */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Writes a buffer, in the specified word size, with current MMU settings. */
|
2013-09-23 03:27:03 -05:00
|
|
|
int arm946e_write_memory(struct target *target, target_addr_t address,
|
2012-02-05 06:03:04 -06:00
|
|
|
uint32_t size, uint32_t count, const uint8_t *buffer)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
LOG_DEBUG("-");
|
|
|
|
|
2012-07-30 18:50:09 -05:00
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
2010-11-04 08:33:10 -05:00
|
|
|
/* Invalidate D$ if it is ON */
|
2012-07-30 18:50:09 -05:00
|
|
|
if (!arm946e_preserve_cache && (arm946e->cp15_control_reg & CP15_CTL_DCACHE))
|
2010-11-04 08:33:10 -05:00
|
|
|
arm946e_invalidate_dcache(target, address, size, count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write memory
|
|
|
|
*/
|
2013-03-11 16:21:13 -05:00
|
|
|
retval = arm7_9_write_memory_opt(target, address, size, count, buffer);
|
2012-02-05 06:03:04 -06:00
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* *
|
|
|
|
* Invalidate I$ if it is ON.
|
|
|
|
*
|
|
|
|
* D$ has been cleaned and flushed before mem write thus forcing it to behave like write-through,
|
|
|
|
* because arm7_9_write_memory() has seen non-valid bit in D$
|
|
|
|
* and wrote data into physical RAM (without touching or allocating the cache line).
|
|
|
|
* From ARM946ES Technical Reference Manual we can see that it uses "allocate on read-miss"
|
|
|
|
* policy for both I$ and D$ (Chapter 3.2 and 3.3)
|
|
|
|
*
|
|
|
|
* Explanation :
|
|
|
|
* "ARM system developer's guide: designing and optimizing system software" by
|
|
|
|
* Andrew N. Sloss, Dominic Symes and Chris Wright,
|
|
|
|
* Chapter 12.3.3 Allocating Policy on a Cache Miss :
|
|
|
|
* A read allocate on cache miss policy allocates a cache line only during a read from main memory.
|
|
|
|
* If the victim cache line contains valid data, then it is written to main memory before the cache line
|
|
|
|
* is filled with new data.
|
|
|
|
* Under this strategy, a write of new data to memory does not update the contents of the cache memory
|
|
|
|
* unless a cache line was allocated on a previous read from main memory.
|
|
|
|
* If the cache line contains valid data, then the write updates the cache and may update the main memory if
|
|
|
|
* the cache write policy is write-through.
|
|
|
|
* If the data is not in the cache, the controller writes to main memory only.
|
|
|
|
*/
|
2012-07-30 18:50:09 -05:00
|
|
|
if (!arm946e_preserve_cache && (arm946e->cp15_control_reg & CP15_CTL_ICACHE))
|
2010-11-04 08:33:10 -05:00
|
|
|
arm946e_invalidate_icache(target, address, size, count);
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-23 03:27:03 -05:00
|
|
|
int arm946e_read_memory(struct target *target, target_addr_t address,
|
2012-02-05 06:03:04 -06:00
|
|
|
uint32_t size, uint32_t count, uint8_t *buffer)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
LOG_DEBUG("-");
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
retval = arm7_9_read_memory(target, address, size, count, buffer);
|
|
|
|
if (retval != ERROR_OK)
|
2010-11-04 08:33:10 -05:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-26 05:55:37 -05:00
|
|
|
COMMAND_HANDLER(arm946e_handle_cp15)
|
2010-11-04 08:33:10 -05:00
|
|
|
{
|
2012-06-08 14:21:31 -05:00
|
|
|
/* one or two arguments, access a single register (write if second argument is given) */
|
2019-03-26 05:55:37 -05:00
|
|
|
if (CMD_ARGC < 1 || CMD_ARGC > 2)
|
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2019-03-26 05:55:37 -05:00
|
|
|
struct target *target = get_current_target(CMD_CTX);
|
2012-06-08 14:21:31 -05:00
|
|
|
|
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
2019-03-31 21:46:29 -05:00
|
|
|
int retval = arm946e_verify_pointer(CMD, arm946e);
|
2010-11-04 08:33:10 -05:00
|
|
|
if (retval != ERROR_OK)
|
2019-03-26 05:55:37 -05:00
|
|
|
return retval;
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (target->state != TARGET_HALTED) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
|
2019-03-26 05:55:37 -05:00
|
|
|
return ERROR_TARGET_NOT_HALTED;
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
2012-06-08 14:21:31 -05:00
|
|
|
uint32_t address;
|
2019-03-26 05:55:37 -05:00
|
|
|
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
|
2010-11-04 08:33:10 -05:00
|
|
|
|
2019-03-26 05:55:37 -05:00
|
|
|
if (CMD_ARGC == 1) {
|
2012-06-08 14:21:31 -05:00
|
|
|
uint32_t value;
|
|
|
|
retval = arm946e_read_cp15(target, address, &value);
|
|
|
|
if (retval != ERROR_OK) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address);
|
2019-03-26 05:55:37 -05:00
|
|
|
return retval;
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
2012-06-08 14:21:31 -05:00
|
|
|
retval = jtag_execute_queue();
|
|
|
|
if (retval != ERROR_OK)
|
2019-03-26 05:55:37 -05:00
|
|
|
return retval;
|
|
|
|
|
2012-06-08 14:21:31 -05:00
|
|
|
/* Return value in hex format */
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "0x%08" PRIx32, value);
|
2019-03-26 05:55:37 -05:00
|
|
|
} else if (CMD_ARGC == 2) {
|
2012-06-08 14:21:31 -05:00
|
|
|
uint32_t value;
|
2019-03-26 05:55:37 -05:00
|
|
|
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
|
|
|
|
|
2012-06-08 14:21:31 -05:00
|
|
|
retval = arm946e_write_cp15(target, address, value);
|
|
|
|
if (retval != ERROR_OK) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address);
|
2019-03-26 05:55:37 -05:00
|
|
|
return retval;
|
2012-06-08 14:21:31 -05:00
|
|
|
}
|
|
|
|
if (address == CP15_CTL)
|
|
|
|
arm946e_update_cp15_caches(target, value);
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
2019-03-26 05:55:37 -05:00
|
|
|
return ERROR_OK;
|
2010-11-04 08:33:10 -05:00
|
|
|
}
|
|
|
|
|
2012-06-08 14:24:13 -05:00
|
|
|
COMMAND_HANDLER(arm946e_handle_idcache)
|
|
|
|
{
|
|
|
|
if (CMD_ARGC > 1)
|
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
|
|
|
|
|
|
|
int retval;
|
|
|
|
struct target *target = get_current_target(CMD_CTX);
|
|
|
|
struct arm946e_common *arm946e = target_to_arm946(target);
|
|
|
|
|
2019-03-31 21:46:29 -05:00
|
|
|
retval = arm946e_verify_pointer(CMD, arm946e);
|
2012-06-08 14:24:13 -05:00
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
if (target->state != TARGET_HALTED) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
|
2012-06-08 14:24:13 -05:00
|
|
|
return ERROR_TARGET_NOT_HALTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool icache = (strcmp(CMD_NAME, "icache") == 0);
|
|
|
|
uint32_t csize = arm946e_cp15_get_csize(target, icache ? GET_ICACHE_SIZE : GET_DCACHE_SIZE) / 1024;
|
|
|
|
if (CMD_ARGC == 0) {
|
|
|
|
bool bena = ((arm946e->cp15_control_reg & (icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE)) != 0)
|
|
|
|
&& (arm946e->cp15_control_reg & 0x1);
|
|
|
|
if (csize == 0)
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "%s-cache absent", icache ? "I" : "D");
|
2012-06-08 14:24:13 -05:00
|
|
|
else
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "%s-cache size: %" PRIu32 "K, %s",
|
2013-09-30 04:31:57 -05:00
|
|
|
icache ? "I" : "D", csize, bena ? "enabled" : "disabled");
|
2012-06-08 14:24:13 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool flush = false;
|
|
|
|
bool enable = false;
|
|
|
|
retval = command_parse_bool_arg(CMD_ARGV[0], &enable);
|
|
|
|
if (retval == ERROR_COMMAND_SYNTAX_ERROR) {
|
|
|
|
if (strcmp(CMD_ARGV[0], "flush") == 0) {
|
|
|
|
flush = true;
|
|
|
|
retval = ERROR_OK;
|
|
|
|
} else
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not invalidate or change state, if cache is absent */
|
|
|
|
if (csize == 0) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]);
|
2012-06-08 14:24:13 -05:00
|
|
|
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: flushing entire cache will not preserve lock-down cache regions */
|
|
|
|
if (icache) {
|
|
|
|
if ((arm946e->cp15_control_reg & CP15_CTL_ICACHE) && !enable)
|
|
|
|
retval = arm946e_invalidate_whole_icache(target);
|
|
|
|
} else {
|
|
|
|
if ((arm946e->cp15_control_reg & CP15_CTL_DCACHE) && !enable)
|
|
|
|
retval = arm946e_invalidate_whole_dcache(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != ERROR_OK || flush)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
uint32_t value;
|
|
|
|
retval = arm946e_read_cp15(target, CP15_CTL, &value);
|
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
uint32_t vnew = value;
|
|
|
|
uint32_t cmask = icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE;
|
|
|
|
if (enable) {
|
|
|
|
if ((value & 0x1) == 0)
|
|
|
|
LOG_WARNING("arm946e: MPU must be enabled for cache to operate");
|
|
|
|
vnew |= cmask;
|
|
|
|
} else
|
|
|
|
vnew &= ~cmask;
|
|
|
|
|
|
|
|
if (vnew == value)
|
|
|
|
return ERROR_OK;
|
|
|
|
|
|
|
|
retval = arm946e_write_cp15(target, CP15_CTL, vnew);
|
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
arm946e_update_cp15_caches(target, vnew);
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-04 08:33:10 -05:00
|
|
|
static const struct command_registration arm946e_exec_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "cp15",
|
2019-03-26 05:55:37 -05:00
|
|
|
.handler = arm946e_handle_cp15,
|
2010-11-04 08:33:10 -05:00
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.usage = "regnum [value]",
|
2012-06-08 14:21:31 -05:00
|
|
|
.help = "read/modify cp15 register",
|
2010-11-04 08:33:10 -05:00
|
|
|
},
|
2012-06-08 14:24:13 -05:00
|
|
|
{
|
|
|
|
.name = "icache",
|
|
|
|
.handler = arm946e_handle_idcache,
|
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.usage = "['enable'|'disable'|'flush']",
|
|
|
|
.help = "I-cache info and operations",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "dcache",
|
|
|
|
.handler = arm946e_handle_idcache,
|
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.usage = "['enable'|'disable'|'flush']",
|
|
|
|
.help = "D-cache info and operations",
|
|
|
|
},
|
2010-11-04 08:33:10 -05:00
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct command_registration arm946e_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.chain = arm9tdmi_command_handlers,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "arm946e",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.help = "arm946e command group",
|
2012-01-16 07:35:23 -06:00
|
|
|
.usage = "",
|
2010-11-04 08:33:10 -05:00
|
|
|
.chain = arm946e_exec_command_handlers,
|
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Holds methods for ARM946 targets. */
|
2012-02-05 06:03:04 -06:00
|
|
|
struct target_type arm946e_target = {
|
2010-11-04 08:33:10 -05:00
|
|
|
.name = "arm946e",
|
|
|
|
|
|
|
|
.poll = arm7_9_poll,
|
|
|
|
.arch_state = arm_arch_state,
|
|
|
|
|
|
|
|
.target_request_data = arm7_9_target_request_data,
|
|
|
|
|
|
|
|
.halt = arm7_9_halt,
|
|
|
|
.resume = arm7_9_resume,
|
|
|
|
.step = arm7_9_step,
|
|
|
|
|
|
|
|
.assert_reset = arm7_9_assert_reset,
|
|
|
|
.deassert_reset = arm7_9_deassert_reset,
|
|
|
|
.soft_reset_halt = arm7_9_soft_reset_halt,
|
|
|
|
|
target/arm: add support for multi-architecture gdb
GDB can be built for multi-architecture through the command
./configure --enable-targets=all && make
Such multi-architecture GDB requires the target's architecture to
be selected either manually by the user through the GDB command
"set architecture" or automatically by the target description sent
by the remote target (i.e. OpenOCD).
Commit e65acd889c61a424c7bd72fdee5d6a3aee1d8504 ("gdb_server: add
support for architecture element") already provides the required
infrastructure to support multi-architecture gdb.
arm-none-eabi-gdb 8.2 uses "arm" as default architecture, but also
supports the following values: "arm_any", "armv2", "armv2a",
"armv3", "armv3m", "armv4", "armv4t", "armv5", "armv5t", "armv5te",
"armv5tej", "armv6", "armv6k", "armv6kz", "armv6-m", "armv6s-m",
"armv6t2", "armv7", "armv7e-m", "armv8-a", "armv8-m.base",
"armv8-m.main", "armv8-r", "ep9312", "iwmmxt", "iwmmxt2", "xscale".
These values can be displayed on arm gdb prompt by typing
"set architecture " followed by a TAB for autocompletion.
Set the gdb architecture value for all arm targets to "arm".
Change-Id: I176cb89878606e1febd546ce26543b3e7849500a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4754
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-11-01 08:50:27 -05:00
|
|
|
.get_gdb_arch = arm_get_gdb_arch,
|
2010-11-04 08:33:10 -05:00
|
|
|
.get_gdb_reg_list = arm_get_gdb_reg_list,
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
/* .read_memory = arm7_9_read_memory, */
|
|
|
|
/* .write_memory = arm7_9_write_memory, */
|
2010-11-04 08:33:10 -05:00
|
|
|
.read_memory = arm946e_read_memory,
|
|
|
|
.write_memory = arm946e_write_memory,
|
|
|
|
|
|
|
|
.checksum_memory = arm_checksum_memory,
|
|
|
|
.blank_check_memory = arm_blank_check_memory,
|
|
|
|
|
|
|
|
.run_algorithm = armv4_5_run_algorithm,
|
|
|
|
|
|
|
|
.add_breakpoint = arm7_9_add_breakpoint,
|
|
|
|
.remove_breakpoint = arm7_9_remove_breakpoint,
|
2012-02-05 06:03:04 -06:00
|
|
|
/* .add_breakpoint = arm946e_add_breakpoint, */
|
|
|
|
/* .remove_breakpoint = arm946e_remove_breakpoint, */
|
2010-11-04 08:33:10 -05:00
|
|
|
|
|
|
|
.add_watchpoint = arm7_9_add_watchpoint,
|
|
|
|
.remove_watchpoint = arm7_9_remove_watchpoint,
|
|
|
|
|
|
|
|
.commands = arm946e_command_handlers,
|
|
|
|
.target_create = arm946e_target_create,
|
|
|
|
.init_target = arm9tdmi_init_target,
|
2020-05-25 04:28:22 -05:00
|
|
|
.deinit_target = arm946e_deinit_target,
|
2010-11-04 08:33:10 -05:00
|
|
|
.examine = arm7_9_examine,
|
|
|
|
.check_reset = arm7_9_check_reset,
|
|
|
|
};
|