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 / uinit < prev    next >
Text File  |  1984-11-16  |  9KB  |  475 lines

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