|
1 .equ a, %eax |
|
2 .equ b, %ebx |
|
3 .equ c, %ecx |
|
4 .equ d, %edx |
|
5 .equ bp, %ebp |
|
6 .equ sp, %esp |
|
7 .equ di, %edi |
|
8 #----------------------------------------------- |
|
9 # M A C R O D E C L A R A T I O N S |
|
10 #----------------------------------------------- |
|
11 # subroutines list |
|
12 .macro SUBRLIST |
|
13 SUBR _start |
|
14 SUBR D.init |
|
15 SUBR D.setId |
|
16 SUBR D.log |
|
17 SUBR D.getTs |
|
18 SUBR D.subr |
|
19 SUBR Node |
|
20 SUBR N.bind |
|
21 SUBR N.conn |
|
22 SUBR N.acc |
|
23 SUBR N.closeSocket |
|
24 SUBR N.read |
|
25 SUBR N.write |
|
26 SUBR N.get |
|
27 SUBR N.put |
|
28 SUBR N.sslErr |
|
29 SUBR Data |
|
30 SUBR Da.load |
|
31 SUBR Da.chk |
|
32 SUBR Da.unl |
|
33 SUBR Da.dttl |
|
34 SUBR Da.ttl |
|
35 SUBR Da.getTs |
|
36 .endm |
|
37 #----------------------------------------------- |
|
38 # push subroutine addr, prints its name and addr |
|
39 # leave subr name and addr on stack |
|
40 .macro SUBR subr:req |
|
41 push $\subr |
|
42 push $9f |
|
43 push $8f |
|
44 push stderr |
|
45 call fprintf |
|
46 jmp 7f |
|
47 9: .asciz "\subr" |
|
48 8: .asciz "%-12s\t%p\n" |
|
49 7: lea 8(sp), sp |
|
50 .endm |
|
51 #----------------------------------------------- |
|
52 # prepare to define subroutine args; use macro DS to define args |
|
53 .macro ARGS |
|
54 ac = 40 |
|
55 .endm |
|
56 #----------------------------------------------- |
|
57 # prepare to define subroutine args; use macro DS to define args |
|
58 .macro M_ARGS |
|
59 ac = 40 |
|
60 DS thisP |
|
61 .endm |
|
62 #----------------------------------------------- |
|
63 # declare storage |
|
64 .macro DS id:req, len=4 |
|
65 \id = ac |
|
66 ac = ac + \len |
|
67 .endm |
|
68 #----------------------------------------------- |
|
69 # prepare to define subroutine local vars |
|
70 .macro PROLOC |
|
71 ac = 0 |
|
72 .endm |
|
73 #----------------------------------------------- |
|
74 # prepare to define subroutine local vars |
|
75 .macro M_LOCAL |
|
76 ac = 0 |
|
77 DL deP |
|
78 .endm |
|
79 #----------------------------------------------- |
|
80 # declare local var |
|
81 .macro DL id:req, len=4 |
|
82 ac = ac + \len |
|
83 \id = -ac |
|
84 .endm |
|
85 #----------------------------------------------- |
|
86 # terminate subroutine local vars definition |
|
87 .macro EPILOC |
|
88 locL = ac |
|
89 .endm |
|
90 #----------------------------------------------- |
|
91 # subroutine prolog |
|
92 # expects length of local storage under the name "locL" |
|
93 .macro PROLOG |
|
94 pusha |
|
95 enter $locL, $0 |
|
96 .endm |
|
97 #----------------------------------------------- |
|
98 # subroutine prolog |
|
99 # expects length of local storage under the name "locL" |
|
100 .altmacro |
|
101 .macro M_PROLOG m_prefix:req, m_name:req |
|
102 .global \m_prefix\().\m_name |
|
103 \m_prefix\().\m_name: |
|
104 pusha |
|
105 enter $ac, $0 |
|
106 mov thisP(bp), b |
|
107 lea \m_prefix\().debug(b), a |
|
108 mov a, deP(bp) |
|
109 .endm |
|
110 .noaltmacro |
|
111 #----------------------------------------------- |
|
112 # subroutine epilog without return value |
|
113 .macro EPILOG |
|
114 leave |
|
115 popa |
|
116 ret |
|
117 .endm |
|
118 #----------------------------------------------- |
|
119 # subroutine epilog with return value in EAX |
|
120 # expects length of local storage under the name "locL" |
|
121 .macro EPILOG_R |
|
122 leave |
|
123 mov a, 28(sp) |
|
124 popa |
|
125 ret |
|
126 # mov -36(sp), a |
|
127 .endm |
|
128 #----------------------------------------------- |
|
129 # ABEND at system routine err |
|
130 .macro ERR causer:req |
|
131 pushl $9f |
|
132 call printf |
|
133 pushl $1 |
|
134 call exit |
|
135 9: .asciz "\causer: %m\n" |
|
136 .endm |
|
137 #----------------------------------------------- |
|
138 # ABEND at system routine err using debug structure |
|
139 # expects deP(bp)-->Debug inst |
|
140 .macro SYSERR causer:req |
|
141 push $9f # -->format |
|
142 push $0 # no. of values |
|
143 push $0 # msg debug level |
|
144 pushl deP(bp) # -->Debug instance |
|
145 call D.log # print msg |
|
146 call C.abend |
|
147 9: .asciz "\causer: %m" |
|
148 .endm |
|
149 #----------------------------------------------- |
|
150 # print SSL err msg queue and then abend |
|
151 # -->Debug in deP(bp) is expected |
|
152 .macro SSLERR msg:req |
|
153 pushl $9f |
|
154 pushl deP(bp) |
|
155 call N.sslErr |
|
156 9: .asciz "\msg" |
|
157 .endm |
|
158 #----------------------------------------------------------- |
|
159 .macro SYS name:req |
|
160 call \name |
|
161 cmp $-1, a |
|
162 jne 8f |
|
163 SYSERR "\name" |
|
164 8: mov thisP(bp), b |
|
165 test a, a |
|
166 .endm |
|
167 #----------------------------------------------- |
|
168 # get integer value from ENV |
|
169 .macro GETINTENV key:req |
|
170 pushl $9f |
|
171 call C.getArg |
|
172 lea 4(sp), sp |
|
173 cmp $0, a |
|
174 jmp 8f |
|
175 9: .asciz "\key" |
|
176 8: |
|
177 .endm |
|
178 #----------------------------------------------- |
|
179 # set local debug ID |
|
180 # supposed: local deP-->Debug |
|
181 # expected on the stack: |
|
182 # \argc values to be put in debug ID according to format |
|
183 # \argc may be zero |
|
184 .macro DEBID format:req, argc=0 |
|
185 push $9f # -->format |
|
186 push $\argc # no. of values |
|
187 pushl deP(bp) # -->Debug instance |
|
188 call D.setId # put debug ID to Debug inst |
|
189 jmp 8f |
|
190 9: .asciz "\format" |
|
191 8: lea 12(sp), sp |
|
192 .endm |
|
193 #----------------------------------------------- |
|
194 # debug output |
|
195 # supposed: local deP-->Debug |
|
196 # expected on the stack: |
|
197 # \argc values to be printed by \format at debug level \level |
|
198 # \argc may be zero |
|
199 # all regs are preserved |
|
200 .macro LOG level:req, format:req, argc=7 |
|
201 push $9f # -->format |
|
202 push $\argc # no. of values |
|
203 push $\level # msg debug level |
|
204 pushl deP(bp) # -->Debug instance |
|
205 call D.log # print msg |
|
206 jmp 8f |
|
207 9: .asciz "\format" |
|
208 8: lea 16(sp), sp |
|
209 .endm |
|
210 #----------------------------------------------- |
|
211 # flat print |
|
212 # sp, bp are preserved |
|
213 .macro PR format:req |
|
214 push $9f |
|
215 push stderr |
|
216 call fprintf |
|
217 jmp 8f |
|
218 9: .asciz ">>> \format\n" |
|
219 8: lea 8(sp), sp |
|
220 .endm |
|
221 #----------------------------------------------- |
|
222 # print ip, bp, sp before subroutine call |
|
223 # to be placed directly before a call instruction |
|
224 # expected deP(bp) as -->Debug |
|
225 # all regs are preserved |
|
226 .macro B_CALL level:req, label="BEFORE SUBR CALL " |
|
227 push a |
|
228 lea 4(sp), a |
|
229 push a |
|
230 push bp |
|
231 pushl $7f+5 |
|
232 LOG \level, "\label: ip: %p, bp: %p, sp: %p", 3 |
|
233 lea 12(sp), sp |
|
234 pop a |
|
235 jmp 7f |
|
236 7: |
|
237 .endm |
|
238 #----------------------------------------------- |
|
239 # print ip, bp, sp saved in sburoutine's stack frame |
|
240 # to be placed anywhere before return seq and after deP(bp) is set |
|
241 # expected deP(bp) as -->Debug |
|
242 # all regs are preserved |
|
243 .macro B_RET level:req, label="BEFORE SUBR RETURN" |
|
244 push a |
|
245 lea 8(bp), a |
|
246 push a |
|
247 push (bp) |
|
248 push 4(bp) |
|
249 LOG \level, "\label: ip: %p, bp: %p, sp: %p", 3 |
|
250 lea 12(sp), sp |
|
251 pop a |
|
252 jmp 7f |
|
253 7: |
|
254 .endm |
|
255 #----------------------------------------------- |
|
256 # print ip, bp, sp retained for return from sburoutine |
|
257 # all regs are preserved |
|
258 .macro A_CALL label="AFTER CALL" |
|
259 pusha |
|
260 lea 8(bp), a |
|
261 push a |
|
262 push (bp) |
|
263 push 4(bp) |
|
264 pushl $9f |
|
265 call printf |
|
266 lea 16(sp), sp |
|
267 popa |
|
268 jmp 8f |
|
269 9: .asciz "\label: ip: %p, bp: %p, sp: %p\n" |
|
270 8: |
|
271 .endm |
|
272 #----------------------------------------------- |
|
273 .macro SLEEPER time:req, ident=">>>" |
|
274 pusha |
|
275 LOG 7, "\ident: sleeping \time" |
|
276 pushl $\time |
|
277 call sleep |
|
278 lea 4(sp), sp |
|
279 LOG 7, "\ident: woken up" |
|
280 popa |
|
281 .endm |
|
282 #----------------------------------------------- |
|
283 # A B S T R A C T D A T A D E C L A R A T I O N S |
|
284 #----------------------------------------------- |
|
285 # rSA reg save area |
|
286 ac = 0 |
|
287 DS retSA |
|
288 DS regSA, 32 |
|
289 DS bpSA |
|
290 rSAL = ac |
|
291 #----------------------------------------------- |
|
292 # Timeval |
|
293 ac = 0 |
|
294 DS secs |
|
295 DS usecs |
|
296 timevalL = ac |
|
297 #----------------------------------------------- |
|
298 # AddrInfo IP family net addr block |
|
299 ac = 0 |
|
300 DS ai_flags |
|
301 DS ai_family |
|
302 DS ai_socktype |
|
303 DS ai_protocol |
|
304 DS ai_addrlen |
|
305 DS ai_addrP # -->sockaddr |
|
306 DS ai_canonnameP |
|
307 DS ai_nextP |
|
308 AddrInfoL = ac |
|
309 #----------------------------------------------- |
|
310 SIGUSR2 = 12 |
|
311 SIG_IGN = 1 |
|
312 SIG_UNBLOCK = 1 |
|
313 # sigaction signal handler definition |
|
314 ac = 0 |
|
315 DS sa_handler |
|
316 DS sa_mask, 128 |
|
317 DS sa_flags |
|
318 DS sa_unused |
|
319 SigActionL = ac |
|
320 #----------------------------------------------- |
|
321 # SockAddr |
|
322 ac = 0 |
|
323 DS sa_family, 2 |
|
324 DS sa_data, 14 |
|
325 SockAddrL = ac |
|
326 #----------------------------------------------- |
|
327 # timeval struct |
|
328 ac = 0 |
|
329 DS Ti.secs |
|
330 DS Ti.usecs |
|
331 timevalL = ac |
|
332 #----------------------------------------------- |
|
333 # Debug debug info |
|
334 ac = 0 |
|
335 D.idL = 128 |
|
336 DS D.id, D.idL # debug ID of process |
|
337 D.msgL = 256 |
|
338 DS D.msg, D.msgL # debug msg workspace |
|
339 DebugL = ac |
|
340 |
|
341 .macro DebugA # returns -->Debug |
|
342 push $DebugL |
|
343 call malloc |
|
344 cmp $0, a |
|
345 ja 8f |
|
346 SYSERR "malloc" |
|
347 8: movl $0, D.id(a) |
|
348 .endm |
|
349 #----------------------------------------------- |
|
350 # CS top level attributes |
|
351 ac = 0 |
|
352 DS C.debug, DebugL |
|
353 DS C.debMaxLev # max level of debug msgs to be printed |
|
354 DS C.txtP # -->text to be sent in messages |
|
355 DS C.ttl # TTL for circulating msgs |
|
356 DS C.mp0 # TCP port of first mash node |
|
357 DS C.mn # intended # of nodes in mash |
|
358 DS C.rp0 # TCP port of first ring node |
|
359 DS C.rn # intended # of nodes in ring |
|
360 DS C.pace.tv_sec # timespec.tv_sec |
|
361 DS C.pace.tv_nsec # timespec.tv_nsec |
|
362 DS C.pacing # pacing indicator |
|
363 # DS C.rs # random() seed |
|
364 DS C.ssl # ssl mask: 01B=noSSL, 10B=SSL, 11B=both |
|
365 DS C.connTh # connection retry threshhold |
|
366 DS C.shP # -->shared counters |
|
367 DS C.pathP # -->pathname to application home dir |
|
368 DS C.cePathP # -->pathname to SSL dir |
|
369 DS C.caPathP # -->pathname to SSL CA CERT dir |
|
370 CSL = ac |
|
371 |
|
372 .macro CSA # returns -->CS |
|
373 push $CSL |
|
374 call malloc |
|
375 cmp $0, a |
|
376 ja 8f |
|
377 SYSERR "malloc" |
|
378 8: |
|
379 .endm |
|
380 #----------------------------------------------- |
|
381 # Share counters shared between procs or threads |
|
382 ac = 0 |
|
383 DS S.counter_sem, 16 # semaphore for counters |
|
384 DS S.conns # overall connections counter both in ring and mash |
|
385 DS S.msgs # overall forewards# both in ring and mash |
|
386 DS S.act # active node processes counter |
|
387 DS S.mash_open_client_count # no. of opened clients in mash |
|
388 DS S.mash_open_SSL_client_count # no. of opened SSL clients in mash |
|
389 ShareL = ac |
|
390 |
|
391 .macro ShareA # returns -->Share |
|
392 push $0 |
|
393 push $-1 |
|
394 push $0x21 # PROT_READ | PROT_WRITE |
|
395 push $0x03 # MAP_SHARED | MAP_ANONYMOUS |
|
396 push $ShareL |
|
397 push $0 |
|
398 call mmap |
|
399 cmp $-1, a |
|
400 jne 8f |
|
401 SYSERR "mmap" |
|
402 8: |
|
403 .endm |
|
404 #----------------------------------------------- |
|
405 # Data - container for data sent through connection topology |
|
406 # Container Header |
|
407 ac = 0 |
|
408 DS H.ttl # msg TTL |
|
409 DS H.ts # timestamp |
|
410 DS H.lport # listening TCP port |
|
411 HeaderL = ac |
|
412 # Container Payload |
|
413 ac = 0 |
|
414 # Pa.loadL = 256 |
|
415 DS Pa.ts # timestamp |
|
416 DS Pa.text, 0 # load sent in msg |
|
417 PayloadL = ac |
|
418 # Container to be send |
|
419 ac = 0 |
|
420 DS Co.hdr, HeaderL # Header |
|
421 DS Co.payl, PayloadL # Payload |
|
422 # ContainerL = ac |
|
423 # Data instantion |
|
424 ac = 0 |
|
425 DS Da.debug, DebugL # Debug |
|
426 DS Da.contP # -->Container |
|
427 DS Da.datalen # container length |
|
428 DataL = ac |
|
429 |
|
430 .macro DataA # returns -->Data |
|
431 push $DataL |
|
432 call malloc |
|
433 cmp $0, a |
|
434 ja 8f |
|
435 SYSERR "malloc" |
|
436 8: |
|
437 .endm |
|
438 #----------------------------------------------- |
|
439 # Node general attributes of node |
|
440 ac = 0 |
|
441 DS N.debug, DebugL # debug info |
|
442 DS N.cnstlnP # -->Constellation block |
|
443 DS N.topo # constellation topology |
|
444 DS N.locPort # TCP port node binds to |
|
445 DS N.first # port # of first node in constellation |
|
446 DS N.last # port # of last node in constellation |
|
447 DS N.nodes # number of nodes |
|
448 DS N.div # random node choise divisor (MAX_INT / nodes) |
|
449 DS N.kicker # kicker indicator |
|
450 DS N.forwP # -->shared forward indicator |
|
451 DS N.closing # closing in progress indicator |
|
452 DS N.ssc # server side socket |
|
453 DS N.data, DataL # data block |
|
454 DS N.dataP # -->data block |
|
455 DS N.srvSideP # -->array of server side Sockets |
|
456 DS N.cliSideP # -->array of client side Sockets |
|
457 DS N.sockArrLen # socket array length |
|
458 DS N.next # next node's port# |
|
459 DS N.nfds # highest FD# in FD sets |
|
460 DS N.rs, 128 # read FD set |
|
461 DS N.es, 128 # exceptional FD set |
|
462 DS N.t, timevalL # timeval for select |
|
463 DS N.ssl # SSL switch: 0=noSSL, 1=SSL |
|
464 DS N.ctxP # -->SSL context |
|
465 DS N.pid # process ID |
|
466 DS N.ptid # closing thread ID |
|
467 NodeL = ac |
|
468 |
|
469 .macro NodeA # returns -->Node |
|
470 push $NodeL |
|
471 call malloc |
|
472 cmp $0, a |
|
473 ja 8f |
|
474 SYSERR "malloc" |
|
475 8: |
|
476 .endm |
|
477 #----------------------------------------------- |
|
478 # SocketInfo comm socket info |
|
479 ac = 0 |
|
480 DS So.remPort # TCP port on remote site |
|
481 DS So.sc # comm socket# |
|
482 DS So.sslP # -->SSL structure |
|
483 SocketInfoL = ac |
|
484 |
|
485 .macro SocketA # returns -->Socket |
|
486 push $SocketL |
|
487 call malloc |
|
488 cmp $0, a |
|
489 ja 8f |
|
490 SYSERR "malloc" |
|
491 8: |
|
492 .endm |
|
493 #----------------------------------------------- |
|
494 # Constellation attributes of constellation of nodes (mash or ring) |
|
495 ac = 0 |
|
496 DS Cn.debug, DebugL # debug info |
|
497 DS Cn.topo # Constellation topology |
|
498 Cn.ring = 0 |
|
499 Cn.mash = 1 |
|
500 DS Cn.first |
|
501 DS Cn.nodes |
|
502 DS Cn.div # random node choise divisor (MAX_INT / nodes) |
|
503 DS Cn.ssl |
|
504 DS Cn.forwP |
|
505 ConstellationL = ac |
|
506 |
|
507 .macro ConstellationA # returns -->Constellation |
|
508 push $ConstellationL |
|
509 call malloc |
|
510 cmp $0, a |
|
511 ja 8f |
|
512 SYSERR "malloc" |
|
513 8: |
|
514 .endm |