Notices


Reply
Thread Tools
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#11
Hi Serge,

If you tell me the compiler directives to force stuff to be aligned, I'll try adding them in to (hopefully) the appropriate places.

Thanks!
 
Posts: 503 | Thanked: 267 times | Joined on Jul 2006 @ Helsinki
#12
Originally Posted by mlvj
If you tell me the compiler directives to force stuff to be aligned, I'll try adding them in to (hopefully) the appropriate places.
All the stuff should be already properly aligned by the compiler. But you can get into a trouble if using pointers conversion though, such as '*(int *)(buffer + 1)' in the example below. Modern compilers can warn about suspicious pointers conversion with -Wall option. Also beware of packed structs on ARM, there are two pitfalls: first is the alignment of data members, the second is the size of struct itself.

Here is the example of code you can experiment with to see these pitfalls:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>

#pragma pack(1)
typedef struct s
{
    char x;
    int y;
} S;
#pragma pack()

int main()
{
    int i;
    char *buffer = (char *)malloc(16);
    for (i = 0; i < 16; i++) buffer[i] = i;

    printf("reading unaligned value from the buffer at offset 1: %08X\n", 
        *(int *)(buffer + 1));
    printf("offsetof(S, y)=%d\n", offsetof(S, y));
    printf("sizeof(S)=%d\n", sizeof(S));

    free(buffer);
    return 0;
}
On x86 it prints:
Code:
reading unaligned value from the buffer at offset 1: 04030201
offsetof(S, y)=1
sizeof(S)=5
On arm (and also when run with qemu) the results will be different.
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#13
Problem is - the whole programme that I'm porting very much depends on tight structure packing - so have to have pack(1) most of the time.

I'll see if adding pack() at strategic places helps.
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#14
hmm... no luck with pack(4). I have to say - I AM a bit rusty with the old c and pointers malarky. I have some fuzzy thinking in my brain after a long day's work and drive. And kids keeping me awake at night! Enough excuses.

Right, looking at a suspicious bit of code now. Here we go:

i8 *STScreen;
ui16 *scr = (ui16*) (STScreen + 160*y0 + LineStart);

/* Read the four ST planes. */
ui16 _one = *(scr++); ui16 four = GUINT16_FROM_BE(_one);
ui16 _two = *(scr++); ui16 three = GUINT16_FROM_BE(_two);
ui16 _three=*(scr++); ui16 two = GUINT16_FROM_BE(_three);
ui16 _four= *(scr++); ui16 one = GUINT16_FROM_BE(_four);

So... do you reckon that *(scr++) is behaving differently on the arm box than on the i86? e.g. *(scr++) is jumping too many or too few bytes forward I guess.

If so, could you recommend a replacement?
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#15
hmm ok so using gdb on that portion of code shows scr incrementing by two bytes each line. So I guess that bit is ok at least.

Time to get a debug build on the local box and step through that at same time as on 770
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#16
Got to what appears to be the critical line with a difference between i86 and 770.

And yes it is a pointer operation.

Time to figure out that it's definitely that, then fix it.

By the way, sound doesn't work at the moment, but the main thing would be to get the main functionality going.

I reckon.
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#17
Right nearly there.

The problem seems to be that a variable:

char somedata [] = {
0x00. 0x01. etc };

...is not aligned on a four byte boundary.

I've tried sticking

#pragma pack(4)

in front of the line, but the thing still doesn't align.

I don't want to stick padding bytes there (nasty idea).

Anyone suggest the right approach, given that I'm porting and I don't want to change the code that assumes it's aligned on a four byte boundary?

Thanks!
 
Posts: 503 | Thanked: 267 times | Joined on Jul 2006 @ Helsinki
#18
char __attribute__ ((aligned(4))) somedata [] = {
0x00. 0x01. etc };
 
Posts: 105 | Thanked: 1 time | Joined on Feb 2006
#19
This is the answer:

char somedata [] __attribute__((aligned (4))) = {
.......
};

Anyone want the raw binaries, or wait for debs (which may be a little while!)
 
Posts: 319 | Thanked: 6 times | Joined on Apr 2006
#20
Originally Posted by mlvj
This is the answer:

char somedata [] __attribute__((aligned (4))) = {
.......
};

Anyone want the raw binaries, or wait for debs (which may be a little while!)
hmm... I think I'll wait for the deb. While I want to play this game, I don't want to be the first person on the beta block.
 
Reply


 
Forum Jump


All times are GMT. The time now is 14:03.