Mercurial > hg > Members > kono > nitros9-code
annotate level1/cmds/inetd.as @ 3148:ffa4b0273cc7
3rdparty/utils/fpgarom: Utilities for CoCo3FPGA booting
Includes Brett Gordon's CocoFPGA Boot ROM.
author | Bill Pierce <merlinious999@gmail.com> |
---|---|
date | Sat, 04 Feb 2017 18:54:49 +0100 |
parents | 1647f1874cdf |
children |
rev | line source |
---|---|
2475 | 1 ******************************************************************** |
2 * inetd - internet daemon | |
3 * | |
4 * $Id$ | |
5 * | |
6 * Edt/Rev YYYY/MM/DD Modified by | |
7 * Comment | |
8 * ------------------------------------------------------------------ | |
9 * 1 2010/01/08 Boisy G. Pitre | |
10 * Started. | |
11 * | |
12 * 2 2010/01/22 Boisy G. Pitre | |
13 * Now reads inetd.conf file. | |
2578 | 14 * |
15 * 3 2011/08/07 Boisy G. Pitre | |
16 * Fixed bug where conf file wasn't being processed correctly. | |
2475 | 17 |
18 nam inetd | |
19 ttl internet daemon | |
20 | |
2807 | 21 section __os9 |
2820
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
22 type equ Prgrm |
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
23 lang equ Objct |
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
24 attr equ ReEnt |
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
25 rev equ $00 |
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
26 edition equ 3 |
d660d443fe5f
Changed set to equ in __os9 section so stack/edition/etc are honored by lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2807
diff
changeset
|
27 stack equ 200 |
2807 | 28 endsect |
2475 | 29 |
2807 | 30 section bss |
2475 | 31 targetport rmb 2 |
32 netdatardy rmb 1 | |
33 nbufferl equ 128 | |
34 nbuffer rmb nbufferl | |
35 lbufferl equ 128 | |
36 lbuffer rmb lbufferl | |
37 nnext rmb 2 | |
38 token rmb 2 | |
39 orgstdin rmb 1 | |
40 orgstdout rmb 1 | |
41 orgstderr rmb 1 | |
42 childnetpath rmb 1 | |
43 netpath rmb 1 | |
44 targetprog rmb 128 | |
45 targetparams rmb 128 | |
2579 | 46 tmodeparamlen rmb 1 |
47 tmodeparams rmb 128 | |
2475 | 48 endsect |
49 | |
2787
28b6ec8a14d5
Added 'extern' pragam, fixed up rules.mak, changed 'section text' to 'section code' in sources
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2783
diff
changeset
|
50 section code |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2722
diff
changeset
|
51 |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2722
diff
changeset
|
52 DEBUG equ 1 |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2722
diff
changeset
|
53 |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2722
diff
changeset
|
54 |
2475 | 55 NetSig equ 2 |
56 | |
2579 | 57 tmode fcs /tmode/ |
58 | |
2475 | 59 * signal intercept routine |
60 sigint cmpb #NetSig | |
61 bne sigex | |
62 inc netdatardy,u | |
63 sigex rti | |
64 | |
65 **** Entry Point **** | |
2790 | 66 __start |
2475 | 67 * setup signal intercept |
68 leax sigint,pcr | |
69 os9 F$Icpt | |
70 | |
71 clr netdatardy,u | |
72 | |
73 leax nbuffer,u | |
74 stx nnext,u | |
75 | |
2702
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
76 * Turn off pause in standard out |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
77 ldd #$01*256+SS.Opt |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
78 leas -32,s |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
79 tfr s,x |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
80 os9 I$GetStt |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
81 bcs opterr |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
82 clr PD.PAU-PD.OPT,x |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
83 os9 I$SetStt |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
84 opterr |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
85 leas 32,s |
2bd966ffd6d5
Fixed longstanding issue with processes not going away when a network path closed. Also inetd now turns of pause
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2579
diff
changeset
|
86 |
2475 | 87 * open the path to the control channel |
88 lbsr TCPOpen | |
89 lbcs errex | |
90 sta netpath,u | |
91 leax SetupPorts,pcr | |
92 lbsr ProcInetd | |
93 lbcs errex | |
94 | |
95 IFNE DEBUG | |
96 lbsr PRINTS | |
97 fcc /Got netpath and setup ports/ | |
98 fcb C$CR | |
99 fcb $00 | |
100 ENDC | |
101 | |
102 ssignetpath | |
103 IFNE DEBUG | |
104 lbsr PRINTS | |
105 fcc /SS.SSig on NetPath/ | |
106 fcb C$CR | |
107 fcb $00 | |
108 ENDC | |
109 | |
110 lda netpath,u | |
111 ldb #SS.SSig send signal on data ready | |
112 ldx #NetSig | |
113 os9 I$SetStt | |
114 lbcs errex | |
115 | |
116 **** MAIN LOOP **** | |
117 mainloop | |
118 pshs cc | |
119 orcc #IntMasks | |
120 tst netdatardy,u | |
121 bne gotdata | |
122 | |
123 * wait for a child to die (or wake up via signal) | |
124 os9 F$Wait | |
125 bcc chkrdy | |
126 cmpb #E$NoChld | |
127 bne chkrdy got error other than "no children" | |
128 * if no children, go to sleep | |
129 ldx #$0000 | |
130 os9 F$Sleep | |
131 | |
132 chkrdy puls cc | |
133 bra ssignetpath | |
134 | |
135 gotdata puls cc | |
136 dec netdatardy,u | |
137 * read the data from netpath | |
138 IFNE DEBUG | |
139 lbsr PRINTS | |
140 fcc /Reading data from netpath/ | |
141 fcb C$CR | |
142 fcb $00 | |
143 ENDC | |
144 | |
145 lda netpath,u | |
146 ldb #SS.Ready | |
147 os9 I$GetStt | |
148 bcs ssignetpath | |
149 | |
150 clra | |
151 tfr d,y | |
152 lda netpath,u | |
153 ldx nnext,u | |
154 os9 I$Read | |
155 lbcs errex | |
156 tfr y,d | |
157 leax d,x | |
158 stx nnext,u | |
159 lda -1,x | |
160 cmpa #C$CR | |
161 lbne ssignetpath | |
162 | |
163 leax nbuffer,u | |
164 stx nnext,u | |
165 | |
166 lda #1 | |
167 ldy #256 | |
168 os9 I$WritLn | |
169 | |
170 * determine response | |
171 lda ,x | |
172 cmpa #'9 | |
173 ble incoming | |
174 | |
175 cmpa #'F | |
176 lbra ssignetpath | |
177 | |
178 * get token number | |
179 incoming | |
180 lbsr DEC_BIN | |
181 std token,u | |
182 IFNE DEBUG | |
183 pshs d | |
184 lbsr PRINTS | |
185 fcc /Got token / | |
186 fcb $00 | |
187 puls d | |
188 lbsr PRINT_DEC | |
189 lbsr PRINTS | |
190 fcb C$CR | |
191 fcb $00 | |
192 ENDC | |
193 | |
194 * skip over token number | |
195 IFNE DEBUG | |
196 lbsr PRINTS | |
197 fcc /To Space.../ | |
198 fcb C$CR | |
199 fcb $00 | |
200 ENDC | |
201 lbsr TO_SP | |
202 IFNE DEBUG | |
203 lbsr PRINTS | |
204 fcc /To Non-Space.../ | |
205 fcb C$CR | |
206 fcb $00 | |
207 ENDC | |
208 lbsr TO_NON_SP | |
209 | |
210 * get port number | |
211 lbsr DEC_BIN | |
212 std targetport,u | |
213 | |
214 IFNE DEBUG | |
215 pshs d | |
216 lbsr PRINTS | |
217 fcc /Got request for port / | |
218 fcb $00 | |
219 ldd ,s | |
220 lbsr PRINT_DEC | |
221 lbsr PRINTS | |
222 fcb C$CR | |
223 fcb $00 | |
224 puls d | |
225 ENDC | |
226 | |
227 leax ForkProcForPort,pcr | |
228 lbsr ProcInetd | |
229 lbra ssignetpath we may want to tell server we have no app | |
230 | |
231 errex os9 F$Exit | |
232 | |
233 | |
234 * Process inetd.conf file | |
235 * | |
236 * Entry: X = processor routine | |
237 * | |
238 * - open conf file | |
239 * - read each line and get first parameter (port number) | |
240 * - send it to the processor routine at x | |
241 * - if error or end of file, close and return | |
242 ProcInetd pshs x | |
243 leax inetdconf,pcr | |
244 lda #READ. | |
245 os9 I$Open | |
246 bcs adex | |
247 IFNE DEBUG | |
248 pshs d | |
249 lbsr PRINTS | |
250 fcc /Opened inetd.conf ok/ | |
251 fcb C$CR | |
252 fcb $00 | |
253 puls d | |
254 ENDC | |
255 nextline leax lbuffer,u | |
256 ldy #lbufferl-1 | |
257 lbsr FGETS | |
258 bcs closeup | |
259 lbsr TO_NON_SP skip any leading spaces | |
260 ldb ,x check for EOL or comment | |
261 cmpb #C$CR | |
262 beq nextline | |
263 cmpb #'# | |
264 beq nextline | |
265 IFNE DEBUG | |
266 pshs d,x | |
267 lbsr PRINTS | |
268 fcc /Reading line: / | |
269 fcb $00 | |
270 ldx 2,s | |
271 lbsr PUTS | |
272 puls d,x | |
273 ENDC | |
274 pshs a | |
275 jsr [1,s] | |
276 puls a | |
277 bcc nextline | |
278 closeup cmpb #E$EOF | |
279 bne closeandex | |
280 clrb | |
281 closeandex pshs b,cc | |
282 os9 I$Close | |
283 puls b,cc | |
284 adex puls x,pc | |
285 | |
286 | |
287 * Setup ports | |
288 * Extract first parameter at X and send to server | |
289 SetupPorts lbsr DEC_BIN | |
290 cmpd #0 | |
291 beq ret0 | |
292 * find comma and change it to nul | |
293 tfr x,y | |
294 setuploop lda ,y+ | |
295 cmpa #C$CR | |
296 beq ret0 | |
297 cmpa #', | |
298 bne setuploop | |
299 setuplisten | |
300 clr -1,y | |
301 IFNE DEBUG | |
302 pshs d,x | |
303 lbsr PRINTS | |
304 fcc /Send listen/ | |
305 fcb C$CR | |
306 fcb $00 | |
307 puls d,x | |
308 ENDC | |
309 lda netpath,u | |
310 lbsr TCPListen | |
311 ret0 rts | |
312 | |
2578 | 313 retcc clrb |
314 rts | |
315 | |
2475 | 316 * Fork Proccess that matches target port |
317 * Extract first parameter at X and see if it matches target port | |
318 * if so, read rest of line and fork the process | |
2579 | 319 * Line looks like this: portnumberplusoptions,prog,params,path opts |
2475 | 320 ForkProcForPort |
321 * get port number | |
322 lbsr DEC_BIN | |
323 IFNE DEBUG | |
324 pshs d | |
325 lbsr PRINTS | |
326 fcc /Reading port / | |
327 fcb $00 | |
328 ldd ,s | |
329 lbsr PRINT_DEC | |
330 lbsr PRINTS | |
331 fcb C$CR | |
332 fcb $00 | |
2578 | 333 lbsr PRINTS |
334 fcc /Comparing to port / | |
335 fcb $00 | |
336 ldd targetport,u | |
337 lbsr PRINT_DEC | |
338 lbsr PRINTS | |
339 fcb C$CR | |
340 fcb $00 | |
2475 | 341 puls d |
342 ENDC | |
343 cmpd targetport,u | |
2578 | 344 lbne retcc |
2475 | 345 * point Y to byte after comma |
346 portloop lda ,y+ | |
347 cmpa #C$CR | |
348 beq ret0 | |
349 cmpa #', | |
350 bne portloop | |
351 tfr y,x | |
352 * copy bytes up to comma at X | |
353 leay targetprog,u | |
354 prgloop lda ,x+ | |
355 cmpa #', | |
356 beq sethi | |
357 cmpa #C$CR | |
358 lbeq ret | |
359 sta ,y+ | |
360 bra prgloop | |
361 sethi lda -1,y | |
362 ora #$80 | |
363 sta -1,y | |
2579 | 364 copypar clr tmodeparamlen,u |
365 leay targetparams,u | |
2475 | 366 parloop lda ,x+ |
367 sta ,y+ | |
2579 | 368 cmpa #', |
369 beq procopts | |
2475 | 370 cmpa #C$CR |
2579 | 371 beq gotprocparms |
2475 | 372 |
2579 | 373 procopts |
374 leay tmodeparams,u | |
375 procoptsloop lda ,x+ | |
376 sta ,y+ | |
377 inc targetparams,u | |
378 cmpa #C$CR | |
379 beq procoptsloop | |
380 | |
381 gotprocparms | |
2475 | 382 IFNE DEBUG |
383 pshs d | |
384 lbsr PRINTS | |
385 fcc /Got proc and params to fork/ | |
386 fcb C$CR | |
387 fcb $00 | |
388 puls d | |
389 ENDC | |
390 | |
391 * ignore client port number and hostname for now | |
392 lbsr TCPOpen | |
393 bcc savechild | |
394 | |
395 ldd token,u | |
396 leas -8,s | |
397 leax ,s | |
398 lbsr BIN_DEC | |
399 lda netpath,u | |
400 tfr x,y | |
401 lbsr TCPKill | |
402 leas 8,s | |
403 lbra forkex | |
404 | |
405 savechild | |
406 sta childnetpath,u | |
407 ldd token,u | |
408 leas -8,s | |
409 leax ,s | |
410 lbsr BIN_DEC | |
411 lda childnetpath,u | |
412 tfr x,y | |
413 lbsr TCPJoin | |
414 leas 8,s | |
415 bcc turnonechoalf | |
416 os9 I$Close | |
417 lbra forkex | |
418 | |
419 turnonechoalf | |
420 IFNE DEBUG | |
421 pshs d | |
422 lbsr PRINTS | |
423 fcc /Turning on PD.EKO and PD.ALF/ | |
424 fcb C$CR | |
425 fcb $00 | |
426 puls d | |
427 ENDC | |
2721
06d492093592
Fixed echo problem with TCPOpen now always turning echo off
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2702
diff
changeset
|
428 lbsr SetEchoOn |
2475 | 429 lbcs ret |
2722
82b12ff069d7
Also turning off autolf on TCPOpen
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2721
diff
changeset
|
430 lbsr SetAutoLFOn |
2475 | 431 lbcs ret |
432 | |
433 * dup paths | |
434 duper | |
435 IFNE DEBUG | |
436 pshs d | |
437 lbsr PRINTS | |
438 fcc /Duping paths/ | |
439 fcb C$CR | |
440 fcb $00 | |
441 puls d | |
442 ENDC | |
443 | |
444 clra | |
445 os9 I$Dup | |
446 lbcs errex | |
447 sta orgstdin,u | |
448 lda #1 | |
449 os9 I$Dup | |
450 lbcs errex | |
451 sta orgstdout,u | |
452 lda #2 | |
453 os9 I$Dup | |
454 lbcs errex | |
455 sta orgstderr,u | |
456 | |
457 * close original stdin/out/err paths | |
458 clra | |
459 os9 I$Close | |
460 inca | |
461 os9 I$Close | |
462 inca | |
463 os9 I$Close | |
464 | |
465 * Dup child net path to stdin/stdout/stderr | |
466 lda childnetpath,u | |
467 os9 I$Dup | |
468 lbcs errex | |
469 os9 I$Dup | |
470 lbcs errex | |
471 os9 I$Dup | |
472 lbcs errex | |
473 | |
2579 | 474 * fork tmode process if tmode param length > 0 |
475 tst tmodeparamlen,u | |
476 beq forkchild | |
477 pshs u | |
478 leax tmode,pcr | |
479 leau tmodeparams,u | |
480 lda #Objct | |
481 clrb | |
482 ldy #256 | |
483 os9 F$Fork | |
484 puls u | |
485 os9 F$Wait | |
486 | |
2475 | 487 * fork child process |
2579 | 488 forkchild |
2475 | 489 pshs u |
490 leax targetprog,u | |
491 leau targetparams,u | |
492 lda #Objct | |
493 clrb | |
494 ldy #256 | |
495 os9 F$Fork | |
496 puls u | |
497 * If our F$Fork fails, do not error out... | |
498 * bcs ret2 | |
499 | |
500 * restore orginal paths | |
501 clra | |
502 os9 I$Close | |
503 inca | |
504 os9 I$Close | |
505 inca | |
506 os9 I$Close | |
507 | |
508 lda orgstdin,u | |
509 os9 I$Dup | |
510 lbcs errex | |
511 lda orgstdout,u | |
512 os9 I$Dup | |
513 lbcs errex | |
514 lda orgstderr,u | |
515 os9 I$Dup | |
516 lbcs errex | |
517 lda orgstdin,u | |
518 os9 I$Close | |
519 lda orgstdout,u | |
520 os9 I$Close | |
521 lda orgstderr,u | |
522 os9 I$Close | |
523 lda childnetpath,u | |
524 os9 I$Close | |
525 | |
526 IFNE DEBUG | |
527 pshs d | |
528 lbsr PRINTS | |
529 fcc /Proc forked/ | |
530 fcb C$CR | |
531 fcb $00 | |
532 puls d | |
533 ENDC | |
534 | |
535 forkex comb | |
536 ldb #E$EOF | |
537 ret rts | |
538 | |
539 inetdconf fcc "....../SYS/inetd.conf" | |
540 fcb C$CR | |
541 endsect |