os/kernelhwsrv/kerneltest/e32test/nkernsa/x86/x86utils.cia
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/nkernsa/x86/x86utils.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\nkernsa\x86\x86utils.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <x86.h>
    1.22 +#include <nktest/nkutils.h>
    1.23 +
    1.24 +
    1.25 +extern "C" {
    1.26 +
    1.27 +void __fastcall thread_request_signal(NThread* aThread);
    1.28 +
    1.29 +extern TUint64 fcf;
    1.30 +extern TUint32 nfcf;
    1.31 +extern TUint32 nfcfs;
    1.32 +
    1.33 +__NAKED__ void __cpu_idle()
    1.34 +	{
    1.35 +	asm("hlt");
    1.36 +	asm("ret");
    1.37 +	}
    1.38 +
    1.39 +__NAKED__ void __cpu_yield()
    1.40 +	{
    1.41 +	X86_PAUSE
    1.42 +	asm("ret");
    1.43 +	}
    1.44 +
    1.45 +__NAKED__ TLinAddr __stack_pointer()
    1.46 +	{
    1.47 +	asm("mov eax, esp");
    1.48 +	asm("ret");
    1.49 +	}
    1.50 +
    1.51 +__NAKED__ TUint32 __cpu_status_reg()
    1.52 +	{
    1.53 +	asm("pushfd");
    1.54 +	asm("pop eax");
    1.55 +	asm("ret");
    1.56 +	}
    1.57 +
    1.58 +__NAKED__ TUint32 __cpu_id()
    1.59 +	{
    1.60 +	asm("xor eax, eax");
    1.61 +	asm("str ax");
    1.62 +	asm("ret");
    1.63 +	}
    1.64 +
    1.65 +__NAKED__ TUint32 __trace_cpu_num()
    1.66 +	{
    1.67 +	asm("xor eax, eax");
    1.68 +	asm("str ax");
    1.69 +	asm("sub al, 0x28");
    1.70 +	asm("shr al, 3");
    1.71 +	asm("ret");
    1.72 +	}
    1.73 +
    1.74 +TUint64 __NAKED__ fast_counter()
    1.75 +	{
    1.76 +	asm("rdtsc");
    1.77 +	asm("ret");
    1.78 +	}
    1.79 +
    1.80 +TUint32 __NAKED__ norm_fast_counter()
    1.81 +	{
    1.82 +	asm("mov ecx, [%a0]": :"i"(&nfcfs));
    1.83 +	asm("rdtsc");
    1.84 +	asm("shrd eax, edx, cl");
    1.85 +	asm("ret");
    1.86 +	}
    1.87 +
    1.88 +__NAKED__ void nfcfspin(TUint32 aTicks)
    1.89 +	{
    1.90 +	asm("mov ecx, [%a0]": :"i"(&nfcfs));
    1.91 +	asm("push ebx");
    1.92 +	asm("mov ebx, [esp+8]");
    1.93 +	asm("rdtsc");
    1.94 +	asm("shrd eax, edx, cl");
    1.95 +	asm("add ebx, eax");
    1.96 +	asm("nfcfspin1:");
    1.97 +	asm("rdtsc");
    1.98 +	asm("shrd eax, edx, cl");
    1.99 +	asm("sub eax, ebx");
   1.100 +	asm("js nfcfspin1");
   1.101 +	asm("pop ebx");
   1.102 +	asm("ret");
   1.103 +	}
   1.104 +
   1.105 +__NAKED__ void fcfspin(TUint64 aTicks)
   1.106 +	{
   1.107 +	asm("mov ecx, [esp+4]");
   1.108 +	asm("push ebx");
   1.109 +	asm("mov ebx, [esp+12]");
   1.110 +	asm("rdtsc");
   1.111 +	asm("add ecx, eax");
   1.112 +	asm("adc ebx, edx");
   1.113 +	asm("fcfspin1:");
   1.114 +	asm("rdtsc");
   1.115 +	asm("sub eax, ecx");
   1.116 +	asm("sbb edx, ebx");
   1.117 +	asm("js fcfspin1");
   1.118 +	asm("pop ebx");
   1.119 +	asm("ret");
   1.120 +	}
   1.121 +
   1.122 +__NAKED__ TUint32 set_bit0_if_nonnull(TUint32&)
   1.123 +	{
   1.124 +	asm("mov ecx, [esp+4]");
   1.125 +	asm("mov eax, [ecx]");
   1.126 +	asm("xx1:");
   1.127 +	asm("cmp eax, 0");
   1.128 +	asm("jz short done1");
   1.129 +	asm("mov edx, eax");
   1.130 +	asm("or edx, 1");
   1.131 +	asm("lock cmpxchg [ecx], edx");
   1.132 +	asm("jne short xx1");
   1.133 +	asm("done1:");
   1.134 +	asm("ret");
   1.135 +	}
   1.136 +
   1.137 +__NAKED__ void flip_bit0(TUint32&)
   1.138 +	{
   1.139 +	asm("mov ecx, [esp+4]");
   1.140 +	asm("lock xor dword ptr [ecx], 1");
   1.141 +	asm("ret");
   1.142 +	}
   1.143 +
   1.144 +__NAKED__ TUint32 swap_out_if_bit0_clear(TUint32&)
   1.145 +	{
   1.146 +	asm("mov ecx, [esp+4]");
   1.147 +	asm("mov eax, [ecx]");
   1.148 +	asm("xx2:");
   1.149 +	asm("test eax, 1");
   1.150 +	asm("jnz short done2");
   1.151 +	asm("xor edx, edx");
   1.152 +	asm("lock cmpxchg [ecx], edx");
   1.153 +	asm("jne short xx2");
   1.154 +	asm("done2:");
   1.155 +	asm("ret");
   1.156 +	}
   1.157 +
   1.158 +__NAKED__ TUint32 __eflags()
   1.159 +	{
   1.160 +	asm("pushfd ");
   1.161 +	asm("pop eax ");
   1.162 +	asm("ret ");
   1.163 +	}
   1.164 +}
   1.165 +
   1.166 +__NAKED__ void RequestComplete(NThread* /*aThread*/, NRequestStatus*& /*aStatus*/, TInt /*aValue*/)
   1.167 +	{
   1.168 +	asm("mov ecx, [esp+8]");
   1.169 +	asm("xor eax, eax");
   1.170 +	asm("lock xchg eax, [ecx]");
   1.171 +	asm("mov edx, [esp+12]");
   1.172 +	asm("cmp eax, 0");
   1.173 +	asm("jz done3");
   1.174 +	asm("mov ecx, [esp+4]");
   1.175 +	asm("mov [eax], edx");
   1.176 +	asm("call %a0": :"i"(&thread_request_signal));
   1.177 +	asm("done3:");
   1.178 +	asm("ret");
   1.179 +	}
   1.180 +
   1.181 +