From b74c5c8fb4de3b2847bc942e57dcf8f0dea705be Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 13 May 2015 23:58:39 +0200 Subject: fixed libc and 'userspace' --- userspace/Makefile | 10 +++++++--- userspace/cat.c | 17 +++++++++++++++++ userspace/foolshell.c | 9 +++++---- userspace/init.c | 2 +- userspace/sys/Makefile | 41 ++++++++++++++++++++++------------------- userspace/sys/crt0.o | Bin 0 -> 660 bytes userspace/sys/libfool.a | Bin 0 -> 7420 bytes userspace/sys/sys.c | 2 +- userspace/sys/sys.o | Bin 0 -> 3744 bytes userspace/sys/syscalls.o | Bin 0 -> 2948 bytes userspace/sys/termios.h | 2 ++ 11 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 userspace/cat.c create mode 100644 userspace/sys/crt0.o create mode 100644 userspace/sys/libfool.a create mode 100644 userspace/sys/sys.o create mode 100644 userspace/sys/syscalls.o create mode 100644 userspace/sys/termios.h (limited to 'userspace') diff --git a/userspace/Makefile b/userspace/Makefile index f112e67..8e97ac8 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -7,13 +7,16 @@ CFLAGS+=-w CFLAGS+=-std=gnu11 CFLAGS+=-O3 CFLAGS+=-g +LDFLAGS= +LDFLAGS=-lfool +#CFLAGS+=$(SYSROOT)/usr/lib/crt0.o -PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init +PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat ext2.img: $(PROGS) dd if=/dev/zero of=ext2.img bs=512 count=10000 - sudo mkfs.ext2 -O none ext2.img -F + sudo mkfs.ext2 -O none ext2.img -F mkdir mnt sudo mount ext2.img mnt sudo chown miguel mnt @@ -35,11 +38,12 @@ brainfuck: brainfuck.o foolshell: foolshell.o simple: simple.o add: add.o - $(CC) -o $@ $< -lm + $(CC) -o $@ $< -lm -lfool checker: checker.o task1: task1.o task2: task2.o init: init.o +cat: cat.o clean: -rm *.o $(PROGS) ext2.img diff --git a/userspace/cat.c b/userspace/cat.c new file mode 100644 index 0000000..a371397 --- /dev/null +++ b/userspace/cat.c @@ -0,0 +1,17 @@ +#include + +int main() +{ + FILE *f = fopen("README", "r"); + + if (f == NULL) + { + perror("unable to open file"); + return 1; + } + + puts("open success"); + fclose(f); + + return 0; +} diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 3a87158..da05e96 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -45,6 +45,7 @@ int main(int argc, char **argv) if(!silent)hello(); char *buf=malloc(256); + // printf("malloc returned: 0x%08X\n",buf); while(1) { @@ -87,8 +88,6 @@ char **tokenize(char *buf) i++; } token[c][t]=0; - - // printf("token %i : <%s>\n",c, token[c]); c++; @@ -216,15 +215,17 @@ int process(char *buf) int pid=fork(); if(pid!=0) { - //printf("new task pid: %i \n",pid); + printf("new task pid: %i \n",pid); } if(pid==0) { char buf[256]; sprintf(buf,"%s",token[0]); execve(buf,token,environ); - sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + //sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + sprintf(buf,"%s/%s","/bin",token[0]); execve(buf,token,environ); + puts("foolshell: command not found"); exit(1); } diff --git a/userspace/init.c b/userspace/init.c index f588875..5d3658c 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,7 +1,7 @@ int main(int argc, char **argv) { - //printf("fool-init: spawning a Fool's Shell\n"); + printf("fool-init: spawning a Fool's Shell\n"); // loop forever and spawn shells if the top-shell exits while(1) diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile index 5e217fa..cdcd3b7 100644 --- a/userspace/sys/Makefile +++ b/userspace/sys/Makefile @@ -1,29 +1,32 @@ +SYSROOT=/home/miguel/opt/foolos CC=i686-foolos-gcc CFLAGS= -CFLAGS+=-I../.. CFLAGS+=-w - +CFLAGS+=-I../.. +CFLAGS+=-gstabs OBJECTS=sys.o syscalls.o crt0.o -full: clean library_install crt_install + +full: clean library_install crt_install header_install + all: $(OBJECTS) -library_install: all - mkdir temp - mv *.o temp - cp /home/miguel/temp/sysroot/usr/lib/libc.a . - ar x libc.a - rm libc.a -# rm lib_a-environ.o - cp temp/sys*.o . - ar rs libc.a *.o - mv libc.a /home/miguel/temp/sysroot/usr/lib/libc.a - cp temp/*.o . - rm temp -rf - -crt_install: all - cp crt0.o /home/miguel/temp/sysroot/usr/lib/ +crt0.o: crt0.S + +crt_install: crt0.o + cp crt0.o $(SYSROOT)/usr/lib/ + + +header_install: + cp termios.h $(SYSROOT)/usr/include/sys/ + +libfool.a: sys.o syscalls.o + ar rcs libfool.a sys.o syscalls.o + +library_install: libfool.a + cp libfool.a $(SYSROOT)/usr/lib/ + clean: - -rm *.o + -rm *.o *.a diff --git a/userspace/sys/crt0.o b/userspace/sys/crt0.o new file mode 100644 index 0000000..db292b0 Binary files /dev/null and b/userspace/sys/crt0.o differ diff --git a/userspace/sys/libfool.a b/userspace/sys/libfool.a new file mode 100644 index 0000000..31fee46 Binary files /dev/null and b/userspace/sys/libfool.a differ diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c index 25dff7b..adf6ff9 100644 --- a/userspace/sys/sys.c +++ b/userspace/sys/sys.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate diff --git a/userspace/sys/sys.o b/userspace/sys/sys.o new file mode 100644 index 0000000..14413b2 Binary files /dev/null and b/userspace/sys/sys.o differ diff --git a/userspace/sys/syscalls.o b/userspace/sys/syscalls.o new file mode 100644 index 0000000..371b8af Binary files /dev/null and b/userspace/sys/syscalls.o differ diff --git a/userspace/sys/termios.h b/userspace/sys/termios.h new file mode 100644 index 0000000..ff1e838 --- /dev/null +++ b/userspace/sys/termios.h @@ -0,0 +1,2 @@ +typedef uint32_t speed_t; +typedef uint32_t DIR; -- cgit v1.2.3