Partially fixed up tree after merge from HEAD. More to do.
[reactos.git] / reactos / ntoskrnl / include / internal / powerpc / ke.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_POWERPC_KE_H
20 #define __NTOSKRNL_INCLUDE_INTERNAL_POWERPC_KE_H
21
22 #include <ndk/powerpc/ketypes.h>
23
24 #if __GNUC__ >=3
25 #pragma GCC system_header
26 #endif
27
28 /* Possible values for KTHREAD's NpxState */
29 #define NPX_STATE_INVALID 0x01
30 #define NPX_STATE_VALID 0x02
31 #define NPX_STATE_DIRTY 0x04
32
33 #ifndef __ASM__
34
35 typedef struct _KIRQ_TRAPFRAME
36 {
37 } KIRQ_TRAPFRAME, *PKIRQ_TRAPFRAME;
38
39 extern ULONG KePPCCacheAlignment;
40
41 struct _KPCR;
42 VOID
43 KiInitializeGdt(struct _KPCR* Pcr);
44 VOID
45 KiPPCApplicationProcessorInitializeTSS(VOID);
46 VOID
47 KiPPCBootInitializeTSS(VOID);
48 VOID
49 KiGdtPrepareForApplicationProcessorInit(ULONG Id);
50 VOID
51 KiPPCInitializeLdt(VOID);
52 VOID
53 KiPPCSetProcessorFeatures(VOID);
54 ULONG KeAllocateGdtSelector(ULONG Desc[2]);
55 VOID KeFreeGdtSelector(ULONG Entry);
56 VOID
57 NtEarlyInitVdm(VOID);
58
59 #ifdef CONFIG_SMP
60 #define LOCK "isync ; "
61 #else
62 #define LOCK ""
63 #endif
64
65
66 static inline LONG KePPCTestAndClearBit(ULONG BitPos, volatile PULONG Addr)
67 {
68 ULONG OldValue, NewValue;
69
70 __asm__ __volatile__ ("lwarx %0,0,%1"
71 : "=r" (OldValue), "=r" (*Addr)
72 :
73 : "memory");
74
75 NewValue = OldValue & ~(1<<BitPos);
76
77 __asm__ __volatile__ ("stwcx. %0,0,%3\n\t"
78 "beq success\n\t"
79 "add %2,0,%1\n"
80 "success:\n\t"
81 "isync\n\t"
82 : "=r" (NewValue), "=r" (OldValue)
83 : "w" (NewValue), "w" (*Addr)
84 : "memory");
85
86 return NewValue & (1 << BitPos);
87 }
88
89 static inline LONG KePPCTestAndSetBit(ULONG BitPos, volatile PULONG Addr)
90 {
91 ULONG OldValue, NewValue;
92
93 __asm__ __volatile__ ("lwarx %0,0,%1"
94 : "=r" (OldValue), "=r" (*Addr)
95 :
96 : "memory");
97
98 NewValue = OldValue | (1<<BitPos);
99
100 __asm__ __volatile__ ("stwcx. %0,0,%3\n\t"
101 "beq success\n\t"
102 "add %2,0,%1\n"
103 "success:\n\t"
104 "isync\n\t"
105 : "=r" (NewValue), "=r" (OldValue)
106 : "w" (NewValue), "w" (*Addr)
107 : "memory");
108
109 return NewValue & (1 << BitPos);
110 }
111
112 #define KePPCRdmsr(msr,val1,val2) __asm__ __volatile__("mfmsr 2")
113
114 #define KePPCWrmsr(msr,val1,val2) __asm__ __volatile__("mtmsr 3")
115
116
117 #define KePPCDisableInterrupts() \
118 __asm__ __volatile__("mfmsr 0\n\t" \
119 "li 8,0x7fff\n\t" \
120 "and 0,8,0\n\t" \
121 "mtmsr 0\n\t")
122
123 #define KePPCEnableInterrupts() \
124 __asm__ __volatile__("mfmsr 0\n\t" \
125 "lis 8,0x8000@ha\n\t" \
126 "or 0,8,0\n\t" \
127 "mtmsr 0\n\t")
128
129 #define KePPCHaltProcessor() ;
130
131 #define KeArchEraseFlags()
132 #define KeArchDisableInterrupts() KePPCDisableInterrupts()
133
134 static __inline struct _KPRCB * KeGetCurrentPrcb(
135 VOID)
136 {
137 return (struct _KPRCB *)__readfsdword(0x20);
138 }
139
140 __inline struct _KPCR * NTHALAPI KeGetCurrentKPCR(
141 VOID)
142 {
143 return (struct _KPCR *)__readfsdword(0x1c);
144 }
145
146 __inline KIRQL NTHALAPI KeGetCurrentIrql(
147 VOID)
148 {
149 return ((KIPCR *)KeGetCurrentKPCR())->CurrentIrql;
150 }
151
152 VOID
153 STDCALL
154 KePPCInitThreadWithContext(
155 PKTHREAD Thread,
156 PKSYSTEM_ROUTINE SystemRoutine,
157 PKSTART_ROUTINE StartRoutine,
158 PVOID StartContext,
159 PCONTEXT Context);
160
161 VOID
162 STDCALL
163 KeApplicationProcessorInitDispatcher(
164 VOID);
165
166 VOID
167 STDCALL
168 KeCreateApplicationProcessorIdleThread(
169 ULONG Id);
170
171 VOID KePPCHaltProcessor();
172
173 #ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */
174 VOID
175 STDCALL
176 KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine,
177 PKSTART_ROUTINE StartRoutine,
178 PVOID StartContext,
179 BOOLEAN UserThread,
180 KTRAP_FRAME TrapFrame);
181 #endif
182
183 #endif /* __ASM__ */
184
185 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_POWERPC_KE_H */
186
187 /* EOF */