Subversion Repositories Kolibri OS

Rev

Rev 7657 | Details | Compare with Previous | Last modification | View Log | RSS feed

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