1
2
3
7
8
9
10
11
12
18
27
28
37
38
39
40
41
42
43
44
45
46
47
48
49
50
54
55
56
57
58
59
85
86
87
88
89
90
91
92
93
97
98
99
103
104
111
112
120
121
122
123
124
125
/* ... */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <helper/log.h>
#include <target/target.h>
#include <target/semihosting_common.h>
#include "esp_semihosting.h"
#include "esp_xtensa.h"
5 includes
static struct esp_semihost_data __attribute__((unused)) *target_to_esp_semihost_data(struct target *target)
{
struct xtensa *xtensa = target->arch_info;
if (xtensa->common_magic == XTENSA_COMMON_MAGIC)
return &target_to_esp_xtensa(target)->semihost;
LOG_ERROR("Unknown target arch!");
return NULL;
}{ ... }
static int esp_semihosting_sys_seek(struct target *target, uint64_t fd, uint32_t pos, size_t whence)
{
struct semihosting *semihosting = target->semihosting;
semihosting->result = lseek(fd, pos, whence);
semihosting->sys_errno = errno;
LOG_TARGET_DEBUG(target, "lseek(%" PRIx64 ", %" PRIu32 " %" PRId64 ")=%d", fd, pos, semihosting->result, errno);
return ERROR_OK;
}{ ... }
int esp_semihosting_common(struct target *target)
{
struct semihosting *semihosting = target->semihosting;
if (!semihosting)
return ERROR_OK;
int retval = ERROR_NOT_IMPLEMENTED;
uint8_t fields[4 * 8];
/* ... */
semihosting->result = -1;
semihosting->sys_errno = EIO;
LOG_TARGET_DEBUG(target, "op=0x%x, param=0x%" PRIx64, semihosting->op, semihosting->param);
switch (semihosting->op) {
case ESP_SEMIHOSTING_SYS_DRV_INFO:
retval = ERROR_OK;
semihosting->result = 0;
semihosting->sys_errno = 0;
break;
case ESP_SEMIHOSTING_SYS_DRV_INFO:
case ESP_SEMIHOSTING_SYS_SEEK:
retval = semihosting_read_fields(target, 3, fields);
if (retval == ERROR_OK) {
uint64_t fd = semihosting_get_field(target, 0, fields);
uint32_t pos = semihosting_get_field(target, 1, fields);
size_t whence = semihosting_get_field(target, 2, fields);
retval = esp_semihosting_sys_seek(target, fd, pos, whence);
}if (retval == ERROR_OK) { ... }
break;
case ESP_SEMIHOSTING_SYS_SEEK:
case ESP_SEMIHOSTING_SYS_APPTRACE_INIT:
case ESP_SEMIHOSTING_SYS_DEBUG_STUBS_INIT:
case ESP_SEMIHOSTING_SYS_BREAKPOINT_SET:
case ESP_SEMIHOSTING_SYS_WATCHPOINT_SET:
/* ... */
break;case ESP_SEMIHOSTING_SYS_WATCHPOINT_SET:
}switch (semihosting->op) { ... }
return retval;
}{ ... }
int esp_semihosting_basedir_command(struct command_invocation *cmd)
{
struct target *target = get_current_target(CMD_CTX);
if (!target) {
LOG_ERROR("No target selected");
return ERROR_FAIL;
}if (!target) { ... }
struct semihosting *semihosting = target->semihosting;
if (!semihosting) {
command_print(CMD, "semihosting not supported for current target");
return ERROR_FAIL;
}if (!semihosting) { ... }
if (!semihosting->is_active) {
if (semihosting->setup(target, true) != ERROR_OK) {
LOG_ERROR("Failed to Configure semihosting");
return ERROR_FAIL;
}if (semihosting->setup(target, true) != ERROR_OK) { ... }
semihosting->is_active = true;
}if (!semihosting->is_active) { ... }
if (CMD_ARGC > 0) {
free(semihosting->basedir);
semihosting->basedir = strdup(CMD_ARGV[0]);
if (!semihosting->basedir) {
command_print(CMD, "semihosting failed to allocate memory for basedir!");
return ERROR_FAIL;
}if (!semihosting->basedir) { ... }
}if (CMD_ARGC > 0) { ... }
command_print(CMD, "DEPRECATED! semihosting base dir: %s",
semihosting->basedir ? semihosting->basedir : "");
return ERROR_OK;
}{ ... }