summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-21 12:56:51 +0200
committerMiguel <m.i@gmx.at>2018-09-21 12:56:51 +0200
commitc298ca7e6beaad0bcc32af6d4cf50d41b79f13b7 (patch)
treeb28e9c052cff3264439cad3c41b29262c60ba6ac
parentf5281689c95758f17628f0286e0265ecf3385a8e (diff)
fix framebufffer/ textmode and clean userspace a little bit more
-rw-r--r--grubiso/boot/grub/grub.cfg2
-rw-r--r--kernel/kernel.c3
-rw-r--r--kernel/scheduler.c7
-rw-r--r--kernel/syscalls.c19
-rw-r--r--kernel/syscalls.h5
-rw-r--r--userspace/date.c19
-rw-r--r--userspace/fd.c8
-rw-r--r--userspace/fsh.c (renamed from userspace/foolshell.c)33
-rw-r--r--userspace/init.c16
-rw-r--r--userspace/newcalls.h2
-rw-r--r--userspace/nonl.c15
-rw-r--r--userspace/piper.c27
-rw-r--r--userspace/task1.c1
-rw-r--r--userspace/test_env.c (renamed from userspace/simple.c)0
-rw-r--r--userspace/test_math.c (renamed from userspace/test-math.c)0
-rw-r--r--userspace/test_sysfs.c (renamed from userspace/sysfs_write.c)0
16 files changed, 81 insertions, 76 deletions
diff --git a/grubiso/boot/grub/grub.cfg b/grubiso/boot/grub/grub.cfg
index 08f1fe1..9c78bfb 100644
--- a/grubiso/boot/grub/grub.cfg
+++ b/grubiso/boot/grub/grub.cfg
@@ -1,4 +1,4 @@
-set timeout=0 //seconds
+set timeout=1 //seconds
menuentry "FoolOS (640x480x32)" {
multiboot /boot/foolos.bin
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 247e978..ab4332a 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -119,6 +119,9 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint32_t addr= ext2_inode_blockstart( VMEM_EXT2_RAMIMAGE,inode,0);
vesa_init(cfg_multiboot->vbe_control_info,cfg_multiboot->vbe_mode_info,addr);
+ // -- STD STREAMS -- //
+ fd_init_std_streams(0,cfg_multiboot->framebuffer_type!=2);
+
// -- KB -- //
klog("Keyboard init ...");
keyboard_init(0);
diff --git a/kernel/scheduler.c b/kernel/scheduler.c
index c13fd4e..667abf8 100644
--- a/kernel/scheduler.c
+++ b/kernel/scheduler.c
@@ -82,8 +82,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir)
task_list[cpu][0].vmem=dir;
task_list[cpu][0].esp = VMEM_CPU_STACK_TOP-0x200;
task_list[cpu][0].esp0 = 0; // esp0 not needed by kernel space tasks
- fd_init_std_streams(task_list[cpu][0].pid);
-
+ fd_init_std_streams(task_list[cpu][0].pid,0);
// this will go to userspace
task_list[cpu][1].parent=0;
@@ -94,7 +93,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir)
task_list[cpu][1].vmem=dir;
task_list[cpu][1].esp = kballoc(4)+4*4096-0x200; // 4 pages stack
task_list[cpu][1].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks
- fd_init_std_streams(task_list[cpu][1].pid);
+ fd_init_std_streams(task_list[cpu][1].pid,0);
// sleeper
@@ -106,7 +105,7 @@ volatile void scheduler_init(uint32_t cpu, void *dir)
task_list[cpu][2].vmem=dir;
task_list[cpu][2].esp = kballoc(4)+4*4096-0x200; // 4 pages stack
task_list[cpu][2].esp0 =kballoc(4)+4*4096; // esp0 not needed by kernel space tasks
- fd_init_std_streams(task_list[cpu][2].pid);
+ fd_init_std_streams(task_list[cpu][2].pid,0);
// stacks
task_pusha(task_list[cpu][0].esp);
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index edc4751..2952c11 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -30,14 +30,24 @@
static fd fds[MAX_PID][MAX_FD];
static bool open_fd[MAX_PID][MAX_FD];
-void fd_init_std_streams(uint32_t pid)
+void fd_init_std_streams(uint32_t pid,bool fb)
{
- if(pid==0)
+ static bool first=true;
+ if(pid==0&&first)
{
+ first=false;
//stdin / stdout /stderr
fds[0][0]=fd_from_ringbuffer();
- fds[0][1]=fd_from_fb_term();
- fds[0][2]=fd_from_fb_term();
+ if(!fb) // ega text mode
+ {
+ fds[0][1]=fd_from_term();
+ fds[0][2]=fd_from_term();
+ }
+ else
+ {
+ fds[0][1]=fd_from_fb_term();
+ fds[0][2]=fd_from_fb_term();
+ }
open_fd[0][0]=true;
open_fd[0][1]=true;
open_fd[0][2]=true;
@@ -52,6 +62,7 @@ void fd_init_std_streams(uint32_t pid)
open_fd[pid][2]=true;
}
}
+//
/** errno helper */
void set_errno(int no)
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index d90e314..7216a46 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -12,6 +12,9 @@
*
*/
+#include <stdint.h>
+#include <stdbool.h>
+
#define SYSCALL_EXIT 60
#define SYSCALL_EXECVE 64
#define SYSCALL_FORK 72
@@ -40,7 +43,7 @@
#define SYSCALL_DUP2 86
/** Todo move somewhere else and init per process , think how to make thread safe */
-void fd_init_std_streams(uint32_t pid);
+void fd_init_std_streams(uint32_t pid, bool use_framebuffer);
/** returns string representation of the syscall from its number */
char* syscall_get_name(uint32_t num);
diff --git a/userspace/date.c b/userspace/date.c
new file mode 100644
index 0000000..64b8dfc
--- /dev/null
+++ b/userspace/date.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+
+int main(int argc, char **argv)
+{
+ time_t ltime;
+ time(&ltime);
+ printf("%s", ctime(&ltime));
+ return 0;
+}
+
+
+
+
+
diff --git a/userspace/fd.c b/userspace/fd.c
deleted file mode 100644
index 80ffd20..0000000
--- a/userspace/fd.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-
-int main()
-{
-// dup(stdout);
- printf("dup\n");
-}
diff --git a/userspace/foolshell.c b/userspace/fsh.c
index 4d011da..4df4e4e 100644
--- a/userspace/foolshell.c
+++ b/userspace/fsh.c
@@ -6,6 +6,8 @@
*
* A minimalsitic and naive shell developed along the Fool OS kernel.
* TODO: Free tokenizer / dynamic size!
+ * TODO: & with pipes
+ * TODO: > <
*/
#include <stdio.h>
@@ -14,7 +16,7 @@
#include <string.h>
#include <errno.h>
#include <string.h>
-
+#include "interface/fs.h"
#include "newcalls.h"
@@ -39,7 +41,7 @@ void help()
"'cd [dir]' - change directory (set $PWD)\n"
"'[binary] [params...]' - run a binary\n"
"'[binary] [params...] &' - run a binary in background\n"
- " TODO - pipes\n"
+ " | - pipes\n"
"'help' - show this message\n"
"'exit' - exit running foolshell\n\n");
@@ -290,8 +292,29 @@ bool setpwd(char *path)
bool cd(char *path)
{
char buf[256];
- if(path==NULL)return setpwd(getenv("HOME"));
- if(path[0]=='/')return setpwd(path);
- sprintf(buf,"%s/%s",getenv("PWD"),path);
+ // home
+ if(path==NULL)
+ {
+ sprintf(buf,"%s",getenv("HOME"));
+ }
+ // absolute
+ else if(path[0]=='/')
+ {
+ sprintf(buf,"%s",path);
+ }
+ // relative
+ else
+ {
+ sprintf(buf,"%s/%s",getenv("PWD"),path);
+ }
+
+ // check if exists
+ fs_dirent dirs;
+ if(-1==_readdir(buf,&dirs,0))
+ {
+ printf("directory not found!\n");
+ return false;
+ }
+
return setpwd(buf);
}
diff --git a/userspace/init.c b/userspace/init.c
index 8530368..0a3b870 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -3,21 +3,19 @@
int main(int argc, char **argv)
{
- char *argv1[]={"/bin/foolshell",0};
+ char *argv1[]={"/bin/fsh",0};
char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0};
- time_t ltime;
- time(&ltime);
- printf("fool-init: current time: %s\n", ctime(&ltime));
-
// loop forever and spawn shells if the top-shell exits
while(1)
{
int pid=_fork();
+
if(pid==0)
{
- _execve("/bin/foolshell",argv1,env1); // replace process with our foolshell :)
+ printf("fool-init: spawning fool-shell\n");
+ _execve("/bin/fsh",argv1,env1); // replace process with our foolshell :)
while(1) puts("FATAL ERROR: Something terrible happened. Unable to Execute SHELL!\n");
}
@@ -25,9 +23,9 @@ int main(int argc, char **argv)
// and respawn SHELL
_wait(pid);
- printf("fool-init: catched exit of process %d.\n",pid);
- printf("fool-init: respawning a new fool-shell\n");
- }
+ printf("fool-init: respawning new fool-shell\n");
+
+ }
return 0;
}
diff --git a/userspace/newcalls.h b/userspace/newcalls.h
index 4568711..20d8ffd 100644
--- a/userspace/newcalls.h
+++ b/userspace/newcalls.h
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////
-// this syscall will be moved to newlib later!
+// this syscall will be moved to newlib later! TODO!
#define SYSCALL_CLONE 83
#define SYSCALL_PIPE 84
#define SYSCALL_DUP2 86
diff --git a/userspace/nonl.c b/userspace/nonl.c
deleted file mode 100644
index 3940453..0000000
--- a/userspace/nonl.c
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-void atex()
-{
- printf("atex\n");
-}
-int main()
-{
- printf("nonextline");
-// fflush(stdout);
-
-// atexit(&atex);
- return EXIT_SUCCESS;
-}
diff --git a/userspace/piper.c b/userspace/piper.c
deleted file mode 100644
index 80cbd27..0000000
--- a/userspace/piper.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <stdio.h>
-#include "newcalls.h"
-
-extern **environ;
-
-int main()
-{
- int fds[2];
- _pipe(fds);
-
- int pid=_fork();
-
- if(pid)
- {
- _close(fds[1]);
- _dup2(fds[0],0); // replace stdin with the read-end of pipe
- char *args[]={"grep",NULL};
- _execve("/bin/grep",args,environ);
- }
- else
- {
- _close(fds[0]);
- _dup2(fds[1],1); // replace stdout with the write-end of our pipe
- char *args[]={"cat","hello.txt",0};
- _execve("/bin/cat",args,environ);
- }
-}
diff --git a/userspace/task1.c b/userspace/task1.c
index 793b7f8..e220424 100644
--- a/userspace/task1.c
+++ b/userspace/task1.c
@@ -7,7 +7,6 @@ static ULL fib1_cached_value=0;
static ULL fib2_cached_index=1;
static ULL fib2_cached_value=1;
-
ULL fib(ULL i)
{
if(i==0)return 0;
diff --git a/userspace/simple.c b/userspace/test_env.c
index 0a04791..0a04791 100644
--- a/userspace/simple.c
+++ b/userspace/test_env.c
diff --git a/userspace/test-math.c b/userspace/test_math.c
index 9327c19..9327c19 100644
--- a/userspace/test-math.c
+++ b/userspace/test_math.c
diff --git a/userspace/sysfs_write.c b/userspace/test_sysfs.c
index 9f91632..9f91632 100644
--- a/userspace/sysfs_write.c
+++ b/userspace/test_sysfs.c