debuggers.hg

view xen/common/keyhandler.c @ 3515:d331c6994d28

bitkeeper revision 1.1159.223.12 (41f14d3cE4GADmEAEr6XE9nXX4dyGw)

Common-code cleanups. Moved arch-specific code out into arch/x86
and asm-x86.
author kaf24@scramble.cl.cam.ac.uk
date Fri Jan 21 18:43:08 2005 +0000 (2005-01-21)
parents 4644bea63898
children 46c14b1a4351 0823f72cd071
line source
1 /******************************************************************************
2 * keyhandler.c
3 */
5 #include <xen/keyhandler.h>
6 #include <xen/reboot.h>
7 #include <xen/event.h>
8 #include <xen/console.h>
9 #include <xen/serial.h>
10 #include <xen/sched.h>
11 #include <xen/softirq.h>
13 #define KEY_MAX 256
14 #define STR_MAX 64
16 static struct {
17 union {
18 keyhandler_t *handler;
19 irq_keyhandler_t *irq_handler;
20 } u;
21 unsigned int flags;
22 char desc[STR_MAX];
23 } key_table[KEY_MAX];
25 #define KEYHANDLER_IRQ_CALLBACK 0x1
27 static unsigned char keypress_key;
29 void keypress_softirq(void)
30 {
31 keyhandler_t *h;
32 unsigned char key = keypress_key;
33 if ( (h = key_table[key].u.handler) != NULL )
34 (*h)(key);
35 }
37 void handle_keypress(unsigned char key, struct xen_regs *regs)
38 {
39 irq_keyhandler_t *h;
41 if ( key_table[key].flags & KEYHANDLER_IRQ_CALLBACK )
42 {
43 if ( (h = key_table[key].u.irq_handler) != NULL )
44 (*h)(key, regs);
45 }
46 else
47 {
48 keypress_key = key;
49 raise_softirq(KEYPRESS_SOFTIRQ);
50 }
51 }
53 void register_keyhandler(
54 unsigned char key, keyhandler_t *handler, char *desc)
55 {
56 ASSERT(key_table[key].u.handler == NULL);
57 key_table[key].u.handler = handler;
58 key_table[key].flags = 0;
59 strncpy(key_table[key].desc, desc, STR_MAX);
60 key_table[key].desc[STR_MAX-1] = '\0';
61 }
63 void register_irq_keyhandler(
64 unsigned char key, irq_keyhandler_t *handler, char *desc)
65 {
66 ASSERT(key_table[key].u.irq_handler == NULL);
67 key_table[key].u.irq_handler = handler;
68 key_table[key].flags = KEYHANDLER_IRQ_CALLBACK;
69 strncpy(key_table[key].desc, desc, STR_MAX);
70 key_table[key].desc[STR_MAX-1] = '\0';
71 }
73 static void show_handlers(unsigned char key)
74 {
75 int i;
76 printk("'%c' pressed -> showing installed handlers\n", key);
77 for ( i = 0; i < KEY_MAX; i++ )
78 if ( key_table[i].u.handler != NULL )
79 printk(" key '%c' (ascii '%02x') => %s\n",
80 (i<33 || i>126)?(' '):(i),i,
81 key_table[i].desc);
82 }
84 static void dump_registers(unsigned char key, struct xen_regs *regs)
85 {
86 printk("'%c' pressed -> dumping registers\n", key);
87 show_registers(regs);
88 }
90 static void halt_machine(unsigned char key, struct xen_regs *regs)
91 {
92 printk("'%c' pressed -> rebooting machine\n", key);
93 machine_restart(NULL);
94 }
96 void do_task_queues(unsigned char key)
97 {
98 struct domain *d;
99 s_time_t now = NOW();
101 printk("'%c' pressed -> dumping task queues (now=0x%X:%08X)\n", key,
102 (u32)(now>>32), (u32)now);
104 read_lock(&domlist_lock);
106 for_each_domain ( d )
107 {
108 printk("Xen: DOM %u, CPU %d [has=%c] flags=%lx refcnt=%d nr_pages=%d "
109 "xenheap_pages=%d\n",
110 d->id, d->processor,
111 test_bit(DF_RUNNING, &d->flags) ? 'T':'F', d->flags,
112 atomic_read(&d->refcnt), d->tot_pages, d->xenheap_pages);
114 dump_pageframe_info(d);
116 printk("Guest: upcall_pend = %02x, upcall_mask = %02x\n",
117 d->shared_info->vcpu_data[0].evtchn_upcall_pending,
118 d->shared_info->vcpu_data[0].evtchn_upcall_mask);
119 printk("Notifying guest...\n");
120 send_guest_virq(d, VIRQ_DEBUG);
121 }
123 read_unlock(&domlist_lock);
124 }
126 extern void dump_runq(unsigned char key);
127 extern void print_sched_histo(unsigned char key);
128 extern void reset_sched_histo(unsigned char key);
129 #ifndef NDEBUG
130 extern void audit_domains_key(unsigned char key);
131 #endif
133 #ifdef PERF_COUNTERS
134 extern void perfc_printall(unsigned char key);
135 extern void perfc_reset(unsigned char key);
136 #endif
138 void initialize_keytable(void)
139 {
140 open_softirq(KEYPRESS_SOFTIRQ, keypress_softirq);
142 register_irq_keyhandler(
143 'd', dump_registers, "dump registers");
144 register_keyhandler(
145 'h', show_handlers, "show this message");
146 register_keyhandler(
147 'l', print_sched_histo, "print sched latency histogram");
148 register_keyhandler(
149 'L', reset_sched_histo, "reset sched latency histogram");
150 register_keyhandler(
151 'q', do_task_queues, "dump task queues + guest state");
152 register_keyhandler(
153 'r', dump_runq, "dump run queues");
154 register_irq_keyhandler(
155 'R', halt_machine, "reboot machine");
157 #ifndef NDEBUG
158 register_keyhandler(
159 'o', audit_domains_key, "audit domains >0 EXPERIMENTAL");
160 #endif
162 #ifdef PERF_COUNTERS
163 register_keyhandler(
164 'p', perfc_printall, "print performance counters");
165 register_keyhandler(
166 'P', perfc_reset, "reset performance counters");
167 #endif
168 }