wok rev 20542

linld: relative lseek for load.cpp
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 30 15:12:24 2018 +0100 (18 months ago)
parents 25e3f390625a
children 16d1d23aefee
files linld/stuff/src/CRTL.ASM linld/stuff/src/CRTL.H linld/stuff/src/CRTLX.H linld/stuff/src/LOAD.CPP linld/stuff/src/pipehole.awk
line diff
     1.1 --- a/linld/stuff/src/CRTL.ASM	Thu Nov 29 13:49:52 2018 +0100
     1.2 +++ b/linld/stuff/src/CRTL.ASM	Fri Nov 30 15:12:24 2018 +0100
     1.3 @@ -280,27 +280,41 @@
     1.4  
     1.5  ;***************************************************************
     1.6  ;_fastcall long lseekset(int fd, unsigned sz);
     1.7 +;_fastcall long lseekcur(int fd, int while);
     1.8  ;***************************************************************
     1.9  
    1.10 +        global  @lseekcur$qii:near
    1.11 +        proc    @lseekcur$qii near
    1.12 +
    1.13 +		xchg	ax,bx
    1.14 +		xchg	ax,dx
    1.15 +		cwd
    1.16 +		xchg	ax,dx
    1.17 +		xchg	ax,cx
    1.18 +		mov	al,1
    1.19 +		jmp	lseek
    1.20 +		ifdef EXTRA
    1.21          global  @lseekset$qiui:near
    1.22 -        proc    @lseekset$qiui near
    1.23 -
    1.24 -		xchg	ax,bx			; fd
    1.25 -		xor	cx,cx			; sz hi
    1.26 +@lseekset$qiui:
    1.27 +		mov	bl,0
    1.28 +		jmp	lseek0x
    1.29  lseekset:
    1.30 -		clc
    1.31 -		db	0B0h			; mov al,im
    1.32 -;        global  rewind:near
    1.33 -rewind:						; rewind(bx)
    1.34 -		stc
    1.35 -		mov	ax,4200h
    1.36 -		jnc	dos
    1.37 +		mov	bl,0
    1.38 +		jmp	lseekx
    1.39 +		endif
    1.40 +rewind:						; rewind(ax)
    1.41 +		mov	bl,0
    1.42  lseek0:						; lseek0(bx,ax=dir)
    1.43 -		cwd
    1.44 +		xor	dx,dx
    1.45 +lseek0x:
    1.46  		xor	cx,cx
    1.47 +lseekx:
    1.48 +		xchg	ax,bx
    1.49 +lseek:
    1.50 +		mov	ah,42h
    1.51  		jmp	dos
    1.52  
    1.53 -        endp    @lseekset$qiui
    1.54 +        endp    @lseekcur$qii
    1.55  
    1.56  		ifdef EXTRA
    1.57  
    1.58 @@ -483,8 +497,7 @@
    1.59  		jc	@@die
    1.60  		mov	[(image_himem di).fd],ax
    1.61  		mov	[(image_himem di).fd2close],ax
    1.62 -		xchg	ax,bx
    1.63 -		mov	ax,4202h		; SEEK_END
    1.64 +		mov	bl,02h			; SEEK_END
    1.65  		call	lseek0
    1.66  @@die:
    1.67  		mov	bx,[(image_himem di).errmsg]
     2.1 --- a/linld/stuff/src/CRTL.H	Thu Nov 29 13:49:52 2018 +0100
     2.2 +++ b/linld/stuff/src/CRTL.H	Fri Nov 30 15:12:24 2018 +0100
     2.3 @@ -35,7 +35,7 @@
     2.4  extern _fastcall int open(const char* name);
     2.5  extern _fastcall int close(int fd);
     2.6  extern _fastcall int read(int fd, void* data, int sz);
     2.7 -extern _fastcall long lseekset(int fd, unsigned sz);
     2.8 +extern _fastcall long lseekcur(int fd, int where);
     2.9  extern _fastcall int puts(const char* s);
    2.10  extern pascal unsigned long strtol(const char *s);
    2.11  
     3.1 --- a/linld/stuff/src/CRTLX.H	Thu Nov 29 13:49:52 2018 +0100
     3.2 +++ b/linld/stuff/src/CRTLX.H	Fri Nov 30 15:12:24 2018 +0100
     3.3 @@ -1,5 +1,6 @@
     3.4  // This file is distributed under GPL
     3.5  //
     3.6 +extern _fastcall long lseekset(int fd, unsigned sz);
     3.7  extern _fastcall void strcpy(const char* a,const char* b);
     3.8  extern _fastcall void strcat(const char* a,const char* b);
     3.9  extern _fastcall int strcmp(const char* a,const char* b);
     4.1 --- a/linld/stuff/src/LOAD.CPP	Thu Nov 29 13:49:52 2018 +0100
     4.2 +++ b/linld/stuff/src/LOAD.CPP	Fri Nov 30 15:12:24 2018 +0100
     4.3 @@ -142,17 +142,15 @@
     4.4      struct kernelparams_t *kernelparams;
     4.5      kernelparams = &(((first1k_t*) (rm_buf = (u8 *)malloc_or_die(_32k)))->params);
     4.6  #define first1k		((first1k_t*)((u8 *)kernelparams-0x1F1))
     4.7 -   {
     4.8 -    u16 rm_seek;
     4.9  
    4.10  do {
    4.11      // Do not use malloc below until heap_top adjustment (see <*>)
    4.12 - if (read(m->fd, rm_buf, rm_seek=0x400) == 0x400) {
    4.13 + if (read(m->fd, rm_buf, 0x200) == 0x200) {
    4.14  
    4.15 +    lseekcur(m->fd,-0x200);
    4.16      if(kernelparams->setup_sects == 0) {
    4.17  #if 1
    4.18          if(* (int *) &first1k->pad10[0x3F-0x24] == 0x3AE8) {
    4.19 -            lseekset(m->fd,rm_seek=0x200);
    4.20              csip+=0xFFE00042;
    4.21          }
    4.22          else
    4.23 @@ -163,17 +161,14 @@
    4.24  	 kernelparams->boot_flag != 0xAA55)
    4.25          die("Not a kernel");
    4.26      heap_top = rm_buf+(rm_size=0x200*(kernelparams->setup_sects+1));  // <*>
    4.27 +    m->size -= rm_size;
    4.28 +    m->chunk_size -= rm_size;
    4.29  
    4.30      // Read remaining rm loader
    4.31 -
    4.32 -    {
    4.33 -    u16 cnt = rm_size-rm_seek;
    4.34 -    if (read(m->fd, rm_buf+rm_seek, cnt) == cnt) break;
    4.35 -    }
    4.36 +    if (read(m->fd, rm_buf, rm_size) == rm_size) break;
    4.37   }
    4.38          die(kernel_file_error);
    4.39  } while (0);
    4.40 -   }
    4.41  
    4.42      // Tell rm loader some info
    4.43  
    4.44 @@ -225,10 +220,8 @@
    4.45  
    4.46    {
    4.47      struct image_himem *m = &pm;
    4.48 -    m->fallback = (u32((u16(_CS)+0x1FFF)&0xF000)<<4);
    4.49 -    m->size -= rm_size;
    4.50 -    m->chunk_size -= rm_size;
    4.51 -    if((u16)((m->fallback+m->size)>>4) > topseg() || pm_high) {
    4.52 +    if((u16)(((m->fallback=(u32((u16(_CS)+0x1FFF)&0xF000)<<4))+m->size)>>4) >
    4.53 +		 topseg() || pm_high) {
    4.54          m->fallback = base_himem;
    4.55      }
    4.56  
    4.57 @@ -252,7 +245,7 @@
    4.58  
    4.59      open_image(initrd_name, m);
    4.60  
    4.61 -    if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK)) < m[-1].fallback+m[-1].size) {
    4.62 +    if ((m->fallback=(memtop()-m->size)&(~PAGE_MASK))-m[-1].fallback < m[-1].size) {
    4.63          close(m->fd);
    4.64          puts(m->errmsg);
    4.65          return;
     5.1 --- a/linld/stuff/src/pipehole.awk	Thu Nov 29 13:49:52 2018 +0100
     5.2 +++ b/linld/stuff/src/pipehole.awk	Fri Nov 30 15:12:24 2018 +0100
     5.3 @@ -36,7 +36,7 @@
     5.4  	}
     5.5  	else if (hold == 3) {
     5.6  		hold=0
     5.7 -		if (/^	add	[abcds][ix],/ || /^	sub	[abcds][ix],/) {
     5.8 +		if (/^	add	[abcds][ix],/) {
     5.9  			split($2,regs2,",")
    5.10  			if (regs[1] == regs2[1] && (regs2[2] == "offset" || isnum(regs2[2]))) {
    5.11  				t=$0; sub(/mov/,$1,s)
    5.12 @@ -118,6 +118,13 @@
    5.13  			print "	and	" substr(args[1],2) "," args[2]; next
    5.14  		}
    5.15  	}
    5.16 +	if (/^	add	[bcd]x,/ || /^	sub	[bcd]x,/) {
    5.17 +		split($0,args,",")
    5.18 +		if (isnum(args[2]) && (args[2] % 256 == 0)) {
    5.19 +			sub(/x,/,"h,",s)
    5.20 +			print s "/256"; next
    5.21 +		}
    5.22 +	}
    5.23  	if (/^	add	word ptr/ || /^	sub	word ptr/) {
    5.24  		split($0,args,",")
    5.25  		if (isnum(args[2]) && (args[2] % 256 == 0)) {