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