atlas_gdb.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * This is the interface to the remote debugger stub.
  19. */
  20. #include <asm/io.h>
  21. #include <asm/mips-boards/atlas.h>
  22. #include <asm/mips-boards/saa9730_uart.h>
  23. #define INB(a) inb((unsigned long)a)
  24. #define OUTB(x,a) outb(x,(unsigned long)a)
  25. /*
  26. * This is the interface to the remote debugger stub
  27. * if the Philips part is used for the debug port,
  28. * called from the platform setup code.
  29. */
  30. void *saa9730_base = (void *)ATLAS_SAA9730_REG;
  31. static int saa9730_kgdb_active = 0;
  32. #define SAA9730_BAUDCLOCK(baud) (((ATLAS_SAA9730_BAUDCLOCK/(baud))/16)-1)
  33. int saa9730_kgdb_hook(int speed)
  34. {
  35. int baudclock;
  36. t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
  37. /*
  38. * Clear all interrupts
  39. */
  40. (void) INB(&kgdb_uart->Lsr);
  41. (void) INB(&kgdb_uart->Msr);
  42. (void) INB(&kgdb_uart->Thr_Rbr);
  43. (void) INB(&kgdb_uart->Iir_Fcr);
  44. /*
  45. * Now, initialize the UART
  46. */
  47. /* 8 data bits, one stop bit, no parity */
  48. OUTB(SAA9730_LCR_DATA8, &kgdb_uart->Lcr);
  49. baudclock = SAA9730_BAUDCLOCK(speed);
  50. OUTB((baudclock >> 16) & 0xff, &kgdb_uart->BaudDivMsb);
  51. OUTB( baudclock & 0xff, &kgdb_uart->BaudDivLsb);
  52. /* Set RTS/DTR active */
  53. OUTB(SAA9730_MCR_DTR | SAA9730_MCR_RTS, &kgdb_uart->Mcr);
  54. saa9730_kgdb_active = 1;
  55. return speed;
  56. }
  57. int saa9730_putDebugChar(char c)
  58. {
  59. t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
  60. if (!saa9730_kgdb_active) { /* need to init device first */
  61. return 0;
  62. }
  63. while (!(INB(&kgdb_uart->Lsr) & SAA9730_LSR_THRE))
  64. ;
  65. OUTB(c, &kgdb_uart->Thr_Rbr);
  66. return 1;
  67. }
  68. char saa9730_getDebugChar(void)
  69. {
  70. t_uart_saa9730_regmap *kgdb_uart = (t_uart_saa9730_regmap *)(saa9730_base + SAA9730_UART_REGS_ADDR);
  71. char c;
  72. if (!saa9730_kgdb_active) { /* need to init device first */
  73. return 0;
  74. }
  75. while (!(INB(&kgdb_uart->Lsr) & SAA9730_LSR_DR))
  76. ;
  77. c = INB(&kgdb_uart->Thr_Rbr);
  78. return(c);
  79. }