| 1 | #include "../module_load.h" |
|---|
| 2 | #include "../gui_draw.h" |
|---|
| 3 | #include "../module_exportlist.h" |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | // ========= MODULE INIT ================= |
|---|
| 7 | |
|---|
| 8 | int module_idx=-1; |
|---|
| 9 | |
|---|
| 10 | extern int basic_module_init(); |
|---|
| 11 | void (*_getmeminfo)(void*) = 0; |
|---|
| 12 | |
|---|
| 13 | /***************** BEGIN OF AUXILARY PART ********************* |
|---|
| 14 | ATTENTION: DO NOT REMOVE OR CHANGE SIGNATURES IN THIS SECTION |
|---|
| 15 | **************************************************************/ |
|---|
| 16 | |
|---|
| 17 | void* MODULE_EXPORT_LIST[] = { |
|---|
| 18 | /* 0 */ (void*)EXPORTLIST_MAGIC_NUMBER, |
|---|
| 19 | /* 1 */ (void*)0 |
|---|
| 20 | }; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | //--------------------------------------------------------- |
|---|
| 24 | // PURPOSE: Bind module symbols with chdk. |
|---|
| 25 | // Required function |
|---|
| 26 | // PARAMETERS: pointer to chdk list of export |
|---|
| 27 | // RETURN VALUE: 1 error, 0 ok |
|---|
| 28 | //--------------------------------------------------------- |
|---|
| 29 | int _module_loader( void** chdk_export_list ) |
|---|
| 30 | { |
|---|
| 31 | if ( (unsigned int)chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER ) |
|---|
| 32 | return 1; |
|---|
| 33 | |
|---|
| 34 | _getmeminfo = chdk_export_list[MODULESYM_GETMEMINFO]; |
|---|
| 35 | |
|---|
| 36 | return 0; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | //--------------------------------------------------------- |
|---|
| 42 | // PURPOSE: Finalize module operations (close allocs, etc) |
|---|
| 43 | // RETURN VALUE: 0-ok, 1-fail |
|---|
| 44 | //--------------------------------------------------------- |
|---|
| 45 | int _module_unloader() |
|---|
| 46 | { |
|---|
| 47 | return 0; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | //--------------------------------------------------------- |
|---|
| 52 | // PURPOSE: Default action for simple modules (direct run) |
|---|
| 53 | // NOTE: Please comment this function if no default action and this library module |
|---|
| 54 | //--------------------------------------------------------- |
|---|
| 55 | int _module_run(int moduleidx, int argn, int* arguments) |
|---|
| 56 | { |
|---|
| 57 | module_idx=moduleidx; |
|---|
| 58 | |
|---|
| 59 | basic_module_init(); |
|---|
| 60 | return 0; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /******************** Module Information structure ******************/ |
|---|
| 64 | |
|---|
| 65 | struct ModuleInfo _module_info = { MODULEINFO_V1_MAGICNUM, |
|---|
| 66 | sizeof(struct ModuleInfo), |
|---|
| 67 | |
|---|
| 68 | ANY_CHDK_BRANCH, 0, // Requirements of CHDK version |
|---|
| 69 | ANY_PLATFORM_ALLOWED, // Specify platform dependency |
|---|
| 70 | 0, // flag |
|---|
| 71 | (int32_t)"Module Inspector",// Module name |
|---|
| 72 | 1, 0, // Module version |
|---|
| 73 | (int32_t)"Show list of loaded modules" |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | /*************** END OF AUXILARY PART *******************/ |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | /*************** GUI MODULE *******************/ |
|---|
| 83 | |
|---|
| 84 | #include "../flt.h" |
|---|
| 85 | #include "../gui_mbox.h" |
|---|
| 86 | #include "keyboard.h" |
|---|
| 87 | #include "stdlib.h" |
|---|
| 88 | #include "platform.h" |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | void gui_module_menu_kbd_process(); |
|---|
| 92 | void gui_module_kbd_process(); |
|---|
| 93 | void gui_module_draw(); |
|---|
| 94 | |
|---|
| 95 | gui_handler GUI_MODE_MODULE_INSPECTOR = |
|---|
| 96 | /*GUI_MODE_MODULE_INSPECTOR*/ { GUI_MODE_MODULE, gui_module_draw, gui_module_kbd_process, gui_module_menu_kbd_process, 0, GUI_MODE_MAGICNUM }; |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | int modinspect_redraw; |
|---|
| 100 | gui_handler *modinspect_old_guimode; |
|---|
| 101 | |
|---|
| 102 | static void modinspect_unload_cb(unsigned int btn) { |
|---|
| 103 | if (btn==MBOX_BTN_YES) { |
|---|
| 104 | module_async_unload_allrunned(0); |
|---|
| 105 | gui_set_mode(modinspect_old_guimode); // if core gui - return to it |
|---|
| 106 | } |
|---|
| 107 | modinspect_redraw=2; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | void gui_module_kbd_process() { |
|---|
| 112 | switch (kbd_get_autoclicked_key()) { |
|---|
| 113 | case KEY_SET: |
|---|
| 114 | modinspect_redraw=2; |
|---|
| 115 | break; |
|---|
| 116 | case KEY_DISPLAY: |
|---|
| 117 | gui_mbox_init( (int)"Module Inspector", (int)"Unload all modules?", |
|---|
| 118 | MBOX_TEXT_CENTER|MBOX_BTN_YES_NO|MBOX_DEF_BTN2, modinspect_unload_cb); |
|---|
| 119 | break; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | //------------------------------------------------------------------- |
|---|
| 124 | |
|---|
| 125 | int basic_module_init() { |
|---|
| 126 | modinspect_redraw=2; |
|---|
| 127 | modinspect_old_guimode = gui_set_mode(&GUI_MODE_MODULE_INSPECTOR); |
|---|
| 128 | return 1; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | extern int module_idx; |
|---|
| 132 | |
|---|
| 133 | void gui_module_menu_kbd_process() { |
|---|
| 134 | gui_set_mode(modinspect_old_guimode); |
|---|
| 135 | module_async_unload(module_idx); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | void gui_module_draw() |
|---|
| 139 | { |
|---|
| 140 | int idx, showidx; |
|---|
| 141 | |
|---|
| 142 | if (modinspect_redraw) { |
|---|
| 143 | |
|---|
| 144 | draw_filled_rect(0, 0, screen_width-1, screen_height-1, MAKE_COLOR(SCREEN_COLOR, SCREEN_COLOR)); |
|---|
| 145 | draw_txt_string(5, 0, "*** Module Inspector ***", MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 146 | draw_txt_string(0, 2, "Idx Name Addr Size", MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 147 | |
|---|
| 148 | showidx=0; |
|---|
| 149 | for ( idx=0; idx<20; idx++) |
|---|
| 150 | { |
|---|
| 151 | struct flat_hdr* flat = module_get_adr(idx); |
|---|
| 152 | if (flat==0) continue; |
|---|
| 153 | |
|---|
| 154 | char namebuf[12]; |
|---|
| 155 | memcpy(namebuf,flat->modulename,11); |
|---|
| 156 | namebuf[11]=0; |
|---|
| 157 | |
|---|
| 158 | char txt[50]; |
|---|
| 159 | sprintf(txt,"%02d: %-12s %08x - %d bytes", idx, namebuf, (unsigned)flat, flat->reloc_start); |
|---|
| 160 | draw_txt_string(0, 3+showidx, txt, MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 161 | showidx++; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | // sprintf(buf, lang_str(LANG_MSG_MEMORY_INFO_TEXT), core_get_free_memory(), MEMISOSIZE, &_start, &_end); |
|---|
| 165 | // sprintf(buf,"MEM %08x-%08x - %d free",&_start, &_end,core_get_free_memory()); |
|---|
| 166 | // sprintf(buf,"--- %-12s %08x - %d","CHDK",&_start, MEMISOSIZE ); |
|---|
| 167 | |
|---|
| 168 | draw_txt_string(1, 4+showidx, "SET-redraw, DISP-unload_all, MENU-exit", MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 169 | |
|---|
| 170 | // Simple platform-dependend part [not always GetMemInfo exits] |
|---|
| 171 | if (_getmeminfo) { |
|---|
| 172 | |
|---|
| 173 | cam_meminfo meminfo; |
|---|
| 174 | memset(&meminfo,sizeof(meminfo),0); |
|---|
| 175 | _getmeminfo(&meminfo); |
|---|
| 176 | |
|---|
| 177 | char txt[50]; |
|---|
| 178 | sprintf(txt,"MEM: %08x-%08x: %dbytes",meminfo.start_address, meminfo.end_address, meminfo.total_size); |
|---|
| 179 | draw_txt_string(0, 5+showidx, txt, MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 180 | sprintf(txt,"alloc: now=%d(%d) max=%d", meminfo.allocated_size, meminfo.allocated_count, meminfo.allocated_peak); |
|---|
| 181 | draw_txt_string(0, 6+showidx, txt, MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 182 | sprintf(txt,"free: now=%d(%d) max=%d", meminfo.free_size, meminfo.free_block_count, meminfo.free_block_max_size); |
|---|
| 183 | draw_txt_string(0, 7+showidx, txt, MAKE_COLOR(SCREEN_COLOR, COLOR_WHITE)); |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | modinspect_redraw = 0; |
|---|
| 188 | } |
|---|
| 189 | |
|---|