Rev 8891 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8891 | dunkaist | 1 | ;------------------------------------------------------------------------------ |
2 | ; DEBUG BOARD for APPLICATIONS and KERNEL DEVELOPMENT |
||
4977 | Akyltist | 3 | ; See f63 |
4 | ; Compile with FASM for KolibriOS |
||
8891 | dunkaist | 5 | ;------------------------------------------------------------------------------ |
6 | use32 |
||
7 | org 0 |
||
8 | db 'MENUET01' |
||
9 | dd 1 |
||
10 | dd START |
||
11 | dd I_END |
||
12 | dd mem |
||
13 | dd mem |
||
14 | dd filename |
||
15 | dd 0 |
||
16 | ;------------------------------------------------------------------------------ |
||
17 | include 'lang.inc' |
||
18 | include '../../../macros.inc' |
||
19 | include '../../../debug.inc' |
||
20 | purge newline |
||
21 | ;SMALL FONT |
||
22 | MAXSTRINGS = 45 |
||
23 | LINE_H = 10 |
||
24 | WINDOW_W = 399 |
||
25 | WINDOW_H = MAXSTRINGS*LINE_H+45 |
||
26 | FONT_TYPE = 0x40000000 |
||
27 | ;BIG FONT |
||
28 | ; MAXSTRINGS = 30 |
||
29 | ; LINE_H = 15 |
||
30 | ; WINDOW_W = 630 |
||
31 | ; WINDOW_H = MAXSTRINGS*LINE_H+50 |
||
32 | ; FONT_TYPE = 0x50000000 |
||
6592 | leency | 33 | |
8891 | dunkaist | 34 | ;------------------------------------------------------------------------------ |
5925 | pathoswith | 35 | START: |
8891 | dunkaist | 36 | call CheckUnique |
37 | mov edi, filename |
||
38 | cmp [edi], byte 0 |
||
39 | jnz param |
||
40 | mov esi, default_filename |
||
41 | @@: |
||
42 | lodsb |
||
43 | stosb |
||
44 | test al,al |
||
45 | jnz @b |
||
46 | param: |
||
47 | mov ecx, (MAXSTRINGS+1)*20 |
||
48 | mov edi, text1 |
||
49 | mov eax, ' ' |
||
50 | rep stosd |
||
4672 | izikiel | 51 | |
8891 | dunkaist | 52 | mov ecx, (MAXSTRINGS+1)*20 |
53 | mov edi, text2 |
||
54 | rep stosd |
||
4672 | izikiel | 55 | |
8891 | dunkaist | 56 | mov byte [tmp1], 'x' |
57 | mov byte [tmp2], 'x' |
||
5925 | pathoswith | 58 | |
8891 | dunkaist | 59 | mcall 14 |
60 | and eax, 0xffff0000 |
||
61 | sub eax, WINDOW_W shl 16 |
||
62 | add eax, WINDOW_W |
||
63 | mov [xstart], eax |
||
64 | mcall 48, 3, sc, sizeof.system_colors |
||
31 | halyavin | 65 | |
8891 | dunkaist | 66 | mov esi, filename |
67 | call CreateFile |
||
68 | ;------------------------------------------------------------------------------ |
||
69 | red: |
||
70 | call draw_window |
||
71 | ;------------------------------------------------------------------------------ |
||
72 | still: |
||
73 | cmp [buffer_length], 0 |
||
74 | je @f |
||
75 | call write_buffer |
||
5925 | pathoswith | 76 | @@: |
8891 | dunkaist | 77 | mcall 23, 50 ; wait here for event |
78 | cmp eax, 1 ; redraw request ? |
||
79 | je red |
||
31 | halyavin | 80 | |
8891 | dunkaist | 81 | cmp eax, 2 ; key in buffer ? |
82 | je key |
||
31 | halyavin | 83 | |
8891 | dunkaist | 84 | cmp eax, 3 ; button in buffer ? |
85 | je button |
||
447 | heavyiron | 86 | |
8891 | dunkaist | 87 | mcall 63, 2 |
88 | cmp ebx, 1 |
||
89 | jne still |
||
31 | halyavin | 90 | |
8891 | dunkaist | 91 | new_data: |
92 | cmp [buffer_length], 255 |
||
93 | jne @f |
||
94 | call write_buffer |
||
5925 | pathoswith | 95 | @@: |
8891 | dunkaist | 96 | movzx ebx, byte[buffer_length] |
97 | mov [ebx+tmp], al |
||
98 | inc [buffer_length] |
||
99 | mov ebp, [targ] |
||
100 | cmp al, 10 |
||
101 | jz new_line |
||
102 | cmp al, 13 |
||
103 | jz new_check |
||
104 | jmp char |
||
105 | ;------------------------------------------ |
||
106 | write_buffer: |
||
107 | pusha |
||
108 | mov edx, tmp |
||
109 | movzx ecx, byte[buffer_length] |
||
110 | mov esi, filename |
||
111 | .write_to_logfile: |
||
112 | call WriteToFile |
||
113 | cmp eax, 5 |
||
114 | jne @f |
||
115 | mov esi, filename |
||
116 | mov [filepos], 0 |
||
117 | call CreateFile |
||
118 | jnc .write_to_logfile |
||
2234 | mario79 | 119 | @@: |
8891 | dunkaist | 120 | movzx eax,byte[buffer_length] |
121 | add [filepos],eax |
||
122 | xor eax,eax |
||
123 | mov [buffer_length],al |
||
124 | popa |
||
125 | ret |
||
126 | ;------------------------------------------ |
||
127 | new_line: |
||
128 | and [ebp-8], dword 0 |
||
129 | inc dword [ebp-4] |
||
130 | cmp [ebp-4], dword MAXSTRINGS |
||
131 | jbe .noypos |
||
132 | mov [ebp-4], dword MAXSTRINGS |
||
133 | lea esi, [ebp+80] |
||
134 | mov edi, ebp |
||
135 | mov ecx, 20*(MAXSTRINGS) |
||
136 | cld |
||
137 | rep movsd |
||
1571 | Asper | 138 | |
8891 | dunkaist | 139 | mov esi, [ebp-4] |
140 | imul esi, 80 |
||
141 | add esi, [ebp-8] |
||
142 | add esi, ebp |
||
143 | mov ecx, 20 |
||
144 | mov eax, ' ' |
||
145 | rep stosd |
||
5925 | pathoswith | 146 | .noypos: |
8891 | dunkaist | 147 | mov [targ],text2 |
148 | and [krnl_cnt],0 |
||
149 | jmp new_check |
||
150 | ;------------------------------------------ |
||
151 | char: |
||
152 | cmp ebp, text1 |
||
153 | je add2 |
||
154 | mov ecx, [krnl_cnt] |
||
155 | cmp al, [krnl_msg+ecx] |
||
156 | jne .noknl |
||
157 | inc [krnl_cnt] |
||
158 | cmp [krnl_cnt], 4 |
||
159 | jne new_check |
||
160 | mov [targ], text1 |
||
161 | .noknl: |
||
162 | mov ebp, [targ] |
||
163 | jecxz .add |
||
164 | push eax |
||
165 | mov esi, krnl_msg |
||
5925 | pathoswith | 166 | .l1: |
8891 | dunkaist | 167 | lodsb |
168 | call add_char |
||
169 | loop .l1 |
||
170 | pop eax |
||
5925 | pathoswith | 171 | .add: |
8891 | dunkaist | 172 | and [krnl_cnt], 0 |
173 | add2: |
||
174 | call add_char |
||
1571 | Asper | 175 | |
8891 | dunkaist | 176 | new_check: |
177 | mcall 63, 2 |
||
178 | cmp ebx, 1 |
||
179 | je new_data |
||
180 | call draw_text |
||
181 | jmp still |
||
2234 | mario79 | 182 | ;------------------------------------------------------------------------------ |
8891 | dunkaist | 183 | key: |
184 | mcall 2 |
||
185 | cmp ah, ' ' |
||
186 | je button.noclose |
||
187 | cmp ah, 51 ; F2 |
||
188 | je open_boardlog |
||
189 | jmp still |
||
190 | open_boardlog: |
||
191 | mcall 70, open_log_in_tinypad |
||
192 | jmp red |
||
193 | |||
194 | ;------------------------------------------------------------------------------ |
||
195 | button: |
||
196 | mcall 17 ; get id |
||
197 | cmp ah, 1 ; button id=1 ? |
||
198 | jne .noclose |
||
199 | or eax, -1 ; close this program |
||
200 | mcall |
||
201 | .noclose: |
||
202 | xor [vmode], 1 |
||
203 | jmp red |
||
204 | ;------------------------------------------------------------------------------ |
||
131 | diamond | 205 | add_char: |
8891 | dunkaist | 206 | push esi |
207 | mov esi, [ebp-4] |
||
208 | imul esi, 80 |
||
209 | add esi, [ebp-8] |
||
210 | mov [ebp+esi], al |
||
211 | inc dword[ebp-8] |
||
212 | cmp dword[ebp-8], 80 |
||
213 | jb .ok |
||
214 | mov dword[ebp-8], 79 |
||
2234 | mario79 | 215 | .ok: |
8891 | dunkaist | 216 | pop esi |
217 | ret |
||
5925 | pathoswith | 218 | |
8891 | dunkaist | 219 | ;------------------------------------------------------------------------------ |
220 | ;************************ WINDOW DEFINITIONS AND DRAW ************************ |
||
221 | ;------------------------------------------------------------------------------ |
||
31 | halyavin | 222 | draw_window: |
8891 | dunkaist | 223 | mcall 12, 1 ; 1, start of draw |
224 | mcall 48, 5 ; GetClientTop |
||
225 | shr ebx, 16 |
||
226 | mov ecx, ebx |
||
227 | shl ecx, 16 |
||
228 | add ecx, WINDOW_H ; [y start] *65536 + [y size] |
||
229 | mov edx, 0xffffff |
||
230 | or edx, 0x14000000 |
||
231 | xor esi, esi |
||
232 | mcall 0,[xstart],,,,title |
||
233 | mov ebx, 296 shl 16+31 |
||
234 | mcall 8,,<4,13>,3,[sc.work_button] |
||
235 | mov edx, [vmode] |
||
236 | lea edx, [edx*4+duk] |
||
237 | mov ecx, 0x80 |
||
238 | shr ecx, 24 |
||
239 | add ecx, [sc.work_button_text] |
||
240 | mcall 4,<300,7>,,,4 |
||
241 | call draw_text |
||
242 | mcall 12, 2 ; 2, end of draw |
||
243 | ret |
||
244 | ;------------------------------------------------------------------------------ |
||
2234 | mario79 | 245 | draw_text: |
8891 | dunkaist | 246 | mov ebx, 15*65536+30 ; draw info text with function 4 |
247 | xor ecx, ecx |
||
248 | or ecx, FONT_TYPE |
||
249 | mov edi, 0xffffff |
||
250 | mov edx, text1 |
||
251 | cmp [vmode], 0 |
||
252 | je .kern |
||
253 | mov edx, text2 |
||
5925 | pathoswith | 254 | .kern: |
8891 | dunkaist | 255 | push ebx ecx edx |
256 | mcall 9, procinfo,-1 |
||
257 | mov eax, [ebx+42] |
||
258 | xor edx, edx |
||
259 | mov ebx, 6 |
||
260 | div ebx |
||
261 | pop edx ecx ebx |
||
262 | mov esi, 80 |
||
263 | cmp eax, esi |
||
264 | ja @f |
||
265 | mov esi, eax |
||
2234 | mario79 | 266 | @@: |
8891 | dunkaist | 267 | cmp esi, 5 |
268 | ja @f |
||
269 | mov esi, 5 |
||
2234 | mario79 | 270 | @@: |
8891 | dunkaist | 271 | sub esi, 4 |
272 | mov eax, 4 |
||
273 | newline: |
||
274 | mcall |
||
275 | add ebx, LINE_H |
||
276 | add edx, 80 |
||
277 | cmp [edx], byte 'x' |
||
278 | jne newline |
||
279 | ret |
||
4977 | Akyltist | 280 | |
8891 | dunkaist | 281 | ;------------------------------------------------------------------------------ |
282 | ;* input: esi = pointer to the file name * |
||
283 | ;------------------------------------------------------------------------------ |
||
284 | CreateFile: |
||
285 | pusha |
||
286 | mov dword [InfoStructure+00], 2 ; create file |
||
287 | mov dword [InfoStructure+04], 0 ; reserved |
||
288 | mov dword [InfoStructure+08], 0 ; reserved |
||
289 | mov dword [InfoStructure+12], 0 ; 0 bytes to write (just create) |
||
290 | mov dword [InfoStructure+16], 0 ; NULL data pointer (no data) |
||
291 | mov dword [InfoStructure+20], 0 ; reserved |
||
292 | mov dword [InfoStructure+21], esi ; pointer to the file name |
||
293 | mcall 70, InfoStructure |
||
294 | test eax, eax |
||
295 | jz .out |
||
296 | stc |
||
297 | .out: |
||
298 | popa |
||
299 | ret |
||
300 | ;------------------------------------------------------------------------------ |
||
301 | ;* input: esi = pointer to the file name * |
||
302 | ;* edx = pointer to data buffer * |
||
303 | ;* ecx = data length * |
||
304 | ;------------------------------------------------------------------------------ |
||
305 | WriteToFile: |
||
306 | push ebx |
||
307 | mov dword [InfoStructure+00], 3 ; write to file |
||
308 | mov eax, [filepos] |
||
309 | mov dword [InfoStructure+04], eax ; lower position addr |
||
310 | mov dword [InfoStructure+08], 0 ; upper position addr (0 for FAT) |
||
311 | mov dword [InfoStructure+12], ecx ; number of bytes to write |
||
312 | mov dword [InfoStructure+16], edx ; pointer to data buffer |
||
313 | mov dword [InfoStructure+20], 0 ; reserved |
||
314 | mov dword [InfoStructure+21], esi ; pointer to the file name |
||
315 | mcall 70, InfoStructure |
||
316 | clc |
||
317 | test eax, eax |
||
318 | jz .out |
||
319 | stc |
||
320 | .out: |
||
321 | pop ebx |
||
322 | ret |
||
4672 | izikiel | 323 | |
8891 | dunkaist | 324 | ;------------------------------------------------------------------------------ |
325 | ;* input: esi = pointer to string * |
||
326 | ;* edi = pointer to string * |
||
327 | ;* ecx = data length * |
||
328 | ;------------------------------------------------------------------------------ |
||
329 | StrCmp: |
||
330 | repe cmpsb |
||
331 | ja .a_greater_b |
||
332 | jb .a_less_b |
||
333 | .equal: |
||
334 | mov eax, 0 |
||
335 | jmp .end |
||
336 | .a_less_b: |
||
337 | mov eax, 1 |
||
338 | jmp .end |
||
339 | .a_greater_b: |
||
340 | mov eax, -1 |
||
341 | .end: |
||
342 | ret |
||
4672 | izikiel | 343 | |
8891 | dunkaist | 344 | ;------------------------------------------------------------------------------ |
345 | ;* input: edi = pointer to string * |
||
346 | ;* ecx = data length * |
||
347 | ;------------------------------------------------------------------------------ |
||
348 | ; 'a' - 'A' = 32 -> 'A'|32 = 'a' |
||
349 | ToLower: |
||
350 | xor eax, eax |
||
351 | .cycle: |
||
352 | or byte[edi+eax], 32 |
||
353 | inc eax |
||
354 | loop .cycle |
||
355 | .end: |
||
356 | ret |
||
4672 | izikiel | 357 | |
8891 | dunkaist | 358 | ;------------------------------------------------------------------------------ |
359 | ;* get info on current thread, save pid/tid |
||
360 | ;* look for another process with same name and different pid/tid |
||
361 | ;* if found, close self |
||
362 | ;* else continue normally |
||
363 | ;------------------------------------------------------------------------------ |
||
364 | CheckUnique: |
||
365 | .get_thread_info: |
||
366 | mov ebx, procinfo |
||
367 | mov ecx, -1 |
||
368 | mcall 9 |
||
4672 | izikiel | 369 | |
8891 | dunkaist | 370 | .get_pid: ; check_buffer |
371 | mov [process_count], eax |
||
372 | mov eax, [ebx+process_information.PID] |
||
373 | mov [pid_tid], eax |
||
374 | mov ecx, 2 |
||
4672 | izikiel | 375 | |
8891 | dunkaist | 376 | .check_threads: |
377 | cmp ecx, [process_count] |
||
378 | ja .leave_check |
||
379 | mov eax, 9 |
||
380 | mcall |
||
4672 | izikiel | 381 | |
8891 | dunkaist | 382 | .check_slot_free: |
383 | cmp dword [ebx+process_information.slot_state], 9 |
||
384 | je .next_thread |
||
4672 | izikiel | 385 | |
8891 | dunkaist | 386 | .check_pid: |
387 | mov eax, [pid_tid] |
||
388 | cmp [ebx+process_information.PID], eax |
||
389 | je .next_thread |
||
4672 | izikiel | 390 | |
8891 | dunkaist | 391 | .get_proc_name: |
392 | lea edi, [ebx+process_information.process_name] |
||
393 | push ecx |
||
394 | mov ecx, my_name_size-1 |
||
4672 | izikiel | 395 | |
8891 | dunkaist | 396 | .lower_case: |
397 | call ToLower |
||
398 | lea esi, [my_name] |
||
399 | mov ecx, my_name_size |
||
400 | call StrCmp |
||
401 | pop ecx |
||
402 | cmp eax, 0 |
||
403 | je .close_program |
||
4672 | izikiel | 404 | |
8891 | dunkaist | 405 | .next_thread: |
406 | inc ecx |
||
407 | jmp .check_threads |
||
4672 | izikiel | 408 | |
8891 | dunkaist | 409 | .close_program: |
410 | ; restore and active window of previous thread |
||
411 | mcall 18, 3 |
||
412 | mov eax, -1 |
||
413 | mcall |
||
4672 | izikiel | 414 | |
8891 | dunkaist | 415 | .leave_check: |
416 | ret |
||
4672 | izikiel | 417 | |
8891 | dunkaist | 418 | ;------------------------------------------------------------------------------ |
5925 | pathoswith | 419 | ; DATA |
4672 | izikiel | 420 | |
8891 | dunkaist | 421 | if lang eq ru |
422 | title db 'Доска отладки и сообщений',0 |
||
423 | else if lang eq it |
||
424 | title db 'Notifiche e informazioni generiche per il debug',0 |
||
425 | else if lang eq ge |
||
426 | title db 'Allgemeines debug- & nachrichtenboard',0 |
||
427 | else |
||
428 | title db 'General debug & message board',0 |
||
429 | end if |
||
5925 | pathoswith | 430 | |
8891 | dunkaist | 431 | default_filename db '/tmp0/1/boardlog.txt',0 |
432 | krnl_msg db 'K : ' |
||
433 | duk db 'KernUser' |
||
434 | my_name db 'board',0 |
||
435 | my_name_size = $-my_name |
||
5925 | pathoswith | 436 | |
437 | align 4 |
||
8891 | dunkaist | 438 | vmode dd 1 |
439 | targ dd text2 |
||
5925 | pathoswith | 440 | |
31 | halyavin | 441 | I_END: |
5925 | pathoswith | 442 | |
8891 | dunkaist | 443 | InfoStructure: |
444 | dd ? ; subfunction number |
||
445 | dd ? ; position in the file in bytes |
||
446 | dd ? ; upper part of the position address |
||
447 | dd ? ; number of bytes to read |
||
448 | dd ? ; pointer to the buffer to write data |
||
449 | db ? |
||
450 | dd ? ; pointer to the filename |
||
5925 | pathoswith | 451 | |
8891 | dunkaist | 452 | open_log_in_tinypad: |
453 | dd 7 |
||
454 | dd 0 |
||
455 | dd filename |
||
456 | dd 0 |
||
457 | dd 0 |
||
9301 | leency | 458 | db '/sys/develop/cedit',0 |
7425 | leency | 459 | |
8891 | dunkaist | 460 | buffer_length rb 3 |
461 | process_count dd ? |
||
462 | krnl_cnt dd ? |
||
463 | pid_tid dd ? |
||
464 | filepos dd ? |
||
465 | xstart dd ? |
||
466 | sc system_colors |
||
5925 | pathoswith | 467 | |
8891 | dunkaist | 468 | rd 2 |
469 | text1 rb 80*(MAXSTRINGS+1) |
||
470 | tmp1 dd ? |
||
5925 | pathoswith | 471 | |
8891 | dunkaist | 472 | rd 2 |
473 | text2 rb 80*(MAXSTRINGS+1) |
||
474 | tmp2 dd ? |
||
5925 | pathoswith | 475 | |
8891 | dunkaist | 476 | tmp rb 256 |
477 | filename rb 256 |
||
478 | procinfo rb 1024 |
||
479 | stackbuf rb 2000h |
||
480 | mem:300,7>4,13> |