This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
problem with bad code generated by m68k cross compiler
- To: egcs-bugs at cygnus dot com
- Subject: problem with bad code generated by m68k cross compiler
- From: Greg Ungerer <gerg at moreton dot com dot au>
- Date: Fri, 05 Feb 1999 09:50:15 +1000
- CC: gerg at moreton dot com dot au
- Organization: Moreton Bay Ventures
Hi egcs-buglist,
I am having a problem with the code produced from an egcs-1.1.1 m68k
cross compiler. This compiler is being used to generate Coldfire code
from a Linux host system.
Cross compiler details:
VERSION: egcs 1.1.1
HOST: i686-pc-linux-gnu (as reported by configure)
TARGET: m68k-*-linux-gnu* (supplied to configure --target)
SYSTEM: Pentium2/266, 64Mb RAM, running Red Hat 5.2 Linux
with a 2.2.1 version kernel.
Compiling the sample code provided below produces some bad assmebler
for the C code at offset line 125 (it has a PROBLEM-LINE comment
around it for clarity). The line reads:
bh[i]->b_rsector = bh[i]->b_blocknr*(bh[i]->b_size>>9);
The compiler command line is:
m68k-elf-gcc -m5200 -Wa,-m5200 -O -c tst.c
(where tst.c is the sample code below)
Looking at the objdump fragment for the code generated by this line:
(full disassembly is provided below too)
de: 2072 2c00 moveal %a2@(00000000,%d2:l:4),%a0
e2: 2028 0020 movel %a0@(32),%d0
e6: 7a09 moveq #9,%d5
e8: eaa8 lsrl %d5,%d0
ea: 4c00 0800 mulsl %d0,%d0
ee: 2140 0008 movel %d0,%a0@(8)
Strait away you can see that the "mulsl" is not right. There is no
way that the d0 should be multiplied by d0. The shift looks ok.
I can't see any code that loads the b_blocknr argument at all.
Sorry for the size of the example code. I tried sample code that
had just the offending line, but it did not produce bad code :-(
I stumbled across this problem when the b_blocknr arg was 0, and
the b_size was 0x400. This routine kept generating reads of sector 4
from the device, when they should clearly be sector 0 with these
arguments. (This result being generated from the bad mulsl).
What do you all think?
If I have sent this to the wrong list, sorry!
(and suggestions on where to send it appreciated...)
Happy to supply more information or detail if I can.
Regards
Greg
-------------------------------CODE-SAMPLE--tst.c----------------------------
struct buffer_head {
/* First cache line: */
unsigned long b_blocknr; /* block number */
short b_dev; /* device (B_FREE = free) */
short b_rdev; /* Real device */
unsigned long b_rsector; /* Real buffer location on disk */
struct buffer_head * b_next; /* Hash queue list */
struct buffer_head * b_this_page; /* circular list of buffers in one page */
/* Second cache line: */
unsigned long b_state; /* buffer state bitmap (see above) */
struct buffer_head * b_next_free;
unsigned int b_count; /* users using this block */
unsigned long b_size; /* block size */
/* Non-performance-critical data follows. */
char * b_data; /* pointer to data block (1024 bytes) */
unsigned int b_list; /* List that this buffer appears */
unsigned long b_flushtime; /* Time when this (dirty) buffer
* should be written */
unsigned long b_lru_time; /* Time when this buffer was
* last used. */
/*struct wait_queue * b_wait;*/
struct buffer_head * b_prev; /* doubly linked list of hash-queue */
struct buffer_head * b_prev_free; /* doubly linked list of buffers */
struct buffer_head * b_reqnext; /* request queue */
};
struct request {
volatile int rq_status; /* should split this into a few status bits */
#define RQ_INACTIVE (-1)
#define RQ_ACTIVE 1
#define RQ_SCSI_BUSY 0xffff
#define RQ_SCSI_DONE 0xfffe
#define RQ_SCSI_DISCONNECTING 0xffe0
unsigned short rq_dev;
int cmd; /* READ or WRITE */
int errors;
unsigned long sector;
unsigned long nr_sectors;
unsigned long current_nr_sectors;
char * buffer;
struct semaphore * sem;
struct buffer_head * bh;
struct buffer_head * bhtail;
struct request * next;
};
struct blk_dev_struct {
void (*request_fn)(void);
struct request * current_request;
struct request plug;
/*struct tq_struct plug_tq;*/
};
#define NULL 0
#define MAX_BLKDEV 16
#define KERN_ERR
#define KERN_NOTICE
#define BH_Req 1
#define BH_Dirty 2
#define BH_Uptodate 3
#define WRITE 1
#define WRITEA 2
extern int BLOCK_SIZE;
extern int *blksize_size[];
extern struct blk_dev_struct *blk_dev;
void ll_rw_block(int rw, int nr, struct buffer_head * bh[])
{
unsigned int major;
int correct_size;
struct blk_dev_struct * dev;
int i;
/* Make sure that the first block contains something reasonable */
while (!*bh) {
bh++;
if (--nr <= 0)
return;
}
dev = NULL;
if ((major = MAJOR(bh[0]->b_dev)) < MAX_BLKDEV)
dev = blk_dev + major;
if (!dev || !dev->request_fn) {
printk(KERN_ERR
"ll_rw_block: Trying to read nonexistent block-device %s (%ld)\n",
kdevname(bh[0]->b_dev), bh[0]->b_blocknr);
goto sorry;
}
/* Determine correct block size for this device. */
correct_size = BLOCK_SIZE;
if (blksize_size[major]) {
i = blksize_size[major][MINOR(bh[0]->b_dev)];
if (i)
correct_size = i;
}
/* Verify requested block sizes. */
for (i = 0; i < nr; i++) {
if (bh[i] && bh[i]->b_size != correct_size) {
printk(KERN_NOTICE "ll_rw_block: device %s: "
"only %d-char blocks implemented (%lu)\n",
kdevname(bh[0]->b_dev),
correct_size, bh[i]->b_size);
goto sorry;
}
/* Md remaps blocks now */
bh[i]->b_rdev = bh[i]->b_dev;
/*------------------PROBLEM-LINE--------------------------------*/
bh[i]->b_rsector = bh[i]->b_blocknr*(bh[i]->b_size>>9);
/*--------------------------------------------------------------*/
#ifdef CONFIG_BLK_DEV_MD
if (major==MD_MAJOR &&
md_map (MINOR(bh[i]->b_dev), &bh[i]->b_rdev,
&bh[i]->b_rsector, bh[i]->b_size >> 9)) {
printk (KERN_ERR
"Bad md_map in ll_rw_block\n");
goto sorry;
}
#endif
}
if ((rw == WRITE || rw == WRITEA) && is_read_only(bh[0]->b_dev)) {
printk(KERN_NOTICE "Can't write to read-only device %s\n",
kdevname(bh[0]->b_dev));
goto sorry;
}
for (i = 0; i < nr; i++) {
if (bh[i]) {
set_bit(BH_Req, &bh[i]->b_state);
make_request(MAJOR(bh[i]->b_rdev), rw, bh[i]);
}
}
return;
sorry:
for (i = 0; i < nr; i++) {
if (bh[i]) {
clear_bit(BH_Dirty, &bh[i]->b_state);
clear_bit(BH_Uptodate, &bh[i]->b_state);
}
}
return;
}
-----------------------------------------------------------------------------
tst.o: file format elf32-m68k
Disassembly of section .text:
00000000 <ll_rw_block>:
0: 4e56 0000 linkw %fp,#0
4: 4fef ffe4 lea %sp@(-28),%sp
8: 48d7 1c3c moveml %d2-%d5/%a2-%a4,%sp@
c: 282e 0008 movel %fp@(8),%d4
10: 262e 000c movel %fp@(12),%d3
14: 246e 0010 moveal %fp@(16),%a2
18: 4a92 tstl %a2@
1a: 660e bnes 2a <ll_rw_block+0x2a>
1c: 588a addql #4,%a2
1e: 5383 subql #1,%d3
20: 4a83 tstl %d3
22: 6f00 01bc blew 1e0 <ll_rw_block+0x1e0>
26: 4a92 tstl %a2@
28: 67f2 beqs 1c <ll_rw_block+0x1c>
2a: 97cb subal %a3,%a3
2c: 2052 moveal %a2@,%a0
2e: 3068 0004 moveaw %a0@(4),%a0
32: 2f08 movel %a0,%sp@-
34: 4eb9 0000 0000 jsr 0 <ll_rw_block>
3a: 2400 movel %d0,%d2
3c: 588f addql #4,%sp
3e: 7a0f moveq #15,%d5
40: ba82 cmpl %d2,%d5
42: 6518 bcss 5c <ll_rw_block+0x5c>
44: 2242 moveal %d2,%a1
46: 43f1 2a00 lea %a1@(00000000,%d2:l:2),%a1
4a: 2009 movel %a1,%d0
4c: 2200 movel %d0,%d1
4e: e789 lsll #3,%d1
50: d081 addl %d1,%d0
52: d080 addl %d0,%d0
54: 2640 moveal %d0,%a3
56: d7f9 0000 0000 addal 0 <ll_rw_block>,%a3
5c: 4a8b tstl %a3
5e: 6704 beqs 64 <ll_rw_block+0x64>
60: 4a93 tstl %a3@
62: 6626 bnes 8a <ll_rw_block+0x8a>
64: 2052 moveal %a2@,%a0
66: 2f10 movel %a0@,%sp@-
68: 3068 0004 moveaw %a0@(4),%a0
6c: 2f08 movel %a0,%sp@-
6e: 4eb9 0000 0000 jsr 0 <ll_rw_block>
74: 2e80 movel %d0,%sp@
76: 4879 0000 0000 pea 0 <ll_rw_block>
7c: 4eb9 0000 0000 jsr 0 <ll_rw_block>
82: 4fef 000c lea %sp@(12),%sp
86: 6000 0120 braw 1a8 <ll_rw_block+0x1a8>
8a: 2679 0000 0000 moveal 0 <ll_rw_block>,%a3
90: e58a lsll #2,%d2
92: 49f9 0000 0000 lea 0 <ll_rw_block>,%a4
98: 4ab4 2800 tstl %a4@(00000000,%d2:l)
9c: 671c beqs ba <ll_rw_block+0xba>
9e: 2052 moveal %a2@,%a0
a0: 3068 0004 moveaw %a0@(4),%a0
a4: 2f08 movel %a0,%sp@-
a6: 4eb9 0000 0000 jsr 0 <ll_rw_block>
ac: 2074 2800 moveal %a4@(00000000,%d2:l),%a0
b0: 2430 0c00 movel %a0@(00000000,%d0:l:4),%d2
b4: 588f addql #4,%sp
b6: 6702 beqs ba <ll_rw_block+0xba>
b8: 2642 moveal %d2,%a3
ba: 4282 clrl %d2
bc: b682 cmpl %d2,%d3
be: 6f38 bles f8 <ll_rw_block+0xf8>
c0: 4ab2 2c00 tstl %a2@(00000000,%d2:l:4)
c4: 670c beqs d2 <ll_rw_block+0xd2>
c6: 2072 2c00 moveal %a2@(00000000,%d2:l:4),%a0
ca: b7e8 0020 cmpal %a0@(32),%a3
ce: 6600 00b2 bnew 182 <ll_rw_block+0x182>
d2: 2072 2c00 moveal %a2@(00000000,%d2:l:4),%a0
d6: 3a28 0004 movew %a0@(4),%d5
da: 3145 0006 movew %d5,%a0@(6)
de: 2072 2c00 moveal %a2@(00000000,%d2:l:4),%a0
e2: 2028 0020 movel %a0@(32),%d0
e6: 7a09 moveq #9,%d5
e8: eaa8 lsrl %d5,%d0
ea: 4c00 0800 mulsl %d0,%d0
ee: 2140 0008 movel %d0,%a0@(8)
f2: 5282 addql #1,%d2
f4: b682 cmpl %d2,%d3
f6: 6ec8 bgts c0 <ll_rw_block+0xc0>
f8: 2004 movel %d4,%d0
fa: 5380 subql #1,%d0
fc: 7a01 moveq #1,%d5
fe: ba80 cmpl %d0,%d5
100: 6536 bcss 138 <ll_rw_block+0x138>
102: 2052 moveal %a2@,%a0
104: 3068 0004 moveaw %a0@(4),%a0
108: 2f08 movel %a0,%sp@-
10a: 4eb9 0000 0000 jsr 0 <ll_rw_block>
110: 588f addql #4,%sp
112: 4a80 tstl %d0
114: 6722 beqs 138 <ll_rw_block+0x138>
116: 2052 moveal %a2@,%a0
118: 3068 0004 moveaw %a0@(4),%a0
11c: 2f08 movel %a0,%sp@-
11e: 4eb9 0000 0000 jsr 0 <ll_rw_block>
124: 2f00 movel %d0,%sp@-
126: 4879 0000 0000 pea 0 <ll_rw_block>
12c: 4eb9 0000 0000 jsr 0 <ll_rw_block>
132: 4fef 000c lea %sp@(12),%sp
136: 6070 bras 1a8 <ll_rw_block+0x1a8>
138: 4282 clrl %d2
13a: b682 cmpl %d2,%d3
13c: 6f00 00a2 blew 1e0 <ll_rw_block+0x1e0>
140: 4ab2 2c00 tstl %a2@(00000000,%d2:l:4)
144: 6734 beqs 17a <ll_rw_block+0x17a>
146: 7a14 moveq #20,%d5
148: dab2 2c00 addl %a2@(00000000,%d2:l:4),%d5
14c: 2f05 movel %d5,%sp@-
14e: 4878 0001 pea 1 <ll_rw_block+0x1>
152: 4eb9 0000 0000 jsr 0 <ll_rw_block>
158: 2f32 2c00 movel %a2@(00000000,%d2:l:4),%sp@-
15c: 2f04 movel %d4,%sp@-
15e: 2072 2c00 moveal %a2@(00000000,%d2:l:4),%a0
162: 3068 0006 moveaw %a0@(6),%a0
166: 2f08 movel %a0,%sp@-
168: 4eb9 0000 0000 jsr 0 <ll_rw_block>
16e: 2e80 movel %d0,%sp@
170: 4eb9 0000 0000 jsr 0 <ll_rw_block>
176: 4fef 0014 lea %sp@(20),%sp
17a: 5282 addql #1,%d2
17c: b682 cmpl %d2,%d3
17e: 6ec0 bgts 140 <ll_rw_block+0x140>
180: 605e bras 1e0 <ll_rw_block+0x1e0>
182: 2f28 0020 movel %a0@(32),%sp@-
186: 2f0b movel %a3,%sp@-
188: 2052 moveal %a2@,%a0
18a: 3068 0004 moveaw %a0@(4),%a0
18e: 2f08 movel %a0,%sp@-
190: 4eb9 0000 0000 jsr 0 <ll_rw_block>
196: 2e80 movel %d0,%sp@
198: 4879 0000 0000 pea 0 <ll_rw_block>
19e: 4eb9 0000 0000 jsr 0 <ll_rw_block>
1a4: 4fef 0010 lea %sp@(16),%sp
1a8: 4282 clrl %d2
1aa: b682 cmpl %d2,%d3
1ac: 6f32 bles 1e0 <ll_rw_block+0x1e0>
1ae: 47f9 0000 0000 lea 0 <ll_rw_block>,%a3
1b4: 4ab2 2c00 tstl %a2@(00000000,%d2:l:4)
1b8: 6720 beqs 1da <ll_rw_block+0x1da>
1ba: 7a14 moveq #20,%d5
1bc: dab2 2c00 addl %a2@(00000000,%d2:l:4),%d5
1c0: 2f05 movel %d5,%sp@-
1c2: 4878 0002 pea 2 <ll_rw_block+0x2>
1c6: 4e93 jsr %a3@
1c8: 7a14 moveq #20,%d5
1ca: dab2 2c00 addl %a2@(00000000,%d2:l:4),%d5
1ce: 2f05 movel %d5,%sp@-
1d0: 4878 0003 pea 3 <ll_rw_block+0x3>
1d4: 4e93 jsr %a3@
1d6: 4fef 0010 lea %sp@(16),%sp
1da: 5282 addql #1,%d2
1dc: b682 cmpl %d2,%d3
1de: 6ed4 bgts 1b4 <ll_rw_block+0x1b4>
1e0: 242e ffe4 movel %fp@(-28),%d2
1e4: 262e ffe8 movel %fp@(-24),%d3
1e8: 282e ffec movel %fp@(-20),%d4
1ec: 2a2e fff0 movel %fp@(-16),%d5
1f0: 246e fff4 moveal %fp@(-12),%a2
1f4: 266e fff8 moveal %fp@(-8),%a3
1f8: 286e fffc moveal %fp@(-4),%a4
1fc: 4e5e unlk %fp
1fe: 4e75 rts
-----------------------------------------------------------------------------