wok rev 20146

linld: tiny shrink
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Nov 16 11:02:48 2017 +0100 (2017-11-16)
parents d40bfc9d243c
children ad173981cb30
files linld/stuff/src/CRTL.ASM
line diff
     1.1 --- a/linld/stuff/src/CRTL.ASM	Sun Nov 12 09:57:44 2017 +0000
     1.2 +++ b/linld/stuff/src/CRTL.ASM	Thu Nov 16 11:02:48 2017 +0100
     1.3 @@ -105,6 +105,71 @@
     1.4          endp    _strcatb
     1.5  
     1.6  
     1.7 +	ifdef	EXTRA
     1.8 +                p8086
     1.9 +;***************************************************************
    1.10 +;char strstr(const char* a,const char* b);
    1.11 +;***************************************************************
    1.12 +        global  _strstr:near
    1.13 +        proc    _strstr near
    1.14 +
    1.15 +		pop	ax			;caller return address
    1.16 +                pop	dx			; a
    1.17 +                pop	cx			; b
    1.18 +                push	cx
    1.19 +                push	dx
    1.20 +                push	ax
    1.21 +                push	si
    1.22 +@@loop:
    1.23 +		xor	ax,ax
    1.24 +		mov	si,dx
    1.25 +		cmp	[si],al			; *a
    1.26 +		jz	strend			; return ax = NULL
    1.27 +		mov	bx,cx
    1.28 +@@match:
    1.29 +		or	ah,[bx]			; *b
    1.30 +		jz	strfound
    1.31 +		inc	bx
    1.32 +		lodsb
    1.33 +		sub	ah,al
    1.34 +		jz	@@match
    1.35 +		inc	dx
    1.36 +		jmp	@@loop
    1.37 +
    1.38 +        endp    _strstr
    1.39 +
    1.40 +
    1.41 +;***************************************************************
    1.42 +;int strcmp(const char* a,const char* b);
    1.43 +;***************************************************************
    1.44 +        global  _strcmp:near
    1.45 +        proc    _strcmp near
    1.46 +
    1.47 +		pop	cx			;caller return address
    1.48 +                pop	bx			; a
    1.49 +                pop	ax			; b
    1.50 +                push	ax
    1.51 +                push	bx
    1.52 +                push	cx
    1.53 +                push	si
    1.54 +		xchg	ax,si
    1.55 +		dec	bx
    1.56 +@@lp:
    1.57 +		inc	bx
    1.58 +		lodsb
    1.59 +		sub	al,[bx]
    1.60 +		jnz	@@out
    1.61 +		sub	al,[bx]
    1.62 +		jnz	@@lp
    1.63 +@@out:
    1.64 +		cbw
    1.65 +                pop	si
    1.66 +                ret
    1.67 +
    1.68 +        endp    _strcmp
    1.69 +	endif
    1.70 +
    1.71 +
    1.72  ;***************************************************************
    1.73  ;void* malloc(unsigned sz);
    1.74  ;***************************************************************
    1.75 @@ -149,17 +214,16 @@
    1.76  puts:
    1.77  		call	putsz
    1.78                  mov	bx,offset msg_crlf
    1.79 -
    1.80 +		jmp	putsz
    1.81 +putcz:
    1.82 +		mov	ah,9
    1.83 +		int	21h
    1.84          global  putsz:near			; putsz(bx)
    1.85  putsz:
    1.86 -                push	bx
    1.87 -		call	strlen
    1.88 -		pop	dx
    1.89 -		xchg	ax,cx
    1.90 -		mov	bx,1
    1.91 -                mov	ah,40h
    1.92 -                int	21h
    1.93 -		xor	ax,ax			; ZF=1	(for malloc failure)
    1.94 +		mov	al,[bx]
    1.95 +		inc	bx
    1.96 +		or	al,al
    1.97 +		jne	putcz			; ZF=1  (for malloc failure)
    1.98  		ret
    1.99  
   1.100          endp    _puts
   1.101 @@ -196,7 +260,8 @@
   1.102          global  open:near			; open(bx)
   1.103  open:
   1.104                  mov	dx,bx
   1.105 -                mov	ax,3d00h
   1.106 +		;mov	cl,0			; attribute mask
   1.107 +                mov	ax,3d00h		; read-only+compatibility
   1.108  dos:
   1.109                  int	21h
   1.110  chkc:
   1.111 @@ -242,10 +307,12 @@
   1.112          global  _read:near
   1.113          proc    _read near
   1.114  
   1.115 +		ifdef	WRITE
   1.116                  stc
   1.117  		db	0B0h			; mov al,im
   1.118          global  _write:near
   1.119                  clc
   1.120 +		endif
   1.121  		pop	ax			;caller return address
   1.122                  pop	bx			; fd
   1.123                  pop	dx			; data
   1.124 @@ -254,27 +321,34 @@
   1.125                  push	dx
   1.126                  push	bx
   1.127                  push	ax
   1.128 +		ifdef	WRITE
   1.129                  mov	ah,40h
   1.130  		sbb	ah,0
   1.131 +		else
   1.132 +                mov	ah,3Fh
   1.133 +		endif
   1.134                  jcxz	fail
   1.135  		jmp	dos
   1.136  
   1.137          endp    _read
   1.138  
   1.139 +        proc    _lseekset near
   1.140 +		ifdef EXTRA
   1.141  ;***************************************************************
   1.142  ;long lseekset(int fd, unsigned long sz);
   1.143  ;***************************************************************
   1.144  
   1.145          global  _lseekset:near
   1.146 -        proc    _lseekset near
   1.147  
   1.148  		pop	ax			;caller return address
   1.149                  pop	bx			; fd
   1.150                  pop	dx			; sz lo
   1.151                  pop	cx			; sz hi
   1.152                  push	cx
   1.153 +                push	dx
   1.154                  push	bx
   1.155                  push	ax
   1.156 +		endif
   1.157          global  lseekset:near
   1.158  lseekset:
   1.159  		clc
   1.160 @@ -337,14 +411,13 @@
   1.161          global  strlen:near			; strlen(bx)
   1.162  strlen:
   1.163                  mov	cx,bx
   1.164 -                jcxz	@@end
   1.165                  dec	bx
   1.166  @@lenlp:
   1.167 +		inc	cx
   1.168                  inc	bx
   1.169                  cmp	[byte bx],0
   1.170 -                jne	@@lenlp
   1.171 +                loopne	@@lenlp			; until eos or s == NULL
   1.172                  sub	bx,cx
   1.173 -@@end:
   1.174                  xchg	ax,bx
   1.175                  ret
   1.176  
   1.177 @@ -664,7 +737,7 @@
   1.178  		jz	@@skip			;   memcpy32(m->fallback,0,m->buf,m->size)
   1.179  	ifdef	LARGE_IMAGES
   1.180  		mov	ecx,[(image_himem bx).size]
   1.181 -memcpy_imagez:
   1.182 +memcpy_imagez:					; memcpy_imagez(edx,eax,ecx)
   1.183  		push	ecx
   1.184  	else
   1.185  		push	[(image_himem bx).size]
   1.186 @@ -693,7 +766,7 @@
   1.187  		push	ax
   1.188  	ifdef	LARGE_IMAGES
   1.189  		jmp	@@memcpy
   1.190 -memcpy_imagez:
   1.191 +memcpy_imagez:					; memcpy_imagez(edx,eax,ecx)
   1.192  		p386
   1.193  		push	ecx
   1.194  		push	eax
   1.195 @@ -731,7 +804,7 @@
   1.196  		mov	ax,[bx]
   1.197  		mov	dx,[bx+2]
   1.198  		endif
   1.199 -storepage:
   1.200 +storepage:					; storepage(edx,cx)
   1.201  		ifndef	NO386
   1.202  		push	0
   1.203  		push	4096
   1.204 @@ -824,13 +897,13 @@
   1.205  @@notfirst2:
   1.206  		pop	si
   1.207  		ret
   1.208 -		ifdef	NO386
   1.209 -                p8086
   1.210 -		endif
   1.211  
   1.212          endp    _prev_bufv
   1.213  	endif
   1.214  
   1.215 +		ifdef	NO386
   1.216 +                p8086
   1.217 +		endif
   1.218  
   1.219  ;***************************************************************
   1.220  ;void open_image(const char *name, struct image_himem *m);
   1.221 @@ -1130,7 +1203,7 @@
   1.222  		jne	@@radixok
   1.223  		mov	cl,8
   1.224  		lodsb
   1.225 -		mov	al,20h
   1.226 +		or	al,20h
   1.227  		cmp	al,'x'
   1.228  		jne	@@radixok
   1.229  		mov	cl,16
   1.230 @@ -1222,74 +1295,6 @@
   1.231  
   1.232  		ifdef	EXTRA
   1.233                  p8086
   1.234 -
   1.235 -;***************************************************************
   1.236 -;int strcmp(const char* a,const char* b);
   1.237 -;***************************************************************
   1.238 -        global  _strcmp:near
   1.239 -        proc    _strcmp near
   1.240 -
   1.241 -		pop	cx			;caller return address
   1.242 -                pop	bx			; a
   1.243 -                pop	ax			; b
   1.244 -                push	ax
   1.245 -                push	bx
   1.246 -                push	cx
   1.247 -                push	si
   1.248 -		xchg	ax,si
   1.249 -                sub	bx,si
   1.250 -@@lp:
   1.251 -                mov	al,[si]
   1.252 -                sub	al,[bx+si]
   1.253 -		jnz	@@out
   1.254 -                lodsb
   1.255 -		cmp	al,0
   1.256 -                jne	@@lp
   1.257 -@@out:
   1.258 -		cbw
   1.259 -                pop	si
   1.260 -                ret
   1.261 -
   1.262 -        endp    _strcmp
   1.263 -
   1.264 -
   1.265 -;***************************************************************
   1.266 -;char strstr(const char* a,const char* b);
   1.267 -;***************************************************************
   1.268 -        global  _strstr:near
   1.269 -        proc    _strstr near
   1.270 -
   1.271 -		pop	ax			;caller return address
   1.272 -                pop	cx			; a
   1.273 -                pop	dx			; b
   1.274 -                push	dx
   1.275 -                push	cx
   1.276 -                push	ax
   1.277 -                push	si
   1.278 -@@loop:
   1.279 -		xor	ax,ax
   1.280 -		mov	si,cx
   1.281 -		cmp	[si],al			; *a
   1.282 -		jz	@@end			; return ax = NULL
   1.283 -		mov	bx,dx
   1.284 -		sub	bx,si
   1.285 -@@match:
   1.286 -		or	ah,[bx+si]		; *b
   1.287 -		jz	@@found
   1.288 -		lodsb
   1.289 -		sub	ah,al
   1.290 -		jz	@@match
   1.291 -		inc	cx
   1.292 -		jmp	@@loop
   1.293 -@@found:
   1.294 -		xchg	ax,cx
   1.295 -@@end:
   1.296 -                pop	si
   1.297 -		ret
   1.298 -
   1.299 -        endp    _strstr
   1.300 -
   1.301 -
   1.302  ;***************************************************************
   1.303  ;char *progname(void)
   1.304  ;***************************************************************
   1.305 @@ -1305,7 +1310,7 @@
   1.306  		jb	@@skip
   1.307  		;mov	es,[cs:2Ch]
   1.308  		mov	es,[di+2Ch]
   1.309 -		mov	cx,-1
   1.310 +		mov	cx,sp			; big enough
   1.311  @@loop:
   1.312  		repne
   1.313  		  scasb
   1.314 @@ -1346,7 +1351,7 @@
   1.315  		push	bx
   1.316  		push	ax
   1.317  
   1.318 -		cmp	[byte bx+1],3Ah
   1.319 +		cmp	[byte bx+1],3Ah		; ':'
   1.320  		jne	@@nodisk
   1.321  		mov	dl,20h
   1.322  		or	dl,[bx]
   1.323 @@ -1372,9 +1377,9 @@
   1.324  		push	[word bx]
   1.325  		mov	[bx],al
   1.326  		stc
   1.327 -		mov	ax,713Bh		; chdir long filename
   1.328 +		mov	ax,713Bh		; chdir long filename (ds:dx)
   1.329  		int	21h
   1.330 -		mov	ah,3Bh			; chdir
   1.331 +		mov	ah,3Bh			; chdir(ds:dx)
   1.332  		jnc	chdirdone
   1.333  		int	21h
   1.334  chdirdone:
   1.335 @@ -1431,17 +1436,13 @@
   1.336  		pop	ax
   1.337  		push	ax
   1.338  		push	bx
   1.339 -		push	bp si di
   1.340 +		push	si
   1.341  		xchg	ax,si
   1.342 -		xor	di,di
   1.343 -		push	di
   1.344 -		push	di
   1.345 -		mov	bp,sp
   1.346 -		inc	di
   1.347 -		inc	di
   1.348 -		mov	cl,4
   1.349 +		xor	bx,bx
   1.350 +		mov	cx,304h
   1.351  @@number:
   1.352  		xor	ax,ax
   1.353 +		cwd
   1.354  @@digit:
   1.355  		shl	al,cl
   1.356  		shl	ax,cl
   1.357 @@ -1449,12 +1450,13 @@
   1.358  		sub	al,30h
   1.359  		cmp	al,9
   1.360  		jbe	@@digit
   1.361 -		mov	[bp+di],ah
   1.362 -		dec	di
   1.363 -		jns	@@number
   1.364 -		pop	ax
   1.365 -		pop	dx
   1.366 -		pop	di si bp
   1.367 +		mov	dl,bh
   1.368 +		mov	bh,bl
   1.369 +		mov	bl,ah
   1.370 +		dec	ch
   1.371 +		jnz	@@number
   1.372 +		xchg	ax,bx
   1.373 +		pop	si
   1.374  kver2ulret:
   1.375  		ret
   1.376