1 // MPTable generation (on emulators)
3 // Copyright (C) 2008,2009 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 "config.h" // CONFIG_*
10 #include "mptable.h" // MPTABLE_SIGNATURE
19 dprintf(3, "init MPTable\n");
21 int length = (sizeof(struct mptable_config_s)
22 + sizeof(struct mpt_cpu) * MaxCountCPUs
23 + sizeof(struct mpt_bus)
24 + sizeof(struct mpt_ioapic)
25 + sizeof(struct mpt_intsrc) * 16);
26 struct mptable_config_s *config = malloc_fseg(length);
27 struct mptable_floating_s *floating = malloc_fseg(sizeof(*floating));
28 if (!config || !floating) {
29 dprintf(1, "No room for MPTABLE!\n");
33 /* floating pointer structure */
34 memset(floating, 0, sizeof(*floating));
35 floating->signature = MPTABLE_SIGNATURE;
36 floating->physaddr = (u32)config;
38 floating->spec_rev = 4;
39 floating->checksum -= checksum(floating, sizeof(*floating));
42 memset(config, 0, sizeof(*config));
43 config->signature = MPCONFIG_SIGNATURE;
45 memcpy(config->oemid, CONFIG_CPUNAME8, sizeof(config->oemid));
46 memcpy(config->productid, "0.1 ", sizeof(config->productid));
47 config->entrycount = MaxCountCPUs + 2 + 16;
48 config->lapic = BUILD_APIC_ADDR;
51 u32 cpuid_signature, ebx, ecx, cpuid_features;
52 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
53 struct mpt_cpu *cpus = (void*)&config[1];
55 for (i = 0; i < MaxCountCPUs; i++) {
56 struct mpt_cpu *cpu = &cpus[i];
57 memset(cpu, 0, sizeof(*cpu));
58 cpu->type = MPT_TYPE_CPU;
61 /* cpu flags: enabled, bootstrap cpu */
63 cpu->cpuflag = 1 | (i == 0) ? 2 : 0;
66 if (cpuid_signature) {
67 cpu->cpusignature = cpuid_signature;
68 cpu->featureflag = cpuid_features;
70 cpu->cpusignature = 0x600;
71 cpu->featureflag = 0x201;
76 struct mpt_bus *bus = (void*)&cpus[MaxCountCPUs];
77 memset(bus, 0, sizeof(*bus));
78 bus->type = MPT_TYPE_BUS;
79 memcpy(bus->bustype, "ISA ", sizeof(bus->bustype));
82 u8 ioapic_id = CountCPUs;
83 struct mpt_ioapic *ioapic = (void*)&bus[1];
84 memset(ioapic, 0, sizeof(*ioapic));
85 ioapic->type = MPT_TYPE_IOAPIC;
86 ioapic->apicid = ioapic_id;
87 ioapic->apicver = 0x11;
88 ioapic->flags = 1; // enable
89 ioapic->apicaddr = BUILD_IOAPIC_ADDR;
92 struct mpt_intsrc *intsrc = (void*)&ioapic[1];
93 for (i = 0; i < 16; i++) {
94 memset(intsrc, 0, sizeof(*intsrc));
95 intsrc->type = MPT_TYPE_INTSRC;
96 intsrc->srcbusirq = i;
97 intsrc->dstapic = ioapic_id;
99 if (qemu_cfg_irq0_override()) {
100 /* Destination 2 is covered by irq0->inti2 override (i ==
101 0). Source IRQ 2 is unused */
111 config->length = (void*)intsrc - (void*)config;
112 config->checksum -= checksum(config, config->length);
114 dprintf(1, "MP table addr=%p MPC table addr=%p size=%d\n",
115 floating, config, config->length);