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
);
64 return udbg_getc_poll();
71 xmon_putc(int c
, void *f
)
77 return xmon_write(f
, &ch
, 1) == 1? c
: -1;
83 return xmon_putc(c
, xmon_stdout
);
87 xmon_fputs(char *str
, void *f
)
91 return xmon_write(f
, str
, n
) == n
? 0: -1;
100 switch (xmon_read(xmon_stdin
, &ch
, 1)) {
104 xmon_printf("read(stdin) returned -1\r\n", 0, 0);
110 static char line
[256];
111 static char *lineptr
;
123 if (c
== -1 || c
== 4)
125 if (c
== '\r' || c
== '\n') {
133 if (lineptr
> line
) {
141 while (lineptr
> line
) {
149 if (lineptr
>= &line
[sizeof(line
) - 1])
157 lineleft
= lineptr
- line
;
167 xmon_fgets(char *str
, int nb
, void *f
)
172 for (p
= str
; p
< str
+ nb
- 1; ) {