udbg.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_putc)(unsigned char c);
  22. unsigned char (*udbg_getc)(void);
  23. int (*udbg_getc_poll)(void);
  24. void udbg_puts(const char *s)
  25. {
  26. if (udbg_putc) {
  27. char c;
  28. if (s && *s != '\0') {
  29. while ((c = *s++) != '\0')
  30. udbg_putc(c);
  31. }
  32. }
  33. #if 0
  34. else {
  35. printk("%s", s);
  36. }
  37. #endif
  38. }
  39. int udbg_write(const char *s, int n)
  40. {
  41. int remain = n;
  42. char c;
  43. if (!udbg_putc)
  44. return 0;
  45. if (s && *s != '\0') {
  46. while (((c = *s++) != '\0') && (remain-- > 0)) {
  47. udbg_putc(c);
  48. }
  49. }
  50. return n - remain;
  51. }
  52. int udbg_read(char *buf, int buflen)
  53. {
  54. char c, *p = buf;
  55. int i;
  56. if (!udbg_getc)
  57. return 0;
  58. for (i = 0; i < buflen; ++i) {
  59. do {
  60. c = udbg_getc();
  61. } while (c == 0x11 || c == 0x13);
  62. if (c == 0)
  63. break;
  64. *p++ = c;
  65. }
  66. return i;
  67. }
  68. void udbg_console_write(struct console *con, const char *s, unsigned int n)
  69. {
  70. udbg_write(s, n);
  71. }
  72. #define UDBG_BUFSIZE 256
  73. void udbg_printf(const char *fmt, ...)
  74. {
  75. unsigned char buf[UDBG_BUFSIZE];
  76. va_list args;
  77. va_start(args, fmt);
  78. vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
  79. udbg_puts(buf);
  80. va_end(args);
  81. }
  82. /* Special print used by PPCDBG() macro */
  83. void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
  84. {
  85. unsigned long active_debugs = debug_flags & ppc64_debug_switch;
  86. if (active_debugs) {
  87. va_list ap;
  88. unsigned char buf[UDBG_BUFSIZE];
  89. unsigned long i, len = 0;
  90. for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
  91. if (((1U << i) & active_debugs) &&
  92. trace_names[i]) {
  93. len += strlen(trace_names[i]);
  94. udbg_puts(trace_names[i]);
  95. break;
  96. }
  97. }
  98. snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
  99. len += strlen(buf);
  100. udbg_puts(buf);
  101. while (len < 18) {
  102. udbg_puts(" ");
  103. len++;
  104. }
  105. va_start(ap, fmt);
  106. vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
  107. udbg_puts(buf);
  108. va_end(ap);
  109. }
  110. }
  111. unsigned long udbg_ifdebug(unsigned long flags)
  112. {
  113. return (flags & ppc64_debug_switch);
  114. }