     1                                  ; ****************************************************************************
     2                                  ; init386.s (init5.s) - Retro Unix 386 v1.2 - /etc/init - sys initialization 
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Retro UNIX 386 v1 - /etc/init - process control initialization
     5                                  ;
     6                                  ; [ Last Modification: 24/01/2022 ]
     7                                  ;
     8                                  ; Derived from UNIX Operating System (v1.0 for PDP-11) 
     9                                  ; (Original) Source Code by Ken Thompson (1971-1972)
    10                                  ; <Bell Laboratories (17/3/1972)>
    11                                  ; <Preliminary Release of UNIX Implementation Document> (Section E.12)
    12                                  ; ****************************************************************************
    13                                  ; init4.s (17/11/2015) - Retro UNIX 386 v1
    14                                  ;
    15                                  ; (Retro UNIX 386 v1 - init386.s, NASM 2.11)
    16                                  ; Derived from INIT09.ASM (17/01/2014, Retro UNIX 8086 v1, MASM 6.11)  
    17                                  ; Derived from 'init.s' file of original UNIX v1
    18                                  ; INIT09.ASM, 17/01/2014 
    19                                  
    20                                  ; 23/01/2022 (init5.s)
    21                                  ; 17/11/2015 (init4.s)
    22                                  ; 23/10/2015 (init3.s)
    23                                  ; 14/10/2015 (init2.s)
    24                                  ; 17/09/2015
    25                                  ; 03/09/2015
    26                                  ; 27/08/2015
    27                                  ; 13/08/2015
    28                                  ; 07/08/2015
    29                                  ; 30/06/2015
    30                                  ; 14/07/2013
    31                                  
    32                                  ; 12/01/2022 (Retro UNIX 386 v1.2)
    33                                  ;
    34                                  ; UNIX v1 system calls
    35                                  _rele 	equ 0
    36                                  _exit 	equ 1
    37                                  _fork 	equ 2
    38                                  _read 	equ 3
    39                                  _write	equ 4
    40                                  _open	equ 5
    41                                  _close 	equ 6
    42                                  _wait 	equ 7
    43                                  _creat 	equ 8
    44                                  _link 	equ 9
    45                                  _unlink	equ 10
    46                                  _exec	equ 11
    47                                  _chdir	equ 12
    48                                  _time 	equ 13
    49                                  _mkdir 	equ 14
    50                                  _chmod	equ 15
    51                                  _chown	equ 16
    52                                  _break	equ 17
    53                                  _stat	equ 18
    54                                  _seek	equ 19
    55                                  _tell 	equ 20
    56                                  _mount	equ 21
    57                                  _umount	equ 22
    58                                  _setuid	equ 23
    59                                  _getuid	equ 24
    60                                  _stime	equ 25
    61                                  _quit	equ 26	
    62                                  _intr	equ 27
    63                                  _fstat	equ 28
    64                                  _emt 	equ 29
    65                                  _mdate 	equ 30
    66                                  _stty 	equ 31
    67                                  _gtty	equ 32
    68                                  _ilgins	equ 33
    69                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    70                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    71                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    72                                  _msg	equ 35 ; Retro UNIX 386 v1 feature only !
    73                                  _geterr	equ 36 ; Retro UNIX 386 v1 feature only !
    74                                  ; 12/01/2022 - Retro UNIX 386 v1.2
    75                                  ; Retro UNIX 386 v2 system calls
    76                                  _setgid	equ 37
    77                                  _getgid	equ 38
    78                                  _sysver	equ 39 ; (get) Retro Unix 386 version
    79                                  
    80                                  ;;;
    81                                  ESCKey equ 1Bh
    82                                  EnterKey equ 0Dh
    83                                  
    84                                  %macro sys 1-4
    85                                      ; 03/09/2015	
    86                                      ; 13/04/2015
    87                                      ; Retro UNIX 386 v1 system call.		
    88                                      %if %0 >= 2   
    89                                          mov ebx, %2
    90                                          %if %0 >= 3    
    91                                              mov ecx, %3
    92                                              %if %0 = 4
    93                                                 mov edx, %4   
    94                                              %endif
    95                                          %endif
    96                                      %endif
    97                                      mov eax, %1
    98                                      int 30h	   
    99                                  %endmacro
   100                                  
   101                                  ; Retro UNIX 386 v1 system call format:
   102                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
   103                                  
   104                                  [BITS 32] ; We need 32-bit intructions for protected mode
   105                                  
   106                                  [ORG 0] 
   107                                  
   108                                  START_CODE:
   109                                  	sys	_intr, 0  ; disable time-out function 
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000000 BB00000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000005 B81B000000          <1>  mov eax, %1
    98 0000000A CD30                <1>  int 30h
   110                                  	sys	_quit, 0  ; disable quit (ctrl+brk) signal
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000000C BB00000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000011 B81A000000          <1>  mov eax, %1
    98 00000016 CD30                <1>  int 30h
   111                                  
   112                                          sys	_open, ctty, 0 ; open tty0
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000018 BB[D2020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000001D B900000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000022 B805000000          <1>  mov eax, %1
    98 00000027 CD30                <1>  int 30h
   113 00000029 7252                    	jc	short error
   114                                  
   115                                          sys	_open, ctty, 1 ; for read and write
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000002B BB[D2020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000030 B901000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000035 B805000000          <1>  mov eax, %1
    98 0000003A CD30                <1>  int 30h
   116 0000003C 723F                    	jc	short error
   117                                  
   118                                  	sys	_write, 1, msg_te, sizeof_mte
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000003E BB01000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000043 B9[5A030000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 00000048 BA55000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000004D B804000000          <1>  mov eax, %1
    98 00000052 CD30                <1>  int 30h
   119 00000054 7227                            jc	short error
   120                                  i0:
   121                                  	sys	_read, 0, tchar, 1
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000056 BB00000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000005B B9[D0020000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 00000060 BA01000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000065 B803000000          <1>  mov eax, %1
    98 0000006A CD30                <1>  int 30h
   122 0000006C 720F                    	jc	short error
   123                                  
   124                                  	;sys	_close, 0 ; close input file/tty
   125                                  	;jc	short error
   126                                          ;sys	_close, 1 ; close output file/tty
   127                                  	;jc	short error
   128                                  
   129 0000006E A0[D0020000]            	mov	al, [tchar]
   130                                  
   131 00000073 3C0D                            cmp	al, EnterKey
   132 00000075 7479                    	je	short multiuser
   133                                  
   134 00000077 3C1B                    	cmp	al, ESCKey
   135 00000079 7428                    	je	short singleuser
   136                                  
   137 0000007B EBD9                    	jmp	short i0
   138                                  		
   139                                  error:
   140                                  	sys	_msg, error_msg, 255, 0Ch 
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000007D BB[CF030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000082 B9FF000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 00000087 BA0C000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000008C B823000000          <1>  mov eax, %1
    98 00000091 CD30                <1>  int 30h
   141                                  		; error message with red color (max. 255 chars)
   142                                  exit:
   143                                  	sys	_exit
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000093 B801000000          <1>  mov eax, %1
    98 00000098 CD30                <1>  int 30h
   144                                  
   145                                  haltsys:
   146                                  	;hlt
   147                                  	; 17/09/2015
   148 0000009A 90                      	nop
   149 0000009B 90                      	nop
   150 0000009C 90                      	nop
   151 0000009D 90                      	nop
   152 0000009E 90                      	nop
   153 0000009F 90                      	nop
   154 000000A0 90                      	nop
   155 000000A1 EBF7                    	jmp	short haltsys
   156                                  
   157                                  singleuser:
   158                                  i1:
   159                                  help:
   160                                  	sys	_close, 0 ; close input file/tty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000A3 BB00000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000A8 B806000000          <1>  mov eax, %1
    98 000000AD CD30                <1>  int 30h
   161                                  	;jc	short error
   162                                  	sys	_close, 1 ; close output file/tty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000AF BB01000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000B4 B806000000          <1>  mov eax, %1
    98 000000B9 CD30                <1>  int 30h
   163                                  	;jc	short error
   164                                  	sys	_open, ctty, 0 ; open control tty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000BB BB[D2020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000000C0 B900000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000C5 B805000000          <1>  mov eax, %1
    98 000000CA CD30                <1>  int 30h
   165                                  	;jc	short error
   166                                          sys	_open, ctty, 1 ; for read an write
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000CC BB[D2020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000000D1 B901000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000D6 B805000000          <1>  mov eax, %1
    98 000000DB CD30                <1>  int 30h
   167                                  	;jc	short error
   168                                  	;
   169                                  	sys	_exec, shell, shellp
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000DD BB[DC020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000000E2 B9[20030000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000E7 B80B000000          <1>  mov eax, %1
    98 000000EC CD30                <1>  int 30h
   170                                  	;
   171 000000EE EBB3                     	jmp	short i1
   172                                  
   173                                  multiuser:
   174                                  	sys	_close, 0 ; close input file/tty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000F0 BB00000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000000F5 B806000000          <1>  mov eax, %1
    98 000000FA CD30                <1>  int 30h
   175                                  	;jc	short error
   176                                          sys	_close, 1 ; close output file/tty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000000FC BB01000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000101 B806000000          <1>  mov eax, %1
    98 00000106 CD30                <1>  int 30h
   177                                  	;jc	short error
   178                                  	;
   179                                  	sys	_mount, fd1, usr
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000108 BB[EC020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000010D B9[E6020000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000112 B815000000          <1>  mov eax, %1
    98 00000117 CD30                <1>  int 30h
   180                                  			; root directory on mounted fd1
   181                                  			; disk is /usr
   182                                  	; 23/01/2022
   183                                  	; truncate /tmp/utmp 
   184                                  	sys	_creat, utmp, 1A4h ; Retro UNIX 386 1.2 
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000119 BB[F6020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000011E B9A4010000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000123 B808000000          <1>  mov eax, %1
    98 00000128 CD30                <1>  int 30h
   185                                  				   ; (runix v2 fs inode flags)
   186                                  	;sys	_creat, utmp, 14 ; Retro UNIX 386 v1.1
   187                                  	;jc	short error	 ; (unix v1 fs inode flags)
   188                                  
   189                                  	sys	_close, eax	; close it
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000012A 89C3                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000012C B806000000          <1>  mov eax, %1
    98 00000131 CD30                <1>  int 30h
   190                                  	
   191                                  	; 23/01/2022
   192 00000133 C605[04040000]78        	mov	byte [zero+8], 'x'
   193                                  	;mov	byte [zero+8], 0 ; put identifier
   194                                  				 ; in output buffer
   195                                  
   196 0000013A E840010000              	call	wtmprec	     ; go to (call) write acting info
   197                                  
   198                                  	; 23/10/2015
   199                                  	;
   200                                  	;; 10/12/2013
   201                                  	;; 'Enable Multi Tasking' (Time-Out)
   202                                  	;; system call (Retro UNIX 8086 v1 feature only !)
   203                                  	sys	_emt, 1
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000013F BB01000000          <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000144 B81D000000          <1>  mov eax, %1
    98 00000149 CD30                <1>  int 30h
   204                                  	;;
   205                                  
   206 0000014B BE[30030000]            	mov	esi, itab    ; address of table to ESI
   207                                  
   208                                  ; create shell processes
   209                                  i2:
   210 00000150 66AD                    	lodsw		     ; 'x', x=0, 1... to AX
   211 00000152 6621C0                  	and	ax, ax
   212 00000155 7412                    	jz	short pwait  ; branch if table end
   213                                  	
   214 00000157 A2[12030000]            	mov	[ttyx+8], al ; put symbol in ttyx
   215 0000015C 89F7                    	mov	edi, esi	
   216 0000015E E89A000000              	call	dfork        ; go to make new init for this ttyx
   217 00000163 66AB                    	stosw		     ; save child id in word offer
   218                                  	 		     ;	'0', '1',...etc.
   219 00000165 89FE                    	mov	esi, edi
   220 00000167 EBE7                    	jmp	short i2     ; set up next child
   221                                  
   222                                  ; wait for process to die
   223                                  pwait:
   224                                  	;sys	_write, 1, beep, 1 ; 10/12/2013
   225                                  	;
   226                                          sys	_wait       ; wait for user to terminate process
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000169 B807000000          <1>  mov eax, %1
    98 0000016E CD30                <1>  int 30h
   227 00000170 BE[30030000]            	mov	esi, itab   ; initialize for search
   228                                  	;mov	dx, ax
   229                                  	; 24/01/2022
   230 00000175 89C2                    	mov	edx, eax
   231                                  
   232                                  ; search for process id
   233                                  i3:
   234 00000177 66AD                    	lodsw		    ; bump ESI to child id location
   235 00000179 6609C0                  	or	ax, ax
   236 0000017C 74EB                    	jz	short pwait ; ? something silly
   237                                  
   238 0000017E 66AD                    	lodsw
   239                                  	; 24/01/2022
   240 00000180 39C2                    	cmp	edx, eax
   241                                  	;cmp	dx, ax      ; which process has terminated
   242 00000182 75F3                    	jne	short i3    ; not this one
   243                                  
   244                                  ; take name out of utmp
   245                                  	;mov	ecx, 4
   246                                  	; 24/01/2022
   247 00000184 31C9                    	xor 	ecx, ecx
   248 00000186 B104                    	mov	cl, 4
   249                                  	;sub	esi, 4	  ; process is found, point x to 'x'
   250                                  		          ; for it
   251 00000188 29CE                    	sub	esi, ecx  ; 4
   252                                  	;push	esi	  ; save address on stack
   253 0000018A 668B06                  	mov	ax, [esi] ; move 'x' to AX
   254                                  	; 24/01/2022
   255 0000018D 2C30                    	sub	al, '0'
   256                                  	;sub	ax, '0'   ; remove zone bits from character
   257                                  	;;shl	ax, 4	  ; generate proper offset for seek
   258 0000018F 66D3E0                  	shl	ax, cl	  ; 4
   259                                  	;movzx	edx, ax	
   260                                  	; 24/01/2022
   261 00000192 89C2                    	mov	edx, eax
   262 00000194 BF[FC030000]            	mov	edi, zero
   263 00000199 31C0                    	xor	eax, eax  ; 0 ; clear	
   264                                  	;mov	ecx, 4	  ; output buffer
   265 0000019B F3AB                    	rep	stosd	 
   266                                  	sys	_open, utmp, 1
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000019D BB[F6020000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000001A2 B901000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000001A7 B805000000          <1>  mov eax, %1
    98 000001AC CD30                <1>  int 30h
   267                                  			  ; open file for writing
   268 000001AE 722E                    	jc	short i4  ; if can't open, create user anyway
   269                                  	;movzx	edi, ax	  ; save file desc
   270                                  	; 24/01/2022
   271 000001B0 89C7                    	mov	edi, eax  ; save file descriptor	
   272                                  	sys	_seek, eax, edx, 0
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000001B2 89C3                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000001B4 89D1                <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 000001B6 BA00000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000001BB B813000000          <1>  mov eax, %1
    98 000001C0 CD30                <1>  int 30h
   273                                  			  ; move to proper pointer position
   274                                  	sys	_write, edi, zero, 16
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000001C2 89FB                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000001C4 B9[FC030000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 000001C9 BA10000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000001CE B804000000          <1>  mov eax, %1
    98 000001D3 CD30                <1>  int 30h
   275                                  			  ; zero this position in
   276                                  	sys	_close, edi
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000001D5 89FB                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000001D7 B806000000          <1>  mov eax, %1
    98 000001DC CD30                <1>  int 30h
   277                                  			  ; close file
   278                                  ; re-create user process
   279                                  i4:
   280                                  	;pop	esi	  ; restore 'x' to ESI
   281 000001DE 66AD                    	lodsw		  ; move it to AX
   282 000001E0 89F7                    	mov	edi, esi 
   283 000001E2 A2[12030000]            	mov	[ttyx+8], al ; get correct ttyx
   284 000001E7 A2[04040000]            	mov	[zero+8], al
   285                                  	 		  ; move identifier to output buffer
   286 000001EC E88E000000              	call	wtmprec   ; go to write accting into
   287 000001F1 E807000000              	call	dfork     ; fork
   288 000001F6 66AB                    	stosw		  ; save id of child
   289 000001F8 E96CFFFFFF              	jmp	pwait	  ; go to wait for next process end
   290                                  
   291                                  dfork:
   292 000001FD BB[0C020000]            	mov	ebx, i5 ; return address for new process
   293                                  	sys	_fork
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000202 B802000000          <1>  mov eax, %1
    98 00000207 CD30                <1>  int 30h
   294 00000209 72F2                    	jc	short dfork ; try again
   295 0000020B C3                      	retn
   296                                  
   297                                  i5: ; to new copy of init
   298                                  	;sys	_quit, 0  ; disable quit (ctrl+brk) signal
   299                                  	;sys	_intr, 0  ; disable time-out function 
   300                                  	;sys	_chown, ttyx, 0
   301                                  	;;sys	_chmod; ttyx, 15
   302                                  	;sys	_chmod; ttyx, 13 ; 23/01/2022
   303                                  o0:	
   304 0000020C 31DB                    	xor	ebx, ebx
   305                                  	;xor	ch, ch
   306                                  	;mov	cl, [ttyx+8]
   307 0000020E 0FB60D[12030000]        	movzx	ecx, byte [ttyx+8]
   308 00000215 80E930                  	sub	cl, '0'
   309                                  	; 17/01/2014
   310                                  	; 07/12/2013
   311                                  	; set console tty for current process
   312                                  	;mov	dx, 0FF00h
   313                                  	;mov	dh, 0FFh ; do not set cursor position
   314                                  		     ; do not set serial port parameters	
   315 00000218 BA00FF0000              	mov	edx, 0FF00h	
   316                                  	sys	_stty
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000021D B81F000000          <1>  mov eax, %1
    98 00000222 CD30                <1>  int 30h
   317 00000224 724D                            jc	short terminate
   318                                  o1:
   319                                  	; 16/11/2015	
   320                                  	sys	_open, ttyx, 0 ; open this ttyx for reading
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000226 BB[0A030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000022B B900000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000230 B805000000          <1>  mov eax, %1
    98 00000235 CD30                <1>  int 30h
   321                                  	;jnc	short o2
   322                                  	;call	wait_for_terminal
   323                                  	;jmp	short o1
   324                                  	; 17/11/2015
   325 00000237 723A                    	jc	short terminate	
   326                                  o2:
   327                                  	; 16/11/2015
   328                                  	sys	_open, ttyx, 1 ; open this ttyx for writing
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 00000239 BB[0A030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 0000023E B901000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000243 B805000000          <1>  mov eax, %1
    98 00000248 CD30                <1>  int 30h
   329                                  	;jnc	short o3
   330                                  	;call	wait_for_terminal
   331                                  	;jmp	short o2
   332                                  	; 17/11/2015
   333 0000024A 7227                    	jc	short terminate			
   334                                  o3:	
   335                                  	sys	_exec, getty, gettyp ; getty types <login> and
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000024C BB[14030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000251 B9[28030000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000256 B80B000000          <1>  mov eax, %1
    98 0000025B CD30                <1>  int 30h
   336                                  				; executes login which logs user
   337                                  				; in and executes sh-
   338                                  	; 14/10/2015
   339                                  	sys	_msg, getty_error_msg, 255, 0Ch 
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000025D BB[E5030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000262 B9FF000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 00000267 BA0C000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000026C B823000000          <1>  mov eax, %1
    98 00000271 CD30                <1>  int 30h
   340                                  				; error msg with red color
   341                                  terminate:
   342                                  	sys	_exit  ; HELP!
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000273 B801000000          <1>  mov eax, %1
    98 00000278 CD30                <1>  int 30h
   343                                  ;help1:
   344 0000027A E924FEFFFF              	jmp	help
   345                                  
   346                                  ;wait_for_terminal:
   347                                  ;	; 16/11/2015
   348                                  ;	; 24/10/2015
   349                                  ;	mov	al, [ttyx+8]
   350                                  ;	sub	al, '0'
   351                                  ;	cmp	al, 8
   352                                  ;	jb	short sysexit
   353                                  ;	sys	_sleep
   354                                  ;	retn
   355                                  ;sysexit:
   356                                  ;	pop	eax ;return address	
   357                                  ;	jmp	short terminate
   358                                  
   359                                  wtmprec:
   360                                  	; 24/01/2022
   361                                  	; 23/10/2015 (wtmp_err)
   362                                  	;cmp	byte [wtmp_err], 0
   363                                  	;ja	short i6 	
   364                                  
   365                                  	sys	_time  ; get time
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89                              <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 0000027F B80D000000          <1>  mov eax, %1
    98 00000284 CD30                <1>  int 30h
   366 00000286 A3[06040000]            	mov	[zero+10], eax ; move to output buffer
   367                                  
   368                                  	sys	_open, wtmp, 1 ; open accounting file
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 0000028B BB[00030000]        <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 00000290 B901000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 00000295 B805000000          <1>  mov eax, %1
    98 0000029A CD30                <1>  int 30h
   369                                  	;jc	short i7
   370                                  	; 24/01/2022
   371 0000029C 7231                    	jc	short i6
   372                                  
   373 0000029E 89C6                    	mov	esi, eax ; save file descriptor
   374                                  
   375                                  	sys	_seek, eax, 0, 2 ; move pointer to end of file
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000002A0 89C3                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000002A2 B900000000          <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 000002A7 BA02000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000002AC B813000000          <1>  mov eax, %1
    98 000002B1 CD30                <1>  int 30h
   376                                  	;;push	esi    ; save file descriptor
   377                                  	;jc	short i7
   378                                  
   379                                  	sys	_write, esi, zero, 16 ; write accting info
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000002B3 89F3                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91 000002B5 B9[FC030000]        <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93 000002BA BA10000000          <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000002BF B804000000          <1>  mov eax, %1
    98 000002C4 CD30                <1>  int 30h
   380                                  	;;pop	ebx	  ; restore file descriptor
   381                                  	;jc	short i7
   382                                  
   383                                  	sys	_close, esi ; close file
    85                              <1> 
    86                              <1> 
    87                              <1> 
    88                              <1>  %if %0 >= 2
    89 000002C6 89F3                <1>  mov ebx, %2
    90                              <1>  %if %0 >= 3
    91                              <1>  mov ecx, %3
    92                              <1>  %if %0 = 4
    93                              <1>  mov edx, %4
    94                              <1>  %endif
    95                              <1>  %endif
    96                              <1>  %endif
    97 000002C8 B806000000          <1>  mov eax, %1
    98 000002CD CD30                <1>  int 30h
   384                                  i6:
   385 000002CF C3                      	retn
   386                                  ;i7:
   387                                  	;inc	byte [wtmp_err] ; 23/10/2015
   388                                  	;retn
   389                                  
   390                                  ; 23/01/2022
   391                                  ;here:
   392                                  ;	hlt	; General Protection Fault ! 17/09/2015
   393                                  ;	;jmp	short here
   394                                  ;	jmp	haltsys	
   395                                  
   396                                  align 2
   397 000002D0 00                      tchar:  db 0
   398 000002D1 90                      align 2
   399 000002D2 2F6465762F74747900      ctty:   db "/dev/tty", 0
   400 000002DB 90                      align 2
   401 000002DC 2F62696E2F736800        shell:  db "/bin/sh", 0
   402 000002E4 2D00                    shellm: db "-", 0
   403                                  ;align 2
   404 000002E6 2F75737200              usr:	db "/usr",0
   405 000002EB 90                      align 2
   406 000002EC 2F6465762F66643100      fd1:	db "/dev/fd1", 0
   407                                  ;
   408 000002F5 90                      align 2
   409 000002F6 2F746D702F75746D70-     utmp:   db "/tmp/utmp", 0
   409 000002FF 00                 
   410 00000300 2F746D702F77746D70-     wtmp:   db "/tmp/wtmp", 0
   410 00000309 00                 
   411 0000030A 2F6465762F74747978-     ttyx:   db "/dev/ttyx", 0
   411 00000313 00                 
   412 00000314 2F6574632F67657474-     getty:  db "/etc/getty",0
   412 0000031D 7900               
   413                                  
   414 0000031F 90                      align 2
   415                                  ; 27/08/2015 (dw -> dd)
   416 00000320 [E4020000]              shellp: dd shellm
   417 00000324 00000000                        dd 0
   418 00000328 [14030000]              gettyp: dd getty
   419 0000032C 00000000                	dd 0
   420                                  itab:
   421 00000330 30000000                	db '0',0, 0,0
   422 00000334 31000000                	db '1',0, 0,0
   423 00000338 32000000                	db '2',0, 0,0
   424 0000033C 33000000                	db '3',0, 0,0
   425 00000340 34000000                	db '4',0, 0,0
   426 00000344 35000000                	db '5',0, 0,0
   427 00000348 36000000                	db '6',0, 0,0
   428 0000034C 37000000                	db '7',0, 0,0
   429                                  	; serial ports (COM1, COM2)
   430 00000350 38000000                	db '8',0, 0,0
   431 00000354 39000000                	db '9',0, 0,0
   432 00000358 0000                    	dw 0
   433                                  
   434                                  ;-----------------------------------------------------------------
   435                                  ;  messages
   436                                  ;-----------------------------------------------------------------
   437                                  
   438                                  msg_te:
   439 0000035A 0D0A                            db 0Dh, 0Ah
   440 0000035C 5479706520454E5445-             db 'Type ENTER to start in multi user mode', 0Dh, 0Ah
   440 00000365 5220746F2073746172-
   440 0000036E 7420696E206D756C74-
   440 00000377 692075736572206D6F-
   440 00000380 64650D0A           
   441 00000384 6F7220747970652045-             db 'or type ESC to start in single user mode.'
   441 0000038D 534320746F20737461-
   441 00000396 727420696E2073696E-
   441 0000039F 676C65207573657220-
   441 000003A8 6D6F64652E         
   442 000003AD 0D0A                            db 0Dh, 0Ah
   443                                  sizeof_mte equ $ - msg_te 
   444 000003AF 00                              db 0
   445                                  copy_right_msg:
   446 000003B0 286329204572646F67-     	db  '(c) Erdogan TAN - 24/01/2022'
   446 000003B9 616E2054414E202D20-
   446 000003C2 32342F30312F323032-
   446 000003CB 32                 
   447 000003CC 0D0A00                  	db  0Dh, 0Ah, 0
   448                                  error_msg:
   449 000003CF 0D0A07                  	db 0Dh, 0Ah, 07h
   450 000003D2 2F6574632F696E6974-     	db '/etc/init error ! '
   450 000003DB 206572726F72202120 
   451 000003E4 00                      	db 0
   452                                  
   453                                  getty_error_msg:
   454                                  	; 14/10/2015
   455 000003E5 0D0A07                  	db 0Dh, 0Ah, 07h
   456 000003E8 2F6574632F67657474-     	db '/etc/getty error ! '
   456 000003F1 79206572726F722021-
   456 000003FA 20                 
   457 000003FB 00                      	db 0
   458                                  
   459                                  ; 23/10/2015
   460                                  align 2
   461                                  zero:
   462 000003FC 00<rep 8h>              	times 8 db 0
   463 00000404 00<rep 6h>              	times 6 db 0
   464 0000040A 00<rep 2h>              	times 2 db 0	 
   465                                  
   466                                  wtmp_err:
   467 0000040C 00                      	db 0
   468                                  
   469                                  ; 23/01/2022
   470                                  	
   471                                  ;-----------------------------------------------------------------
   472                                  ; Original UNIX v1 - /etc/init source code (init.s)
   473                                  ;		     in PDP-11 (unix) assembly language
   474                                  ;-----------------------------------------------------------------
   475                                  
   476                                  ;/ init -- process control initialization
   477                                  ;
   478                                  ;mount = 21.
   479                                  ;
   480                                  ;	sys	intr; 0 / turn off interrupts
   481                                  ;	sys 	quit; 0
   482                                  ;	cmp	csw,$73700 / single user?
   483                                  ;	bne	1f / no
   484                                  ;help:
   485                                  ;	clr	r0 / yes
   486                                  ;	sys	close / close current read
   487                                  ;	mov	$1,r0 / and write
   488                                  ;	sys	close / files
   489                                  ;	sys	open; ctty; 0 / open control tty
   490                                  ;	sys	open; ctty; 1 / for read and write
   491                                  ;	sys	exec; shell; shellp / execute shell
   492                                  ;	br	help / keep trying
   493                                  ;1:
   494                                  ;	mov	$'0,r1 / prepare to change
   495                                  ;1 :
   496                                  ;	movb	r1,tapx+8 / mode of dec tape drive x, where
   497                                  ;	sys	chmod; tapx; 17 / x=0 to 7, to read/write by owner or
   498                                  ;	inc	r1 / non-owner mode
   499                                  ;	cmp	r1,$'8 / finished?
   500                                  ;	blo	1b / no
   501                                  ;	sys	mount; rk0; usr / yes, root file on mounted rko5
   502                                  ;				/ disk ls /usr
   503                                  ;	sys	creat; utmp; 16 / truncate /tmp/utmp
   504                                  ;	sys	close / close it
   505                                  ;	movb	$'x,zero+8. / put identifier in output buffer
   506                                  ;	jsr	pc,wtmprec / go to write accting info
   507                                  ;	mov	$itab,r1 / address of table to r1
   508                                  ;
   509                                  ;/ create shell processes
   510                                  ;
   511                                  ;1:
   512                                  ;	mov	(r1)+,r0 / 'x, x=0, 1... to r0
   513                                  ;	beq	1f / branch if table end
   514                                  ;	movb	r0,ttyx+8 / put symbol in ttyx
   515                                  ;	jsr	pc,dfork / go to make new init for this ttyx
   516                                  ;	mov	r0,(r1)+ / save child id in word offer '0, '1,...etc.
   517                                  ;	br	1b / set up next child
   518                                  ;
   519                                  ;/ wait for process to die
   520                                  ;
   521                                  ;1:
   522                                  ;	sys	wait / wait for user to terminate process
   523                                  ;	mov	$itab,r1 / initialize for search
   524                                  ;
   525                                  ;/ search for process id
   526                                  ;
   527                                  ;2:
   528                                  ;	tst	(r1)+ / bump r1 to child id location
   529                                  ;	beq	1b / ? something silly
   530                                  ;	cmp	r0,(r1)+ / which process has terminated
   531                                  ;	bne	2b / not this one
   532                                  ;
   533                                  ;/ take name out of utmp
   534                                  ;
   535                                  ;	sub	$4, r1 / process is found, point x' to 'x
   536                                  ;		       / for it
   537                                  ;	mov	r1,-(sp) / save address on stack
   538                                  ;	mov	(r1),r1 / move 'x to r1
   539                                  ;	sub	$'0,r1 / remove zone bits from character
   540                                  ;	asl	r1 / generate proper
   541                                  ;	asl	r1 / offset
   542                                  ;	asl	r1 / for
   543                                  ;	asl	r1 / seek
   544                                  ;	mov	r1,0f / move it to offset loc for seek
   545                                  ;	mov	$zero,r1
   546                                  ;2:
   547                                  ;	clr	(r1)+ / ccear-
   548                                  ;	cmp	r1,$zero+16. / output buffer
   549                                  ;	blo	2b / area
   550                                  ;	sys	open; utmp; 1 / open file for writing
   551                                  ;	bes	2f / if can't open, create user anyway
   552                                  ;	mov	r0,r1 / save file desc
   553                                  ;	sys	seek; 0:..; 0 / move to proper pointer position
   554                                  ;	mov	r1,r0 / not required
   555                                  ;	sys	write; zero; 16. / zero this position in
   556                                  ;	mov	r1,r0 / restore file descriptor
   557                                  ;	sys	close / close file
   558                                  ;
   559                                  ;/ re-create user process
   560                                  ;
   561                                  ;2:
   562                                  ;	mov	(sp)+,r1 / restore 'x to r1
   563                                  ;	mov	(r1)+,r0 / move it to r0
   564                                  ;	movb	r0,ttyx+8 / get correct ttyx
   565                                  ;	movb	r0,zero+8 / move identifier to output buffer
   566                                  ;	jsr	pc,wtmprec / go to write accting into
   567                                  ;	jsr	pc,dfork / fork
   568                                  ;	mov	r0,(r1)+ / save id of child
   569                                  ;	br	1b / go to wait for next process end
   570                                  ;
   571                                  ;dfork:
   572                                  ;	mov	r1,r2
   573                                  ;	sub	$itab+2,r2 / left over
   574                                  ;	asl	r2 / from previous
   575                                  ;	asl	r2 / version of code
   576                                  ;	mov	r2,offset
   577                                  ;	sys	fork
   578                                  ;		br 1f / to new copy of init
   579                                  ;	bes	dfork / try again
   580                                  ;	rts	pc / return
   581                                  ;1 :
   582                                  ;	sys	quit; 0 / new init turns off
   583                                  ;	sys	intr; 0 / interrupts
   584                                  ;	sys	chown; ttyx; 0 / change owner to super user
   585                                  ;	sys	chmod; ttyx; 15 / changemode to read/write owner,
   586                                  ;				/ write non-owner
   587                                  ;	sys	open; ttyx; 0 / open this ttyx for reading
   588                                  ;			      / and wait until someone calls
   589                                  ;	bes	help1 / branch if trouble
   590                                  ;	sys	open; ttyx; 1 / open this ttyx for writing after
   591                                  ;			      / user call
   592                                  ;	bes	help1 / branch if trouble
   593                                  ;	sys	exec; getty; gettyp / getty types <login> and
   594                                  ;				    / executes login which logs user
   595                                  ;				    / in and executes sh-
   596                                  ;	sys	exit / HELP!
   597                                  ;
   598                                  ;help1:
   599                                  ;	jmp	help / trouble
   600                                  ;
   601                                  ;wtmprec:
   602                                  ;	sys	time / get time
   603                                  ;	mov	ac,zero+10. / more to output
   604                                  ;	mov	mq,zero+12. / buffer
   605                                  ;	sys	open; wtmp; 1 / open accounting file
   606                                  ;	bes	2f
   607                                  ;	mov	r0,r2 / save file descriptor
   608                                  ;	sys	seek; 0; 2 / move pointer to end of file
   609                                  ;	mov	r2,r0 / not required
   610                                  ;	sys	write; zero; 16. / write accting info
   611                                  ;	mov	r2,r0 / restore file descriptor
   612                                  ;	sys	close / close file
   613                                  ;2:
   614                                  ;	rts	pc
   615                                  ;
   616                                  ;ctty:	</dev/tty\0>
   617                                  ;shell:	</bin/sh\0>
   618                                  ;shellm: <-\0>
   619                                  ;tapx:	</dev/tapx\0>
   620                                  ;rk0:	</dev/rk0\0>
   621                                  ;utmp:	</tmp/utmp\0>
   622                                  ;wtmp:	</tmp/wtmp\0>
   623                                  ;ttyx:	</dev/ttyx\0>
   624                                  ;getty:	</etc/getty\0>
   625                                  ;usr:	</usr\0>
   626                                  ;	.even
   627                                  ;
   628                                  ;shellp: shellm
   629                                  ;	0
   630                                  ;gettyp: getty
   631                                  ;	0
   632                                  ;itab:
   633                                  ;	'0; ..
   634                                  ;	'1; ..
   635                                  ;	'2; ..
   636                                  ;	'3; ..
   637                                  ;	'4; ..
   638                                  ;	'5; ..
   639                                  ;	'6; ..
   640                                  ;	'7; ..
   641                                  ;	0
   642                                  ;
   643                                  ;offset: .=.+2
   644                                  ;zero:	 .=.+8; .=.+6; .=.+2
   645                                  
   646                                  ; 23/01/2022
   647                                  
   648                                  ;-----------------------------------------------------------------
   649                                  ; Original UNIX v2 - /etc/init source code (init.s)
   650                                  ;		     in PDP-11 (unix) assembly language
   651                                  ;-----------------------------------------------------------------
   652                                  
   653                                  ; / init -- process control initialization
   654                                  ;
   655                                  ;	sys	intr; 0
   656                                  ;	sys	quit; 0
   657                                  ;	sys	38. / get console switches
   658                                  ;	cmp	r0,$173030
   659                                  ;	bne	1f
   660                                  ;help:
   661                                  ;	clr	r0
   662                                  ;	sys	close
   663                                  ;	mov	$1,r0
   664                                  ;	sys	close
   665                                  ;	sys	open; ctty; 0
   666                                  ;	sys	open; ctty; 1
   667                                  ;	sys	exec; shell; shellp
   668                                  ;	br	help
   669                                  ;1:
   670                                  ;	sys	mount; rk1; usr
   671                                  ;	sys	mount; rk2; ssys
   672                                  ;	sys	mount; rk3; crp
   673                                  ;	mov	$'0,r1
   674                                  ;1:
   675                                  ;	movb	r1,tapx+8
   676                                  ;	sys	chmod; tapx; 17
   677                                  ;	inc	r1
   678                                  ;	cmp	r1,$'8
   679                                  ;	blo	1b
   680                                  ;	sys	creat; utmp; 16
   681                                  ;	sys	close
   682                                  ;	sys	unlink; dpdlock
   683                                  ;	sys	fork
   684                                  ;		br daemon
   685                                  ;	sys	fork
   686                                  ;		br dirass
   687                                  ;	sys	fork
   688                                  ;		br dds
   689                                  ;	movb	$'x,zero+8.
   690                                  ;	jsr	pc,wtmprec
   691                                  ;	mov	$itab,r1
   692                                  ;	br	1f
   693                                  ;
   694                                  ;daemon:
   695                                  ;	sys	exec; etcdpd; etcdpdp
   696                                  ;	sys	exit
   697                                  ;
   698                                  ;dirass:
   699                                  ;	sys	chdir; usrmel
   700                                  ;	sys	exec; melda; meldap
   701                                  ;	sys	exit
   702                                  ;
   703                                  ;dds:
   704                                  ;	sys	exec; usrdd; usrddp
   705                                  ;	sys	exit
   706                                  ;
   707                                  ;/ create shell processes
   708                                  ;
   709                                  ;1:
   710                                  ;	mov	(r1)+,r0
   711                                  ;	beq	pwait
   712                                  ;	movb	r0,ttyx+8
   713                                  ;	jsr	pc,dfork
   714                                  ;	mov	r0,(r1)+
   715                                  ;	br	1b
   716                                  ;
   717                                  ;/ wait for process to die
   718                                  ;
   719                                  ;pwait:
   720                                  ;	sys	wait
   721                                  ;	mov	$itab,r1
   722                                  ;
   723                                  ;/ search for process id
   724                                  ;
   725                                  ;2:
   726                                  ;	tst	(r1)+
   727                                  ;	beq	pwait
   728                                  ;	cmp	r0,(r1)+
   729                                  ;	bne	2b
   730                                  ;
   731                                  ;/ take name out of utmp
   732                                  ;
   733                                  ;	sub	$4,r1
   734                                  ;	mov	r1,-(sp)
   735                                  ;	mov	(r1),r1
   736                                  ;	sub	$'0,r1
   737                                  ;	cmp	r1,$'a-'0
   738                                  ;	blo	2f
   739                                  ;	sub	$'a-'0-10.,r1	/ map a-z into 10. on
   740                                  ;2:
   741                                  ;	asl	r1
   742                                  ;	asl	r1
   743                                  ;	asl	r1
   744                                  ;	asl	r1
   745                                  ;	mov	r1,0f
   746                                  ;	mov	$zero,r1
   747                                  ;2:
   748                                  ;	clr	(r1)+
   749                                  ;	cmp	r1,$zero+16.
   750                                  ;	blo	2b
   751                                  ;	sys	open; utmp; 1
   752                                  ;	bes	2f
   753                                  ;	mov	r0,r1
   754                                  ;	sys	seek; 0:..; 0
   755                                  ;	mov	r1,r0
   756                                  ;	sys	write; zero; 16.
   757                                  ;	mov	r1,r0
   758                                  ;	sys	close
   759                                  ;
   760                                  ;/ re-create user process
   761                                  ;
   762                                  ;2:
   763                                  ;	mov	(sp)+,r1
   764                                  ;	mov	(r1)+,r0
   765                                  ;	movb	r0,ttyx+8
   766                                  ;	movb	r0,zero+8.
   767                                  ;	jsr	pc,wtmprec
   768                                  ;	jsr	pc,dfork
   769                                  ;	mov	r0,(r1)+
   770                                  ;	br	pwait
   771                                  ;
   772                                  ;dfork:
   773                                  ;	sys	fork
   774                                  ;		br 1f
   775                                  ;	bes	dfork
   776                                  ;	rts	pc
   777                                  ;1:
   778                                  ;	sys	quit; 0
   779                                  ;	sys	intr; 0
   780                                  ;	sys	chown; ttyx; 0
   781                                  ;	sys	chmod; ttyx; 15
   782                                  ;	sys	open; ttyx; 0
   783                                  ;	bes	help1
   784                                  ;	sys	open; ttyx; 1
   785                                  ;	bes	help1
   786                                  ;	sys	exec; getty; gettyp
   787                                  ;	sys	exit			/ HELP!
   788                                  ;
   789                                  ;help1:
   790                                  ;	jmp	help
   791                                  ;
   792                                  ;wtmprec:
   793                                  ;	mov	r1,-(sp)
   794                                  ;	sys	time
   795                                  ;	mov	r0,zero+10.
   796                                  ;	mov	r1,zero+12.
   797                                  ;	sys	open; wtmp; 1
   798                                  ;	bes	2f
   799                                  ;	mov	r0,r2
   800                                  ;	sys	seek; 0; 2
   801                                  ;	mov	r2,r0
   802                                  ;	sys	write; zero; 16.
   803                                  ;	mov	r2,r0
   804                                  ;	sys	close
   805                                  ;2:
   806                                  ;	mov	(sp)+,r1
   807                                  ;	rts	pc
   808                                  ;
   809                                  ;etcdpdp:
   810                                  ;	etcdpd; 0
   811                                  ;meldap:
   812                                  ;	melda; 0
   813                                  ;usrddp:
   814                                  ;	usrdd; 0
   815                                  ;usrdd:	</usr/demo/dds\0>
   816                                  ;melda:	</usr/mel/da\0>
   817                                  ;usrmel:</usr/mel\0>
   818                                  ;rk1:	</dev/rk1\0>
   819                                  ;rk2:	</dev/rk2\0>
   820                                  ;rk3:	</dev/rk3\0>
   821                                  ;usr:	</usr\0>
   822                                  ;ssys:	</sys\0>
   823                                  ;crp:	</crp\0>
   824                                  ;ctty:	</dev/tty\0>
   825                                  ;shell:	</bin/sh\0>
   826                                  ;shellm:<-\0>
   827                                  ;dpdlock:
   828                                  ;	</usr/dpd/lock\0>
   829                                  ;etcdpd:
   830                                  ;	</etc/dpd\0>
   831                                  ;tapx:	</dev/tapx\0>
   832                                  ;utmp:	</tmp/utmp\0>
   833                                  ;wtmp:	</tmp/wtmp\0>
   834                                  ;ttyx:	</dev/ttyx\0>
   835                                  ;getty:	</etc/getty\0>
   836                                  ;	.even
   837                                  ;
   838                                  ;shellp:shellm
   839                                  ;	0
   840                                  ;gettyp:getty
   841                                  ;	0
   842                                  ;itab:
   843                                  ;	'0; ..
   844                                  ;	'1; ..
   845                                  ;	'2; ..
   846                                  ;	'3; ..
   847                                  ;	'4; ..
   848                                  ;	'5; ..
   849                                  ;	'6; ..
   850                                  ;	'7; ..
   851                                  ;	'8; ..
   852                                  ;	'a; ..
   853                                  ;	'b; ..
   854                                  ;	 0
   855                                  ;
   856                                  ;	.bss
   857                                  ;offset:.=.+2
   858                                  ;zero:	.=.+8.; .=.+6; .=.+2.
