/* test mixed integer and char operations on the Hades MIPS processors. * * 04.04.06 fnh * * Note that the compiler will use load-byte and store-byte instructions, * which means that the endianness of the processor matters. * Our gcc x86-x86-mips-elf (2.7.2.3) crosscompiler uses little-endian * memory accesses, and the MIPS must be configured correspondingly. * * When successful, the program writes an array of 256 chars (bytes) * with values 00,01,02,...,fe,ff starting at memory address 0x*400 * (Hades MipsRAM internal address 0x00100), and a second array of * 256 bytes with values 03,04,05,...,fe,ff,00,01,02 starting at * memory address 0x*600 (internal address 0x00150). * The program then tries to read the first array back and checks * the values. If successful, the program writes the magic value * 0xcafe0000 into memory address 0x*3ff (0x000ff) and enters an endless * loop. * When the read-back values don't match, the program writes the value * 0xdead0000 and enters an endless loop. */ #define BASE 0x00000400 #define OK (BASE- 8) #define BAD (BASE- 12) static char* hello = "Hello, world!\n\f"; void bad( int c ) { int i, *bad; bad= (int*) BAD; *(bad-1) = 0xdead0000 + c; for( i=0; ; i++ ) { *bad= i; } } int main( int argc, char** argv ) { char c, d; char *ptr, *ptr2; int *ready; int i,j; ptr = (char*) (BASE-32); *ptr = 'a'; *(ptr+1) = 'b'; *(ptr+2) = 'c'; *(ptr+3) = 'd'; // *(ptr+4) = 'e'; *(ptr+5) = 'f'; d = *(ptr+3); ready = (int*) OK; *(ready-12) = 0xbabe0000 | d; *(ready-11) = 0x000a1234 | d; ptr = (char*) BASE; ptr2 = (char*) (BASE+256+64); // write sequence of ASCII chars c = (char) 1; for( i=0; i < 256; i++ ) { c = (char) i; d = (char) (i+3); *(ptr+i) = c; *ptr2 = d; ptr2++; } // read them back and compare ptr = (char*) BASE; for( i=0; i < 256; i++ ) { c = (*ptr); if (c != (char)i) { bad( i ); } ptr++; } // success: endless loop *(ready+1) = 0xcafe0000; for( i=0; ; i++ ) { *ready = i; } }