os/kernelhwsrv/kerneltest/e32test/nkernsa/x86/x86utils.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
// e32test\nkernsa\x86\x86utils.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <x86.h>
sl@0
    19
#include <nktest/nkutils.h>
sl@0
    20
sl@0
    21
sl@0
    22
extern "C" {
sl@0
    23
sl@0
    24
void __fastcall thread_request_signal(NThread* aThread);
sl@0
    25
sl@0
    26
extern TUint64 fcf;
sl@0
    27
extern TUint32 nfcf;
sl@0
    28
extern TUint32 nfcfs;
sl@0
    29
sl@0
    30
__NAKED__ void __cpu_idle()
sl@0
    31
	{
sl@0
    32
	asm("hlt");
sl@0
    33
	asm("ret");
sl@0
    34
	}
sl@0
    35
sl@0
    36
__NAKED__ void __cpu_yield()
sl@0
    37
	{
sl@0
    38
	X86_PAUSE
sl@0
    39
	asm("ret");
sl@0
    40
	}
sl@0
    41
sl@0
    42
__NAKED__ TLinAddr __stack_pointer()
sl@0
    43
	{
sl@0
    44
	asm("mov eax, esp");
sl@0
    45
	asm("ret");
sl@0
    46
	}
sl@0
    47
sl@0
    48
__NAKED__ TUint32 __cpu_status_reg()
sl@0
    49
	{
sl@0
    50
	asm("pushfd");
sl@0
    51
	asm("pop eax");
sl@0
    52
	asm("ret");
sl@0
    53
	}
sl@0
    54
sl@0
    55
__NAKED__ TUint32 __cpu_id()
sl@0
    56
	{
sl@0
    57
	asm("xor eax, eax");
sl@0
    58
	asm("str ax");
sl@0
    59
	asm("ret");
sl@0
    60
	}
sl@0
    61
sl@0
    62
__NAKED__ TUint32 __trace_cpu_num()
sl@0
    63
	{
sl@0
    64
	asm("xor eax, eax");
sl@0
    65
	asm("str ax");
sl@0
    66
	asm("sub al, 0x28");
sl@0
    67
	asm("shr al, 3");
sl@0
    68
	asm("ret");
sl@0
    69
	}
sl@0
    70
sl@0
    71
TUint64 __NAKED__ fast_counter()
sl@0
    72
	{
sl@0
    73
	asm("rdtsc");
sl@0
    74
	asm("ret");
sl@0
    75
	}
sl@0
    76
sl@0
    77
TUint32 __NAKED__ norm_fast_counter()
sl@0
    78
	{
sl@0
    79
	asm("mov ecx, [%a0]": :"i"(&nfcfs));
sl@0
    80
	asm("rdtsc");
sl@0
    81
	asm("shrd eax, edx, cl");
sl@0
    82
	asm("ret");
sl@0
    83
	}
sl@0
    84
sl@0
    85
__NAKED__ void nfcfspin(TUint32 aTicks)
sl@0
    86
	{
sl@0
    87
	asm("mov ecx, [%a0]": :"i"(&nfcfs));
sl@0
    88
	asm("push ebx");
sl@0
    89
	asm("mov ebx, [esp+8]");
sl@0
    90
	asm("rdtsc");
sl@0
    91
	asm("shrd eax, edx, cl");
sl@0
    92
	asm("add ebx, eax");
sl@0
    93
	asm("nfcfspin1:");
sl@0
    94
	asm("rdtsc");
sl@0
    95
	asm("shrd eax, edx, cl");
sl@0
    96
	asm("sub eax, ebx");
sl@0
    97
	asm("js nfcfspin1");
sl@0
    98
	asm("pop ebx");
sl@0
    99
	asm("ret");
sl@0
   100
	}
sl@0
   101
sl@0
   102
__NAKED__ void fcfspin(TUint64 aTicks)
sl@0
   103
	{
sl@0
   104
	asm("mov ecx, [esp+4]");
sl@0
   105
	asm("push ebx");
sl@0
   106
	asm("mov ebx, [esp+12]");
sl@0
   107
	asm("rdtsc");
sl@0
   108
	asm("add ecx, eax");
sl@0
   109
	asm("adc ebx, edx");
sl@0
   110
	asm("fcfspin1:");
sl@0
   111
	asm("rdtsc");
sl@0
   112
	asm("sub eax, ecx");
sl@0
   113
	asm("sbb edx, ebx");
sl@0
   114
	asm("js fcfspin1");
sl@0
   115
	asm("pop ebx");
sl@0
   116
	asm("ret");
sl@0
   117
	}
sl@0
   118
sl@0
   119
__NAKED__ TUint32 set_bit0_if_nonnull(TUint32&)
sl@0
   120
	{
sl@0
   121
	asm("mov ecx, [esp+4]");
sl@0
   122
	asm("mov eax, [ecx]");
sl@0
   123
	asm("xx1:");
sl@0
   124
	asm("cmp eax, 0");
sl@0
   125
	asm("jz short done1");
sl@0
   126
	asm("mov edx, eax");
sl@0
   127
	asm("or edx, 1");
sl@0
   128
	asm("lock cmpxchg [ecx], edx");
sl@0
   129
	asm("jne short xx1");
sl@0
   130
	asm("done1:");
sl@0
   131
	asm("ret");
sl@0
   132
	}
sl@0
   133
sl@0
   134
__NAKED__ void flip_bit0(TUint32&)
sl@0
   135
	{
sl@0
   136
	asm("mov ecx, [esp+4]");
sl@0
   137
	asm("lock xor dword ptr [ecx], 1");
sl@0
   138
	asm("ret");
sl@0
   139
	}
sl@0
   140
sl@0
   141
__NAKED__ TUint32 swap_out_if_bit0_clear(TUint32&)
sl@0
   142
	{
sl@0
   143
	asm("mov ecx, [esp+4]");
sl@0
   144
	asm("mov eax, [ecx]");
sl@0
   145
	asm("xx2:");
sl@0
   146
	asm("test eax, 1");
sl@0
   147
	asm("jnz short done2");
sl@0
   148
	asm("xor edx, edx");
sl@0
   149
	asm("lock cmpxchg [ecx], edx");
sl@0
   150
	asm("jne short xx2");
sl@0
   151
	asm("done2:");
sl@0
   152
	asm("ret");
sl@0
   153
	}
sl@0
   154
sl@0
   155
__NAKED__ TUint32 __eflags()
sl@0
   156
	{
sl@0
   157
	asm("pushfd ");
sl@0
   158
	asm("pop eax ");
sl@0
   159
	asm("ret ");
sl@0
   160
	}
sl@0
   161
}
sl@0
   162
sl@0
   163
__NAKED__ void RequestComplete(NThread* /*aThread*/, NRequestStatus*& /*aStatus*/, TInt /*aValue*/)
sl@0
   164
	{
sl@0
   165
	asm("mov ecx, [esp+8]");
sl@0
   166
	asm("xor eax, eax");
sl@0
   167
	asm("lock xchg eax, [ecx]");
sl@0
   168
	asm("mov edx, [esp+12]");
sl@0
   169
	asm("cmp eax, 0");
sl@0
   170
	asm("jz done3");
sl@0
   171
	asm("mov ecx, [esp+4]");
sl@0
   172
	asm("mov [eax], edx");
sl@0
   173
	asm("call %a0": :"i"(&thread_request_signal));
sl@0
   174
	asm("done3:");
sl@0
   175
	asm("ret");
sl@0
   176
	}
sl@0
   177
sl@0
   178