jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / espressif / esp_semihosting.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /***************************************************************************
4 * Semihosting API for Espressif chips *
5 * Copyright (C) 2022 Espressif Systems Ltd. *
6 ***************************************************************************/
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include <helper/log.h>
13 #include <target/target.h>
14 #include <target/semihosting_common.h>
15 #include "esp_semihosting.h"
16 #include "esp_xtensa.h"
17
18 static struct esp_semihost_data __attribute__((unused)) *target_to_esp_semihost_data(struct target *target)
19 {
20 struct xtensa *xtensa = target->arch_info;
21 if (xtensa->common_magic == XTENSA_COMMON_MAGIC)
22 return &target_to_esp_xtensa(target)->semihost;
23 /* TODO: add riscv */
24 LOG_ERROR("Unknown target arch!");
25 return NULL;
26 }
27
28 static int esp_semihosting_sys_seek(struct target *target, uint64_t fd, uint32_t pos, size_t whence)
29 {
30 struct semihosting *semihosting = target->semihosting;
31
32 semihosting->result = lseek(fd, pos, whence);
33 semihosting->sys_errno = errno;
34 LOG_TARGET_DEBUG(target, "lseek(%" PRIx64 ", %" PRIu32 " %" PRId64 ")=%d", fd, pos, semihosting->result, errno);
35 return ERROR_OK;
36 }
37
38 int esp_semihosting_common(struct target *target)
39 {
40 struct semihosting *semihosting = target->semihosting;
41 if (!semihosting)
42 /* Silently ignore if the semihosting field was not set. */
43 return ERROR_OK;
44
45 int retval = ERROR_NOT_IMPLEMENTED;
46
47 /* Enough space to hold 4 long words. */
48 uint8_t fields[4 * 8];
49
50 /*
51 * By default return an error.
52 * The actual result must be set by each function
53 */
54 semihosting->result = -1;
55 semihosting->sys_errno = EIO;
56
57 LOG_TARGET_DEBUG(target, "op=0x%x, param=0x%" PRIx64, semihosting->op, semihosting->param);
58
59 switch (semihosting->op) {
60 case ESP_SEMIHOSTING_SYS_DRV_INFO:
61 /* Return success to make esp-idf application happy */
62 retval = ERROR_OK;
63 semihosting->result = 0;
64 semihosting->sys_errno = 0;
65 break;
66
67 case ESP_SEMIHOSTING_SYS_SEEK:
68 retval = semihosting_read_fields(target, 3, fields);
69 if (retval == ERROR_OK) {
70 uint64_t fd = semihosting_get_field(target, 0, fields);
71 uint32_t pos = semihosting_get_field(target, 1, fields);
72 size_t whence = semihosting_get_field(target, 2, fields);
73 retval = esp_semihosting_sys_seek(target, fd, pos, whence);
74 }
75 break;
76
77 case ESP_SEMIHOSTING_SYS_APPTRACE_INIT:
78 case ESP_SEMIHOSTING_SYS_DEBUG_STUBS_INIT:
79 case ESP_SEMIHOSTING_SYS_BREAKPOINT_SET:
80 case ESP_SEMIHOSTING_SYS_WATCHPOINT_SET:
81 /* For the time being only riscv chips support these commands
82 * TODO: invoke riscv custom command handler */
83 break;
84 }
85
86 return retval;
87 }
88
89 int esp_semihosting_basedir_command(struct command_invocation *cmd)
90 {
91 struct target *target = get_current_target(CMD_CTX);
92
93 if (!target) {
94 LOG_ERROR("No target selected");
95 return ERROR_FAIL;
96 }
97
98 struct semihosting *semihosting = target->semihosting;
99 if (!semihosting) {
100 command_print(CMD, "semihosting not supported for current target");
101 return ERROR_FAIL;
102 }
103
104 if (!semihosting->is_active) {
105 if (semihosting->setup(target, true) != ERROR_OK) {
106 LOG_ERROR("Failed to Configure semihosting");
107 return ERROR_FAIL;
108 }
109 semihosting->is_active = true;
110 }
111
112 if (CMD_ARGC > 0) {
113 free(semihosting->basedir);
114 semihosting->basedir = strdup(CMD_ARGV[0]);
115 if (!semihosting->basedir) {
116 command_print(CMD, "semihosting failed to allocate memory for basedir!");
117 return ERROR_FAIL;
118 }
119 }
120
121 command_print(CMD, "DEPRECATED! semihosting base dir: %s",
122 semihosting->basedir ? semihosting->basedir : "");
123
124 return ERROR_OK;
125 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)