From: Thorsten O. <ad...@th...> - 2025-03-22 13:07:14
|
Hi, while trying to write a test program, i encountered a strange bug with gcc asm clobber list. The code in question is register unsigned short *start __asm__("a0"); unsigned short *end; oldsp = Super(0); start = buf + sizeof(buf) / sizeof(buf[0]); __asm__ __volatile__( ".dc.w 0xf320,0x4e71,0x4e71,0x4e71\n" /* fsave -(a0) */ "move.l %1,%0\n" : "=a"(end) : "a"(start) : ); SuperToUser(oldsp); printf("start: %08lx end: %08lx size: %ld\n", (long)end, (long)start, (long)start - (long)end); And the generated code is: [0000014a] 7000 moveq.l #0,d0 [0000014c] 2f00 move.l d0,-(a7) [0000014e] 3f3c 0020 move.w #$0020,-(a7) ; Super [00000152] 4e41 trap #1 [00000154] 5c8f addq.l #6,a7 [00000156] 41f9 0001 94c8 lea.l $000193E4,a0 [0000015c] f320 fsave -(a0) [0000015e] 4e71 nop [00000160] 4e71 nop [00000162] 4e71 nop [00000164] 2648 movea.l a0,a3 [00000166] 2a4f movea.l a7,a5 <-- apparently the backup_sp from SuperToUser macro [00000168] 2f00 move.l d0,-(a7) [0000016a] 3f3c 0020 move.w #$0020,-(a7) ; Super [0000016e] 4e41 trap #1 [00000170] 2e4d movea.l a5,a7 [00000172] 2008 move.l a0,d0 <-- using a0, although it was declared as being clobbered??? [00000174] 908b sub.l a3,d0 [00000176] 2f00 move.l d0,-(a7) [00000178] 2f08 move.l a0,-(a7) [0000017a] 2f0b move.l a3,-(a7) [00000186] 487a ff3a pea.l .LC0(pc) [0000018a] 4eb9 0000 2998 jsr _printf As seen above, gcc seems to assume that "a0" still contains the value of start, although is was declared as being clobbered in the SuperToUser macro. Did i miss something, or what is going wrong there? |