2 * Copyright (C) 1996 Paul Mackerras.
4 #include <linux/config.h>
5 #include <linux/string.h>
6 #include <asm/machdep.h>
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/sysrq.h>
12 #include <linux/bitops.h>
14 #include <asm/machdep.h>
15 #include <asm/errno.h>
16 #include <asm/processor.h>
17 #include <asm/delay.h>
18 #include <asm/btext.h>
20 static volatile unsigned char *sccc
, *sccd
;
21 unsigned int TXRDY
, RXRDY
, DLAB
;
22 static int xmon_expect(const char *str
, unsigned int timeout
);
26 #define TB_SPEED 25000000
28 static inline unsigned int readtb(void)
32 asm volatile("mftb %0" : "=r" (ret
) :);
39 sccd
[3] &= ~DLAB
; /* reset DLAB */
43 #ifdef CONFIG_MAGIC_SYSRQ
44 static void sysrq_handle_xmon(int key
, struct pt_regs
*regs
,
45 struct tty_struct
*tty
)
50 static struct sysrq_key_op sysrq_xmon_op
=
52 .handler
= sysrq_handle_xmon
,
54 .action_msg
= "Entering xmon",
61 #ifdef CONFIG_PPC_PREP
62 volatile unsigned char *base
;
64 #elif defined(CONFIG_GEMINI)
65 /* should already be mapped by the kernel boot */
66 sccc
= (volatile unsigned char *) 0xffeffb0d;
67 sccd
= (volatile unsigned char *) 0xffeffb08;
71 #elif defined(CONFIG_405GP)
72 sccc
= (volatile unsigned char *)0xef600305;
73 sccd
= (volatile unsigned char *)0xef600300;
79 register_sysrq_key('x', &sysrq_xmon_op
);
82 static int scc_initialized
;
84 void xmon_init_scc(void);
87 xmon_write(void *handle
, void *ptr
, int nb
)
93 static unsigned long xmon_write_lock
;
94 int lock_wait
= 1000000;
97 while ((locked
= test_and_set_bit(0, &xmon_write_lock
)) != 0)
102 if (!scc_initialized
)
105 for (i
= 0; i
< nb
; ++i
) {
106 while ((*sccc
& TXRDY
) == 0)
109 if (c
== '\n' && !ct
) {
123 clear_bit(0, &xmon_write_lock
);
132 xmon_read(void *handle
, void *ptr
, int nb
)
137 if (!scc_initialized
)
139 for (i
= 0; i
< nb
; ++i
) {
140 while ((*sccc
& RXRDY
) == 0)
151 if ((*sccc
& RXRDY
) == 0) {
165 xmon_write(NULL
, "ATE1V1\r", 7);
166 if (xmon_expect("OK", 5)) {
167 xmon_write(NULL
, "ATA\r", 4);
168 if (xmon_expect("CONNECT", 40))
171 xmon_write(NULL
, "+++", 3);
172 xmon_expect("OK", 3);
189 xmon_putc(int c
, void *f
)
195 return xmon_write(f
, &ch
, 1) == 1? c
: -1;
201 return xmon_putc(c
, xmon_stdout
);
205 xmon_fputs(char *str
, void *f
)
209 return xmon_write(f
, str
, n
) == n
? 0: -1;
218 switch (xmon_read(xmon_stdin
, &ch
, 1)) {
222 xmon_printf("read(stdin) returned -1\r\n", 0, 0);
228 static char line
[256];
229 static char *lineptr
;
232 int xmon_expect(const char *str
, unsigned int timeout
)
242 c
= xmon_read_poll();
244 if (readtb() - t0
> timeout
)
250 if (c
!= '\r' && lineptr
< &line
[sizeof(line
) - 1])
254 } while (strstr(line
, str
) == NULL
);
267 if (c
== -1 || c
== 4)
269 if (c
== '\r' || c
== '\n') {
277 if (lineptr
> line
) {
285 while (lineptr
> line
) {
293 if (lineptr
>= &line
[sizeof(line
) - 1])
301 lineleft
= lineptr
- line
;
311 xmon_fgets(char *str
, int nb
, void *f
)
316 for (p
= str
; p
< str
+ nb
- 1; ) {