mirror of
https://github.com/linux-msm/openocd.git
synced 2026-02-25 13:15:07 -08:00
semihosting: support fileio operation
This patch adds support for bridging semihosting to GDB's File-I/O remote protocol extension. For the most part operations match up 1:1, however some require a working area to complete successfully, namely operations that devolve to read, stat, and gettimeofday. A new command was added to enable support for fileio named `arm semihosting_fileio`, which ensures that the default behavior remains intact for those that prefer it. Finally, redundant logging was removed from the target_arch_state function; this permits ARM targets to quiesce log output when polling for a fileio reply. This prevents filling the logs with halt/resume messages when using semihosting fileio. Change-Id: Ifbb864fc2373336a501cc0332675b887b552e1ee Signed-off-by: Steven Stallion <stallion@squareup.com> Reviewed-on: http://openocd.zylin.com/3566 Tested-by: jenkins Reviewed-by: Steven Stallion <sstallion@gmail.com> Reviewed-by: Paul Fertser <fercerpav@gmail.com>
This commit is contained in:
committed by
Paul Fertser
parent
dc0a009ef4
commit
c0e7ccbd87
@@ -7404,6 +7404,17 @@ requests by using a special SVC instruction that is trapped at the
|
||||
Supervisor Call vector by OpenOCD.
|
||||
@end deffn
|
||||
|
||||
@deffn Command {arm semihosting_fileio} [@option{enable}|@option{disable}]
|
||||
@cindex ARM semihosting
|
||||
Display status of semihosting fileio, after optionally changing that
|
||||
status.
|
||||
|
||||
Enabling this option forwards semihosting I/O to GDB process using the
|
||||
File-I/O remote protocol extension. This is especially useful for
|
||||
interacting with remote files or displaying console messages in the
|
||||
debugger.
|
||||
@end deffn
|
||||
|
||||
@section ARMv4 and ARMv5 Architecture
|
||||
@cindex ARMv4
|
||||
@cindex ARMv5
|
||||
|
||||
@@ -130,6 +130,18 @@ struct arm {
|
||||
/** Flag reporting whether semihosting is active. */
|
||||
bool is_semihosting;
|
||||
|
||||
/** Flag reporting whether semihosting fileio is active. */
|
||||
bool is_semihosting_fileio;
|
||||
|
||||
/** Flag reporting whether semihosting fileio operation is active. */
|
||||
bool semihosting_hit_fileio;
|
||||
|
||||
/** Current semihosting operation. */
|
||||
int semihosting_op;
|
||||
|
||||
/** Current semihosting result. */
|
||||
int semihosting_result;
|
||||
|
||||
/** Value to be returned by semihosting SYS_ERRNO request. */
|
||||
int semihosting_errno;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "target_type.h"
|
||||
#include "register.h"
|
||||
#include "arm_opcodes.h"
|
||||
#include "arm_semihosting.h"
|
||||
|
||||
/*
|
||||
* For information about ARM7TDMI, see ARM DDI 0210C (r4p1)
|
||||
@@ -615,7 +616,7 @@ static void arm7tdmi_build_reg_cache(struct target *target)
|
||||
int arm7tdmi_init_target(struct command_context *cmd_ctx, struct target *target)
|
||||
{
|
||||
arm7tdmi_build_reg_cache(target);
|
||||
|
||||
arm_semihosting_init(target);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "target_type.h"
|
||||
#include "register.h"
|
||||
#include "arm_opcodes.h"
|
||||
#include "arm_semihosting.h"
|
||||
|
||||
/*
|
||||
* NOTE: this holds code that's used with multiple ARM9 processors:
|
||||
@@ -714,6 +715,7 @@ int arm9tdmi_init_target(struct command_context *cmd_ctx,
|
||||
struct target *target)
|
||||
{
|
||||
arm9tdmi_build_reg_cache(target);
|
||||
arm_semihosting_init(target);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,6 +19,7 @@
|
||||
#ifndef OPENOCD_TARGET_ARM_SEMIHOSTING_H
|
||||
#define OPENOCD_TARGET_ARM_SEMIHOSTING_H
|
||||
|
||||
int arm_semihosting_init(struct target *target);
|
||||
int arm_semihosting(struct target *target, int *retval);
|
||||
|
||||
#endif /* OPENOCD_TARGET_ARM_SEMIHOSTING_H */
|
||||
|
||||
@@ -666,14 +666,19 @@ int arm_arch_state(struct target *target)
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
/* avoid filling log waiting for fileio reply */
|
||||
if (arm->semihosting_hit_fileio)
|
||||
return ERROR_OK;
|
||||
|
||||
LOG_USER("target halted in %s state due to %s, current mode: %s\n"
|
||||
"cpsr: 0x%8.8" PRIx32 " pc: 0x%8.8" PRIx32 "%s",
|
||||
"cpsr: 0x%8.8" PRIx32 " pc: 0x%8.8" PRIx32 "%s%s",
|
||||
arm_state_strings[arm->core_state],
|
||||
debug_reason_name(target),
|
||||
arm_mode_name(arm->core_mode),
|
||||
buf_get_u32(arm->cpsr->value, 0, 32),
|
||||
buf_get_u32(arm->pc->value, 0, 32),
|
||||
arm->is_semihosting ? ", semihosting" : "");
|
||||
arm->is_semihosting ? ", semihosting" : "",
|
||||
arm->is_semihosting_fileio ? " fileio" : "");
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
@@ -1055,6 +1060,37 @@ COMMAND_HANDLER(handle_arm_semihosting_command)
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
COMMAND_HANDLER(handle_arm_semihosting_fileio_command)
|
||||
{
|
||||
struct target *target = get_current_target(CMD_CTX);
|
||||
|
||||
if (target == NULL) {
|
||||
LOG_ERROR("No target selected");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
struct arm *arm = target_to_arm(target);
|
||||
|
||||
if (!is_arm(arm)) {
|
||||
command_print(CMD_CTX, "current target isn't an ARM");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
if (!arm->is_semihosting) {
|
||||
command_print(CMD_CTX, "semihosting is not enabled");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
if (CMD_ARGC > 0)
|
||||
COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm->is_semihosting_fileio);
|
||||
|
||||
command_print(CMD_CTX, "semihosting fileio is %s",
|
||||
arm->is_semihosting_fileio
|
||||
? "enabled" : "disabled");
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static const struct command_registration arm_exec_command_handlers[] = {
|
||||
{
|
||||
.name = "reg",
|
||||
@@ -1097,6 +1133,13 @@ static const struct command_registration arm_exec_command_handlers[] = {
|
||||
.usage = "['enable'|'disable']",
|
||||
.help = "activate support for semihosting operations",
|
||||
},
|
||||
{
|
||||
"semihosting_fileio",
|
||||
.handler = handle_arm_semihosting_fileio_command,
|
||||
.mode = COMMAND_EXEC,
|
||||
.usage = "['enable'|'disable']",
|
||||
.help = "activate support for semihosting fileio operations",
|
||||
},
|
||||
|
||||
COMMAND_REGISTRATION_DONE
|
||||
};
|
||||
|
||||
@@ -536,11 +536,15 @@ int armv7m_arch_state(struct target *target)
|
||||
struct arm *arm = &armv7m->arm;
|
||||
uint32_t ctrl, sp;
|
||||
|
||||
/* avoid filling log waiting for fileio reply */
|
||||
if (arm->semihosting_hit_fileio)
|
||||
return ERROR_OK;
|
||||
|
||||
ctrl = buf_get_u32(arm->core_cache->reg_list[ARMV7M_CONTROL].value, 0, 32);
|
||||
sp = buf_get_u32(arm->core_cache->reg_list[ARMV7M_R13].value, 0, 32);
|
||||
|
||||
LOG_USER("target halted due to %s, current mode: %s %s\n"
|
||||
"xPSR: %#8.8" PRIx32 " pc: %#8.8" PRIx32 " %csp: %#8.8" PRIx32 "%s",
|
||||
"xPSR: %#8.8" PRIx32 " pc: %#8.8" PRIx32 " %csp: %#8.8" PRIx32 "%s%s",
|
||||
debug_reason_name(target),
|
||||
arm_mode_name(arm->core_mode),
|
||||
armv7m_exception_string(armv7m->exception_number),
|
||||
@@ -548,7 +552,8 @@ int armv7m_arch_state(struct target *target)
|
||||
buf_get_u32(arm->pc->value, 0, 32),
|
||||
(ctrl & 0x02) ? 'p' : 'm',
|
||||
sp,
|
||||
arm->is_semihosting ? ", semihosting" : "");
|
||||
arm->is_semihosting ? ", semihosting" : "",
|
||||
arm->is_semihosting_fileio ? " fileio" : "");
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
@@ -3103,6 +3103,7 @@ static int cortex_a_init_target(struct command_context *cmd_ctx,
|
||||
struct target *target)
|
||||
{
|
||||
/* examine_first() does a bunch of this */
|
||||
arm_semihosting_init(target);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1696,6 +1696,7 @@ static int cortex_m_init_target(struct command_context *cmd_ctx,
|
||||
struct target *target)
|
||||
{
|
||||
armv7m_build_reg_cache(target);
|
||||
arm_semihosting_init(target);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ static int adapter_init_target(struct command_context *cmd_ctx,
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
armv7m_build_reg_cache(target);
|
||||
|
||||
arm_semihosting_init(target);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1944,13 +1944,10 @@ int target_arch_state(struct target *target)
|
||||
{
|
||||
int retval;
|
||||
if (target == NULL) {
|
||||
LOG_USER("No target has been configured");
|
||||
LOG_WARNING("No target has been configured");
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
LOG_USER("%s: target state: %s", target_name(target),
|
||||
target_state_name(target));
|
||||
|
||||
if (target->state != TARGET_HALTED)
|
||||
return ERROR_OK;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user