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  int scan_bits;
390  uint8_t *buf = NULL;
391  int retval = ERROR_OK;
392 
393  scan_bits = jtag_build_buffer(cmd, &buf);
394 
395  if (cmd->ir_scan) {
397  if (retval != ERROR_OK)
398  return retval;
399  } else {
401  if (retval != ERROR_OK)
402  return retval;
403  }
404 
405  if (cmd->end_state == TAP_DRSHIFT) {
406  retval = jtag_vpi_queue_tdi(buf, scan_bits, NO_TAP_SHIFT);
407  if (retval != ERROR_OK)
408  return retval;
409  } else {
410  retval = jtag_vpi_queue_tdi(buf, scan_bits, TAP_SHIFT);
411  if (retval != ERROR_OK)
412  return retval;
413  }
414 
415  if (cmd->end_state != TAP_DRSHIFT) {
416  /*
417  * As our JTAG is in an unstable state (IREXIT1 or DREXIT1), move it
418  * forward to a stable IRPAUSE or DRPAUSE.
419  */
420  retval = jtag_vpi_clock_tms(0);
421  if (retval != ERROR_OK)
422  return retval;
423 
424  if (cmd->ir_scan)
426  else
428  }
429 
430  retval = jtag_read_buffer(buf, cmd);
431  if (retval != ERROR_OK)
432  return retval;
433 
434  free(buf);
435 
436  if (cmd->end_state != TAP_DRSHIFT) {
437  retval = jtag_vpi_state_move(cmd->end_state);
438  if (retval != ERROR_OK)
439  return retval;
440  }
441 
442  return ERROR_OK;
443 }
444 
445 static int jtag_vpi_runtest(unsigned int num_cycles, enum tap_state state)
446 {
447  int retval;
448 
449  retval = jtag_vpi_state_move(TAP_IDLE);
450  if (retval != ERROR_OK)
451  return retval;
452 
453  retval = jtag_vpi_queue_tdi(NULL, num_cycles, NO_TAP_SHIFT);
454  if (retval != ERROR_OK)
455  return retval;
456 
457  return jtag_vpi_state_move(state);
458 }
459 
460 static int jtag_vpi_stableclocks(unsigned int num_cycles)
461 {
462  uint8_t tms_bits[4];
463  unsigned int cycles_remain = num_cycles;
464  int nb_bits;
465  int retval;
466  const unsigned int cycles_one_batch = sizeof(tms_bits) * 8;
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(struct jtag_command *cmd_queue)
484 {
485  struct jtag_command *cmd;
486  int retval = ERROR_OK;
487 
488  for (cmd = cmd_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  if (!server_address)
531 
532  const struct addrinfo hints = {
533  .ai_family = AF_UNSPEC,
534  .ai_socktype = SOCK_STREAM
535  };
536 
537  char port_str[5 + 1];
538  snprintf(port_str, sizeof(port_str), "%" PRIu16, server_port);
539 
540  struct addrinfo *result;
541  int ret = getaddrinfo(server_address, port_str, &hints, &result);
542 
543  if (ret != 0) {
544  LOG_ERROR("getaddrinfo: %s", gai_strerror(ret));
545  return ERROR_FAIL;
546  }
547 
548  struct addrinfo *rp;
549  for (rp = result; rp ; rp = rp->ai_next) {
550  sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
551  if (sockfd == -1)
552  continue;
553 
554  if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) != -1)
555  break;
556 
557  close(sockfd);
558  }
559 
560  if (!rp) {
561  LOG_ERROR("jtag_vpi: Can't connect to %s : %" PRIu16,
563  freeaddrinfo(result);
564  return ERROR_FAIL;
565  }
566 
567  bool is_loopback = false;
568  if (rp->ai_family == AF_INET) {
569  struct sockaddr_in sa;
570  memcpy(&sa, rp->ai_addr, sizeof(sa));
571  is_loopback = (sa.sin_addr.s_addr == htonl(INADDR_LOOPBACK));
572  } else if (rp->ai_family == AF_INET6) {
573  struct sockaddr_in6 sa;
574  memcpy(&sa, rp->ai_addr, sizeof(sa));
575  is_loopback = IN6_IS_ADDR_LOOPBACK(&sa.sin6_addr);
576  }
577 
578  if (is_loopback) {
579  /* This increases performance dramatically for local
580  * connections, which is the most likely arrangement
581  * for a VPI connection. */
582  LOG_DEBUG("Enabling TCP_NODELAY to enhance the speed of local connections");
583 
584  int flag = 1;
585  setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
586  sizeof(int));
587  }
588 
589  freeaddrinfo(result);
590 
591  LOG_INFO("jtag_vpi: Connection to %s : %" PRIu16 " successful",
593 
594  return ERROR_OK;
595 }
596 
597 static int jtag_vpi_stop_simulation(void)
598 {
599  struct vpi_cmd cmd;
600  memset(&cmd, 0, sizeof(struct vpi_cmd));
601  cmd.length = 0;
602  cmd.nb_bits = 0;
603  cmd.cmd = CMD_STOP_SIMU;
604  return jtag_vpi_send_cmd(&cmd);
605 }
606 
607 static int jtag_vpi_quit(void)
608 {
609  if (stop_sim_on_exit) {
611  LOG_WARNING("jtag_vpi: failed to send \"stop simulation\" command");
612  }
613  if (close_socket(sockfd) != 0) {
614  LOG_WARNING("jtag_vpi: could not close jtag_vpi client socket");
615  log_socket_error("jtag_vpi");
616  }
617  free(server_address);
618  return ERROR_OK;
619 }
620 
621 COMMAND_HANDLER(jtag_vpi_set_port)
622 {
623  if (CMD_ARGC == 0)
625 
627  LOG_INFO("jtag_vpi: server port set to %" PRIu16, server_port);
628 
629  return ERROR_OK;
630 }
631 
632 COMMAND_HANDLER(jtag_vpi_set_address)
633 {
634 
635  if (CMD_ARGC == 0)
637 
638  free(server_address);
639  server_address = strdup(CMD_ARGV[0]);
640  LOG_INFO("jtag_vpi: server address set to %s", server_address);
641 
642  return ERROR_OK;
643 }
644 
645 COMMAND_HANDLER(jtag_vpi_stop_sim_on_exit_handler)
646 {
647  if (CMD_ARGC != 1)
649 
651  return ERROR_OK;
652 }
653 
654 static const struct command_registration jtag_vpi_subcommand_handlers[] = {
655  {
656  .name = "set_port",
657  .handler = &jtag_vpi_set_port,
658  .mode = COMMAND_CONFIG,
659  .help = "set the TCP port number of the jtag_vpi server (default: 5555)",
660  .usage = "tcp_port_num",
661  },
662  {
663  .name = "set_address",
664  .handler = &jtag_vpi_set_address,
665  .mode = COMMAND_CONFIG,
666  .help = "set the hostname or IP address of the jtag_vpi server (default: 127.0.0.1)",
667  .usage = "ipv4_addr",
668  },
669  {
670  .name = "stop_sim_on_exit",
671  .handler = &jtag_vpi_stop_sim_on_exit_handler,
672  .mode = COMMAND_CONFIG,
673  .help = "Configure if simulation stop command shall be sent "
674  "before OpenOCD exits (default: off)",
675  .usage = "<on|off>",
676  },
678 };
679 
680 static const struct command_registration jtag_vpi_command_handlers[] = {
681  {
682  .name = "jtag_vpi",
683  .mode = COMMAND_ANY,
684  .help = "perform jtag_vpi management",
686  .usage = "",
687  },
689 };
690 
691 static struct jtag_interface jtag_vpi_interface = {
693  .execute_queue = jtag_vpi_execute_queue,
694 };
695 
697  .name = "jtag_vpi",
698  .transport_ids = TRANSPORT_JTAG,
699  .transport_preferred_id = TRANSPORT_JTAG,
700  .commands = jtag_vpi_command_handlers,
701 
702  .init = jtag_vpi_init,
703  .quit = jtag_vpi_quit,
704 
705  .jtag_ops = &jtag_vpi_interface,
706 };
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:1070
#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:527
#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:696
static int jtag_vpi_stableclocks(unsigned int num_cycles)
Definition: jtag_vpi.c:460
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:445
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:680
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:691
static int jtag_vpi_execute_queue(struct jtag_command *cmd_queue)
Definition: jtag_vpi.c:483
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:607
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:621
static int jtag_vpi_stop_simulation(void)
Definition: jtag_vpi.c:597
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:654
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:175
static int close_socket(int sock)
Definition: replacements.h:184
static int write_socket(int handle, const void *buffer, unsigned int count)
Definition: replacements.h:166
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