1 /* This file contains information dump procedures. During the initialization 2 * of the Information Service 'known' function keys are registered at the TTY 3 * server in order to receive a notification if one is pressed. Here, the 4 * corresponding dump procedure is called. 5 * 6 * The entry points into this file are 7 * map_unmap_fkeys: register or unregister function key maps with TTY 8 * do_fkey_pressed: handle a function key pressed notification 9 */ 10 11 #include "inc.h" 12 #include <minix/vm.h> 13 14 struct hook_entry { 15 int key; 16 void (*function)(void); 17 char *name; 18 } hooks[] = { 19 { F1, proctab_dmp, "Kernel process table" }, 20 { F3, image_dmp, "System image" }, 21 { F4, privileges_dmp, "Process privileges" }, 22 { F5, monparams_dmp, "Boot monitor parameters" }, 23 { F6, irqtab_dmp, "IRQ hooks and policies" }, 24 { F7, kmessages_dmp, "Kernel messages" }, 25 { F8, vm_dmp, "VM status and process maps" }, 26 { F10, kenv_dmp, "Kernel parameters" }, 27 { SF1, mproc_dmp, "Process manager process table" }, 28 { SF2, sigaction_dmp, "Signals" }, 29 { SF3, fproc_dmp, "Filesystem process table" }, 30 { SF4, dtab_dmp, "Device/Driver mapping" }, 31 { SF5, mapping_dmp, "Print key mappings" }, 32 { SF6, rproc_dmp, "Reincarnation server process table" }, 33 { SF8, data_store_dmp, "Data store contents" }, 34 { SF9, procstack_dmp, "Processes with stack traces" }, 35 }; 36 37 /* Define hooks for the debugging dumps. This table maps function keys 38 * onto a specific dump and provides a description for it. 39 */ 40 #define NHOOKS (sizeof(hooks)/sizeof(hooks[0])) 41 42 /*===========================================================================* 43 * map_unmap_keys * 44 *===========================================================================*/ 45 void 46 map_unmap_fkeys(int map) 47 { 48 int fkeys, sfkeys; 49 int h, s; 50 51 fkeys = sfkeys = 0; 52 53 for (h = 0; h < NHOOKS; h++) { 54 if (hooks[h].key >= F1 && hooks[h].key <= F12) 55 bit_set(fkeys, hooks[h].key - F1 + 1); 56 else if (hooks[h].key >= SF1 && hooks[h].key <= SF12) 57 bit_set(sfkeys, hooks[h].key - SF1 + 1); 58 } 59 60 if (map) s = fkey_map(&fkeys, &sfkeys); 61 else s = fkey_unmap(&fkeys, &sfkeys); 62 63 if (s != OK) 64 printf("IS: warning, fkey_ctl failed: %d\n", s); 65 } 66 67 /*===========================================================================* 68 * handle_fkey * 69 *===========================================================================*/ 70 #define pressed(start, end, bitfield, key) \ 71 (((start) <= (key)) && ((end) >= (key)) && \ 72 bit_isset((bitfield), ((key) - (start) + 1))) 73 int do_fkey_pressed(m) 74 message *m; /* notification message */ 75 { 76 int s, h; 77 int fkeys, sfkeys; 78 79 /* The notification message does not convey any information, other 80 * than that some function keys have been pressed. Ask TTY for details. 81 */ 82 s = fkey_events(&fkeys, &sfkeys); 83 if (s < 0) { 84 printf("IS: warning, fkey_events failed: %d\n", s); 85 } 86 87 /* Now check which keys were pressed: F1-F12, SF1-SF12. */ 88 for(h=0; h < NHOOKS; h++) { 89 if (pressed(F1, F12, fkeys, hooks[h].key)) { 90 hooks[h].function(); 91 } else if (pressed(SF1, SF12, sfkeys, hooks[h].key)) { 92 hooks[h].function(); 93 } 94 } 95 96 /* Don't send a reply message. */ 97 return(EDONTREPLY); 98 } 99 100 /*===========================================================================* 101 * key_name * 102 *===========================================================================*/ 103 static char *key_name(int key) 104 { 105 static char name[15]; 106 107 if(key >= F1 && key <= F12) 108 snprintf(name, sizeof(name), " F%d", key - F1 + 1); 109 else if(key >= SF1 && key <= SF12) 110 snprintf(name, sizeof(name), "Shift+F%d", key - SF1 + 1); 111 else 112 strlcpy(name, "?", sizeof(name)); 113 return name; 114 } 115 116 117 /*===========================================================================* 118 * mapping_dmp * 119 *===========================================================================*/ 120 void mapping_dmp(void) 121 { 122 int h; 123 124 printf("Function key mappings for debug dumps in IS server.\n"); 125 printf(" Key Description\n"); 126 printf("-------------------------------------"); 127 printf("------------------------------------\n"); 128 129 for(h=0; h < NHOOKS; h++) 130 printf(" %10s. %s\n", key_name(hooks[h].key), hooks[h].name); 131 printf("\n"); 132 } 133