Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 May 1995 12:24:27 +1000 (EST)
From:      David Dawes <dawes@physics.usyd.edu.au>
To:        hackers@FreeBSD.org
Cc:        alpha@xfree86.org
Subject:   Problem with asm code in Mach32 server on FreeBSD 2.0 snaps
Message-ID:  <199505030224.AA12944@physics.su.oz.au>

next in thread | raw e-mail | index | archive | help
I've just been debugging a problem with the XFree86 Mach32 server on
a machine running one of the 2.0 snaps (the Feb snap, but the same problem
happens with a server compiled with the latest snap).  The problem is
a SIGSEGV in outsw(), with the following stack trace:

#0  0xb07c in outsw (buf=0x338928, count=3, port=58088) at mach32im.c:127
#1  0x5 in ?? ()
#2  0x9bc3 in mach32ImageWriteNoMem (x=17, y=452, w=5, h=13, 
    psrc=0x338928 <Address 0x338928 out of bounds>, pwidth=8, px=0, py=0, 
    alu=5, planemask=4294967295) at mach32im.c:433
#3  0x9636 in mach32ImageWrite (x=17, y=452, w=5, h=13, 
    psrc=0x338928 <Address 0x338928 out of bounds>, pwidth=8, px=0, py=0, 
    alu=5, planemask=4294967295) at mach32im.c:257
#4  0xc4a8 in mach32CopyArea (pSrcDrawable=0x338900, pDstDrawable=0x338700, 
    pGC=0x342000, srcx=0, srcy=0, width=5, height=13, dstx=17, dsty=452)
    at mach32blt.c:443
#5  0x4555b in ProcCopyArea ()
#6  0x4b5c8 in SProcCopyArea ()
#7  0x433ef in Dispatch ()
#8  0x36d75 in main ()


I've isolated the problem to the following __asm__ function:

  static __inline__ void outsw(void *buf, short count, unsigned short port)
  {
     __asm__ __volatile__ ("cld;rep;outsw" 
                       ::"d" (port),"S" (buf),"c" (count):"cx","si");
  }


Replacing this with:

  static void outsw(buf, count, port)
  void *buf;
  short count;
  register unsigned short port;
  {
          register int i;
          register unsigned short *p = (unsigned short *)buf;
  
          for (i=0; i < count; i++)
                  outw(port, *(p++));
  }

fixes the problem.

The asm version doesn't cause a problem on FreeBSD 1.1.5.  I haven't been
able to test this on a 2.0R system.

Whether or not the asm version is inlined makes no difference.  I've
disassembled both the 2.0-SNAP-950412 and 1.1.5 versions.  They are
slightly different, but I don't know enough about the assembler
instructions to know if the differences are important, or if the
problem is compiler related.  I've attached the disassembled output.

If anyone wants to reproduce the SIGSEGV, try running:

  x11perf -rop GXxor copypixwin10

It may be useful to know if this shows up on a 2.0R system.

Does anyone have any ideas as to the cause of this?  We can work around it,
but I'd like to know the cause so that we can avoid this occurring elsewhere.


For SNAP-950412 (gcc version 2.6.3, compiled with '-g', no optimisation)

Dump of assembler code for function outsw:
0xb05c <outsw>: pushl  %ebp
0xb05d <outsw+1>:       movl   %esp,%ebp
0xb05f <outsw+3>:       subl   $0x4,%esp
0xb062 <outsw+6>:       pushl  %edi
0xb063 <outsw+7>:       pushl  %esi
0xb064 <outsw+8>:       pushl  %ebx
0xb065 <outsw+9>:       movl   0xc(%ebp),%esi
0xb068 <outsw+12>:      movl   %esi,0xfffffffc(%ebp)
0xb06b <outsw+15>:      movl   0x10(%ebp),%eax
0xb06e <outsw+18>:      movw   0xfffffffc(%ebp),%di
0xb072 <outsw+22>:      movl   %eax,%ebx
0xb074 <outsw+24>:      movl   %ebx,%edx
0xb076 <outsw+26>:      movl   0x8(%ebp),%esi
0xb079 <outsw+29>:      movl   %edi,%ecx
0xb07b <outsw+31>:      cld    
0xb07c <outsw+32>:      repz outsw %ds:(%esi),(%dx)
0xb07f <outsw+35>:      leal   0xfffffff0(%ebp),%esp
0xb082 <outsw+38>:      popl   %ebx
0xb083 <outsw+39>:      popl   %esi
0xb084 <outsw+40>:      popl   %edi
0xb085 <outsw+41>:      leave  
0xb086 <outsw+42>:      ret    
0xb087 <outsw+43>:      addb   %dl,0xffffff89(%ebp)


For 1.1.5 (gcc version 2.4.5, compiled with '-g', no optimisation)

Dump of assembler code for function outsw:
0xbd50 <outsw>: pushl  %ebp
0xbd51 <outsw+1>:       movl   %esp,%ebp
0xbd53 <outsw+3>:       subl   $0x8,%esp
0xbd56 <outsw+6>:       pushl  %edi
0xbd57 <outsw+7>:       pushl  %esi
0xbd58 <outsw+8>:       pushl  %ebx
0xbd59 <outsw+9>:       movl   0x8(%ebp),%ebx
0xbd5c <outsw+12>:      movl   0xc(%ebp),%ecx
0xbd5f <outsw+15>:      movl   %ecx,0xfffffff8(%ebp)
0xbd62 <outsw+18>:      movl   0x10(%ebp),%eax
0xbd65 <outsw+21>:      movw   0xfffffff8(%ebp),%si
0xbd69 <outsw+25>:      movw   %si,0xfffffffc(%ebp)
0xbd6d <outsw+29>:      movl   %eax,%edi
0xbd6f <outsw+31>:      movl   %edi,%edx
0xbd71 <outsw+33>:      movl   %ebx,%esi
0xbd73 <outsw+35>:      movw   0xfffffffc(%ebp),%cx
0xbd77 <outsw+39>:      cld    
0xbd78 <outsw+40>:      repz outsw %ds:(%esi),(%dx)
0xbd7b <outsw+43>:      leal   0xffffffec(%ebp),%esp
0xbd7e <outsw+46>:      popl   %ebx
0xbd7f <outsw+47>:      popl   %esi
0xbd80 <outsw+48>:      popl   %edi
0xbd81 <outsw+49>:      leave  
0xbd82 <outsw+50>:      ret    
0xbd83 <outsw+51>:      addb   %dl,0xffffff89(%ebp)
End of assembler dump.


David



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199505030224.AA12944>