diff --git a/bin/init/main.c b/bin/init/main.c index 6356377..1d47d80 100644 --- a/bin/init/main.c +++ b/bin/init/main.c @@ -40,6 +40,7 @@ int i=0x0; mpi_message_t myMsg; + /* Create a mailbox for this task */ /* if (mpi_createMbox("init") != 0x0) { diff --git a/bin/shell/commands.c b/bin/shell/commands.c index 33f7f21..598af10 100644 --- a/bin/shell/commands.c +++ b/bin/shell/commands.c @@ -144,7 +144,7 @@ else if (memcmp(data->args->arg,"id",2) == 0x0) { printf("UID: %i, GID: %i\n",getuid(),getgid()); } - else if (!strcmp(argv[1],"reboot")) { + else if (argv[1] != 0x0 && !strcmp(argv[1],"reboot")) { cmdMsg.header = 1000; cmdMsg.data[0] = '\0'; mpi_postMessage("system",0x1,&cmdMsg); diff --git a/bin/shell/main.c b/bin/shell/main.c index eb5c348..4155073 100644 --- a/bin/shell/main.c +++ b/bin/shell/main.c @@ -41,9 +41,11 @@ int main(int argc, char **argv, char **env) { unsigned int *segbase = 0x0; + /* __asm __volatile("movl %%gs:0, %0" : "=r" (segbase)); printf("Segbase: 0x%X - 0x%X\n", segbase, &segbase); + */ for (int i=0;i < argc; i++) printf("ARGV[%i]: %s\n", i, argv[i]); diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index daa38be..bc4f7b0 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -367,7 +367,8 @@ /* Set Up Stack Space */ //MrOlsen (2016-01-14) FIX: is the stack start supposed to be addressable xhcnage x= 1 to x=0 - for (x = 1; x <= 100; x++) { + //x = 0 because GS= stack address not address -1 fix! + for (x = 0; x <= 100; x++) { vmm_remapPage(vmm_findFreePage(newProcess->id), STACK_ADDR - (x * 0x1000), PAGE_DEFAULT | PAGE_STACK, newProcess->id); bzero(STACK_ADDR - (x * 0x1000), 0x1000); } @@ -388,7 +389,7 @@ newProcess->tss.eip = (long) binaryHeader->e_entry; newProcess->tss.eflags = 0x206; newProcess->tss.esp = STACK_ADDR; - newProcess->tss.ebp = STACK_ADDR; + newProcess->tss.ebp = 0x0;//STACK_ADDR; newProcess->tss.esi = 0x0; newProcess->tss.edi = 0x0; @@ -447,12 +448,12 @@ : : "d" ((uint32_t *)(kernelPageDirectory)) ); - kprintf("execFile Return: %i\n", newProcess->id); + kprintf("execFile Return: 0x%X - %i\n", newProcess->tss.eip, newProcess->id); /* Put new thread into the READY state */ sched_setStatus(newProcess->id, READY); - _current = newProcess; + //_current = newProcess; /* Finally Return */ return; @@ -764,7 +765,7 @@ tmp[i++] = 0x1000; tmp[i++] = 7; - tmp[i++] = 0x0;//LD_START; + tmp[i++] = LD_START; kprintf("AT_BASE: [0x%X]", tmp[i - 1]); tmp[i++] = 8; diff --git a/sys/i386/sched.c b/sys/i386/sched.c index 98438d1..81e8ffb 100644 --- a/sys/i386/sched.c +++ b/sys/i386/sched.c @@ -141,6 +141,12 @@ */ spinUnlock(&schedulerSpinLock); + if (_current->id == 600) { + kprintf("EIP: 0x%X", _current->tss.eip); + kprintf("esp0: 0x%X", _current->tss.esp0); + kprintf("user_esp: 0x%X", _current->tss.esp); + } + asm("sti"); asm("ljmp $0x20,$0\n"); } diff --git a/sys/i386/sys_call.S b/sys/i386/sys_call.S index bff7fb0..5bf4d96 100644 --- a/sys/i386/sys_call.S +++ b/sys/i386/sys_call.S @@ -38,9 +38,9 @@ _astRet: -_sysCall: -push $0x2 -sub $0x4,%esp +_sysCall_MrOlsen: +//MrOlsen 2018-01-14 push $0x2 +//MrOlsen 2018-01-14 sub $0x4,%esp pusha push %ds push %es @@ -62,6 +62,7 @@ _notVM: testb $0x3,0x38(%esp) /* See If We're In User CS (GDT Entry 5) */ jz _popFS +jmp _popFS /* TMP BECAUSE ABOVE ISN'T RIGHT */ cli mov %fs:0x0,%eax testl $0x10800,0x80(%eax) /* Document This */ @@ -80,9 +81,29 @@ pop %es pop %ds popa -add $0x8,%esp +//MrOlsen 2018-01-14 add $0x8,%esp iret -/*** - END - ***/ +_sysCall: +push $0x0 +push $0x80 +pusha +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax, %ds +mov %eax, %es +mov %eax, %fs +cld +push %esp +call syscall +add $0x4,%esp /* Remove Stack Pointer From Stack */ +pop %gs +pop %fs +pop %es +pop %ds +popa +add $0x8,%esp //Back Out Error Code & trap_no +iret diff --git a/sys/i386/timer.S b/sys/i386/timer.S index 556bb5b..1ddfcc1 100644 --- a/sys/i386/timer.S +++ b/sys/i386/timer.S @@ -50,12 +50,26 @@ div %ebx test %edx,%edx jnz done +/* +push %ds +push %es +push %fs +push %gs +mov $0x10,%eax +mov %eax, %ds +mov %eax, %es +mov %eax, %fs +cld +*/ +/* push %esp */ call sched +/* add $0x4,%esp */ /* Remove Stack Pointer From Stack */ +/* +pop %gs +pop %fs +pop %es +pop %ds +*/ done: popa /* Restore Registers */ iret - -/*** - END - ***/ - diff --git a/sys/i386/trap.c b/sys/i386/trap.c index a91a728..8af89b9 100644 --- a/sys/i386/trap.c +++ b/sys/i386/trap.c @@ -35,12 +35,18 @@ #define KERNEL_STACK 0x2000 +void die_if_kernel(char *str, struct trapframe *regs, long err); + static void trap_end_task(char *string, struct trapframe *regs, long error_code); #define TRAP_CODE(trap_nr, signr, str, trap_name, tsk) void do_##trap_name(struct trapframe *regs, long error_code) { \ - trap_end_task(str, regs, error_code); \ + die_if_kernel(str, regs, error_code); \ } +/* + trap_end_task(str, regs, error_code); \ +*/ + TRAP_CODE(0, SIGFPE, "divide error", divide_error, _current) TRAP_CODE(3, SIGTRAP, "int3", int3, _current) TRAP_CODE(4, SIGSEGV, "overflow", overflow, _current) @@ -56,7 +62,7 @@ TRAP_CODE(17, SIGSEGV, "alignment check", alignment_check, _current) static void trap_end_task(char *string, struct trapframe *regs, long error_code) { - kprintf("S"); + kprintf("S: %s[0x%X]", string, error_code); } #define FIRST_TSS_ENTRY 6 diff --git a/sys/kernel/ld.c b/sys/kernel/ld.c index 841ca6d..b839cf5 100644 --- a/sys/kernel/ld.c +++ b/sys/kernel/ld.c @@ -104,8 +104,8 @@ break; case PT_DYNAMIC: /* Now Load Section To Memory */ - fseek(ldFd, programHeader[i].p_offset, 0x0); - fread(newLoc, programHeader[i].p_filesz, 1, ldFd); + //fseek(ldFd, programHeader[i].p_offset, 0x0); + //fread(newLoc, programHeader[i].p_filesz, 1, ldFd); break; case PT_GNU_STACK: /* Tells us if the stack should be executable. Failsafe to executable @@ -119,17 +119,17 @@ for (i = 0x0; i < binaryHeader->e_shnum; i++) { switch (sectionHeader[i].sh_type) { - case 3: + case SHT_STRTAB: if (!strcmp((shStr + sectionHeader[i].sh_name), ".dynstr")) { dynStr = (char *) kmalloc(sectionHeader[i].sh_size); - fseek(ldFd, sectionHeader[i].sh_offset, 0x0); - fread(dynStr, sectionHeader[i].sh_size, 1, ldFd); + //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); + //fread(dynStr, sectionHeader[i].sh_size, 1, ldFd); } break; - case 9: + case SHT_REL: elfRel = (Elf_Rel *) kmalloc(sectionHeader[i].sh_size); - fseek(ldFd, sectionHeader[i].sh_offset, 0x0); - fread(elfRel, sectionHeader[i].sh_size, 1, ldFd); + //fseek(ldFd, sectionHeader[i].sh_offset, 0x0); + //fread(elfRel, sectionHeader[i].sh_size, 1, ldFd); for (x = 0x0; x < sectionHeader[i].sh_size / sizeof(Elf_Rel); x++) { rel = ELF32_R_SYM(elfRel[x].r_info); @@ -144,6 +144,8 @@ case R_386_RELATIVE: *reMap += (uint32_t) LD_START; break; + case R_386_NONE: + break; default: kprintf("[0x%X][0x%X](%i)[%s]\n", elfRel[x].r_offset, elfRel[x].r_info, rel, elfGetRelType(ELF32_R_TYPE(elfRel[x].r_info))); kprintf("relTab [%s][0x%X][0x%X]\n", dynStr + relSymTab[rel].st_name, relSymTab[rel].st_value, relSymTab[rel].st_name); @@ -152,12 +154,24 @@ } kfree(elfRel); break; - case 11: + case SHT_DYNSYM: relSymTab = (Elf_Sym *) kmalloc(sectionHeader[i].sh_size); fseek(ldFd, sectionHeader[i].sh_offset, 0x0); fread(relSymTab, sectionHeader[i].sh_size, 1, ldFd); sym = i; break; + case SHT_PROGBITS: + //kprintf("PROGBITS"); + break; + case SHT_HASH: + //kprintf("HASH"); + break; + case SHT_DYNAMIC: + //kprintf("DYNAMIC"); + break; + case SHT_SYMTAB: + //kprintf("SYMTAB"); + break; default: kprintf("INvalid: %i]", sectionHeader[i].sh_type); break; diff --git a/sys/kernel/syscall_new.c b/sys/kernel/syscall_new.c index 31736ba..8f08310 100644 --- a/sys/kernel/syscall_new.c +++ b/sys/kernel/syscall_new.c @@ -43,6 +43,11 @@ uint32_t code = 0x0; caddr_t params; + /* + if (_current->id == 6) + kprintf("SYSCALL: 0x%X.", frame->tf_eip); + */ + struct thread *td = &_current->td; td->frame = frame; @@ -114,6 +119,10 @@ kprintf("RET2"); } } + /* + if (_current->id == 6) + kprintf("SYSCALL-EXIT"); + */ } int invalidCall() { diff --git a/sys/vmm/copyvirtualspace.c b/sys/vmm/copyvirtualspace.c index f478767..5b82c98 100644 --- a/sys/vmm/copyvirtualspace.c +++ b/sys/vmm/copyvirtualspace.c @@ -59,14 +59,14 @@ spinLock(&cvsSpinLock); /* Set Address Of Parent Page Directory */ - parentPageDirectory = (uInt32 *) PD_BASE_ADDR; + parentPageDirectory = (uint32_t *) PD_BASE_ADDR; /* Allocate A New Page For The New Page Directory */ - if ((newPageDirectory = (uInt32 *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + if ((newPageDirectory = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) kpanic("Error: newPageDirectory == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */ - newPageDirectoryAddress = (void *) vmm_getPhysicalAddr((uInt32) newPageDirectory); + newPageDirectoryAddress = (void *) vmm_getPhysicalAddr((uint32_t) newPageDirectory); /* First Set Up A Flushed Page Directory */ bzero(newPageDirectory, PAGE_SIZE); @@ -92,7 +92,7 @@ parentPageTable = (uint32_t *) (PT_BASE_ADDR + (PAGE_SIZE * x)); /* Allocate A New Page Table */ - if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); bzero(newPageTable, PAGE_SIZE); @@ -107,7 +107,7 @@ if (((uint32_t) parentPageTable[i] & PAGE_STACK) == PAGE_STACK) { /* Alloc A New Page For This Stack Page */ - if ((newStackPage = (uInt32 *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + if ((newStackPage = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) kpanic("Error: newStackPage == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); /* Set Pointer To Parents Stack Page */ @@ -150,9 +150,9 @@ } /* Put New Page Table Into New Page Directory */ - newPageDirectory[x] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[x] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); /* Unmap Page From Kernel Space But Keep It Marked As Not Avail */ - vmm_unmapPage((uInt32) newPageTable, 1); + vmm_unmapPage((uint32_t) newPageTable, 1); } } @@ -160,14 +160,14 @@ * Allocate A New Page For The The First Page Table Where We Will Map The * Lower Region First 4MB */ - if ((newPageTable = (uInt32 *) vmm_getFreeKernelPage(pid, 1)) == 0x0) + if ((newPageTable = (uint32_t *) vmm_getFreeKernelPage(pid, 1)) == 0x0) kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n", __FILE__, __LINE__); /* Flush The Page From Garbage In Memory */ bzero(newPageTable, PAGE_SIZE); /* Map This Into The Page Directory */ - newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[0] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ parentPageTable = (uint32_t *) PT_BASE_ADDR; @@ -187,7 +187,7 @@ newPageTable[x] = (((uint32_t) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); /* Increment The COW Counter For This Page */ - if (((uInt32) parentPageTable[x] & PAGE_COW) == PAGE_COW) { + if (((uint32_t) parentPageTable[x] & PAGE_COW) == PAGE_COW) { adjustCowCounter(((uint32_t) parentPageTable[x] & 0xFFFFF000), 1); } else { @@ -203,14 +203,14 @@ * First Page After Page Tables * This must be mapped into the page directory before we map all 1024 page directories into the memory space */ - newPageTable = (uInt32 *) vmm_getFreePage(pid); + newPageTable = (uint32_t *) vmm_getFreePage(pid); newPageDirectory[PD_INDEX(PD_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); newPageTable[0] = (uint32_t) ((uint32_t) (newPageDirectoryAddress) | PAGE_DEFAULT); //MrOlsen (2017-12-15) - kprintf( "PD3: %i - 0x%X - 0x%X\n", PD_INDEX( PD_BASE_ADDR ), newPageDirectoryAddress, newPageTable[0] ); - vmm_unmapPage((uInt32) newPageTable, 1); + vmm_unmapPage((uint32_t) newPageTable, 1); /* * @@ -221,7 +221,7 @@ newPageTable = (uint32_t *) vmm_getFreePage(pid); - newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT); + newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); /* Flush The Page From Garbage In Memory */ bzero(newPageTable, PAGE_SIZE); diff --git a/sys/vmm/createvirtualspace.c b/sys/vmm/createvirtualspace.c index 17dc20f..ca620a3 100644 --- a/sys/vmm/createvirtualspace.c +++ b/sys/vmm/createvirtualspace.c @@ -85,7 +85,7 @@ bzero(newPageTable, PAGE_SIZE); /* Map This Into The Page Directory */ - newPageDirectory[0] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + newPageDirectory[0] = (vmm_getPhysicalAddr((uint32_t) newPageTable) | KERNEL_PAGE_DEFAULT); //MrOlsen 2018-01-14 PAGE_DEFAULT /* Set Address Of Parents Page Table */ parentPageTable = (uint32_t *) PT_BASE_ADDR; @@ -106,9 +106,9 @@ */ newPageTable = (uint32_t *) vmm_getFreePage(pid); - newPageDirectory[PD_INDEX(PD_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + newPageDirectory[PD_INDEX(PD_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | KERNEL_PAGE_DEFAULT ); //MrOlsen 2018-01-14 PAGE_DEFAULT - newPageTable[0] = (uint32_t) ((uint32_t) (newPageDirectoryAddress) | PAGE_DEFAULT); + newPageTable[0] = (uint32_t) ((uint32_t) (newPageDirectoryAddress) | KERNEL_PAGE_DEFAULT); //MrOlsen 2018-01-14 PAGE_DEFAULT vmm_unmapPage((uint32_t) newPageTable, 1); @@ -121,7 +121,7 @@ newPageTable = (uint32_t *) vmm_getFreePage(pid); - newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | PAGE_DEFAULT); + newPageDirectory[PD_INDEX(PT_BASE_ADDR)] = (uint32_t) (vmm_getPhysicalAddr((uint32_t) newPageTable) | KERNEL_PAGE_DEFAULT); //MrOlsen 2018-01-14 PAGE_DEFAULT /* Flush The Page From Garbage In Memory */ bzero(newPageTable, PAGE_SIZE); diff --git a/sys/vmm/getfreevirtualpage.c b/sys/vmm/getfreevirtualpage.c index dcd9a36..98a5fe5 100644 --- a/sys/vmm/getfreevirtualpage.c +++ b/sys/vmm/getfreevirtualpage.c @@ -127,6 +127,7 @@ } //kprintf("HERE?"); + keepMapping: ptI = ((start_page - (pdI * 0x400000)) / 0x1000); for (y = ptI; y < 1024 && counter < count; y++) { @@ -144,11 +145,16 @@ kprintf("-> y: %i, ptI: 0x%X, pdI: 0x%X pTS: 0x%X ??\n", y, ptI, pdI, pageTableSrc[y]); K_PANIC("UHM HOW DO WE HAVE AN ALLOCATED PAGE HERE!!\n"); } + + kprintf("[0x%X:%i:%i:%i]", ((pdI * (1024 * 4096)) + (y * 4096)), y, counter, count); counter++; } - if (count < count) { + if (counter < count) { kprintf("Need More Pages!"); + start_page += (0x1000 * counter); + pdI = ((start_page + (counter * 0x1000)) / 0x400000); + goto keepMapping; } } diff --git a/sys/vmm/paging.c b/sys/vmm/paging.c index 7aeec1d..c7531fa 100644 --- a/sys/vmm/paging.c +++ b/sys/vmm/paging.c @@ -87,7 +87,7 @@ /* MrOlsen (2016-01-15) NOTE: I'm Mappying It For Now Until I Can Figure Out Why FS:0x0 */ for (i = 0x0; i < (PD_ENTRIES / 0x4); i++) { - pageTable[i] = (uint32_t) ((i * 0x1000) | PAGE_DEFAULT); + pageTable[i] = (uint32_t) ((i * 0x1000) | KERNEL_PAGE_DEFAULT); //MrOlsen 2018-01-14 PAGE_DEFAULT } /* end for */ /* diff --git a/sys/vmm/vmm_mmap.c b/sys/vmm/vmm_mmap.c index cf245b7..9db382a 100644 --- a/sys/vmm/vmm_mmap.c +++ b/sys/vmm/vmm_mmap.c @@ -177,6 +177,7 @@ } tmp = uap->addr; + kprintf("mm1: 0x%X\n", uap->len); bzero(tmp, uap->len); td->td_retval[0] = (uint32_t)tmp; return (0x0); @@ -184,8 +185,8 @@ //td->td_retval[0] = (int) vmm_getFreeVirtualPage( _current->id, uap->len / 0x1000, VM_TASK ); //td->td_retval[0] = (int) td->td_retval[0] = vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_TASK); - bzero(td->td_retval[0], uap->len); - kprintf("mm: 0x%X\n", uap->len); + kprintf("mm2: 0x%X-0x%X\n", td->td_retval[0], round_page(uap->len) / 0x1000); + //bzero(td->td_retval[0], uap->len); return (0x0); //vmm_getFreeVirtualPage(_current->id, round_page( uap->len ) / 0x1000, VM_THRD)); } else {