|
0
|
1 |
.include "DS.S"
|
|
|
2 |
#-----------------------------------------------
|
|
|
3 |
# A B S T R A C T S T R U C T U R E S
|
|
|
4 |
#-----------------------------------------------
|
|
|
5 |
#-----------------------------------------------
|
|
|
6 |
# S T A T I C V A R I A B L E S
|
|
|
7 |
#-----------------------------------------------
|
|
|
8 |
.data
|
|
|
9 |
D.t0: .int 0 # initial timestamp in usecs
|
|
|
10 |
D.semP: .int 0 # -->semaphore for debug output
|
|
|
11 |
.globl D.prgNameP
|
|
|
12 |
D.prgNameP:
|
|
|
13 |
.int 0 # -->prog name
|
|
|
14 |
#-----------------------------------------------
|
|
|
15 |
# D E B U G I N I T
|
|
|
16 |
#-----------------------------------------------
|
|
|
17 |
# initialize static debug vars
|
|
|
18 |
ARGS
|
|
|
19 |
DS prgP # -->program name
|
|
|
20 |
# returns: nothing
|
|
|
21 |
PROLOC
|
|
|
22 |
EPILOC
|
|
|
23 |
#-----------------------------------------------
|
|
|
24 |
.text
|
|
|
25 |
.global D.init
|
|
|
26 |
D.init:
|
|
|
27 |
PROLOG
|
|
|
28 |
push prgP(bp)
|
|
|
29 |
call strlen
|
|
|
30 |
inc a
|
|
|
31 |
push a
|
|
|
32 |
call malloc
|
|
|
33 |
mov a, D.prgNameP # save -->prog name for debugging
|
|
|
34 |
push prgP(bp)
|
|
|
35 |
push a
|
|
|
36 |
call strcpy
|
|
|
37 |
movl $0, D.t0
|
|
|
38 |
call D.getTs # get actual time - t0 = actual time
|
|
|
39 |
mov a, D.t0 # set t0 to actual time
|
|
|
40 |
|
|
|
41 |
jmp 3f
|
|
|
42 |
push $0
|
|
|
43 |
push $t
|
|
|
44 |
call gettimeofday # get initial timestamp t0
|
|
|
45 |
cmp $0, a
|
|
|
46 |
jz 0f
|
|
|
47 |
ERR "gettimeofday"
|
|
|
48 |
0: lea t, b # compute (1000000*secs+usecs)
|
|
|
49 |
mov secs(b), c
|
|
|
50 |
mov $1000000, a
|
|
|
51 |
mul c # 1000000*secs
|
|
|
52 |
add usecs(b), a # 1000000*secs+usecs
|
|
|
53 |
movl a, D.t0 # save low 32 bits of timestamp in t0
|
|
|
54 |
3:
|
|
|
55 |
push $0 # allocate semaphore for debug output
|
|
|
56 |
push $-1
|
|
|
57 |
push $0x21 # PROT_READ | PROT_WRITE
|
|
|
58 |
push $0x03 # MAP_SHARED | MAP_ANONYMOUS
|
|
|
59 |
push $16 # semaphore size
|
|
|
60 |
push $0
|
|
|
61 |
call mmap # get shared storage for semaphore
|
|
|
62 |
cmp $-1, a
|
|
|
63 |
jne 0f
|
|
|
64 |
ERR "mmap"
|
|
|
65 |
0: mov a, D.semP # save -->semaphore
|
|
|
66 |
|
|
|
67 |
push $1 # initial semaphore value
|
|
|
68 |
push $1 # semaphore shared between processes
|
|
|
69 |
pushl D.semP
|
|
|
70 |
call sem_init # initialize semaphore
|
|
|
71 |
cmp $0, a
|
|
|
72 |
jz 0f
|
|
|
73 |
ERR "sem_init of debug semaphore"
|
|
|
74 |
0:
|
|
|
75 |
EPILOG
|
|
|
76 |
#-----------------------------------------------
|
|
|
77 |
# S E T D E B U G I D
|
|
|
78 |
#-----------------------------------------------
|
|
|
79 |
# sets debug ID according to format
|
|
|
80 |
ARGS
|
|
|
81 |
DS deP # -->Debug instance
|
|
|
82 |
DS argc # # of values to be put into deb ID
|
|
|
83 |
DS formP # -->format
|
|
|
84 |
# ... # values
|
|
|
85 |
# returns: nothing
|
|
|
86 |
PROLOC
|
|
|
87 |
EPILOC
|
|
|
88 |
#-----------------------------------------------
|
|
|
89 |
.global D.setId
|
|
|
90 |
D.setId:
|
|
|
91 |
PROLOG
|
|
|
92 |
# format debug ID
|
|
|
93 |
mov argc(bp), c # no. of values
|
|
|
94 |
0: mov formP(bp,c,4), a # push values and format
|
|
|
95 |
push a
|
|
|
96 |
dec c
|
|
|
97 |
jns 0b # iterate on values
|
|
|
98 |
pushl $D.idL # max deb ID len
|
|
|
99 |
mov deP(bp), b # -->Debug instance
|
|
|
100 |
lea D.id(b), a # -->DebId
|
|
|
101 |
push a
|
|
|
102 |
call snprintf # construct DebId
|
|
|
103 |
cmp $0, a
|
|
|
104 |
jnl 0f
|
|
|
105 |
ERR "DEBID snprintf"
|
|
|
106 |
0:
|
|
|
107 |
LOG 6, "debid '%s' set", 1
|
|
|
108 |
EPILOG
|
|
|
109 |
#-----------------------------------------------
|
|
|
110 |
# P R I N T D E B U G M S G
|
|
|
111 |
#-----------------------------------------------
|
|
|
112 |
# outputs to stderr the synchronized debug msg with time diff from program start
|
|
|
113 |
# on appripriate debug level, flushes stderr
|
|
|
114 |
ARGS
|
|
|
115 |
ac = 40
|
|
|
116 |
DS deP # -->Debug instance
|
|
|
117 |
DS level # msg debug level
|
|
|
118 |
DS argc # # of values to be used in msg
|
|
|
119 |
DS form # -->format
|
|
|
120 |
# ... # values
|
|
|
121 |
# returns: nothing
|
|
|
122 |
PROLOC
|
|
|
123 |
ac = 0
|
|
|
124 |
EPILOC
|
|
|
125 |
#-----------------------------------------------
|
|
|
126 |
.global D.log
|
|
|
127 |
D.log:
|
|
|
128 |
PROLOG
|
|
|
129 |
|
|
|
130 |
mov C.csP, c
|
|
|
131 |
mov level(bp), a # msg debug level
|
|
|
132 |
cmp C.debMaxLev(c), a # max debug level >= msg debug level ?
|
|
|
133 |
jg 3f # nothing to print, leave
|
|
|
134 |
cmp $7, C.debMaxLev(c) # on max debug level = 7 print level 7 only
|
|
|
135 |
jne 0f
|
|
|
136 |
cmp $7, a # msg debug level = 7 ?
|
|
|
137 |
jne 3f
|
|
|
138 |
# prepare output string of msg
|
|
|
139 |
0: mov argc(bp), c # no. of values
|
|
|
140 |
0: mov form(bp,c,4), a # copy values and format
|
|
|
141 |
push a
|
|
|
142 |
dec c
|
|
|
143 |
jns 0b
|
|
|
144 |
push $D.msgL # msg buffer len
|
|
|
145 |
mov deP(bp), b # -->Debug instance
|
|
|
146 |
lea D.msg(b), a # -->msg buffer
|
|
|
147 |
push a
|
|
|
148 |
call snprintf # construct msg in buffer
|
|
|
149 |
cmp $0, a
|
|
|
150 |
jnl 0f
|
|
|
151 |
ERR "LOG snprintf"
|
|
|
152 |
# synchronize with other tasks
|
|
|
153 |
0: pushl D.semP
|
|
|
154 |
call sem_wait # synchronize
|
|
|
155 |
cmp $0, a
|
|
|
156 |
jz 0f
|
|
|
157 |
ERR "LOG sem_wait"
|
|
|
158 |
# get timestamp
|
|
|
159 |
0: call D.getTs # time from beg of program in usecs
|
|
|
160 |
# print debug msg
|
|
|
161 |
mov deP(bp), b # -->Debug instance
|
|
|
162 |
lea D.msg(b), c # -->msg text
|
|
|
163 |
push c
|
|
|
164 |
lea D.id(b), c # -->instance debug ID
|
|
|
165 |
push c
|
|
|
166 |
push a # tdiff in usecs
|
|
|
167 |
push $1f
|
|
|
168 |
push stderr
|
|
|
169 |
call fprintf
|
|
|
170 |
jmp 2f
|
|
|
171 |
1: .ascii "%09u %s: %s\n\0"
|
|
|
172 |
# flush stderr
|
|
|
173 |
2: push stderr
|
|
|
174 |
call fflush # flush stderr
|
|
|
175 |
# free semaphore
|
|
|
176 |
pushl D.semP
|
|
|
177 |
call sem_post # free semaphore
|
|
|
178 |
cmp $0, a
|
|
|
179 |
jz 3f
|
|
|
180 |
ERR "LOG sem_post"
|
|
|
181 |
3:
|
|
|
182 |
EPILOG
|
|
|
183 |
#-----------------------------------------------
|
|
|
184 |
# G E T T I M E S T A M P I N U S E C S
|
|
|
185 |
#-----------------------------------------------
|
|
|
186 |
# returns timestamp in usecs from beg of program
|
|
|
187 |
# returns: int value
|
|
|
188 |
PROLOC
|
|
|
189 |
DL t, timevalL # timestamp buffer
|
|
|
190 |
EPILOC
|
|
|
191 |
#-----------------------------------------------
|
|
|
192 |
.global D.getTs
|
|
|
193 |
D.getTs:
|
|
|
194 |
PROLOG
|
|
|
195 |
push $0
|
|
|
196 |
lea t(bp), b # -->timeval buffer
|
|
|
197 |
push b
|
|
|
198 |
call gettimeofday
|
|
|
199 |
# compute time delta from program start = t-t0 in usecs
|
|
|
200 |
# tdiff = (1000000*ts.secs+ts.usecs)-t0
|
|
|
201 |
lea t(bp), b # actual timestamp
|
|
|
202 |
mov secs(b), c # t.secs
|
|
|
203 |
mov $1000000, a
|
|
|
204 |
mul c # 1000000*t.secs
|
|
|
205 |
add usecs(b), a # 1000000*t.secs+t.usecs
|
|
|
206 |
sub D.t0, a # 1000000*t.secs+t.usecs-t0
|
|
|
207 |
EPILOG_R
|
|
|
208 |
#-----------------------------------------------
|
|
|
209 |
# S U B R O U T I N E S L I S T
|
|
|
210 |
#-----------------------------------------------
|
|
|
211 |
# print subroutines names and addresses
|
|
|
212 |
# localize address from env ADDR= in subroutine
|
|
|
213 |
PROLOC
|
|
|
214 |
DL wAddr # wanted addr
|
|
|
215 |
EPILOC
|
|
|
216 |
#-----------------------------------------------
|
|
|
217 |
.global D.subr
|
|
|
218 |
D.subr:
|
|
|
219 |
PROLOG
|
|
|
220 |
movl $0, wAddr(bp)
|
|
|
221 |
pushl $0f
|
|
|
222 |
call getenv # get env ADDR
|
|
|
223 |
lea 4(sp), sp
|
|
|
224 |
jmp 1f
|
|
|
225 |
0: .ascii "ADDR\0"
|
|
|
226 |
1: cmp $0, a
|
|
|
227 |
jz 0f # no addr wanted
|
|
|
228 |
pushl $16
|
|
|
229 |
pushl $0
|
|
|
230 |
push a
|
|
|
231 |
call strtol # convert str to hex
|
|
|
232 |
lea 12(sp), sp
|
|
|
233 |
mov a, wAddr(bp) # searched addr
|
|
|
234 |
0:
|
|
|
235 |
pushl $0 # end of list
|
|
|
236 |
SUBRLIST # print and push list of subroutines
|
|
|
237 |
cmp $0, wAddr(bp) # address wanted ?
|
|
|
238 |
je D.subrR
|
|
|
239 |
mov wAddr(bp), d
|
|
|
240 |
mov sp, b # -->beg of subr list
|
|
|
241 |
xor a, a
|
|
|
242 |
jmp 1f
|
|
|
243 |
0: lea 8(b), b
|
|
|
244 |
1: cmpl $0, (b) # end of list ?
|
|
|
245 |
je 2f # yes
|
|
|
246 |
cmp 4(b), d # -->subr > wanted addr ?
|
|
|
247 |
jb 0b # yes, next
|
|
|
248 |
cmp 4(b), a # -->subr > last found ?
|
|
|
249 |
jnb 0b # no, next
|
|
|
250 |
mov (b), c # get subr name
|
|
|
251 |
mov 4(b), a # get subr addr
|
|
|
252 |
jmp 0b # next
|
|
|
253 |
2: test a, a
|
|
|
254 |
jnz 1f
|
|
|
255 |
push d
|
|
|
256 |
push $0f
|
|
|
257 |
push stderr
|
|
|
258 |
call fprintf
|
|
|
259 |
jmp D.subrR
|
|
|
260 |
0: .ascii "addr %p not found in subroutines\n\0"
|
|
|
261 |
1: sub a, d
|
|
|
262 |
push d # offset in subr
|
|
|
263 |
push c # subroutine name
|
|
|
264 |
pushl wAddr(bp) # wanted addr
|
|
|
265 |
push $0f
|
|
|
266 |
push stderr
|
|
|
267 |
call fprintf
|
|
|
268 |
jmp D.subrR
|
|
|
269 |
0: .ascii "searched addr %p in subroutine %s at offset %x\n\0"
|
|
|
270 |
D.subrR:
|
|
|
271 |
EPILOG
|
|
|
272 |
#-----------------------------------------------
|
|
|
273 |
.end
|