udbg.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * polling mode stateless debugging stuff, originally for NS16550 Serial Ports
  3. *
  4. * c 2001 PPC 64 Team, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <stdarg.h>
  12. #define WANT_PPCDBG_TAB /* Only defined here */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <asm/ppcdebug.h>
  16. #include <asm/processor.h>
  17. #include <asm/uaccess.h>
  18. #include <asm/machdep.h>
  19. #include <asm/io.h>
  20. #include <asm/prom.h>
  21. void udbg_puts(const char *s)
  22. {
  23. if (ppc_md.udbg_putc) {
  24. char c;
  25. if (s && *s != '\0') {
  26. while ((c = *s++) != '\0')
  27. ppc_md.udbg_putc(c);
  28. }
  29. }
  30. #if 0
  31. else {
  32. printk("%s", s);
  33. }
  34. #endif
  35. }
  36. int udbg_write(const char *s, int n)
  37. {
  38. int remain = n;
  39. char c;
  40. if (!ppc_md.udbg_putc)
  41. return 0;
  42. if (s && *s != '\0') {
  43. while (((c = *s++) != '\0') && (remain-- > 0)) {
  44. ppc_md.udbg_putc(c);
  45. }
  46. }
  47. return n - remain;
  48. }
  49. int udbg_read(char *buf, int buflen)
  50. {
  51. char c, *p = buf;
  52. int i;
  53. if (!ppc_md.udbg_getc)
  54. return 0;
  55. for (i = 0; i < buflen; ++i) {
  56. do {
  57. c = ppc_md.udbg_getc();
  58. } while (c == 0x11 || c == 0x13);
  59. if (c == 0)
  60. break;
  61. *p++ = c;
  62. }
  63. return i;
  64. }
  65. void udbg_console_write(struct console *con, const char *s, unsigned int n)
  66. {
  67. udbg_write(s, n);
  68. }
  69. #define UDBG_BUFSIZE 256
  70. void udbg_printf(const char *fmt, ...)
  71. {
  72. unsigned char buf[UDBG_BUFSIZE];
  73. va_list args;
  74. va_start(args, fmt);
  75. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  76. udbg_puts(buf);
  77. va_end(args);
  78. }
  79. /* Special print used by PPCDBG() macro */
  80. void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
  81. {
  82. unsigned long active_debugs = debug_flags & ppc64_debug_switch;
  83. if (active_debugs) {
  84. va_list ap;
  85. unsigned char buf[UDBG_BUFSIZE];
  86. unsigned long i, len = 0;
  87. for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
  88. if (((1U << i) & active_debugs) &&
  89. trace_names[i]) {
  90. len += strlen(trace_names[i]);
  91. udbg_puts(trace_names[i]);
  92. break;
  93. }
  94. }
  95. snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
  96. len += strlen(buf);
  97. udbg_puts(buf);
  98. while (len < 18) {
  99. udbg_puts(" ");
  100. len++;
  101. }
  102. va_start(ap, fmt);
  103. vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
  104. udbg_puts(buf);
  105. va_end(ap);
  106. }
  107. }
  108. unsigned long udbg_ifdebug(unsigned long flags)
  109. {
  110. return (flags & ppc64_debug_switch);
  111. }