[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MiNT] [GCC] volatile and -O2
Hi list,
I have a pb in gemlib with GCC when the optimisation flag is set (-O2).
Here is a sample. just type
$ gcc -o test.tos test.c
to build it. You don't have to link gemlib.
<code>
#include <stdio.h>
typedef struct
{
short *control;
short *global;
const short *intin;
short *intout;
const long *addrin;
long *addrout;
} AESPB;
static inline void
_aes_trap (AESPB * aespb)
{
__asm__ volatile ("
move.l %0, d1; | &aespb
move.w #200,d0;
trap #2;
"
:
: "a"(aespb)
: "d0","d1"
);
}
static short
mt_appl_init(short *global_aes)
{
static short aes_control[5]={10,0,1,0,0};
short aes_intin[16];
#if USE_VOLATILE
volatile
#endif
short aes_intout[16];
long aes_addrin[16];
#if USE_VOLATILE
volatile
#endif
long aes_addrout[16];
AESPB aes_params;
aes_params.control = &aes_control[0];
aes_params.global = &global_aes[0];
aes_params.intin = &aes_intin[0];
#if USE_VOLATILE
(volatile short*)
#endif
aes_params.intout = aes_intout;
aes_params.addrin = &aes_addrin[0];
#if USE_VOLATILE
(volatile long *)
#endif
aes_params.addrout = aes_addrout;
/* clear some variable that may be used to check if an AES is
loaded */
global_aes[0] = 0; /* AES version number */
global_aes[2] = -1; /* AES application ID */
aes_intout[0] = -1; /* AES application ID */
_aes_trap(&aes_params);
return aes_intout[0];
}
int main( void) {
int i, appid;
short aes_global[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
appid = mt_appl_init(aes_global);
printf("\nUSE_VOLATILE "
#if USE_VOLATILE
"is defined = 1"
#else
"is not defined"
#endif
"\n");
printf("mt_appl_init() return %d\n",appid);
for (i=0; i<16; i++)
printf("aes_global[%2d] = %d\n",i,aes_global[i]);
return 0;
}
<code>
The problem is in the following lines:
aes_intout[0] = -1; /* AES application ID */
_aes_trap(&aes_params);
return aes_intout[0];
If optimisation is set (-O2), this function always returns -1.
If i remove the optimisation flag, or add the "volatile" keyword before
intout (compile the example above with -DUSE_VOLATILE=1), all works fine.
How can i tell GCC that the function _aes_trap() may touch aes_intout ?
Is it a GCC 2.95.3 bug, or a pb in the C code above.
best regards,
Arnaud.