summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/syscalls.c61
-rw-r--r--userspace/foolshell.c26
-rw-r--r--userspace/simple.c15
-rw-r--r--userspace/sys/Makefile1
-rw-r--r--userspace/sys/crt0.S9
-rw-r--r--userspace/sys/syscalls.c11
-rw-r--r--userspace/test.c25
7 files changed, 90 insertions, 58 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index e4cb6cc..4023dfe 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -191,6 +191,49 @@ int syscall_execve(char *name, char **argv, char **env)
}
argvcopy[argc]=NULL;
+ //
+ char *env1="PS1=$ ";
+ char *env2="PATH=/bin";
+ char environstr[256];
+ char **oldenviron=env;
+ char **environ=0xf00001;
+
+ static bool first=true;
+ if(first)
+ {
+ environ[0]=env1;
+ environ[1]=env2;
+ environ[3]=NULL;
+ first=false;
+ }
+ else
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"environ: (0x%08X)",oldenviron);
+ int i=0;
+ int k=-1;
+ while(oldenviron[i]!=NULL)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy env: %s (0x%08X)",oldenviron[i],oldenviron[i]);
+ int start=k+1;
+ int j=-1;
+ do{
+ j++;
+ k++;
+ environstr[k]=oldenviron[i][j];
+ }while(oldenviron[i][j]!=0);
+
+ environ[i]=&environstr[start];
+ i++;
+ }
+
+ environ[i]=NULL;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[0],environ[0]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[1],environ[1]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[2],environ[2]);
+
+ }
+
+
//TODO: load ELF binary and move this to own compilation unit
@@ -278,10 +321,18 @@ int syscall_execve(char *name, char **argv, char **env)
}
- // argv / argc
- //asm("mov $0xf00000,%esp"); // set stack pointer
+
+ int i=0;
+ do{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"envvar %d : 0x%08X : %s" ,i,environ[i],environ[i]);
+ i++;
+ }while(environ[i]!=NULL);
+
+
+ asm("mov $0xf00000,%esp"); // set stack pointer
asm("push %0" :: "r" (argvcopy));
asm("push %0" :: "r" (argc));
+ asm("push %0" :: "r" (environ));
// push addr and return to it
asm("push %0"::"r"(elf->e_entry));
@@ -342,14 +393,14 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
}
-int syscall_exit(int ret, int none1, int none2)
+int syscall_exit(int ret, char **env, int none2)
{
#ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d)", ret);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d) (env=0x%08X)", ret, env);
#endif
static char *argv[]={"shell","--silent",NULL};
- syscall_execve("/bin/foolshell",argv,0); // start shell
+ syscall_execve("/bin/foolshell",argv,env); // start shell
}
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 819c5d6..7a4f616 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -3,20 +3,21 @@
#include <stdbool.h>
#include <string.h>
+extern char **environ;
//
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"
+ "--------------------------------------------------------------------\n\n"
"type 'help' anytime to show shell built-ins\n"
"or execute user programms that are in the '/bin' directory (e.g. ls)\n"
);
@@ -24,9 +25,8 @@ void hello()
void prompt()
{
- printf(
- "$ "
- );
+ printf("%s",getenv("PS1"));
+ printf("%s",getenv("PS1"));
}
int main(int argc, char **argv)
@@ -125,7 +125,7 @@ int process(char *buf)
}
else if(!strcmp(command,"getenv"))
{
- printf("%s = %s \n",token[1],getenv(token[1]));
+ printf("%s = %s(0x%08X) \n",token[1],getenv(token[1]),getenv(token[1]));
}
else if(!strcmp(command,"putenv"))
{
@@ -139,7 +139,7 @@ int process(char *buf)
execve(token[0],token,0);
char buf[256];
sprintf(buf,"/bin/%s",token[0]);
- execve(buf,token,0);
+ execve(buf,token,environ);
puts("foolshell: command not found");
}
diff --git a/userspace/simple.c b/userspace/simple.c
index 5322584..bd42d9c 100644
--- a/userspace/simple.c
+++ b/userspace/simple.c
@@ -1,14 +1,23 @@
+#include <stdlib.h>
+
+extern char **environ;
int main(int argc, char **argv)
{
- int i;
printf("argv: 0x%08X\n",argv);
+ printf("env: 0x%08X\n",environ);
+
+ putenv("test=11");
- for(i=0;i<argc;i++)
+
+ int i=0;
+ while(environ[i]!=NULL)
{
- if(!strcmp(argv[i],"-v"))puts("version 1");
+ printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]);
+ i++;
}
+
puts("bye");
return 0;
diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile
index 374d490..9917d90 100644
--- a/userspace/sys/Makefile
+++ b/userspace/sys/Makefile
@@ -12,6 +12,7 @@ library_install: all
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
diff --git a/userspace/sys/crt0.S b/userspace/sys/crt0.S
index 33e5d32..025c21b 100644
--- a/userspace/sys/crt0.S
+++ b/userspace/sys/crt0.S
@@ -1,14 +1,15 @@
.global _start
-.extern main
-.extern exit
-
_start:
+pop %eax
+mov %eax, environ
+
call main
+push environ
push %eax
-call _exit
+call _exit2
# this should never be reached anyway!
.wait:
diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c
index 25c48b0..9456ea4 100644
--- a/userspace/sys/syscalls.c
+++ b/userspace/sys/syscalls.c
@@ -1,15 +1,10 @@
#include "kernel/syscalls.h"
-/*
-char *__env3[]={0};
-char *__env1[]={"a=10","b=20"};
-char *__env2[]={"dupa=test2"};
-char **environ={__env1,__env2,__env3};
-*/
+char **environ;
-void _exit(int ret)
+void _exit2(int ret,char **environ)
{
- return syscall(SYSCALL_EXIT,ret,0,0);
+ return syscall(SYSCALL_EXIT,ret,environ,0);
}
// generic syscall interface!
diff --git a/userspace/test.c b/userspace/test.c
deleted file mode 100644
index 12226d3..0000000
--- a/userspace/test.c
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "syscalls.h>
-
-int main()
-{
- int x=atoi("33");
- int *mem=0x80000;
- int *mem2=0x80010;
-
- int y=0;
- *mem=x;
-
- while(1)
- {
- printf("test printf");
-// write(1,"dupa",4);
-// y=example_call();
- y++;
- *mem2=y;
- }
-
-
-}