1 ; **************************************************************************** 2 ; passwd386.s (passwd1.s) - by Erdogan Tan - 30/04/2022 3 ; ---------------------------------------------------------------------------- 4 ; Retro UNIX 386 v1 (& v1.1) - passwd - change user's password 5 ; 6 ; [ Last Modification: 01/05/2022 ] 7 ; 8 ; Derived from (original) UNIX v5 'passwd.s' source Code 9 ; Ref: 10 ; www.tuhs.org (https://minnie.tuhs.org) 11 ; v5root.tar.gz 12 ; **************************************************************************** 13 ; [ usr/source/s2/passwd.s (archive date: 27-11-1974) ] 14 15 ; passwd0.s - Retro UNIX 8086 v1 (16 bit version of 'passwd1.s') 16 ; passwd1.s - Retro UNIX 386 v1 & v1.1 (unix v1 inode structure) 17 ; passwd2.s - Retro UNIX 386 v1.2 (& v2) (modified unix v7 inode) 18 19 ; UNIX v1 system calls 20 _rele equ 0 21 _exit equ 1 22 _fork equ 2 23 _read equ 3 24 _write equ 4 25 _open equ 5 26 _close equ 6 27 _wait equ 7 28 _creat equ 8 29 _link equ 9 30 _unlink equ 10 31 _exec equ 11 32 _chdir equ 12 33 _time equ 13 34 _mkdir equ 14 35 _chmod equ 15 36 _chown equ 16 37 _break equ 17 38 _stat equ 18 39 _seek equ 19 40 _tell equ 20 41 _mount equ 21 42 _umount equ 22 43 _setuid equ 23 44 _getuid equ 24 45 _stime equ 25 46 _quit equ 26 47 _intr equ 27 48 _fstat equ 28 49 _emt equ 29 50 _mdate equ 30 51 _stty equ 31 52 _gtty equ 32 53 _ilgins equ 33 54 _sleep equ 34 ; Retro UNIX 8086 v1 feature only ! 55 _msg equ 35 ; Retro UNIX 386 v1 feature only ! 56 57 ;;; 58 ESCKey equ 1Bh 59 EnterKey equ 0Dh 60 61 %macro sys 1-4 62 ; 03/09/2015 63 ; 13/04/2015 64 ; Retro UNIX 386 v1 system call. 65 %if %0 >= 2 66 mov ebx, %2 67 %if %0 >= 3 68 mov ecx, %3 69 %if %0 = 4 70 mov edx, %4 71 %endif 72 %endif 73 %endif 74 mov eax, %1 75 int 30h 76 %endmacro 77 78 ; Retro UNIX 386 v1 system call format: 79 ; sys systemcall (eax) , , 80 81 [BITS 32] ; 32-bit intructions (for 80386 protected mode) 82 83 [ORG 0] 84 85 START_CODE: 86 ; 01/05/2022 87 ; 30/04/2022 88 89 ;cmp (sp)+,$3 90 ;bge 1f 91 ;jsr r5,mesg 92 ; ; .even 93 ;sys exit 94 95 00000000 58 pop eax ; eax = number of arguments 96 97 ;cmp eax, 3 98 00000001 3C03 cmp al, 3 99 00000003 7311 jnb short pswd_1 100 101 00000005 B8[23040000] mov eax, usage_msg 102 0000000A E804020000 call print_msg 103 exit: 104 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 0000000F B801000000 <1> mov eax, %1 75 00000014 CD30 <1> int 30h 105 ;hang: 106 ; nop 107 ; jmp short hang 108 109 pswd_1: 110 ;1: 111 ;tst (sp)+ 112 ;mov (sp)+,uidp 113 ;mov (sp)+,r0 114 ;tstb (r0) 115 ;beq 1f 116 ;jsr pc,crypt 117 ;clrb 8(r0) 118 119 00000016 58 pop eax ; argument 0 - binary file name 120 121 00000017 8F05[C40F0000] pop dword [uidp] ; argument 1 - user id 122 0000001D 5E pop esi ; argument 2 - password 123 124 ; 01/05/2022 125 0000001E E812020000 call strlen 126 00000023 3C08 cmp al, 8 127 00000025 7733 ja short max_8_chars 128 129 00000027 E813020000 call crypt 130 ; esi = encyrpted password address 131 0000002C C6460800 mov byte [esi+8], 0 132 pswd_2: 133 ;1: 134 ;mov r0,cryptp 135 ;mov $passwf,r0 136 ;jsr r5,fopen; ibuf 137 ;bec 1f 138 ;jsr r5,mesg 139 ; ; .even 140 ;sys exit 141 142 00000030 8935[C00F0000] mov [cryptp], esi 143 144 sys _open, passwf, 0 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000036 BB[0D040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000003B B900000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000040 B805000000 <1> mov eax, %1 75 00000045 CD30 <1> int 30h 145 00000047 7318 jnc short pswd_3 146 147 00000049 B8[42040000] mov eax, cant_open_msg 148 write_msg_and_exit: 149 0000004E E8C0010000 call print_msg 150 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000053 B801000000 <1> mov eax, %1 75 00000058 CD30 <1> int 30h 151 152 ;hangemhigh: 153 ; nop 154 ; jmp short hangemhigh 155 156 max_8_chars: 157 0000005A B8[06050000] mov eax, long_pswd_msg 158 0000005F EBED jmp short write_msg_and_exit 159 160 pswd_3: 161 ;1: 162 ; 30/04/2022 163 ;mov [ibuf], ax ; file descriptor 164 00000061 A3[B00B0000] mov [ibuf], eax ; file descriptor 165 pswd_4: 166 ;sys stat; tempf; obuf+20. 167 ;bec 2f 168 ;sys creat; tempf; 222 169 ;bec 1f 170 171 sys _stat, tempf, obuf+20 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000066 BB[19040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000006B B9[CC0D0000] <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000070 B812000000 <1> mov eax, %1 75 00000075 CD30 <1> int 30h 172 00000077 7313 jnc short pswd_5 173 174 ; set write permission only 175 sys _creat, tempf, 101b ; unix v1 inode 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000079 BB[19040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000007E B905000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000083 B808000000 <1> mov eax, %1 75 00000088 CD30 <1> int 30h 176 ;sys _creat, tempf, 10010010b ; runix v2 inode 177 0000008A 7307 jnc short pswd_6 178 pswd_5: 179 ;2: 180 ;jsr r5,mesg 181 ; ; .even 182 ;sys exit 183 184 0000008C B8[60040000] mov eax, tmpf_bsy_msg 185 00000091 EBBB jmp short write_msg_and_exit 186 187 pswd_6: 188 ;1: 189 ;mov r0,obuf 190 191 ;mov [obuf], ax ; file descriptor 192 00000093 A3[B80D0000] mov [obuf], eax ; file descriptor 193 194 ; / search for uid 195 196 comp: 197 ;mov uidp,r1 198 00000098 8B35[C40F0000] mov esi, [uidp] ; 01/05/2022 199 cmp_1: 200 ;1: 201 ;jsr pc,pcop 202 ;cmp r0,$': 203 ;beq 1f 204 ;cmpb r0,(r1)+ 205 ;beq 1b 206 207 0000009E E84B010000 call pcop 208 000000A3 3C3A cmp al, ':' 209 000000A5 7417 je short cmp_3 210 000000A7 88C4 mov ah, al 211 000000A9 AC lodsb 212 000000AA 38E0 cmp al, ah 213 000000AC 74F0 je short cmp_1 214 cmp_2: 215 ;2: 216 ;jsr pc,pcop 217 ;cmp r0,$'\n 218 ;bne 2b 219 ;br comp 220 221 000000AE E83B010000 call pcop 222 ; (skip remain bytes on row, get next line/row) 223 ; check cr byte of crlf (end of line chars) 224 000000B3 3C0D cmp al, EnterKey ; cmp al, 0Dh 225 000000B5 75F7 jne short cmp_2 226 ; get lf byte of crlf out 227 000000B7 E832010000 call pcop 228 000000BC EBDA jmp short comp ; next line 229 230 cmp_3: 231 ;1: 232 ;tstb (r1)+ 233 ;bne 2b 234 235 ; check end of uid input (match condition) 236 000000BE AC lodsb 237 000000BF 08C0 or al, al 238 000000C1 75EB jnz short cmp_2 ; uid is not same 239 ; skip remain bytes on line/row 240 241 ; uid (input) matches with uid in passwd file 242 243 ; / skip over old password 244 245 pswd_7: 246 ;1: 247 ;jsr pc,pget 248 ;cmp r0,$': 249 ;bne 1b 250 251 000000C3 E80F010000 call pget 252 000000C8 3C3A cmp al, ':' 253 000000CA 75F7 jne short pswd_7 254 255 ; / copy in new password 256 257 ;mov cryptp,r1 258 000000CC 8B35[C00F0000] mov esi, [cryptp] ; ptr to encyrpted passwd 259 pswd_8: 260 ;1: 261 ;movb (r1)+,r0 262 ;beq 1f 263 ;jsr pc,pput 264 ;br 1b 265 266 000000D2 AC lodsb 267 000000D3 20C0 and al, al 268 000000D5 7407 jz short pswd_9 269 000000D7 E8F6000000 call pput 270 000000DC EBF4 jmp short pswd_8 271 pswd_9: 272 ;1: 273 ;mov $':,r0 274 ;jsr pc,pput 275 276 000000DE B03A mov al, ':' 277 000000E0 E8ED000000 call pput 278 279 ; / validate permission 280 281 ;clr r1 282 000000E5 29C9 sub ecx, ecx ; 0 283 000000E7 BF0A000000 mov edi, 10 284 pswd_10: 285 ;1: 286 ;jsr pc,pcop 287 ;cmp r0,$': 288 ;beq 1f 289 ;mpy $10.,r1 290 ;sub $'0,r0 291 ;add r0,r1 292 ;br 1b 293 294 000000EC 51 push ecx 295 000000ED E8FC000000 call pcop 296 000000F2 59 pop ecx 297 ; (eax <= 255) 298 000000F3 3C3A cmp al, ':' 299 000000F5 740A je short pswd_11 300 000000F7 91 xchg eax, ecx 301 000000F8 F7E7 mul edi ; * 10 302 000000FA 80E930 sub cl, '0' 303 000000FD 01C1 add ecx, eax 304 000000FF EBEB jmp short pswd_10 305 306 pswd_11: 307 ;1: 308 ;sys getuid 309 ;tst r0 310 ;beq 1f 311 312 ; ecx = uid (as in passwd file) 313 314 sys _getuid 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000101 B818000000 <1> mov eax, %1 75 00000106 CD30 <1> int 30h 315 316 ;or al, al 317 ;;or ax, ax 318 00000108 09C0 or eax, eax 319 0000010A 7410 jz short pswd_12 ; root (superuser) 320 321 ;cmp r0,r1 322 ;beq 1f 323 324 ;cmp cl, al 325 ;;cmp cx, ax 326 0000010C 39C1 cmp ecx, eax 327 0000010E 740C je short pswd_12 328 329 ;jsr r5,mesg 330 ; ; .even 331 ;br done 332 333 00000110 B8[80040000] mov eax, p_denied_msg 334 00000115 E8F9000000 call print_msg 335 0000011A EB0D jmp short done 336 337 pswd_12: 338 ;1: 339 ;inc sflg 340 341 ; set 1st stage (cmpleted) flag 342 0000011C FE05[C80F0000] inc byte [sflg] ; 1st stage is ok 343 pswd_13: 344 ;1: 345 ;jsr pc,pcop 346 ;br 1b 347 348 00000122 E8C7000000 call pcop 349 350 ; pcop will return/jump to 'done' 351 ; after the last byte of (old) passwd file 352 ; (call return address will be discarded) 353 354 ; (but if there is a next byte to read/write 355 ; cpu will return here) 356 357 00000127 EBF9 jmp short pswd_13 ; r/w next byte 358 359 ; --------------------------- 360 361 done: 362 ;jsr r5,flush; obuf 363 ;mov obuf,r0 364 ;sys close 365 366 ;mov ebx, obuf 367 00000129 E887020000 call flush 368 ; (write buffer content to disk) 369 0000012E 0FB71D[B80D0000] movzx ebx, word [obuf] 370 sys _close ; (close output file) 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000135 B806000000 <1> mov eax, %1 75 0000013A CD30 <1> int 30h 371 372 ;mov ibuf,r0 373 ;sys close 374 375 ;movzx ebx, word [ibuf] 376 0000013C 668B1D[B00B0000] mov bx, [ibuf] 377 sys _close ; (close input file) 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000143 B806000000 <1> mov eax, %1 75 00000148 CD30 <1> int 30h 378 379 ;tst sflg 380 ;beq 1f 381 ;tst dflg 382 ;bne 1f 383 ;inc dflg 384 385 0000014A F605[C80F0000]FF test byte [sflg], 0FFh 386 00000151 746C jz short done_4 ; 1st stage failed 387 ; unlink/remove tempf 388 ; 1st stage is ok 389 00000153 F605[C90F0000]FF test byte [dflg], 0FFh 390 0000015A 7563 jnz short done_4 ; 2nd stage is ok (completed) 391 392 ; 2nd stage 393 ; (writing to tempf at 1st stage is ok) 394 0000015C FE05[C90F0000] inc byte [dflg] ; set 2nd stage flag 395 ; (open tempf for read and 396 ; write to new passwd file) 397 ;mov $tempf,r0 398 ;jsr r5,fopen; ibuf 399 ;bec 2f 400 401 sys _open, tempf, 0 ; open tempf for read 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 00000162 BB[19040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 00000167 B900000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 0000016C B805000000 <1> mov eax, %1 75 00000171 CD30 <1> int 30h 402 00000173 730C jnc short done_1 403 404 ;jsr r5,mesg 405 ; ; .even 406 ;br 1f 407 408 00000175 B8[96040000] mov eax, cnro_tmpf_msg 409 0000017A E894000000 call print_msg 410 0000017F EB3E jmp short done_4 411 done_1: 412 ;2: 413 00000181 A3[B00B0000] mov [ibuf], eax 414 00000186 31C0 xor eax, eax ; 0 415 00000188 A3[B40B0000] mov [ibuf+4], eax 416 417 ;mov $passwf,r0 418 ;jsr r5,fcreat; obuf 419 ;bec 2f 420 421 ; retro unix v1 inode 422 sys _creat, passwf, 1100b ; rw-- 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 0000018D BB[0D040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 00000192 B90C000000 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000197 B808000000 <1> mov eax, %1 75 0000019C CD30 <1> int 30h 423 ; retro unix v2 inode 424 ;sys _creat, passwf, 110000000b ; rw------- 425 0000019E 730C jnc short done_2 426 427 ;jsr r5,mesg 428 ; ; .even 429 ;br 1f 430 431 000001A0 B8[B2040000] mov eax, cnro_pswdf_msg 432 000001A5 E869000000 call print_msg 433 000001AA EB13 jmp short done_4 434 done_2: 435 ;2: 436 ;jsr pc,pcop 437 ;br 2b 438 439 000001AC A3[B80D0000] mov [obuf], eax 440 000001B1 29C0 sub eax, eax ; 0 441 000001B3 A3[BC0D0000] mov [obuf+4], eax 442 done_3: ; 01/05/2022 443 000001B8 E831000000 call pcop 444 000001BD EBF9 jmp short done_3 445 446 done_4: 447 ;1: 448 ;sys unlink; tempf 449 ;sys exit 450 451 sys _unlink, tempf 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 000001BF BB[19040000] <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000001C4 B80A000000 <1> mov eax, %1 75 000001C9 CD30 <1> int 30h 452 sys _exit 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000001CB B801000000 <1> mov eax, %1 75 000001D0 CD30 <1> int 30h 453 454 ; --------------------------- 455 456 pput: 457 ;jsr r5,putc; obuf 458 ;rts pc 459 460 ;mov ebx, obuf 461 ;call putc 462 ;retn 463 000001D2 E9C1010000 jmp putc 464 465 ; --------------------------- 466 467 pget: 468 ;jsr r5,getc; ibuf 469 ;bes 1f 470 ;rts pc 471 472 ;mov ebx, ibuf 473 000001D7 E87F010000 call getc 474 000001DC 7201 jc short pget_1 475 000001DE C3 retn 476 pget_1: 477 ;1: 478 ;jsr r5,mesg 479 ; ; .even 480 ;br done 481 482 000001DF B8[D2040000] mov eax, format_err_msg 483 000001E4 E82A000000 call print_msg 484 485 000001E9 E93BFFFFFF jmp done 486 487 ; --------------------------- 488 489 ; 30/04/2022 490 pcop: 491 ;jsr r5,getc; ibuf 492 ;bes 1f 493 ;jsr r5,putc; obuf 494 ;rts pc 495 496 ;mov ebx, ibuf 497 000001EE E868010000 call getc 498 000001F3 7205 jc short pcop_1 499 ;mov ebx, obuf 500 ;call putc 501 ;retn 502 000001F5 E99E010000 jmp putc 503 pcop_1: 504 ;1: 505 ;tst sflg 506 ;bne 1f 507 ;jsr r5,mesg 508 ; ; .even 509 510 000001FA F605[C80F0000]FF test byte [sflg], 0FFh 511 00000201 750A jnz short pcop_2 512 513 00000203 B8[F4040000] mov eax, not_valid_msg 514 00000208 E806000000 call print_msg 515 pcop_2: 516 ;1: 517 ;br done 518 0000020D 58 pop eax ; discard call return addr 519 0000020E E916FFFFFF jmp done 520 521 ; --------------------------- 522 523 print_msg: 524 ; 01/05/2022 525 ; 29/04/2022 526 ; Modified registers: eax, ebx, ecx, edx 527 528 00000213 E811000000 call _strlen ; 01/05/2022 529 print_str: 530 00000218 89DA mov edx, ebx 531 sys _write, 1, eax 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 0000021A BB01000000 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 0000021F 89C1 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000221 B804000000 <1> mov eax, %1 75 00000226 CD30 <1> int 30h 532 ; 533 00000228 C3 retn 534 535 ; 01/05/2022 536 ; 29/04/2022 537 _strlen: 538 ; eax = asciiz string address 539 00000229 89C3 mov ebx, eax 540 0000022B 4B dec ebx 541 nextchr: 542 0000022C 43 inc ebx 543 0000022D 803B00 cmp byte [ebx], 0 544 00000230 77FA ja short nextchr 545 ;cmp [ebx], 0Dh 546 ;ja short nextchr 547 00000232 29C3 sub ebx, eax 548 ; bx = asciiz string length 549 00000234 C3 retn 550 551 ; 01/05/2022 552 strlen: 553 00000235 89F0 mov eax, esi 554 00000237 E8EDFFFFFF call _strlen 555 0000023C 89D8 mov eax, ebx 556 0000023E C3 retn 557 558 ; --------------------------------------------------- 559 ; 30/04/2022 560 ; 'crypt' assembly source code 561 ; copied from: 'login386.s' (Erdogan Tan, 27/02/2022) 562 ; --------------------------------------------------- 563 564 ;/ crypt -- password incoding 565 ; 566 ;; Original Unix v5 (PDP-11) 'crypt' 567 ;; code has been converted to 568 ;; Retro UNIX 8086 v1 'crypt' 569 ;; procedure in 'login.asm' 570 ;; (by Erdogan Tan - 12/11/2013). 571 ; 572 ; 573 ;crypt: 574 ; mov r1,-(sp) 575 ; mov r2,-(sp) 576 ; mov r3,-(sp) 577 ; mov r4,-(sp) 578 ; mov r5,-(sp) 579 ; 580 ; mov r0,r1 581 ; mov $key,r0 582 ; movb $004,(r0)+ 583 ; movb $034,(r0)+ 584 585 ; 14/10/2015 - 32 bit version (Retro UNIX 386 v1) 586 587 crypt: 588 ; 30/04/2022 589 ; INPUT: 590 ; esi = password string address 591 ; OUTPUT: 592 ; esi = encyrpted password str address 593 ; 594 ; Modified registers: 595 ; eax, ebx, ecx, edx, esi, edi, ebp 596 597 ;mov esi, passwd 598 0000023F BF[24050000] mov edi, key 599 00000244 B004 mov al, 4 600 00000246 AA stosb 601 00000247 B01C mov al, 28 602 00000249 AA stosb 603 604 ;1: 605 ; cmp r0,$key+64. 606 ; bhis 1f 607 ; movb (r1)+,(r0)+ 608 ; bne 1b 609 ;1: 610 ; dec r0 611 612 cryp0: 613 0000024A AC lodsb 614 0000024B AA stosb 615 0000024C 20C0 and al, al 616 0000024E 7408 jz short cryp1 617 00000250 81FF[64050000] cmp edi, key + 64 618 00000256 72F2 jb short cryp0 619 cryp1: 620 00000258 4F dec edi 621 ;/ 622 ;/ 623 ;/ fill out key space with clever junk 624 ;/ 625 ; mov $key,r1 626 ;1: 627 ; movb -1(r0),r2 628 ; movb (r1)+,r3 629 ; xor r3,r2 630 ; movb r2,(r0)+ 631 ; cmp r0,$key+128. 632 ; blo 1b 633 634 635 ;/ fill out key space with clever junk 636 637 00000259 BE[24050000] mov esi, key 638 cryp2: 639 0000025E 8A5FFF mov bl, [edi-1] 640 00000261 AC lodsb 641 00000262 30D8 xor al, bl 642 00000264 AA stosb 643 00000265 81FF[A4050000] cmp edi, key + 128 644 0000026B 72F1 jb short cryp2 645 ; 646 ;/ 647 ;/ 648 ;/ establish wheel codes and cage codes 649 ;/ 650 ; mov $wheelcode,r4 651 ; mov $cagecode,r5 652 ; mov $256.,-(sp) 653 ;2: 654 ; clr r2 655 ; clr (r4) 656 ; mov $wheeldiv,r3 657 ;3: 658 ; clr r0 659 ; mov (sp),r1 660 ; div (r3)+,r0 661 ; add r1,r2 662 ; bic $40,r2 663 ; bis shift(r2),(r4) 664 ; cmp r3,$wheeldiv+6. 665 ; bhis 4f 666 ; bis shift+4(r2),(r5) 667 ;4: 668 ; cmp r3,$wheeldiv+10. 669 ; blo 3b 670 ; sub $2,(sp) 671 ; tst (r4)+ 672 ; tst (r5)+ 673 ; cmp r4,$wheelcode+256. 674 ; blo 2b 675 ; tst (sp)+ 676 ;/ 677 678 ;/ establish wheel codes and cage codes 679 680 0000026D BE[B0090000] mov esi, wheelcode 681 00000272 BF[B0070000] mov edi, cagecode 682 00000277 66B80001 mov ax, 256 683 0000027B 6650 push ax ; * 684 0000027D 89E5 mov ebp, esp 685 cryp3: 686 0000027F 6629D2 sub dx, dx ; 0 687 00000282 668916 mov [esi], dx ; 0 688 00000285 BB[08040000] mov ebx, wheeldiv 689 cryp4: 690 0000028A 668B4500 mov ax, [ebp] 691 0000028E 8A0B mov cl, [ebx] 692 00000290 F6F1 div cl 693 00000292 00E2 add dl, ah 694 00000294 43 inc ebx 695 00000295 80E21F and dl, 01Fh 696 00000298 53 push ebx 697 00000299 BB[E4030000] mov ebx, shift 698 0000029E 01D3 add ebx, edx 699 000002A0 668B03 mov ax, [ebx] 700 000002A3 660906 or [esi], ax 701 000002A6 59 pop ecx 702 000002A7 81F9[0B040000] cmp ecx, wheeldiv + 3 703 000002AD 7309 jnb short cryp5 704 000002AF 83C304 add ebx, 4 705 000002B2 668B03 mov ax, [ebx] 706 000002B5 660907 or [edi], ax 707 cryp5: 708 000002B8 89CB mov ebx, ecx 709 000002BA 81FB[0D040000] cmp ebx, wheeldiv + 5 710 000002C0 72C8 jb short cryp4 711 000002C2 66836D0002 sub word [ebp], 2 712 000002C7 66AD lodsw 713 000002C9 47 inc edi 714 000002CA 47 inc edi 715 000002CB 81FE[B00A0000] cmp esi, wheelcode + 256 716 000002D1 72AC jb short cryp3 717 000002D3 6658 pop ax ; * 718 719 ; .data 720 ;shift: 1;2;4;10;20;40;100;200;400;1000;2000;4000;10000;20000;40000;100000 721 ; 1;2 722 ;wheeldiv: 32.; 18.; 10.; 6.; 4. 723 ; .bss 724 ;cagecode: .=.+256. 725 ;wheelcode: .=.+256. 726 ; .text 727 ;/ 728 ;/ 729 ;/ make the internal settings of the machine 730 ;/ both the lugs on the 128 cage bars and the lugs 731 ;/ on the 16 wheels are set from the expanded key 732 ;/ 733 ; mov $key,r0 734 ; mov $cage,r2 735 ; mov $wheel,r3 736 ;1: 737 ; movb (r0)+,r1 738 ; bic $!177,r1 739 ; asl r1 740 ; mov cagecode(r1),(r2)+ 741 ; mov wheelcode(r1),(r3)+ 742 ; cmp r0,$key+128. 743 ; blo 1b 744 745 ;/ make the internal settings of the machine 746 ;/ both the lugs on the 128 cage bars and the lugs 747 ;/ on the 16 wheels are set from the expanded key 748 cryp6: 749 000002D5 BB[24050000] mov ebx, key 750 000002DA BE[B0050000] mov esi, cage 751 000002DF BF[B0060000] mov edi, wheel 752 cryp7: 753 000002E4 8A0B mov cl, [ebx] 754 000002E6 43 inc ebx 755 000002E7 83E17F and ecx, 7Fh 756 000002EA D0E1 shl cl, 1 757 000002EC 87CB xchg ecx, ebx 758 000002EE 668B83[B0070000] mov ax, [ebx+cagecode] 759 000002F5 668906 mov [esi], ax 760 000002F8 46 inc esi 761 000002F9 46 inc esi 762 000002FA 668B83[B0090000] mov ax, [ebx+wheelcode] 763 00000301 66AB stosw 764 00000303 89CB mov ebx, ecx 765 00000305 81FB[A4050000] cmp ebx, key + 128 766 0000030B 72D7 jb short cryp7 767 ;/ 768 ;/ 769 ;/ now spin the cage against the wheel to produce output. 770 ;/ 771 ; mov $word,r4 772 ; mov $wheel+128.,r3 773 ;3: 774 ; mov -(r3),r2 775 ; mov $cage,r0 776 ; clr r5 777 ;1: 778 ; bit r2,(r0)+ 779 ; beq 2f 780 ; incb r5 781 ;2: 782 ; cmp r0,$cage+256. 783 ; blo 1b 784 785 ;/ 786 ;/ now spin the cage against the wheel to produce output. 787 ;/ 788 cryp8: 789 0000030D BF[A4050000] mov edi, _word 790 00000312 BB[30070000] mov ebx, wheel + 128 791 cryp9: 792 00000317 4B dec ebx 793 00000318 4B dec ebx 794 00000319 668B13 mov dx, [ebx] 795 0000031C BE[B0050000] mov esi, cage 796 00000321 6629C9 sub cx, cx ; 0 797 cryp10: 798 00000324 66AD lodsw 799 00000326 6685D0 test ax, dx 800 00000329 7402 jz short cryp11 801 0000032B FEC1 inc cl 802 cryp11: 803 0000032D 81FE[B0060000] cmp esi, cage + 256 804 00000333 72EF jb short cryp10 805 806 ;/ 807 ;/ we have a piece of output from current wheel 808 ;/ it needs to be folded to remove lingering hopes of 809 ;/ inverting the function 810 ;/ 811 ; mov r4,-(sp) 812 ; clr r4 813 ; div $26.+26.+10.,r4 814 ; add $'0,r5 815 ; cmp r5,$'9 816 ; blos 1f 817 ; add $'A-'9-1,r5 818 ; cmp r5,$'Z 819 ; blos 1f 820 ; add $'a-'Z-1,r5 821 ;1: 822 ; mov (sp)+,r4 823 ; movb r5,(r4)+ 824 ; cmp r4,$word+8. 825 ; blo 3b 826 ;/ 827 ; 828 ; mov (sp)+,r5 829 ; mov (sp)+,r4 830 ; mov (sp)+,r3 831 ; mov (sp)+,r2 832 ; mov (sp)+,r1 833 ; mov $word,r0 834 ; rts pc 835 ; .bss 836 ;key: .=.+128. 837 ;word: .=.+32. 838 ;cage: .=.+256. 839 ;wheel: .=.+256. 840 841 ;/ 842 ;/ we have a piece of output from current wheel 843 ;/ it needs to be folded to remove lingering hopes of 844 ;/ inverting the function 845 ;/ 846 00000335 6689C8 mov ax, cx 847 00000338 B23E mov dl, 26+26+10 848 0000033A F6F2 div dl 849 0000033C 88E0 mov al, ah 850 0000033E 0430 add al, '0' 851 00000340 3C39 cmp al, '9' 852 00000342 7608 jna short cryp12 853 00000344 0407 add al, 'A'-'9'-1 854 00000346 3C5A cmp al, 'Z' 855 00000348 7602 jna short cryp12 856 0000034A 0406 add al, 'a'-'Z'-1 857 cryp12: 858 0000034C AA stosb 859 0000034D 81FF[AC050000] cmp edi, _word + 8 860 00000353 72C2 jb short cryp9 861 00000355 BE[A4050000] mov esi, _word 862 0000035A C3 retn 863 864 ; --------------------------------------------------- 865 ; 30/04/2022 866 ; 'getc' assembly source code 867 ; copied from: 'chown1.s' (Erdogan Tan, 30/04/2022) 868 ; (derived from unix v5 'get.s') 869 ; --------------------------------------------------- 870 871 getc: 872 ; 30/04/2022 873 ; 29/04/2022 874 875 ; INPUT: 876 ; ibuf = read buffer (header) address 877 ; OUTPUT: 878 ; al = character (if cf=0) 879 ; (if cf = 1 -> read error) 880 881 ; Modified registers: eax, ebx, ecx, edx, ebp 882 883 0000035B BD[B00B0000] mov ebp, ibuf 884 ;mov ax, [ebp+2] 885 00000360 0FB74502 movzx eax, word [ebp+2] ; char count 886 ;and ax, ax 887 00000364 21C0 and eax, eax 888 00000366 751F jnz short gch1 889 gch0: 890 00000368 0FB75D00 movzx ebx, word [ebp] 891 0000036C B9[B80B0000] mov ecx, ibuf+8 ; read buff. (data) addr. 892 00000371 894D04 mov [ebp+4], ecx ; char offset 893 ;mov [ebp+2], ax ; 0 894 00000374 29D2 sub edx, edx 895 00000376 B602 mov dh, 2 896 ;mov edx, 512 897 sys _read ; sys _read, ebx, ecx, edx 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 <1> mov ebx, %2 67 <1> %if %0 >= 3 68 <1> mov ecx, %3 69 <1> %if %0 = 4 70 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 00000378 B803000000 <1> mov eax, %1 75 0000037D CD30 <1> int 30h 898 0000037F 7216 jc short gch2 899 00000381 09C0 or eax, eax 900 ;jz short gch3 901 00000383 7502 jnz short gch1 902 ; 903 00000385 F9 stc 904 00000386 C3 retn 905 gch1: 906 ;dec ax 907 00000387 48 dec eax 908 00000388 66894502 mov [ebp+2], ax 909 0000038C 8B5D04 mov ebx, [ebp+4] 910 ;xor eax, eax 911 0000038F 30E4 xor ah, ah 912 00000391 8A03 mov al, [ebx] 913 00000393 43 inc ebx 914 00000394 895D04 mov [ebp+4], ebx 915 ;;xor ah, ah 916 ;retn 917 gch2: 918 ;;xor ax, ax 919 ;xor eax, eax 920 00000397 C3 retn 921 ;gch3: 922 ;stc 923 ;retn 924 925 ; --------------------------------------------------- 926 ; 30/04/2022 (Erdogan Tan) 927 ; 'putc' assembly source code 928 ; (derived from unix v5 'put.s') 929 ; --------------------------------------------------- 930 931 putc: 932 ; 30/04/2022 933 ; 29/04/2022 934 935 ; INPUT: 936 ; al = character (to be written) 937 ; obuf = write buffer (header) address 938 ; OUTPUT: 939 ; al = character (if cf=0) 940 ; (if cf = 1 -> write error) 941 942 ; Modified registers: eax, ebx, ecx, edx, ebp 943 944 00000398 BD[B80D0000] mov ebp, obuf 945 pch0: 946 0000039D 66FF4D02 dec word [ebp+2] ; char count 947 000003A1 7D09 jge short pch1 948 000003A3 50 push eax 949 000003A4 E811000000 call _fl_ 950 000003A9 58 pop eax 951 000003AA EBF1 jmp short pch0 952 pch1: 953 000003AC 8B5D04 mov ebx, [ebp+4] ; char offset 954 000003AF 8803 mov [ebx], al 955 ;inc ebx 956 ;mov [ebp+4], ebx 957 000003B1 FF4504 inc dword [ebp+4] 958 000003B4 C3 retn 959 flush: 960 000003B5 BD[B80D0000] mov ebp, obuf 961 _fl_: 962 000003BA 89EA mov edx, ebp ; buffer header address 963 000003BC 83C208 add edx, 8 ; + 8 964 ; edx = buffer data address 965 000003BF 52 push edx 966 000003C0 8B4504 mov eax, [ebp+4] ; char offset 967 000003C3 09C0 or eax, eax 968 000003C5 7413 jz short pch2 ; empty/new buffer 969 000003C7 29D0 sub eax, edx ; char count 970 ; [ebp] = file descriptor 971 000003C9 0FB74D00 movzx ecx, word [ebp] 972 ;movzx ecx, byte [ebp] ; < 256 973 ; ; (<=10 for retro unix v1) 974 sys _write, ecx, edx, eax 62 <1> 63 <1> 64 <1> 65 <1> %if %0 >= 2 66 000003CD 89CB <1> mov ebx, %2 67 <1> %if %0 >= 3 68 000003CF 89D1 <1> mov ecx, %3 69 <1> %if %0 = 4 70 000003D1 89C2 <1> mov edx, %4 71 <1> %endif 72 <1> %endif 73 <1> %endif 74 000003D3 B804000000 <1> mov eax, %1 75 000003D8 CD30 <1> int 30h 975 pch2: 976 000003DA 8F4504 pop dword [ebp+4]; character offset 977 000003DD 66C745020002 mov word [ebp+2], 512 978 ; available char count 979 ; to write in buffer 980 ; (before flushing) 981 000003E3 C3 retn 982 983 ;----------------------------------------------------------------- 984 ; data - initialized data 985 ;----------------------------------------------------------------- 986 987 ;align 4 988 989 ; 30/04/2022 990 991 ; cryprt.s 992 993 000003E4 010002000400080010- shift: dw 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 993 000003ED 002000400080000001- 993 000003F6 0002 994 000003F8 000400080010002000- dw 1024, 2048, 4096, 8192, 16384, 32768 994 00000401 400080 995 00000404 01000200 dw 1, 2 996 wheeldiv: 997 00000408 20120A0604 db 32, 18, 10, 6, 4 998 999 ; passwd.s 1000 1001 0000040D 2F6574632F70617373- passwf: db "/etc/passwd", 0 ; password file 1001 00000416 776400 1002 00000419 2F746D702F70746D70- tempf: db "/tmp/ptmp", 0 ; temporary file 1002 00000422 00 1003 1004 usage_msg: 1005 00000423 0D0A db 0Dh, 0Ah 1006 00000425 55736167653A207061- db "Usage: passwd uid password", 0Dh, 0Ah, 0 1006 0000042E 737377642075696420- 1006 00000437 70617373776F72640D- 1006 00000440 0A00 1007 cant_open_msg: 1008 00000442 0D0A db 0Dh, 0Ah 1009 00000444 63616E6E6F74206F70- db "cannot open password file", 0Dh, 0Ah, 0 1009 0000044D 656E2070617373776F- 1009 00000456 72642066696C650D0A- 1009 0000045F 00 1010 tmpf_bsy_msg: 1011 00000460 0D0A db 0Dh, 0Ah 1012 00000462 74656D702066696C65- db "temp file busy -- try again", 0Dh, 0Ah, 0 1012 0000046B 2062757379202D2D20- 1012 00000474 74727920616761696E- 1012 0000047D 0D0A00 1013 p_denied_msg: 1014 00000480 0D0A db 0Dh, 0Ah 1015 00000482 7065726D697373696F- db "permission denied", 0Dh, 0Ah, 0 1015 0000048B 6E2064656E6965640D- 1015 00000494 0A00 1016 cnro_tmpf_msg: 1017 00000496 0D0A db 0Dh, 0Ah 1018 00000498 63616E6E6F74207265- db "cannot reopen temp file", 0Dh, 0Ah, 0 1018 000004A1 6F70656E2074656D70- 1018 000004AA 2066696C650D0A00 1019 cnro_pswdf_msg: 1020 000004B2 0D0A db 0Dh, 0Ah 1021 000004B4 63616E6E6F74207265- db "cannot reopen password file", 0Dh, 0Ah, 0 1021 000004BD 6F70656E2070617373- 1021 000004C6 776F72642066696C65- 1021 000004CF 0D0A00 1022 format_err_msg: 1023 000004D2 0D0A db 0Dh, 0Ah 1024 000004D4 666F726D6174206572- db "format error on password file", 0Dh, 0Ah, 0 1024 000004DD 726F72206F6E207061- 1024 000004E6 7373776F7264206669- 1024 000004EF 6C650D0A00 1025 not_valid_msg: 1026 000004F4 0D0A db 0Dh, 0Ah 1027 000004F6 756964206E6F742076- db "uid not valid", 0Dh, 0Ah, 0 1027 000004FF 616C69640D0A00 1028 1029 ; 01/05/2022 1030 long_pswd_msg: 1031 00000506 0D0A db 0Dh, 0Ah 1032 00000508 70617373776F726420- db "password length > 8 chars", 0Dh, 0Ah, 0 1032 00000511 6C656E677468203E20- 1032 0000051A 382063686172730D0A- 1032 00000523 00 1033 1034 ;----------------------------------------------------------------- 1035 ; bss - uninitialized data 1036 ;----------------------------------------------------------------- 1037 1038 align 4 1039 1040 bss_start: 1041 1042 ABSOLUTE bss_start 1043 1044 ; 30/04/2022 1045 1046 ; crypt.s 1047 1048 00000524 key: resb 128 1049 ;_word: resb 32 1050 000005A4 _word: resb 10 1051 000005AE ???? resb 2 1052 000005B0 cage: resb 256 1053 000006B0 wheel: resb 256 1054 000007B0 cagecode: resw 256 ; resb 256 1055 000009B0 wheelcode: resw 256 ; resb 256 1056 1057 ; passwd.s 1058 1059 00000BB0 ibuf: resb 520 1060 00000DB8 obuf: resb 520 1061 00000FC0 ???? cryptp: resw 1 1062 00000FC2 ???? resw 1 ; 32 bit pointer for Retro UNIX 386 v1 1063 00000FC4 ???? uidp: resw 1 1064 00000FC6 ???? resw 1 ; 32 bit pointer for Retro UNIX 386 v1 1065 00000FC8 ?? sflg: resb 1 ; resw 1 1066 00000FC9 ?? dflg: resb 1 ; resw 1 1067 1068 ; 30/04/2022 1069 1070 ;----------------------------------------------------------------- 1071 ; Original UNIX v5 - /bin/passwd source code (passwd.s) 1072 ; in PDP-11 (unix) assembly language 1073 ;----------------------------------------------------------------- 1074 ; 1075 ;/ passwd -- change user's password 1076 ; 1077 ;.globl mesg 1078 ;.globl crypt 1079 ;.globl getc 1080 ;.globl flush 1081 ;.globl fcreat 1082 ;.globl putc 1083 ;.globl fopen 1084 ; 1085 ; cmp (sp)+,$3 1086 ; bge 1f 1087 ; jsr r5,mesg 1088 ; ; .even 1089 ; sys exit 1090 ;1: 1091 ; tst (sp)+ 1092 ; mov (sp)+,uidp 1093 ; mov (sp)+,r0 1094 ; tstb (r0) 1095 ; beq 1f 1096 ; jsr pc,crypt 1097 ; clrb 8(r0) 1098 ;1: 1099 ; mov r0,cryptp 1100 ; mov $passwf,r0 1101 ; jsr r5,fopen; ibuf 1102 ; bec 1f 1103 ; jsr r5,mesg 1104 ; ; .even 1105 ; sys exit 1106 ;1: 1107 ; sys stat; tempf; obuf+20. 1108 ; bec 2f 1109 ; sys creat; tempf; 222 1110 ; bec 1f 1111 ;2: 1112 ; jsr r5,mesg 1113 ; ; .even 1114 ; sys exit 1115 ;1: 1116 ; mov r0,obuf 1117 ; 1118 ;/ search for uid 1119 ; 1120 ;comp: 1121 ; mov uidp,r1 1122 ;1: 1123 ; jsr pc,pcop 1124 ; cmp r0,$': 1125 ; beq 1f 1126 ; cmpb r0,(r1)+ 1127 ; beq 1b 1128 ;2: 1129 ; jsr pc,pcop 1130 ; cmp r0,$'\n 1131 ; bne 2b 1132 ; br comp 1133 ;1: 1134 ; tstb (r1)+ 1135 ; bne 2b 1136 ; 1137 ;/ skip over old password 1138 ; 1139 ;1: 1140 ; jsr pc,pget 1141 ; cmp r0,$': 1142 ; bne 1b 1143 ; 1144 ;/ copy in new password 1145 ; 1146 ; mov cryptp,r1 1147 ;1: 1148 ; movb (r1)+,r0 1149 ; beq 1f 1150 ; jsr pc,pput 1151 ; br 1b 1152 ;1: 1153 ; mov $':,r0 1154 ; jsr pc,pput 1155 ; 1156 ;/ validate permission 1157 ; 1158 ; clr r1 1159 ;1: 1160 ; jsr pc,pcop 1161 ; cmp r0,$': 1162 ; beq 1f 1163 ; mpy $10.,r1 1164 ; sub $'0,r0 1165 ; add r0,r1 1166 ; br 1b 1167 ;1: 1168 ; sys getuid 1169 ; tst r0 1170 ; beq 1f 1171 ; cmp r0,r1 1172 ; beq 1f 1173 ; jsr r5,mesg 1174 ; ; .even 1175 ; br done 1176 ;1: 1177 ; inc sflg 1178 ;1: 1179 ; jsr pc,pcop 1180 ; br 1b 1181 ; 1182 ;done: 1183 ; jsr r5,flush; obuf 1184 ; mov obuf,r0 1185 ; sys close 1186 ; mov ibuf,r0 1187 ; sys close 1188 ; tst sflg 1189 ; beq 1f 1190 ; tst dflg 1191 ; bne 1f 1192 ; inc dflg 1193 ; mov $tempf,r0 1194 ; jsr r5,fopen; ibuf 1195 ; bec 2f 1196 ; jsr r5,mesg 1197 ; ; .even 1198 ; br 1f 1199 ;2: 1200 ; mov $passwf,r0 1201 ; jsr r5,fcreat; obuf 1202 ; bec 2f 1203 ; jsr r5,mesg 1204 ; ; .even 1205 ; br 1f 1206 ;2: 1207 ; jsr pc,pcop 1208 ; br 2b 1209 ;1: 1210 ; sys unlink; tempf 1211 ; sys exit 1212 ; 1213 ;pput: 1214 ; jsr r5,putc; obuf 1215 ; rts pc 1216 ; 1217 ;pget: 1218 ; jsr r5,getc; ibuf 1219 ; bes 1f 1220 ; rts pc 1221 ;1: 1222 ; jsr r5,mesg 1223 ; ; .even 1224 ; br done 1225 ; 1226 ;pcop: 1227 ; jsr r5,getc; ibuf 1228 ; bes 1f 1229 ; jsr r5,putc; obuf 1230 ; rts pc 1231 ;1: 1232 ; tst sflg 1233 ; bne 1f 1234 ; jsr r5,mesg 1235 ; ; .even 1236 ;1: 1237 ; br done 1238 ; 1239 ;.data 1240 ;passwf: 1241 ;tempf: 1242 ;.even 1243 ;.bss 1244 ;ibuf: .=.+520. 1245 ;obuf: .=.+520. 1246 ;cryptp: .=.+2 1247 ;uidp: .=.+2 1248 ;sflg: .=.+2 1249 ;dflg: .=.+2 1250 1251 ; 30/04/2022 1252 1253 ;----------------------------------------------------------------- 1254 ; Original UNIX v5 - 'crypt' source code (crypt.s) 1255 ; in PDP-11 (unix) assembly language 1256 ;----------------------------------------------------------------- 1257 ;/usr/source/s3/crypt.s -- password incoding 1258 ; 1259 ;/ crypt -- password incoding 1260 ; 1261 ;/ mov $key,r0 1262 ;/ jsr pc,crypt 1263 ; 1264 ;.globl crypt, word 1265 ; 1266 ;crypt: 1267 ; mov r1,-(sp) 1268 ; mov r2,-(sp) 1269 ; mov r3,-(sp) 1270 ; mov r4,-(sp) 1271 ; mov r5,-(sp) 1272 ; 1273 ; mov r0,r1 1274 ; mov $key,r0 1275 ; movb $004,(r0)+ 1276 ; movb $034,(r0)+ 1277 ;1: 1278 ; cmp r0,$key+64. 1279 ; bhis 1f 1280 ; movb (r1)+,(r0)+ 1281 ; bne 1b 1282 ;1: 1283 ; dec r0 1284 ;/ 1285 ;/ 1286 ;/ fill out key space with clever junk 1287 ;/ 1288 ; mov $key,r1 1289 ;1: 1290 ; movb -1(r0),r2 1291 ; movb (r1)+,r3 1292 ; xor r3,r2 1293 ; movb r2,(r0)+ 1294 ; cmp r0,$key+128. 1295 ; blo 1b 1296 ;/ 1297 ;/ 1298 ;/ establish wheel codes and cage codes 1299 ;/ 1300 ; mov $wheelcode,r4 1301 ; mov $cagecode,r5 1302 ; mov $256.,-(sp) 1303 ;2: 1304 ; clr r2 1305 ; clr (r4) 1306 ; mov $wheeldiv,r3 1307 ;3: 1308 ; clr r0 1309 ; mov (sp),r1 1310 ; div (r3)+,r0 1311 ; add r1,r2 1312 ; bic $40,r2 1313 ; bis shift(r2),(r4) 1314 ; cmp r3,$wheeldiv+6. 1315 ; bhis 4f 1316 ; bis shift+4(r2),(r5) 1317 ;4: 1318 ; cmp r3,$wheeldiv+10. 1319 ; blo 3b 1320 ; sub $2,(sp) 1321 ; tst (r4)+ 1322 ; tst (r5)+ 1323 ; cmp r4,$wheelcode+256. 1324 ; blo 2b 1325 ; tst (sp)+ 1326 ;/ 1327 ; .data 1328 ;shift: 1;2;4;10;20;40;100;200;400;1000;2000;4000;10000;20000;40000;100000 1329 ; 1;2 1330 ;wheeldiv: 32.; 18.; 10.; 6.; 4. 1331 ; .bss 1332 ;cagecode: .=.+256. 1333 ;wheelcode: .=.+256. 1334 ; .text 1335 ;/ 1336 ;/ 1337 ;/ make the internal settings of the machine 1338 ;/ both the lugs on the 128 cage bars and the lugs 1339 ;/ on the 16 wheels are set from the expanded key 1340 ;/ 1341 ; mov $key,r0 1342 ; mov $cage,r2 1343 ; mov $wheel,r3 1344 ;1: 1345 ; movb (r0)+,r1 1346 ; bic $!177,r1 1347 ; asl r1 1348 ; mov cagecode(r1),(r2)+ 1349 ; mov wheelcode(r1),(r3)+ 1350 ; cmp r0,$key+128. 1351 ; blo 1b 1352 ;/ 1353 ;/ 1354 ;/ now spin the cage against the wheel to produce output. 1355 ;/ 1356 ; mov $word,r4 1357 ; mov $wheel+128.,r3 1358 ;3: 1359 ; mov -(r3),r2 1360 ; mov $cage,r0 1361 ; clr r5 1362 ;1: 1363 ; bit r2,(r0)+ 1364 ; beq 2f 1365 ; incb r5 1366 ;2: 1367 ; cmp r0,$cage+256. 1368 ; blo 1b 1369 ;/ 1370 ;/ we have a piece of output from current wheel 1371 ;/ it needs to be folded to remove lingering hopes of 1372 ;/ inverting the function 1373 ;/ 1374 ; mov r4,-(sp) 1375 ; clr r4 1376 ; div $26.+26.+10.,r4 1377 ; add $'0,r5 1378 ; cmp r5,$'9 1379 ; blos 1f 1380 ; add $'A-'9-1,r5 1381 ; cmp r5,$'Z 1382 ; blos 1f 1383 ; add $'a-'Z-1,r5 1384 ;1: 1385 ; mov (sp)+,r4 1386 ; movb r5,(r4)+ 1387 ; cmp r4,$word+8. 1388 ; blo 3b 1389 ;/ 1390 ; 1391 ; mov (sp)+,r5 1392 ; mov (sp)+,r4 1393 ; mov (sp)+,r3 1394 ; mov (sp)+,r2 1395 ; mov (sp)+,r1 1396 ; mov $word,r0 1397 ; rts pc 1398 ; 1399 ; .bss 1400 ;key: .=.+128. 1401 ;word: .=.+32. 1402 ;cage: .=.+256. 1403 ;wheel: .=.+256. 1404 1405 ; 30/04/2022 1406 1407 ;----------------------------------------------------------------- 1408 ; Original UNIX v5 - 'getc' & 'fopen' source code (get.s) 1409 ; in PDP-11 (unix) assembly language 1410 ;----------------------------------------------------------------- 1411 ;/usr/source/s3/get.s 1412 ;-------------------- 1413 ;/ getw/getc -- get words/characters from input file 1414 ;/ fopen -- open a file for use by get(c|w) 1415 ;/ 1416 ;/ calling sequences -- 1417 ;/ 1418 ;/ mov $filename,r0 1419 ;/ jsr r5,fopen; ioptr 1420 ;/ 1421 ;/ on return ioptr buffer is set up or error bit is set if 1422 ;/ file could not be opened. 1423 ;/ 1424 ;/ jsr r5,get(c|w)1; ioptr 1425 ;/ 1426 ;/ on return char/word is in r0; error bit is 1427 ;/ set on error or end of file. 1428 ;/ 1429 ;/ ioptr is the address of a 518-byte buffer 1430 ;/ whose layout is as follows: 1431 ;/ 1432 ;/ ioptr: .=.+2 / file descriptor 1433 ;/ .=.+2 / charact+2 / pointer to next character (reset if no. chars=0) 1434 ;/ .=.+512. / the buffer 1435 ; 1436 ; .globl getc,getw,fopen 1437 ; 1438 ;fopen: 1439 ; mov r1,-(sp) 1440 ; mov (r5)+,r1 1441 ; mov r0,0f 1442 ; sys 0; 9f 1443 ;.data 1444 ;9: 1445 ; sys open; 0:..; 0 1446 ;.text 1447 ; bes 1f 1448 ; mov r0,(r1)+ 1449 ; clr (r1)+ 1450 ; mov (sp)+,r1 1451 ; rts r5 1452 ;1: 1453 ; mov $-1,(r1) 1454 ; mov (sp)+,r1 1455 ; sec 1456 ; rts r5 1457 ; 1458 ;.data 1459 ;getw: 1460 ; mov (r5),9f 1461 ; mov (r5)+,8f 1462 ; jsr r5,getc; 8:.. 1463 ; bec 1f 1464 ; rts r5 1465 ;1: 1466 ; mov r0,-(sp) 1467 ; jsr r5,getc; 9:.. 1468 ; swab r0 1469 ; bis (sp)+,r0 1470 ; rts r5 1471 ;.text 1472 ; 1473 ;getc: 1474 ; mov r1,-(sp) 1475 ; mov (r5)+,r1 1476 ; dec 2(r1) 1477 ; bge 1f 1478 ; mov r1,r0 1479 ; add $6,r0 1480 ; mov r0,0f 1481 ; mov r0,4(r1) 1482 ; mov (r1),r0 1483 ; sys 0; 9f 1484 ;.data 1485 ;9: 1486 ; sys read; 0:..; 512. 1487 ;.text 1488 ; bes 2f 1489 ; tst r0 1490 ; bne 3f 1491 ;2: 1492 ; mov (sp)+,r1 1493 ; sec 1494 ; rts r5 1495 ;3: 1496 ; dec r0 1497 ; mov r0,2(r1) 1498 ;1: 1499 ; clr r0 1500 ; bisb *4(r1),r0 1501 ; inc 4(r1) 1502 ; mov (sp)+,r1 1503 ; rts r5 1504 1505 ; 30/04/2022 1506 1507 ;----------------------------------------------------------------- 1508 ; Original UNIX v5 - 'putc' & 'flush' & 'fcreat' source code 1509 ; (put.s) in PDP-11 (unix) assembly language 1510 ;----------------------------------------------------------------- 1511 ;/usr/source/s3/put.s 1512 ;-------------------- 1513 ;/ putw/putc -- write words/characters on output file 1514 ;/ 1515 ;/ fcreat -- create an output file for use by put(w|c) 1516 ;/ 1517 ;/ calling sequences -- 1518 ;/ 1519 ;/ mov $filename,r0 1520 ;/ jsr r5,fcreat; ioptr 1521 ;/ 1522 ;/ on return ioptr is set up for use by put or error 1523 ;/ bit is set if file could not be created. 1524 ;/ 1525 ;/ mov(b) thing,r0 1526 ;/ jsr r5,put(w|c)1; ioptr 1527 ;/ 1528 ;/ the character or word is written out. 1529 ;/ 1530 ;/ jsr r5,flush; ioptr 1531 ;/ 1532 ;/ the buffer is fled. 1533 ;/ 1534 ; 1535 ; .globl putc, putw, flush, fcreat 1536 ; 1537 ;fcreat: 1538 ; mov r1,-(sp) 1539 ; mov (r5)+,r1 1540 ; mov r0,0f 1541 ; sys 0; 9f 1542 ;.data 1543 ;9: 1544 ; sys creat; 0:..; 666 1545 ;.text 1546 ; bes 1f 1547 ; mov r0,(r1)+ 1548 ;2: 1549 ; clr (r1)+ 1550 ; clr (r1)+ 1551 ; mov (sp)+,r1 1552 ; rts r5 1553 ;1: 1554 ; mov $-1,(r1)+ 1555 ; mov (sp)+,r1 1556 ; sec 1557 ; rts r5 1558 ; 1559 ;.data 1560 ;putw: 1561 ; mov (r5),8f 1562 ; mov (r5)+,9f 1563 ; mov r0,-(sp) 1564 ; jsr r5,putc; 8:.. 1565 ; mov (sp)+,r0 1566 ; swab r0 1567 ; jsr r5,putc; 9:.. 1568 ; rts r5 1569 ;.text 1570 ; 1571 ;putc: 1572 ; mov r1,-(sp) 1573 ; mov (r5)+,r1 1574 ;1: 1575 ; dec 2(r1) 1576 ; bge 1f 1577 ; mov r0,-(sp) 1578 ; jsr pc,fl 1579 ; mov (sp)+,r0 1580 ; br 1b 1581 ;1: 1582 ; movb r0,*4(r1) 1583 ; inc 4(r1) 1584 ; mov (sp)+,r1 1585 ; rts r5 1586 ; 1587 ;flush: 1588 ; mov r0,-(sp) 1589 ; mov r1,-(sp) 1590 ; mov (r5)+,r1 1591 ; jsr pc,fl 1592 ; mov (sp)+,r1 1593 ; mov (sp)+,r0 1594 ; rts r5 1595 ; 1596 ;fl: 1597 ; mov r1,r0 1598 ; add $6,r0 1599 ; mov r0,-(sp) 1600 ; mov r0,0f 1601 ; mov 4(r1),0f+2 1602 ; beq 1f 1603 ; sub (sp),0f+2 1604 ; mov (r1),r0 1605 ; sys 0; 9f 1606 ;.data 1607 ;9: 1608 ; sys write; 0:..; .. 1609 ;.text 1610 ;1: 1611 ; mov (sp)+,4(r1) 1612 ; mov $512.,2(r1) 1613 ; rts pc