summaryrefslogtreecommitdiff
path: root/kernel/smp.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/smp.c')
-rw-r--r--kernel/smp.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/kernel/smp.c b/kernel/smp.c
index f776c72..76a8b1c 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -1,3 +1,8 @@
+// http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf
+// http://download.intel.com/design/chipsets/datashts/29056601.pdf
+// http://www.scs.stanford.edu/05au-cs240c/lab/ia32/IA32-3.pdf
+
+
#define FOOLOS_MODULE_NAME "smp"
#include "lib/logger/log.h"
@@ -10,20 +15,35 @@
#define FOOLOS_APIC_SPUR_INT 0x00f0
#define FOOLOS_APIC_INT_COMMAND_LOW 0x0300
#define FOOLOS_APIC_INT_COMMAND_HIGH 0x0310
+#define FOOLOS_APIC_ID 0x020
// some multiprocessor shit that should move away TODO
uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
-extern
+uint32_t local_apic_addr;
void smp_main()
{
- // int_install();
- // x86_int_enable();
+ while(1);
+
+ // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"local apic_addr:0x%08X",local_apic_addr);
+ uint32_t *reg=local_apic_addr+FOOLOS_APIC_ID;
+ // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"local apic id: 0x%08X",(*reg));
+
+ *reg=local_apic_addr+FOOLOS_APIC_SPUR_INT;
+ *reg|=0x100;//0xffffffff; // all bits 1 and interrupt 255
+// *reg=0;//xffffffff; // all bits 1 and interrupt 255
+
+ //int_install();
+ x86_int_enable();
+
+ while(1);
+
switch_to_user_mode();
+// int x=1/0;
while(1);
@@ -64,7 +84,9 @@ void smp_log_procdata(smp_processors *procdata)
// this will start all our application processors!
void smp_start_aps(smp_processors *pros,char *path)
-{
+{
+ local_apic_addr=pros->local_apic_address;
+
//lets copy the binary into mbr
fs_content(path,0x7000,0x100); // copy 0x100 bytes to 0x7000
@@ -73,8 +95,12 @@ void smp_start_aps(smp_processors *pros,char *path)
*entry=smp_main;
//bsp (boot processor) enables its local apic
- uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
-// *reg=0xffffffff; // all bits 1 and interrupt 255
+// uint32_t *reg=local_apic_addr+FOOLOS_APIC_SPUR_INT;
+// *reg=0xffffffff; // all bits 1 and interrupt 255 (is this not set anyway?)
+// *reg=0;
+
+ uint32_t *reg=local_apic_addr+FOOLOS_APIC_ID;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"local apic id: 0x%08X",(*reg));
for(int i=0;i<pros->processors;i++)
{
@@ -84,10 +110,10 @@ void smp_start_aps(smp_processors *pros,char *path)
uint8_t dest=pros->local_apic_id[i];
- reg=pros->local_apic_address+FOOLOS_APIC_INT_COMMAND_HIGH;
+ reg=local_apic_addr+FOOLOS_APIC_INT_COMMAND_HIGH;
*reg=dest<<24; // destination apic.
- reg=pros->local_apic_address+FOOLOS_APIC_INT_COMMAND_LOW;
+ reg=local_apic_addr+FOOLOS_APIC_INT_COMMAND_LOW;
*reg=(5<<8)|(1<<14); // 101 INIT
// do we really neet this?
@@ -97,14 +123,11 @@ void smp_start_aps(smp_processors *pros,char *path)
// start proc 0x7 = 0x7000; etc..
*reg=(6<<8)|(1<<14)|0x7; // 110 SIPI
-
- //bsp (boot processor) enables its local apic
- uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
- // *reg=0xffffffff; // all bits 1 and interrupt 255
-
}
+
}
+