ccbc2be434916998ac5692df499a74b132ba4af1
[openocd.git] / src / target / smp.c
blobccbc2be434916998ac5692df499a74b132ba4af1
1 /***************************************************************************
2 * *
3 * Copyright (C) ST-Ericsson SA 2011 *
4 * Author: Michel Jaouen <michel.jaouen@stericsson.com> for ST-Ericsson. *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
25 #include "server/server.h"
27 #include "target/target.h"
29 #include "server/gdb_server.h"
30 #include "smp.h"
32 /* implementation of new packet in gdb interface for smp feature */
33 /* */
34 /* j : smp status request */
35 /* J : smp set request */
36 /* */
37 /* jc :read core id displayed by gdb connection */
38 /* reply XXXXXXXX core id is int32_t , 8 hex digits */
39 /* */
40 /* Reply ENN error not supported (target not smp) */
41 /* */
42 /* JcXX set core id displayed at next gdb continue */
43 /* maximum 8 bytes described core id int32_t (8 hex digits) */
44 /* (core id -1 , reserved for returning to normal continue mode) */
45 /* Reply ENN error not supported(target not smp,core id out of range) */
46 /* Reply OK : for success */
47 /* */
48 /* handling of this packet within gdb can be done by the creation */
49 /* internal variable by mean of function allocate_computed_value */
50 /* set $_core 1 => Jc01 packet is sent */
51 /* print $_core => jc packet is sent and result is affected in $ */
52 /* Another way to test this packet is the usage of maintenance packet */
53 /* maint packet Jc01 */
54 /* maint packet jc */
56 static const char DIGITS[16] = "0123456789abcdef";
58 /* packet j :smp status request */
59 int gdb_read_smp_packet(struct connection *connection,
60 char *packet, int packet_size)
62 struct target *target = get_target_from_connection(connection);
63 uint32_t len = sizeof(int32_t);
64 uint8_t *buffer;
65 char *hex_buffer;
66 int retval = ERROR_OK;
67 if (target->smp) {
68 if (strncmp(packet, "jc", 2) == 0) {
69 hex_buffer = malloc(len * 2 + 1);
70 buffer = (uint8_t *)&target->gdb_service->core[0];
71 uint32_t i;
72 for (i = 0; i < 4; i++) {
73 uint8_t t = buffer[i];
74 hex_buffer[2 * i] = DIGITS[(t >> 4) & 0xf];
75 hex_buffer[2 * i + 1] = DIGITS[t & 0xf];
78 retval = gdb_put_packet(connection, hex_buffer, len * 2);
80 free(hex_buffer);
82 } else
83 retval = gdb_put_packet(connection, "E01", 3);
84 return retval;
87 /* J : smp set request */
88 int gdb_write_smp_packet(struct connection *connection,
89 char *packet, int packet_size)
91 struct target *target = get_target_from_connection(connection);
92 char *separator;
93 int coreid = 0;
94 int retval = ERROR_OK;
96 /* skip command character */
97 if (target->smp) {
98 if (strncmp(packet, "Jc", 2) == 0) {
99 packet += 2;
100 coreid = strtoul(packet, &separator, 16);
101 target->gdb_service->core[1] = coreid;
102 retval = gdb_put_packet(connection, "OK", 2);
104 } else
105 retval = gdb_put_packet(connection, "E01", 3);
107 return retval;