views:

95

answers:

2

I've downloaded HD Photo Device Porting Kit 1.0 and successfully compiled and executed it on x86 PC.

I want to port the image viewer program to ARM-based Windows Mobile Smartphone, but there is some missing ARM code.

First, no "/image/x86/x86.h" equivalent header file for ARM. But the file is very simple, so I copied and renamed it to "arm.h" and successfully compiled and linked the source code.

But at runtime, DWORD alignment exception occurrs. I found that on ARM build, it seems that ARMOPT_BITIO should be declared for properly aligned read & write. But with ARMOPT_BITIO, some IO functions are missing, e. g. peekBits, getBits, flushToByte, flushBits.

I copied x86 version of these functions (peekBit16, flushBit16, etc), but no luck, it does not work (I've got a stack overflow error).

I can't debug the complex HD Photo source files. Please let me know where can I find the missing ARM code.

Any help would be much appreciated. Thanks!

+1  A: 

Based on my experience of porting some Microsoft code to ARM Linux, I do not think there is an easy way around it, unless someone has ported it already. You'll have to dive into this sort of low-level debugging.

Bugs I encountered were mainly related to unaligned access, and missing platform API calls. Also incorrect preprocessor checks resulted in code thinking it's running on big-endian platform.

The method I found useful to debug in such scenario is to build the code for the target platform and for the platform where it's known to work, and debug/trace these builds in parallel using a number of use cases. This will catch the most severe bugs.

Alex B
A: 

Thank you for advice.

I precisely looked at the I/O code and found that only load4BE and _load4 functions are used to read from memory.

So I changed the 4-byte oneshot read to 2-byte twice read. and undeclared ARMOPT_BITIO again, then it worked.

In fact, there was already 2-byte twice read code with conditional #ifdef. I just changed the condition.

original code:

#ifdef _M_IA64
    U32  v;
    v = ((U16 *) pv)[0];
    v |= ((U32)((U16 *) pv)[1]) << 16;
    return _byteswap_ulong(v);           <-- ok
#else // _M_IA64
    return _byteswap_ulong(*(U32*)pv);   <-- exception on ARM
#endif // _M_IA64
shkim
This is not an answer - should be a comment to the other answer I guess.
martinwguy