1433d6423SLionel Sambuc /* This file contains information dump procedures. During the initialization
2433d6423SLionel Sambuc * of the Information Service 'known' function keys are registered at the TTY
3433d6423SLionel Sambuc * server in order to receive a notification if one is pressed. Here, the
4433d6423SLionel Sambuc * corresponding dump procedure is called.
5433d6423SLionel Sambuc *
6433d6423SLionel Sambuc * The entry points into this file are
7433d6423SLionel Sambuc * map_unmap_fkeys: register or unregister function key maps with TTY
8433d6423SLionel Sambuc * do_fkey_pressed: handle a function key pressed notification
9433d6423SLionel Sambuc */
10433d6423SLionel Sambuc
11433d6423SLionel Sambuc #include "inc.h"
12433d6423SLionel Sambuc #include <minix/vm.h>
13433d6423SLionel Sambuc
14433d6423SLionel Sambuc struct hook_entry {
15433d6423SLionel Sambuc int key;
16433d6423SLionel Sambuc void (*function)(void);
17433d6423SLionel Sambuc char *name;
18433d6423SLionel Sambuc } hooks[] = {
19433d6423SLionel Sambuc { F1, proctab_dmp, "Kernel process table" },
20433d6423SLionel Sambuc { F3, image_dmp, "System image" },
21433d6423SLionel Sambuc { F4, privileges_dmp, "Process privileges" },
22433d6423SLionel Sambuc { F5, monparams_dmp, "Boot monitor parameters" },
23433d6423SLionel Sambuc { F6, irqtab_dmp, "IRQ hooks and policies" },
24433d6423SLionel Sambuc { F7, kmessages_dmp, "Kernel messages" },
25433d6423SLionel Sambuc { F8, vm_dmp, "VM status and process maps" },
26433d6423SLionel Sambuc { F10, kenv_dmp, "Kernel parameters" },
27433d6423SLionel Sambuc { SF1, mproc_dmp, "Process manager process table" },
28433d6423SLionel Sambuc { SF2, sigaction_dmp, "Signals" },
29433d6423SLionel Sambuc { SF3, fproc_dmp, "Filesystem process table" },
30433d6423SLionel Sambuc { SF4, dtab_dmp, "Device/Driver mapping" },
31433d6423SLionel Sambuc { SF5, mapping_dmp, "Print key mappings" },
32433d6423SLionel Sambuc { SF6, rproc_dmp, "Reincarnation server process table" },
33433d6423SLionel Sambuc { SF8, data_store_dmp, "Data store contents" },
34433d6423SLionel Sambuc { SF9, procstack_dmp, "Processes with stack traces" },
35433d6423SLionel Sambuc };
36433d6423SLionel Sambuc
37433d6423SLionel Sambuc /* Define hooks for the debugging dumps. This table maps function keys
38433d6423SLionel Sambuc * onto a specific dump and provides a description for it.
39433d6423SLionel Sambuc */
40433d6423SLionel Sambuc #define NHOOKS (sizeof(hooks)/sizeof(hooks[0]))
41433d6423SLionel Sambuc
42433d6423SLionel Sambuc /*===========================================================================*
43433d6423SLionel Sambuc * map_unmap_keys *
44433d6423SLionel Sambuc *===========================================================================*/
45*4aa48abaSRichard Sailer void
map_unmap_fkeys(int map)46*4aa48abaSRichard Sailer map_unmap_fkeys(int map)
47433d6423SLionel Sambuc {
48433d6423SLionel Sambuc int fkeys, sfkeys;
49433d6423SLionel Sambuc int h, s;
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc fkeys = sfkeys = 0;
52433d6423SLionel Sambuc
53433d6423SLionel Sambuc for (h = 0; h < NHOOKS; h++) {
54433d6423SLionel Sambuc if (hooks[h].key >= F1 && hooks[h].key <= F12)
55433d6423SLionel Sambuc bit_set(fkeys, hooks[h].key - F1 + 1);
56433d6423SLionel Sambuc else if (hooks[h].key >= SF1 && hooks[h].key <= SF12)
57433d6423SLionel Sambuc bit_set(sfkeys, hooks[h].key - SF1 + 1);
58433d6423SLionel Sambuc }
59433d6423SLionel Sambuc
60433d6423SLionel Sambuc if (map) s = fkey_map(&fkeys, &sfkeys);
61433d6423SLionel Sambuc else s = fkey_unmap(&fkeys, &sfkeys);
62433d6423SLionel Sambuc
63433d6423SLionel Sambuc if (s != OK)
64433d6423SLionel Sambuc printf("IS: warning, fkey_ctl failed: %d\n", s);
65433d6423SLionel Sambuc }
66433d6423SLionel Sambuc
67433d6423SLionel Sambuc /*===========================================================================*
68433d6423SLionel Sambuc * handle_fkey *
69433d6423SLionel Sambuc *===========================================================================*/
70433d6423SLionel Sambuc #define pressed(start, end, bitfield, key) \
71433d6423SLionel Sambuc (((start) <= (key)) && ((end) >= (key)) && \
72433d6423SLionel Sambuc bit_isset((bitfield), ((key) - (start) + 1)))
do_fkey_pressed(m)73433d6423SLionel Sambuc int do_fkey_pressed(m)
74433d6423SLionel Sambuc message *m; /* notification message */
75433d6423SLionel Sambuc {
76433d6423SLionel Sambuc int s, h;
77433d6423SLionel Sambuc int fkeys, sfkeys;
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc /* The notification message does not convey any information, other
80433d6423SLionel Sambuc * than that some function keys have been pressed. Ask TTY for details.
81433d6423SLionel Sambuc */
82433d6423SLionel Sambuc s = fkey_events(&fkeys, &sfkeys);
83433d6423SLionel Sambuc if (s < 0) {
84433d6423SLionel Sambuc printf("IS: warning, fkey_events failed: %d\n", s);
85433d6423SLionel Sambuc }
86433d6423SLionel Sambuc
87433d6423SLionel Sambuc /* Now check which keys were pressed: F1-F12, SF1-SF12. */
88433d6423SLionel Sambuc for(h=0; h < NHOOKS; h++) {
89433d6423SLionel Sambuc if (pressed(F1, F12, fkeys, hooks[h].key)) {
90433d6423SLionel Sambuc hooks[h].function();
91433d6423SLionel Sambuc } else if (pressed(SF1, SF12, sfkeys, hooks[h].key)) {
92433d6423SLionel Sambuc hooks[h].function();
93433d6423SLionel Sambuc }
94433d6423SLionel Sambuc }
95433d6423SLionel Sambuc
96433d6423SLionel Sambuc /* Don't send a reply message. */
97433d6423SLionel Sambuc return(EDONTREPLY);
98433d6423SLionel Sambuc }
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc /*===========================================================================*
101433d6423SLionel Sambuc * key_name *
102433d6423SLionel Sambuc *===========================================================================*/
key_name(int key)103433d6423SLionel Sambuc static char *key_name(int key)
104433d6423SLionel Sambuc {
105433d6423SLionel Sambuc static char name[15];
106433d6423SLionel Sambuc
107433d6423SLionel Sambuc if(key >= F1 && key <= F12)
108433d6423SLionel Sambuc snprintf(name, sizeof(name), " F%d", key - F1 + 1);
109433d6423SLionel Sambuc else if(key >= SF1 && key <= SF12)
110433d6423SLionel Sambuc snprintf(name, sizeof(name), "Shift+F%d", key - SF1 + 1);
111433d6423SLionel Sambuc else
112433d6423SLionel Sambuc strlcpy(name, "?", sizeof(name));
113433d6423SLionel Sambuc return name;
114433d6423SLionel Sambuc }
115433d6423SLionel Sambuc
116433d6423SLionel Sambuc
117433d6423SLionel Sambuc /*===========================================================================*
118433d6423SLionel Sambuc * mapping_dmp *
119433d6423SLionel Sambuc *===========================================================================*/
mapping_dmp(void)120433d6423SLionel Sambuc void mapping_dmp(void)
121433d6423SLionel Sambuc {
122433d6423SLionel Sambuc int h;
123433d6423SLionel Sambuc
124433d6423SLionel Sambuc printf("Function key mappings for debug dumps in IS server.\n");
125433d6423SLionel Sambuc printf(" Key Description\n");
126433d6423SLionel Sambuc printf("-------------------------------------");
127433d6423SLionel Sambuc printf("------------------------------------\n");
128433d6423SLionel Sambuc
129433d6423SLionel Sambuc for(h=0; h < NHOOKS; h++)
130433d6423SLionel Sambuc printf(" %10s. %s\n", key_name(hooks[h].key), hooks[h].name);
131433d6423SLionel Sambuc printf("\n");
132433d6423SLionel Sambuc }
133