diff --git a/bin/ls/main.c b/bin/ls/main.c index 4650cb0..6092b77 100644 --- a/bin/ls/main.c +++ b/bin/ls/main.c @@ -58,6 +58,13 @@ FILE *fd; struct directoryEntry *dirEntry = 0x0; + unsigned int *segbase = 0x0; + + __asm __volatile("movl %%gs:0, %0" : "=r" (segbase)); + + printf("Segbase: 0x%X - 0x%X\n", segbase, &segbase); + + printf("argc: %i - %i\n", argc, argv[0]); exit(0); diff --git a/lib/ubix/sstart.c b/lib/ubix/sstart.c index 6ab626f..8739da9 100644 --- a/lib/ubix/sstart.c +++ b/lib/ubix/sstart.c @@ -10,11 +10,13 @@ //argv = ≈ //argc = *(long *)(void *)(argv - 1); //argc = *(long *)(void *)(argv - 1); -printf("0x%X}}", ap); +printf("{0x%X}", ap); argc = *ap++; argv = (char **)ap; ap += argc + 1; env = (char **)ap; + while (*ap++ != 0) + ; environ = env; // if (env[0] != 0) diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index 7f79293..2f8b5dc 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -331,24 +331,21 @@ tmp[0] = binaryHeader->eEntry; tmp[3] = STACK_ADDR - 12; - //tmp = (uInt32 *) STACK_ADDR - 2; tmp = (uint32_t *) _current->tss.esp; - /* - if ( _current->id > 4 ) - kprintf( "argv[0]: [%s]\n", argv[0] ); - */ - kprintf( "argv: [0x%X]\n", argv ); - *tmp-- = 0x1; - *tmp-- = 0x0; - *tmp-- = 0x0; - *tmp-- = 0x0; - - /* - tmp[0] = (uint32_t) argv; - tmp[1] = (uint32_t) argv; - */ + *tmp++ = 0x0; // Stack EIP Return Addr + *tmp++ = tmp + 1; // Pointer To AP + *tmp++ = 0x1; // ARGC + *tmp++ = 0x0; // ARGV + *tmp++ = 0x0; // ARGV TERM + *tmp++ = 0x0; // ENV + *tmp++ = 0x0; // ENV TERM + *tmp++ = 0x0; // AUX 1.A + *tmp++ = 0x0; // AUX 1.B + *tmp++ = 0x0; // AUX TERM + *tmp++ = 0x0; // AUX TERM + *tmp++ = 0x0; // TERM /* Switch Back To The Kernels VM Space */ asm volatile( @@ -634,31 +631,37 @@ iFrame->ebp = STACK_ADDR; iFrame->eip = binaryHeader->eEntry; - iFrame->user_esp = ((uint32_t) STACK_ADDR) - (sizeof(uint32_t) * (argc + 5)); + iFrame->user_esp = ((uint32_t) STACK_ADDR) - ((sizeof(uint32_t) * (argc + 8 + 1)) + (sizeof(Elf32_Auxinfo) * 2)); tmp = (void *) iFrame->user_esp; //MrOlsen 2017-11-14 iFrame->user_ebp; - *tmp++ = 0x0; - *tmp++ = tmp + 1; + *tmp++ = 0x0; // Stack EIP Return Addr + *tmp++ = tmp + 1; // Pointer To AP - //kprintf( "STACK: 0x%X, ESP0: 0x%X\n", iFrame->user_esp, _current->tss.esp0 ); - - //! build argc and argv[] - *tmp++ = argc; - - //kprintf( "xSTACK: 0x%X, ESP0: 0x%X\n", iFrame->user_esp, _current->tss.esp0 ); + *tmp++ = argc; // ARGC if ( argc == 1 ) { - *tmp++ = 0x0; + *tmp++ = 0x0; //ARGV Pointers } else { for ( i = 0; i < argc; i++ ) { - *tmp++ = (u_int) argv[i]; } } *tmp++ = 0x0; // ARGV Terminator + *tmp++ = 0x0; // ENV *tmp++ = 0x0; // ENV Terminator + + *tmp++ = 0x0; + *tmp++ = 0x0; + + *tmp++ = 0x0; // AUX VECTOR 8 Bytes + *tmp++ = 0x0; // Terminator + + *tmp++ = 0x0; // End Marker + + tmp = (void *)STACK_ADDR; + tmp[0] = (void *)iFrame->user_esp; //0x10; /* */ diff --git a/sys/include/sys/elf.h b/sys/include/sys/elf.h index 1f08379..39b383d 100644 --- a/sys/include/sys/elf.h +++ b/sys/include/sys/elf.h @@ -203,6 +203,13 @@ uint32_t trace; } Elf_Auxargs; +typedef struct { /* Auxiliary vector entry on initial stack */ + int a_type; /* Entry type. */ + union { + int a_val; /* Integer value. */ + } a_un; +} Elf32_Auxinfo; + char *elfGetShType( int ); char *elfGetPhType( int ); char *elfGetRelType( int ); diff --git a/sys/init/main.c b/sys/init/main.c index 9828773..7c59cb1 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -85,7 +85,7 @@ ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl0)), -ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), +ubixStandardDescriptor(0xC800000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), }; struct {