dbg_io.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifdef CONFIG_KGDB
  2. /* --- CONFIG --- */
  3. /* we need uint32 uint8 */
  4. /* #include "types.h" */
  5. typedef unsigned char uint8;
  6. typedef unsigned int uint32;
  7. /* --- END OF CONFIG --- */
  8. #define UART16550_BAUD_2400 2400
  9. #define UART16550_BAUD_4800 4800
  10. #define UART16550_BAUD_9600 9600
  11. #define UART16550_BAUD_19200 19200
  12. #define UART16550_BAUD_38400 38400
  13. #define UART16550_BAUD_57600 57600
  14. #define UART16550_BAUD_115200 115200
  15. #define UART16550_PARITY_NONE 0
  16. #define UART16550_PARITY_ODD 0x08
  17. #define UART16550_PARITY_EVEN 0x18
  18. #define UART16550_PARITY_MARK 0x28
  19. #define UART16550_PARITY_SPACE 0x38
  20. #define UART16550_DATA_5BIT 0x0
  21. #define UART16550_DATA_6BIT 0x1
  22. #define UART16550_DATA_7BIT 0x2
  23. #define UART16550_DATA_8BIT 0x3
  24. #define UART16550_STOP_1BIT 0x0
  25. #define UART16550_STOP_2BIT 0x4
  26. /* ----------------------------------------------------- */
  27. /* === CONFIG === */
  28. /* [stevel] we use the IT8712 serial port for kgdb */
  29. #define DEBUG_BASE 0xB40003F8 /* 8712 serial port 1 base address */
  30. #define MAX_BAUD 115200
  31. /* === END OF CONFIG === */
  32. /* register offset */
  33. #define OFS_RCV_BUFFER 0
  34. #define OFS_TRANS_HOLD 0
  35. #define OFS_SEND_BUFFER 0
  36. #define OFS_INTR_ENABLE 1
  37. #define OFS_INTR_ID 2
  38. #define OFS_DATA_FORMAT 3
  39. #define OFS_LINE_CONTROL 3
  40. #define OFS_MODEM_CONTROL 4
  41. #define OFS_RS232_OUTPUT 4
  42. #define OFS_LINE_STATUS 5
  43. #define OFS_MODEM_STATUS 6
  44. #define OFS_RS232_INPUT 6
  45. #define OFS_SCRATCH_PAD 7
  46. #define OFS_DIVISOR_LSB 0
  47. #define OFS_DIVISOR_MSB 1
  48. /* memory-mapped read/write of the port */
  49. #define UART16550_READ(y) (*((volatile uint8*)(DEBUG_BASE + y)))
  50. #define UART16550_WRITE(y,z) ((*((volatile uint8*)(DEBUG_BASE + y))) = z)
  51. void debugInit(uint32 baud, uint8 data, uint8 parity, uint8 stop)
  52. {
  53. /* disable interrupts */
  54. UART16550_WRITE(OFS_INTR_ENABLE, 0);
  55. /* set up baud rate */
  56. {
  57. uint32 divisor;
  58. /* set DIAB bit */
  59. UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
  60. /* set divisor */
  61. divisor = MAX_BAUD / baud;
  62. UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
  63. UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00) >> 8);
  64. /* clear DIAB bit */
  65. UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
  66. }
  67. /* set data format */
  68. UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
  69. }
  70. static int remoteDebugInitialized = 0;
  71. uint8 getDebugChar(void)
  72. {
  73. if (!remoteDebugInitialized) {
  74. remoteDebugInitialized = 1;
  75. debugInit(UART16550_BAUD_115200,
  76. UART16550_DATA_8BIT,
  77. UART16550_PARITY_NONE, UART16550_STOP_1BIT);
  78. }
  79. while ((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
  80. return UART16550_READ(OFS_RCV_BUFFER);
  81. }
  82. int putDebugChar(uint8 byte)
  83. {
  84. if (!remoteDebugInitialized) {
  85. remoteDebugInitialized = 1;
  86. debugInit(UART16550_BAUD_115200,
  87. UART16550_DATA_8BIT,
  88. UART16550_PARITY_NONE, UART16550_STOP_1BIT);
  89. }
  90. while ((UART16550_READ(OFS_LINE_STATUS) & 0x20) == 0);
  91. UART16550_WRITE(OFS_SEND_BUFFER, byte);
  92. return 1;
  93. }
  94. #endif