OpenOCD
nds32_cmd.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2013 Andes Technology *
5  * Hsiangkai Wang <hkwang@andestech.com> *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <helper/command.h>
13 #include "nds32.h"
14 #include "nds32_aice.h"
15 #include "nds32_disassembler.h"
16 
18 extern uint32_t nds32_edm_ops_num;
19 
20 static const char *const nds_memory_access_name[] = {
21  "BUS",
22  "CPU",
23 };
24 
25 static const char *const nds_memory_select_name[] = {
26  "AUTO",
27  "MEM",
28  "ILM",
29  "DLM",
30 };
31 
32 COMMAND_HANDLER(handle_nds32_dssim_command)
33 {
35  struct nds32 *nds32 = target_to_nds32(target);
36 
37  if (!is_nds32(nds32)) {
38  command_print(CMD, "current target isn't an Andes core");
39  return ERROR_FAIL;
40  }
41 
42  if (CMD_ARGC > 0) {
43  if (strcmp(CMD_ARGV[0], "on") == 0)
44  nds32->step_isr_enable = true;
45  if (strcmp(CMD_ARGV[0], "off") == 0)
46  nds32->step_isr_enable = false;
47  }
48 
49  command_print(CMD, "%s: $INT_MASK.DSSIM: %d", target_name(target),
51 
52  return ERROR_OK;
53 }
54 
55 COMMAND_HANDLER(handle_nds32_memory_access_command)
56 {
58  struct nds32 *nds32 = target_to_nds32(target);
59  struct aice_port_s *aice = target_to_aice(target);
60  struct nds32_memory *memory = &(nds32->memory);
61 
62  if (!is_nds32(nds32)) {
63  command_print(CMD, "current target isn't an Andes core");
64  return ERROR_FAIL;
65  }
66 
67  if (CMD_ARGC > 0) {
68  if (strcmp(CMD_ARGV[0], "bus") == 0)
70  else if (strcmp(CMD_ARGV[0], "cpu") == 0)
72  else /* default access channel is NDS_MEMORY_ACC_CPU */
74 
75  LOG_DEBUG("memory access channel is changed to %s",
77 
78  aice_memory_access(aice, memory->access_channel);
79  } else {
80  command_print(CMD, "%s: memory access channel: %s",
83  }
84 
85  return ERROR_OK;
86 }
87 
88 COMMAND_HANDLER(handle_nds32_memory_mode_command)
89 {
91  struct nds32 *nds32 = target_to_nds32(target);
92  struct aice_port_s *aice = target_to_aice(target);
93 
94  if (!is_nds32(nds32)) {
95  command_print(CMD, "current target isn't an Andes core");
96  return ERROR_FAIL;
97  }
98 
99  if (CMD_ARGC > 0) {
100 
101  if (nds32->edm.access_control == false) {
102  command_print(CMD, "%s does not support ACC_CTL. "
103  "Set memory mode to MEMORY", target_name(target));
105  } else if (nds32->edm.direct_access_local_memory == false) {
106  command_print(CMD, "%s does not support direct access "
107  "local memory. Set memory mode to MEMORY",
110 
111  /* set to ACC_CTL */
113  } else {
114  if (strcmp(CMD_ARGV[0], "auto") == 0) {
116  } else if (strcmp(CMD_ARGV[0], "mem") == 0) {
118  } else if (strcmp(CMD_ARGV[0], "ilm") == 0) {
119  if (nds32->memory.ilm_base == 0)
120  command_print(CMD, "%s does not support ILM",
122  else
124  } else if (strcmp(CMD_ARGV[0], "dlm") == 0) {
125  if (nds32->memory.dlm_base == 0)
126  command_print(CMD, "%s does not support DLM",
128  else
130  }
131 
132  /* set to ACC_CTL */
134  }
135  }
136 
137  command_print(CMD, "%s: memory mode: %s",
140 
141  return ERROR_OK;
142 }
143 
144 COMMAND_HANDLER(handle_nds32_cache_command)
145 {
147  struct nds32 *nds32 = target_to_nds32(target);
148  struct aice_port_s *aice = target_to_aice(target);
149  struct nds32_cache *icache = &(nds32->memory.icache);
150  struct nds32_cache *dcache = &(nds32->memory.dcache);
151  int result;
152 
153  if (!is_nds32(nds32)) {
154  command_print(CMD, "current target isn't an Andes core");
155  return ERROR_FAIL;
156  }
157 
158  if (CMD_ARGC > 0) {
159 
160  if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
161  if ((dcache->line_size != 0) && (dcache->enable == true)) {
162  /* D$ write back */
163  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0);
164  if (result != ERROR_OK) {
165  command_print(CMD, "%s: Write back data cache...failed",
167  return result;
168  }
169 
170  command_print(CMD, "%s: Write back data cache...done",
172 
173  /* D$ invalidate */
174  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0);
175  if (result != ERROR_OK) {
176  command_print(CMD, "%s: Invalidate data cache...failed",
178  return result;
179  }
180 
181  command_print(CMD, "%s: Invalidate data cache...done",
183  } else {
184  if (dcache->line_size == 0)
185  command_print(CMD, "%s: No data cache",
187  else
188  command_print(CMD, "%s: Data cache disabled",
190  }
191 
192  if ((icache->line_size != 0) && (icache->enable == true)) {
193  /* I$ invalidate */
194  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0);
195  if (result != ERROR_OK) {
196  command_print(CMD, "%s: Invalidate instruction cache...failed",
198  return result;
199  }
200 
201  command_print(CMD, "%s: Invalidate instruction cache...done",
203  } else {
204  if (icache->line_size == 0)
205  command_print(CMD, "%s: No instruction cache",
207  else
208  command_print(CMD, "%s: Instruction cache disabled",
210  }
211  } else
212  command_print(CMD, "No valid parameter");
213  }
214 
215  return ERROR_OK;
216 }
217 
218 COMMAND_HANDLER(handle_nds32_icache_command)
219 {
221  struct nds32 *nds32 = target_to_nds32(target);
222  struct aice_port_s *aice = target_to_aice(target);
223  struct nds32_cache *icache = &(nds32->memory.icache);
224  int result;
225 
226  if (!is_nds32(nds32)) {
227  command_print(CMD, "current target isn't an Andes core");
228  return ERROR_FAIL;
229  }
230 
231  if (CMD_ARGC > 0) {
232 
233  if (icache->line_size == 0) {
234  command_print(CMD, "%s: No instruction cache",
236  return ERROR_OK;
237  }
238 
239  if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
240  if (icache->enable == true) {
241  /* I$ invalidate */
242  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0);
243  if (result != ERROR_OK) {
244  command_print(CMD, "%s: Invalidate instruction cache...failed",
246  return result;
247  }
248 
249  command_print(CMD, "%s: Invalidate instruction cache...done",
251  } else {
252  command_print(CMD, "%s: Instruction cache disabled",
254  }
255  } else if (strcmp(CMD_ARGV[0], "enable") == 0) {
256  uint32_t value;
257  nds32_get_mapped_reg(nds32, IR8, &value);
258  nds32_set_mapped_reg(nds32, IR8, value | 0x1);
259  } else if (strcmp(CMD_ARGV[0], "disable") == 0) {
260  uint32_t value;
261  nds32_get_mapped_reg(nds32, IR8, &value);
262  nds32_set_mapped_reg(nds32, IR8, value & ~0x1);
263  } else if (strcmp(CMD_ARGV[0], "dump") == 0) {
264  /* TODO: dump cache content */
265  } else {
266  command_print(CMD, "%s: No valid parameter", target_name(target));
267  }
268  }
269 
270  return ERROR_OK;
271 }
272 
273 COMMAND_HANDLER(handle_nds32_dcache_command)
274 {
276  struct nds32 *nds32 = target_to_nds32(target);
277  struct aice_port_s *aice = target_to_aice(target);
278  struct nds32_cache *dcache = &(nds32->memory.dcache);
279  int result;
280 
281  if (!is_nds32(nds32)) {
282  command_print(CMD, "current target isn't an Andes core");
283  return ERROR_FAIL;
284  }
285 
286  if (CMD_ARGC > 0) {
287 
288  if (dcache->line_size == 0) {
289  command_print(CMD, "%s: No data cache", target_name(target));
290  return ERROR_OK;
291  }
292 
293  if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
294  if (dcache->enable == true) {
295  /* D$ write back */
296  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0);
297  if (result != ERROR_OK) {
298  command_print(CMD, "%s: Write back data cache...failed",
300  return result;
301  }
302 
303  command_print(CMD, "%s: Write back data cache...done",
305 
306  /* D$ invalidate */
307  result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0);
308  if (result != ERROR_OK) {
309  command_print(CMD, "%s: Invalidate data cache...failed",
311  return result;
312  }
313 
314  command_print(CMD, "%s: Invalidate data cache...done",
316  } else {
317  command_print(CMD, "%s: Data cache disabled",
319  }
320  } else if (strcmp(CMD_ARGV[0], "enable") == 0) {
321  uint32_t value;
322  nds32_get_mapped_reg(nds32, IR8, &value);
323  nds32_set_mapped_reg(nds32, IR8, value | 0x2);
324  } else if (strcmp(CMD_ARGV[0], "disable") == 0) {
325  uint32_t value;
326  nds32_get_mapped_reg(nds32, IR8, &value);
327  nds32_set_mapped_reg(nds32, IR8, value & ~0x2);
328  } else if (strcmp(CMD_ARGV[0], "dump") == 0) {
329  /* TODO: dump cache content */
330  } else {
331  command_print(CMD, "%s: No valid parameter", target_name(target));
332  }
333  }
334 
335  return ERROR_OK;
336 }
337 
338 COMMAND_HANDLER(handle_nds32_auto_break_command)
339 {
341  struct nds32 *nds32 = target_to_nds32(target);
342 
343  if (!is_nds32(nds32)) {
344  command_print(CMD, "current target isn't an Andes core");
345  return ERROR_FAIL;
346  }
347 
348  if (CMD_ARGC > 0) {
349  if (strcmp(CMD_ARGV[0], "on") == 0)
350  nds32->auto_convert_hw_bp = true;
351  if (strcmp(CMD_ARGV[0], "off") == 0)
352  nds32->auto_convert_hw_bp = false;
353  }
354 
356  command_print(CMD, "%s: convert sw break to hw break on ROM: on",
358  else
359  command_print(CMD, "%s: convert sw break to hw break on ROM: off",
361 
362  return ERROR_OK;
363 }
364 
365 COMMAND_HANDLER(handle_nds32_virtual_hosting_command)
366 {
368  struct nds32 *nds32 = target_to_nds32(target);
369 
370  if (!is_nds32(nds32)) {
371  command_print(CMD, "current target isn't an Andes core");
372  return ERROR_FAIL;
373  }
374 
375  if (CMD_ARGC > 0) {
376  if (strcmp(CMD_ARGV[0], "on") == 0)
377  nds32->virtual_hosting = true;
378  if (strcmp(CMD_ARGV[0], "off") == 0)
379  nds32->virtual_hosting = false;
380  }
381 
382  if (nds32->virtual_hosting)
383  command_print(CMD, "%s: virtual hosting: on", target_name(target));
384  else
385  command_print(CMD, "%s: virtual hosting: off", target_name(target));
386 
387  return ERROR_OK;
388 }
389 
390 COMMAND_HANDLER(handle_nds32_global_stop_command)
391 {
393  struct nds32 *nds32 = target_to_nds32(target);
394 
395  if (!is_nds32(nds32)) {
396  command_print(CMD, "current target isn't an Andes core");
397  return ERROR_FAIL;
398  }
399 
400  if (CMD_ARGC > 0) {
401  if (strcmp(CMD_ARGV[0], "on") == 0)
402  nds32->global_stop = true;
403  if (strcmp(CMD_ARGV[0], "off") == 0)
404  nds32->global_stop = false;
405  }
406 
407  if (nds32->global_stop)
408  LOG_INFO("%s: global stop: on", target_name(target));
409  else
410  LOG_INFO("%s: global stop: off", target_name(target));
411 
412  return ERROR_OK;
413 }
414 
415 COMMAND_HANDLER(handle_nds32_soft_reset_halt_command)
416 {
418  struct nds32 *nds32 = target_to_nds32(target);
419 
420  if (!is_nds32(nds32)) {
421  command_print(CMD, "current target isn't an Andes core");
422  return ERROR_FAIL;
423  }
424 
425  if (CMD_ARGC > 0) {
426  if (strcmp(CMD_ARGV[0], "on") == 0)
427  nds32->soft_reset_halt = true;
428  if (strcmp(CMD_ARGV[0], "off") == 0)
429  nds32->soft_reset_halt = false;
430  }
431 
432  if (nds32->soft_reset_halt)
433  LOG_INFO("%s: soft-reset-halt: on", target_name(target));
434  else
435  LOG_INFO("%s: soft-reset-halt: off", target_name(target));
436 
437  return ERROR_OK;
438 }
439 
440 COMMAND_HANDLER(handle_nds32_boot_time_command)
441 {
443  struct nds32 *nds32 = target_to_nds32(target);
444 
445  if (!is_nds32(nds32)) {
446  command_print(CMD, "current target isn't an Andes core");
447  return ERROR_FAIL;
448  }
449 
450  if (CMD_ARGC > 0)
452 
453  return ERROR_OK;
454 }
455 
456 COMMAND_HANDLER(handle_nds32_login_edm_passcode_command)
457 {
459  struct nds32 *nds32 = target_to_nds32(target);
460 
461  if (!is_nds32(nds32)) {
462  command_print(CMD, "current target isn't an Andes core");
463  return ERROR_FAIL;
464  }
465 
466  nds32->edm_passcode = strdup(CMD_ARGV[0]);
467 
468  return ERROR_OK;
469 }
470 
471 COMMAND_HANDLER(handle_nds32_login_edm_operation_command)
472 {
474  struct nds32 *nds32 = target_to_nds32(target);
475 
476  if (!is_nds32(nds32)) {
477  command_print(CMD, "current target isn't an Andes core");
478  return ERROR_FAIL;
479  }
480 
481  if (CMD_ARGC > 1) {
482 
483  uint32_t misc_reg_no;
484  uint32_t data;
485 
486  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], misc_reg_no);
487  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], data);
488 
490  return ERROR_FAIL;
491 
492  /* Just save the operation. Execute it in nds32_login() */
493  nds32_edm_ops[nds32_edm_ops_num].reg_no = misc_reg_no;
496  } else
497  return ERROR_FAIL;
498 
499  return ERROR_OK;
500 }
501 
502 COMMAND_HANDLER(handle_nds32_reset_halt_as_init_command)
503 {
505  struct nds32 *nds32 = target_to_nds32(target);
506 
507  if (!is_nds32(nds32)) {
508  command_print(CMD, "current target isn't an Andes core");
509  return ERROR_FAIL;
510  }
511 
512  if (CMD_ARGC > 0) {
513  if (strcmp(CMD_ARGV[0], "on") == 0)
515  if (strcmp(CMD_ARGV[0], "off") == 0)
516  nds32->reset_halt_as_examine = false;
517  }
518 
519  return ERROR_OK;
520 }
521 
522 COMMAND_HANDLER(handle_nds32_keep_target_edm_ctl_command)
523 {
525  struct nds32 *nds32 = target_to_nds32(target);
526 
527  if (!is_nds32(nds32)) {
528  command_print(CMD, "current target isn't an Andes core");
529  return ERROR_FAIL;
530  }
531 
532  if (CMD_ARGC > 0) {
533  if (strcmp(CMD_ARGV[0], "on") == 0)
534  nds32->keep_target_edm_ctl = true;
535  if (strcmp(CMD_ARGV[0], "off") == 0)
536  nds32->keep_target_edm_ctl = false;
537  }
538 
539  return ERROR_OK;
540 }
541 
542 COMMAND_HANDLER(handle_nds32_decode_command)
543 {
545  struct nds32 *nds32 = target_to_nds32(target);
546 
547  if (!is_nds32(nds32)) {
548  command_print(CMD, "current target isn't an Andes core");
549  return ERROR_FAIL;
550  }
551 
552  if (CMD_ARGC > 1) {
553 
554  uint32_t addr;
555  uint32_t insn_count;
556  uint32_t opcode;
557  uint32_t read_addr;
558  uint32_t i;
559  struct nds32_instruction instruction;
560 
562  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], insn_count);
563 
564  read_addr = addr;
565  i = 0;
566  while (i < insn_count) {
567  if (nds32_read_opcode(nds32, read_addr, &opcode) != ERROR_OK)
568  return ERROR_FAIL;
569  if (nds32_evaluate_opcode(nds32, opcode, read_addr, &instruction) != ERROR_OK)
570  return ERROR_FAIL;
571 
572  command_print(CMD, "%s", instruction.text);
573 
574  read_addr += instruction.instruction_size;
575  i++;
576  }
577  } else if (CMD_ARGC == 1) {
578 
579  uint32_t addr;
580  uint32_t opcode;
581  struct nds32_instruction instruction;
582 
584 
586  return ERROR_FAIL;
587  if (nds32_evaluate_opcode(nds32, opcode, addr, &instruction) != ERROR_OK)
588  return ERROR_FAIL;
589 
590  command_print(CMD, "%s", instruction.text);
591  } else
592  return ERROR_FAIL;
593 
594  return ERROR_OK;
595 }
596 
597 COMMAND_HANDLER(handle_nds32_word_access_mem_command)
598 {
600  struct nds32 *nds32 = target_to_nds32(target);
601 
602  if (!is_nds32(nds32)) {
603  command_print(CMD, "current target isn't an Andes core");
604  return ERROR_FAIL;
605  }
606 
607  if (CMD_ARGC > 0) {
608  if (strcmp(CMD_ARGV[0], "on") == 0)
609  nds32->word_access_mem = true;
610  if (strcmp(CMD_ARGV[0], "off") == 0)
611  nds32->word_access_mem = false;
612  }
613 
614  return ERROR_OK;
615 }
616 
617 COMMAND_HANDLER(handle_nds32_query_target_command)
618 {
620  struct nds32 *nds32 = target_to_nds32(target);
621 
622  if (!is_nds32(nds32)) {
623  command_print(CMD, "current target isn't an Andes core");
624  return ERROR_FAIL;
625  }
626 
627  command_print(CMD, "OCD");
628 
629  return ERROR_OK;
630 }
631 
632 COMMAND_HANDLER(handle_nds32_query_endian_command)
633 {
635  struct nds32 *nds32 = target_to_nds32(target);
636 
637  if (!is_nds32(nds32)) {
638  command_print(CMD, "current target isn't an Andes core");
639  return ERROR_FAIL;
640  }
641 
642  uint32_t value_psw;
643  nds32_get_mapped_reg(nds32, IR0, &value_psw);
644 
645  if (value_psw & 0x20)
646  command_print(CMD, "%s: BE", target_name(target));
647  else
648  command_print(CMD, "%s: LE", target_name(target));
649 
650  return ERROR_OK;
651 }
652 
653 COMMAND_HANDLER(handle_nds32_query_cpuid_command)
654 {
656  struct nds32 *nds32 = target_to_nds32(target);
657 
658  if (!is_nds32(nds32)) {
659  command_print(CMD, "current target isn't an Andes core");
660  return ERROR_FAIL;
661  }
662 
663  command_print(CMD, "CPUID: %s", target_name(target));
664 
665  return ERROR_OK;
666 }
667 
668 static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
669 {
670  const char *cmd_name = Jim_GetString(argv[0], NULL);
671 
672  struct jim_getopt_info goi;
673  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
674 
675  if (goi.argc < 3) {
676  Jim_SetResultFormatted(goi.interp,
677  "usage: %s <address> <count> <data>", cmd_name);
678  return JIM_ERR;
679  }
680 
681  int e;
682  jim_wide address;
683  e = jim_getopt_wide(&goi, &address);
684  if (e != JIM_OK)
685  return e;
686 
687  jim_wide count;
688  e = jim_getopt_wide(&goi, &count);
689  if (e != JIM_OK)
690  return e;
691 
692  uint32_t *data = malloc(count * sizeof(uint32_t));
693  if (!data)
694  return JIM_ERR;
695 
696  jim_wide i;
697  for (i = 0; i < count; i++) {
698  jim_wide tmp;
699  e = jim_getopt_wide(&goi, &tmp);
700  if (e != JIM_OK) {
701  free(data);
702  return e;
703  }
704  data[i] = (uint32_t)tmp;
705  }
706 
707  /* all args must be consumed */
708  if (goi.argc != 0) {
709  free(data);
710  return JIM_ERR;
711  }
712 
714  assert(cmd_ctx);
715  struct target *target = get_current_target(cmd_ctx);
716  int result;
717 
718  result = target_write_buffer(target, address, count * 4, (const uint8_t *)data);
719 
720  free(data);
721 
722  return result;
723 }
724 
725 static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
726 {
727  const char *cmd_name = Jim_GetString(argv[0], NULL);
728 
729  struct jim_getopt_info goi;
730  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
731 
732  if (goi.argc < 3) {
733  Jim_SetResultFormatted(goi.interp,
734  "usage: %s # of pairs [<address> <data>]+", cmd_name);
735  return JIM_ERR;
736  }
737 
738  int e;
739  jim_wide num_of_pairs;
740  e = jim_getopt_wide(&goi, &num_of_pairs);
741  if (e != JIM_OK)
742  return e;
743 
745  assert(cmd_ctx);
746  struct target *target = get_current_target(cmd_ctx);
747  struct aice_port_s *aice = target_to_aice(target);
748  int result;
749  uint32_t address;
750  uint32_t data;
751  jim_wide i;
752 
754  for (i = 0; i < num_of_pairs; i++) {
755  jim_wide tmp;
756  e = jim_getopt_wide(&goi, &tmp);
757  if (e != JIM_OK)
758  break;
759  address = (uint32_t)tmp;
760 
761  e = jim_getopt_wide(&goi, &tmp);
762  if (e != JIM_OK)
763  break;
764  data = (uint32_t)tmp;
765 
766  result = target_write_buffer(target, address, 4, (const uint8_t *)&data);
767  if (result != ERROR_OK)
768  break;
769  }
771 
772  /* all args must be consumed */
773  if (goi.argc != 0)
774  return JIM_ERR;
775 
776  return ERROR_OK;
777 }
778 
779 static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
780 {
781  const char *cmd_name = Jim_GetString(argv[0], NULL);
782 
783  struct jim_getopt_info goi;
784  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
785 
786  if (goi.argc < 2) {
787  Jim_SetResultFormatted(goi.interp,
788  "usage: %s <address> <count>", cmd_name);
789  return JIM_ERR;
790  }
791 
792  int e;
793  jim_wide address;
794  e = jim_getopt_wide(&goi, &address);
795  if (e != JIM_OK)
796  return e;
797 
798  jim_wide count;
799  e = jim_getopt_wide(&goi, &count);
800  if (e != JIM_OK)
801  return e;
802 
803  /* all args must be consumed */
804  if (goi.argc != 0)
805  return JIM_ERR;
806 
808  assert(cmd_ctx);
809  struct target *target = get_current_target(cmd_ctx);
810  uint32_t *data = malloc(count * sizeof(uint32_t));
811  int result;
812  result = target_read_buffer(target, address, count * 4, (uint8_t *)data);
813  char data_str[12];
814 
815  jim_wide i;
816  Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
817  for (i = 0; i < count; i++) {
818  sprintf(data_str, "0x%08" PRIx32 " ", data[i]);
819  Jim_AppendStrings(interp, Jim_GetResult(interp), data_str, NULL);
820  }
821 
822  free(data);
823 
824  return result;
825 }
826 
827 static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
828 {
829  const char *cmd_name = Jim_GetString(argv[0], NULL);
830 
831  struct jim_getopt_info goi;
832  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
833 
834  if (goi.argc < 1) {
835  Jim_SetResultFormatted(goi.interp,
836  "usage: %s <edm_sr_name>", cmd_name);
837  return JIM_ERR;
838  }
839 
840  int e;
841  const char *edm_sr_name;
842  int edm_sr_name_len;
843  e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
844  if (e != JIM_OK)
845  return e;
846 
847  /* all args must be consumed */
848  if (goi.argc != 0)
849  return JIM_ERR;
850 
851  uint32_t edm_sr_number;
852  uint32_t edm_sr_value;
853  if (strncmp(edm_sr_name, "edm_dtr", edm_sr_name_len) == 0)
854  edm_sr_number = NDS_EDM_SR_EDM_DTR;
855  else if (strncmp(edm_sr_name, "edmsw", edm_sr_name_len) == 0)
856  edm_sr_number = NDS_EDM_SR_EDMSW;
857  else
858  return ERROR_FAIL;
859 
861  assert(cmd_ctx);
862  struct target *target = get_current_target(cmd_ctx);
863  struct aice_port_s *aice = target_to_aice(target);
864  char data_str[11];
865 
866  aice_read_debug_reg(aice, edm_sr_number, &edm_sr_value);
867 
868  sprintf(data_str, "0x%08" PRIx32, edm_sr_value);
869  Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
870  Jim_AppendStrings(interp, Jim_GetResult(interp), data_str, NULL);
871 
872  return ERROR_OK;
873 }
874 
875 static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
876 {
877  const char *cmd_name = Jim_GetString(argv[0], NULL);
878 
879  struct jim_getopt_info goi;
880  jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
881 
882  if (goi.argc < 2) {
883  Jim_SetResultFormatted(goi.interp,
884  "usage: %s <edm_sr_name> <value>", cmd_name);
885  return JIM_ERR;
886  }
887 
888  int e;
889  const char *edm_sr_name;
890  int edm_sr_name_len;
891  e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
892  if (e != JIM_OK)
893  return e;
894 
895  jim_wide value;
896  e = jim_getopt_wide(&goi, &value);
897  if (e != JIM_OK)
898  return e;
899 
900  /* all args must be consumed */
901  if (goi.argc != 0)
902  return JIM_ERR;
903 
904  uint32_t edm_sr_number;
905  if (strncmp(edm_sr_name, "edm_dtr", edm_sr_name_len) == 0)
906  edm_sr_number = NDS_EDM_SR_EDM_DTR;
907  else
908  return ERROR_FAIL;
909 
911  assert(cmd_ctx);
912  struct target *target = get_current_target(cmd_ctx);
913  struct aice_port_s *aice = target_to_aice(target);
914 
915  aice_write_debug_reg(aice, edm_sr_number, value);
916 
917  return ERROR_OK;
918 }
919 
920 static const struct command_registration nds32_query_command_handlers[] = {
921  {
922  .name = "target",
923  .handler = handle_nds32_query_target_command,
924  .mode = COMMAND_EXEC,
925  .usage = "",
926  .help = "reply 'OCD' for gdb to identify server-side is OpenOCD",
927  },
928  {
929  .name = "endian",
930  .handler = handle_nds32_query_endian_command,
931  .mode = COMMAND_EXEC,
932  .usage = "",
933  .help = "query target endian",
934  },
935  {
936  .name = "cpuid",
937  .handler = handle_nds32_query_cpuid_command,
938  .mode = COMMAND_EXEC,
939  .usage = "",
940  .help = "query CPU ID",
941  },
942 
944 };
945 
946 static const struct command_registration nds32_exec_command_handlers[] = {
947  {
948  .name = "dssim",
949  .handler = handle_nds32_dssim_command,
950  .mode = COMMAND_EXEC,
951  .usage = "['on'|'off']",
952  .help = "display/change $INT_MASK.DSSIM status",
953  },
954  {
955  .name = "mem_access",
956  .handler = handle_nds32_memory_access_command,
957  .mode = COMMAND_EXEC,
958  .usage = "['bus'|'cpu']",
959  .help = "display/change memory access channel",
960  },
961  {
962  .name = "mem_mode",
963  .handler = handle_nds32_memory_mode_command,
964  .mode = COMMAND_EXEC,
965  .usage = "['auto'|'mem'|'ilm'|'dlm']",
966  .help = "display/change memory mode",
967  },
968  {
969  .name = "cache",
970  .handler = handle_nds32_cache_command,
971  .mode = COMMAND_EXEC,
972  .usage = "['invalidate']",
973  .help = "cache control",
974  },
975  {
976  .name = "icache",
977  .handler = handle_nds32_icache_command,
978  .mode = COMMAND_EXEC,
979  .usage = "['invalidate'|'enable'|'disable'|'dump']",
980  .help = "icache control",
981  },
982  {
983  .name = "dcache",
984  .handler = handle_nds32_dcache_command,
985  .mode = COMMAND_EXEC,
986  .usage = "['invalidate'|'enable'|'disable'|'dump']",
987  .help = "dcache control",
988  },
989  {
990  .name = "auto_break",
991  .handler = handle_nds32_auto_break_command,
992  .mode = COMMAND_EXEC,
993  .usage = "['on'|'off']",
994  .help = "convert software breakpoints to hardware breakpoints if needed",
995  },
996  {
997  .name = "virtual_hosting",
998  .handler = handle_nds32_virtual_hosting_command,
999  .mode = COMMAND_ANY,
1000  .usage = "['on'|'off']",
1001  .help = "turn on/off virtual hosting",
1002  },
1003  {
1004  .name = "global_stop",
1005  .handler = handle_nds32_global_stop_command,
1006  .mode = COMMAND_ANY,
1007  .usage = "['on'|'off']",
1008  .help = "turn on/off global stop. After turning on, every load/store "
1009  "instructions will be stopped to check memory access.",
1010  },
1011  {
1012  .name = "soft_reset_halt",
1013  .handler = handle_nds32_soft_reset_halt_command,
1014  .mode = COMMAND_ANY,
1015  .usage = "['on'|'off']",
1016  .help = "as issuing rest-halt, to use soft-reset-halt or not."
1017  "the feature is for backward-compatible.",
1018  },
1019  {
1020  .name = "boot_time",
1021  .handler = handle_nds32_boot_time_command,
1022  .mode = COMMAND_CONFIG,
1023  .usage = "milliseconds",
1024  .help = "set the period to wait after srst.",
1025  },
1026  {
1027  .name = "login_edm_passcode",
1028  .handler = handle_nds32_login_edm_passcode_command,
1029  .mode = COMMAND_CONFIG,
1030  .usage = "passcode",
1031  .help = "set EDM passcode for secure MCU debugging.",
1032  },
1033  {
1034  .name = "login_edm_operation",
1035  .handler = handle_nds32_login_edm_operation_command,
1036  .mode = COMMAND_CONFIG,
1037  .usage = "misc_reg_no value",
1038  .help = "add EDM operations for secure MCU debugging.",
1039  },
1040  {
1041  .name = "reset_halt_as_init",
1042  .handler = handle_nds32_reset_halt_as_init_command,
1043  .mode = COMMAND_CONFIG,
1044  .usage = "['on'|'off']",
1045  .help = "reset halt as openocd init.",
1046  },
1047  {
1048  .name = "keep_target_edm_ctl",
1049  .handler = handle_nds32_keep_target_edm_ctl_command,
1050  .mode = COMMAND_CONFIG,
1051  .usage = "['on'|'off']",
1052  .help = "Backup/Restore target EDM_CTL register.",
1053  },
1054  {
1055  .name = "decode",
1056  .handler = handle_nds32_decode_command,
1057  .mode = COMMAND_EXEC,
1058  .usage = "address icount",
1059  .help = "decode instruction.",
1060  },
1061  {
1062  .name = "word_access_mem",
1063  .handler = handle_nds32_word_access_mem_command,
1064  .mode = COMMAND_ANY,
1065  .usage = "['on'|'off']",
1066  .help = "Always use word-aligned address to access memory.",
1067  },
1068  {
1069  .name = "bulk_write",
1070  .jim_handler = jim_nds32_bulk_write,
1071  .mode = COMMAND_EXEC,
1072  .help = "Write multiple 32-bit words to target memory",
1073  .usage = "address count data",
1074  },
1075  {
1076  .name = "multi_write",
1077  .jim_handler = jim_nds32_multi_write,
1078  .mode = COMMAND_EXEC,
1079  .help = "Write multiple addresses/words to target memory",
1080  .usage = "num_of_pairs [address data]+",
1081  },
1082  {
1083  .name = "bulk_read",
1084  .jim_handler = jim_nds32_bulk_read,
1085  .mode = COMMAND_EXEC,
1086  .help = "Read multiple 32-bit words from target memory",
1087  .usage = "address count",
1088  },
1089  {
1090  .name = "read_edmsr",
1091  .jim_handler = jim_nds32_read_edm_sr,
1092  .mode = COMMAND_EXEC,
1093  .help = "Read EDM system register",
1094  .usage = "['edmsw'|'edm_dtr']",
1095  },
1096  {
1097  .name = "write_edmsr",
1098  .jim_handler = jim_nds32_write_edm_sr,
1099  .mode = COMMAND_EXEC,
1100  .help = "Write EDM system register",
1101  .usage = "['edm_dtr'] value",
1102  },
1103  {
1104  .name = "query",
1105  .mode = COMMAND_EXEC,
1106  .help = "Andes query command group",
1107  .usage = "",
1109  },
1110 
1112 };
1113 
1115  {
1116  .name = "nds",
1117  .mode = COMMAND_ANY,
1118  .help = "Andes command group",
1119  .usage = "",
1120  .chain = nds32_exec_command_handlers,
1121  },
1123 };
@ AICE_COMMAND_MODE_NORMAL
Definition: aice_port.h:90
@ AICE_COMMAND_MODE_PACK
Definition: aice_port.h:91
@ AICE_CACHE_CTL_L1D_WBALL
Definition: aice_port.h:83
@ AICE_CACHE_CTL_L1D_INVALALL
Definition: aice_port.h:81
@ AICE_CACHE_CTL_L1I_INVALALL
Definition: aice_port.h:85
struct command_context * current_command_context(Jim_Interp *interp)
Definition: command.c:187
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:473
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:140
#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 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 CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:145
#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
@ COMMAND_EXEC
Definition: command.h:40
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
Definition: jim-nvp.c:221
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
Definition: jim-nvp.c:148
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:187
#define ERROR_FAIL
Definition: log.h:161
#define LOG_INFO(expr ...)
Definition: log.h:117
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
int nds32_get_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t *value)
Definition: nds32.c:513
int nds32_set_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t value)
set register internally
Definition: nds32.c:532
Holds the interface to Andes cores.
#define NDS32_EDM_OPERATION_MAX_NUM
Definition: nds32.h:20
static struct nds32 * target_to_nds32(struct target *target)
Convert target handle to generic Andes target state handle.
Definition: nds32.h:422
static bool is_nds32(struct nds32 *nds32)
Definition: nds32.h:435
static struct aice_port_s * target_to_aice(struct target *target)
Definition: nds32.h:429
int aice_cache_ctl(struct aice_port_s *aice, uint32_t subtype, uint32_t address)
Definition: nds32_aice.c:45
int aice_set_command_mode(struct aice_port_s *aice, enum aice_command_mode command_mode)
Definition: nds32_aice.c:75
static int aice_write_debug_reg(struct aice_port_s *aice, uint32_t addr, const uint32_t val)
Definition: nds32_aice.h:85
static int aice_read_debug_reg(struct aice_port_s *aice, uint32_t addr, uint32_t *val)
Definition: nds32_aice.h:79
static int aice_memory_access(struct aice_port_s *aice, enum nds_memory_access a_access)
Definition: nds32_aice.h:132
static int aice_memory_mode(struct aice_port_s *aice, enum nds_memory_select mem_select)
Definition: nds32_aice.h:138
uint32_t nds32_edm_ops_num
Definition: nds32.c:20
static const char *const nds_memory_access_name[]
Definition: nds32_cmd.c:20
COMMAND_HANDLER(handle_nds32_dssim_command)
Definition: nds32_cmd.c:32
const struct command_registration nds32_command_handlers[]
Definition: nds32_cmd.c:1114
struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM]
Definition: nds32.c:19
static const struct command_registration nds32_query_command_handlers[]
Definition: nds32_cmd.c:920
static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: nds32_cmd.c:779
static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: nds32_cmd.c:875
static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: nds32_cmd.c:725
static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: nds32_cmd.c:668
static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: nds32_cmd.c:827
static const char *const nds_memory_select_name[]
Definition: nds32_cmd.c:25
static const struct command_registration nds32_exec_command_handlers[]
Definition: nds32_cmd.c:946
int nds32_evaluate_opcode(struct nds32 *nds32, uint32_t opcode, uint32_t address, struct nds32_instruction *instruction)
int nds32_read_opcode(struct nds32 *nds32, uint32_t address, uint32_t *value)
@ NDS_EDM_SR_EDM_DTR
Definition: nds32_edm.h:75
@ NDS_EDM_SR_EDMSW
Definition: nds32_edm.h:73
@ NDS_MEMORY_SELECT_DLM
Definition: nds32_edm.h:91
@ NDS_MEMORY_SELECT_MEM
Definition: nds32_edm.h:89
@ NDS_MEMORY_SELECT_ILM
Definition: nds32_edm.h:90
@ NDS_MEMORY_SELECT_AUTO
Definition: nds32_edm.h:88
@ NDS_MEMORY_ACC_CPU
Definition: nds32_edm.h:84
@ NDS_MEMORY_ACC_BUS
Definition: nds32_edm.h:83
@ IR0
Definition: nds32_reg.h:61
@ IR8
Definition: nds32_reg.h:69
uint32_t addr
Definition: nuttx.c:65
Jim_Interp * interp
Definition: command.h:53
const char * name
Definition: command.h:229
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:135
Jim_Interp * interp
Definition: jim-nvp.h:136
Jim_Obj *const * argv
Definition: jim-nvp.h:138
int line_size
cache line size
Definition: nds32.h:107
bool enable
enable cache or not
Definition: nds32.h:98
uint32_t reg_no
Definition: nds32.h:360
uint32_t value
Definition: nds32.h:361
bool direct_access_local_memory
EDM_CFG.DALM, indicate if direct local memory access feature is supported or not.
Definition: nds32.h:86
bool access_control
Support ACC_CTL register.
Definition: nds32.h:89
enum nds_memory_access access_channel
Memory access method.
Definition: nds32.h:158
int dlm_base
On-chip data local memory base.
Definition: nds32.h:140
int ilm_base
On-chip instruction local memory base.
Definition: nds32.h:122
struct nds32_cache dcache
DCache.
Definition: nds32.h:119
struct nds32_cache icache
ICache.
Definition: nds32.h:116
enum nds_memory_select mode
Memory access mode.
Definition: nds32.h:161
Represents a generic Andes core.
Definition: nds32.h:226
bool auto_convert_hw_bp
Flag to indicate if auto convert software breakpoints to hardware breakpoints or not in ROM.
Definition: nds32.h:340
uint32_t boot_time
Period to wait after SRST.
Definition: nds32.h:315
bool reset_halt_as_examine
reset-halt as target examine
Definition: nds32.h:296
bool keep_target_edm_ctl
backup/restore target EDM_CTL value.
Definition: nds32.h:300
bool word_access_mem
always use word-aligned address to access memory
Definition: nds32.h:306
struct nds32_memory memory
Memory information.
Definition: nds32.h:235
bool global_stop
Flag reporting whether global stop is active.
Definition: nds32.h:290
bool soft_reset_halt
Flag reporting whether to use soft-reset-halt or not as issuing reset-halt.
Definition: nds32.h:293
char * edm_passcode
EDM passcode for debugging secure MCU.
Definition: nds32.h:309
struct nds32_edm edm
Handle for the debug module.
Definition: nds32.h:232
bool virtual_hosting
Flag reporting whether virtual hosting is active.
Definition: nds32.h:273
bool step_isr_enable
Flag to indicate HSS steps into ISR or not.
Definition: nds32.h:318
Definition: target.h:120
char * cmd_name
Definition: target.h:122
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
Definition: target.c:2408
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
Definition: target.c:2473
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:536
static const char * target_name(struct target *target)
Returns the instance-specific name of the specified target.
Definition: target.h:234
#define NULL
Definition: usb.h:16
uint8_t count[4]
Definition: vdebug.c:22