/* * Get the CPU type. */ cpu_type_t cpu_type_get(void) { unsigned int eax, ebx, ecx, edx; int family, model, ext_model; cpu_type_t type = CPU_UNSUP; char vendor[16]; eax = 0; cpuid(&eax, &ebx, &ecx, &edx); (void) strncpy(&vendor[0], (char *)(&ebx), 4); (void) strncpy(&vendor[4], (char *)(&ecx), 4); (void) strncpy(&vendor[8], (char *)(&edx), 4); vendor[12] = 0; if (strncmp(vendor, "Genu" "ntel" "ineI", 12) != 0) { return (CPU_UNSUP); } eax = 1; cpuid(&eax, &ebx, &ecx, &edx); family = CPU_FAMILY(eax); model = CPU_MODEL(eax); ext_model = CPU_EXT_MODEL(eax); if (family == 6) { model = (ext_model << 4) + model; switch (model) { case 26: type = CPU_NHM_EP; break; case 44: type = CPU_WSM_EP; break; case 45: type = CPU_SNB_EP; break; case 46: type = CPU_NHM_EX; break; case 47: type = CPU_WSM_EX; break; case 62: type = CPU_IVB_EX; break; case 63: type = CPU_HSX; break; case 79: type = CPU_BDX; break; } } return (type); }
static void model_set (sim_cpu *cpu, const MODEL *model) { CPU_MACH (cpu) = MODEL_MACH (model); CPU_MODEL (cpu) = model; (* MACH_INIT_CPU (MODEL_MACH (model))) (cpu); (* MODEL_INIT (model)) (cpu); }
static SIM_RC sim_model_init (SIM_DESC sd) { SIM_CPU *cpu; /* If both cpu model and state architecture are set, ensure they're compatible. If only one is set, set the other. If neither are set, use the default model. STATE_ARCHITECTURE is the bfd_arch_info data for the selected "mach" (bfd terminology). */ /* Only check cpu 0. STATE_ARCHITECTURE is for that one only. */ /* ??? At present this only supports homogeneous multiprocessors. */ cpu = STATE_CPU (sd, 0); if (! STATE_ARCHITECTURE (sd) && ! CPU_MACH (cpu)) { /* Set the default model. */ const MODEL *model = sim_model_lookup (WITH_DEFAULT_MODEL); sim_model_set (sd, NULL, model); } if (STATE_ARCHITECTURE (sd) && CPU_MACH (cpu)) { if (strcmp (STATE_ARCHITECTURE (sd)->printable_name, MACH_BFD_NAME (CPU_MACH (cpu))) != 0) { sim_io_eprintf (sd, "invalid model `%s' for `%s'\n", MODEL_NAME (CPU_MODEL (cpu)), STATE_ARCHITECTURE (sd)->printable_name); return SIM_RC_FAIL; } } else if (STATE_ARCHITECTURE (sd)) { /* Use the default model for the selected machine. The default model is the first one in the list. */ const MACH *mach = sim_mach_lookup_bfd_name (STATE_ARCHITECTURE (sd)->printable_name); if (mach == NULL) { sim_io_eprintf (sd, "unsupported machine `%s'\n", STATE_ARCHITECTURE (sd)->printable_name); return SIM_RC_FAIL; } sim_model_set (sd, NULL, MACH_MODELS (mach)); } else { STATE_ARCHITECTURE (sd) = bfd_scan_arch (MACH_BFD_NAME (CPU_MACH (cpu))); } return SIM_RC_OK; }