Thanks Ben and John. Semi-related, I re-read this page:
http://www.palmos.com/dev/support/docs/os5arm/PalmOS5ARM_Chapter.html
which describes my situation nicely (see the section on integer alignment).
A couple points I'll post to help others who may stumble across this...
* The URL above refers to a sample armlet app, and a file named "endianutils.h"
included in the Palm OS 5 SDK. Endianutils.h was nowhere to be seen, but I did find
the macros I was looking for in utils68k.h. Anybody at Palm reading this might want
to pass it along to your documentation team.
* Originally, on the ARM side, I was using a macro similar to EndianSwap32 to
translate 68k addresses (which were 16 bit aligned, not 32 bit aligned) to arm
addresses:
#define EndianSwap32(n) (((((unsigned long) n) << 24) & 0xFF000000) | \
((((unsigned long) n) << 8) & 0x00FF0000) | \
((((unsigned long) n) >> 8) & 0x0000FF00) | \
((((unsigned long) n) >> 24) & 0x000000FF))
What I should have been using is Read68KUnaligned32:
#define Read68KUnaligned32(addr) \
(((((unsigned char *)(addr))[0]) << 24) | \
((((unsigned char *)(addr))[1]) << 16) | \
((((unsigned char *)(addr))[2]) << 8) | \
((((unsigned char *)(addr))[3])))
This should access the 68k memory a byte at a time rather than 32 bits at a time, so
reading a 32 bit word on any 16-bit aligned boundary should work without crashing.
It's a little slower, but correct.
Ben, don't know which way you want to go with this. Might still be nice to provide
the #pragma, but in any event the arm side should be using Read68KUnaligned32 rather
than EndianSwap32 to protect itself from unaligned 68k callers... so using your
#pragma I'd be sacrificing cycles (to do the alignment on the 68k side) for nothing.
This was an educational thread for me, thanks.
Chris
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Ben
> Combee
> Sent: Wednesday, August 28, 2002 12:06 PM
> To: Palm Developer Forum
> Subject: Re: 4 byte alignment on stack variables?
>
>
>
> >If the current tools don't support this, it might be a very
> nice feature
> >to add to the prc/code warrior compilers ASAP as 5.0 devices
> start showing
> >up and people start writing armlets.
>
> This is a good suggestion... right now, I'm not sure of a way
> to get 4-byte
> alignment for stack variables in the 68K compiler, but I'll
> check with the
> Palm OS compiler engineer. I know you can get struct's to be 4-byte
> aligned using "#pragma align mac68k4byte", but I think that
> only affects
> internal alignment, not alignment on the stack.
>
> This is a good idea... I'll find about how difficult it will
> be to add
> something like
>
> #pragma align_stack NNN | reset
>
> for CW Palm OS V9. We've already done code like that in our
> x86 compiler
> -- its stack is usually 4-byte aligned, but it gets aligned
> to 8-bytes or
> 16-bytes when there are double, MMX, or SSE variables
> allocated on the
> stack. For the compiler, its just a matter of allocating an
> extra two
> bytes, setting the stack pointer, then ANDing it to get it aligned
> appropriately, at least when you're generating code with
> A6-based stack
> frames. If you don't have a frame pointer, doing the
> alignment is a bit
> trickier -- we'd probably just force the FP for "aligned"
> functions, same
> as how we force it for code that is in the path of a C++ exception.
>
> In the meantime, John Marshall's suggestion about doing a union and
> detecting the appropriate member is OK, and there are plenty of other
> work-arounds, as he mentioned.
>
> --
> Ben Combee <[EMAIL PROTECTED]>
> CodeWarrior for Palm OS technical lead
> Palm OS programming help @ www.palmoswerks.com
>
>
>
> --
> For information on using the Palm Developer Forums, or to
> unsubscribe, please see http://www.palmos.com/dev/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/