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.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/kernel/smp.c b/src/kernel/smp.c
index d3c74fe..5796ab9 100644
--- a/src/kernel/smp.c
+++ b/src/kernel/smp.c
@@ -1,9 +1,12 @@
#include <kernel.h>
+#include <printf.h>
#include <madt.h>
#include <timer.h>
#include <cpuid.h>
#include <int.h>
#include <libc.h>
+#include <paging.h>
+#include <heap.h>
#define LAPIC_ICR_LOW 192
#define LAPIC_ICR_HIGH 196
@@ -11,6 +14,8 @@
extern lapic_t lapic;
extern char __load_start_smp_bootloader, __load_stop_smp_bootloader;
extern uint8_t *smp_bootstrap_corecount;
+extern uint8_t smp_bootstrap_bsp;
+extern uint64_t *smp_bootstrap_stackarray;
struct icr_reg {
uint8_t vector;
@@ -37,19 +42,24 @@ static inline void write_icr(uint8_t dest, uint32_t message) {
}
void smp_boot() {
- uint8_t cores_active = 0; //TODO change in asm
+ uint8_t cores_active = 1; //TODO change in asm
struct cores_info cores;
- unsigned int ci;
-
struct icr_reg icr;
+ get_coreinfo(&cores);
bzero(&icr, sizeof(icr));
+ void **core_stacks = malloc(sizeof(void *) * (cores.corecount - 1));
+ for(unsigned int s = 0; s < (cores.corecount - 1); s++) {
+ core_stacks[s] = palloc(0x1000);
+ }
+
memcpy(PHYS_TO_VIRT((void *)0x8000), PHYS_TO_VIRT(&__load_start_smp_bootloader),
&__load_stop_smp_bootloader - &__load_start_smp_bootloader);
- *(uint8_t **)PHYS_TO_VIRT(&smp_bootstrap_corecount) = &cores_active;
+ smp_bootstrap_corecount = &cores_active;
+ smp_bootstrap_bsp = cores.bsp;
+ smp_bootstrap_stackarray = (uint64_t)core_stacks;
- get_coreinfo(&cores);
icr.deliv_mode = 0b101;
icr.dest_shorthand = 0b11;
@@ -61,20 +71,13 @@ void smp_boot() {
icr.vector = 8;
write_icr(0, *(uint32_t *)&icr);
usleep(200);
- write_icr(0, *(uint32_t *)&icr);
-
- /**
+ if(cores_active != cores.corecount) write_icr(0, *(uint32_t *)&icr);
+ usleep(200);
if(cores_active != cores.corecount) {
- write_icr(0, *(uint32_t *)&icr);
- usleep(200);
+ printf("NOT ALL CORES ONLINE\n");
+ asm("cli\nhlt");
}
- **/
- /**
- for(ci = 0; ci < cores.corecount; ci++) {
- if(ci == cores.bsp) continue;
- //send init sipi
- write_icr(ci, *(uint32_t *)&icr);
+ else {
+ printf("%i!!!!!!\n", cores_active);
}
- **/
-
}