summaryrefslogtreecommitdiff
path: root/src/kernel/smp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/smp.c')
-rw-r--r--src/kernel/smp.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/kernel/smp.c b/src/kernel/smp.c
index ff08f93..a55fe49 100644
--- a/src/kernel/smp.c
+++ b/src/kernel/smp.c
@@ -53,11 +53,30 @@ struct cpu_info {
static struct gdt_descriptor gdtr;
+struct cores_info cores;
-void smp_boot() {
+struct apicid_to_coreid_deleteme { //WILL BE DELETED AFTER THREADING EXISTS TODO
+ uint8_t apic_id;
+ uint8_t core_id;
+};
+
+static struct apicid_to_coreid_deleteme *apicid_to_coreid;
+
+
+uint8_t get_coreid() { //WILL BE DELETED AFTER THREADING EXISTS TODO
+ uint32_t ebx, unused_cpuid;
+ uint8_t apic_id;
+ __get_cpuid(1, &unused_cpuid, &ebx, &unused_cpuid, &unused_cpuid);
+ apic_id = ebx >> 24;
+ for(uint8_t core = 0; core < corecount; core++) {
+ if(apicid_to_coreid[core].apic_id == apic_id) return apicid_to_coreid[core].core_id;
+ }
+ return 0;
+}
+
+void smp_prepare() {
uint8_t cores_active = 1;
uint8_t stack_i = 0, core_i;
- struct cores_info cores;
struct icr_reg icr;
struct cpu_info *stackarray;
get_coreinfo(&cores);
@@ -72,11 +91,18 @@ void smp_boot() {
corecount = cores.corecount;
stackarray = malloc(sizeof(struct cpu_info) * (cores.corecount - 1));
+ apicid_to_coreid = malloc(sizeof(struct apicid_to_coreid_deleteme) * (cores.corecount - 1));
for(core_i = 0; core_i < cores.corecount; core_i++) {
+
+ //WILL BE DELETED AFTER THREADING EXISTS TODO
+ apicid_to_coreid[core_i].apic_id = cores.apic_id[core_i];
+ apicid_to_coreid[core_i].core_id = core_i;
+
if(cores.apic_id[core_i] == cores.bsp) continue;
stackarray[stack_i].apic_id = cores.apic_id[core_i];
stackarray[stack_i].stack = palloc(0x1000);
stackarray[stack_i].secondary_bsp = (stack_i)? false : true;
+
stack_i++;
}
for(stack_i = 0; stack_i < (cores.corecount - 1); stack_i++) {