Hi there,
this days I've been working on one project of mines involving an
AT91SAM7-S micro-controller, I'm actually using the GCC compiler I've
found in the yagarto toolpack, pre-compiled an just ready to use.
Invoking the compiler with --version I get the following output:
C:\Documents and Settings\Administrator>arm-elf-gcc --version
arm-elf-gcc (GCC) 4.4.2
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
I've got some really weird and bad trouble with my project and on
further investigation I discovered that I'm having some problem on
function calling. To make it clear I wrote a sample program that
reproduces the situation (and the problems) I've encountered in my
application, here it is the simple program:
1 | #include <stdlib.h>
|
2 | #include <stdio.h>
|
3 | #include <math.h>
|
4 | #include "AT91SAM7S256.h"
|
5 |
|
6 | struct BigDealStruct {
|
7 | unsigned int member0;
|
8 | unsigned char member1;
|
9 | long int member2;
|
10 | };
|
11 |
|
12 | static unsigned char (*function_ptr)(unsigned int, unsigned int, struct BigDealStruct);
|
13 | unsigned char my_function(unsigned int, unsigned int, struct BigDealStruct);
|
14 |
|
15 | void main()
|
16 | {
|
17 | function_ptr = my_function;
|
18 |
|
19 | unsigned int my_reg1 = 58;
|
20 | unsigned int my_reg2 = 34;
|
21 | struct BigDealStruct my_struct;
|
22 |
|
23 | function_ptr(my_reg1, my_reg2, my_struct);
|
24 |
|
25 | while(1);
|
26 | }
|
27 |
|
28 | unsigned char my_function(unsigned int arg0, unsigned int arg1, struct BigDealStruct arg3)
|
29 | {
|
30 | unsigned int dummy = arg0;
|
31 | }
|
The following are the values with which the function is being called
(the ones in the struct are random but who cares) and the values inside
the function. These have been retrieved with gdb.
Calling values:
- my_reg1 = 58
- my_reg2 = 34
- my_struct.member0 = 2099276
- my_struct.member1 = 76
- my_struct.member2 = 58
Inside-function values:
- arg1 = 2099276
- arg2 = 58
- arg3.member0 = 58
- arg3.member1 = 76
- arg3.member2 = 2099276
It's all messed up! But why?
I discovered that for the problem to occur a quite big amount of data to
be passed is needed, indeed removing one of the two unsigned int args
fixes the problem. Is it possible that arm calling conventions used by
GCC can't manage to pass a load of data like this or larger?
Can someone please try this out in its own platform and let me know if
he's getting the same problem as me?
Any help or advice would be really appreciated!