I am running xv6 via QEMU on Ubuntu 20.04.6 via Windows WSL. I wanted to write a syscall to extract and print the CPU vendor name by editing the kernel code. Did the usual pleasantries, wrote up a function that was successfully implemented as a syscall within xv6
I then edited the function to print the CPU vendor name, only to get the most perplexing of results
// within sysproc.c
#include "types.h"
#include "x86.h"
#include "defs.h"
#include "proc.h"
int sys_cpuvendor(void)
{
char *buf;
if(argptr(0, &buf, 13) < 0) //take a 13 element buffer to write the results into
return -1;
unsigned int ebx, ecx, edx;
asm volatile (
"mov $0, %%eax; n"
"cpuid; n"
"mov %%ebx, %0; n"
"mov %%edx, %1; n"
"mov %%ecx, %2; n"
: "=r"(ebx), "=r"(edx), "=r"(ecx)
:
: "%eax"
);
//run cpuid via asm magic and write the results into registers, and finally into buf
((unsigned int*)buf)[0] = ebx;
((unsigned int*)buf)[1] = edx;
((unsigned int*)buf)[2] = ecx;
buf[12] = '';
return 0;
}
Here is the program that uses the syscall
int main(void)
{
char vendBuf[255];
printf(1, "Printing device info with deviceInfo() call: ");
deviceInfo(vendBuf);
printf(1, "CPU Vendor Name: %sn", vendBuf);
exit();
}
Running this function and printing the buffer it writes to gives me a strange result. The output is Genuntelntel
, with the typo. The funny part is I am working on an AMD Ryzen machine? How and why did it get the CPU vendor wrong entirely, let alone the typo?