I would like to do some testing on cache for my x86 IA32 Intel CPU.
Referred the below document, due to poor coding in assembly and new to cache concepts, I could not proceed the cache testing.
I would like to enable the cache, invalidate, writeback, writethrough and cache disable.
Can you please help me with inline C assembly code ?
I come across some asm instruction, clflush, wbinvd... not sure when to use and how to use.
Also how can I verify the cache enable/disable/invalidate/writeback functions.
Saw this post, but it seems x86 64bit. Lot of assembly instruction is not matched.
enable/disable cache on intel 64bit machine: CD bit always set?
int cache_test(int opt) {
unsigned int cr0;
switch(opt) {
case 0:
__asm__ volatile(
"pushl %%eax\n\t"
"movl %%cr0,%%eax\n\t"
"orl $0x60000000,%%eax\n\t"
"movl %%eax,%%cr0\n\t"
"movl %%cr0, %0\n\t"
"wbinvd\n\t"
"popl %%eax"
: "=r"(cr0)
:
:);
printf("printf: disable cache cr0 0x%x\n", cr0);
break;
case 1:
__asm__ volatile(
"pushl %%eax\n\t"
"movl %%cr0,%%eax\n\t"
"andl $0x9fffffff,%%eax\n\t"
"movl %%eax,%%cr0\n\t"
"movl %%cr0, %0\n\t"
"popl %%eax"
: "=r"(cr0)
:
:);
printf("printf: enable cache; cr0 0x%x\n", cr0);
break;
case 2:
__asm__ volatile(
"pushl %%eax\n\t"
"movl %%cr0, %%eax\n\t"
"movl %%eax, %0\n\t"
"popl %%eax"
: "=r"(cr0)
:
:);
printf("printf: XENMEM_show_cache_status cro value is 0x%x\n", cr0);
return (long)cr0;
}
return cr0;
}
Ported the code to 32bit IA CPU. Is this okay to enable and disable the cache ?
Thanks for the help.