diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-08-30 18:32:21 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-08-30 18:32:21 +0200 |
| commit | 837255c8ff040f84699d3c2efd329fc04dbafbdf (patch) | |
| tree | 69e7f907818c289e615c216c242f055acf45d55c /kernel/kernel.c | |
| parent | e733ac719f0bec2bd8f749dbca4de8ad524aaddb (diff) | |
Added multitasking support for two tasks ;)
Diffstat (limited to 'kernel/kernel.c')
| -rw-r--r-- | kernel/kernel.c | 87 |
1 files changed, 70 insertions, 17 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c index 88df43e..eee66d7 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -24,24 +24,56 @@ void int_floppy_handler(); uint32_t read_eip(); -// just a test handler for software interrupt 88, todo: remove and -// implement some syscalls! -// -void int_test_handler_worker() -{ - // this can not be called directly from interrupt handler - // due to optional parameters (...) probably! - panic(FOOLOS_MODULE_NAME,"unhandled EXCEPTION!"); -} -void int_test_handler() +void int_unhandled() { X86_IRQ_BEGIN - int_test_handler_worker(); - sleep(30); - while(1); // hang! + panic(FOOLOS_MODULE_NAME,"unhandled EXCEPTION!"); X86_IRQ_END } +void int_irq0(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Divide by 0"); X86_IRQ_END } +void int_irq1(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Single step (debugger)"); X86_IRQ_END } +void int_irq2(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Non Maskable Interrupt"); X86_IRQ_END } +void int_irq3(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Breakpoint (debugger)"); X86_IRQ_END } +void int_irq4(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Overflow"); X86_IRQ_END } +void int_irq5(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Bounds check"); X86_IRQ_END } +void int_irq6(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Undefined OP Code"); X86_IRQ_END } +void int_irq7(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"No coprocessor"); X86_IRQ_END } +void int_irq8(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Double Fault"); X86_IRQ_END } +void int_irq9(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor Segment Overrun"); X86_IRQ_END } +void int_irq10(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Invalid TSS"); X86_IRQ_END } +void int_irq11(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Segment Not Present"); X86_IRQ_END } +void int_irq12(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Stack Segment Overrun"); X86_IRQ_END } + +void show_error(uint32_t err) +{ + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"interrupt error code: 0x%08x",err); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"External Event: %x",err&0b001); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Location: %x",err&0b110); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Selector: %x",err&0b1111111111111000); +} + +void int_irq13() +{ + X86_IRQ_BEGIN + + + uint32_t err; + asm("pop %eax"); // get Error Code + asm ("mov %%eax, %0":"=r"(err)); + show_error(err); + + panic(FOOLOS_MODULE_NAME,"General Protection Fault"); + + X86_IRQ_END +} + +void int_irq14(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Page Fault"); X86_IRQ_END } +void int_irq15(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Unassigned"); X86_IRQ_END } +void int_irq16(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor error"); X86_IRQ_END } +void int_irq17(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Alignment Check"); X86_IRQ_END } +void int_irq18(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Machine Check"); X86_IRQ_END } + // heart of our operating system. void kernel_main(uint32_t initial_stack) { @@ -69,7 +101,6 @@ void kernel_main(uint32_t initial_stack) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); - // // PIT config (timer) timer_init(); @@ -104,10 +135,31 @@ void kernel_main(uint32_t initial_stack) int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); // install test software interrupt handler - int_install_ir(88, 0b10001110, 0x08,&int_test_handler); + int_install_ir(88, 0b10001110, 0x08,&int_unhandled); - for(int i=0;i<19;i++) - int_install_ir(i, 0b10001110, 0x08,&int_test_handler); + // exceptions + int_install_ir(0, 0b10001110, 0x08,&int_irq0); + int_install_ir(1, 0b10001110, 0x08,&int_irq1); + int_install_ir(2, 0b10001110, 0x08,&int_irq2); + int_install_ir(3, 0b10001110, 0x08,&int_irq3); + int_install_ir(4, 0b10001110, 0x08,&int_irq4); + int_install_ir(5, 0b10001110, 0x08,&int_irq5); + int_install_ir(6, 0b10001110, 0x08,&int_irq6); + int_install_ir(7, 0b10001110, 0x08,&int_irq7); + int_install_ir(8, 0b10001110, 0x08,&int_irq8); + int_install_ir(9, 0b10001110, 0x08,&int_irq9); + int_install_ir(10, 0b10001110, 0x08,&int_irq10); + int_install_ir(11, 0b10001110, 0x08,&int_irq11); + int_install_ir(12, 0b10001110, 0x08,&int_irq12); + int_install_ir(13, 0b10001110, 0x08,&int_irq13); + int_install_ir(14, 0b10001110, 0x08,&int_irq14); + int_install_ir(15, 0b10001110, 0x08,&int_irq15); + int_install_ir(16, 0b10001110, 0x08,&int_irq16); + int_install_ir(17, 0b10001110, 0x08,&int_irq17); + int_install_ir(18, 0b10001110, 0x08,&int_irq18); + + // multitasking + task_init(); // now we can enable interrupts back again int_enable(); @@ -120,6 +172,7 @@ void kernel_main(uint32_t initial_stack) // floppy floppy_init(); + //init shell shell_init(); /* |
