I would like to do some testing on cache for my x86 IA32 Intel CPU.
Referred to the below document, am newbie to coding in assembly and also new to cache concepts, so I am in need of help for the same.
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.
Went through the following post and it seems to be x86 64bit. Most of assembly instructions are 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 looks good to enable and disable the cache ?