Select one of the symbols to view example projects that use it.
 
Outline
#include "config.h"
#include <helper/log.h>
#include <target/target.h>
#include <target/semihosting_common.h>
#include "esp_semihosting.h"
#include "esp_xtensa.h"
target_to_esp_semihost_data(struct target *)
esp_semihosting_sys_seek(struct target *, uint64_t, uint32_t, size_t)
esp_semihosting_common(struct target *)
esp_semihosting_basedir_command(struct command_invocation *)
Files
loading...
CodeScopeDevelopment ToolsOpenOCDsrc/target/espressif/esp_semihosting.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// SPDX-License-Identifier: GPL-2.0-or-later /*************************************************************************** * Semihosting API for Espressif chips * * Copyright (C) 2022 Espressif Systems Ltd. * ***************************************************************************//* ... */ #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; /* TODO: add riscv */ 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) /* Silently ignore if the semihosting field was not set. */ return ERROR_OK; int retval = ERROR_NOT_IMPLEMENTED; /* Enough space to hold 4 long words. */ uint8_t fields[4 * 8]; /* * By default return an error. * The actual result must be set by each function *//* ... */ 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: /* Return success to make esp-idf application happy */ 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: /* For the time being only riscv chips support these commands * TODO: invoke riscv custom command handler *//* ... */ 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; }{ ... }