summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-23 14:00:52 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-23 14:00:52 +0100
commit6a3ef39feb635f529da9e36975ba77a26c1ff3b4 (patch)
tree4a65630f27d0779a5bc3cce1927b13465d10b466
parent608e66827d8aee1e55424c667777fac017501def (diff)
passing argv and argc to main, and fixed ELF load.
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/kernel.c5
-rw-r--r--kernel/syscalls.c67
-rw-r--r--userspace/shell.c13
-rw-r--r--userspace/simple.c3
5 files changed, 48 insertions, 42 deletions
diff --git a/kernel/config.h b/kernel/config.h
index ef0fa71..e48c63c 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -6,7 +6,7 @@
//#define FOOLOS_COMPILE_FLOPPY // compile floppy drivers
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-//#define FOOLOS_LOG_OFF // do not log anything
+#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 45c8fbb..6daa625 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -9,11 +9,13 @@
#endif
#define FOOLOS_MODULE_NAME "kernel"
+
+#include <stdint.h>
+
#include "config.h"
#include "asm/asm.h"
#include "lib/logger/log.h"
-#include "lib/int/stdint.h"
#include "lib/bool/bool.h"
#include "lib/buffer/ringbuffer.h"
@@ -34,7 +36,6 @@
#include "task.h"
-
#ifdef FOOLOS_COMPILE_FLOPPY
#include "floppy.h"
#endif
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 06caf2d..9f29750 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -140,9 +140,36 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max)
int syscall_execve(char *name, char **argv, char **env)
{
-#ifdef LOG_SYSCALLS
+ #ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X, argvs=0x%08X, env=0x%08X)", name,argv,env);
-#endif
+ #endif
+
+
+ char arg1[100];
+ char arg2[100];
+ char arg3[100];
+ char arg4[100];
+ char arg5[100];
+ char *argvcopy[]={arg1,arg2,arg3,arg4,arg5};
+
+ int argc=0;
+
+ if(argv!=NULL)
+ {
+ while(argv[argc+1]!=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);
+
+ argc++;
+ }
+ }
+ argvcopy[argc]=NULL;
//TODO: load ELF binary and move this to own compilation unit
@@ -151,7 +178,6 @@ int syscall_execve(char *name, char **argv, char **env)
ext2_check(EXT2_RAM_ADDRESS);
ext2_inode_content(EXT2_RAM_ADDRESS,name,0x800000,0x100000);
-
Elf32_Ehdr *elf;
elf=0x800000;
@@ -226,39 +252,16 @@ int syscall_execve(char *name, char **argv, char **env)
}
+ // argv / argc
+ asm("push %0" :: "r" (argvcopy));
+ asm("push %0" :: "r" (argc));
- /*
- // iterate over section headers
- for(int shidx=0;shidx<elf->e_shnum;shidx++)
- {
- Elf32_Shdr *shdr=0x800000+elf->e_shoff;//+shidx*elf->e_shentsize;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"-- SECTION HEADER %d --",shidx);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sh-name idx: %d",shdr->sh_name);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sh-type: %d",shdr->sh_type);
- while(1);
- }
- */
-
- static char arg1[]="x";;
- static char arg2[]="blah";
- static char arg3[]="foo";
- static char *args[]={arg1,arg2,arg3};
-
- asm("push %0" :: "r" (args)); //argv
- asm("push $3");//argc
-
- asm("push $0x800080");
+ // push addr and return to it
+ asm("push %0"::"r"(elf->e_entry));
asm("ret");
- while(1);
- /*
+ // this is never reached!
- // autorun "user-space" prog
- asm("push $10");//argv TODO: addresse
- asm("push $20"); //argc TODO: real number of params!
- asm("push $0x800000");
- asm("ret");
- */
}
diff --git a/userspace/shell.c b/userspace/shell.c
index ae39c1a..06a03d2 100644
--- a/userspace/shell.c
+++ b/userspace/shell.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdint.h>
-#include <assert.h>
#include <string.h>
+
#include "../fs/fs.h"
void hello() {
@@ -18,16 +18,15 @@ void prompt() {
int main(int argc, char **argv)
{
-// hello();
- FILE *input;
- input=fopen("input.txt","r");
+// hello();
+
char *buf=malloc(256);
while(1)
{
prompt();
- fgets(buf,255,input);
+ fgets(buf,255,stdin);
buf[strlen(buf)-1]=0; // remove \n
process(buf);
}
@@ -65,10 +64,12 @@ char **tokenize(char *buf)
i++;
}
token[c][t]=0;
+
// printf("token %i : <%s>\n",c, token[c]);
c++;
+ token[c]=NULL;
}
@@ -103,7 +104,7 @@ int process(char *buf)
}
else if(!strcmp(command,"exec"))
{
- execve(atoi(token[1]),0,0);
+ execve(atoi(token[1]),token,0);
}
else if(!strcmp(command,"echo"))
diff --git a/userspace/simple.c b/userspace/simple.c
index d4c48c2..5322584 100644
--- a/userspace/simple.c
+++ b/userspace/simple.c
@@ -1,12 +1,13 @@
int main(int argc, char **argv)
{
+
int i;
printf("argv: 0x%08X\n",argv);
for(i=0;i<argc;i++)
{
- printf("param %i: %08X: %s\n",i,argv[i],argv[i]);
+ if(!strcmp(argv[i],"-v"))puts("version 1");
}
puts("bye");