public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
* memcpy_fromfs() failing. Wrong variable offsets
@ 2004-06-01 21:32 Eduardo Pereira Habkost
  2004-06-01 22:02 ` Experimental fix for my memcpy_{to,from}fs problem Eduardo Pereira Habkost
  0 siblings, 1 reply; 11+ messages in thread
From: Eduardo Pereira Habkost @ 2004-06-01 21:32 UTC (permalink / raw)
  To: linux-8086

[-- Attachment #1: Type: text/plain, Size: 2825 bytes --]


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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-06-03 14:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-01 21:32 memcpy_fromfs() failing. Wrong variable offsets Eduardo Pereira Habkost
2004-06-01 22:02 ` Experimental fix for my memcpy_{to,from}fs problem Eduardo Pereira Habkost
2004-06-01 22:30   ` Eduardo Pereira Habkost
2004-06-02  2:57     ` Miguel Bolanos
2004-06-02 16:25       ` Eduardo Pereira Habkost
2004-06-03 14:02         ` Miguel Bolanos
2004-06-03 14:14           ` Eduardo Pereira Habkost
2004-06-03 14:37             ` Paul Nasrat
2004-06-02  1:33   ` claudio
2004-06-02 20:53     ` Miguel Bolanos
2004-06-02  3:05   ` Miguel Bolanos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox