Skip to contentSkip to conversation

memcpy_fromfs() failing. Wrong variable offsets

DISCUSSION Applied Eduardo Pereira Habkost 4 participants 11 messages Jun 1, 2004 – Jun 3, 2004

lore
Share & tools
lore
#0 lore raw

I was trying to boot ELKS CVS here and it was failing when trying to run init. I've tracked the bug until I discovered that

memcpy_fromfs() is failing, and it is not copying the right data.

Here is the function, with my debug line:

===============
void memcpy_fromfs(void *daddr, void *saddr, size_t len)

{
    /*@unused@*/ unsigned short int ds = current->t_regs.ds;

#ifndef S_SPLINT_S
#asm

        mov     dx,es
        mov     bx,ds
        mov     es,bx
        mov     ax,[bp-6]       ! source segment (local variable)
        mov     ds,ax
        mov     di,[bp+4]       ! destination address
        mov     si,[bp+6]       ! source address
        mov     cx,[bp+8]       ! number of bytes to copy

cld
rep
movsb
mov ds,bx
mov es,dx
#endasm
#endif

    debug3("DS: 0x%04x, real: 0x%02x, copied: 0x%02x\n",
                ds, *((unsigned char*)saddr), *((unsigned char*)daddr));
}

====================

Note that, as the DS for the init task, at the time of the error is the same of the kernel's DS, *((unsigned char*)saddr) showed the right value.

What I got when the kernel tries to run init is:

DS: 0x1dc1, real: 0x64, copied: 0x00

That means: the data wasn't copied.

Looking at the generated assembly file, We get:

==================
! 32 void memcpy_fromfs(daddr,saddr,len)
! Register SI DI used in function verfy_area
verfy_area.off = 0
! 33 # 32 "user.c"
! 32 void *daddr;
export>·_memcpy_fromfs
_memcpy_fromfs:
!BCC_EOS
! 33 # 32 "user.c"
! 32 void *saddr;
!BCC_EOS
! 33 # 32 "user.c"
! 32 size_t len;
!BCC_EOS
! 33 {
! 34 unsigned short int ds = current->t_regs.ds;
push>···bp
mov>····bp,sp
if memcpy_fromfs.off=0
push>···di
push>···si
endif
dec>····sp
dec>····sp
mov>····bx,[_current]
! Debug: eq unsigned short = [bx+6] to unsigned short ds = [S+8-8] (used reg = ) mov>····bx,6[bx]
mov>····-6+memcpy_fromfs.off[bp],bx

[...]

! 53 }
inc>····sp
inc>····sp
if memcpy_fromfs.off=0
pop>····si
pop>····di
endif
pop>····bp
ret
! 54·
! 55 int verified_memcpy_fromfs(daddr,saddr,len)
memcpy_fromfs.off = 4
============

That means: if memcpy_fromfs.off were 0, the function would be ok. The variable ds is supposed to be in [bp-6], but it is on [bp-2], because memcpy_fromfs.off is being defined to 4. Probably someday the compiler generated code in a way that memcpy_fromfs.off was always zero, and the function assumes that.

Anyway, looking at the code of the compiler, it looks like that it should know if SI or DI was modified by the function, because it should save their values on the stack.

I am using dev86-0.16.15 to compile elks.

Someone have reproduced this problem, too? Does anyone had success booting ELKS CVS?

--
Eduardo

#1 lore raw

Experimental fix for my memcpy_{to,from}fs problem

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

arch/i86/mm/user.c +11 -2
@@ -34,10 +34,12 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	ds,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -47,8 +49,11 @@
 	movsb
 	mov	ds,bx
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
+
 }
 
 int verified_memcpy_fromfs(void *daddr, void *saddr, size_t len)
@@ -69,8 +74,10 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	es,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -79,6 +86,8 @@
 	rep
 	movsb
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
 }
Signature · 1 line
Eduardo
#2 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Interesting:

The diff between dev86-0.16.0 and 0.16.15 shows:

@@ -664,8 +693,34 @@

        if( main_flag > 2 )
           globl("environ");
     }
+#ifdef I8088
+    regfuse = 0;
+#endif
     lbrace();
     compound();
+#ifdef I8088
+    if (regfuse & callee1mask) {
+        outstr("! Register");
+        if (regfuse & INDREG0 & callee1mask) outstr(" BX");
+        if (regfuse & INDREG1 & callee1mask) outstr(" SI");
+       if (regfuse & INDREG2 & callee1mask) outstr(" DI");
+       outstr(" used in function ");
+       outnstr(funcname);
+       if (optimise && !callersaves) {

+ outstr(funcname);
+ outnstr(".off = 0");
+ }
+ } else
+ if (optimise && !callersaves) {
+ outstr(funcname);
+ outstr(".off = ");
+#ifndef I80386
+ outnhex(4);
+#else
+ outnhex(i386_32?12:4);
+#endif
+ }
+#endif

     clearfunclabels();

}

This register-saving optmization was added after 0.16.0. The fix is valid, but probably it will break systems using dev86 <= 0.16.0.

Quoted 62 lines · Eduardo Pereira Habkost

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

arch/i86/mm/user.c +11 -2
@@ -34,10 +34,12 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	ds,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -47,8 +49,11 @@
 	movsb
 	mov	ds,bx
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
+
 }
 
 int verified_memcpy_fromfs(void *daddr, void *saddr, size_t len)
@@ -69,8 +74,10 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	es,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -79,6 +86,8 @@
 	rep
 	movsb
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
 }
Signature · 2 lines
-- 
Eduardo
Signature · 1 line
Eduardo
#3 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Greetings,

Quoted 39 lines · Eduardo Pereira Habkost

Interesting:

The diff between dev86-0.16.0 and 0.16.15 shows:

(quoted diff) +26 -0
@@ -664,8 +693,34 @@
        if( main_flag > 2 )
           globl("environ");
     }
+#ifdef I8088
+    regfuse = 0;
+#endif
     lbrace();
     compound();
+#ifdef I8088
+    if (regfuse & callee1mask) {
+        outstr("! Register");
+        if (regfuse & INDREG0 & callee1mask) outstr(" BX");
+        if (regfuse & INDREG1 & callee1mask) outstr(" SI");
+       if (regfuse & INDREG2 & callee1mask) outstr(" DI");
+       outstr(" used in function ");
+       outnstr(funcname);
+       if (optimise && !callersaves) {
+           outstr(funcname);
+           outnstr(".off = 0");
+       }
+    } else
+       if (optimise && !callersaves) {
+           outstr(funcname);
+           outstr(".off = ");
+#ifndef I80386
+           outnhex(4);
+#else
+           outnhex(i386_32?12:4);
+#endif
+       }
+#endif
     clearfunclabels();
 }
 
Quoted 3 lines

This register-saving optmization was added after 0.16.0. The fix is valid, but probably it will break systems using dev86 <= 0.16.0.

Yes the fix is ok.. but it will break dev86 <= 0.16.0 versions... this fact makes me hesitate a bit because Bruce does warn that 0.16.15 can behave a bit unstable.
But we will see.

best wishes

Mike

Quoted 65 lines · Eduardo Pereira Habkost
Quoted 62 lines

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

arch/i86/mm/user.c +11 -2
@@ -34,10 +34,12 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	ds,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -47,8 +49,11 @@
 	movsb
 	mov	ds,bx
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
+
 }
 
 int verified_memcpy_fromfs(void *daddr, void *saddr, size_t len)
@@ -69,8 +74,10 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	es,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -79,6 +86,8 @@
 	rep
 	movsb
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
 }
Signature · 2 lines
-- 
Eduardo
#4 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

On Tue, Jun 01, 2004 at 08:57:06PM -0600, Miguel Bolanos wrote:
<snip>

Quoted 5 lines

Yes the fix is ok.. but it will break dev86 <= 0.16.0 versions... this fact makes me hesitate a bit because Bruce does warn that 0.16.15 can behave a bit unstable.
But we will see.

Yes, and bcc >= 0.16.8 variable offset macros are broken, anyway.

The original code didn't used the offset macros for accessing the variables. It will work only on:

- dev86 < 0.16.8
- any dev86 version if not using optimization

And it will not work if the bcc variable offset macros bug is fixed, because the offsets really changed, with the optimized code.

The fix I've sent before really broke systems with dev86 <= 0.16.8.

The following patch against the current CVS code (that already has the "wrong" fix) change the asm code to access the variables using the "right way", that is: the variable offset macros.

It will work for:
- dev86 < 0.16.8
- any dev86 version if not using optimization
- dev86 >= 0.16.8 with the previous patch I sent (Fix variable offset macros)
- dev86 with the patch Robert sent

So please apply.

--
Eduardo

arch/i86/mm/user.c +12 -12
@@ -39,11 +39,11 @@
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_fromfs.ds]	! source segment (local variable)
 	mov	ds,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
+	mov	di,[bp+.memcpy_fromfs.daddr]	! destination address
+	mov	si,[bp+.memcpy_fromfs.saddr]	! source address
+	mov	cx,[bp+.memcpy_fromfs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb
@@ -77,11 +77,11 @@
 	push	si
 	push	di
 	mov	dx,es
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_tofs.es]	! source segment (local variable)
 	mov	es,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
+	mov	di,[bp+.memcpy_tofs.daddr]	! destination address
+	mov	si,[bp+.memcpy_tofs.saddr]	! source address
+	mov	cx,[bp+.memcpy_tofs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb
@@ -167,17 +167,17 @@
 #ifndef S_SPLINT_S
 #asm
 
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp+.strlen_fromfs.ds]	! source segment (local variable)
 	mov	es,ax
-	mov	di,[bp+4]	! source address
+	mov	di,[bp+.strlen_fromfs.saddr]	! source address
 	cld
 	xor	al,al		! search for NULL byte
 	mov	cx,#-1
 	rep
 	scasb
-	sub	di,[bp+4]	! calc len +1
+	sub	di,[bp+.strlen_fromfs.saddr]	! calc len +1
 	dec	di
-	mov	[bp-6],di	! save in local var ds
+	mov	[bp+.strlen_fromfs.ds],di	! save in local var ds
 #endasm
 #endif
 
#5 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Applied, but i did some changes on the patch, please read bellow.

Quoted 45 lines · Eduardo Pereira Habkost

On Tue, Jun 01, 2004 at 08:57:06PM -0600, Miguel Bolanos wrote:
<snip>

Quoted 5 lines

Yes the fix is ok.. but it will break dev86 <= 0.16.0 versions... this fact makes me hesitate a bit because Bruce does warn that 0.16.15 can behave a bit unstable.
But we will see.

Yes, and bcc >= 0.16.8 variable offset macros are broken, anyway.

The original code didn't used the offset macros for accessing the variables. It will work only on:

- dev86 < 0.16.8
- any dev86 version if not using optimization

And it will not work if the bcc variable offset macros bug is fixed, because the offsets really changed, with the optimized code.

The fix I've sent before really broke systems with dev86 <= 0.16.8.

The following patch against the current CVS code (that already has the "wrong" fix) change the asm code to access the variables using the "right way", that is: the variable offset macros.

It will work for:
- dev86 < 0.16.8
- any dev86 version if not using optimization
- dev86 >= 0.16.8 with the previous patch I sent (Fix variable offset macros)
- dev86 with the patch Robert sent

So please apply.

--
Eduardo

arch/i86/mm/user.c +1 -1
@@ -39,11 +39,11 @@
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_fromfs.ds]	! source segment (local variable)

arch/i86/mm/user.c line 49

Quoted 10 lines
arch/i86/mm/user.c +3 -3
 	mov	ds,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
+	mov	di,[bp+.memcpy_fromfs.daddr]	! destination address
+	mov	si,[bp+.memcpy_fromfs.saddr]	! source address
+	mov	cx,[bp+.memcpy_fromfs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb

This was already applied on a the previous patch

Quoted 6 lines
arch/i86/mm/user.c +1 -1
@@ -77,11 +77,11 @@
 	push	si
 	push	di
 	mov	dx,es
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_tofs.es]	! source segment (local variable)

arch/i86/mm/user.c line 87

Quoted 10 lines
arch/i86/mm/user.c +3 -3
 	mov	es,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
+	mov	di,[bp+.memcpy_tofs.daddr]	! destination address
+	mov	si,[bp+.memcpy_tofs.saddr]	! source address
+	mov	cx,[bp+.memcpy_tofs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb

This was already done as well.

Quoted 12 lines
arch/i86/mm/user.c +2 -2
@@ -167,17 +167,17 @@
 #ifndef S_SPLINT_S
 #asm
 
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp+.strlen_fromfs.ds]	! source segment (local variable)
 	mov	es,ax
-	mov	di,[bp+4]	! source address
+	mov	di,[bp+.strlen_fromfs.saddr]	! source address
 	cld
 	xor	al,al		! search for NULL byte
 	mov	cx,#-1

arch/i86/mm/user.c line 183

Quoted 10 lines
arch/i86/mm/user.c +2 -2
 	rep
 	scasb
-	sub	di,[bp+4]	! calc len +1
+	sub	di,[bp+.strlen_fromfs.saddr]	! calc len +1
 	dec	di
-	mov	[bp-6],di	! save in local var ds
+	mov	[bp+.strlen_fromfs.ds],di	! save in local var ds
 #endasm
 #endif
 

This part was applied.

thanks a lot.

Signature · 6 lines
--------------------miguel bolanos, systems administrator, linuxlabs
... ........ ..... ....                 230 peachtree st nw ste 2701
the original linux labs                          atlanta.ga.us 30303
       -since 1995                          http://www.linuxlabs.com
                                office 404.577.7747 fax 404.577.7743
--------------------------------------------------------------------
#6 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Hi, Mike,

Quoted 16 lines · Miguel Bolanos

Applied, but i did some changes on the patch, please read bellow.

Quoted 14 lines
arch/i86/mm/user.c +1 -4
@@ -39,11 +39,11 @@
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_fromfs.ds]	! source segment (local variable)
 	mov	ds,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
Quoted 8 lines

arch/i86/mm/user.c line 49

Quoted 6 lines
arch/i86/mm/user.c +3 -0
+	mov	di,[bp+.memcpy_fromfs.daddr]	! destination address
+	mov	si,[bp+.memcpy_fromfs.saddr]	! source address
+	mov	cx,[bp+.memcpy_fromfs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb

This was already applied on a the previous patch

I think I am missing something. What was applied? The code on CVS is not using .<function>.<variable> to access the function parameters and variables. This is what is being changed.

Quoted 11 lines
Quoted 11 lines
arch/i86/mm/user.c +1 -4
@@ -77,11 +77,11 @@
 	push	si
 	push	di
 	mov	dx,es
-	mov	ax,[bp-2]	! source segment (local variable)
+	mov	ax,[bp+.memcpy_tofs.es]	! source segment (local variable)
 	mov	es,ax
-	mov	di,[bp+4]	! destination address
-	mov	si,[bp+6]	! source address
-	mov	cx,[bp+8]	! number of bytes to copy
Quoted 8 lines

arch/i86/mm/user.c line 87

Quoted 6 lines
arch/i86/mm/user.c +3 -0
+	mov	di,[bp+.memcpy_tofs.daddr]	! destination address
+	mov	si,[bp+.memcpy_tofs.saddr]	! source address
+	mov	cx,[bp+.memcpy_tofs.len]	! number of bytes to copy
 	cld
 	rep
 	movsb

This was already done as well.

The CVS don't contain these changes, too. I just 'cvs update'd.

Quoted 17 lines
Quoted 17 lines
arch/i86/mm/user.c +3 -3
@@ -167,17 +167,17 @@
 #ifndef S_SPLINT_S
 #asm
 
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp+.strlen_fromfs.ds]	! source segment (local variable)
 	mov	es,ax
-	mov	di,[bp+4]	! source address
+	mov	di,[bp+.strlen_fromfs.saddr]	! source address
 	cld
 	xor	al,al		! search for NULL byte
 	mov	cx,#-1
 	rep
 	scasb
-	sub	di,[bp+4]	! calc len +1
+	sub	di,[bp+.strlen_fromfs.saddr]	! calc len +1
Quoted 8 lines

arch/i86/mm/user.c line 183

Quoted 6 lines
arch/i86/mm/user.c +1 -1
 	dec	di
-	mov	[bp-6],di	! save in local var ds
+	mov	[bp+.strlen_fromfs.ds],di	! save in local var ds
 #endasm
 #endif
 

This part was applied.

The changes are on CVS? I did an 'cvs update', and the last revision of user.c (1.17) doesn't contain any of these changes.

Signature · 1 line
Eduardo
#7 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Quoted 7 lines · Eduardo Pereira Habkost

Hi, Mike,

Quoted 1 line · Miguel Bolanos

Applied, but i did some changes on the patch, please read bellow.

The changes are on CVS? I did an 'cvs update', and the last revision of user.c (1.17) doesn't contain any of these changes.

Does sf still lag public anoncvs one day behind?

Paul

#8 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

In reply to Eduardo Pereira Habkost
Quoted 8 lines · Eduardo Pereira Habkost

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

You may need to apply the same fix in strlen_fromfs().

arch/i86/mm/user.c 2004-06-01 22:27:54.000000000 -0300 renamed from arch/i86/mm/user.c 2004-06-01 22:29:01.000000000 -0300 +5 -2
diff -rud e/arch/i86/mm/user.c elks/arch/i86/mm/user.c
@@ -165,8 +165,9 @@
 
 #ifndef S_SPLINT_S
 #asm
-
-       mov     ax,[bp-6]       ! source segment (local variable)
+       push    di
+       push    si
+       mov     ax,[bp-2]       ! source segment (local variable)
        mov     es,ax
        mov     di,[bp+4]       ! source address
        cld
@@ -177,6 +178,8 @@
        sub     di,[bp+4]       ! calc len +1
        dec     di
        mov     [bp-6],di       ! save in local var ds
+       pop     si
+       pop     di
 #endasm
 #endif
 
#9 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

Applied. Thanks

Mike

Quoted 43 lines · On Tue, 2004-06-01 at 19:33, [email protected] wrote:
Quoted 8 lines · Eduardo Pereira Habkost

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

You may need to apply the same fix in strlen_fromfs().

diff -rud e/arch/i86/mm/user.c elks/arch/i86/mm/user.c

arch/i86/mm/user.c 2004-06-01 22:27:54.000000000 -0300 renamed from arch/i86/mm/user.c 2004-06-01 22:29:01.000000000 -0300 +5 -3
@@ -165,8 +165,9 @@
 
 #ifndef S_SPLINT_S
 #asm
-
-       mov     ax,[bp-6]       ! source segment (local variable)
+       push    di
+       push    si
+       mov     ax,[bp-2]       ! source segment (local variable)
        mov     es,ax
        mov     di,[bp+4]       ! source address
        cld
@@ -177,6 +178,8 @@
        sub     di,[bp+4]       ! calc len +1
        dec     di
        mov     [bp-6],di       ! save in local var ds
+       pop     si
+       pop     di
 #endasm
 #endif
 
 
-

To unsubscribe from this list: send the line "unsubscribe linux-8086" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: Experimental fix for my memcpy_{to,from}fs problem

In reply to Eduardo Pereira Habkost

Applied. Thanks.

Mike

Quoted 58 lines · Eduardo Pereira Habkost

The following patch fixes the problem on my system. Probably with some versions of bcc the patch will break something.

I've added code to save the contents of SI and DI, I don't know if the callers of these functions assume that SI and DI are touched, but just in case.

Now the system booted and ran flawlessly.

arch/i86/mm/user.c +11 -2
@@ -34,10 +34,12 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
 	mov	bx,ds
 	mov	es,bx
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	ds,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -47,8 +49,11 @@
 	movsb
 	mov	ds,bx
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
+
 }
 
 int verified_memcpy_fromfs(void *daddr, void *saddr, size_t len)
@@ -69,8 +74,10 @@
 
 #ifndef S_SPLINT_S
 #asm
+	push	si
+	push	di
 	mov	dx,es
-	mov	ax,[bp-6]	! source segment (local variable)
+	mov	ax,[bp-2]	! source segment (local variable)
 	mov	es,ax
 	mov	di,[bp+4]	! destination address
 	mov	si,[bp+6]	! source address
@@ -79,6 +86,8 @@
 	rep
 	movsb
 	mov	es,dx
+	pop	di
+	pop	si
 #endasm
 #endif
 }