|
1 .include "DS.S" |
|
2 #----------------------------------------------- |
|
3 # C O N S T E L L A T I O N O P E R A T I O N S |
|
4 #----------------------------------------------- |
|
5 ARGS |
|
6 DS ssl # ssl switch |
|
7 DS topo # topology |
|
8 # returns: nothing |
|
9 PROLOC |
|
10 DL this, ConstellationL # this Constellation instance |
|
11 DL thisP # -->this Constellation |
|
12 DL deP # -->Debug |
|
13 DL len |
|
14 DL pid |
|
15 DL stat |
|
16 DL bad # "some node BAD" exit indicator |
|
17 EPILOC |
|
18 #----------------------------------------------- |
|
19 .global Constellation |
|
20 Constellation: |
|
21 PROLOG |
|
22 lea this(bp), b # -->this Constellation |
|
23 mov b, thisP(bp) # save -->this Constellation |
|
24 # lea this, b # -->this inst |
|
25 # set debid |
|
26 lea Cn.debug(b), a # -->Debug |
|
27 mov a, deP(bp) # save -->Debug locally |
|
28 mov C.csP, c # -->CS |
|
29 cmp $Cn.ring, topo(bp) # ring topology ? |
|
30 je 0f |
|
31 mov C.mn(c), a # num. of nodes |
|
32 mov a, Cn.nodes(b) |
|
33 mov C.mp0(c), a # port # of fist node |
|
34 mov a, Cn.first(b) |
|
35 movl $Cn.mash, Cn.topo(b) |
|
36 push $8f |
|
37 jmp 1f |
|
38 0: mov C.rn(c), a # num. of nodes |
|
39 mov a, Cn.nodes(b) |
|
40 mov C.rp0(c), a # port # of fist node |
|
41 mov a, Cn.first(b) |
|
42 movl $Cn.ring, Cn.topo(b) |
|
43 push $7f |
|
44 1: cmp $0, ssl(bp) # SSL ? |
|
45 jz 2f # no |
|
46 movl $1, Cn.ssl(b) |
|
47 addl $500, Cn.first(b) # first SSL port # |
|
48 push $6f |
|
49 jmp 9f |
|
50 2: movl $0, Cn.ssl(b) |
|
51 push $5f |
|
52 jmp 9f |
|
53 5: .ascii "non\0" |
|
54 6: .ascii "\0" |
|
55 7: .ascii "RING\0" |
|
56 8: .ascii "MASH\0" |
|
57 9: DEBID "%sSSL %s", 2 |
|
58 # check # of nodes |
|
59 movL $0, bad(bp) |
|
60 cmp $1, Cn.nodes(b) # num of nodes |
|
61 jl ConstellationR # < 1 ? nothing to do |
|
62 jg 0f |
|
63 LOG 0, "1 node configuration not implemented yet" |
|
64 jmp ConstellationR |
|
65 0: LOG 5, "initializing..." |
|
66 # determine divisor for random next node choise |
|
67 mov $1, a |
|
68 shl $31, a |
|
69 not a # MAX_INT |
|
70 xor d, d |
|
71 divl Cn.nodes(b) |
|
72 mov a, Cn.div(b) # save divisor (MAX_INT / nodes) |
|
73 # allocate "forward" indicator shared by nodes in constellation |
|
74 push $0 |
|
75 push $-1 |
|
76 push $0x21 # PROT_READ | PROT_WRITE |
|
77 push $0x03 # MAP_SHARED | MAP_ANONYMOUS |
|
78 push $4 |
|
79 push $0 |
|
80 call mmap |
|
81 cmp $-1, a |
|
82 jne 0f |
|
83 SYSERR "mmap" |
|
84 0: mov thisP(bp), b |
|
85 mov a, Cn.forwP(b) # save -->forw |
|
86 movl $1, (a) # enable forwarding |
|
87 mov C.csP, c # -->CS |
|
88 push C.ttl(c) |
|
89 push Cn.nodes(b) |
|
90 LOG 1, "%d node(s), ttl=%d starting..." |
|
91 # start processes for all nodes in constellation |
|
92 mov Cn.first(b), d # first node# |
|
93 mov d, c |
|
94 add Cn.nodes(b), c # last node + 1 |
|
95 0: pusha |
|
96 call fork |
|
97 cmp $0, a |
|
98 jnz 1f # parent |
|
99 popa |
|
100 push d # node's port# |
|
101 push b # -->Cnstlln |
|
102 call Node |
|
103 1: mov a, pid(bp) |
|
104 popa |
|
105 push pid(bp) # nodes's pid |
|
106 push d # node's port# |
|
107 LOG 3, "node %u established in process %u", 2 |
|
108 inc d |
|
109 cmp d, c # last node ? |
|
110 jg 0b # no, continue forking |
|
111 # wait for completion of node processes |
|
112 LOG 5, "all nodes established, waiting for them to terminate..." |
|
113 movl $0, bad(bp) |
|
114 0: lea stat(bp), a |
|
115 cmp $0, bad(bp) # status still OK ? |
|
116 je 1f # yes |
|
117 mov Cn.forwP(b), a # -->forward switch |
|
118 movl $0, (a) # disable forwarding |
|
119 1: mov a, (sp) # -->return status of task |
|
120 call wait |
|
121 mov thisP(bp), b |
|
122 cmp $0, a # normal return from wait? |
|
123 jl 3f # no, all subtasks finshed |
|
124 mov a, pid(bp) # save subtask's pid |
|
125 mov stat(bp), a |
|
126 test $0x7f, a # subtask ended by exit ? |
|
127 jnz 2f # no, killed |
|
128 and $0xff00, a # extract subtask rc |
|
129 jz 1f # rc = 0 |
|
130 movl $1, bad(bp) # non zero rc, turn on BAD switch |
|
131 1: push a # rc |
|
132 push pid(bp) # pid |
|
133 LOG 4, "node process %u ended with exit(%d)" |
|
134 jmp 0b # continue waiting for other subtasks |
|
135 2: movl $1, bad(bp) # subtask killed, turn on BAD switch |
|
136 push pid(bp) |
|
137 LOG 4, "node process %u killed" |
|
138 jmp 0b # continue waiting for other subtasks |
|
139 |
|
140 # opers of all nodes finished |
|
141 3: cmp $0, bad(bp) # all nodes ended OK ? |
|
142 je 0f # yes |
|
143 push $7f |
|
144 jmp 9f |
|
145 0: push $8f |
|
146 jmp 9f |
|
147 7: .ascii "with ERROR\0" |
|
148 8: .ascii "OK\0" |
|
149 9: LOG 1, "ENDED %s" |
|
150 ConstellationR: |
|
151 push bad(bp) |
|
152 call exit |
|
153 #----------------------------------------------- |
|
154 .end |
|
155 |