diff --git a/kernel/cpu/i386/isr.c b/kernel/cpu/i386/isr.c index e47463d..59ca89e 100644 --- a/kernel/cpu/i386/isr.c +++ b/kernel/cpu/i386/isr.c @@ -291,7 +291,7 @@ void isr_handler(registers_t* r) { break; default: break; - } + } break; } } @@ -310,13 +310,17 @@ void isr_register_handler(int n,isr_t handler) { * \param r The saved state of the CPU */ void irq_handler(registers_t* r) { - /* After every interrupt we need to send an EOI to the PICs - * or they will not send another interrupt again */ - if (r->int_no >= 40) port_byte_out(0xA0,0x20); /* slave */ - port_byte_out(0x20,0x20); /* master */ - /* Handle the interrupt in a more modular way */ - if (irq_handlers[r->int_no-32] != NULL) { - isr_t handler = irq_handlers[r->int_no-32]; - handler(r); + /* After every interrupt we need to send an EOI to the PICs + * or they will not send another interrupt again */ + if (r->int_no >= 40) port_byte_out(0xA0,0x20); /* slave */ + port_byte_out(0x20,0x20); /* master */ + /* Handle the interrupt in a more modular way */ + if (irq_handlers[r->int_no-32] != NULL) { + isr_t handler = irq_handlers[r->int_no-32]; + if((uint32_t)handler<32768) { + kernel_rpc_call((pid_t)handler,"irq_handler",NULL,NULL); + } else { + handler(r); } + } } diff --git a/kernel/cpu/i386/paging.c b/kernel/cpu/i386/paging.c index 5687611..0543e7b 100644 --- a/kernel/cpu/i386/paging.c +++ b/kernel/cpu/i386/paging.c @@ -33,12 +33,8 @@ static pg_struct_entry kstack_page_tables[218*1024] __attribute__((aligned(4096) static pg_struct_entry kmalloc_page_tables[4*1024] __attribute__((aligned(4096))); //!< Page tables for the kmalloc heap static pg_struct_entry* pagdirmap=(pg_struct_entry*)0xFFFFF000; //!< Pointer to the page directory entries in the recursive mapping static pg_struct_entry* page_table_map=(pg_struct_entry*)0xFFC00000; //!< Pointer to the page table entries in the recursive mapping -/** - * Checks whether a page is present - * \param page The page number to check - * \return Whether the page is present -*/ -static char is_page_present(size_t page) { + +char is_page_present(size_t page) { int table=page>>10; page=page&0x3FF; if (!pagdirmap[table].pres) { diff --git a/kernel/cpu/i386/tasking_helpers_c.c b/kernel/cpu/i386/tasking_helpers_c.c index 4defe8d..31f146a 100644 --- a/kernel/cpu/i386/tasking_helpers_c.c +++ b/kernel/cpu/i386/tasking_helpers_c.c @@ -7,6 +7,7 @@ #include "../tasking_helpers.h" #include "../../pmem.h" #include +#include static void** kstacks=(void*)0xC8000000; //!< Pointer to all the thread kernel stacks static char kstack_bmap[(218*1024)/8]={0}; //!< Bitmap of what kernel stacks have been allocated @@ -49,7 +50,9 @@ static int new_kstack() { return -1; } mark_kstack_allocated(num); - map_pages(((char*)kstacks+num*0x1000),pmem_alloc(1),1,1,1); + if (!is_page_present(((uint32_t)((char*)kstacks+num*0x1000))>>12)) { + map_pages(((char*)kstacks+num*0x1000),pmem_alloc(1),1,1,1); + } return num; } @@ -76,3 +79,12 @@ void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip) kstacks[top_idx-1]=(void*)eip; } } + +void free_kstack(void* stack_ptr) { + uint32_t stack=(uint32_t)stack_ptr; + stack-=0xC8000000; + stack=stack>>12; + size_t byte=stack/8; + size_t bit=stack%8; + kstack_bmap[byte]=kstack_bmap[byte]&(~(1< /** * Run a block of code in a different address space @@ -87,4 +88,11 @@ void* find_free_pages(int num_pages); */ void* get_address_space(); +/** + * Checks whether a page is present + * \param page The page number to check + * \return Whether the page is present +*/ +char is_page_present(size_t page); + #endif diff --git a/kernel/cpu/tasking_helpers.h b/kernel/cpu/tasking_helpers.h index 7b7f016..ec43ced 100644 --- a/kernel/cpu/tasking_helpers.h +++ b/kernel/cpu/tasking_helpers.h @@ -34,4 +34,10 @@ void wait_for_unblocked_thread_asm(); */ void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip); +/** + * Frees a kernel stack so it can be used again + * \param stack_ptr The kernel stack to free +*/ +void free_kstack(void* stack_ptr); + #endif diff --git a/kernel/tasking.c b/kernel/tasking.c index f5a616b..82592ed 100644 --- a/kernel/tasking.c +++ b/kernel/tasking.c @@ -274,6 +274,9 @@ void tasking_block(thread_state newstate) { } } current_thread->process->num_threads_blocked++; + if (current_thread->process->num_threads_blocked==current_thread->process->num_threads) { + unmark_proc_scheduled(current_thread->process->pid); + } tasking_yield(); } @@ -332,7 +335,7 @@ void tasking_exit(int code) { ready_to_run_tail=ready_to_run_tail->prev_ready_to_run; if (ready_to_run_tail==NULL) { ready_to_run_head=NULL; - + } } if (ready_to_run_head&&ready_to_run_head->next_ready_to_run) { @@ -348,7 +351,10 @@ void tasking_exit(int code) { } unmark_proc_scheduled(current_thread->process->pid); for (Thread* thread=current_thread->process->first_thread;thread!=NULL;thread=thread->next_thread_in_process) { - thread->state=THREAD_EXITED; + if (thread->state!=THREAD_EXITED) { + thread->state=THREAD_EXITED; + free_kstack(thread->kernel_esp_top); + } } current_thread->process->num_threads_blocked=current_thread->process->num_threads; num_procs--; @@ -383,6 +389,7 @@ void* tasking_get_rpc_ret_buf() { void tasking_thread_exit() { tasking_block(THREAD_EXITED); + free_kstack(current_thread->kernel_esp_top); } char tasking_check_proc_exists(pid_t pid) {