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 GPLv3 license.
8 #include "util.h" // dprintf
9 #include "memmap.h" // bios_table_cur_addr
10 #include "config.h" // CONFIG_*
12 static void putb(u8 **pp, int val)
20 static void putstr(u8 **pp, const char *str)
29 static void putle16(u8 **pp, int val)
38 static void putle32(u8 **pp, int val)
55 u8 *mp_config_table, *q, *float_pointer_struct;
56 int ioapic_id, i, len;
57 int mp_config_table_size;
59 int smp_cpus = smp_probe();
61 // Building an mptable on uniprocessor machines confuses some OSes.
64 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
65 mp_config_table = (u8 *)bios_table_cur_addr;
67 putstr(&q, "PCMP"); /* "PCMP signature */
68 putle16(&q, 0); /* table length (patched later) */
69 putb(&q, 4); /* spec rev */
70 putb(&q, 0); /* checksum (patched later) */
71 putstr(&q, CONFIG_CPUNAME8); /* OEM id */
72 putstr(&q, "0.1 "); /* vendor id */
73 putle32(&q, 0); /* OEM table ptr */
74 putle16(&q, 0); /* OEM table size */
75 putle16(&q, smp_cpus + 18); /* entry count */
76 putle32(&q, 0xfee00000); /* local APIC addr */
77 putle16(&q, 0); /* ext table length */
78 putb(&q, 0); /* ext table checksum */
79 putb(&q, 0); /* reserved */
81 for(i = 0; i < smp_cpus; i++) {
82 putb(&q, 0); /* entry type = processor */
83 putb(&q, i); /* APIC id */
84 putb(&q, 0x11); /* local APIC version number */
86 putb(&q, 3); /* cpu flags: enabled, bootstrap cpu */
88 putb(&q, 1); /* cpu flags: enabled */
89 putb(&q, 0); /* cpu signature */
93 putle16(&q, 0x201); /* feature flags */
96 putle16(&q, 0); /* reserved */
103 putb(&q, 1); /* entry type = bus */
104 putb(&q, 0); /* bus ID */
108 ioapic_id = smp_cpus;
109 putb(&q, 2); /* entry type = I/O APIC */
110 putb(&q, ioapic_id); /* apic ID */
111 putb(&q, 0x11); /* I/O APIC version number */
112 putb(&q, 1); /* enable */
113 putle32(&q, 0xfec00000); /* I/O APIC addr */
116 for(i = 0; i < 16; i++) {
117 putb(&q, 3); /* entry type = I/O interrupt */
118 putb(&q, 0); /* interrupt type = vectored interrupt */
119 putb(&q, 0); /* flags: po=0, el=0 */
121 putb(&q, 0); /* source bus ID = ISA */
122 putb(&q, i); /* source bus IRQ */
123 putb(&q, ioapic_id); /* dest I/O APIC ID */
124 putb(&q, i); /* dest I/O APIC interrupt in */
127 len = q - mp_config_table;
128 mp_config_table[4] = len;
129 mp_config_table[5] = len >> 8;
131 mp_config_table[7] = -checksum(mp_config_table, q - mp_config_table);
133 mp_config_table_size = q - mp_config_table;
135 bios_table_cur_addr += mp_config_table_size;
137 /* floating pointer structure */
138 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
139 float_pointer_struct = (u8 *)bios_table_cur_addr;
140 q = float_pointer_struct;
142 /* pointer to MP config table */
143 putle32(&q, (unsigned long)mp_config_table);
145 putb(&q, 1); /* length in 16 byte units */
146 putb(&q, 4); /* MP spec revision */
147 putb(&q, 0); /* checksum (patched later) */
148 putb(&q, 0); /* MP feature byte 1 */
154 float_pointer_struct[10] = -checksum(float_pointer_struct
155 , q - float_pointer_struct);
156 bios_table_cur_addr += (q - float_pointer_struct);
157 dprintf(1, "MP table addr=0x%08lx MPC table addr=0x%08lx size=0x%x\n",
158 (unsigned long)float_pointer_struct,
159 (unsigned long)mp_config_table,
160 mp_config_table_size);