wok-next rev 19667

linld: resync with wok
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Mar 17 15:18:10 2017 +0100 (2017-03-17)
parents 42d840ecf3bb
children 5d48570cca72
files linld/receipt linld/stuff/linld.txt linld/stuff/src/!COMPILE.BAT linld/stuff/src/!COMPILEX.BAT linld/stuff/src/A20.ASM linld/stuff/src/COMMON.H linld/stuff/src/CRTL.ASM linld/stuff/src/CRTL.H linld/stuff/src/CRTLX.ASM linld/stuff/src/CRTLX.H linld/stuff/src/HIMEM.CPP linld/stuff/src/ISO9660.CPP linld/stuff/src/ISO9660.H linld/stuff/src/JUMP.ASM linld/stuff/src/LINKX.CMD linld/stuff/src/LINLD.CPP linld/stuff/src/LOAD.CPP linld/stuff/src/MEMCPY32.ASM linld/stuff/src/MEMTOP.ASM linld/stuff/src/TAZBOOT.CPP linld/stuff/src/VCPI.ASM linld/stuff/src/XMM.ASM linld/stuff/src/_BEG.ASM linld/stuff/upx.sh
line diff
     1.1 --- a/linld/receipt	Fri Mar 17 15:14:21 2017 +0200
     1.2 +++ b/linld/receipt	Fri Mar 17 15:18:10 2017 +0100
     1.3 @@ -31,7 +31,8 @@
     1.4  cd tazboot
     1.5  $(cat TAZBOOT/!COMPILEX.BAT)
     1.6  EOT
     1.7 -	SDL_VIDEODRIVER=dummy dosbox MAKE.BAT -exit -c "mount D $src"
     1.8 +	SDL_VIDEODRIVER=dummy dosbox MAKE.BAT -exit -c "mount D $src" \
     1.9 +		2>&1 | grep -v 'ALSA lib'
    1.10  	cp LINLD$SUFFIX/LINLD.COM linld.com
    1.11  	cp TAZBOOT/TAZBOOT.COM tazboot.com
    1.12  	objdump -D -b binary -mi386 -Maddr16,data16 --adjust-vma=0x100 \
     2.1 --- a/linld/stuff/linld.txt	Fri Mar 17 15:14:21 2017 +0200
     2.2 +++ b/linld/stuff/linld.txt	Fri Mar 17 15:18:10 2017 +0100
     2.3 @@ -40,3 +40,17 @@
     2.4          Some VCPI comments added
     2.5  0.96    Do not lowercase entire command line
     2.6  0.97    memtop() must be rounded down to page boundary
     2.7 +
     2.8 +SliTaz patches
     2.9 +--------------
    2.10 +New command line arguments:
    2.11 +-f		force. Do not ask memory manager for allocation
    2.12 +-b base		lower buffer address, default 1088k
    2.13 +root number	root filesystem device
    2.14 +mem number	higher memory address, default 256m
    2.15 +
    2.16 +Every arguments can be stored in a separate file and load with @filename, i.e
    2.17 +> linld @args.cmd
    2.18 +
    2.19 +The -f and -b are useful skip XMM (max 64M ?) and VCPI (max 32M ?) limits:
    2.20 +> linld -f -b 64m initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz "cl=rw root=/dev/null video=-32"
     3.1 --- a/linld/stuff/src/!COMPILE.BAT	Fri Mar 17 15:14:21 2017 +0200
     3.2 +++ b/linld/stuff/src/!COMPILE.BAT	Fri Mar 17 15:18:10 2017 +0100
     3.3 @@ -3,14 +3,17 @@
     3.4  tasm /h > helptasm.log
     3.5  bcc > helpbcc.log
     3.6  tlink > helptlink.log
     3.7 -tasm /la /m *.asm > asm.log
     3.8 +rem tasm /la /m *.asm > asm.log
     3.9 +tasm /la /m /dLARGE_IMAGES *.asm > asm.log
    3.10  rem @pause
    3.11 -bcc @bccopt.opt -S -mt *.cpp
    3.12 +rem bcc @bccopt.opt -S -mt *.cpp
    3.13 +bcc @bccopt.opt -S -mt -DLARGE_IMAGES *.cpp
    3.14  tasm /l /m load.asm
    3.15  tasm /l /m himem.asm
    3.16  tasm /l /m linld.asm
    3.17  tasm /l /m iso9660.asm
    3.18 -bcc @bccopt.opt -c -mt *.cpp > cpp.log
    3.19 +rem bcc @bccopt.opt -c -mt *.cpp > cpp.log
    3.20 +bcc @bccopt.opt -c -mt -DLARGE_IMAGES *.cpp > cpp.log
    3.21  rem @pause
    3.22  tlink /m /s /t @link.cmd > lnk.log
    3.23  rem @pause
     4.1 --- a/linld/stuff/src/!COMPILEX.BAT	Fri Mar 17 15:14:21 2017 +0200
     4.2 +++ b/linld/stuff/src/!COMPILEX.BAT	Fri Mar 17 15:18:10 2017 +0100
     4.3 @@ -1,13 +1,16 @@
     4.4  path ..\BC31;%PATH%
     4.5  call !clean.bat
     4.6 -tasm /la /m /dNO386 *.asm > asm.log
     4.7 +rem tasm /la /m /dEXTRA /dNO386 *.asm > asm.log
     4.8 +tasm /la /m /dEXTRA /dNO386 /dLARGE_IMAGES *.asm > asm.log
     4.9  rem @pause
    4.10 -bcc @bccopt.opt -S -mt *.cpp
    4.11 +rem bcc @bccopt.opt -S -mt *.cpp
    4.12 +bcc @bccopt.opt -S -mt -DLARGE_IMAGES *.cpp
    4.13  tasm /l /m load.asm
    4.14  tasm /l /m himem.asm
    4.15  tasm /l /m tazboot.asm
    4.16  tasm /l /m iso9660.asm
    4.17 -bcc @bccopt.opt -c -mt *.cpp > cpp.log
    4.18 +rem bcc @bccopt.opt -c -mt *.cpp > cpp.log
    4.19 +bcc @bccopt.opt -c -mt -DLARGE_IMAGES *.cpp > cpp.log
    4.20  rem @pause
    4.21  tlink /m /s /t @linkx.cmd > lnk.log
    4.22  rem @pause
     5.1 --- a/linld/stuff/src/A20.ASM	Fri Mar 17 15:14:21 2017 +0200
     5.2 +++ b/linld/stuff/src/A20.ASM	Fri Mar 17 15:18:10 2017 +0100
     5.3 @@ -5,7 +5,7 @@
     5.4                  %crefref
     5.5                  %noincl
     5.6                  %nomacs
     5.7 -                p386
     5.8 +                p8086
     5.9  
    5.10          group   DGROUP  _TEXT,_DATA
    5.11          assume  cs:DGROUP,ds:DGROUP
    5.12 @@ -15,7 +15,7 @@
    5.13          global  die:near
    5.14  enable_a20_methods:
    5.15  		dw	_enable_a20_fast, _enable_a20_kbd, _enable_a20_xmm, die
    5.16 -msg_a20		db	"Can't enable A20",0
    5.17 +msg_a20		db	"Can't use A20",0
    5.18  
    5.19          ends    _DATA
    5.20  
    5.21 @@ -51,16 +51,14 @@
    5.22                  xor     cx,cx           ; 64K iterations
    5.23  @@loop:
    5.24                  call    @@delay         ; 8042 status port
    5.25 -                in      al,64h          ; output buffer?
    5.26 +                in      al,64h
    5.27 +                test    al,3            ; is output or input full?
    5.28 +                jz      @@break         ; no - break loop
    5.29                  test    al,1            ;
    5.30                  jz      @@no_output
    5.31                  call    @@delay         ; yes: read it
    5.32                  in      al,60h          ;
    5.33 -                jmp     @@cont          ;
    5.34  @@no_output:
    5.35 -                test    al,2            ; is input buffer full?
    5.36 -                jz      @@break         ; no - break loop
    5.37 -@@cont:
    5.38                  loop    @@loop
    5.39  @@break:
    5.40                  ret
    5.41 @@ -86,9 +84,24 @@
    5.42          endp    _enable_a20_fast
    5.43  
    5.44  ;***************************************************************
    5.45 +;void enable_a20_or_die();
    5.46 +;***************************************************************
    5.47 +        global  _enable_a20_or_die:near
    5.48 +        proc    _enable_a20_or_die near
    5.49 +
    5.50 +		push	si
    5.51 +		mov	si,offset enable_a20_methods
    5.52 +		jmp	@@check
    5.53 +@@loop:
    5.54 +		lodsw
    5.55 +		mov	bx,offset msg_a20
    5.56 +		call	ax
    5.57 +@@check:
    5.58 +		;call	_check_a20
    5.59 +;***************************************************************
    5.60  ;int check_a20();
    5.61  ;***************************************************************
    5.62 -        proc    _check_a20 near
    5.63 +        ;proc    _check_a20 near
    5.64  
    5.65  ; From linux kernel setup.S:
    5.66  ; wait until a20 really *is* enabled; it can take a fair amount of
    5.67 @@ -113,25 +126,10 @@
    5.68  		loopne	a20lp
    5.69  		xchg	ax,cx
    5.70                  pop     es ds
    5.71 -                ret
    5.72 +                ;ret
    5.73  
    5.74 -        endp    _check_a20
    5.75 +        ;endp    _check_a20
    5.76  
    5.77 -;***************************************************************
    5.78 -;void enable_a20_or_die();
    5.79 -;***************************************************************
    5.80 -        global  _enable_a20_or_die:near
    5.81 -        proc    _enable_a20_or_die near
    5.82 -
    5.83 -		push	si
    5.84 -		mov	si,offset enable_a20_methods
    5.85 -		jmp	@@check
    5.86 -@@loop:
    5.87 -		lodsw
    5.88 -		mov	bx,offset msg_a20
    5.89 -		call	ax
    5.90 -@@check:
    5.91 -		call	_check_a20
    5.92  		jne	@@loop
    5.93  		pop	si
    5.94                  ret
     6.1 --- a/linld/stuff/src/COMMON.H	Fri Mar 17 15:14:21 2017 +0200
     6.2 +++ b/linld/stuff/src/COMMON.H	Fri Mar 17 15:18:10 2017 +0100
     6.3 @@ -22,6 +22,8 @@
     6.4  const u16 _32k = 32*1024u;
     6.5  const u32 _64k = 64*1024ul;
     6.6  const u32 _1m = 1024ul*1024ul;
     6.7 +const u32 _32m = 32*1024ul*1024ul;
     6.8 +const u32 _64m = 64*1024ul*1024ul;
     6.9  
    6.10  const PAGE_BITS = 12;
    6.11  const PAGE_SIZE = 1<<PAGE_BITS;
    6.12 @@ -49,6 +51,22 @@
    6.13      u16 fd2close;
    6.14  } pm, initrd;
    6.15  
    6.16 +extern int skip_alloc;
    6.17 +extern u32 base_himem;
    6.18 +
    6.19 +extern "C" void memcpy_image(struct image_himem *m);
    6.20 +extern "C" void storepage(u32 *dst, u16 src);
    6.21 +#ifdef LARGE_IMAGES
    6.22 +extern "C" void reset_bufv(unsigned long *p);
    6.23 +extern "C" unsigned long* prev_bufv();
    6.24 +extern "C" unsigned long* next_bufv();
    6.25 +#define next(p)	 p = next_bufv()
    6.26 +#define prev(p)	 p = prev_bufv()
    6.27 +#else
    6.28 +#define reset_bufv(p)
    6.29 +#define next(p)	 ++p
    6.30 +#define prev(p)	 --p
    6.31 +#endif
    6.32  extern char vcpi;
    6.33  extern const char* kernel_name;
    6.34  extern const char* initrd_name;
    6.35 @@ -57,8 +75,8 @@
    6.36  extern u16 vid_mode;
    6.37  // External asm helpers
    6.38  extern "C" void memcpy32(u32, u16,u32, u32);
    6.39 -extern "C" void rmcpy(void* rmbuf, u16 rmsize);
    6.40 -extern "C" void set_sregs_jump_seg_ofs(u32 csip, u32 sssp);
    6.41 +extern "C" void rmcpy();
    6.42 +extern "C" void set_sregs_jump_seg_ofs(u32 csip);
    6.43  extern "C" void xmm_alloc(struct image_himem *m);
    6.44  extern u32 topmem;
    6.45  extern "C" u32 memtopz();
     7.1 --- a/linld/stuff/src/CRTL.ASM	Fri Mar 17 15:14:21 2017 +0200
     7.2 +++ b/linld/stuff/src/CRTL.ASM	Fri Mar 17 15:18:10 2017 +0100
     7.3 @@ -5,7 +5,11 @@
     7.4                  %crefref
     7.5                  %noincl
     7.6                  %nomacs
     7.7 +		ifdef	NO386
     7.8 +                p8086
     7.9 +		else
    7.10                  p386
    7.11 +		endif
    7.12  
    7.13          group   DGROUP  _TEXT,_DATA,_BSS
    7.14          assume  cs:DGROUP,ds:DGROUP
    7.15 @@ -18,7 +22,10 @@
    7.16  msg_hang	db      "High mem corrupted - not exiting to DOS"
    7.17  msg_crlf	db	13,10,0
    7.18  vcpi_alloc_err	db	"vcpi "
    7.19 -msg_malloc      db      "malloc() failure",0
    7.20 +msg_malloc      db      "malloc failure",0
    7.21 +	ifdef	EXTRA
    7.22 +tazboot_cmd	db	"tazboot.cmd",0
    7.23 +	endif
    7.24  
    7.25          ends    _DATA
    7.26  
    7.27 @@ -28,6 +35,12 @@
    7.28  _no_exit	db	?
    7.29  filecnt		db	?		; in fact 0 minus file count...
    7.30  nextfilename	dw	?
    7.31 +	ifdef	LARGE_IMAGES
    7.32 +curdata		dw	?
    7.33 +	endif
    7.34 +	ifdef	EXTRA
    7.35 +ultoabuf	db	12	dup (?)
    7.36 +	endif
    7.37  
    7.38          ends    _BSS
    7.39  
    7.40 @@ -35,12 +48,23 @@
    7.41  
    7.42  ;***************************************************************
    7.43  ;char* strcpy(const char* a, const char* b);
    7.44 +;char* strcat(const char* a, const char* b);
    7.45 +;char* strcatb(const char* a, const char* b);
    7.46  ;***************************************************************
    7.47 +        global  _strcatb:near
    7.48 +        proc    _strcatb near
    7.49 +
    7.50 +	ifdef	EXTRA
    7.51 +		mov	dl,3
    7.52 +		db	0bbh			; mov	bx,imm opcode
    7.53 +        global  _strcat:near
    7.54 +_strcat:
    7.55 +		mov	dl,1
    7.56 +		db	0bbh			; mov	bx,imm opcode
    7.57          global  _strcpy:near
    7.58 -        proc    _strcpy near
    7.59 -
    7.60 +_strcpy:
    7.61  		mov	dl,0
    7.62 -cat:
    7.63 +	endif
    7.64  		pop	ax			;caller return address
    7.65                  pop	cx			; a
    7.66                  pop	bx			; b
    7.67 @@ -49,15 +73,19 @@
    7.68                  push	ax
    7.69                  push	si
    7.70                  mov	si,cx
    7.71 +	ifdef	EXTRA
    7.72  		shr	dl,1
    7.73  		jnc	@@nocat
    7.74 +	endif
    7.75  @@catlp:
    7.76  		lodsb
    7.77  		cmp	al,0
    7.78                  jne	@@catlp
    7.79  		dec	si
    7.80 +	ifdef	EXTRA
    7.81  		shr	dl,1
    7.82  		jnc	@@nocat
    7.83 +	endif
    7.84  		cmp	cx,si
    7.85  		jz	@@nocat
    7.86  		mov	[word si],20h
    7.87 @@ -74,30 +102,6 @@
    7.88                  pop	si
    7.89                  ret
    7.90  
    7.91 -        endp    _strcpy
    7.92 -
    7.93 -
    7.94 -;***************************************************************
    7.95 -;char* strcat(const char* a,const char* b);
    7.96 -;***************************************************************
    7.97 -        global  _strcat:near
    7.98 -        proc    _strcat near
    7.99 -
   7.100 -		mov	dl,1
   7.101 -                jmp	cat
   7.102 -
   7.103 -        endp    _strcat
   7.104 -
   7.105 -
   7.106 -;***************************************************************
   7.107 -;char* strcatb(const char* a,const char* b);
   7.108 -;***************************************************************
   7.109 -        global  _strcatb:near
   7.110 -        proc    _strcatb near
   7.111 -
   7.112 -		mov	dl,3
   7.113 -                jmp	cat
   7.114 -
   7.115          endp    _strcatb
   7.116  
   7.117  
   7.118 @@ -112,13 +116,13 @@
   7.119  		push	cx
   7.120  		push	ax
   7.121          global  malloc:near			; malloc(cx)
   7.122 -malloc:
   7.123 +malloc:						; keep CX, use AX,BX
   7.124  		mov	ax,[_heap_top]
   7.125 +		mov	bx,-1400h		; MIN_STACK=_1k+PAGE_SIZE
   7.126 +		add	bx,sp
   7.127 +		sub	bx,ax			; can't overflow
   7.128 +		cmp	bx,cx
   7.129  		mov	bx,offset msg_malloc
   7.130 -		mov	dx,-1400h		; MIN_STACK=_1k+PAGE_SIZE
   7.131 -		add	dx,sp
   7.132 -		sub	dx,ax			; can't overflow
   7.133 -		cmp	dx,cx
   7.134  		jb	puts
   7.135  		add	[_heap_top],cx		; _BEG has zero'd heap
   7.136  		;mov	bx,ax
   7.137 @@ -133,7 +137,6 @@
   7.138  
   7.139  ;***************************************************************
   7.140  ;void puts(const char* s):
   7.141 -;void putsz(const char* s):
   7.142  ;***************************************************************
   7.143          global  _puts:near
   7.144          proc    _puts near
   7.145 @@ -146,14 +149,7 @@
   7.146  puts:
   7.147  		call	putsz
   7.148                  mov	bx,offset msg_crlf
   7.149 -		jmp	putsz
   7.150  
   7.151 -        global  _putsz:near
   7.152 -_putsz:
   7.153 -		pop	ax			;caller return address
   7.154 -                pop	bx			; s
   7.155 -                push	bx
   7.156 -                push	ax
   7.157          global  putsz:near			; putsz(bx)
   7.158  putsz:
   7.159                  push	bx
   7.160 @@ -169,6 +165,29 @@
   7.161          endp    _puts
   7.162  
   7.163  
   7.164 +		ifdef	EXTRA
   7.165 +;***************************************************************
   7.166 +;int chdir(char *path);
   7.167 +;***************************************************************
   7.168 +        global  _chdir:near
   7.169 +        proc    _chdir near
   7.170 +
   7.171 +		pop	ax
   7.172 +		pop	dx
   7.173 +		push	dx
   7.174 +		push	ax
   7.175 +chdir:
   7.176 +		stc
   7.177 +		mov	ax,713Bh
   7.178 +		int	21h
   7.179 +		jnc	chkc
   7.180 +		mov	ah,3Bh
   7.181 +		jmp	dos
   7.182 +
   7.183 +        endp    _chdir
   7.184 +		endif
   7.185 +
   7.186 +
   7.187  ;***************************************************************
   7.188  ;int fileattr(const char* name);
   7.189  ;***************************************************************
   7.190 @@ -241,83 +260,111 @@
   7.191  
   7.192  ;***************************************************************
   7.193  ;int read(int fd, void* data, int sz);
   7.194 +;int write(int fd, const void* data, int sz);
   7.195  ;***************************************************************
   7.196          global  _read:near
   7.197          proc    _read near
   7.198  
   7.199 -                mov	ah,3fh
   7.200 -rwio:
   7.201 -		ifndef	NO386
   7.202 -		pop	dx			;caller return address
   7.203 -                pop	ebx			; fd & data
   7.204 +                stc
   7.205 +		db	0B0h			; mov al,im
   7.206 +        global  _write:near
   7.207 +                clc
   7.208 +		pop	ax			;caller return address
   7.209 +                pop	bx			; fd
   7.210 +                pop	dx			; data
   7.211                  pop	cx			; sz
   7.212                  push	cx
   7.213 -                push	ebx
   7.214                  push	dx
   7.215 -		else
   7.216 -		mov	bx,sp
   7.217 -		mov	cx,[bx+6]
   7.218 -		mov	dx,[bx+4]
   7.219 -		mov	bx,[bx+2]
   7.220 -		endif
   7.221 -                clc
   7.222 +                push	bx
   7.223 +                push	ax
   7.224 +                mov	ah,40h
   7.225 +		sbb	ah,0
   7.226                  jcxz	fail
   7.227 -rwioz:
   7.228 -		ifndef	NO386
   7.229 -                push	ebx
   7.230 -                pop	bx
   7.231 -                pop	dx
   7.232 -		endif
   7.233  		jmp	dos
   7.234  
   7.235          endp    _read
   7.236  
   7.237 +		ifdef	EXTRA 
   7.238 +;***************************************************************
   7.239 +;long lseekset(int fd, unsigned long sz);
   7.240 +;***************************************************************
   7.241 +        global  _lseekset:near
   7.242 +        proc    _lseekset near
   7.243  
   7.244 -;***************************************************************
   7.245 -;int write(int fd, const void* data, int sz);
   7.246 -;***************************************************************
   7.247 -        global  _write:near
   7.248 -        proc    _write near
   7.249 -
   7.250 -                mov	ah,40h
   7.251 -		jmp	rwio
   7.252 -
   7.253 -        endp    _write
   7.254 -
   7.255 -
   7.256 -;***************************************************************
   7.257 -;long lseek(int fd, long sz, int dir);
   7.258 -;***************************************************************
   7.259 -        global  _lseek:near
   7.260 -        proc    _lseek near
   7.261 -
   7.262 -		ifndef	NO386
   7.263  		pop	ax			;caller return address
   7.264                  pop	bx			; fd
   7.265 -                pop	ecx			; sz
   7.266 -                pop	dx			; dir
   7.267 +                pop	dx			; sz lo
   7.268 +                pop	cx			; sz hi
   7.269 +                push	cx
   7.270                  push	dx
   7.271 -                push	ecx
   7.272 +
   7.273 +		else
   7.274 +;***************************************************************
   7.275 +;long seekset(int fd, unsigned sz);
   7.276 +;***************************************************************
   7.277 +        global  _seekset:near
   7.278 +        proc    _seekset near
   7.279 +
   7.280 +		xor	cx,cx
   7.281 +		pop	ax			;caller return address
   7.282 +                pop	bx			; fd
   7.283 +                pop	dx			; sz
   7.284 +                push	dx
   7.285 +		endif
   7.286 +
   7.287                  push	bx
   7.288                  push	ax
   7.289 -		else
   7.290 -		mov	bx,sp
   7.291 -		mov	dx,[bx+8]
   7.292 -		mov	cx,[bx+6]
   7.293 -		mov	ax,[bx+4]
   7.294 -		mov	bx,[bx+2]
   7.295 -		endif
   7.296 -lseek:
   7.297 -		xchg	ax,dx			; dir
   7.298 -                mov	ah,42h
   7.299 -		ifndef	NO386
   7.300 -                push	ecx
   7.301 -                pop	dx
   7.302 -                pop	cx
   7.303 -		endif
   7.304 +        global  lseekset:near
   7.305 +lseekset:
   7.306 +		clc
   7.307 +		db	0B0h			; mov al,im
   7.308 +        global  rewind:near
   7.309 +rewind:						; rewind(bx)
   7.310 +		stc
   7.311 +		mov	ax,4200h
   7.312 +		jnc	dos
   7.313 +lseek0:						; lseek0(bx,ax=dir)
   7.314 +		cwd
   7.315 +		xor	cx,cx
   7.316  		jmp	dos
   7.317  
   7.318 -        endp    _lseek
   7.319 +		ifdef	EXTRA 
   7.320 +        endp    _lseekset
   7.321 +		else
   7.322 +        endp    _seekset
   7.323 +		endif
   7.324 +
   7.325 +		ifdef	EXTRA
   7.326 +struc		isostate	; struct isostate {
   7.327 +fd		dw	?	; 0	int fd;
   7.328 +fileofs		dd	?	; 2	unsigned long fileofs;
   7.329 +filesize	dd	?	; 6	unsigned long filesize;
   7.330 +filemod		dw	?	;10	unsigned short filemod;
   7.331 +filename	dw	?	;12	char *filename;
   7.332 +dirofs		dd	?	;14	unsigned long dirofs;
   7.333 +dirsize		dd	?	;16	unsigned long dirsize;
   7.334 +curdirofs	dd	?	;20	unsigned long curdirofs;
   7.335 +curdirsize	dd	?	;24	unsigned long curdirsize;
   7.336 +curpos		dd	?	;28	unsigned long curpos;
   7.337 +ends				; } isostate;
   7.338 +;***************************************************************
   7.339 +;unsigned long isolseek(const unsigned long *offset);
   7.340 +;***************************************************************
   7.341 +        global  _isolseek:near
   7.342 +        proc    _isolseek near
   7.343 +
   7.344 +		pop	ax
   7.345 +		pop	bx
   7.346 +		push	bx
   7.347 +		push	ax
   7.348 +		mov	dx,[bx]
   7.349 +		mov	cx,[bx+2]
   7.350 +		extrn	_isostate:isostate
   7.351 +		mov	bx,[_isostate.fd]
   7.352 +		jmp	lseekset		; (bx=fd, sz=cx:dx)
   7.353 +		
   7.354 +        endp    _isolseek
   7.355 +		endif
   7.356  
   7.357  
   7.358  ;***************************************************************
   7.359 @@ -354,24 +401,23 @@
   7.360          proc    _strhead near
   7.361  
   7.362  		pop	cx			;caller return address
   7.363 -                pop	ax			; a
   7.364 -                pop	bx			; b
   7.365 +                pop	bx			; a
   7.366 +                pop	ax			; b
   7.367 +                push	ax
   7.368                  push	bx
   7.369 -                push	ax
   7.370                  push	cx
   7.371  @@loop:
   7.372 +		xchg	ax,bx
   7.373                  mov	cl,[bx]			; cl = *b++
   7.374                  inc	bx
   7.375  		or	cl,cl			; clear C
   7.376  		jz	fail			; return 0
   7.377  		xchg	ax,bx
   7.378                  xor	cl,[bx]			; cl -= *a++
   7.379 +                inc	bx
   7.380  		and	cl,0dfh			; case insensitive
   7.381 -		stc
   7.382 -		jnz	fail			; return -1
   7.383 -                inc	bx
   7.384 -		xchg	ax,bx
   7.385 -                jmp	@@loop
   7.386 +                jz	@@loop
   7.387 +		ret				; return b (is not 0)
   7.388  
   7.389          endp    _strhead
   7.390  
   7.391 @@ -445,97 +491,11 @@
   7.392  ends				;};
   7.393  
   7.394  ;***************************************************************
   7.395 -;u32* malloc_bufv_or_die(struct image_himem *m);
   7.396 +;void next_chunk(struct image_himem *di);
   7.397  ;***************************************************************
   7.398 -        global  _malloc_bufv_or_die:near
   7.399 -        proc    _malloc_bufv_or_die near
   7.400 +        proc    next_chunk near
   7.401  
   7.402 -		pop	bx			;caller return address
   7.403 -		pop	ax
   7.404 -		push	ax
   7.405 -		push	bx
   7.406  		push	si
   7.407 -		xchg	ax,si
   7.408 -		mov	ecx,[(image_himem si).size]
   7.409 -		dec	ecx
   7.410 -		shr	ecx,12
   7.411 -		inc	cx			; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
   7.412 -		push	cx
   7.413 -		inc	cx			; cnt+1
   7.414 -		shl	cx,2			; bufv => vcpi => vm86
   7.415 -; our malloc zeroes allocated mem: bufv[cnt]=0;
   7.416 -; Allocate pages, storing addrs in addrbuf
   7.417 -		call	malloc_or_die
   7.418 -                pop	cx
   7.419 -		push	cx			; _sort:nel
   7.420 -		push	ax			; _sort:base
   7.421 -		mov	[(image_himem si).bufv],ax
   7.422 -		xchg	ax,bx
   7.423 -@@vcpi_alloc:
   7.424 -                xor     edx,edx
   7.425 -                mov     ax,0DE04h
   7.426 -                int     67h
   7.427 -		or	ah,ah
   7.428 -		jz	@@ok
   7.429 -		mov	bx,offset vcpi_alloc_err
   7.430 -		jmp	die
   7.431 -@@ok:
   7.432 -		mov	[bx],edx
   7.433 -		add	bx,4
   7.434 -		loop	@@vcpi_alloc
   7.435 -@@again:
   7.436 -		call	_sort
   7.437 -		extrn	_initrd
   7.438 -		cmp	si,offset _initrd
   7.439 -		jne	@@quit
   7.440 -		pop	ax
   7.441 -		pop	cx
   7.442 -		push	cx			; _sort:nel
   7.443 -		push	ax			; _sort:base = m->bufv
   7.444 -;again:
   7.445 -; for (i = cnt-1; i >= 0; i--) {
   7.446 -@@chkloop:
   7.447 -		mov	bx,cx
   7.448 -		dec	bx
   7.449 -;   if  (m->bufv[i] > m->fallback+i*_4k && m->bufv[i] < m->fallback+m->size) {
   7.450 -		shl	bx,2
   7.451 -		add	bx,ax			; m->bufv
   7.452 -		mov	edx,[bx]		; m->bufv[i]
   7.453 -		sub	edx,[(image_himem si).fallback]
   7.454 -		cmp	edx,[(image_himem si).size]
   7.455 -		jae	@@chknext
   7.456 -		shr	edx,12
   7.457 -		cmp	dx,cx
   7.458 -		jb	@@chknext
   7.459 -;     m->bufv[i] = vcpi_alloc_or_die();
   7.460 -;     sort(m->bufv,cnt);
   7.461 -;     goto again;
   7.462 -		mov	cx,1
   7.463 -		jmp	@@vcpi_alloc
   7.464 -;   }
   7.465 -; }
   7.466 -@@chknext:
   7.467 -		loop	@@chkloop
   7.468 -@@quit:
   7.469 -		pop	ax
   7.470 -		pop	cx
   7.471 -		pop	si
   7.472 -		ret
   7.473 -
   7.474 -        endp    _malloc_bufv_or_die
   7.475 -
   7.476 -
   7.477 -;***************************************************************
   7.478 -;void next_chunk(struct image_himem *m);
   7.479 -;***************************************************************
   7.480 -        proc    _next_chunk near
   7.481 -
   7.482 -		pop	bx
   7.483 -		pop	ax
   7.484 -		push	ax
   7.485 -		push	bx
   7.486 -		push	si di
   7.487 -		xchg	ax,di
   7.488  		mov	bx,[(image_himem di).fd]
   7.489  		call	close
   7.490  		ifndef	NO386
   7.491 @@ -567,44 +527,352 @@
   7.492  		jc	@@die
   7.493  		mov	[(image_himem di).fd],ax
   7.494  		mov	[(image_himem di).fd2close],ax
   7.495 -		mov	dx,2			; SEEK_END
   7.496  		xchg	ax,bx
   7.497 -		ifndef	NO386
   7.498 -		xor	ecx,ecx
   7.499 -		else
   7.500 -		xor	ax,ax
   7.501 -		xor	cx,cx
   7.502 -		endif
   7.503 -		call	lseek
   7.504 +		mov	ax,4202h		; SEEK_END
   7.505 +		call	lseek0
   7.506  @@die:
   7.507  		mov	bx,[(image_himem di).errmsg]
   7.508  		jc	die
   7.509  		mov	bx,[(image_himem di).fd]
   7.510  		ifndef	NO386
   7.511  		push	eax
   7.512 -		xor	ecx,ecx
   7.513 -		xor	dx,dx
   7.514 -		call	lseek			; rewind
   7.515 +		call	rewind
   7.516  		pop	eax
   7.517  @@end:
   7.518  		mov	[(image_himem di).chunk_size],eax
   7.519  		else
   7.520  		push	ax
   7.521  		push	dx
   7.522 -		xor	ax,ax
   7.523 -		xor	cx,cx
   7.524 -		cwd
   7.525 -		call	lseek			; rewind
   7.526 +		call	rewind
   7.527  		pop	dx
   7.528  		pop	ax
   7.529  @@end:
   7.530  		mov	[word (image_himem di).chunk_size],ax
   7.531  		mov	[word ((image_himem di).chunk_size)+2],dx
   7.532  		endif
   7.533 -		pop	di si
   7.534 +		pop	si
   7.535  		ret
   7.536  
   7.537 -        endp    _next_chunk
   7.538 +        endp    next_chunk
   7.539 +
   7.540 +
   7.541 +	ifdef	LARGE_IMAGES
   7.542 +struc   data_himem			;struct data_himem {
   7.543 +first		dd	?		;   0  u32 first;
   7.544 +cacheidx	dw	?		;   4  int cacheidx;
   7.545 +pageidx		dw	?		;   6  int pageidx;
   7.546 +cache		dd	1024 dup(?)	;   8  int cache;
   7.547 +page		dd	1024 dup(?)	;4104  int page;
   7.548 +ends					;}; // size=8200
   7.549 +	endif
   7.550 +
   7.551 +;***************************************************************
   7.552 +;u32* malloc_bufv_or_die(struct image_himem *m);
   7.553 +;***************************************************************
   7.554 +        global  _malloc_bufv_or_die:near
   7.555 +        proc    _malloc_bufv_or_die near
   7.556 +
   7.557 +                p386
   7.558 +		pop	bx			;caller return address
   7.559 +		pop	ax
   7.560 +		push	ax
   7.561 +		push	bx
   7.562 +		push	si
   7.563 +		xchg	ax,si
   7.564 +	ifdef	LARGE_IMAGES
   7.565 +		mov	cx,[word ((image_himem si).size) + 2]
   7.566 +		shr	cx,4			; pages index size = size >> 20
   7.567 +		add	cx,8+4096+8
   7.568 +		call	malloc_or_die
   7.569 +		mov	ecx,4096+4095		; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
   7.570 +		add	ecx,[(image_himem si).size]
   7.571 +		shr	ecx,12
   7.572 +		mov	[curdata],ax
   7.573 +	else
   7.574 +		mov	ecx,[(image_himem si).size]
   7.575 +		dec	ecx
   7.576 +		shr	ecx,12
   7.577 +		inc	cx			; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
   7.578 +		push	cx
   7.579 +		inc	cx			; cnt+1
   7.580 +		shl	cx,2			; bufv => vcpi => vm86
   7.581 +; our malloc zeroes allocated mem: bufv[cnt]=0;
   7.582 +; Allocate pages, storing addrs in addrbuf
   7.583 +		call	malloc_or_die
   7.584 +		pop	cx
   7.585 +		push	ax
   7.586 +	endif
   7.587 +		mov	[(image_himem si).bufv],ax
   7.588 +		xchg	ax,si
   7.589 +@@vcpi_alloc:
   7.590 +                xor     edx,edx
   7.591 +                mov     ax,0DE04h
   7.592 +                int     67h
   7.593 +		or	ah,ah
   7.594 +		mov	bx,offset vcpi_alloc_err
   7.595 +		jnz	die
   7.596 +; for (i = cnt-1; i >= 0; i--)
   7.597 +	ifdef	LARGE_IMAGES
   7.598 +		mov	eax,ecx
   7.599 +		dec	eax
   7.600 +	else
   7.601 +		mov	ax,cx
   7.602 +		dec	ax
   7.603 +		cwde
   7.604 +	endif
   7.605 +		shl	eax,12		; i*_4k
   7.606 +; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
   7.607 +		extrn	_pm
   7.608 +		mov	bx,offset _pm+2
   7.609 +		push	eax
   7.610 +		add	eax,[bx-2+2]
   7.611 +		cmp	eax,edx		; pm.fallback+i*_4k <= edx ?
   7.612 +		pop	eax		; i*_4k
   7.613 +		jbe	@@pmok
   7.614 +		cmp	edx,[bx-2+2]	; edx >= pm.fallback ?
   7.615 +		jae	@@vcpi_alloc
   7.616 +@@pmok:
   7.617 +; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
   7.618 +		extrn	_initrd
   7.619 +		mov	bx,offset _initrd+2
   7.620 +		add	eax,[bx-2+2]	; +initrd.fallback
   7.621 +		cmp	eax,edx		; initrd.fallback+i*_4k > edx ?
   7.622 +		ja	@@initrdok
   7.623 +		mov	eax,[bx-2+6]	; initrd.size
   7.624 +		add	eax,[bx-2+2]	; +initrd.fallback
   7.625 +		cmp	eax,edx		; initrd.fallback+initrd.size > edx ?
   7.626 +@@jnc_vcpi_alloc:
   7.627 +		ja	@@vcpi_alloc
   7.628 +@@initrdok:
   7.629 +	ifdef	LARGE_IMAGES
   7.630 +		cmp	[(data_himem si).first],0
   7.631 +		jne	@@notfirst
   7.632 +		mov	[(data_himem si).first],edx
   7.633 +@@notfirst:
   7.634 +		mov	bx,[(data_himem si).cacheidx]
   7.635 +		cmp	bh,4
   7.636 +		jae	@@nextpage
   7.637 +		shl	bx,2
   7.638 +		inc	[(data_himem si).cacheidx]
   7.639 +		mov	[(data_himem bx+si).cache],edx
   7.640 +		loopd	@@vcpi_alloc
   7.641 +		mov	[(data_himem bx+si).cache],ecx	; last is 0
   7.642 +@@nextpage:
   7.643 +		and	[(data_himem si).cacheidx],0
   7.644 +		mov	bx,[(data_himem si).pageidx]
   7.645 +		mov	[(data_himem bx+si).page],edx
   7.646 +		add	[(data_himem si).pageidx],4
   7.647 +		push	cx
   7.648 +		lea	cx,[(data_himem si).cache]
   7.649 +		ifdef	NO386
   7.650 +		push	edx
   7.651 +		pop	dx
   7.652 +		pop	ax
   7.653 +		endif
   7.654 +		call	storepage		; storepage(edx,cx)	
   7.655 +		pop	cx
   7.656 +		or	ecx,ecx			; clear C
   7.657 +		jnz	@@jnc_vcpi_alloc
   7.658 +		mov	[dword (data_himem si).cacheidx],ecx
   7.659 +		xchg	ax,si
   7.660 +	else
   7.661 +		mov	[si],edx
   7.662 +		lodsd				; si=+4
   7.663 +		loop	@@vcpi_alloc
   7.664 +		pop	ax
   7.665 +	endif
   7.666 +		pop	si
   7.667 +		ret
   7.668 +		ifdef	NO386
   7.669 +                p8086
   7.670 +		endif
   7.671 +
   7.672 +        endp    _malloc_bufv_or_die
   7.673 +
   7.674 +
   7.675 +;***************************************************************
   7.676 +; void memcpy_image(struct image_himem *m);
   7.677 +;***************************************************************
   7.678 +        global  _memcpy_image:near
   7.679 +        proc    _memcpy_image near
   7.680 +
   7.681 +		pop	ax			;caller return address
   7.682 +		pop	bx
   7.683 +		push	bx
   7.684 +		push	ax
   7.685 +		ifndef	NO386
   7.686 +		mov	edx,[(image_himem bx).fallback]
   7.687 +		mov	eax,[(image_himem bx).buf]
   7.688 +		cmp	eax,edx			; if (m->fallback != m->buf)
   7.689 +		jz	@@skip			;   memcpy32(m->fallback,0,m->buf,m->size)
   7.690 +	ifdef	LARGE_IMAGES
   7.691 +		mov	ecx,[(image_himem bx).size]
   7.692 +memcpy_imagez:
   7.693 +		push	ecx
   7.694 +	else
   7.695 +		push	[(image_himem bx).size]
   7.696 +	endif
   7.697 +		push	eax
   7.698 +		push	0
   7.699 +call_memcpy32:
   7.700 +		push	edx
   7.701 +		else
   7.702 +		mov	ax,[word ((image_himem bx).fallback)]
   7.703 +		mov	dx,[word ((image_himem bx).fallback)+2]
   7.704 +		mov	cx,[word ((image_himem bx).buf)]
   7.705 +		cmp	ax,cx			; if (m->fallback != m->buf)
   7.706 +		jnz	@@do
   7.707 +		cmp	dx,[word ((image_himem bx).buf)+2]
   7.708 +		jz	@@skip			;   memcpy32(m->fallback,0,m->buf,m->size)
   7.709 +@@do:
   7.710 +		push	[word ((image_himem bx).size)+2]
   7.711 +		push	[word ((image_himem bx).size)]
   7.712 +		push	[word ((image_himem bx).buf)+2]
   7.713 +		push	cx
   7.714 +		xor	cx,cx
   7.715 +		push	cx
   7.716 +call_memcpy32:
   7.717 +		push	dx
   7.718 +		push	ax
   7.719 +	ifdef	LARGE_IMAGES
   7.720 +		jmp	@@memcpy
   7.721 +memcpy_imagez:
   7.722 +		p386
   7.723 +		push	ecx
   7.724 +		push	eax
   7.725 +		push	0
   7.726 +		push	edx
   7.727 +		ifdef	NO386
   7.728 +                p8086
   7.729 +		endif
   7.730 +	endif
   7.731 +		endif
   7.732 +@@memcpy:
   7.733 +		extrn	_memcpy32:near
   7.734 +		call	near _memcpy32
   7.735 +		add	sp,14
   7.736 +@@skip:
   7.737 +		ret
   7.738 +
   7.739 +        endp    _memcpy_image
   7.740 +
   7.741 +;***************************************************************
   7.742 +;void storepage(u32 *dst, u16 src);
   7.743 +;***************************************************************
   7.744 +        global  _storepage:near
   7.745 +        proc    _storepage near
   7.746 +
   7.747 +		pop	ax			;caller return address
   7.748 +		pop	bx
   7.749 +		pop	cx
   7.750 +		push	cx
   7.751 +		push	bx
   7.752 +		push	ax
   7.753 +		ifndef	NO386
   7.754 +		mov	edx,[bx]
   7.755 +		else
   7.756 +		mov	ax,[bx]
   7.757 +		mov	dx,[bx+2]
   7.758 +		endif
   7.759 +storepage:
   7.760 +		ifndef	NO386
   7.761 +		push	0
   7.762 +		push	4096
   7.763 +		push	0
   7.764 +		else
   7.765 +		xor	bx,bx
   7.766 +		push	bx
   7.767 +		mov	bh,4096/256
   7.768 +		push	bx
   7.769 +		xor	bx,bx
   7.770 +		push	bx
   7.771 +		endif
   7.772 +		push	cx
   7.773 +		push	ds
   7.774 +		jmp	call_memcpy32
   7.775 +
   7.776 +        endp    _storepage
   7.777 +
   7.778 +
   7.779 +	ifdef	LARGE_IMAGES
   7.780 +                p386
   7.781 +;***************************************************************
   7.782 +;void reset_bufv(u32 *p);
   7.783 +;***************************************************************
   7.784 +        global  _reset_bufv:near
   7.785 +        proc    _reset_bufv near
   7.786 +
   7.787 +		pop	ax			;caller return address
   7.788 +		pop	bx
   7.789 +		push	bx
   7.790 +		push	ax
   7.791 +		mov	[curdata],bx
   7.792 +		and	[dword (data_himem bx).cacheidx],0
   7.793 +		ret
   7.794 +
   7.795 +        endp    _reset_bufv
   7.796 +
   7.797 +;***************************************************************
   7.798 +;u32* prev_bufv();
   7.799 +;u32* prev_bufv();
   7.800 +;***************************************************************
   7.801 +        global  _prev_bufv:near
   7.802 +        global  _next_bufv:near
   7.803 +        proc    _prev_bufv near
   7.804 +
   7.805 +		stc
   7.806 +		db	73h			; jnc
   7.807 +_next_bufv:
   7.808 +		clc
   7.809 +		sbb	ax,ax
   7.810 +		stc
   7.811 +		rcl	ax,1			; -1/+1
   7.812 +		xor	ecx,ecx
   7.813 +		push	si
   7.814 +		mov	si,[curdata]
   7.815 +		add	ax,[(data_himem si).cacheidx]
   7.816 +		test	ax,0fc00h
   7.817 +		jz	@@gotpage
   7.818 +		push	ax			; FFFF / 0400
   7.819 +		sar	ax,8			; FFFC / 0004
   7.820 +		and	al,0fch
   7.821 +		add	[(data_himem si).pageidx],ax
   7.822 +		mov	bx,[(data_himem si).pageidx]
   7.823 +		lea	bx,[(data_himem bx+si).page]
   7.824 +		mov	edx,ds
   7.825 +		shl	edx,4
   7.826 +		lea	cx,[(data_himem si).cache]		
   7.827 +		add	edx,ecx
   7.828 +		mov	eax,[bx]
   7.829 +		or	eax,eax
   7.830 +		jnz	@@pageok
   7.831 +		pop	ax
   7.832 +		xchg	ax,bx
   7.833 +		pop	si
   7.834 +		ret
   7.835 +@@pageok:
   7.836 +		mov	cx,4096
   7.837 +		call	memcpy_imagez		; get page
   7.838 +		pop	ax			; FFFF / 0400
   7.839 +		cbw
   7.840 +		shr	ax,6			; 03FF / 0000
   7.841 +@@gotpage:
   7.842 +		mov	[(data_himem si).cacheidx],ax
   7.843 +		shl	ax,2
   7.844 +		xchg	ax,bx
   7.845 +		lea	ax,[(data_himem bx+si).cache]		
   7.846 +		or	bx,[(data_himem si).pageidx]	; !pageidx && !cacheidx
   7.847 +		jnz	@@notfirst2
   7.848 +		xchg	ax,si				; &first
   7.849 +@@notfirst2:
   7.850 +		pop	si
   7.851 +		ret
   7.852 +		ifdef	NO386
   7.853 +                p8086
   7.854 +		endif
   7.855 +
   7.856 +        endp    _prev_bufv
   7.857 +	endif
   7.858  
   7.859  
   7.860  ;***************************************************************
   7.861 @@ -633,7 +901,7 @@
   7.862  		mov	[word (image_himem di).size],ax	; m->size = 0L
   7.863  		mov	[word ((image_himem di).size)+2],ax
   7.864  		endif
   7.865 -		mov	[(image_himem di).next_chunk],offset _next_chunk
   7.866 +		mov	[(image_himem di).next_chunk],offset next_chunk
   7.867                  mov	si,[fname]
   7.868                  mov	[(image_himem di).state],si
   7.869  @@next:
   7.870 @@ -724,7 +992,6 @@
   7.871  		xor	cx,cx
   7.872  		ifndef	NO386
   7.873  		cwde				; ax < 8000h
   7.874 -		cwd
   7.875  		sub	[(image_himem di).chunk_size],eax
   7.876  		else
   7.877  		cwd				; ax < 8000h
   7.878 @@ -778,29 +1045,30 @@
   7.879  		push	cx
   7.880  		push	ax
   7.881  		xor	ebx,ebx
   7.882 -		jcxz	@@jncend
   7.883  		push	si
   7.884 +		jcxz	@@end
   7.885  		mov	si,cx
   7.886  		xor	ecx,ecx
   7.887  		xor	eax,eax
   7.888  		lodsb
   7.889 -		mov	dl,20h
   7.890 -		or	dl,al
   7.891 -		cmp	dl,'n'			; vga=normal
   7.892 +		mov	dx,ax
   7.893 +		or	al,20h
   7.894 +		cmp	al,'n'			; vga=normal
   7.895  		je	@@vga
   7.896  		dec	cx
   7.897 -		cmp	dl,'e'			; vga=extended
   7.898 +		cmp	al,'e'			; vga=extended
   7.899  		je	@@vga
   7.900  		dec	cx
   7.901 -		cmp	dl,'a'			; vga=ask
   7.902 +		cmp	al,'a'			; vga=ask
   7.903  		jne	@@notvga
   7.904  @@vga:
   7.905  		dec	cx
   7.906  		xchg	ax,cx
   7.907  		cwd
   7.908 -		jmp	popsiret
   7.909 +		jmp	@@popsiret
   7.910  @@notvga:
   7.911  		mov	cx,10			; radix
   7.912 +		xchg	ax,dx
   7.913  		cmp	al,'+'
   7.914  		je	@@radixskip
   7.915  		cmp	al,'-'
   7.916 @@ -815,19 +1083,18 @@
   7.917  		jne	@@radixok
   7.918  		mov	cl,8
   7.919  		lodsb
   7.920 -		mov	dl,20h
   7.921 -		or	dl,al
   7.922 -		cmp	dl,'x'
   7.923 +		or	al,20h
   7.924 +		cmp	al,'x'
   7.925  		jne	@@radixok
   7.926  		mov	cl,16
   7.927  @@strtollp:
   7.928  		lodsb
   7.929  @@radixok:
   7.930 +		or	al,20h
   7.931  		sub	al,'0'
   7.932  		jb	@@endstrtol
   7.933  		cmp	al,9
   7.934  		jbe	@@digitok
   7.935 -		or	al,20h
   7.936  		cmp	al,'a'-'0'
   7.937  		jb	@@endstrtol
   7.938  		sub	al,'a'-'0'-10
   7.939 @@ -853,14 +1120,13 @@
   7.940  		shl	ebx,cl
   7.941  @@noshift:
   7.942  		popf
   7.943 -@@jncend:
   7.944  		jnc	@@end
   7.945  		neg	ebx
   7.946  @@end:
   7.947  		push	ebx
   7.948  		pop	ax
   7.949  		pop	dx
   7.950 -popsiret:
   7.951 +@@popsiret:
   7.952  		pop	si
   7.953  		else
   7.954  		pop	ax			;caller return address
   7.955 @@ -871,29 +1137,28 @@
   7.956  		push	di
   7.957  		xor	ax,ax
   7.958  		cwd
   7.959 +		jcxz	@@goend
   7.960  		xchg	ax,di
   7.961 -		jcxz	@@goend
   7.962  		mov	si,cx
   7.963  		lodsb
   7.964 -		mov	dl,20h
   7.965 -		or	dl,al
   7.966 +		mov	bx,ax
   7.967 +		or	al,20h
   7.968  		mov	cx,-1
   7.969 -		cmp	dl,'n'			; vga=normal
   7.970 +		cmp	al,'n'			; vga=normal
   7.971  		je	@@vga
   7.972  		dec	cx
   7.973 -		cmp	dl,'e'			; vga=extended
   7.974 +		cmp	al,'e'			; vga=extended
   7.975  		je	@@vga
   7.976  		dec	cx
   7.977 -		cmp	dl,'a'			; vga=ask
   7.978 +		cmp	al,'a'			; vga=ask
   7.979  		jne	@@notvga
   7.980  @@vga:
   7.981  		xchg	ax,cx
   7.982 -		cwd
   7.983 -		jmp	popsiret
   7.984  @@goend:
   7.985 -		jmp	@@end
   7.986 +		jmp	@@popdisiret
   7.987  @@notvga:
   7.988  		mov	cx,10			; radix
   7.989 +		xchg	ax,bx
   7.990  		cmp	al,'+'
   7.991  		je	@@radixskip
   7.992  		cmp	al,'-'
   7.993 @@ -908,19 +1173,18 @@
   7.994  		jne	@@radixok
   7.995  		mov	cl,8
   7.996  		lodsb
   7.997 -		mov	ah,20h
   7.998 -		or	ah,al
   7.999 -		cmp	ah,'x'
  7.1000 +		mov	al,20h
  7.1001 +		cmp	al,'x'
  7.1002  		jne	@@radixok
  7.1003  		mov	cl,16
  7.1004  @@strtollp:
  7.1005  		lodsb
  7.1006  @@radixok:
  7.1007 +		or	al,20h
  7.1008  		sub	al,'0'
  7.1009  		jb	@@endstrtol
  7.1010  		cmp	al,9
  7.1011  		jbe	@@digitok
  7.1012 -		or	al,20h
  7.1013  		cmp	al,'a'-'0'
  7.1014  		jb	@@endstrtol
  7.1015  		sub	al,'a'-'0'-10
  7.1016 @@ -970,8 +1234,8 @@
  7.1017  		inc	dx
  7.1018  @@end:
  7.1019  		xchg	ax,di
  7.1020 +@@popdisiret:
  7.1021  		pop	di
  7.1022 -popsiret:
  7.1023  		pop	si
  7.1024  		endif
  7.1025  		ret
  7.1026 @@ -979,130 +1243,6 @@
  7.1027          endp    _strtol
  7.1028  
  7.1029  
  7.1030 -;***************************************************************
  7.1031 -;>void sort(unsigned long  *base:BX!, size_t nel:CX)
  7.1032 -;NO386 safe: only used by VCPI
  7.1033 -;***************************************************************
  7.1034 -        global  _sort:near
  7.1035 -        proc    _sort near
  7.1036 -
  7.1037 -		pop	ax			;caller return address
  7.1038 -                pop	bx			; base
  7.1039 -		pop	cx			; nel
  7.1040 -		push	cx
  7.1041 -		push	bx
  7.1042 -		push	ax
  7.1043 -        global  sort:near
  7.1044 -sort:
  7.1045 -	ifndef	fastsort
  7.1046 -;  bubble sort
  7.1047 -		push	si
  7.1048 -		shl	cx,2
  7.1049 -@@loop:
  7.1050 -		xor	ax,ax
  7.1051 -		mov	si,4
  7.1052 -		cmp	cx,si
  7.1053 -		jbe	popsiret
  7.1054 -@@next:
  7.1055 -		mov	edx,[bx+si-4]
  7.1056 -		cmp	edx,[bx+si]
  7.1057 -		jbe	@@ok
  7.1058 -		xchg	edx,[bx+si]
  7.1059 -		mov	[bx+si-4],edx
  7.1060 -		mov	ax,si
  7.1061 -@@ok:
  7.1062 -		add	si,4
  7.1063 -		cmp	si,cx
  7.1064 -		jb	@@next
  7.1065 -		xchg	ax,cx
  7.1066 -		jmp	@@loop
  7.1067 -	else
  7.1068 -;  shell sort (c) uclibc GPL
  7.1069 -		push	si di
  7.1070 -; {
  7.1071 -;>	size_t wgap:SI;
  7.1072 -;
  7.1073 -;	if (nel > 1) {
  7.1074 -		cmp	cx,1
  7.1075 -		jbe	@@end
  7.1076 -;		wgap = 0;
  7.1077 -		xor	ax,ax
  7.1078 -;		do {
  7.1079 -@@wgaplp:
  7.1080 -		mov	si,ax
  7.1081 -;			wgap = 3 * wgap + 1;
  7.1082 -		mov	dx,3
  7.1083 -		mul	dx
  7.1084 -		inc	ax
  7.1085 -;		} while (wgap < (nel-1)/3);
  7.1086 -		cmp	ax,cx
  7.1087 -		jb	@@wgaplp
  7.1088 -;		/* From the above, we know that either wgap == 1 < nel or */
  7.1089 -;		/* ((wgap-1)/3 < (int) ((nel-1)/3) <= (nel-1)/3 ==> wgap <  nel. */
  7.1090 -;		wgap *= 4;			/* So this can not overflow if wnel doesn't. */
  7.1091 -		shl	si,2
  7.1092 -;		nel *= 4;			/* Convert nel to 'wnel' */
  7.1093 -		shl	cx,2
  7.1094 -;		do {
  7.1095 -@@lp1:
  7.1096 -;>	                size_t i:DI;
  7.1097 -;			i = wgap;
  7.1098 -		mov	di,si
  7.1099 -;			do {
  7.1100 -@@lp2:
  7.1101 -;>	                	size_t j:DX;
  7.1102 -;				j = i;
  7.1103 -		mov	dx,di
  7.1104 -;				do {
  7.1105 -@@lp3:
  7.1106 -;>					register char *a:BX!;
  7.1107 -;
  7.1108 -;					j -= wgap;
  7.1109 -		sub	dx,si
  7.1110 -;					a = j + ((char *)base);
  7.1111 -		push	bx
  7.1112 -		add	bx,dx
  7.1113 -;					if (cmp(a, a + wgap) <= 0) {
  7.1114 -		mov	eax,[bx]
  7.1115 -		cmp	eax,[bx+si]
  7.1116 -		jbe	@@brk3
  7.1117 -;						break;
  7.1118 -;					}
  7.1119 -		xchg	eax,[bx+si]
  7.1120 -		mov	[bx],eax
  7.1121 -;					swap(a, a + wgap);
  7.1122 -		pop	bx
  7.1123 -;				} while (j >= wgap);
  7.1124 -		cmp	dx,si
  7.1125 -		jae	@@lp3
  7.1126 -		push	bx
  7.1127 -@@brk3:
  7.1128 -		pop	bx
  7.1129 -;				i += 4;
  7.1130 -		add	di,4
  7.1131 -;			} while (i < nel);
  7.1132 -		cmp	di,cx
  7.1133 -		jb	@@lp2
  7.1134 -;			wgap = (wgap - 4)/3;
  7.1135 -		sub	si,4
  7.1136 -		xchg	ax,si
  7.1137 -		cwd
  7.1138 -		mov	si,3
  7.1139 -		div	si	; kill dx
  7.1140 -		xchg	ax,si
  7.1141 -;		} while (wgap);
  7.1142 -		or	si,si
  7.1143 -		jnz	@@lp1
  7.1144 -@@end:
  7.1145 -;	}
  7.1146 -;}
  7.1147 -		pop	di si
  7.1148 -		ret
  7.1149 -endif
  7.1150 -
  7.1151 -        endp    _sort
  7.1152 -
  7.1153 -
  7.1154  		ifdef	NO386
  7.1155  ;***************************************************************
  7.1156  ;u16 topseg();
  7.1157 @@ -1114,7 +1254,7 @@
  7.1158  		jnc	@@max640k
  7.1159  		mov	ax,640			; 9000
  7.1160  @@max640k:
  7.1161 -		sub	ax,028h
  7.1162 +		dec	ax
  7.1163  		and	al,0C0h
  7.1164  		mov	cl,6
  7.1165  		shl	ax,cl
  7.1166 @@ -1123,44 +1263,270 @@
  7.1167          endp    _topseg
  7.1168  		endif
  7.1169  
  7.1170 +		ifdef	EXTRA
  7.1171 +                p8086
  7.1172 +
  7.1173  ;***************************************************************
  7.1174 -;void rmcpy(void* rmbuf, u16 rmsize);
  7.1175 +;int strcmp(const char* a,const char* b);
  7.1176  ;***************************************************************
  7.1177 -        global  _rmcpy:near
  7.1178 -        proc    _rmcpy near
  7.1179 +        global  _strcmp:near
  7.1180 +        proc    _strcmp near
  7.1181  
  7.1182 -		pop	bx			;caller return address
  7.1183 -                pop	ax			; rmbuf
  7.1184 -		pop	cx			; rmsize
  7.1185 -		push	cx
  7.1186 -		push	ax
  7.1187 -		push	bx
  7.1188 +		pop	cx			;caller return address
  7.1189 +                pop	bx			; a
  7.1190 +                pop	ax			; b
  7.1191 +                push	ax
  7.1192 +                push	bx
  7.1193 +                push	cx
  7.1194 +                push	si
  7.1195 +		xchg	ax,si
  7.1196 +                sub	bx,si
  7.1197 +@@lp:
  7.1198 +                mov	al,[si]
  7.1199 +                sub	al,[bx+si]
  7.1200 +		jnz	@@out
  7.1201 +                lodsb
  7.1202 +		cmp	al,0
  7.1203 +                jne	@@lp
  7.1204 +@@out:
  7.1205 +		cbw
  7.1206 +                pop	si
  7.1207 +                ret
  7.1208 +
  7.1209 +        endp    _strcmp
  7.1210 +
  7.1211 +
  7.1212 +;***************************************************************
  7.1213 +;char strstr(const char* a,const char* b);
  7.1214 +;***************************************************************
  7.1215 +        global  _strstr:near
  7.1216 +        proc    _strstr near
  7.1217 +
  7.1218 +		pop	ax			;caller return address
  7.1219 +                pop	cx			; a
  7.1220 +                pop	dx			; b
  7.1221 +                push	dx
  7.1222 +                push	cx
  7.1223 +                push	ax
  7.1224 +                push	si
  7.1225 +@@loop:
  7.1226 +		xor	ax,ax
  7.1227 +		mov	si,cx
  7.1228 +		cmp	[si],al			; *a
  7.1229 +		jz	@@end			; return ax = NULL
  7.1230 +		mov	bx,dx
  7.1231 +		sub	bx,si
  7.1232 +@@match:
  7.1233 +		or	ah,[bx+si]		; *b
  7.1234 +		jz	@@found
  7.1235 +		lodsb
  7.1236 +		sub	ah,al
  7.1237 +		jz	@@match
  7.1238 +		inc	cx
  7.1239 +		jmp	@@loop
  7.1240 +@@found:
  7.1241 +		xchg	ax,cx
  7.1242 +@@end:
  7.1243 +                pop	si
  7.1244 +		ret
  7.1245 +
  7.1246 +        endp    _strstr
  7.1247 +
  7.1248 +
  7.1249 +;***************************************************************
  7.1250 +;char *progname(void)
  7.1251 +;***************************************************************
  7.1252 +        global  _progname:near
  7.1253 +        proc    _progname near
  7.1254 +
  7.1255  		push	si di es
  7.1256 -		xchg	ax,si
  7.1257 +		mov	ah,30h
  7.1258 +		int	21h
  7.1259 +		cmp	al,3
  7.1260 +		jb	@@skip
  7.1261  		xor	di,di
  7.1262 -		ifdef	NO386
  7.1263 -		call	_topseg
  7.1264 -		mov	es,ax
  7.1265 -		else
  7.1266 -		push	9000h
  7.1267 +		mov	es,[cs:2Ch]
  7.1268 +		mov	cx,-1
  7.1269 +		mov	ax,di
  7.1270 +@@loop1:
  7.1271 +		repne
  7.1272 +		  scasb
  7.1273 +		scasb
  7.1274 +		jne	@@loop1
  7.1275 +		lea	si,[di+2]
  7.1276 +		mov	bx, si
  7.1277 +		call	strlen
  7.1278 +		xchg	ax,cx
  7.1279 +		inc	cx
  7.1280 +		call	malloc_or_die
  7.1281 +		xchg	ax,di
  7.1282 +		push	ds
  7.1283 +		push	ds
  7.1284 +		push	es
  7.1285 +		pop	ds
  7.1286  		pop	es
  7.1287 -		endif
  7.1288 -		cld
  7.1289 -		rep
  7.1290 -		  movsb
  7.1291 -		extrn	_cmdline:word
  7.1292 -		mov	si,[_cmdline]
  7.1293 -		mov	di,8000h
  7.1294 -		mov	ch,10h			; 4k
  7.1295 -		rep
  7.1296 -		  movsb
  7.1297 +		push	di
  7.1298 +@@loop2:
  7.1299 +		lodsb
  7.1300 +		stosb
  7.1301 +		or	al,al
  7.1302 +		jnz	@@loop2
  7.1303 +		pop	ax
  7.1304 +		pop	ds
  7.1305 +@@skip:
  7.1306  		pop	es di si
  7.1307  		ret
  7.1308  
  7.1309 -        endp    _rmcpy
  7.1310 +        endp    _progname
  7.1311 +
  7.1312 +
  7.1313 +;***************************************************************
  7.1314 +;int chdirname(char *path)
  7.1315 +;***************************************************************
  7.1316 +        global  _chdirname:near
  7.1317 +        proc    _chdirname near
  7.1318 +
  7.1319 +		pop	ax
  7.1320 +		pop	bx
  7.1321 +		push	bx
  7.1322 +		push	ax
  7.1323 +
  7.1324 +		cmp	[byte bx+1],3Ah
  7.1325 +		jne	@@nodisk
  7.1326 +		mov	dl,[bx]
  7.1327 +		or	dl,20h
  7.1328 +		sub	dl,61h
  7.1329 +		mov	ah,0Eh
  7.1330 +		push	bx
  7.1331 +		int	21h
  7.1332 +		pop	bx
  7.1333 +		inc	bx
  7.1334 +		inc	bx
  7.1335 +@@nodisk:
  7.1336 +		mov	dx,bx
  7.1337 +		xor	cx,cx
  7.1338 +@@next:
  7.1339 +		mov	al,[bx]
  7.1340 +		cmp	al,5Ch
  7.1341 +		jne	@@tsteos
  7.1342 +		mov	cx,bx
  7.1343 +@@tsteos:
  7.1344 +		inc	bx
  7.1345 +		or	al,al
  7.1346 +		jnz	@@next
  7.1347 +		cbw
  7.1348 +		jcxz	@@end
  7.1349 +		mov	bx,cx
  7.1350 +		push	[word bx]
  7.1351 +		mov	[bx],al
  7.1352 +		push	bx
  7.1353 +		call	chdir
  7.1354 +		pop	bx
  7.1355 +		pop	[word bx]
  7.1356 +@@end:
  7.1357 +		ret
  7.1358 +
  7.1359 +        endp    _chdirname
  7.1360 +
  7.1361 +
  7.1362 +;***************************************************************
  7.1363 +;char *ultoa(unsigned long n);
  7.1364 +;***************************************************************
  7.1365 +        global  _ultoa:near
  7.1366 +        proc    _ultoa near
  7.1367 +
  7.1368 +		pop	ax
  7.1369 +		pop	cx
  7.1370 +		pop	dx
  7.1371 +		push	dx
  7.1372 +		push	cx
  7.1373 +		push	ax		; DX:CX = n
  7.1374 +		push	si
  7.1375 +		mov	si,10
  7.1376 +		mov	bx,offset ultoabuf+11
  7.1377 +@@loop:
  7.1378 +		dec	bx
  7.1379 +		xchg	ax,dx
  7.1380 +		xor	dx,dx
  7.1381 +		div	si		; DX:AX = 0000:hi(n)
  7.1382 +		xchg	ax,cx		; CX = hi(n)/10
  7.1383 +		div	si		; DX:AX = hi(n)%10:lo(n)
  7.1384 +		xchg	ax,cx		; CX = lo(n/10)
  7.1385 +		xchg	ax,dx		; DX = hi(n)/10 = hi(n/10)
  7.1386 +		add	al,'0'
  7.1387 +		mov	[bx],al
  7.1388 +		mov	ax,cx
  7.1389 +		or	ax,dx
  7.1390 +		jnz	@@loop
  7.1391 +		xchg	ax,bx
  7.1392 +		pop	si
  7.1393 +		ret
  7.1394 +
  7.1395 +        endp    _ultoa
  7.1396 +
  7.1397 +
  7.1398 +;***************************************************************
  7.1399 +;unsigned long kver2ul(char *kernel_version);
  7.1400 +;***************************************************************
  7.1401 +        global  _kver2ul:near
  7.1402 +        proc    _kver2ul near
  7.1403 +
  7.1404 +		pop	bx
  7.1405 +		pop	ax
  7.1406 +		push	ax
  7.1407 +		push	bx
  7.1408 +		push	bp si di
  7.1409 +		xchg	ax,si
  7.1410 +		xor	di,di
  7.1411 +		push	di
  7.1412 +		push	di
  7.1413 +		mov	bp,sp
  7.1414 +		inc	di
  7.1415 +		inc	di
  7.1416 +		mov	cl,4
  7.1417 +@@number:
  7.1418 +		xor	ax,ax
  7.1419 +@@digit:
  7.1420 +		shl	al,cl
  7.1421 +		shl	ax,cl
  7.1422 +		lodsb
  7.1423 +		sub	al,30h
  7.1424 +		cmp	al,9
  7.1425 +		jbe	@@digit
  7.1426 +		mov	[bp+di],ah
  7.1427 +		dec	di
  7.1428 +		jns	@@number
  7.1429 +		pop	ax
  7.1430 +		pop	dx
  7.1431 +		pop	di si bp
  7.1432 +kver2ulret:
  7.1433 +		ret
  7.1434 +
  7.1435 +        endp    _kver2ul
  7.1436 +
  7.1437 +
  7.1438 +;***************************************************************
  7.1439 +;void try_default_args();
  7.1440 +;***************************************************************
  7.1441 +        global  _try_default_args:near
  7.1442 +        proc    _try_default_args near
  7.1443 +
  7.1444 +		mov	bx,offset tazboot_cmd
  7.1445 +		call	open
  7.1446 +		jc	kver2ulret
  7.1447 +		mov	cx,4096
  7.1448 +		mov	di,[_heap_top]
  7.1449 +		push	cx
  7.1450 +		extrn	read_cmdline:near
  7.1451 +		jmp	near read_cmdline	; read_cmdline(ax,di,cx)
  7.1452 +		
  7.1453 +        endp    _try_default_args
  7.1454 +
  7.1455 +			endif
  7.1456  
  7.1457          ends    _TEXT
  7.1458  
  7.1459          end
  7.1460  
  7.1461  ;###### END OF FILE ############################################
  7.1462 +
     8.1 --- a/linld/stuff/src/CRTL.H	Fri Mar 17 15:14:21 2017 +0200
     8.2 +++ b/linld/stuff/src/CRTL.H	Fri Mar 17 15:18:10 2017 +0100
     8.3 @@ -9,31 +9,23 @@
     8.4  const unsigned MIN_STACK = 0x400;
     8.5  const unsigned MAX_MALLOC = 0xF000;
     8.6  
     8.7 -const A_RDONLY    = 1;     // for fileattr()
     8.8 -const A_HIDDEN    = 2;
     8.9 -const A_SYSTEM    = 4;
    8.10 -const A_LABEL     = 8;
    8.11 -const A_DIRECTORY = 16;
    8.12 -const A_ARCHIVE   = 32;
    8.13 +const char A_RDONLY    = 1;     // for fileattr()
    8.14 +const char A_HIDDEN    = 2;
    8.15 +const char A_SYSTEM    = 4;
    8.16 +const char A_LABEL     = 8;
    8.17 +const char A_DIRECTORY = 16;
    8.18 +const char A_ARCHIVE   = 32;
    8.19  
    8.20  
    8.21 -const O_RDONLY = 0;     // for open()
    8.22 -const O_BINARY = 0;
    8.23 -
    8.24 -const SEEK_SET = 0;     // for lseek()
    8.25 -const SEEK_CUR = 1;
    8.26 -const SEEK_END = 2;
    8.27 +const char O_RDONLY = 0;     // for open()
    8.28 +const char O_BINARY = 0;
    8.29  
    8.30  extern char text_start; extern char text_end;
    8.31  extern char data_start; extern char data_end;
    8.32  extern char bss_start;  extern char bss_end;
    8.33  extern char* heap_top;
    8.34  
    8.35 -extern int ximage_size, ximage_fd;
    8.36 -
    8.37  void parse_cmdline();
    8.38 -extern "C" char* strcpy(const char* a,const char* b);
    8.39 -extern "C" char* strcat(const char* a,const char* b);
    8.40  extern "C" char* strcatb(const char* a,const char* b);
    8.41  extern "C" int strhead(const char* a,const char* b);
    8.42  extern "C" int fileattr(const char* name);
    8.43 @@ -44,17 +36,12 @@
    8.44  extern "C" void abort();
    8.45  extern "C" int read(int fd, void* data, int sz);
    8.46  extern "C" int write(int fd, const void* data, int sz);
    8.47 -extern "C" long lseek(int fd, long sz, int dir);
    8.48 +extern "C" long seekset(int fd, unsigned sz);
    8.49  extern "C" void* malloc(unsigned sz);
    8.50 -extern "C" void puts(const char* s);
    8.51 -extern "C" void putsz(const char* s);
    8.52 +extern "C" int puts(const char* s);
    8.53  extern "C" unsigned long strtol(const char *s);
    8.54  
    8.55  // Extensions
    8.56 -//static void barrier() {}
    8.57 -//static void cli() { asm { cli } }
    8.58 -//static void sti() { asm { sti } }
    8.59 -#define barrier() do {} while(0)
    8.60  #define cli() do { asm { cli } } while(0)
    8.61  #define sti() do { asm { sti } } while(0)
    8.62  #define int3() do { asm { db 0cch } } while(0)
     9.1 --- a/linld/stuff/src/CRTLX.ASM	Fri Mar 17 15:14:21 2017 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,356 +0,0 @@
     9.4 -;***************************************************************
     9.5 -;****** This file is distributed under GPL
     9.6 -;***************************************************************
     9.7 -                ideal
     9.8 -                %crefref
     9.9 -                %noincl
    9.10 -                %nomacs
    9.11 -                p386
    9.12 -
    9.13 -        group   DGROUP  _TEXT,_DATA,_BSS
    9.14 -        assume  cs:DGROUP,ds:DGROUP
    9.15 -
    9.16 -        segment _DATA byte public use16 'DATA'
    9.17 -
    9.18 -tazboot_cmd	db	"tazboot.cmd",0
    9.19 -
    9.20 -        ends    _DATA
    9.21 -
    9.22 -        segment _BSS byte public use16 'BSS'
    9.23 -
    9.24 -ultoabuf	db	12	dup (?)
    9.25 -
    9.26 -        ends    _BSS
    9.27 -
    9.28 -        segment _TEXT byte public use16 'CODE'
    9.29 -
    9.30 -;***************************************************************
    9.31 -;int strcmp(const char* a,const char* b);
    9.32 -;***************************************************************
    9.33 -        global  _strcmp:near
    9.34 -        proc    _strcmp near
    9.35 -
    9.36 -		pop	ax			;caller return address
    9.37 -                pop	cx			; a
    9.38 -                pop	bx			; b
    9.39 -                push	bx
    9.40 -                push	cx
    9.41 -                push	ax
    9.42 -                push	si
    9.43 -                mov	si,cx
    9.44 -                sub	bx,si
    9.45 -@@lp:
    9.46 -                mov	al,[bx+si]
    9.47 -                sub	al,[si]
    9.48 -		jnz	@@out
    9.49 -                lodsb
    9.50 -		cmp	al,0
    9.51 -                jne	@@lp
    9.52 -@@out:
    9.53 -		cbw
    9.54 -                pop	si
    9.55 -                ret
    9.56 -
    9.57 -        endp    _strcmp
    9.58 -
    9.59 -
    9.60 -;***************************************************************
    9.61 -;char strstr(const char* a,const char* b);
    9.62 -;***************************************************************
    9.63 -        global  _strstr:near
    9.64 -        proc    _strstr near
    9.65 -
    9.66 -		pop	ax			;caller return address
    9.67 -                pop	cx			; a
    9.68 -                pop	dx			; b
    9.69 -                push	dx
    9.70 -                push	cx
    9.71 -                push	ax
    9.72 -                push	si
    9.73 -@@loop:
    9.74 -		xor	ax,ax
    9.75 -		mov	si,cx
    9.76 -		cmp	[si],al			; *a
    9.77 -		jz	@@end			; return ax = NULL
    9.78 -		mov	bx,dx
    9.79 -		sub	bx,si
    9.80 -@@match:
    9.81 -		or	ah,[bx+si]		; *b
    9.82 -		jz	@@found
    9.83 -		lodsb
    9.84 -		sub	ah,al
    9.85 -		jz	@@match
    9.86 -		inc	cx
    9.87 -		jmp	@@loop
    9.88 -@@found:
    9.89 -		xchg	ax,cx
    9.90 -@@end:
    9.91 -                pop	si
    9.92 -		ret
    9.93 -
    9.94 -        endp    _strstr
    9.95 -
    9.96 -
    9.97 -;***************************************************************
    9.98 -;int cpuhaslm(void)
    9.99 -;***************************************************************
   9.100 -        global  _cpuhaslm:near
   9.101 -        proc    _cpuhaslm near
   9.102 -
   9.103 -		pushf
   9.104 -; Check for oldies
   9.105 -		mov	bh, 0F0h
   9.106 -		push	bx		; < 286 : flags[12..15] are forced 1
   9.107 -		popf			; = 286 : flags[12..15] are forced 0
   9.108 -		pushf			; > 286 : only flags[15] is forced 0
   9.109 -		pop	dx
   9.110 -		popf
   9.111 -		add	dh,bh		; NS=386+, NC=286
   9.112 -		clc
   9.113 -                js     @@bad   		;it is a 86/186/286, not a 386+
   9.114 -		pushfd
   9.115 -		pushfd
   9.116 -		pop	ebx
   9.117 -		mov	ecx,ebx
   9.118 -		xor	ebx,00100000h	; toggle CPUID feature bit 21
   9.119 -		push	ebx
   9.120 -		popfd
   9.121 -		pushfd
   9.122 -		pop	ebx
   9.123 -		popfd
   9.124 -		xor	ebx,ecx
   9.125 -		shr	ebx,1+21	; CPUID feature bit ?
   9.126 -		jnc	@@bad
   9.127 -		mov	eax,80000001h	; Extended Processor Info and Feature Bits
   9.128 -		db	0Fh,0A2h	; cpuid
   9.129 -		shr	edx,1+29	; LM feature bit ?
   9.130 -@@bad:
   9.131 -		sbb	ax,ax
   9.132 -		ret
   9.133 -
   9.134 -        endp    _cpuhaslm
   9.135 -
   9.136 -
   9.137 -;***************************************************************
   9.138 -;char *progname(void)
   9.139 -;***************************************************************
   9.140 -        global  _progname:near
   9.141 -        proc    _progname near
   9.142 -
   9.143 -		push	si di es
   9.144 -		mov	ah,30h
   9.145 -		int	21h
   9.146 -		cmp	al,3
   9.147 -		mov	ax,0
   9.148 -		jb	@@skip
   9.149 -		mov	es,[cs:2Ch]
   9.150 -		mov	cx,-1
   9.151 -		xor	di,di
   9.152 -		xor	al,al
   9.153 -@@loop1:
   9.154 -		repne
   9.155 -		  scasb
   9.156 -		scasb
   9.157 -		jne	@@loop1
   9.158 -		lea	si,[di+2]
   9.159 -		mov	bx, si
   9.160 -		extrn	strlen:near
   9.161 -		call	near strlen
   9.162 -		xchg	ax,cx
   9.163 -		inc	cx
   9.164 -		extrn	malloc_or_die:near
   9.165 -		call	near malloc_or_die
   9.166 -		xchg	ax,di
   9.167 -		push	ds
   9.168 -		push	ds
   9.169 -		push	es
   9.170 -		pop	ds
   9.171 -		pop	es
   9.172 -		push	di
   9.173 -@@loop2:
   9.174 -		lodsb
   9.175 -		stosb
   9.176 -		or	al,al
   9.177 -		jnz	@@loop2
   9.178 -		pop	ax
   9.179 -		pop	ds
   9.180 -@@skip:
   9.181 -		pop	es di si
   9.182 -		ret
   9.183 -
   9.184 -        endp    _progname
   9.185 -
   9.186 -
   9.187 -;***************************************************************
   9.188 -;int chdir(char *path);
   9.189 -;***************************************************************
   9.190 -        global  _chdir:near
   9.191 -        proc    _chdir near
   9.192 -
   9.193 -		pop	ax
   9.194 -		pop	dx
   9.195 -		push	dx
   9.196 -		push	ax
   9.197 -chdir:
   9.198 -		stc
   9.199 -		mov	ax,713Bh
   9.200 -		int	21h
   9.201 -		jnc	@@end
   9.202 -		mov	ah,3Bh
   9.203 -		int	21h
   9.204 -@@end:
   9.205 -		sbb	ax,ax
   9.206 -		ret
   9.207 -
   9.208 -        endp    _chdir
   9.209 -
   9.210 -
   9.211 -;***************************************************************
   9.212 -;int chdirname(char *path)
   9.213 -;***************************************************************
   9.214 -        global  _chdirname:near
   9.215 -        proc    _chdirname near
   9.216 -
   9.217 -		pop	ax
   9.218 -		pop	bx
   9.219 -		push	bx
   9.220 -		push	ax
   9.221 -
   9.222 -		cmp	[byte bx+1],3Ah
   9.223 -		jne	@@nodisk
   9.224 -		mov	dl,[bx]
   9.225 -		or	dl,20h
   9.226 -		sub	dl,61h
   9.227 -		mov	ah,0Eh
   9.228 -		push	bx
   9.229 -		int	21h
   9.230 -		pop	bx
   9.231 -		inc	bx
   9.232 -		inc	bx
   9.233 -@@nodisk:
   9.234 -		mov	dx,bx
   9.235 -		xor	cx,cx
   9.236 -@@next:
   9.237 -		mov	al,[bx]
   9.238 -		cmp	al,5Ch
   9.239 -		jne	@@tsteos
   9.240 -		mov	cx,bx
   9.241 -@@tsteos:
   9.242 -		inc	bx
   9.243 -		or	al,al
   9.244 -		jnz	@@next
   9.245 -		cbw
   9.246 -		jcxz	@@end
   9.247 -		mov	bx,cx
   9.248 -		push	[word bx]
   9.249 -		mov	[bx],al
   9.250 -		push	bx
   9.251 -		call	chdir
   9.252 -		pop	bx
   9.253 -		pop	[word bx]
   9.254 -@@end:
   9.255 -		ret
   9.256 -
   9.257 -        endp    _chdirname
   9.258 -
   9.259 -
   9.260 -;***************************************************************
   9.261 -;char *ultoa(unsigned long n);
   9.262 -;***************************************************************
   9.263 -        global  _ultoa:near
   9.264 -        proc    _ultoa near
   9.265 -
   9.266 -		pop	ax
   9.267 -		pop	cx
   9.268 -		pop	dx
   9.269 -		push	dx
   9.270 -		push	cx
   9.271 -		push	ax		; DX:CX = n
   9.272 -		push	si
   9.273 -		mov	si,10
   9.274 -		mov	bx,offset ultoabuf+11
   9.275 -@@loop:
   9.276 -		dec	bx
   9.277 -		xchg	ax,dx
   9.278 -		xor	dx,dx
   9.279 -		div	si		; DX:AX = 0000:hi(n)
   9.280 -		xchg	ax,cx		; CX = hi(n)/10
   9.281 -		div	si		; DX:AX = hi(n)%10:lo(n)
   9.282 -		xchg	ax,cx		; CX = lo(n/10)
   9.283 -		xchg	ax,dx		; DX = hi(n)/10 = hi(n/10)
   9.284 -		add	al,'0'
   9.285 -		mov	[bx],al
   9.286 -		mov	ax,cx
   9.287 -		or	ax,dx
   9.288 -		jnz	@@loop
   9.289 -		xchg	ax,bx
   9.290 -		pop	si
   9.291 -		ret
   9.292 -
   9.293 -        endp    _ultoa
   9.294 -
   9.295 -
   9.296 -;***************************************************************
   9.297 -;unsigned long kver2ul(char *kernel_version);
   9.298 -;***************************************************************
   9.299 -        global  _kver2ul:near
   9.300 -        proc    _kver2ul near
   9.301 -
   9.302 -		pop	ax
   9.303 -		pop	dx
   9.304 -		push	dx
   9.305 -		push	ax
   9.306 -		push	bp si di
   9.307 -		xor	di,di
   9.308 -		push	di
   9.309 -		push	di
   9.310 -		mov	bp,sp
   9.311 -		mov	si,dx
   9.312 -		inc	di
   9.313 -		inc	di
   9.314 -		mov	cl,4
   9.315 -@@number:
   9.316 -		xor	ax,ax
   9.317 -@@digit:
   9.318 -		shl	al,cl
   9.319 -		shl	ax,cl
   9.320 -		lodsb
   9.321 -		sub	al,30h
   9.322 -		cmp	al,9
   9.323 -		jbe	@@digit
   9.324 -		mov	[bp+di],ah
   9.325 -		dec	di
   9.326 -		jns	@@number
   9.327 -		pop	ax
   9.328 -		pop	dx
   9.329 -		pop	di si bp
   9.330 -kver2ulret:
   9.331 -		ret
   9.332 -
   9.333 -        endp    _kver2ul
   9.334 -
   9.335 -
   9.336 -;***************************************************************
   9.337 -;void try_default_args();
   9.338 -;***************************************************************
   9.339 -        global  _try_default_args:near
   9.340 -        proc    _try_default_args near
   9.341 -
   9.342 -		mov	bx,offset tazboot_cmd
   9.343 -		extrn	open:near
   9.344 -		call	near open
   9.345 -		jc	kver2ulret
   9.346 -		mov	cx,4096
   9.347 -		extrn	_heap_top:word
   9.348 -		mov	di,[_heap_top]
   9.349 -		push	cx
   9.350 -		extrn	read_cmdline:near
   9.351 -		jmp	near read_cmdline	; read_cmdline(ax,di,cx)
   9.352 -		
   9.353 -        endp    _try_default_args
   9.354 -
   9.355 -        ends    _TEXT
   9.356 -
   9.357 -        end
   9.358 -
   9.359 -;###### END OF FILE ############################################
    10.1 --- a/linld/stuff/src/CRTLX.H	Fri Mar 17 15:14:21 2017 +0200
    10.2 +++ b/linld/stuff/src/CRTLX.H	Fri Mar 17 15:18:10 2017 +0100
    10.3 @@ -1,14 +1,18 @@
    10.4  // This file is distributed under GPL
    10.5  //
    10.6  #define NULL 0
    10.7 +extern "C" char* strcpy(const char* a,const char* b);
    10.8 +extern "C" char* strcat(const char* a,const char* b);
    10.9  extern "C" int strcmp(const char* a,const char* b);
   10.10  extern "C" int strlen(const char* s);
   10.11  extern "C" char* strstr(const char* a,const char* b);
   10.12 -extern "C" int cpuhaslm();
   10.13  extern "C" char *progname(void);
   10.14  extern "C" int chdir(char *path);
   10.15  extern "C" int chdirname(char *path);
   10.16  extern "C" unsigned long kver2ul(char *kernel_version);
   10.17  extern "C" char *ultoa(unsigned long n);
   10.18  extern "C" void try_default_args();
   10.19 -
   10.20 +extern "C" long lseekset(int fd, unsigned long sz);
   10.21 +#define seekset(fd,sz)	lseekset(fd,(unsigned long) sz)
   10.22 +extern char cpu_features[];
   10.23 +#define cpuhaslm() (cpu_features[3]&0x20)
    11.1 --- a/linld/stuff/src/HIMEM.CPP	Fri Mar 17 15:14:21 2017 +0200
    11.2 +++ b/linld/stuff/src/HIMEM.CPP	Fri Mar 17 15:18:10 2017 +0100
    11.3 @@ -6,29 +6,105 @@
    11.4  #include "crtl.h"
    11.5  #include "common.h"
    11.6  
    11.7 -int skip_xmmalloc;
    11.8 +struct image_himem pm;
    11.9 +struct image_himem initrd;
   11.10 +int skip_alloc;
   11.11 +
   11.12 +// Called from inside kernel just before rm->pm
   11.13 +// _loadds _saveregs: done by hand
   11.14 +void far last_ditch() {
   11.15 +    cli();  // we start doing *really* destructive things to DOS/BIOS
   11.16 +            // it means: do not even try to enable ints
   11.17 +            // or call BIOS services after this
   11.18 +    asm {
   11.19 +        push    ds
   11.20 +        push    cs
   11.21 +        pop     ds
   11.22 +#ifndef NO386
   11.23 +        pusha
   11.24 +#else
   11.25 +        push	ax
   11.26 +        push	bx
   11.27 +        push	cx
   11.28 +        push	dx
   11.29 +#endif
   11.30 +    }
   11.31 +    struct image_himem *m = &pm;
   11.32 +    vm2rm();
   11.33 +    if(((u16 *)&m->fallback)[1] >= 0x10) m->fallback = _1m; // >= _1m ?
   11.34 +    if(m->bufv==0) {
   11.35 +        // Move kernel
   11.36 +        memcpy_image(m);
   11.37 +        // Move initrd
   11.38 +        memcpy_image(&initrd);
   11.39 +    } else { //vcpi
   11.40 +        // Move kernel
   11.41 +        // 'Gathering' copy in chunks of PAGE_SIZE
   11.42 +        // No risk of overlapping: kernel is copied from above to 1m mark
   11.43 +        m->size = initrd.size = PAGE_SIZE;
   11.44 +        u32 *p = m->bufv;
   11.45 +	reset_bufv(p);
   11.46 +	if (p) do {
   11.47 +            m->buf = *p;
   11.48 +            memcpy_image(m);
   11.49 +            next(p); m->fallback+=PAGE_SIZE;
   11.50 +        } while(*p);
   11.51 +        // Move initrd
   11.52 +	m = &initrd;
   11.53 +        if(m->fallback) {
   11.54 +            // This is tricky: copy initrd backwards to reduce
   11.55 +            // risk of overlapping: use the fact that initrd is copied
   11.56 +            // to the very top of ram
   11.57 +            // (overlapping still can happen with more than 256mb ram)
   11.58 +            // (generic solution for this overwrite problem, anyone?)
   11.59 +            p=m->bufv;
   11.60 +	    reset_bufv(p);
   11.61 +            do {
   11.62 +                next(p); m->fallback+=PAGE_SIZE;
   11.63 +            } while(*p);
   11.64 +            do {
   11.65 +                prev(p); m->fallback-=PAGE_SIZE;
   11.66 +                m->buf = *p;
   11.67 +                memcpy_image(m);
   11.68 +            } while(p != m->bufv);
   11.69 +        }
   11.70 +    }
   11.71 +    asm {
   11.72 +#ifndef NO386
   11.73 +        popa
   11.74 +#else
   11.75 +        pop	dx
   11.76 +        pop	cx
   11.77 +        pop	bx
   11.78 +        pop	ax
   11.79 +#endif
   11.80 +        pop     ds
   11.81 +    }
   11.82 +}
   11.83 +
   11.84  void load_image(struct image_himem *m) {
   11.85      no_exit++;       // die() won't return to DOS
   11.86      m->remaining = m->size;
   11.87 -    u32 buf= m->buf = m->fallback;
   11.88 +    m->buf = m->fallback;
   11.89 +    u32 buf;
   11.90      u32* bufv= &buf;
   11.91 -    if(m->fallback >= _1m) {
   11.92 +    if(((u16 *)&m->fallback)[1] >= 0x10 && !skip_alloc) { // >= _1m ?
   11.93  	if(vcpi) {
   11.94 -	    bufv = malloc_bufv_or_die(m);
   11.95 +	    bufv = malloc_bufv_or_die(m);	// update m->bufv
   11.96  	}
   11.97 -	else if (!skip_xmmalloc) {
   11.98 -            xmm_alloc(m);
   11.99 +	else {
  11.100 +            xmm_alloc(m);			// update m->buf
  11.101  	}
  11.102      }
  11.103 +    buf = m->buf;
  11.104      do {
  11.105  	u8 xfer_buf[PAGE_SIZE];
  11.106 -        u16 size = read_image(m, xfer_buf, PAGE_SIZE);
  11.107 -        if(s16(size) <= 0) break;
  11.108 -        memcpy32(*bufv, seg(xfer_buf), ofs(xfer_buf), PAGE_SIZE);
  11.109 -	if (bufv != &buf) bufv++;
  11.110 +        u16 size;
  11.111 +	if(s16(size = read_image(m, xfer_buf, PAGE_SIZE)) <= 0) break;
  11.112 +        storepage(bufv, ofs(xfer_buf));
  11.113 +	if (bufv != &buf) next(bufv);
  11.114          buf += size;
  11.115      } while (*bufv);
  11.116      if(m->remaining) die("Read error");
  11.117      close(m->fd2close);
  11.118  }
  11.119 -
    12.1 --- a/linld/stuff/src/ISO9660.CPP	Fri Mar 17 15:14:21 2017 +0200
    12.2 +++ b/linld/stuff/src/ISO9660.CPP	Fri Mar 17 15:18:10 2017 +0100
    12.3 @@ -3,171 +3,144 @@
    12.4  #include "iso9660.h"
    12.5  #define __ROCKRIDGE
    12.6  
    12.7 -char *isofilename;
    12.8 -unsigned long isofileofs, isofilesize;
    12.9 -unsigned short isofilemod;
   12.10 -int isofd;
   12.11 -
   12.12  #define SECTORSZ 2048
   12.13  #define SECTORBITS 11
   12.14 -static char buffer[SECTORSZ];
   12.15 +static char buffer[SECTORSZ+512];	// RR overflow
   12.16 +struct isostate isostate;
   12.17  
   12.18 -static int readsector(unsigned long offset)
   12.19 +static int readsector(const unsigned long *offset)
   12.20  {
   12.21 -	return (lseek(isofd, offset, SEEK_SET) != -1
   12.22 -		    && read(isofd, buffer, SECTORSZ) == SECTORSZ);
   12.23 +	return (isolseek(offset) != -1
   12.24 +		    && read(isostate.fd, buffer, sizeof(buffer)) >= SECTORSZ);
   12.25  }
   12.26  
   12.27 -int isoread(char *data, unsigned size)
   12.28 -{
   12.29 -	int get, n;
   12.30 -	
   12.31 -	if (size > isofilesize)
   12.32 -		size = isofilesize;
   12.33 -	if (lseek(isofd, isofileofs, SEEK_SET) == -1)
   12.34 -		return -1;
   12.35 -	for (get = size; get; get -= n, data += n) {
   12.36 -		n = read(isofd,data,get);
   12.37 -		if (n < 0)
   12.38 -			return n;
   12.39 -		if (n == 0)
   12.40 -			break;
   12.41 -		isofileofs += n;
   12.42 -		isofilesize -= n;
   12.43 -	}
   12.44 -	return size - get;
   12.45 -}
   12.46 -
   12.47 -static unsigned long isodirofs, isodirsize;
   12.48  int isoreset(char *name)
   12.49  {
   12.50 +	static const unsigned long root = 16UL * 2048;
   12.51 +	struct isostate *x=&isostate;
   12.52  	if (name)
   12.53 -		//isofd = open(name, O_RDONLY);
   12.54 -		isofd = open(name);
   12.55 -	if (!readsector(16UL * 2048) || strhead(buffer+1,"CD001")) {
   12.56 -		//close(isofd);
   12.57 +		//x->fd = open(name, O_RDONLY);
   12.58 +		x->fd = open(name);
   12.59 +	if (!readsector(&root) || strhead(buffer+1,"CD001")) {
   12.60 +		//close(x->fd);
   12.61  		return -1;
   12.62  	}
   12.63 -	isodirofs = * (unsigned long *) (buffer + 0x9E);
   12.64 -	isodirofs <<= SECTORBITS;
   12.65 -	isodirsize = * (unsigned long *) (buffer + 0xA6);
   12.66 +	x->dirofs = (* (unsigned long *) (buffer + 0x9E)) << SECTORBITS;
   12.67 +	x->dirsize = filesize2dirsize(* (unsigned long *) (buffer + 0xA6));
   12.68  	return 0;
   12.69  }
   12.70  
   12.71  int isoreaddir(int restart)
   12.72  {
   12.73 -	static unsigned long pos, dirofs, dirsize;
   12.74  	static char dots[] = "..";
   12.75 -	int size, n;
   12.76 +	int size;
   12.77 +	char *p;
   12.78  #ifdef __ROCKRIDGE
   12.79  	char *endname;
   12.80  #endif
   12.81 +	struct isostate *x=&isostate;
   12.82  
   12.83  	if (restart) {
   12.84 -		dirofs = isodirofs;
   12.85 -		dirsize = isodirsize;
   12.86 -		pos = SECTORSZ;
   12.87 +		x->curdirsize = x->dirsize;
   12.88 +		x->curdirofs = x->dirofs;
   12.89 +		goto restarted;
   12.90  	}
   12.91 -	if (pos >= SECTORSZ || * (short *) (buffer + pos) == 0) {
   12.92 -		if (dirsize < SECTORSZ) return -1;
   12.93 -		readsector(dirofs);
   12.94 -		dirofs += SECTORSZ;
   12.95 -		dirsize -= SECTORSZ;
   12.96 -		pos = 0;
   12.97 +	if (x->curpos >= SECTORSZ || * (short *) (buffer + x->curpos) == 0) {
   12.98 +		if (x->curdirsize < DIRSECTORSZ) return -1;
   12.99 +	restarted:
  12.100 +		readsector(&x->curdirofs);
  12.101 +		x->curdirofs += SECTORSZ;
  12.102 +		x->curdirsize -= DIRSECTORSZ;
  12.103 +		x->curpos = 0;
  12.104  	}
  12.105 -	size = * (short *) (buffer + pos);
  12.106 -	if (size == 0)
  12.107 +	p = buffer + x->curpos;
  12.108 +	if ((size = * (short *) p) == 0)
  12.109  		return -1;
  12.110 -	isofileofs = (* (unsigned long *) (buffer + pos + 2)) << SECTORBITS;
  12.111 -	isofilesize = * (unsigned long *) (buffer + pos + 10);
  12.112 -	isofilemod = (buffer[pos + 25] & 2) ? 0040755 : 0100755;
  12.113 +	x->fileofs = (* (unsigned long *) (p + 2)) << SECTORBITS;
  12.114 +	x->filesize = * (unsigned long *) (p + 10);
  12.115 +	x->filemod = (p[25] & 2) ? 0040755 : 0100755;
  12.116  #ifdef __ROCKRIDGE
  12.117  	endname = NULL;
  12.118 -	n = (buffer[pos + 32] + pos + 34) & -2;
  12.119 +	// p += 34 + (p[32] & -2); ?
  12.120 +	p = buffer + 34 + ((p[32] + x->curpos) & -2);
  12.121  	do {
  12.122 -		int len = buffer[n + 2];
  12.123 -		switch (* (short *) (buffer + n)) {
  12.124 +		int len = p[2];
  12.125 +		switch (* (short *) p) {
  12.126  		case 0x4D4E: // NM
  12.127 -			isofilename = buffer + n + 5;
  12.128 -			endname = buffer + n + len;
  12.129 +			x->filename = p + 5;
  12.130 +			endname = p + len;
  12.131  			break;
  12.132  		case 0x5850: // PX
  12.133 -			isofilemod = * (short *) (buffer + n + 4);
  12.134 +			x->filemod = * (short *) (p + 4);
  12.135  			break;
  12.136  		}
  12.137 -		n += len;
  12.138 +		p += len;
  12.139  	}
  12.140 -	while (n + 2 < pos + size);
  12.141 +	while (buffer + x->curpos + size > p + 2);
  12.142  	if (endname)
  12.143  		*endname = 0;
  12.144  	else
  12.145  #endif
  12.146  	{
  12.147 -		isofilename = buffer + pos + 33;
  12.148 -		switch (* (short *) (isofilename - 1)) {
  12.149 +		p = x->filename = buffer + x->curpos + 33;
  12.150 +		p--;
  12.151 +		switch (* (short *) p) {
  12.152  		case 0x0101:
  12.153 -			isofilename = dots;
  12.154 +			x->filename = dots;
  12.155  			break;
  12.156  		case 0x0001:
  12.157 -			isofilename = dots + 1;
  12.158 +			x->filename = dots + 1;
  12.159  			break;
  12.160  		default:
  12.161 -			n = isofilename[-1];
  12.162 -			if (* (short *) (isofilename + n - 2) == 0x313B)
  12.163 -				n -= 2; // remove ;1
  12.164 -			if (isofilename[n - 1] == '.') n--;
  12.165 -			isofilename[n] = 0;
  12.166 +			p += *p; p--;
  12.167 +			if (* (short *) (p) != 0x313B) {
  12.168 +				p++; p++; // no ;1 to remove
  12.169 +			}
  12.170 +			if (p[-1] == '.') p--;
  12.171 +			*p = 0;
  12.172  		}
  12.173  	}
  12.174 -	pos += size;
  12.175 +	x->curpos += size;
  12.176  	return 0;
  12.177  }
  12.178  
  12.179 -#define IS_DIR(x)( ((x) & ~0777) == 040000)
  12.180 -int isoopen(char *filename)
  12.181 +//#define IS_DIR(x)( ((x) & ~0777) == 040000)
  12.182 +#define IS_DIR(x)( (char)((x) >> 9) == (char)040)
  12.183 +int isoopen(const char *filename)
  12.184  {
  12.185  	int restart;
  12.186  	char *name, *s, c;
  12.187 -	int _64bits = cpuhaslm();
  12.188 +	char _64bits = cpuhaslm();
  12.189 +	struct isostate *x=&isostate;
  12.190  
  12.191 -retry32:
  12.192 -	name = filename;
  12.193 -	while (*name == '/') {
  12.194 -		name++;
  12.195 +  retry32:
  12.196 +	for (s = (char *) filename; *s == '/' ; s++) {
  12.197  		isoreset(NULL);
  12.198  	}
  12.199 -	s = name;
  12.200 -	while (1) {
  12.201 -		while (*s && *s != '/') s++;
  12.202 -		c = *s;
  12.203 -		*s = 0;
  12.204 -		for (restart = 1; isoreaddir(restart) == 0; restart = 0) {
  12.205 -			char *n = name, *i = isofilename;
  12.206 -			if (_64bits) {
  12.207 -				int len = strlen(name);
  12.208 -				if (strhead(isofilename, name)) continue;
  12.209 -				n = "64";
  12.210 -				i += len;
  12.211 -			}
  12.212 -			if (strcmp(n, i)) continue;
  12.213 -			if (IS_DIR(isofilemod)) {
  12.214 -				isodirofs = isofileofs;
  12.215 -				isodirsize = isofilesize;
  12.216 -				if (c) {
  12.217 -					*s++ = c;
  12.218 -					name = s;
  12.219 -					goto next;
  12.220 -				}
  12.221 -			}
  12.222 -			lseek(isofd, isofileofs, SEEK_SET);
  12.223 -			return 0;
  12.224 +  next:
  12.225 +	for (name = s; *s && *s != '/'; s++);
  12.226 +	c = *s;
  12.227 +	*s = 0;
  12.228 +	for (restart = 1; isoreaddir(restart) == 0; restart = 0) {
  12.229 +		const char *n = name, *i = x->filename;
  12.230 +		if (_64bits) {
  12.231 +			if (strhead(i, n)) continue;
  12.232 +			n = "64";
  12.233 +			i += s - name; // strlen(name);
  12.234  		}
  12.235 -		if (_64bits) {
  12.236 -			_64bits = 0;
  12.237 -			*s = c;
  12.238 -			goto retry32;
  12.239 +		if (strcmp(i, n)) continue;
  12.240 +		*s++ = c;
  12.241 +		if (IS_DIR(x->filemod)) {
  12.242 +			x->dirofs = x->fileofs;
  12.243 +			x->dirsize = filesize2dirsize(x->filesize);
  12.244 +			if (c) goto next;
  12.245  		}
  12.246 -		return -1;
  12.247 -	  next: ;
  12.248 +		isolseek(&x->fileofs);
  12.249 +		return 0;
  12.250  	}
  12.251 +	if (_64bits) {
  12.252 +		_64bits = 0;
  12.253 +		goto retry32;
  12.254 +	}
  12.255 +	return -1;
  12.256  }
    13.1 --- a/linld/stuff/src/ISO9660.H	Fri Mar 17 15:14:21 2017 +0200
    13.2 +++ b/linld/stuff/src/ISO9660.H	Fri Mar 17 15:18:10 2017 +0100
    13.3 @@ -1,12 +1,30 @@
    13.4  #ifndef __ISO9660_H
    13.5  #define __ISO9660_H
    13.6 -extern char *isofilename;
    13.7 -extern unsigned long isofileofs, isofilesize;
    13.8 -extern unsigned short isofilemod;
    13.9 -extern int isofd;
   13.10 +//typedef unsigned long dirsizetype;
   13.11 +//#define filesize2dirsize(x)	(x)
   13.12 +//#define DIRSECTORSZ	SECTORSZ
   13.13 +typedef unsigned dirsizetype;
   13.14 +#define filesize2dirsize(x)	(*(unsigned *)((char *)&(x)+1))
   13.15 +#define DIRSECTORSZ	(SECTORSZ/256)
   13.16 +extern struct isostate {
   13.17 +	int fd;
   13.18 +	unsigned long fileofs;
   13.19 +	unsigned long filesize;
   13.20 +	unsigned short filemod;
   13.21 +	char *filename;
   13.22 +//private
   13.23 +	dirsizetype curdirsize, dirsize;
   13.24 +	unsigned long curdirofs, dirofs;
   13.25 +	unsigned curpos;
   13.26 +} isostate;
   13.27 +#define isofd isostate.fd
   13.28 +#define	isofileofs isostate.fileofs
   13.29 +#define	isofilesize isostate.filesize
   13.30 +#define	isofilemod isostate.filemod
   13.31 +#define	isofilename isostate.filename
   13.32 +extern "C" unsigned long isolseek(const unsigned long *offset);
   13.33  extern int isoreset(char *name);
   13.34 -extern int isoopen(char *name);
   13.35 +extern int isoopen(const char *name);
   13.36  extern int isoreaddir(int restart);
   13.37 -extern int isoread(char *data, unsigned size);
   13.38  #define isolabel() do { isofileofs=0x8028; isofilesize=32; } while (0)
   13.39  #endif
    14.1 --- a/linld/stuff/src/JUMP.ASM	Fri Mar 17 15:14:21 2017 +0200
    14.2 +++ b/linld/stuff/src/JUMP.ASM	Fri Mar 17 15:18:10 2017 +0100
    14.3 @@ -5,14 +5,17 @@
    14.4                  %crefref
    14.5                  %noincl
    14.6                  %nomacs
    14.7 +		ifdef	NO386
    14.8 +                p8086
    14.9 +		else
   14.10                  p386
   14.11 +		endif
   14.12  
   14.13          group   DGROUP  _TEXT,_BSS
   14.14          assume  cs:DGROUP,ds:DGROUP
   14.15  
   14.16          segment _BSS byte public use16 'BSS'
   14.17  
   14.18 -        global  _pm_high:byte
   14.19          global  _pm:dword
   14.20  
   14.21          ends    _BSS
   14.22 @@ -21,7 +24,7 @@
   14.23          segment _TEXT byte public use16 'CODE'
   14.24  
   14.25  ;***************************************************************
   14.26 -;void set_sregs_jump_seg_ofs(u32 csip, u32 sssp);
   14.27 +;void set_sregs_jump_seg_ofs(u32 csip);
   14.28  ;****** Never returns
   14.29  ;***************************************************************
   14.30          global  _set_sregs_jump_seg_ofs:near
   14.31 @@ -29,18 +32,55 @@
   14.32  
   14.33  		extrn	dos_shutdown:near
   14.34  
   14.35 -		pop	ax			;caller return address
   14.36 -		test	[byte _pm_high],-1	; load high ? clear CF
   14.37 +		pop	ax			; caller return address
   14.38 +		ifdef	NO386
   14.39 +		extrn	_topseg:near
   14.40 +		call	near _topseg
   14.41 +		mov	es,ax
   14.42 +		xchg	ax,bx
   14.43 +		else
   14.44 +		push	9000h
   14.45 +		pop	es
   14.46 +		endif
   14.47 +		pop	dx			; ip
   14.48 +		pop	cx			; cs
   14.49 +		cli				; we start doing destructive things to DOS
   14.50 +		push	es
   14.51 +		pop	ss
   14.52 +		mov	sp,0A000h
   14.53 +		push	cx dx
   14.54 +		extrn	_rm_size:word
   14.55 +		mov	si,offset _rm_size	; _rm_size, _pm_high, _rm_buf
   14.56 +		lodsw
   14.57 +		xchg	ax,cx			; _rm_size
   14.58 +		lodsb				; _pm_high
   14.59 +		mov	si,[si]			; _rm_buf
   14.60 +		xor	di,di
   14.61 +		;cld
   14.62 +		rep
   14.63 +		  movsb
   14.64 +		extrn	_cmdline:word
   14.65 +		mov	si,[_cmdline]
   14.66 +		mov	di,8000h
   14.67 +		mov	ch,10h			; 4k
   14.68 +		rep
   14.69 +		  movsb
   14.70 +		cmp	al,cl			; load high ?
   14.71  		jne	isbzimage
   14.72 +		ifdef	NO386
   14.73 +		add	bh,9
   14.74 +		push	bx			; topseg()+0x0900
   14.75 +		else
   14.76 +		push	9900h			; 4096 bytes for cmdline
   14.77 +	;push	9820h			; 512 bytes for cmdline
   14.78 +		endif
   14.79  		; finish loading
   14.80  		extrn   @last_ditch$qv:near
   14.81  		push	cs
   14.82  		call	@last_ditch$qv
   14.83 -		mov	bx,[word _pm+2+2]	; get pm->fallback high word
   14.84 +		mov	ax,[word _pm+2+2]	; get pm->fallback high word
   14.85  		; self move
   14.86 -		cld
   14.87 -		push	9900h			; 4096 bytes for cmdline
   14.88 -	;push	9820h			; 512 bytes for cmdline
   14.89 +		;cld
   14.90  		pop	es			; min 2048 bytes for stack
   14.91  		xor	si,si			;  A000 -9000 -0800(>movedend)
   14.92  		xor	di,di			; set ZF
   14.93 @@ -51,18 +91,11 @@
   14.94  		  movsb
   14.95  		push	es
   14.96  		call	near doretf		; mov cs,es
   14.97 -		stc
   14.98 -isbzimage:
   14.99 -		pop	cx			; ip
  14.100 -		pop	dx			; cs
  14.101 -		pop	ax			; sp
  14.102 -		pop	ss			; ss
  14.103 -		xchg	sp,ax
  14.104 -		push	dx cx
  14.105 -		jnc	nomove
  14.106 +		push	ss
  14.107 +		pop	es
  14.108  		push	cs
  14.109  		pop	ds
  14.110 -		push	bx
  14.111 +		push	ax
  14.112  		call	near dos_shutdown
  14.113  		;in	al,70h
  14.114  		;or	al,80h			; disable NMI
  14.115 @@ -81,7 +114,13 @@
  14.116  		push	bx			; src ofs= pm.fallback
  14.117  		push	dx
  14.118  		push	dx			; srcseg=0
  14.119 -		push	1			; dst
  14.120 +		ifdef	NO386
  14.121 +		inc	dx
  14.122 +		push	dx			; dst
  14.123 +		dec	dx
  14.124 +		else
  14.125 +		push	1			; dst	
  14.126 +		endif
  14.127  		push	dx			;    ofs=64k
  14.128  		extrn   _memcpy32:near
  14.129  		call	_memcpy32
  14.130 @@ -98,7 +137,15 @@
  14.131  		cmp	[word 1E8h],'SK'
  14.132  		endif
  14.133  		jne	notelks
  14.134 +		ifdef	NO386
  14.135 +		mov	cx,120h
  14.136 +		push	cx
  14.137 +		mov	cl,0h
  14.138 +		push	cx
  14.139 +		else
  14.140 +		push	120h
  14.141  		push	100h
  14.142 +		endif
  14.143  		pop	es
  14.144  		xor	si,si
  14.145  		xor	di,di
  14.146 @@ -107,20 +154,21 @@
  14.147  		  movsw
  14.148  		push	es
  14.149  		pop	ss
  14.150 -		push	120h
  14.151 -		push	0
  14.152 +		push	cx
  14.153  notelks:
  14.154  		endif
  14.155  
  14.156 -nomove:
  14.157 +isbzimage:
  14.158  		push	ss
  14.159  		pop	ds
  14.160 -		push	ss
  14.161 -		pop	es
  14.162 +		;push	ss
  14.163 +		;pop	es
  14.164 +		ifndef	NO386
  14.165  		push	ss
  14.166  		pop	fs
  14.167  		push	ss
  14.168  		pop	gs
  14.169 +		endif
  14.170  		assume	nothing
  14.171  		assume	cs:DGROUP
  14.172  
    15.1 --- a/linld/stuff/src/LINKX.CMD	Fri Mar 17 15:14:21 2017 +0200
    15.2 +++ b/linld/stuff/src/LINKX.CMD	Fri Mar 17 15:18:10 2017 +0100
    15.3 @@ -1,1 +1,1 @@
    15.4 -_beg.obj memcpy32.obj jump.obj vcpi.obj himem.obj crtl.obj crtlx.obj memtop.obj xmm.obj a20.obj load.obj iso9660.obj tazboot.obj _end.obj, tazboot
    15.5 +_beg.obj memcpy32.obj jump.obj vcpi.obj himem.obj crtl.obj memtop.obj xmm.obj a20.obj load.obj iso9660.obj tazboot.obj _end.obj, tazboot
    16.1 --- a/linld/stuff/src/LINLD.CPP	Fri Mar 17 15:14:21 2017 +0200
    16.2 +++ b/linld/stuff/src/LINLD.CPP	Fri Mar 17 15:18:10 2017 +0100
    16.3 @@ -24,30 +24,32 @@
    16.4          "\tinitrd,vga,root=(void)" NL
    16.5          "\tmem=256m" NL
    16.6          "\tcl=auto" NL
    16.7 +        "\t-b 1088k" NL
    16.8          "Use quotes: \"cl=...\" if you need spaces in cmdline" NL
    16.9          "Use cl=@filename to get it from a file"
   16.10  #if 1
   16.11          NL NL "Examples:" NL
   16.12 -        "\tlinld initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
   16.13 +        "\tlinld -f -b 64m initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz \"cl=rw root=/dev/null video=-32\""
   16.14  	NL NL "\tlinld image=memtest"
   16.15  #endif
   16.16      );
   16.17  }
   16.18  
   16.19 -static char _cmdline[256];
   16.20 +static char _cmdline[128];
   16.21  int main(int argc, char *argv[]) {
   16.22 +
   16.23 +    (void) argc;
   16.24 +
   16.25      // Believe it or not - this enables A20
   16.26      // on my box! Must be DOS in HMA...   -vda
   16.27      puts("LINLD v" VERSION_STR "+");
   16.28  
   16.29 -    if(argc<2) {
   16.30 -dosyntax:
   16.31 -        syntax();
   16.32 -    }
   16.33 -
   16.34      // Parse command line
   16.35 -    {for (char i=0;;) {
   16.36 -	char *s=*++argv;
   16.37 +    if (argv[1]) {for (char i=0;;) {
   16.38 +	char *s;
   16.39 +    next:
   16.40 +	argv++;
   16.41 +	s=*argv;
   16.42  	i++;
   16.43  	if (!s) {
   16.44  	    puts(load_kernel());
   16.45 @@ -56,21 +58,27 @@
   16.46  	}
   16.47          if(strhead(s,"image=") == 0) {
   16.48  	    s+=6;
   16.49 +	set_kernel_name:
   16.50              kernel_name=s;
   16.51          }
   16.52          else if(strhead(s,"initrd=") == 0) {
   16.53  	    s+=7;
   16.54              initrd_name=s;
   16.55          }
   16.56 -        else if((*(u16 *)s|0x2002) == 0x662F) { // -F /f
   16.57 -            extern int skip_xmmalloc;
   16.58 -            skip_xmmalloc++;
   16.59 -        }
   16.60          else if(strhead(s,"vga=") == 0) {
   16.61  	    s+=4;
   16.62              vid_mode = strtol(s);	// support normal, extended & ask
   16.63          }
   16.64 -        else if(strhead(s,"cl=") == 0) {
   16.65 +        else switch (*(u16 *)s|0x2002) {
   16.66 +	case 0x662F:	// -F /f
   16.67 +	    skip_alloc++;
   16.68 +	    goto next;
   16.69 +	case 0x622F:	// -B /b
   16.70 +	    argv++;
   16.71 +	    base_himem = strtol(*argv);
   16.72 +	    goto next;
   16.73 +	default:
   16.74 +        if(strhead(s,"cl=") == 0) {
   16.75              cmdline=s+=3;
   16.76              if (*s == '@') {
   16.77  		static struct image_himem image;
   16.78 @@ -104,18 +112,20 @@
   16.79              topmem = strtol(s);
   16.80  	    goto addincmdline;
   16.81          }
   16.82 -        else if(cmdline == (const char *) _cmdline) {
   16.83 +        else if(cmdline == (const char *) _cmdline + 1) {
   16.84  addincmdline:
   16.85  	    strcatb(_cmdline,*argv);
   16.86          }
   16.87  	else if(i == 1 && fileattr(s) != -1) {
   16.88 -            kernel_name = s;
   16.89 -	    cmdline = (const char *) _cmdline;
   16.90 +	    cmdline = (const char *) _cmdline + 1;
   16.91 +	    goto set_kernel_name;
   16.92          }
   16.93  	else
   16.94 -	    goto dosyntax;
   16.95 +	    break;
   16.96 +	}
   16.97      }}
   16.98 +    syntax();
   16.99  
  16.100      // Let compiler be happy
  16.101 -    // return _AX;
  16.102 +    return _AX;
  16.103  }
    17.1 --- a/linld/stuff/src/LOAD.CPP	Fri Mar 17 15:14:21 2017 +0200
    17.2 +++ b/linld/stuff/src/LOAD.CPP	Fri Mar 17 15:18:10 2017 +0100
    17.3 @@ -44,7 +44,6 @@
    17.4  */
    17.5  
    17.6  struct kernelparams_t {
    17.7 -    u8      pad0;
    17.8      u8      setup_sects;    // 01F1 The size of the setup in sectors
    17.9                              //      boot sector is NOT included here
   17.10      u16     ro_flag;        // 01F2 If set, the root is mounted readonly
   17.11 @@ -92,8 +91,9 @@
   17.12      u16     ext_mem_size;   // 0002 extended memory size in Kb (from int 0x15 fn 0x88)
   17.13      u8      pad00[0x20-4];
   17.14                              // old-style cmdline (not used in LINLD (yet?))
   17.15 -    u16     cl_magic;       // 0020 commandline magic number (=0xA33F)
   17.16 -    u16     cl_ofs;         // 0022 commandline offset
   17.17 +    u32     cl_magic_ofs;
   17.18 +    //u16     cl_magic;       // 0020 commandline magic number (=0xA33F)
   17.19 +    //u16     cl_ofs;         // 0022 commandline offset
   17.20      u8      pad10[0x80-0x24];
   17.21                              // these two set by rm setup:
   17.22      u8      hd0_disk_par[16]; // 0080 hd0-disk-parameter from intvector 0x41
   17.23 @@ -101,7 +101,7 @@
   17.24      u8      pad20[0x01e0-0xa0];
   17.25                              // this is set by rm setup:
   17.26      u32     alt_mem_size;   // 01E0 extended memory size in Kb (from int 0x15 fn 0xe801)
   17.27 -    u8      pad28[0x01f0-0x1e4];
   17.28 +    u8      pad28[0x01f1-0x1e4];
   17.29      struct kernelparams_t params;
   17.30  }; //__attribute((packed));
   17.31  
   17.32 @@ -111,96 +111,17 @@
   17.33  
   17.34  const u32 HdrS = 'H' + ('d'<<8) + (u32('r')<<16) + (u32('S')<<24);
   17.35  
   17.36 -u8* rm_buf;
   17.37 -static u16 rm_size;
   17.38 -u8 pm_high;
   17.39 -struct image_himem pm;
   17.40 -struct image_himem initrd;
   17.41 -
   17.42 -static void memcpy_image(struct image_himem *m) {
   17.43 -    if (m->fallback != m->buf)
   17.44 -        memcpy32(
   17.45 -            m->fallback,    // dst seg,ofs
   17.46 -            0, m->buf,      // src seg,ofs
   17.47 -            m->size         // size
   17.48 -        );
   17.49 -}
   17.50 -
   17.51 -// Called from inside kernel just before rm->pm
   17.52 -// _loadds _saveregs: done by hand
   17.53 -void far last_ditch() {
   17.54 -    cli();  // we start doing *really* destructive things to DOS/BIOS
   17.55 -            // it means: do not even try to enable ints
   17.56 -            // or call BIOS services after this
   17.57 -    asm {
   17.58 -        push    ds
   17.59 -        push    cs
   17.60 -        pop     ds
   17.61 -#ifndef NO386
   17.62 -        pusha
   17.63 -#else
   17.64 -        push	ax
   17.65 -        push	bx
   17.66 -        push	cx
   17.67 -        push	dx
   17.68 -#endif
   17.69 -    }
   17.70 -    if(pm.fallback > _1m) pm.fallback = _1m;
   17.71 -    if(vcpi==0) {
   17.72 -        // Move kernel
   17.73 -        memcpy_image(&pm);
   17.74 -        // Move initrd
   17.75 -        memcpy_image(&initrd);
   17.76 -    } else { //vcpi
   17.77 -        vm2rm();
   17.78 -        // Move kernel
   17.79 -        // 'Gathering' copy in chunks of PAGE_SIZE
   17.80 -        // No risk of overlapping: kernel is copied from above to 1m mark
   17.81 -        pm.size = initrd.size = PAGE_SIZE;
   17.82 -        u32 *p = pm.bufv;
   17.83 -        if (p) while(*p) {
   17.84 -            pm.buf = *p;
   17.85 -            memcpy_image(&pm);
   17.86 -            p++; pm.fallback+=PAGE_SIZE;
   17.87 -        }
   17.88 -        // Move initrd
   17.89 -        if(initrd.fallback) {
   17.90 -            // This is tricky: copy initrd backwards to reduce
   17.91 -            // risk of overlapping: use the fact that initrd is copied
   17.92 -            // to the very top of ram
   17.93 -            // (overlapping still can happen with more than 256mb ram)
   17.94 -            // (generic solution for this overwrite problem, anyone?)
   17.95 -            p=initrd.bufv;
   17.96 -            do {
   17.97 -                p++; initrd.fallback+=PAGE_SIZE;
   17.98 -            } while(*p);
   17.99 -            do {
  17.100 -                p--; initrd.fallback-=PAGE_SIZE;
  17.101 -                initrd.buf = *p;
  17.102 -                memcpy_image(&initrd);
  17.103 -            } while(p != initrd.bufv);
  17.104 -        }
  17.105 -    }
  17.106 -    asm {
  17.107 -#ifndef NO386
  17.108 -        popa
  17.109 -#else
  17.110 -        pop	dx
  17.111 -        pop	cx
  17.112 -        pop	bx
  17.113 -        pop	ax
  17.114 -#endif
  17.115 -        pop     ds
  17.116 -    }
  17.117 -}
  17.118 +u16 rm_size;
  17.119 +u8 pm_high;	// @ = @rm_size + 2, see JUMP.ASM
  17.120 +u8* rm_buf;	// @ = @rm_size + 3, see JUMP.ASM
  17.121 +u32 base_himem = _1m+_64k;
  17.122 +extern struct image_himem pm, initrd;
  17.123  
  17.124  // register value to launch the kernel real mode code
  17.125  #ifdef NO386
  17.126 -static u32 sssp;
  17.127  static u32 csip;
  17.128  extern "C" u16 topseg();
  17.129  #else
  17.130 -const  u32 sssp=0x9000A000;
  17.131  static u32 csip=0x90200000;
  17.132  #define topseg() 0x9000
  17.133  #endif
  17.134 @@ -208,49 +129,49 @@
  17.135  static const char kernel_file_error[] = "Can't use kernel file";
  17.136  char* load_kernel() {
  17.137  
  17.138 +    struct	image_himem *m = &pm;
  17.139  #ifdef NO386
  17.140 -    sssp=((u32)topseg()<<16)+0xA000;
  17.141 -    csip=((u32)(topseg()+0x20)<<16);
  17.142 +    *((u16 *)&csip+1)=topseg()+0x20;
  17.143  #endif
  17.144      // Open kernel, read first kb, check it
  17.145 -    pm.errmsg = kernel_file_error;
  17.146 -    open_image(kernel_name, &pm);
  17.147 +    m->errmsg = kernel_file_error;
  17.148 +    open_image(kernel_name, m);
  17.149  
  17.150      char *version_string;
  17.151    {
  17.152      struct first1k_t *first1k;
  17.153      struct kernelparams_t *kernelparams;
  17.154 -    first1k = (first1k_t*) (rm_buf = malloc_or_die(_32k));
  17.155 -    kernelparams = &first1k->params;
  17.156 +    kernelparams = &(((first1k_t*) (rm_buf = malloc_or_die(_32k)))->params);
  17.157 +#define first1k		((first1k_t*)((u8 *)kernelparams-0x1F1))
  17.158     {
  17.159      u16 rm_seek;
  17.160  
  17.161      // Do not use malloc below until heap_top adjustment (see <*>)
  17.162 -    if (read(pm.fd, rm_buf, rm_seek=0x400) != 0x400) {
  17.163 +    if (read(m->fd, rm_buf, rm_seek=0x400) != 0x400) {
  17.164    readfail:
  17.165          die(kernel_file_error);
  17.166      }
  17.167  
  17.168 -    if(!kernelparams->setup_sects) {
  17.169 +    if(kernelparams->setup_sects == 0) {
  17.170  #if 1
  17.171          if(* (int *) &first1k->pad10[0x3F-0x24] == 0x3AE8) {
  17.172 -            lseek(pm.fd,rm_seek=0x200,SEEK_SET);
  17.173 -            csip=((u32)topseg()<<16)+0x0042;
  17.174 +            seekset(pm.fd,rm_seek=0x200);
  17.175 +            csip+=0xFFE00042;
  17.176          }
  17.177          else
  17.178  #endif
  17.179          kernelparams->setup_sects=4;
  17.180      }
  17.181 -    rm_size = 0x200*(kernelparams->setup_sects+1); // 0th sector is not counted there
  17.182 -    if(rm_size>_32k || kernelparams->boot_flag != 0xAA55)
  17.183 +    if((kernelparams->setup_sects)>=(_32k/512) || // 0th sector not counted
  17.184 +	 kernelparams->boot_flag != 0xAA55)
  17.185          die("It's not a kernel");
  17.186 -    heap_top = rm_buf+rm_size;  // <*>
  17.187 +    heap_top = rm_buf+(rm_size=0x200*(kernelparams->setup_sects+1));  // <*>
  17.188  
  17.189      // Read remaining rm loader
  17.190  
  17.191      {
  17.192      u16 cnt = rm_size-rm_seek;
  17.193 -    if (read(pm.fd, rm_buf+rm_seek, cnt) != cnt) goto readfail;
  17.194 +    if (read(m->fd, rm_buf+rm_seek, cnt) != cnt) goto readfail;
  17.195      }
  17.196     }
  17.197  
  17.198 @@ -275,7 +196,8 @@
  17.199              hook_int15_88();
  17.200  
  17.201              // * will be called just before rm -> pm
  17.202 -            kernelparams->realmode_switch_ofs = ofs(last_ditch);
  17.203 +	    extern void far last_ditch();
  17.204 +            kernelparams->realmode_switch_ofs = ofs((void *)last_ditch);
  17.205              kernelparams->realmode_switch_seg = seg(last_ditch);
  17.206          }
  17.207          if(kernelparams->kernel_version)
  17.208 @@ -295,8 +217,7 @@
  17.209              goto cmd_line_ok;
  17.210          }
  17.211      }
  17.212 -    first1k->cl_magic = 0xA33F;
  17.213 -    first1k->cl_ofs   = 0x8000;
  17.214 +    first1k->cl_magic_ofs = 0x8000A33F;
  17.215    }
  17.216  
  17.217  cmd_line_ok:
  17.218 @@ -307,14 +228,17 @@
  17.219      // Try to load kernel high, maybe even blindly storing it
  17.220      // in unallocated memory as a last resort
  17.221  
  17.222 -    pm.fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4);
  17.223 -    pm.size -= rm_size;
  17.224 -    pm.chunk_size -= rm_size;
  17.225 -    if(pm.fallback+pm.size > (((u32)topseg())<<4) || pm_high) {
  17.226 -        pm.fallback = _1m+_64k;
  17.227 +  {
  17.228 +    struct image_himem *m = &pm;
  17.229 +    m->fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4);
  17.230 +    m->size -= rm_size;
  17.231 +    m->chunk_size -= rm_size;
  17.232 +    if((u16)((m->fallback+m->size)>>4) > topseg() || pm_high) {
  17.233 +        m->fallback = base_himem;
  17.234      }
  17.235  
  17.236 -    load_image(&pm);
  17.237 +    load_image(m);
  17.238 +  }
  17.239      return version_string;
  17.240  }
  17.241  
  17.242 @@ -322,23 +246,19 @@
  17.243  
  17.244  void load_initrd() {
  17.245      struct image_himem *m = &initrd;
  17.246 -    if (!initrd_name && !initrd.fd) return;
  17.247      m->errmsg = "Can't use initrd file";
  17.248 -    if (!pm.errmsg) {
  17.249 -noinitrd:
  17.250 +    if (!initrd_name && !m->fd) return;
  17.251 +
  17.252 +    open_image(initrd_name, m);
  17.253 +
  17.254 +    if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK)) < pm.fallback+pm.size) {
  17.255 +        close(m->fd);
  17.256          puts(m->errmsg);
  17.257          return;
  17.258      }
  17.259 -    open_image(initrd_name, m);
  17.260 -
  17.261 -    m->fallback = (memtop()-m->size) & (~PAGE_MASK);
  17.262 -    if (m->fallback < pm.fallback + pm.size) {
  17.263 -        close(m->fd);
  17.264 -	goto noinitrd;
  17.265 -    }
  17.266  
  17.267      load_image(m);
  17.268 -    struct kernelparams_t *kernelparams = (kernelparams_t *)(rm_buf+0x1F0);
  17.269 +    struct kernelparams_t *kernelparams = &(((first1k_t*) rm_buf)->params);
  17.270      if(kernelparams->header == HdrS) {
  17.271          kernelparams->initrd_buf  = m->fallback;
  17.272          kernelparams->initrd_size = m->size;
  17.273 @@ -352,17 +272,11 @@
  17.274          u16 new_SP=u16(heap_top)+0x100;
  17.275          if(_SP>new_SP) _SP=new_SP;
  17.276      }
  17.277 -    if( u16(_CS)+(u16(_SP)>>4) >= topseg() ) {
  17.278 +    if( (u16(_SP)>>4)+u16(_CS) >= topseg() ) {
  17.279          // Oops! We can stomp on our toes... better stop now
  17.280          die("Loaded too close to 9000:0");
  17.281      }
  17.282  
  17.283 -    cli(); // we start doing destructive things to DOS
  17.284 -
  17.285 -    // Move rm loader & commandline to 0x90000
  17.286 -    // overkill: copy PAGE_SIZE bytes
  17.287 -    rmcpy(rm_buf, rm_size);
  17.288 -
  17.289 -    // Jump to kernel rm code
  17.290 -    set_sregs_jump_seg_ofs(csip, sssp);
  17.291 +    // Move rm loader & commandline to 0x90000, Jump to kernel rm code
  17.292 +    set_sregs_jump_seg_ofs(csip);
  17.293  }
    18.1 --- a/linld/stuff/src/MEMCPY32.ASM	Fri Mar 17 15:14:21 2017 +0200
    18.2 +++ b/linld/stuff/src/MEMCPY32.ASM	Fri Mar 17 15:18:10 2017 +0100
    18.3 @@ -5,7 +5,11 @@
    18.4                  %crefref
    18.5                  %noincl
    18.6                  %nomacs
    18.7 +		ifdef	NO386
    18.8 +                p8086
    18.9 +		else
   18.10                  p386
   18.11 +		endif
   18.12  
   18.13          group   DGROUP  _TEXT,_DATA
   18.14          assume  cs:DGROUP,ds:DGROUP
   18.15 @@ -50,7 +54,7 @@
   18.16  		inc	ah			; set TF
   18.17  		push	ax
   18.18  		popf
   18.19 -		jmp	small [dword bx+4*19h]
   18.20 +		jmp	[dword bx+4*19h]
   18.21  doiret:
   18.22  		iret
   18.23  sssp:
   18.24 @@ -113,37 +117,35 @@
   18.25                          oldGDTR :pword  = TEMP_SIZE
   18.26  
   18.27  ;****** Init ***************************************************
   18.28 -		push	bp
   18.29 -		mov	bp,sp
   18.30 -		sub	sp,TEMP_SIZE
   18.31 -                pushf
   18.32 -		cld
   18.33 -                push    ds es
   18.34  
   18.35  			ifndef	NO386
   18.36  
   18.37 +		enter	TEMP_SIZE,0
   18.38 +		;cld
   18.39 +                pushf
   18.40 +                push    ds es
   18.41                  pushad
   18.42 +		mov	cl,4
   18.43                  movzx   esi,[srcseg]
   18.44 -                shl     esi,4
   18.45 -                add     [srcofs],esi
   18.46 -                mov     esi,[srcofs]
   18.47 +                shl     esi,cl
   18.48 +                add     esi,[srcofs]
   18.49 +                mov     [srcofs],esi		; for memcpy_vcpi
   18.50                  mov     edi,[dstofs]
   18.51  
   18.52  	ifndef	pm_only
   18.53  		mov	eax,esi
   18.54 -		or	eax,edi
   18.55 -		shr	eax,20			; >1mb ?
   18.56 -                jnz     pmcopy
   18.57 -		mov	eax,esi
   18.58 -		shr	eax,4
   18.59 +		shr	eax,cl
   18.60  		mov	edx,edi
   18.61 -		shr	edx,4
   18.62 +		shr	edx,cl
   18.63 +		mov	ecx,esi
   18.64 +		or	ecx,edi
   18.65 +		shr	ecx,20			; >1mb ?
   18.66 +                jnz     @@pmcopy
   18.67  @@movlp:
   18.68  		mov	ds,ax
   18.69  		mov	es,dx
   18.70  		inc	ax
   18.71  		inc	dx
   18.72 -		xor	ecx,ecx
   18.73  		mov	cl,0Fh
   18.74  		and	si,cx
   18.75  		and	di,cx
   18.76 @@ -151,19 +153,25 @@
   18.77                  sub     [sz],ecx
   18.78              rep movsb
   18.79                  ja	@@movlp
   18.80 -		jmp	done
   18.81 +		jmp	@@done
   18.82  	endif
   18.83 -pmcopy:
   18.84 +@@pmcopy:
   18.85  			else
   18.86  
   18.87 +		push	bp
   18.88 +		mov	bp,sp
   18.89 +		sub	sp,TEMP_SIZE
   18.90 +		;cld
   18.91 +                pushf
   18.92 +                push    ds es
   18.93  		push	si
   18.94  		xor	bx,bx
   18.95  		xor	dx,dx
   18.96  		xor	si,si
   18.97 -		mov	ax,[bp+si+8]		; srcseg
   18.98 +		mov	ax,[bp+8]		; srcseg
   18.99  		call	near N_LXLSH@4
  18.100 -		add	[bp+si+10],ax		; srcofs lo
  18.101 -		adc	[bp+si+10+2],dx		; srcofs hi
  18.102 +		add	[bp+10],ax		; srcofs lo
  18.103 +		adc	[bp+10+2],dx		; srcofs hi
  18.104  @@2flat:
  18.105  		mov	ax,[bp+si+10]		; srcofs, dstofs lo
  18.106  		mov	dx,[bp+si+10+2]		; srcofs, dstofs hi
  18.107 @@ -174,8 +182,8 @@
  18.108  		jnz	@@2flat
  18.109  		pop	dx			; dstseg
  18.110  		pop	ax			; srcseg
  18.111 -		or	bx,bx			; <1mb ?
  18.112 -                jnz     pmcopy
  18.113 +		test	bx,bx			; <1mb ? (clear C)
  18.114 +                jnz     @@pmcopy
  18.115  		push	di
  18.116  @@movlp:
  18.117  		mov	ds,ax
  18.118 @@ -190,13 +198,14 @@
  18.119  		inc	cx
  18.120                  sub     [word sz],cx
  18.121              rep movsb
  18.122 -		jae	@@movlp
  18.123 +		ja	@@movlp
  18.124  		dec	[word sz+2]
  18.125 -                jns	@@movlp			; mov 1-16 more bytes...
  18.126 -		pop	di si
  18.127 -		jmp	done16
  18.128 -pmcopy:
  18.129 +		jns	@@movlp			; mov 1-16 more bytes...
  18.130 +		pop	di
  18.131 +@@pmcopy:
  18.132  		pop	si
  18.133 +		js	@@done16
  18.134 +                p386
  18.135                  pushad
  18.136                  mov     esi,[srcofs]
  18.137                  mov     edi,[dstofs]
  18.138 @@ -204,7 +213,7 @@
  18.139  			endif
  18.140  
  18.141                  mov     ecx,[sz]
  18.142 -                jecxz   done
  18.143 +                jecxz   @@done
  18.144  
  18.145  		smsw	ax
  18.146  		test	al,1
  18.147 @@ -216,11 +225,8 @@
  18.148  		extrn	call_pm_routine:near
  18.149                  call    near call_pm_routine ; Call pm copy routine via vcpi pm
  18.150                  pop     ax
  18.151 -		jmp	done
  18.152 +		jmp	@@done
  18.153  @@real_mode:
  18.154 -		mov	dx,-1
  18.155 -
  18.156 -with_movsw:
  18.157                  cmp     esi,edi
  18.158                  jae     @@do_copy
  18.159                  add     esi,ecx         ;src<dst: we must do
  18.160 @@ -236,13 +242,13 @@
  18.161                  mov     eax,cs
  18.162                  shl     eax,4
  18.163                  addzx_e ax,<offset GDT>
  18.164 -                mov     [word GDTR],dx          ;GDT limit = 0FFFFh
  18.165 +                or      [word GDTR],-1          ;GDT limit = 0FFFFh
  18.166                  mov     [dword GDTR+2],eax      ;GDT base
  18.167                  lgdt    [GDTR]
  18.168  
  18.169  ;****** Go into pm *********************************************
  18.170                  mov     eax,cr0
  18.171 -                or      al,01h          ;CR0_PE on
  18.172 +                inc     ax		;CR0_PE on
  18.173                  mov     cr0,eax
  18.174                  jmp     short $+2       ;*Required*!
  18.175                                          ;3+ NOPs also work fine (chkd on 386)
  18.176 @@ -251,9 +257,10 @@
  18.177                  pop     ds              ;base=0, lim = 4gb
  18.178                  push    ds              ;
  18.179                  pop     es              ;
  18.180 -                db      66h     ;operand width override for ecx
  18.181 +                ;db      66h     ;operand width override for ecx
  18.182                  db      67h     ;address width override for esi/edi
  18.183              rep movsb
  18.184 +		cld
  18.185  
  18.186  ;****** Return to rm *******************************************
  18.187                  dec     ax              ;CR0_PE off
  18.188 @@ -263,13 +270,19 @@
  18.189  
  18.190  ;****** Return *************************************************
  18.191                  lgdt    [oldGDTR]
  18.192 -done:
  18.193 +@@done:
  18.194                  popad
  18.195 -done16:
  18.196 +                p8086
  18.197 +@@done16:
  18.198                  pop     es ds
  18.199                  popf
  18.200 +			ifndef	NO386
  18.201 +                p386
  18.202 +		leave
  18.203 +			else
  18.204  		mov	sp,bp
  18.205  		pop	bp
  18.206 +			endif
  18.207                  ret
  18.208  
  18.209  ;****** Const data *********************************************
    19.1 --- a/linld/stuff/src/MEMTOP.ASM	Fri Mar 17 15:14:21 2017 +0200
    19.2 +++ b/linld/stuff/src/MEMTOP.ASM	Fri Mar 17 15:18:10 2017 +0100
    19.3 @@ -5,7 +5,11 @@
    19.4                  %crefref
    19.5                  %noincl
    19.6                  %nomacs
    19.7 +		ifdef	NO386
    19.8 +                p8086
    19.9 +		else
   19.10                  p386
   19.11 +		endif
   19.12  
   19.13          group   DGROUP  _TEXT,_DATA,_BSS
   19.14          assume  cs:DGROUP,ds:DGROUP
   19.15 @@ -38,7 +42,7 @@
   19.16  ;***************************************************************
   19.17  ;        proc    _memtop_e801 near
   19.18  
   19.19 -                push    cx bx
   19.20 +                ;push    cx bx
   19.21                  xor     cx,cx           ;fix to work around buggy
   19.22                  xor     dx,dx           ;  BIOSes which dont clear/set
   19.23                  stc                     ;  carry on pass/error of
   19.24 @@ -54,7 +58,7 @@
   19.25  @@use_cxdx:     xchg    ax,cx
   19.26  @@end_kludge:                   ;now: dx=64k units above 16m
   19.27                                  ;     ax=1k units above 1m below 16m (max 3c00h)
   19.28 -                pop     bx cx
   19.29 +                ;pop     bx cx
   19.30                  test    dx,dx
   19.31                  jz      tokb            ;dx=0 here, ax=kbs above 1m
   19.32                  xor     ax,ax           ;ignore info on low 16M (assume full)
   19.33 @@ -78,10 +82,11 @@
   19.34                  jnc     @@ok            ;  error: cf=1 or ax=0
   19.35                  xor     ax,ax           ;
   19.36  @@ok:
   19.37 -                xor     dx,dx
   19.38 +;                xor     dx,dx
   19.39                  test    ax,ax           ;happens on big mem systems
   19.40                  jz      @@fail
   19.41  tokb:
   19.42 +                xor     dx,dx
   19.43                  add     ah,4h           ;account for 1024 low kb
   19.44                  adc     dx,dx           ;  (optimized to death)
   19.45  		ifndef	NO386
   19.46 @@ -117,7 +122,6 @@
   19.47                  cli
   19.48                  call	rdcmos17
   19.49                  popf
   19.50 -		xor     dx,dx
   19.51  		jmp	tokb
   19.52  
   19.53  rdcmos17:       mov     al,18h		; read bytes 17-18 from CMOS
   19.54 @@ -169,17 +173,22 @@
   19.55  
   19.56  		ifndef  xmm_hook
   19.57                  mov     ax,4300h
   19.58 +		ifdef	NO386
   19.59 +		cwd
   19.60 +		endif
   19.61                  int     2fh
   19.62 -                cmp     al,80h
   19.63 +                cmp     al,80h			; 80h = XMS driver installed
   19.64                  je      @@skip
   19.65  		endif
   19.66 +		ifndef	NO386
   19.67  		push	0
   19.68  		pop	es
   19.69  		mov	bx,15*4
   19.70 -		ifndef	NO386
   19.71  		mov	eax,[bx]
   19.72  		mov	[saved15],eax
   19.73  		else
   19.74 +		mov	es,dx
   19.75 +		mov	bx,15*4
   19.76  		mov	ax,[bx]
   19.77  		mov	[word saved15],ax
   19.78  		mov	ax,[bx+2]
    20.1 --- a/linld/stuff/src/TAZBOOT.CPP	Fri Mar 17 15:14:21 2017 +0200
    20.2 +++ b/linld/stuff/src/TAZBOOT.CPP	Fri Mar 17 15:18:10 2017 +0100
    20.3 @@ -7,19 +7,23 @@
    20.4  #include "common.h"
    20.5  #include "iso9660.h"
    20.6  
    20.7 +struct initrd_info {
    20.8 +	u32 ofs;
    20.9 +	u32 size;
   20.10 +};
   20.11  #define MAXINITRD 10
   20.12  static struct initrd_state {
   20.13 -	u32 ofs[MAXINITRD];
   20.14 -	u32 size[MAXINITRD];
   20.15 +	struct initrd_info info[MAXINITRD];
   20.16  	u16 cnt;
   20.17  } initrd_state;
   20.18  
   20.19  static void next_chunk(struct image_himem *m)
   20.20  {
   20.21 +	struct initrd_info *i = &initrd_state.info[m->state];
   20.22  	m->chunk_size = 0;
   20.23  	if (m->state >= initrd_state.cnt) return;
   20.24 -	lseek(m->fd,initrd_state.ofs[m->state],SEEK_SET);
   20.25 -	m->chunk_size = initrd_state.size[m->state];
   20.26 +	lseekset(m->fd,i->ofs);
   20.27 +	m->chunk_size = i->size;
   20.28  	m->state++;
   20.29  }
   20.30  
   20.31 @@ -30,11 +34,12 @@
   20.32  
   20.33  static void addinitrd()
   20.34  {
   20.35 -	struct initrd_state *p = &initrd_state;
   20.36 -	if (p->cnt >= MAXINITRD) return;
   20.37 -	p->size[p->cnt] = isofilesize;
   20.38 -	p->ofs[p->cnt] = isofileofs;
   20.39 -	p->cnt++;
   20.40 +	u16 *pcnt = &initrd_state.cnt;
   20.41 +	struct initrd_info *i = &initrd_state.info[*pcnt];
   20.42 +	if (*pcnt >= MAXINITRD) return;
   20.43 +	++*pcnt;
   20.44 +	i->size = isofilesize;
   20.45 +	i->ofs = isofileofs;
   20.46  	initrd.size += isofilesize4round();
   20.47  }
   20.48  
   20.49 @@ -57,49 +62,63 @@
   20.50  	return load_kernel();
   20.51  }
   20.52  
   20.53 -char _cmdline[256];
   20.54 -const char *cmdline = (const char *) _cmdline;
   20.55 -extern int skip_xmmalloc;
   20.56 +char _cmdline[4096];
   20.57 +const char *cmdline = (const char *) _cmdline+1;
   20.58  static void bootiso(char **iso)
   20.59  {
   20.60 -	char *init = " rdinit=/init.exe", *mode="menu";
   20.61 -	char *s, c, rootfs[16], fallback[16];
   20.62 -	int restart, isknoppix = 0;
   20.63 +	const char *init = " rdinit=/init.exe", *mode="menu";
   20.64 +	char c;
   20.65 +	static char rootfs[16], fallback[16], isknoppix, noauto;
   20.66 +	int restart;
   20.67  	unsigned long magic;
   20.68 +	struct isostate *x=&isostate;
   20.69  	
   20.70  	if (!*iso || isoreset(*iso) < 0) return;
   20.71 -	skip_xmmalloc++;
   20.72 +	skip_alloc++;
   20.73 +	base_himem = memtop() /2;
   20.74 +	if (base_himem > _64m) base_himem = _64m;
   20.75  	isoopen("boot") >= 0 ||
   20.76  	isoopen("live") >= 0 ||	// debian
   20.77  	isoopen("casper") >= 0;	// ubuntu
   20.78  	if (iso[1] && !strcmp(mode = iso[1], "text"))
   20.79  		init = "";
   20.80  	do {
   20.81 -		if (isoopen(mode) >= 0		||	// custom
   20.82 -		    isoopen("bzImage") >= 0	|| 	// SliTaz
   20.83 -		    isoopen("vmlinuz") >= 0	||	// misc
   20.84 +		if ((isoopen(mode) >= 0 && ++noauto)	||	// custom
   20.85 +		    isoopen("bzImage") >= 0		|| 	// SliTaz
   20.86 +		    isoopen("vmlinuz") >= 0		||	// misc
   20.87  		    (isoopen("linux") >= 0 && ++isknoppix)) {
   20.88  			magic = kver2ul(isokernel());
   20.89  			break;
   20.90  		}
   20.91  	} while (isoopen("isolinux") >= 0);		// Knoppix
   20.92 -	fallback[0] = 0;
   20.93  	for (c = 0, restart = 1; isoreaddir(restart) == 0; restart = 0) {
   20.94 -		if (strstr(isofilename, ".gz"))
   20.95 -			strcpy(fallback, isofilename);
   20.96 -		if (strhead(isofilename, "rootfs") 
   20.97 -			|| c > isofilename[6]) continue;
   20.98 -		strcpy(rootfs, isofilename);
   20.99 -		c = isofilename[6];
  20.100 +		if (strstr(x->filename, ".gz"))
  20.101 +			strcpy(fallback, x->filename);
  20.102 +		if (strhead(x->filename, "rootfs") 
  20.103 +			|| c > x->filename[6]) continue;
  20.104 +		strcpy(rootfs, x->filename);
  20.105 +		c = x->filename[6];
  20.106  	}
  20.107  
  20.108 -	strcpy(_cmdline,"rw root=/dev/null autologin bootfrom=");
  20.109 +	strcatb(_cmdline,"rw root=/dev/null autologin bootfrom=");
  20.110  	strcat(_cmdline,*iso);
  20.111  	if (magic < 0x20630)
  20.112  		init = ""; // Does not support multiple initramfs
  20.113  
  20.114 -	if (magic > 0) {
  20.115 +	if (noauto) {
  20.116 +		char *s;
  20.117 +		* (int *) _cmdline = 0;
  20.118 +		iso++;
  20.119 +		while ((s = *++iso) != NULL) {
  20.120 +			if (strhead(s,"initrd=")) 
  20.121 +				strcatb(_cmdline,s);
  20.122 +			else if (isoopen(s+7) >= 0)
  20.123 +				addinitrd();
  20.124 +		}
  20.125 +	}
  20.126 +	else if (magic > 0) {
  20.127  		char *initrd = fallback;
  20.128 +		static const unsigned long initrddesc = 20L;
  20.129  
  20.130  		if (rootfs[0]) {
  20.131  			initrd = rootfs;
  20.132 @@ -109,29 +128,28 @@
  20.133  		if (isoopen(initrd) >= 0) {
  20.134  			addinitrd();
  20.135  		}
  20.136 -		if (*init && lseek(isofd, 20L, SEEK_SET) != -1) {
  20.137 -			read(isofd, &isofileofs, 4);
  20.138 -			read(isofd, &magic, 4);
  20.139 -			isofileofs &= 0xFFFFL;
  20.140 -			isofilesize = magic & 0xFFFFL;
  20.141 -			isofileofs -= 0xC0L + isofilesize;
  20.142 -			if (isofilesize) addinitrd();
  20.143 +		if (*init && isolseek(&initrddesc) != -1) {
  20.144 +			read(x->fd, &x->fileofs, 8); // and x->filesize
  20.145 +			x->fileofs &= 0xFFFFL;
  20.146 +			x->fileofs -= 0xC0L + (x->filesize &= 0xFFFF);
  20.147 +			if (((short *) &x->fileofs)[1] == 0) addinitrd();
  20.148  			else init="";
  20.149  		}
  20.150 -		load_initrds();
  20.151  		strcat(_cmdline,init);
  20.152  		strcatb(_cmdline,"mode=");
  20.153  		strcat(_cmdline,mode);
  20.154  		strcatb(_cmdline,"magic=");
  20.155  		strcat(_cmdline,ultoa(magic));
  20.156  	}
  20.157 +	load_initrds();
  20.158  	if (isknoppix) {
  20.159 -		if (iso[0][1] == ':')
  20.160 -			*iso += 2;
  20.161 -		for (s = *iso; *s; s++)
  20.162 +		char *s = *iso;
  20.163 +		if (s[1] == ':')
  20.164 +			s += 2;
  20.165 +		for (; *s; s++)
  20.166  			if (*s == '\\') *s = '/';
  20.167  	}
  20.168 -	close(isofd);
  20.169 +	close(x->fd);
  20.170  	boot_kernel();
  20.171  }
  20.172  
  20.173 @@ -148,7 +166,7 @@
  20.174  	if (argc < 2) {
  20.175  		try_default_args();
  20.176  dousage:
  20.177 -		die("Usage: tazboot [[@commands]|[-f][kernel=<bzimage>] \
  20.178 +		die("Usage: tazboot [[@commands]|[-f][-b base_himem][kernel=<bzimage>] \
  20.179  [initrd=<rootfs>[,<rootfs2>...]] [bootfrom=<isofile>] ...]\r\n\n\
  20.180  Defaults: tazboot kernel=bzImage auto\r\n\n\
  20.181  Examples for tazboot.cmd:\r\n\n\
  20.182 @@ -163,17 +181,17 @@
  20.183  	chdirname(*argv);
  20.184  	for (int i=0;;) {
  20.185  		char *s;
  20.186 -		argv++;
  20.187 +	next:	argv++;
  20.188  		s=*argv;
  20.189  		i++;
  20.190  		if (!s) break;
  20.191  		if (strhead(s,"kernel=") == 0) {
  20.192 -			s += 7;
  20.193 +			s++;
  20.194  	set_kernel:
  20.195 +			s += 6;
  20.196  			kernel_name = s;
  20.197  		}
  20.198  		else if (strhead(s,"image=") == 0) {
  20.199 -			s += 6;
  20.200  			goto set_kernel;
  20.201  		}
  20.202  		else if (strhead(s,"initrd=") == 0) {
  20.203 @@ -193,10 +211,20 @@
  20.204  			s += 4;
  20.205  			vid_mode = strtol(s);	// support normal, extended & ask
  20.206  		}
  20.207 -		else if((*(u16 *)s|0x2002) == 0x662F) { // -F /f
  20.208 -			skip_xmmalloc++;
  20.209 -		}
  20.210 -		else if(i == 1 && fileattr(s) != -1) {
  20.211 +	        else switch (*(u16 *)s|0x2002) {
  20.212 +		case 0x662F:	// -F /f
  20.213 +			skip_alloc++;
  20.214 +			goto next;
  20.215 +		case 0x652F:	// -E /e
  20.216 +			argv++;
  20.217 +			topmem = strtol(*argv);
  20.218 +			goto next;
  20.219 +		case 0x622F:	// -B /b
  20.220 +			argv++;
  20.221 +			base_himem = strtol(*argv);
  20.222 +			goto next;
  20.223 +		default:
  20.224 +		if(i == 1 && fileattr(s) != -1) {
  20.225  			goto set_kernel;
  20.226  		}
  20.227  		else {
  20.228 @@ -209,7 +237,7 @@
  20.229  				topmem = strtol(s);
  20.230  			}
  20.231  			strcatb(_cmdline,*argv);
  20.232 -		}
  20.233 +		}}
  20.234  	}
  20.235  	if (iso && isoreset(iso) >= 0) {
  20.236  		char *s = (char *) initrd_name;
    21.1 --- a/linld/stuff/src/VCPI.ASM	Fri Mar 17 15:14:21 2017 +0200
    21.2 +++ b/linld/stuff/src/VCPI.ASM	Fri Mar 17 15:18:10 2017 +0100
    21.3 @@ -65,11 +65,6 @@
    21.4  use_32          = 01000000b
    21.5  
    21.6  ;****** rm32,imm16 helpers
    21.7 -macro   movzx_e rm,i
    21.8 -        db      66h
    21.9 -        mov     rm,i
   21.10 -        dw      0
   21.11 -endm
   21.12  macro   addzx_e rm,i
   21.13          db      66h
   21.14          add     rm,i
   21.15 @@ -77,13 +72,11 @@
   21.16  endm
   21.17  
   21.18  
   21.19 -        group   DGROUP  _TEXT,_DATA
   21.20 +        group   DGROUP  _TEXT,_DATA,_BSS
   21.21          assume  cs:DGROUP,ds:DGROUP
   21.22  
   21.23          segment _DATA byte public use16 'DATA'
   21.24  
   21.25 -tss             dd      0,0     ;enough, we'll never use it anyway
   21.26 -
   21.27  label   gdt     byte
   21.28  gdt_null        descr   <?>     ;0000
   21.29  gdt_vcpi        descr   <?>     ;0008
   21.30 @@ -104,39 +97,42 @@
   21.31  label   gdtr    pword
   21.32  gdt_lim         dw      0ffffh
   21.33  gdt_base        dw      offset gdt,0
   21.34 -label   idtr    pword
   21.35 -idt_lim         dw      03ffh   ;we won't enable ints,
   21.36 -idt_base        dd      0       ;  so let's leave it the same as for rm
   21.37  
   21.38  ;Note: layout dictated by vcpi api, don't rearrange!
   21.39  label sw2pm_params byte
   21.40  ;Note: base addrs will be fixed up in prepare_vcpi()
   21.41 +label	pagedir_laddr   dword
   21.42  sw2pm_cr3       dd      ?
   21.43  sw2pm_gdtr_ptr  dw      offset gdtr,0
   21.44  sw2pm_idtr_ptr  dw      offset idtr,0
   21.45  sw2pm_ldtr      dw      0       ;we don't need it
   21.46  sw2pm_tr        dw      SEL_TSS ;vcpi thinks we need it... can't set to 0
   21.47 -sw2pm_jumpaddr  dd      ?
   21.48 +sw2pm_jumpaddr  dd      0
   21.49                  dw      SEL_CODE
   21.50  
   21.51 +vcpi_pm_entry   dd      0
   21.52 +                dw      SEL_VCPI
   21.53 +
   21.54 +label   idtr    pword
   21.55 +idt_lim         dw      03ffh   ;we won't enable ints,
   21.56 +idt_base        dd      0       ;  so let's leave it the same as for rm
   21.57 +
   21.58 +        ends    _DATA
   21.59 +
   21.60 +        segment _BSS byte public use16 'BSS'
   21.61 +
   21.62  ;Pagedir/page0 addrs: linear, seg:0 and cs:ofs
   21.63 -pagedir_laddr   dd      ?
   21.64  page0_laddr     dd      ?
   21.65 -;;pagedir_seg     dw      ?
   21.66 -;;page0_seg       dw      ?
   21.67 -pagedir_ofs     dw      ?
   21.68 -page0_ofs       dw      ?
   21.69 -
   21.70 -vcpi_pm_entry   dd      ?
   21.71 -                dw      SEL_VCPI
   21.72 +;pagedir_ofs     dw      ?
   21.73 +;page0_ofs       dw      ?
   21.74  
   21.75  label   saved_ss_sp dword
   21.76  saved_sp        dw      ?
   21.77  saved_ss        dw      ?
   21.78  
   21.79 +tss             dd      ?,?     ;enough, we'll never use it anyway
   21.80  
   21.81 -        ends    _DATA
   21.82 -
   21.83 +        ends    _BSS
   21.84  
   21.85          segment _TEXT byte public use16 'CODE'
   21.86  
   21.87 @@ -166,45 +162,51 @@
   21.88  
   21.89  		mov	cl,4
   21.90                  mov     edx,cs
   21.91 -                shl     edx,cl          ;ebx = linear addr of CS
   21.92 -                mov     bx, offset page0_laddr
   21.93 +                shl     edx,cl          ;edx = linear addr of CS
   21.94 +                mov     si,offset gdt_vcpi
   21.95  ; Fix up base of some gdt descriptors
   21.96  ; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity!
   21.97  ; Do NOT replace with mov!
   21.98 -                add     [dword bx+gdt_base-page0_laddr],edx
   21.99 -                add     [dword bx+sw2pm_gdtr_ptr-page0_laddr],edx
  21.100 -                add     [dword bx+sw2pm_idtr_ptr-page0_laddr],edx
  21.101 -                add     [dword bx+(gdt_code.base0)-page0_laddr],edx
  21.102 -                add     [dword bx+(gdt_data.base0)-page0_laddr],edx
  21.103 -                add     [dword bx+(gdt_tss.base0)-page0_laddr],edx
  21.104 +		xor	ebx,ebx
  21.105 +                add     [dword bx+si+sw2pm_idtr_ptr-gdt_vcpi],edx
  21.106 +@@fixup:
  21.107 +                add     [dword bx+si+(gdt_code.base0)-gdt_vcpi],edx
  21.108 +		add	bl,8
  21.109 +		cmp	bl,28h
  21.110 +		jb	@@fixup
  21.111 +                ;add     [dword si+(gdt_data.base0)-gdt_vcpi],edx
  21.112 +                ;add     [dword si+(gdt_tss.base0)-gdt_vcpi],edx
  21.113 +                ;add     [dword si+gdt_base-gdt_vcpi],edx
  21.114 +                ;add     [dword si+sw2pm_gdtr_ptr-gdt_vcpi],edx
  21.115 +                ;add     [dword si+sw2pm_idtr_ptr-gdt_vcpi],edx
  21.116                  add     eax,edx
  21.117 -                mov     esi,0FFFh
  21.118 -                add     eax,esi
  21.119 -		inc	si		;esi=00001000h
  21.120 +                mov     bx,0FFFh
  21.121 +                add     eax,ebx
  21.122 +		inc	bx		;ebx=00001000h
  21.123  
  21.124                  shr     eax,cl
  21.125                  mov     al,0   ;eax = 4k aligned linear addr of pagebuf
  21.126                  mov     es,ax           ;es:0->page0,es:1000h->pagedir
  21.127                  shl     eax,cl          ;eax=page0 linear addr
  21.128 -                mov     [bx+page0_laddr-page0_laddr],eax
  21.129                  mov     al,3            ;add present+writable bits
  21.130 -                mov     [es:si],eax     ;stuff it into pagedir[0]
  21.131 +                mov     [es:bx],eax     ;stuff it into pagedir[0]
  21.132 +                push    ds
  21.133 +                pop     es
  21.134  
  21.135 -                add     eax,esi
  21.136  		mov	al,0
  21.137 -                mov     [bx+pagedir_laddr-page0_laddr],eax
  21.138 +                mov     [page0_laddr],eax
  21.139 +                add     eax,ebx
  21.140 +                ;mov     [pagedir_laddr],eax
  21.141                          ;page directory will use only one entry (4 bytes):
  21.142                          ;cr3 => pagedir => page0  => ########
  21.143                          ;      (1 entry)  (1024   => #  4M  #
  21.144                          ;                 entries)=> # page #
  21.145                          ;                         => ########
  21.146 -                mov     [bx+sw2pm_cr3-page0_laddr],eax
  21.147 +                mov     [sw2pm_cr3],eax
  21.148                  sub     eax,edx         ;ax = offset in CS of pagedir
  21.149 -                mov     [bx+pagedir_ofs-page0_laddr],ax
  21.150 -                sub     ax,si   ;ax-=1000
  21.151 -                mov     [bx+page0_ofs-page0_laddr],ax
  21.152 -                push    ds
  21.153 -                pop     es
  21.154 +                ;mov     [pagedir_ofs],ax
  21.155 +                sub     ax,bx   ;ax-=1000
  21.156 +                ;mov     [page0_ofs],ax
  21.157                  mov     di,ax          ;ES:DI => page0
  21.158  ; Return
  21.159                  ;pop     es
  21.160 @@ -219,8 +221,8 @@
  21.161  
  21.162  ;***************************************************************
  21.163  ;int get_vcpi_interface();
  21.164 -;****** Return: AX=1 - page mapping for low 640k is 1:1
  21.165 -;******         AX=0 - otherwise (it's bad)
  21.166 +;****** Return: Z  - page mapping for low 640k is 1:1
  21.167 +;******         NZ - otherwise (it's bad)
  21.168  ;****** Uses:   Flags
  21.169  ;***************************************************************
  21.170          global  _get_vcpi_interface:near
  21.171 @@ -229,32 +231,29 @@
  21.172                  ;push    si di
  21.173  
  21.174  ; Get and save VCPI pm interface
  21.175 -                mov     si,offset gdt_vcpi      ;DS:DI => 3 GDT entries for VCPI
  21.176 +                ;mov     si,offset gdt_vcpi      ;DS:DI => 3 GDT entries for VCPI
  21.177                  ;mov     di,[si+page0_ofs-gdt_vcpi]          ;ES:DI => page0
  21.178                  ;push    ds
  21.179                  ;pop     es
  21.180 +                push    di
  21.181                  mov     ax,0DE01h               ;get vcpi pm interface
  21.182                  int     67h
  21.183 -                mov     [vcpi_pm_entry],ebx
  21.184 +                xchg    [vcpi_pm_entry],ebx	;clear ebx
  21.185 +                ;xor     bx,bx
  21.186  
  21.187  ; Check that mapping for low 640k is 1:1
  21.188 -                mov     si,[page0_ofs]
  21.189 -                xor     bx,bx
  21.190 -                cld
  21.191 +                pop     si			; [page0_ofs]
  21.192 +                ;cld
  21.193  @@map_chk:
  21.194                  lodsd
  21.195                  shr     eax,12
  21.196                  cmp     ax,bx
  21.197 -                stc
  21.198                  jne     @@bad
  21.199                  inc     bx
  21.200 -                cmp     ax,((640*1024) shr 12)-1
  21.201 +                cmp     al,((640*1024) shr 12)-1
  21.202                  jne     @@map_chk
  21.203  ; Return
  21.204  @@bad:
  21.205 -                sbb     ax,ax
  21.206 -                inc	ax			; update Z
  21.207 -                ;pop     di si
  21.208                  ret
  21.209          endp    _get_vcpi_interface
  21.210  
  21.211 @@ -302,17 +301,10 @@
  21.212                  push    ax              ;\eip
  21.213                  push    offset @@vm_ret ;/
  21.214  
  21.215 -                cli
  21.216                ;;mov     [saved_xx],xx   ;use if your vcpi trashes bp/etc
  21.217  
  21.218 -                movzx_e <[word sw2pm_jumpaddr]>,<offset @@pm_entry>
  21.219 -               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
  21.220 -                mov     esi,cs
  21.221 -                shl     esi,4
  21.222 -                addzx_e si,<offset sw2pm_params>
  21.223 -                mov     ax,0DE0Ch       ; vcpi: switch to pm
  21.224 -                int     67h
  21.225 -@@pm_entry:
  21.226 +		call	switch_to_pm
  21.227 +
  21.228  ; Now we are in 16-bit protected mode
  21.229                  mov     ax,SEL_DATA
  21.230                  mov     ss,ax
  21.231 @@ -332,17 +324,30 @@
  21.232                  call    ax
  21.233  
  21.234  ; Ok, let's return to vm
  21.235 +                mov     ax,0DE0Ch       ; maybe we need whole eax?
  21.236                  cli     ; to be safe
  21.237                  clts    ;
  21.238                  push    SEL_ABS         ; vcpi wants ds=all_addrspace
  21.239                  pop     ds              ;
  21.240 -                mov     ax,0DE0Ch       ; maybe we need whole eax?
  21.241                  call    [pword cs:vcpi_pm_entry]
  21.242  @@vm_ret:
  21.243  ; Now we are in vm86 mode. Sregs, esp, eflags (IF) restored from IRET stack
  21.244                  ret
  21.245  
  21.246  ;***************************************************************
  21.247 +switch_to_pm:
  21.248 +                assume  cs:DGROUP,ds:DGROUP
  21.249 +                pop	[word sw2pm_jumpaddr]
  21.250 +               ;mov     [word sw2pm_jumpaddr+2],0
  21.251 +               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
  21.252 +                mov     esi,cs
  21.253 +                shl     esi,4
  21.254 +                addzx_e si,<offset sw2pm_params>
  21.255 +                mov     ax,0DE0Ch       ; vcpi: switch to pm
  21.256 +                cli
  21.257 +                int     67h
  21.258 +
  21.259 +;***************************************************************
  21.260  ;****** Helper: This is where real copy is done
  21.261  ;***************************************************************
  21.262  	global	do_memcpy_vcpi:near
  21.263 @@ -350,30 +355,28 @@
  21.264  
  21.265  ; Note: ss:bp => params
  21.266  ; Move data
  21.267 -                mov     cx,SEL_ABS
  21.268 -                mov     ds,cx
  21.269 -                mov     es,cx
  21.270 +                mov     ax,SEL_ABS
  21.271 +                mov     ds,ax
  21.272 +                mov     es,ax
  21.273                  assume  nothing
  21.274                  assume  cs:DGROUP
  21.275  
  21.276          ; Set up target addr:
  21.277          ; replace page mapping for page at 0 so
  21.278          ; that it points to dstofs
  21.279 -                mov     esi,[cs:page0_laddr]
  21.280                  mov     eax,[dstofs]
  21.281                  mov     al,03h          ; writeable, present
  21.282 -                xchg    [esi],eax       ; replace page0[0]
  21.283 +		call	@@set_mapping
  21.284                 ;push    eax             ;X we'll need to restore mapping...
  21.285 -                mov     ecx,cr3         ; reload TLB cache
  21.286 -                mov     cr3,ecx         ;
  21.287                  xor     edi,edi         ;es:edi => remapped page
  21.288  
  21.289          ; Set up source addr
  21.290                  mov     esi,[srcofs]
  21.291  
  21.292          ; Do copying
  21.293 -                mov     ecx,4096/2
  21.294 -                cld
  21.295 +		xor	ecx,ecx
  21.296 +                mov     ch,4096/256
  21.297 +                ;cld
  21.298  ;;              cmp     esi,edi
  21.299  ;;              jae     @@do_copy
  21.300  ;;              add     esi,ecx         ;src<dst: we must do
  21.301 @@ -383,13 +386,14 @@
  21.302  ;;              std                     ;
  21.303  ;;@@do_copy:
  21.304                  db      67h     ;address width override for esi/edi
  21.305 -            rep movsw
  21.306 +            rep movsb
  21.307  ;;              cld
  21.308  
  21.309          ; Restore page mapping for page at 0
  21.310                 ;pop     eax             ;X
  21.311 +@@set_mapping:
  21.312                  mov     esi,[cs:page0_laddr]
  21.313 -                mov     [esi],eax       ; restore page0[0]
  21.314 +                xchg    [esi],eax       ; restore page0[0]
  21.315                  mov     ecx,cr3         ; reload TLB cache
  21.316                  mov     cr3,ecx         ;
  21.317  ; Return
  21.318 @@ -407,30 +411,29 @@
  21.319          global  _vm2rm:near
  21.320          proc    _vm2rm near
  21.321  
  21.322 -                push	esi
  21.323 +                p8086
  21.324 +		extrn	_vcpi:byte
  21.325 +		test	[_vcpi],-1
  21.326 +		jz	@@ret
  21.327 +                p386
  21.328 +                push	si
  21.329                ;;pushf
  21.330 -              ;;cli
  21.331                ;;pushad
  21.332                  push    cs      ;*
  21.333                  push    ds
  21.334 +                ;push    es
  21.335                  mov     [saved_ss],ss
  21.336                  mov     [saved_sp],sp
  21.337  
  21.338 -                movzx_e <[word sw2pm_jumpaddr]>,<offset @@pm_entry>
  21.339 -               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
  21.340 -                mov     esi,cs
  21.341 -                shl     esi,4
  21.342 -                addzx_e si,<offset sw2pm_params>
  21.343 -                mov     ax,0DE0Ch       ; vcpi: switch to pm
  21.344 -                int     67h
  21.345 +		call	switch_to_pm
  21.346 +
  21.347  ; Now we are in 16-bit protected mode
  21.348 -@@pm_entry:
  21.349                  mov     ax,SEL_DATA     ; load data sregs with limit >=64k
  21.350                  mov     ss,ax           ;   or you may get limit violations
  21.351                  mov     ds,ax           ;   later in rm
  21.352 -                mov     es,ax           ;   (actually I prefer 4gig limits :-)
  21.353 -                mov     fs,ax           ;
  21.354 -                mov     gs,ax           ;
  21.355 +                ;mov     es,ax           ;   (actually I prefer 4gig limits :-)
  21.356 +                ;mov     fs,ax           ;
  21.357 +                ;mov     gs,ax           ;
  21.358  
  21.359  ; Black magic here
  21.360                  mov     eax,cr0
  21.361 @@ -442,6 +445,7 @@
  21.362  
  21.363  ; Now we are in rm, but not yet: have to restore sregs:
  21.364                  lss     sp,[saved_ss_sp]; SS
  21.365 +                ;pop     es              ; ES
  21.366                  pop     ds              ; DS
  21.367                 ;push    cs      ;* done earlier
  21.368                  push    offset @@next
  21.369 @@ -449,8 +453,10 @@
  21.370  @@next:
  21.371                ;;popad
  21.372                ;;popf
  21.373 -                pop	esi
  21.374 -                ret             ; We don't care much about rest (ES/FS/GS)
  21.375 +                pop	si
  21.376 +@@ret:
  21.377 +                ret             ; We don't care much about rest (FS/GS)
  21.378 +
  21.379          endp    _vm2rm
  21.380  
  21.381          ends    _TEXT
    22.1 --- a/linld/stuff/src/XMM.ASM	Fri Mar 17 15:14:21 2017 +0200
    22.2 +++ b/linld/stuff/src/XMM.ASM	Fri Mar 17 15:18:10 2017 +0100
    22.3 @@ -5,7 +5,11 @@
    22.4                  %crefref
    22.5                  %noincl
    22.6                  %nomacs
    22.7 +		ifdef	NO386
    22.8 +                p8086
    22.9 +		else
   22.10                  p386
   22.11 +		endif
   22.12  
   22.13          group   DGROUP  _TEXT,_BSS
   22.14          assume  cs:DGROUP,ds:DGROUP
   22.15 @@ -39,7 +43,12 @@
   22.16          global  xmm_driver:near
   22.17          proc    xmm_driver near
   22.18  
   22.19 +		ifndef	NO386
   22.20  		cmp	[xmm_handler],0
   22.21 +		else
   22.22 +		mov	ax,[word xmm_handler]
   22.23 +		or	ax,[word xmm_handler+2]
   22.24 +		endif
   22.25  		jne	@@gotit
   22.26  
   22.27  		xchg	ax,cx			; save cmd
    23.1 --- a/linld/stuff/src/_BEG.ASM	Fri Mar 17 15:14:21 2017 +0200
    23.2 +++ b/linld/stuff/src/_BEG.ASM	Fri Mar 17 15:18:10 2017 +0100
    23.3 @@ -5,13 +5,17 @@
    23.4                  %crefref
    23.5                  %noincl
    23.6                  %nomacs
    23.7 -                p386
    23.8 +                p8086
    23.9  
   23.10          group   DGROUP  _TEXT,_DATA,_BSS
   23.11          assume  cs:DGROUP,ds:DGROUP
   23.12  
   23.13          segment _TEXT byte public use16 'CODE'
   23.14  
   23.15 +	macro   cpuid
   23.16 +        	db      0fh,0A2h
   23.17 +	endm
   23.18 +
   23.19                  org     100h
   23.20          global  _text_start:byte
   23.21          label   _text_start byte
   23.22 @@ -24,36 +28,47 @@
   23.23  		mov	[byte bx],0		; clear bss + heap + sp
   23.24  		inc	bx
   23.25  		jne	clearbss
   23.26 +                cld
   23.27  
   23.28  ;***************************************************************
   23.29  ; check CPU
   23.30  ;***************************************************************
   23.31  
   23.32  ; Check for oldies
   23.33 -		mov	bh, 0F0h
   23.34 -		pushf
   23.35 -		push	bx		; < 286 : flags[12..15] are forced 1
   23.36 -		popf			; = 286 : flags[12..15] are forced 0
   23.37 -		pushf			; > 286 : only flags[15] is forced 0
   23.38 +		push	sp
   23.39 +		pop	ax
   23.40 +		mov	bx,offset msg_badcpu
   23.41 +		sub	ax,sp
   23.42 +		ifndef	NO386
   23.43 +                jnz	no_vcpi   	;it is a 86/186 not a 286+
   23.44 +		else
   23.45 +		jnz	endcpu
   23.46 +		endif
   23.47 +                p386
   23.48 +		ifdef	EXTRA
   23.49 +		pushfd
   23.50  		pop	dx
   23.51 -		popf
   23.52 -		add	dh,bh		; NS=386+, NC=286
   23.53 -		ifndef	NO386
   23.54 -                js	no_vcpi   	;it is a 86/186/286, not a 386+
   23.55 -		else
   23.56 -		js	endcpu
   23.57 +		pop	ax
   23.58 +		mov	bl,al
   23.59 +		xor	al,20h		; toggle CPUID feature bit 21
   23.60 +		push	ax
   23.61 +		push	dx
   23.62 +		popfd
   23.63 +		pushfd
   23.64 +		pop	dx
   23.65 +		pop	ax
   23.66 +		xor	al,bl		; clear C
   23.67 +		je	@@check_vm	; CPUID feature bit changed ?
   23.68 +		mov	eax,80000001h	; Extended Processor Info and Feature Bits
   23.69 +		cpuid
   23.70 +		mov	[_cpu_features],edx
   23.71 +@@check_vm:
   23.72  		endif
   23.73  ; Check for vm
   23.74                  smsw    ax      ;SMSW cannot be trapped! :-)
   23.75 -                and     ax,1	;MSW_PE
   23.76 +                and     al,1	;MSW_PE
   23.77  ; We're in vm
   23.78 -                jnz     check_vcpi
   23.79 -
   23.80 -; It's a 386 in real mode, chk for paging (crazy but possible)
   23.81 -                mov     edx,cr0
   23.82 -                shl     edx,1   ;CR0_PG to CF
   23.83 -		jc	no_vcpi
   23.84 -		jmp	endcpu
   23.85 +		jz	check_rm_paging
   23.86  
   23.87  ;***************************************************************
   23.88  ; checks for vcpi
   23.89 @@ -61,24 +76,27 @@
   23.90  label   check_vcpi near
   23.91                  push    ds
   23.92  ; Check whether it is safe to call 67h (we trust only known EMM managers)
   23.93 -                push    0
   23.94 +		xor	bx,bx
   23.95 +                push    bx
   23.96                  pop     ds
   23.97                  mov     ds,[word 67h*4+2]
   23.98 -                cmp     [dword 10+4],'0XXX'
   23.99 +                cmp     [dword bx+10+4],'0XXX'
  23.100                  jne     skip
  23.101 -                mov     eax,'XMME'
  23.102 -                xor     eax,[dword 10]
  23.103 +		;mov	eax,'XMME'
  23.104 +		;xor	eax,[dword bx+10]
  23.105          ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
  23.106 -                shl     eax,8
  23.107 +		;shl	eax,8
  23.108 +		mov	ax,'ME'
  23.109 +		xor	ax,[word bx+10]
  23.110  skip:
  23.111                  pop     ds
  23.112                  jne     no_vcpi
  23.113  
  23.114  ; Check emm manager status and version
  23.115 -                mov     ah,40h          ; get status
  23.116 -                int     67h
  23.117 -                test    ah,ah
  23.118 -                jnz     no_vcpi
  23.119 +                ;mov     ah,40h          ; get status
  23.120 +                ;int     67h
  23.121 +                ;test    ah,ah
  23.122 +                ;jnz     no_vcpi
  23.123                  mov     ah,46h          ; get version
  23.124                  int     67h
  23.125                  test    ah,ah
  23.126 @@ -94,27 +112,33 @@
  23.127                ;;push    dx              ;$ save handle
  23.128                  mov     ax,0DE00h       ; check for vcpi present
  23.129                  int     67h
  23.130 -                mov     al,1
  23.131                  test    ah,ah
  23.132 -                jz      is386vcpi
  23.133 -              ;;pop     dx              ;$ handle
  23.134 -              ;;mov     ax,4500h        ; DEALLOCATE PAGES
  23.135 -              ;;int     67h
  23.136 -no_vcpi:
  23.137 -		mov	bx,offset msg_badcpu
  23.138 -                extrn   die:near
  23.139 -godie:
  23.140 -		jmp	near die
  23.141 +		jnz	no_vcpi
  23.142  is386vcpi:
  23.143 -		mov	[_vcpi],al
  23.144 +		inc	[_vcpi]
  23.145                  extrn   prepare_vcpi:near
  23.146  		call	prepare_vcpi
  23.147  ;    get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
  23.148                  ;extrn   _get_vcpi_interface:near
  23.149  		;call	_get_vcpi_interface
  23.150  		mov	bx,offset msg_badmapping
  23.151 -		jz	godie
  23.152 +		jz	endcpu
  23.153 +no_vcpi:
  23.154 +                p8086
  23.155 +              ;;pop     dx              ;$ handle
  23.156 +              ;;mov     ax,4500h        ; DEALLOCATE PAGES
  23.157 +              ;;int     67h
  23.158 +                extrn   die:near
  23.159 +godie:
  23.160 +		jmp	near die
  23.161 +check_rm_paging:
  23.162 +; It's a 386 in real mode, chk for paging (crazy but possible)
  23.163 +                p386
  23.164 +                mov     edx,cr0
  23.165 +                shl     edx,1   ;CR0_PG to CF
  23.166 +		jc	no_vcpi
  23.167  endcpu:
  23.168 +                p8086
  23.169  
  23.170  ;***************************************************************
  23.171  ; build argv & argc
  23.172 @@ -125,7 +149,6 @@
  23.173                  ;push	ax			; envp (already cleared)
  23.174                  ;mov	[word di],ax		; argv[0] = 0 (idem)
  23.175                  mov	si,80h
  23.176 -                cld
  23.177                  lodsb
  23.178                  cmp	al,7Eh
  23.179                  jbe	alok
  23.180 @@ -220,6 +243,10 @@
  23.181          segment _BSS byte public use16 'BSS'
  23.182          global  _bss_start:byte
  23.183          label   _bss_start byte
  23.184 +		ifdef	EXTRA
  23.185 +        global  _cpu_features:dword
  23.186 +_cpu_features	dd	?
  23.187 +		endif
  23.188          ends    _BSS
  23.189  
  23.190          end     _text_start
    24.1 --- a/linld/stuff/upx.sh	Fri Mar 17 15:14:21 2017 +0200
    24.2 +++ b/linld/stuff/upx.sh	Fri Mar 17 15:18:10 2017 +0100
    24.3 @@ -1,4 +1,8 @@
    24.4  #!/bin/sh
    24.5  
    24.6 -upx -5 $1 && echo "0  3C E8 75 FB 89 F7 AD 86 E0 29 F8 AB |" | hexdump -R | \
    24.7 -dd bs=1 seek=$(($(stat -c %s $1) - 15)) of=$1 conv=notrunc 2> /dev/null
    24.8 +if upx 2>&1 | grep -q "UPX 3.91" ; then
    24.9 +  upx -5 $1 && echo "0  3C E8 75 FB 89 F7 AD 86 E0 29 F8 AB |" | hexdump -R | \
   24.10 +  dd bs=1 seek=$(($(stat -c %s $1) - 15)) of=$1 conv=notrunc 2> /dev/null
   24.11 +else
   24.12 +  upx -5 --8086 $1
   24.13 +fi