the folowing simple code snippet does a dawn-compatible loop (64 bit big endian subleq cpu cycle).
Code: Select all
unsigned long emulalproc(unsigned long eip){
for(unsigned int w=0;w<4096;w++){ // doing actually only 32 bit. makes no sense to do long long in a 32 bit arm binary. this limits the maximum ram to 3,9 gbyte.
unsigned int * utasitaskezd=(unsigned int*)&RAM[eip];
unsigned int A=bswap32(utasitaskezd[1]);
unsigned int B=bswap32(utasitaskezd[3]);
long long B_ertek=bswap64(*(unsigned long long*)&RAM[B])-bswap64(*(unsigned long long*)&RAM[A]);
if(B_ertek<=0){
eip=bswap32(utasitaskezd[5]);
}else{
eip+=24;
}
*(long long*)&RAM[B]=bswap64(B_ertek);
// you may do more than one emulation cycle here, or you may use other optimization tricks.
// i dont know arm, so i will not do any spectacular here. you may do arm assembly (so you also can have big endian).
}
return eip;
}
bswap64 on x86 is defined to __bswap_64 and on arm its __builtin_bswap64.
bswap32 on x86 is defined to __bswap_32 and on arm its __builtin_bswap32.
the format of the internal bit representation is big endian:
64 63 62 61 (........ ) 4 3 2 1
on x86 windows / linux, when compiled with gcc, the code is fine.
however when i attempt to run the code on arm (android and gcc), i get crash.
-i dont know, when or why i get the crash, as i cant do printf on android (maybe i will try sprintf later to log into a file to see what is going on)
-arm is biendian cpu, but its in little endian mode by default for sure (i checked the defines to see if its little endian for sure)
-i am started to worry of arm gcc's 64 bit integer representation is messed up, and the built in bswap64 will convert it to some different format. is this possible?
-or it is possible that 32 bit arm gcc will not work with 64 bit numbers when comparing due to an old compiler glitch that has been fixed since eons (but can still exist on arm)?
-or do i overlook something complitely different with the arm architecture?