debuggers.hg

view xen/common/keyhandler.c @ 3705:4294cfa9fad3

bitkeeper revision 1.1159.212.95 (4204aa0ee0re5Xx1zWrJ9ejxzgRs3w)

Various cleanups. Remove PDB pending simpler GDB stub and/or NetBSD debugger.
Force emacs mode to appropriate tabbing in various files.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Sat Feb 05 11:12:14 2005 +0000 (2005-02-05)
parents 610068179f96
children 88957a238191 a00d7a994a59
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil -*- */
2 /******************************************************************************
3 * keyhandler.c
4 */
6 #include <xen/keyhandler.h>
7 #include <xen/reboot.h>
8 #include <xen/event.h>
9 #include <xen/console.h>
10 #include <xen/serial.h>
11 #include <xen/sched.h>
12 #include <xen/softirq.h>
14 #define KEY_MAX 256
15 #define STR_MAX 64
17 static struct {
18 union {
19 keyhandler_t *handler;
20 irq_keyhandler_t *irq_handler;
21 } u;
22 unsigned int flags;
23 char desc[STR_MAX];
24 } key_table[KEY_MAX];
26 #define KEYHANDLER_IRQ_CALLBACK 0x1
28 static unsigned char keypress_key;
30 void keypress_softirq(void)
31 {
32 keyhandler_t *h;
33 unsigned char key = keypress_key;
34 if ( (h = key_table[key].u.handler) != NULL )
35 (*h)(key);
36 }
38 void handle_keypress(unsigned char key, struct xen_regs *regs)
39 {
40 irq_keyhandler_t *h;
42 if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
43 {
44 if ( (h = key_table[key].u.irq_handler) != NULL )
45 (*h)(key, regs);
46 }
47 else
48 {
49 keypress_key = key;
50 raise_softirq(KEYPRESS_SOFTIRQ);
51 }
52 }
54 void register_keyhandler(
55 unsigned char key, keyhandler_t *handler, char *desc)
56 {
57 ASSERT(key_table[key].u.handler == NULL);
58 key_table[key].u.handler = handler;
59 key_table[key].flags = 0;
60 strncpy(key_table[key].desc, desc, STR_MAX);
61 key_table[key].desc[STR_MAX-1] = '\0';
62 }
64 void register_irq_keyhandler(
65 unsigned char key, irq_keyhandler_t *handler, char *desc)
66 {
67 ASSERT(key_table[key].u.irq_handler == NULL);
68 key_table[key].u.irq_handler = handler;
69 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK;
70 strncpy(key_table[key].desc, desc, STR_MAX);
71 key_table[key].desc[STR_MAX-1] = '\0';
72 }
74 static void show_handlers(unsigned char key)
75 {
76 int i;
77 printk("'%c' pressed -> showing installed handlers\n", key);
78 for ( i = 0; i < KEY_MAX; i++ )
79 if ( key_table[i].u.handler != NULL )
80 printk(" key '%c' (ascii '%02x') => %s\n",
81 (i<33 || i>126)?(' '):(i),i,
82 key_table[i].desc);
83 }
85 static void dump_registers(unsigned char key, struct xen_regs *regs)
86 {
87 printk("'%c' pressed -> dumping registers\n", key);
88 show_registers(regs);
89 }
91 static void halt_machine(unsigned char key, struct xen_regs *regs)
92 {
93 printk("'%c' pressed -> rebooting machine\n", key);
94 machine_restart(NULL);
95 }
97 void do_task_queues(unsigned char key)
98 {
99 struct domain *d;
100 struct exec_domain *ed;
101 s_time_t now = NOW();
103 printk("'%c' pressed -> dumping task queues (now=0x%X:%08X)\n", key,
104 (u32)(now>>32), (u32)now);
106 read_lock(&domlist_lock);
108 for_each_domain ( d )
109 {
110 printk("Xen: DOM %u, flags=%lx refcnt=%d nr_pages=%d "
111 "xenheap_pages=%d\n", d->id, d->d_flags,
112 atomic_read(&d->refcnt), d->tot_pages, d->xenheap_pages);
114 dump_pageframe_info(d);
116 for_each_exec_domain ( d, ed ) {
117 printk("Guest: %p CPU %d [has=%c] flags=%lx "
118 "upcall_pend = %02x, upcall_mask = %02x\n", ed,
119 ed->processor,
120 test_bit(EDF_RUNNING, &ed->ed_flags) ? 'T':'F',
121 ed->ed_flags,
122 ed->vcpu_info->evtchn_upcall_pending,
123 ed->vcpu_info->evtchn_upcall_mask);
124 printk("Notifying guest... %d/%d\n", d->id, ed->eid);
125 printk("port %d/%d stat %d %d %d\n",
126 VIRQ_DEBUG, ed->virq_to_evtchn[VIRQ_DEBUG],
127 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG], &d->shared_info->evtchn_pending[0]),
128 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG], &d->shared_info->evtchn_mask[0]),
129 test_bit(ed->virq_to_evtchn[VIRQ_DEBUG]>>5, &ed->vcpu_info->evtchn_pending_sel));
130 send_guest_virq(ed, VIRQ_DEBUG);
131 }
132 }
134 read_unlock(&domlist_lock);
135 }
137 extern void dump_runq(unsigned char key);
138 extern void print_sched_histo(unsigned char key);
139 extern void reset_sched_histo(unsigned char key);
140 #ifndef NDEBUG
141 extern void audit_domains_key(unsigned char key);
142 #endif
144 #ifdef PERF_COUNTERS
145 extern void perfc_printall(unsigned char key);
146 extern void perfc_reset(unsigned char key);
147 #endif
149 void initialize_keytable(void)
150 {
151 open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
153 register_irq_keyhandler(
154 'd', dump_registers, "dump registers");
155 register_keyhandler(
156 'h', show_handlers, "show this message");
157 register_keyhandler(
158 'l', print_sched_histo, "print sched latency histogram");
159 register_keyhandler(
160 'L', reset_sched_histo, "reset sched latency histogram");
161 register_keyhandler(
162 'q', do_task_queues, "dump task queues + guest state");
163 register_keyhandler(
164 'r', dump_runq, "dump run queues");
165 register_irq_keyhandler(
166 'R', halt_machine, "reboot machine");
168 #ifndef NDEBUG
169 register_keyhandler(
170 'o', audit_domains_key, "audit domains >0 EXPERIMENTAL");
171 #endif
173 #ifdef PERF_COUNTERS
174 register_keyhandler(
175 'p', perfc_printall, "print performance counters");
176 register_keyhandler(
177 'P', perfc_reset, "reset performance counters");
178 #endif
179 }