jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / smp.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /***************************************************************************
4 * *
5 * Copyright (C) ST-Ericsson SA 2011 *
6 * Author: Michel Jaouen <michel.jaouen@stericsson.com> for ST-Ericsson. *
7 ***************************************************************************/
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12
13 #include "server/server.h"
14
15 #include "target/target.h"
16
17 #include "server/gdb_server.h"
18 #include "smp.h"
19 #include "helper/binarybuffer.h"
20
21 /* DEPRECATED: gdb_read_smp_packet/gdb_write_smp_packet to be removed */
22 /* implementation of new packet in gdb interface for smp feature */
23 /* */
24 /* j : smp status request */
25 /* J : smp set request */
26 /* */
27 /* jc :read core id displayed by gdb connection */
28 /* reply XXXXXXXX core id is int32_t , 8 hex digits */
29 /* */
30 /* Reply ENN error not supported (target not smp) */
31 /* */
32 /* JcXX set core id displayed at next gdb continue */
33 /* maximum 8 bytes described core id int32_t (8 hex digits) */
34 /* (core id -1 , reserved for returning to normal continue mode) */
35 /* Reply ENN error not supported(target not smp,core id out of range) */
36 /* Reply OK : for success */
37 /* */
38 /* handling of this packet within gdb can be done by the creation */
39 /* internal variable by mean of function allocate_computed_value */
40 /* set $_core 1 => Jc01 packet is sent */
41 /* print $_core => jc packet is sent and result is affected in $ */
42 /* Another way to test this packet is the usage of maintenance packet */
43 /* maint packet Jc01 */
44 /* maint packet jc */
45
46 /* packet j :smp status request */
47 #define DEPRECATED_MSG "DEPRECATED: This method is deprecated in favor of the hwthread pseudo RTOS"
48 int gdb_read_smp_packet(struct connection *connection,
49 char const *packet, int packet_size)
50 {
51 struct target *target = get_target_from_connection(connection);
52 int retval = ERROR_OK;
53
54 LOG_WARNING(DEPRECATED_MSG);
55
56 if (target->smp) {
57 if (strncmp(packet, "jc", 2) == 0) {
58 const uint32_t len = sizeof(target->gdb_service->core[0]);
59 char hex_buffer[len * 2 + 1];
60 uint8_t buffer[len];
61 buf_set_u32(buffer, 0, len * 8, target->gdb_service->core[0]);
62 size_t pkt_len = hexify(hex_buffer, buffer, sizeof(buffer),
63 sizeof(hex_buffer));
64
65 retval = gdb_put_packet(connection, hex_buffer, pkt_len);
66 }
67 } else
68 retval = gdb_put_packet(connection, "E01", 3);
69 return retval;
70 }
71
72 /* J : smp set request */
73 int gdb_write_smp_packet(struct connection *connection,
74 char const *packet, int packet_size)
75 {
76 struct target *target = get_target_from_connection(connection);
77 char *separator;
78 int coreid = 0;
79 int retval = ERROR_OK;
80
81 LOG_WARNING(DEPRECATED_MSG);
82
83 /* skip command character */
84 if (target->smp) {
85 if (strncmp(packet, "Jc", 2) == 0) {
86 packet += 2;
87 coreid = strtoul(packet, &separator, 16);
88 target->gdb_service->core[1] = coreid;
89 retval = gdb_put_packet(connection, "OK", 2);
90 }
91 } else
92 retval = gdb_put_packet(connection, "E01", 3);
93
94 return retval;
95 }
96
97 COMMAND_HANDLER(default_handle_smp_command)
98 {
99 struct target *target = get_current_target(CMD_CTX);
100 struct target_list *head;
101
102 if (CMD_ARGC > 1)
103 return ERROR_COMMAND_SYNTAX_ERROR;
104
105 if (!CMD_ARGC) {
106 command_print(CMD, "%s", target->smp ? "on" : "off");
107 return ERROR_OK;
108 }
109
110 if (!strcmp(CMD_ARGV[0], "on")) {
111 foreach_smp_target(head, target->smp_targets)
112 head->target->smp = 1;
113
114 return ERROR_OK;
115 }
116
117 if (!strcmp(CMD_ARGV[0], "off")) {
118 foreach_smp_target(head, target->smp_targets)
119 head->target->smp = 0;
120
121 /* fixes the target display to the debugger */
122 if (!list_empty(target->smp_targets))
123 target->gdb_service->target = target;
124
125 return ERROR_OK;
126 }
127
128 return ERROR_COMMAND_SYNTAX_ERROR;
129 }
130
131 COMMAND_HANDLER(handle_smp_gdb_command)
132 {
133 struct target *target = get_current_target(CMD_CTX);
134 int retval = ERROR_OK;
135
136 LOG_WARNING(DEPRECATED_MSG);
137
138 if (!list_empty(target->smp_targets)) {
139 if (CMD_ARGC == 1) {
140 int coreid = 0;
141 COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], coreid);
142 if (retval != ERROR_OK)
143 return retval;
144 target->gdb_service->core[1] = coreid;
145
146 }
147 command_print(CMD, "gdb coreid %" PRId32 " -> %" PRId32, target->gdb_service->core[0]
148 , target->gdb_service->core[1]);
149 }
150 return ERROR_OK;
151 }
152
153 const struct command_registration smp_command_handlers[] = {
154 {
155 .name = "smp",
156 .handler = default_handle_smp_command,
157 .mode = COMMAND_EXEC,
158 .help = "smp handling",
159 .usage = "[on|off]",
160 },
161 {
162 .name = "smp_gdb",
163 .handler = handle_smp_gdb_command,
164 .mode = COMMAND_EXEC,
165 .help = "display/fix current core played to gdb",
166 .usage = "",
167 },
168 COMMAND_REGISTRATION_DONE
169 };

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)