I've knocked together a quick function to get the CPU vendor using the CPUID instruction, but a few things about it are a bit strange.
Edit: I don't want the function its self to print the vendor string, I want to return the vendor string so I'm able to print myself elsewhere, that's why the function is as such.
Here's the function:
Code: Select all
char *getCPUVendor(char *rtn)
{
asm(
".intel_syntax noprefix;"
"mov eax,0;"
"cpuid;"
"mov [%0],ebx;"
"mov [%0+4],edx;"
"mov [%0+8],ecx;"
"movb [%0+12],0;"
".att_syntax;" : "=r" (rtn)
);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//int t;
//for (t = 0; t< 13;t++){
// printCharacter(*(rtn+t));
//}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return rtn;
}
Code: Select all
#include <screen.h>
#include <cpuid.h>
void kmain( void* mbd, unsigned int magic )
{
initScreen();
char vendor[13];
char *ptr = vendor;
ptr = getCPUVendor(ptr);
printString("SEPARATOR");
printString(ptr);
for(;;);
}
I cannot understand why that section in the getCPUVendor() function makes a difference.
Here's the printString() and printCharacter() functions.
Code: Select all
void printCharacter(unsigned char character)
{
if (character == '\b'){
if (pos_x != 0){
pos_x--;
}
}else if (character == '\t'){
pos_x = (pos_x + 8) & ~(8 - 1);
}else if (character == '\r'){
pos_x = 0;
}else if (character == '\n'){
pos_y++;
}else if (character == '\a'){
}else{
short offset = calculateOffset(pos_x,pos_y);
unsigned short output = constructOutputShort(character);
buffer[offset] = output;
pos_x++;
}
scroll();
}
void printString(const char *string)
{
int stringLength = strlen(string);
const char *strPointer = (const char *)string;
for(; stringLength > 0; stringLength--){
printCharacter(*strPointer++);
}
}
Cheers,
Puff
P.S. I know I'm asking a lot of questions on this forum, but every answer I get really helps me learn. Thank You all very much!