Leaked source code of windows server 2003
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.

1113 lines
30 KiB

  1. /*----------------------------------------------------------------------------
  2. | debuger.c -
  3. |----------------------------------------------------------------------------*/
  4. #include "precomp.h"
  5. void read_in_queue(char *str);
  6. void reset_box(void);
  7. void reset_port(void);
  8. void reset_modem(void);
  9. void dump_driver(void);
  10. void dump_mem(UCHAR *ptr, ULONG len);
  11. void dump_net(void);
  12. void send_str(char *str);
  13. void dump_ext1(void);
  14. void no_port_message(void);
  15. #ifdef S_VS
  16. void eth_test_pkt(void);
  17. void dump_box(int index);
  18. void dump_nic(int index);
  19. int read_trace_queue(PortMan *pm);
  20. int write_remote_cmd(PortMan *pm, char *cmd);
  21. #endif
  22. #define TraceStr(s) GTrace(D_L10, sz_modid, s)
  23. #define TraceErr(s) GTrace(D_Error, sz_modid_err, s)
  24. #define TraceC(c) GMark(c,10)
  25. static char *sz_modid = {"deb"};
  26. static char *sz_modid_err = {"Error,deb"};
  27. // following used to restrict to one pending debug packet to box
  28. static int pending_debug_packet = 0;
  29. /*----------------------------------------------------------------------------
  30. | do_cmd_line - complete line entered, handle command line interpreter.
  31. |----------------------------------------------------------------------------*/
  32. void do_cmd_line(char *line)
  33. {
  34. char *s = line;
  35. int i, j, k;
  36. char cmd[20]; // buffer for command only, not for params
  37. //char str2[20];
  38. ULONG dnums[5];
  39. PSERIAL_DEVICE_EXTENSION ext;
  40. i = strlen(s);
  41. if (i==0)
  42. return;
  43. if (s[i-1] == 0xd)
  44. {
  45. s[i-1] = 0;
  46. if (i == 0)
  47. deb_printf("\x0d\x0a:");
  48. }
  49. while ((*s == ' ') || (*s == 0xa))
  50. ++s;
  51. if (*s == 0)
  52. {
  53. deb_printf("\x0d\x0a:");
  54. return;
  55. }
  56. deb_printf(":%s\x0d\x0a", s); // echo cmd line
  57. i = 0;
  58. while ((*s != ' ') && (*s != 0) && (*s != ',') && (i < 8))
  59. {
  60. cmd[i++] = (char)my_toupper(*s);
  61. ++s;
  62. }
  63. cmd[i] = 0;
  64. while (*s == ' ')
  65. ++s;
  66. dnums[0] = 0;
  67. dnums[1] = 0;
  68. dnums[2] = 0;
  69. i = getnumbers(s, (long *)dnums, 4, 1); // get max of 4 hex dword numbers
  70. Driver.DebugTimeOut = 1000; // about 600 second seconds timeout
  71. switch (cmd[0])
  72. {
  73. case 'B': // b - box selection to debug
  74. #ifdef S_VS
  75. #if 0
  76. if (*s != 0)
  77. {
  78. write_remote_cmd(&Driver.pm[0], s);
  79. }
  80. else
  81. {
  82. read_trace_queue(&Driver.pm[0]);
  83. }
  84. #endif
  85. #endif
  86. break;
  87. case 'D': // d - dump memory
  88. getstr(cmd, s, &j, 16);
  89. if (my_lstricmp(cmd, "ext") == 0)
  90. dump_mem((UCHAR *)Driver.DebugExt,
  91. sizeof(*Driver.DebugExt)); // dump memory
  92. else if (my_lstricmp(cmd, "RxBuf") == 0)
  93. {
  94. k = Driver.DebugExt->RxQ.QPut;
  95. dump_mem((UCHAR *)&Driver.DebugExt->RxQ.QBase[0], 0x200); // dump memory
  96. }
  97. else if (my_lstricmp(cmd, "port") == 0)
  98. {
  99. #ifdef S_VS
  100. dump_mem((UCHAR *)Driver.DebugExt->Port,
  101. sizeof(*Driver.DebugExt->Port)); // dump memory
  102. #else
  103. dump_mem((UCHAR *)Driver.DebugExt->ChP,
  104. sizeof(*Driver.DebugExt->ChP)); // dump memory
  105. #endif
  106. }
  107. else if (my_lstricmp(cmd, "driver") == 0)
  108. {
  109. dump_driver();
  110. }
  111. else if (i == 1) // 1 number
  112. dump_mem((UCHAR *)dnums[0], 0x100); // dump memory
  113. break;
  114. case 'E': // EXIT
  115. if (my_lstricmp(cmd, "EXIT") == 0)
  116. debug_all_off();
  117. break;
  118. case 'I': // iw
  119. if (cmd[1] == 'W')
  120. {
  121. dnums[1] = READ_PORT_USHORT((PUSHORT) dnums[0]);
  122. deb_printf("iw[%x] = %x\n", dnums[0], dnums[1]);
  123. }
  124. else if (cmd[1] == ' ')
  125. {
  126. dnums[1] = READ_PORT_UCHAR((PUCHAR) dnums[0]);
  127. deb_printf("i[%x] = %x\n", dnums[0], dnums[1]);
  128. }
  129. case 'L': // L
  130. Driver.load_testing = dnums[0];
  131. deb_printf("test load = %d\n", Driver.load_testing);
  132. break;
  133. case 'M': // M
  134. if (my_lstricmp(cmd, "M") == 0) // MON {RX | TX | EV}
  135. {
  136. Driver.GTraceFlags = D_Error;
  137. debug_all_off();
  138. break;
  139. }
  140. if (my_lstricmp(cmd, "MONG") == 0) // MONG {0,1,2,3,4...}
  141. {
  142. if (dnums[0] == 0)
  143. Driver.GTraceFlags = D_Error | D_Init;
  144. else Driver.GTraceFlags |= (1 << dnums[0]);
  145. break;
  146. }
  147. if (Driver.DebugExt == NULL)
  148. {
  149. no_port_message();
  150. break;
  151. }
  152. if (my_lstricmp(cmd, "MON") == 0) // MON {RX | TX | EV}
  153. {
  154. getstr(cmd, s, &j, 16);
  155. if (my_lstricmp(cmd, "rx") == 0)
  156. {
  157. Driver.DebugExt->TraceOptions |= 2;
  158. Driver.TraceOptions |= 2;
  159. }
  160. else if (my_lstricmp(cmd, "off") == 0)
  161. {
  162. Driver.DebugExt->TraceOptions = 0;
  163. Driver.TraceOptions = 0;
  164. }
  165. else if (my_lstricmp(cmd, "tx") == 0)
  166. {
  167. Driver.DebugExt->TraceOptions |= 4;
  168. Driver.TraceOptions |= 4;
  169. }
  170. else if (my_lstricmp(cmd, "ev") == 0)
  171. {
  172. Driver.DebugExt->TraceOptions |= 1;
  173. Driver.TraceOptions |= 1;
  174. }
  175. else if (my_lstricmp(cmd, "irq") == 0)
  176. {
  177. Driver.DebugExt->TraceOptions |= 8;
  178. Driver.TraceOptions |= 8;
  179. }
  180. }
  181. break;
  182. #ifdef S_VS
  183. case 'N': // Net
  184. dump_net();
  185. break;
  186. #endif
  187. case 'O':
  188. if (cmd[1] == 'D')
  189. {
  190. WRITE_PORT_ULONG((PULONG) dnums[0], (ULONG) dnums[1]);
  191. deb_printf("od[%x] = %x\n", dnums[0], dnums[1]);
  192. }
  193. else if (cmd[1] == 'W')
  194. {
  195. WRITE_PORT_USHORT((PUSHORT) dnums[0], (USHORT) dnums[1]);
  196. deb_printf("ow[%x] = %x\n", dnums[0], dnums[1]);
  197. }
  198. else if (cmd[1] == ' ')
  199. {
  200. WRITE_PORT_UCHAR((PUCHAR) dnums[0], (UCHAR) dnums[1]);
  201. deb_printf("o[%x] = %x\n", dnums[0], dnums[1]);
  202. }
  203. break;
  204. case 'P': // PORT name
  205. debug_all_off();
  206. getstr(cmd, s, &j, 10);
  207. deb_printf("Port - %s\n", cmd);
  208. ext = find_ext_by_name(cmd, NULL);
  209. Driver.DebugExt = ext;
  210. if (ext != NULL)
  211. deb_printf("Found port.\n");
  212. else deb_printf("Not Found!!!\n");
  213. break;
  214. case 'R': // RESET PORT
  215. if (Driver.DebugExt == NULL)
  216. {
  217. no_port_message();
  218. break;
  219. }
  220. if (my_lstricmp(cmd, "RESET") == 0)
  221. {
  222. getstr(cmd, s, &j, 16);
  223. if (my_lstricmp(cmd, "port") == 0)
  224. reset_port();
  225. if (my_lstricmp(cmd, "modem") == 0)
  226. reset_modem();
  227. #ifdef S_VS
  228. if (my_lstricmp(cmd, "box") == 0)
  229. reset_box();
  230. #endif
  231. }
  232. break;
  233. case 'S': // STAT
  234. #ifdef S_VS
  235. if (my_lstricmp(cmd, "SENDE") == 0)
  236. {
  237. eth_test_pkt();
  238. break;
  239. }
  240. #endif
  241. if (Driver.DebugExt == NULL)
  242. {
  243. no_port_message();
  244. break;
  245. }
  246. if (my_lstricmp(cmd, "STAT") == 0)
  247. {
  248. deb_printf("--stats--\n");
  249. dump_ext1();
  250. }
  251. else if (my_lstricmp(cmd, "SEND") == 0)
  252. {
  253. send_str(s);
  254. }
  255. break;
  256. #ifdef COMMENT_OUT
  257. case 'T': // timer
  258. if (my_lstricmp(cmd, "timer") == 0)
  259. {
  260. LARGE_INTEGER t1,t2;
  261. our_assert(123, 0);
  262. t1 = KeQueryPerformanceCounter(NULL);
  263. deb_printf("Low:%x High:%x\n", Driver.PollIntervalTime.LowPart,
  264. Driver.PollIntervalTime.HighPart);
  265. t2 = KeQueryPerformanceCounter(NULL);
  266. deb_printf("L2:%x L1:%x H2:%x H1:%x\n", t2.LowPart, t1.LowPart,
  267. t2.HighPart, t1.HighPart);
  268. }
  269. break;
  270. #endif
  271. default:
  272. deb_printf("Driver Version:%s\n", VER_PRODUCTVERSION_STR);
  273. deb_printf("? - This help.\n");
  274. deb_printf("PORT COM# - set the port to work on.\n");
  275. deb_printf("D {ext | chp | rxbuf | driver} - Dump structure.\n");
  276. deb_printf("STAT - Dump key info.\n");
  277. deb_printf("SEND string - Send string out port.\n");
  278. #ifdef S_VS
  279. //deb_printf("SENDE - Send a test ethernet pkt.\n");
  280. //deb_printf("RESET {PORT | BOX} - Reset Port or device.\n");
  281. #endif
  282. deb_printf("M - Turn event/data monitor off.\n");
  283. #ifdef S_VS
  284. deb_printf("NET - Dump network statistics.\n");
  285. #endif
  286. deb_printf("MON {EV | TX | RX} - monitor events, rx-data or tx-data\n");
  287. #ifdef S_VS
  288. deb_printf("MONG {0,1,...10} - monitor stack 1=nic 3=hdlc 5=port\n");
  289. deb_printf("RESET modem - Reset VS2000 modem(on selected port).\n");
  290. #endif
  291. break;
  292. }
  293. deb_printf("\x0d\x0a:");
  294. }
  295. #ifdef S_VS
  296. /*----------------------------------------------------------------------------
  297. | eth_test_pkt -
  298. |----------------------------------------------------------------------------*/
  299. void eth_test_pkt(void)
  300. {
  301. BYTE buf[80];
  302. int stat, len;
  303. static BYTE cnt;
  304. Nic *nic;
  305. nic = Driver.board_ext->pm->nic;
  306. if (nic == NULL)
  307. {
  308. Tprintf("Null Nic!");
  309. return;
  310. }
  311. len = 64;
  312. //memset(&buf[0], 0xff, 6);
  313. memcpy(&buf[0], Driver.board_ext->hd->dest_addr, 6);
  314. memcpy(&buf[6], nic->address, 6); // our addr
  315. // BYTE 12-13: Comtrol PCI ID (11H, FEH), Ethernet Len field
  316. *((WORD *)&buf[12]) = 0xfe11;
  317. buf[14] = ASYNC_PRODUCT_HEADER_ID; // comtrol packet type = driver management, any product.
  318. buf[15] = 0; // conc. index field
  319. buf[16] = 1; // admin
  320. *((WORD *)&buf[17]) = len;
  321. buf[19] = 0x70; // ADMIN packet type, 1=boot-loader, 3=id-reply
  322. buf[20] = cnt++;
  323. stat = nic_send_pkt(nic, buf, len);
  324. if (stat)
  325. {
  326. deb_printf("Error sending.\x0d\x0a:");
  327. }
  328. else deb_printf("Sent.\x0d\x0a:");
  329. }
  330. #endif
  331. /*----------------------------------------------------------------------------
  332. | bad_cmd_message -
  333. |----------------------------------------------------------------------------*/
  334. void bad_cmd_message(void)
  335. {
  336. deb_printf("Unknown command!");
  337. }
  338. /*----------------------------------------------------------------------------
  339. | no_port_message -
  340. |----------------------------------------------------------------------------*/
  341. void no_port_message(void)
  342. {
  343. deb_printf("Use PORT com# to setup a port to monitor!");
  344. }
  345. /*----------------------------------------------------------------------------
  346. | read_in_queue -
  347. |----------------------------------------------------------------------------*/
  348. void read_in_queue(char *str)
  349. {
  350. int j,k;
  351. PSERIAL_DEVICE_EXTENSION ext;
  352. ext = Driver.DebugExt;
  353. k = getint(str, &j);
  354. if (j==0) // got a number
  355. {
  356. // dump_mem(UCHAR *ptr, ULONG len);
  357. deb_printf("read %d!\n", k);
  358. }
  359. }
  360. /*----------------------------------------------------------------------------
  361. | debug_poll - used to timeout inactive debug session and turn off any
  362. | tracing which might be active. Called roughly every 6 seconds.
  363. |----------------------------------------------------------------------------*/
  364. void debug_poll(void)
  365. {
  366. if (Driver.DebugTimeOut == 0) // used to timeout inactive debug sessions.
  367. return;
  368. --Driver.DebugTimeOut;
  369. if (Driver.DebugTimeOut == 0) // used to timeout inactive debug sessions.
  370. {
  371. debug_all_off();
  372. }
  373. }
  374. /*----------------------------------------------------------------------------
  375. | debug_all_off -
  376. |----------------------------------------------------------------------------*/
  377. void debug_all_off(void)
  378. {
  379. #ifdef S_VS
  380. int Dev;
  381. #endif
  382. PSERIAL_DEVICE_EXTENSION ext;
  383. PSERIAL_DEVICE_EXTENSION board_ext;
  384. // Driver.DebugExt = NULL;
  385. Driver.TraceOptions = 0;
  386. board_ext = Driver.board_ext;
  387. while (board_ext)
  388. {
  389. ext = board_ext->port_ext;
  390. while (ext)
  391. {
  392. ext->TraceOptions = 0;
  393. ext = ext->port_ext; // next in chain
  394. } // while port extension
  395. board_ext = board_ext->board_ext;
  396. } // while board extension
  397. }
  398. #ifdef S_VS
  399. /*----------------------------------------------------------------------------
  400. | reset_box -
  401. |----------------------------------------------------------------------------*/
  402. void reset_box(void)
  403. {
  404. PSERIAL_DEVICE_EXTENSION ext;
  405. ext = Driver.board_ext;
  406. while (ext)
  407. {
  408. ext->pm->state = ST_INIT;
  409. ext = ext->board_ext;
  410. }
  411. }
  412. #endif
  413. /*----------------------------------------------------------------------------
  414. | reset_modem - Reset Port Modem Hardware
  415. |----------------------------------------------------------------------------*/
  416. void reset_modem(void)
  417. {
  418. PSERIAL_DEVICE_EXTENSION ext = Driver.DebugExt;
  419. if (ext == NULL)
  420. return;
  421. #ifdef S_VS
  422. pModemReset(ext->Port);
  423. #endif
  424. }
  425. /*----------------------------------------------------------------------------
  426. | reset_port - Reset Port Hardware(assume modem on with RTS/CTS flow ctrl)
  427. |----------------------------------------------------------------------------*/
  428. void reset_port(void)
  429. {
  430. PSERIAL_DEVICE_EXTENSION ext = Driver.DebugExt;
  431. if (ext == NULL)
  432. return;
  433. #ifndef S_VS
  434. sFlushTxFIFO(ext->ChP);
  435. sFlushRxFIFO(ext->ChP);
  436. // Disable all Tx and Rx functions
  437. sDisTransmit(ext->ChP);
  438. sDisRxFIFO(ext->ChP);
  439. sDisRTSFlowCtl(ext->ChP);
  440. sDisCTSFlowCtl(ext->ChP);
  441. sDisRTSToggle(ext->ChP);
  442. sClrBreak(ext->ChP);
  443. // Drop the modem outputs
  444. // Takes care of DTR flow control as well
  445. sClrRTS(ext->ChP);
  446. sClrDTR(ext->ChP);
  447. //---- wait, give time for user to see this reset
  448. time_stall(10); // wait 1 second
  449. ProgramBaudRate(ext, ext->BaudRate);
  450. // Enable Rx, Tx and interrupts for the channel
  451. sEnRxFIFO(ext->ChP); // Enable Rx
  452. sEnTransmit(ext->ChP); // Enable Tx
  453. sSetRxTrigger(ext->ChP,TRIG_1); // always trigger
  454. sEnInterrupts(ext->ChP, ext->IntEnables); // allow interrupts
  455. sEnRTSFlowCtl(ext->ChP);
  456. sEnCTSFlowCtl(ext->ChP);
  457. sSetDTR(ext->ChP);
  458. #endif
  459. }
  460. /*----------------------------------------------------------------------------
  461. | send_str - Dump extension data
  462. |----------------------------------------------------------------------------*/
  463. void send_str(char *str)
  464. {
  465. PSERIAL_DEVICE_EXTENSION ext = Driver.DebugExt;
  466. ULONG i;
  467. if (ext == NULL)
  468. return;
  469. strcat(str, "\x0d\x0a"); // modems like CR,LF
  470. #ifdef S_VS
  471. i = q_put(&ext->Port->QOut, str, strlen(str));
  472. #else
  473. i = sWriteTxBlk(ext->ChP, str, strlen(str));
  474. #endif
  475. deb_printf("%d bytes sent\n", i);
  476. }
  477. /*----------------------------------------------------------------------------
  478. | dump_driver - Dump driver status
  479. |----------------------------------------------------------------------------*/
  480. void dump_driver(void)
  481. {
  482. deb_printf("DRIVER, PollCnt:%d, PollStop:%d\n",
  483. Driver.PollCnt, Driver.Stop_Poll);
  484. deb_printf(" MemAlloced:%d\n", Driver.mem_alloced);
  485. #ifdef S_VS
  486. deb_printf(" Tick100usBase:%d\n", Driver.Tick100usBase);
  487. #endif
  488. }
  489. #ifdef S_VS
  490. /*----------------------------------------------------------------------------
  491. | dump_box - Dump box status
  492. |----------------------------------------------------------------------------*/
  493. void dump_box(int index)
  494. {
  495. PortMan *pm;
  496. Hdlc *hd;
  497. int i;
  498. PSERIAL_DEVICE_EXTENSION ext;
  499. i = 0;
  500. ext = Driver.board_ext;
  501. while (ext != NULL)
  502. {
  503. if ((index == i) || (index == 10000))
  504. {
  505. pm = ext->pm;
  506. hd = ext->hd;
  507. deb_printf("BOX, Index:%d, Nic:%d Ports:%d\n",
  508. i, pm->nic_index, pm->num_ports);
  509. if(pm->backup_server)
  510. deb_printf(" Backup Server: Timeout:%d min Current Time:%d min/%d tic\n",
  511. pm->backup_timer, (pm->load_timer/6000), pm->load_timer);
  512. else
  513. deb_printf(" Designated as Primary Server\n");
  514. deb_printf(" State:%s Reload Errors:%d Timer:%d\n",
  515. port_state_str[pm->state],
  516. pm->reload_errors, pm->state_timer);
  517. deb_printf(" MAC:%x %x %x %x %x %x\n",
  518. hd->dest_addr[0], hd->dest_addr[1], hd->dest_addr[2],
  519. hd->dest_addr[3], hd->dest_addr[4], hd->dest_addr[5]);
  520. deb_printf("Hdlc Status:\n");
  521. //----- circular que of outgoing data packets
  522. #if DBG
  523. deb_printf(" qout.QBase:%x", hd->qout.QBase); // our packet buffer circular queue
  524. deb_printf(" Pkt Cnt:%d Put:%d Get:%d\n",
  525. q_count(&hd->qout), hd->qout.QPut, hd->qout.QGet);
  526. #endif
  527. deb_printf(" Pkt Sends:%d ReSends:%d", hd->iframes_sent, hd->iframes_resent);
  528. deb_printf(" Timeouts, RAck:%d SAck:%d", hd->rec_ack_timeouts,
  529. hd->send_ack_timeouts);
  530. deb_printf(" status:%x\n", hd->status);
  531. #if DBG
  532. deb_printf(" HDLC: V(s):%x V(r):%x NextIn:%x\n",
  533. hd->out_snd_index, hd->in_ack_index, hd->next_in_index);
  534. deb_printf(" UnAcked:%x TxAckTimer:%x RxAckTimer:%x\n",
  535. hd->unacked_pkts, hd->sender_ack_timer, hd->rec_ack_timer);
  536. #endif
  537. deb_printf(" Window pkt size:%d\n", hd->pkt_window_size);
  538. deb_printf(" Errors OurOfSeq:%d\n",
  539. hd->iframes_outofseq);
  540. deb_printf("\n");
  541. }
  542. ext = ext->board_ext; // next one
  543. ++i;
  544. }
  545. }
  546. /*----------------------------------------------------------------------------
  547. | dump_nic - Dump nic status
  548. |----------------------------------------------------------------------------*/
  549. void dump_nic(int index)
  550. {
  551. Nic *nic;
  552. int i;
  553. for (i=0; i<VS1000_MAX_NICS; i++)
  554. {
  555. if ((index == i) || (index == 10000))
  556. {
  557. if (Driver.nics[i].Open)
  558. {
  559. nic = &Driver.nics[i];
  560. deb_printf("NIC, Name[%d]=%s\n",i, nic->NicName);
  561. deb_printf(" MAC:%x %x %x %x %x %x\n",
  562. nic->address[0],nic->address[1],nic->address[2],
  563. nic->address[3],nic->address[4],nic->address[5]);
  564. deb_printf(" Packets Rcvd: Ours:%d NotOurs:%d Pend:%d NonPend:%d",
  565. nic->pkt_rcvd_ours,
  566. nic->pkt_rcvd_not_ours,
  567. nic->RxPendingMoves,
  568. nic->RxNonPendingMoves);
  569. deb_printf(" OvrFlows:%d Rcvd Bytes:%d\n",
  570. nic->pkt_overflows, nic->rec_bytes);
  571. deb_printf(" Packets Sent: Pkts:%d Bytes:%d\n", nic->pkt_sent,
  572. nic->send_bytes);
  573. } // open
  574. deb_printf("\n");
  575. }
  576. }
  577. }
  578. /*----------------------------------------------------------------------------
  579. | dump_net - Dump network status
  580. |----------------------------------------------------------------------------*/
  581. void dump_net(void)
  582. {
  583. PSERIAL_DEVICE_EXTENSION ext = Driver.board_ext;
  584. int num_devs = 0;
  585. while (ext != NULL)
  586. {
  587. #if DBG
  588. //write_device_options(ext);
  589. #endif
  590. ext = ext->board_ext;
  591. ++num_devs;
  592. }
  593. deb_printf("ScanRate:%d, Base:%d\n", Driver.ScanRate, Driver.Tick100usBase);
  594. deb_printf("----Num Devices:%d\n", num_devs);
  595. deb_printf(" threadHandle: %x, threadCount:%d\n",
  596. Driver.threadHandle, Driver.threadCount);
  597. dump_nic(10000); // dump all nic card data;
  598. dump_box(10000); // dump all box data;
  599. }
  600. #endif
  601. /*----------------------------------------------------------------------------
  602. | dump_ext1 - Dump extension data
  603. |----------------------------------------------------------------------------*/
  604. void dump_ext1(void)
  605. {
  606. // int i;
  607. PSERIAL_DEVICE_EXTENSION ext = Driver.DebugExt;
  608. if (ext == NULL)
  609. return;
  610. deb_printf("%s, BaudRate:%d Open:%d\n", ext->SymbolicLinkName,
  611. ext->BaudRate, ext->DeviceIsOpen);
  612. if (ext->port_config->LockBaud != 0)
  613. deb_printf(" LockBaud:%d\n", ext->port_config->LockBaud);
  614. deb_printf("ModemStatus:%xH DTRRTS:%xH\n", ext->ModemStatus, ext->DTRRTSStatus);
  615. #ifdef NEW_Q
  616. {
  617. #ifdef S_VS
  618. LONG tx_remote;
  619. #endif
  620. LONG rx_buf = 0;
  621. if (ext->DeviceIsOpen)
  622. rx_buf = q_count(&ext->RxQ);
  623. #ifdef S_VS
  624. tx_remote = PortGetTxCntRemote(ext->Port);
  625. deb_printf("IRP TxCnt:%d TxBufCnt:%d TxRemoteCnt:%d BufRxCnt:%d\n",
  626. ext->TotalCharsQueued,
  627. PortGetTxCnt(ext->Port),
  628. tx_remote, rx_buf);
  629. deb_printf(" (nPutRemote:%d, nGetRemote:%d, nGetLocal:%d)\n",
  630. ext->Port->nPutRemote,
  631. ext->Port->nGetRemote,
  632. ext->Port->nGetLocal);
  633. #else
  634. deb_printf("TxIRP_Cnt:%d TxBoardCnt:%d RxBufCnt:%d RxBoardCnt:%d\n",
  635. ext->TotalCharsQueued,
  636. sGetTxCnt(ext->ChP),
  637. rx_buf,
  638. sGetRxCnt(ext->ChP));
  639. #endif
  640. }
  641. #else
  642. // old-q-tracking code.....
  643. deb_printf("RxPut:%d RxGet:%d RxSize:%d RxBufAddr:%xH\n",
  644. ext->RxQ.QPut, ext->RxQ.QGet, ext->RxQ.QSize, ext->RxQ.QBase);
  645. #ifndef S_VS
  646. deb_printf("BoardTxCnt:%d BoardRxCnt:%d\n",
  647. sGetTxCnt(ext->ChP), sGetRxCnt(ext->ChP));
  648. #endif
  649. #endif
  650. deb_printf("Stats - RxTot:%u TxTot:%u\n",
  651. ext->OurStats.ReceivedCount,
  652. ext->OurStats.TransmittedCount);
  653. deb_printf("Errors - Parity:%d Frame:%d Buf Overflow:%d Hardware Overflow:%d\n",
  654. ext->OurStats.ParityErrorCount,
  655. ext->OurStats.FrameErrorCount,
  656. ext->OurStats.BufferOverrunErrorCount,
  657. ext->OurStats.SerialOverrunErrorCount);
  658. deb_printf("Stats - Writes:%u Reads:%u\n", ext->sent_packets, ext->rec_packets);
  659. deb_printf("IRPs -");
  660. //------
  661. if ( (!IsListEmpty(&ext->WriteQueue)) // no queued up output data
  662. || (ext->CurrentWriteIrp) )
  663. deb_printf("WrIRP:");
  664. if (!IsListEmpty(&ext->WriteQueue)) // no queued up output data
  665. deb_printf("Q");
  666. if (ext->CurrentWriteIrp)
  667. deb_printf("C");
  668. //------
  669. if ( (!IsListEmpty(&ext->ReadQueue)) // no queued up output data
  670. || (ext->CurrentReadIrp) )
  671. deb_printf(" RdIRP:");
  672. if (!IsListEmpty(&ext->ReadQueue)) // no queued up output data
  673. deb_printf("Q");
  674. if (ext->CurrentReadIrp)
  675. deb_printf("C");
  676. //------
  677. //if ( (!IsListEmpty(&ext->MaskQueue)) // no queued up output data
  678. // || (ext->CurrentMaskIrp) )
  679. // deb_printf(" MaskIRP:");
  680. //if (!IsListEmpty(&ext->MaskQueue)) // no queued up output data
  681. // deb_printf("Q");
  682. //if (ext->CurrentMaskIrp)
  683. // deb_printf("C");
  684. //------
  685. if (ext->CurrentWaitIrp)
  686. deb_printf(" WaitIRP:C");
  687. //------
  688. if ( (!IsListEmpty(&ext->PurgeQueue)) // no queued up output data
  689. || (ext->CurrentPurgeIrp))
  690. deb_printf(" PurgeIRP:");
  691. if (!IsListEmpty(&ext->PurgeQueue)) // no queued up output data
  692. deb_printf("Q");
  693. if (ext->CurrentPurgeIrp)
  694. deb_printf("C");
  695. deb_printf("\n");
  696. //------
  697. if ((ext->WriteLength) ||
  698. (ext->NumberNeededForRead))
  699. {
  700. deb_printf("WrLen:%x, ReadLeft:%x\n",
  701. ext->WriteLength,
  702. ext->NumberNeededForRead);
  703. }
  704. if (ext->IsrWaitMask || ext->HistoryMask || ext->WaitIsISRs)
  705. {
  706. deb_printf("WaitMask:%x HistMask:%x MaskLoc:%x\n",
  707. ext->IsrWaitMask,
  708. ext->HistoryMask,
  709. ext->IrpMaskLocation);
  710. if (ext->IsrWaitMask & 2) // RXFLAG(event-char)
  711. deb_printf("Event Char:%xH\n",
  712. ext->SpecialChars.EventChar);
  713. }
  714. if (ext->TXHolding || ext->RXHolding || ext->ErrorWord)
  715. deb_printf("TXHolding:%x RXHolding:%x ErrorW:%x\n",
  716. ext->TXHolding,
  717. ext->RXHolding,
  718. ext->ErrorWord);
  719. if (ext->TotalCharsQueued)
  720. deb_printf("TotalTX:%x\n",
  721. ext->TotalCharsQueued);
  722. #ifdef S_VS
  723. deb_printf("%s ExtAddr:%xH(size:%xH)\n",
  724. ext->SymbolicLinkName,
  725. ext, sizeof(*ext));
  726. #else
  727. deb_printf("%s ExtAddr:%xH(size:%xH) ChnAddr:%xH(size:%xH)\n",
  728. ext->SymbolicLinkName, ext, sizeof(*ext),
  729. ext->ChP, sizeof(*ext->ChP));
  730. #endif
  731. }
  732. /*----------------------------------------------------------------------------
  733. | dump_mem - Dump memory to debug channel.
  734. |----------------------------------------------------------------------------*/
  735. void dump_mem(UCHAR *ptr, ULONG len)
  736. {
  737. unsigned char binbuf[17];
  738. char tmpstr[60];
  739. int j,i;
  740. ULONG off = 0;
  741. if (ptr == NULL)
  742. {
  743. deb_printf("Null\n");
  744. return;
  745. }
  746. if (MmIsAddressValid(ptr) == FALSE)
  747. {
  748. deb_printf("Not valid\n");
  749. return;
  750. }
  751. if (len > 0x500) len = 0x500;
  752. while (len > 0)
  753. {
  754. j = 16;
  755. if (len < 16)
  756. j = len;
  757. deb_printf("%08x> ", (ULONG)ptr + off);
  758. for (i=0; i<j; i++)
  759. {
  760. binbuf[i] = ptr[i+off];
  761. Sprintf(tmpstr, "%02x ", binbuf[i]);
  762. if ((i % 16) == 7)
  763. strcat(tmpstr,"- ");
  764. deb_printf(tmpstr);
  765. if ((binbuf[i] < 0x20) || (binbuf[i] >= 0x80))
  766. binbuf[i] = '.';
  767. else if (binbuf[i] == '\\')
  768. binbuf[i] = '.';
  769. else if (binbuf[i] == '%')
  770. binbuf[i] = '.';
  771. }
  772. off += 16;
  773. binbuf[i] = 0;
  774. Sprintf(tmpstr, "%s\x0d\x0a", binbuf);
  775. deb_printf(tmpstr);
  776. len -= j;
  777. }
  778. }
  779. /*---------------------------------------------------------------------------
  780. | deb_printf - uart printf.
  781. |---------------------------------------------------------------------------*/
  782. void __cdecl deb_printf(char *format, ...)
  783. {
  784. va_list next;
  785. int len;
  786. static char buf[120];
  787. va_start(next, format);
  788. our_vsnprintf(buf, 118, format, next);
  789. len = strlen(buf);
  790. if (len > 0) //--- convert "\n" to a CR,LF
  791. {
  792. if (buf[len-1] == 0xa)
  793. {
  794. buf[len-1] = 0xd;
  795. buf[len] = 0xa;
  796. buf[len+1] = 0;
  797. ++len;
  798. }
  799. }
  800. //----- log it into our debug Q
  801. q_put(&Driver.DebugQ, (BYTE *) buf, len);
  802. }
  803. #ifdef S_VS
  804. #if 0
  805. /*---------------------------------------------------------------------------
  806. | write_remote_cmd - Write remote trace debug command.
  807. This is experimental code to read box traces, not in working order.
  808. |---------------------------------------------------------------------------*/
  809. int write_remote_cmd(PortMan *pm, char *cmd)
  810. {
  811. int stat;
  812. BYTE *buf;
  813. BYTE cmd_buf[60];
  814. BYTE *tx_base;
  815. TraceStr("writeTrace");
  816. strcpy(cmd_buf, cmd);
  817. cmd_buf[0x3f] = 1; // new-command flag
  818. hdlc_get_ctl_outpkt(pm->hd, &buf);
  819. if (buf == NULL)
  820. return 1;
  821. tx_base = buf - 20; // backup to start of pkt
  822. stat = ioctl_device(UPLOAD_COMMAND,
  823. (BYTE *) cmd_buf,
  824. buf,
  825. 0x400L, // offset into memory
  826. 0x40); // num bytes of data
  827. // setup header
  828. tx_base[14] = ASYNC_PRODUCT_HEADER_ID; // comtrol packet type = driver management, any product.
  829. tx_base[15] = 0; // conc. index field
  830. tx_base[16] = 1; // admin
  831. *((WORD *)&tx_base[17]) = 0x80;
  832. tx_base[19] = 1; // ADMIN packet type, 1=boot-loader, 3=id-reply
  833. if (pending_debug_packet)
  834. time_stall(1); // wait 1/10th second
  835. pending_debug_packet = 1; // flag to tell when response comes in
  836. // send it.
  837. stat = hdlc_send_raw(pm->hd, 60, NULL);
  838. if (stat)
  839. {TraceErr("Bad send");}
  840. return 0;
  841. }
  842. /*---------------------------------------------------------------------------
  843. | read_trace_queue - Read remote trace buffer, so we can display any new
  844. trace data to the screen. This routine just sends out the query.
  845. admin.c will get a reply and stuff the incoming data into the
  846. local trace queue.
  847. This is experimental code to read box traces, not in working order.
  848. |---------------------------------------------------------------------------*/
  849. int read_trace_queue(PortMan *pm)
  850. {
  851. int stat;
  852. BYTE *buf;
  853. WORD io_buf[60];
  854. BYTE *tx_base;
  855. TraceStr("readTrace");
  856. hdlc_get_ctl_outpkt(pm->hd, &buf);
  857. if (buf == NULL)
  858. return 1;
  859. tx_base = buf - 20; // backup to start of pkt
  860. stat = ioctl_device(IOCTL_COMMAND,
  861. (BYTE *) io_buf,
  862. buf,
  863. 22, // 22 = get trace q
  864. 0); // num bytes of data
  865. // setup header
  866. tx_base[14] = ASYNC_PRODUCT_HEADER_ID; // comtrol packet type = driver management, any product.
  867. tx_base[15] = 0; // conc. index field
  868. tx_base[16] = 1; // admin
  869. *((WORD *)&tx_base[17]) = 40;
  870. tx_base[19] = 1; // ADMIN packet type, 1=boot-loader, 3=id-reply
  871. if (pending_debug_packet)
  872. time_stall(1); // wait 1/10th second
  873. pending_debug_packet = 22; // flag to tell when response comes in
  874. // send it.
  875. stat = hdlc_send_raw(pm->hd, 60, NULL);
  876. if (stat)
  877. {TraceErr("Bad send");}
  878. return 0;
  879. }
  880. /*---------------------------------------------------------------------------
  881. | debug_device_reply - Handle received debug-boot loader ADMIN packets
  882. from device.
  883. This is experimental code to read box traces, not in working order.
  884. |---------------------------------------------------------------------------*/
  885. int debug_device_reply(PVOID *void_pm, // PortMan *pm,
  886. unsigned char *data,
  887. unsigned char *pkt);
  888. {
  889. int i;
  890. unsigned char chksum;
  891. // unsigned char *bf;
  892. unsigned char uc;
  893. WORD ret_size;
  894. BYTE *bptr;
  895. BYTE message_type;
  896. PortMan *pm = (PortMan *)void_pm;
  897. bptr = data;
  898. if (bptr[0] != '|') // good reply header
  899. {
  900. deb_printf("dbg:bad hdr\n");
  901. return 1;
  902. }
  903. chksum = bptr[1];
  904. ret_size = bptr[1]; // get len
  905. chksum += bptr[2];
  906. ret_size += ((WORD)(bptr[2]) << 8); // get len
  907. if (ret_size > 1600) // limit
  908. ret_size = 0;
  909. uc = bptr[3]; // get command return word
  910. message_type = uc & 0x7f; // strip off 80H bit.
  911. chksum += uc;
  912. uc = bptr[4];
  913. chksum += uc;
  914. i = 0;
  915. if ((message_type == IOCTL_COMMAND) || (message_type == DOWNLOAD_COMMAND))
  916. {
  917. // o_printf("ret size:%d\n", ret_size-2);
  918. if (data == NULL)
  919. {
  920. pending_debug_packet = 0;
  921. //deb_printf("dbg:no data\n");
  922. return 20; // err out
  923. }
  924. //bf = data;
  925. for (i=0; i<ret_size-2; i++)
  926. {
  927. //bf[i] = bptr[5+i];
  928. chksum += bptr[5+i];
  929. }
  930. i = ret_size-2;
  931. }
  932. chksum += bptr[5+i];
  933. if (chksum != 0xff)
  934. {
  935. deb_printf("dbg:bad chksum\n");
  936. return 2; /* bad chksum */
  937. }
  938. //if ((message_type == IOCTL_COMMAND) || (message_type == DOWNLOAD_COMMAND))
  939. // *num_bytes = ret_size-2;
  940. //else
  941. // *num_bytes = 0;
  942. if (message_type == IOCTL_COMMAND)
  943. {
  944. if (pending_debug_packet == 22) // flag to tell when response comes in
  945. {
  946. if (ret_size > 2)
  947. TracePut(&bptr[5], ret_size -2);
  948. deb_printf("dbg:read q\n");
  949. }
  950. }
  951. else
  952. deb_printf("dbg:set q\n");
  953. pending_debug_packet = 0;
  954. return 0; // ok
  955. }
  956. #endif
  957. #endif