summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-24 01:10:32 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-24 01:10:32 +0100
commit0d36b950f6a560a0312f2dcd326d3bb5362af370 (patch)
tree6d417483e22589e5ca07bf98a0bd8099ae5882e8 /userspace
parentec0ba7bc40854eab6a1cdb41364f41f9c11407e1 (diff)
playing with enviroment variables
Diffstat (limited to 'userspace')
-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
6 files changed, 34 insertions, 53 deletions
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;
- }
-
-
-}