Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cacheid.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ int main(){
* EAX, bits 07-05
* Starts at 1
*/
long int level = (eax & ~(~0 << 3) << 5) >> 5;
unsigned long level = (eax & ~(~0ul << 3) << 5) >> 5;
printf("\n-- Level: %lu ", level);

/*
* Cache type
* EAX, bits 04-00
*/
long int type = (eax & ~(~0 << 4) << 0) >> 0;
unsigned long type = (eax & ~(~0ul << 4) << 0) >> 0;
switch(type){
case 1:
printf("(data cache)\n");
Expand Down Expand Up @@ -91,23 +91,23 @@ int main(){
* EBX, bits 11-00
* Add one to the return value to get the result.
*/
long int line_size = (ebx & ~(~0 << 12) << 0) >> 0;
unsigned long line_size = (ebx & ~(~0ul << 12) << 0) >> 0;
printf("Line size: %lu\n", line_size+1);

/*
* Ways of associativity
* EBX, bits 31-22
* Add one to the return value to get the result.
*/
long int ways = (ebx & ~(~0 << 10) << 22) >> 22;
unsigned long ways = (ebx & ~(~0ul << 10) << 22) >> 22;
printf("Number of ways: %lu\n", ways+1);

/*
* Number of sets
* ECX, bits 31-22
* Add one to the return value to get the result.
*/
long int sets = (ecx & ~(~0 << 31) << 0) >> 0;
unsigned long sets = (ecx & ~(~0ul << 31) << 0) >> 0;
printf("Number of sets: %lu\n", sets+1);

/* Raw results */
Expand Down