#include "../include/cpu.h"
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
EFI_STATUS bp_cpu_fill_cpu_info(bp_cpu_CPU_INFO* cpu_info) {
  UINT32 Eax,Ebx,Ecx,Edx;
  AsmCpuid(0,&Eax,&Ebx,&Ecx,&Edx);
  *(UINT32 *)&cpu_info->vendor[0]=Ebx;
  *(UINT32 *)&cpu_info->vendor[4]=Edx;
  *(UINT32 *)&cpu_info->vendor[8]=Ecx;
  cpu_info->vendor[12]='\0';
  cpu_info->max_cpuid_level=Eax;
  AsmCpuid(1,&Eax,&Ebx,&Ecx,&Edx);
  cpu_info->stepping=Eax&0xF;
  cpu_info->model=(Eax>>4)&0xF;
  cpu_info->family=(Eax>>8)&0xF;
  cpu_info->ext_model=(Eax>>16)&0xF;
  cpu_info->ext_family=(Eax>>20)&0xFF;
  cpu_info->display_family=cpu_info->family+(cpu_info->family==0xF?cpu_info->ext_family:0);
  cpu_info->display_model=cpu_info->family+((cpu_info->family==0x6||cpu_info->family==0xF)?(cpu_info->ext_model<<4):0);
  for (INTN i=0;i<32;i++) {
    cpu_info->ecx_bin[i]=(Ecx&(1<<(31-i)))?L'1':L'0';
  }
  cpu_info->ecx_bin[32]=L'\0';
  for (INTN i=0;i<32;i++) {
    cpu_info->edx_bin[i]=(Edx&(1<<(31-i)))?L'1':L'0';
  }
  cpu_info->edx_bin[32]=L'\0';
  return 0;
}
