aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/apps/init/Makefile12
-rw-r--r--src/apps/init/main.c9
-rw-r--r--src/apps/linker.ld32
-rw-r--r--src/common/Makefile11
-rw-r--r--src/common/README9
-rw-r--r--src/common/libalgo/Makefile11
-rw-r--r--src/common/libalgo/hashtbl.c (renamed from src/common/hashtbl.c)0
-rw-r--r--src/common/libc/Makefile11
-rw-r--r--src/common/libc/printf.c (renamed from src/common/printf.c)0
-rw-r--r--src/common/libc/string.c (renamed from src/common/string.c)0
-rw-r--r--src/common/libkogata/Makefile11
-rw-r--r--src/common/libkogata/mutex.c (renamed from src/common/mutex.c)0
-rw-r--r--src/common/libkogata/slab_alloc.c (renamed from src/common/slab_alloc.c)0
-rw-r--r--src/kernel/Makefile2
-rw-r--r--src/kernel/core/thread.c6
-rw-r--r--src/lib/include/syscall.h12
-rw-r--r--src/lib/libkogata/Makefile11
-rw-r--r--src/lib/libkogata/debug.c13
-rw-r--r--src/lib/libkogata/malloc.c11
-rw-r--r--src/lib/libkogata/start.c9
-rw-r--r--src/lib/libkogata/syscall.c10
21 files changed, 163 insertions, 17 deletions
diff --git a/src/apps/init/Makefile b/src/apps/init/Makefile
new file mode 100644
index 0000000..e56d4c0
--- /dev/null
+++ b/src/apps/init/Makefile
@@ -0,0 +1,12 @@
+
+OBJ = main.o
+
+LIB = ../../lib/libkogata/libkogata.lib
+
+CFLAGS = -I ./include -I ../../common/include -I ../../lib/include
+
+LDFLAGS = -T ../linker.ld -Xlinker -Map=init.map
+
+OUT = init.bin
+
+include ../../rules.make
diff --git a/src/apps/init/main.c b/src/apps/init/main.c
new file mode 100644
index 0000000..ef51834
--- /dev/null
+++ b/src/apps/init/main.c
@@ -0,0 +1,9 @@
+#include <stdbool.h>
+
+#include <debug.h>
+
+int main(int argc, char **argv) {
+ asm volatile("int $0x80");
+ while(true);
+}
+
diff --git a/src/apps/linker.ld b/src/apps/linker.ld
new file mode 100644
index 0000000..0c84ecf
--- /dev/null
+++ b/src/apps/linker.ld
@@ -0,0 +1,32 @@
+ENTRY (__libkogata_start)
+
+SECTIONS{
+ . = 0x100000;
+
+ .text : {
+ *(.text)
+ }
+
+ .rodata ALIGN (0x1000) :{
+ *(.rodata)
+ }
+
+ .data ALIGN (0x1000) : {
+ start_ctors = .;
+ *(.ctor*)
+ end_ctors = .;
+ start_dtors = .;
+ *(.dtor*)
+ end_dtors = .;
+ *(.data)
+ }
+
+ .bss : {
+ sbss = .;
+ *(COMMON)
+ *(.bss)
+ ebss = .;
+ }
+
+ end = .; _end = .; __end = .;
+}
diff --git a/src/common/Makefile b/src/common/Makefile
deleted file mode 100644
index 40b8ba9..0000000
--- a/src/common/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-OBJ = string.o printf.o slab_alloc.o mutex.o hashtbl.o
-
-LIB =
-
-CFLAGS = -I ./include
-
-LDFLAGS =
-
-OUT = common.lib
-
-include ../rules.make
diff --git a/src/common/README b/src/common/README
index e40df40..7e3e1f7 100644
--- a/src/common/README
+++ b/src/common/README
@@ -1,5 +1,9 @@
This directory contains the library functions common to userland
-and kernel code.
+and kernel code, for the three basic libraries of the system :
+
+- libkogata : memory allocation, system functions
+- libc : (partial)implementation of standard libc functions
+- libalgo : usefull data structures
It relies on a few functions being exported :
@@ -14,6 +18,9 @@ These function are supposed to be defined in the code that calls
the common functions. The headers for these functions are to be
found in `assert.h` and `malloc.h`.
+In kernel code, these functions are defined somewhere in the kernel.
+In user code, these functions are defined in the user part of libkogata.
+
Panic and panic_assert end the execution of the current program
(or of the kernel when in kernel-mode).
diff --git a/src/common/libalgo/Makefile b/src/common/libalgo/Makefile
new file mode 100644
index 0000000..3e021c4
--- /dev/null
+++ b/src/common/libalgo/Makefile
@@ -0,0 +1,11 @@
+OBJ = hashtbl.o
+
+LIB =
+
+CFLAGS = -I ../include
+
+LDFLAGS =
+
+OUT = libalgo.lib
+
+include ../../rules.make
diff --git a/src/common/hashtbl.c b/src/common/libalgo/hashtbl.c
index b87bcef..b87bcef 100644
--- a/src/common/hashtbl.c
+++ b/src/common/libalgo/hashtbl.c
diff --git a/src/common/libc/Makefile b/src/common/libc/Makefile
new file mode 100644
index 0000000..54fa9f1
--- /dev/null
+++ b/src/common/libc/Makefile
@@ -0,0 +1,11 @@
+OBJ = string.o printf.o
+
+LIB =
+
+CFLAGS = -I ../include
+
+LDFLAGS =
+
+OUT = libc.lib
+
+include ../../rules.make
diff --git a/src/common/printf.c b/src/common/libc/printf.c
index 68e08d8..68e08d8 100644
--- a/src/common/printf.c
+++ b/src/common/libc/printf.c
diff --git a/src/common/string.c b/src/common/libc/string.c
index f6c27b4..f6c27b4 100644
--- a/src/common/string.c
+++ b/src/common/libc/string.c
diff --git a/src/common/libkogata/Makefile b/src/common/libkogata/Makefile
new file mode 100644
index 0000000..ea70be5
--- /dev/null
+++ b/src/common/libkogata/Makefile
@@ -0,0 +1,11 @@
+OBJ = slab_alloc.o mutex.o
+
+LIB =
+
+CFLAGS = -I ../include
+
+LDFLAGS =
+
+OUT = libkogata.lib
+
+include ../../rules.make
diff --git a/src/common/mutex.c b/src/common/libkogata/mutex.c
index b345ee5..b345ee5 100644
--- a/src/common/mutex.c
+++ b/src/common/libkogata/mutex.c
diff --git a/src/common/slab_alloc.c b/src/common/libkogata/slab_alloc.c
index 714c49f..714c49f 100644
--- a/src/common/slab_alloc.c
+++ b/src/common/libkogata/slab_alloc.c
diff --git a/src/kernel/Makefile b/src/kernel/Makefile
index bca1765..6cfa414 100644
--- a/src/kernel/Makefile
+++ b/src/kernel/Makefile
@@ -4,7 +4,7 @@ OBJ = core/loader.o core/kmain.o core/dbglog.o core/sys.o \
core/frame.o core/paging.o core/region.o core/kmalloc.o \
user/vfs.o user/nullfs.o user/process.o
-LIB = ../common/common.lib
+LIB = ../common/libc/libc.lib ../common/libkogata/libkogata.lib ../common/libalgo/libalgo.lib
CFLAGS = -I ./include -I ../common/include
diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c
index 4ca3f63..cc39eb2 100644
--- a/src/kernel/core/thread.c
+++ b/src/kernel/core/thread.c
@@ -124,13 +124,11 @@ thread_t *new_thread(entry_t entry, void* data) {
for (void* i = stack + PAGE_SIZE; i < stack + KPROC_STACK_SIZE; i += PAGE_SIZE) {
uint32_t f = frame_alloc(1);
if (f == 0) {
- region_free_unmap_free(stack);
- free(t);
- return 0;
+ PANIC("TODO (OOM could not create kernel stack for new thread)");
}
bool map_ok = pd_map_page(i, f, true);
if (!map_ok) {
- PANIC("TODO");
+ PANIC("TODO (OOM(2) could not create kernel stack for new thread)");
}
}
diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h
new file mode 100644
index 0000000..d6df4ec
--- /dev/null
+++ b/src/lib/include/syscall.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include <fs.h>
+#include <debug.h>
+
+void dbg_print(const char* str);
+void yield();
+
diff --git a/src/lib/libkogata/Makefile b/src/lib/libkogata/Makefile
new file mode 100644
index 0000000..2649e25
--- /dev/null
+++ b/src/lib/libkogata/Makefile
@@ -0,0 +1,11 @@
+OBJ = start.o malloc.o debug.o syscall.o
+
+LIB = ../../common/libkogata/libkogata.lib
+
+CFLAGS = -I ../include -I ../../common/include
+
+LDFLAGS =
+
+OUT = libkogata.lib
+
+include ../../rules.make
diff --git a/src/lib/libkogata/debug.c b/src/lib/libkogata/debug.c
new file mode 100644
index 0000000..27c9e28
--- /dev/null
+++ b/src/lib/libkogata/debug.c
@@ -0,0 +1,13 @@
+#include <stdbool.h>
+
+#include <debug.h>
+
+void panic(const char* msg, const char* file, int line) {
+ // TODO
+ while(true);
+}
+
+void panic_assert(const char* assert, const char* file, int line) {
+ // TODO
+ while(true);
+}
diff --git a/src/lib/libkogata/malloc.c b/src/lib/libkogata/malloc.c
new file mode 100644
index 0000000..c776cdf
--- /dev/null
+++ b/src/lib/libkogata/malloc.c
@@ -0,0 +1,11 @@
+#include <malloc.h>
+
+void* malloc(size_t size) {
+ // TODO
+ return 0;
+}
+
+void free(void* ptr) {
+ // TODO
+}
+
diff --git a/src/lib/libkogata/start.c b/src/lib/libkogata/start.c
new file mode 100644
index 0000000..88a4eb3
--- /dev/null
+++ b/src/lib/libkogata/start.c
@@ -0,0 +1,9 @@
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+void __libkogata_start() {
+ // TODO
+ while(true);
+}
+
diff --git a/src/lib/libkogata/syscall.c b/src/lib/libkogata/syscall.c
new file mode 100644
index 0000000..234b9ff
--- /dev/null
+++ b/src/lib/libkogata/syscall.c
@@ -0,0 +1,10 @@
+#include <debug.h>
+#include <syscall.h>
+
+void dbg_print(const char* str) {
+ // TODO
+}
+
+void yield() {
+ // TODO
+}