OpenOCD
jtag_vpi.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  * JTAG to VPI driver
5  *
6  * Copyright (C) 2013 Franck Jullien, <elec4fun@gmail.com>
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  */
11 
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include <jtag/interface.h>
17 #ifdef HAVE_ARPA_INET_H
18 #include <arpa/inet.h>
19 #endif
20 
21 #ifndef _WIN32
22 #include <netinet/tcp.h>
23 #endif
24 
25 #include "helper/replacements.h"
26 
27 #define NO_TAP_SHIFT 0
28 #define TAP_SHIFT 1
29 
30 #define DEFAULT_SERVER_ADDRESS "127.0.0.1"
31 #define DEFAULT_SERVER_PORT 5555
32 
33 #define XFERT_MAX_SIZE 512
34 
35 #define CMD_RESET 0
36 #define CMD_TMS_SEQ 1
37 #define CMD_SCAN_CHAIN 2
38 #define CMD_SCAN_CHAIN_FLIP_TMS 3
39 #define CMD_STOP_SIMU 4
40 
41 /* jtag_vpi server port and address to connect to */
43 static char *server_address;
44 
45 /* Send CMD_STOP_SIMU to server when OpenOCD exits? */
46 static bool stop_sim_on_exit;
47 
48 static int sockfd;
49 static struct sockaddr_in serv_addr;
50 
51 /* One jtag_vpi "packet" as sent over a TCP channel. */
52 struct vpi_cmd {
53  union {
54  uint32_t cmd;
55  unsigned char cmd_buf[4];
56  };
57  unsigned char buffer_out[XFERT_MAX_SIZE];
58  unsigned char buffer_in[XFERT_MAX_SIZE];
59  union {
60  uint32_t length;
61  unsigned char length_buf[4];
62  };
63  union {
64  uint32_t nb_bits;
65  unsigned char nb_bits_buf[4];
66  };
67 };
68 
69 static char *jtag_vpi_cmd_to_str(int cmd_num)
70 {
71  switch (cmd_num) {
72  case CMD_RESET:
73  return "CMD_RESET";
74  case CMD_TMS_SEQ:
75  return "CMD_TMS_SEQ";
76  case CMD_SCAN_CHAIN:
77  return "CMD_SCAN_CHAIN";
79  return "CMD_SCAN_CHAIN_FLIP_TMS";
80  case CMD_STOP_SIMU:
81  return "CMD_STOP_SIMU";
82  default:
83  return "<unknown>";
84  }
85 }
86 
87 static int jtag_vpi_send_cmd(struct vpi_cmd *vpi)
88 {
89  int retval;
90 
91  /* Optional low-level JTAG debug */
93  if (vpi->nb_bits > 0) {
94  /* command with a non-empty data payload */
95  char *char_buf = buf_to_hex_str(vpi->buffer_out,
96  (vpi->nb_bits > DEBUG_JTAG_IOZ)
98  : vpi->nb_bits);
99  LOG_DEBUG_IO("sending JTAG VPI cmd: cmd=%s, "
100  "length=%" PRIu32 ", "
101  "nb_bits=%" PRIu32 ", "
102  "buf_out=0x%s%s",
103  jtag_vpi_cmd_to_str(vpi->cmd),
104  vpi->length,
105  vpi->nb_bits,
106  char_buf,
107  (vpi->nb_bits > DEBUG_JTAG_IOZ) ? "(...)" : "");
108  free(char_buf);
109  } else {
110  /* command without data payload */
111  LOG_DEBUG_IO("sending JTAG VPI cmd: cmd=%s, "
112  "length=%" PRIu32 ", "
113  "nb_bits=%" PRIu32,
114  jtag_vpi_cmd_to_str(vpi->cmd),
115  vpi->length,
116  vpi->nb_bits);
117  }
118  }
119 
120  /* Use little endian when transmitting/receiving jtag_vpi cmds.
121  The choice of little endian goes against usual networking conventions
122  but is intentional to remain compatible with most older OpenOCD builds
123  (i.e. builds on little-endian platforms). */
124  h_u32_to_le(vpi->cmd_buf, vpi->cmd);
125  h_u32_to_le(vpi->length_buf, vpi->length);
126  h_u32_to_le(vpi->nb_bits_buf, vpi->nb_bits);
127 
128 retry_write:
129  retval = write_socket(sockfd, vpi, sizeof(struct vpi_cmd));
130 
131  if (retval < 0) {
132  /* Account for the case when socket write is interrupted. */
133 #ifdef _WIN32
134  int wsa_err = WSAGetLastError();
135  if (wsa_err == WSAEINTR)
136  goto retry_write;
137 #else
138  if (errno == EINTR)
139  goto retry_write;
140 #endif
141  /* Otherwise this is an error using the socket, most likely fatal
142  for the connection. B*/
143  log_socket_error("jtag_vpi xmit");
144  /* TODO: Clean way how adapter drivers can report fatal errors
145  to upper layers of OpenOCD and let it perform an orderly shutdown? */
146  exit(-1);
147  } else if (retval < (int)sizeof(struct vpi_cmd)) {
148  /* This means we could not send all data, which is most likely fatal
149  for the jtag_vpi connection (the underlying TCP connection likely not
150  usable anymore) */
151  LOG_ERROR("jtag_vpi: Could not send all data through jtag_vpi connection.");
152  exit(-1);
153  }
154 
155  /* Otherwise the packet has been sent successfully. */
156  return ERROR_OK;
157 }
158 
159 static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi)
160 {
161  unsigned bytes_buffered = 0;
162  while (bytes_buffered < sizeof(struct vpi_cmd)) {
163  int bytes_to_receive = sizeof(struct vpi_cmd) - bytes_buffered;
164  int retval = read_socket(sockfd, ((char *)vpi) + bytes_buffered, bytes_to_receive);
165  if (retval < 0) {
166 #ifdef _WIN32
167  int wsa_err = WSAGetLastError();
168  if (wsa_err == WSAEINTR) {
169  /* socket read interrupted by WSACancelBlockingCall() */
170  continue;
171  }
172 #else
173  if (errno == EINTR) {
174  /* socket read interrupted by a signal */
175  continue;
176  }
177 #endif
178  /* Otherwise, this is an error when accessing the socket. */
179  log_socket_error("jtag_vpi recv");
180  exit(-1);
181  } else if (retval == 0) {
182  /* Connection closed by the other side */
183  LOG_ERROR("Connection prematurely closed by jtag_vpi server.");
184  exit(-1);
185  }
186  /* Otherwise, we have successfully received some data */
187  bytes_buffered += retval;
188  }
189 
190  /* Use little endian when transmitting/receiving jtag_vpi cmds. */
191  vpi->cmd = le_to_h_u32(vpi->cmd_buf);
192  vpi->length = le_to_h_u32(vpi->length_buf);
193  vpi->nb_bits = le_to_h_u32(vpi->nb_bits_buf);
194 
195  return ERROR_OK;
196 }
197 
203 static int jtag_vpi_reset(int trst, int srst)
204 {
205  struct vpi_cmd vpi;
206  memset(&vpi, 0, sizeof(struct vpi_cmd));
207 
208  vpi.cmd = CMD_RESET;
209  vpi.length = 0;
210  return jtag_vpi_send_cmd(&vpi);
211 }
212 
224 static int jtag_vpi_tms_seq(const uint8_t *bits, int nb_bits)
225 {
226  struct vpi_cmd vpi;
227  int nb_bytes;
228 
229  memset(&vpi, 0, sizeof(struct vpi_cmd));
230  nb_bytes = DIV_ROUND_UP(nb_bits, 8);
231 
232  vpi.cmd = CMD_TMS_SEQ;
233  memcpy(vpi.buffer_out, bits, nb_bytes);
234  vpi.length = nb_bytes;
235  vpi.nb_bits = nb_bits;
236 
237  return jtag_vpi_send_cmd(&vpi);
238 }
239 
252 {
253  uint8_t trans[DIV_ROUND_UP(cmd->num_states, 8)];
254 
255  memset(trans, 0, DIV_ROUND_UP(cmd->num_states, 8));
256 
257  for (int i = 0; i < cmd->num_states; i++) {
258  if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
259  buf_set_u32(trans, i, 1, 1);
260  tap_set_state(cmd->path[i]);
261  }
262 
263  return jtag_vpi_tms_seq(trans, cmd->num_states);
264 }
265 
270 static int jtag_vpi_tms(struct tms_command *cmd)
271 {
272  return jtag_vpi_tms_seq(cmd->bits, cmd->num_bits);
273 }
274 
276 {
277  if (tap_get_state() == state)
278  return ERROR_OK;
279 
280  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), state);
281  int tms_len = tap_get_tms_path_len(tap_get_state(), state);
282 
283  int retval = jtag_vpi_tms_seq(&tms_scan, tms_len);
284  if (retval != ERROR_OK)
285  return retval;
286 
288 
289  return ERROR_OK;
290 }
291 
292 static int jtag_vpi_queue_tdi_xfer(uint8_t *bits, int nb_bits, int tap_shift)
293 {
294  struct vpi_cmd vpi;
295  int nb_bytes = DIV_ROUND_UP(nb_bits, 8);
296 
297  memset(&vpi, 0, sizeof(struct vpi_cmd));
298 
299  vpi.cmd = tap_shift ? CMD_SCAN_CHAIN_FLIP_TMS : CMD_SCAN_CHAIN;
300 
301  if (bits)
302  memcpy(vpi.buffer_out, bits, nb_bytes);
303  else
304  memset(vpi.buffer_out, 0xff, nb_bytes);
305 
306  vpi.length = nb_bytes;
307  vpi.nb_bits = nb_bits;
308 
309  int retval = jtag_vpi_send_cmd(&vpi);
310  if (retval != ERROR_OK)
311  return retval;
312 
313  retval = jtag_vpi_receive_cmd(&vpi);
314  if (retval != ERROR_OK)
315  return retval;
316 
317  /* Optional low-level JTAG debug */
319  char *char_buf = buf_to_hex_str(vpi.buffer_in,
321  LOG_DEBUG_IO("recvd JTAG VPI data: nb_bits=%d, buf_in=0x%s%s",
322  nb_bits, char_buf, (nb_bits > DEBUG_JTAG_IOZ) ? "(...)" : "");
323  free(char_buf);
324  }
325 
326  if (bits)
327  memcpy(bits, vpi.buffer_in, nb_bytes);
328 
329  return ERROR_OK;
330 }
331 
338 static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift)
339 {
340  int nb_xfer = DIV_ROUND_UP(nb_bits, XFERT_MAX_SIZE * 8);
341  int retval;
342 
343  while (nb_xfer) {
344  if (nb_xfer == 1) {
345  retval = jtag_vpi_queue_tdi_xfer(bits, nb_bits, tap_shift);
346  if (retval != ERROR_OK)
347  return retval;
348  } else {
350  if (retval != ERROR_OK)
351  return retval;
352  nb_bits -= XFERT_MAX_SIZE * 8;
353  if (bits)
354  bits += XFERT_MAX_SIZE;
355  }
356 
357  nb_xfer--;
358  }
359 
360  return ERROR_OK;
361 }
362 
369 static int jtag_vpi_clock_tms(int tms)
370 {
371  const uint8_t tms_0 = 0;
372  const uint8_t tms_1 = 1;
373 
374  return jtag_vpi_tms_seq(tms ? &tms_1 : &tms_0, 1);
375 }
376 
385 static int jtag_vpi_scan(struct scan_command *cmd)
386 {
387  int scan_bits;
388  uint8_t *buf = NULL;
389  int retval = ERROR_OK;
390 
391  scan_bits = jtag_build_buffer(cmd, &buf);
392 
393  if (cmd->ir_scan) {
395  if (retval != ERROR_OK)
396  return retval;
397  } else {
399  if (retval != ERROR_OK)
400  return retval;
401  }
402 
403  if (cmd->end_state == TAP_DRSHIFT) {
404  retval = jtag_vpi_queue_tdi(buf, scan_bits, NO_TAP_SHIFT);
405  if (retval != ERROR_OK)
406  return retval;
407  } else {
408  retval = jtag_vpi_queue_tdi(buf, scan_bits, TAP_SHIFT);
409  if (retval != ERROR_OK)
410  return retval;
411  }
412 
413  if (cmd->end_state != TAP_DRSHIFT) {
414  /*
415  * As our JTAG is in an unstable state (IREXIT1 or DREXIT1), move it
416  * forward to a stable IRPAUSE or DRPAUSE.
417  */
418  retval = jtag_vpi_clock_tms(0);
419  if (retval != ERROR_OK)
420  return retval;
421 
422  if (cmd->ir_scan)
424  else
426  }
427 
428  retval = jtag_read_buffer(buf, cmd);
429  if (retval != ERROR_OK)
430  return retval;
431 
432  free(buf);
433 
434  if (cmd->end_state != TAP_DRSHIFT) {
435  retval = jtag_vpi_state_move(cmd->end_state);
436  if (retval != ERROR_OK)
437  return retval;
438  }
439 
440  return ERROR_OK;
441 }
442 
443 static int jtag_vpi_runtest(int cycles, tap_state_t state)
444 {
445  int retval;
446 
447  retval = jtag_vpi_state_move(TAP_IDLE);
448  if (retval != ERROR_OK)
449  return retval;
450 
451  retval = jtag_vpi_queue_tdi(NULL, cycles, NO_TAP_SHIFT);
452  if (retval != ERROR_OK)
453  return retval;
454 
455  return jtag_vpi_state_move(state);
456 }
457 
458 static int jtag_vpi_stableclocks(int cycles)
459 {
460  uint8_t tms_bits[4];
461  int cycles_remain = cycles;
462  int nb_bits;
463  int retval;
464  const int CYCLES_ONE_BATCH = sizeof(tms_bits) * 8;
465 
466  assert(cycles >= 0);
467 
468  /* use TMS=1 in TAP RESET state, TMS=0 in all other stable states */
469  memset(&tms_bits, (tap_get_state() == TAP_RESET) ? 0xff : 0x00, sizeof(tms_bits));
470 
471  /* send the TMS bits */
472  while (cycles_remain > 0) {
473  nb_bits = (cycles_remain < CYCLES_ONE_BATCH) ? cycles_remain : CYCLES_ONE_BATCH;
474  retval = jtag_vpi_tms_seq(tms_bits, nb_bits);
475  if (retval != ERROR_OK)
476  return retval;
477  cycles_remain -= nb_bits;
478  }
479 
480  return ERROR_OK;
481 }
482 
483 static int jtag_vpi_execute_queue(void)
484 {
485  struct jtag_command *cmd;
486  int retval = ERROR_OK;
487 
488  for (cmd = jtag_command_queue; retval == ERROR_OK && cmd;
489  cmd = cmd->next) {
490  switch (cmd->type) {
491  case JTAG_RESET:
492  retval = jtag_vpi_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
493  break;
494  case JTAG_RUNTEST:
495  retval = jtag_vpi_runtest(cmd->cmd.runtest->num_cycles,
496  cmd->cmd.runtest->end_state);
497  break;
498  case JTAG_STABLECLOCKS:
499  retval = jtag_vpi_stableclocks(cmd->cmd.stableclocks->num_cycles);
500  break;
501  case JTAG_TLR_RESET:
502  retval = jtag_vpi_state_move(cmd->cmd.statemove->end_state);
503  break;
504  case JTAG_PATHMOVE:
505  retval = jtag_vpi_path_move(cmd->cmd.pathmove);
506  break;
507  case JTAG_TMS:
508  retval = jtag_vpi_tms(cmd->cmd.tms);
509  break;
510  case JTAG_SLEEP:
511  jtag_sleep(cmd->cmd.sleep->us);
512  break;
513  case JTAG_SCAN:
514  retval = jtag_vpi_scan(cmd->cmd.scan);
515  break;
516  default:
517  LOG_ERROR("BUG: unknown JTAG command type 0x%X",
518  cmd->type);
519  retval = ERROR_FAIL;
520  break;
521  }
522  }
523 
524  return retval;
525 }
526 
527 static int jtag_vpi_init(void)
528 {
529  int flag = 1;
530 
531  sockfd = socket(AF_INET, SOCK_STREAM, 0);
532  if (sockfd < 0) {
533  LOG_ERROR("jtag_vpi: Could not create client socket");
534  return ERROR_FAIL;
535  }
536 
537  memset(&serv_addr, 0, sizeof(serv_addr));
538 
539  serv_addr.sin_family = AF_INET;
540  serv_addr.sin_port = htons(server_port);
541 
542  if (!server_address)
544 
545  serv_addr.sin_addr.s_addr = inet_addr(server_address);
546 
547  if (serv_addr.sin_addr.s_addr == INADDR_NONE) {
548  LOG_ERROR("jtag_vpi: inet_addr error occurred");
549  return ERROR_FAIL;
550  }
551 
552  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
553  close(sockfd);
554  LOG_ERROR("jtag_vpi: Can't connect to %s : %u", server_address, server_port);
556  }
557 
558  if (serv_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) {
559  /* This increases performance dramatically for local
560  * connections, which is the most likely arrangement
561  * for a VPI connection. */
562  setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
563  }
564 
565  LOG_INFO("jtag_vpi: Connection to %s : %u successful", server_address, server_port);
566 
567  return ERROR_OK;
568 }
569 
570 static int jtag_vpi_stop_simulation(void)
571 {
572  struct vpi_cmd cmd;
573  memset(&cmd, 0, sizeof(struct vpi_cmd));
574  cmd.length = 0;
575  cmd.nb_bits = 0;
576  cmd.cmd = CMD_STOP_SIMU;
577  return jtag_vpi_send_cmd(&cmd);
578 }
579 
580 static int jtag_vpi_quit(void)
581 {
582  if (stop_sim_on_exit) {
584  LOG_WARNING("jtag_vpi: failed to send \"stop simulation\" command");
585  }
586  if (close_socket(sockfd) != 0) {
587  LOG_WARNING("jtag_vpi: could not close jtag_vpi client socket");
588  log_socket_error("jtag_vpi");
589  }
590  free(server_address);
591  return ERROR_OK;
592 }
593 
594 COMMAND_HANDLER(jtag_vpi_set_port)
595 {
596  if (CMD_ARGC == 0) {
597  LOG_ERROR("Command \"jtag_vpi set_port\" expects 1 argument (TCP port number)");
599  }
600 
602  LOG_INFO("jtag_vpi: server port set to %u", server_port);
603 
604  return ERROR_OK;
605 }
606 
607 COMMAND_HANDLER(jtag_vpi_set_address)
608 {
609 
610  if (CMD_ARGC == 0) {
611  LOG_ERROR("Command \"jtag_vpi set_address\" expects 1 argument (IP address)");
613  }
614 
615  free(server_address);
616  server_address = strdup(CMD_ARGV[0]);
617  LOG_INFO("jtag_vpi: server address set to %s", server_address);
618 
619  return ERROR_OK;
620 }
621 
622 COMMAND_HANDLER(jtag_vpi_stop_sim_on_exit_handler)
623 {
624  if (CMD_ARGC != 1) {
625  LOG_ERROR("Command \"jtag_vpi stop_sim_on_exit\" expects 1 argument (on|off)");
627  }
628 
630  return ERROR_OK;
631 }
632 
633 static const struct command_registration jtag_vpi_subcommand_handlers[] = {
634  {
635  .name = "set_port",
636  .handler = &jtag_vpi_set_port,
637  .mode = COMMAND_CONFIG,
638  .help = "set the TCP port number of the jtag_vpi server (default: 5555)",
639  .usage = "tcp_port_num",
640  },
641  {
642  .name = "set_address",
643  .handler = &jtag_vpi_set_address,
644  .mode = COMMAND_CONFIG,
645  .help = "set the IP address of the jtag_vpi server (default: 127.0.0.1)",
646  .usage = "ipv4_addr",
647  },
648  {
649  .name = "stop_sim_on_exit",
650  .handler = &jtag_vpi_stop_sim_on_exit_handler,
651  .mode = COMMAND_CONFIG,
652  .help = "Configure if simulation stop command shall be sent "
653  "before OpenOCD exits (default: off)",
654  .usage = "<on|off>",
655  },
657 };
658 
659 static const struct command_registration jtag_vpi_command_handlers[] = {
660  {
661  .name = "jtag_vpi",
662  .mode = COMMAND_ANY,
663  .help = "perform jtag_vpi management",
665  .usage = "",
666  },
668 };
669 
670 static struct jtag_interface jtag_vpi_interface = {
672  .execute_queue = jtag_vpi_execute_queue,
673 };
674 
676  .name = "jtag_vpi",
677  .transports = jtag_only,
678  .commands = jtag_vpi_command_handlers,
679 
680  .init = jtag_vpi_init,
681  .quit = jtag_vpi_quit,
682 
683  .jtag_ops = &jtag_vpi_interface,
684 };
const char *const jtag_only[]
Definition: adapter.c:31
uint32_t bits
Definition: armv4_5.c:359
char * buf_to_hex_str(const void *_buf, unsigned buf_len)
Definition: binarybuffer.c:192
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:30
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
Definition: command.h:504
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:385
#define ERROR_COMMAND_CLOSE_CONNECTION
Definition: command.h:384
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:425
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
Definition: commands.c:36
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:189
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
Definition: commands.c:230
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_STABLECLOCKS
Definition: commands.h:142
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_RESET
Definition: commands.h:139
@ JTAG_TMS
Definition: commands.h:143
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
Definition: interface.c:37
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
Definition: interface.h:49
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1062
#define DEBUG_JTAG_IOZ
Definition: jtag.h:19
@ TAP_RESET
Definition: jtag.h:55
@ TAP_DRPAUSE
Definition: jtag.h:43
@ TAP_IRSHIFT
Definition: jtag.h:50
@ TAP_IDLE
Definition: jtag.h:52
@ TAP_DRSHIFT
Definition: jtag.h:42
@ TAP_IRPAUSE
Definition: jtag.h:51
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
static int jtag_vpi_init(void)
Definition: jtag_vpi.c:527
#define CMD_SCAN_CHAIN_FLIP_TMS
Definition: jtag_vpi.c:38
static int jtag_vpi_tms(struct tms_command *cmd)
jtag_vpi_tms - ask a tms command
Definition: jtag_vpi.c:270
struct adapter_driver jtag_vpi_adapter_driver
Definition: jtag_vpi.c:675
static int jtag_vpi_stableclocks(int cycles)
Definition: jtag_vpi.c:458
static int jtag_vpi_scan(struct scan_command *cmd)
jtag_vpi_scan - launches a DR-scan or IR-scan
Definition: jtag_vpi.c:385
static int jtag_vpi_send_cmd(struct vpi_cmd *vpi)
Definition: jtag_vpi.c:87
static int jtag_vpi_runtest(int cycles, tap_state_t state)
Definition: jtag_vpi.c:443
#define TAP_SHIFT
Definition: jtag_vpi.c:28
static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift)
jtag_vpi_queue_tdi - short description
Definition: jtag_vpi.c:338
static int jtag_vpi_tms_seq(const uint8_t *bits, int nb_bits)
jtag_vpi_tms_seq - ask a TMS sequence transition to JTAG
Definition: jtag_vpi.c:224
static const struct command_registration jtag_vpi_command_handlers[]
Definition: jtag_vpi.c:659
#define CMD_SCAN_CHAIN
Definition: jtag_vpi.c:37
static struct jtag_interface jtag_vpi_interface
Definition: jtag_vpi.c:670
static char * jtag_vpi_cmd_to_str(int cmd_num)
Definition: jtag_vpi.c:69
static int jtag_vpi_execute_queue(void)
Definition: jtag_vpi.c:483
static int jtag_vpi_reset(int trst, int srst)
jtag_vpi_reset - ask to reset the JTAG device
Definition: jtag_vpi.c:203
#define DEFAULT_SERVER_ADDRESS
Definition: jtag_vpi.c:30
static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi)
Definition: jtag_vpi.c:159
#define CMD_TMS_SEQ
Definition: jtag_vpi.c:36
static int jtag_vpi_queue_tdi_xfer(uint8_t *bits, int nb_bits, int tap_shift)
Definition: jtag_vpi.c:292
static int jtag_vpi_quit(void)
Definition: jtag_vpi.c:580
static int jtag_vpi_clock_tms(int tms)
jtag_vpi_clock_tms - clock a TMS transition
Definition: jtag_vpi.c:369
COMMAND_HANDLER(jtag_vpi_set_port)
Definition: jtag_vpi.c:594
static int jtag_vpi_stop_simulation(void)
Definition: jtag_vpi.c:570
static int jtag_vpi_path_move(struct pathmove_command *cmd)
jtag_vpi_path_move - ask a TMS sequence transition to JTAG
Definition: jtag_vpi.c:251
#define CMD_STOP_SIMU
Definition: jtag_vpi.c:39
static struct sockaddr_in serv_addr
Definition: jtag_vpi.c:49
#define XFERT_MAX_SIZE
Definition: jtag_vpi.c:33
static int sockfd
Definition: jtag_vpi.c:48
static const struct command_registration jtag_vpi_subcommand_handlers[]
Definition: jtag_vpi.c:633
static bool stop_sim_on_exit
Definition: jtag_vpi.c:46
#define NO_TAP_SHIFT
Definition: jtag_vpi.c:27
static int jtag_vpi_state_move(tap_state_t state)
Definition: jtag_vpi.c:275
static int server_port
Definition: jtag_vpi.c:42
#define DEFAULT_SERVER_PORT
Definition: jtag_vpi.c:31
static char * server_address
Definition: jtag_vpi.c:43
#define CMD_RESET
Definition: jtag_vpi.c:35
void log_socket_error(const char *socket_desc)
Definition: log.c:488
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_LEVEL_IS(FOO)
Definition: log.h:99
#define LOG_INFO(expr ...)
Definition: log.h:117
#define ERROR_OK
Definition: log.h:155
@ LOG_LVL_DEBUG_IO
Definition: log.h:48
int flag
Definition: mips32.c:41
static int read_socket(int handle, void *buffer, unsigned int count)
Definition: replacements.h:176
static int close_socket(int sock)
Definition: replacements.h:185
static int write_socket(int handle, const void *buffer, unsigned int count)
Definition: replacements.h:167
Represents a driver for a debugging interface.
Definition: interface.h:207
const char *const name
The name of the interface driver.
Definition: interface.h:209
const char * name
Definition: command.h:229
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235
Represents a driver for a debugging interface.
Definition: interface.h:184
unsigned supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:188
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...
Definition: commands.h:35
Encapsulates a series of bits to be clocked out, affecting state and mode of the interface.
Definition: commands.h:101
unsigned char nb_bits_buf[4]
Definition: jtag_vpi.c:65
uint32_t cmd
Definition: jtag_vpi.c:54
unsigned char cmd_buf[4]
Definition: jtag_vpi.c:55
uint32_t length
Definition: jtag_vpi.c:60
unsigned char buffer_in[XFERT_MAX_SIZE]
Definition: jtag_vpi.c:58
unsigned char length_buf[4]
Definition: jtag_vpi.c:61
unsigned char buffer_out[XFERT_MAX_SIZE]
Definition: jtag_vpi.c:57
uint32_t nb_bits
Definition: jtag_vpi.c:64
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t state[4]
Definition: vdebug.c:21