GP2X Word Of Warning About Clobber List With Inline Asm


MadDog

Member
Joined
Mar 4, 2006
Messages
262
Age
53
Location
UK
Website
www.maddoggames.com
I've been wasting most of my dev time on this, turned out to be the clobber lists on the inline asm. That is unless I got it very wrong on how they work. (could be a posiblity ;)

This one works, I store the regs I mess with, then restore on exit.
asm volatile
(
"stmfd sp!, {r0-r11} \n"
"mov r0,#0x000000f0 \n"
"mov r1,%1 \n"
"mov r2,%0 \n"
"orr r2,r2,r2,lsl #8 \n"
"orr r2,r2,r2,lsl #16 \n"
"mov r3,r2 \n"
"mov r4,r2 \n"
"mov r5,r2 \n"
"mov r6,r2 \n"
"mov r7,r2 \n"
"mov r8,r2 \n"
"mov r9,r2 \n"
"mov r10,r2 \n"
"mov r11,r2 \n"
"clear_screen_loop: \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" subs r0,r0,#1 \n"
"bne clear_screen_loop \n"
"ldmfd sp!, {r0-r11} \n"
:
:"r"(pPalette_index), "r"(pDest)
);*/

On this code I ask the compiler to do it for me with a clobber list, and it locks up the CPU. :(
asm volatile
(
"mov r0,#0x000000f0 \n"
"mov r1,%1 \n"
"mov r2,%0 \n"
"orr r2,r2,r2,lsl #8 \n"
"orr r2,r2,r2,lsl #16 \n"
"mov r3,r2 \n"
"mov r4,r2 \n"
"mov r5,r2 \n"
"mov r6,r2 \n"
"mov r7,r2 \n"
"mov r8,r2 \n"
"mov r9,r2 \n"
"mov r10,r2 \n"
"mov r11,r2 \n"
"clear_screen_loop: \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" stmia r1!,{r2-r11} \n"
" subs r0,r0,#1 \n"
"bne clear_screen_loop \n"
:
:"r"(pPalette_index), "r"(pDest)
:"r0","r1","r2","r3","r4","r5","r6","r7","r8","r9","r10","r11"
);
 

Flavor

Daddy
Joined
Mar 19, 2003
Messages
374
Yeah, it's always interesting to compile with -save-temps as an option. Then you can see exactlly what the compiler is doing.
 

MadDog

Member
Joined
Mar 4, 2006
Messages
262
Age
53
Location
UK
Website
www.maddoggames.com
rixed posted on May 26 2006 at 03:49 PM said:
What's the code generated by the compiler for the second code sequence ?
Is there an easy way to check? (may be a dumb question, but i'm a non gcc guru)
That was my first idea, go have a look at what it made but then I hit a wall. Tried googling for some kind of disassembler. Something wacky is going on, restoring regs I trash by hand got rid of all the random locks ups I was getting. Now the 920 and 940 run for hours no probs. Use the clobber list in just one place, don't matter what your doing and the code will lockup, sometimes within a few seconds other times takes 20 secs.
 
Last edited by a moderator:

rixed

Member
Joined
Dec 31, 2005
Messages
206
Age
46
Location
Paris (fr)
Website
happyleptic.org
MadDog posted on May 26 2006 at 05:17 PM said:
Is there an easy way to check? (may be a dumb question, but i'm a non gcc guru)

Use objdump.

If you have all symbols compiled in and its a standard executable : objdump -g -s -d file

If its in a 'strange' format, uses other switches (-m arm, -b binary perhaps, -D to force disassembly of all sections ...)
 
Last edited by a moderator:

Radek

Certified Guru
Joined
Oct 13, 2005
Messages
871
I think you can use only r0-r7 safely for the clobber list.

Squidge gave me once a link for PDF where it was explained. I have this PDF on my hdd probably - as I hope to get back to coding soon I will have to look at this pdf.
 
Top