diff --git a/libexec/Makefile b/libexec/Makefile index 830ac14..96e6538 100644 --- a/libexec/Makefile +++ b/libexec/Makefile @@ -10,4 +10,4 @@ clean: (cd ld;make clean) - (cd rtld-elf;make clean) +# (cd rtld-elf;make clean) diff --git a/libexec/ld/addlibrary.c b/libexec/ld/addlibrary.c index 9081474..f591d31 100644 --- a/libexec/ld/addlibrary.c +++ b/libexec/ld/addlibrary.c @@ -26,7 +26,6 @@ } //if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) { //if ((tmpLib->output = (char *)malloc(0x111000)) == 0x0) { - printf("[%i](0x%X:0x%X)", __LINE__, linkerFd->size+0x4000, 0x111000); //if ((tmpLib->output = (char *)getPage((0x111000/0x1000),2)) == 0x0) { if ((tmpLib->output = (char *)getPage(((linkerFd->size+0x4000)/0x1000),2)) == 0x0) { printf("malloc failed: tmpLib->output\n"); @@ -35,43 +34,29 @@ sprintf(tmpLib->name,lib); } printf("Base: {0x%X}[%i]\n",tmpLib->output, __LINE__); - printf("[%i]\n", __LINE__); if (tmpLib->linkerHeader == 0x0) { - printf("[%i]", __LINE__); fseek(linkerFd,0x0,0x0); - printf("[%i]", __LINE__); if ((tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader))) == 0x0) { printf("malloc failed: tmpLib->linkerHeader\n"); exit(0x1); } - printf("[%i]", __LINE__); fread(tmpLib->linkerHeader,sizeof(elfHeader),1,linkerFd); - printf("[%i]", __LINE__); } - printf("[%i]", __LINE__); if (tmpLib->linkerProgramHeader == 0x0) { - printf("[%i]", __LINE__); if ((tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum)) == 0x0) { printf("malloc failed: tmpLib->linkerProgramHeader\n"); exit(0x1); } - printf("[%i]", __LINE__); fseek(linkerFd,tmpLib->linkerHeader->ePhoff,0); fread(tmpLib->linkerProgramHeader,sizeof(elfProgramHeader),tmpLib->linkerHeader->ePhnum,linkerFd); - printf("[%i]", __LINE__); for (i=0;ilinkerHeader->ePhnum;i++) { - printf("[%i]", __LINE__); switch (tmpLib->linkerProgramHeader[i].phType) { case PT_LOAD: case PT_DYNAMIC: - printf("[%i](0x%X)", __LINE__, tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output); newLoc = (char *)tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output; - printf("[%i]", __LINE__); fseek(linkerFd,tmpLib->linkerProgramHeader[i].phOffset,0); - printf("[%i](0x%X)", __LINE__,tmpLib->linkerProgramHeader[i].phFilesz); fread(newLoc,tmpLib->linkerProgramHeader[i].phFilesz,1,linkerFd); - printf("[%i]", __LINE__); break; case PT_TLS: tmpLib->tlsindex = 1; @@ -79,17 +64,14 @@ tmpLib->tlsalign = tmpLib->linkerProgramHeader[i].phAlign;//ph->p_align; tmpLib->tlsinitsize = tmpLib->linkerProgramHeader[i].phFilesz;//ph->p_filesz; tmpLib->tlsinit = (void*)(tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output); - printf("[%i](0x%X)", __LINE__, tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output); +/* newLoc = (char *)tmpLib->linkerProgramHeader[i].phVaddr + (uInt32)tmpLib->output; - printf("[%i]", __LINE__); fseek(linkerFd,tmpLib->linkerProgramHeader[i].phOffset,0); - printf("[%i](0x%X)", __LINE__,tmpLib->linkerProgramHeader[i].phFilesz); fread(newLoc,tmpLib->linkerProgramHeader[i].phFilesz,1,linkerFd); - printf("[%i]", __LINE__); +*/ break; case PT_GNU_STACK: - /* Tells us if the stack should be executable. Failsafe to - executable until we add checking */ + /* Tells us if the stack should be executable. Failsafe to executable until we add checking */ printf("NOT DEF1\n"); break; case PT_PAX_FLAGS: @@ -103,7 +85,6 @@ } } - printf("[%i]", __LINE__); if (tmpLib->linkerSectionHeader == 0x0) { if ((tmpLib->linkerSectionHeader = (elfSectionHeader *)malloc(sizeof(elfSectionHeader)*tmpLib->linkerHeader->eShnum)) == 0x0) { printf("malloc failed: tmpLib->linkerSectionHeader\n"); @@ -150,6 +131,7 @@ case R_386_TLS_DTPMOD32: case R_386_TLS_DTPOFF32: *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue); + *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue) - (uInt32)reMap; break; case R_386_PC32: *reMap += ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue) - (uInt32)reMap; @@ -179,10 +161,12 @@ tmpLib->sym = i; } break; + default: + printf("[SHTYPE: 0x%X]", tmpLib->linkerSectionHeader[i].shType); + break; } } } - printf("[%i]", __LINE__); if (libs != 0x0) libs->prev = tmpLib; diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index 4f2f646..536ef29 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -321,7 +321,7 @@ //*tmp++ = 0x0; // Stack EIP Return Addr //*tmp++ = tmp + 1; // Pointer To AP *tmp++ = 0x1; // ARGC - *tmp++ = 0x0; // ARGV + *tmp++ = 0x100; // ARGV *tmp++ = 0x0; // ARGV TERM *tmp++ = 0x0; // ENV *tmp++ = 0x0; // ENV TERM @@ -329,7 +329,7 @@ *tmp++ = 0x0; // AUX 1.B *tmp++ = 0x0; // AUX TERM *tmp++ = 0x0; // AUX TERM - *tmp++ = 0x0; // TERM + *tmp++ = 0x1; // TERM /* Switch Back To The Kernels VM Space */ asm volatile( @@ -380,6 +380,7 @@ elfProgramHeader *programHeader = 0x0; elfSectionHeader *sectionHeader = 0x0; elfDynamic *elfDynamicS = 0x0; + elfDynamic *dynp = 0x0; u_long text_addr = 0, text_size = 0; u_long data_addr = 0, data_size = 0; @@ -551,22 +552,52 @@ /* What is this doing? 11/23/06 */ if ( elfDynamicS != 0x0 ) { - for ( i = 0; i < 12; i++ ) { - if ( elfDynamicS[i].dynVal == 0x3 ) { - tmp = (void *) elfDynamicS[i].dynPtr; - if ( tmp == 0x0 ) - kpanic( "tmp: NULL\n" ); - else - kprintf("[0x%X]", tmp); - tmp[2] = (uInt32) ldAddr; - tmp[1] = (uInt32) fd; + for ( dynp = elfDynamicS ; dynp->d_tag != 0x0; dynp++) { + switch (dynp->d_tag) { + case DT_NEEDED: + break; + case DT_INIT: + break; + case DT_FINI: + break; + case DT_HASH: + kprintf("COM BACK TO THIS"); + break; + case DT_STRTAB: + break; + case DT_SYMTAB: + break; + case DT_STRSZ: + break; + case DT_SYMENT: + break; + case DT_DEBUG: + break; + case DT_PLTRE: + break; + case DT_JMPREL: + break; + case DT_REL: + break; + case DT_RELSZ: + break; + case DT_RELENT: + if (dynp->d_un.d_val != sizeof(Elf_Rel)) + kpanic("NOEXEC"); + break; + case DT_PLTGOT: + tmp = (void *) dynp->d_un.d_ptr;//elfDynamicS[i].dynPtr; + if ( tmp == 0x0 ) + kpanic( "tmp: NULL\n" ); + else + kprintf("[0x%X]", tmp); + tmp[2] = (uInt32) ldAddr; + tmp[1] = (uInt32) fd; + break; + default: + kprintf("t_tag: 0x%X>", dynp->d_tag); break; } - /* - else { - kprintf("dyn_val: %i",elfDynamicS[i].dynVal); - } - */ } } /* @@ -651,7 +682,7 @@ tmp[7] = 0x0; // AUX VECTOR 8 Bytes tmp[8] = 0x0; // Terminator - tmp[9] = 0x0; // End Marker + tmp[9] = 0xDEADBEEF; // End Marker kfree( argvNew ); diff --git a/sys/i386/trap.c b/sys/i386/trap.c index f98c210..a30c2f7 100644 --- a/sys/i386/trap.c +++ b/sys/i386/trap.c @@ -32,6 +32,11 @@ #include #include #include +#include + +int kmain(uint32_t); + +#define KERNEL_STACK 0x2000 static void trap_end_task(char *string, struct trapframe *regs, long error_code); @@ -83,28 +88,68 @@ int i; unsigned long esp; unsigned short ss; + unsigned long *stack, addr, module_start, module_end; + char *_etext = 0x300a0; esp = (unsigned long) ®s->tf_esp; - //ss = KERNEL_DS; - ss = 0x10; - if ((regs->tf_eflags & VM_MASK) || (3 & regs->tf_cs) == 3) - return; - if (regs->tf_cs & 3) { + + ss = 0x10; //KERNEL_DS + + //if ((regs->tf_eflags & VM_MASK) || (3 & regs->tf_cs) == 3) + // return; + + // if ((regs->tf_cs & 3) == 3) { esp = regs->tf_esp; ss = regs->tf_ss; - } + kprintf("USER TASK!"); + //} - kprintf("%s: %04lx\n", str, err & 0xffff); - kprintf("EIP: %04x:%08lx\nEFLAGS: %08lx\n", 0xffff & regs->tf_cs, regs->tf_eip, regs->tf_eflags); + ss = 0x30; + + kprintf("%s: %04lx(%i:%i)[0x%X]\n", str, err & 0xffff, regs->tf_trapno, regs->tf_err, regs->tf_ss); + kprintf("CPU: %d\n", 0); + kprintf("EIP: %04x:[<%08lx>]\nEFLAGS: %08lx\n", 0xffff & regs->tf_cs, regs->tf_eip, regs->tf_eflags); kprintf("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", regs->tf_eax, regs->tf_ebx, regs->tf_ecx, regs->tf_edx); kprintf("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", regs->tf_esi, regs->tf_edi, regs->tf_ebp, esp); - kprintf("ds: %04x es: %04x fs: %04x gs: %04x ss: %04x\n", regs->tf_ds, regs->tf_es, regs->tf_fs, regs->tf_gs, ss); + kprintf("cs: 0x%X ds: 0x%X es: 0x%X fs: 0x%X gs: 0x%X ss: 0x%X\n", regs->tf_cs, regs->tf_ds, regs->tf_es, regs->tf_fs, regs->tf_gs, ss); store_TR(i); - //kprintf("Pid: %d, process nr: %d (%s)\nStack: ", _current->id, 0xffff & i, _current->comm); - kprintf("Pid: %d, process nr: %d ()\nStack: ", _current->id, 0xffff & i); - for (i = 0; i < 5; i++) - kprintf("%08lx ", get_seg_long(ss, (i+(unsigned long *)esp))); - kprintf("\nCode: "); + kprintf("Process %s (pid: %i, process nr: %d, stackpage=%08lx)\nStack:", _current->name, _current->id, 0xffff & i, KERNEL_STACK); + + stack = (unsigned long *)esp; + for (i = 0; i < 16; i++) { + if (i && ((i % 8) == 0)) + kprintf("\n "); + kprintf("%08lx ", get_seg_long(ss, stack++)); + } + kprintf("\nCall Trace: "); + stack = (unsigned long *)esp; + i = 1; + +#define VMALLOC_OFFSET (8*1024*1024) +#define MODULE_RANGE (8*1024*1024) + + module_start = ((numPages + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)); + module_end = module_start + MODULE_RANGE; + + //while (((long) stack & 4095) != 0) { + while (i < 12) { + addr = get_seg_long(ss, stack++); + /* + * If the address is either in the text segment of the + * kernel, or in the region which contains vmalloc'ed + * memory, it *may* be the address of a calling + * routine; if so, print it so that someone tracing + * down the cause of the crash will be able to figure + * out the call path that was taken. + */ + if (((addr >= (unsigned long) &kmain) && (addr <= (unsigned long) &_etext)) || ((addr >= module_start) && (addr <= module_end))) { + if (i && ((i % 8) == 0)) + kprintf("\n "); + kprintf("[<%08lx>] ", addr); + i++; + } + } + for (i = 0; i < 20; i++) kprintf("%02x ", 0xff & get_seg_byte(regs->tf_cs, (i+(char *)regs->tf_eip))); kprintf("\n"); @@ -131,6 +176,10 @@ cr2 = rcr2(); kprintf("trap_code: %i(0x%X), EIP: 0x%X, CR2: 0x%X\n", frame->tf_trapno, frame->tf_trapno, frame->tf_eip, cr2); + die_if_kernel("trapCode", frame, frame->tf_trapno); + endTask( _current->id ); + sched_yield(); + /* switch (trap_code) { diff --git a/sys/include/i386/elf.h b/sys/include/i386/elf.h index d482f84..ff85ee4 100644 --- a/sys/include/i386/elf.h +++ b/sys/include/i386/elf.h @@ -45,6 +45,14 @@ typedef struct { uInt32 dynVal; uInt32 dynPtr; +} elfDynamic_Old; + +typedef struct { + uint32_t d_tag; + union { + uint32_t d_val; + uint32_t d_ptr; + } d_un; } elfDynamic; typedef struct { diff --git a/sys/include/i386/signal.h b/sys/include/i386/signal.h index 1481c5b..bc08ad9 100644 --- a/sys/include/i386/signal.h +++ b/sys/include/i386/signal.h @@ -1,41 +1,41 @@ -#ifndef _I386_SIGNAL_H_ -#define _i386_SIGNAL_H_ - -#define _NSIG 32 -#define NSIG _NSIG - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT 6 -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL SIGIO -#define SIGPWR 30 -#define SIGUNUSED 31 - -#endif +#ifndef _I386_SIGNAL_H_ +#define _I386_SIGNAL_H_ + +#define _NSIG 32 +#define NSIG _NSIG + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT 6 +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL SIGIO +#define SIGPWR 30 +#define SIGUNUSED 31 + +#endif diff --git a/sys/include/ubixos/sched.h b/sys/include/ubixos/sched.h index b6649d7..229fe6c 100644 --- a/sys/include/ubixos/sched.h +++ b/sys/include/ubixos/sched.h @@ -54,6 +54,7 @@ typedef struct taskStruct { pidType id; + char name[256]; struct taskStruct *prev; struct taskStruct *next; struct tssStruct tss; diff --git a/sys/sys/idt.c b/sys/sys/idt.c index 4dce798..b02ac4f 100644 --- a/sys/sys/idt.c +++ b/sys/sys/idt.c @@ -68,7 +68,7 @@ /* Set up default vector table for all possible 256 interrupts */ for ( i = 0x0; i < 256; i++ ) { - setVector( intNull, i, dPresent + dInt + dDpl3 ); + setVector( intNull, i, dPresent + dTrap + dDpl3 ); } /* Load the IDT into the system */ @@ -90,7 +90,7 @@ setVector( _int3, 3, dPresent + dInt + dDpl0 ); setVector( _int4, 4, dPresent + dInt + dDpl0 ); setVector( _int5, 5, dPresent + dInt + dDpl0 ); - setVector( _int6, 6, dPresent + dInt + dDpl0 ); + setVector( _int6, 6, dPresent + dTrap + dDpl0 ); setVector( _int7, 7, dPresent + dInt + dDpl0 ); setTaskVector( 8, dPresent + dTask + dDpl0, 0x40 ); setVector( _int9, 9, dPresent + dInt + dDpl0 ); @@ -227,6 +227,8 @@ asm volatile( ".globl _int6 \n" "_int6: \n" + " pushl $0x0 \n" + " pushl $0x6 \n" " pushal \n" /* Save all registers */ " push %ds \n" " push %es \n" @@ -246,7 +248,7 @@ void __int6(struct trapframe *frame) { die_if_kernel("invalid_op",frame,6); kprintf("tf_gs: 0x%X, tf_fs: 0x%X, tf_es: 0x%X, tf_ds: 0x%X\n", frame->tf_gs, frame->tf_fs, frame->tf_es, frame->tf_ds); - kpanic( "int6: Invalid opcode! [%i:0x%X:0x%X]\n", _current->id, _current->tss.eip, frame->tf_eip ); + //kpanic( "int6: Invalid opcode! [%i:0x%X:0x%X]\n", _current->id, _current->tss.eip, frame->tf_eip ); endTask( _current->id ); sched_yield(); }