Subversion Repositories Kolibri OS

Rev

Rev 3618 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3618 hidnplayr 1
;
2
; Formatted Debug Output (FDO)
3
; Copyright (c) 2005-2006, mike.dld
4
; Created: 2005-01-29, Changed: 2006-11-10
5
;
6
; For questions and bug reports, mail to mike.dld@gmail.com
7
;
8
; Available format specifiers are: %s, %d, %u, %x (with partial width support)
9
;
10
 
11
; to be defined:
12
;   __DEBUG__ equ 1
13
;   __DEBUG_LEVEL__ equ 5
14
 
15
macro debug_func name {
16
 if used name
17
  name@of@func equ name
18
}
19
 
20
macro debug_beginf {
21
 align 4
22
 name@of@func:
23
}
24
 
25
debug_endf fix end if
26
 
27
macro DEBUGS _sign,[_str] {
28
 common
29
  local tp
30
  tp equ 0
31
  match _arg:_num,_str \{
32
   DEBUGS_N _sign,_num,_arg
33
   tp equ 1
34
  \}
35
  match =0 _arg,tp _str \{
36
   DEBUGS_N _sign,,_arg
37
  \}
38
}
39
 
40
macro DEBUGS_N _sign,_num,[_str] {
41
 common
42
  pushf
43
  pushad
44
  local ..str,..label,is_str
45
  is_str = 0
46
 forward
47
  if _str eqtype ''
48
   is_str = 1
49
  end if
50
 common
51
  if is_str = 1
52
   jmp ..label
53
   ..str db _str,0
54
   ..label:
55
   add  esp,4*8+4
56
   mov  edx,..str
57
   sub  esp,4*8+4
58
  else
59
   mov  edx,_str
60
  end if
61
  if ~_num eq
62
   if _num eqtype eax
63
    if _num in 
64
     mov esi,_num
65
    else if ~_num eq esi
66
     movzx esi,_num
67
    end if
68
   else if _num eqtype 0
69
    mov esi,_num
70
   else
71
    local tp
72
    tp equ 0
73
    match [_arg],_num \{
74
     mov esi,dword[_arg]
75
     tp equ 1
76
    \}
77
    match =0 =dword[_arg],tp _num \{
78
     mov esi,dword[_arg]
79
     tp equ 1
80
    \}
81
    match =0 =word[_arg],tp _num \{
82
     movzx esi,word[_arg]
83
     tp equ 1
84
    \}
85
    match =0 =byte[_arg],tp _num \{
86
     movzx esi,byte[_arg]
87
     tp equ 1
88
    \}
89
    match =0,tp \{
90
     'Error: specified string width is incorrect'
91
    \}
92
   end if
93
  else
94
   mov esi,0x7FFFFFFF
95
  end if
96
  call fdo_debug_outstr
97
  popad
98
  popf
99
}
100
 
101
macro DEBUGD _sign,_dec {
102
 local tp
103
 tp equ 0
104
 match _arg:_num,_dec \{
105
  DEBUGD_N _sign,_num,_arg
106
  tp equ 1
107
 \}
108
 match =0 _arg,tp _dec \{
109
  DEBUGD_N _sign,,_arg
110
 \}
111
}
112
 
113
macro DEBUGD_N _sign,_num,_dec {
114
 pushf
115
 pushad
116
 if (~_num eq)
117
  if (_dec eqtype eax | _dec eqtype 0)
118
   'Error: precision allowed only for in-memory variables'
119
  end if
120
  if (~_num in <1,2,4>)
121
   if _sign
122
    'Error: 1, 2 and 4 are only allowed for precision in %d'
123
   else
124
    'Error: 1, 2 and 4 are only allowed for precision in %u'
125
   end if
126
  end if
127
 end if
128
 if _dec eqtype eax
129
  if _dec in 
130
   mov eax,_dec
131
  else if ~_dec eq eax
132
   if _sign = 1
133
    movsx eax,_dec
134
   else
135
    movzx eax,_dec
136
   end if
137
  end if
138
 else if _dec eqtype 0
139
  mov eax,_dec
140
 else
141
  add esp,4*8+4
142
  if _num eq
143
   mov eax,dword _dec
144
  else if _num = 1
145
   if _sign = 1
146
    movsx eax,byte _dec
147
   else
148
    movzx eax,byte _dec
149
   end if
150
  else if _num = 2
151
   if _sign = 1
152
    movsx eax,word _dec
153
   else
154
    movzx eax,word _dec
155
   end if
156
  else
157
   mov eax,dword _dec
158
  end if
159
  sub esp,4*8+4
160
 end if
161
 mov cl,_sign
162
 call fdo_debug_outdec
163
 popad
164
 popf
165
}
166
 
167
macro DEBUGH _sign,_hex {
168
 local tp
169
 tp equ 0
170
 match _arg:_num,_hex \{
171
  DEBUGH_N _sign,_num,_arg
172
  tp equ 1
173
 \}
174
 match =0 _arg,tp _hex \{
175
  DEBUGH_N _sign,,_arg
176
 \}
177
}
178
 
179
macro DEBUGH_N _sign,_num,_hex {
180
 pushf
181
 pushad
182
 if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>)
183
  'Error: 1..8 are only allowed for precision in %x'
184
 end if
185
 if _hex eqtype eax
186
  if _hex in 
187
   if ~_hex eq eax
188
    mov eax,_hex
189
   end if
190
  else if _hex in 
191
   if ~_hex eq ax
192
    movzx eax,_hex
193
   end if
194
   shl eax,16
195
   if (_num eq)
196
    mov edx,4
197
   end if
198
  else if _hex in 
199
   if ~_hex eq al
200
    movzx eax,_hex
201
   end if
202
   shl eax,24
203
   if (_num eq)
204
    mov edx,2
205
   end if
206
  end if
207
 else if _hex eqtype 0
208
  mov eax,_hex
209
 else
210
  add esp,4*8+4
211
  mov eax,dword _hex
212
  sub esp,4*8+4
213
 end if
214
 if ~_num eq
215
  mov edx,_num
216
 else
217
  mov edx,8
218
 end if
219
 call fdo_debug_outhex
220
 popad
221
 popf
222
}
223
 
224
;-----------------------------------------------------------------------------
225
 
226
debug_func fdo_debug_outchar
227
debug_beginf
228
        pushad
229
        mov     cl,al
230
        mov     ebx,1
231
        mov     eax,63
232
        mcall
233
        popad
234
        ret
235
debug_endf
236
 
237
debug_func fdo_debug_outstr
238
debug_beginf
239
        mov     eax,63
240
        mov     ebx,1
241
  .l1:  dec     esi
242
        js      .l2
243
        mov     cl,[edx]
244
        or      cl,cl
245
        jz      .l2
246
        mcall
247
        inc     edx
248
        jmp     .l1
249
  .l2:  ret
250
debug_endf
251
 
252
debug_func fdo_debug_outdec
253
debug_beginf
254
        or      cl,cl
255
        jz      @f
256
        or      eax,eax
257
        jns     @f
258
        neg     eax
259
        push    eax
260
        mov     al,'-'
261
        call    fdo_debug_outchar
262
        pop     eax
263
    @@: push    10
264
        pop     ecx
265
        push    -'0'
266
  .l1:  xor     edx,edx
267
        div     ecx
268
        push    edx
269
        test    eax,eax
270
        jnz     .l1
271
  .l2:  pop     eax
272
        add     al,'0'
273
        jz      .l3
274
        call    fdo_debug_outchar
275
        jmp     .l2
276
  .l3:  ret
277
debug_endf
278
 
279
debug_func fdo_debug_outhex
280
  __fdo_hexdigits db '0123456789ABCDEF'
281
debug_beginf
282
        mov     cl,dl
283
        neg     cl
284
        add     cl,8
285
        shl     cl,2
286
        rol     eax,cl
287
  .l1:  rol     eax,4
288
        push    eax
289
        and     eax,0x0000000F
290