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.v102 < prev    next >
Text File  |  1983-01-07  |  9KB  |  468 lines

  1.  opt pag,nol
  2.  ttl UniFLEX init task (task 1)
  3.  pag
  4.  lib sysdef
  5.  opt lis
  6.  pag
  7.  
  8.  info UniFLEX init system
  9.  info Version 1.02, Released February 15, 1982
  10.  info Copyright, (C) 1982, by
  11.  info Technical Systems Consultants, Inc.
  12.  info All rights reserved.
  13.  
  14. *
  15. * This task is executed after system initialization.
  16. * Task 0 is the scheduler, and 'init' is task 1.  Its
  17. * main purpose is to read the ttys file and start
  18. * the loggin task for each terminal listed in the file.
  19. *
  20.  
  21.  
  22. *
  23. * constants
  24. *
  25.  
  26. DFALT equ 0 default interrupt mode
  27. IGNORE equ 1 ignore interrupt for 'cpint'
  28. HANGS equ 1 hangup interrupt for 'cpint'
  29. KILLS equ 5 kill job interrupt
  30. ALRMI equ 10 alarm interrupt
  31. UTPRM equ %00001011 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 %00010011 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,HANGS,IGNORE ignore hangup interrupt
  74.  sys cpint,ALRMI,aupdt set for auto update
  75.  ldd #30
  76.  sys alarm
  77.  ldd #('b<<8)|'t setup 'bt' for boot
  78.  lbsr uphf update history file
  79. init0 ldd #-1 kill all tasks
  80.  sys spint,KILLS
  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 #('s<<8)|'u 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 #('m<<8)|'u 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 #('s<<8)|'t set up 'st' for stop
  128.  lbsr uphf update history file
  129.  ldd #-1 kill all tasks
  130.  sys spint,KILLS
  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,HANGS,reset
  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 #KILLS 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 open,ctty,RW open console term
  249.  ldd #0 duplicate the file
  250.  sys dup
  251.  ldd #0
  252.  sys dup
  253.  sys create,utmp,UTPRM create user file
  254.  sys close close the file
  255.  sys exec,shell,sharg execute the shell
  256.  sys term term if error
  257.  
  258.  pag
  259. *
  260. * mkjob
  261. *
  262. * Make a new task for the terminal name specified
  263. * in the table entry pointed at by X.
  264. *
  265.  
  266. mkjob ldd trmnm,x get term name
  267.  std mttnm set in device name
  268.  sys fork fork a new task
  269.  bra mkjob2 if new guy, jump ahead
  270.  std ttid,x save task id
  271.  rts return
  272. mkjob2 sys cpint,HANGS,DFALT reset hangs interrupt
  273.  sys cpint,ALRMI,DFALT
  274.  sys chown,mktty,0 change owner to 0
  275.  bes mkjob8
  276.  sys chprm,mktty,TTPRM set perms for tty
  277.  bes mkjob8
  278.  sys open,mktty,RW open terminal
  279.  bes mkjob8
  280.  ldd #0 duplicate the open term
  281.  sys dup
  282.  sys exec,login,lgarg execute the login program
  283. mkjob8 sys term if error
  284.  
  285. *
  286. * kiljb
  287. *
  288. * Terminate the job whose entry is pointed at by X.
  289. *
  290.  
  291. kiljb pshs x save pointer
  292.  ldd ttid,x get task id
  293.  beq kiljb4 if null, already killed!
  294.  lbsr upduf update login file
  295.  ldx 0,s get table entry
  296.  ldd trmnm,x get terminal name
  297.  lbsr uphf update history file
  298.  ldx 0,s point to entry
  299.  ldd ttid,x get id
  300.  sys spint,KILLS kill job
  301. kiljb4 puls x reset entry pointer
  302.  ldd #0 set null word
  303.  std ttid,x zero task id
  304.  rts return
  305.  
  306. *
  307. * kilal
  308. *
  309. * Kill all active jobs.
  310. *
  311.  
  312. kilal ldx #ttab point to term table
  313. kilal2 bsr kiljb kill this job
  314.  leax TIBSIZ,x bump to next entry
  315.  cmpx #ttend end ot table?
  316.  bne kilal2 if not, repeat
  317.  rts return
  318.  pag
  319.  
  320. *
  321. * Get a character for read line
  322. *
  323.  
  324. rlgetc pshs x,b save regs
  325.  ldx rbfbeg get start ptr
  326.  cmpx rbfend empty list?
  327.  bne rlget4
  328.  ldd ttfd get file desc
  329.  sys read,rdbuf,RBUFS fill buffer
  330.  bes rlget6 error?
  331.  cmpd #0 end of file?
  332.  beq rlget6
  333.  ldx #rdbuf reset pointers
  334.  stx rbfbeg
  335.  leax d,x find end of buffer
  336.  stx rbfend mark it
  337.  ldx #rdbuf point to 1st char
  338. rlget4 lda 0,x+ get a character
  339.  stx rbfbeg set new start
  340.  puls x,b,pc return
  341. rlget6 sez set error status
  342.  puls x,b,pc return
  343.  
  344. *
  345. * upduf
  346. *
  347. * Update the act/utmp file with this user
  348. *
  349.  
  350. upduf pshs x save entry ptr
  351.  sys open,utmp,1 open the file
  352.  bes upduf6 if error, skip
  353.  pshs d save file desc
  354.  ldx 2,s get entry ptr
  355.  ldd trmnm,x get term name
  356.  anda #$f mask low 4 bits
  357.  andb #$f of each char
  358.  asla hi byte times 10
  359.  pshs a
  360.  asla
  361.  asla
  362.  asla
  363.  adda 0,s result now x10
  364.  sta 0,s save result
  365.  addb 0,s+ add in low byte
  366.  clra clear hi byte
  367.  aslb now x16
  368.  rola
  369.  aslb
  370.  rola
  371.  aslb
  372.  rola
  373.  aslb
  374.  rola
  375.  std isk2 save in seek call
  376.  ldd 0,s get file desc
  377.  sys ind,isk seek in file
  378.  ldd 0,s get file desc
  379.  sys write,nulls,16 zero out entry
  380.  puls d get file desc
  381.  sys close close the file
  382. upduf6 puls x,pc return
  383.  
  384. *
  385. * reset
  386. *
  387. * Reset system
  388. *
  389.  
  390. reset ldd #init0 reset the pc
  391.  std 10,s on stack
  392.  rti do it!
  393.  
  394. * do auto update
  395.  
  396. aupdt sys update do update
  397.  sys cpint,ALRMI,aupdt
  398.  ldd #30
  399.  sys alarm
  400.  rti return
  401.  
  402.  pag
  403.  
  404. *
  405. * uphf
  406. *
  407. * Update the history file (/act/history).
  408. *
  409.  
  410. uphf std uphbuf save name
  411.  sys open,hisf,1 open file for write
  412.  bes uphf4 if error - exit
  413.  pshs d save file desc
  414.  sys time,uphtim get time
  415.  ldd 0,s get file desc
  416.  sys seek,0,0,2 seek to eof
  417.  ldd 0,s get file desc
  418.  sys write,uphbuf,16 write out entry
  419.  puls d get file desc
  420.  sys close close the file
  421. uphf4 rts return
  422.  
  423.  pag
  424.  
  425. *
  426. * data constants
  427. *
  428.  
  429. root fcc '/',0
  430. utmp fcc '/act/utmp',0
  431. hisf fcc '/act/history',0
  432. shell fcc '/bin/shell',0
  433. startup fcc '/etc/startup',0
  434. ctty fcc '/dev/tty00',0
  435. sharg fdb shnm,0
  436. shnm fcc 'shell',0
  437. login fcc '/etc/login',0
  438. lgarg fdb lgnm,0
  439. lgnm fcc 'login',0
  440. mktty fcc '/dev/tty'
  441. mttnm fdb 0,0
  442. starg fdb shnm2,strnm,0
  443. shnm2 fcc 'shell',0
  444. strnm fcc '/etc/startup',0
  445. ttyf fcc '/etc/ttylist',0
  446. nulls fdb 0,0,0,0,0,0,0,0 null entry
  447. uphbuf fdb 0,0,0,0,0,0 buffer for history updates
  448. uphtim fdb 0,0,0,0 time for history
  449.  
  450. *
  451. * data section
  452. *
  453.  
  454. isk fcb seek ind seek call
  455.  fdb 0
  456. isk2 fdb 0,0
  457. bdflag fcb 0 bring down flag
  458. rbfbeg rmb 2 buffer ptr
  459. rbfend rmb 2
  460. ttfd rmb 2 open file descriptor
  461. linbuf rmb LINSIZ line buffer
  462. ttab rmb TTYS*TIBSIZ terminal table
  463. ttend equ * end of table
  464. rdbuf rmb RBUFS read line buffer
  465.  
  466.  
  467.  end
  468.