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