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