Author: bonefish Date: 2010-06-06 00:09:24 +0200 (Sun, 06 Jun 2010) New Revision: 37024 Changeset: http://dev.haiku-os.org/changeset/37024/haiku Modified: haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp haiku/trunk/src/system/kernel/arch/x86/arch_x86.S Log: x86: * Renamed i386_context_switch() to x86_context_switch(). * x86_context_switch() no longer sets the page directory. arch_thread_context_switch() does that explicitly, now. This allows to solve the TODO by reordering releasing the previous paging structures reference and setting the new page directory. Modified: haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h 2010-06-05 21:53:32 UTC (rev 37023) +++ haiku/trunk/headers/private/kernel/arch/x86/arch_cpu.h 2010-06-05 22:09:24 UTC (rev 37024) @@ -271,8 +271,8 @@ void __x86_setup_system_time(uint32 conversionFactor, uint32 conversionFactorNsecs, bool conversionFactorNsecsShift); -void i386_context_switch(struct arch_thread* oldState, - struct arch_thread* newState, uint32 newPageDir); +void x86_context_switch(struct arch_thread* oldState, + struct arch_thread* newState); void x86_userspace_thread_exit(void); void x86_end_userspace_thread_exit(void); void x86_enter_userspace(addr_t entry, addr_t stackTop); Modified: haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2010-06-05 21:53:32 UTC (rev 37023) +++ haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2010-06-05 22:09:24 UTC (rev 37024) @@ -370,7 +370,6 @@ = cpuData->arch.active_paging_structures; VMAddressSpace* toAddressSpace = to->team->address_space; - uint32 newPageDirectory; X86PagingStructures* toPagingStructures; if (toAddressSpace != NULL && (toPagingStructures = static_cast<X86VMTranslationMap*>( @@ -382,23 +381,21 @@ ~((uint32)1 << cpu)); atomic_or(&toPagingStructures->active_on_cpus, (uint32)1 << cpu); - activePagingStructures->RemoveReference(); -// TODO: This might cause deferred deletion, which on SMP machines could happen -// right now on another CPU! - // assign the new paging structures to the CPU toPagingStructures->AddReference(); cpuData->arch.active_paging_structures = toPagingStructures; - // get the new page directory - newPageDirectory = toPagingStructures->pgdir_phys; - } else { - newPageDirectory = 0; - // this means no change + // set the page directory, if it changes + uint32 newPageDirectory = toPagingStructures->pgdir_phys; + if (newPageDirectory != activePagingStructures->pgdir_phys) + x86_swap_pgdir(newPageDirectory); + + // This CPU no longer uses the previous paging structures. + activePagingStructures->RemoveReference(); } gX86SwapFPUFunc(from->arch_info.fpu_state, to->arch_info.fpu_state); - i386_context_switch(&from->arch_info, &to->arch_info, newPageDirectory); + x86_context_switch(&from->arch_info, &to->arch_info); } Modified: haiku/trunk/src/system/kernel/arch/x86/arch_x86.S =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_x86.S 2010-06-05 21:53:32 UTC (rev 37023) +++ haiku/trunk/src/system/kernel/arch/x86/arch_x86.S 2010-06-05 22:09:24 UTC (rev 37024) @@ -121,25 +121,20 @@ ret FUNCTION_END(x86_write_msr) -/* void i386_context_switch(struct arch_thread *old_state, - struct arch_thread *new_state, uint32 new_pgdir); */ -FUNCTION(i386_context_switch): +/* void x86_context_switch(struct arch_thread* oldState, + struct arch_thread* newState); */ +FUNCTION(x86_context_switch): pusha /* pushes 8 words onto the stack */ - movl 36(%esp),%eax /* save old_state->current_stack */ + movl 36(%esp),%eax /* save oldState->current_stack */ movl %esp,(%eax) pushl %ss popl %edx movl %edx,4(%eax) - movl 44(%esp),%eax /* get possible new pgdir */ - orl %eax,%eax /* is it null? */ - je skip_pgdir_swap - movl %eax,%cr3 -skip_pgdir_swap: - movl 40(%esp),%eax /* get new new_state->current_stack */ + movl 40(%esp),%eax /* get new newState->current_stack */ lss (%eax),%esp popa ret -FUNCTION_END(i386_context_switch) +FUNCTION_END(x86_context_switch) /* void x86_swap_pgdir(uint32 newPageDir); */ FUNCTION(x86_swap_pgdir):