start_8xx.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright (C) 1996 Paul Mackerras.
  3. * Copyright (C) 2000 Dan Malek.
  4. * Quick hack of Paul's code to make XMON work on 8xx processors. Lots
  5. * of assumptions, like the SMC1 is used, it has been initialized by the
  6. * loader at some point, and we can just stuff and suck bytes.
  7. * We rely upon the 8xx uart driver to support us, as the interface
  8. * changes between boot up and operational phases of the kernel.
  9. */
  10. #include <linux/string.h>
  11. #include <asm/machdep.h>
  12. #include <asm/io.h>
  13. #include <asm/page.h>
  14. #include <linux/kernel.h>
  15. #include <asm/8xx_immap.h>
  16. #include <asm/mpc8xx.h>
  17. #include <asm/commproc.h>
  18. extern void xmon_printf(const char *fmt, ...);
  19. extern int xmon_8xx_write(char *str, int nb);
  20. extern int xmon_8xx_read_poll(void);
  21. extern int xmon_8xx_read_char(void);
  22. void prom_drawhex(uint);
  23. void prom_drawstring(const char *str);
  24. static int use_screen = 1; /* default */
  25. #define TB_SPEED 25000000
  26. static inline unsigned int readtb(void)
  27. {
  28. unsigned int ret;
  29. asm volatile("mftb %0" : "=r" (ret) :);
  30. return ret;
  31. }
  32. void buf_access(void)
  33. {
  34. }
  35. void
  36. xmon_map_scc(void)
  37. {
  38. cpmp = (cpm8xx_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);
  39. use_screen = 0;
  40. prom_drawstring("xmon uses serial port\n");
  41. }
  42. static int scc_initialized = 0;
  43. void xmon_init_scc(void);
  44. int
  45. xmon_write(void *handle, void *ptr, int nb)
  46. {
  47. char *p = ptr;
  48. int i, c, ct;
  49. if (!scc_initialized)
  50. xmon_init_scc();
  51. return(xmon_8xx_write(ptr, nb));
  52. }
  53. int xmon_wants_key;
  54. int
  55. xmon_read(void *handle, void *ptr, int nb)
  56. {
  57. char *p = ptr;
  58. int i;
  59. if (!scc_initialized)
  60. xmon_init_scc();
  61. for (i = 0; i < nb; ++i) {
  62. *p++ = xmon_8xx_read_char();
  63. }
  64. return i;
  65. }
  66. int
  67. xmon_read_poll(void)
  68. {
  69. return(xmon_8xx_read_poll());
  70. }
  71. void
  72. xmon_init_scc()
  73. {
  74. scc_initialized = 1;
  75. }
  76. #if 0
  77. extern int (*prom_entry)(void *);
  78. int
  79. xmon_exit(void)
  80. {
  81. struct prom_args {
  82. char *service;
  83. } args;
  84. for (;;) {
  85. args.service = "exit";
  86. (*prom_entry)(&args);
  87. }
  88. }
  89. #endif
  90. void *xmon_stdin;
  91. void *xmon_stdout;
  92. void *xmon_stderr;
  93. void
  94. xmon_init(void)
  95. {
  96. }
  97. int
  98. xmon_putc(int c, void *f)
  99. {
  100. char ch = c;
  101. if (c == '\n')
  102. xmon_putc('\r', f);
  103. return xmon_write(f, &ch, 1) == 1? c: -1;
  104. }
  105. int
  106. xmon_putchar(int c)
  107. {
  108. return xmon_putc(c, xmon_stdout);
  109. }
  110. int
  111. xmon_fputs(char *str, void *f)
  112. {
  113. int n = strlen(str);
  114. return xmon_write(f, str, n) == n? 0: -1;
  115. }
  116. int
  117. xmon_readchar(void)
  118. {
  119. char ch;
  120. for (;;) {
  121. switch (xmon_read(xmon_stdin, &ch, 1)) {
  122. case 1:
  123. return ch;
  124. case -1:
  125. xmon_printf("read(stdin) returned -1\r\n", 0, 0);
  126. return -1;
  127. }
  128. }
  129. }
  130. static char line[256];
  131. static char *lineptr;
  132. static int lineleft;
  133. #if 0
  134. int xmon_expect(const char *str, unsigned int timeout)
  135. {
  136. int c;
  137. unsigned int t0;
  138. timeout *= TB_SPEED;
  139. t0 = readtb();
  140. do {
  141. lineptr = line;
  142. for (;;) {
  143. c = xmon_read_poll();
  144. if (c == -1) {
  145. if (readtb() - t0 > timeout)
  146. return 0;
  147. continue;
  148. }
  149. if (c == '\n')
  150. break;
  151. if (c != '\r' && lineptr < &line[sizeof(line) - 1])
  152. *lineptr++ = c;
  153. }
  154. *lineptr = 0;
  155. } while (strstr(line, str) == NULL);
  156. return 1;
  157. }
  158. #endif
  159. int
  160. xmon_getchar(void)
  161. {
  162. int c;
  163. if (lineleft == 0) {
  164. lineptr = line;
  165. for (;;) {
  166. c = xmon_readchar();
  167. if (c == -1 || c == 4)
  168. break;
  169. if (c == '\r' || c == '\n') {
  170. *lineptr++ = '\n';
  171. xmon_putchar('\n');
  172. break;
  173. }
  174. switch (c) {
  175. case 0177:
  176. case '\b':
  177. if (lineptr > line) {
  178. xmon_putchar('\b');
  179. xmon_putchar(' ');
  180. xmon_putchar('\b');
  181. --lineptr;
  182. }
  183. break;
  184. case 'U' & 0x1F:
  185. while (lineptr > line) {
  186. xmon_putchar('\b');
  187. xmon_putchar(' ');
  188. xmon_putchar('\b');
  189. --lineptr;
  190. }
  191. break;
  192. default:
  193. if (lineptr >= &line[sizeof(line) - 1])
  194. xmon_putchar('\a');
  195. else {
  196. xmon_putchar(c);
  197. *lineptr++ = c;
  198. }
  199. }
  200. }
  201. lineleft = lineptr - line;
  202. lineptr = line;
  203. }
  204. if (lineleft == 0)
  205. return -1;
  206. --lineleft;
  207. return *lineptr++;
  208. }
  209. char *
  210. xmon_fgets(char *str, int nb, void *f)
  211. {
  212. char *p;
  213. int c;
  214. for (p = str; p < str + nb - 1; ) {
  215. c = xmon_getchar();
  216. if (c == -1) {
  217. if (p == str)
  218. return 0;
  219. break;
  220. }
  221. *p++ = c;
  222. if (c == '\n')
  223. break;
  224. }
  225. *p = 0;
  226. return str;
  227. }
  228. void
  229. prom_drawhex(uint val)
  230. {
  231. unsigned char buf[10];
  232. int i;
  233. for (i = 7; i >= 0; i--)
  234. {
  235. buf[i] = "0123456789abcdef"[val & 0x0f];
  236. val >>= 4;
  237. }
  238. buf[8] = '\0';
  239. xmon_fputs(buf, xmon_stdout);
  240. }
  241. void
  242. prom_drawstring(const char *str)
  243. {
  244. xmon_fputs(str, xmon_stdout);
  245. }