diff --git a/fs/exec.c b/fs/exec.c index b38f3b21636b9e1a2914307bbf746995b3449234..95fd765b9fc090bb2b44971e3c401f8441d663be 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -14,7 +14,7 @@ extern int sys_close(int fd); -static unsigned long * create_tables(char * p,int argc,int envc) { +unsigned long * create_tables(char * p,int argc,int envc) { unsigned long *argv,*envp; unsigned long * sp; @@ -52,7 +52,7 @@ int count(char ** argv) { return i; } -static unsigned long copy_strings(int argc,char ** argv,unsigned long *page, +unsigned long copy_strings(int argc,char ** argv,unsigned long *page, unsigned long p, int from_kmem) { char *tmp, *pag; int len, offset = 0; @@ -82,25 +82,25 @@ static unsigned long copy_strings(int argc,char ** argv,unsigned long *page, set_fs(old_fs); return 0; } - } - while (len) { - --p; --tmp; --len; - if (--offset < 0) { - offset = p % PAGE_SIZE; - if (from_kmem==2) - set_fs(old_fs); - if (!(pag = (char *) page[p/PAGE_SIZE])) { - page[p / PAGE_SIZE] = (unsigned long*) get_free_page(); - pag = (char*) page[p / PAGE_SIZE]; - - if (!pag) - return 0; + while (len) { + --p; --tmp; --len; + if (--offset < 0) { + offset = p % PAGE_SIZE; + if (from_kmem==2) + set_fs(old_fs); + if (!(pag = (char *) page[p/PAGE_SIZE])) { + page[p / PAGE_SIZE] = (unsigned long*) get_free_page(); + pag = (char*) page[p / PAGE_SIZE]; + + if (!pag) + return 0; + } + if (from_kmem==2) + set_fs(new_fs); } - if (from_kmem==2) - set_fs(new_fs); + *(pag + offset) = get_fs_byte(tmp); } - *(pag + offset) = get_fs_byte(tmp); } if (from_kmem==2) @@ -228,7 +228,6 @@ int do_execve(unsigned long * eip,long tmp,char * filename, current->start_stack = p & 0xfffff000; current->suid = current->euid = e_uid; current->sgid = current->egid = e_gid; - printk("0x%x, 0x%x, eip is 0x%x, 0x%x\n", ex.a_entry, p, eip[0], eip[3]); eip[0] = ex.a_entry; eip[3] = p; return 0; diff --git a/kernel/main.c b/kernel/main.c index b353a25f894efd5ec096a89d53e3b125a86a0b74..e5b8522fd3f527c46340104719273abc5c1d4b87 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -81,7 +81,7 @@ static char * argv_rc[] = { "/bin/sh", NULL }; static char * envp_rc[] = { "HOME=/", NULL ,NULL }; //static char * argv[] = { "-/bin/sh",NULL }; -static char * argv[] = { "/etc/rc",NULL }; +static char * argv[] = { "/usrs/", NULL }; static char * envp[] = { "HOME=/usr/root", NULL, NULL }; void main() { @@ -170,7 +170,7 @@ static void run_sh() { int pid; if (!(pid=fork())) { printf("read to start shell\n"); - execve("/usr/bin/cat",argv,envp); + execve("/tmp/et",argv,envp); } } diff --git a/tools/Makefile b/tools/Makefile index 068a861be71656ce953b9dfaf2f04c31494b0ef3..42a04ec12bdd658343a9d76c2cbfe4ed17bfdd91 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -10,13 +10,17 @@ et: myld test myld: myld.c gcc -o myld myld.c -test: test.o - ld -Ttext 0x0 --oformat binary -o test test.o +test: test.o crt0.o + ld -Ttext 0x0 --oformat binary -m elf_i386 -o test crt0.o test.o ../lib/lib.a -test.o: test.S - as -o test.o test.S +test.o: test.c + gcc -m32 -ffreestanding -c -o test.o test.c + +crt0.o: crt0.S + gcc -c -m32 -o crt0.o crt0.S clean: + -rm crt0.o -rm test -rm test.o -rm myld diff --git a/tools/crt0.S b/tools/crt0.S new file mode 100644 index 0000000000000000000000000000000000000000..bd5e46dc3b5e65649bdcf4c3691444e23823effa --- /dev/null +++ b/tools/crt0.S @@ -0,0 +1,16 @@ +.code32 + +.text + +.globl _environ, _start + +_start: + movl 8(%esp),%eax + movl %eax,_environ + call main + ret + +.data + +_environ: + .long 0 diff --git a/tools/test.c b/tools/test.c new file mode 100644 index 0000000000000000000000000000000000000000..3a60a2150caaaf168d1d5c28d669559caec5a482 --- /dev/null +++ b/tools/test.c @@ -0,0 +1,17 @@ +int errno; + +int main(int argc, char** argv, char** envp) { + write(1, "argv\n", 5); + while (*argv) { + write(1, *argv, 3); + argv++; + } + + write(1, "envp\n", 5); + while (*envp) { + write(1, *envp, 4); + envp++; + } + + return 0; +}