From c742be9c738c91703a7be787639cad167de3a6b1 Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 17 Aug 2018 02:28:02 +0200 Subject: started reviving my fool os --- userspace/sys/Makefile | 37 +++++++++++++++++++++---------------- userspace/sys/crt.S | 20 -------------------- userspace/sys/crt0.S | 23 +++++++++++++++++++++++ userspace/sys/linker.ld | 37 ------------------------------------- userspace/sys/sys.c | 3 +-- userspace/sys/syscalls.c | 6 +++--- 6 files changed, 48 insertions(+), 78 deletions(-) delete mode 100644 userspace/sys/crt.S create mode 100644 userspace/sys/crt0.S delete mode 100644 userspace/sys/linker.ld (limited to 'userspace/sys') diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile index 05177a6..289da1e 100644 --- a/userspace/sys/Makefile +++ b/userspace/sys/Makefile @@ -1,23 +1,28 @@ -SYSROOT=/home/miguel/opt/foolos -CC=i686-foolos-gcc -LD=i686-foolos-ld +CC=i686-elf-gcc +LD=i686-elf-ld -CFLAGS= -CFLAGS+=-w -CFLAGS+=-I../.. -CFLAGS+=-gstabs +#CFLAGS= +#CFLAGS+=-w +#CFLAGS+=-I../.. +#CFLAGS+=-gstabs +#CFLAGS+=-I. -install: crt_install header_install +#LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ -lc -lm -lg -lnosys +#CFLAGS+=-I/home/miguel/foolos/usr/i686-foolos/include -crt_install: crt0.o - cp crt0.o $(SYSROOT)/usr/lib/ +#install: crt_install header_install -crt0.o: crt.o sys.o syscalls.o - $(LD) -r $^ -o $@ +#crt_install: crt0.o +# cp crt0.o $(SYSROOT)/usr/lib/ -header_install: - cp *.h $(SYSROOT)/usr/include/ - cp sys/*.h $(SYSROOT)/usr/include/sys/ +#crt0.o: crt.o sys.o #syscalls.o +# $(LD) -r $^ -o $@ + +#header_install: +# cp *.h $(SYSROOT)/usr/include/ +# cp sys/*.h $(SYSROOT)/usr/include/sys/ + +crt0.o: crt0.S clean: - -rm *.o *.a + -rm -f *.o *.a diff --git a/userspace/sys/crt.S b/userspace/sys/crt.S deleted file mode 100644 index d09f8ca..0000000 --- a/userspace/sys/crt.S +++ /dev/null @@ -1,20 +0,0 @@ -.global _start - -_start: - -pop %eax -mov %eax, environ - -pop %eax -#mov %eax, _impure_ptr - -call main - -push environ -push %eax -call _exit2 - -# this should never be reached anyway! -.wait: - hlt -jmp .wait diff --git a/userspace/sys/crt0.S b/userspace/sys/crt0.S new file mode 100644 index 0000000..2d6cbbd --- /dev/null +++ b/userspace/sys/crt0.S @@ -0,0 +1,23 @@ +.global _start + +_start: + +jmp . + +##pop %eax +##mov %eax, environ + +##pop %eax +#mov %eax, _impure_ptr + +##call main + + +##push environ +##push %eax +##call _exit2 + +# this should never be reached anyway! +.wait: + hlt +jmp .wait diff --git a/userspace/sys/linker.ld b/userspace/sys/linker.ld deleted file mode 100644 index 7c1c4bf..0000000 --- a/userspace/sys/linker.ld +++ /dev/null @@ -1,37 +0,0 @@ -ENTRY(_start) - -SECTIONS -{ - . = 1M; - - kernel_start = .; - - .text BLOCK(4K) : ALIGN(4K) - { - *(.multiboot) - *(.text) - } - - /* Read-only data. */ - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } - - /* Read-write data (initialized) */ - .data BLOCK(4K) : ALIGN(4K) - { - *(.data) - } - - /* Read-write data (uninitialized) and stack */ - .bss BLOCK(4K) : ALIGN(4K) - { - *(COMMON) - *(.bss) - *(.bootstrap_stack) - } - - kernel_end = .; - -} diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c index 5cd4396..4ff77f3 100644 --- a/userspace/sys/sys.c +++ b/userspace/sys/sys.c @@ -1,8 +1,7 @@ #include #include #include -#include - +#include // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate // with kernel.c diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c index c3ff909..10e035c 100644 --- a/userspace/sys/syscalls.c +++ b/userspace/sys/syscalls.c @@ -4,16 +4,16 @@ extern char **environ; //struct _reent *_impure_ptr; // generic syscall interface! -int syscall(int call, int p1, int p2, int p3) + +int __attribute__ ((noinline)) syscall(int call, int p1, int p2, int p3) { int ebx; // will hold return value; + // select syscall and pass params asm("pusha"); - // select syscall asm("mov %0, %%eax"::"m"(call)); - // pass params asm("mov %0,%%edx"::"m"(p1)); asm("mov %0,%%ecx"::"m"(p2)); asm("mov %0,%%ebx"::"m"(p3)); -- cgit v1.2.3