summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile20
-rw-r--r--userspace/add.c4
-rw-r--r--userspace/brainfuck.c6
-rw-r--r--userspace/crt0.S (renamed from userspace/sys/crt.S)9
-rw-r--r--userspace/foolshell.c16
-rw-r--r--userspace/init.c13
-rw-r--r--userspace/ls.c2
-rw-r--r--userspace/sys/Makefile37
-rw-r--r--userspace/sys/crt0.S23
-rw-r--r--userspace/sys/linker.ld37
-rw-r--r--userspace/sys/sys.c3
-rw-r--r--userspace/sys/syscalls.c6
12 files changed, 85 insertions, 91 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 49d93a0..62bc857 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,21 +1,24 @@
CC=i686-foolos-gcc
+CC=i686-elf-gcc
CFLAGS=
CFLAGS+=-I..
+CFLAGS+=-I/home/miguel/foolos/usr/i686-foolos/include
CFLAGS+=-w
CFLAGS+=-std=gnu11
CFLAGS+=-O0
CFLAGS+=-g
#CFLAGS+=-fstack-protector-all
-LDFLAGS=
+#LDFLAGS=-nostdlib
+LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ -lc -lm -lg -lnosys
PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat snake
include ../Makefile.common
-ext2.img: $(PROGS) ../mp/mp.bin
+ext2.img: crt0.o $(PROGS) ../mp/mp.bin
dd if=/dev/zero of=ext2.img bs=512 count=50000
sudo mkfs.ext2 -O none ext2.img -F
mkdir mnt
@@ -30,12 +33,12 @@ ext2.img: $(PROGS) ../mp/mp.bin
# cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin
# cp ../font/binfont.bin mnt/
# cp ~/temp/fool-os-stuff/ncurses/ncurses-5.9-build/progs/* mnt/bin/
- cp ~/opt/foolos/usr/bin/worm mnt/bin/
- cp ~/opt/foolos/usr/bin/dots mnt/bin/
- cp ~/opt/foolos/usr/bin/background mnt/bin/
- cp ~/opt/foolos/usr/bin/view mnt/bin/
- cp ~/opt/foolos/usr/bin/ncurses mnt/bin/
- cp ~/opt/foolos/usr/bin/bs mnt/bin/
+# cp ~/opt/foolos/usr/bin/worm mnt/bin/
+# cp ~/opt/foolos/usr/bin/dots mnt/bin/
+# cp ~/opt/foolos/usr/bin/background mnt/bin/
+# cp ~/opt/foolos/usr/bin/view mnt/bin/
+# cp ~/opt/foolos/usr/bin/ncurses mnt/bin/
+# cp ~/opt/foolos/usr/bin/bs mnt/bin/
cp ../mp/mp.bin mnt/boot/
mkdir -p mnt/etc
echo "127.0.0.1 localhost" > mnt/etc/hosts
@@ -48,7 +51,6 @@ snake: snake.o
foolshell: foolshell.o
simple: simple.o
add: add.o
- $(CC) -o $@ $< -lm
checker: checker.o
task1: task1.o
task2: task2.o
diff --git a/userspace/add.c b/userspace/add.c
index 04f7f17..94bb244 100644
--- a/userspace/add.c
+++ b/userspace/add.c
@@ -1,8 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#include "../fs/fs.h"
#include <math.h>
+#include "../fs/fs.h"
int main(int argc, char **argv)
{
@@ -29,7 +29,7 @@ int main(int argc, char **argv)
puts("--------");
printf("sum = %f \n",sum);
printf("avg = %f \n",sum/i);
- printf("sin(avg) = %f \n\n",sin(sum/i));
+// printf("sin(avg) = %f \n\n",sin(sum/i));
}
return 0;
diff --git a/userspace/brainfuck.c b/userspace/brainfuck.c
index 6bb28cb..a1d5d53 100644
--- a/userspace/brainfuck.c
+++ b/userspace/brainfuck.c
@@ -102,7 +102,7 @@ int main(int argc, char **argv)
else {
puts("brainfuck error: pointer overflow");
// replace with foolshell.
- execve(15,0,0);
+ _execve(15,0,0);
return EXIT_FAILURE;
}
break;
@@ -111,7 +111,7 @@ int main(int argc, char **argv)
else {
puts("brainfuck error: pointer underflow");
// replace with foolshell.
- execve(15,0,0);
+ _execve(15,0,0);
return EXIT_FAILURE;
}
break;
@@ -151,7 +151,7 @@ int main(int argc, char **argv)
}
}
// replace with foolshell.
- execve(15,0,0);
+ _execve(15,0,0);
return EXIT_SUCCESS;
}
diff --git a/userspace/sys/crt.S b/userspace/crt0.S
index d09f8ca..4c08f89 100644
--- a/userspace/sys/crt.S
+++ b/userspace/crt0.S
@@ -8,6 +8,12 @@ mov %eax, environ
pop %eax
#mov %eax, _impure_ptr
+#mov $61, %eax # write syscall
+#mov $1,%edx # stdout
+#mov .hellostr,%ecx
+#mov 9,%ebx # string length
+#int $0x80
+
call main
push environ
@@ -18,3 +24,6 @@ call _exit2
.wait:
hlt
jmp .wait
+
+.hellostr:
+.ascii "Hello Ass"
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index ba73e1d..a502f47 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -8,13 +8,8 @@
extern char **environ;
extern struct _reent *_impure_ptr;
-
-
uint8_t buf_test[1024*300];
-
-
-
//
void hello()
{
@@ -36,7 +31,7 @@ void hello()
"\033[37;44m"
" \n"
- " Welcome to FoolShell v0.8 (Compiled on " __DATE__ " at " __TIME__")\n"
+ " Welcome to FoolShell v0.12 (Compiled on " __DATE__ " at " __TIME__")\n"
" ------------------------------------------------------------------\n\n"
" Please type 'help' anytime, to show shell \"built-ins\". You can execute \n"
" user programms that are in your $PATH directory by simply typing \n"
@@ -147,6 +142,7 @@ int process(char *buf)
"'cd [dir]' - change directory (set $PWD)\n"
"'exit' - exit running foolshell\n\n");
}
+
else if(!strcmp(command,"cd"))
{
char *dir=getenv("PWD");
@@ -241,7 +237,7 @@ int process(char *buf)
}
else
{
- int pid=fork();
+ int pid=_fork();
if(pid!=0)
{
// printf("new task pid: %i \n",pid);
@@ -250,15 +246,15 @@ int process(char *buf)
{
char buf[256];
sprintf(buf,"%s",token[0]);
- execve(buf,token,environ);
+ _execve(buf,token,environ);
//sprintf(buf,"%s/%s",getenv("PATH"),token[0]);
sprintf(buf,"%s/%s","/bin",token[0]);
- execve(buf,token,environ);
+ _execve(buf,token,environ);
puts("foolshell: command not found");
exit(1);
}
int status;
- if(strcmp(token[1],"branch"))wait(&status);
+ if(strcmp(token[1],"branch"))_wait(&status);
}
return 0;
diff --git a/userspace/init.c b/userspace/init.c
index 31f14e3..e984d30 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -1,35 +1,34 @@
+#include <stdio.h>
+
int main(int argc, char **argv)
{
-
printf("fool-init: spawning a Fool's Shell\n");
// loop forever and spawn shells if the top-shell exits
while(1)
{
- int pid=fork();
+ int pid=_fork();
int status;
if(pid==0)
{
char *argv[]={"/bin/foolshell",0};
char *env[]={"PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0};
- execve("/bin/foolshell",argv,env); // replace process with our foolshell :)
+ _execve("/bin/foolshell",argv,env); // replace process with our foolshell :)
//execve("/bin/clear",argv,env); // replace process with our foolshell :)
puts("FATAL ERROR: Something terrible happened. Unable to Execute SHELL!");
while(1);// hang
-
}
// wait until our child process state changes (exits)
// and respawn SHELL
- wait(&status);
+ _wait(&status);
printf("fool-init: catched exit of process %d.\n",pid);
printf("fool-init: respawning a Fools Shell\n");
}
+
return 0;
}
-
-
diff --git a/userspace/ls.c b/userspace/ls.c
index 1cbb065..79e0633 100644
--- a/userspace/ls.c
+++ b/userspace/ls.c
@@ -5,8 +5,6 @@ void usage()
puts("ls [inode_nr]");
}
-
-
int main(int argc, char **argv)
{
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/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 <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <termios.h>
-
+#include <sys/termios.h>
// 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));