os/kernelhwsrv/kernel/eka/memmodel/epoc/multiple/x86/xmmu.cia
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\memmodel\epoc\multiple\x86\xmmu.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <x86_mem.h>
sl@0
    19
sl@0
    20
#if defined(KMMU)
sl@0
    21
extern "C" void __DebugMsgFlushTLB();
sl@0
    22
extern "C" void __DebugMsgLocalFlushTLB();
sl@0
    23
extern "C" void __DebugMsgTotalFlushTLB();
sl@0
    24
extern "C" void __DebugMsgINVLPG(int a);
sl@0
    25
#endif
sl@0
    26
sl@0
    27
sl@0
    28
extern "C"
sl@0
    29
{
sl@0
    30
sl@0
    31
sl@0
    32
__NAKED__ void __fastcall DoInvalidateTLBForPage(TLinAddr /*aLinAddr*/)
sl@0
    33
//
sl@0
    34
// Flush a specified virtual address from the TLB.
sl@0
    35
//
sl@0
    36
	{
sl@0
    37
	ASM_DEBUG1(INVLPG,ecx)
sl@0
    38
	asm("invlpg [ecx]");
sl@0
    39
	asm("ret");
sl@0
    40
	}
sl@0
    41
sl@0
    42
// On 486 and Pentium this invalidates all TLB entries.
sl@0
    43
// On P6 and later CPUs it only invalidates non-global TLB entries.
sl@0
    44
__NAKED__ void DoLocalInvalidateTLB()
sl@0
    45
	{
sl@0
    46
	ASM_DEBUG0(LocalFlushTLB)
sl@0
    47
	asm("mov eax, cr3");
sl@0
    48
	asm("mov cr3, eax");
sl@0
    49
	asm("ret");
sl@0
    50
	}
sl@0
    51
sl@0
    52
// This function is only used on P6 and later CPUs.
sl@0
    53
// It invalidates all TLB entries, including global ones.
sl@0
    54
extern "C" __NAKED__ void DoTotalInvalidateTLB()
sl@0
    55
	{
sl@0
    56
	ASM_DEBUG0(TotalFlushTLB)
sl@0
    57
	asm("pushfd");
sl@0
    58
	asm("mov eax, cr3");
sl@0
    59
	MOV_ECX_CR4;
sl@0
    60
	asm("mov edx, ecx");
sl@0
    61
	asm("and dl, 0x7f");
sl@0
    62
	asm("cli");
sl@0
    63
	MOV_CR4_EDX;
sl@0
    64
	asm("mov cr3, eax");
sl@0
    65
	MOV_CR4_ECX;
sl@0
    66
	asm("popfd");
sl@0
    67
	asm("ret");
sl@0
    68
	}
sl@0
    69
sl@0
    70
// Invalidate all TLB entries regardless of CPU type.
sl@0
    71
__NAKED__ void DoInvalidateTLB()
sl@0
    72
	{
sl@0
    73
	ASM_DEBUG0(FlushTLB)
sl@0
    74
	asm("mov edx, [%a0]": : "i"(&X86_UseGlobalPTEs));
sl@0
    75
	asm("mov eax, cr3");
sl@0
    76
	asm("cmp edx, 0");
sl@0
    77
	asm("jz no_global_pages");
sl@0
    78
	MOV_ECX_CR4;
sl@0
    79
	asm("mov edx, ecx");
sl@0
    80
	asm("and dl, 0x7f");
sl@0
    81
	asm("pushfd");
sl@0
    82
	asm("cli");
sl@0
    83
	MOV_CR4_EDX;
sl@0
    84
	asm("mov cr3, eax");
sl@0
    85
	MOV_CR4_ECX;
sl@0
    86
	asm("popfd");
sl@0
    87
	asm("ret");
sl@0
    88
	asm("no_global_pages:");
sl@0
    89
	asm("mov cr3, eax");
sl@0
    90
	asm("ret");
sl@0
    91
	}
sl@0
    92
}
sl@0
    93
sl@0
    94
__NAKED__ void DMemModelThread::RestoreAddressSpace()
sl@0
    95
	{
sl@0
    96
#ifndef __SMP__
sl@0
    97
	//SMP FIXME
sl@0
    98
	asm("mov eax, [%a0]": : "i"(&TheScheduler.iCurrentThread));
sl@0
    99
sl@0
   100
	// edx = current thread owning process...
sl@0
   101
	asm("mov edx, 0");
sl@0
   102
	asm("lea edx, [edx+%0]": : "i"_FOFF(DThread,iNThread));
sl@0
   103
	asm("neg edx");
sl@0
   104
	asm("mov edx, [eax+edx+%0]": : "i"_FOFF(DThread,iOwningProcess));
sl@0
   105
sl@0
   106
	// update page directory and address space values...
sl@0
   107
	asm("cli");
sl@0
   108
	asm("mov [%a0], edx": :"i"(&TheScheduler.iAddressSpace));
sl@0
   109
	asm("mov [eax+%0], edx": : "i"_FOFF(NThreadBase,iAddressSpace));
sl@0
   110
	asm("mov edx, [edx+%0]": : "i"_FOFF(DMemModelProcess,iGlobalPageDir));
sl@0
   111
	asm("mov cr3, edx");
sl@0
   112
	asm("sti");
sl@0
   113
#endif
sl@0
   114
	asm("ret");
sl@0
   115
	}
sl@0
   116
sl@0
   117