summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README.md8
-rw-r--r--kernel/kernel.c17
-rw-r--r--kernel/spinlock.c34
-rw-r--r--kernel/x86.c18
-rw-r--r--lib/logger/log.c2
6 files changed, 59 insertions, 22 deletions
diff --git a/Makefile b/Makefile
index 33f2d85..4e960d8 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ KERNEL_START=0x18000
############ flags ############
-CFLAGS=-ffreestanding -std=gnu99 -m32 -fno-asynchronous-unwind-tables -O0
+CFLAGS=-ffreestanding -std=gnu11 -m32 -fno-asynchronous-unwind-tables -O0
CFLAGS+= -I.
#CFLAGS+=-fdata-sections -ffunction-sections
#CFLAGS+= -Werror
diff --git a/README.md b/README.md
index d7bf7cf..5c4e848 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,6 @@ Features
Please note that all features are only very rudimentary and buggy.
-
* PIT support / Timing
* PIC support & Interrupt handling framework
* PCI bus scanning
@@ -60,22 +59,23 @@ Please note that all features are only very rudimentary and buggy.
* Floppy disk driver
* VESA
* ACPI / MP (to get processor info)
+* Spinlocks
Todos
-----
-* Sync primitives
* Shell
* E1000 driver
* Port c lib and gcc
* Networking stack
* Web-server
* User space
+* mouse driver
+* window manager
+
* 64-bit
* ARM
* JVM
-* mouse driver
-* window manager
* USB driver
* Ext2 driver
* Higher half kernel
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;
}
diff --git a/lib/logger/log.c b/lib/logger/log.c
index 4a510f9..331726f 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -17,6 +17,8 @@ void PutConsole(char *str, int color);
void log(char *module_name, int log_level, char *format_string, ...)
{
+
+
if(log_level<FOOLOS_LOG_INFO)return;