summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rwxr-xr-xcopy_fdd.sh4
-rw-r--r--menu_fdd.cfg4
-rw-r--r--src/grapes/test/main.c8
-rw-r--r--src/kernel/Makefile (renamed from src/stem/Makefile)5
-rw-r--r--src/kernel/core/kmain.c (renamed from src/stem/core/kmain.c)4
-rw-r--r--src/kernel/core/loader_.asm (renamed from src/stem/core/loader_.asm)0
-rw-r--r--src/kernel/core/monitor.c (renamed from src/stem/core/monitor.c)0
-rw-r--r--src/kernel/core/monitor.h (renamed from src/stem/core/monitor.h)0
-rw-r--r--src/kernel/core/multiboot.h (renamed from src/stem/core/multiboot.h)0
-rw-r--r--src/kernel/core/sys.c (renamed from src/stem/core/sys.c)0
-rw-r--r--src/kernel/core/sys.h (renamed from src/stem/core/sys.h)0
-rw-r--r--src/kernel/lib/bitset.c (renamed from src/stem/lib/bitset.c)0
-rw-r--r--src/kernel/lib/bitset.h (renamed from src/stem/lib/bitset.h)0
-rw-r--r--src/kernel/lib/stdlib.c (renamed from src/stem/lib/stdlib.c)0
-rw-r--r--src/kernel/lib/stdlib.h (renamed from src/stem/lib/stdlib.h)0
-rw-r--r--src/kernel/lib/types.h (renamed from src/stem/lib/types.h)0
-rw-r--r--src/kernel/link.ld (renamed from src/stem/link.ld)0
-rw-r--r--src/kernel/linker/elf.c (renamed from src/stem/linker/elf.c)0
-rw-r--r--src/kernel/linker/elf.h (renamed from src/stem/linker/elf.h)0
-rw-r--r--src/kernel/mem/gdt.c (renamed from src/stem/mem/gdt.c)0
-rw-r--r--src/kernel/mem/gdt.h (renamed from src/stem/mem/gdt.h)0
-rw-r--r--src/kernel/mem/heap.c (renamed from src/stem/mem/heap.c)0
-rw-r--r--src/kernel/mem/heap.h (renamed from src/stem/mem/heap.h)0
-rw-r--r--src/kernel/mem/mem.c (renamed from src/stem/mem/mem.c)0
-rw-r--r--src/kernel/mem/mem.h (renamed from src/stem/mem/mem.h)0
-rw-r--r--src/kernel/mem/paging.c (renamed from src/stem/mem/paging.c)0
-rw-r--r--src/kernel/mem/paging.h (renamed from src/stem/mem/paging.h)0
-rw-r--r--src/kernel/mem/seg.c (renamed from src/stem/mem/seg.c)0
-rw-r--r--src/kernel/mem/seg.h (renamed from src/stem/mem/seg.h)0
-rw-r--r--src/kernel/task/idt.c (renamed from src/stem/task/idt.c)0
-rw-r--r--src/kernel/task/idt.h (renamed from src/stem/task/idt.h)0
-rw-r--r--src/kernel/task/idt_.asm (renamed from src/stem/task/idt_.asm)0
-rw-r--r--src/kernel/task/syscall.c (renamed from src/stem/task/syscall.c)0
-rw-r--r--src/kernel/task/syscall.h (renamed from src/stem/task/syscall.h)0
-rw-r--r--src/kernel/task/task.c (renamed from src/stem/task/task.c)0
-rw-r--r--src/kernel/task/task.h (renamed from src/stem/task/task.h)0
-rw-r--r--src/kernel/task/task_.asm (renamed from src/stem/task/task_.asm)0
-rw-r--r--src/kernel/task/timer.c (renamed from src/stem/task/timer.c)0
-rw-r--r--src/kernel/task/timer.h (renamed from src/stem/task/timer.h)0
-rw-r--r--src/library/Makefile34
-rw-r--r--src/library/grapes/syscall.c27
-rw-r--r--src/library/grapes/syscall.h10
-rw-r--r--src/library/link.ld (renamed from src/grapes/link.ld)1
-rw-r--r--src/library/start.c6
-rw-r--r--src/modules/test/Makefile (renamed from src/grapes/test/Makefile)12
-rw-r--r--src/modules/test/main.c8
48 files changed, 104 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index a79b141..c524a07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*.o
*.swp
*.map
+*.elf
diff --git a/Makefile b/Makefile
index 6861fe2..9cfa382 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,7 @@
.PHONY: clean, mrproper, Init.rfs, floppy, commit
-Projects = stem grapes/test
+Projects = kernel library modules/test
-Kernel = src/stem/stem.elf
Floppy = Grapes.fl.img
all:
diff --git a/copy_fdd.sh b/copy_fdd.sh
index 940586e..1372f2c 100755
--- a/copy_fdd.sh
+++ b/copy_fdd.sh
@@ -6,8 +6,8 @@
cp menu_fdd.cfg mnt/boot/menu.cfg
# copy kernel
-cp src/stem/stem.elf mnt
-cp src/grapes/test/test mnt
+cp src/kernel/kernel.elf mnt
+cp src/modules/test/test.elf mnt
#echo "*** Launching a BASH shell, if you want to do any maintenance ***"
#bash || exit 0
diff --git a/menu_fdd.cfg b/menu_fdd.cfg
index e51d0f6..f6e077f 100644
--- a/menu_fdd.cfg
+++ b/menu_fdd.cfg
@@ -1,3 +1,3 @@
title Grapes
-kernel /stem.elf
-module /test
+kernel /kernel.elf
+module /test.elf
diff --git a/src/grapes/test/main.c b/src/grapes/test/main.c
deleted file mode 100644
index 0413889..0000000
--- a/src/grapes/test/main.c
+++ /dev/null
@@ -1,8 +0,0 @@
-void printk(char *s) {
- asm volatile("int $64" : : "a"(4), "b"(s));
-}
-
-void start() {
- printk("Hi world !");
- asm volatile("int $64" : : "a"(3), "b"(0));
-}
diff --git a/src/stem/Makefile b/src/kernel/Makefile
index fe42ea3..5af7f4b 100644
--- a/src/stem/Makefile
+++ b/src/kernel/Makefile
@@ -15,15 +15,16 @@ OBJECTS = core/loader_.o core/kmain.o core/sys.o \
lib/stdlib.o lib/bitset.o \
mem/mem.o mem/paging.o mem/gdt.o mem/heap.o mem/seg.o \
linker/elf.o
-OUT = stem.elf
+OUT = kernel.elf
all: $(OBJECTS)
echo "* Linking $(OUT)..."
- $(LD) $(LDFLAGS) $(OBJECTS) -o $(OUT) -Map stem.map
+ $(LD) $(LDFLAGS) $(OBJECTS) -o $(OUT) -Map kernel.map
clean:
rm $(OBJECTS) || exit 0
rm *.o */*.o || exit 0
+ rm *.map || exit 0
mrproper: clean
rm $(OUT) || exit 0
diff --git a/src/stem/core/kmain.c b/src/kernel/core/kmain.c
index d6233db..ef92dff 100644
--- a/src/stem/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -31,7 +31,7 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) {
PANIC("wrong multiboot magic number.");
}
- monitor_write("Grapes::Stem is booting\n");
+ monitor_write("Grapes kernel booting ...\n");
idt_init();
@@ -57,7 +57,7 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) {
}
}
- monitor_write("Passing controll to loaded modules...\n");
+ monitor_write("Passing control to loaded modules...\n");
sti();
tasking_switch();
}
diff --git a/src/stem/core/loader_.asm b/src/kernel/core/loader_.asm
index d3b92cf..d3b92cf 100644
--- a/src/stem/core/loader_.asm
+++ b/src/kernel/core/loader_.asm
diff --git a/src/stem/core/monitor.c b/src/kernel/core/monitor.c
index 8c4744a..8c4744a 100644
--- a/src/stem/core/monitor.c
+++ b/src/kernel/core/monitor.c
diff --git a/src/stem/core/monitor.h b/src/kernel/core/monitor.h
index 3abe072..3abe072 100644
--- a/src/stem/core/monitor.h
+++ b/src/kernel/core/monitor.h
diff --git a/src/stem/core/multiboot.h b/src/kernel/core/multiboot.h
index 908274c..908274c 100644
--- a/src/stem/core/multiboot.h
+++ b/src/kernel/core/multiboot.h
diff --git a/src/stem/core/sys.c b/src/kernel/core/sys.c
index d31c20e..d31c20e 100644
--- a/src/stem/core/sys.c
+++ b/src/kernel/core/sys.c
diff --git a/src/stem/core/sys.h b/src/kernel/core/sys.h
index 76e3560..76e3560 100644
--- a/src/stem/core/sys.h
+++ b/src/kernel/core/sys.h
diff --git a/src/stem/lib/bitset.c b/src/kernel/lib/bitset.c
index a6d334b..a6d334b 100644
--- a/src/stem/lib/bitset.c
+++ b/src/kernel/lib/bitset.c
diff --git a/src/stem/lib/bitset.h b/src/kernel/lib/bitset.h
index fe9e8c2..fe9e8c2 100644
--- a/src/stem/lib/bitset.h
+++ b/src/kernel/lib/bitset.h
diff --git a/src/stem/lib/stdlib.c b/src/kernel/lib/stdlib.c
index c5245e7..c5245e7 100644
--- a/src/stem/lib/stdlib.c
+++ b/src/kernel/lib/stdlib.c
diff --git a/src/stem/lib/stdlib.h b/src/kernel/lib/stdlib.h
index 704c410..704c410 100644
--- a/src/stem/lib/stdlib.h
+++ b/src/kernel/lib/stdlib.h
diff --git a/src/stem/lib/types.h b/src/kernel/lib/types.h
index b7b19ab..b7b19ab 100644
--- a/src/stem/lib/types.h
+++ b/src/kernel/lib/types.h
diff --git a/src/stem/link.ld b/src/kernel/link.ld
index 1ce17cf..1ce17cf 100644
--- a/src/stem/link.ld
+++ b/src/kernel/link.ld
diff --git a/src/stem/linker/elf.c b/src/kernel/linker/elf.c
index dc7481b..dc7481b 100644
--- a/src/stem/linker/elf.c
+++ b/src/kernel/linker/elf.c
diff --git a/src/stem/linker/elf.h b/src/kernel/linker/elf.h
index f84bb62..f84bb62 100644
--- a/src/stem/linker/elf.h
+++ b/src/kernel/linker/elf.h
diff --git a/src/stem/mem/gdt.c b/src/kernel/mem/gdt.c
index 5aaad41..5aaad41 100644
--- a/src/stem/mem/gdt.c
+++ b/src/kernel/mem/gdt.c
diff --git a/src/stem/mem/gdt.h b/src/kernel/mem/gdt.h
index aac16bb..aac16bb 100644
--- a/src/stem/mem/gdt.h
+++ b/src/kernel/mem/gdt.h
diff --git a/src/stem/mem/heap.c b/src/kernel/mem/heap.c
index b6d2cd4..b6d2cd4 100644
--- a/src/stem/mem/heap.c
+++ b/src/kernel/mem/heap.c
diff --git a/src/stem/mem/heap.h b/src/kernel/mem/heap.h
index 39ba37e..39ba37e 100644
--- a/src/stem/mem/heap.h
+++ b/src/kernel/mem/heap.h
diff --git a/src/stem/mem/mem.c b/src/kernel/mem/mem.c
index 2f7e1c8..2f7e1c8 100644
--- a/src/stem/mem/mem.c
+++ b/src/kernel/mem/mem.c
diff --git a/src/stem/mem/mem.h b/src/kernel/mem/mem.h
index 5417d5f..5417d5f 100644
--- a/src/stem/mem/mem.h
+++ b/src/kernel/mem/mem.h
diff --git a/src/stem/mem/paging.c b/src/kernel/mem/paging.c
index 27ce043..27ce043 100644
--- a/src/stem/mem/paging.c
+++ b/src/kernel/mem/paging.c
diff --git a/src/stem/mem/paging.h b/src/kernel/mem/paging.h
index cb76cd6..cb76cd6 100644
--- a/src/stem/mem/paging.h
+++ b/src/kernel/mem/paging.h
diff --git a/src/stem/mem/seg.c b/src/kernel/mem/seg.c
index 1452d61..1452d61 100644
--- a/src/stem/mem/seg.c
+++ b/src/kernel/mem/seg.c
diff --git a/src/stem/mem/seg.h b/src/kernel/mem/seg.h
index 022d38e..022d38e 100644
--- a/src/stem/mem/seg.h
+++ b/src/kernel/mem/seg.h
diff --git a/src/stem/task/idt.c b/src/kernel/task/idt.c
index 360ac91..360ac91 100644
--- a/src/stem/task/idt.c
+++ b/src/kernel/task/idt.c
diff --git a/src/stem/task/idt.h b/src/kernel/task/idt.h
index bb89013..bb89013 100644
--- a/src/stem/task/idt.h
+++ b/src/kernel/task/idt.h
diff --git a/src/stem/task/idt_.asm b/src/kernel/task/idt_.asm
index 63d1570..63d1570 100644
--- a/src/stem/task/idt_.asm
+++ b/src/kernel/task/idt_.asm
diff --git a/src/stem/task/syscall.c b/src/kernel/task/syscall.c
index 5aab011..5aab011 100644
--- a/src/stem/task/syscall.c
+++ b/src/kernel/task/syscall.c
diff --git a/src/stem/task/syscall.h b/src/kernel/task/syscall.h
index 54af108..54af108 100644
--- a/src/stem/task/syscall.h
+++ b/src/kernel/task/syscall.h
diff --git a/src/stem/task/task.c b/src/kernel/task/task.c
index 804adc2..804adc2 100644
--- a/src/stem/task/task.c
+++ b/src/kernel/task/task.c
diff --git a/src/stem/task/task.h b/src/kernel/task/task.h
index c9f1794..c9f1794 100644
--- a/src/stem/task/task.h
+++ b/src/kernel/task/task.h
diff --git a/src/stem/task/task_.asm b/src/kernel/task/task_.asm
index ae45c68..ae45c68 100644
--- a/src/stem/task/task_.asm
+++ b/src/kernel/task/task_.asm
diff --git a/src/stem/task/timer.c b/src/kernel/task/timer.c
index 8c1a2b8..8c1a2b8 100644
--- a/src/stem/task/timer.c
+++ b/src/kernel/task/timer.c
diff --git a/src/stem/task/timer.h b/src/kernel/task/timer.h
index 4909245..4909245 100644
--- a/src/stem/task/timer.h
+++ b/src/kernel/task/timer.h
diff --git a/src/library/Makefile b/src/library/Makefile
new file mode 100644
index 0000000..c562dec
--- /dev/null
+++ b/src/library/Makefile
@@ -0,0 +1,34 @@
+.PHONY: clean, mrproper
+
+CC = gcc
+CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra
+
+LD = ld
+LDFLAGS = -r
+
+Library = grapes.o
+Objects = grapes/syscall.o \
+ start.o
+
+all: $(Library)
+ echo "* Done with library $(Library)"
+
+rebuild: mrproper all
+
+$(Library): $(Objects)
+ echo "* Linking library $(Library)..."
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.uo: %.c
+ echo "* Compiling $<..."
+ $(CC) $(CFLAGS) -c $< -o $@
+
+clean:
+ echo "* Removing object files..."
+ rm *.o || exit 0
+ rm -rf $(Objects) || exit 0
+
+mrproper: clean
+ echo "* Removing library..."
+ rm *.o || exit 0
+ rm -rf $(Library) || exit 0
diff --git a/src/library/grapes/syscall.c b/src/library/grapes/syscall.c
new file mode 100644
index 0000000..5a1a26e
--- /dev/null
+++ b/src/library/grapes/syscall.c
@@ -0,0 +1,27 @@
+#include "syscall.h"
+
+static int call(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f) {
+ unsigned ret;
+ asm volatile("int $64" : "=a"(ret) : "a"(a), "b"(b), "c"(c), "d"(d), "S"(e), "D"(f));
+ return ret;
+}
+
+void thread_exit() {
+ call(0, 0, 0, 0, 0, 0);
+}
+
+void schedule() {
+ call(1, 0, 0,0, 0, 0);
+}
+
+void thread_sleep(int time) {
+ call(2, time, 0, 0, 0, 0);
+}
+
+void process_exit(int retval) {
+ call(3, retval, 0, 0, 0, 0);
+}
+
+void printk(char* str) {
+ call(4, (unsigned)str, 0, 0, 0, 0);
+}
diff --git a/src/library/grapes/syscall.h b/src/library/grapes/syscall.h
new file mode 100644
index 0000000..9f4c280
--- /dev/null
+++ b/src/library/grapes/syscall.h
@@ -0,0 +1,10 @@
+#ifndef DEF_SYSCALL_H
+#define DEF_SYSCALL_H
+
+void thread_exit();
+void schedule();
+void thread_sleep(int time);
+void process_exit(int retval);
+void printk(char* str);
+
+#endif
diff --git a/src/grapes/link.ld b/src/library/link.ld
index 7527b80..17c944a 100644
--- a/src/grapes/link.ld
+++ b/src/library/link.ld
@@ -1,4 +1,5 @@
ENTRY (start)
+INPUT (grapes.o)
SECTIONS{
. = 0x10000000;
diff --git a/src/library/start.c b/src/library/start.c
new file mode 100644
index 0000000..9324ccb
--- /dev/null
+++ b/src/library/start.c
@@ -0,0 +1,6 @@
+extern int main();
+
+void start() {
+ int ret = main();
+ asm volatile("int $64" : : "a"(3), "b"(ret));
+}
diff --git a/src/grapes/test/Makefile b/src/modules/test/Makefile
index ddcc36f..105aa54 100644
--- a/src/grapes/test/Makefile
+++ b/src/modules/test/Makefile
@@ -1,13 +1,13 @@
.PHONY: clean, mrproper
CC = gcc
-CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra
+CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -I ../../library
LD = ld
-LDFLAGS = -T ../link.ld
+LDFLAGS = -T ../../library/link.ld -L ../../library
Objects = main.o
-Outfile = test
+Outfile = test.elf
all: $(Outfile)
echo "* Done with $(Outfile)"
@@ -23,8 +23,10 @@ $(Outfile): $(Objects)
clean:
echo "* Removing objects..."
- rm $(Objects)
+ rm *.o || exit 0
+ rm $(Objects) || exit 0
mrproper: clean
- rm $(Outfile)
+ rm *.elf || exit 0
+ rm $(Outfile) || exit 0
diff --git a/src/modules/test/main.c b/src/modules/test/main.c
new file mode 100644
index 0000000..3ac5cb5
--- /dev/null
+++ b/src/modules/test/main.c
@@ -0,0 +1,8 @@
+#include <grapes/syscall.h>
+
+int main() {
+ printk("[module:test] Hi world !\n");
+ thread_sleep(5000);
+ printk("[module:test] 5sec later...\n");
+ return 0;
+}