summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-23 23:26:26 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-23 23:26:26 +0100
commitec0ba7bc40854eab6a1cdb41364f41f9c11407e1 (patch)
tree88f3896c70ac32bc1b70dcd7ebddbbe595c6608f
parent50300fa573bf2bc00f9732e812d54ab77cf03dd7 (diff)
foolshell and syscalls improvememets
-rw-r--r--Makefile2
-rw-r--r--asm/int_syscall_handler.asm2
-rw-r--r--fs/ext2.c48
-rw-r--r--fs/fs.c4
-rw-r--r--fs/fs.h3
-rw-r--r--kernel/kernel.c4
-rw-r--r--kernel/keyboard.c6
-rw-r--r--kernel/syscalls.c16
-rw-r--r--userspace/Makefile16
-rw-r--r--userspace/foolshell.c (renamed from userspace/shell.c)33
-rw-r--r--userspace/ls.c8
11 files changed, 100 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index ecd38ec..e33c0fb 100644
--- a/Makefile
+++ b/Makefile
@@ -144,7 +144,7 @@ $(FOOLOS): $(IMG_FILLUP) $(BIN_KERNEL) $(SUBDIRS)
#data starts at 0x168000
dd if=$(BIN_MP) of=$@ bs=512 seek=842 conv=notrunc
dd if=$(BIN_FOOLFONT) of=$@ bs=512 seek=843 conv=notrunc
- dd if=$(IMG_USERSPACE) of=$@ bs=512 seek=846 conv=notrunc
+ dd if=$(IMG_USERSPACE) of=$@ bs=512 seek=2894 conv=notrunc
############ virtual machines stuff ############
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
index f90ba51..50202d3 100644
--- a/asm/int_syscall_handler.asm
+++ b/asm/int_syscall_handler.asm
@@ -156,5 +156,5 @@ call_execve:
sti
call syscall_execve
- jmp $ ; this should never return TODO: pop stack!?
+ jmp done_blocking
diff --git a/fs/ext2.c b/fs/ext2.c
index 6920b40..4db858f 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -3,6 +3,8 @@
#define FOOLOS_MODULE_NAME "ext2"
+#include <stdbool.h>
+
#include "lib/int/stdint.h"
#include "lib/logger/log.h"
#include "fs.h"
@@ -240,11 +242,53 @@ int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max)
}
-//TODO!!!
-int ext2_filename_to_inode(char *path)
+int ext2_filename_to_inode_traverse(uint8_t *ram, char *path,int inode_start)
{
+ bool final=false;
+
+ // skip leading slashes
+ while(*path=='/')path++;
+ char *first=path;
+
+ while(*path!='/'&&*path!=0)path++;
+ char *last=path;
+
+ if(*path==0)final=true;
+ else(*path=0);
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"looking for %s '%s' in inode: %d",final?"file":"dir",first,inode_start);
+
+ fs_dirent dirs[15];
+ int count= ext2_read_dir(ram, inode_start,dirs,15); // get dir
+
+ for(int i=0;i<count;i++)
+ {
+ if(true==strcmp(first,dirs[i].name,0))
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"found: %s (%s)",first,dirs[i].type==FS_FILE_TYPE_DIR?"dir":"file");
+ if(final)return dirs[i].inode;
+ return ext2_filename_to_inode_traverse(ram,last+1,dirs[i].inode);
+ }
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"no match: %s",dirs[i].name);
+ }
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"file not found!");
+ return -1;
+
+
+}
+int ext2_filename_to_inode(uint8_t *ram, char *path)
+{
+ char buf[256];
+ for(int i=0;i<256;i++)
+ {
+ buf[i]=path[i];
+ if(buf[i]==0)break;
+ }
+
+ return ext2_filename_to_inode_traverse(ram,buf,2);
}
int ext2_read_dir(uint8_t *ram, int inode_nr,fs_dirent *dirs,int max)
diff --git a/fs/fs.c b/fs/fs.c
index 5f5ea75..8052d5f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -9,7 +9,9 @@
int fs_readdir(const char *name,fs_dirent *dirs,int max)
{
- return ext2_read_dir(EXT2_RAM_ADDRESS, name,dirs,max); // TODO: hardcoded, fix this
+ int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,name);
+ if(inode_nr<1)return -1;
+ return ext2_read_dir(EXT2_RAM_ADDRESS, inode_nr,dirs,max); // TODO: hardcoded, fix this
}
diff --git a/fs/fs.h b/fs/fs.h
index 77b53ad..7ced0a7 100644
--- a/fs/fs.h
+++ b/fs/fs.h
@@ -3,7 +3,8 @@
#include <stdint.h>
-#define EXT2_RAM_ADDRESS 0x168800
+
+#define EXT2_RAM_ADDRESS (0x168800+0x100000)
enum FS_FILE_TYPE{
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 66ca21a..684b70d 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -103,9 +103,9 @@ void kernel_main(uint32_t initial_stack, int mp)
// ringbuffer for stdin!
ringbuffer_init();
- // load and run inode 15 (shell)
+ // load and run foolshell
// we will come back into the kernel only on interrupts...
- syscall_execve(15,0,0);
+ syscall_execve("/bin/foolshell",0,0);
//
diff --git a/kernel/keyboard.c b/kernel/keyboard.c
index 49c2fa0..074c495 100644
--- a/kernel/keyboard.c
+++ b/kernel/keyboard.c
@@ -112,6 +112,7 @@ void keyboard_handle(uint8_t in)
uint8_t break_key_shift_r=0xb6;
uint8_t break_caps_lock=0xba;
+ uint8_t break_slash=0xb5;
if(make_key_shift_l==in)shift_l=true;
if(break_key_shift_l==in)shift_l=false;;
@@ -126,6 +127,11 @@ void keyboard_handle(uint8_t in)
bool match=false;
// optimize this!
+ if(break_slash==in)
+ {
+ ascii='/';
+ match=true;
+ }
if(break_key_space==in)
{
ascii=' ';
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 401a5aa..e4cb6cc 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -158,9 +158,12 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max)
int syscall_execve(char *name, char **argv, char **env)
{
#ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X, argvs=0x%08X, env=0x%08X)", name,argv,env);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv,env);
#endif
+ int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,name);
+ if(inode_nr<1)return -1;
+
char arg1[100];
char arg2[100];
@@ -173,15 +176,15 @@ int syscall_execve(char *name, char **argv, char **env)
if(argv!=NULL)
{
- while(argv[argc+1]!=NULL)
+ while(argv[argc]!=NULL)
{
//log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"arg at 0x%08X: %s", argv[argc],argv[argc]);
int i=-1;
do{
i++;
- argvcopy[argc][i]=argv[argc+1][i];
- }while(argv[argc+1][i]!=0);
+ argvcopy[argc][i]=argv[argc][i];
+ }while(argv[argc][i]!=0);
argc++;
}
@@ -193,7 +196,7 @@ int syscall_execve(char *name, char **argv, char **env)
//load binary
ext2_check(EXT2_RAM_ADDRESS);
- ext2_inode_content(EXT2_RAM_ADDRESS,name,0x800000,0x100000);
+ ext2_inode_content(EXT2_RAM_ADDRESS,inode_nr,0x800000,0x100000);
Elf32_Ehdr *elf;
elf=0x800000;
@@ -276,6 +279,7 @@ int syscall_execve(char *name, char **argv, char **env)
}
// argv / argc
+ //asm("mov $0xf00000,%esp"); // set stack pointer
asm("push %0" :: "r" (argvcopy));
asm("push %0" :: "r" (argc));
@@ -345,7 +349,7 @@ int syscall_exit(int ret, int none1, int none2)
#endif
static char *argv[]={"shell","--silent",NULL};
- syscall_execve(15,argv,0); // start shell
+ syscall_execve("/bin/foolshell",argv,0); // start shell
}
diff --git a/userspace/Makefile b/userspace/Makefile
index 55e78bc..3327375 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -4,7 +4,7 @@ CFLAGS=
CFLAGS+=-w
CFLAGS+=-std=gnu11
-PROGS=shell simple brainfuck add checker ls clear
+PROGS=foolshell simple brainfuck add checker ls clear
ext2.img: $(PROGS)
dd if=/dev/zero of=ext2.img bs=512 count=5000
@@ -12,17 +12,19 @@ ext2.img: $(PROGS)
mkdir mnt
sudo mount ext2.img mnt
sudo chown miguel mnt
- mkdir mnt/miguel
- echo "hello one" > mnt/miguel/test1.txt
- echo "hello two" > mnt/test2.txt
- cp $^ mnt
- cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt
+ mkdir -p mnt/home/miguel
+ echo "hello one" > mnt/home/miguel/test1.txt
+ mkdir -p mnt/bin
+ cp $^ mnt/bin
+ cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin
+ mkdir -p mnt/etc
+ echo "127.0.0.1 localhost" > mnt/etc/hosts
sync
sudo umount mnt
rm mnt -rf
brainfuck: brainfuck.o
-shell: shell.o
+foolshell: foolshell.o
simple: simple.o
add: add.o
checker: checker.o
diff --git a/userspace/shell.c b/userspace/foolshell.c
index bb8b873..819c5d6 100644
--- a/userspace/shell.c
+++ b/userspace/foolshell.c
@@ -3,28 +3,22 @@
#include <stdbool.h>
#include <string.h>
-// ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS
//
void hello()
{
+ // ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS
puts(
- " ______ __ ____ _____\n"
- " / ____/___ ____ / / / __ \\/ ___/\n"
- " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
- " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
- " /_/ \\____/\\____/_/ \\____//____/ \n"
- "\n"
-
-
-
-
-
-
+ " ______ __ ____ _____ \n"
+ " / ____/___ ____ / / / __ \\/ ___/ \n"
+ " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
+ " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
+ " /_/ \\____/\\____/_/ \\____//____/ \n"
+ " \n"
"Welcome to FoolShell v0.2 (Compiled on " __DATE__ " at " __TIME__ "\n"
"--------------------------------------------------------------------\n\n"
"type 'help' anytime to show shell built-ins\n"
- "or execute programms/commands that are on your $PATH (e.g. ls)\n"
+ "or execute user programms that are in the '/bin' directory (e.g. ls)\n"
);
}
@@ -112,12 +106,7 @@ int process(char *buf)
if(!strcmp(command,"help"))
{
- puts("foolshell: supported built-in commands: 'help', 'echo [string]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'");
- }
- else if(!strcmp(command,"exec"))
- {
- execve(atoi(token[1]),token,0);
-
+ puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'");
}
else if(!strcmp(command,"echo"))
{
@@ -147,6 +136,10 @@ int process(char *buf)
}
else
{
+ execve(token[0],token,0);
+ char buf[256];
+ sprintf(buf,"/bin/%s",token[0]);
+ execve(buf,token,0);
puts("foolshell: command not found");
}
diff --git a/userspace/ls.c b/userspace/ls.c
index 50c733b..5b5034b 100644
--- a/userspace/ls.c
+++ b/userspace/ls.c
@@ -15,7 +15,13 @@ int main(int argc, char **argv)
return 0;
}
- int ls=readdir(atoi(argv[1]),dirs,25);
+ char *dir=argv[1];
+ int ls=readdir(dir,dirs,25);
+ if(ls==-1)
+ {
+ printf("%s: file or directory '%s' not found.\n",argv[0],dir);
+ return 0;
+ }
int i;