# HG changeset patch # User Pascal Bellard # Date 1610136935 0 # Node ID a946c16510822b8f2119eab032d1d2a8b4c171d0 # Parent 9c5316bc7e8ec43affa6743e0dae405004f99c06 linld: add iso support diff -r 9c5316bc7e8e -r a946c1651082 linld/receipt --- a/linld/receipt Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/receipt Fri Jan 08 20:15:35 2021 +0000 @@ -33,9 +33,6 @@ d: cd linld$SUFFIX $(cat LINLD$SUFFIX/!COMPILE.BAT) -cd .. -cd tazboot -$(cat TAZBOOT/!COMPILEX.BAT) EOT SDL_VIDEODRIVER=dummy dosbox MAKE.BAT -exit -c "mount D $src" \ 2>&1 | grep -v 'ALSA lib' @@ -46,19 +43,8 @@ grep '^Warning[ :]' */LNK.LOG */CPP.LOG grep '*Warning*' */*.LST cp LINLD$SUFFIX/LINLD.COM linld.com - cp LINLD$SUFFIX/HEADER.COM header.com - cp TAZBOOT/TAZBOOT.COM tazboot.com - dd count=$((0x$(sed '/ FOLD/!d;s|.*:||;s| .*||;q' LINLD$SUFFIX/ISOBOOT.MAP) - 0x100)) \ - if=LINLD$SUFFIX/ISOBOOT.COM bs=1 > isoboot.com - dd skip=$((0x$(sed '/ UNFOLD/!d;s|.*:||;s| .*||;q' LINLD$SUFFIX/ISOBOOT.MAP) - 0x100)) \ - if=LINLD$SUFFIX/ISOBOOT.COM bs=1 >> isoboot.com objdump -D -b binary -mi386 -Maddr16,data16 --adjust-vma=0x100 \ linld.com > linld.lst - linld=linld.com - [ $(stat -c %s $linld) -le 4096 ] && ls -l $linld && linld= - for f in $linld tazboot.com ; do - upx -qq --ultra-brute --8086 $f - done cc -o tobzimage.o -Wa,-algms=tobzimage.lst -c $stuff/tobzimage.S objcopy -O binary tobzimage.o tobzimage.bin cp $stuff/tobzimage . diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/!COMPILE.BAT --- a/linld/stuff/src/!COMPILE.BAT Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/!COMPILE.BAT Fri Jan 08 20:15:35 2021 +0000 @@ -12,7 +12,5 @@ mawk -f pipehole.awk LOAD.ASO > LOAD.ASM mawk -f pipehole.awk HIMEM.ASO > HIMEM.ASM mawk -f pipehole.awk ISO9660.ASO > ISO9660.ASM -tasm /la /m /dISOHOOK /dMOVE_SETUP /dUSE_ARGSTR /dNO386 /dLARGE_IMAGES /dLONG_FILENAME *.asm > asm.log +tasm /la /m /dISOHOOK /dBIG_CMDLINE /dMOVE_SETUP /dUSE_ARGSTR /dNO386 /dLARGE_IMAGES /dLONG_FILENAME *.asm > asm.log tlink /m /s /t @link.cmd > lnk.log -tlink /m /s /t @link2.cmd > lnk2.log -tlink /m /s /t @header.cmd > header.log diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/!COMPILEX.BAT --- a/linld/stuff/src/!COMPILEX.BAT Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -path ..\BC31;..;%PATH% -call !clean.bat -bcc @bccopt.opt -S -mt -DEXTRA -DMOVE_SETUP -DLARGE_IMAGES *.cpp > cpp.log -ren TAZBOOT.ASM TAZBOOT.ASO -ren LOAD.ASM LOAD.ASO -ren HIMEM.ASM HIMEM.ASO -ren ISO9660.ASM ISO9660.ASO -mawk -f pipehole.awk TAZBOOT.ASO > TAZBOOT.ASM -mawk -f pipehole.awk LOAD.ASO > LOAD.ASM -mawk -f pipehole.awk HIMEM.ASO > HIMEM.ASM -mawk -f pipehole.awk ISO9660.ASO > ISO9660.ASM -tasm /la /m /dMOVE_SETUP /dEXTRA /dNO386 /dLARGE_IMAGES /dLONG_FILENAME *.asm > asm.log -tlink /m /s /t @linkx.cmd > lnk.log diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/A20.ASM --- a/linld/stuff/src/A20.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/A20.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -16,11 +16,13 @@ global die:near enable_a20_methods: dw _enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die -msg_a20 db "Can't use A20",0 +msg_a20 db "A20 broken",0 extrn overflow:byte ifdef NO386 -bzimage86 db "8086 & bzImage",0 +bzimage86 db "8086 " endif + global _bzimagestr:byte +_bzimagestr db "bzImage",0 global sssp:dword global _initrd_desc:dword _initrd_desc dd 90000218h @@ -109,7 +111,7 @@ mov cl,4 shr ax,cl mov dx,cs - add dx,ax + add dx,ax ; last used segment mov cx,0fffh extrn _pm_low:byte test [_pm_low],cl @@ -124,7 +126,7 @@ xchg ax,dx cmp ax,cx jae @sys@ok - xchg ax,cx + xchg ax,cx ; segment min 1000h @sys@ok: inc ax extrn N_LXLSH@4:near @@ -142,13 +144,13 @@ sbb dx,cx endif mov cl,12 - shl dx,cl - jc @jbe_overflow + shl dx,cl ; last segment + jc @jbe_overflow ; >= 1Mb ? @bzimage: extrn _topseg:near call near _topseg mov [word sssp+2],ax - and ch,0 + and ch,0 ; vcpi flag org $-1 global _vcpi:byte _vcpi db ? @@ -157,14 +159,14 @@ movzx eax,[word _heap_top] shr ax,4 mov dx,cs - add ax,dx + add ax,dx ; last used segment mov cx,0fffh extrn _pm_low:byte test [_pm_low],cl je @bzimage cmp ax,cx jae @sys@ok - xchg ax,cx + xchg ax,cx ; segment min 1000h @sys@ok: inc ax shl eax,4 @@ -186,7 +188,7 @@ extrn _vcpi:byte and ch,[_vcpi] endif - add dh,ch ; room for malloc_bufv_or_die + add dh,ch ; 60k room for malloc_bufv_or_die cmp ax,dx les cx,[bx] ; rm_size mov si,es ; rm_buf @@ -240,16 +242,17 @@ mov cx,0FFFFh mov es,cx a20lp: - cli - mov ax,0AA55h - xchg al,[bx] - xchg ah,[es:bx+10h] - xchg al,[bx] - xchg ah,[es:bx+10h] + cli ; A20 off A20 on + mov ax,0AA55h ; al ah [bx] al ah [bx] es:[bx+10h] + xchg al,[bx] ; ?? AA 55 ?1 AA 55 ?2 + xchg ah,[es:bx+10h] ; ?? 55 AA ?1 ?2 55 AA + xchg al,[bx] ; AA 55 ?? 55 ?2 ?1 AA cmp al,55h sti + loopne a20lp + jne a20ko + xchg ah,[es:bx+10h] ; AA ?? 55 55 AA ?1 ?2 a20ko: - loopne a20lp ;xchg ax,cx pop ds ;ret diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/COMMON.H --- a/linld/stuff/src/COMMON.H Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/COMMON.H Fri Jan 08 20:15:35 2021 +0000 @@ -44,9 +44,7 @@ u32 remaining; u32 buf; u32 *bufv; - const char *errmsg; u32 chunk_size; - void (*next_chunk)(struct image_himem *); u16 state; u16 fd2close; } imgs[2]; @@ -55,8 +53,19 @@ #define pm2initrd(p) (p+1) extern u8 pm_low; -extern u32 base_himem; + extern u32 far *initrd_desc; +#define cmdline (cmdstr[0]) +#define kernel_name (cmdstr[1]) +#define initrd_name (cmdstr[2]) +#define isofile (cmdstr[3]) +extern const char* cmdstr[4]; + +#define root_dev (cmdnum[0]) +#define vid_mode (cmdnum[1]) // -3 = ask, -2 = Extended VGA, -1 = Normal VGA, n = as "n" was pressed +#define topmem (cmdnum[2]) +#define base_himem (cmdnum[3]) +extern u32 cmdnum[4]; extern _fastcall void memcpy_image(struct image_himem *m); extern _fastcall void storepage(u32 *dst); @@ -73,17 +82,10 @@ #endif extern char vcpi; extern char version_string[]; -extern const char* kernel_name; -extern const char* initrd_name; -extern const char* cmdline; -extern u32 root_dev; -extern u32 vid_mode; // External asm helpers #ifdef WITH_XMM_ALLOC -extern u16 skip_alloc; extern _fastcall void xmm_alloc(struct image_himem *m); #endif -extern u32 topmem; extern "C" u32 memtop(); extern "C" void enable_a20_or_die(); extern "C" void vm2rm(); diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/CRTL.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -17,71 +17,44 @@ segment _DATA byte public use16 'DATA' +loaderr db "Load failure",0 msg_hang db "Himem broken",0 vcpi_alloc_err db "VCPI" global overflow:byte overflow db "/" -msg_malloc db "Out of memory",0 +msg_malloc db "Out of memory" +isorootofs dd 16*2048 ends _DATA segment _BSS byte public use16 'BSS' - ifdef EXTRA include "isostate.inc" public _isostate _isostate isostate org $-7 - endif _xfer_buf db 4096 dup (?) filecnt db ? ; in fact 0 minus file count... nextfilename dw ? - ifdef EXTRA -utoabuf db 6 dup (?) - endif ends _BSS segment _TEXT byte public use16 'CODE' ;*************************************************************** -;_fastcall void strcpy(bx:const char* a, ax:const char* b); -;_fastcall void strcat(bx:const char* a, ax:const char* b); ;_fastcall void strcatb(bx:const char* a, ax:const char* b); ;*************************************************************** - ifdef EXTRA - global @strcat$qpxzct1:near -@strcat$qpxzct1: - mov cx,1h - db 0bah ; mov dx,imm opcode - endif global @strcatb$qpxzct1:near proc @strcatb$qpxzct1 near - ifdef EXTRA - mov cl,7Fh - db 0bah ; mov dx,imm opcode - global @strcpy$qpxzct1:near -@strcpy$qpxzct1: - xor cx,cx - endif push si xchg ax,si ; b - ifdef EXTRA - jcxz @@nocat - endif dec bx @@catlp: inc bx cmp [byte bx],0 ; a=bx jne @@catlp - ifdef EXTRA - mov al,20h - loop @@cpyhead - else db 0b8h,20h ; mov ax,??20h - endif -@@nocat: @@cpylp: lodsb @@cpyhead: @@ -89,80 +62,51 @@ inc bx or al,al jne @@cpylp - ifdef EXTRA -strfound: - xchg ax,dx - endif strend: pop si - global @ret:near @ret: ret endp @strcatb$qpxzct1 - ifdef EXTRA p8086 -;*************************************************************** -;_fastcall int strstr(bx:const char* a, ax:const char* b); -;*************************************************************** - global @strstr$qpxzct1:near - proc @strstr$qpxzct1 near - xchg ax,cx ; b - mov dx,bx ; a - push si -@@loop: - xor ax,ax - mov si,dx - cmp [si],al ; *a - jz strend ; return ax = NULL - mov bx,cx -@@match: - or ah,[bx] ; *b - jz strfound - inc bx - lodsb - sub ah,al - jz @@match - inc dx - jmp @@loop - - endp @strstr$qpxzct1 - - -;*************************************************************** -;_fastcall int strcmp(bx:const char* a, ax:const char* b); -;*************************************************************** - global @strcmp$qpxzct1:near - proc @strcmp$qpxzct1 near - - ifdef USE_ARGSTR -@@loop: +opendos: + ifdef LONG_FILENAME + xchg ax,cx ; attributes + mov ax,716Ch + push bx si + mov si,bx + xor bx,bx ; R/O + cwd ; action = open + stc + int 21h + pop si dx + jnc openok + mov ax,3d00h ; read-only+compatibility + else + mov ah,3dh ; read-only+compatibility + mov dx,bx + endif + ;mov cl,0 ; attribute mask + call dos + jc openret +openok: xchg ax,bx - mov cl,[bx] ; cl = *b++ - inc bx + mov ax,4202h + cwd + xor cx,cx + int 21h + mov [word _isostate.filesize],ax + mov [(word _isostate.filesize)+2],dx xchg ax,bx - cmp cl,[bx] ; cl ?= *a++ - jnz fail ; return -1 - inc bx - or cl,cl ; clear C - jz failifc ; return 0 - jmp @@loop - - else - - call @strhead$qpxzct1 - jne closeret ; return -1 - cmp cl,[bx] - jmp failifc ; return 0 or -1 - - endif - - endp @strcmp$qpxzct1 - endif - + ;xor cx,cx + cwd + call seeksetpos0 ; filepos = 0 + xchg ax,bx ; fd +openret: + ret ;*************************************************************** ;_fastcall int open(bx:const char* name, int flags=O_RDONLY); @@ -175,34 +119,18 @@ inc bx global @open$qpxzc:near - proc @open$qpxzc near - -open: ; open(bx) - ifdef ISOHOOK - extrn iso_open_hack:word - jmp [iso_open_hack] - global __open:near -__open: - endif - ifdef LONG_FILENAME - mov ax,716Ch - push bx si - mov si,bx - xor bx,bx ; R/O - xor cx,cx ; attributes - cwd ; action = open - stc - int 21h - pop si dx - jnc doret - else - mov dx,bx - endif - mov ax,3d00h ; read-only+compatibility - ;mov cl,0 ; attribute mask - jmp dos - - endp @open$qpxzc +@open$qpxzc: + mov ax,[_isostate.fd] + or ax,ax + je opendos +openiso: + ifdef ISOHOOK + cmp [byte bx],'!' + je @readmenu$qv + endif + extrn @_isoopen$qv:near + mov [word _isostate.filename2open],bx + jmp @_isoopen$qv ; filepos = 0 ;*************************************************************** @@ -222,60 +150,53 @@ global close:near ; close(ax) close: mov bh,3Eh - ifdef ISOHOOK - extrn iso_close_hack:word - jmp [iso_close_hack] - endif - global dosbx:near -dosbx: - xchg ax,bx - or bx,bx - jnz dos -closeret: - ret + mov cx,[_isostate.fd] + jcxz dosbx + jmp fail endp @close$qi ;*************************************************************** -;_fastcall int readrm(di:struct himem *m, ax:int sz); -;_fastcall int read(ax:int fd, bx:void* data, dx:int sz); -;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz); +;_fastcall int readrm(si:struct himem *m, ax:int sz); ;*************************************************************** global @readrm$qp11image_himemi:near @readrm$qp11image_himemi: xchg ax,dx ; sz - mov ax,[di] ; fd - mov bx,[di-2] ; data - global @read$qipvi:near + mov ax,[si] ; fd + mov bx,[si-2] ; data proc @read$qipvi near - ifdef WRITE - stc - db 0B0h ; mov al,im - global @write$qipvi:near -@write$qipvi: - clc - endif @read$dxbxax: xchg ax,bx ; fd +@read$dxaxbx: xchg ax,dx ; data xchg ax,cx ; sz - ifdef WRITE - mov ah,40h - sbb ah,0 - else global @read$cxdxbx:near @read$cxdxbx: + push bx + mov bx,offset _isostate.filepos + push cx + mov cx,[bx-4] ; filesize + sub cx,[bx] ; filepos + mov ax,[bx-2] + sbb ax,[bx+2] + pop ax + ja @@axok + ;je @@rem + ;xor ax,ax +@@rem: + cmp cx,ax + jb @@cxok +@@axok: + xchg ax,cx +@@cxok: + add [bx],cx + adc [(word bx)+2],0 + pop bx +readfd: mov ah,3Fh - endif - jcxz fail - ifdef ISOHOOK -;_fastcall int read(bx:int fd, dx:void* data, cx:int sz, ah=3Fh); - extrn iso_read_hack:word - jmp [iso_read_hack] ; or ret - endif - global dos:near + ;jcxz fail dos: int 21h jnc doret @@ -283,13 +204,7 @@ stc failifc: sbb ax,ax ; ax=-1 CF - cwd doret: - ifndef NO386 - push dx ; see next_chunk:lseek - push ax - pop eax - endif ret endp @read$qipvi @@ -301,99 +216,120 @@ global @rewind$qi:near ; fd=ax proc @rewind$qi near - ifdef EXTRA ; catch ISO image case - stc - mov dx,-512 ; curpos = 512, see LOAD.CPP - mov bl,1 - jmp lseekword - endif -rewind: ; rewind(ax) - mov bl,0 -lseek0: ; lseek0(ax,bl=dir) - xor dx,dx ; clear C -lseekword: - sbb cx,cx -lseekset: - mov bh,42h ; bx=fd cx:dx=offset al=whence - ifdef ISOHOOK -;_fastcall long lseek(ax:int fd, cxdx:unsigned long offset, bl:whence, bh=42h); - extrn iso_lseek_hack:word - jmp [iso_lseek_hack] - else - jmp dosbx - endif +rewind: + mov bx,offset _isostate.fileofs + jmp lseek endp @rewind$qi - ifdef EXTRA + + ifdef ISOHOOK +;*************************************************************** +;_fastcall void readmenu(void); +;*************************************************************** + proc @readmenu$qv near + + mov dx,18 + xor cx,cx + call seeksetpos0 ; filepos = 0 + mov dx,offset _isostate.filemod + ; //magic = x->filemod; + mov cl,10 + call readfd ; // read x->filemod + x->fileofs & x->filesize + mov bx,offset _isostate.fileofs + ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF); + mov ax,7FF0h + cwd + mov [word bx+6],dx + sub ax,[bx+4] + mov [word bx+2],dx + mov [bx],ax + call isolseek ; filepos = 0 + xchg ax,bx ; fd + ret + + endp @readmenu$qv + endif + ;*************************************************************** ;_fastcall void isolseek(bx:const unsigned long *offset); -;_fastcall long lseekset2(ax:int fd, bx:unsigned long* offset); ;*************************************************************** global @isolseek$qpxul:near proc @isolseek$qpxul near isolseek: mov ax,[_isostate.fd] - global @lseekset2$qipul:near -@lseekset2$qipul: +lseek: les dx,[dword bx] mov cx,es - mov bl,0 - jmp lseekset +seeksetpos0: + xor bx,bx + mov [word _isostate.filepos],bx + mov [(word _isostate.filepos)+2],bx + mov bh,42h ; bx=fd cx:dx=offset al=whence +dosbx: + xchg ax,bx + jmp dos endp @isolseek$qpxul ;*************************************************************** ;_fastcall int isoreadsector(bx:const unsigned long *offset); +;_fastcall int isoreadrootsector(void); ;*************************************************************** + global @isoreadrootsector$qv:near +@isoreadrootsector$qv: + mov bx,offset isorootofs global @isoreadsector$qpxul:near proc @isoreadsector$qpxul near - call isolseek + call isolseek ; filepos = 0 jc fail - mov dx,2560 - mov bx,offset _isostate.buffer - mov ax,[_isostate.fd] - jmp @read$dxbxax ; read(fd,buffer,2560) + mov dh,10 + mov ax,offset _isostate.buffer + jmp @read$dxaxbx ; read(fd,buffer,2560+) endp @isoreadsector$qpxul ;*************************************************************** -;_fastcall int isoreset(bx:const char *name); +;_fastcall int strhead(bx:const char* a, ax:const char* b); ;*************************************************************** - global @isoreset$qpzc:near - proc @isoreset$qpzc near + global @strhead$qpxzct1:near + proc @strhead$qpxzct1 near - or bx,bx - jz fail - call near ptr @open$qpxzc - mov [_isostate.fd],ax - extrn @isoroot$qv:near - jmp @isoroot$qv +@@loop: + xchg ax,bx + mov dl,[bx] ; dl = *b++ + inc bx + xchg ax,bx + or dl,dl ; clear C + jz failifc ; return 0 + xor dl,[bx] ; dl -= *a++ + jne fail ; return -1 + inc bx + jmp @@loop - endp @isoreset$qpzc + endp @strhead$qpxzct1 ;*************************************************************** -;_fastcall int isoopen(bx:const char *name); +;_fastcall int strcmp(bx:const char* a, ax:const char* b); ;*************************************************************** - global @isoopen$qpxzc:near - proc @isoopen$qpxzc near + global @strcmp$qpxzct1:near + proc @strcmp$qpxzct1 near - extrn @_isoopen$qv:near - mov [_isostate.filename2open],bx - jmp @_isoopen$qv + call @strhead$qpxzct1 + jne fail ; return -1 + xor dl,[bx] ; clear C + jne fail ; return -1 + jmp failifc ; return 0 - endp @isoopen$qpxzc + endp @strcmp$qpxzct1 - endif - - ifdef USE_ARGSTR ;*************************************************************** -;_fastcall const char ** argstr(bx:const char *s, ax:const char keywords[], dx:const char **var); +;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var); ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var); ;*************************************************************** global @argstr$qpxzcxt1ppxzc:near @@ -428,13 +364,6 @@ cmp [byte bx],'-' je @@match @@notopt: - ifdef EXTRA - cmp [byte bx],'/' - jne @@notalt - or al,al ; 1st loop ? - js @@testalt -@@notalt: - endif cmp [byte bx],'|' je @@test cmp [byte bx],dh @@ -451,13 +380,12 @@ cmp al,'=' ;je @@found ;cmp al,0 ; eos, si=next argv - mov ax,-1 + xchg ax,cx ; return s if failure jne @@nokeyword @@found: dec dx dec dx je @@done - ;mov bx,si call @strtol$qpxzc xchg ax,si mov [di+2],dx @@ -470,30 +398,33 @@ endp @argstr$qpxzcxt1ppxzc - else +;*************************************************************** +;_fastcall void puts(bx:const char* s): +;*************************************************************** + global @puts$qpxzc:near -;*************************************************************** -;_fastcall int strhead(bx:const char* a, ax:const char* b); -;*************************************************************** - global @strhead$qpxzct1:near - proc @strhead$qpxzct1 near +; global puts:near ; puts(bx) +@putsz: + call @putc +@puts$qpxzc: +puts: + mov dl,[bx] + inc bx + or dl,dl + jne @putsz + mov dl,10 +@putc: + cmp dl,10 + jne @putcz + call @putcz2 +@putcz2: + xor dl,7 ; 10^13 1010^1101 +@putcz: + mov ah,2 +do_int21h: + int 21h + ret -@@loop: - xchg ax,bx - mov cl,[bx] ; cl = *b++ - inc bx - xchg ax,bx - or cl,cl ; clear C - jz failifc ; return 0 - xor cl,[bx] ; cl -= *a++ - inc bx - and cl,0dfh ; case insensitive - jne fail ; return -1 - jmp @@loop - - endp @strhead$qpxzct1 - - endif include "himem.inc" @@ -504,11 +435,9 @@ xchg ax,[bx] ret - global @malloc_or_die$qui:near proc @malloc_or_die$qui near - global malloc_or_die:near ; ax = malloc_or_die(ax) -malloc_or_die: +malloc_or_die: ; ax = malloc_or_die(ax) extrn _heap_top mov bx,offset _heap_top add ax,[bx] @@ -547,98 +476,108 @@ endp @die$qpxzc ;*************************************************************** -;_fastcall void puts(bx:const char* s): +;_fastcall void open_image(si:struct image_himem *m, ax:const char *name); ;*************************************************************** - global @puts$qpxzc:near -; global puts:near ; puts(bx) -@putsz: - call @putc -@puts$qpxzc: -puts: - mov dl,[bx] - inc bx - or dl,dl - jne @putsz - mov dl,10 -@putc: - cmp dl,10 - jne @putcz - call @putcz2 -@putcz2: - xor dl,7 ; 10^13 1010^1101 -@putcz: - mov ah,2 -do_int21h: - int 21h - ret + global @open_image$qp11image_himempxzc:near + proc @open_image$qp11image_himempxzc near + + mov [(image_himem si).state],ax + push ax +@@next: + call next_chunk + ifndef NO386 + add eax,3 + and al,0FCh + add [(image_himem si).size],eax ; m->size += m->chunk_size + or eax,eax + else + add ax,3 + adc dx,0 + and al,0FCh + add [word (image_himem si).size],ax ; m->size += m->chunk_size + adc [word ((image_himem si).size)+2],dx + or ax,dx + endif + jnz @@next + pop [(image_himem si).state] + + endp @open_image$qp11image_himempxzc ;*************************************************************** -;static long next_chunk(struct image_himem *di); +;static long next_chunk(struct image_himem *si); ;*************************************************************** proc next_chunk near - push si - mov ax,[(image_himem di).fd] + ifndef NO_CLOSE + mov ax,[(image_himem si).fd] call close + endif ifndef NO386 xor eax,eax else xor ax,ax cwd endif - mov [(image_himem di).fd],ax - mov bx,[(image_himem di).state] + mov [(image_himem si).fd],ax + mov bx,[(image_himem si).state] cmp al,[bx] ; "" jz @@end - mov si,bx + dec bx + push di @@scan: - lodsb - mov cx,si - cmp al,',' + inc bx + mov al,[bx] + mov di,bx + or al,al jz @@eos - or al,al + sub al,',' jnz @@scan - dec cx ; blocked to eos + inc bx @@eos: - mov [(image_himem di).state],cx - dec si - push [word si] - mov [byte si],ah ; set temp eos - call open - pop [word si] ; restore string - jc jcdie - mov [(image_himem di).fd],ax - mov [(image_himem di).fd2close],ax - mov bl,02h ; SEEK_END - call lseek0 -jcdie: - mov bx,[(image_himem di).errmsg] - jc die + xchg [(image_himem si).state],bx ; set start of string + mov [current_file],bx + xchg [di],ax ; set temp eos (ax == 0) + push ax + call @open$qpxzc + pop [word di] ; restore string + pop di + jnc @@opened +loadfailure: +;*************************************************************** +;_fastcall void loadfailure(void); +;*************************************************************** + global @loadfailure$qv:near +@loadfailure$qv: + mov bx,0 + org $-2 +current_file dw ? + call puts + mov bx,offset loaderr +jmpdie: + jmp die +@@opened: + mov [(image_himem si).fd],ax + ifndef NO_CLOSE + mov [(image_himem si).fd2close],ax + endif ifndef NO386 - push eax - mov ax,[(image_himem di).fd] - call rewind - pop eax + mov eax,[_isostate.filesize] @@end: - mov [(image_himem di).chunk_size],eax + mov [(image_himem si).chunk_size],eax else - push ax - push dx - mov ax,[(image_himem di).fd] - call rewind - pop dx - pop ax + mov ax,[word _isostate.filesize] + mov dx,[(word _isostate.filesize)+2] @@end: - mov [word (image_himem di).chunk_size],ax - mov [word ((image_himem di).chunk_size)+2],dx + mov [word (image_himem si).chunk_size],ax + mov [word ((image_himem si).chunk_size)+2],dx endif - pop si ret endp next_chunk +;*************************************************************** ifdef LARGE_IMAGES struc data_himem ;struct data_himem { @@ -685,12 +624,12 @@ mov [(image_himem si).bufv],ax xchg ax,si @@vcpi_alloc: - mov ax,0DE04h + mov ax,0DE04h ; allocate a 4K page => EDX int 67h or ah,ah stc mov bx,offset vcpi_alloc_err - jnz jcdie + jnz jmpdie ; for (i = cnt-1; i >= 0; i--) ifdef LARGE_IMAGES mov eax,ecx @@ -712,12 +651,11 @@ jae @@vcpi_alloc @@pmok: ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again - mov bx,offset _imgs.fallback+32 - add eax,[bx-2+2] ; +initrd.fallback + add eax,[bx-2+2+32] ; +initrd.fallback cmp eax,edx ; initrd.fallback+i*_4k > edx ? ja @@initrdok - mov eax,[bx-2+6] ; initrd.size - add eax,[bx-2+2] ; +initrd.fallback + mov eax,[bx-2+6+32] ; initrd.size + add eax,[bx-2+2+32] ; +initrd.fallback cmp eax,edx ; initrd.fallback+initrd.size > edx ? @@jnc_vcpi_alloc: ja @@vcpi_alloc @@ -744,8 +682,8 @@ lea cx,[(data_himem si).cache] ifdef NO386 push edx + pop ax ; to dx:ax pop dx - pop ax endif call storepage ; storepage(edx,cx) pop cx @@ -778,7 +716,6 @@ global memcpy_image_kernel:near memcpy_image_kernel: mov bx,si - global @memcpy_image$qp11image_himem:near proc @memcpy_image$qp11image_himem near ifndef NO386 @@ -813,7 +750,7 @@ xor cx,cx push cx call_memcpy32: - push dx + push dx ; push dx:ax push ax ifdef LARGE_IMAGES jmp @@memcpy @@ -846,7 +783,7 @@ mov edx,[di] else les ax,[dword di] - mov dx,es + mov dx,es ; to dx:ax endif mov cx,offset _xfer_buf storepage: ; storepage(edx,cx) @@ -945,106 +882,48 @@ endif ;*************************************************************** -;_fastcall void open_image(bx:struct image_himem *m, ax:const char *name); -;*************************************************************** - - global @open_image$qp11image_himempxzc:near - proc @open_image$qp11image_himempxzc near - - push di - xchg ax,bx - xchg ax,di - ifdef EXTRA - cmp [(image_himem di).fd],0 ; iso image/kernel ? - jnz @@alreadydone - endif - mov [(image_himem di).state],bx - push bx - ifdef EXTRA - cmp [(image_himem di).next_chunk],0 ; iso image/initrd ? - jnz @@next - mov [(image_himem di).next_chunk],offset next_chunk -@@next: - ;push di - call [(image_himem di).next_chunk] ; m->next_chunk() - ;pop di - else -@@next: - call next_chunk - endif - ifndef NO386 - add eax,3 - and al,0FCh - add [(image_himem di).size],eax ; m->size += m->chunk_size - or eax,eax - else - add ax,3 - adc dx,0 - and al,0FCh - add [word (image_himem di).size],ax ; m->size += m->chunk_size - adc [word ((image_himem di).size)+2],dx - or ax,dx - endif - jnz @@next - pop [(image_himem di).state] - ifdef EXTRA - ;push di - call [(image_himem di).next_chunk] ; m->next_chunk() - ;pop di - else - call next_chunk - endif -@@alreadydone: - pop di - ret - - endp @open_image$qp11image_himempxzc - - -;*************************************************************** -;_fastcall int read_image(bx:struct image_himem *m); +;_fastcall int read_image(si:struct image_himem *m); ;*************************************************************** global @read_image$qp11image_himem:near proc @read_image$qp11image_himem near - push si di - mov di,bx - mov si,4096 - push si ; original size + push di + mov di,4096 + push di ; original size @@loop: ifndef NO386 - movzx ecx,si - mov eax,[(image_himem di).chunk_size] + movzx ecx,di + mov eax,[(image_himem si).chunk_size] cmp ecx,eax jb @@szok else - mov cx,si - mov ax,[word (image_himem di).chunk_size] + mov cx,di + mov ax,[word (image_himem si).chunk_size] cmp cx,ax jb @@szok - cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size + cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size jne @@szok endif xchg ax,cx @@szok: jcxz image_done mov dx,offset _xfer_buf+4096 - sub dx,si - mov bx,[di] + sub dx,di + mov bx,[si] call @read$cxdxbx jb image_done xor cx,cx cwd ; ax < 8000h ifndef NO386 cwde ; ax < 8000h - sub [(image_himem di).chunk_size],eax + sub [(image_himem si).chunk_size],eax xchg eax,ebx else - sub [word (image_himem di).chunk_size],ax + sub [word (image_himem si).chunk_size],ax xchg ax,bx - sbb [word ((image_himem di).chunk_size)+2],dx + sbb [word ((image_himem si).chunk_size)+2],dx jnz @@fill - cmp [word (image_himem di).chunk_size],dx + cmp [word (image_himem si).chunk_size],dx endif jnz @@fill dec cx @@ -1056,30 +935,22 @@ jmp @@fill @@filled: ifndef NO386 - sub [(image_himem di).remaining],ebx + sub [(image_himem si).remaining],ebx else - sub [word (image_himem di).remaining],bx - sbb [word ((image_himem di).remaining)+2],dx + sub [word (image_himem si).remaining],bx + sbb [word ((image_himem si).remaining)+2],dx endif - sub si,bx + sub di,bx pushf - ifdef EXTRA - and cx,[(image_himem di).next_chunk] - jcxz @@same_chunk - push di - call cx - pop cx - else jcxz @@same_chunk call next_chunk - endif @@same_chunk: popf jnz @@loop image_done: pop ax ; original size - sub ax,si - pop di si + sub ax,di + pop di ret endp @read_image$qp11image_himem @@ -1088,21 +959,12 @@ ;*************************************************************** ;_fastcall unsigned long strtol(const char *s); ;*************************************************************** - ifndef USE_ARGSTR - global @strtol$qpxzc:near - endif proc @strtol$qpxzc near ifndef NO386 - ifndef USE_ARGSTR - push si - mov si,bx - endif xor ecx,ecx xor eax,eax xor ebx,ebx - or si,si - jz @@end lodsb or al,20h cmp al,'a' @@ -1173,16 +1035,7 @@ pop ax pop dx @@popsiret: - ifndef USE_ARGSTR - pop si - endif else - ifndef USE_ARGSTR - push si - mov si,bx - endif - or si,si - jz @@goend xor bx,bx xor cx,cx xor dx,dx @@ -1198,7 +1051,6 @@ @@vga: xchg ax,cx ;cwd -@@goend: jmp @@end @@notvga: mov cl,10 ; radix @@ -1264,9 +1116,6 @@ jne @@end inc dx @@end: - ifndef USE_ARGSTR - pop si - endif endif strtol_ret: ret @@ -1274,64 +1123,6 @@ endp @strtol$qpxzc - ifdef EXTRA - p8086 -;*************************************************************** -;_fastcall char *utoa(ax:unsigned n); -;*************************************************************** - global @utoa$qui:near - proc @utoa$qui near - - mov cx,10 - mov bx,offset utoabuf+5 -@@loop: - dec bx - xor dx,dx - div cx ; DX:AX = n%10:n/10 - mov [byte bx],'0' - add [bx],dl ; DL = n%10 - or ax,ax - jnz @@loop - xchg ax,bx - ret - - endp @utoa$qui - - -;*************************************************************** -;_fastcall unsigned long kver2ul(bx:char *kernel_version); -;*************************************************************** - global @kver2ul$qpzc:near - proc @kver2ul$qpzc near - - push si - mov si,bx - xor bx,bx - mov cx,304h -@@number: - xor ax,ax - cwd -@@digit: - shl al,cl - shl ax,cl - lodsb - sub al,30h - cmp al,9 - jbe @@digit - mov dl,bh - mov bh,bl - mov bl,ah - dec ch - jnz @@number - xchg ax,bx - pop si -kver2ulret: - ret - - endp @kver2ul$qpzc - - endif - ends _TEXT end diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/CRTL.H --- a/linld/stuff/src/CRTL.H Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/CRTL.H Fri Jan 08 20:15:35 2021 +0000 @@ -22,22 +22,19 @@ void parse_cmdline(); extern _fastcall void strcatb(const char* a,const char* b); extern _fastcall void strcpy(const char* a,const char* b); -#ifdef USE_ARGSTR extern _fastcall int argstr(const char *s, const char keywords[], const char **var); extern _fastcall int argnum(char *s, const char keywords[], unsigned long *var); extern _fastcall void set_cmdline(const char *filename); -#ifndef ISOHOOK -#define strhead(a,b) (strstr(a,b) != (int) (a)) -#else -extern _fastcall int strhead(const char* a,const char* head); -#endif -#else -extern _fastcall int strhead(const char* a,const char* head); -#endif +extern _fastcall int strcmp(const char* a,const char* b); +extern _fastcall int strhead(const char* a,const char* b); extern _fastcall int fileexist(const char* name); //extern "C" int open(const char* name, int flags); extern _fastcall int open(const char* name); +#ifdef NO_CLOSE +#define close(x) +#else extern _fastcall int close(int fd); +#endif extern _fastcall int moverm(unsigned short *p); extern _fastcall int readrm(struct image_himem *m, int sz); extern _fastcall int read(int fd, void* data, int sz); @@ -59,3 +56,5 @@ extern char cpu_features[]; #define CPUMASKLM (0x20) #define cpuhaslm() (cpu_features[3]&CPUMASKLM) + +extern void loadfailure(void); diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/CRTLX.H --- a/linld/stuff/src/CRTLX.H Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -// This file is distributed under GPL -// -extern _fastcall long lseekset2(int fd, unsigned long* whence); -extern _fastcall void strcat(const char* a,const char* b); -extern _fastcall int strcmp(const char* a,const char* b); -//extern "C" char* strstr(const char* a,const char* b); -extern _fastcall int strstr(const char* a,const char* b); -extern _fastcall unsigned long kver2ul(char *kernel_version); -//extern "C" char *utoa(unsigned n); -extern _fastcall int utoa(unsigned n); -extern "C" void try_default_args(); diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/HEADER.ASM --- a/linld/stuff/src/HEADER.ASM Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -;*************************************************************** -;****** This file is distributed under GPL -;*************************************************************** - ideal - %PAGESIZE 1000 - %crefref - %noincl - %nomacs - p8086 - - group DGROUP _TEXT - assume cs:DGROUP,ds:DGROUP - - segment _TEXT byte public use16 'CODE' - -COMSTART = 100h -MAXCODESZ = 0F000h ; < 64K - COMSTART - STKSZ - - org COMSTART - global _text_start:byte - label _text_start byte - - cld - mov dx,offset tazboot_cmd - mov di,80h - cmp [byte di],dh - ja notfound - mov ax,3d00h ; read-only+compatibility - ;mov cl,0 ; attribute mask - int 21h - jc notfound -found: - xchg ax,bx - mov ah,3Eh ; close - int 21h - mov si,offset default_arg ; di = 0080h - mov cx,di - rep - movsb -notfound: - mov di,MAXCODESZ+offset endcmd - mov si,offset move - mov cx,COMSTART - mov ax,offset endcmd -move: - push di - push cx - rep - movsb - pop di - pop cx - ;sub cx,ax - xchg ax,si - push cx - ret - -default_arg db endcmd-begcmd -begcmd db " @" -tazboot_cmd db "tazboot.cmd",0 -endcmd: - -;*************************************************************** - - ends _TEXT - - - end _text_start - -;###### END OF FILE ############################################ diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/HEADER.CMD --- a/linld/stuff/src/HEADER.CMD Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -header.obj, header diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/HIMEM.CPP --- a/linld/stuff/src/HIMEM.CPP Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/HIMEM.CPP Fri Jan 08 20:15:35 2021 +0000 @@ -6,20 +6,13 @@ #include "crtl.h" #include "common.h" -#ifdef WITH_XMM_ALLOC -u16 skip_alloc; -#endif -static u32 buf; +extern u32 himem_buf; void load_image(struct image_himem *m) { m->remaining = m->size; m->buf = m->fallback; // set no_exit btw: die() won't return to DOS - u32* bufv= &buf; -#ifdef WITH_XMM_ALLOC - if(((u16 *)&m->fallback)[1] >= (skip_alloc|0x10)) { // >= _1m ? -#else + u32* bufv= &himem_buf; if(((u16 *)&m->fallback)[1] >= 0x10) { // >= _1m ? -#endif if(vcpi) { bufv = (u32 *)malloc_bufv_or_die(m); // update m->bufv } @@ -29,15 +22,15 @@ } #endif } - buf = m->buf; + himem_buf = m->buf; do { u16 size; if(s16(size = read_image(m)) -1 < 0) break; storepage(bufv); - if (bufv != &buf) next(bufv); - buf += size; + if (bufv != &himem_buf) next(bufv); + himem_buf += size; } while (*bufv); - if(m->remaining) die("Read error"); + if(m->remaining) loadfailure(); close(m->fd2close); } @@ -57,9 +50,9 @@ pusha # endif } + vm2rm(); struct image_himem *m = ± u32 *q; - vm2rm(); if(((u16 *)&m->fallback)[1] >= 0x10) // >= _1m ? ((u16 *)&m->fallback)[1] = 0x10; q = m->bufv; diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/HIMEM.INC --- a/linld/stuff/src/HIMEM.INC Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/HIMEM.INC Fri Jan 08 20:15:35 2021 +0000 @@ -5,9 +5,7 @@ remaining dd ? ;10 u32 remaining; buf dd ? ;14 u32 buf; bufv dw ? ;18 u32 *bufv; -errmsg dw ? ;20 char *errmsg; -chunk_size dd ? ;22 u32 chunk_size; -next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *); -state dw ? ;28 u16 state; -fd2close dw ? ;30 u16 fd2close; +chunk_size dd ? ;20 u32 chunk_size; +state dw ? ;24 u16 state; +fd2close dw ? ;26 u16 fd2close; ends image_himem ;}; diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/ISO9660.CPP --- a/linld/stuff/src/ISO9660.CPP Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/ISO9660.CPP Fri Jan 08 20:15:35 2021 +0000 @@ -1,73 +1,41 @@ #include "crtl.h" -#include "crtlx.h" #include "iso9660.h" -#define __ROCKRIDGE -#if 1 -#define setdirofs(to,sec) (*(int*)((char*)&(to)+1) = *(int*)&(sec)<<(SECTORBITS-8)) -#define cpydirofs(to,from) (*(int*)((char*)&(to)+1) = *(int*)((char*)&(from)+1)) -#else -#define setdirofs(to,sec) (to = (sec)<dirpage, (* (unsigned long *) (isostate.buffer + 0x9E))); \ + x->dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); \ } -#else -int isoroot(void) -{ - static const unsigned long root = 16UL * 2048; - if (isoreadsector(&root) == -1 || strhead(isostate.buffer+1,"CD001") == -1) { - //close(isostate.fd); - return -1; - } - setdirofs(isostate.dirofs, (* (unsigned long *) (isostate.buffer + 0x9E))); - isostate.dirsize = filesize2dirsize(* (unsigned long *) (isostate.buffer + 0xA6)); - return 0; -} -#endif -int isoreaddir(void) +static int isoreaddir(void) { char *p; struct isostate *x=&isostate; - if (x->curdirsize == 0xFFFF) { - x->curdirsize = x->dirsize; - cpydirofs(x->curdirofs, x->dirofs); - goto restarted; - } if (x->curpos >= SECTORSZ || * (short *) (x->buffer + x->curpos) == 0) { - restarted: - if (x->curdirsize < DIRSECTORSZ) return -1; - isoreadsector(&x->curdirofs); + if ((x->curdirsize =- DIRSECTORSZ) < 0) return -1; + isoreadsector(&x->curdirofs); // x->filepos = 0 //x->curdirofs += SECTORSZ; *(int *)((char *) &x->curdirofs+1) += SECTORSZ/256; - x->curdirsize -= DIRSECTORSZ; x->curpos = 0; } p = x->buffer; p += x->curpos; + x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS; if ((x->entrysize = * (short *) p) == 0) { return -1; } - x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS; + // x->filename = ""; x->filesize = * (unsigned long *) (p + 10); x->filemod = 0x81ED; if (p[25] & 2) ((char *)&(x->filemod))[1] = 0x41; - //x->filemod = (p[25] & 2) ? 0040755 : 0100755; - //x->filemod = 0100755 - ((p[25] & (char)2) << 13); -#ifdef __ROCKRIDGE - // p += 34 + (p[32] & -2); ? p = x->buffer + 34 + ((p[32] + x->curpos) & -2); -#ifdef ISOHOOK x->curpos += x->entrysize; -#endif do { register len = p[2]; if (* (short *) p == 0x4D4E) { @@ -76,42 +44,18 @@ goto found; } p += len; -#ifdef ISOHOOK - } while (x->buffer + x->curpos - 2 > p); -#else - } while (x->buffer + x->curpos + x->entrysize - 2 > p); -#endif -#endif -#ifndef ISOHOOK - { - p = x->buffer + 33; x->filename = p += x->curpos; - p--; - if (((* (short *) p) & 0xFEFF) -1 == 0) { - x->filename = ".."; - if (--(* (short *) p) == 0) - x->filename++; - } - else { - p += *p; p--; - if (* (short *) (p) != 0x313B) { - p++; p++; // no ;1 to remove - } - if (p[-1] == '.') p--; - *p = 0; - } - } -#endif + } while (x->buffer + x->curpos - 3 >= p); found: -#ifndef ISOHOOK - x->curpos += x->entrysize; -#endif return 0; } -//#define IS_DIR(x)( ((x) & ~0777) == 040000) -//#define IS_DIR(x)( (char)((x) >> 9) == (char)040) -//#define IS_DIR(x)( (*((char*) &x + 1) & (char)0776) == (char)0100) -#define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0) +#define isoreaddir_reset() \ +{ \ + x->curdirsize = x->dirsize; \ + cpyfromdirpage(x->curdirofs, x->dirpage); \ + x->curpos = -1; \ +} + int _isoopen(void) { // char *name, *s, c; @@ -123,25 +67,24 @@ char *s; _64bits = cpuhaslm(); - do { -#ifdef ISOHOOK + _32bits: s = (char *) x->filename2open; if (*s == '/') { s++; isoroot(); - } - name = s; - while (*++s); -#else - for (s = (char *) x->filename2open; *s == '/' ; s++) { - isoroot(); + //if (strncmp(x->buffer+1,"CD001,5) == -1) return -1; + //if (*(int*)(x->buffer+1) != 0x4443) return -1; } next: + isoreaddir_reset(); name = s; do s++; while (*s && *s != '/'); c = *s; *s = 0; -#endif - for (x->curdirsize = 0xFFFF; isoreaddir() != -1;) { + do { + if (isoreaddir() == -1) { + if ((_64bits ^= CPUMASKLM) == 0) goto _32bits; + return -1; + } const char *n = name; #define i (x->tmp) i = x->filename; @@ -150,20 +93,15 @@ n = "64"; i += s - name; // strlen(name); } - if (strcmp(i, n) == -1) continue; -#ifndef ISOHOOK - *s++ = c; -#endif - if (IS_DIR(x->filemod)) { - cpydirofs(x->dirofs, x->fileofs); - x->dirsize = filesize2dirsize(x->filesize); -#ifndef ISOHOOK - if (c) goto next; -#endif - } - isolseek(&x->fileofs); - return 0; + if (strcmp(i, n) != -1) break; + } while (1); + *s++ = c; +#define IS_DIR(x)( (*((char*) &x + 1) & (char)0676) == (char)0) + if (IS_DIR(x->filemod)) { + cpytodirpage(x->dirpage, x->fileofs); + x->dirsize = filesize2dirsize(x->filesize); + if (c) goto next; } - } while ((_64bits ^= CPUMASKLM) == 0); - return -1; + isolseek(&x->fileofs); + return x->fd; } diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/ISO9660.H --- a/linld/stuff/src/ISO9660.H Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/ISO9660.H Fri Jan 08 20:15:35 2021 +0000 @@ -3,7 +3,7 @@ //typedef unsigned long dirsizetype; //#define filesize2dirsize(x) (x) //#define DIRSECTORSZ SECTORSZ -typedef unsigned dirsizetype; +typedef short dirsizetype; #define filesize2dirsize(x) (*(dirsizetype *)((char *)&(x)+1)) #define DIRSECTORSZ (SECTORSZ/256) extern struct isostate { @@ -13,9 +13,12 @@ unsigned short filemod; unsigned long fileofs; unsigned long filesize; + unsigned long filepos; char *filename; dirsizetype curdirsize, dirsize; - unsigned long curdirofs, dirofs; +typedef unsigned dirpagetype; + dirpagetype dirpage; + unsigned long curdirofs; int entrysize; const char *tmp; char c; @@ -31,8 +34,8 @@ #define isofilename isostate.filename extern _fastcall void isolseek(const unsigned long *offset); extern _fastcall int isoreadsector(const unsigned long *offset); -extern _fastcall int isoreset(char *name); -extern _fastcall int isoopen(const char *name); +extern int _isoopen(void); extern int isoreaddir(void); #define isolabel() do { isofileofs=0x8028; isofilesize=32; } while (0) +#define setiso(x) (isostate.fd = open(x)) #endif diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/ISOCRTL.ASM --- a/linld/stuff/src/ISOCRTL.ASM Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,263 +0,0 @@ -;*************************************************************** -;****** This file is distributed under GPL -;*************************************************************** - ideal - %PAGESIZE 1000 - %crefref - %noincl - %nomacs - ifdef NO386 - p8086 - else - p386 - endif - - group DGROUP _TEXT,_DATA,_BSS - assume cs:DGROUP,ds:DGROUP - - segment _TEXT byte public use16 'CODE' - ends _TEXT - - segment _DATA byte public use16 'DATA' - ends _DATA - - segment _BSS byte public use16 'BSS' - - include "isostate.inc" - - public _isostate -_isostate isostate -; org $-7 - - ends _BSS - - segment _TEXT byte public use16 'CODE' - - global fold:near -fold: - org 130h-100h - global _cpu_features:dword -_cpu_features dd ? - org 0F000h-100h - global unfold:near -unfold: - jmp iso_open - extrn @isoreaddir$qv - dw @isoreaddir$qv - jmp @readmenu$qv - - push dx - call readfd - push ds - pop es - mov di,128h ; TABLE - mov ax,offset iso_close_hack - stosw - inc ax ; iso_open_hack - stosw - add al,offset iso_read_hack-offset iso_open_hack - stosw - add al,offset iso_lseek_hack-offset iso_read_hack - stosw - ifdef NO386 - global N_LXLSH@ES:near -N_LXLSH@ES: - mov dx,es - global N_LXLSH@:near -N_LXLSH@: - mov ch,0 -@@lp: - shl ax,1 - rcl dx,1 - loop @@lp - endif -iso_close_hack: - ret - -;*************************************************************** -;_fastcall int open(bx:const char* name); -;*************************************************************** -iso_open_hack: - extrn @_isoopen$qv:near - cmp [byte bx],'!' - je @readmenu$qv - xchg ax,bx -iso_open: - mov [_isostate.filename2open],ax - call @_isoopen$qv - cmp al,1 - cmc - ret - - -;*************************************************************** -;_fastcall int read(bx:int fd=isostate.fd, dx:void* data, cx:int sz, ah=3Fh); -;*************************************************************** -iso_read_hack: - push dx - xor dx,dx - ifndef NO386 - push dx - endif - push cx - xor cx,cx - mov al,01h - call doseek ; bx = _isostate.fileofs - ifdef NO386 - mov cx,[bx+4] ; _isostate.filesize - sub cx,ax - mov ax,[bx+6] - sbb ax,dx - pop ax - ja @@axok - cmp ax,cx - else - push dx - push ax - pop ecx - mov eax,[_isostate.filesize] - sub eax,ecx - pop ecx - cmp eax,ecx - endif - ja @@cxok -@@axok: - xchg ax,cx -@@cxok: - pop dx ; buffer - jmp readfd - - -;*************************************************************** -;_fastcall long lseek(ax:int fd=isostate.fd, cxdx:unsigned long offset, bl:whence, bh=42h); -;*************************************************************** -iso_lseek_hack: - xchg ax,bx - ifdef SEEK_CUR - cmp al,1 ; current - je doseek - endif - mov bx,offset _isostate.fileofs - add dx,[bx] - adc cx,[bx+2] - cmp al,0 ; start - je doseek - add dx,[bx+4] ; _isostate.filesize - adc cx,[bx+6] - mov al,0 -doseek: - call lseek ; lseek(,,al) -sub_fileofs: - mov bx,offset _isostate.fileofs - sub ax,[bx] - sbb dx,[bx+2] - ret - - -;*************************************************************** -;_fastcall void readmenu(void); -;*************************************************************** - proc @readmenu$qv near - - mov dx,18 - xor cx,cx - call lseekset - mov dx,offset _isostate.filemod - mov cl,10 - call readfd ; // read x->filemod + x->fileofs & x->filesize - mov bx,offset _isostate.fileofs - ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF); - mov ax,7FF0h - cwd - mov [word bx+6],dx - sub ax,[bx+4] - mov [word bx+2],dx - mov [bx],ax - ; //magic = x->filemod; - - endp @readmenu$qv - -;*************************************************************** -;_fastcall void isolseek(bx:const unsigned long *offset); -;*************************************************************** - global @isolseek$qpxul:near - proc @isolseek$qpxul near - -isolseek: - mov dx,[bx] - mov cx,[bx+2] -lseekset: - mov al,00h ; bx=fd cx:dx=offset al=whence -lseek: - mov ah,42h -dosfd: - mov bx,[_isostate.fd] -dos: - int 21h -failifc: - jnc dosok -fail: - sbb ax,ax - cwd -dosok: - ret - - endp @isolseek$qpxul - - -;*************************************************************** -;_fastcall int isoreadsector(bx:const unsigned long *offset); -;*************************************************************** - global @isoreadsector$qpxul:near - proc @isoreadsector$qpxul near - - call isolseek - jc fail - mov ch,9 ; < 2560 - mov dx,offset _isostate.buffer -readfd: - mov ah,3Fh - jmp dosfd - - endp @isoreadsector$qpxul - - -;*************************************************************** -;_fastcall int strhead(bx:const char* a, ax:const char* b); -;*************************************************************** - global @strhead$qpxzct1:near - proc @strhead$qpxzct1 near - -@@loop: - xchg ax,bx - mov cl,[bx] ; cl = *b++ - inc bx - xchg ax,bx - or cl,cl ; clear C - jz fail ; return 0 - xor cl,[bx] ; cl -= *a++ - inc bx - or cl,cl - stc - jne fail ; return -1 - jmp @@loop - - endp @strhead$qpxzct1 - - -;*************************************************************** -;_fastcall int strcmp(bx:const char* a, ax:const char* b); -;*************************************************************** - global @strcmp$qpxzct1:near - proc @strcmp$qpxzct1 near - - call @strhead$qpxzct1 - jne dosok ; return -1 - cmp cl,[bx] - jmp fail ; return 0 or -1 - - endp @strcmp$qpxzct1 - - ends _TEXT - - end diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/ISOSTATE.INC --- a/linld/stuff/src/ISOSTATE.INC Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/ISOSTATE.INC Fri Jan 08 20:15:35 2021 +0000 @@ -7,15 +7,16 @@ filemod dw ? ; 6 unsigned short filemod; fileofs dd ? ; 8 unsigned long fileofs; filesize dd ? ;12 unsigned long filesize; -filename dw ? ;16 char *filename; -curdirsize dw ? ;18 dirsizetype curdirsize; -dirsize dw ? ;20 dirsizetype dirsize; -curdirofs dd ? ;22 unsigned long curdirofs; -dirofs dd ? ;26 unsigned long dirofs; +filepos dd ? ;16 unsigned long filepos; +filename dw ? ;20 char *filename; +curdirsize dw ? ;22 dirsizetype curdirsize; +dirsize dw ? ;24 dirsizetype dirsize; +dirpape dw ? ;26 unsigned short dirpage; +curdirofs dd ? ;28 unsigned long curdirofs; ;overlap -entrysize dw ? ;30 int entrysize; -tmp dw ? ;32 const char *tmp; -c db ? ;34 char c; -_64bits db ? ;35 char _64bits; -buffer db ? ;36 char buffer[2048+512]; +entrysize dw ? ;32 int entrysize; +tmp dw ? ;34 const char *tmp; +c db ? ;36 char c; +_64bits db ? ;37 char _64bits; +buffer db ? ;38 char buffer[2048+512]; ends isostate ; } isostate; diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/JUMP.ASM --- a/linld/stuff/src/JUMP.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/JUMP.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -87,7 +87,8 @@ extrn sssp:word mov ax,[sssp+2] mov es,ax - extrn _cmdline:word + extrn _cmdstr:word +_cmdline = _cmdstr+0 mov si,[_cmdline] mov di,8000h mov cx,2000h ; 4k for cmdline + 4k up to sp diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/LINK.CMD --- a/linld/stuff/src/LINK.CMD Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/LINK.CMD Fri Jan 08 20:15:35 2021 +0000 @@ -1,1 +1,1 @@ -_beg.obj memtop.obj memcpy32.obj jump.obj vcpi.obj xmm.obj a20.obj crtl.obj load.obj himem.obj linld.obj _end.obj, linld +_beg.obj memtop.obj memcpy32.obj jump.obj vcpi.obj xmm.obj a20.obj crtl.obj load.obj himem.obj iso9660.obj linld.obj _end.obj, linld diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/LINK2.CMD --- a/linld/stuff/src/LINK2.CMD Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -_isobeg.obj isocrtl.obj iso9660.obj _end.obj, isoboot diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/LINKX.CMD --- a/linld/stuff/src/LINKX.CMD Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -_beg.obj memtop.obj memcpy32.obj jump.obj vcpi.obj xmm.obj a20.obj crtl.obj load.obj himem.obj iso9660.obj tazboot.obj _end.obj, tazboot diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/LINLD.CPP --- a/linld/stuff/src/LINLD.CPP Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/LINLD.CPP Fri Jan 08 20:15:35 2021 +0000 @@ -4,29 +4,16 @@ #include "crtl.h" #include "common.h" +#include "iso9660.h" -const char* cmdline = "auto"; -const char* kernel_name = "bzImage"; -#ifdef USE_ARGSTR -const char* initrd_name = NULL; -#else -const char* initrd_name; -#endif -u32 root_dev; -u32 vid_mode; // -3 = ask - // -2 = Extended VGA - // -1 = Normal VGA - // n = as "n" was pressed -u32 topmem; -u32 base_himem; +extern char bzimagestr[]; +const char* cmdstr[4] = {"auto",bzimagestr,NULL,NULL}; +u32 cmdnum[4]; inline void syntax() { die("Syntax:" NL - "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline]" NL + "LINLD [image=file] [initrd=files] [vga=mode] [root=num] [mem=max] [cl=cmdline] [iso=file]" NL "vga mode: ask,extended,normal or dec/oct/hex number" NL -#ifdef WITH_XMM_ALLOC - "-f force" NL -#endif "-64 for cpu64 only" NL "Defaults:" NL "\timage=bzImage" NL @@ -39,9 +26,6 @@ #if 1 NL NL "Examples:" NL "\tLINLD " -#ifdef WITH_XMM_ALLOC - "-f " -#endif "-b 64m " "initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz " "\"cl=root=/dev/null video=-32\"" @@ -50,7 +34,7 @@ ); } -static char buf_cmdline[128]; +extern char buf_cmdline[128]; int main(int argc, char *argv[]) { (void) argc; @@ -59,21 +43,14 @@ puts("LINLD v" VERSION_STR "+"); // Parse command line -#ifdef USE_ARGSTR if (!*++argv) syntax(); const char **clp = &cmdline; do { if ((*(u16 *)*argv|2) == 0x362F) { // -64 /64 - if (cpuhaslm() == 0) exit(); - continue; + if (cpuhaslm() != 0) continue; + exit(); } -#ifdef WITH_XMM_ALLOC - if ((*(u16 *)*argv|0x2002) == 0x662F) { // -F /f - skip_alloc--; - continue; - } -#endif - if (argstr(*argv,"cl|image|initrd",clp) == (int) clp) continue; + if (argstr(*argv,"cl|image|initrd|iso",clp) == (int) clp) continue; if (argnum(*argv,"root|vga|mem|-b",&root_dev) == (int) &base_himem) continue; if (fileexist(*argv) != -1) { kernel_name=*argv; @@ -83,94 +60,12 @@ strcatb((const char *) buf_cmdline,*argv); } while (*++argv); puts(*clp); + if (isofile) setiso(isofile); set_cmdline(*clp); load_kernel(); load_initrd(); boot_kernel(); -#else - if (!argv[1]) syntax(); - while (1) { - char *s; - next: - argv++; - s=*argv; - if (!s) { - load_kernel(); - puts(version_string); - load_initrd(); - boot_kernel(); - } - if(strhead(s,"initrd=") != -1) { - initrd_name=s+7; - } - else if(strhead(s,"vga=") != -1) { - *(u16*)&vid_mode = (u16)strtol(s+7); // support normal, extended & ask - } - else switch (*(u16 *)s|0x2002) { - case 0x362F: // -64 /64 - if (cpuhaslm() == 0) exit(); - goto next; -#ifdef WITH_XMM_ALLOC - case 0x662F: // -F /f - skip_alloc--; - goto next; -#endif - case 0x622F: // -B /b - argv++; - ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16); - goto next; - default: - if(strhead(s,"cl=") != -1) { - cmdline=s+=3; - if (*s == '@') { - static struct image_himem image; - char c; - - s++; - image.errmsg = "Error in cl=@file"; - open_image(&image, s); - s+=read(image.fd, (void *)cmdline=s= - (char *)malloc_or_die(image.size), image.size); - // Strip any trailing cr/lf - c='\0'; - do { - // Replace all other cr/lfs with spaces - s--; - if(*s>=' ') c=' '; - else *s = c; - } while (s>cmdline); - puts("Kernel command line:"); - puts(cmdline); - } - } - else if(strhead(s,"root=") != -1) { - *(u16*)&root_dev = (u16)strtol(s+5); - goto addincmdline; - } - else if(strhead(s,"mem=") != -1) { - ((u16 *)&topmem)[1] = (u16)(strtol(s+4)>>16); - goto addincmdline; - } - else if(strhead(s,"image=") != -1) { - s+=6; - set_kernel_name: - kernel_name=s; - } - else { - addincmdline: - if(cmdline == (const char *) buf_cmdline + 1) { - strcatb(buf_cmdline,*argv); - } - else { - if(fileexist(s) != -1) goto set_kernel_name; - cmdline = (const char *) buf_cmdline + 1; - goto addincmdline; - } - } - } - } -#endif // Let compiler be happy - //return _AX; + return _AX; } diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/LOAD.CPP --- a/linld/stuff/src/LOAD.CPP Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/LOAD.CPP Fri Jan 08 20:15:35 2021 +0000 @@ -60,8 +60,8 @@ // The file-system on that floppy must be MINIX // If rd_load() succeeds it sets the root_dev // to the ramdisk for mounting it - u16 vid_mode; // 01FA Video mode control - u16 root_dev; // 01FC Default root device number + u16 vidmode; // 01FA Video mode control + u16 rootdev; // 01FC Default root device number u16 boot_flag; // 01FE 0xAA55 magic number u16 jump; // 0200 Jump instruction u32 header; // 0202 Magic signature "HdrS" @@ -120,8 +120,6 @@ static u8* rm_buf; // @ = @rm_size + 2, see A20.ASM struct image_himem imgs[2]; -static const char kernel_file_error[] = "Can't use kernel file"; -#define not_kernel "Not a kernel" void load_kernel() { struct image_himem *m = ± @@ -133,7 +131,6 @@ #define first1k ((first1k_t*)((u8 *)kernelparams-0x1F1)) // Open kernel, read first kb, check it - m->errmsg = kernel_file_error; open_image(m, kernel_name); do { @@ -151,20 +148,20 @@ } if((kernelparams->setup_sects)>=(_32k/512) || // 0th sector not counted kernelparams->boot_flag != 0xAA55) - die(not_kernel); + die("Not a kernel"); _rm_size=0x200*(kernelparams->setup_sects+1); m->size -= _rm_size; m->chunk_size -= _rm_size; // Read remaining rm loader if (readrm(m, _rm_size) == _rm_size) break; - die(kernel_file_error); + loadfailure(); } while (0); // Tell rm loader some info - if((int)vid_mode) kernelparams->vid_mode = vid_mode; - if((int)root_dev) kernelparams->root_dev = root_dev; + if((int)vid_mode) kernelparams->vidmode = vid_mode; + if((int)root_dev) kernelparams->rootdev = root_dev; if(kernelparams->header == HdrS) { // starting linux 1.3.73 if(kernelparams->loadflags & 1) { // zImage as pre 1.3.73 @@ -178,11 +175,7 @@ hook_int15_88(); // break _ES } if (kernelparams->kernel_version) -#ifndef EXTRA puts((char *) first1k+kernelparams->kernel_version+0x200); -#else - strcatb(version_string,(char *) first1k+kernelparams->kernel_version+0x200); -#endif kernelparams->type_of_loader = 0xff; // kernel do not know us (yet :-) if(kernelparams->version >= 0x201) { // * offset limit of the setup heap @@ -216,20 +209,17 @@ // Read initrd if needed void load_initrd() { struct image_himem *m = &initrd; - if (((int)initrd_name | m->fd) == 0) return; // !initrd_name && !m->fd + if ((int)initrd_name == 0) return; #if defined(__BORLANDC__) && defined(NO386) #pragma option -3 asm{ .386p } #endif - m->errmsg = "Can't use initrd file"; - open_image(m, initrd_name); if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK))-m[-1].fallback < m[-1].size) { - puts(m->errmsg); - close(m->fd); + loadfailure(); return; } diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/MEMCPY32.ASM --- a/linld/stuff/src/MEMCPY32.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/MEMCPY32.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -15,6 +15,12 @@ group DGROUP _TEXT assume cs:DGROUP,ds:DGROUP +macro lcr0 reg + mov cr0,reg + jmp short $+2 ;*Required*! + ;3+ NOPs also work fine (chkd on 386) +endm + segment _TEXT byte public use16 'CODE' ;*************************************************************** @@ -25,25 +31,16 @@ global memcpy32:near proc memcpy32 near -; rm32,imm16 helper -macro addzx_e rm,i - db 66h - add rm,i - dw 0 -endm arg dstofs :dword, \ srcseg :word, \ srcofs :dword, \ sz :dword = PARAM_SIZE - local GDTR :pword, \ - oldGDTR :pword = TEMP_SIZE - ;****** Init *************************************************** ifndef NO386 - enter TEMP_SIZE,0 + enter 0,0 ;cld pushf push ds es @@ -86,7 +83,6 @@ push bp mov bp,sp - sub sp,TEMP_SIZE ;cld pushf push ds es @@ -168,22 +164,16 @@ std ; @@do_copy: cli +oldGDTR = (pword srcseg) ; don't need src seg/ofs anymore sgdt [oldGDTR] ;****** Load gdtr ********************************************** - mov eax,cs - shl eax,4 - addzx_e ax, - or [word GDTR],-1 ;GDT limit = 0FFFFh - mov [dword GDTR+2],eax ;GDT base lgdt [GDTR] ;****** Go into pm ********************************************* mov eax,cr0 inc ax ;CR0_PE on - mov cr0,eax - jmp short $+2 ;*Required*! - ;3+ NOPs also work fine (chkd on 386) + lcr0 eax ;****** Move data ********************************************** push 0008h pop ds ;base=0, lim = 4gb @@ -196,10 +186,7 @@ ;****** Return to rm ******************************************* dec ax ;CR0_PE off - mov cr0,eax ;ds/es limits are *not* reset to 64kb - ; but who cares :-) - jmp short $+2 - + lcr0 eax ;****** Return ************************************************* lgdt [oldGDTR] @@done: @@ -212,21 +199,17 @@ p386 leave else - mov sp,bp pop bp endif ret 14 ;****** Const data ********************************************* - org $-8 ;save 8 bytes - they are unused anyway -;0000: unused -GDT dd ?,? -;0008: Data seg [0,FFFFFFFF] - ; lim_lo base_lo - dw 1111111111111111b, 0000000000000000b - db 00000000b,10010010b,10001111b,00000000b - ; base_med P S D A G ??l_hi base_hi - ; Pl E W D + + extrn gdt_memcpy +label GDTR pword +gdt_limit dw 0ffffh + global gdt_base_memcpy:word +gdt_base_memcpy dw offset gdt_memcpy,0 endp memcpy32 diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/MEMTOP.ASM --- a/linld/stuff/src/MEMTOP.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/MEMTOP.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -139,7 +139,8 @@ ; we had trouble detecting memory size cmp dx,cx jb @@set - extrn _topmem:dword + extrn _cmdnum:dword +_topmem = _cmdnum+8 mov cx,[word _topmem+2] inc cx ; jcxnz loop @@topmemset @@ -186,11 +187,13 @@ mov [dword saved15],eax else mov ax,offset int15_88 + call saved15z + mov ax,cs + inc bx + inc bx +saved15z: xchg ax,[es:bx+15*4] - mov [word saved15],ax - mov ax,cs - xchg ax,[es:bx+15*4+2] - mov [word saved15+2],ax + mov [word bx+saved15],ax endif ;push ds ;pop es diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/TAZBOOT.CPP --- a/linld/stuff/src/TAZBOOT.CPP Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,271 +0,0 @@ -// This file is distributed under GPL -// -// TAZBOOT main() lives here - -#include "crtl.h" -#include "crtlx.h" -#include "common.h" -#include "iso9660.h" - -struct initrd_info { - u32 ofs; - u32 size; -}; -#define MAXINITRD 10 -static struct initrd_state { - struct initrd_info info[MAXINITRD]; - u16 cnt; -} initrd_state; - -static void next_chunk(struct image_himem *m) -{ - m->chunk_size = 0; - if (m->state >= initrd_state.cnt) return; - struct initrd_info *i = &initrd_state.info[m->state]; - m->chunk_size = i->size; - m->state++; - lseekset2(m->fd,&i->ofs); -} - -static u32 isofilesize4round() -{ - return (isofilesize+3)&-4; -} - -static void addinitrd() -{ - u16 *pcnt = &initrd_state.cnt; - if (*pcnt >= MAXINITRD) return; - struct initrd_info *i = &initrd_state.info[(*pcnt)++]; - i->size = isofilesize; - i->ofs = isofileofs; - initrd.size += isofilesize4round(); -} - -static void load_initrds() -{ - struct image_himem *m = &initrd; - if (!m->size) return; - m->next_chunk = next_chunk; - m->fd = isofd; - m->state = 0; - next_chunk(m); - load_initrd(); -} - -static char *isokernel() -{ - struct image_himem *m = ± - m->chunk_size = m->size = isofilesize4round(); - m->fd = isofd; - load_kernel(); - return version_string; -} - -static char buf_cmdline[4096]; -const char *cmdline = (const char *) buf_cmdline+1; -static void bootiso(char **iso) -{ - const char *init = " rdinit=/init.exe", *mode="menu"; - char c; - static char rootfs[16], fallback[16], noauto; - unsigned long magic; - struct isostate *x=&isostate; - - if (isoreset(*iso) == -1) return; -#ifdef WITH_XMM_ALLOC - skip_alloc--; -#endif - base_himem = memtop() /2; - //if (base_himem >= _64m) base_himem = _64m; - if (* ((char *) &base_himem +3) >= 4) ((short *)&base_himem)[1] = _64m/_64k; - isoopen("boot"); - if (iso[1] && !strcmp(mode = iso[1], "text")) - init = ""; - if (isoopen(mode) == -1 || ++noauto == 0) // custom - isoopen("bzImage"); // SliTaz - magic = kver2ul(isokernel()); - for (c = 0, x->curdirsize = 0xFFFF; isoreaddir() != -1;) { - if (strstr(x->filename, ".gz")) - strcpy(fallback, x->filename); - if (strhead(x->filename, "rootfs") == -1 - || c > x->filename[6]) continue; - c = x->filename[6]; - strcpy(rootfs, x->filename); - } - - strcatb(buf_cmdline,"autologin bootfrom="); - strcat(buf_cmdline,*iso); - if (magic < 0x20630) - init = ""; // Does not support multiple initramfs - - if (noauto) { - char *s; - * (int *) buf_cmdline = 0; - iso++; - while ((s = *++iso) != NULL) { - if (strhead(s,"initrd=") == -1) - strcatb(buf_cmdline,s); - else if (isoopen(s+7) != -1) - addinitrd(); - } - } - else if (magic != 0) { - static const unsigned long initrddesc = 18L; - - if (isoopen("rootfs.gz") != -1 || - isoopen(rootfs[0] ? rootfs : fallback) != -1) { - addinitrd(); - } - if (*init) { - isolseek(&initrddesc); - read(x->fd, &x->filemod, 10); // + x->fileofs & x->filesize - magic = x->filemod; - x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF); - if (((short *) &x->fileofs)[1] == 0) addinitrd(); - else init=""; - } - strcat(buf_cmdline,init); - strcatb(buf_cmdline,"mode="); - strcat(buf_cmdline,mode); - strcatb(buf_cmdline,"magic="); - strcat(buf_cmdline,(char *)utoa(magic)); - } - load_initrds(); - close(x->fd); - boot_kernel(); -} - -u32 root_dev; -u32 vid_mode; -u32 topmem; -u32 base_himem; -const char* kernel_name = "bzImage"; -const char* initrd_name; -static char* iso; - -int main(int argc, char *argv[]) -{ - ((u16*) &base_himem)[1] |= (_1m+_64k)>>16; // base_himem = _1m+_64k - - if (argc < 2) { - try_default_args(); -dousage: - die("Usage: tazboot [[@commands]|" -#ifdef WITH_XMM_ALLOC -"[-f]" -#endif -"[-b base_himem][kernel=] [initrd=[,...]] [bootfrom=] ...]\n\n\ -Defaults: tazboot kernel=bzImage auto\n\n\ -Examples for tazboot.cmd:\n\n\ - bootfrom=\\isos\\slitaz-4.0.iso\n\ - kernel=boot/bzImage\n\ - initrd=boot/rootfs4.gz,boot/rootfs3.gz,boot/rootfs2.gz,boot/rootfs1.gz,\\slitaz\\extrafs.gz\n\ - root=/dev/null vga=normal autologin\n\n\ - kernel=\\slitaz\\elks\n\ - root=/dev/bda1 ro\n"); - } - bootiso(argv + 1); // iso ? parsing is /init.exe stuff ! - for (int i=0;;) { - char *s; - next: argv++; - s=*argv; - i++; - if (!s) { - if (isoreset(iso) != -1) { - s = (char *) initrd_name; - if (isoopen((char *) kernel_name) != -1) { - isokernel(); - } - if (s) { - do { - char *p, c; - for (p = s; *s && *s != ','; s++); - c = *s; *s = 0; - if (isoopen(p) != -1) { - addinitrd(); - } - *s = c; - if (c) s++; - } while (*s); - load_initrds(); - } - } - else { - load_kernel(); - load_initrd(); - } - boot_kernel(); - } -#ifdef USE_ARGSTR -#ifdef WITH_XMM_ALLOC - if ((*(u16 *)s|0x2002) == 0x662F) { // -F /f - skip_alloc--; - goto next; - } -#endif - if (argstr(s,"kernel/image|initrd|bootfrom/iso",&kernel_name) != -1); - else if (argnum(s,"root|vga|mem/-e|-b",&root_dev) != -1); - else if(i == 1 && fileexist(s) != -1) { - kernel_name = s; - } - else strcatb(buf_cmdline,*argv); // FIXME mem ? - } -#else - if (strhead(s,"initrd=") != -1) { - s += 7; - initrd_name = s; - } - else if (strhead(s,"bootfrom=") != -1) { - s += 9; - goto set_iso; - } - else if (strhead(s,"iso=") != -1) { - s += 4; - set_iso: - iso = s; - } - else if (strhead(s,"image=") != -1) { - goto set_kernel; - } - else if(strhead(s,"vga=") != -1) { - *(u16*)&vid_mode = (u16)strtol(s+4); // support normal, extended & ask - } - else if (strhead(s,"kernel=") != -1) { - s++; - set_kernel: - s += 6; - set_kernelz: - kernel_name = s; - } - else switch (*(u16 *)s|0x2002) { -#ifdef WITH_XMM_ALLOC - case 0x662F: // -F /f - skip_alloc--; - goto next; -#endif - case 0x652F: // -E /e - s=*++argv; - goto set_topmem; - case 0x622F: // -B /b - argv++; - ((u16 *)&base_himem)[1] = (u16)(strtol(*argv)>>16); - goto next; - default: - if(i == 1 && fileexist(s) != -1) { - goto set_kernelz; - } - else { - strcatb(buf_cmdline,*argv); - if(strhead(s,"root=") != -1) { - *(u16*)&root_dev = (u16)strtol(s+5); - } - if(strhead(s,"mem=") != -1) { - s += 4; - set_topmem: - ((u16 *)&topmem)[1] = (u16)(strtol(s)>>16); - } - }} - } -#endif -} diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/VCPI.ASM --- a/linld/stuff/src/VCPI.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/VCPI.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -1,421 +1,424 @@ -;*************************************************************** -;****** This file is distributed under GPL -;*************************************************************** -;VDPI init: -;Call char* prepare_vcpi(void *pagebuf) first to -;initialize paging tables needed for vm86. -;pagebuf needs to be 8k+4 bytes. Returns ptr to 1st unused byte. -;Then call int get_vcpi_interface(). Returns 1 if ok, 0 if bad. -; -;VCPI use: -;u32* malloc_vcpi(u32 size) - source in HIMEM.CPP -; Returns ptr to mallocated zero-terminated list of 4k page addrs -; Addresses are sorted in ascending order -; Never fails (will die if not enough mem) -;void read2vcpi(int fd, u32* vp, u32 size, -;void* xfer_buf, u16 xfer_size) - source in HIMEM.CPP -; Reads opened fd data into malloc_vcpi'ed memory -; Dies if file isn't exactly 'size' bytes long -; Needs intermediate buffer of exactly Nx4k bytes -;void memcpy_vcpi(u32 dstofs,u16 srcseg,u32 srcofs) -; copies 4k from conventional memory to VCPI -;void _vm2rm() -; switches you from vm86 to plain real mode - - - ideal - %PAGESIZE 1000 - %crefref - %noincl - %nomacs - p386 - -;****** Stuff for declaring descriptors -struc descr -limit dw ? -base0 dw ? -base16 db ? -type db ? -limit16 db ? -base24 db ? -ends descr -macro descriptor name,typ,plevel,present,limit,gran,base - ;;name descr - name descr -endm -; decriptor types (bit0..4 of descr.type ) -tss386_avail = 09h -data_seg = 00010000b ; data segment - expand_down = 00000100b ; =1 limit counts down from base - writable = 00000010b ; =1 if write access allowed to data segment -code_seg = 00011000b ; code segment - conforming = 00000100b ; =1 code can be accesses and executed at any PL - readable = 00000010b ; =1 if code also can be read (cannot be ovwritten) -; privilege levels (bit5..6 of descr.type ) -priv0 = 00000000b -priv1 = 00100000b -priv2 = 01000000b -priv3 = 01100000b -; segment present bit (bit7 of descr.type ) -is_present = 10000000b -not_present = 00000000b -;definition of granularity ( bits6..7 in descr.limit16 ) -gran_byte = 00000000b -gran_page = 10000000b ; 4k granularity -use_16 = 00000000b -use_32 = 01000000b - -;****** rm32,imm16 helpers -macro addzx_e rm,i - db 66h - add rm,i - dw 0 -endm - - - group DGROUP _TEXT,_BSS - assume cs:DGROUP,ds:DGROUP - - segment _BSS byte public use16 'BSS' - -tss dd ?,? ;enough, we'll never use it anyway - - ends _BSS - - segment _TEXT byte public use16 'CODE' - -label gdt byte -gdt_null descr ;0000 -gdt_vcpi descr ;0008 -gdt_vcpi2 descr ;0010 -gdt_vcpi3 descr ;0018 -descriptor gdt_abs ,(data_seg+writable),priv0,is_present,0fffffh,(gran_page+use_32),0 -;Note: code/data segs must be flagged use16 (i.e. use ip/sp, not eip/esp) -;Note: base addrs will be fixed up in prepare_vcpi() -descriptor gdt_code,(code_seg+readable),priv0,is_present,0fffffh,(gran_page+use_16),0 +;*************************************************************** +;****** This file is distributed under GPL +;*************************************************************** +;VDPI init: +;Call char* prepare_vcpi(void *pagebuf) first to +;initialize paging tables needed for vm86. +;pagebuf needs to be 8k+4 bytes. Returns ptr to 1st unused byte. +;Then call int get_vcpi_interface(). Returns 1 if ok, 0 if bad. +; +;VCPI use: +;u32* malloc_vcpi(u32 size) - source in HIMEM.CPP +; Returns ptr to mallocated zero-terminated list of 4k page addrs +; Addresses are sorted in ascending order +; Never fails (will die if not enough mem) +;void read2vcpi(int fd, u32* vp, u32 size, +;void* xfer_buf, u16 xfer_size) - source in HIMEM.CPP +; Reads opened fd data into malloc_vcpi'ed memory +; Dies if file isn't exactly 'size' bytes long +; Needs intermediate buffer of exactly Nx4k bytes +;void memcpy_vcpi(u32 dstofs,u16 srcseg,u32 srcofs) +; copies 4k from conventional memory to VCPI +;void _vm2rm() +; switches you from vm86 to plain real mode + + + ideal + %PAGESIZE 1000 + %crefref + %noincl + %nomacs + p386 + +;****** Stuff for declaring descriptors +struc descr +limit dw ? +base0 dw ? +base16 db ? +type db ? +limit16 db ? +base24 db ? +ends descr +macro descriptor name,typ,plevel,present,limit,gran,base + ;;name descr + name descr +endm +; decriptor types (bit0..4 of descr.type ) +tss386_avail = 09h +data_seg = 00010000b ; data segment + expand_down = 00000100b ; =1 limit counts down from base + writable = 00000010b ; =1 if write access allowed to data segment +code_seg = 00011000b ; code segment + conforming = 00000100b ; =1 code can be accesses and executed at any PL + readable = 00000010b ; =1 if code also can be read (cannot be ovwritten) +; privilege levels (bit5..6 of descr.type ) +priv0 = 00000000b +priv1 = 00100000b +priv2 = 01000000b +priv3 = 01100000b +; segment present bit (bit7 of descr.type ) +is_present = 10000000b +not_present = 00000000b +;definition of granularity ( bits6..7 in descr.limit16 ) +gran_byte = 00000000b +gran_page = 10000000b ; 4k granularity +use_16 = 00000000b +use_32 = 01000000b + +;****** rm32,imm16 helper +macro movzx_e rm,i + db 66h + mov rm,i + dw 0 +endm + +macro pushd v + db 66h + push v +endm + + group DGROUP _TEXT + assume cs:DGROUP,ds:DGROUP + + segment _TEXT byte public use16 'CODE' + +;*************************************************************** +;int get_vcpi_interface(); +;****** Return: Z - page mapping for low 640k is 1:1 +;****** NZ - otherwise (it's bad) +;****** Uses: Flags +;*************************************************************** + ;global _get_vcpi_interface:near + proc _get_vcpi_interface near + + ;push si di + +; Get and save VCPI pm interface + ;mov si,offset gdt_vcpi ;DS:DI => 3 GDT entries for VCPI + ;mov di,[si+page0_ofs-gdt_vcpi] ;ES:DI => page0 + ;push ds + ;pop es + ;push di + ;mov ax,0DE01h ;get vcpi pm interface + int 67h + xchg [si+vcpi_pm_entry-gdt_vcpi],ebx ; bx=((640*1024) shr 12) + ;xor bx,bx + +; Check that mapping for low 640k is 1:1 + pop si ; [page0_ofs] + ;cld + mov cx,bx +@@map_chk: + lodsd + shr eax,12 + add al,cl + cmp al,((640*1024) shr 12) + loope @@map_chk +; Return +@@bad: + ret + endp _get_vcpi_interface + + +;*************************************************************** +;char* prepare_vcpi(void *pagebuf); +;****** Return: AX=>first unused byte in pagebuf +;****** Uses: Flags +;*************************************************************** + global prepare_vcpi:near + proc prepare_vcpi near + +;Calculate pagedir/page0 addrs, initialize cr3 and pagedir[0] +; heap_top = prepare_vcpi(malloc_or_die(8*1024+4)); + + ;mov edx,cs + ;shl edx,4 ;edx = linear addr of CS + mov si,offset gdt_vcpi +; Fix up base of some gdt descriptors +; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity! +; Do NOT replace with mov! + mov ebx,10000h-28h + add [dword si+sw2pm_addr-gdt_vcpi],edx + add [dword si+sw2pm_idtr_ptr-gdt_vcpi],edx +@@fixup: + add [dword bx+si+(gdt_code.base0)-gdt_vcpi+28h],edx + add bx,8 + js @@fixup + mov bh,10h + extrn _heap_top:word + movzx eax,[_heap_top] + add eax,edx + and ax,0f000h ;eax = 4k aligned linear addr of pagebuf + add eax,ebx ;eax=page0 linear addr + add [si+sw2pm_cr3-gdt_vcpi],eax + mov edi,eax + sub edi,edx + mov al,3 ;add present+writable bits + mov [bx+di],eax ;stuff it into pagedir[0] + push ds + pop es ;es:di->page0,es:di+1000h->pagedir + ;page directory will use only one entry (4 bytes): + ;cr3 => pagedir => page0 => ######## + ; (1 entry) (1024 => # 4M # + ; entries)=> # page # + ; => ######## +; Return + lea ax,[bx+di+4] + mov [_heap_top],ax + ;ret + push di + mov ax,0DE01h ;get vcpi pm interface + jmp _get_vcpi_interface + + endp prepare_vcpi + + org $-40 +tss dd ?,? ;enough, we'll never use it anyway +label gdt byte +gdt_null descr ;0000 +gdt_vcpi descr ;0008 +gdt_vcpi2 descr ;0010 +gdt_vcpi3 descr ;0018 + org $-8 + global gdt_memcpy:descr +gdt_memcpy descr +descriptor gdt_abs ,(data_seg+writable),priv0,is_present,0fffffh,(gran_page+use_32),0 +;Note: code/data segs must be flagged use16 (i.e. use ip/sp, not eip/esp) +;Note: base addrs will be fixed up in prepare_vcpi() +descriptor gdt_code,(code_seg+readable),priv0,is_present,0fffffh,(gran_page+use_16),0 global gdt_data:descr -descriptor gdt_data,(data_seg+writable),priv0,is_present,0fffffh,(gran_page+use_16),0 -descriptor gdt_tss ,tss386_avail ,priv0,is_present,0ffh ,gran_byte , -SEL_VCPI = (gdt_vcpi - gdt_null) -SEL_TSS = (gdt_tss - gdt_null) -SEL_ABS = (gdt_abs - gdt_null) -SEL_CODE = (gdt_code - gdt_null) -SEL_DATA = (gdt_data - gdt_null) - -label gdtr pword -gdt_lim dw 0ffffh -gdt_base dw offset gdt,0 - -;Note: layout dictated by vcpi api, don't rearrange! -label sw2pm_params byte -;Note: base addrs will be fixed up in prepare_vcpi() -label pagedir_laddr dword -sw2pm_cr3 dd 1000h -sw2pm_gdtr_ptr dw offset gdtr,0 -sw2pm_idtr_ptr dw offset idtr,0 -sw2pm_ldtr dw 0 ;we don't need it -sw2pm_tr dw SEL_TSS ;vcpi thinks we need it... can't set to 0 -sw2pm_jumpaddr dd 0 - dw SEL_CODE - -vcpi_pm_entry dd 0 - dw SEL_VCPI - -label idtr pword -idt_lim dw 03ffh ;we won't enable ints, -idt_base dd 0 ; so let's leave it the same as for rm - - -;*************************************************************** -;char* prepare_vcpi(void *pagebuf); -;****** Return: AX=>first unused byte in pagebuf -;****** Uses: Flags -;*************************************************************** - global prepare_vcpi:near - proc prepare_vcpi near - - ;pop ax - ;pop bx ;pgbuf - ;push bx - ;push ax - -;Calculate pagedir/page0 addrs, initialize cr3 and pagedir[0] -; heap_top = prepare_vcpi(malloc_or_die(8*1024+4)); - - mov edx,cs - shl edx,4 ;edx = linear addr of CS - mov si,offset gdt_vcpi -; Fix up base of some gdt descriptors -; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity! -; Do NOT replace with mov! - mov ebx,10000h-28h - add [dword bx+si+sw2pm_idtr_ptr-gdt_vcpi+28h],edx -@@fixup: - add [dword bx+si+(gdt_code.base0)-gdt_vcpi+28h],edx - add bx,8 - js @@fixup - mov bh,10h - extrn _heap_top:word - movzx eax,[_heap_top] - add eax,edx - and ax,0f000h ;eax = 4k aligned linear addr of pagebuf - add eax,ebx ;eax=page0 linear addr - add [si+sw2pm_cr3-gdt_vcpi],eax - mov edi,eax - sub edi,edx - mov al,3 ;add present+writable bits - mov [bx+di],eax ;stuff it into pagedir[0] - push ds - pop es ;es:di->page0,es:di+1000h->pagedir - ;page directory will use only one entry (4 bytes): - ;cr3 => pagedir => page0 => ######## - ; (1 entry) (1024 => # 4M # - ; entries)=> # page # - ; => ######## -; Return - lea ax,[bx+di+4] - mov [_heap_top],ax - ;ret - - endp prepare_vcpi - - -;*************************************************************** -;int get_vcpi_interface(); -;****** Return: Z - page mapping for low 640k is 1:1 -;****** NZ - otherwise (it's bad) -;****** Uses: Flags -;*************************************************************** - ;global _get_vcpi_interface:near - proc _get_vcpi_interface near - - ;push si di - -; Get and save VCPI pm interface - ;mov si,offset gdt_vcpi ;DS:DI => 3 GDT entries for VCPI - ;mov di,[si+page0_ofs-gdt_vcpi] ;ES:DI => page0 - ;push ds - ;pop es - push di - mov ax,0DE01h ;get vcpi pm interface - int 67h - xchg [vcpi_pm_entry],ebx ;clear ebx - ;xor bx,bx - -; Check that mapping for low 640k is 1:1 - pop si ; [page0_ofs] - ;cld -@@map_chk: - lodsd - shr eax,12 - cmp ax,bx - jne @@bad - inc bx - cmp al,((640*1024) shr 12)-1 - jne @@map_chk -; Return -@@bad: - ret - endp _get_vcpi_interface - - -;*************************************************************** -;void memcpy_vcpi(u32 dstofs,u16 srcseg,u32 srcofs); -;*************************************************************** -;****** Copies PAGE_SIZE bytes -;****** Uses: Flags -;*************************************************************** - global vcpi_pm_copy_routine:near - proc vcpi_pm_copy_routine near - - arg dstofs :dword, \ - srcseg :word, \ - srcofs :dword = PARAM_SIZE - -struc pm_regs -$$retaddr dw ? -$$edi dd ? -$$esi dd ? -$$ebp dd ? -$$esp dd ? -$$ebx dd ? -$$edx dd ? -$$ecx dd ? -$$eax dd ? -ends - -;*************************************************************** -;****** Helper: goes into 16bit pm and calls routine (addr on stk) -;*************************************************************** - mov bp,sp ; ss:bp => struct pm_regs - - xor ax,ax ; IRET stack for return to vm - push ax gs ; (9 dwords) - push ax fs ; - push ax ds ; - push ax es ; - push ax ss ; - push ebp ; esp - pushfd ; eflags: IF saved here - push ax cs ; - push ax ;\eip - push offset @@vm_ret ;/ - - ;;mov [saved_xx],xx ;use if your vcpi trashes bp/etc - - call switch_to_pm - -; Now we are in 16-bit protected mode - mov ax,SEL_DATA - mov ss,ax - ;;mov ds,ax - ;;mov es,ax - ;;mov fs,ax - ;;mov gs,ax - assume nothing - assume cs:DGROUP - - ;;mov xx,[saved_xx] ;use if your vcpi trashes bp/etc - lea sp,[bp-9*4] ;else we can do this trick with bp - -; Call the routine (bp points to params on stack if any) - mov bp,[word (pm_regs bp).$$ebp] ;ss:bp => params - call do_memcpy_vcpi - -; Ok, let's return to vm - mov ax,0DE0Ch ; maybe we need whole eax? - cli ; to be safe - clts ; - ;;push SEL_ABS ; vcpi wants ds=all_addrspace - ;;pop ds ; - call [pword cs:vcpi_pm_entry] -@@vm_ret: -; Now we are in vm86 mode. Sregs, esp, eflags (IF) restored from IRET stack - ret - -;*************************************************************** -switch_to_pm: - assume cs:DGROUP,ds:DGROUP - pop [word sw2pm_jumpaddr] - ;mov [word sw2pm_jumpaddr+2],0 - ;mov [word sw2pm_jumpaddr+4],SEL_CODE - mov esi,cs - shl esi,4 - addzx_e si, - mov ax,0DE0Ch ; vcpi: switch to pm - cli - int 67h - -;*************************************************************** -;****** Helper: This is where real copy is done -;*************************************************************** -label do_memcpy_vcpi near - -; Note: ss:bp => params -; Move data - mov al,SEL_ABS - mov ds,ax - mov es,ax - assume nothing - assume cs:DGROUP - - ; Set up target addr: - ; replace page mapping for page at 0 so - ; that it points to dstofs - mov eax,[dstofs] - mov al,03h ; writeable, present - call @@set_mapping - ;push eax ;X we'll need to restore mapping... - xor edi,edi ;es:edi => remapped page - - ; Set up source addr - mov esi,[srcofs] - - ; Do copying - xor ecx,ecx - mov ch,4096/256 - ;cld -;; cmp esi,edi -;; jae @@do_copy -;; add esi,ecx ;src +SEL_VCPI = (gdt_vcpi - gdt_null) +SEL_TSS = (gdt_tss - gdt_null) +SEL_ABS = (gdt_abs - gdt_null) +SEL_CODE = (gdt_code - gdt_null) +SEL_DATA = (gdt_data - gdt_null) + +label gdtr pword +gdt_lim dw 0ffffh +gdt_base dw offset gdt,0 + +;Note: layout dictated by vcpi api, don't rearrange! +label sw2pm_params byte +;Note: base addrs will be fixed up in prepare_vcpi() +label pagedir_laddr dword +sw2pm_cr3 dd 1000h +sw2pm_gdtr_ptr dw offset gdtr,0 +sw2pm_idtr_ptr dw offset idtr,0 +sw2pm_ldtr dw 0 ;we don't need it +sw2pm_tr dw SEL_TSS ;vcpi thinks we need it... can't set to 0 +sw2pm_jumpaddr dd 0 + dw SEL_CODE + +vcpi_pm_entry dd ((640*1024) shr 12) + dw SEL_VCPI + +label idtr pword +idt_lim dw 03ffh ;we won't enable ints, +idt_base dd 0 ; so let's leave it the same as for rm + +;*************************************************************** +switch_to_pm: + assume cs:DGROUP,ds:DGROUP + mov edx,esi + movzx_e si, + org $-4 +sw2pm_addr dd ? + pop [word sw2pm_jumpaddr] ; CS:EIP of protected mode entry-point + ;mov [word sw2pm_jumpaddr+2],0 + ;mov [word sw2pm_jumpaddr+4],SEL_CODE + mov ax,0DE0Ch ; vcpi: switch to pm + cli ; load GDTR LDTR TR need 16 bytes in SS:ESP + int 67h ; EAX, ESI, DS, ES, FS, GS destroyed + + +;*************************************************************** +;void memcpy_vcpi(u32 dstofs,u16 srcseg,u32 srcofs); +;*************************************************************** +;****** Copies PAGE_SIZE bytes +;****** Uses: Flags +;*************************************************************** + global vcpi_pm_copy_routine:near + proc vcpi_pm_copy_routine near + +struc pm_regs +$$retaddr dw ? +$$edi dd ? +$$esi dd ? +$$ebp dd ? +$$esp dd ? +$$ebx dd ? +$$edx dd ? +$$ecx dd ? +$$eax dd ? +ends + +;*************************************************************** +;****** Helper: goes into 16bit pm and calls routine (addr on stk) +;*************************************************************** + mov bp,sp ; ss:bp => struct pm_regs + + pushd gs ; IRET stack for return to vm + pushd fs ; (9 dwords) + pushd ds ; + pushd es ; + pushd ss ; + push ebp ; esp + pushfd ; eflags: IF saved here + pushd cs ; + push 0 ;\eip + push offset @@vm_ret ;/ + + ;;mov [saved_xx],xx ;use if your vcpi trashes bp/etc + + call switch_to_pm ; EAX, EDX/ESI, DS, ES, FS, GS destroyed + assume nothing + assume cs:DGROUP + +; Now we are in 16-bit protected mode + ;push SEL_DATA + ;pop ss + mov ax,SEL_DATA + mov ss,ax + ;;mov ds,ax + ;;mov es,ax + ;;mov fs,ax + ;;mov gs,ax + + ;;mov xx,[saved_xx] ;use if your vcpi trashes bp/etc + lea sp,[bp-9*4] ;else we can do this trick with bp + +; Call the routine (bp points to params on stack if any) + call do_memcpy_vcpi + +; Ok, let's return to vm + mov ax,0DE0Ch ; maybe we need whole eax? + cli ; to be safe + clts ; + ;;push SEL_ABS ; vcpi wants ds=all_addrspace + ;;pop ds ; (done by do_memcpy_vcpi) + call [pword cs:vcpi_pm_entry] +@@vm_ret: +; Now we are in vm86 mode. Sregs, esp, eflags (IF) restored from IRET stack + ret + +;*************************************************************** + +;*************************************************************** +;****** Helper: This is where real copy is done +;*************************************************************** +label do_memcpy_vcpi near + +; Note: ss:bp => params +; Move data + push SEL_ABS + pop ds + push ds + pop es + assume nothing + assume cs:DGROUP + + ; Set up target addr: + ; replace page mapping for page at 0 so + ; that it points to dstofs + xchg eax,edi + mov al,03h ; writeable, present + call @@set_mapping + ;push eax ;X we'll need to restore mapping... + xor edi,edi ;es:edi => remapped page + + ; Set up source addr + mov esi,edx + + ; Do copying +; xor ecx,ecx +; mov ch,4096/256 + ;cld +;; cmp esi,edi +;; jae @@do_copy +;; add esi,ecx ;src=64k - mov ss,ax ; or you may get limit violations - mov ds,ax ; later in rm - ;mov es,ax ; (actually I prefer 4gig limits :-) - ;mov fs,ax ; - ;mov gs,ax ; - -; Black magic here - mov eax,cr0 - and eax,7ffffffeh ; clear PG,P bits - mov cr0,eax ; look mommy, we're in rm now! - mov cr3,eax ; flush TLB cache - -; Now we are in rm, but not yet: have to restore sregs: - lss sp,[dword sssp]; SS - pop ds ; DS - pop si - retf ; CS - - endp _vm2rm - - ends _TEXT - - end - -;###### END OF FILE ############################################ + ret + + endp vcpi_pm_copy_routine + + +;*************************************************************** +;void _vm2rm(); +;*************************************************************** +;****** Uses: Flags +;*************************************************************** + global _vm2rm:near + proc _vm2rm near + + assume cs:DGROUP,ds:DGROUP + extrn sssp:dword + ifdef NO386 + p8086 + extrn _vcpi:byte + mov bx,offset sssp + test [_vcpi],bh + jz vcpi_ret + else + p386 + smsw ax ;SMSW cannot be trapped! :-) + and al,1 ;MSW_PE + jz vcpi_ret + mov bx,offset sssp + endif + p386 + pop ax + push cs ;* + push ax + push ds + mov [bx],sp + ;mov [bx+2],ss + + call switch_to_pm ; EAX, EDX/ESI, DS, ES, FS, GS destroyed + assume nothing + assume cs:DGROUP + +; Now we are in 16-bit protected mode + ;mov ax,SEL_DATA ; load data sregs with limit >=64k + ;mov ss,ax ; or you may get limit violations + ;mov ds,ax ; later in rm + ;mov es,ax ; (actually I prefer 4gig limits :-) + ;mov fs,ax ; + ;mov gs,ax ; + +; Black magic here + mov eax,cr0 + and eax,7ffffffeh ; clear PG,P bits + mov cr0,eax ; look mommy, we're in rm now! + mov cr3,eax ; flush TLB cache + +; Now we are in rm, but not yet: have to restore sregs: + lss sp,[cs:bx] ; SS + pop ds ; DS + retf ; CS + + endp _vm2rm + + ends _TEXT + + end + +;###### END OF FILE ############################################ diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/XMM.ASM --- a/linld/stuff/src/XMM.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/XMM.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -12,15 +12,9 @@ p386 endif - group DGROUP _TEXT,_BSS + group DGROUP _TEXT assume cs:DGROUP,ds:DGROUP - segment _BSS byte public use16 'BSS' - -xmm_handler dd ? - - ends _BSS - segment _TEXT byte public use16 'CODE' ;*************************************************************** @@ -42,47 +36,30 @@ ;*************************************************************** proc xmm_driver near - push si - mov si,offset xmm_handler - ifndef NO386 - cmp [dword si],0 - jne @@gotit push ax ; save cmd mov ax,4300h ; installation check in al - else - push ax ; save cmd - lodsw - or ax,[word si] - jne @@gotit - mov ah,43h ; installation check in al - endif - int 2fh - mov bx,offset xmm_fail - push ds + mov bx,offset @@xmm_fail + push cs pop es cmp al,80h jne @@err mov ax,4310h ; get driver address in es:bx int 2fh @@err: - ifndef NO386 pop ax ; restore cmd - mov [si],bx - mov [si+2],es -@@gotit: - call [dword si] ; far ptr [si] - else - mov [si-2],bx - mov [si],es -@@gotit: - pop ax ; restore cmd - call [dword si-2] ; far ptr [si-2] - endif + + push cs ; call far + call @@jmp_esbx dec ax ; Z=1=OK - pop si ret -xmm_fail: + +@@jmp_esbx: + push es ; \ + push bx ; > jmp far es:bx + retf ; / + +@@xmm_fail: xor ax,ax cwd retf diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/_BEG.ASM --- a/linld/stuff/src/_BEG.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/_BEG.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -15,7 +15,7 @@ ends _TEXT segment _DATA byte public use16 'DATA' - global _data_start:byte + ;global _data_start:byte label _data_start byte ifndef NO386 msg_badcpu db "I need 386+ CPU in real mode w/o paging" @@ -24,18 +24,18 @@ global _vcpi:byte _vcpi db 0 endif - ifdef EXTRA -tazboot_cmd db "tazboot.cmd",0 - endif ends _DATA segment _BSS byte public use16 'BSS' - global _bss_start:byte + ifdef BIG_CMDLINE + extrn _big_cmdline:byte + db 254 dup(?) + endif + ;global _bss_start:byte label _bss_start byte global stktop:byte - ifndef ISOHOOK ifdef NO386 global _cpu386:byte _cpu386 db ? @@ -43,7 +43,6 @@ endif global _cpu_features:dword _cpu_features dd ? - endif ends _BSS segment _TEXT byte public use16 'CODE' @@ -53,21 +52,23 @@ endm org 100h - global _text_start:byte + ;global _text_start:byte label _text_start byte ;*************************************************************** ; clear bss ;*************************************************************** mov sp,offset stktop + mov bx, 0F000h ; cld ; cli & empty string + org $-4-2 + global _himem_buf:dword +_himem_buf dd ? + global _buf_cmdline:word +_buf_cmdline dw ? ; 128 bytes, must start with 00 mov si,offset _bss_start - mov bx, 0F000h ; cld ; cli & empty string clearbss: mov [si],bl ; clear bss + heap inc si - ifdef ISOHOOK - cmp si,bx - endif jne clearbss ;*************************************************************** @@ -87,6 +88,10 @@ js endcpu86 ;it is not a 386+, try ELKS & co endif p386 + mov edx,cs + shl edx,4 ; edx for prepare_vcpi + extrn gdt_base_memcpy:word ; gdt_base for memcpy32 + add [dword gdt_base_memcpy],edx ; Check for vm smsw ax ;SMSW cannot be trapped! :-) and al,1 ;MSW_PE @@ -102,32 +107,11 @@ p8086 extrn die:near godie: -no_vcpi: call near die else jmp endcpu86 endif - ifdef ISOHOOK - global iso_close_hack -iso_close_hack dw dosbx - global iso_open_hack - extrn __open:near -iso_open_hack dw __open - global iso_read_hack - extrn dos:near -iso_read_hack dw dos - global iso_lseek_hack - extrn dosbx:near -iso_lseek_hack dw dosbx - global _cpu_features:dword -_cpu_features dd ? ; default _cpu_features+3=1Fh/8Eh (bit5=0, not 64bits) - org $-4 - ifdef NO386 - global _cpu386:byte -_cpu386 db 0 - endif - endif ;*************************************************************** ; checks for vcpi @@ -138,38 +122,13 @@ ; Check whether it is safe to call 67h (we trust only known EMM managers) push si pop ds - mov ds,[word 67h*4+2] - cmp [dword si+10+4],'0XXX' - jne skip - ;mov eax,'XMME' - ;xor eax,[dword si+10] - ; QMME also works (as told by ) - ;shl eax,8 - mov ax,'ME' - xor ax,[word si+10] -skip: + mov ax,[word 67h*4] + or ax,[word 67h*4+2] pop ds - jne no_vcpi - -; Check emm manager status and version - ;mov ah,40h ; get status - ;int 67h - ;inc ax - ;js no_vcpi - mov ah,46h ; get version - int 67h - cmp ax,40h ; version must be >= 4.0 - jl no_vcpi ; btw check ax.15 -; Check vcpi manager status - ;;mov ax,5A01h ; ALLOCATE RAW PAGES - ;;mov bx,4 - ;;int 67h - ;;inc ax - ;;js no_vcpi - ;;push dx ;$ save handle + je no_vcpi mov ax,0DE00h ; check for vcpi present int 67h - test ah,ah + or ah,ah jnz no_vcpi is386vcpi: extrn prepare_vcpi:near @@ -186,13 +145,14 @@ extrn _vcpi:byte dec [byte _vcpi] endif +no_vcpi: endcpu386: pushfd pop dx pop ax mov bl,al - xor al,20h ; toggle CPUID feature bit 21 - push ax + xor al,20h ; toggle CPUID feature bit 21 (=> pentium+) + push ax ; (toggle AC: bit 18 => 486+) push dx popfd pushfd @@ -202,12 +162,11 @@ je @@no_cpuid ; CPUID feature bit changed ? mov eax,80000001h ; Extended Processor Info and Feature Bits cpuid + mov dl,-1 ; set 386 flag (assume cpuid => fpu:bit0=1 ?) ifdef NO386 - mov dl,-1 ; set 386 flag db 66h ; mov [_cpu_features],edx @@no_cpuid: mov [word _cpu_features],dx ; dl != 0 -no_vcpi: else mov [_cpu_features],edx @@no_cpuid: @@ -223,27 +182,30 @@ global _heap_top org $-2 _heap_top dw ? - ;xor ax,ax - ;push ax ; envp (already cleared) - ;mov [word di],ax ; argv[0] = 0 (idem) mov si,80h - lodsb - cmp al,7Eh - jbe alok - mov al,7Eh -alok: + ifdef BIG_CMDLINE + mov bx,offset _big_cmdline + cmp [byte si],2 + jnb @@user_args + call @set_cmdline$qpxzc +@@user_args: + endif + lodsb ; size 0..127 cbw + ifdef BIG_CMDLINE + inc ax + jnz short_cmdline + mov si,bx + lodsb ; size 0..254 +short_cmdline: + dec ax + endif xchg ax,bx mov [bx+si],bh ; set eos + ;xor dx,dx + ;push dx ; envp (already cleared) + ;mov [word di],dx ; argv[0] = 0 (idem) argbuild: - ifdef DEBUG - p386 - pusha - mov bx,si - extrn puts:near - call puts - popa - endif mov bx,2 ; argc * 2 argeos: mov cx,1 ; look for a start of string @@ -290,15 +252,15 @@ read_cmdline: mov dx,di push dx - push ax xchg ax,bx extrn @read$cxdxbx:near ; read(fd=bx,buffer=dx,size=cx) call near @read$cxdxbx - pop bx ; fd for close pop si ; si=buffer=argv add di,ax + ifndef NO_CLOSE extrn close:near call near close + endif jmp argbuild argend: endif @@ -311,7 +273,6 @@ ;*************************************************************** - extrn _head_top:word ifdef USE_ARGSTR ;*************************************************************** ;_fastcall void set_cmdline(bx:const char *filename); @@ -328,25 +289,6 @@ endp @set_cmdline$qpxzc endif -;*************************************************************** -;void try_default_args(); -;*************************************************************** - - ifdef EXTRA - global _try_default_args:near - proc _try_default_args near - - mov bx,offset tazboot_cmd - extrn @open$qpxzc:near - call @open$qpxzc - jc @ret - mov ch,15 ; cx<4096 - mov di,[_heap_top] - jmp read_cmdline ; read_cmdline(ax,di,cx) - - endp _try_default_args - endif - ifdef NO386 ;*************************************************************** ;u16 topseg(); diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/_END.ASM --- a/linld/stuff/src/_END.ASM Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/_END.ASM Fri Jan 08 20:15:35 2021 +0000 @@ -1,35 +1,35 @@ -;*************************************************************** -;****** This file is distributed under GPL -;*************************************************************** - ideal - %crefref - %noincl - %nomacs - p386 - - segment _TEXT byte public use16 'CODE' - global _text_end:byte - label _text_end byte - ends _TEXT - - segment _DATA byte public use16 'DATA' - global _data_end:byte - label _data_end byte - ends _DATA - - segment _BSS word public use16 'BSS' - ifdef EXTRA - global _version_string:byte - label _version_string byte - endif -STACK_SIZE = 1024 - db STACK_SIZE dup(?) - global stktop:byte - label stktop byte - global _bss_end:byte - label _bss_end byte - ends _BSS - - end - -;###### END OF FILE ############################################ +;*************************************************************** +;****** This file is distributed under GPL +;*************************************************************** + ideal + %crefref + %noincl + %nomacs + p386 + + segment _TEXT byte public use16 'CODE' + ;global _text_end:byte + label _text_end byte + ends _TEXT + + segment _DATA byte public use16 'DATA' + ;global _data_end:byte + label _data_end byte + ifdef BIG_CMDLINE + global _big_cmdline:byte +_big_cmdline db 0 + endif + ends _DATA + + segment _BSS word public use16 'BSS' +STACK_SIZE = 256 + db STACK_SIZE dup(?) + global stktop:byte + label stktop byte + global _bss_end:byte + label _bss_end byte + ends _BSS + + end + +;###### END OF FILE ############################################ diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/_ISOBEG.ASM --- a/linld/stuff/src/_ISOBEG.ASM Wed Dec 16 17:23:49 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -;*************************************************************** -;****** This file is distributed under GPL -;*************************************************************** - ideal - %PAGESIZE 1000 - %crefref - %noincl - %nomacs - p8086 - - group DGROUP _TEXT,_DATA,_BSS - assume cs:DGROUP,ds:DGROUP - - segment _TEXT byte public use16 'CODE' - ends _TEXT - - segment _DATA byte public use16 'DATA' - global _data_start:byte - label _data_start byte - ends _DATA - - segment _BSS byte public use16 'BSS' - global _bss_start:byte - label _bss_start byte - ends _BSS - - segment _TEXT byte public use16 'CODE' - - org 100h - global _text_start:byte - label _text_start byte - - extrn _isostate - dw _isostate - - ends _TEXT - - - end _text_start - -;###### END OF FILE ############################################ diff -r 9c5316bc7e8e -r a946c1651082 linld/stuff/src/pipehole.awk --- a/linld/stuff/src/pipehole.awk Wed Dec 16 17:23:49 2020 +0000 +++ b/linld/stuff/src/pipehole.awk Fri Jan 08 20:15:35 2021 +0000 @@ -8,16 +8,6 @@ if (/^ \.386p$/) is386=1 if (file == "" && /debug S/) { file=$3; gsub(/\"/,"",file) } if (/debug S/) print " %PAGESIZE 1000" - if (file == "tazboot.cpp") { - if (/add si,2/) $0=" lodsw ; " $0 - if (/add si,4/) { print " lodsw"; $0=" lodsw ; " $0 } - if (/add di,2/) $0=" scasw ; " $0 - if (/int argc/) istazboot=1 - if (istazboot == 1) { - if (/push.*i$/) $0="; " $0 - if (/word ptr/) { istazboot=0; $0="; " $0 } - } - } # file == "tazboot.cpp" if (file == "linld.cpp") { if (/add si,2/) $0=" lodsw ; " $0 if (/add di,2/) $0=" scasw ; " $0 @@ -53,14 +43,19 @@ } if (/buf_cmdline\+1/) { islinld=5 - print " mov bx,offset DGROUP:buf_cmdline+1" - sub(/offset DGROUP:buf_cmdline\+1/,"bx") + print " mov bx,offset DGROUP:_buf_cmdline+1" + sub(/offset DGROUP:_buf_cmdline\+1/,"bx") } if (islinld==5) { - if (/bx,offset DGROUP:buf_cmdline/) $0=" dec bx" + if (/bx,offset DGROUP:_buf_cmdline/) $0=" dec bx" if (/ax,word ptr/) next if (/call/) islinld=0 } + if (/bx,word ptr DGROUP:_cmdstr\+6/) next + if (/_cmdstr\+6,0/) { + print " mov bx,word ptr [di+6]" + $0=" or bx,bx" + } } # file == "linld.cpp" if (file == "himem.cpp") { if (/sp,bp/ || /pop bp/) next @@ -68,20 +63,17 @@ if (ishimem == 1 && is386 == 0) { if (/si\+8\]$/ || /si\+4\]$/ || /si\+16\]$/) next if (/si\+6\]$/ || /si\+2\]$/ || /si\+14\]$/) sub(/mov dx,/,"les dx,d") - if (/si\+12\],ax/ || /si\+16\],ax/ || /DGROUP:buf\+2,ax/) sub(/,ax/,",es") - if (/dx,dword ptr \[si\+14\]/ || /DGROUP:buf,dx/) sub(/dx/,"ax") + if (/si\+12\],ax/ || /si\+16\],ax/ || /DGROUP:_himem_buf\+2,ax/) sub(/,ax/,",es") + if (/dx,dword ptr \[si\+14\]/ || /DGROUP:_himem_buf,dx/) sub(/dx/,"ax") } if (ishimem == 1) { if (/do \{/) ishimem=2 if (/bx,si/ || /push bp/ || /bp,sp/ || /push di/ || /push si/) next - if (/sp,2/) next - if (/bp\+4/) { - $0=" xchg ax,si" - } + if (/sp,2/ || /bp\+4/) next } if (ishimem == 2) { if (/movzx/) print " cwde" - if (/bp-2/ || /di,ax/ || /bx,di/) next + if (/bp-2/ || /di,ax/ || /bx,di/ || /bx,si/) next if (/storepage.bufv/) { print " inc ax" print " push ax" @@ -89,6 +81,14 @@ if (/buf \+= size;/) { print " pop ax" } + if (/i\+12/) ishimem=20 + } + if (ishimem == 20) { + if (/stc/ || /loadfail/) next + if (/je/) { + print " extrn jmploadfailure" + $0=" jne short jmploadfailure" + } if (/endp/) ishimem=0 } if (/@memcpy_image\$qp11image_himem/) next @@ -99,25 +99,33 @@ cpy_initrd=0 } if (ishimem == 3) { - if (/bx,di/ || /di,ax/ || /bx,32/) next + sub(/DGROUP:_imgs\+4,/,"[si+4],") + if (/bx,di/ || /di,ax/ || /bx,30/) next if (/mov bx,si/) { if (cpy_initrd==0) sub(/mov bx,si/, "call memcpy_image_kernel") else sub(/mov bx,si/, "call memcpy_image_initrd") cpy_initrd=1-cpy_initrd } - sub(/lea bx,\[si\+32\]/, "call memcpy_image_initrd") + sub(/lea bx,\[si\+30\]/, "call memcpy_image_initrd") } if (/m = pm2initrd/) ishimem=4 if (ishimem == 4) { - if (/si,32/ || /bx,di/ || /di,ax/) next - sub(/\[si/,"[si+32") + if (/si,30/ || /bx,di/ || /di,ax/) next + sub(/\[si/,"[si+30") sub(/mov bx,si/, "call memcpy_image_initrd") } } # file == "himem.cpp" if (file == "load.cpp") { + if (isload != 3 && isload != 6) { # LOAD.LST + if (/,si/ || /si,/ || /\[si/) sub(/si/,"di") + else if (/,di/ || /di,/ || /\[di/) sub(/di/,"si") + } + if (/moverm\(/) isload=16 + if (isload != 16 && /bx,si/) next + if (/@moverm/) isload=0 if (/readrm\(m, 0x200/) isload=15 if (isload == 15) { # LOAD.LST - if (/bx,di/) next + if (/bx,si/) next if (/call/) isload=0 } if (/load_image\(/) { @@ -125,10 +133,7 @@ else isload=14 } if (isload == 14) { # LOAD.LST - if (/call/) { - print " xchg ax,di" - $0=" jmp short load_imagez" - } + if (/call/) $0=" jmp short load_imagez" if (/ret/) isload=0 if (/pop/ || /ret/ || /push/) next } @@ -152,24 +157,11 @@ sub(/jb/,"ja") } sub(/_imgs\+65534/,"_imgs-2") - if (/m, _rm_size/) isload=10 - if (isload == 10) { # LOAD.LST - if (/^ je / || /bx,di/) next - if (/ptr @die\$qpxzc/) { - $0=" jne @die@" - isload=0 - } - } if (/setup_sects == 0/) isload=9 if (isload == 9) { # LOAD.LST sub(/,0/,",al") if (/jne/) isload=0 } - if (/fallback\)\[1\] == 0/) isload=8 - if (isload == 8) { # LOAD.LST - if (/load_image/) isload=0 - else next - } if (/cmd_line_ptr =/ && is386 == 0) isload=7 if (isload == 7) { # LOAD.LST if (/add/ || /xor/ || /extrn/ || /N_LXLSH@/ || /cl,4/ || /,ax/) next @@ -187,8 +179,8 @@ } } if (/pm_low == 0/) { - print " mov ax,si" print " push di" + print " push si" isload=6 } if (isload == 6) { # LOAD.LST @@ -203,21 +195,22 @@ print " movsw" print " movsw" print " movsw" + print " pop si" print "load_imagez:" next } } if (isload == 5) { # LOAD.LST sub(/ax,/,"bx,") - if (/strcatb/) isload=0 + if (/@puts\$qpxzc/) isload=0 if (/mov bx,ax/) next - sub(/,word ptr \[si\+29\]/,",cx") + sub(/,word ptr \[di\+29\]/,",cx") } - if (/_base_himem\+2/ && is386 == 0) isload=4 + if (/_cmdnum\+14/ && is386 == 0) isload=4 if (isload == 4) { # LOAD.LST - if (/_base_himem\+2/) next - if (/_base_himem$/) { - sub(/mov dx,/,"les dx,d") + if (/_cmdnum\+14/) next + if (/_cmdnum\+12$/) { + $0=" les dx,dword ptr [bx+12]" } sub(/,ax/,",es") if (/add ax,word ptr/) $0=" add ax,cx" @@ -226,10 +219,17 @@ sub(/cmp /,"mov cx,") } sub(/je/,"jcxz") + if (/@strcpy/) isload=0 if (/\+0x200/) isload=5 } - if (/void load_initrd\(\)/) isload=3 + if (/void load_initrd\(\)/) { isload=3; isload2=0 } if (isload == 3) { # LOAD.LST + if (/cmdstr\+4,0/) { + isload2++ + print " mov ax,word ptr DGROUP:_cmdstr+4" + $0=" or ax,ax" + } + if (isload2 && /DGROUP:_cmdstr\+4/) $0=";" $0 if (/je short @2@.*/) sub(/@2@.*/,"load_initrd_ret") if (/mov ax,word ptr \[si\]/) $0=" lodsw" if( /jmp/) { @@ -238,18 +238,23 @@ print " ret" next } + if (/@loadfailure/) { + print " global jmploadfailure:near" + print "jmploadfailure:" + } sub(/\[di/,"[bx") sub(/di,/,"bx,") } - if (/vid_mode = vid_mode/) isload=2 + if (/mode = vid_mode/) { isload=2; print " mov bx,offset _cmdnum" } if (isload == 2) { # LOAD.LST + if (/DGROUP:_cmdnum/) { sub(/DGROUP:_cmdnum/,"[bx"); $0=$0 "]"} sub(/,0/,""); sub(/cmp /,"mov cx,") sub(/je/,"jcxz") if (/ax,word/) next sub(/,ax/,",cx") if (/starting linux 1\.3\.73/) isload=0 } - if (/die\(not_kernel/ || /_rm_size=0x200/ || /heap_top = _rm_buf/) isload=1 + if (/_rm_size=0x200/ || /heap_top = _rm_buf/) isload=1 if (isload == 1) { # LOAD.LST if (/ptr .die\$qpxzc/) $0="@die@:\n" $0 if (/mov al,byte ptr/ && is386) { @@ -264,38 +269,101 @@ } } # file == "load.cpp" if (file == "iso9660.cpp") { - if (/x->curpos \+= x->entrysize/) isiso=14 + if (/ptr \[si\+10\],dx/) next + if (/ptr \[si\+8\],ax/) next + if (/si\+32/) next + if (/add word ptr \[si\],ax/) $0=" add word ptr [si],cx" + if (/ax,word ptr \[si\+24\]/) sub(/mov ax,/,"les ax,d") + if (/ax,word ptr \[si\+26\]/) next + if (/word ptr \[si\+29\],ax/) sub(/ax/,"es") + if (/\[si\],-1/) $0=" not word ptr [si]" + sub(/di,word ptr DGROUP:_isostate\+2/,"di,word ptr [si+2]") + if (isiso == 19) { # ISO9660.LST + if (/short @2@282/) $0=" jc restoreC" + if (/bp-2/ || /si\+34/ || /ax,dx/ || /cmp ax,-1/) next + sub(/dx,/,"bx,") + if (/short @2@282/) sub(/je/,"jnc") + if (/\[si\+37\],0/) sub(/,0/,",ch") + if (/@strcmp\$qpxzct1/) { + print + print "restoreC:" + $0=" mov byte ptr [di],cl ; c" + isiso=1 + } + } + if (/ax,-8/) { isiso=18; next } + if (isiso == 18) { # ISO9660.LST + if (/ax,ax/) { isiso=0;next } + sub(/mov/,"sub") + sub(/,ax/,",8") + } + if (isiso == 17) { # ISO9660.LST + if (/inc di/) $0="; " $0 + if (/_isostate\+205/) { + print + $0=" jmp setdirofsnsz" + } + else sub(/ax/,"bx") + if (/si\+24/) isiso=0 + if (/,bx/) next + if (/isoreadrootsector/) { + print + print " cmp word ptr [si+39],17475" + print " stc" + $0=" jne returnC" + } + } + if (/cpytodirpage.x->dirpage/) isiso=16 + if (isiso == 16) { # ISO9660.LST + if (/filesize2dirsize/) { + print " mov bx,word ptr [si+9]" + print " mov ax,word ptr [si+13]" + print "setdirofsnsz:" + print " mov word ptr [si+26],bx" + } + if (/ax,/ || /si\+13/ || /si\+26/) next + if (/si\+24/) isiso=1 + } + if (/found:/) isiso=15 + if (/short @1@394/) sub(/@1@394/,"@1@422") + if (isiso != 15 && /si,offset DGROUP:_isostate/) $0=";" $0 + if (isiso == 15) { # ISO9660.LST + if (/xor/) { + print "returnNotC:" + print " cmc" + print "returnC:" + print "@1@422:" + print " sbb ax,ax" + print "return:" + next + } + if (/@1@422:/ || /bp$/ || /bp,sp/ || /sp,2/) next + if (/\[di\],47/) isiso=17 + } + if (/short @1@142/) { isiso=14; next } if (isiso == 14) { # ISO9660.LST - if (/ax,ax/) { - print "return0:" - isiso=0 - } + if (/ax,-1/) next + if (/jmp @1@422/) sub(/jmp/,"jb") } if (/p = x->buffer \+ 34/) isiso=13 if (isiso == 13) { # ISO9660.LST if (/di,si/) $0=" xchg ax,bx" - if (/di,ax/) $0=" lea di,[si+bx+70]" - if (/di,70/) { + if (/di,ax/) $0=" lea di,[si+bx+72]" + if (/di,72/) { isiso=0 next } } if (/register len/) isiso=12 if (isiso == 12) { # ISO9660.LST - sub(/mov dx,ax/,"xchg ax,bx") + if (/di\+2/) sub(/al/,"bl") + if (/cbw/) next + sub(/dx,ax/,"bh,0") if (/bx,dx/) next sub(/i,dx/,"i,bx") + sub(/bx\+di\],0/,"bx+di],bh") if (/while/) isiso=0 } - if (/while \(\*\+\+s/) isiso=11 - if (isiso == 11) { # ISO9660.LST - if (/cmp/ || /filename2open/) isiso=0 - if (/cmp/) next - if (/mov/) { - sub(/mov bx,/,"cmp byte ptr [") - sub(/i$/,"i],0") - } - } if (/curpos >= SECT/) isiso=10 if (isiso == 10) { # ISO9660.LST if (/cmp/) { @@ -311,7 +379,7 @@ } if (/<< SECTORBITS/) isiso=9 if (isiso == 9) { # ISO9660.LST - if (/dx,/) next + if (/dx,/) next sub(/mov ax,/,"les ax,d") if (/^ call/) { print " extrn N_LXLSH@ES:near" @@ -326,277 +394,50 @@ sub(/,ax/,",es") if (/filemod/) isiso=0 } - if (/CD001/) isiso=7 - if (isiso == 7) { # ISO9660.LST - sub(/mov ax,-1/,"dec ax") - if (/jmp/) isiso=0 - } - if (/int len =/) isiso=6 - if (isiso == 6) { # ISO9660.LST - if (/dx,ax/) next - sub(/ax/,"dx") - sub(/cx,di/,"bx,di") - sub(/cx,dx/,"bx,ax") - sub(/di,dx/,"di,ax") - if (/while/) isiso=2 - } if (/entrysize =/) isiso=5 if (isiso == 5) { # ISO9660.LST if (/ax,ax/) next sub(/ax/,"cx") sub(/je/,"jcxz") + if (/jcxz/) { + hold=0 + print s + sub(/@1@114/,"@1@394") + print + print " mov word ptr [si+10],dx" + $0=" mov word ptr [si+8],ax" + } if (/return/) isiso=0 } - if (/x->curdirsize == 0xFFFF/) isiso=4 - if (isiso == 4) { # ISO9660.LST - sub(/DGROUP:_isostate\+18/,"[si+18]") - sub(/DGROUP:_isostate\+20/,"[si+20]") - if (/goto restarted/) isiso=0 - } - } # file == "iso9660.cpp" - if (file == "iso9660.cpp" || file == "tazboot.cpp") { if (/do s\+\+; while/) isiso=3 - if (/for \(p = s; \*s && \*s \!=/) isiso=3 # tazboot/main - if (isiso == 3) { # ISO9660.LST, TAZBOOT.LST + if (isiso == 3) { # ISO9660.LST sub(/cmp byte ptr \[.i\]/,"sub al") - if (/mov byte ptr \[bp-5\],al/) $0=" push ax" - if (/mov al,byte ptr \[bp-5\]/) $0=" pop ax" if (/inc /) { r=$2; print; next } if (/al,0/) print " mov al,[" r "]" - if (/al,byte ptr/) sub(/mov/,"xchg") + if (/al,byte ptr/) next if (/byte ptr \[.*\],0/) next - if (/jmp/) { - print " mov bx,si" - $0=" db 0A8h ; test al,xx instead of " $0 + } + if (/ptr .isoreaddir/) isiso=1 + if (isiso == 1) { # ISO9660.LST + if (/n = name;/) { + isiso=19 + print " xchg ax,cx" + print " xchg cl,byte ptr [di] ; c" } - if (/word ptr \[bp-4\]/) next - if (/\) s\+\+;/ || /\],-1/) isiso=0 + if (/short @2@366/) sub(/jne/,"jnc") + if (/short @2@282/) sub(/je/,"jc") + if (/short @2@562/) sub(/@2@562/,"returnNotC") + if (/short @2@534/) { print; $0=" inc cx" } + if (/ax,word ptr \[si\+4\]/) $0=" xchg ax,bx ; " $0 + if (/\[di\],al/) next + if (/@2@310/) next + if (/ax,-1/) next + if (/inc di/ || /@@0/) next + if (/@2@142$/) { print " inc di"; sub(/jmp/,"loop") } } - } # file == "iso9660.cpp" || file == "tazboot.cpp" - if (file == "iso9660.cpp") { - if (/endname = NULL/) isiso=2 - if (isiso == 2) { # ISO9660.LST - if (/mov bx,cx/) next - gsub(/cx/,"bx") - sub(/DGROUP:_isostate\+35/,"[si+35]") - } - if (/const char \*n = name/) isiso=1 - if (isiso == 1) { # ISO9660.LST - if ((/mov word ptr \[si\+32\],ax/ ) || - (/mov ax,word ptr \[si\+2\]/) || - (/bx,word ptr \[si\+32\]/) || (/ax,dx/)) next - if (/dx,/) sub(/dx/,"ax") - if ((/sub ax,word ptr \[si\+2\]/) || - (/\[si\+16\]/) || (/ax,di/)) sub(/ax/,"bx") - if (/add word ptr \[si\+32\],ax/) $0=" add bx,word ptr [si+16]" - if (/al,/ || /,al/) sub(/al/,"cl") - if (/cmp byte ptr \[si\+34\],0/) $0=" or cl,cl" - if (/ax,ax/) next - if (/short @.@506/) $0=" jmp return0" - if (/jne @@0$/) next - if (/jmp @.@58$/) sub(/jmp/,"je") - sub(/mov ax,-1/,"dec ax") - } + if (/i\+36\]/) next + sub(/DGROUP:_isostate\[bx/,"[bx+si") } # file == "iso9660.cpp" - if (/endp/) { xlabel = ""; goto2=0 } - if (/isoopen\(s\+7\)/ && xlabel == "") goto2=1 # tazboot/bootiso - if (/_vid_mode,ax/ && xlabel == "") goto2=1 # tazboot/main - if (/_initrd_name,si/ && xlabel == "") goto2=1 # tazboot/main - if (/_base_himem\+2,/ && xlabel == "@") goto2=1 # tazboot/bootiso tazboot/main - if (/DGROUP:_skip_alloc/ && xlabel == "@") goto2=1 # tazboot/bootiso tazboot/main - if (/puts\(cmdline\)/ && xlabel == "@@") goto2=1 - if (goto2 == 1 && /jmp/) { # TAZBOOT.LST && LINLD.LST - print $NF xlabel "@:" - label=$NF - } - if (goto2 > 0 && label == $NF) { - $0=$0 xlabel - if (goto2++ == 1) xlabel=xlabel "@" - } - if (file == "tazboot.cpp" && /close\(x/) isotazboot=16 - if (isotazboot == 160) { # TAZBOOT.LST - $0="; " $0 - if (/ret/) isotazboot=0 - } - if (isotazboot == 16) { # TAZBOOT.LST - if (/@.@/) { - isotazboot=160 - next - } - } - if (file == "tazboot.cpp" && /jne @@2/) isotazboot=15 - if (isotazboot == 15) { # TAZBOOT.LST - if (/@.@/) { - print " pop di" - print " pop si" - print " mov sp,bp" - print " pop bp" - print " ret" - next - } - if (/skip_alloc/) isotazboot=0 - } - if (/if\(\*s>=/) isotazboot=14 - if (isotazboot == 14) { # LINLD.LST - if (/jmp/) { - $0=" db 0A9h ; test ax,xxxx instead of " $0 - isotazboot=0 - } - } - if (file == "tazboot.cpp" && /; s \+= 4/) isotazboot=13 # tazboot/main - if (isotazboot == 13) { # TAZBOOT.LST - if (/si,4/) $0=" lea bx,[si+4]" - if (/bx,si/) next - if (/DGROUP:_topmem/ || /set_iso/) isotazboot=0 - } - if (file == "tazboot.cpp" && /case 0x652F:/) isotazboot=12 # tazboot/main - if (isotazboot == 12) { # TAZBOOT.LST - sub(/si,word/,"bx,word") - if (/short/) isotazboot=0 - } - if (/return load_kernel/) isotazboot=11 # tazboot/isokernel - if (isotazboot == 11) { # TAZBOOT.LST - sub(/call/,"jmp") - if (/ret/ || /pop/) next - if (/endp/) isotazboot=0 - } - if (/cmdline=s\+=3/ || /magic \!= 0/ || /&root_dev =/) { isotazboot=10; j="" } # ,tazboot/bootiso,tazboot/main - if (isotazboot == 10) { # TAZBOOT.LST && LINLD.LST - if (/je/ || /jne/) { j=$1; next } - if (/jmp/) { - if (j=="jne") sub(/jmp/,"je") - else if (j=="je") sub(/jmp/,"jne") - isotazboot=0 - } - } - if (/static const unsigned long initrddesc = 18L/) isotazboot=9 # tazboot/bootiso - if (isotazboot == 9) { # TAZBOOT.LST - if (/,0/) { - split($4,y,",") - print " mov bx,offset " y[1] - sub(/DGROUP:.*,/,"[bx],") - } - if (/mov/ && $3 == y[1]) next - if (/je/) next - if (/jmp/) sub(/jmp/,"jne") - sub(/ax,offset/,"bx,offset") - if (/bx,ax/) { isotazboot=0; next } - } - if (/isoopen\(s\+7\) != -1/) isotazboot=8 # tazboot/bootiso - if (isotazboot == 8) { # TAZBOOT.LST - sub(/\[bx/,"[si") - if (/bx,si/) next - if (/magic/) isotazboot=0 - } - if (/isoopen\(\"bzImage\"\)/) isotazboot=7 # tazboot/bootiso - if (isotazboot == 7) { # TAZBOOT.LST - if (/inc/ || /,al/) next - if (/al,byte/) sub (/mov al,/,"inc ") - if (/isokernel/) isotazboot=0 - } - if (/if \(c\) s\+\+;/) isotazboot=6 # tazboot/main - if (isotazboot == 6) { # TAZBOOT.LST - if (/cmp/) { - $0=" cmp al,0" - isotazboot=0 - } - } - if (/static void next_chunk/) isotazboot=5 # tazboot/next_chunk - if (isotazboot == 501) { - if (/ret/) { - print "@1@86:" - isotazboot=0 - } - } - if (isotazboot == 5 || isotazboot == 500) { # TAZBOOT.LST - if (/cx,ax/) $0=" xchg ax,bx" - if (/ax,word ptr \[si\+28\]/ && isotazboot == 500) next - if (/bx,cx/) next - if (/push/ || /pop/ || /bp,sp/ || /si,/) next - sub(/\[si/,"[di") - if (/initrd_info/) isotazboot=500 - if (/bx\+6\]/) next - if (/bx\+4\]/) sub(/mov dx,/,"les dx,d") - sub(/di\+24\],ax/,"di+24],es") - sub(/call/,"jmp") - if (/ret/ || /pop/ || /^@1@86:/) next - if (/_isostate\+14/) next - if (/_isostate\+12/) { - sub(/mov ax,/,"les ax,d") - print - print " mov dx,es" - next - } - if (/ax,-4/) isotazboot++ - } - if (/0x7FF0/) isotazboot=4 # tazboot/bootiso - if (isotazboot == 4) { # TAZBOOT.LST - if (/ax,word ptr/) { - print " mov ax,32752" - print " cwd" - sub(/mov/,"sub") - } - if (/bx,/ || /cx,/ || /dx,/) next - sub(/,0/,",dx") - sub(/,bx/,",dx") - sub(/,cx/,",ax") - if (/@addinitrd\$qv/) isotazboot=0 - } - if (/c = x->filename/) isotazboot=3 # tazboot/bootiso - if (isotazboot == 3) { # TAZBOOT.LST - if (/ax,/) $0=" xchg ax,bx" - if (/\]$/) next - if (/@strcpy\$qpxzct1/) isotazboot=0 - } - if (/base_himem = memtop/) isotazboot=2 # tazboot/bootiso - if (isotazboot == 2) { # TAZBOOT.LST - if (/word ptr \[si\+2\],0/) { - print s; hold=0 - print " mov bx,word ptr [si+2]" - $0=" or bx,bx" - } - if (/\[bp-4\],ax/) sub(/ax/,"bx") - if (/ax,word ptr \[si\+2\]/ || /bx,ax/) next - if (/_base_himem\+2,dx/) { - print " mov bx,offset DGROUP:_base_himem+2" - } - sub(/DGROUP:_base_himem,/,"[bx-2],") - sub(/DGROUP:_base_himem\+2,/,"[bx],") - sub(/DGROUP:_base_himem\+3,/,"[bx+1],") - if (/@strcmp\$qpxzct1/) isotazboot=0 - } - if (/static void addinitrd/) isotazboot=100 # tazboot/addinitrd - if (isotazboot == 100) { # TAZBOOT.LST - if (/cx,ax/) { - print " mov si,offset _isostate+8" - print " push ds" - print " pop es" - print " xchg ax,di" - print " movsw" - print " movsw" - print " movsw" - print " movsw" - $0=" xchg ax,di" - } - if (/mov/ && !/si/ && !/cl/) next - if (/void load_initrds/) isotazboot=101 - } - if (isotazboot == 101 || isotazboot == 102) { # TAZBOOT.LST - sub(/\[si/,"[di"); sub(/si,/,"di,"); sub(/si$/,"di") - sub(/DGROUP:_imgs\+38$/,"[di+38-32]") - sub(/DGROUP:_imgs\+40$/,"[di+40-32]") - if (/isofd/) isotazboot=102 - if (/push/ && isotazboot == 102) next - if (/pop/ && isotazboot == 102) next - if (/load_initrd/) isotazboot=101 - if (/isokernel/) isotazboot=103 - } - if (isotazboot > 102) { # TAZBOOT.LST - if (/push/ || /pop/) next - sub(/\[si/,"[bx") - sub(/si,/,"bx,") - if (/static void bootiso/) isotazboot=0 - } if (wascall) { if (rcall != "") { if (/,ax$/) print " mov " rcall ",ax" diff -r 9c5316bc7e8e -r a946c1651082 syslinux/stuff/iso2exe/bootiso.S --- a/syslinux/stuff/iso2exe/bootiso.S Wed Dec 16 17:23:49 2020 +0000 +++ b/syslinux/stuff/iso2exe/bootiso.S Fri Jan 08 20:15:35 2021 +0000 @@ -153,71 +153,30 @@ ////////////////////////////// DOS EXE code /////////////////////////////////// -bootdir: - .asciz "/boot" -linld: - .asciz "linld.com" cmdline: -// .ascii "-f " -// .ascii "image=\boot\" -// .ascii "bzImage " - .ascii "initrd=" -rootfs: - .ascii "rootfs" -dotgz: - .ascii ".gz,! " -// .ascii ".gz,rootfs4.gz,! " -args: -// .ascii " rw " -// .ascii " mode=menu" - .ascii " autologin rdinit=/init.exe magic=" -magicstr: - .ascii "0 iso=" -// .ascii "65535 iso=" -filename: + .ds.b 128,0 +linldofs: // offset of linld.com in iso + .long 0 // Updated by iso2exe +linldsz: // size-1 + .word 0 // Updated by iso2exe exestart: movb $0x30,%ah // get DOS version int $0x21 cmpb $3,%al - jc goabort + jc abort + +// load linld.com cld - movw EXEADRS(comstart),%si - movw $0xF000,%di - movb $4,%ch // 2k min +linldbuf = 0x8000 +isopath = 0x7000 + movw $0x8000,%cx // clear 8000-FFFF + movw %cx,%di + movb %cl,%al rep - movsw // helper - movw $129,%si - leaw args-cmdline(%si),%di - movb -1(%si),%cl - pushw %si - rep - movsb // user args - xchgw %ax,%di - popw %di - movw $EXEADRS(cmdline),%si - movb $args-cmdline,%cl - rep - movsb // files - xchgw %ax,%di - movb $filename-args,%cl - rep - movsb // end - pushw %di // filename + stosb -#define ISOSTATE 0xF000 -#define ISO_OPEN iso_open -#define ISO_READDIR *0xF004 -#define ISO_READMENU iso_readmenu -#define RUN_LINLD run_linld - movw ISOSTATE,%bp - xorw %ax,%ax - movw %bp,%di - movb $64,%cl - rep - stosb // clear BSS - - movw %ax,%di + movw %di,%ax movw 0x2C(%di),%es decw %cx scalp: @@ -225,22 +184,23 @@ scasb scasb jne scalp - scasw - movw %di,%si // %es:%di = programme pathname - + scasw // %es:%di = programme pathname pushw %es - pushw %ds + pushw %cs popw %es popw %ds - popw %di // filename - pushw %di +#define CONONICALIZE_FILENAME insert obsolute path +#ifdef CONONICALIZE_FILENAME + movw %di,%si // %ds:%si = programme pathname + movw $EXEADRS(isopath),%di // to filename %es:%di movb $0x60,%ah // canonicalize filename int $0x21 pushw %es popw %ds +#endif + movw %di,%si // %ds:%si = programme pathname #define LONG_FILENAME #ifdef LONG_FILENAME - popw %si pushw %si movw $0x716C,%ax xorw %bx,%bx // R/O @@ -249,126 +209,133 @@ stc int $0x21 jnc opened + popw %dx +#else + movw %si,%dx #endif - popw %dx - pushw %dx + pushw %si movw $0x3D00,%ax // movb $0,%cl int $0x21 -goabort: - jc abort + jc popNabort opened: - movw %ax,4(%bp) // fd - - call ISO_READMENU - movw 6(%bp),%ax // magic = filemod - popw %bx - leaw magicstr-filename(%bx),%di - movb $10,%bl - xorw %cx,%cx -lp1: - xorw %dx,%dx - divw %bx - pushw %dx - incw %cx - orw %ax,%ax - jnz lp1 -lp2: - popw %ax - addb $'0',%al - stosb // store magic - loop lp2 - - movw $EXEADRS(bootdir),%ax - call ISO_OPEN - orw $-1,18(%bp) // curdirsize = -1 - xorw %ax,%ax -found: - incb %ah -patchtest: - pushw %ax - call ISO_READDIR - pushw %ds - popw %es - incw %ax - popw %ax - movw $EXEADRS(rootfs),%si - je dopatch - movw %si,%di - movw 16(%bp),%si // filename - movw $9,%cx - rep - cmpsb - jcxz found - cmpb $3,%cl - ja patchtest - decw %si - cmpb (%si),%al - ja patchtest - lodsb - jmp patchtest -done: - movw $128,%ax - subw %ax,%si - xchgw %ax,%si - decw %ax - movb %al,(%si) // cmdline length - - movw $EXEADRS(linld),%ax - call ISO_OPEN - jc abort - movw 12(%bp),%cx // filesize - movw $0x100,%dx - call RUN_LINLD + xchgw %ax,%bx // fd = %bx + movw $32,%cx + movw $EXEADRS(headbuf),%dx + movb $0x3F,%ah + int $0x21 // read(%bx,%dx,%cx) + jc popNabort + les EXEADRS(linldofs),%dx + movw %es,%cx + movw $0x4200,%ax // lseek(%bx,%cx:%dx,SEEK_SET) + int $0x21 + jc popNabort + movw EXEADRS(linldsz),%cx + jcxz popNabort + movw $EXEADRS(linldbuf),%dx + movw %cx,%di + addw %dx,%di + movb $0x3F,%ah + int $0x21 // read(%bx,%dx,%cx) + jnc copycmdline +popNabort: + popw %si abort: movw $EXEADRS(stopmsg),%dx movb $9,%ah int $0x21 int $0x20 -dopatch: - pushw %si - cmpw $0x200,%ax - je initrddone - movw $EXEADRS(dotgz),%di - decb %ah - je modify - scasw - scasw // addw $4,%di - movsw - movsw - movsw -modify: + +// installed args (ex: image=/boot/bzImage initrd=rootfs4.gz,! autologin rdinit=/init.exe) + +copycmdline: + pushw %ds + popw %es + movw $EXEADRS(cmdline),%si + movw %di,%bx + +copylp: + lodsb stosb - movw $129+dotgz-cmdline,%si - movsb - movsw - movsw -initrddone: - movw $129+rootfs-cmdline,%di - popw %si - movw $args-rootfs,%cx + orb %al,%al + jnz copylp + +// magic= arg + + decw %di + movw $7,%cx + movw $EXEADRS(magicstr),%si rep movsb + movw EXEADRS(headbuf+18),%ax // magic + movw $10,%si +magiclp1: + xorw %dx,%dx + divw %si + pushw %dx + incw %cx + orw %ax,%ax + jnz magiclp1 +magiclp2: + popw %ax + addb $'0',%al + stosb // store magic + loop magiclp2 -shrink0: - movw $129,%si -shrink: - movw %si,%di - lodsb - cmpb $0,%al - je done - cmpb $' ',%al - jne shrink - cmpb (%si),%al - jne shrink -pack: +// iso= arg + + movb $5,%cl + movw $EXEADRS(isostr),%si + rep + movsb + popw %si +isolp: lodsb stosb - cmpb $0,%al - jne pack - jmp shrink0 - + orb %al,%al + jne isolp + decw %di + +// append user args + + movw $0x80,%si + lodsb + movb $0xFF,-1(%si) // long cmdline flag + cbw + xchgw %ax,%cx + rep + movsb + movb $0,(%di) + +// set cmdline size + + movw %di,%ax + subw %bx,%ax + incw %ax + movb %al,-1(%bx) + +// run linld.com + + movw $EXEADRS(mvNjump),%si + incw %di + movb $endmvNjump-mvNjump,%cl +mvNjump: + pushw %di + rep + movsb + movw $EXEADRS(linldbuf),%si + movw $0x0100,%di + popw %cx + pushw %cx + subw %si,%cx + ret +endmvNjump: + +magicstr: .ascii " magic=" +isostr: .ascii " iso=" + .org 0x0400,0xEE +headbuf: .org 0x0600,0xFF isolinux: @@ -632,12 +599,5 @@ stopmsg: .ascii "This program cannot be run in DOS mode.$" .org 0x0778,0xEE - .org 0xF002-0xC0 -iso_open: - .word 0 - .word 0 -iso_readmenu: - .word 0 -run_linld: .end diff -r 9c5316bc7e8e -r a946c1651082 syslinux/stuff/iso2exe/iso2exe.sh --- a/syslinux/stuff/iso2exe/iso2exe.sh Wed Dec 16 17:23:49 2020 +0000 +++ b/syslinux/stuff/iso2exe/iso2exe.sh Fri Jan 08 20:15:35 2021 +0000 @@ -51,15 +51,6 @@ rm -rf $TMP } -add_doscom() -{ - SIZE=$($0 --get boot.com | wc -c) - OFS=$(( $OFS - $SIZE )) - printf "Adding DOS boot file at %04X (%d bytes) ...\n" $OFS $SIZE - $0 --get boot.com | ddn of=$1 bs=1 seek=$OFS - store 64 $(($OFS+0xC0)) $1 -} - add_tazlito_info() { HOLE=$OFS @@ -110,6 +101,20 @@ store 454 $(($i/512)) $1 32 ### 446+8 OFFSET store 458 $(($(stat -c %s $1)/512)) $1 32 ### 446+12 SIZE fi + mkdir /tmp/mnt$$ + mount -o loop,ro $1 /tmp/mnt$$ + if [ -s /tmp/mnt$$/boot/linld.com ]; then + i=$(($(get 20 $1)-0xC0)) + store $(($i-6)) $(($(stat -m /tmp/mnt$$/boot/linld.com | sed q)*2048)) $1 32 + store $(($i-2)) $(stat -c %s /tmp/mnt$$/boot/linld.com) $1 + r0="$(cd /tmp/mnt$$/boot/ ; ls rootfs.gz 2> /dev/null)" + r1="$(cd /tmp/mnt$$/boot/ ; ls -r rootfs?*.gz 2> /dev/null | sed q)" + [ "$r0" -a "$r1" ] && r0="$r0," + echo -n "image=/boot/bzImage initrd=$r0$r1,! autologin rdinit=/init.exe" | \ + ddn bs=1 of=$1 conv=notrunc seek=$(($i-134)) + fi + umount /tmp/mnt$$ + rmdir /tmp/mnt$$ } add_fdbootstrap() @@ -293,8 +298,8 @@ --build) shift TMP=/tmp/iso2exe$$ - dd if=/dev/zero bs=1k count=100 of=/tmp/fs$$ - mke2fs /tmp/fs$$ + ddq if=/dev/zero bs=1k count=100 of=/tmp/fs$$ + mke2fs /tmp/fs$$ > /dev/null mkdir $TMP mount -o loop /tmp/fs$$ $TMP rm -rf $TMP/* @@ -307,7 +312,7 @@ umount -d $TMP rm -rf $TMP /tmp/fs$$ p=$((4-($(stat -c %s rootfs.gz)%4))) - [ $p = 4 ] || dd if=/dev/zero bs=1 count=$p >> rootfs.gz + [ $p = 4 ] || ddq if=/dev/zero bs=1 count=$p >> rootfs.gz chmod 644 ${@/init/rootfs.gz} chown root.root ${@/init/rootfs.gz} touch -t 197001010100.00 ${@/init/rootfs.gz} @@ -328,7 +333,6 @@ add_win32exe $DATA $2 > /dev/null HSZ=$OFS add_rootfs $DATA > /dev/null - add_doscom $DATA > /dev/null add_fdbootstrap $DATA > /dev/null name=${3:-bootiso} BOOTISOSZ=$((0x8000 - $OFS + $HSZ)) @@ -574,7 +578,6 @@ # keep the largest room for the tazlito info file add_rootfs $1 - add_doscom $1 add_fdbootstrap $1 printf "%d free bytes in %04X..%04X\n" $(($OFS-$HOLE)) $HOLE $OFS store 440 $(date +%s) $1 32 diff -r 9c5316bc7e8e -r a946c1651082 syslinux/stuff/iso2exe/taziso --- a/syslinux/stuff/iso2exe/taziso Wed Dec 16 17:23:49 2020 +0000 +++ b/syslinux/stuff/iso2exe/taziso Fri Jan 08 20:15:35 2021 +0000 @@ -44,16 +44,14 @@ gettazboot() { echo -e "\nCreating $(basename $1) ..." - S=$((32+HEADERSZ)) + gotcdfile linld.com + S=$(($(stat -c %s $file)+12)) P=$((($S+511)/512)) E=$((4096-(32*$P))) words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 -16 \ -2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1 - uudecode - >> $1 << EOT -HEADERCODE -EOT - gotcdfile linld.com - ddq if=$file >> $1 + dd if=$file bs=1 count=$(($(stat -c %s $file)-1)) >> $1 2> /dev/null + echo -en '@tazboot.cmd\0' >> $1 } maybe64() @@ -1370,8 +1368,6 @@ } if [ "$1" = "--build" ]; then #install-begin - uuencode -m - < header.com | sed -e '/^HEADERCODE$/r/dev/stdin' \ - -e "s|HEADERSZ|$(size header.com)|" -e '/^HEADERCODE$/d' -i $0 uuencode -m - < ifmem.bin | sed -e '/^ifmemcode$/r/dev/stdin' \ -e '/^ifmemcode$/d' -i $0 uuencode -m - < bootloader.bin | sed -e '/^bootloader$/r/dev/stdin' \ diff -r 9c5316bc7e8e -r a946c1651082 web-applications/stuff/applications/gemini.desktop --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web-applications/stuff/applications/gemini.desktop Fri Jan 08 20:15:35 2021 +0000 @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=Gemini project +Name[fr]=Projet Gemini +TryExec=browser +Exec=browser https://proxy.vulpes.one/gemini/gemini.circumlunar.space/ +#Exec=browser https://portal.mozz.us/gemini/gemini.circumlunar.space/ +Icon=applications-internet +Categories=Network;