]> git.sur5r.net Git - openocd/blob - src/target/smp.c
cleanup trailing whitespaces
[openocd] / src / target / smp.c
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  ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "server/server.h"
25 #include <helper/types.h>
26
27 #include "target/target.h"
28
29 #include "server/gdb_server.h"
30 #include "smp.h"
31
32
33 /*  implementation of new packet in gdb interface for smp feature          */
34 /*                                                                         */
35 /*   j : smp  status request                                               */
36 /*   J : smp  set request                                                  */
37 /*                                                                         */
38 /*   jc :read core id displayed by gdb connection                          */
39 /*   reply XXXXXXXX core id is int32_t , 8 hex digits                      */
40 /*                                                                         */
41 /*   Reply ENN error not supported (target not smp)                        */
42 /*                                                                         */
43 /*   JcXX  set core id displayed at next gdb continue                      */
44 /*   maximum 8 bytes described core id int32_t (8 hex digits)              */
45 /*  (core id -1 , reserved for returning to normal continue mode) */
46 /*  Reply ENN error not supported(target not smp,core id out of range)     */
47 /*  Reply OK : for success                                                 */
48 /*                                                                         */
49 /*  handling of this packet within gdb can be done by the creation         */
50 /*  internal variable by mean of function allocate_computed_value          */
51 /*  set $_core 1 => Jc01 packet is sent                                    */
52 /*  print $_core => jc packet is sent and result is affected in $          */
53 /*  Another way to test this packet is the usage of maintenance packet     */
54 /*  maint packet Jc01                                                      */
55 /*  maint packet jc                                                        */
56                                                 
57 static const char DIGITS[16] = "0123456789abcdef";
58
59
60 /* packet j :smp status request */
61 int gdb_read_smp_packet(struct connection *connection,
62                 struct target *target, char *packet, int packet_size)
63 {
64         uint32_t len = sizeof(int32_t);
65         uint8_t *buffer;
66         char *hex_buffer;
67         int retval = ERROR_OK;
68         if (target->smp)
69         {
70                 if (strstr(packet, "jc"))
71                 {
72                         hex_buffer = malloc(len * 2 + 1);
73                         buffer = (uint8_t *)&target->gdb_service->core[0];
74                         uint32_t i;
75                         for (i = 0; i < 4; i++)
76                         {
77                                 uint8_t t = buffer[i];
78                                 hex_buffer[2 * i] = DIGITS[(t >> 4) & 0xf];
79                                 hex_buffer[2 * i + 1] = DIGITS[t & 0xf];
80                         }
81
82                         gdb_put_packet(connection, hex_buffer, len * 2);
83
84                         free(hex_buffer);
85                 }
86         }
87         else
88                 retval = gdb_put_packet(connection,"E01",3);
89         return retval;
90 }
91
92 /* J :  smp set request */
93 int gdb_write_smp_packet(struct connection *connection,
94                 struct target *target, char *packet, int packet_size)
95 {
96         char *separator;
97         int coreid = 0;
98
99         /* skip command character */
100         if (target->smp)
101         {
102                 if (strstr(packet, "Jc"))
103                 {
104                         packet+=2;
105                         coreid = strtoul(packet, &separator, 16);
106                         target->gdb_service->core[1] = coreid;
107                         gdb_put_packet(connection, "OK", 2);
108                 }
109         }
110         else
111         {
112                 gdb_put_packet(connection,"E01",3);
113         }
114
115         return ERROR_OK;
116 }