puts.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Debug routines which directly access the uart.
  3. */
  4. #include <linux/types.h>
  5. #include <asm/gt64120.h>
  6. //#define SERIAL_BASE EV96100_UART0_REGS_BASE
  7. #define SERIAL_BASE 0xBD000020
  8. #define NS16550_BASE SERIAL_BASE
  9. #define SERA_CMD 0x0D
  10. #define SERA_DATA 0x08
  11. //#define SERB_CMD 0x05
  12. #define SERB_CMD 20
  13. #define SERB_DATA 0x00
  14. #define TX_BUSY 0x20
  15. #define TIMEOUT 0xffff
  16. #undef SLOW_DOWN
  17. static const char digits[16] = "0123456789abcdef";
  18. static volatile unsigned char *const com1 = (unsigned char *) SERIAL_BASE;
  19. #ifdef SLOW_DOWN
  20. static inline void slow_down()
  21. {
  22. int k;
  23. for (k = 0; k < 10000; k++);
  24. }
  25. #else
  26. #define slow_down()
  27. #endif
  28. void putch(const unsigned char c)
  29. {
  30. unsigned char ch;
  31. int i = 0;
  32. do {
  33. ch = com1[SERB_CMD];
  34. slow_down();
  35. i++;
  36. if (i > TIMEOUT) {
  37. break;
  38. }
  39. } while (0 == (ch & TX_BUSY));
  40. com1[SERB_DATA] = c;
  41. }
  42. void putchar(const unsigned char c)
  43. {
  44. unsigned char ch;
  45. int i = 0;
  46. do {
  47. ch = com1[SERB_CMD];
  48. slow_down();
  49. i++;
  50. if (i > TIMEOUT) {
  51. break;
  52. }
  53. } while (0 == (ch & TX_BUSY));
  54. com1[SERB_DATA] = c;
  55. }
  56. void puts(unsigned char *cp)
  57. {
  58. unsigned char ch;
  59. int i = 0;
  60. while (*cp) {
  61. do {
  62. ch = com1[SERB_CMD];
  63. slow_down();
  64. i++;
  65. if (i > TIMEOUT) {
  66. break;
  67. }
  68. } while (0 == (ch & TX_BUSY));
  69. com1[SERB_DATA] = *cp++;
  70. }
  71. putch('\r');
  72. putch('\n');
  73. }
  74. void fputs(unsigned char *cp)
  75. {
  76. unsigned char ch;
  77. int i = 0;
  78. while (*cp) {
  79. do {
  80. ch = com1[SERB_CMD];
  81. slow_down();
  82. i++;
  83. if (i > TIMEOUT) {
  84. break;
  85. }
  86. } while (0 == (ch & TX_BUSY));
  87. com1[SERB_DATA] = *cp++;
  88. }
  89. }
  90. void put64(uint64_t ul)
  91. {
  92. int cnt;
  93. unsigned ch;
  94. cnt = 16; /* 16 nibbles in a 64 bit long */
  95. putch('0');
  96. putch('x');
  97. do {
  98. cnt--;
  99. ch = (unsigned char) (ul >> cnt * 4) & 0x0F;
  100. putch(digits[ch]);
  101. } while (cnt > 0);
  102. }
  103. void put32(unsigned u)
  104. {
  105. int cnt;
  106. unsigned ch;
  107. cnt = 8; /* 8 nibbles in a 32 bit long */
  108. putch('0');
  109. putch('x');
  110. do {
  111. cnt--;
  112. ch = (unsigned char) (u >> cnt * 4) & 0x0F;
  113. putch(digits[ch]);
  114. } while (cnt > 0);
  115. }