#include "libsys.h"

int uncached_cachemiss_bug(UINT32* pMem)
{
	UINT32 result;

	pMem[0] = 0x12345678;
	pMem[1] = 0xFFFFFFFF;

	DCACHE_invalidate_all();

	__asm__
	(
		"lui    $s0, 0xA000\n"
		"lw     $a0, 32($s0)\n"
		"or		$s1, $a0, $0\n"
		"or		$a2, $0, $0\n"
		"addiu	$a2, 1\n"
		"sw     $a2, 32($s0)\n"
//		"lw     $a1, 0(%[pMem])\n"
		"lw     $a0, 32($s0)\n"
		"lw     $a2, 4(%[pMem])\n"
		"lw     $a1, 0(%[pMem])\n"
		"nop\n"
		"sw     $s1, 8($s0)\n"
		"or		%[val], $a0, $0\n"
		: [val] "=r" (result)
		: [pMem] "r" (pMem)
		: "a0", "a1", "a2", "s0", "s1"
	);
	return result;
}

int main()
{
	UINT32 volatile *pLed = (UINT32*)SYS_LED_PORT;
	int buf[256], res;

	res = uncached_cachemiss_bug(buf);
	*pLed = res;

	return res;

}
