cmd.c 16 KB

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