This source file includes following definitions.
- _run
- _module_can_unload
- _module_exit_alt
- dummy_function1
- sampling_proc
- write_log
- gui_exmem_kbd_process
- basic_module_init
- gui_exmem_menu_kbd_process
- gui_exmem_draw
1 #include "camera_info.h"
2 #include "gui.h"
3 #include "gui_draw.h"
4 #include "meminfo.h"
5 #include "module_load.h"
6 #include "simple_module.h"
7 #include "clock.h"
8 #include "cachebit.h"
9 #include "exmem.h"
10 #include "time.h"
11
12
13
14 static int running = 0;
15 static int sampling = 0;
16 static int shandle = 0;
17
18 extern int basic_module_init();
19
20
21
22
23
24 int _run()
25 {
26 basic_module_init();
27
28 return 0;
29 }
30
31 int _module_can_unload()
32 {
33 return (running==0 && shandle==0 && sampling==0);
34 }
35
36 int _module_exit_alt()
37 {
38
39 return 0;
40 }
41
42
43
44 libsimple_sym _librun =
45 {
46 {
47 0, 0, _module_can_unload, _module_exit_alt, _run
48 }
49 };
50
51 ModuleInfo _module_info =
52 {
53 MODULEINFO_V1_MAGICNUM,
54 sizeof(ModuleInfo),
55 {1,0},
56
57 ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,
58 ANY_PLATFORM_ALLOWED,
59
60 (int32_t)"EXMEM Inspector",
61 MTYPE_TOOL,
62
63 &_librun.base,
64
65 ANY_VERSION,
66 CAM_SCREEN_VERSION,
67 ANY_VERSION,
68 ANY_VERSION,
69
70 0,
71 };
72
73
74
75
76 #ifndef THUMB_FW
77 int sampling_proc_ARM(int, int);
78
79 void __attribute__((naked,noinline)) dummy_function1(void) {
80 asm volatile (
81 ".code 32\n"
82 "sampling_proc_ARM:\n"
83 "adr r3, sapr_thumb+1\n"
84 "bx r3\n"
85 ".code 16\n"
86 "sapr_thumb:\n"
87 "push {lr}\n"
88 "bl sampling_proc\n"
89 "pop {pc}\n"
90 );
91 }
92 #endif
93
94 typedef struct
95 {
96 int tim;
97 unsigned int typ;
98 char *adr;
99 unsigned int len;
100 } exmemlog_s;
101
102 #define LOG_LEN 128
103 static exmemlog_s exl[LOG_LEN];
104 static int exlpnt = 0;
105 static unsigned int extypcnt = 0;
106 static exmem_alloc_info exm_prev[42];
107 static exmem_alloc_info eaitmp;
108 static int speriod = 2000;
109
110 int sampling_proc(__attribute__ ((unused))int ttime, __attribute__ ((unused))int param) {
111
112 if (!sampling) {
113 shandle = 0;
114 return 0;
115 }
116
117 #ifndef THUMB_FW
118 shandle = SetHPTimerAfterNow(speriod, sampling_proc_ARM, sampling_proc_ARM, 0);
119 #else
120 shandle = SetHPTimerAfterNow(speriod, sampling_proc, sampling_proc, 0);
121 #endif
122
123 int gtc = get_tick_count();
124 unsigned int n;
125 for (n=0; n<extypcnt; n++) {
126 get_exmem_type_status(n, &eaitmp);
127 if (exm_prev[n].addr!=eaitmp.addr || exm_prev[n].len!=eaitmp.len) {
128 if (exlpnt<LOG_LEN) {
129 exl[exlpnt].tim = gtc;
130 exl[exlpnt].typ = n;
131 exl[exlpnt].adr = eaitmp.addr;
132 exl[exlpnt].len = eaitmp.len;
133 exlpnt++;
134 }
135 }
136 exm_prev[n].addr=eaitmp.addr;
137 exm_prev[n].len=eaitmp.len;
138 }
139 return 0;
140 }
141
142
143 void write_log()
144 {
145 FILE *f = NULL;
146 char txt[80], name[18];
147 int n = 0;
148 do {
149 sprintf(txt, "A/CHDK/LOGS/EXM_%04d.LOG", n++);
150 if (stat(txt,0) != 0) {
151 f=fopen(txt, "wb");
152 break;
153 }
154 } while(n<9999);
155
156 if (!f)
157 return;
158
159 struct tm *tms;
160 time_t t;
161 t = time(NULL);
162 tms = localtime(&t);
163 sprintf(txt,"%04d-%02d-%02d %02d:%02d:%02d\n",tms->tm_year+1900,tms->tm_mon+1,tms->tm_mday,
164 tms->tm_hour,tms->tm_min,tms->tm_sec);
165 fwrite(txt,1,strlen(txt),f);
166 sprintf(txt,"%s, %s\n\n",camera_info.platform,camera_info.platformsub);
167 fwrite(txt,1,strlen(txt),f);
168 sprintf(txt,"TIME,TYPE,ADDRESS,SIZE\n");
169 fwrite(txt,1,strlen(txt),f);
170 for (n=0; n<LOG_LEN; n++)
171 {
172 char *s = get_exmem_type_name(exl[n].typ);
173 if (!s)
174 {
175 strcpy(name, "-");
176 }
177 else
178 {
179 s += 6;
180 strncpy(name, s, 17); name[17] = 0;
181 }
182 if (exl[n].tim)
183 {
184 sprintf(txt,"%d,%s,%08x,%08x\n", exl[n].tim, name, (unsigned int)exl[n].adr, exl[n].len);
185 fwrite(txt,1,strlen(txt),f);
186 }
187 }
188 fclose(f);
189 }
190
191
192
193 #include "gui_mbox.h"
194 #include "keyboard.h"
195
196 void gui_exmem_menu_kbd_process();
197 int gui_exmem_kbd_process();
198 void gui_exmem_draw();
199
200 gui_handler GUI_MODE_EXMEM_INSPECTOR =
201 { GUI_MODE_MODULE, gui_exmem_draw, gui_exmem_kbd_process, gui_exmem_menu_kbd_process, 0, 0 };
202
203 static unsigned int log_disp_start = 0;
204 static int exmeminspect_mode = 0;
205 static int exmeminspect_column = 0;
206 static int disph = 0;
207 int exmeminspect_redraw;
208 gui_handler *exmeminspect_old_guimode;
209
210 int gui_exmem_kbd_process()
211 {
212 switch (kbd_get_autoclicked_key())
213 {
214 case KEY_SET:
215 sampling = !sampling;
216 if (sampling) {
217
218 memset(exm_prev, 0, sizeof(exmem_alloc_info)*42);
219 memset(exl, 0, sizeof(exmemlog_s)*LOG_LEN);
220 exlpnt = 0;
221 }
222 sampling_proc(0,0);
223 exmeminspect_redraw = 2;
224 break;
225 case KEY_UP:
226 if (log_disp_start > 0) log_disp_start--;
227 exmeminspect_redraw = 1;
228 break;
229 case KEY_DOWN:
230 if (log_disp_start < LOG_LEN-1) log_disp_start++;
231 exmeminspect_redraw = 1;
232 break;
233 case KEY_SHOOT_HALF:
234 exmeminspect_mode = exmeminspect_mode==0?1:0;
235 exmeminspect_redraw = 2;
236 break;
237 case KEY_LEFT:
238 if (exlpnt>0)
239 write_log();
240 exmeminspect_redraw = 2;
241 break;
242 case KEY_RIGHT:
243 exmeminspect_column = exmeminspect_column==0?1:0;
244 exmeminspect_redraw = 2;
245 break;
246 }
247 return 0;
248 }
249
250
251
252 int basic_module_init()
253 {
254 if (!running)
255 {
256 running = 1;
257 extypcnt = exmem_type_count;
258 sampling = 0;
259 shandle = 0;
260 disph = camera_screen.height / FONT_HEIGHT;
261 }
262 exmeminspect_redraw = 2;
263 exmeminspect_old_guimode = gui_set_mode(&GUI_MODE_EXMEM_INSPECTOR);
264 return 1;
265 }
266
267 void gui_exmem_menu_kbd_process()
268 {
269 running = 0;
270 sampling = 0;
271 if (shandle) {
272 CancelHPTimer(shandle);
273 shandle = 0;
274 }
275
276 gui_set_mode(exmeminspect_old_guimode);
277 }
278
279 void gui_exmem_draw()
280 {
281 unsigned int idx, idxmax, showidx;
282
283 if (exmeminspect_redraw) {
284
285 if (exmeminspect_redraw == 2)
286 {
287 draw_rectangle(camera_screen.disp_left, 0, camera_screen.disp_right, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
288 draw_string(camera_screen.disp_left, 0, "EXMEM Inspector", MAKE_COLOR(COLOR_WHITE, COLOR_BLACK));
289 draw_string(camera_screen.disp_left, FONT_HEIGHT, sampling?"SET-stop MENU-exit RIGHT-viewmode LEFT-save":"SET-start MENU-exit RIGHT-viewmode LEFT-save", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
290 if (exmeminspect_mode == 0) {
291 draw_string(camera_screen.disp_left+17*FONT_WIDTH, 0, "LIST, HALFSHOOT->LOG", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
292 if (exmeminspect_column == 0) {
293 draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Idx Name Addr Size ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
294 }
295 else {
296 draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Idx Name Addr Top ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
297 }
298 }
299 else {
300 draw_string(camera_screen.disp_left+17*FONT_WIDTH, 0, "LOG, HALFSHOOT->LIST", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
301 if (exmeminspect_column == 0) {
302 draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Time Name Addr Size ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
303 }
304 else {
305 draw_string(camera_screen.disp_left, 2*FONT_HEIGHT, "Time Name Addr Top ", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
306 }
307 }
308 }
309
310 showidx=3*FONT_HEIGHT;
311 if (exmeminspect_mode == 0)
312 {
313 idxmax = extypcnt;
314 for ( idx=0; idx<idxmax; idx++)
315 {
316 char *s = get_exmem_type_name(idx);
317 if (!s)
318 continue;
319 exmem_alloc_info eai;
320 if (!get_exmem_type_status(idx, &eai) || !eai.addr)
321 continue;
322
323 char txt[50], name[18];
324 s += 6;
325 strncpy(name, s, 17); name[17] = 0;
326 if (exmeminspect_column == 0) {
327 sprintf(txt,"%02d: %-17s %08x %8x", idx, name, (unsigned int)eai.addr, eai.len);
328 }
329 else {
330 sprintf(txt,"%02d: %-17s %08x %08x", idx, name, (unsigned int)eai.addr, (unsigned int)eai.addr+eai.len);
331 }
332 draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
333 showidx += FONT_HEIGHT;
334 }
335 }
336 else
337 {
338 idx = log_disp_start;
339 while (showidx < (unsigned)camera_screen.height)
340 {
341 if (idx >= LOG_LEN || exl[idx].tim == 0)
342 {
343 draw_string(camera_screen.disp_left, showidx,
344 " ",
345 MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
346 }
347 else
348 {
349 char *s = get_exmem_type_name(exl[idx].typ);
350 if (!s)
351 s = " -";
352
353 char txt[50], name[18];
354 s += 6;
355 strncpy(name, s, 17); name[17] = 0;
356 if (exmeminspect_column == 0) {
357 sprintf(txt,"%06d: %-17s %08x %8x", exl[idx].tim, name, (unsigned int)exl[idx].adr, exl[idx].len);
358 }
359 else {
360 sprintf(txt,"%06d: %-17s %08x %08x", exl[idx].tim, name, (unsigned int)exl[idx].adr, (unsigned int)exl[idx].adr+exl[idx].len);
361 }
362 draw_string(camera_screen.disp_left, showidx, txt, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
363 }
364 showidx += FONT_HEIGHT;
365 idx++;
366 }
367 }
368 }
369
370 exmeminspect_redraw = 0;
371 }
372