You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1135 lines
29 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2013 Andes Technology *
  3. * Hsiangkai Wang <hkwang@andestech.com> *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <helper/command.h>
  22. #include "nds32.h"
  23. #include "nds32_aice.h"
  24. #include "nds32_disassembler.h"
  25. extern struct nds32_edm_operation nds32_edm_ops[NDS32_EDM_OPERATION_MAX_NUM];
  26. extern uint32_t nds32_edm_ops_num;
  27. static const char *const nds_memory_access_name[] = {
  28. "BUS",
  29. "CPU",
  30. };
  31. static const char *const nds_memory_select_name[] = {
  32. "AUTO",
  33. "MEM",
  34. "ILM",
  35. "DLM",
  36. };
  37. COMMAND_HANDLER(handle_nds32_dssim_command)
  38. {
  39. struct target *target = get_current_target(CMD_CTX);
  40. struct nds32 *nds32 = target_to_nds32(target);
  41. if (!is_nds32(nds32)) {
  42. command_print(CMD, "current target isn't an Andes core");
  43. return ERROR_FAIL;
  44. }
  45. if (CMD_ARGC > 0) {
  46. if (strcmp(CMD_ARGV[0], "on") == 0)
  47. nds32->step_isr_enable = true;
  48. if (strcmp(CMD_ARGV[0], "off") == 0)
  49. nds32->step_isr_enable = false;
  50. }
  51. command_print(CMD, "%s: $INT_MASK.DSSIM: %d", target_name(target),
  52. nds32->step_isr_enable);
  53. return ERROR_OK;
  54. }
  55. COMMAND_HANDLER(handle_nds32_memory_access_command)
  56. {
  57. struct target *target = get_current_target(CMD_CTX);
  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. if (!is_nds32(nds32)) {
  62. command_print(CMD, "current target isn't an Andes core");
  63. return ERROR_FAIL;
  64. }
  65. if (CMD_ARGC > 0) {
  66. if (strcmp(CMD_ARGV[0], "bus") == 0)
  67. memory->access_channel = NDS_MEMORY_ACC_BUS;
  68. else if (strcmp(CMD_ARGV[0], "cpu") == 0)
  69. memory->access_channel = NDS_MEMORY_ACC_CPU;
  70. else /* default access channel is NDS_MEMORY_ACC_CPU */
  71. memory->access_channel = NDS_MEMORY_ACC_CPU;
  72. LOG_DEBUG("memory access channel is changed to %s",
  73. nds_memory_access_name[memory->access_channel]);
  74. aice_memory_access(aice, memory->access_channel);
  75. } else {
  76. command_print(CMD, "%s: memory access channel: %s",
  77. target_name(target),
  78. nds_memory_access_name[memory->access_channel]);
  79. }
  80. return ERROR_OK;
  81. }
  82. COMMAND_HANDLER(handle_nds32_memory_mode_command)
  83. {
  84. struct target *target = get_current_target(CMD_CTX);
  85. struct nds32 *nds32 = target_to_nds32(target);
  86. struct aice_port_s *aice = target_to_aice(target);
  87. if (!is_nds32(nds32)) {
  88. command_print(CMD, "current target isn't an Andes core");
  89. return ERROR_FAIL;
  90. }
  91. if (CMD_ARGC > 0) {
  92. if (nds32->edm.access_control == false) {
  93. command_print(CMD, "%s does not support ACC_CTL. "
  94. "Set memory mode to MEMORY", target_name(target));
  95. nds32->memory.mode = NDS_MEMORY_SELECT_MEM;
  96. } else if (nds32->edm.direct_access_local_memory == false) {
  97. command_print(CMD, "%s does not support direct access "
  98. "local memory. Set memory mode to MEMORY",
  99. target_name(target));
  100. nds32->memory.mode = NDS_MEMORY_SELECT_MEM;
  101. /* set to ACC_CTL */
  102. aice_memory_mode(aice, nds32->memory.mode);
  103. } else {
  104. if (strcmp(CMD_ARGV[0], "auto") == 0) {
  105. nds32->memory.mode = NDS_MEMORY_SELECT_AUTO;
  106. } else if (strcmp(CMD_ARGV[0], "mem") == 0) {
  107. nds32->memory.mode = NDS_MEMORY_SELECT_MEM;
  108. } else if (strcmp(CMD_ARGV[0], "ilm") == 0) {
  109. if (nds32->memory.ilm_base == 0)
  110. command_print(CMD, "%s does not support ILM",
  111. target_name(target));
  112. else
  113. nds32->memory.mode = NDS_MEMORY_SELECT_ILM;
  114. } else if (strcmp(CMD_ARGV[0], "dlm") == 0) {
  115. if (nds32->memory.dlm_base == 0)
  116. command_print(CMD, "%s does not support DLM",
  117. target_name(target));
  118. else
  119. nds32->memory.mode = NDS_MEMORY_SELECT_DLM;
  120. }
  121. /* set to ACC_CTL */
  122. aice_memory_mode(aice, nds32->memory.mode);
  123. }
  124. }
  125. command_print(CMD, "%s: memory mode: %s",
  126. target_name(target),
  127. nds_memory_select_name[nds32->memory.mode]);
  128. return ERROR_OK;
  129. }
  130. COMMAND_HANDLER(handle_nds32_cache_command)
  131. {
  132. struct target *target = get_current_target(CMD_CTX);
  133. struct nds32 *nds32 = target_to_nds32(target);
  134. struct aice_port_s *aice = target_to_aice(target);
  135. struct nds32_cache *icache = &(nds32->memory.icache);
  136. struct nds32_cache *dcache = &(nds32->memory.dcache);
  137. int result;
  138. if (!is_nds32(nds32)) {
  139. command_print(CMD, "current target isn't an Andes core");
  140. return ERROR_FAIL;
  141. }
  142. if (CMD_ARGC > 0) {
  143. if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
  144. if ((dcache->line_size != 0) && (dcache->enable == true)) {
  145. /* D$ write back */
  146. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0);
  147. if (result != ERROR_OK) {
  148. command_print(CMD, "%s: Write back data cache...failed",
  149. target_name(target));
  150. return result;
  151. }
  152. command_print(CMD, "%s: Write back data cache...done",
  153. target_name(target));
  154. /* D$ invalidate */
  155. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0);
  156. if (result != ERROR_OK) {
  157. command_print(CMD, "%s: Invalidate data cache...failed",
  158. target_name(target));
  159. return result;
  160. }
  161. command_print(CMD, "%s: Invalidate data cache...done",
  162. target_name(target));
  163. } else {
  164. if (dcache->line_size == 0)
  165. command_print(CMD, "%s: No data cache",
  166. target_name(target));
  167. else
  168. command_print(CMD, "%s: Data cache disabled",
  169. target_name(target));
  170. }
  171. if ((icache->line_size != 0) && (icache->enable == true)) {
  172. /* I$ invalidate */
  173. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0);
  174. if (result != ERROR_OK) {
  175. command_print(CMD, "%s: Invalidate instruction cache...failed",
  176. target_name(target));
  177. return result;
  178. }
  179. command_print(CMD, "%s: Invalidate instruction cache...done",
  180. target_name(target));
  181. } else {
  182. if (icache->line_size == 0)
  183. command_print(CMD, "%s: No instruction cache",
  184. target_name(target));
  185. else
  186. command_print(CMD, "%s: Instruction cache disabled",
  187. target_name(target));
  188. }
  189. } else
  190. command_print(CMD, "No valid parameter");
  191. }
  192. return ERROR_OK;
  193. }
  194. COMMAND_HANDLER(handle_nds32_icache_command)
  195. {
  196. struct target *target = get_current_target(CMD_CTX);
  197. struct nds32 *nds32 = target_to_nds32(target);
  198. struct aice_port_s *aice = target_to_aice(target);
  199. struct nds32_cache *icache = &(nds32->memory.icache);
  200. int result;
  201. if (!is_nds32(nds32)) {
  202. command_print(CMD, "current target isn't an Andes core");
  203. return ERROR_FAIL;
  204. }
  205. if (CMD_ARGC > 0) {
  206. if (icache->line_size == 0) {
  207. command_print(CMD, "%s: No instruction cache",
  208. target_name(target));
  209. return ERROR_OK;
  210. }
  211. if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
  212. if (icache->enable == true) {
  213. /* I$ invalidate */
  214. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0);
  215. if (result != ERROR_OK) {
  216. command_print(CMD, "%s: Invalidate instruction cache...failed",
  217. target_name(target));
  218. return result;
  219. }
  220. command_print(CMD, "%s: Invalidate instruction cache...done",
  221. target_name(target));
  222. } else {
  223. command_print(CMD, "%s: Instruction cache disabled",
  224. target_name(target));
  225. }
  226. } else if (strcmp(CMD_ARGV[0], "enable") == 0) {
  227. uint32_t value;
  228. nds32_get_mapped_reg(nds32, IR8, &value);
  229. nds32_set_mapped_reg(nds32, IR8, value | 0x1);
  230. } else if (strcmp(CMD_ARGV[0], "disable") == 0) {
  231. uint32_t value;
  232. nds32_get_mapped_reg(nds32, IR8, &value);
  233. nds32_set_mapped_reg(nds32, IR8, value & ~0x1);
  234. } else if (strcmp(CMD_ARGV[0], "dump") == 0) {
  235. /* TODO: dump cache content */
  236. } else {
  237. command_print(CMD, "%s: No valid parameter", target_name(target));
  238. }
  239. }
  240. return ERROR_OK;
  241. }
  242. COMMAND_HANDLER(handle_nds32_dcache_command)
  243. {
  244. struct target *target = get_current_target(CMD_CTX);
  245. struct nds32 *nds32 = target_to_nds32(target);
  246. struct aice_port_s *aice = target_to_aice(target);
  247. struct nds32_cache *dcache = &(nds32->memory.dcache);
  248. int result;
  249. if (!is_nds32(nds32)) {
  250. command_print(CMD, "current target isn't an Andes core");
  251. return ERROR_FAIL;
  252. }
  253. if (CMD_ARGC > 0) {
  254. if (dcache->line_size == 0) {
  255. command_print(CMD, "%s: No data cache", target_name(target));
  256. return ERROR_OK;
  257. }
  258. if (strcmp(CMD_ARGV[0], "invalidate") == 0) {
  259. if (dcache->enable == true) {
  260. /* D$ write back */
  261. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0);
  262. if (result != ERROR_OK) {
  263. command_print(CMD, "%s: Write back data cache...failed",
  264. target_name(target));
  265. return result;
  266. }
  267. command_print(CMD, "%s: Write back data cache...done",
  268. target_name(target));
  269. /* D$ invalidate */
  270. result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0);
  271. if (result != ERROR_OK) {
  272. command_print(CMD, "%s: Invalidate data cache...failed",
  273. target_name(target));
  274. return result;
  275. }
  276. command_print(CMD, "%s: Invalidate data cache...done",
  277. target_name(target));
  278. } else {
  279. command_print(CMD, "%s: Data cache disabled",
  280. target_name(target));
  281. }
  282. } else if (strcmp(CMD_ARGV[0], "enable") == 0) {
  283. uint32_t value;
  284. nds32_get_mapped_reg(nds32, IR8, &value);
  285. nds32_set_mapped_reg(nds32, IR8, value | 0x2);
  286. } else if (strcmp(CMD_ARGV[0], "disable") == 0) {
  287. uint32_t value;
  288. nds32_get_mapped_reg(nds32, IR8, &value);
  289. nds32_set_mapped_reg(nds32, IR8, value & ~0x2);
  290. } else if (strcmp(CMD_ARGV[0], "dump") == 0) {
  291. /* TODO: dump cache content */
  292. } else {
  293. command_print(CMD, "%s: No valid parameter", target_name(target));
  294. }
  295. }
  296. return ERROR_OK;
  297. }
  298. COMMAND_HANDLER(handle_nds32_auto_break_command)
  299. {
  300. struct target *target = get_current_target(CMD_CTX);
  301. struct nds32 *nds32 = target_to_nds32(target);
  302. if (!is_nds32(nds32)) {
  303. command_print(CMD, "current target isn't an Andes core");
  304. return ERROR_FAIL;
  305. }
  306. if (CMD_ARGC > 0) {
  307. if (strcmp(CMD_ARGV[0], "on") == 0)
  308. nds32->auto_convert_hw_bp = true;
  309. if (strcmp(CMD_ARGV[0], "off") == 0)
  310. nds32->auto_convert_hw_bp = false;
  311. }
  312. if (nds32->auto_convert_hw_bp)
  313. command_print(CMD, "%s: convert sw break to hw break on ROM: on",
  314. target_name(target));
  315. else
  316. command_print(CMD, "%s: convert sw break to hw break on ROM: off",
  317. target_name(target));
  318. return ERROR_OK;
  319. }
  320. COMMAND_HANDLER(handle_nds32_virtual_hosting_command)
  321. {
  322. struct target *target = get_current_target(CMD_CTX);
  323. struct nds32 *nds32 = target_to_nds32(target);
  324. if (!is_nds32(nds32)) {
  325. command_print(CMD, "current target isn't an Andes core");
  326. return ERROR_FAIL;
  327. }
  328. if (CMD_ARGC > 0) {
  329. if (strcmp(CMD_ARGV[0], "on") == 0)
  330. nds32->virtual_hosting = true;
  331. if (strcmp(CMD_ARGV[0], "off") == 0)
  332. nds32->virtual_hosting = false;
  333. }
  334. if (nds32->virtual_hosting)
  335. command_print(CMD, "%s: virtual hosting: on", target_name(target));
  336. else
  337. command_print(CMD, "%s: virtual hosting: off", target_name(target));
  338. return ERROR_OK;
  339. }
  340. COMMAND_HANDLER(handle_nds32_global_stop_command)
  341. {
  342. struct target *target = get_current_target(CMD_CTX);
  343. struct nds32 *nds32 = target_to_nds32(target);
  344. if (!is_nds32(nds32)) {
  345. command_print(CMD, "current target isn't an Andes core");
  346. return ERROR_FAIL;
  347. }
  348. if (CMD_ARGC > 0) {
  349. if (strcmp(CMD_ARGV[0], "on") == 0)
  350. nds32->global_stop = true;
  351. if (strcmp(CMD_ARGV[0], "off") == 0)
  352. nds32->global_stop = false;
  353. }
  354. if (nds32->global_stop)
  355. LOG_INFO("%s: global stop: on", target_name(target));
  356. else
  357. LOG_INFO("%s: global stop: off", target_name(target));
  358. return ERROR_OK;
  359. }
  360. COMMAND_HANDLER(handle_nds32_soft_reset_halt_command)
  361. {
  362. struct target *target = get_current_target(CMD_CTX);
  363. struct nds32 *nds32 = target_to_nds32(target);
  364. if (!is_nds32(nds32)) {
  365. command_print(CMD, "current target isn't an Andes core");
  366. return ERROR_FAIL;
  367. }
  368. if (CMD_ARGC > 0) {
  369. if (strcmp(CMD_ARGV[0], "on") == 0)
  370. nds32->soft_reset_halt = true;
  371. if (strcmp(CMD_ARGV[0], "off") == 0)
  372. nds32->soft_reset_halt = false;
  373. }
  374. if (nds32->soft_reset_halt)
  375. LOG_INFO("%s: soft-reset-halt: on", target_name(target));
  376. else
  377. LOG_INFO("%s: soft-reset-halt: off", target_name(target));
  378. return ERROR_OK;
  379. }
  380. COMMAND_HANDLER(handle_nds32_boot_time_command)
  381. {
  382. struct target *target = get_current_target(CMD_CTX);
  383. struct nds32 *nds32 = target_to_nds32(target);
  384. if (!is_nds32(nds32)) {
  385. command_print(CMD, "current target isn't an Andes core");
  386. return ERROR_FAIL;
  387. }
  388. if (CMD_ARGC > 0)
  389. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], nds32->boot_time);
  390. return ERROR_OK;
  391. }
  392. COMMAND_HANDLER(handle_nds32_login_edm_passcode_command)
  393. {
  394. struct target *target = get_current_target(CMD_CTX);
  395. struct nds32 *nds32 = target_to_nds32(target);
  396. if (!is_nds32(nds32)) {
  397. command_print(CMD, "current target isn't an Andes core");
  398. return ERROR_FAIL;
  399. }
  400. nds32->edm_passcode = strdup(CMD_ARGV[0]);
  401. return ERROR_OK;
  402. }
  403. COMMAND_HANDLER(handle_nds32_login_edm_operation_command)
  404. {
  405. struct target *target = get_current_target(CMD_CTX);
  406. struct nds32 *nds32 = target_to_nds32(target);
  407. if (!is_nds32(nds32)) {
  408. command_print(CMD, "current target isn't an Andes core");
  409. return ERROR_FAIL;
  410. }
  411. if (CMD_ARGC > 1) {
  412. uint32_t misc_reg_no;
  413. uint32_t data;
  414. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], misc_reg_no);
  415. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], data);
  416. if (nds32_edm_ops_num >= NDS32_EDM_OPERATION_MAX_NUM)
  417. return ERROR_FAIL;
  418. /* Just save the operation. Execute it in nds32_login() */
  419. nds32_edm_ops[nds32_edm_ops_num].reg_no = misc_reg_no;
  420. nds32_edm_ops[nds32_edm_ops_num].value = data;
  421. nds32_edm_ops_num++;
  422. } else
  423. return ERROR_FAIL;
  424. return ERROR_OK;
  425. }
  426. COMMAND_HANDLER(handle_nds32_reset_halt_as_init_command)
  427. {
  428. struct target *target = get_current_target(CMD_CTX);
  429. struct nds32 *nds32 = target_to_nds32(target);
  430. if (!is_nds32(nds32)) {
  431. command_print(CMD, "current target isn't an Andes core");
  432. return ERROR_FAIL;
  433. }
  434. if (CMD_ARGC > 0) {
  435. if (strcmp(CMD_ARGV[0], "on") == 0)
  436. nds32->reset_halt_as_examine = true;
  437. if (strcmp(CMD_ARGV[0], "off") == 0)
  438. nds32->reset_halt_as_examine = false;
  439. }
  440. return ERROR_OK;
  441. }
  442. COMMAND_HANDLER(handle_nds32_keep_target_edm_ctl_command)
  443. {
  444. struct target *target = get_current_target(CMD_CTX);
  445. struct nds32 *nds32 = target_to_nds32(target);
  446. if (!is_nds32(nds32)) {
  447. command_print(CMD, "current target isn't an Andes core");
  448. return ERROR_FAIL;
  449. }
  450. if (CMD_ARGC > 0) {
  451. if (strcmp(CMD_ARGV[0], "on") == 0)
  452. nds32->keep_target_edm_ctl = true;
  453. if (strcmp(CMD_ARGV[0], "off") == 0)
  454. nds32->keep_target_edm_ctl = false;
  455. }
  456. return ERROR_OK;
  457. }
  458. COMMAND_HANDLER(handle_nds32_decode_command)
  459. {
  460. struct target *target = get_current_target(CMD_CTX);
  461. struct nds32 *nds32 = target_to_nds32(target);
  462. if (!is_nds32(nds32)) {
  463. command_print(CMD, "current target isn't an Andes core");
  464. return ERROR_FAIL;
  465. }
  466. if (CMD_ARGC > 1) {
  467. uint32_t addr;
  468. uint32_t insn_count;
  469. uint32_t opcode;
  470. uint32_t read_addr;
  471. uint32_t i;
  472. struct nds32_instruction instruction;
  473. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr);
  474. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], insn_count);
  475. read_addr = addr;
  476. i = 0;
  477. while (i < insn_count) {
  478. if (ERROR_OK != nds32_read_opcode(nds32, read_addr, &opcode))
  479. return ERROR_FAIL;
  480. if (nds32_evaluate_opcode(nds32, opcode, read_addr, &instruction) != ERROR_OK)
  481. return ERROR_FAIL;
  482. command_print(CMD, "%s", instruction.text);
  483. read_addr += instruction.instruction_size;
  484. i++;
  485. }
  486. } else if (CMD_ARGC == 1) {
  487. uint32_t addr;
  488. uint32_t opcode;
  489. struct nds32_instruction instruction;
  490. COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr);
  491. if (ERROR_OK != nds32_read_opcode(nds32, addr, &opcode))
  492. return ERROR_FAIL;
  493. if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode, addr, &instruction))
  494. return ERROR_FAIL;
  495. command_print(CMD, "%s", instruction.text);
  496. } else
  497. return ERROR_FAIL;
  498. return ERROR_OK;
  499. }
  500. COMMAND_HANDLER(handle_nds32_word_access_mem_command)
  501. {
  502. struct target *target = get_current_target(CMD_CTX);
  503. struct nds32 *nds32 = target_to_nds32(target);
  504. if (!is_nds32(nds32)) {
  505. command_print(CMD, "current target isn't an Andes core");
  506. return ERROR_FAIL;
  507. }
  508. if (CMD_ARGC > 0) {
  509. if (strcmp(CMD_ARGV[0], "on") == 0)
  510. nds32->word_access_mem = true;
  511. if (strcmp(CMD_ARGV[0], "off") == 0)
  512. nds32->word_access_mem = false;
  513. }
  514. return ERROR_OK;
  515. }
  516. COMMAND_HANDLER(handle_nds32_query_target_command)
  517. {
  518. struct target *target = get_current_target(CMD_CTX);
  519. struct nds32 *nds32 = target_to_nds32(target);
  520. if (!is_nds32(nds32)) {
  521. command_print(CMD, "current target isn't an Andes core");
  522. return ERROR_FAIL;
  523. }
  524. command_print(CMD, "OCD");
  525. return ERROR_OK;
  526. }
  527. COMMAND_HANDLER(handle_nds32_query_endian_command)
  528. {
  529. struct target *target = get_current_target(CMD_CTX);
  530. struct nds32 *nds32 = target_to_nds32(target);
  531. if (!is_nds32(nds32)) {
  532. command_print(CMD, "current target isn't an Andes core");
  533. return ERROR_FAIL;
  534. }
  535. uint32_t value_psw;
  536. nds32_get_mapped_reg(nds32, IR0, &value_psw);
  537. if (value_psw & 0x20)
  538. command_print(CMD, "%s: BE", target_name(target));
  539. else
  540. command_print(CMD, "%s: LE", target_name(target));
  541. return ERROR_OK;
  542. }
  543. COMMAND_HANDLER(handle_nds32_query_cpuid_command)
  544. {
  545. struct target *target = get_current_target(CMD_CTX);
  546. struct nds32 *nds32 = target_to_nds32(target);
  547. if (!is_nds32(nds32)) {
  548. command_print(CMD, "current target isn't an Andes core");
  549. return ERROR_FAIL;
  550. }
  551. command_print(CMD, "CPUID: %s", target_name(target));
  552. return ERROR_OK;
  553. }
  554. static int jim_nds32_bulk_write(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  555. {
  556. const char *cmd_name = Jim_GetString(argv[0], NULL);
  557. struct jim_getopt_info goi;
  558. jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
  559. if (goi.argc < 3) {
  560. Jim_SetResultFormatted(goi.interp,
  561. "usage: %s <address> <count> <data>", cmd_name);
  562. return JIM_ERR;
  563. }
  564. int e;
  565. jim_wide address;
  566. e = jim_getopt_wide(&goi, &address);
  567. if (e != JIM_OK)
  568. return e;
  569. jim_wide count;
  570. e = jim_getopt_wide(&goi, &count);
  571. if (e != JIM_OK)
  572. return e;
  573. uint32_t *data = malloc(count * sizeof(uint32_t));
  574. if (!data)
  575. return JIM_ERR;
  576. jim_wide i;
  577. for (i = 0; i < count; i++) {
  578. jim_wide tmp;
  579. e = jim_getopt_wide(&goi, &tmp);
  580. if (e != JIM_OK) {
  581. free(data);
  582. return e;
  583. }
  584. data[i] = (uint32_t)tmp;
  585. }
  586. /* all args must be consumed */
  587. if (goi.argc != 0) {
  588. free(data);
  589. return JIM_ERR;
  590. }
  591. struct command_context *cmd_ctx = current_command_context(interp);
  592. assert(cmd_ctx);
  593. struct target *target = get_current_target(cmd_ctx);
  594. int result;
  595. result = target_write_buffer(target, address, count * 4, (const uint8_t *)data);
  596. free(data);
  597. return result;
  598. }
  599. static int jim_nds32_multi_write(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  600. {
  601. const char *cmd_name = Jim_GetString(argv[0], NULL);
  602. struct jim_getopt_info goi;
  603. jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
  604. if (goi.argc < 3) {
  605. Jim_SetResultFormatted(goi.interp,
  606. "usage: %s # of pairs [<address> <data>]+", cmd_name);
  607. return JIM_ERR;
  608. }
  609. int e;
  610. jim_wide num_of_pairs;
  611. e = jim_getopt_wide(&goi, &num_of_pairs);
  612. if (e != JIM_OK)
  613. return e;
  614. struct command_context *cmd_ctx = current_command_context(interp);
  615. assert(cmd_ctx);
  616. struct target *target = get_current_target(cmd_ctx);
  617. struct aice_port_s *aice = target_to_aice(target);
  618. int result;
  619. uint32_t address;
  620. uint32_t data;
  621. jim_wide i;
  622. aice_set_command_mode(aice, AICE_COMMAND_MODE_PACK);
  623. for (i = 0; i < num_of_pairs; i++) {
  624. jim_wide tmp;
  625. e = jim_getopt_wide(&goi, &tmp);
  626. if (e != JIM_OK)
  627. break;
  628. address = (uint32_t)tmp;
  629. e = jim_getopt_wide(&goi, &tmp);
  630. if (e != JIM_OK)
  631. break;
  632. data = (uint32_t)tmp;
  633. result = target_write_buffer(target, address, 4, (const uint8_t *)&data);
  634. if (result != ERROR_OK)
  635. break;
  636. }
  637. aice_set_command_mode(aice, AICE_COMMAND_MODE_NORMAL);
  638. /* all args must be consumed */
  639. if (goi.argc != 0)
  640. return JIM_ERR;
  641. return ERROR_OK;
  642. }
  643. static int jim_nds32_bulk_read(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  644. {
  645. const char *cmd_name = Jim_GetString(argv[0], NULL);
  646. struct jim_getopt_info goi;
  647. jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
  648. if (goi.argc < 2) {
  649. Jim_SetResultFormatted(goi.interp,
  650. "usage: %s <address> <count>", cmd_name);
  651. return JIM_ERR;
  652. }
  653. int e;
  654. jim_wide address;
  655. e = jim_getopt_wide(&goi, &address);
  656. if (e != JIM_OK)
  657. return e;
  658. jim_wide count;
  659. e = jim_getopt_wide(&goi, &count);
  660. if (e != JIM_OK)
  661. return e;
  662. /* all args must be consumed */
  663. if (goi.argc != 0)
  664. return JIM_ERR;
  665. struct command_context *cmd_ctx = current_command_context(interp);
  666. assert(cmd_ctx);
  667. struct target *target = get_current_target(cmd_ctx);
  668. uint32_t *data = malloc(count * sizeof(uint32_t));
  669. int result;
  670. result = target_read_buffer(target, address, count * 4, (uint8_t *)data);
  671. char data_str[12];
  672. jim_wide i;
  673. Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
  674. for (i = 0; i < count; i++) {
  675. sprintf(data_str, "0x%08" PRIx32 " ", data[i]);
  676. Jim_AppendStrings(interp, Jim_GetResult(interp), data_str, NULL);
  677. }
  678. free(data);
  679. return result;
  680. }
  681. static int jim_nds32_read_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  682. {
  683. const char *cmd_name = Jim_GetString(argv[0], NULL);
  684. struct jim_getopt_info goi;
  685. jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
  686. if (goi.argc < 1) {
  687. Jim_SetResultFormatted(goi.interp,
  688. "usage: %s <edm_sr_name>", cmd_name);
  689. return JIM_ERR;
  690. }
  691. int e;
  692. const char *edm_sr_name;
  693. int edm_sr_name_len;
  694. e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
  695. if (e != JIM_OK)
  696. return e;
  697. /* all args must be consumed */
  698. if (goi.argc != 0)
  699. return JIM_ERR;
  700. uint32_t edm_sr_number;
  701. uint32_t edm_sr_value;
  702. if (strncmp(edm_sr_name, "edm_dtr", edm_sr_name_len) == 0)
  703. edm_sr_number = NDS_EDM_SR_EDM_DTR;
  704. else if (strncmp(edm_sr_name, "edmsw", edm_sr_name_len) == 0)
  705. edm_sr_number = NDS_EDM_SR_EDMSW;
  706. else
  707. return ERROR_FAIL;
  708. struct command_context *cmd_ctx = current_command_context(interp);
  709. assert(cmd_ctx);
  710. struct target *target = get_current_target(cmd_ctx);
  711. struct aice_port_s *aice = target_to_aice(target);
  712. char data_str[11];
  713. aice_read_debug_reg(aice, edm_sr_number, &edm_sr_value);
  714. sprintf(data_str, "0x%08" PRIx32, edm_sr_value);
  715. Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
  716. Jim_AppendStrings(interp, Jim_GetResult(interp), data_str, NULL);
  717. return ERROR_OK;
  718. }
  719. static int jim_nds32_write_edm_sr(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
  720. {
  721. const char *cmd_name = Jim_GetString(argv[0], NULL);
  722. struct jim_getopt_info goi;
  723. jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
  724. if (goi.argc < 2) {
  725. Jim_SetResultFormatted(goi.interp,
  726. "usage: %s <edm_sr_name> <value>", cmd_name);
  727. return JIM_ERR;
  728. }
  729. int e;
  730. const char *edm_sr_name;
  731. int edm_sr_name_len;
  732. e = jim_getopt_string(&goi, &edm_sr_name, &edm_sr_name_len);
  733. if (e != JIM_OK)
  734. return e;
  735. jim_wide value;
  736. e = jim_getopt_wide(&goi, &value);
  737. if (e != JIM_OK)
  738. return e;
  739. /* all args must be consumed */
  740. if (goi.argc != 0)
  741. return JIM_ERR;
  742. uint32_t edm_sr_number;
  743. if (strncmp(edm_sr_name, "edm_dtr", edm_sr_name_len) == 0)
  744. edm_sr_number = NDS_EDM_SR_EDM_DTR;
  745. else
  746. return ERROR_FAIL;
  747. struct command_context *cmd_ctx = current_command_context(interp);
  748. assert(cmd_ctx);
  749. struct target *target = get_current_target(cmd_ctx);
  750. struct aice_port_s *aice = target_to_aice(target);
  751. aice_write_debug_reg(aice, edm_sr_number, value);
  752. return ERROR_OK;
  753. }
  754. static const struct command_registration nds32_query_command_handlers[] = {
  755. {
  756. .name = "target",
  757. .handler = handle_nds32_query_target_command,
  758. .mode = COMMAND_EXEC,
  759. .usage = "",
  760. .help = "reply 'OCD' for gdb to identify server-side is OpenOCD",
  761. },
  762. {
  763. .name = "endian",
  764. .handler = handle_nds32_query_endian_command,
  765. .mode = COMMAND_EXEC,
  766. .usage = "",
  767. .help = "query target endian",
  768. },
  769. {
  770. .name = "cpuid",
  771. .handler = handle_nds32_query_cpuid_command,
  772. .mode = COMMAND_EXEC,
  773. .usage = "",
  774. .help = "query CPU ID",
  775. },
  776. COMMAND_REGISTRATION_DONE
  777. };
  778. static const struct command_registration nds32_exec_command_handlers[] = {
  779. {
  780. .name = "dssim",
  781. .handler = handle_nds32_dssim_command,
  782. .mode = COMMAND_EXEC,
  783. .usage = "['on'|'off']",
  784. .help = "display/change $INT_MASK.DSSIM status",
  785. },
  786. {
  787. .name = "mem_access",
  788. .handler = handle_nds32_memory_access_command,
  789. .mode = COMMAND_EXEC,
  790. .usage = "['bus'|'cpu']",
  791. .help = "display/change memory access channel",
  792. },
  793. {
  794. .name = "mem_mode",
  795. .handler = handle_nds32_memory_mode_command,
  796. .mode = COMMAND_EXEC,
  797. .usage = "['auto'|'mem'|'ilm'|'dlm']",
  798. .help = "display/change memory mode",
  799. },
  800. {
  801. .name = "cache",
  802. .handler = handle_nds32_cache_command,
  803. .mode = COMMAND_EXEC,
  804. .usage = "['invalidate']",
  805. .help = "cache control",
  806. },
  807. {
  808. .name = "icache",
  809. .handler = handle_nds32_icache_command,
  810. .mode = COMMAND_EXEC,
  811. .usage = "['invalidate'|'enable'|'disable'|'dump']",
  812. .help = "icache control",
  813. },
  814. {
  815. .name = "dcache",
  816. .handler = handle_nds32_dcache_command,
  817. .mode = COMMAND_EXEC,
  818. .usage = "['invalidate'|'enable'|'disable'|'dump']",
  819. .help = "dcache control",
  820. },
  821. {
  822. .name = "auto_break",
  823. .handler = handle_nds32_auto_break_command,
  824. .mode = COMMAND_EXEC,
  825. .usage = "['on'|'off']",
  826. .help = "convert software breakpoints to hardware breakpoints if needed",
  827. },
  828. {
  829. .name = "virtual_hosting",
  830. .handler = handle_nds32_virtual_hosting_command,
  831. .mode = COMMAND_ANY,
  832. .usage = "['on'|'off']",
  833. .help = "turn on/off virtual hosting",
  834. },
  835. {
  836. .name = "global_stop",
  837. .handler = handle_nds32_global_stop_command,
  838. .mode = COMMAND_ANY,
  839. .usage = "['on'|'off']",
  840. .help = "turn on/off global stop. After turning on, every load/store "
  841. "instructions will be stopped to check memory access.",
  842. },
  843. {
  844. .name = "soft_reset_halt",
  845. .handler = handle_nds32_soft_reset_halt_command,
  846. .mode = COMMAND_ANY,
  847. .usage = "['on'|'off']",
  848. .help = "as issuing rest-halt, to use soft-reset-halt or not."
  849. "the feature is for backward-compatible.",
  850. },
  851. {
  852. .name = "boot_time",
  853. .handler = handle_nds32_boot_time_command,
  854. .mode = COMMAND_CONFIG,
  855. .usage = "milliseconds",
  856. .help = "set the period to wait after srst.",
  857. },
  858. {
  859. .name = "login_edm_passcode",
  860. .handler = handle_nds32_login_edm_passcode_command,
  861. .mode = COMMAND_CONFIG,
  862. .usage = "passcode",
  863. .help = "set EDM passcode for secure MCU debugging.",
  864. },
  865. {
  866. .name = "login_edm_operation",
  867. .handler = handle_nds32_login_edm_operation_command,
  868. .mode = COMMAND_CONFIG,
  869. .usage = "misc_reg_no value",
  870. .help = "add EDM operations for secure MCU debugging.",
  871. },
  872. {
  873. .name = "reset_halt_as_init",
  874. .handler = handle_nds32_reset_halt_as_init_command,
  875. .mode = COMMAND_CONFIG,
  876. .usage = "['on'|'off']",
  877. .help = "reset halt as openocd init.",
  878. },
  879. {
  880. .name = "keep_target_edm_ctl",
  881. .handler = handle_nds32_keep_target_edm_ctl_command,
  882. .mode = COMMAND_CONFIG,
  883. .usage = "['on'|'off']",
  884. .help = "Backup/Restore target EDM_CTL register.",
  885. },
  886. {
  887. .name = "decode",
  888. .handler = handle_nds32_decode_command,
  889. .mode = COMMAND_EXEC,
  890. .usage = "address icount",
  891. .help = "decode instruction.",
  892. },
  893. {
  894. .name = "word_access_mem",
  895. .handler = handle_nds32_word_access_mem_command,
  896. .mode = COMMAND_ANY,
  897. .usage = "['on'|'off']",
  898. .help = "Always use word-aligned address to access memory.",
  899. },
  900. {
  901. .name = "bulk_write",
  902. .jim_handler = jim_nds32_bulk_write,
  903. .mode = COMMAND_EXEC,
  904. .help = "Write multiple 32-bit words to target memory",
  905. .usage = "address count data",
  906. },
  907. {
  908. .name = "multi_write",
  909. .jim_handler = jim_nds32_multi_write,
  910. .mode = COMMAND_EXEC,
  911. .help = "Write multiple addresses/words to target memory",
  912. .usage = "num_of_pairs [address data]+",
  913. },
  914. {
  915. .name = "bulk_read",
  916. .jim_handler = jim_nds32_bulk_read,
  917. .mode = COMMAND_EXEC,
  918. .help = "Read multiple 32-bit words from target memory",
  919. .usage = "address count",
  920. },
  921. {
  922. .name = "read_edmsr",
  923. .jim_handler = jim_nds32_read_edm_sr,
  924. .mode = COMMAND_EXEC,
  925. .help = "Read EDM system register",
  926. .usage = "['edmsw'|'edm_dtr']",
  927. },
  928. {
  929. .name = "write_edmsr",
  930. .jim_handler = jim_nds32_write_edm_sr,
  931. .mode = COMMAND_EXEC,
  932. .help = "Write EDM system register",
  933. .usage = "['edm_dtr'] value",
  934. },
  935. {
  936. .name = "query",
  937. .mode = COMMAND_EXEC,
  938. .help = "Andes query command group",
  939. .usage = "",
  940. .chain = nds32_query_command_handlers,
  941. },
  942. COMMAND_REGISTRATION_DONE
  943. };
  944. const struct command_registration nds32_command_handlers[] = {
  945. {
  946. .name = "nds",
  947. .mode = COMMAND_ANY,
  948. .help = "Andes command group",
  949. .usage = "",
  950. .chain = nds32_exec_command_handlers,
  951. },
  952. COMMAND_REGISTRATION_DONE
  953. };