summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kernel.c17
-rw-r--r--kernel/spinlock.c34
-rw-r--r--kernel/x86.c18
3 files changed, 52 insertions, 17 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 533ff7c..d1de73f 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -4,6 +4,7 @@
#include "lib/logger/log.h"
#include "lib/int/stdint.h"
#include "lib/bool/bool.h"
+
#include "smp.h"
#include "time.h"
@@ -21,7 +22,15 @@ void kernel_ap()
{
proc++;
uint8_t p=proc;
- while(1)cpu_counter[p]++;
+ while(1)
+ {
+ cpu_counter[p]++;
+/*
+ lock_spin(0);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu[%d] %d",p,cpu_counter[p]);
+ lock_release(0);
+*/
+ }
}
//
@@ -131,19 +140,13 @@ void kernel_main(uint32_t initial_stack, int mp)
mem_init(0x7c00+1,*((uint16_t *)(0x7c00)));
// init spinlocks
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing Spinlocks");
-
init_spinlocks();
- lock_spin(0);
-
//
// Start the other Processors (also before paging !)
//
smp_log_procdata(&procdata);
- lock_spin(0);
-
smp_start_aps(&procdata,0x80000); // starts at 0x90000
// but it will be copied over mbr
diff --git a/kernel/spinlock.c b/kernel/spinlock.c
new file mode 100644
index 0000000..c7f5062
--- /dev/null
+++ b/kernel/spinlock.c
@@ -0,0 +1,34 @@
+#define FOOLOS_MODULE_NAME "spinlock"
+
+#include "lib/logger/log.h"
+#include "lib/int/stdint.h"
+
+typedef uint8_t spinlock;
+
+volatile spinlock spinlocks[16];
+
+
+void init_spinlocks()
+{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing spinlocks at 0x%08X ",spinlocks);
+ for(int i=0;i<16;i++)spinlocks[i]=0;
+}
+
+volatile void lock_spin(int i)
+{
+
+ spinlock *addr=spinlocks+i;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locking %d (0x%08X)",i,addr);
+
+ while(x86_xchg(addr,1));
+}
+
+void lock_release(int i)
+{
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocking %d",i);
+ spinlock *addr=spinlocks+i;
+
+ asm("movb $0,%0"::"m"(*addr));
+
+}
diff --git a/kernel/x86.c b/kernel/x86.c
index 7775ab7..15236a3 100644
--- a/kernel/x86.c
+++ b/kernel/x86.c
@@ -4,6 +4,10 @@
#include "lib/int/stdint.h"
#include "lib/logger/log.h"
+//
+// suffix (b, w, l, q for byte, word, dword, and qword).
+//
+
extern volatile uint64_t task_system_clock; // from task.c
void sleep(int i)
@@ -139,25 +143,19 @@ void x86_flush_tlb(uint32_t addr)
}
//xchg
-volatile uint8_t x86_xchg(volatile uint8_t *addr, uint8_t val)
+uint8_t x86_xchg(uint8_t *addr, uint8_t val)
{
- uint8_t result;
- // test. because asm does not work !?
- uint8_t oldval=*addr;
- *addr=val;
- return oldval;
-
+ uint8_t result;
-
// The + in "+m" denotes a read-modify-write operand.
- asm volatile("lock xchg %0, %1" :
+ asm volatile("lock xchgb %0, %1" :
"+m" (*addr), "=a" (result) :
"1" (val) :
"cc");
//log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"xchg val:%d with addr:0x%08X : result: %d",val,addr,result);
-//
+
return result;
}