1 ; **************************************************************************** 2 ; ls386.s (ls2.s) - Retro Unix 386 v1.2 - /bin/ls - list file or directory 3 ; ---------------------------------------------------------------------------- 4 ; RETRO UNIX 386 (Retro Unix == Turkish Rational Unix) 5 ; Operating System Project (v0.2) by ERDOGAN TAN (Beginning: 24/12/2013) 6 ; 7 ; [ Last Modification: 22/01/2022 ] 8 ; 9 ; Derived from 'ls0.asm' source code file of 'Retro UNIX 8086 v1' 10 ; operating system project, /bin/ls source code by Erdogan Tan 11 ; (19/11/2013-29/11/2013) 12 ; 13 ; Derived from 'ls.s' file of original UNIX operating system 14 ; (v1.0 for PDP-11) 15 ; **************************************************************************** 16 17 ; ls2.s (12/01/2022), Retro UNIX 386 v1.2 (Retro UNIX 386 v2 fs inode) 18 ; ls1.s (04/12/2015), Retro UNIX 386 v1.1 (14 byte file names) 19 ; ls0.s (07/10/2015), Retro UNIX 386 v1 (8 byte file names) 20 21 ; ls386.s (23/09/2015, Retro UNIX 386 v1, NASM 2.11, 32 bit version) 22 ; LS0.ASM, 19/11/2013 - 29/11/2013 (Retro UNIX 8086 v1, MASM 6.11) 23 24 ; Assembler: NASM 2.15 (NASM v2.11) 25 ; nasm ls386.s -l ls386.txt -o ls386 -Z error.txt 26 27 ; 12/01/2022 (Retro UNIX 386 v1.2) 28 ; 06/10/2015 29 ; 05/10/2015 30 ; 23/09/2015 31 32 ; UNIX v1 system calls 33 _rele equ 0 34 _exit equ 1 35 _fork equ 2 36 _read equ 3 37 _write equ 4 38 _open equ 5 39 _close equ 6 40 _wait equ 7 41 _creat equ 8 42 _link equ 9 43 _unlink equ 10 44 _exec equ 11 45 _chdir equ 12 46 _time equ 13 47 _mkdir equ 14 48 _chmod equ 15 49 _chown equ 16 50 _break equ 17 51 _stat equ 18 52 _seek equ 19 53 _tell equ 20 54 _mount equ 21 55 _umount equ 22 56 _setuid equ 23 57 _getuid equ 24 58 _stime equ 25 59 _quit equ 26 60 _intr equ 27 61 _fstat equ 28 62 _emt equ 29 63 _mdate equ 30 64 _stty equ 31 65 _gtty equ 32 66 _ilgins equ 33 67 _sleep equ 34 ; Retro UNIX 8086 v1 feature only ! 68 _msg equ 35 ; Retro UNIX 386 v1 feature only ! 69 _geterr equ 36 ; Retro UNIX 386 v1 feature only ! 70 ; 12/01/2022 - Retro UNIX 386 v1.2 71 ; Retro UNIX 386 v2 system calls 72 _setgid equ 37 73 _getgid equ 38 74 _sysver equ 39 ; (get) Retro Unix 386 version 75 76 %macro sys 1-4 77 ; 03/09/2015 78 ; 13/04/2015 79 ; Retro UNIX 386 v1 system call. 80 %if %0 >= 2 81 mov ebx, %2 82 %if %0 >= 3 83 mov ecx, %3 84 %if %0 = 4 85 mov edx, %4 86 %endif 87 %endif 88 %endif 89 mov eax, %1 90 int 30h 91 %endmacro 92 93 ; Retro UNIX 386 v1 system call format: 94 ; sys systemcall (eax) , , 95 96 [BITS 32] ; We need 32-bit intructions for protected mode 97 98 [ORG 0] 99 100 START_CODE: ; / ls -- list file or directory 101 102 ;.globl flush 103 ;.globl fopen 104 ;.globl getw 105 ;.globl getc 106 ;.globl putc 107 ;.globl ctime 108 ;.globl end 109 110 ;mov eax, _end + 512 111 ;and al, 0FEh 112 ;cmp eax, esp 113 ;jna short S1 114 ;mov esp, eax 115 ;S1: 116 ;mov ebx, eax 117 118 ; Retro UNIX 8086 v1 modification: 119 ; 'sys break' is not needed to extend 120 ; current user core memory 121 ; (because of 8086 segmentation and 32 kB 122 ; memory allocation); 123 ; but, it is needed to clear/reset 124 ; user core memory beyond of (after) previous 125 ; 'u.break' which depends on executable 126 ; file size; because 'bss' 127 ; data is not in current executable file 128 ; ('BSS' is an external data structure after 129 ; the last byte of the executable file). 130 131 ; clear bss area 132 ; (It is not necessary to clear bss area 133 ; because Retro UNIX 386 v1 kernel will clear 134 ; this bss area during memory page allocation.) 135 ;mov ecx, _end 136 ;mov edi, bss_start 137 ;sub ecx, edi 138 ;shr cx, 2 139 ;sub eax, eax 140 ;rep stosd 141 142 ; sys break 143 ; clears memory from 'bss' to 'bss._end+512' 144 00000000 BB[C8150000] mov ebx, _end + 512 145 sys _break 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 00000005 B811000000 <1> mov eax, %1 90 0000000A CD30 <1> int 30h 146 ; sys break; end+512. 147 sys _write, 1, nl, 2 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 0000000C BB01000000 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 00000011 B9[EA080000] <1> mov ecx, %3 84 <1> %if %0 = 4 85 00000016 BA02000000 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 0000001B B804000000 <1> mov eax, %1 90 00000020 CD30 <1> int 30h 148 ; 149 ; 12/01/2022 150 00000022 881D[B00B0000] mov [obuf], bl ; 1 ; file descriptor/number 151 ;mov [obuf], bx ; 1 152 ; mov $1,obuf 153 00000028 89E6 mov esi, esp 154 ; mov sp,r5 155 0000002A AD lodsd 156 0000002B 48 dec eax 157 ; 12/01/2022 158 ; eax = number of arguments (except file name) 159 ; ((eax < 32)) 160 ; 12/01/2022 161 0000002C A2[18090000] mov [count], al 162 ;mov [count], ax 163 ; mov (r5)+,count 164 ; tst (r5)+ 165 ; dec count 166 ; 12/01/2022 167 00000031 A2[19090000] mov [ocount], al 168 ;mov [ocount], ax 169 ; mov count,ocount 170 ; bgt loop 171 ; mov $dotp,r5 172 00000036 766D jna short B0 173 ;and eax, eax 174 ;jnz short S2 175 ;jz short B0 176 ;mov esi, dotp 177 ;jmp short sloop 178 ;S2: 179 00000038 AD lodsd ; file name ptr 180 sloop: ;loop: 181 00000039 AD lodsd ; argument pointer in sequence 182 0000003A 89C3 mov ebx, eax 183 ;mov (r5)+,r4 184 0000003C 803B2D cmp byte [ebx], '-' 185 ; cmpb (r4)+,$'- 186 0000003F 754E jne short A1 187 ; bne 1f 188 00000041 43 inc ebx 189 ; 12/01/2022 190 00000042 FE0D[19090000] dec byte [ocount] 191 ;dec word [ocount] 192 ; dec ocount 193 A3: ;3: 194 00000048 8A03 mov al, [ebx] 195 ; movb (r4)+,r0 196 0000004A 43 inc ebx 197 0000004B 08C0 or al, al 198 0000004D 7445 jz short eloop ; end of argument (string) 199 ; beq eloop 200 0000004F 3C6C cmp al, 'l' 201 ; cmp r0,$'l 202 00000051 7508 jne short S3 203 ; bne 4f 204 ; 12/01/2022 205 00000053 FE05[1A090000] inc byte [longf] 206 ;inc word [longf] 207 ; inc longf 208 00000059 EBED jmp short A3 209 ; br 3b 210 S3: ;4: 211 0000005B 3C74 cmp al, 't' 212 ; cmpb r0,$'t 213 0000005D 750C jne short S4 214 ; bne 4f 215 ; 12/01/2022 216 ; (save mtime position) 217 0000005F C705[24090000]1A00- mov dword [sortoff], 26 ; 14+12 (runix v2 fs) 217 00000067 0000 218 ; 219 ; { Note: 'ls -t' does not sort files (for modification time) 220 ; correctly in retro unix 386 v1.1 because 221 ; [sortoff] must be 20 (14+6) here for v1.1 } 222 ;; (14 byte file names in v1.1) 223 ;; (8 byte file names in v1.0) 224 ; 225 ;mov dword [sortoff], 14 ; 8+6 (runix v1 fs) 226 ; mov $14.,sortoff 227 00000069 EBDD jmp short A3 228 ; br 3b 229 S4: ;4: 230 0000006B 3C61 cmp al, 'a' 231 ; cmpb r0,$'a 232 0000006D 7508 jne short S5 233 ; bne 4f 234 ; 12/01/2022 235 0000006F FE05[1C090000] inc byte [allflg] 236 ;inc word [allflg] 237 ; inc allflg 238 00000075 EBD1 jmp short A3 239 S5: ;4: 240 00000077 3C73 cmp al, 's' 241 ; cmpb r0,$'s 242 00000079 7508 jne short S6 243 ; bne 4f 244 0000007B FE05[1B090000] inc byte [longf+1] 245 ; incb longf+1 246 00000081 EBC5 jmp short A3 247 ; br 3b 248 S6: ;4: 249 00000083 3C64 cmp al, 'd' 250 ; cmpb r0,$'d 251 00000085 75C1 jne short A3 252 ; bne 3b 253 ; 12/01/2022 254 00000087 FE05[1D090000] inc byte [dirflg] 255 ;inc word [dirflg] 256 ; inc dirflg 257 0000008D EBB9 jmp short A3 258 ; br 3b 259 A1: ;1: 260 ;dec ebx 261 ; dec r4 262 0000008F E829000000 call do 263 ; jsr pc,do 264 eloop: 265 ; 12/01/2022 266 00000094 FE0D[18090000] dec byte [count] 267 ;dec word [count] 268 ; dec count 269 0000009A 7F9D jg short sloop 270 ; bgt loop 271 0000009C A1[DC080000] mov eax, [dnp] 272 000000A1 21C0 and eax, eax 273 ;tst dnp 274 000000A3 7507 jnz short S7 275 ; bne 1f 276 B0: 277 000000A5 BE[E0080000] mov esi, dotp 278 ; mov $dotp,r5 279 000000AA EB8D jmp short sloop 280 ; br loop 281 S7: ;1: 282 000000AC BE[B00B0000] mov esi, obuf 283 000000B1 E8A0050000 call flush 284 ; jsr r5,flush; obuf 285 sys _exit 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 000000B6 B801000000 <1> mov eax, %1 90 000000BB CD30 <1> int 30h 286 ; sys exit 287 288 ; 04/12/2015 (14 byte file names) 289 ;; 26 bytes listing (source) data 290 ;; structure: 291 ;; offset 292 ;; 0-13 : file name 293 ;; 14-15 : flags 294 ;; 16-17 : nlinks, uid 295 ;; 18-19 : size 296 ;; 20-21-22-23 : mtime 297 ;; 24-25 : inode number 298 299 ; 12/01/2022 (Retro UNIX 386 v2 file system inode) 300 ; ((Retro UNIX 386 v1.2 listing method)) 301 ;; 302 ;; 32 bytes listing (source) data structure: 303 ;; offset 304 ;; 0-13 : file name 305 ;; 14-15 : flags 306 ;; 16-17 : nlinks 307 ;; 18-19 : uid 308 ;; 20 : gid 309 ;; 21 : size_h (not used) 310 ;; 22-25 : size 311 ;; 26-29 : mtime 312 ;; 30-31 : inode number 313 314 do: 315 000000BD 56 push esi ; r5 316 000000BE 29C0 sub eax, eax 317 000000C0 A3[20090000] mov [tblocks], eax ; 0 318 ; clr tblocks 319 000000C5 BD[C8130000] mov ebp, _end 320 ; mov $end,r1 321 000000CA BF[28090000] mov edi, filnam 322 ; mov $filnam,r3 323 000000CF 891D[DC080000] mov [dnp], ebx 324 ; mov r4,dnp 325 000000D5 89DE mov esi, ebx ; r4 326 ;mov [isadir], ax ; 0 327 ; ; clr isadir 328 ; 12/01/2022 329 000000D7 A2[1E090000] mov [isadir], al ; 0 330 ;cmp [dirflg], ax ; 0 331 ; ; tst dirflg 332 ;ja nondir 333 ; ; bne nondir 334 ; 12/01/2022 335 000000DC 3805[1D090000] cmp [dirflg], al ; 0 336 000000E2 7605 jna short do_stat 337 000000E4 E9C2000000 jmp nondir 338 do_stat: 339 ;mov ebx, [dnp] 340 000000E9 B9[66090000] mov ecx, statb 341 sys _stat 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 000000EE B812000000 <1> mov eax, %1 90 000000F3 CD30 <1> int 30h 342 ; sys stat; dnp: 0; statb 343 000000F5 731B jnc short B1 344 ; bec 1f 345 ; EBX = file name address 346 000000F7 BE[03010000] mov esi, S8 347 do_err: 348 000000FC E8AF020000 call questf 349 00000101 5E pop esi 350 00000102 C3 retn 351 ;jsr r5,questf; < nonexistent\n\0>; .even 352 ; rts pc 353 S8: 354 00000103 206E6F6E6578697374- db ' nonexistent', 0Dh, 0Ah, 0 354 0000010C 656E740D0A00 355 356 B1: ;1: 357 ; 12/01/2022 358 00000112 A0[69090000] mov al, [statb+3] ; high byte of flags (w) 359 ; 12/01/2022 - Retro UNIX 386 v2 fs inode 360 00000117 A880 test al, 80h ; Regular file ? 361 ;jz nondir ; no, device/special file 362 00000119 7404 jz short B8 363 ;;test word [statb+2], 4000h 364 ;test byte [statb+3], 40h 365 ; ; bit $40000,statb+2 /test directory 366 ;jz nondir 367 ; ; beq nondir 368 ; 12/01/2022 369 0000011B A840 test al, 40h ; directory ? 370 0000011D 7505 jnz short B9 ; yes 371 ; regular file 372 B8: 373 0000011F E987000000 jmp nondir 374 B9: 375 ;inc word [isadir] 376 ; inc isadir 377 ; 12/01/2022 378 00000124 FE05[1E090000] inc byte [isadir] 379 ;mov eax, ebx 380 ; mov r4,r0 381 0000012A 57 push edi 382 0000012B BF[A8090000] mov edi, dbuf 383 00000130 E844050000 call fopen 384 ; jsr r5,fopen; dbuf 385 00000135 5F pop edi 386 00000136 7315 jnc short B2 387 ; bcc 1f 388 ; EBX = file name address 389 00000138 BE[3F010000] mov esi, S9 390 0000013D EBBD jmp short do_err 391 ;call questf 392 ;pop esi 393 ;retn 394 ; jsr r5,questf; < unreadable\n\0>; .even 395 ; rts pc 396 S9: 397 0000013F 20756E726561646162- db ' unreadable', 0Dh, 0Ah, 0 397 00000148 6C650D0A00 398 B2: 399 ;mov esi, ebx ; r4 400 S10: ;1: 401 0000014D AC lodsb 402 0000014E AA stosb 403 ;movb (r4)+,(r3)+ 404 0000014F 08C0 or al, al 405 00000151 75FA jnz short S10 406 ; bne 1b 407 00000153 4F dec edi 408 ; dec r3 409 ; 410 00000154 807FFF2F cmp byte [edi-1],'/' 411 ; cmpb -1(r3),$'/ 412 00000158 7403 je short B3 413 ; beq 1f 414 0000015A B02F mov al, '/' 415 0000015C AA stosb 416 ; movb $'/,(r3)+ 417 B3: ;1: 418 ;mov ebx, dbuf 419 0000015D BE[A8090000] mov esi, dbuf 420 S11: 421 00000162 E823050000 call getw 422 ; jsr r5,getw; dbuf 423 00000167 726B jc short pass2 424 ; bcs pass2 425 ; 12/01/2022 426 00000169 29C9 sub ecx, ecx 427 0000016B B107 mov cl, 7 428 ;mov ecx, 7 ; 04/12/2015 (14 byte file names) 429 ; mov $4,-(sp) 430 0000016D 21C0 and eax, eax ; 12/01/2022 431 ;and ax, ax 432 ; tst r0 433 0000016F 750B jnz short B5 434 ; bne 2f 435 B4: ;3: 436 00000171 51 push ecx 437 ; mov esi, dbuf 438 00000172 E813050000 call getw 439 ; jsr r5,getw; dbuf 440 00000177 59 pop ecx 441 00000178 E2F7 loop B4 442 ; dec (sp) 443 ; bne 3b 444 ; tst (sp)+ 445 0000017A EBE6 jmp short S11 446 ;jmp short B3 447 ; br 1b 448 B5: ;2: 449 ; EDI == r2 450 ; mov r3,r2 451 0000017C 57 push edi ; r3 (filnam +'/'+1) 452 B6: ;2: 453 ;; copying file name 454 ;; to listing (source) data address (ebp) 455 ;; (offset 0-13) ; 04/12/2015 (14 byte file names) 456 ;; and filnam (edi) 457 ; 458 0000017D 51 push ecx 459 ; mov esi, dbuf 460 0000017E E807050000 call getw 461 ; jsr r5,getw; dbuf 462 00000183 66894500 mov [ebp], ax 463 00000187 45 inc ebp 464 00000188 45 inc ebp 465 ; mov r0,(r1)+ 466 00000189 66AB stosw 467 ;stosb 468 ; movb r0,(r2)+ 469 ;xchg al, ah 470 ; swab r0 471 ;stosb 472 ; movb r0,(r2)+ 473 0000018B 59 pop ecx 474 0000018C E2EF loop B6 475 ; dec (sp) 476 ; bne 2b 477 ; tst (sp)+ 478 0000018E 31C0 xor eax, eax ; 0 479 00000190 AA stosb 480 ; clrb (r2)+ 481 00000191 5F pop edi ; r3 482 ; 12/01/2022 483 00000192 3805[1C090000] cmp [allflg], al ; 0 484 ;cmp [allflg], ax ; 0 485 ; tst allflg 486 00000198 770A ja short B7 487 ; bne 2f 488 0000019A 803F2E cmp byte [edi], '.' 489 ; cmpb (r3),$'. 490 0000019D 7505 jne short B7 491 ; bne 2f 492 0000019F 83ED0E sub ebp, 14 ; 04/12/2015 (14 byte file names) 493 ; sub $8.,r1 494 000001A2 EBBE jmp short S11 495 ;jmp short B3 496 ; br 1b 497 B7: ;2: 498 ;; copying 12 bytes inode data to 499 ;; listing (source) data from offset 500 ;; 14 to offset 25 (of 26 data bytes) 501 ; 502 503 ; 12/01/2022 - Retro UNIX 386 v1.2 (v2 fs) inode 504 ;; copying 18 bytes inode data to 505 ;; listing (source) data from offset 506 ;; 14 to offset 31 (of 32 data bytes) 507 508 000001A4 E893030000 call gstat 509 ; jsr r5,gstat 510 000001A9 EBB2 jmp short B3 511 ; br 1b 512 513 nondir: 514 ; mov esi, ebx ; r4 515 000001AB 89FB mov ebx, edi ; offset filnam 516 ;mov r3,r2 517 S12: ;1: 518 ; ESI points to file name (input) 519 000001AD AC lodsb 520 000001AE AA stosb 521 ; movb (r4)+,(r2)+ 522 000001AF 20C0 and al, al 523 000001B1 75FA jnz short S12 524 ; bne 1b 525 S13: ;1: 526 000001B3 39DF cmp edi, ebx ; offset filnam 527 ; cmp r2,r3 528 000001B5 7607 jna short S14 529 ; blos 1f 530 000001B7 4F dec edi 531 000001B8 803F2F cmp byte [edi], '/' 532 ; cmpb -(r2),$'/ 533 000001BB 75F6 jne short S13 534 ; bne 1b 535 000001BD 47 inc edi 536 ; inc r2 537 ;; EDI points to last name 538 ;; of the path (after "/") 539 S14: ;1: 540 ; 12/01/2022 541 000001BE 31C9 xor ecx, ecx 542 000001C0 B10E mov cl, 14 543 ;mov ecx, 14 ; 04/12/2015 (14 byte file names) 544 ; mov $8.,-(sp) 545 ndloop: ;1: 546 000001C2 8A07 mov al, [edi] 547 000001C4 884500 mov [ebp], al 548 000001C7 45 inc ebp 549 ; movb (r2)+,(r1)+ 550 ; bne 2f 551 ; dec r2 552 000001C8 08C0 or al, al 553 000001CA 7401 jz short S15 554 000001CC 47 inc edi 555 S15: 556 000001CD E2F3 loop ndloop 557 ; 12/01/2022 558 ; fill/get 18 bytes listing data 559 000001CF E868030000 call gstat ; fill/get 12 bytes listing data 560 ;jmp short pass2 561 S16: ;2: 562 ; dec (sp) 563 ; bne 1b 564 ; jsr r5,gstat 565 ; tst (sp)+ 566 567 pass2: 568 ; 12/01/2022 569 000001D4 0FB61D[A8090000] movzx ebx, byte [dbuf] 570 ;movzx ebx, word [dbuf] 571 ; mov dbuf,r0 572 sys _close 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 000001DB B806000000 <1> mov eax, %1 90 000001E0 CD30 <1> int 30h 573 ; sys close 574 000001E2 89D9 mov ecx, ebx ; file descriptor 575 000001E4 BB[C8130000] mov ebx, _end 576 ; mov $end,r2 577 000001E9 39DD cmp ebp, ebx ; ebp >= _end (= last word + 4) 578 ; cmp r1,r2 579 000001EB 7502 jne short C1 580 ; bne 1f 581 000001ED 5E pop esi ; r5 582 000001EE C3 retn 583 ; rts pc 584 C1: ;1: 585 ; sorting begins here 586 ; mov r5,-(sp) 587 000001EF 89EF mov edi, ebp ; current end of listing words (+4) 588 000001F1 55 push ebp ; r1 589 ; mov r1,-(sp) 590 ; 12/01/2022 591 ; EBX will point to mtime or file name (+14 or 0) 592 ; offset of 32 bytes listing (source) data 593 ; 2015 594 ; EBX will point to mtime or file name (+14 or 0) 595 ; offset of 26 bytes listing (source) data 596 000001F2 031D[24090000] add ebx, [sortoff] 597 ; add sortoff,r2 598 C2: ;1: 599 000001F8 89D8 mov eax, ebx 600 000001FA AB stosd 601 ; mov r2,(r1)+ 602 ; 12/01/2022 603 000001FB 83C320 add ebx, 32 ; EBX now points to next 32 bytes 604 ; 04/12/2015 (20 -> 26) 605 ;add ebx, 26 ; EBX now points to next 26 bytes 606 ; add $20.,r2 607 000001FE 39EB cmp ebx, ebp ; is EBX passed the data limit ? 608 ; cmp r2,(sp) 609 00000200 72F6 jb short C2 610 ; blo 1b 611 S17: 612 00000202 89EB mov ebx, ebp 613 ; mov (sp),r2 614 00000204 83EF04 sub edi, 4 615 ; tst -(r1) 616 C3: ;1: 617 00000207 89FA mov edx, edi ; r1 618 S18: 619 ;mov ebp, ebx 620 ; mov r2,r3 621 C4: ;2: 622 00000209 83C504 add ebp, 4 623 ; tst (r3)+ 624 0000020C 39D5 cmp ebp, edx 625 ; cmp r3,r1 626 0000020E 7724 ja short C7 627 ; bhi 2f 628 00000210 8B33 mov esi, [ebx] ; file name 1 or time 1 629 ; mov (r2),r4 630 00000212 8B7D00 mov edi, [ebp] ; file name 2 or time 2 631 ; mov (r3),r5 632 00000215 833D[24090000]00 cmp dword [sortoff], 0 633 ; tst sortoff 634 0000021C 7605 jna short C5 635 ; beq 4f 636 637 ; sorting by modification time 638 0000021E A7 cmpsd 639 0000021F 7209 jb short C6 640 ; cmp (r4)+,(r5)+ 641 ; blo 3f 642 ; bhi 2b 643 ; cmp (r4)+,(r5)+ 644 ; blo 3f 645 00000221 EBE6 jmp short C4 646 ; br 2b 647 648 ; sorting by file name 649 C5: ;4: 650 ; ? 651 ;; mov ecx, 14 ; 04/12/2015 (14 byte file names) 652 ;C5x: ;4: 653 00000223 A6 cmpsb 654 ; cmpb (r4)+,(r5)+ 655 00000224 7704 ja short C6 656 ; bhi 3f 657 00000226 72E1 jb short C4 658 ; blo 2b 659 ;dec ecx ; ? 660 ; dec r0 661 ;jnz short C5x ; ? 662 ;jmp short C5x 663 00000228 EBF9 jmp short C5 664 ; br 4b 665 C6: ;3: 666 ; 05/10/2015 667 ; (xchg [ebx],[ebp]) ; 22/01/2022 668 0000022A 8B4500 mov eax, [ebp] 669 0000022D 8703 xchg eax, [ebx] 670 0000022F 894500 mov [ebp], eax 671 ; mov (r2),-(sp) 672 ; mov (r3),(r2) 673 ; mov (sp)+,(r3) 674 00000232 EBD5 jmp short C4 675 ; br 2b 676 C7: ;2: 677 00000234 83C304 add ebx, 4 678 ; tst (r2)+ 679 00000237 39D3 cmp ebx, edx 680 ; cmp r2,r1 681 ;jb short S18 682 ;jb short C3 683 ; blo 1b 684 ; 685 00000239 7304 jnb short C8 686 0000023B 89DD mov ebp, ebx 687 0000023D EBCA jmp short S18 688 C8: ;1: 689 ; end of sorting 690 0000023F 5D pop ebp ; r1 -> r2 691 ; mov (sp)+,r2 692 ; mov (sp)+,r5 693 694 ; BP = R2 695 pass3: 696 ; DX = R1 -> 'eol:' points to end of the list 697 00000240 8915[09090000] mov [eol], edx ; save dx/r1 698 ; 699 ; 13/01/2022 700 00000246 803D[19090000]01 cmp byte [ocount], 1 701 ;cmp word [ocount], 1 702 ; cmp ocount,$1 703 0000024D 7E1E jng short E1 704 ; ble 1f 705 ; 12/01/2022 706 0000024F 803D[1E090000]00 cmp byte [isadir], 0 707 ;cmp word [isadir], 0 708 ; tst isadir 709 00000256 7648 jna short E2 710 ; beq 2f 711 00000258 8B35[DC080000] mov esi, [dnp] 712 ; mov dnp,0f 713 0000025E E840010000 call pstring 714 ; jsr r5,pstring; 0:.. 715 00000263 BE[05090000] mov esi, colon 716 ; jsr r5,pstring; colon 717 00000268 E836010000 call pstring 718 E1: ;1: 719 0000026D 66833D[1A090000]00 cmp word [longf], 0 720 ; tst longf 721 ;jna E10 722 ; ; beq 1f 723 ; 12/01/2022 724 00000275 7705 ja short E16 725 00000277 E99E000000 jmp E10 726 E16: 727 0000027C BE[ED080000] mov esi, totmes 728 00000281 E81D010000 call pstring 729 ; jsr r5,pstring; totmes 730 00000286 A1[20090000] mov eax, [tblocks] 731 ; mov tblocks,r0 732 ;mov ebx, 4 733 ; 22/01/2022 734 0000028B 29DB sub ebx, ebx 735 0000028D B304 mov bl, 4 736 0000028F E845030000 call decimal 737 ; jsr r5,decimal; 4 738 00000294 BE[EA080000] mov esi, nl 739 00000299 E805010000 call pstring 740 ; jsr r5,pstring; nl 741 0000029E EB09 jmp short S19 742 E2: ;2: 743 000002A0 803D[1A090000]00 cmp byte [longf], 0 744 ; tstb longf 745 000002A7 7671 jna short E10 746 ; beq 1f 747 S19: 748 000002A9 BB[F9080000] mov ebx, passwd 749 ; mov $passwd,r0 750 000002AE BF[BE110000] mov edi, iobuf 751 000002B3 E8C1030000 call fopen 752 ; jsr r5,fopen; iobuf 753 000002B8 7260 jc short E10 754 ; bes 1f 755 000002BA BF[BE0D0000] mov edi, uidbuf 756 ; mov $uidbuf,r3 757 E3: ;3: 758 E4: ;2: 759 000002BF BE[BE110000] mov esi, iobuf 760 S20: 761 000002C4 E8D4030000 call getc 762 ; jsr r5,getc; iobuf 763 000002C9 723B jc short E9 764 ; bes 3f 765 E17: 766 000002CB AA stosb 767 ; movb r0,(r3)+ 768 000002CC 3C3A cmp al, ':' 769 ; cmpb r0,$': 770 ; 21/01/2022 771 000002CE 75F4 jne short S20 772 ;jne short E4 773 ; bne 2b 774 E5: ;2: 775 ;mov esi, iobuf 776 000002D0 E8C8030000 call getc 777 ; jsr r5,getc; iobuf 778 000002D5 3C3A cmp al, ':' 779 ; cmpb r0,$': 780 000002D7 75F7 jne short E5 781 ; bne 2b 782 E6: ;2: 783 ;mov esi, iobuf 784 000002D9 E8BF030000 call getc 785 ; jsr r5,getc; iobuf 786 000002DE 3C3A cmp al, ':' 787 ; cmpb r0,$': 788 000002E0 7403 je short E7 789 ; beq 2f ; 21/01/2022 790 000002E2 AA stosb 791 ; movb r0,(r3)+ 792 000002E3 EBF4 jmp short E6 793 ; br 2b 794 E7: ;2: 795 000002E5 B00D mov al, 0Dh 796 000002E7 AA stosb 797 ; movb $'\n,(r3)+ 798 000002E8 81FF[BE110000] cmp edi, euidbuf 799 ; cmp r3,$euidbuf 800 000002EE 7316 jnb short E9 801 ; bhis 3f 802 E8: ;2: 803 ;mov esi, iobuf 804 000002F0 E8A8030000 call getc 805 ; jsr r5,getc; iobuf 806 000002F5 3C0D cmp al, 0Dh ; end of line 807 ; cmpb r0,$'\n 808 000002F7 75F7 jne short E8 809 ; bne 2b 810 ;jmp short E3 811 ; br 3b 812 ; 813 ; 22/01/2022 814 ; (msdos/windows 'passwd' text file, CRLF) 815 000002F9 E89F030000 call getc 816 000002FE 7206 jc short E9 817 00000300 3C0A cmp al, 0Ah ; LF 818 00000302 75C7 jne short E17 819 ; 820 00000304 EBBE jmp short S20 821 E9: ;3: 822 00000306 893D[E4080000] mov [euids], edi 823 ; mov r3,euids 824 ; 12/01/2022 825 0000030C 0FB61D[BE110000] movzx ebx, byte [iobuf] 826 827 ; 07/10/2015 (32 bit modification) 828 ; Retro UNIX 8086 v1 modification !!! 829 ; 830 ;movzx ebx, word [iobuf] 831 ; 832 ;; ??? (file descriptor ???) 833 ;; Original unix v1 'ls.s' has/had source 834 ;; code defect here !!! 835 ; 836 sys _close 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 00000313 B806000000 <1> mov eax, %1 90 00000318 CD30 <1> int 30h 837 ; sys close 838 E10: ;1: 839 ; BP = R2 840 ; [eol] = end of the list 841 ; (= r1 in original unix v1 'ls.s') 842 0000031A 3B2D[09090000] cmp ebp, [eol] 843 ; cmp r2,r1 844 00000320 772F ja short E14 845 ; bhi 1f 846 00000322 8B7500 mov esi, [ebp] 847 00000325 83C504 add ebp, 4 848 ; mov (r2)+,r3 849 00000328 2B35[24090000] sub esi, [sortoff] 850 ; sub sortoff,r3 851 ;; 852 ;; ESI points to filename offset (0) 853 ;; of the listing (source) data (26 bytes) 854 ; 855 856 ; 12/01/2022 857 ;; 858 ;; ESI points to filename offset (0) 859 ;; of the listing (source) data (32 bytes) 860 ; 861 862 0000032E E83C000000 call pentry 863 ; jsr r5,pentry 864 ; 865 ; 12/01/2022 866 00000333 29C9 sub ecx, ecx 867 00000335 B10E mov cl, 14 868 ;mov ecx, 14 ; 04/12/2015 (14 byte file names) 869 ; mov $8.,-(sp) 870 ;; print/write file name (on the end of 871 ;; the listing row (after time string) 872 E11: ;2: 873 00000337 AC lodsb 874 ; movb (r3)+,r0 875 00000338 08C0 or al, al 876 0000033A 7409 jz short E13 877 ; beq 2f 878 0000033C 51 push ecx 879 ;mov ebx, obuf 880 0000033D E8F5020000 call putc 881 ; jsr r5,putc; obuf 882 00000342 59 pop ecx 883 00000343 E2F2 loop E11 884 ; dec (sp) 885 ; bne 2b 886 E13: ;2: 887 ; tst (sp)+ 888 00000345 BE[EA080000] mov esi, nl ; new line 889 0000034A E854000000 call pstring 890 ; jsr r5,pstring; nl 891 0000034F EBC9 jmp short E10 892 ; br 1b 893 E14: ;1: 894 ; 12/01/2022 895 00000351 803D[19090000]01 cmp byte [ocount], 1 896 ;cmp word [ocount], 1 897 ; cmp ocount,$1 898 00000358 7E13 jng short E15 899 ; ble 1f 900 ; 12/01/2022 901 0000035A 803D[1E090000]00 cmp byte [isadir], 0 902 ;cmp word [isadir], 0 903 ; tst isadir 904 00000361 740A je short E15 905 ; beq 1f 906 00000363 BE[EA080000] mov esi, nl 907 00000368 E836000000 call pstring 908 ; jsr r5,pstring; nl 909 E15: ;1: 910 0000036D 5E pop esi ; r5 911 0000036E C3 retn 912 ; rts pc 913 914 pentry: 915 ;mov r2,-(sp) 916 0000036F 803D[1A090000]00 cmp byte [longf], 0 917 ; tstb longf 918 00000376 7743 ja short listl 919 ; bne listl 920 00000378 803D[1B090000]00 cmp byte [longf+1], 0 921 ; tstb longf+1 922 0000037F 7701 ja short S21 923 ; bne 2f 924 ; mov (sp)+,r2 925 00000381 C3 retn 926 ; rts r5 927 S21: ;2: 928 ; 12/01/2022 929 ; (14+8) 930 00000382 8B4616 mov eax, [esi+22] ; (Runix 386 v2 fs inode) 931 ; eax = file (or directory) size 932 ;movzx eax, word [esi+18] ; 04/12/2015 (+12 -> +18) 933 ; mov 12.(r3),r0 934 ; 12/01/2022 935 00000385 8A5E0F mov bl, [esi+15] ; high byte of inode flags 936 ; 937 00000388 E887020000 call calcb 938 ; jsr r5,calcb 939 0000038D 56 push esi 940 ;mov ebx, 3 941 ; 12/01/2022 942 0000038E 29DB sub ebx, ebx 943 00000390 B303 mov bl, 3 944 00000392 E842020000 call decimal 945 ; jsr r5,decimal; 3 946 00000397 E802000000 call _pstring 947 ; jsr r5,pstring; space 948 ; mov (sp)+,r2 949 0000039C 5E pop esi 950 0000039D C3 retn 951 ; rts r5 952 953 _pstring: 954 0000039E BE[F7080000] mov esi, space 955 956 pstring: 957 ; mov r5,-(sp) 958 ; mov (r5),r5 959 S22: ;1: 960 000003A3 AC lodsb 961 ; movb (r5)+,r0 962 000003A4 20C0 and al, al 963 000003A6 7407 jz short S23 964 ; beq 1f 965 ;mov ebx, obuf 966 000003A8 E88A020000 call putc 967 ; jsr r5,putc; obuf 968 000003AD EBF4 jmp short S22 969 ; br 1b 970 S23: ;1: 971 000003AF C3 retn 972 ; mov (sp)+,r5 973 ; tst (r5)+ 974 ; rts r5 975 976 questf: 977 000003B0 56 push esi 978 000003B1 89DE mov esi, ebx 979 ; mov r4,0f 980 000003B3 E8EBFFFFFF call pstring 981 ; jsr r5,pstring; 0:.. 982 000003B8 5E pop esi 983 ; mov r5,0f 984 ;call pstring 985 ; jsr r5,pstring; 0:.. 986 ;retn 987 ; 988 000003B9 EBE8 jmp short pstring 989 ;1: 990 ; tstb (r5)+ 991 ; bne 1b 992 ; inc r5 993 ; bic $1,r5 994 ; rts r5 995 listl: 996 ; 06/10/2015 (32 bit modifications) 997 ;movzx eax, word [esi+24] ; 04/12/2015 (+18 -> +24) 998 ; ; mov 18.(r3),r0 / inode 999 ; 12/01/2022 (Retro UNIX 386 v1.2) 1000 000003BB 0FB7461E movzx eax, word [esi+30] ; inode number (14+16) 1001 000003BF 56 push esi ; r3 1002 ;mov ebx, 4 1003 ; 12/01/2022 1004 000003C0 31DB xor ebx, ebx 1005 000003C2 B304 mov bl, 4 1006 000003C4 E810020000 call decimal 1007 ; jsr r5,decimal; 4 1008 000003C9 E8D0FFFFFF call _pstring 1009 ; jsr r5,pstring; space 1010 1011 000003CE 5E pop esi ; r3 1012 000003CF 89F7 mov edi, esi 1013 ; mov r3,r4 1014 ;add edi, 14 ; 04/12/2015 (8 -> 14) 1015 ; ; add $8.,r4 / get to flags 1016 ; 12/01/2022 1017 000003D1 83C70F add edi, 15 1018 000003D4 8A07 mov al, [edi] ; [edi+1] 1019 000003D6 4F dec edi ; (add edi, 14) 1020 000003D7 A2[1F090000] mov [flgsh], al 1021 ;test byte [edi+1], 80h 1022 000003DC A880 test al, 80h ; regular file ? 1023 000003DE 7514 jnz short F0 1024 000003E0 B063 mov al, 'c' ; character device 1025 000003E2 F605[1F090000]40 test byte [flgsh], 40h 1026 ;test byte [edi+1], 40h ; block device 1027 000003E9 7402 jz short F16 1028 000003EB B062 mov al, 'b' ; block device 1029 F16: 1030 ; 12/01/2022 1031 ;test byte [flgs], 20h ; must be 1 1032 ;jnz short F17 1033 ;mov al, '?' 1034 ;F17: 1035 000003ED E845020000 call mode 1036 000003F2 EB21 jmp short F3 1037 F0: 1038 ; 12/01/2022 1039 000003F4 F605[1F090000]10 test byte [flgsh], 10h 1040 ;test byte [edi+1], 10h 1041 ;;test word [edi], 1000h 1042 ; bit $10000,(r4) /large 1043 000003FB 7404 jz short F1 1044 ; beq 2f 1045 000003FD B06C mov al, 'l' 1046 ; 13/01/2022 1047 ;call mode 1048 ; jsr r5,mode; 'l 1049 000003FF EB02 jmp short F2 1050 ; br 3f 1051 F1: ;2: 1052 00000401 B073 mov al, 's' 1053 F2: ; 14/01/2022 1054 00000403 E82F020000 call mode 1055 ; jsr r5,mode; 's 1056 ;F2: ;3: 1057 ; 12/01/2022 1058 00000408 F605[1F090000]40 test byte [flgsh], 40h 1059 ;test byte [edi+1], 40h 1060 ;;test word [edi], 4000h 1061 ; bit $40000,(r4) /directory 1062 0000040F 7404 jz short F3 1063 ; beq 2f 1064 00000411 B064 mov al, 'd' 1065 ; 13/01/2022 1066 ;call mode 1067 ; jsr r5,mode; 'd 1068 00000413 EB16 jmp short F6 1069 ; br 3f 1070 F3: ;2: 1071 ; 12/01/2022 1072 00000415 F605[1F090000]08 test byte [flgsh], 8 ; set uid 1073 ;test byte [edi], 20h 1074 ; bit $40,(r4) /set uid 1075 0000041C 7404 jz short F4 1076 ; beq 2f 1077 0000041E B075 mov al, 'u' 1078 ; 13/01/2022 1079 ;call mode 1080 ; jsr r5,mode; 'u 1081 00000420 EB09 jmp short F6 1082 ; br 3f 1083 F4: ;2: 1084 ; 13/01/2022 1085 00000422 B02D mov al, '-' 1086 ; 12/01/2022 1087 00000424 F60749 test byte [edi], 49h ; 40h+08h+01h 1088 ;test byte [edi], 10h 1089 ; ; bit $20,(r4) /executable 1090 00000427 7402 jz short F5 1091 ; beq 2f 1092 00000429 B078 mov al, 'x' 1093 ; 13/01/2022 1094 ;call mode 1095 ; jsr r5,mode; 'x 1096 ;jmp short F6 1097 ; br 3f 1098 F5: ;2: 1099 ; 13/01/2022 1100 ;call _mode 1101 ; jsr r5,mode; '- 1102 F6: ;3: 1103 ; 13/01/2022 1104 0000042B E807020000 call mode 1105 00000430 B02D mov al, '-' 1106 ; 1107 ; 12/01/2022 1108 00000432 F605[1F090000]01 test byte [flgsh], 1 ; read owner 1109 ;test byte [edi], 8 1110 ; bit $10,(r4) /read owner 1111 00000439 7402 jz short F7 1112 ; beq 2f 1113 0000043B B072 mov al, 'r' 1114 ; 13/01/2022 1115 F7: 1116 0000043D E8F5010000 call mode 1117 ; jsr r5,mode; 'r 1118 ;jmp short F8 1119 ; br 3f 1120 ;F7: ;2: 1121 ; 13/01/2022 1122 ;call _mode 1123 ; jsr r5, mode; '- 1124 F8: ;3: 1125 ; 13/01/2022 1126 00000442 B02D mov al, '-' 1127 ; 1128 ; 12/01/2022 1129 00000444 F60780 test byte [edi], 80h ; write owner 1130 ;test byte [edi], 4 1131 ; bit $4,(r4) /write owner 1132 00000447 7402 jz short F9 1133 ; beq 2f 1134 00000449 B077 mov al, 'w' 1135 ; 13/01/2022 1136 F9: 1137 0000044B E8E7010000 call mode 1138 ; jsr r5,mode; 'w 1139 ;jmp short F10 1140 ; br 3f 1141 ;F9: ;2: 1142 ;call _mode 1143 ; jsr r5,mode; '- 1144 F10: ;3: 1145 ; 13/01/2022 1146 00000450 B02D mov al, '-' 1147 ; 1148 ; 12/01/2022 1149 00000452 F60724 test byte [edi], 24h ; 20h+04h 1150 ;test byte [edi], 2 1151 ; bit $2,(r4) /read non-owner 1152 00000455 7402 jz short F11 1153 ; beq 2f 1154 00000457 B072 mov al, 'r' 1155 ; 13/01/2022 1156 F11: 1157 00000459 E8D9010000 call mode 1158 ; jsr r5,mode; 'r 1159 ;jmp short F12 1160 ; br 3f 1161 ;F11: ;2: 1162 ;call _mode 1163 ; jsr r5,mode; '- 1164 F12: ;3: 1165 ; 13/01/2022 1166 0000045E B02D mov al, '-' 1167 ; 1168 ; 12/01/2022 1169 00000460 F60712 test byte [edi], 12h ; 10h+02h 1170 ;test byte [edi], 1 ; (r4) 1171 ; bit $1,(r4)+ /write non-owner 1172 00000463 7402 jz short F13 1173 ; beq 2f 1174 00000465 B077 mov al, 'w' 1175 F13: 1176 00000467 E8CB010000 call mode 1177 ; jsr r5,mode; 'w 1178 ;jmp short F14 1179 ; br 3f 1180 ;F13: ;2: 1181 ;call _mode 1182 ; jsr r5,mode; '- 1183 F14: ;3: 1184 0000046C 56 push esi ; r3 1185 0000046D E82CFFFFFF call _pstring 1186 ; jsr r5,pstring; space 1187 ; inc edi, 4 ;; (r4)+ 1188 ; inc edi ;; 1189 00000472 89FE mov esi, edi 1190 00000474 66AD lodsw ; (r4)+ 1191 ;lodsb ;; nlinks 1192 ; 12/01/2022 1193 00000476 29C0 sub eax, eax 1194 00000478 66AD lodsw ;; nlinks 1195 ;movzx eax, al 1196 ; movb (r4)+,r0 1197 ;mov ebx, 2 1198 ; 12/01/2022 1199 0000047A 29DB sub ebx, ebx 1200 0000047C B302 mov bl, 2 1201 0000047E E84E010000 call _decimal 1202 ; jsr r5,decimal; 2 1203 ; 12/01/2022 1204 00000483 66AD lodsw ;; uid 1205 ;lodsb ;; uid 1206 ; movb (r4)+,r2 1207 00000485 E834000000 call puid 1208 ; jsr pc,puid 1209 ; 12/01/2022 1210 0000048A AC lodsb ;; gid 1211 0000048B AC lodsb ;; size_h 1212 ;lodsw ;; size 1213 ; mov (r4)+,r0 1214 0000048C AD lodsd ;; size ; 12/01/2022 1215 ;;movzx eax, ax 1216 ;mov ebx, 5 1217 ; 12/01/2022 1218 0000048D 31DB xor ebx, ebx 1219 0000048F B305 mov bl, 5 1220 00000491 E83B010000 call _decimal 1221 ; jsr r5,decimal; 5 1222 00000496 56 push esi 1223 00000497 E802FFFFFF call _pstring 1224 ; jsr r5,pstring; space 1225 0000049C 5E pop esi 1226 ; mov r1,-(sp) 1227 0000049D 8B1D[09090000] mov ebx, [eol] ;r1 1228 000004A3 AD lodsd ; mtime 1229 ; mov (r4)+,r0 1230 ; mov (r4)+,r1 1231 ; sub $16.,sp 1232 ; mov sp,r2 1233 ; EAX = unix time (epoch) 1234 000004A4 E830020000 call ctime 1235 ; jsr pc,ctime 1236 ; mov sp,r2 1237 ;mov ecx, 25 1238 ; 12/01/2022 1239 000004A9 29C9 sub ecx, ecx 1240 000004AB B119 mov cl, 25 1241 ;;mov ecx, 15 1242 ; mov $15.,-(sp) 1243 000004AD BE[BE080000] mov esi, cbuf 1244 F15: ;1: 1245 000004B2 51 push ecx 1246 000004B3 AC lodsb 1247 ; movb (r2)+,r0 1248 ;mov ebx, obuf 1249 000004B4 E87E010000 call putc 1250 ; jsr r5,putc; obuf 1251 000004B9 59 pop ecx 1252 000004BA E2F6 loop F15 1253 ; dec (sp) 1254 ; bne 1b 1255 ; add $18.,sp 1256 ; mov (sp)+,r1 1257 ;call _pstring 1258 ; jsr r5,pstring; space 1259 ; mov (sp)+,r2 1260 000004BC 5E pop esi ; r3 1261 000004BD C3 retn 1262 ; rts r5 1263 1264 puid: 1265 ; 22/01/2022 1266 ; 20/01/2022 - Retro UNIX 386 v1.2 1267 ; 06/10/2015 (32 bit modifications) 1268 ; print user name 1269 ; AL = user id/number 1270 ; 1271 000004BE 56 push esi ; r4 ; 20/01/2022 1272 G0: 1273 ; 22/01/2022 1274 ;push eax ; r2 1275 ; ; mov r1,-(sp) 1276 000004BF BE[BE0D0000] mov esi, uidbuf 1277 ; mov $uidbuf,r1 1278 G1: ;1: 1279 ; 22/01/2022 1280 000004C4 50 push eax ; r2 1281 ; mov r1,-(sp) 1282 ;cmp esi, [euids] ; 22/01/2022 1283 ; cmp r1,euids 1284 ;jnb short G8 1285 ; bhis 1f 1286 000004C5 56 push esi ; 0: 1287 ; mov r1,0f 1288 G2: ;2: 1289 000004C6 AC lodsb 1290 000004C7 20C0 and al, al 1291 ; tstb (r1)+ 1292 000004C9 7409 jz short G3 1293 ; beq 3f 1294 000004CB 3C3A cmp al, ':' 1295 ; cmpb -1(r1),$': 1296 000004CD 75F7 jne short G2 1297 ; bne 2b 1298 000004CF 30C0 xor al, al ; 0 1299 000004D1 8846FF mov [esi-1], al ;0 1300 ; clrb -1(r1) 1301 G3: ;3: 1302 000004D4 31DB xor ebx, ebx 1303 ; clr -(sp) 1304 ;mov ecx, 10 1305 000004D6 B10A mov cl, 10 1306 G4: ;3: 1307 000004D8 AC lodsb 1308 ; movb (r1)+,r0 1309 000004D9 2C30 sub al, '0' 1310 ; sub $'0,r0 1311 000004DB 3C09 cmp al, 9 1312 ; cmp r0,$9. 1313 000004DD 770A ja short G5 1314 ; bhi 3f 1315 ; mov r1,-(sp) 1316 ; 07/10/2015 1317 000004DF 0FB6C0 movzx eax, al 1318 000004E2 93 xchg eax, ebx 1319 ; mov 2(sp),r1 1320 000004E3 F7E1 mul ecx 1321 ; mpy $10.,r1 1322 000004E5 01C3 add ebx, eax 1323 ; add r0,r1 1324 ; mov r1,2(sp) 1325 ; mov (sp)+,r1 1326 000004E7 EBEF jmp short G4 1327 ; br 3b 1328 G5: ;3: 1329 ;pop esi ; 0: 1330 ; 20/01/2022 1331 ; (esi = r1) 1332 000004E9 5A pop edx ; 0: 1333 000004EA 58 pop eax ; r2 1334 ; mov (sp)+,r0 1335 000004EB 39C3 cmp ebx, eax 1336 ; cmp r0,r2 1337 ;jne short G1 1338 ; bne 1b 1339 000004ED 7424 je short S24 1340 ; 20/01/2022 1341 ; (esi = r1) 1342 000004EF 3B35[E4080000] cmp esi, [euids] ; 22/01/2022 1343 000004F5 72CD jb short G1 1344 ;jmp short G8 1345 G8: 1346 000004F7 50 push eax ; r2/UID 1347 000004F8 E8A1FEFFFF call _pstring 1348 ;jsr r5,pstring; space 1349 000004FD 58 pop eax 1350 ; mov r2,r0 1351 ;mov ebx, 3 1352 ; 12/01/2022 1353 000004FE 29DB sub ebx, ebx 1354 00000500 B303 mov bl, 3 1355 00000502 E8D2000000 call decimal 1356 ; jsr r5,decimal; 3 1357 00000507 BE[F4080000] mov esi, space3 1358 0000050C E892FEFFFF call pstring 1359 ; jsr r5,pstring; space3 1360 00000511 5E pop esi ; r4 ; 20/01/2022 1361 ; mov (sp)+,r1 1362 00000512 C3 retn 1363 ; rts pc 1364 S24: 1365 ;push esi ; 0: 1366 ; 20/01/2022 1367 00000513 52 push edx ; 0: 1368 00000514 E885FEFFFF call _pstring 1369 ; jsr r5,pstring; space 1370 00000519 5E pop esi ; 0: 1371 0000051A 56 push esi ; 0: 1372 0000051B E883FEFFFF call pstring 1373 ; jsr r5,pstring; 0:.. 1374 00000520 5E pop esi ; 0: 1375 ; mov 0b,r1 1376 ; 12/01/2022 1377 00000521 31C9 xor ecx, ecx 1378 00000523 B106 mov cl, 6 1379 ;mov cx, 6 1380 ; mov $6,-(sp) 1381 G6: ;3: 1382 00000525 AC lodsb 1383 ; tstb (r1)+ 1384 00000526 20C0 and al, al 1385 00000528 7406 jz short G7 1386 ; beq 3f 1387 0000052A FEC9 dec cl 1388 ; dec (sp) 1389 ;jmp short G6 1390 ; ; br 3b 1391 ; 22/01/2022 1392 ; (max. 5 chars of uid will be usable here) 1393 0000052C 75F7 jnz short G6 1394 0000052E FEC1 inc cl 1395 G7: ;3: 1396 ;push cx 1397 ; 12/01/2022 1398 00000530 51 push ecx 1399 00000531 E868FEFFFF call _pstring 1400 ; jsr r5,pstring; space 1401 ;pop cx 1402 00000536 59 pop ecx 1403 ; 12/01/2022 1404 00000537 49 dec ecx 1405 ;dec cx 1406 ; dec (sp) 1407 ;jg short G7 1408 ; ; bgt 3b 1409 ; 22/01/2022 1410 00000538 75F6 jnz short G7 1411 ; tst (sp)+ 1412 0000053A 5E pop esi ; r4 ; 20/01/2022 1413 ; mov (sp)+,r1 1414 0000053B C3 retn 1415 ; rts pc 1416 ;G8: ;1: 1417 ; jsr r5,pstring; space 1418 ; mov r2,r0 1419 ; jsr r5,decimal; 3 1420 ; jsr r5,pstring; space3 1421 ; mov (sp)+,r1 1422 ; rts pc 1423 1424 ;_mode: 1425 ; mov al, '-' 1426 ;mode: 1427 ; AL = mode char 1428 ; mov (r5)+,r0 1429 ;mov ebx, obuf 1430 ; call putc 1431 ; jsr r5,putc; obuf 1432 ; retn 1433 ; rts r5 1434 1435 gstat: 1436 ; 06/10/2015 (32 bit modifications) 1437 0000053C 55 push ebp 1438 ; mov r1,-(sp) 1439 0000053D 81C500020000 add ebp, 512 1440 ; add $512.,r1 1441 00000543 3B2D[D8080000] cmp ebp, [brk] 1442 ; cmp r1,0f 1443 00000549 720F jb short D1 1444 ; blo 1f 1445 0000054B 892D[D8080000] mov [brk], ebp 1446 ; mov r1,0f 1447 sys _break, ebp ; sys _break, brk 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 00000551 89EB <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 00000553 B811000000 <1> mov eax, %1 90 00000558 CD30 <1> int 30h 1448 ; sys break; 0: end+512. 1449 D1: ;1: 1450 0000055A 5D pop ebp 1451 ; mov (sp)+,r1 1452 0000055B 31C0 xor eax, eax 1453 ; Detailed (Long) listing 1454 0000055D 663905[1A090000] cmp [longf], ax ;0 1455 ; tst longf 1456 00000564 7708 ja short D2 1457 ; bne 2f 1458 ; Sorting by modification time 1459 00000566 3905[24090000] cmp [sortoff], eax ;0 1460 ; tst sortoff 1461 0000056C 761D jna short D3 1462 ; beq 1f 1463 D2: ;2: 1464 sys _stat, filnam, statb 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 0000056E BB[28090000] <1> mov ebx, %2 82 <1> %if %0 >= 3 83 00000573 B9[66090000] <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 00000578 B812000000 <1> mov eax, %1 90 0000057D CD30 <1> int 30h 1465 ; sys stat; filnam; statb 1466 0000057F 731C jnc short D4 1467 ; bec 2f 1468 ; mov r4,-(sp) 1469 ;mov ebx, filnam 1470 ; mov $filnam,r4 1471 00000581 BE[8F050000] mov esi, S25 1472 00000586 E825FEFFFF call questf 1473 ; jsr r5,questf; < unstatable\n\0>; .even 1474 ; mov (sp)+,r4 1475 D3: ;1: 1476 ; 12/01/2022 1477 0000058B 83C512 add ebp, 18 ; 32-14 1478 ;add ebp, 12 ; 26-14 ? 1479 ; add $12.,r1 1480 0000058E C3 retn 1481 ; rts r5 1482 S25: 1483 0000058F 20756E737461746162- db ' unstatable', 0Dh, 0Ah, 0 1483 00000598 6C650D0A00 1484 1485 D4: ;2: 1486 0000059D 57 push edi 1487 0000059E 89EF mov edi, ebp 1488 000005A0 BE[68090000] mov esi, statb + 2 1489 ; mov $statb+2,r0 1490 ;movsd 1491 ; mov (r0)+,(r1)+ /flags 1492 ; mov (r0)+,(r1)+ /nlinks, uid 1493 ; mov r0,-(sp) 1494 ; 12/01/2022 - Retro UNIX 386 v2 fs inode 1495 ;mov bl, [esi+1] ; high byte of inode flags 1496 000005A5 AD lodsd ; flags (w), nlinks (w) 1497 000005A6 AB stosd 1498 000005A7 88E3 mov bl, ah ; ((calcb will use this)) 1499 ;movsd ; flags (w), nlinks (w) 1500 000005A9 A5 movsd ; uid (w), guid (b), size_h (b) 1501 1502 ;movzx eax, word [esi] 1503 ; mov (r0),r0 1504 ; 12/01/2022 1505 ;mov eax, [esi] ; size (dd) 1506 000005AA AD lodsd ; size 1507 ; eax = file (directory) size 1508 ; 17/01/2021 1509 000005AB F6C380 test bl, 80h ; regular file flag 1510 000005AE 7505 jnz short D5 ; regular file 1511 ; device file 1512 ; eax = major, minor device num (not 1st block num!) 1513 ; file size = 0 1514 000005B0 29C0 sub eax, eax 1515 000005B2 AB stosd 1516 000005B3 EB0C jmp short D6 1517 D5: 1518 000005B5 AB stosd 1519 000005B6 E859000000 call calcb 1520 ; jsr r5,calcb 1521 000005BB 0105[20090000] add [tblocks], eax 1522 ; add r0,tblocks 1523 ; mov (sp)+,r0 1524 ;movsw 1525 ; ; mov (r0)+,(r1)+ /size 1526 ; 12/01/2022 - 32 bit file size 1527 ;movsd ; size (dd) 1528 D6: 1529 ;add esi, 20 1530 ; ; add $20.,r0 /dska, ctim 1531 000005C1 83C62C add esi, 44 ; Retro UNIX 386 v2 fs inode 1532 000005C4 A5 movsd ; inode (file) modification/write time 1533 ; mov (r0)+,(r1)+ /mtim 1534 ; mov (r0)+,(r1)+ 1535 000005C5 66A1[66090000] mov ax, [statb] 1536 000005CB 66AB stosw 1537 ; mov statb,(r1)+ /inode 1538 000005CD 89FD mov ebp, edi 1539 000005CF 5F pop edi 1540 000005D0 C3 retn 1541 ; rts r5 1542 ;D4: ;1: 1543 ; add ebp, 12 1544 ; add $12.,r1 1545 ; retn 1546 ; rts r5 1547 1548 _decimal: 1549 000005D1 56 push esi 1550 000005D2 E802000000 call decimal 1551 000005D7 5E pop esi 1552 000005D8 C3 retn 1553 1554 decimal: 1555 ; convert number to decimal number chars 1556 ; 5/10/2015 (32 bit modifications) 1557 ; EAX = number to be converted 1558 ; EBX = number of digits (=4) 1559 ; mov r1,-(sp) 1560 ; mov r2,-(sp) 1561 ; mov r3,-(sp) 1562 ;push edi 1563 000005D9 31D2 xor edx, edx 1564 ; 12/01/2022 1565 000005DB 29C9 sub ecx, ecx 1566 000005DD B10A mov cl, 10 1567 000005DF 89CE mov esi, ecx ; esi = 10 1568 000005E1 B106 mov cl, 6 1569 ;mov ecx, 6 1570 ; mov $6,r2 1571 000005E3 BF[BE0D0000] mov edi, numbuf + 6 1572 ; mov $numbuf+6,r3 1573 ; 12/01/2022 1574 ;mov esi, 10 1575 S26: ;1: 1576 ;and eax, eax 1577 ;jz short S27 1578 ;mov r0,r1 1579 ;xor edx, edx 1580 ; clr r0 1581 ;mov esi, 10 1582 ; dvd $10.,r0 1583 000005E8 F7F6 div esi 1584 ;S27: 1585 000005EA 80C230 add dl, '0' 1586 ; add $'0,r1 1587 000005ED 4F dec edi 1588 000005EE 8817 mov [edi], dl 1589 ; movb r1,-(r3) 1590 000005F0 30D2 xor dl, dl 1591 000005F2 E2F4 loop S26 1592 ; sob r2,1b 1593 000005F4 B020 mov al, 20h ; space 1594 000005F6 B105 mov cl, 5 1595 S28: ;1: 1596 ;cmp edi, numbuf + 5 1597 ; cmp r3,$numbuf+5 1598 ;je short S29 1599 ; beq 1f 1600 000005F8 803F30 cmp byte [edi], '0' 1601 ; cmpb (r3),$'0 1602 000005FB 7503 jne short S29 1603 ; bne 1f 1604 ;mov al, 20h 1605 000005FD AA stosb 1606 ; movb $' ,(r3)+ 1607 ;jmp short S28 1608 ; br 1b 1609 000005FE E2F8 loop S28 1610 S29: ;1: 1611 00000600 BE[BE0D0000] mov esi, numbuf + 6 1612 ; mov $numbuf+6,r1 1613 00000605 29DE sub esi, ebx 1614 ; sub (r5),r1 1615 ;mov ecx, ebx 1616 00000607 88D9 mov cl, bl 1617 ; mov (r5)+,-(sp) 1618 S30: ;1: 1619 00000609 51 push ecx 1620 0000060A AC lodsb 1621 ; movb (r1)+,r0 1622 ;mov ebx, obuf 1623 0000060B E827000000 call putc 1624 ; jsr r5,putc; obuf 1625 00000610 59 pop ecx 1626 00000611 E2F6 loop S30 1627 ; dec (sp) 1628 ; bne 1b 1629 ; tst (sp)+ 1630 ; mov (sp)+,r3 1631 ; mov (sp)+,r2 1632 ; mov (sp)+,r1 1633 ;pop edi 1634 00000613 C3 retn 1635 ; rts r5 1636 1637 calcb: 1638 ; 13/01/2022 1639 ; 06/10/2015 (32 bit modifications) 1640 ; calculate number of blocks 1641 ; 12/01/2022 - Retro UNIX 386 v2 fs inode 1642 ; bl = high byte of inode flags 1643 ; eax = file (directory) size 1644 00000614 05FF010000 add eax, 511 1645 00000619 C1E809 shr eax, 9 ; (eax+511)/512 1646 ; add $511.,r0 1647 ; clrb r0 1648 ; swab r0 1649 ; asr r0 1650 ; eax = (size+511)/512 1651 ; large file ? (>=4096 bytes) 1652 ;cmp eax, 8 1653 ; ; cmp r0,$8 1654 ;jb short S31 1655 ; ; blo 1f 1656 ; add indirect block 1657 ;inc eax 1658 ; ; inc r0 1659 ;S31: ;1: 1660 ;retn 1661 ; rts r5 1662 1663 ; 12/01/2022 - Retro UNIX 386 v2 fs inode 1664 ; bl = high byte of inode flags 1665 1666 0000061C F6C310 test bl, 10h ; large file flag 1667 0000061F 7415 jz short S37 ; 14/01/2022 1668 1669 ; 12/01/2022 - Retro UNIX 386 v1.2 ls 1670 ; NOTE: this ls version does not recognize 1671 ; double and triple indirect blocks.. 1672 ; file size limit: 8*128*512 bytes 1673 ; (8 indirect blocks, <= 512KB file size) 1674 1675 00000621 50 push eax 1676 00000622 83C07F add eax, 127 1677 00000625 C1E807 shr eax, 7 1678 ; eax = number of indirect blocks 1679 00000628 83F808 cmp eax, 8 1680 0000062B 7605 jna short S31 1681 ; limit file size to 512 KB (for now!) 1682 0000062D B808000000 mov eax, 8 1683 S31: 1684 ; add indirect blocks (<=8) 1685 00000632 010424 add [esp], eax 1686 00000635 58 pop eax 1687 S37: 1688 00000636 C3 retn 1689 1690 ; 13/01/2022 1691 ;_mode: 1692 ; mov al, '-' 1693 mode: 1694 ; AL = mode char 1695 ; mov (r5)+,r0 1696 ;mov ebx, obuf 1697 ; call putc 1698 ; jsr r5,putc; obuf 1699 ; retn 1700 ; rts r5 1701 1702 ; 'putc' procedure 1703 ; is derived from 'put.s' 1704 ; file of original UNIX v5 1705 ; 1706 ; write characters on output file 1707 putc: 1708 ; AL = character to be written 1709 ; obuf = output buffer 1710 ;; EBX = buffer address 1711 00000637 56 push esi 1712 ;mov r1,-(sp) 1713 00000638 BE[B00B0000] mov esi, obuf 1714 ;mov esi, ebx 1715 ;mov (r5)+,r1 1716 S32: ;1: 1717 0000063D 66FF4E02 dec word [esi+2] 1718 ; dec 2(r1) 1719 00000641 7909 jns short S33 1720 ; bge 1f 1721 00000643 50 push eax 1722 ; mov r0,-(sp) 1723 00000644 E80D000000 call fl 1724 ; jsr pc,fl 1725 00000649 58 pop eax 1726 ; mov (sp)+,r0 1727 0000064A EBF1 jmp short S32 1728 ; br 1b 1729 S33: ;1: 1730 0000064C 8B5E04 mov ebx, [esi+4] 1731 0000064F 8803 mov [ebx], al 1732 ; movb r0,*4(r1) 1733 00000651 FF4604 inc dword [esi+4] 1734 ; inc 4(r1) 1735 00000654 5E pop esi 1736 ; mov (sp)+,r1 1737 00000655 C3 retn 1738 ; rts r5 1739 1740 ; 'flush' procedure 1741 ; is derived from 'put.s' 1742 ; file of original UNIX v5 1743 1744 flush: 1745 ; mov r0,-(sp) 1746 ; mov r1,-(sp) 1747 ; mov (r5)+,r1 1748 ; jsr pc,fl 1749 ; mov (sp)+,r1 1750 ; mov (sp)+,r0 1751 ; rts r5 1752 fl: 1753 ;mov ecx, esi 1754 ; ; mov r1,r0 1755 ;add ecx, 8 1756 ; ; add $6,r0 1757 ; 12/01/2022 1758 ;lea ecx, [esi+8] 1759 00000656 31C9 xor ecx, ecx 1760 00000658 B108 mov cl, 8 1761 0000065A 01F1 add ecx, esi 1762 ;push ecx ; Buffer data address 1763 ; mov r0,-(sp) 1764 ; mov r0,0f 1765 0000065C 8B5604 mov edx, [esi+4] ; Buffer offset 1766 ; mov 4(r1),0f+2 1767 0000065F 09D2 or edx, edx 1768 00000661 740C jz short S34 1769 ; beq 1f 1770 00000663 29CA sub edx, ecx ; Byte count 1771 ; sub (sp),0f+2 1772 ;movzx ebx, word [esi] ; File descriptor (=1) 1773 ; mov (r1),r0 1774 ; 12/01/2022 1775 00000665 0FB61E movzx ebx, byte [esi] ; File descriptor (=1) 1776 ; 1777 sys _write ; sys _write, ebx, ecx, edx 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 00000668 B804000000 <1> mov eax, %1 90 0000066D CD30 <1> int 30h 1778 ; sys 0; 9f 1779 ;.data 1780 ;9: 1781 ; ; sys write; 0:..; .. 1782 ;.text 1783 S34: ;1: 1784 ;pop ecx 1785 0000066F 894E04 mov [esi+4], ecx ; Begin. of buf. data 1786 ; mov (sp)+,4(r1) 1787 00000672 66C746020002 mov word [esi+2], 512 ; Buffer data size 1788 ; mov $512.,2(r1) 1789 00000678 C3 retn 1790 ; rts pc 1791 1792 ; 'getw', 'getc' and 'fopen' procedures 1793 ; are derived from 'get.s' 1794 ; file of original UNIX v5 1795 1796 ; open a file for use by get(c|w) 1797 ; 1798 fopen: 1799 ; EBX = file name offset 1800 ; EDI = buffer offset 1801 ; 1802 00000679 31C9 xor ecx, ecx ; 0 => open for read 1803 sys _open ; sys _open, ebx, ecx (0) 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 0000067B B805000000 <1> mov eax, %1 90 00000680 CD30 <1> int 30h 1804 00000682 7202 jc short S35 1805 ;stosw ; file descriptor (in buffer offset 0) 1806 ; 12/01/2022 1807 00000684 AA stosb ; file descriptor 1808 00000685 C3 retn 1809 S35: 1810 ;mov ax, 0FFFFh ; -1 1811 ;stosw 1812 ; 12/01/2022 1813 00000686 B0FF mov al, 0FFh ; -1 1814 00000688 AA stosb 1815 ;stc 1816 00000689 C3 retn 1817 1818 ; get words from input file 1819 ; 1820 getw: 1821 ;mov esi, ebx 1822 0000068A E80E000000 call getc 1823 0000068F 720B jc short S36 1824 1825 ; 12/01/2022 1826 ;push ax 1827 00000691 50 push eax 1828 00000692 E806000000 call getc 1829 ;;pop dx 1830 ;pop edx 1831 ;mov ah, dl 1832 ;xchg ah, al 1833 ; 14/01/2022 1834 00000697 88442401 mov [esp+1], al 1835 0000069B 58 pop eax 1836 S36: 1837 0000069C C3 retn 1838 1839 ; get characters from input file 1840 ; 1841 getc: 1842 ; ESI = buffer address 1843 0000069D 668B4602 mov ax, [esi+2] ; char count 1844 000006A1 6621C0 and ax, ax 1845 000006A4 751D jnz short gch1 1846 gch0: 1847 ;mov ecx, esi 1848 ;add ecx, 8 ; read buffer address 1849 ; 12/01/2022 1850 ;lea ecx, [esi+8] 1851 000006A6 29C9 sub ecx, ecx 1852 000006A8 B108 mov cl, 8 1853 000006AA 01F1 add ecx, esi ; buffer data address 1854 ;movzx ebx, word [esi] 1855 ; 12/01/2022 1856 000006AC 0FB61E movzx ebx, byte [esi] 1857 000006AF 894E04 mov [esi+4], ecx ; char offset 1858 ;xor ax, ax 1859 ;mov [esi+2], ax ; 0 1860 ;mov edx, 512 1861 ; 12/01/2022 1862 000006B2 31D2 xor edx, edx 1863 000006B4 B602 mov dh, 2 ; edx = 512 1864 sys _read ; sys _read, ebx, ecx, edx 77 <1> 78 <1> 79 <1> 80 <1> %if %0 >= 2 81 <1> mov ebx, %2 82 <1> %if %0 >= 3 83 <1> mov ecx, %3 84 <1> %if %0 = 4 85 <1> mov edx, %4 86 <1> %endif 87 <1> %endif 88 <1> %endif 89 000006B6 B803000000 <1> mov eax, %1 90 000006BB CD30 <1> int 30h 1865 000006BD 7216 jc short gch2 1866 000006BF 09C0 or eax, eax 1867 000006C1 7414 jz short gch3 1868 gch1: 1869 000006C3 6648 dec ax 1870 000006C5 66894602 mov [esi+2], ax 1871 000006C9 8B5E04 mov ebx, [esi+4] 1872 000006CC 31C0 xor eax, eax ; 12/01/2022 1873 000006CE 8A03 mov al, [ebx] 1874 000006D0 43 inc ebx 1875 000006D1 895E04 mov [esi+4], ebx 1876 ;xor ah, ah 1877 000006D4 C3 retn 1878 gch2: 1879 ;xor ax, ax 1880 ; 12/01/2022 1881 000006D5 29C0 sub eax, eax 1882 gch3: 1883 000006D7 F9 stc 1884 000006D8 C3 retn 1885 1886 ;/ getw/getc -- get words/characters from input file 1887 ;/ fopen -- open a file for use by get(c|w) 1888 ;/ 1889 ;/ calling sequences -- 1890 ;/ 1891 ;/ mov $filename,r0 1892 ;/ jsr r5,fopen; ioptr 1893 ;/ 1894 ;/ on return ioptr buffer is set up or error bit is set if 1895 ;/ file could not be opened. 1896 ;/ 1897 ;/ jsr r5,get(c|w)1; ioptr 1898 ;/ 1899 ;/ on return char/word is in r0; error bit is 1900 ;/ set on error or end of file. 1901 ;/ 1902 ;/ ioptr is the address of a 518-byte buffer 1903 ;/ whose layout is as follows: 1904 ;/ 1905 ;/ ioptr: .=.+2 / file descriptor 1906 ; .=.+2 /// buffer size (This is noted by Erdogan Tan; 19/11/2013) 1907 ;/ .=.+2 / charact+2 / pointer to next character (reset if no. chars=0) 1908 ;/ .=.+512. / the buffer 1909 1910 ; .globl getc,getw,fopen 1911 1912 ;fopen: 1913 ; mov r1,-(sp) 1914 ; mov (r5)+,r1 1915 ; mov r0,0f 1916 ; sys 0; 9f 1917 ;.data 1918 ;9: 1919 ; sys open; 0:..; 0 1920 ;.text 1921 ; bes 1f 1922 ; mov r0,(r1)+ 1923 ; clr (r1)+ 1924 ; mov (sp)+,r1 1925 ; rts r5 1926 ;1: 1927 ; mov $-1,(r1) 1928 ; mov (sp)+,r1 1929 ; sec 1930 ; rts r5 1931 ; 1932 ;.data 1933 ;getw: 1934 ; mov (r5),9f 1935 ; mov (r5)+,8f 1936 ; jsr r5,getc; 8:.. 1937 ; bec 1f 1938 ; rts r5 1939 ;1: 1940 ; mov r0,-(sp) 1941 ; jsr r5,getc; 9:.. 1942 ; swab r0 1943 ; bis (sp)+,r0 1944 ; rts r5 1945 ;.text 1946 ; 1947 ;getc: 1948 ; mov r1,-(sp) 1949 ; mov (r5)+,r1 1950 ; dec 2(r1) 1951 ; bge 1f 1952 ; mov r1,r0 1953 ; add $6,r0 1954 ; mov r0,0f 1955 ; mov r0,4(r1) 1956 ; mov (r1),r0 1957 ; sys 0; 9f 1958 ;.data 1959 ;9: 1960 ; sys read; 0:..; 512. 1961 ;.text 1962 ; bes 2f 1963 ; tst r0 1964 ; bne 3f 1965 ;2: 1966 ; mov (sp)+,r1 1967 ; sec 1968 ; rts r5 1969 ;3: 1970 ; dec r0 1971 ; mov r0,2(r1) 1972 ;1: 1973 ; clr r0 1974 ; bisb *4(r1),r0 1975 ; inc 4(r1) 1976 ; mov (sp)+,r1 1977 ; rts r5 1978 1979 ;%include 'ctime386.inc' ; 24/11/2013 1980 %include 'ctime386.s' ; 12/01/2022 1981 <1> ; **************************************************************************** 1982 <1> ; ctime386.inc (Retro Unix 386 v1 - /bin/ls - list file or directory) 1983 <1> ; ---------------------------------------------------------------------------- 1984 <1> ; RETRO UNIX 386 (Retro Unix == Turkish Rational Unix) 1985 <1> ; Operating System Project (v0.2) by ERDOGAN TAN (Beginning: 24/12/2013) 1986 <1> ; 1987 <1> ; [ Last Modification: 06/10/2015 ] 1988 <1> ; 1989 <1> ; Derived from 'CTIME.INC' source code file of 'Retro UNIX 8086 v1' 1990 <1> ; operating system project, /bin/ls source code by Erdogan Tan 1991 <1> ; (28/11/2013) 1992 <1> ; 1993 <1> ; Derived from 'ctime.c' file of original UNIX v5 (usr/source/s3/ctime.c) 1994 <1> ; 1995 <1> ; ls386.s (ls0.s) 23/09/2015 - 06/10/2015 1996 <1> ; include ctime386.inc 1997 <1> ; 1998 <1> ; **************************************************************************** 1999 <1> 2000 <1> ; Assembler: NASM 2.11 2001 <1> 2002 <1> ;timezone equ 5*60*60 2003 <1> 2004 <1> 2005 <1> ctime: ; ctime(at) 2006 <1> ; int *at; 2007 <1> ; { 2008 <1> ; return(asctime(localtime(at))); 2009 <1> ; } 2010 <1> 2011 <1> ; EAX = unix epoch time (in seconds) 2012 <1> 2013 <1> ;call localtime 2014 <1> ;call asctime 2015 <1> 2016 <1> ;retn 2017 <1> 2018 <1> localtime: 2019 <1> ; localtime(tim) 2020 <1> ; int tim[]; 2021 <1> ; { 2022 <1> ; register int *t, *ct, dayno; 2023 <1> ; int daylbegin, daylend; 2024 <1> ; int copyt[2]; 2025 <1> ; t = copyt; 2026 <1> ; t[0] = tim[0]; 2027 <1> ; t[1] = tim[1]; 2028 <1> ; dpadd(t, -timezone); 2029 <1> ; ct = gmtime(t); 2030 <1> ; dayno = ct[YDAY]; 2031 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 2032 <1> ; dayno==5 && ct[HOUR]>=2))) { 2033 <1> ; daylight =| 1; 2034 <1> ; daylbegin = -1; 2035 <1> ; daylend = 367; 2036 <1> ; } else { 2037 <1> ; daylbegin = sunday(ct, 119); /* last Sun in Apr */ 2038 <1> ; daylend = sunday(ct, 303); /* last Sun in Oct */ 2039 <1> ; } 2040 <1> ; if (daylight && 2041 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 2042 <1> ; (dayno ; dpadd(t, 1*60*60); 2044 <1> ; ct = gmtime(t); 2045 <1> ; ct[ISDAY]++; 2046 <1> ; } 2047 <1> ; return(ct); 2048 <1> ; } 2049 <1> 2050 <1> ;sub eax, timezone 2051 <1> 2052 <1> ;push eax 2053 <1> 2054 000006D9 E885000000 <1> call gmtime 2055 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 2056 <1> ; dayno==5 && ct[HOUR]>=2))) { 2057 <1> ;cmp byte [nixonflg], 0 2058 <1> ;jna short lt1 2059 <1> ;cmp word [year], 1974 2060 <1> ;jb short lt1 2061 <1> ;ja short lt0 2062 <1> ;cmp word [yday], 5 2063 <1> ;jb short lt1 2064 <1> ;ja short lt0 2065 <1> ;cmp word [hour], 2 2066 <1> ;jb short lt1 2067 <1> ; nixonflag > 0 2068 <1> ;lt0: 2069 <1> ;mov word [daylight], 1 2070 <1> ;mov word [daylbegin], -1 2071 <1> ;mov word [daylend], 367 2072 <1> ; ;jmp short lt2 2073 <1> 2074 <1> ; } else { 2075 <1> ;lt1: 2076 <1> ; mov cx, 119 2077 <1> ; call sunday ; sunday(ct, 119); /* last Sun in Apr */ 2078 <1> ; mov [daylbegin], cx 2079 <1> ; mov cx, 303 2080 <1> ; call sunday ; sunday(ct, 303); /* last Sun in Oct */ 2081 <1> ; mov [daylend], cx 2082 <1> ;lt2: 2083 <1> ; if (daylight && 2084 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 2085 <1> ; (dayno 2087 <1> ; pop eax 2088 <1> 2089 <1> ;cmp byte [daylight], 0 2090 <1> ;jna short lt5 2091 <1> 2092 <1> ;mov cx, [yday] 2093 <1> 2094 <1> ;cmp cx, [daylbegin] 2095 <1> ;jb short lt5 2096 <1> ;ja short lt3 2097 <1> ;cmp word [hour], 2 2098 <1> ;jb short lt5 2099 <1> ;jmp short lt4 2100 <1> ;lt3: 2101 <1> ;cmp cx, [daylend] 2102 <1> ;jb short lt4 2103 <1> ;ja short lt5 2104 <1> ;cmp word [hour], 1 2105 <1> ;jnb short lt5 2106 <1> ;lt4: 2107 <1> ;add eax, 1*60*60 2108 <1> ;call gmtime 2109 <1> ;inc word [isday] 2110 <1> ;lt5: 2111 <1> ; } 2112 <1> ; return(ct); 2113 <1> ; } 2114 <1> 2115 <1> ;retn 2116 <1> 2117 <1> 2118 <1> asctime: 2119 <1> ; asctime(t) 2120 <1> ;int *t; 2121 <1> ;{ 2122 <1> ; register char *cp, *ncp; 2123 <1> ; register int *tp; 2124 <1> ; 2125 <1> ; cp = cbuf; 2126 <1> ; for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;); 2127 <1> ; ncp = &"SunMonTueWedThuFriSat"[3*t[6]]; 2128 <1> ; cp = cbuf; 2129 <1> ; *cp++ = *ncp++; 2130 <1> ; *cp++ = *ncp++; 2131 <1> ; *cp++ = *ncp++; 2132 <1> ; cp++; 2133 <1> ; tp = &t[4]; 2134 <1> ; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3]; 2135 <1> ; *cp++ = *ncp++; 2136 <1> ; *cp++ = *ncp++; 2137 <1> ; *cp++ = *ncp++; 2138 <1> ; cp = numb(cp, *--tp); 2139 <1> ; cp = numb(cp, *--tp+100); 2140 <1> ; cp = numb(cp, *--tp+100); 2141 <1> ; cp = numb(cp, *--tp+100); 2142 <1> ; cp =+ 2; 2143 <1> ; cp = numb(cp, t[YEAR]); 2144 <1> ; return(cbuf); 2145 <1> ;} 2146 <1> 2147 <1> ;;mov edi, cbuf 2148 <1> ;;mov esi, ncp0 2149 <1> ;;mov ecx, 13 2150 <1> ;;movsw 2151 <1> ; 2152 000006DE BF[BE080000] <1> mov edi, cbuf 2153 <1> ;movzx esi, word [wday] 2154 <1> ;shl si, 2 2155 <1> ;add esi, ncp1 2156 <1> ;movsd 2157 000006E3 0FB735[54080000] <1> movzx esi, word [month] 2158 000006EA 66C1E602 <1> shl si, 2 2159 000006EE 81C6[8A080000] <1> add esi, ncp2 - 4 2160 000006F4 A5 <1> movsd 2161 <1> ;movzx eax, word [day] 2162 000006F5 66A1[52080000] <1> mov ax, [day] 2163 <1> ;mov cx, 10 2164 000006FB B10A <1> mov cl, 10 2165 000006FD E831010000 <1> call numb 2166 00000702 B020 <1> mov al, 20h 2167 00000704 AA <1> stosb 2168 <1> ; 2169 00000705 66A1[56080000] <1> mov ax, [year] 2170 0000070B B564 <1> mov ch, 100 2171 0000070D F6F5 <1> div ch 2172 0000070F 6650 <1> push ax ; 2173 00000711 6698 <1> cbw ; century (19, 20) 2174 00000713 E81B010000 <1> call numb 2175 00000718 6658 <1> pop ax 2176 0000071A 88E0 <1> mov al, ah 2177 0000071C 6698 <1> cbw ; year (0 to 99) 2178 0000071E E810010000 <1> call numb 2179 00000723 B020 <1> mov al, 20h 2180 00000725 AA <1> stosb 2181 <1> ; 2182 00000726 0FB735[58080000] <1> movzx esi, word [wday] 2183 0000072D 66C1E602 <1> shl si, 2 2184 00000731 81C6[72080000] <1> add esi, ncp1 2185 00000737 A5 <1> movsd 2186 <1> ; 2187 00000738 66A1[50080000] <1> mov ax, [hour] 2188 0000073E E8F0000000 <1> call numb 2189 00000743 B03A <1> mov al, ':' 2190 00000745 AA <1> stosb 2191 00000746 66A1[4E080000] <1> mov ax, [minute] 2192 0000074C E8E2000000 <1> call numb 2193 00000751 B03A <1> mov al, ':' 2194 00000753 AA <1> stosb 2195 00000754 66A1[4C080000] <1> mov ax, [second] 2196 0000075A E8D4000000 <1> call numb 2197 0000075F B020 <1> mov al, 20h 2198 00000761 AA <1> stosb 2199 <1> ;mov ax, [year] 2200 <1> ;mov ch, 100 2201 <1> ;div ch 2202 <1> ;push ax ; 2203 <1> ;cbw ; century (19, 20) 2204 <1> ;call numb 2205 <1> ;pop ax 2206 <1> ;mov al, ah 2207 <1> ;cbw ; year (0 to 99) 2208 <1> ;call numb 2209 <1> ;mov al, 20h 2210 <1> ;stosb 2211 <1> ;xor al, al 2212 <1> ;stosb 2213 <1> 2214 00000762 C3 <1> retn 2215 <1> 2216 <1> gmtime: 2217 <1> ; 24/11/2013 (yday, wday) 2218 <1> ; Retro UNIX 8086 v1 - UNIX.ASM (20/06/2013) 2219 <1> ; Retro UNIX 8086 v1 feature/procedure only! 2220 <1> ; 'convert_from_epoch' procedure prototype: 2221 <1> ; UNIXCOPY.ASM, 10/03/2013 2222 <1> ; 30/11/2012 2223 <1> ; Derived from DALLAS Semiconductor 2224 <1> ; Application Note 31 (DS1602/DS1603) 2225 <1> ; 6 May 1998 2226 <1> ; 2227 <1> ; INPUT: 2228 <1> ; DX:AX = Unix (Epoch) Time 2229 <1> ; 2230 <1> ; ((Modified registers: AX, DX, CX, BX)) 2231 <1> ; 2232 00000763 31D2 <1> xor edx, edx 2233 00000765 B93C000000 <1> mov ecx, 60 2234 0000076A F7F1 <1> div ecx 2235 <1> ;mov [imin], eax ; whole minutes 2236 <1> ; since 1/1/1970 2237 0000076C 668915[4C080000] <1> mov [second], dx ; leftover seconds 2238 <1> ; mov ecx, 60 2239 00000773 29D2 <1> sub edx, edx 2240 00000775 F7F1 <1> div ecx 2241 <1> ;mov [ihrs], eax ; whole hours 2242 <1> ; since 1/1/1970 2243 00000777 668915[4E080000] <1> mov [minute], dx ; leftover minutes 2244 <1> ;mov ecx, 24 2245 0000077E 31D2 <1> xor edx, edx 2246 00000780 B118 <1> mov cl, 24 2247 00000782 F7F1 <1> div ecx 2248 <1> ;mov [iday], ax ; whole days 2249 <1> ; since 1/1/1970 2250 00000784 66A3[58080000] <1> mov [wday], ax ; 24/11/2013 2251 0000078A 668915[50080000] <1> mov [hour], dx ; leftover hours 2252 00000791 05DB020000 <1> add eax, 365+366 ; whole day since 2253 <1> ; 1/1/1968 2254 <1> ;mov [iday], ax 2255 00000796 50 <1> push eax 2256 00000797 66B9B505 <1> mov cx, (4*365)+1 ; 4 years = 1461 days 2257 0000079B 29D2 <1> sub edx, edx 2258 0000079D F7F1 <1> div ecx 2259 0000079F 59 <1> pop ecx 2260 <1> ;mov [lday], ax ; count of quadyrs (4 years) 2261 000007A0 52 <1> push edx 2262 <1> ;mov [qday], dx ; days since quadyr began 2263 000007A1 6683FA3C <1> cmp dx, 31 + 29 ; if past feb 29 then 2264 000007A5 F5 <1> cmc ; add this quadyr's leap day 2265 000007A6 83D000 <1> adc eax, 0 ; to # of qadyrs (leap days) 2266 <1> ;mov [lday], ax ; since 1968 2267 <1> ;mov cx, [iday] 2268 000007A9 91 <1> xchg ecx, eax ; CX = lday, AX = iday 2269 000007AA 29C8 <1> sub eax, ecx ; iday - lday 2270 <1> ;mov ecx, 365 2271 000007AC 66B96D01 <1> mov cx, 365 2272 000007B0 31D2 <1> xor edx, edx ; DX = 0 2273 <1> ; EAX = iday-lday 2274 000007B2 F7F1 <1> div ecx 2275 <1> ;mov [iyrs], ax ; whole years since 1968 2276 <1> ; jday = iday - (iyrs*365) - lday 2277 <1> ;mov [jday], dx ; days since 1/1 of current year 2278 <1> ;add eax, 1968 ; compute year 2279 000007B4 05B0070000 <1> add eax, 1968 2280 000007B9 66A3[56080000] <1> mov [year], ax 2281 000007BF 89C3 <1> mov ebx, eax 2282 <1> ;mov ax, [qday] 2283 000007C1 58 <1> pop eax 2284 000007C2 663D6D01 <1> cmp ax, 365 ; if qday <= 365 and qday >= 60 2285 000007C6 7709 <1> ja short L1 ; jday = jday +1 2286 000007C8 6683F83C <1> cmp ax, 60 ; if past 2/29 and leap year then 2287 000007CC F5 <1> cmc ; add a leap day to the # of whole 2288 000007CD 6683D200 <1> adc dx, 0 ; days since 1/1 of current year 2289 <1> L1: 2290 <1> ;mov [jday], dx 2291 <1> ;mov [yday], dx ; 24/11/2013 2292 000007D1 66B90C00 <1> mov cx, 12 ; estimate month 2293 000007D5 6687CA <1> xchg cx, dx ; CX = jday, DX = month 2294 000007D8 66B86E01 <1> mov ax, 366 ; mday, max. days since 1/1 is 365 2295 000007DC 6683E303 <1> and bx, 11b ; year mod 4 (and bx, 3) 2296 <1> L2: ; Month calculation ; 0 to 11 (11 to 0) 2297 000007E0 6639C1 <1> cmp cx, ax ; mday = # of days passed from 1/1 2298 000007E3 731D <1> jnb short L3 2299 000007E5 664A <1> dec dx ; month = month - 1 2300 000007E7 66D1E2 <1> shl dx, 1 2301 000007EA 668B82[5A080000] <1> mov ax, [edx+DMonth] ; # elapsed days at 1st of month 2302 000007F1 66D1EA <1> shr dx, 1 ; dx = month - 1 (0 to 11) 2303 000007F4 6683FA01 <1> cmp dx, 1 ; if month > 2 and year mod 4 = 0 2304 000007F8 76E6 <1> jna short L2 ; then mday = mday + 1 2305 000007FA 08DB <1> or bl, bl ; if past 2/29 and leap year then 2306 000007FC 75E2 <1> jnz short L2 ; add leap day (to mday) 2307 000007FE 6640 <1> inc ax ; mday = mday + 1 2308 00000800 EBDE <1> jmp short L2 2309 <1> L3: 2310 00000802 6642 <1> inc dx ; -> dx = month, 1 to 12 2311 00000804 668915[54080000] <1> mov [month], dx 2312 0000080B 6629C1 <1> sub cx, ax ; day = jday - mday + 1 2313 0000080E 6641 <1> inc cx 2314 00000810 66890D[52080000] <1> mov [day], cx 2315 <1> 2316 <1> ; eax, ebx, ecx, edx are changed at return 2317 <1> ; output -> 2318 <1> ; [year], [month], [day], [hour], [minute], [second] 2319 <1> ; [yday] -> 24/11/2013 2320 <1> ; [wday] -> 24/11/2013 2321 <1> ; 2322 <1> ; 24/11/2013 2323 00000817 66A1[58080000] <1> mov ax, [wday] ; [iday] 2324 0000081D 6631D2 <1> xor dx, dx 2325 00000820 6683C004 <1> add ax, 4 2326 <1> ; NOTE: January 1, 1970 was THURSDAY 2327 <1> ; ch = 0 2328 00000824 B107 <1> mov cl, 7 2329 00000826 66F7F1 <1> div cx 2330 00000829 668915[58080000] <1> mov [wday], dx ; week of the day, 0 to 6 2331 <1> ; 0 = sunday ... 6 = saturday 2332 <1> ;mov word [isday], 0 2333 <1> 2334 00000830 C3 <1> retn 2335 <1> 2336 <1> 2337 <1> ;sunday: 2338 <1> ; sunday(at, ad) 2339 <1> ; int *at; 2340 <1> ; { 2341 <1> ; register int *t, d; 2342 <1> ; t = at; 2343 <1> ; d = ad; 2344 <1> ; d = ad + dysize(t[YEAR]) - 365; 2345 <1> ; return(d - (d - t[YDAY] + t[WDAY] + 700) % 7); 2346 <1> ; } 2347 <1> 2348 <1> ;mov dx, [year] 2349 <1> ;call dysize 2350 <1> ;sub ax, 365 2351 <1> ; add cx, ax 2352 <1> ; test word [year], 11b 2353 <1> ; jnz short sunday1 2354 <1> ; CX = 119 (77h) or CX = 303 (12Fh) 2355 <1> ;inc cx 2356 <1> ; inc cl 2357 <1> ;sunday1: 2358 <1> ; mov ax, cx 2359 <1> ; add ax, [wday] 2360 <1> ;adc ax, 700 2361 <1> ; add ax, 700 2362 <1> ; sub ax, [yday] 2363 <1> ;xor dx, dx 2364 <1> ; mov bx, 7 2365 <1> ;div bx 2366 <1> ; div bl 2367 <1> ; sub cx, bx 2368 <1> ; retn 2369 <1> 2370 <1> ;dysize: 2371 <1> ; dysize(y) 2372 <1> ; { 2373 <1> ; if((y%4) == 0) 2374 <1> ; return(366); 2375 <1> ; return(365); 2376 <1> ; } 2377 <1> 2378 <1> ; mov ax, 365 2379 <1> ; test dx, 11b 2380 <1> ; jnz short dysize1 2381 <1> ; ;inc ax 2382 00000831 FEC0 <1> inc al 2383 <1> ;dysize1: 2384 <1> ; retn 2385 <1> 2386 <1> 2387 <1> numb: ; AX = 0 to 99 2388 <1> ; 2389 <1> ; numb(acp, n) 2390 <1> ; { 2391 <1> ; register char *cp; 2392 <1> ; 2393 <1> ; cp = acp; 2394 <1> ; cp++; 2395 <1> ; if (n>=10) 2396 <1> ; *cp++ = (n/10)%10 + '0'; 2397 <1> ; else 2398 <1> ; *cp++ = ' '; 2399 <1> ; *cp++ = n%10 + '0'; 2400 <1> ; return(cp); 2401 <1> ; } 2402 <1> ; 2403 <1> ;mov cl, 10 2404 00000833 6683F80A <1> cmp ax, 10 2405 00000837 7306 <1> jnb short nb1 2406 00000839 88C4 <1> mov ah, al 2407 0000083B 30C0 <1> xor al, al ; 0 2408 0000083D EB04 <1> jmp short nb2 2409 <1> nb1: 2410 0000083F F6F1 <1> div cl 2411 00000841 88E2 <1> mov dl, ah 2412 <1> 2413 <1> nb2: 2414 00000843 0430 <1> add al, '0' 2415 00000845 AA <1> stosb ; digit 1 2416 00000846 88E0 <1> mov al, ah 2417 00000848 0430 <1> add al, '0' 2418 0000084A AA <1> stosb ; digit 2 2419 0000084B C3 <1> retn 2420 <1> 2421 <1> 2422 <1> ;;; DATA 2423 <1> 2424 <1> ;daylight: db 1 ; int daylight 1; /* Allow daylight conversion */ 2425 <1> ;nixonflg: db 0 ; int nixonflg 0; /* Daylight time all year around */ 2426 <1> ;daylbegin: dw 0 2427 <1> ;daylend: dw 0 2428 <1> 2429 <1> 2430 <1> ct: 2431 <1> ; 24/11/2013 (re-order) 2432 <1> ; 2433 <1> ; Retro UNIX 8086 v1 - UNIX.ASM 2434 <1> ; 09/04/2013 epoch variables 2435 <1> ; Retro UNIX 8086 v1 Prototype: UNIXCOPY.ASM, 10/03/2013 2436 <1> ; 2437 <1> 2438 0000084C 0000 <1> second: dw 0 2439 0000084E 0000 <1> minute: dw 0 2440 00000850 0000 <1> hour: dw 0 2441 00000852 0100 <1> day: dw 1 2442 00000854 0100 <1> month: dw 1 2443 00000856 B207 <1> year: dw 1970 2444 00000858 0000 <1> wday: dw 0 ; 24/11/2013 2445 <1> ;yday: dw 0 ; 24/11/2013 2446 <1> ;isday: dw 0 ; 24/11/2013 2447 <1> 2448 <1> DMonth: 2449 0000085A 0000 <1> dw 0 2450 0000085C 1F00 <1> dw 31 2451 0000085E 3B00 <1> dw 59 2452 00000860 5A00 <1> dw 90 2453 00000862 7800 <1> dw 120 2454 00000864 9700 <1> dw 151 2455 00000866 B500 <1> dw 181 2456 00000868 D400 <1> dw 212 2457 0000086A F300 <1> dw 243 2458 0000086C 1101 <1> dw 273 2459 0000086E 3001 <1> dw 304 2460 00000870 4E01 <1> dw 334 2461 <1> 2462 <1> ;ncp0: db "Day Mon 00 00:00:00 1970", 0, 0 2463 00000872 53756E204D6F6E2054- <1> ncp1: db "Sun Mon Tue Wed Thu Fri Sat " 2463 0000087B 756520576564205468- <1> 2463 00000884 752046726920536174- <1> 2463 0000088D 20 <1> 2464 0000088E 4A616E20466562204D- <1> ncp2: db "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec " 2464 00000897 617220417072204D61- <1> 2464 000008A0 79204A756E204A756C- <1> 2464 000008A9 204175672053657020- <1> 2464 000008B2 4F6374204E6F762044- <1> 2464 000008BB 656320 <1> 2465 <1> 2466 <1> cbuf: ; char cbuf[26] 2467 000008BE 00 <1> times 26 db 0 2468 <1> 2469 <1> 2470 <1> ;; ctime.c (Unix v5) 2471 <1> ; 2472 <1> ;# 2473 <1> ;/* 2474 <1> ; * This routine converts time as follows. 2475 <1> ; * The epoch is 0000 Jan 1 1970 GMT. 2476 <1> ; * The argument time is in seconds since then. 2477 <1> ; * The localtime(t) entry returns a pointer to an array 2478 <1> ; * containing 2479 <1> ; * seconds (0-59) 2480 <1> ; * minutes (0-59) 2481 <1> ; * hours (0-23) 2482 <1> ; * day of month (1-31) 2483 <1> ; * month (0-11) 2484 <1> ; * year-1970 2485 <1> ; * weekday (0-6, Sun is 0) 2486 <1> ; * day of the year 2487 <1> ; * daylight savings flag 2488 <1> ; * 2489 <1> ; * The routine corrects for daylight saving 2490 <1> ; * time and will work in any time zone provided 2491 <1> ; * "timezone" is adjusted to the difference between 2492 <1> ; * Greenwich and local standard time (measured in seconds). 2493 <1> ; * In places like Michigan "daylight" must 2494 <1> ; * be initialized to 0 to prevent the conversion 2495 <1> ; * to daylight time. 2496 <1> ; * 2497 <1> ; * "nixonflg,", if set to 1, will 2498 <1> ; * cause daylight savings time all year around 2499 <1> ; * independently of "daylight". 2500 <1> ; * 2501 <1> ; * The routine does not work 2502 <1> ; * in Saudi Arabia which runs on Solar time. 2503 <1> ; * 2504 <1> ; * asctime(tvec)) 2505 <1> ; * where tvec is produced by localtime 2506 <1> ; * returns a ptr to a character string 2507 <1> ; * that has the ascii time in the form 2508 <1> ; * Thu Jan 01 00:00:00 1970n0\; * 01234567890123456789012345 2510 <1> ; * 0 1 2 2511 <1> ; * 2512 <1> ; * ctime(t) just calls localtime, then asctime. 2513 <1> ; */ 2514 <1> ;char cbuf[26]; 2515 <1> ;int dmsize[12] 2516 <1> ;{ 2517 <1> ; 31, 2518 <1> ; 28, 2519 <1> ; 31, 2520 <1> ; 30, 2521 <1> ; 31, 2522 <1> ; 30, 2523 <1> ; 31, 2524 <1> ; 31, 2525 <1> ; 30, 2526 <1> ; 31, 2527 <1> ; 30, 2528 <1> ; 31 2529 <1> ;}; 2530 <1> ; 2531 <1> ;int timezone 5*60*60; 2532 <1> ;int tzname[] 2533 <1> ;{ 2534 <1> ; "EST", 2535 <1> ; "EDT", 2536 <1> ;}; 2537 <1> ;int daylight 1; /* Allow daylight conversion */ 2538 <1> ;int nixonflg 0; /* Daylight time all year around */ 2539 <1> ; 2540 <1> ;#define SEC 0 2541 <1> ;#define MIN 1 2542 <1> ;#define HOUR 2 2543 <1> ;#define MDAY 3 2544 <1> ;#define MON 4 2545 <1> ;#define YEAR 5 2546 <1> ;#define WDAY 6 2547 <1> ;#define YDAY 7 2548 <1> ;#define ISDAY 8 2549 <1> ; 2550 <1> ;ctime(at) 2551 <1> ;int *at; 2552 <1> ;{ 2553 <1> ; return(asctime(localtime(at))); 2554 <1> ;} 2555 <1> ; 2556 <1> ;localtime(tim) 2557 <1> ;int tim[]; 2558 <1> ;{ 2559 <1> ; register int *t, *ct, dayno; 2560 <1> ; int daylbegin, daylend; 2561 <1> ; int copyt[2]; 2562 <1> ; 2563 <1> ; t = copyt; 2564 <1> ; t[0] = tim[0]; 2565 <1> ; t[1] = tim[1]; 2566 <1> ; dpadd(t, -timezone); 2567 <1> ; ct = gmtime(t); 2568 <1> ; dayno = ct[YDAY]; 2569 <1> ; if (nixonflg && (ct[YEAR]>74 || ct[YEAR]==74 && (dayno > 5 || 2570 <1> ; dayno==5 && ct[HOUR]>=2))) { 2571 <1> ; daylight =| 1; 2572 <1> ; daylbegin = -1; 2573 <1> ; daylend = 367; 2574 <1> ; } else { 2575 <1> ; daylbegin = sunday(ct, 119); /* last Sun in Apr */ 2576 <1> ; daylend = sunday(ct, 303); /* last Sun in Oct */ 2577 <1> ; } 2578 <1> ; if (daylight && 2579 <1> ; (dayno>daylbegin || (dayno==daylbegin && ct[HOUR]>=2)) && 2580 <1> ; (dayno ; dpadd(t, 1*60*60); 2582 <1> ; ct = gmtime(t); 2583 <1> ; ct[ISDAY]++; 2584 <1> ; } 2585 <1> ; return(ct); 2586 <1> ;} 2587 <1> ; 2588 <1> ;sunday(at, ad) 2589 <1> ;int *at; 2590 <1> ;{ 2591 <1> ; register int *t, d; 2592 <1> ; 2593 <1> ; t = at; 2594 <1> ; d = ad; 2595 <1> ; d = ad + dysize(t[YEAR]) - 365; 2596 <1> ; return(d - (d - t[YDAY] + t[WDAY] + 700) % 7); 2597 <1> ;} 2598 <1> ; 2599 <1> ;gmtime(tim) 2600 <1> ;int tim[]; 2601 <1> ;{ 2602 <1> ; register int d0, d1; 2603 <1> ; register *tp; 2604 <1> ; static xtime[9]; 2605 <1> ; extern int ldivr; 2606 <1> ; 2607 <1> ; /* 2608 <1> ; * break initial number into 2609 <1> ; * multiples of 8 hours. 2610 <1> ; * (28800 = 60*60*8) 2611 <1> ; */ 2612 <1> ; 2613 <1> ; d0 = ldiv(tim[0], tim[1], 28800); 2614 <1> ; d1 = ldivr; 2615 <1> ; tp = &xtime[0]; 2616 <1> ; 2617 <1> ; /* 2618 <1> ; * generate hours:minutes:seconds 2619 <1> ; */ 2620 <1> ; 2621 <1> ; *tp++ = d1%60; 2622 <1> ; d1 =/ 60; 2623 <1> ; *tp++ = d1%60; 2624 <1> ; d1 =/ 60; 2625 <1> ; d1 =+ (d0%3)*8; 2626 <1> ; d0 =/ 3; 2627 <1> ; *tp++ = d1; 2628 <1> ; 2629 <1> ; /* 2630 <1> ; * d0 is the day number. 2631 <1> ; * generate day of the week. 2632 <1> ; */ 2633 <1> ; 2634 <1> ; xtime[WDAY] = (d0+4)%7; 2635 <1> ; 2636 <1> ; /* 2637 <1> ; * year number 2638 <1> ; */ 2639 <1> ; for(d1=70; d0 >= dysize(d1); d1++) 2640 <1> ; d0 =- dysize(d1); 2641 <1> ; xtime[YEAR] = d1; 2642 <1> ; xtime[YDAY] = d0; 2643 <1> ; 2644 <1> ; /* 2645 <1> ; * generate month 2646 <1> ; */ 2647 <1> ; 2648 <1> ; if (dysize(d1)==366) 2649 <1> ; dmsize[1] = 29; 2650 <1> ; for(d1=0; d0 >= dmsize[d1]; d1++) 2651 <1> ; d0 =- dmsize[d1]; 2652 <1> ; dmsize[1] = 28; 2653 <1> ; *tp++ = d0+1; 2654 <1> ; *tp++ = d1; 2655 <1> ; xtime[ISDAY] = 0; 2656 <1> ; return(xtime); 2657 <1> ;} 2658 <1> ; 2659 <1> ;asctime(t) 2660 <1> ;int *t; 2661 <1> ;{ 2662 <1> ; register char *cp, *ncp; 2663 <1> ; register int *tp; 2664 <1> ; 2665 <1> ; cp = cbuf; 2666 <1> ; for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;); 2667 <1> ; ncp = &"SunMonTueWedThuFriSat"[3*t[6]]; 2668 <1> ; cp = cbuf; 2669 <1> ; *cp++ = *ncp++; 2670 <1> ; *cp++ = *ncp++; 2671 <1> ; *cp++ = *ncp++; 2672 <1> ; cp++; 2673 <1> ; tp = &t[4]; 2674 <1> ; ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3]; 2675 <1> ; *cp++ = *ncp++; 2676 <1> ; *cp++ = *ncp++; 2677 <1> ; *cp++ = *ncp++; 2678 <1> ; cp = numb(cp, *--tp); 2679 <1> ; cp = numb(cp, *--tp+100); 2680 <1> ; cp = numb(cp, *--tp+100); 2681 <1> ; cp = numb(cp, *--tp+100); 2682 <1> ; cp =+ 2; 2683 <1> ; cp = numb(cp, t[YEAR]); 2684 <1> ; return(cbuf); 2685 <1> ;} 2686 <1> ; 2687 <1> ;dysize(y) 2688 <1> ;{ 2689 <1> ; if((y%4) == 0) 2690 <1> ; return(366); 2691 <1> ; return(365); 2692 <1> ;} 2693 <1> ; 2694 <1> ; 2695 <1> ;numb: 2696 <1> ; 2697 <1> ; 2698 <1> ;numb(acp, n) 2699 <1> ;{ 2700 <1> ; register char *cp; 2701 <1> ; cp = acp; 2702 <1> ; cp++; 2703 <1> ; if (n>=10) 2704 <1> ; *cp++ = (n/10)%10 + '0'; 2705 <1> ; else 2706 <1> ; *cp++ = ' '; 2707 <1> ; *cp++ = n%10 + '0'; 2708 <1> ; return(cp); 2709 <1> ;} 2710 <1> ; 1981 1982 000008D8 [C8150000] brk: dd _end + 512 ; (gstat:) 1983 1984 ; directory name pointer 1985 000008DC 00000000 dnp: dd 0 ; (do:) 1986 1987 000008E0 [E8080000] dotp: dd dot 1988 ;dotp: dot 1989 000008E4 [BE0D0000] euids: dd uidbuf 1990 ; euids: uidbuf 1991 000008E8 2E00 dot: db '.', 0 1992 ;dot: <.\0> 1993 000008EA 0D0A00 nl: db 0Dh, 0Ah, 0 1994 ; nl: <\n\0> 1995 000008ED 746F74616C2000 totmes: db 'total ', 0 1996 ; totmes: 1997 000008F4 202020 space3: db 20h, 20h, 20h 1998 ; space3: < > 1999 000008F7 2000 space: db 20h, 0 2000 ; space: < \0> 2001 000008F9 2F6574632F70617373- passwd: db '/etc/passwd', 0 2001 00000902 776400 2002 ; passwd: 2003 00000905 3A0D0A00 colon: db ':', 0Dh, 0Ah, 0 2004 ; colon: <:\n\0> 2005 2006 00000909 00000000 eol: dd 0 ; (pass3:) 2007 2008 ; 22/01/2022 2009 0000090D 16 db 22 2010 0000090E 01 db 1 2011 0000090F E607 dw 2022 2012 00000911 0000 dw 0 2013 00000913 A101 dw 417 2014 2015 00000915 90 align 4 2016 2017 bss_start: 2018 2019 ABSOLUTE bss_start 2020 ;EVEN 2021 ;bss: 2022 ;count: resw 1 2023 ;ocount: resw 1 2024 ; 12/01/2022 2025 00000918 ?? count: resb 1 2026 00000919 ?? ocount: resb 1 2027 ; 2028 0000091A ???? longf: resw 1 2029 ;allflg: resw 1 2030 ;dirflg: resw 1 2031 ;isadir: resw 1 2032 ; 12/01/2022 2033 0000091C ?? allflg: resb 1 2034 0000091D ?? dirflg: resb 1 2035 0000091E ?? isadir: resb 1 2036 0000091F ?? flgsh: resb 1 ; high byte of flags 2037 ; 2038 00000920 ???????? tblocks: resd 1 2039 00000924 ???????? sortoff: resd 1 2040 ;filnam: resb 32 2041 ; 12/01/2022 2042 00000928 filnam: resb 60 ; (enough or more than reguired ?) ; 12/01/2022 2043 ;statb: resb 34 2044 ; 12/01/2022 - Retro UNIX v2 file system inode 2045 00000964 ???? resb 2 ; dword alignment (not necessary) 2046 00000966 statb: resb 66 ; 2 bytes inode number + 64 bytes inode's itself 2047 ; 2048 000009A8 dbuf: resb 520 2049 ; 2 byte file descriptor, 2 byte buffer data size, 2050 ; 4 byte buffer offset, 512 byte buffer data 2051 00000BB0 obuf: resb 520 2052 00000DB8 ???????????? numbuf: resb 6 2053 00000DBE uidbuf: resb 1024 2054 euidbuf: 2055 000011BE iobuf: resb 520 2056 2057 000013C6 ???? alignb 4 2058 _end: 2059 2060 ; .even 2061 2062 ;.bss 2063 2064 ;count: .=.+2 2065 ;ocount: .=.+2 2066 ;longf: .=.+2 2067 ;sortoff: .=.+2 2068 ;allflg: .=.+2 2069 ;dirflg: .=.+2 2070 ;isadir: .=.+2 2071 ;filnam: .=.+32. 2072 ;statb: .=.+34. 2073 ;dbuf: .=.+518. 2074 ;obuf: .=.+518. 2075 ;numbuf: .=.+6 2076 ;tblocks: .=.+2 2077 ;uidbuf: .=.+1024. 2078 ;euidbuf: 2079 ;iobuf: .=.+518.