1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#include "kernel/kernel.h"
#include <stdbool.h>
#include "asm/x86.h"
#include "smp.h"
typedef struct mp_fps_struct
{
uint32_t sig; //signature "_MP_"
uint32_t conf; //pointer to config struct
uint8_t length; //should be 1
uint8_t version; // 1=1.1, 4=1.4
uint8_t checksum;
uint8_t features1;
uint8_t features2;
uint8_t res1; //reserved
uint8_t res2;
uint8_t res3;
}mp_fps;
typedef struct mp_config_struct
{
uint32_t sig; //signature "PCMP"
uint16_t length; //base table length
uint8_t version; //revision 1=1.1 4=1.4
uint8_t checksum;
uint32_t oemid1; //OEM id (ascii)
uint32_t oemid2;
uint32_t prodid1; //Product id (ascii)
uint32_t prodid2;
uint32_t prodid3;
uint32_t oem_table; //pointer (optional)
uint16_t oem_size; //size of this table
uint16_t entries; //entry count (following the header)
uint32_t local_apic; //local apic address (same for every cpu)
uint16_t length_ext; //extended table length (optional)
uint8_t check_ext; //checksum for ext. table
}mp_config;
typedef struct proc_struct
{
uint8_t type; //0=processor
uint8_t apic_id;
uint8_t apic_ver;
uint8_t cpu_bits;
uint32_t cpu_sig;
uint32_t cpu_flags;
}proc_entry;
//entries are sorted. (otherwise ignore. bochs!)
uint8_t *walk_mp_table(uint8_t *start_addr,smp_processors *smp)
{
if(*start_addr==0x0||*start_addr==0x2)
klog("entry type: %d",*start_addr);
// that is a processor
if(*start_addr==0x00)
{
proc_entry *pro=start_addr;
klog("local apic id: %02X",pro->apic_id);
klog("cpu enabled bit: %s",pro->cpu_bits&1?"yes":"no");
klog("bootstrap cpu bit: %s",pro->cpu_bits&2?"yes":"no");
// that is a enabled processor
if(pro->cpu_bits&1)
{
if(smp->processors>=SMP_MAX_PROC)
kpanic("we do not support that many processors. recompile with higher SMP_MAX_PROC.");
smp->local_apic_id[smp->processors]=pro->apic_id;
// that is the bootstrap processor
if(pro->cpu_bits&2)smp->boot=smp->processors;
smp->processors++;
}
return start_addr+20;
}
return start_addr+8;
}
void do_mp_conf(mp_config *addr,smp_processors *procdata)
{
char buf[]="XXXX";
uint32_t *buf_addr=buf;
*buf_addr=addr->sig;
klog("mp_config table addr: %08X",addr);
klog("mp_config signature: %s",buf);
klog("mp_config version: %02X",addr->version);
klog("mp_config # of entries: %d",addr->entries);
klog("mp_config local apic addr: 0x%08X",addr->local_apic);
klog("mp_config tabel length: %d",addr->length);
uint8_t *start_addr=addr;
start_addr+=44;
procdata->processors=0;
procdata->local_apic_address=addr->local_apic;
for(int i=0;i<addr->entries;i++)
{
start_addr=walk_mp_table(start_addr,procdata);
}
}
bool do_mp_fps(mp_fps *addr,smp_processors *procdata)
{
if(addr->length!=1)return false;
if(addr->version!=1&&addr->version!=4)return false;
char buf[]="XXXX";
uint32_t *buf_addr=buf;
*buf_addr=addr->sig;
klog("signature: %s",buf);
klog("conf: %08X",addr->conf);
klog("ver: %02X",addr->version);
klog("f1: %02X",addr->features1);
if(addr->features1!=0)kpanic("Intel default config not supported yet!");
do_mp_conf(addr->conf,procdata);
return true;
}
// todo: check checksum,version etc. and narrow down search
bool mp_find(smp_processors *procdata)
{
klog("Looking for Mp Floating Ponter Struct...");
uint8_t *addr=0x8000;
while(addr<=0xfffff)
{
if(!strcmp_l("_MP_",addr,4))
{
// klog("Found at 0x%04X",addr);
if(do_mp_fps(addr,procdata))return true;
}
addr++;
}
addr=0x190000-1025;
while(addr<=0x190000+1024)
{
if(!strcmp_l("_MP_",addr,4))
{
// klog("Found at 0x%04X",addr);
if(do_mp_fps(addr,procdata))return true;
}
addr++;
}
return false;
}
|