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