Article View: gnu.g++.bug
Article #1157Re: GCC 2.1 - Bad code for 68k with g++ persists.
From: Mike Stump
Date: Mon, 21 Dec 1992 22:03
Date: Mon, 21 Dec 1992 22:03
581 lines
14486 bytes
14486 bytes
This problem has been fixed, and should not exist in the next release of gcc.
> Message-Id: <9204030609.AA16331@raisin-nut>
> To: bug-gcc@prep.ai.mit.edu
> Cc: bst%tt@cam.org
> Date: Thu, 02 Apr 92 21:18:28 -0500
> From: Brent Townshend <bst%tt@cam.org>
> I just checked out gcc 2.1 to see if the following bug
> is fixed and discovered that it is still present. Since
> I did not see my previous bug report on my news feed of
> gnu.gcc.bug I am reposting this in case the original bug
> report was lost.
> -Brent
> ------- Forwarded Message
> Date: Thu, 5 Mar 92 16:22:18 EST
> From: bst (Brent Townshend)
> Message-Id: <9203052122.AA13825@tt.UUCP>
> To: bug-gcc@prep.ai.mit.edu
> Cc: bst
> Using g++ 2.0 (built from gcc 2.0),
> I just hit a case of some bad code generated for a 68k target
> using a Sparc host. The result is that the code tries to
> access a 32bit word on an odd-byte boundary. The situation
> that causes the bug seems complicated -- the example following
> is about the smallest I could pare it down to without undue
> effort. The bad assembler output below is marked with BAD.
> Configuration:
> #!/bin/sh
> # GCC was configured as follows:
> ../../gcc/gcc-2.00/configure --host=sun4 --target=sun3
> The sun3.h file was editted to change TARGET to 0 from 7
> for compilation to a 68000 with no floating point. This
> configuration was then built and installed as tct68. Some
> of the link specs were also changed, but I doubt that will
> affect the results. (If it does I will send more info).
> Host:
> Sparc 1+ SunOS 4.1
> Command line:
> g++ -S -btct68 -O bug.c
> Source File (bug.c)
> - ----------------------------------
> typedef unsigned char byte;
> typedef unsigned short word;
> typedef unsigned int u_int;
> typedef byte boolean;
> extern void debug(int level,const char *fmt,...);
> extern void debug(const char *t_name,int level,const char *fmt,...);
> struct Status {
> enum StatCodes {
> Good = 0x00,
> CheckCondition = 0x02,
> ConditionMet = 0x04,
> Busy = 0x08,
> Intermediate = 0x10,
> IntermediateConditionMet = 0x14,
> ReservationConflict = 0x18,
> CommandTerminated = 0x22,
> QueueFull = 0x28,
> } code;
> Status()
> { code = Good; }
> Status(StatCodes c)
> { code = c; }
> };
> class SCSICommand;
> class SCSI;
> class SCSIUnit {
> Status stat;
> byte reservedBy;
> byte reservedFor;
> int init;
> byte unitAttention;
> protected:
> static const unsigned int MaxSCSIHold;
> void MainLoop();
> virtual Status ChangeDefinition(boolean save, byte defParam,
> byte paramDataLength);
> virtual Status Compare(boolean pad, u_int paramListLength);
> virtual Status Copy(boolean pad, u_int paramListLength);
> virtual Status CopyAndVerify(boolean pad, boolean byteCheck,
> u_int paramListLength);
> virtual Status Inquiry(boolean EPVD, byte pageCode, byte allocLength);
> virtual Status LogSelect(boolean savePages, boolean paramCodeReset,
> byte pageControl,word allocLength);
> virtual Status LogSense(boolean savePages, boolean paramPtrControl,
> byte pageControl, byte pageCode,word paramPointer,
> word allocLength);
> virtual Status ModeSelect(boolean tenByte, boolean pageFormat,
> boolean savePages,word paramListLength);
> virtual Status ModeSense(boolean tenByte, boolean disableBlockDesc,
> byte pageControl,byte pageCode,word allocLength);
> virtual Status ReadBuffer(byte mode, byte bufferID, u_int bufferOffset,
> u_int allocLength);
> virtual Status ReceiveDiagnosticResults(word allocLength);
> virtual Status RequestSense(word allocLength);
> virtual Status SendDiagnostic(boolean pageFormat, boolean selfTest,
> boolean deviceOffLine, boolean unitOffLine,
> word paramListLength);
> virtual Status TestUnitReady();
> virtual Status WriteBuffer(byte mode, byte bufferID, u_int bufferOffset,
> u_int paramListLength);
> byte mediumType;
> byte deviceSpecificParameter;
> u_int bdLength;
> u_int modeDataLength;
> byte *modeData;
> int BlockSize() const;
> Status Unimplemented(const char *s);
> int Read(byte *data, int nbytes);
> int Write(const byte *data, int nbytes);
> public:
> SCSIUnit();
> virtual ~SCSIUnit();
> virtual Status Execute(const SCSICommand &cmd);
> };
> class SCSICommand {
> public:
> enum OpCodeType {
> Inquiry = 0x12,
> ModeSelect6 = 0x15,
> ModeSense6 = 0x1a,
> RequestSense = 0x03,
> TestUnitReady = 0x00,
> ChangeDefinition = 0x40,
> Compare = 0x39,
> Copy = 0x18,
> CopyAndVerify = 0x3a,
> LogSelect = 0x4c,
> LogSense = 0x4d,
> ModeSelect10 = 0x55,
> ModeSense10 = 0x5a,
> ReadBuffer = 0x3c,
> ReceiveDiagnosticResults = 0x1c,
> SendDiagnostic = 0x1d,
> WriteBuffer = 0x3b,
> Erase = 0x19,
> Read = 0x08,
> ReadBlockLimits = 0x05,
> ReleaseUnit = 0x17,
> ReserveUnit = 0x16,
> Rewind = 0x01,
> Space = 0x11,
> Write = 0x0a,
> WriteFilemarks = 0x10,
> LoadUnload = 0x1b,
> Locate = 0x2b,
> PreventAllowMediumRemoval = 0x1e,
> ReadPosition = 0x34,
> ReadReverse = 0x0f,
> RecoverBufferedData = 0x14,
> Verify = 0x13,
> RequestBlockAddress = 0x02,
> SeekBlock = 0x0c,
> };
> private:
> byte data[12];
> public:
> OpCodeType OpCode() const { return (OpCodeType)data[0]; }
> const byte &GetByte(int i) const { return data[i]; }
> word GetWord(int i) const { return data[i]<<8|data[i+1]; }
> u_int GetUInt(int msb, int lsb) const;
> boolean GetBit(int bytenum, int bitnum) const
> { return (GetByte(bytenum)>>bitnum)&0x1; }
> };
> Status SCSIUnit::Execute(const SCSICommand &cmd)
> {
> switch (cmd.OpCode()) {
> case SCSICommand::Inquiry:
> return Inquiry(cmd.GetBit(1,0),cmd.GetByte(2),cmd.GetByte(4));
> case SCSICommand::ModeSelect6:
> case SCSICommand::ModeSelect10:
> boolean tenByte = (cmd.OpCode() == SCSICommand::ModeSelect10);
> boolean pageFormat = cmd.GetBit(1,4);
> boolean savePages = cmd.GetBit(1,0);
> word paramListLength;
> if (tenByte)
> paramListLength = cmd.GetUInt(7,8);
> else
> paramListLength = cmd.GetByte(4);
> debug(1,"ModeSelect(tenByte=%c,pageFormat=%c,savePages=%c,paramL
> istLen=%d)\n",
> ((tenByte)?'T':'F') ,((pageFormat)?'T':'F')
> ,((savePages)?'T':'F') ,paramListLength);
> return ModeSelect(tenByte, pageFormat, savePages, paramListLength);
> case SCSICommand::ModeSense6:
> case SCSICommand::ModeSense10:
> tenByte = (cmd.OpCode() == SCSICommand::ModeSense10);
> byte PC = cmd.GetByte(2)>>6;
> word allocLength;
> if (tenByte)
> allocLength = cmd.GetUInt(7,8);
> else
> allocLength = cmd.GetByte(4);
> boolean DBD = cmd.GetBit(1,3);
> byte pageCode = cmd.GetByte(2)&0x3f;
> debug(1,"ModeSense(tenByte=%c,DBD=%c,PC=%d,page=%d,allocLen=%d)\n",
> ((tenByte)?'T':'F') ,((DBD)?'T':'F') ,PC,pageCode,allocLength);
> return ModeSense(tenByte, DBD, PC, pageCode, allocLength);
> case SCSICommand::SendDiagnostic:
> debug(1,"SendDiagnostice(pageFormat=%c,selfTest=%c,deviceOffLine
> =%c,unitOffLine=%c,paramListLength=%d)\n",
> ((cmd.GetBit(1,4))?'T':'F') ,((cmd.GetBit(1,2))?'T':'F')
> ,((cmd.GetBit(1,1))?'T':'F') ,
> ((cmd.GetBit(1,0))?'T':'F') ,cmd.GetWord(3));
> return SendDiagnostic(cmd.GetBit(1,4),cmd.GetBit(1,2),cmd.GetBit(1,1),
> cmd.GetBit(1,0),cmd.GetWord(3));
> case SCSICommand::WriteBuffer:
> debug(1,"WriteBuffer(mode=%d,bufferID=%d,bufferOffset=%d,paramLen=%d)\n",
> cmd.GetByte(1)&0x7,cmd.GetByte(2),cmd.GetUInt(3,5),cmd.GetUInt(6,8));
> return
> WriteBuffer(cmd.GetByte(1)&0x7,cmd.GetByte(2),cmd.GetUInt(3,5),cmd.GetUInt(6,8));
> default:
> char buf[10];
> return Unimplemented(buf);
> }
> }
> Assembler output (bug.s)
> - ----------------------------------
> #NO_APP
> gcc2_compiled.:
> .text
> LC0:
> .ascii
> "ModeSelect(tenByte=%c,pageFormat=%c,savePages=%c,paramListLen=%d)\12\0"
> LC1:
> .ascii "ModeSense(tenByte=%c,DBD=%c,PC=%d,page=%d,allocLen=%d)\12\0"
> LC2:
> .ascii
> "SendDiagnostice(pageFormat=%c,selfTest=%c,deviceOffLine=%c,unitOffLine=
> %c,paramListLength=%d)\12\0"
> LC3:
> .ascii "WriteBuffer(mode=%d,bufferID=%d,bufferOffset=%d,paramLen=%d)\12\0"
> .even
> .globl _Execute__8SCSIUnitRC11SCSICommand
> _Execute__8SCSIUnitRC11SCSICommand:
> link a6,#-28
> moveml #0x3f3c,sp@-
> movel a1,d6
> movel a6@(12),a5
> movel a6@(8),a3
> movel a3@(26),a6@(-14)
> clrl d0
> moveb a5@,d0
> moveq #29,d7
> cmpl d0,d7
> jeq L47
> jlt L82
> moveq #21,d4
> cmpl d0,d4
> jeq L18
> jlt L83
> moveq #18,d7
> cmpl d0,d7
> jeq L12
> jra L79
> L83:
> moveq #26,d4
> cmpl d0,d4
> jeq L34
> jra L79
> L82:
> moveq #85,d7
> cmpl d0,d7
> jeq L18
> jlt L84
> moveq #59,d4
> cmpl d0,d4
> jeq L74
> jra L79
> L84:
> moveq #90,d7
> cmpl d0,d7
> jeq L34
> jra L79
> L12:
> moveb a5@(4),d4
> clrl sp@-
> moveb d4,sp@(3)
> moveb a5@(2),d7
> clrl sp@-
> moveb d7,sp@(3)
> moveb a5@(1),d4
> moveq #1,d7
> andl d7,d4
> movel d4,sp@-
> movel a6@(-14),a3
> movew a3@(40),a0
> movel a6@(8),d7
> pea a0@(d7:l)
> movel d6,a1
> movel a3@(44),a0
> jbsr a0@
> jra L10
> L18:
> moveq #0,d0
> movel a5,a0
> moveb a0@+,d0
> moveq #85,d4
> cmpl d0,d4
> seq d3
> negb d3
> clrl d0
> moveb a0@,d0
> movel d0,d1
> asrl #4,d1
> moveq #1,d5
> andl d1,d5
> moveq #1,d7
> andl d0,d7
> moveb d7,a6@(-19)
> tstb d3
> jeq L24
> pea 8:w
> pea 7:w
> movel a5,sp@-
> jbsr _GetUInt__C11SCSICommandii
> movew d0,d2
> addw #12,sp
> jra L25
> L24:
> clrw d2
> moveb a5@(4),d2
> L25:
> movew d2,sp@-
> clrw sp@-
> moveq #70,d0
> tstb a6@(-19)
> jeq L27
> moveq #84,d0
> L27:
> movel d0,sp@-
> moveq #70,d0
> tstb d5
> jeq L29
> moveq #84,d0
> L29:
> movel d0,sp@-
> moveq #70,d0
> tstb d3
> jeq L31
> moveq #84,d0
> L31:
> movel d0,sp@-
> pea LC0
> pea 1:w
> jbsr _debug__FiPCce
> movew d2,sp@-
> clrw sp@-
> moveq #1,d4
> andl a6@(-22),d4
> movel d4,sp@-
> moveq #1,d7
> andl d5,d7
> movel d7,sp@-
> clrl sp@-
> moveb d3,sp@(3)
> movel a6@(-14),a3
> movew a3@(64),a0
> movel a6@(8),d7
> pea a0@(d7:l)
> movel d6,a1
> movel a3@(68),a0
> jbsr a0@
> jra L10
> L34:
> cmpb #90,a5@
> seq d3
> negb d3
> moveb a5@(2),d0
> lsrb #6,d0
> moveb d0,a6@(-15)
> tstb d3
> jeq L37
> pea 8:w
> pea 7:w
> movel a5,sp@-
> jbsr _GetUInt__C11SCSICommandii
> movew d0,d2
> addw #12,sp
> jra L38
> L37:
> clrw d2
> moveb a5@(4),d2
> L38:
> moveb a5@(1),d0
> lsrl #3,d0
> moveq #1,d5
> andl d0,d5
> moveb a5@(2),d4
> andb #63,d4
> moveb d4,a6@(-16)
> movew d2,sp@-
> clrw sp@-
> moveq #63,d7
> andl d4,d7
> movel d7,sp@-
> moveq #3,d4
> andl a6@(-18),d4
> movel d4,sp@-
> moveq #70,d0
> tstb d5
> jeq L43
> moveq #84,d0
> L43:
> movel d0,sp@-
> moveq #70,d0
> tstb d3
> jeq L45
> moveq #84,d0
> L45:
> movel d0,sp@-
> pea LC1
> pea 1:w
> jbsr _debug__FiPCce
> movew d2,sp@-
> clrw sp@-
> moveq #63,d7
> andl a6@(-19),d7 <<<<<<<<<< BAD alignment
> movel d7,sp@-
> moveq #3,d4
> andl a6@(-18),d4
> movel d4,sp@-
> moveq #1,d7
> andl d5,d7
> movel d7,sp@-
> clrl sp@-
> moveb d3,sp@(3)
> movel a6@(-14),a3
> movew a3@(72),a0
> movel a6@(8),d7
> pea a0@(d7:l)
> movel d6,a1
> movel a3@(76),a0
> jbsr a0@
> jra L10
> L47:
> clrl d0
> moveb a5@(3),d0
> asll #8,d0
> clrl d1
> moveb a5@(4),d1
> orl d1,d0
> movel d0,sp@-
> moveb a5@(1),d0
> moveq #1,d4
> andl d4,d0
> moveq #70,d1
> tstb d0
> jeq L49
> moveq #84,d1
> L49:
> movel d1,sp@-
> moveq #70,d0
> btst #1,a5@(1)
> jeq L53
> moveq #84,d0
> L53:
> movel d0,sp@-
> moveq #70,d0
> btst #2,a5@(1)
> jeq L57
> moveq #84,d0
> L57:
> movel d0,sp@-
> moveq #70,d0
> btst #4,a5@(1)
> jeq L61
> moveq #84,d0
> L61:
> movel d0,sp@-
> pea LC2
> pea 1:w
> jbsr _debug__FiPCce
> addw #28,sp
> clrl d1
> moveb a5@(3),d1
> asll #8,d1
> clrl d0
> moveb a5@(4),d0
> orl d0,d1
> movel d1,sp@-
> clrl d0
> moveb a5@(1),d0
> moveq #1,d7
> andl d0,d7
> movel d7,sp@-
> movel d0,d1
> asrl #1,d1
> moveq #1,d4
> andl d4,d1
> movel d1,sp@-
> movel d0,d1
> asrl #2,d1
> andl d4,d1
> movel d1,sp@-
> asrl #4,d0
> andl d4,d0
> movel d0,sp@-
> movel a6@(-14),a3
> movew a3@(104),a0
> movel a6@(8),d7
> pea a0@(d7:l)
> movel d6,a1
> movel a3@(108),a0
> jbsr a0@
> jra L10
> L74:
> pea 8:w
> pea 6:w
> movel a5,sp@-
> lea _GetUInt__C11SCSICommandii,a2
> jbsr a2@
> movel d0,sp@-
> pea 5:w
> pea 3:w
> movel a5,sp@-
> jbsr a2@
> addqw #8,sp
> movel d0,sp@
> lea a5@(2),a4
> moveb a4@,d4
> clrl sp@-
> moveb d4,sp@(3)
> lea a5@(1),a3
> moveb a3@,d0
> andb #7,d0
> moveq #7,d7
> andl d0,d7
> movel d7,sp@-
> pea LC3
> pea 1:w
> jbsr _debug__FiPCce
> addw #32,sp
> movel #8,sp@
> pea 6:w
> movel a5,sp@-
> jbsr a2@
> movel d0,sp@-
> pea 5:w
> pea 3:w
> movel a5,sp@-
> jbsr a2@
> addqw #8,sp
> movel d0,sp@
> moveb a4@,d4
> clrl sp@-
> moveb d4,sp@(3)
> moveb a3@,d0
> andb #7,d0
> moveq #7,d7
> andl d0,d7
> movel d7,sp@-
> movel a6@(-14),a3
> movew a3@(120),a0
> movel a6@(8),d7
> pea a0@(d7:l)
> movel d6,a1
> movel a3@(124),a0
> jbsr a0@
> jra L10
> L79:
> pea a6@(-10)
> movel a6@(8),sp@-
> movel d6,a1
> jbsr _Unimplemented__8SCSIUnitPCc
> L10:
> movel d6,d0
> moveml a6@(-68),#0x3cfc
> unlk a6
> rts
> ------- End of Forwarded Message
Technical Details
Message-ID:
<9212212203.AA15653@cygnus.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrsShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs From: mrs@cygnus.com (Mike Stump) Subject: Re: GCC 2.1 - Bad code for 68k with g++ persists. Message-ID: <9212212203.AA15653@cygnus.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 21 Dec 1992 22:03:24 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 582