This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


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

Interesting thing


Try compiling the following c++ program:

// start here

#define TSTR  (*(volatile unsigned char *)(0xFFFF8240))
#define TSYN  (*(volatile unsigned char *)(0xFFFF8241))

inline void x()
	{
	TSTR=TSTR & 0xFE;
	}

inline void y()
	{
	TSYN=0;
	}

void broken()
	{
	x();
	y();
	}

// stop here

save this as "t.cc"

now run:
	gcc -g -O2 -c t.cc
	objdump -s -d t.o

and you get:

Disassembly of section .text:

00000000 <broken__Fv>:
   0:	55                   	push   %ebp
   1:	a0 40 82 ff ff       	mov    0xffff8240,%al
   6:	25 fe 00 00 00       	and    $0xfe,%eax
   b:	a2 40 82 ff ff       	mov    %al,0xffff8240
  10:	a0 40 82 ff ff       	mov    0xffff8240,%al
  15:	c6 05 41 82 ff ff 00  movb   $0x0,0xffff8241
  1c:	89 e5                	mov    %esp,%ebp
  1e:	a0 41 82 ff ff       	mov    0xffff8241,%al
  23:	5d                   	pop    %ebp
  24:	c3                   	ret   

Why are the instructions at 0x10 & 0x1e included? 
Is there any way around this apart from dropping the volatile?
Have I misinterpreted the meaning of volatile?

BTW This does a similar thing on the sh target as well:

Disassembly of section .text:

00000000 <_broken__Fv>:
   0:	2f e6       	mov.l	r14,@-r15
   2:	91 0b       mov.w	1c <_broken__Fv+0x1c>,r1	! 0x8240
   4:	6e f3       	mov	r15,r14
   6:	60 10       mov.b	@r1,r0
   8:	c9 fe       	and	#-2,r0
   a:	21 00       mov.b	r0,@r1
   c:	61 10       mov.b	@r1,r1
   e:	92 06       mov.w	1e <_broken__Fv+0x1e>,r2	! 0x8241
  10:	e1 00       	mov	#0,r1
  12:	22 10       mov.b	r1,@r2
  14:	61 20       mov.b	@r2,r1
  16:	6f e3       	mov	r14,r15
  18:	00 0b       rts	
  1a:	6e f6       	mov.l	@r15+,r14
  1c:	82 40       .word 0x8240
  1e:	82 41       .word 0x8241

Interesting enough, it works fine if the file is a C program (i.e. you've 
called it t.c or similar.


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


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