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