diff --git a/src/config.c b/src/config.c index 574513e49..4ee5aeab2 100644 --- a/src/config.c +++ b/src/config.c @@ -546,7 +546,7 @@ load_machine(void) if (cpu_f && !cpu_family_is_eligible(cpu_f, machine)) /* only honor eligible families */ cpu_f = NULL; } else { - /* Backwards compatibility for the previous CPU model system. */ + /* Backwards compatibility with the previous CPU model system. */ legacy_mfg = config_get_int(cat, "cpu_manufacturer", 0); legacy_cpu = config_get_int(cat, "cpu", 0); if (legacy_mfg || legacy_cpu) { @@ -567,8 +567,12 @@ load_machine(void) legacy_table_entry = (cpu_legacy_table_t *) &cpu_legacy_table[c].tables[legacy_mfg][i]; if (legacy_cpu >= legacy_table_entry->old_offset) { /* Found CPU entry, set new values. */ + + if (!legacy_table_entry->family) /* reset to defaults if the CPU ID is beyond what is supported by the legacy table */ + break; + legacy_family = cpu_get_family((char *) legacy_table_entry->family); - if (!legacy_family || !cpu_family_is_eligible(legacy_family, machine)) /* check if the family exists and is eligible */ + if (!legacy_family || !cpu_family_is_eligible(legacy_family, machine)) /* check if the family exists and is eligible; if not, reset to defaults */ break; config_set_string(cat, "cpu_family", (char *) legacy_family->internal_name); cpu_f = legacy_family; @@ -585,7 +589,7 @@ load_machine(void) break; } } - if (new_cpu != -1) { /* store only if an eligible CPU was found */ + if (new_cpu != -1) { /* store only if an eligible CPU was found; if not, reset CPU (but not family) to defaults */ config_set_int(cat, "cpu_speed", legacy_family->cpus[new_cpu].rspeed); config_set_double(cat, "cpu_multi", legacy_family->cpus[new_cpu].multi); } @@ -603,18 +607,20 @@ load_machine(void) /* Find the configured CPU. */ cpu = 0; - i = -1; + c = 0; + i = 256; while (cpu_f->cpus[cpu].cpu_type != -1) { if (cpu_is_eligible(cpu_f, cpu, machine)) { /* skip ineligible CPUs */ - if (i == -1) /* store the first eligible CPU */ - i = cpu; if ((cpu_f->cpus[cpu].rspeed == speed) && (cpu_f->cpus[cpu].multi == multi)) /* check if clock speed and multiplier match */ break; + else if ((cpu_f->cpus[cpu].rspeed > speed) && (i == 256)) /* store closest matching faster CPU */ + i = cpu; + c = cpu; /* store fastest eligible CPU */ } cpu++; } - if (cpu_f->cpus[cpu].cpu_type == -1) /* use first eligible CPU if no match was found */ - cpu = MAX(i, 0); + if (cpu_f->cpus[cpu].cpu_type == -1) /* if no exact match was found, use closest matching faster CPU, or fastest eligible CPU */ + cpu = MIN(i, c); } else { /* default */ /* Find first eligible family. */ c = 0; @@ -1790,7 +1796,7 @@ save_machine(void) { char *cat = "Machine"; char *p; - int c, i, j, legacy_cpu = -1; + int c, i, j, old_offset_max, legacy_cpu = -1; p = machine_get_internal_name(); config_set_string(cat, "machine", p); @@ -1799,7 +1805,7 @@ save_machine(void) config_set_int(cat, "cpu_speed", cpu_f->cpus[cpu].rspeed); config_set_double(cat, "cpu_multi", cpu_f->cpus[cpu].multi); - /* Limited forwards compatibility for the previous CPU model system. */ + /* Limited forwards compatibility with the previous CPU model system. */ config_delete_var(cat, "cpu_manufacturer"); config_delete_var(cat, "cpu"); @@ -1817,20 +1823,23 @@ save_machine(void) if (!cpu_legacy_table[c].tables[j]) continue; + old_offset_max = 256; i = -1; do { i++; legacy_table_entry = (cpu_legacy_table_t *) &cpu_legacy_table[c].tables[j][i]; - if (!strcmp(legacy_table_entry->family, cpu_f->internal_name) && (cpu >= legacy_table_entry->new_offset)) { + if (legacy_table_entry->family && (cpu >= legacy_table_entry->new_offset) && !strcmp(legacy_table_entry->family, cpu_f->internal_name)) { /* Found CPU entry, set legacy values. */ if (j) config_set_int(cat, "cpu_manufacturer", j); legacy_cpu = cpu - legacy_table_entry->new_offset + legacy_table_entry->old_offset; + if (legacy_cpu >= old_offset_max) /* if the CPU ID is beyond what is supported by the legacy table, reset to the last supported ID */ + legacy_cpu = old_offset_max - 1; if (legacy_cpu) config_set_int(cat, "cpu", legacy_cpu); - break; } + old_offset_max = legacy_table_entry->old_offset; } while (cpu_legacy_table[c].tables[j][i].old_offset); } } diff --git a/src/cpu/cpu_table.c b/src/cpu/cpu_table.c index 8c17e5b72..a463302fb 100644 --- a/src/cpu/cpu_table.c +++ b/src/cpu/cpu_table.c @@ -958,54 +958,54 @@ cpu_family_t cpu_families[] = { } }; -static cpu_legacy_table_t cpus_8088[] = {{"8088", 0, 0}}; -#define cpus_pcjr cpus_8088 -static cpu_legacy_table_t cpus_europc[] = {{"8088_europc", 0, 0}}; -static cpu_legacy_table_t cpus_8086[] = {{"8086", 0, 0}}; -static cpu_legacy_table_t cpus_pc1512[] = {{"8086", 0, 1}}; -static cpu_legacy_table_t cpus_286[] = {{"286", 0, 0}}; -#define cpus_ibmat cpus_286 -#define cpus_ibmxt286 cpus_286 -static cpu_legacy_table_t cpus_ps1_m2011[] = {{"286", 0, 2}}; -#define cpus_ps2_m30_286 cpus_ps1_m2011 -static cpu_legacy_table_t cpus_i386SX[] = {{"i386sx", 0, 0}}; -static cpu_legacy_table_t cpus_i386DX[] = {{"rapidcad", 5, 0}, {"i386dx", 0, 0}}; -static cpu_legacy_table_t cpus_Am386SX[] = {{"am386sx", 0, 0}}; -static cpu_legacy_table_t cpus_Am386DX[] = {{"am386dx", 0, 0}}; -static cpu_legacy_table_t cpus_ALiM6117[] = {{"m6117", 0, 0}}; -static cpu_legacy_table_t cpus_486SLC[] = {{"cx486srx2", 3, 0}, {"cx486slc", 0, 0}}; -static cpu_legacy_table_t cpus_IBM486SLC[] = {{"ibm486slc3", 4, 0}, {"ibm486slc2", 1, 0}, {"ibm386slc", 0, 0}}; -static cpu_legacy_table_t cpus_IBM486BL[] = {{"ibm486bl3", 2, 0}, {"ibm486bl2", 0, 0}}; -static cpu_legacy_table_t cpus_486DLC[] = {{"cx486drx2", 3, 0}, {"cx486dlc", 0, 0}}; -static cpu_legacy_table_t cpus_i486S1[] = {{"idx4_od", 12, 0}, {"i486dx2", 9, 0}, {"i486dx", 6, 0}, {"i486sx2", 4, 0}, {"i486sx", 0, 0}}; -static cpu_legacy_table_t cpus_Am486S1[] = {{"am486dx2", 6, 0}, {"am486dx", 4, 0}, {"am486sx2", 2, 0}, {"am486sx", 0, 0}}; -static cpu_legacy_table_t cpus_Cx486S1[] = {{"cx486dx2", 5, 0}, {"cx486dx", 3, 0}, {"cx486s", 0, 0}}; -static cpu_legacy_table_t cpus_i486[] = {{"pentium_od_s3", 16, 0}, {"idx4_od", 14, 0}, {"idx4", 12, 0}, {"i486dx2", 9, 0}, {"i486dx", 6, 0}, {"i486sx2", 4, 0}, {"i486sx", 0, 0}}; -static cpu_legacy_table_t cpus_i486_PC330[] = {{"pentium_od_s3", 4, 0}, {"idx4", 2, 0}, {"i486dx2_pc330", 0, 0}}; -static cpu_legacy_table_t cpus_Am486[] = {{"am5x86", 13, 0}, {"am486dx4", 9, 0}, {"am486dx2", 6, 0}, {"am486dx", 4, 0}, {"am486sx2", 2, 0}, {"am486sx", 0, 0}}; -static cpu_legacy_table_t cpus_Cx486[] = {{"cx5x86", 10, 0}, {"cx486dx4", 8, 0}, {"cx486dx2", 5, 0}, {"cx486dx", 3, 0}, {"cx486s", 0, 0}}; -static cpu_legacy_table_t cpus_STPCDX[] = {{"stpc_dx", 0, 0}}; -static cpu_legacy_table_t cpus_STPCDX2[] = {{"stpc_dx2", 0, 0}}; -static cpu_legacy_table_t cpus_6x863V[] = {{"cx6x86", 0, 0}}; -static cpu_legacy_table_t cpus_6x86[] = {{"mii", 14, 0}, {"cx6x86mx", 10, 0}, {"cx6x86l", 6, 0}, {"cx6x86", 0, 0}}; -#define cpus_6x86SS7 cpus_6x86 -static cpu_legacy_table_t cpus_WinChip[] = {{"winchip2a", 15, 0}, {"winchip2", 11, 0}, {"winchip", 0, 0}}; -#define cpus_WinChip_SS7 cpus_WinChip -static cpu_legacy_table_t cpus_Pentium5V[] = {{"pentium_od_s4", 2, 1}, {"pentium_p5", 0, 1}}; -static cpu_legacy_table_t cpus_PentiumS5[] = {{"pentium_od_p55c", 10, 1}, {"pentium_od_s5", 7, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; -static cpu_legacy_table_t cpus_Pentium3V[] = {{"pentium_od_p55c", 13, 1}, {"pentium_od_s5", 10, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; -static cpu_legacy_table_t cpus_Pentium[] = {{"pentium_od_p55c", 24, 1}, {"pentium_od_s5", 21, 0}, {"pentium_tillamook", 13, 0}, {"pentium_p55c", 10, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; -static cpu_legacy_table_t cpus_K5[] = {{"k5_5k86", 6, 3}, {"k5_ssa5", 5, 2}, {"k5_5k86", 4, 2}, {"k5_ssa5", 3, 1}, {"k5_5k86", 2, 1}, {"k5_ssa5", 1, 0}, {"k5_5k86", 0, 0}}; -#define K6_ENTRIES {"k6_2", 18, 0}, {"k6_m7", 14, 0}, {"k6_m6", 11, 0} -static cpu_legacy_table_t cpus_K56[] = {K6_ENTRIES}; -static cpu_legacy_table_t cpus_K56_SS7[] = {{"k6_3p", 38, 0}, {"k6_3", 36, 0}, {"k6_2p", 31, 0}, K6_ENTRIES}; -static cpu_legacy_table_t cpus_PentiumPro[] = {{"pentium2_od", 8, 0}, {"pentiumpro", 0, 0}}; -static cpu_legacy_table_t cpus_PentiumII66[] = {{"pentium2_deschutes", 7, 0}, {"pentium2_klamath", 0, 0}}; -#define cpus_PentiumII cpus_PentiumII66 -static cpu_legacy_table_t cpus_Xeon[] = {{"pentium2_xeon", 0, 0}}; -static cpu_legacy_table_t cpus_Celeron[] = {{"celeron_mendocino", 0, 0}}; -static cpu_legacy_table_t cpus_PentiumIID[] = {{"pentium2_deschutes", 0, 0}}; -static cpu_legacy_table_t cpus_Cyrix3[] = {{"c3_samuel", 0, 0}}; +static cpu_legacy_table_t cpus_8088[] = {{NULL, 6}, {"8088", 0, 0}}; +static cpu_legacy_table_t cpus_pcjr[] = {{NULL, 1}, {"8088", 0, 0}}; +static cpu_legacy_table_t cpus_europc[] = {{NULL, 3}, {"8088_europc", 0, 0}}; +static cpu_legacy_table_t cpus_8086[] = {{NULL, 6}, {"8086", 0, 0}}; +static cpu_legacy_table_t cpus_pc1512[] = {{NULL, 1}, {"8086", 0, 1}}; +static cpu_legacy_table_t cpus_286[] = {{NULL, 7}, {"286", 0, 0}}; +static cpu_legacy_table_t cpus_ibmat[] = {{NULL, 2}, {"286", 0, 0}}; +static cpu_legacy_table_t cpus_ibmxt286[] = {{NULL, 1}, {"286", 0, 0}}; +static cpu_legacy_table_t cpus_ps1_m2011[] = {{NULL, 1}, {"286", 0, 2}}; +static cpu_legacy_table_t cpus_ps2_m30_286[] = {{NULL, 5}, {"286", 0, 2}}; +static cpu_legacy_table_t cpus_i386SX[] = {{NULL, 5}, {"i386sx", 0, 0}}; +static cpu_legacy_table_t cpus_i386DX[] = {{NULL, 8}, {"rapidcad", 5, 0}, {"i386dx", 0, 0}}; +static cpu_legacy_table_t cpus_Am386SX[] = {{NULL, 5}, {"am386sx", 0, 0}}; +static cpu_legacy_table_t cpus_Am386DX[] = {{NULL, 3}, {"am386dx", 0, 0}}; +static cpu_legacy_table_t cpus_ALiM6117[] = {{NULL, 2}, {"m6117", 0, 0}}; +static cpu_legacy_table_t cpus_486SLC[] = {{NULL, 6}, {"cx486srx2", 3, 0}, {"cx486slc", 0, 0}}; +static cpu_legacy_table_t cpus_IBM486SLC[] = {{NULL, 7}, {"ibm486slc3", 4, 0}, {"ibm486slc2", 1, 0}, {"ibm386slc", 0, 0}}; +static cpu_legacy_table_t cpus_IBM486BL[] = {{NULL, 4}, {"ibm486bl3", 2, 0}, {"ibm486bl2", 0, 0}}; +static cpu_legacy_table_t cpus_486DLC[] = {{NULL, 7}, {"cx486drx2", 3, 0}, {"cx486dlc", 0, 0}}; +static cpu_legacy_table_t cpus_i486S1[] = {{NULL, 14}, {"idx4_od", 12, 0}, {"i486dx2", 9, 0}, {"i486dx", 6, 0}, {"i486sx2", 4, 0}, {"i486sx", 0, 0}}; +static cpu_legacy_table_t cpus_Am486S1[] = {{NULL, 9}, {"am486dx2", 6, 0}, {"am486dx", 4, 0}, {"am486sx2", 2, 0}, {"am486sx", 0, 0}}; +static cpu_legacy_table_t cpus_Cx486S1[] = {{NULL, 8}, {"cx486dx2", 5, 0}, {"cx486dx", 3, 0}, {"cx486s", 0, 0}}; +static cpu_legacy_table_t cpus_i486[] = {{NULL, 18}, {"pentium_od_s3", 16, 0}, {"idx4_od", 14, 0}, {"idx4", 12, 0}, {"i486dx2", 9, 0}, {"i486dx", 6, 0}, {"i486sx2", 4, 0}, {"i486sx", 0, 0}}; +static cpu_legacy_table_t cpus_i486_PC330[] = {{NULL, 6}, {"pentium_od_s3", 4, 0}, {"idx4", 2, 0}, {"i486dx2_pc330", 0, 0}}; +static cpu_legacy_table_t cpus_Am486[] = {{NULL, 16}, {"am5x86", 13, 0}, {"am486dx4", 9, 0}, {"am486dx2", 6, 0}, {"am486dx", 4, 0}, {"am486sx2", 2, 0}, {"am486sx", 0, 0}}; +static cpu_legacy_table_t cpus_Cx486[] = {{NULL, 14}, {"cx5x86", 10, 0}, {"cx486dx4", 8, 0}, {"cx486dx2", 5, 0}, {"cx486dx", 3, 0}, {"cx486s", 0, 0}}; +static cpu_legacy_table_t cpus_STPCDX[] = {{NULL, 2}, {"stpc_dx", 0, 0}}; +static cpu_legacy_table_t cpus_STPCDX2[] = {{NULL, 1}, {"stpc_dx2", 0, 0}}; +static cpu_legacy_table_t cpus_6x863V[] = {{NULL, 6}, {"cx6x86", 0, 0}}; +static cpu_legacy_table_t cpus_6x86[] = {{NULL, 16}, {"mii", 14, 0}, {"cx6x86mx", 10, 0}, {"cx6x86l", 6, 0}, {"cx6x86", 0, 0}}; +static cpu_legacy_table_t cpus_6x86SS7[] = {{NULL, 19}, {"mii", 14, 0}, {"cx6x86mx", 10, 0}, {"cx6x86l", 6, 0}, {"cx6x86", 0, 0}}; +static cpu_legacy_table_t cpus_WinChip[] = {{NULL, 17}, {"winchip2a", 15, 0}, {"winchip2", 11, 0}, {"winchip", 0, 0}}; +static cpu_legacy_table_t cpus_WinChip_SS7[] = {{NULL, 19}, {"winchip2a", 15, 0}, {"winchip2", 11, 0}, {"winchip", 0, 0}}; +static cpu_legacy_table_t cpus_Pentium5V[] = {{NULL, 4}, {"pentium_od_s4", 2, 1}, {"pentium_p5", 0, 1}}; +static cpu_legacy_table_t cpus_PentiumS5[] = {{NULL, 15}, {"pentium_od_p55c", 10, 1}, {"pentium_od_s5", 7, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; +static cpu_legacy_table_t cpus_Pentium3V[] = {{NULL, 18}, {"pentium_od_p55c", 13, 1}, {"pentium_od_s5", 10, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; +static cpu_legacy_table_t cpus_Pentium[] = {{NULL, 29}, {"pentium_od_p55c", 24, 1}, {"pentium_od_s5", 21, 0}, {"pentium_tillamook", 13, 0}, {"pentium_p55c", 10, 0}, {"pentium_p54c", 2, 1}, {"pentium_od_p55c", 1, 0}, {"pentium_p54c", 0, 0}}; +static cpu_legacy_table_t cpus_K5[] = {{NULL, 11}, {"k5_5k86", 6, 3}, {"k5_ssa5", 5, 2}, {"k5_5k86", 4, 2}, {"k5_ssa5", 3, 1}, {"k5_5k86", 2, 1}, {"k5_ssa5", 1, 0}, {"k5_5k86", 0, 0}}; +#define K6_ENTRIES {"k6_2", 7, 0}, {"k6_m7", 3, 0}, {"k6_m6", 0, 0} +static cpu_legacy_table_t cpus_K56[] = {{NULL, 11}, K6_ENTRIES}; +static cpu_legacy_table_t cpus_K56_SS7[] = {{NULL, 43}, {"k6_3p", 38, 0}, {"k6_3", 36, 0}, {"k6_2p", 31, 0}, K6_ENTRIES}; +static cpu_legacy_table_t cpus_PentiumPro[] = {{NULL, 20}, {"pentium2_od", 8, 0}, {"pentiumpro", 0, 0}}; +static cpu_legacy_table_t cpus_PentiumII66[] = {{NULL, 14}, {"pentium2_deschutes", 7, 0}, {"pentium2_klamath", 0, 0}}; +static cpu_legacy_table_t cpus_PentiumII[] = {{NULL, 17}, {"pentium2_deschutes", 7, 0}, {"pentium2_klamath", 0, 0}}; +static cpu_legacy_table_t cpus_Xeon[] = {{NULL, 6}, {"pentium2_xeon", 0, 0}}; +static cpu_legacy_table_t cpus_Celeron[] = {{NULL, 12}, {"celeron_mendocino", 0, 0}}; +static cpu_legacy_table_t cpus_PentiumIID[] = {{NULL, 10}, {"pentium2_deschutes", 0, 0}}; +static cpu_legacy_table_t cpus_Cyrix3[] = {{NULL, 13}, {"c3_samuel", 0, 0}}; cpu_legacy_machine_t cpu_legacy_table[] = { {"ibmpc", {cpus_8088}},