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