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]
Other format: [Raw text]

RE: Assembler in C


Daniel, 

I hope the following snippet of code from a powerpc sram-test routine can
help you.
The code is running from the sram we want to test, so we first re-allocate
the code to our DRAM.
Then run the test from there and then jump back. (after copying the original
code again bcoz the test destroyed the contents of our sram)

unsigned int sramtest(unsigned char* pTESTADDRESS)
{
  unsigned int iJumpDistance=BOOTSRAM_BASE-(unsigned int) pTESTADDRESS; 

[...]

  iNewEVPR=(unsigned int) pTESTADDRESS;
  __asm__ __volatile__("bl ..s1getpc    \n"
                       "..s1getpc:      \n"
                       "mflr 11         \n"
                       "subf 11,%0,11   \n"
                       "addi 11,11,48   \n"
                       "mtlr 11         \n"
                       "subf 14,%0,14   \n"
                       "mtevpr %1       \n"
                       "blr             \n"
 
"nop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop"
                       ::"r" (iJumpDistance),"r" (iNewEVPR):"11");

[...]
}

The __asm__ keyword is used to prevent name conflicts and the __volatile__
is used so that the compiler doesn't reorder your assembly code, but uses it
*exactly* as you wrote it.

The way we learned to do inline asm, was to read a really good tutorial on
the subject on:
http://www.geocities.com/SiliconValley/Ridge/2544/cprog/rmiyagi-inline-asm.t
xt

It is written for x86, but we had no trouble using the same ideas for ppc.

Best regards,
Jan





-----Original Message-----
From: Daniel Lidsten [mailto:Daniel.Lidsten@combitechsystems.com]
Sent: maandag 25 november 2002 16:44
To: crossgcc
Subject: Assembler in C


Hi, 

I have a very simple question. How do i compile some assembler into a
C-file.

The following doesnt work: (compile error due to the word: asm)

void AnyFunction()
{
	asm{		
		lwi	r0,0
		mtmsr   r0

		// Mask interrupt sources in the SIU
		lis	r2,0
		lwi	r3,CYGARC_REG_IMM_SIMASK
		stw	r2,0(r3)
	}
}

I have also tried some other alternativ like __asm__, but without
success.

When i search through the mailing list then i could find stuff like:
asm volatile("sbi PORTB,0x07;");

but as i dont want to convert all my assembler code then there must be a
way of compiling real assembler.

Regards, Daniel

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

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


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