2 * Copyright (C) 1996 Paul Mackerras.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/config.h>
10 #include <linux/string.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/sysrq.h>
14 #include <linux/init.h>
15 #include <asm/machdep.h>
19 #include <asm/processor.h>
21 #include <asm/system.h>
24 #ifdef CONFIG_MAGIC_SYSRQ
26 static void sysrq_handle_xmon(int key
, struct pt_regs
*pt_regs
,
27 struct tty_struct
*tty
)
29 /* ensure xmon is enabled */
34 static struct sysrq_key_op sysrq_xmon_op
=
36 .handler
= sysrq_handle_xmon
,
38 .action_msg
= "Entering xmon",
41 static int __init
setup_xmon_sysrq(void)
43 register_sysrq_key('x', &sysrq_xmon_op
);
46 __initcall(setup_xmon_sysrq
);
47 #endif /* CONFIG_MAGIC_SYSRQ */
50 xmon_write(void *handle
, void *ptr
, int nb
)
52 return udbg_write(ptr
, nb
);
56 xmon_read(void *handle
, void *ptr
, int nb
)
58 return udbg_read(ptr
, nb
);
65 return udbg_getc_poll();
73 xmon_putc(int c
, void *f
)
79 return xmon_write(f
, &ch
, 1) == 1? c
: -1;
85 return xmon_putc(c
, xmon_stdout
);
89 xmon_fputs(char *str
, void *f
)
93 return xmon_write(f
, str
, n
) == n
? 0: -1;
102 switch (xmon_read(xmon_stdin
, &ch
, 1)) {
106 xmon_printf("read(stdin) returned -1\r\n", 0, 0);
112 static char line
[256];
113 static char *lineptr
;
125 if (c
== -1 || c
== 4)
127 if (c
== '\r' || c
== '\n') {
135 if (lineptr
> line
) {
143 while (lineptr
> line
) {
151 if (lineptr
>= &line
[sizeof(line
) - 1])
159 lineleft
= lineptr
- line
;
169 xmon_fgets(char *str
, int nb
, void *f
)
174 for (p
= str
; p
< str
+ nb
- 1; ) {