Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / August 2004



Tip: Looking for answers? Try searching our database.

CodeWarrior's inline assembler and the Mach-O PIC base

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mars Saxman - 23 Aug 2004 19:35 GMT
I am trying to modify an existing PEF-based threads library to work
under Mach-O. One critical function must be written in assembly
language, cannot use a conventional stack frame (it uses the nofralloc
directive), cannot modify any nonvolatile registers, and must load &
store the contents of two static variables.

I have updated the code that refers to static variables as follows:

   #if EXE_FORMAT_MACHO
       addis r4, r2, ha16(sCurrentThread)    // r2 == rPIC
       lwz r4, lo16(sCurrentThread)(r4)
   #else
       lwz r4, sCurrentThread
   #endif

Now I need to load the PIC base into r2. The instruction sequence is
simple enough:

bl next
next:
mflr r2

Here's the hangup: how do I tell CodeWarrior's linker that the label
'next' represents the PIC base, and that it should calculate my static
data references relative to that point? I have not found any special
name or assembler directive that does the trick.

Mars Saxman
REAL Software
MW Ron - 30 Aug 2004 20:26 GMT
>I am trying to modify an existing PEF-based threads library to work
>under Mach-O. One critical function must be written in assembly
[quoted text clipped - 22 lines]
>data references relative to that point? I have not found any special
>name or assembler directive that does the trick.

Hi,

Sorry for the delay in replying.  I was hoping someone could help, but
when no one did I asked one of our PowerPC engineers... he said.

I generally look to the runtime libraries for examples, in this case
there is an assembler directive: picbase which associates a picbase
register with it's label:

runtime.c: __cvt_fp2unsigned()

asm unsigned long __cvt_fp2unsigned(register double d)
{
#if __MACH__
             mflr    r0
             bcl      20,31,@1
@1            mflr    r4
             picbase r4,@1

             addis  r4,r4,ha16(__constants)
             la     r4,lo16(__constants)(r4)
// restore the link register (I moved down here as scheduling)
             mtlr    r0
#else
             entry   __uitrunc
             lwz           r4,__constants(RTOC)
#endif

It is important to use "bcl    30,31,@1" to avoid link register stack
delays which happen when using "bl" to compute the address of the next
instruction (code will run correctly but might be slower).

again my apology for the delay.

Ron

Signature

Metrowerks Community Forum is a free online resource for developers
to discuss CodeWarrior topics with other users and Metrowerks' staff
       --   http://www.metrowerks.com/community  --

Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.