Rev 3545 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
6 | |||
7 | |||
8 | ; |
||
9 | ; Formatted Debug Output (FDO) |
||
10 | ; Copyright (c) 2005-2006, mike.dld |
||
11 | ; Created: 2005-01-29, Changed: 2006-11-10 |
||
12 | ; |
||
13 | ; For questions and bug reports, mail to mike.dld@gmail.com |
||
14 | ; |
||
15 | ; Available format specifiers are: %s, %d, %u, %x (with partial width support) |
||
16 | ; |
||
17 | |||
18 | ; to be defined: |
||
19 | ; __DEBUG__ equ 1 |
||
20 | ; __DEBUG_LEVEL__ equ 5 |
||
21 | |||
22 | macro debug_func name { |
||
23 | if used name |
||
24 | name@of@func equ name |
||
25 | } |
||
26 | |||
27 | macro debug_beginf { |
||
28 | align 4 |
||
29 | name@of@func: |
||
30 | } |
||
31 | |||
32 | debug_endf fix end if |
||
33 | |||
34 | macro DEBUGS _sign,[_str] { |
||
35 | common |
||
36 | local tp |
||
37 | tp equ 0 |
||
38 | match _arg:_num,_str \{ |
||
39 | DEBUGS_N _sign,_num,_arg |
||
40 | tp equ 1 |
||
41 | \} |
||
42 | match =0 _arg,tp _str \{ |
||
43 | DEBUGS_N _sign,,_arg |
||
44 | \} |
||
45 | } |
||
46 | |||
47 | macro DEBUGS_N _sign,_num,[_str] { |
||
48 | common |
||
49 | pushf |
||
50 | pushad |
||
51 | local ..str,..label,is_str |
||
52 | is_str = 0 |
||
53 | forward |
||
54 | if _str eqtype '' |
||
55 | is_str = 1 |
||
56 | end if |
||
57 | common |
||
58 | if is_str = 1 |
||
59 | jmp ..label |
||
60 | ..str db _str,0 |
||
61 | ..label: |
||
62 | add esp,4*8+4 |
||
63 | mov edx,..str |
||
64 | sub esp,4*8+4 |
||
65 | else |
||
66 | mov edx,_str |
||
67 | end if |
||
68 | if ~_num eq |
||
69 | if _num eqtype eax |
||
70 | if _num in |
||
71 | mov esi,_num |
||
72 | else if ~_num eq esi |
||
73 | movzx esi,_num |
||
74 | end if |
||
75 | else if _num eqtype 0 |
||
76 | mov esi,_num |
||
77 | else |
||
78 | local tp |
||
79 | tp equ 0 |
||
80 | match [_arg],_num \{ |
||
81 | mov esi,dword[_arg] |
||
82 | tp equ 1 |
||
83 | \} |
||
84 | match =0 =dword[_arg],tp _num \{ |
||
85 | mov esi,dword[_arg] |
||
86 | tp equ 1 |
||
87 | \} |
||
88 | match =0 =word[_arg],tp _num \{ |
||
89 | movzx esi,word[_arg] |
||
90 | tp equ 1 |
||
91 | \} |
||
92 | match =0 =byte[_arg],tp _num \{ |
||
93 | movzx esi,byte[_arg] |
||
94 | tp equ 1 |
||
95 | \} |
||
96 | match =0,tp \{ |
||
97 | 'Error: specified string width is incorrect' |
||
98 | \} |
||
99 | end if |
||
100 | else |
||
101 | mov esi,0x7FFFFFFF |
||
102 | end if |
||
103 | call fdo_debug_outstr |
||
104 | popad |
||
105 | popf |
||
106 | } |
||
107 | |||
108 | macro DEBUGD _sign,_dec { |
||
109 | local tp |
||
110 | tp equ 0 |
||
111 | match _arg:_num,_dec \{ |
||
112 | DEBUGD_N _sign,_num,_arg |
||
113 | tp equ 1 |
||
114 | \} |
||
115 | match =0 _arg,tp _dec \{ |
||
116 | DEBUGD_N _sign,,_arg |
||
117 | \} |
||
118 | } |
||
119 | |||
120 | macro DEBUGD_N _sign,_num,_dec { |
||
121 | pushf |
||
122 | pushad |
||
123 | if (~_num eq) |
||
124 | if (_dec eqtype eax | _dec eqtype 0) |
||
125 | 'Error: precision allowed only for in-memory variables' |
||
126 | end if |
||
127 | if (~_num in <1,2,4>) |
||
128 | if _sign |
||
129 | 'Error: 1, 2 and 4 are only allowed for precision in %d' |
||
130 | else |
||
131 | 'Error: 1, 2 and 4 are only allowed for precision in %u' |
||
132 | end if |
||
133 | end if |
||
134 | end if |
||
135 | if _dec eqtype eax |
||
136 | if _dec in |
||
137 | mov eax,_dec |
||
138 | else if ~_dec eq eax |
||
139 | if _sign = 1 |
||
140 | movsx eax,_dec |
||
141 | else |
||
142 | movzx eax,_dec |
||
143 | end if |
||
144 | end if |
||
145 | else if _dec eqtype 0 |
||
146 | mov eax,_dec |
||
147 | else |
||
148 | add esp,4*8+4 |
||
149 | if _num eq |
||
150 | mov eax,dword _dec |
||
151 | else if _num = 1 |
||
152 | if _sign = 1 |
||
153 | movsx eax,byte _dec |
||
154 | else |
||
155 | movzx eax,byte _dec |
||
156 | end if |
||
157 | else if _num = 2 |
||
158 | if _sign = 1 |
||
159 | movsx eax,word _dec |
||
160 | else |
||
161 | movzx eax,word _dec |
||
162 | end if |
||
163 | else |
||
164 | mov eax,dword _dec |
||
165 | end if |
||
166 | sub esp,4*8+4 |
||
167 | end if |
||
168 | mov cl,_sign |
||
169 | call fdo_debug_outdec |
||
170 | popad |
||
171 | popf |
||
172 | } |
||
173 | |||
174 | macro DEBUGH _sign,_hex { |
||
175 | local tp |
||
176 | tp equ 0 |
||
177 | match _arg:_num,_hex \{ |
||
178 | DEBUGH_N _sign,_num,_arg |
||
179 | tp equ 1 |
||
180 | \} |
||
181 | match =0 _arg,tp _hex \{ |
||
182 | DEBUGH_N _sign,,_arg |
||
183 | \} |
||
184 | } |
||
185 | |||
186 | macro DEBUGH_N _sign,_num,_hex { |
||
187 | pushf |
||
188 | pushad |
||
189 | if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>) |
||
190 | 'Error: 1..8 are only allowed for precision in %x' |
||
191 | end if |
||
192 | if _hex eqtype eax |
||
193 | if _hex in |
||
194 | if ~_hex eq eax |
||
195 | mov eax,_hex |
||
196 | end if |
||
197 | mov edx,8 |
||
198 | else if _hex in |
||
199 | if ~_hex eq ax |
||
200 | movzx eax,_hex |
||
201 | end if |
||
202 | if (_num eq) |
||
203 | mov edx,4 |
||
204 | end if |
||
205 | else if _hex in |
||
206 | if ~_hex eq al |
||
207 | movzx eax,_hex |
||
208 | end if |
||
209 | if (_num eq) |
||
210 | mov edx,2 |
||
211 | end if |
||
212 | end if |
||
213 | else if _hex eqtype 0 |
||
214 | mov eax,_hex |
||
215 | else |
||
216 | add esp,4*8+4 |
||
217 | mov eax,dword _hex |
||
218 | sub esp,4*8+4 |
||
219 | end if |
||
220 | if ~_num eq |
||
221 | mov edx,_num |
||
222 | else |
||
223 | if ~_hex eqtype eax |
||
224 | mov edx,8 |
||
225 | end if |
||
226 | end if |
||
227 | call fdo_debug_outhex |
||
228 | popad |
||
229 | popf |
||
230 | } |
||
231 | |||
232 | ;----------------------------------------------------------------------------- |
||
233 | |||
234 | debug_func fdo_debug_outchar |
||
235 | debug_beginf |
||
236 | pushad |
||
3614 | shikhin | 237 | movzx ecx,al |
238 | mov ebx,1 |
||
3545 | hidnplayr | 239 | ; mov ecx,sys_msg_board |
240 | ; call ecx ; sys_msg_board |
||
3614 | shikhin | 241 | stdcall SysMsgBoard |
3545 | hidnplayr | 242 | popad |
243 | ret |
||
244 | debug_endf |
||
245 | |||
246 | debug_func fdo_debug_outstr |
||
247 | debug_beginf |
||
3614 | shikhin | 248 | mov ebx,1 |
3545 | hidnplayr | 249 | .l1: dec esi |
250 | js .l2 |
||
3614 | shikhin | 251 | movzx ecx,byte[edx] |
252 | or cl,cl |
||
3545 | hidnplayr | 253 | jz .l2 |
254 | ; mov ecx,sys_msg_board |
||
255 | ; call ecx ; sys_msg_board |
||
3614 | shikhin | 256 | stdcall SysMsgBoard |
3545 | hidnplayr | 257 | inc edx |
258 | jmp .l1 |
||
259 | .l2: ret |
||
260 | debug_endf |
||
261 | |||
262 | debug_func fdo_debug_outdec |
||
263 | debug_beginf |
||
264 | or cl,cl |
||
265 | jz @f |
||
266 | or eax,eax |
||
267 | jns @f |
||
268 | neg eax |
||
269 | push eax |
||
270 | mov al,'-' |
||
271 | call fdo_debug_outchar |
||
272 | pop eax |
||
273 | @@: push 10 |
||
274 | pop ecx |
||
275 | push -'0' |
||
276 | .l1: xor edx,edx |
||
277 | div ecx |
||
278 | push edx |
||
279 | test eax,eax |
||
280 | jnz .l1 |
||
281 | .l2: pop eax |
||
282 | add al,'0' |
||
283 | jz .l3 |
||
284 | call fdo_debug_outchar |
||
285 | jmp .l2 |
||
286 | .l3: ret |
||
287 | debug_endf |
||
288 | |||
289 | debug_func fdo_debug_outhex |
||
290 | __fdo_hexdigits db '0123456789ABCDEF' |
||
291 | debug_beginf |
||
292 | mov cl,dl |
||
293 | neg cl |
||
294 | add cl,8 |
||
295 | shl cl,2 |
||
296 | rol eax,cl |
||
297 | .l1: rol eax,4 |
||
298 | push eax |
||
299 | and eax,0x0000000F |
||
300 | mov al,[__fdo_hexdigits+eax] |
||
301 | call fdo_debug_outchar |
||
302 | pop eax |
||
303 | dec edx |
||
304 | jnz .l1 |
||
305 | ret |
||
306 | debug_endf |
||
307 | |||
308 | ;----------------------------------------------------------------------------- |
||
309 | |||
310 | macro DEBUGF _level,_format,[_arg] { |
||
311 | common |
||
312 | if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__ |
||
313 | local ..f1,f2,a1,a2,c1,c2,c3,..lbl |
||
314 | _debug_str_ equ __debug_str_ # a1 |
||
315 | a1 = 0 |
||
316 | c2 = 0 |
||
317 | c3 = 0 |
||
318 | f2 = 0 |
||
319 | repeat ..lbl-..f1 |
||
320 | virtual at 0 |
||
321 | db _format,0,0 |
||
322 | load c1 word from %-1 |
||
323 | end virtual |
||
324 | if c1 = '%s' |
||
325 | virtual at 0 |
||
326 | db _format,0,0 |
||
327 | store word 0 at %-1 |
||
328 | load c1 from f2-c2 |
||
329 | end virtual |
||
330 | if c1 <> 0 |
||
331 | DEBUGS 0,_debug_str_+f2-c2 |
||
332 | end if |
||
333 | c2 = c2 + 1 |
||
334 | f2 = %+1 |
||
335 | DEBUGF_HELPER S,a1,0,_arg |
||
336 | else if c1 = '%x' |
||
337 | virtual at 0 |
||
338 | db _format,0,0 |
||
339 | store word 0 at %-1 |
||
340 | load c1 from f2-c2 |
||
341 | end virtual |
||
342 | if c1 <> 0 |
||
343 | DEBUGS 0,_debug_str_+f2-c2 |
||
344 | end if |
||
345 | c2 = c2 + 1 |
||
346 | f2 = %+1 |
||
347 | DEBUGF_HELPER H,a1,0,_arg |
||
348 | else if c1 = '%d' | c1 = '%u' |
||
349 | local c4 |
||
350 | if c1 = '%d' |
||
351 | c4 = 1 |
||
352 | else |
||
353 | c4 = 0 |
||
354 | end if |
||
355 | virtual at 0 |
||
356 | db _format,0,0 |
||
357 | store word 0 at %-1 |
||
358 | load c1 from f2-c2 |
||
359 | end virtual |
||
360 | if c1 <> 0 |
||
361 | DEBUGS 0,_debug_str_+f2-c2 |
||
362 | end if |
||
363 | c2 = c2 + 1 |
||
364 | f2 = %+1 |
||
365 | DEBUGF_HELPER D,a1,c4,_arg |
||
366 | else if c1 = '\n' |
||
367 | c3 = c3 + 1 |
||
368 | end if |
||
369 | end repeat |
||
370 | virtual at 0 |
||
371 | db _format,0,0 |
||
372 | load c1 from f2-c2 |
||
373 | end virtual |
||
374 | if (c1<>0)&(f2<>..lbl-..f1-1) |
||
375 | DEBUGS 0,_debug_str_+f2-c2 |
||
376 | end if |
||
377 | virtual at 0 |
||
378 | ..f1 db _format,0 |
||
379 | ..lbl: |
||
380 | __debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3 |
||
381 | end virtual |
||
382 | end if |
||
383 | } |
||
384 | |||
385 | macro __include_debug_strings dummy,[_id,_fmt,_len] { |
||
386 | common |
||
387 | local c1,a1,a2 |
||
388 | forward |
||
389 | if defined _len & ~_len eq |
||
390 | _id: |
||
391 | a1 = 0 |
||
392 | a2 = 0 |
||
393 | repeat _len |
||
394 | virtual at 0 |
||
395 | db _fmt,0,0 |
||
396 | load c1 word from %+a2-1 |
||
397 | end virtual |
||
398 | if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u') |
||
399 | db 0 |
||
400 | a2 = a2 + 1 |
||
401 | else if (c1='\n') |
||
402 | dw $0A0D |
||
403 | a1 = a1 + 1 |
||
404 | a2 = a2 + 1 |
||
405 | else |
||
406 | db c1 and 0x0FF |
||
407 | end if |
||
408 | end repeat |
||
409 | db 0 |
||
410 | end if |
||
411 | } |
||
412 | |||
413 | macro DEBUGF_HELPER _letter,_num,_sign,[_arg] { |
||
414 | common |
||
415 | local num |
||
416 | num = 0 |
||
417 | forward |
||
418 | if num = _num |
||
419 | DEBUG#_letter _sign,_arg |
||
420 | end if |
||
421 | num = num+1 |
||
422 | common |
||
423 | _num = _num+1 |
||
424 | } |
||
425 | |||
426 | macro include_debug_strings { |
||
427 | if __DEBUG__ = 1 |
||
428 | match dbg_str,__debug_strings \{ |
||
429 | __include_debug_strings dbg_str |
||
430 | \} |
||
431 | end if |
||
432 | }>>>>>1,2,3,4,5,6,7,8>1,2,4> |