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