This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

egcs-1.0.1/m68k-coff bug


Hi,

I think I've found a bug in egcs-1.0.1 for m68k-coff.  In the
following program the variable pnum is stored in register %a0 which
is some statements further down clobbered.  Below is an example
program which shows the causes the problem, followed by snippets
of machine code.

The weird thing is that gcc-2.7.2 gives the same problem in this
function but in antoher function (which has the same general
structure, but uses different data structutures) it generates
correct code:  it moves the initial value of pnum to %a3 which is
left alone thereafter.  Egcs gets it wrong in both.  The current
solution is to hard assign a register to pnum, but that is sub-optimal.

Any ideas?

				Hans

----------------------------------------------------------------------

Reading specs from /usr/cross/lib/gcc-lib/m68k-coff/egcs-2.90.23/specs
/usr/cross/bin/m68k-coff-gcc -O4 -g -v -mcpu32 -Wall -fasm
	-Wa,-ahl,-L -nostdinc
	-DRTEMS -DRTEMS_NEWLIB -DMALLOC_PROVIDED -Dmcpu32
	-I/home/hans/src/work/rtems-3.6.0/c/bi0501/include
	-I/usr/cross/m68k-rtems/include
	-I/usr/cross/lib/gcc-lib/m68k-coff/egcs-2.90.23/include
	-I/usr/cross/include
	-I.
	-c -o o-bi0501/yyy.o yyy.c
Reading specs from /usr/cross/lib/gcc-lib/m68k-coff/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)

----------------------------------------------------------------------

#define	htonl(v)	v
#define	htons(v)	v
#define	ntohl(v)	v
#define	ntohs(v)	v
#define	u_long		unsigned long


#define	PKT_TYPE_RESPONSE	1
#define	PKT_CMD_WATCHDOG_STATUS	23
#define	PKT_ERR_OK		0
#define	PKT_ERR_NOPORT		10
#define	PKT_SETLEN(P, L)	*(u_long *) &(P[2]) = htonl(L)
#define	MAX_PORTS		8
#define	MAX_WDOGS		8


struct wdog {
    int	wd_nr;
};


struct port {
    int		p_nwd;
    struct wdog	p_wd[MAX_WDOGS];
};


unsigned char	pkt_cmd_in[100], pkt_out[100];
int		pkt_olen, pkt_cmd_ilen;
struct port	port[MAX_PORTS];


void
pkt_watchdog_status(int how)
{
    int	pnum, nwd;
	/*
	 * pnum is assigned to %a0 which is subsequently forgotten by egcs
	 */
    int	wnum;

    if (pkt_cmd_ilen != 10) {
	pkt_errmf();
	return;
    }

    pnum = ntohl(*(u_long *) &(pkt_cmd_in[ 6]));

    pkt_out[0] = PKT_TYPE_RESPONSE;
    pkt_out[1] = PKT_CMD_WATCHDOG_STATUS;
    pkt_olen = 6;

    *(u_long *) &(pkt_out[ 6]) = htonl(pnum);
    pkt_olen += 4;

    if ((pnum < 0) || (pnum > (MAX_PORTS - 1))) {
	pkt_out[10] = PKT_ERR_NOPORT;
	pkt_olen += 1;

	*(u_long *) &(pkt_out[11]) = htonl(0);
	pkt_olen += 4;

	PKT_SETLEN(pkt_out, pkt_olen);
	return;
    }

    if (port[pnum].p_nwd == 0) {	/* here pnum (i.e. %a0 is overwritten */
	pkt_out[10] = PKT_ERR_OK;
	pkt_olen += 1;

	*(u_long *) &(pkt_out[11]) = htonl(0);
	pkt_olen += 4;

	PKT_SETLEN(pkt_out, pkt_olen);
	return;
    }

    for (wnum = nwd = 0; wnum < MAX_WDOGS; wnum++) {
	if (port[pnum].p_wd[wnum].wd_nr != wnum)
	    continue;
    }

    pkt_out[10] = PKT_ERR_OK;
    pkt_olen += 1;

    *(u_long *) &(pkt_out[11]) = htonl(nwd);
    pkt_olen += 4;

    PKT_SETLEN(pkt_out, pkt_olen);
    return;

}

----------------------------------------------------------------------

44:yyy.c         ****     pnum = ntohl(*(u_long *) &(pkt_cmd_in[ 6]));
  57                    .stabn 68,0,44,.LM7-pkt_watchdog_status
  58                    .LM7:
  59 0018 2079 0000             move.l pkt_cmd_in+6,%a0
                                ^^^^^^^^^^^^^^^^^^^^^^^
Here pnum is assigned to %a0


  64:yyy.c         ****     if (port[pnum].p_nwd == 0) {
  90                    .stabn 68,0,64,.LM16-pkt_watchdog_status
  91                    .LM16:
  92 0054 41F0 8E00             lea (%a0,%a0.l*8),%a0
  93 0058 2008                  move.l %a0,%d0
  94 005a 41F9 0000             lea port,%a0
  94      0000 
                                ^^^^^^^^^^^^
Here %a0 (i.e. pnum) gets clobbered

  95 0060 4AB0 0C00             tst.l (%a0,%d0.l*4)
  96 0064 6624                  jbne .L4
  65:yyy.c         ****         pkt_out[10] = PKT_ERR_OK;


 119                    .L4:
  73:yyy.c         ****     }
  74:yyy.c         **** 
  75:yyy.c         ****     for (wnum = nwd = 0; wnum < MAX_WDOGS; wnum++) {
 120                    .stabn 68,0,75,.LM23-pkt_watchdog_status
 121                    .LM23:
 122 008a 7007                  moveq.l #7,%d0
                                ^^^^^^^^^^^^^^

Here %d0 get overwritten

 123                            .even
 124                    .L8:
 125                    .stabn 68,0,75,.LM24-pkt_watchdog_status
 126                    .LM24:
 127 008c 51C8 FFFE             dbra %d0,.L8
 128 0090 4240                  clr.w %d0
 129 0092 5380                  subq.l #1,%d0
 130 0094 64F6                  jbcc .L8
  76:yyy.c         ****         if (port[pnum].p_wd[wnum].wd_nr != wnum)
  77:yyy.c         ****             continue;
  78:yyy.c         ****     }

----------------------------------------------------------------------

-- 
H. Zuidam                        E-Mail: hans@brandinnovators.com
Brand Innovators B.V.            P-Mail: P.O. Box 1377
de Pinckart 54                   5602 BJ Eindhoven, The Netherlands
5674 CC Nuenen                   Tel. +31 40 2631134, Fax. +31 40 2831138


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]