wok rev 19634

linld: some fixes for strtoul
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Jan 16 10:15:15 2017 +0100 (2017-01-16)
parents 7c138665bd75
children faf865f8822c
files linld/stuff/src/CRTL.ASM linld/stuff/src/CRTL.H linld/stuff/src/CRTLX.ASM linld/stuff/src/MEMCPY32.ASM linld/stuff/src/MEMTOP.ASM linld/stuff/src/VCPI.ASM linld/stuff/src/_BEG.ASM
line diff
     1.1 --- a/linld/stuff/src/CRTL.ASM	Sun Jan 15 10:32:17 2017 +0100
     1.2 +++ b/linld/stuff/src/CRTL.ASM	Mon Jan 16 10:15:15 2017 +0100
     1.3 @@ -39,6 +39,7 @@
     1.4  ;***************************************************************
     1.5  ;char* strcpy(const char* a, const char* b);
     1.6  ;char* strcat(const char* a, const char* b);
     1.7 +;char* strcatb(const char* a, const char* b);
     1.8  ;***************************************************************
     1.9          global  _strcpy:near
    1.10          proc    _strcpy near
    1.11 @@ -48,7 +49,10 @@
    1.12          global  _strcat:near
    1.13  _strcat:
    1.14  		mov	dl,1
    1.15 -cat:
    1.16 +		db	0bbh			; mov	bx,imm opcode
    1.17 +        global  _strcatb:near
    1.18 +_strcatb:
    1.19 +		mov	dl,3
    1.20  		pop	ax			;caller return address
    1.21                  pop	cx			; a
    1.22                  pop	bx			; b
    1.23 @@ -86,18 +90,6 @@
    1.24  
    1.25  
    1.26  ;***************************************************************
    1.27 -;char* strcatb(const char* a, const char* b);
    1.28 -;***************************************************************
    1.29 -        global  _strcatb:near
    1.30 -        proc    _strcatb near
    1.31 -
    1.32 -		mov	dl,3
    1.33 -                jmp	cat
    1.34 -
    1.35 -        endp    _strcatb
    1.36 -
    1.37 -
    1.38 -;***************************************************************
    1.39  ;void* malloc(unsigned sz);
    1.40  ;***************************************************************
    1.41          global  _malloc:near
    1.42 @@ -129,7 +121,6 @@
    1.43  
    1.44  ;***************************************************************
    1.45  ;void puts(const char* s):
    1.46 -;void putsz(const char* s):
    1.47  ;***************************************************************
    1.48          global  _puts:near
    1.49          proc    _puts near
    1.50 @@ -142,14 +133,7 @@
    1.51  puts:
    1.52  		call	putsz
    1.53                  mov	bx,offset msg_crlf
    1.54 -		jmp	putsz
    1.55  
    1.56 -        global  _putsz:near
    1.57 -_putsz:
    1.58 -		pop	ax			;caller return address
    1.59 -                pop	bx			; s
    1.60 -                push	bx
    1.61 -                push	ax
    1.62          global  putsz:near			; putsz(bx)
    1.63  putsz:
    1.64                  push	bx
    1.65 @@ -243,7 +227,7 @@
    1.66          proc    _read near
    1.67  
    1.68                  stc
    1.69 -		db	73h			; jnc
    1.70 +		db	0B0h			; mov al,im
    1.71          global  _write:near
    1.72                  clc
    1.73  		pop	ax			;caller return address
    1.74 @@ -256,7 +240,6 @@
    1.75                  push	ax
    1.76                  mov	ah,40h
    1.77  		sbb	ah,0
    1.78 -                clc
    1.79                  jcxz	fail
    1.80  		jmp	dos
    1.81  
    1.82 @@ -280,8 +263,10 @@
    1.83          global  lseekset:near
    1.84  lseekset:
    1.85  		clc
    1.86 +		db	0B0h			; mov al,im
    1.87          global  rewind:near
    1.88 -rewind:						; rewind(bx,C=1)
    1.89 +rewind:						; rewind(bx)
    1.90 +		stc
    1.91  		mov	ax,4200h
    1.92  		jnc	dos
    1.93  lseek0:						; lseek0(bx,ax=dir)
    1.94 @@ -326,24 +311,23 @@
    1.95          proc    _strhead near
    1.96  
    1.97  		pop	cx			;caller return address
    1.98 -                pop	ax			; a
    1.99 -                pop	bx			; b
   1.100 +                pop	bx			; a
   1.101 +                pop	ax			; b
   1.102 +                push	ax
   1.103                  push	bx
   1.104 -                push	ax
   1.105                  push	cx
   1.106  @@loop:
   1.107 +		xchg	ax,bx
   1.108                  mov	cl,[bx]			; cl = *b++
   1.109                  inc	bx
   1.110  		or	cl,cl			; clear C
   1.111  		jz	fail			; return 0
   1.112  		xchg	ax,bx
   1.113                  xor	cl,[bx]			; cl -= *a++
   1.114 +                inc	bx
   1.115  		and	cl,0dfh			; case insensitive
   1.116 -		stc
   1.117 -		jnz	fail			; return -1
   1.118 -                inc	bx
   1.119 -		xchg	ax,bx
   1.120 -                jmp	@@loop
   1.121 +                jz	@@loop
   1.122 +		ret				; return b (is not 0)
   1.123  
   1.124          endp    _strhead
   1.125  
   1.126 @@ -653,12 +637,11 @@
   1.127          global  _reset_bufv:near
   1.128          proc    _reset_bufv near
   1.129  
   1.130 -		pop	bx			;caller return address
   1.131 -		pop	ax
   1.132 +		pop	ax			;caller return address
   1.133 +		pop	bx
   1.134 +		push	bx
   1.135  		push	ax
   1.136 -		push	bx
   1.137 -		mov	[curdata],ax
   1.138 -		xchg	ax,bx
   1.139 +		mov	[curdata],bx
   1.140  		and	[dword (data_himem bx).cacheidx],0
   1.141  		ret
   1.142  
   1.143 @@ -725,7 +708,7 @@
   1.144  
   1.145  
   1.146  ;***************************************************************
   1.147 -;void next_chunk(struct image_himem *m);
   1.148 +;void next_chunk(struct image_himem *di);
   1.149  ;***************************************************************
   1.150          proc    next_chunk near
   1.151  
   1.152 @@ -770,7 +753,6 @@
   1.153  		mov	bx,[(image_himem di).fd]
   1.154  		ifndef	NO386
   1.155  		push	eax
   1.156 -		stc
   1.157  		call	rewind
   1.158  		pop	eax
   1.159  @@end:
   1.160 @@ -778,7 +760,6 @@
   1.161  		else
   1.162  		push	ax
   1.163  		push	dx
   1.164 -		stc
   1.165  		call	rewind
   1.166  		pop	dx
   1.167  		pop	ax
   1.168 @@ -909,7 +890,6 @@
   1.169  		xor	cx,cx
   1.170  		ifndef	NO386
   1.171  		cwde				; ax < 8000h
   1.172 -		cwd
   1.173  		sub	[(image_himem di).chunk_size],eax
   1.174  		else
   1.175  		cwd				; ax < 8000h
   1.176 @@ -963,29 +943,30 @@
   1.177  		push	cx
   1.178  		push	ax
   1.179  		xor	ebx,ebx
   1.180 -		jcxz	@@jncend
   1.181  		push	si
   1.182 +		jcxz	@@end
   1.183  		mov	si,cx
   1.184  		xor	ecx,ecx
   1.185  		xor	eax,eax
   1.186  		lodsb
   1.187 -		mov	dl,20h
   1.188 -		or	dl,al
   1.189 -		cmp	dl,'n'			; vga=normal
   1.190 +		mov	dx,ax
   1.191 +		or	al,20h
   1.192 +		cmp	al,'n'			; vga=normal
   1.193  		je	@@vga
   1.194  		dec	cx
   1.195 -		cmp	dl,'e'			; vga=extended
   1.196 +		cmp	al,'e'			; vga=extended
   1.197  		je	@@vga
   1.198  		dec	cx
   1.199 -		cmp	dl,'a'			; vga=ask
   1.200 +		cmp	al,'a'			; vga=ask
   1.201  		jne	@@notvga
   1.202  @@vga:
   1.203  		dec	cx
   1.204  		xchg	ax,cx
   1.205  		cwd
   1.206 -		jmp	popsiret
   1.207 +		jmp	@@popsiret
   1.208  @@notvga:
   1.209  		mov	cx,10			; radix
   1.210 +		xchg	ax,dx
   1.211  		cmp	al,'+'
   1.212  		je	@@radixskip
   1.213  		cmp	al,'-'
   1.214 @@ -1000,19 +981,18 @@
   1.215  		jne	@@radixok
   1.216  		mov	cl,8
   1.217  		lodsb
   1.218 -		mov	dl,20h
   1.219 -		or	dl,al
   1.220 -		cmp	dl,'x'
   1.221 +		or	al,20h
   1.222 +		cmp	al,'x'
   1.223  		jne	@@radixok
   1.224  		mov	cl,16
   1.225  @@strtollp:
   1.226  		lodsb
   1.227  @@radixok:
   1.228 +		or	al,20h
   1.229  		sub	al,'0'
   1.230  		jb	@@endstrtol
   1.231  		cmp	al,9
   1.232  		jbe	@@digitok
   1.233 -		or	al,20h
   1.234  		cmp	al,'a'-'0'
   1.235  		jb	@@endstrtol
   1.236  		sub	al,'a'-'0'-10
   1.237 @@ -1038,14 +1018,13 @@
   1.238  		shl	ebx,cl
   1.239  @@noshift:
   1.240  		popf
   1.241 -@@jncend:
   1.242  		jnc	@@end
   1.243  		neg	ebx
   1.244  @@end:
   1.245  		push	ebx
   1.246  		pop	ax
   1.247  		pop	dx
   1.248 -popsiret:
   1.249 +@@popsiret:
   1.250  		pop	si
   1.251  		else
   1.252  		pop	ax			;caller return address
   1.253 @@ -1056,29 +1035,28 @@
   1.254  		push	di
   1.255  		xor	ax,ax
   1.256  		cwd
   1.257 +		jcxz	@@goend
   1.258  		xchg	ax,di
   1.259 -		jcxz	@@goend
   1.260  		mov	si,cx
   1.261  		lodsb
   1.262 -		mov	dl,20h
   1.263 -		or	dl,al
   1.264 +		mov	bx,ax
   1.265 +		or	al,20h
   1.266  		mov	cx,-1
   1.267 -		cmp	dl,'n'			; vga=normal
   1.268 +		cmp	al,'n'			; vga=normal
   1.269  		je	@@vga
   1.270  		dec	cx
   1.271 -		cmp	dl,'e'			; vga=extended
   1.272 +		cmp	al,'e'			; vga=extended
   1.273  		je	@@vga
   1.274  		dec	cx
   1.275 -		cmp	dl,'a'			; vga=ask
   1.276 +		cmp	al,'a'			; vga=ask
   1.277  		jne	@@notvga
   1.278  @@vga:
   1.279  		xchg	ax,cx
   1.280 -		cwd
   1.281 -		jmp	popsiret
   1.282  @@goend:
   1.283 -		jmp	@@end
   1.284 +		jmp	@@popdisiret
   1.285  @@notvga:
   1.286  		mov	cx,10			; radix
   1.287 +		xchg	ax,bx
   1.288  		cmp	al,'+'
   1.289  		je	@@radixskip
   1.290  		cmp	al,'-'
   1.291 @@ -1093,19 +1071,18 @@
   1.292  		jne	@@radixok
   1.293  		mov	cl,8
   1.294  		lodsb
   1.295 -		mov	ah,20h
   1.296 -		or	ah,al
   1.297 -		cmp	ah,'x'
   1.298 +		mov	al,20h
   1.299 +		cmp	al,'x'
   1.300  		jne	@@radixok
   1.301  		mov	cl,16
   1.302  @@strtollp:
   1.303  		lodsb
   1.304  @@radixok:
   1.305 +		or	al,20h
   1.306  		sub	al,'0'
   1.307  		jb	@@endstrtol
   1.308  		cmp	al,9
   1.309  		jbe	@@digitok
   1.310 -		or	al,20h
   1.311  		cmp	al,'a'-'0'
   1.312  		jb	@@endstrtol
   1.313  		sub	al,'a'-'0'-10
   1.314 @@ -1155,8 +1132,8 @@
   1.315  		inc	dx
   1.316  @@end:
   1.317  		xchg	ax,di
   1.318 +@@popdisiret:
   1.319  		pop	di
   1.320 -popsiret:
   1.321  		pop	si
   1.322  		endif
   1.323  		ret
   1.324 @@ -1175,7 +1152,7 @@
   1.325  		jnc	@@max640k
   1.326  		mov	ax,640			; 9000
   1.327  @@max640k:
   1.328 -		sub	ax,028h
   1.329 +		dec	ax
   1.330  		and	al,0C0h
   1.331  		mov	cl,6
   1.332  		shl	ax,cl
     2.1 --- a/linld/stuff/src/CRTL.H	Sun Jan 15 10:32:17 2017 +0100
     2.2 +++ b/linld/stuff/src/CRTL.H	Mon Jan 16 10:15:15 2017 +0100
     2.3 @@ -43,7 +43,6 @@
     2.4  extern "C" long lseekset(int fd, long sz);
     2.5  extern "C" void* malloc(unsigned sz);
     2.6  extern "C" void puts(const char* s);
     2.7 -extern "C" void putsz(const char* s);
     2.8  extern "C" unsigned long strtol(const char *s);
     2.9  
    2.10  // Extensions
     3.1 --- a/linld/stuff/src/CRTLX.ASM	Sun Jan 15 10:32:17 2017 +0100
     3.2 +++ b/linld/stuff/src/CRTLX.ASM	Mon Jan 16 10:15:15 2017 +0100
     3.3 @@ -30,18 +30,18 @@
     3.4          global  _strcmp:near
     3.5          proc    _strcmp near
     3.6  
     3.7 -		pop	ax			;caller return address
     3.8 -                pop	cx			; a
     3.9 -                pop	bx			; b
    3.10 +		pop	cx			;caller return address
    3.11 +                pop	bx			; a
    3.12 +                pop	ax			; b
    3.13 +                push	ax
    3.14                  push	bx
    3.15                  push	cx
    3.16 -                push	ax
    3.17                  push	si
    3.18 -                mov	si,cx
    3.19 +		xchg	ax,si
    3.20                  sub	bx,si
    3.21  @@lp:
    3.22 -                mov	al,[bx+si]
    3.23 -                sub	al,[si]
    3.24 +                mov	al,[si]
    3.25 +                sub	al,[bx+si]
    3.26  		jnz	@@out
    3.27                  lodsb
    3.28  		cmp	al,0
    3.29 @@ -295,16 +295,16 @@
    3.30          global  _kver2ul:near
    3.31          proc    _kver2ul near
    3.32  
    3.33 +		pop	bx
    3.34  		pop	ax
    3.35 -		pop	dx
    3.36 -		push	dx
    3.37  		push	ax
    3.38 +		push	bx
    3.39  		push	bp si di
    3.40 +		xchg	ax,si
    3.41  		xor	di,di
    3.42  		push	di
    3.43  		push	di
    3.44  		mov	bp,sp
    3.45 -		mov	si,dx
    3.46  		inc	di
    3.47  		inc	di
    3.48  		mov	cl,4
    3.49 @@ -372,7 +372,6 @@
    3.50  		push	cx
    3.51  		push	dx
    3.52  		push	ax
    3.53 -		xor	ax,ax
    3.54  		extrn	_isostate:isostate
    3.55  		mov	bx,[_isostate.fd]
    3.56  		extrn	lseekset:near
     4.1 --- a/linld/stuff/src/MEMCPY32.ASM	Sun Jan 15 10:32:17 2017 +0100
     4.2 +++ b/linld/stuff/src/MEMCPY32.ASM	Mon Jan 16 10:15:15 2017 +0100
     4.3 @@ -113,15 +113,13 @@
     4.4                          oldGDTR :pword  = TEMP_SIZE
     4.5  
     4.6  ;****** Init ***************************************************
     4.7 -		push	bp
     4.8 -		mov	bp,sp
     4.9 -		sub	sp,TEMP_SIZE
    4.10 +
    4.11 +			ifndef	NO386
    4.12 +
    4.13 +		enter	TEMP_SIZE,0
    4.14  		;cld
    4.15                  pushf
    4.16                  push    ds es
    4.17 -
    4.18 -			ifndef	NO386
    4.19 -
    4.20                  pushad
    4.21  		mov	cl,4
    4.22                  movzx   esi,[srcseg]
    4.23 @@ -156,6 +154,12 @@
    4.24  @@pmcopy:
    4.25  			else
    4.26  
    4.27 +		push	bp
    4.28 +		mov	bp,sp
    4.29 +		sub	sp,TEMP_SIZE
    4.30 +		;cld
    4.31 +                pushf
    4.32 +                push    ds es
    4.33  		push	si
    4.34  		xor	bx,bx
    4.35  		xor	dx,dx
    4.36 @@ -233,7 +237,7 @@
    4.37                  mov     eax,cs
    4.38                  shl     eax,4
    4.39                  addzx_e ax,<offset GDT>
    4.40 -                mov     [word GDTR],-1          ;GDT limit = 0FFFFh
    4.41 +                or      [word GDTR],-1          ;GDT limit = 0FFFFh
    4.42                  mov     [dword GDTR+2],eax      ;GDT base
    4.43                  lgdt    [GDTR]
    4.44  
    4.45 @@ -248,7 +252,7 @@
    4.46                  pop     ds              ;base=0, lim = 4gb
    4.47                  push    ds              ;
    4.48                  pop     es              ;
    4.49 -                db      66h     ;operand width override for ecx
    4.50 +                ;db      66h     ;operand width override for ecx
    4.51                  db      67h     ;address width override for esi/edi
    4.52              rep movsb
    4.53  		cld
    4.54 @@ -266,8 +270,12 @@
    4.55  @@done16:
    4.56                  pop     es ds
    4.57                  popf
    4.58 +			ifndef	NO386
    4.59 +		leave
    4.60 +			else
    4.61  		mov	sp,bp
    4.62  		pop	bp
    4.63 +			endif
    4.64                  ret
    4.65  
    4.66  ;****** Const data *********************************************
     5.1 --- a/linld/stuff/src/MEMTOP.ASM	Sun Jan 15 10:32:17 2017 +0100
     5.2 +++ b/linld/stuff/src/MEMTOP.ASM	Mon Jan 16 10:15:15 2017 +0100
     5.3 @@ -78,10 +78,11 @@
     5.4                  jnc     @@ok            ;  error: cf=1 or ax=0
     5.5                  xor     ax,ax           ;
     5.6  @@ok:
     5.7 -                xor     dx,dx
     5.8 +;                xor     dx,dx
     5.9                  test    ax,ax           ;happens on big mem systems
    5.10                  jz      @@fail
    5.11  tokb:
    5.12 +                xor     dx,dx
    5.13                  add     ah,4h           ;account for 1024 low kb
    5.14                  adc     dx,dx           ;  (optimized to death)
    5.15  		ifndef	NO386
    5.16 @@ -117,7 +118,6 @@
    5.17                  cli
    5.18                  call	rdcmos17
    5.19                  popf
    5.20 -		xor     dx,dx
    5.21  		jmp	tokb
    5.22  
    5.23  rdcmos17:       mov     al,18h		; read bytes 17-18 from CMOS
     6.1 --- a/linld/stuff/src/VCPI.ASM	Sun Jan 15 10:32:17 2017 +0100
     6.2 +++ b/linld/stuff/src/VCPI.ASM	Mon Jan 16 10:15:15 2017 +0100
     6.3 @@ -65,11 +65,6 @@
     6.4  use_32          = 01000000b
     6.5  
     6.6  ;****** rm32,imm16 helpers
     6.7 -macro   movzx_e rm,i
     6.8 -        db      66h
     6.9 -        mov     rm,i
    6.10 -        dw      0
    6.11 -endm
    6.12  macro   addzx_e rm,i
    6.13          db      66h
    6.14          add     rm,i
    6.15 @@ -77,13 +72,11 @@
    6.16  endm
    6.17  
    6.18  
    6.19 -        group   DGROUP  _TEXT,_DATA
    6.20 +        group   DGROUP  _TEXT,_DATA,_BSS
    6.21          assume  cs:DGROUP,ds:DGROUP
    6.22  
    6.23          segment _DATA byte public use16 'DATA'
    6.24  
    6.25 -tss             dd      0,0     ;enough, we'll never use it anyway
    6.26 -
    6.27  label   gdt     byte
    6.28  gdt_null        descr   <?>     ;0000
    6.29  gdt_vcpi        descr   <?>     ;0008
    6.30 @@ -104,39 +97,42 @@
    6.31  label   gdtr    pword
    6.32  gdt_lim         dw      0ffffh
    6.33  gdt_base        dw      offset gdt,0
    6.34 -label   idtr    pword
    6.35 -idt_lim         dw      03ffh   ;we won't enable ints,
    6.36 -idt_base        dd      0       ;  so let's leave it the same as for rm
    6.37  
    6.38  ;Note: layout dictated by vcpi api, don't rearrange!
    6.39  label sw2pm_params byte
    6.40  ;Note: base addrs will be fixed up in prepare_vcpi()
    6.41 +label	pagedir_laddr   dword
    6.42  sw2pm_cr3       dd      ?
    6.43  sw2pm_gdtr_ptr  dw      offset gdtr,0
    6.44  sw2pm_idtr_ptr  dw      offset idtr,0
    6.45  sw2pm_ldtr      dw      0       ;we don't need it
    6.46  sw2pm_tr        dw      SEL_TSS ;vcpi thinks we need it... can't set to 0
    6.47 -sw2pm_jumpaddr  dd      ?
    6.48 +sw2pm_jumpaddr  dd      0
    6.49                  dw      SEL_CODE
    6.50  
    6.51 +vcpi_pm_entry   dd      0
    6.52 +                dw      SEL_VCPI
    6.53 +
    6.54 +label   idtr    pword
    6.55 +idt_lim         dw      03ffh   ;we won't enable ints,
    6.56 +idt_base        dd      0       ;  so let's leave it the same as for rm
    6.57 +
    6.58 +        ends    _DATA
    6.59 +
    6.60 +        segment _BSS byte public use16 'BSS'
    6.61 +
    6.62  ;Pagedir/page0 addrs: linear, seg:0 and cs:ofs
    6.63 -pagedir_laddr   dd      ?
    6.64  page0_laddr     dd      ?
    6.65 -;;pagedir_seg     dw      ?
    6.66 -;;page0_seg       dw      ?
    6.67 -pagedir_ofs     dw      ?
    6.68 -page0_ofs       dw      ?
    6.69 -
    6.70 -vcpi_pm_entry   dd      ?
    6.71 -                dw      SEL_VCPI
    6.72 +;pagedir_ofs     dw      ?
    6.73 +;page0_ofs       dw      ?
    6.74  
    6.75  label   saved_ss_sp dword
    6.76  saved_sp        dw      ?
    6.77  saved_ss        dw      ?
    6.78  
    6.79 +tss             dd      ?,?     ;enough, we'll never use it anyway
    6.80  
    6.81 -        ends    _DATA
    6.82 -
    6.83 +        ends    _BSS
    6.84  
    6.85          segment _TEXT byte public use16 'CODE'
    6.86  
    6.87 @@ -166,45 +162,51 @@
    6.88  
    6.89  		mov	cl,4
    6.90                  mov     edx,cs
    6.91 -                shl     edx,cl          ;ebx = linear addr of CS
    6.92 -                mov     bx, offset page0_laddr
    6.93 +                shl     edx,cl          ;edx = linear addr of CS
    6.94 +                mov     si,offset gdt_vcpi
    6.95  ; Fix up base of some gdt descriptors
    6.96  ; Note: 'add [dword xx.base0],edx' actually updates 24 bit quantity!
    6.97  ; Do NOT replace with mov!
    6.98 -                add     [dword bx+gdt_base-page0_laddr],edx
    6.99 -                add     [dword bx+sw2pm_gdtr_ptr-page0_laddr],edx
   6.100 -                add     [dword bx+sw2pm_idtr_ptr-page0_laddr],edx
   6.101 -                add     [dword bx+(gdt_code.base0)-page0_laddr],edx
   6.102 -                add     [dword bx+(gdt_data.base0)-page0_laddr],edx
   6.103 -                add     [dword bx+(gdt_tss.base0)-page0_laddr],edx
   6.104 +		xor	ebx,ebx
   6.105 +                add     [dword bx+si+sw2pm_idtr_ptr-gdt_vcpi],edx
   6.106 +@@fixup:
   6.107 +                add     [dword bx+si+(gdt_code.base0)-gdt_vcpi],edx
   6.108 +		add	bl,8
   6.109 +		cmp	bl,28h
   6.110 +		jb	@@fixup
   6.111 +                ;add     [dword si+(gdt_data.base0)-gdt_vcpi],edx
   6.112 +                ;add     [dword si+(gdt_tss.base0)-gdt_vcpi],edx
   6.113 +                ;add     [dword si+gdt_base-gdt_vcpi],edx
   6.114 +                ;add     [dword si+sw2pm_gdtr_ptr-gdt_vcpi],edx
   6.115 +                ;add     [dword si+sw2pm_idtr_ptr-gdt_vcpi],edx
   6.116                  add     eax,edx
   6.117 -                mov     esi,0FFFh
   6.118 -                add     eax,esi
   6.119 -		inc	si		;esi=00001000h
   6.120 +                mov     bx,0FFFh
   6.121 +                add     eax,ebx
   6.122 +		inc	bx		;ebx=00001000h
   6.123  
   6.124                  shr     eax,cl
   6.125                  mov     al,0   ;eax = 4k aligned linear addr of pagebuf
   6.126                  mov     es,ax           ;es:0->page0,es:1000h->pagedir
   6.127                  shl     eax,cl          ;eax=page0 linear addr
   6.128 -                mov     [bx+page0_laddr-page0_laddr],eax
   6.129                  mov     al,3            ;add present+writable bits
   6.130 -                mov     [es:si],eax     ;stuff it into pagedir[0]
   6.131 +                mov     [es:bx],eax     ;stuff it into pagedir[0]
   6.132 +                push    ds
   6.133 +                pop     es
   6.134  
   6.135 -                add     eax,esi
   6.136  		mov	al,0
   6.137 -                mov     [bx+pagedir_laddr-page0_laddr],eax
   6.138 +                mov     [page0_laddr],eax
   6.139 +                add     eax,ebx
   6.140 +                ;mov     [pagedir_laddr],eax
   6.141                          ;page directory will use only one entry (4 bytes):
   6.142                          ;cr3 => pagedir => page0  => ########
   6.143                          ;      (1 entry)  (1024   => #  4M  #
   6.144                          ;                 entries)=> # page #
   6.145                          ;                         => ########
   6.146 -                mov     [bx+sw2pm_cr3-page0_laddr],eax
   6.147 +                mov     [sw2pm_cr3],eax
   6.148                  sub     eax,edx         ;ax = offset in CS of pagedir
   6.149 -                mov     [bx+pagedir_ofs-page0_laddr],ax
   6.150 -                sub     ax,si   ;ax-=1000
   6.151 -                mov     [bx+page0_ofs-page0_laddr],ax
   6.152 -                push    ds
   6.153 -                pop     es
   6.154 +                ;mov     [pagedir_ofs],ax
   6.155 +                sub     ax,bx   ;ax-=1000
   6.156 +                ;mov     [page0_ofs],ax
   6.157                  mov     di,ax          ;ES:DI => page0
   6.158  ; Return
   6.159                  ;pop     es
   6.160 @@ -219,8 +221,8 @@
   6.161  
   6.162  ;***************************************************************
   6.163  ;int get_vcpi_interface();
   6.164 -;****** Return: AX=1 - page mapping for low 640k is 1:1
   6.165 -;******         AX=0 - otherwise (it's bad)
   6.166 +;****** Return: Z  - page mapping for low 640k is 1:1
   6.167 +;******         NZ - otherwise (it's bad)
   6.168  ;****** Uses:   Flags
   6.169  ;***************************************************************
   6.170          global  _get_vcpi_interface:near
   6.171 @@ -229,32 +231,29 @@
   6.172                  ;push    si di
   6.173  
   6.174  ; Get and save VCPI pm interface
   6.175 -                mov     si,offset gdt_vcpi      ;DS:DI => 3 GDT entries for VCPI
   6.176 +                ;mov     si,offset gdt_vcpi      ;DS:DI => 3 GDT entries for VCPI
   6.177                  ;mov     di,[si+page0_ofs-gdt_vcpi]          ;ES:DI => page0
   6.178                  ;push    ds
   6.179                  ;pop     es
   6.180 +                push    di
   6.181                  mov     ax,0DE01h               ;get vcpi pm interface
   6.182                  int     67h
   6.183 -                mov     [vcpi_pm_entry],ebx
   6.184 +                xchg    [vcpi_pm_entry],ebx	;clear ebx
   6.185 +                ;xor     bx,bx
   6.186  
   6.187  ; Check that mapping for low 640k is 1:1
   6.188 -                mov     si,[page0_ofs]
   6.189 -                xor     bx,bx
   6.190 +                pop     si			; [page0_ofs]
   6.191                  ;cld
   6.192  @@map_chk:
   6.193                  lodsd
   6.194                  shr     eax,12
   6.195                  cmp     ax,bx
   6.196 -                stc
   6.197                  jne     @@bad
   6.198                  inc     bx
   6.199 -                cmp     ax,((640*1024) shr 12)-1
   6.200 +                cmp     al,((640*1024) shr 12)-1
   6.201                  jne     @@map_chk
   6.202  ; Return
   6.203  @@bad:
   6.204 -                sbb     ax,ax
   6.205 -                inc	ax			; update Z
   6.206 -                ;pop     di si
   6.207                  ret
   6.208          endp    _get_vcpi_interface
   6.209  
   6.210 @@ -302,17 +301,10 @@
   6.211                  push    ax              ;\eip
   6.212                  push    offset @@vm_ret ;/
   6.213  
   6.214 -                cli
   6.215                ;;mov     [saved_xx],xx   ;use if your vcpi trashes bp/etc
   6.216  
   6.217 -                movzx_e <[word sw2pm_jumpaddr]>,<offset @@pm_entry>
   6.218 -               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
   6.219 -                mov     esi,cs
   6.220 -                shl     esi,4
   6.221 -                addzx_e si,<offset sw2pm_params>
   6.222 -                mov     ax,0DE0Ch       ; vcpi: switch to pm
   6.223 -                int     67h
   6.224 -@@pm_entry:
   6.225 +		call	switch_to_pm
   6.226 +
   6.227  ; Now we are in 16-bit protected mode
   6.228                  mov     ax,SEL_DATA
   6.229                  mov     ss,ax
   6.230 @@ -332,17 +324,30 @@
   6.231                  call    ax
   6.232  
   6.233  ; Ok, let's return to vm
   6.234 +                mov     ax,0DE0Ch       ; maybe we need whole eax?
   6.235                  cli     ; to be safe
   6.236                  clts    ;
   6.237                  push    SEL_ABS         ; vcpi wants ds=all_addrspace
   6.238                  pop     ds              ;
   6.239 -                mov     ax,0DE0Ch       ; maybe we need whole eax?
   6.240                  call    [pword cs:vcpi_pm_entry]
   6.241  @@vm_ret:
   6.242  ; Now we are in vm86 mode. Sregs, esp, eflags (IF) restored from IRET stack
   6.243                  ret
   6.244  
   6.245  ;***************************************************************
   6.246 +switch_to_pm:
   6.247 +                assume  cs:DGROUP,ds:DGROUP
   6.248 +                pop	[word sw2pm_jumpaddr]
   6.249 +               ;mov     [word sw2pm_jumpaddr+2],0
   6.250 +               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
   6.251 +                mov     esi,cs
   6.252 +                shl     esi,4
   6.253 +                addzx_e si,<offset sw2pm_params>
   6.254 +                mov     ax,0DE0Ch       ; vcpi: switch to pm
   6.255 +                cli
   6.256 +                int     67h
   6.257 +
   6.258 +;***************************************************************
   6.259  ;****** Helper: This is where real copy is done
   6.260  ;***************************************************************
   6.261  	global	do_memcpy_vcpi:near
   6.262 @@ -350,29 +355,27 @@
   6.263  
   6.264  ; Note: ss:bp => params
   6.265  ; Move data
   6.266 -                mov     cx,SEL_ABS
   6.267 -                mov     ds,cx
   6.268 -                mov     es,cx
   6.269 +                mov     ax,SEL_ABS
   6.270 +                mov     ds,ax
   6.271 +                mov     es,ax
   6.272                  assume  nothing
   6.273                  assume  cs:DGROUP
   6.274  
   6.275          ; Set up target addr:
   6.276          ; replace page mapping for page at 0 so
   6.277          ; that it points to dstofs
   6.278 -                mov     esi,[cs:page0_laddr]
   6.279                  mov     eax,[dstofs]
   6.280                  mov     al,03h          ; writeable, present
   6.281 -                xchg    [esi],eax       ; replace page0[0]
   6.282 +		call	@@set_mapping
   6.283                 ;push    eax             ;X we'll need to restore mapping...
   6.284 -                mov     ecx,cr3         ; reload TLB cache
   6.285 -                mov     cr3,ecx         ;
   6.286                  xor     edi,edi         ;es:edi => remapped page
   6.287  
   6.288          ; Set up source addr
   6.289                  mov     esi,[srcofs]
   6.290  
   6.291          ; Do copying
   6.292 -                mov     ecx,4096/2
   6.293 +		xor	ecx,ecx
   6.294 +                mov     ch,4096/256
   6.295                  ;cld
   6.296  ;;              cmp     esi,edi
   6.297  ;;              jae     @@do_copy
   6.298 @@ -383,13 +386,14 @@
   6.299  ;;              std                     ;
   6.300  ;;@@do_copy:
   6.301                  db      67h     ;address width override for esi/edi
   6.302 -            rep movsw
   6.303 +            rep movsb
   6.304  ;;              cld
   6.305  
   6.306          ; Restore page mapping for page at 0
   6.307                 ;pop     eax             ;X
   6.308 +@@set_mapping:
   6.309                  mov     esi,[cs:page0_laddr]
   6.310 -                mov     [esi],eax       ; restore page0[0]
   6.311 +                xchg    [esi],eax       ; restore page0[0]
   6.312                  mov     ecx,cr3         ; reload TLB cache
   6.313                  mov     cr3,ecx         ;
   6.314  ; Return
   6.315 @@ -410,29 +414,22 @@
   6.316  		extrn	_vcpi:byte
   6.317  		test	[_vcpi],-1
   6.318  		jz	@@ret
   6.319 -                push	esi
   6.320 +                push	si
   6.321                ;;pushf
   6.322 -              ;;cli
   6.323                ;;pushad
   6.324                  push    cs      ;*
   6.325                  push    ds
   6.326 -                push    es
   6.327 +                ;push    es
   6.328                  mov     [saved_ss],ss
   6.329                  mov     [saved_sp],sp
   6.330  
   6.331 -                movzx_e <[word sw2pm_jumpaddr]>,<offset @@pm_entry>
   6.332 -               ;mov     [word sw2pm_jumpaddr+4],SEL_CODE
   6.333 -                mov     esi,cs
   6.334 -                shl     esi,4
   6.335 -                addzx_e si,<offset sw2pm_params>
   6.336 -                mov     ax,0DE0Ch       ; vcpi: switch to pm
   6.337 -                int     67h
   6.338 +		call	switch_to_pm
   6.339 +
   6.340  ; Now we are in 16-bit protected mode
   6.341 -@@pm_entry:
   6.342                  mov     ax,SEL_DATA     ; load data sregs with limit >=64k
   6.343                  mov     ss,ax           ;   or you may get limit violations
   6.344                  mov     ds,ax           ;   later in rm
   6.345 -                mov     es,ax           ;   (actually I prefer 4gig limits :-)
   6.346 +                ;mov     es,ax           ;   (actually I prefer 4gig limits :-)
   6.347                  ;mov     fs,ax           ;
   6.348                  ;mov     gs,ax           ;
   6.349  
   6.350 @@ -446,7 +443,7 @@
   6.351  
   6.352  ; Now we are in rm, but not yet: have to restore sregs:
   6.353                  lss     sp,[saved_ss_sp]; SS
   6.354 -                pop     es              ; ES
   6.355 +                ;pop     es              ; ES
   6.356                  pop     ds              ; DS
   6.357                 ;push    cs      ;* done earlier
   6.358                  push    offset @@next
   6.359 @@ -454,7 +451,7 @@
   6.360  @@next:
   6.361                ;;popad
   6.362                ;;popf
   6.363 -                pop	esi
   6.364 +                pop	si
   6.365  @@ret:
   6.366                  ret             ; We don't care much about rest (FS/GS)
   6.367  
     7.1 --- a/linld/stuff/src/_BEG.ASM	Sun Jan 15 10:32:17 2017 +0100
     7.2 +++ b/linld/stuff/src/_BEG.ASM	Mon Jan 16 10:15:15 2017 +0100
     7.3 @@ -100,7 +100,7 @@
     7.4                  ;extrn   _get_vcpi_interface:near
     7.5  		;call	_get_vcpi_interface
     7.6  		mov	bx,offset msg_badmapping
     7.7 -		jnz	endcpu
     7.8 +		jz	endcpu
     7.9  no_vcpi:
    7.10                ;;pop     dx              ;$ handle
    7.11                ;;mov     ax,4500h        ; DEALLOCATE PAGES