#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libsys.h"

#define TEST_SIZE	32768
int main (void)
{
	int i;
	UINT16 *ram16;
	UINT32 sr;
	UINT32 volatile *pReg = (UINT32*)SYS_LED_PORT;

	*pReg = 0;

	sr = CP0_SR_read();

	ram16 = (UINT16*)calloc(TEST_SIZE/2,sizeof(UINT16));

	CP0_SR_write(sr | (1 << 25));

	for (i=0; i < TEST_SIZE/2; i++)
		ram16[i] = (UINT16)i;

	for (i=TEST_SIZE/2-1; i >= 0; i--)
		if (ram16[i] != (UINT16)i)
			break;

	i++;
	if (i)
		*pReg = 0xFFFFFFFF;
	else
		*pReg = 1;


	free(ram16);

	ram16 = (UINT16*)calloc(TEST_SIZE/2,sizeof(UINT16));

	*pReg = 0;
	CP0_SR_write(sr & ~(1 << 25));

	for (i=0; i < TEST_SIZE/2; i++)
		ram16[i] = (UINT16)i;

	for (i=TEST_SIZE/2-1; i >= 0; i--)
		if (ram16[i] != (UINT16)i)
			break;

	i++;
	if (i)
		*pReg = 0xFFFFFFFF;
	else
		*pReg = 1;


	free(ram16);


//	sputs("Status : ");print_word(sr);sputs("\n");

	return 0;
}

