diff options
author | Alexis211 <alexis211@gmail.com> | 2010-02-06 20:51:56 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2010-02-06 20:51:56 +0100 |
commit | 6a52d123672b7a00af6e22b4c138205be2042a94 (patch) | |
tree | cd9b0a13490159369a66c850850596fd4b418139 /src/library | |
parent | 3558f18daf50281ee1cd68cca96cd967dbac04ba (diff) | |
download | TCE-6a52d123672b7a00af6e22b4c138205be2042a94.tar.gz TCE-6a52d123672b7a00af6e22b4c138205be2042a94.zip |
Reorganisation
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/Makefile | 34 | ||||
-rw-r--r-- | src/library/grapes/syscall.c | 27 | ||||
-rw-r--r-- | src/library/grapes/syscall.h | 10 | ||||
-rw-r--r-- | src/library/link.ld | 27 | ||||
-rw-r--r-- | src/library/start.c | 6 |
5 files changed, 104 insertions, 0 deletions
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/library/link.ld b/src/library/link.ld new file mode 100644 index 0000000..17c944a --- /dev/null +++ b/src/library/link.ld @@ -0,0 +1,27 @@ +ENTRY (start) +INPUT (grapes.o) + +SECTIONS{ + . = 0x10000000; + + .text : { + *(.text) + } + + .rodata ALIGN (0x1000) :{ + *(.rodata) + } + + .data ALIGN (0x1000) : { + *(.data) + } + + .bss : { + sbss = .; + *(COMMON) + *(.bss) + ebss = .; + } + + end = .; _end = .; __end = .; +} 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)); +} |