summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile47
-rw-r--r--userspace/crt0.S7
-rw-r--r--userspace/sys/Makefile28
-rw-r--r--userspace/sys/crt0.S23
-rw-r--r--userspace/sys/sgtty.h19
-rw-r--r--userspace/sys/sys.c188
-rw-r--r--userspace/sys/sys/ioctl.h0
-rw-r--r--userspace/sys/sys/termios.h27
-rw-r--r--userspace/sys/syscalls.c158
9 files changed, 18 insertions, 479 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 2812edd..e1e5484 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,35 +1,42 @@
+IMAGESIZE=30000 #ext2.img size in Kb (30Megs)
+
+#######################
+
CC=i686-foolos-gcc
CC=i686-elf-gcc
CFLAGS=
+CFLAGS=-w
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=-nostdlib
LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/
LDLIBS=-lc -lm -lg -lnosys
-PROGS=foolshell ls simple brainfuck test-math checker clear task1 task2 init cat snake
+PROGS_C=$(wildcard *.c)
+PROGS=$(patsubst %.c,%,$(PROGS_C))
+
include ../Makefile.common
+all: ext2.img
+
ext2.img: crt0.o $(PROGS) ../mp/mp.bin
- dd if=/dev/zero of=ext2.img bs=512 count=50000
+
+ dd if=/dev/zero of=ext2.img bs=1024 count=$(IMAGESIZE)
sudo mkfs.ext2 -O none ext2.img -F
mkdir mnt
sudo mount ext2.img mnt
sudo chown miguel mnt
mkdir -p mnt/home/miguel
mkdir -p mnt/boot
- echo "hello one" > mnt/home/miguel/test1.txt
+ echo "Welcome to FoolOs\nWe hope you will enjoy your stay." > mnt/home/miguel/hello.txt
mkdir -p mnt/bin
- cp $^ mnt/bin
+ cp $(PROGS) mnt/bin
echo "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." > mnt/home/miguel/hello.brain
+
# 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/
@@ -39,6 +46,7 @@ ext2.img: crt0.o $(PROGS) ../mp/mp.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
@@ -46,27 +54,8 @@ ext2.img: crt0.o $(PROGS) ../mp/mp.bin
sudo umount mnt
rm mnt -rf
-brainfuck: brainfuck.o
-snake: snake.o
-foolshell: foolshell.o
-simple: simple.o
-test-math: test-math.o
-checker: checker.o
-task1: task1.o
-task2: task2.o
-init: init.o
-cat: cat.o
-
clean:
- -rm *.o $(PROGS) ext2.img *.d
+ -rm -f *.o $(PROGS) ext2.img *.d
-mount:
- mkdir mnt
- sudo mount ext2.img mnt
- sudo chown miguel mnt
-
-umount:
- sudo umount mnt
- rm mnt -rf
+new: clean all
-new: clean ext2.img
diff --git a/userspace/crt0.S b/userspace/crt0.S
index 23efec5..87f1995 100644
--- a/userspace/crt0.S
+++ b/userspace/crt0.S
@@ -7,13 +7,6 @@ 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
diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile
deleted file mode 100644
index 289da1e..0000000
--- a/userspace/sys/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
-CC=i686-elf-gcc
-LD=i686-elf-ld
-
-#CFLAGS=
-#CFLAGS+=-w
-#CFLAGS+=-I../..
-#CFLAGS+=-gstabs
-#CFLAGS+=-I.
-
-#LDFLAGS=-L/home/miguel/foolos/usr/i686-foolos/lib/ -lc -lm -lg -lnosys
-#CFLAGS+=-I/home/miguel/foolos/usr/i686-foolos/include
-
-#install: crt_install header_install
-
-#crt_install: crt0.o
-# cp crt0.o $(SYSROOT)/usr/lib/
-
-#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 -f *.o *.a
diff --git a/userspace/sys/crt0.S b/userspace/sys/crt0.S
deleted file mode 100644
index 2d6cbbd..0000000
--- a/userspace/sys/crt0.S
+++ /dev/null
@@ -1,23 +0,0 @@
-.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/sgtty.h b/userspace/sys/sgtty.h
deleted file mode 100644
index 24d0218..0000000
--- a/userspace/sys/sgtty.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#define TIOCFLUSH 0x01
-#define RAW 0x02
-#define CBREAK 0x04
-#define XTABS 0x08
-#define CRMOD 0x10
-#define ECHO 0x20
-
-// TODO: same struct should be used for /terminal/terminal.h ?
-struct sgttyb{
-
- int sg_ospeed;
- int sg_ispeed;
-
- char sg_erase;
- char sg_kill;
-
- int sg_flags;
-
-};
diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c
deleted file mode 100644
index 4ff77f3..0000000
--- a/userspace/sys/sys.c
+++ /dev/null
@@ -1,188 +0,0 @@
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/termios.h>
-
-// CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate
-// with kernel.c
-// http://wiki.osdev.org/Stack_Smashing_Protector
-#include <stdint.h>
-#include <stdlib.h>
-
-#if UINT32_MAX == UINTPTR_MAX
-#define STACK_CHK_GUARD 0xe2dee396
-#else
-#define STACK_CHK_GUARD 0x595e9fbd94fda766
-#endif
-
-uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
-
-__attribute__((noreturn))
-void __stack_chk_fail(void)
-{
- write(1,"stack smashing!\n",16);
- exit(99);
-}
-
-
-///////////////////
-
-// required by binutils!
-
-long sysconf(int name)
-{
- printf("UNIMPL: sysconf\n");
- printf("SYSCONF CALLED WITH : %s\n",name);
- return 0;
-}
-
-// set file mode creation mask
-mode_t umask(mode_t mask)
-{
- printf("UNIMPL: umask\n");
- return mask;
-}
-
-// chmod
-int chmod(const char * path, mode_t mode)
-{
- printf("UNIMPL: chmod\n");
- return -1;
-}
-
-// manipulating file descriptor
-int fcntl(int fd, int cmd, ...)
-{
- printf("UNIMPL: fcntl\n");
- return -1;
-}
-
-// working directory
-char *getwd(char *buf)
-{
- printf("UNIMPL: getwd\n");
- static char wd[]="/";
- buf=wd;
- return buf;
-}
-
-// check if access allowed
-int access(const char *pathname, int mode)
-{
- printf("UNIMPL: access\n");
- //TODO: at leas check if this file exists!
- return 0;
-}
-
-// update time
-int utime(const char *filename, const int *x)
-{
- printf("UNIMPL: utime\n");
- return -1;
-}
-
-// rmdir
-int rmdir (const char *pathname)
-{
- printf("UNIMPL: rmdir\n");
- return -1;
-}
-
-// chonw
-int chown(const char *path, uid_t owner, gid_t group)
-{
- printf("UNIMPL: chown\n");
- return -1;
-}
-
-// termios / ncurses
-int tcgetattr(int fd, struct termios *termios_p)
-{
- printf("UNIMPL: tcgetattr\n");
- return 0;
-}
-int tcsetattr(int fd, int optional_actions, const struct termios *termios_p){
- printf("UNIMPL: tsetattr\n");
- return 0;
-}
-int mkdir(const char *pathname, mode_t mode)
-{
- printf("UNIMPL: mkdir\n");
- return -1;
-}
-int chdir (const char *pathname)
-{
- printf("UNIMPL: chdir\n");
- return -1;
-}
-
-// TODO; check if this is allright for not-real serial line!?
-// http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_12.html#SEC242
-// here they write something about padding may be affected? experiment.
-speed_t cfgetospeed(const struct termios *termios_p)
-{
-// printf("UNIMPL: cfgetospeed\n");
- return 9600;
-}
-
-char *ttyname(int fd)
-{
- printf("UNIMPL: ttyname\n");
- return "foolterm";
-}
-
-
-DIR *opendir(const char *name)
-{
- printf("UNIMPL: opendir\n");
- return 0;
-}
-int closedir(DIR *dirp)
-{
- printf("UNIMPL: closedir\n");
- return 0;
-}
-
-
-int tcflush(int fd, int queue_selector)
-{
- printf("UNIMPL: tcflush\n");
- return -1;
-}
-long fpathconf(int fd, int name)
-{
- printf("UNIMPL: fpathconf\n");
- return -1;
-}
-
-
-unsigned int sleep(unsigned int seconds)
-{
- printf("UNIMPL: sleep\n");
- return 0;
-}
-
-char *getlogin(void)
-{
- printf("UNIMPL: getlogin\n");
- return NULL;
-}
-
-int ioctl(int fd, unsigned long request, ...)
-{
- printf("UNIMPL: ioctl\n");
- return -1;
-}
-
-int gtty(int fd, void *buf)
-{
- // printf("UNIMPL: gettty\n");
- return -1;
-}
-
-int stty(int fd, void *buf)
-{
- // printf("UNIMPL: settty\n");
- return -1;
-}
-
diff --git a/userspace/sys/sys/ioctl.h b/userspace/sys/sys/ioctl.h
deleted file mode 100644
index e69de29..0000000
--- a/userspace/sys/sys/ioctl.h
+++ /dev/null
diff --git a/userspace/sys/sys/termios.h b/userspace/sys/sys/termios.h
deleted file mode 100644
index 9b9cdc4..0000000
--- a/userspace/sys/sys/termios.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <stdint.h>
-
-typedef uint32_t speed_t;
-typedef uint32_t DIR;
-
-#define B0 0000000 /* hang up */
-#define B50 0000001
-#define B75 0000002
-#define B110 0000003
-#define B134 0000004
-#define B150 0000005
-#define B200 0000006
-#define B300 0000007
-#define B600 0000010
-#define B1200 0000011
-#define B1800 0000012
-#define B2400 0000013
-#define B4800 0000014
-#define B9600 0000015
-#define B19200 0000016
-#define B38400 0000017
-
-struct direct{
- char d_name[256];
- int d_namlen
-};
-
diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c
deleted file mode 100644
index 10e035c..0000000
--- a/userspace/sys/syscalls.c
+++ /dev/null
@@ -1,158 +0,0 @@
-#include "kernel/syscalls.h"
-
-extern char **environ;
-//struct _reent *_impure_ptr;
-
-// generic syscall interface!
-
-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");
-
- asm("mov %0, %%eax"::"m"(call));
-
- asm("mov %0,%%edx"::"m"(p1));
- asm("mov %0,%%ecx"::"m"(p2));
- asm("mov %0,%%ebx"::"m"(p3));
-
- // interrrupt
- asm("int $0x80");
-
- // get return value
- asm("mov %%ebx, %0": "=b" (ebx));
-
- asm("popa");
-
- return ebx;
-}
-
-// fool os custom
-int readdir(const char *name,fs_dirent *dirs,int max)
-{
-
- return syscall(SYSCALL_READDIR,name,dirs,max);
-}
-
-int has_data_waiting()
-{
-
- return syscall(SYSCALL_HAS_DATA,0,0,0);
-}
-
-int fool_tune(int v1, int v2, int v3)
-{
-
- return syscall(SYSCALL_TUNE,v1,v2,v3);
-}
-
-void _exit(int ret)
-{
- _exit2(ret,environ);
-}
-
-void _exit2(int ret,char **environ)
-{
- return syscall(SYSCALL_EXIT,ret,environ,0);
-}
-
-//required by newlibc
-int close(int file)
-{
- return syscall(SYSCALL_CLOSE,file,0,0);
-}
-
-int isatty(int file)
-{
- return syscall(SYSCALL_ISATTY,file,0,0);
-}
-
-int lseek(int file, int ptr, int dir)
-{
- return syscall(SYSCALL_LSEEK,file,ptr,dir);
-}
-
-int read(int file, char *ptr, int len)
-{
-
- return syscall(SYSCALL_READ,file,ptr,len);
-}
-
-int open(const char *name, int flags, int mode)
-{
- return syscall(SYSCALL_OPEN,name,flags,mode);
-}
-
-int write(int file, char *ptr, int len)
-{
- return syscall(SYSCALL_WRITE,file,ptr,len);
-}
-
-int execve(char *name, char **argv, char **env)
-{
- return syscall(SYSCALL_EXECVE,name,argv,env);
-}
-
-uint32_t sbrk(int incr)
-{
- return syscall(SYSCALL_SBRK,incr,0,0);
-}
-
-int gettimeofday(struct timeval *tv, void *tz)
-{
- return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0);
-}
-
-int fork(void)
-{
- return syscall(SYSCALL_FORK,0,0,0);
-}
-
-int getpid(void)
-{
- return syscall(SYSCALL_GETPID,0,0,0);
-}
-
-int kill(int pid, int sig)
-{
- return syscall(SYSCALL_KILL,pid,sig,0);
-}
-
-int link(char *old, char *ne)
-{
- return syscall(SYSCALL_LINK,old,ne,0);
-}
-
-int unlink(char *name)
-{
- return syscall(SYSCALL_UNLINK,name,0,0);
-}
-
-int times(struct tms *buf)
-{
- return syscall(SYSCALL_TIMES,buf,0,0);
-}
-
-int wait(int *status)
-{
- return syscall(SYSCALL_WAIT,status,0,0);
-}
-
-int stat(const char *file, struct stat *st)
-{
- return syscall(SYSCALL_STAT,file,st,0);
-}
-
-int lstat(const char *file, struct stat *st)
-{
- return syscall(SYSCALL_LSTAT,file,st,0);
-}
-
-int fstat(int file, struct stat *st)
-{
- return syscall(SYSCALL_FSTAT,file,st,0);
-}
-
-