cmd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /**
  3. ******************************************************************************
  4. * @file cmd.c
  5. * @author StarFive Technology
  6. * @version V1.0
  7. * @date 07/20/2020
  8. * @brief
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * COPYRIGHT 2020 Shanghai StarFive Technology Co., Ltd.
  20. */
  21. #include "cmd.h"
  22. #include "comdef.h"
  23. #include "uart.h"
  24. #define CMD_MAXNUM 4
  25. #define UART_CMD_BUFFER 0x18010000
  26. //TAG_CMD_T _CmdBuffer; //:0719 del, use memory directly
  27. P_TAG_CMD_T StdHdl = ( P_TAG_CMD_T ) UART_CMD_BUFFER;
  28. int gcurCmd = CMD_MAXNUM;
  29. /*
  30. ?: cmd help
  31. show: display memory in byte/short/long
  32. do: do a procedure, and return to uart control
  33. run: remap, and jump to 0 , and not return to uart control
  34. */
  35. const CMDTBLITEM CmdHandle[CMD_MAXNUM] =
  36. {
  37. { "?" , 0x00000000 , CmdHelpProc, 0x01 },
  38. { "show" , 0x00000000 , ShowProc , 0x01 },
  39. { "load" , 0x00000000 , LoadProc , 0x01 },
  40. { "do" , 0x00000000 , Do32Proc , 0x01 },
  41. };
  42. unsigned char showMode = 0x10;
  43. void* pCurShow = ( void * )0x00 ;
  44. unsigned long Showlength = 0x100;
  45. void ShowByte( unsigned char * pbuf , int length );
  46. void ShowShort( unsigned short * pbuf , int length );
  47. void ShowLong( unsigned long * pbuf , int length );
  48. /* C720 uart cmd line init*/
  49. void StdInit( P_TAG_CMD_T hdl )
  50. {
  51. hdl->ver = 0x100;
  52. hdl->length = 0x400;
  53. hdl->maxlen = 0x3FF;
  54. hdl->startbuf = ( unsigned char * )hdl->buf + 0x80;
  55. hdl->curbuf = hdl->startbuf;
  56. hdl->curitem = 0x000000;
  57. hdl->inputflag = 0x00000000;
  58. }
  59. void CmdInit( void )
  60. {
  61. //:StdHdl = &_CmdBuffer; // 0719 del
  62. //PrintIntHex(( unsigned long ) StdHdl , 0x8 );
  63. StdInit( StdHdl );
  64. }
  65. void RelayProc( void )
  66. {
  67. int item;
  68. unsigned int retflag;
  69. if( CmdString(( char * ) StdHdl->argvList[0] , "" )){
  70. return;
  71. }
  72. for( item = 0x00 ; item < gcurCmd ; item++ ){
  73. if( CmdString(( char * ) StdHdl->argvList[0] , ( char * ) CmdHandle[item].cmdCode )){
  74. CmdHandle[item].cmdScriptProc( CmdHandle[item].context , ( int ) StdHdl->curArgc , ( char ** )StdHdl->argvList );
  75. return;
  76. }
  77. }
  78. //*************************************************
  79. if( StdHdl->curArgc == 0x02 ){
  80. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "rb" )){
  81. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  82. retflag = (( unsigned char * )item)[0x00];
  83. rlSendString( "\r\n Read Byte : 0x" );
  84. PrintIntHex(( unsigned long ) retflag , 0x2 );
  85. rlSendString( "\r\n" );
  86. return;
  87. }
  88. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "rh" )){
  89. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  90. if( item & 0x0001 ){
  91. rlSendString( "\r\n Error address: 0x" );
  92. PrintIntHex(( unsigned long ) item , 0x8 );
  93. rlSendString( "\r\n" );
  94. return;
  95. }
  96. retflag = (( unsigned short * )item)[0x00];
  97. rlSendString( "\r\n Read Half : 0x" );
  98. PrintIntHex(( unsigned long ) retflag , 0x4 );
  99. rlSendString( "\r\n" );
  100. return;
  101. }
  102. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "rl" )){
  103. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  104. if( item & 0x0003 ){
  105. rlSendString( "\r\n Error address: 0x" );
  106. PrintIntHex(( unsigned long ) item , 0x8 );
  107. rlSendString( "\r\n" );
  108. return;
  109. }
  110. retflag = (( unsigned long * )item)[0x00];
  111. rlSendString( "Read Long : 0x" );
  112. PrintIntHex(( unsigned long ) retflag , 0x8 );
  113. rlSendString( "\r\n" );
  114. return;
  115. }
  116. }
  117. if( StdHdl->curArgc == 0x03 ){
  118. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "wb" )){
  119. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  120. retflag = A2Int(( char * ) StdHdl->argvList[0x02] );
  121. (( unsigned char * )item)[0x00] = ( unsigned char )retflag;
  122. rlSendString( "\r\n Write Byte: 0x" );
  123. PrintIntHex(( unsigned long ) retflag , 0x2 );
  124. rlSendString( "\r\n" );
  125. return;
  126. }
  127. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "wh" )){
  128. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  129. retflag = A2Int(( char * ) StdHdl->argvList[0x02] );
  130. if( item & 0x0001 ){
  131. rlSendString( "\r\n Write Half Error address: 0x" );
  132. PrintIntHex(( unsigned long ) item , 0x8 );
  133. rlSendString( "\r\n" );
  134. return;
  135. }
  136. (( unsigned short * )item)[0x00] = ( unsigned short )retflag;
  137. rlSendString( "\r\n Write Half: 0x" );
  138. PrintIntHex(( unsigned long ) retflag , 0x4 );
  139. rlSendString( "\r\n" );
  140. return;
  141. }
  142. if( CmdString(( char * )( StdHdl->argvList[0x00]) , "wl" )){
  143. item = A2Int(( char * ) StdHdl->argvList[0x01] );
  144. retflag = A2Int(( char * ) StdHdl->argvList[0x02] );
  145. if( item & 0x0003 ){
  146. rlSendString( "\r\n Write Long Error address: 0x" );
  147. PrintIntHex(( unsigned long ) item , 0x8 );
  148. rlSendString( "\r\n" );
  149. return;
  150. }
  151. (( unsigned long * )item)[0x00] = ( unsigned long )retflag;
  152. rlSendString( "\r\n Write Long: 0x" );
  153. PrintIntHex(( unsigned long ) retflag , 0x8 );
  154. rlSendString( "\r\n" );
  155. return;
  156. }
  157. }
  158. rlSendString( "\r\nWarning : Error command, Type ? or help to get CMD info\r\n" );
  159. }
  160. int ReadString( unsigned char * buf , int length )
  161. {
  162. int curitem;
  163. int retflag;
  164. curitem = 0x00000000;
  165. length--;
  166. while( 0x01 ){
  167. retflag = serial_getc( );
  168. if( curitem < length ){
  169. if( retflag >= 0x20 ){
  170. buf[curitem] = ( unsigned char )retflag;
  171. _putc(( char ) buf[curitem] );
  172. curitem++;
  173. continue;
  174. }
  175. }
  176. if(( retflag == '\r' ) || ( retflag == '\n' )){
  177. buf[curitem] = 0x00;
  178. _putc( '\r' );
  179. _putc( '\n' );
  180. break;
  181. }
  182. if( retflag == '\b' ){
  183. if( curitem > 0x00 ){
  184. curitem--;
  185. _putc( '\b' );
  186. _putc( ' ' );
  187. _putc( '\b' );
  188. }
  189. continue;
  190. }
  191. continue;
  192. }
  193. return curitem;
  194. }
  195. int CmdString( char * srccmd , char * basecmd )
  196. {
  197. while(( *srccmd == *basecmd ) && ( *srccmd != 0x00 )){
  198. srccmd++;
  199. basecmd++;
  200. }
  201. if( *srccmd == 0x00 ){
  202. return 0x01;
  203. }
  204. return 0x00;
  205. }
  206. int piteCmdLine( char * curRead , char **pargv , int maxArgc )
  207. {
  208. int curItem;
  209. curItem = 0x00000000;
  210. while( curItem < maxArgc ){
  211. while(( *curRead ) == ' ' ){
  212. curRead++;
  213. }
  214. pargv[curItem] = curRead;
  215. if(( *curRead ) == 0x00 ){
  216. break;
  217. }
  218. while((( *curRead ) != ' ' ) && (( *curRead ) != 0x00 )){
  219. curRead++;
  220. }
  221. curItem++;
  222. if(( *curRead ) == ' ' ){
  223. *curRead = 0x00;
  224. curRead++;
  225. continue;
  226. }
  227. if(( *curRead ) == 0x00 ){
  228. break;
  229. }
  230. }
  231. return curItem;
  232. }
  233. int CmdHelpProc( void * Context , int argc , char ** argv )
  234. {
  235. int item;
  236. rlSendString( "\r\n Command list :\r\n " );
  237. for( item = 0x01 ; item < gcurCmd ; item++ ){
  238. rlSendString( CmdHandle[item].cmdCode );
  239. rlSendString( " \r\n" );
  240. }
  241. rlSendString( "rb/rh/rl addr\r\n" );
  242. rlSendString( "wb/wh/wl addr val\r\n" );
  243. return 0x01;
  244. }
  245. int CmdErrorProc( void * Context , int argc , char ** argv )
  246. {
  247. int i;
  248. rlSendString( " msg : error cmd ->\r\n" );
  249. for( i = 0x00 ; i < argc ; i++ ){
  250. rlSendString( "\t" );
  251. rlSendString( argv[i] );
  252. rlSendString( "\r\n" );
  253. }
  254. rlSendString( "\r\n" );
  255. return 0x01;
  256. }
  257. //file:length <= 0x08
  258. int U2Hex( unsigned long value , char * buf , int length )
  259. {
  260. int temp;
  261. int retflag;
  262. buf[0x00] = 0x00;
  263. buf[length] = 0x00;
  264. retflag = 0x00;
  265. while( length > 0x00 ){
  266. temp = value & 0x0F;
  267. value >>= 0x04;
  268. length--;
  269. retflag++;
  270. if( temp < 0x0A ){
  271. buf[length] = ( char )temp + '0';
  272. continue;
  273. }
  274. buf[length] = ( char )temp + ('A' - 0x0A );
  275. }
  276. return retflag;
  277. }
  278. int A2Int( char * buf )
  279. {
  280. int retflag;
  281. int flag;
  282. retflag = 0x00;
  283. do{
  284. if(( buf[0x00] == '0' ) && (( buf[0x01] == 'x' ) || ( buf[0x01] == 'X' ))){
  285. buf += 0x02;
  286. while( 0x01 ){
  287. if(( *buf >= '0' ) && ( *buf <= '9' )){
  288. retflag <<= 0x04;
  289. retflag += *buf - '0';
  290. buf++;
  291. continue;
  292. }
  293. if(( *buf >= 'a' ) && ( *buf <= 'f' )){
  294. retflag <<= 0x04;
  295. retflag += *buf - ( 'a' - 0x0a );
  296. buf++;
  297. continue;
  298. }
  299. if(( *buf >= 'A' ) && ( *buf <= 'F' )){
  300. retflag <<= 0x04;
  301. retflag += *buf - ( 'A' - 0x0A );
  302. buf++;
  303. continue;
  304. }
  305. break;
  306. }
  307. break;
  308. }
  309. flag = 0x01;
  310. if( *buf == '+' ){
  311. buf++;
  312. }else{
  313. if( *buf == '-' ){
  314. flag = -1;
  315. buf++;
  316. }
  317. }
  318. while( 0x01 ){
  319. if(( *buf >= '0' ) && ( *buf <= '9' )){
  320. retflag *= 0x0A;
  321. retflag += *buf - '0';
  322. buf++;
  323. continue;
  324. }
  325. retflag *= flag;
  326. break;
  327. }
  328. }while( 0x00 );
  329. return retflag;
  330. }
  331. /* load addr : use xmodem protocol, to load a binary file to memory */
  332. int LoadProc( void * Context , int argc , char ** argv )
  333. {
  334. unsigned long pStart;
  335. int retflag;
  336. retflag = 0;
  337. if( argc == 0x02 )
  338. {
  339. pStart = A2Int(( char * ) StdHdl->argvList[0x01] );
  340. if( pStart & 0x03 ){
  341. rlSendString( "\r\n Error : load error for 0x" );
  342. PrintIntHex(( unsigned long ) pStart , 0x8 );
  343. rlSendString( "\r\n" );
  344. retflag = 2;
  345. }
  346. else
  347. {
  348. // retflag = xmodem_recv_file((unsigned char *)pStart, 0);
  349. retflag = xmodemReceive((unsigned char *)pStart, 0);
  350. rlSendString( "\r\nLoad file " );
  351. if(retflag == TRUE)
  352. {
  353. rlSendString( " ok\r\n" );
  354. }
  355. else
  356. {
  357. rlSendString( " Error\r\n" );
  358. }
  359. }
  360. }
  361. else
  362. {
  363. rlSendString( "\r\nCMD format: load startaddr\r\n" );
  364. retflag = 2;
  365. }
  366. return retflag;
  367. }
  368. int Do32Proc( void * Context , int argc , char ** argv )
  369. {
  370. unsigned long pStart;
  371. int retflag;
  372. UINT32 return_pc;
  373. retflag = 0;
  374. if( argc == 0x02 ){
  375. pStart = A2Int(( char * ) StdHdl->argvList[0x01] );
  376. //rlSendString( "\r\nDo procedure at : 0x" );
  377. //PrintIntHex(( unsigned int ) pStart , 0x8);
  378. //rlSendString( "\r\n" );
  379. if((pStart &0x3)==0)
  380. {
  381. /* importent@20060615 */
  382. /* save the return PC here */
  383. return_pc =(UINT32 )(&sys_cmd_main_loop);
  384. //MA_OUTW(EXIT_MINIBOOT_PC, return_pc);
  385. start2run32(pStart);
  386. //do_go_exec ((void *)pStart, argc - 1, argv + 1);
  387. retflag = 0;
  388. }
  389. else
  390. {
  391. rlSendString( "\r\nError, it's invalid Address: 0x" );
  392. PrintIntHex(( unsigned long ) pStart , 0x8 );
  393. rlSendString( "\r\n" );
  394. retflag = 1;
  395. }
  396. }
  397. else
  398. {
  399. rlSendString( "\r\nCMD format: do startaddr\r\n" );
  400. retflag = 2;
  401. }
  402. return retflag;
  403. }
  404. int ShowProc( void * Context , int argc , char ** argv )
  405. {
  406. unsigned long pStart;
  407. unsigned long pEnd;
  408. int retflag;
  409. unsigned char mode;
  410. mode = 0x000000;
  411. if( argc <= 0x03 ){
  412. do{
  413. if( argc == 0x01 ){
  414. pStart = ( unsigned long )pCurShow;
  415. pEnd = Showlength;
  416. break;
  417. }
  418. if( argc == 0x02 ){
  419. if( CmdString( argv[1] , "byte" )){
  420. mode = 0x01;
  421. }
  422. if( CmdString( argv[1] , "half" )){
  423. mode = 0x02;
  424. }
  425. if( CmdString( argv[1] , "long" )){
  426. mode = 0x04;
  427. }
  428. if(( mode == 0x00 ) && (( argv[0x01][0x00] < '0' ) || ( argv[0x01][0x00] > '9' ))){
  429. mode = 0x10;
  430. }
  431. pStart = ( unsigned long )pCurShow;
  432. pEnd = Showlength;
  433. if( mode == 0x00 ){
  434. pStart = A2Int( argv[1] );
  435. }
  436. break;
  437. }
  438. if( CmdString( argv[1] , "byte" )){
  439. mode = 0x01;
  440. }
  441. if( CmdString( argv[1] , "half" )){
  442. mode = 0x02;
  443. }
  444. if( CmdString( argv[1] , "long" )){
  445. mode = 0x04;
  446. }
  447. if(( mode == 0x00 ) && (( argv[0x01][0x00] < '0' ) || ( argv[0x01][0x00] > '9' ))){
  448. mode = 0x10;
  449. }
  450. pEnd = Showlength;
  451. if( mode == 0x00 ){
  452. pStart = A2Int( argv[1] );
  453. pEnd = A2Int( argv[2] );
  454. }else{
  455. pStart = A2Int( argv[2] );
  456. }
  457. break;
  458. }while( 0x00 );
  459. if( mode == 0x00 ){
  460. mode = showMode;
  461. }
  462. pEnd += pStart;
  463. pEnd += 0x0f;
  464. pStart &= 0xFFFFFFF0;
  465. pEnd &= 0xFFFFFFF0;
  466. pEnd -= pStart;
  467. if( mode != 0x10 ){
  468. pCurShow = ( void * )( pStart + pEnd );
  469. Showlength = pEnd;
  470. showMode = mode;
  471. }
  472. switch( mode ){
  473. case 0x01:
  474. ShowByte(( void * ) pStart , pEnd );
  475. break;
  476. case 0x02:
  477. ShowShort(( void * ) pStart , pEnd );
  478. break;
  479. case 0x04:
  480. ShowLong(( void * ) pStart , pEnd );
  481. break;
  482. default:
  483. rlSendString( "\r\nCMD format: show [ byte | half | long ] startAddress [ length ]" );
  484. break;
  485. }
  486. return 1;
  487. }
  488. pStart = A2Int( argv[2] );
  489. pEnd = 0x0100;
  490. if( argc >= 0x04 ){
  491. pEnd = A2Int( argv[3] );
  492. }
  493. retflag = 0x00000001;
  494. do{
  495. if( CmdString( argv[1] , "byte" )){
  496. mode = 0x01;
  497. pEnd += pStart;
  498. pEnd += 0x0f;
  499. pStart &= 0xFFFFFFF0;
  500. pEnd &= 0xFFFFFFF0;
  501. pEnd -= pStart;
  502. ShowByte(( void * ) pStart , pEnd );
  503. break;
  504. }
  505. if( CmdString( argv[1] , "half" )){
  506. mode = 0x02;
  507. //pEnd <<= 0x0001;
  508. pEnd += pStart;
  509. pEnd += 0x0f;
  510. pStart &= 0xFFFFFFF0;
  511. pEnd &= 0xFFFFFFF0;
  512. pEnd -= pStart;
  513. ShowShort(( void * ) pStart , pEnd );
  514. break;
  515. }
  516. if( CmdString( argv[1] , "long" )){
  517. mode = 0x04;
  518. //pEnd <<= 0x0002;
  519. pEnd += pStart;
  520. pEnd += 0x0f;
  521. pStart &= 0xFFFFFFF0;
  522. pEnd &= 0xFFFFFFF0;
  523. pEnd -= pStart;
  524. ShowLong(( void * ) pStart , pEnd );
  525. break;
  526. }
  527. rlSendString( "\r\n show [ byte | half | long ] startAddress [ length ]" );
  528. retflag = -2;
  529. }while( FALSE );
  530. if( retflag > 0x000000 ){
  531. pCurShow = ( void * )( pStart + pEnd );
  532. Showlength = pEnd;
  533. showMode = mode;
  534. }
  535. return retflag;
  536. }
  537. void ShowHexChar( unsigned char * pbuf )
  538. {
  539. int item;
  540. rlSendString( " " );
  541. for( item = 0x00 ; item < 0x10 ; item++ ){
  542. if(( pbuf[item] >= 0x20 ) && ( pbuf[item] < 0x80 )) {
  543. _putc( pbuf[item] );
  544. continue;
  545. }
  546. _putc( '.' );
  547. }
  548. }
  549. //******************************************
  550. //start , length = nBytes
  551. void ShowByte( unsigned char * pbuf , int length )
  552. {
  553. unsigned long endPbuf;
  554. unsigned char *pCurBuf;
  555. pCurBuf = pbuf;
  556. for( endPbuf = (( unsigned long ) pbuf ) + length ; ( unsigned long )pbuf < endPbuf ; pbuf++ ){
  557. if(((( unsigned long ) pbuf ) & 0x0000000F ) == 0x00000000 ){
  558. PrintIntHex(( unsigned long ) pbuf , 0x08 );
  559. pCurBuf = pbuf;
  560. }
  561. _putc( ' ' );
  562. PrintIntHex(( unsigned long )( *pbuf ) , 0x00000002 );
  563. if(((( unsigned long ) pbuf ) & 0x0000000F ) == 0x0000000F ){
  564. ShowHexChar( pCurBuf );
  565. rlSendString( "\r\n" );
  566. if( CtrlBreak( )){
  567. break;
  568. }
  569. }
  570. }
  571. }
  572. //******************************************
  573. //start , length = nBytes
  574. void ShowShort( unsigned short * pbuf , int length )
  575. {
  576. unsigned long endPbuf;
  577. unsigned char *pCurBuf;
  578. pCurBuf = ( unsigned char * )pbuf;
  579. for( endPbuf = (( unsigned long ) pbuf ) + length ; ( unsigned long )pbuf < endPbuf ; pbuf++ ){
  580. if(((( unsigned long ) pbuf ) & 0x0000000F ) == 0x00000000 ){
  581. PrintIntHex(( unsigned long ) pbuf , 0x08 );
  582. pCurBuf = ( unsigned char * )pbuf;
  583. }
  584. _putc( ' ' );
  585. PrintIntHex(( unsigned long )( *pbuf ) , 0x00000004 );
  586. if(((( unsigned long ) pbuf ) & 0x0000000E ) == 0x0000000E ){
  587. ShowHexChar( pCurBuf );
  588. rlSendString( "\r\n" );
  589. if( CtrlBreak( )){
  590. break;
  591. }
  592. }
  593. }
  594. }
  595. void ShowLong( unsigned long * pbuf , int length )
  596. {
  597. unsigned long endPbuf;
  598. unsigned char *pCurBuf;
  599. pCurBuf = ( unsigned char * )pbuf;
  600. for( endPbuf = (( unsigned long ) pbuf ) + length ; ( unsigned long )pbuf < endPbuf ; pbuf++ ){
  601. if(((( unsigned long ) pbuf ) & 0x0000000F ) == 0x00000000 ){
  602. PrintIntHex(( unsigned long ) pbuf , 0x08 );
  603. pCurBuf = ( unsigned char * )pbuf;
  604. }
  605. _putc( ' ' );
  606. PrintIntHex(( unsigned long )( *pbuf ) , 0x00000008 );
  607. if(((( unsigned long ) pbuf ) & 0x0000000C ) == 0x0000000C ){
  608. ShowHexChar( pCurBuf );
  609. rlSendString( "\r\n" );
  610. if( CtrlBreak( )){
  611. break;
  612. }
  613. }
  614. }
  615. }
  616. void PrintIntHex( unsigned long hexData , int length )
  617. {
  618. int curItem;
  619. unsigned int temp;
  620. char msgbuf[0x10];
  621. msgbuf[0x0A] = 0x00;
  622. curItem = 0x09;
  623. while( curItem > 0x01 ){
  624. temp = hexData & 0x0F;
  625. hexData >>= 0x04;
  626. if( temp <= 0x09 ){
  627. msgbuf[curItem] = '0' + temp;
  628. curItem--;
  629. continue;
  630. }
  631. msgbuf[curItem] = ( 'A' - 0x0A ) + temp;
  632. curItem--;
  633. }
  634. rlSendString( msgbuf + ( 0x0A - length ));
  635. }
  636. void sys_cmd_proc( void )
  637. {
  638. StdHdl = ( P_TAG_CMD_T ) UART_CMD_BUFFER;
  639. gcurCmd = CMD_MAXNUM;
  640. CmdInit( );
  641. rlSendString( "\r\n" );
  642. rlSendString( "(C)SiFive" );
  643. /* command line main loop */
  644. sys_cmd_main_loop();
  645. }
  646. void sys_cmd_main_loop(void)
  647. {
  648. unsigned int retflag;
  649. rlSendString( "\r\n# " );
  650. while( TRUE){
  651. retflag = ReadString(( unsigned char * ) StdHdl->curbuf , 0x3FF );
  652. retflag = piteCmdLine(( char * ) StdHdl->curbuf , ( char ** )StdHdl->argvList , 0x20 );
  653. StdHdl->curArgc = retflag;
  654. RelayProc( );
  655. rlSendString( "\r\n# " );
  656. }
  657. }