1 // MPTable generation (on emulators)
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2006 Fabrice Bellard
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "util.h" // dprintf
9 #include "memmap.h" // bios_table_cur_addr
10 #include "config.h" // CONFIG_*
11 #include "mptable.h" // MPTABLE_SIGNATURE
19 dprintf(3, "init MPTable\n");
21 int smp_cpus = smp_probe();
23 // Building an mptable on uniprocessor machines confuses some OSes.
26 u32 start = ALIGN(bios_table_cur_addr, 16);
27 int length = (sizeof(struct mptable_floating_s)
28 + sizeof(struct mptable_config_s)
29 + sizeof(struct mpt_cpu) * smp_cpus
30 + sizeof(struct mpt_bus)
31 + sizeof(struct mpt_ioapic)
32 + sizeof(struct mpt_intsrc) * 16);
33 if (start + length > bios_table_end_addr) {
34 dprintf(1, "No room for MPTABLE!\n");
37 bios_table_cur_addr = start + length;
39 /* floating pointer structure */
40 struct mptable_floating_s *floating = (void*)start;
41 memset(floating, 0, sizeof(*floating));
42 struct mptable_config_s *config = (void*)&floating[1];
43 floating->signature = MPTABLE_SIGNATURE;
44 floating->physaddr = (u32)config;
46 floating->spec_rev = 4;
47 floating->checksum = -checksum(floating, sizeof(*floating));
50 memset(config, 0, sizeof(*config));
51 config->signature = MPCONFIG_SIGNATURE;
52 config->length = length - sizeof(*floating);
54 memcpy(config->oemid, CONFIG_CPUNAME8, sizeof(config->oemid));
55 memcpy(config->productid, "0.1 ", sizeof(config->productid));
56 config->entrycount = smp_cpus + 2 + 16;
57 config->lapic = BUILD_APIC_ADDR;
60 struct mpt_cpu *cpus = (void*)&config[1];
62 for (i = 0; i < smp_cpus; i++) {
63 struct mpt_cpu *cpu = &cpus[i];
64 memset(cpu, 0, sizeof(*cpu));
65 cpu->type = MPT_TYPE_CPU;
68 /* cpu flags: enabled, bootstrap cpu */
69 cpu->cpuflag = (i == 0 ? 3 : 1);
70 cpu->cpufeature = 0x600;
71 cpu->featureflag = 0x201;
75 struct mpt_bus *bus = (void*)&cpus[smp_cpus];
76 memset(bus, 0, sizeof(*bus));
77 bus->type = MPT_TYPE_BUS;
78 memcpy(bus->bustype, "ISA ", sizeof(bus->bustype));
81 u8 ioapic_id = smp_cpus;
82 struct mpt_ioapic *ioapic = (void*)&bus[1];
83 memset(ioapic, 0, sizeof(*ioapic));
84 ioapic->type = MPT_TYPE_IOAPIC;
85 ioapic->apicid = ioapic_id;
86 ioapic->apicver = 0x11;
87 ioapic->flags = 1; // enable
88 ioapic->apicaddr = BUILD_IOAPIC_ADDR;
91 struct mpt_intsrc *intsrcs = (void *)&ioapic[1];
92 for(i = 0; i < 16; i++) {
93 struct mpt_intsrc *isrc = &intsrcs[i];
94 memset(isrc, 0, sizeof(*isrc));
95 isrc->type = MPT_TYPE_INTSRC;
97 isrc->dstapic = ioapic_id;
102 config->checksum = -checksum(config, config->length);
104 dprintf(1, "MP table addr=0x%x MPC table addr=0x%x size=0x%x\n",
105 (u32)floating, (u32)config, length);