home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / UNIFLEX / UNIFLEX / UniFLEX_Std.Utils1.tar.Z / UniFLEX_Std.Utils1.tar / utils1 / init.A < prev    next >
Text File  |  1985-09-10  |  10KB  |  507 lines

  1.  opt pag,nol
  2.  ttl UniFLEX init task (task 1)
  3.  pag
  4.  abs
  5.  lib sysdef
  6.  lib sysstat
  7.  lib sysints
  8.  opt lis
  9.  pag
  10.  
  11.  info UniFLEX init system
  12.  info Version 1.06, Released September 10, 1985
  13.  info Copyright, (C) 1984, 1985, by
  14.  info Technical Systems Consultants, Inc.
  15.  info All rights reserved.
  16.  
  17. *
  18. * This task is executed after system initialization.
  19. * Task 0 is the scheduler, and 'init' is task 1.  Its
  20. * main purpose is to read the ttylist file and start
  21. * the login task for each terminal listed in the file.
  22. *
  23.  
  24.  
  25. *
  26. * constants
  27. *
  28.  
  29. DFALT equ 0 default interrupt mode
  30. IGNORE equ 1 ignore interrupt for 'cpint'
  31. UTPRM equ FACUR+FACUW+FACOR utmp file permissions for create
  32. READ equ 0 read mode for open
  33. RW equ 2 read/write mode for open
  34. UNFILS equ 16 number of possible task files
  35. TTYS equ 32 max number of terminals
  36. TTPRM equ FACUR+FACUW+FACOR perms for tty open
  37. CR equ $d carriage return
  38. RBUFS equ 512 read line buffer size
  39.  
  40. *
  41. * structure definitions
  42. *
  43.  
  44. * struct ttab
  45.  
  46.  org 0
  47.  
  48. trmnm rmb 2 2 character terminal name
  49. tstyp rmb 1 ttyset parameter
  50. ttid rmb 2 task id started with this tty
  51.  
  52. TIBSIZ equ * structure size
  53.  
  54.  
  55. * struct linbuf
  56.  
  57.  org 0
  58.  
  59. lacpt rmb 1 accept flag (should be '1)
  60. lstyp rmb 1 ttyset parameter
  61. ltnam rmb 2 terminal name
  62. lterm rmb 1 line terminator ($D)
  63.  
  64. LINSIZ equ * structure size
  65.  
  66.  
  67.  pag
  68. *
  69. * Program entry here
  70. *
  71.  
  72.  org 0
  73. init sys cpint,HANGI,IGNORE ignore hangup interrupt
  74.  sys cpint,ALRMI,aupdt set for auto update
  75.  ldd #30
  76.  sys alarm
  77.  ldd #"bt setup 'bt' for boot
  78.  lbsr uphf update history file
  79. init0 ldd #-1 kill all tasks
  80.  sys spint,KILLI
  81.  ldx #ttab point to terminal table
  82. init1 clr 0,x+ zero it out
  83.  cmpx #ttend end of table?
  84.  bne init1 loop til done
  85.  clr bdflag set bring down flag
  86.  sys sacct,0 turn off accounting
  87. init2 ldd #"su setup 'su'
  88.  lbsr uphf update history file
  89.  lbsr single execute single user mode
  90.  tst bdflag bring system down?
  91.  bne down
  92.  ldd #"mu setup 'mu' for multi-user mode
  93.  lbsr uphf update history file
  94.  sys fork fork a new task
  95.  bra runst new guy branch ahead
  96.  pshs d save task id
  97. init4 sys wait wait for new task
  98.  bes init4
  99.  cmpd 0,s is this the one?
  100.  bne init4 if not, wait again
  101.  puls d reset stack
  102.  bra iloop go to main loop
  103.  
  104. *
  105. * runst
  106. *
  107. * Run the system startup file thru the shell.
  108. *
  109.  
  110. runst sys cpint,ALRMI,DFALT
  111.  sys open,root,READ open the root
  112.  ldd #0 set file desc 0
  113.  sys dup dup file
  114.  ldd #0
  115.  sys dup
  116.  sys exec,shell,starg exec the shell with startup file
  117.  sys term if here, error!
  118.  
  119. *
  120. * down
  121. *
  122. * Bring system down.
  123. *
  124.  
  125. down sys cpint,ALRMI,DFALT
  126.  lbsr kilal kill all jobs
  127.  ldd #"st set up 'st' for stop
  128.  lbsr uphf update history file
  129.  ldd #-1 kill all tasks
  130.  sys spint,KILLI
  131.  sys sacct,0 turn off accounting
  132.  sys update update disks
  133.  bra * halt!
  134.  
  135.  pag
  136.  
  137. *
  138. * iloop
  139. *
  140. * This is the main processing loop of init.
  141. *
  142.  
  143. iloop sys cpint,HANGI,reset
  144.  sys cpint,EMTI,reset0
  145.  ldd #0 prepare to close all files
  146.  pshs d save count
  147. iloop2 sys close close a file
  148.  ldd 0,s get count
  149.  addd #1 bump to next file
  150.  std 0,s save new
  151.  cmpd #UNFILS last file?
  152.  bne iloop2
  153.  puls d get count
  154.  sys open,ttyf,READ open ttys file
  155.  std ttfd save descriptor
  156.  ldd #rdbuf init read line ptrs
  157.  std rbfbeg
  158.  std rbfend
  159.  ldx #ttab point to tty table
  160. iloop4 pshs x save entry
  161.  lbsr rdline read a tty file line
  162.  puls x
  163.  beq iloop6 finished?
  164.  lda linbuf+lacpt an accepted line?
  165.  cmpa #'+ is it not '+'?
  166.  bne iloop4 if so, skip it
  167.  ldd linbuf+ltnam get tty name
  168.  std trmnm,x save in table
  169.  lda linbuf+lstyp get ttyset parameter
  170.  sta tstyp,x save in table
  171.  leax TIBSIZ,x bump to next entry
  172.  bra iloop4 repeat
  173. iloop6 ldd ttfd get file descriptor
  174.  sys close close the tty file
  175.  ldx #ttab point to terminal table just built
  176. iloo65 ldd trmnm,x get tty name
  177.  beq iloop7 is it null?
  178.  lbsr mkjob go create task
  179. iloop7 leax TIBSIZ,x bump to next entry
  180.  cmpx #ttend end of table?
  181.  bne iloo65 repeat?
  182. iloop8 sys wait wait for a task to terminate
  183.  bes iloop8
  184.  pshs x
  185.  ldx #ttab point to terminal table
  186. iloo85 cmpd ttid,x look for task id
  187.  beq iloop9 does it match?
  188.  leax TIBSIZ,x move to next entry
  189.  cmpx #ttend end of list?
  190.  bne iloo85 if not, repeat
  191.  puls x
  192.  bra iloop8 if so, go wait again
  193. iloop9 lbsr kiljb kill off the tasks tty
  194.  puls d
  195.  cmpd #8
  196.  beq iloop8
  197.  lbsr mkjob go make new tty task
  198.  bra iloop8 go wait again
  199.  
  200.  
  201. *
  202. * rdline
  203. *
  204. * Read a line from the 'ttylist' file and enter
  205. * the data in the tty table.
  206. *
  207.  
  208. rdline ldx #linbuf point to line buffer
  209.  ldb #LINSIZ set size count
  210. rdlin2 jsr rlgetc get a character
  211.  beq rdlin4 error?
  212.  sta 0,x+ save in buffer
  213.  decb dec the count
  214.  bne rdlin2 repeat?
  215.  cmpa #CR is it cr term?
  216.  beq rdlin3
  217.  cmpa #': is it ':' term?
  218.  bne rdlin4 if not - error
  219. rdli25 jsr rlgetc get character
  220.  beq rdlin4 error?
  221.  cmpa #CR look for cr
  222.  bne rdli25
  223. rdlin3 clz set ok status
  224.  rts return
  225. rdlin4 sez set error status
  226.  rts return
  227.  
  228. *
  229. * single
  230. *
  231. * Run a single user shell (initial system is single
  232. * usr only).
  233. *
  234.  
  235. single lbsr kilal kill all other jobs
  236.  sys fork fork a task
  237.  bra singl4 ne jump ahead
  238.  pshs d save new task id
  239. singl2 sys wait wait for job
  240.  bes singl2
  241.  cmpd 0,s right one term'd?
  242.  bne singl2
  243.  tfr x,d get status
  244.  cmpa #KILLI was it killed?
  245.  bne singl3
  246.  inc bdflag set down flag
  247. singl3 puls d,pc return
  248. singl4 sys cpint,ALRMI,DFALT
  249.  sys cpint,EMTI,DFALT
  250.  sys cpint,HANGI,DFALT
  251.  sys open,ctty,RW open console term
  252.  ldd #0 duplicate the file
  253.  sys dup
  254.  ldd #0
  255.  sys dup
  256.  sys create,utmp,UTPRM create user file
  257.  sys close close the file
  258.  sys exec,shell,sharg execute the shell
  259.  sys term term if error
  260.  
  261.  pag
  262. *
  263. * mkjob
  264. *
  265. * Make a new task for the terminal name specified
  266. * in the table entry pointed at by X.
  267. *
  268.  
  269. mkjob ldd trmnm,x get term name
  270.  std mttnm set in device name
  271.  sys fork fork a new task
  272.  bra mkjob2 if new guy, jump ahead
  273.  std ttid,x save task id
  274.  rts return
  275. mkjob2 pshs x save table pointer
  276.  sys cpint,HANGI,DFALT reset hangs interrupt
  277.  sys cpint,ALRMI,DFALT
  278.  sys cpint,EMTI,DFALT
  279.  sys chown,mktty,0 change owner to 0
  280.  bes mkjob8
  281.  sys chprm,mktty,TTPRM set perms for tty
  282.  bes mkjob8
  283.  sys open,mktty,RW open terminal
  284.  bes mkjob8
  285.  sys ttyget,ttbuf get current parameters
  286.  puls x restore table pointer
  287.  lda tstyp,x get ttyset parameter
  288.  cmpa #$20 blank means do nothing
  289.  beq 10f
  290.  cmpa #'1 digits 1..9, a..f are baud rate
  291.  blo 10f
  292.  tfr a,b
  293.  andb #$0F
  294.  cmpa #'9
  295.  bls 05f
  296.  cmpa #'a
  297.  blo 10f
  298.  tfr a,b
  299.  subb #'a
  300.  addb #$0A
  301.  cmpa #'f
  302.  bhi 10f
  303. 05 pshs b update baud rate
  304.  ldb ttyprm
  305.  andb #$F0
  306.  orb ,s+
  307.  stb ttyprm
  308.  ldd #0 set new tty set parameters
  309.  sys ttyset,ttbuf
  310.  ldd #0
  311.  sys close
  312.  sys open,mktty,RW
  313. 10 ldd #0 duplicate the open term
  314.  sys dup
  315.  sys exec,login,lgarg execute the login program
  316. mkjob8 sys term if error
  317.  
  318. *
  319. * kiljb
  320. *
  321. * Terminate the job whose entry is pointed at by X.
  322. *
  323.  
  324. kiljb pshs x save pointer
  325.  ldd ttid,x get task id
  326.  beq kiljb4 if null, already killed!
  327.  lbsr upduf update login file
  328.  ldx 0,s get table entry
  329.  ldd trmnm,x get terminal name
  330.  lbsr uphf update history file
  331.  ldx 0,s point to entry
  332.  ldd ttid,x get id
  333.  sys spint,KILLI kill job
  334. kiljb4 puls x reset entry pointer
  335.  ldd #0 set null word
  336.  std ttid,x zero task id
  337.  rts return
  338.  
  339. *
  340. * kilal
  341. *
  342. * Kill all active jobs.
  343. *
  344.  
  345. kilal ldx #ttab point to term table
  346. kilal2 bsr kiljb kill this job
  347.  leax TIBSIZ,x bump to next entry
  348.  cmpx #ttend end ot table?
  349.  bne kilal2 if not, repeat
  350.  rts return
  351.  pag
  352.  
  353. *
  354. * Get a character for read line
  355. *
  356.  
  357. rlgetc pshs x,b save regs
  358.  ldx rbfbeg get start ptr
  359.  cmpx rbfend empty list?
  360.  bne rlget4
  361.  ldd ttfd get file desc
  362.  sys read,rdbuf,RBUFS fill buffer
  363.  bes rlget6 error?
  364.  cmpd #0 end of file?
  365.  beq rlget6
  366.  ldx #rdbuf reset pointers
  367.  stx rbfbeg
  368.  leax d,x find end of buffer
  369.  stx rbfend mark it
  370.  ldx #rdbuf point to 1st char
  371. rlget4 lda 0,x+ get a character
  372.  stx rbfbeg set new start
  373.  puls x,b,pc return
  374. rlget6 sez set error status
  375.  puls x,b,pc return
  376.  
  377. *
  378. * upduf
  379. *
  380. * Update the act/utmp file with this user
  381. *
  382.  
  383. upduf pshs x save entry ptr
  384.  sys open,utmp,1 open the file
  385.  bes upduf6 if error, skip
  386.  pshs d save file desc
  387.  ldx 2,s get entry ptr
  388.  ldd trmnm,x get term name
  389.  anda #$f mask low 4 bits
  390.  andb #$f of each char
  391.  asla hi byte times 10
  392.  pshs a
  393.  asla
  394.  asla
  395.  adda 0,s result now x10
  396.  sta 0,s save result
  397.  addb 0,s+ add in low byte
  398.  clra clear hi byte
  399.  aslb now x16
  400.  rola
  401.  aslb
  402.  rola
  403.  aslb
  404.  rola
  405.  aslb
  406.  rola
  407.  std isk2 save in seek call
  408.  ldd 0,s get file desc
  409.  sys ind,isk seek in file
  410.  ldd 0,s get file desc
  411.  sys write,nulls,16 zero out entry
  412.  puls d get file desc
  413.  sys close close the file
  414. upduf6 puls x,pc return
  415.  
  416. *
  417. * reset
  418. *
  419. * Reset system
  420. *
  421.  
  422. reset ldd #-1 hangup all tasks
  423.  sys spint,HANGI
  424.  ldd #15 sleep for 15 seconds
  425.  sys alarm
  426.  sys stop
  427. reset0 ldd #init0 reset the pc
  428.  std 10,s on stack
  429.  rti do it!
  430.  
  431. * do auto update
  432.  
  433. aupdt sys update do update
  434.  sys cpint,ALRMI,aupdt
  435.  ldd #30
  436.  sys alarm
  437.  rti return
  438.  
  439.  pag
  440.  
  441. *
  442. * uphf
  443. *
  444. * Update the history file (/act/history).
  445. *
  446.  
  447. uphf std uphbuf save name
  448.  sys open,hisf,1 open file for write
  449.  bes uphf4 if error - exit
  450.  pshs d save file desc
  451.  sys time,uphtim get time
  452.  ldd 0,s get file desc
  453.  sys seek,0,0,2 seek to eof
  454.  ldd 0,s get file desc
  455.  sys write,uphbuf,16 write out entry
  456.  puls d get file desc
  457.  sys close close the file
  458. uphf4 rts return
  459.  
  460.  pag
  461.  
  462. *
  463. * data constants
  464. *
  465.  
  466. root fcc '/',0
  467. utmp fcc '/act/utmp',0
  468. hisf fcc '/act/history',0
  469. shell fcc '/bin/shell',0
  470. startup fcc '/etc/startup',0
  471. ctty fcc '/dev/tty00',0
  472. sharg fdb shnm,0
  473. shnm fcc 'shell',0
  474. login fcc '/etc/login',0
  475. lgarg fdb lgnm,0
  476. lgnm fcc 'login',0
  477. mktty fcc '/dev/tty'
  478. mttnm fdb 0,0
  479. starg fdb shnm2,strnm,0
  480. shnm2 fcc 'shell',0
  481. strnm fcc '/etc/startup',0
  482. ttyf fcc '/etc/ttylist',0
  483. nulls fdb 0,0,0,0,0,0,0,0 null entry
  484. uphbuf fdb 0,0,0,0,0,0 buffer for history updates
  485. uphtim fdb 0,0,0,0 time for history
  486.  
  487. *
  488. * data section
  489. *
  490.  
  491. isk fcb seek ind seek call
  492.  fdb 0
  493. isk2 fdb 0,0
  494. bdflag fcb 0 bring down flag
  495. rbfbeg rmb 2 buffer ptr
  496. rbfend rmb 2
  497. ttfd rmb 2 open file descriptor
  498. linbuf rmb LINSIZ line buffer
  499. ttab rmb TTYS*TIBSIZ terminal table
  500. ttend equ * end of table
  501. ttbuf rmb 5 ttyset/get buffer
  502. ttyprm rmb 1 Baud rate byte
  503. rdbuf rmb RBUFS read line buffer
  504.  
  505.  
  506.  end init
  507.