Modified cache-flush and added access-cache test.

This commit is contained in:
Allen 2018-07-09 12:07:12 +00:00
parent ac2b069106
commit d2cfb30899
2 changed files with 25 additions and 27 deletions

View File

@ -0,0 +1,11 @@
#include "trap.h"
int main() {
int round = 30;
static char arr[4 * 1024 * 1024];
for (int i = 0; i < round; i++)
arr[i * 64] = i;
for (int i = 0; i < round; i++)
nemu_assert(arr[i * 64] == (char)i);
return 0;
}

View File

@ -1,5 +1,4 @@
#include <am.h>
#include <klib.h>
#include "trap.h"
#define KB 1024
@ -16,41 +15,29 @@ int fast_rand(void) {
return g_seed;
}
#define _STR(x) #x
#define MFC0(dst, src, sel) \
asm volatile("mfc0 %0, $"_STR(src)", %1\n\t":"=r"(dst):"i"(sel))
#define MTC0(dst, src, sel) \
asm volatile("mtc0 %0, $"_STR(dst)", %1\n\t"::"r"(src),"i"(sel))
#define NOP() \
asm volatile("nop")
#define cp0_count 9
uint32_t inline GetCount(int sel){
uint32_t tick = 0;
if(sel == 0)
MFC0(tick, cp0_count, 0);
else if(sel == 1)
MFC0(tick, cp0_count, 1);
else
_halt(1);
return tick;
}
int main() {
fast_srand(0x12345678);
unsigned int steps = 1024;
static char arr[4 * 1024 * 1024];
static uint32_t arr[4 * MB];
int lengthMod;
int sizes[] = { 10 * KB };
int sizes[] = { 4 * MB };
int s;
for (int j = 0; j < 10; j++) {
for (s = 0; s < sizeof(sizes)/sizeof(int); s++) {
lengthMod = sizes[s] - 1;
for (unsigned int i = 0; i < steps; i++) {
arr[fast_rand() & lengthMod] += 10;
arr[fast_rand() & lengthMod] = fast_rand();
}
}
}
fast_srand(0x12345678);
for (int j = 0; j < 10; j++) {
for (s = 0; s < sizeof(sizes)/sizeof(int); s++) {
lengthMod = sizes[s] - 1;
for (unsigned int i = 0; i < steps; i++) {
nemu_assert(arr[fast_rand() & lengthMod] == fast_rand());
}
}
}