KraKern

C++ Kernel
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/KraKern

commit 7fd521461fbfde50c1b271b12500696b1354af94
parent f00b71e33070ddb2a19e56b7b7603e84e816a58e
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 23 Feb 2016 15:17:29 +0100

Work(MultiTask): Not working

Diffstat:
Mboot/x86/IDT.cpp | 14+++++++++-----
Mboot/x86/x86.asm | 2--
Mclean.img | 0
Mincludes/core/Kernel.hpp | 1+
Mincludes/core/ProcessTable.hpp | 3+++
Mkernel/ELF.cpp | 4+++-
Mkernel/Io.cpp | 1+
Mkernel/Kernel.cpp | 4++--
Mkernel/ProcessTable.cpp | 6++++++
Mkernel/Scheduler.cpp | 7++++---
10 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/boot/x86/IDT.cpp b/boot/x86/IDT.cpp @@ -13,13 +13,16 @@ extern "C" { void do_syscalls(int n) { (void)n; - //__kern.io.puts("Here !"); + __kern.io.printk("Sycall !"); + while (1); } void isr_schedule_int(void) { - //__kern.sch.tick(); - __kern.io.obyte(0x20,0x20); - __kern.io.obyte(0xA0,0x20); + if (!__kern.is_panic) { + __kern.sch.tick(); + __kern.io.obyte(0x20,0x20); + __kern.io.obyte(0xA0,0x20); + } } void isr_GP_exc(void) { @@ -49,7 +52,8 @@ void IDT::_init_idt(void) { this->_init_idt_desc(0x08, (u32)_asm_exc_PF, INT_GATE, &this->_idtdesc[14]); this->_init_idt_desc(0x08, (u32)_asm_schedule, INT_GATE, &this->_idtdesc[32]); this->_init_idt_desc(0x08, (u32)_asm_int_1, INT_GATE, &this->_idtdesc[33]); - this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[48]); + //this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[48]); + this->_init_idt_desc(0x08, (u32)_asm_syscalls, INT_GATE | 0x6000, &this->_idtdesc[48]); this->_init_idt_desc(0x08, (u32)_asm_syscalls, TRAP_GATE, &this->_idtdesc[128]); this->_idtr.limite = IDT_SIZE * 8; this->_idtr.base = IDT_BASE; diff --git a/boot/x86/x86.asm b/boot/x86/x86.asm @@ -107,6 +107,4 @@ do_switch: pop edx pop ecx pop eax - iret - diff --git a/clean.img b/clean.img Binary files differ. diff --git a/includes/core/Kernel.hpp b/includes/core/Kernel.hpp @@ -32,6 +32,7 @@ class Kernel { IDE ide; Scheduler sch; ELF elf; + int is_panic; }; # include <Modules.hpp> diff --git a/includes/core/ProcessTable.hpp b/includes/core/ProcessTable.hpp @@ -17,6 +17,9 @@ class ProcessTable { void change_process_father(Process *p, Process *f); void destroy_all_zombies(void); + // TMP + int load_function(u32 *code_phy_addr, u32 *fn, unsigned int code_size); + Process *get_current(void); Process *get_list(void); diff --git a/kernel/ELF.cpp b/kernel/ELF.cpp @@ -32,8 +32,10 @@ u32 ELF::load_elf(char *file, process_st *proc) { if (p_entry->p_type == PT_LOAD) { v_begin = p_entry->p_vaddr; v_end = p_entry->p_vaddr + p_entry->p_memsz; - if (v_begin < USER_OFFSET || v_end > USER_STACK) + if (v_begin < USER_OFFSET || v_end > USER_STACK) { + __kern.io.printk("%d - %d | %d - %d\n", v_begin, USER_OFFSET, v_end, USER_STACK); __kern.io.panic("ELF: load_elf(): Can't load executable"); + } if (p_entry->p_flags == PF_X + PF_R) { proc->b_exec = (char *)v_begin; proc->e_exec = (char *)v_end; diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -192,6 +192,7 @@ void Io::panic(const char *s) { if (this->_in_loading) this->printk("[%e FAIL %e]", COLOR_RED, COLOR_WHITE); this->printk("\n[%e PANIC %e]: %s", COLOR_RED, COLOR_WHITE, s); + __kern.is_panic = 1; asm("hlt"); while (1); // Reboot diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -25,6 +25,7 @@ Kernel::Kernel(void) { } void Kernel::init(multiboot_info *mbi) { + this->is_panic = 0; this->io = __io; this->gdt = __gdt; this->idt = __idt; @@ -48,8 +49,7 @@ void Kernel::init(multiboot_info *mbi) { __kern.io.puts("\n"); asm("sti"); //list_files(this->fs.get_root(), 0); - char *p[] = {"Test", 0x0}; - this->elf.execv("./a.out", 0, p); + this->elf.execv("/hello", 0, 0x0); while (1); } diff --git a/kernel/ProcessTable.cpp b/kernel/ProcessTable.cpp @@ -5,9 +5,13 @@ void ProcessTable::init(void) { this->_first = new Process("kernel"); this->_first->set_state(P_ZOMBIE); this->_first->add_file(__kern.fs.path("/dev/tty"), 0); + this->_first->add_file(__kern.fs.path("/dev/tty"), 0); + this->_first->add_file(__kern.fs.path("/dev/tty"), 0); this->_list = this->_first; this->_current = this->_first; this->_current->set_p_next(0x0); + process_st* current= this->_current->get_p_info(); + current->regs.cr3 = (u32)__kern.mem.get_pd0(); __kern.io.done(); } @@ -80,7 +84,9 @@ int ProcessTable::create_proc(process_st *info, char *f, int ac, char **av) { this->_init_info(info, stackp, kstack, e_entry); this->_current = (Process *)previous->vinfo; current = this->_current->get_p_info(); + __kern.io.printk("Adding %s ...", ((Process *)info->vinfo)->get_name()); asm("mov %0, %%eax ;mov %%eax, %%cr3":: "m"(current->regs.cr3)); + __kern.io.printk("Done \n"); return 1; } diff --git a/kernel/Scheduler.cpp b/kernel/Scheduler.cpp @@ -69,8 +69,8 @@ void Scheduler::_switch_to_task(process_st *current, int mode) { kss = current->regs.ss; kesp = current->regs.esp; } - __kern.io.printk("Switching to %x", current->regs.eip); - asm(" mov %0, %%ss; \ + __kern.io.printk("Switching to %x (%s)\n", current->regs.eip, ((Process *)(current->vinfo))->get_name()); + asm(" mov %0, %%ss; \ mov %1, %%esp; \ cmp %[KMODE], %[mode]; \ je nextt; \ @@ -81,7 +81,7 @@ void Scheduler::_switch_to_task(process_st *current, int mode) { push %5; \ push %6; \ push %7; \ - ljmp $0x08, $do_switch" + ljmp $0x08, $do_switch" :: \ "m"(kss), \ "m"(kesp), \ @@ -94,6 +94,7 @@ void Scheduler::_switch_to_task(process_st *current, int mode) { [KMODE] "i"(KERNELMODE), \ [mode] "g"(mode) ); + __kern.io.printk("Hey !"); } int Scheduler::_dequeue_signal(int mask) {