ppc4xx_kgdb.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <linux/config.h>
  2. #include <linux/types.h>
  3. #include <asm/ibm4xx.h>
  4. #include <linux/kernel.h>
  5. #define LSR_DR 0x01 /* Data ready */
  6. #define LSR_OE 0x02 /* Overrun */
  7. #define LSR_PE 0x04 /* Parity error */
  8. #define LSR_FE 0x08 /* Framing error */
  9. #define LSR_BI 0x10 /* Break */
  10. #define LSR_THRE 0x20 /* Xmit holding register empty */
  11. #define LSR_TEMT 0x40 /* Xmitter empty */
  12. #define LSR_ERR 0x80 /* Error */
  13. #include <platforms/4xx/ibm_ocp.h>
  14. extern struct NS16550* COM_PORTS[];
  15. #ifndef NULL
  16. #define NULL 0x00
  17. #endif
  18. static volatile struct NS16550 *kgdb_debugport = NULL;
  19. volatile struct NS16550 *
  20. NS16550_init(int chan)
  21. {
  22. volatile struct NS16550 *com_port;
  23. int quot;
  24. #ifdef BASE_BAUD
  25. quot = BASE_BAUD / 9600;
  26. #else
  27. quot = 0x000c; /* 0xc = 9600 baud (on a pc) */
  28. #endif
  29. com_port = (struct NS16550 *) COM_PORTS[chan];
  30. com_port->lcr = 0x00;
  31. com_port->ier = 0xFF;
  32. com_port->ier = 0x00;
  33. com_port->lcr = com_port->lcr | 0x80; /* Access baud rate */
  34. com_port->dll = ( quot & 0x00ff ); /* 0xc = 9600 baud */
  35. com_port->dlm = ( quot & 0xff00 ) >> 8;
  36. com_port->lcr = 0x03; /* 8 data, 1 stop, no parity */
  37. com_port->mcr = 0x00; /* RTS/DTR */
  38. com_port->fcr = 0x07; /* Clear & enable FIFOs */
  39. return( com_port );
  40. }
  41. void
  42. NS16550_putc(volatile struct NS16550 *com_port, unsigned char c)
  43. {
  44. while ((com_port->lsr & LSR_THRE) == 0)
  45. ;
  46. com_port->thr = c;
  47. return;
  48. }
  49. unsigned char
  50. NS16550_getc(volatile struct NS16550 *com_port)
  51. {
  52. while ((com_port->lsr & LSR_DR) == 0)
  53. ;
  54. return (com_port->rbr);
  55. }
  56. unsigned char
  57. NS16550_tstc(volatile struct NS16550 *com_port)
  58. {
  59. return ((com_port->lsr & LSR_DR) != 0);
  60. }
  61. #if defined(CONFIG_KGDB_TTYS0)
  62. #define KGDB_PORT 0
  63. #elif defined(CONFIG_KGDB_TTYS1)
  64. #define KGDB_PORT 1
  65. #elif defined(CONFIG_KGDB_TTYS2)
  66. #define KGDB_PORT 2
  67. #elif defined(CONFIG_KGDB_TTYS3)
  68. #define KGDB_PORT 3
  69. #else
  70. #error "invalid kgdb_tty port"
  71. #endif
  72. void putDebugChar( unsigned char c )
  73. {
  74. if ( kgdb_debugport == NULL )
  75. kgdb_debugport = NS16550_init(KGDB_PORT);
  76. NS16550_putc( kgdb_debugport, c );
  77. }
  78. int getDebugChar( void )
  79. {
  80. if (kgdb_debugport == NULL)
  81. kgdb_debugport = NS16550_init(KGDB_PORT);
  82. return(NS16550_getc(kgdb_debugport));
  83. }
  84. void kgdb_interruptible(int enable)
  85. {
  86. return;
  87. }
  88. void putDebugString(char* str)
  89. {
  90. while (*str != '\0') {
  91. putDebugChar(*str);
  92. str++;
  93. }
  94. putDebugChar('\r');
  95. return;
  96. }
  97. void
  98. kgdb_map_scc(void)
  99. {
  100. printk("kgdb init \n");
  101. kgdb_debugport = NS16550_init(KGDB_PORT);
  102. }