summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile10
-rw-r--r--userspace/cat.c17
-rw-r--r--userspace/foolshell.c9
-rw-r--r--userspace/init.c2
-rw-r--r--userspace/sys/Makefile41
-rw-r--r--userspace/sys/crt0.obin0 -> 660 bytes
-rw-r--r--userspace/sys/libfool.abin0 -> 7420 bytes
-rw-r--r--userspace/sys/sys.c2
-rw-r--r--userspace/sys/sys.obin0 -> 3744 bytes
-rw-r--r--userspace/sys/syscalls.obin0 -> 2948 bytes
-rw-r--r--userspace/sys/termios.h2
11 files changed, 55 insertions, 28 deletions
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 <stdio.h>
+
+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
--- /dev/null
+++ b/userspace/sys/crt0.o
Binary files differ
diff --git a/userspace/sys/libfool.a b/userspace/sys/libfool.a
new file mode 100644
index 0000000..31fee46
--- /dev/null
+++ b/userspace/sys/libfool.a
Binary files 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 <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/termios.h>
+#include <termios.h>
// 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
--- /dev/null
+++ b/userspace/sys/sys.o
Binary files differ
diff --git a/userspace/sys/syscalls.o b/userspace/sys/syscalls.o
new file mode 100644
index 0000000..371b8af
--- /dev/null
+++ b/userspace/sys/syscalls.o
Binary files 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;