gdb_hook.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * ########################################################################
  6. *
  7. * This program is free software; you can distribute it and/or modify it
  8. * under the terms of the GNU General Public License (Version 2) as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  19. *
  20. * ########################################################################
  21. *
  22. * This is the interface to the remote debugger stub.
  23. *
  24. */
  25. #include <linux/types.h>
  26. #include <linux/serial.h>
  27. #include <linux/serialP.h>
  28. #include <linux/serial_reg.h>
  29. #include <linux/serial_ip3106.h>
  30. #include <asm/serial.h>
  31. #include <asm/io.h>
  32. #include <uart.h>
  33. static struct serial_state rs_table[IP3106_NR_PORTS] = {
  34. };
  35. static struct async_struct kdb_port_info = {0};
  36. void rs_kgdb_hook(int tty_no)
  37. {
  38. struct serial_state *ser = &rs_table[tty_no];
  39. kdb_port_info.state = ser;
  40. kdb_port_info.magic = SERIAL_MAGIC;
  41. kdb_port_info.port = tty_no;
  42. kdb_port_info.flags = ser->flags;
  43. /*
  44. * Clear all interrupts
  45. */
  46. /* Clear all the transmitter FIFO counters (pointer and status) */
  47. ip3106_lcr(UART_BASE, tty_no) |= IP3106_UART_LCR_TX_RST;
  48. /* Clear all the receiver FIFO counters (pointer and status) */
  49. ip3106_lcr(UART_BASE, tty_no) |= IP3106_UART_LCR_RX_RST;
  50. /* Clear all interrupts */
  51. ip3106_iclr(UART_BASE, tty_no) = IP3106_UART_INT_ALLRX |
  52. IP3106_UART_INT_ALLTX;
  53. /*
  54. * Now, initialize the UART
  55. */
  56. ip3106_lcr(UART_BASE, tty_no) = IP3106_UART_LCR_8BIT;
  57. ip3106_baud(UART_BASE, tty_no) = 5; // 38400 Baud
  58. }
  59. int putDebugChar(char c)
  60. {
  61. /* Wait until FIFO not full */
  62. while (((ip3106_fifo(UART_BASE, kdb_port_info.port) & IP3106_UART_FIFO_TXFIFO) >> 16) >= 16)
  63. ;
  64. /* Send one char */
  65. ip3106_fifo(UART_BASE, kdb_port_info.port) = c;
  66. return 1;
  67. }
  68. char getDebugChar(void)
  69. {
  70. char ch;
  71. /* Wait until there is a char in the FIFO */
  72. while (!((ip3106_fifo(UART_BASE, kdb_port_info.port) &
  73. IP3106_UART_FIFO_RXFIFO) >> 8))
  74. ;
  75. /* Read one char */
  76. ch = ip3106_fifo(UART_BASE, kdb_port_info.port) &
  77. IP3106_UART_FIFO_RBRTHR;
  78. /* Advance the RX FIFO read pointer */
  79. ip3106_lcr(UART_BASE, kdb_port_info.port) |= IP3106_UART_LCR_RX_NEXT;
  80. return (ch);
  81. }
  82. void rs_disable_debug_interrupts(void)
  83. {
  84. ip3106_ien(UART_BASE, kdb_port_info.port) = 0; /* Disable all interrupts */
  85. }
  86. void rs_enable_debug_interrupts(void)
  87. {
  88. /* Clear all the transmitter FIFO counters (pointer and status) */
  89. ip3106_lcr(UART_BASE, kdb_port_info.port) |= IP3106_UART_LCR_TX_RST;
  90. /* Clear all the receiver FIFO counters (pointer and status) */
  91. ip3106_lcr(UART_BASE, kdb_port_info.port) |= IP3106_UART_LCR_RX_RST;
  92. /* Clear all interrupts */
  93. ip3106_iclr(UART_BASE, kdb_port_info.port) = IP3106_UART_INT_ALLRX |
  94. IP3106_UART_INT_ALLTX;
  95. ip3106_ien(UART_BASE, kdb_port_info.port) = IP3106_UART_INT_ALLRX; /* Enable RX interrupts */
  96. }