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

UINT32 tset(UINT32 *pMem)
{

	__asm__
	(
		".set	noreorder\n"
		".set	nomacro\n"
		"addiu  $t1, $0, 0x5555\n"
		"lw     $t0, 0(%[pMem])\n"
		"sw     $t1, 24(%[pMem])\n"
		"addiu	$t0, 8\n"
		"sw     $t0, 0(%[pMem])\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"nop\n"
		"lw     $v0, 24(%[pMem])\n"
		".set	macro\n"
		".set	reorder\n"
		:
		: [pMem] "r" (pMem)
		: "t0", "t1"
	);
}

int main(void)
{
	int i;
	volatile int *pLED = (int*)SYS_LED_PORT;
	UINT64 *pBuf64;
	UINT32 *pPtr;

	pBuf64 = (UINT64*)0x4000FC80; //malloc(1024*sizeof(UINT32));

	pPtr = (UINT32*)pBuf64;

	for(i=0; i < 1024; i++)
		*pPtr++ = i;

	pPtr = (UINT32*)pBuf64;
	sputs("Ptr: "); print_word((int)pPtr); sputs("\n");
	DCACHE_invalidate_all();


	*pLED = tset(pPtr);

	return 0;
}
