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