- add ntoskrnl to the build again, as we will need it now.

- add ke.h, mm.h and intrin_i.h for amd64 currently copied from i386
- remove Interlocked funtions from private ntoskrnl header that don't belong there, this will probably break x86 build, but who cares ;-)
At least the header compiles now...

svn path=/branches/ros-amd64-bringup/; revision=34753
This commit is contained in:
Timo Kreuzer
2008-07-24 20:07:30 +00:00
parent dc58f19c9a
commit efc2458c66
8 changed files with 599 additions and 47 deletions
@@ -0,0 +1,415 @@
#ifndef _INTRIN_INTERNAL_
#define _INTRIN_INTERNAL_
#ifdef CONFIG_SMP
#define LOCK "lock ; "
#else
#define LOCK ""
#endif
#if defined(__GNUC__)
#define Ke386SetInterruptDescriptorTable(X) \
__asm__("lidt %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386GetInterruptDescriptorTable(X) \
__asm__("sidt %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386SetGlobalDescriptorTable(X) \
__asm__("lgdt %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386GetGlobalDescriptorTable(X) \
__asm__("sgdt %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386GetLocalDescriptorTable(X) \
__asm__("sldt %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386SetLocalDescriptorTable(X) \
__asm__("lldt %w0\n\t" \
: /* no outputs */ \
: "q" (X));
#define Ke386SetTr(X) __asm__ __volatile__("ltr %%ax" : :"a" (X));
#define Ke386GetTr(X) \
__asm__("str %0\n\t" \
: /* no outputs */ \
: "m" (X));
#define Ke386SaveFlags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */)
#define Ke386RestoreFlags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory")
#define _Ke386GetSeg(N) ({ \
unsigned int __d; \
__asm__("movl %%" #N ",%0\n\t" :"=r" (__d)); \
__d; \
})
#define _Ke386SetSeg(N,X) __asm__ __volatile__("movl %0,%%" #N : :"r" (X));
#define _Ke386GetDr(N) ({ \
unsigned int __d; \
__asm__("movl %%dr" #N ",%0\n\t" :"=r" (__d)); \
__d; \
})
#define _Ke386SetDr(N,X) __asm__ __volatile__("movl %0,%%dr" #N : :"r" (X));
static inline void Ki386Cpuid(ULONG Op, PULONG Eax, PULONG Ebx, PULONG Ecx, PULONG Edx)
{
__asm__("cpuid"
: "=a" (*Eax), "=b" (*Ebx), "=c" (*Ecx), "=d" (*Edx)
: "0" (Op));
}
#define Ke386Rdmsr(msr,val1,val2) __asm__ __volatile__("rdmsr" : "=a" (val1), "=d" (val2) : "c" (msr))
#define Ke386Wrmsr(msr,val1,val2) __asm__ __volatile__("wrmsr" : /* no outputs */ : "c" (msr), "a" (val1), "d" (val2))
#define Ke386HaltProcessor() __asm__("hlt\n\t");
#define Ke386FnInit() __asm__("fninit\n\t");
//
// CR Macros
//
#define Ke386SetCr2(X) __asm__ __volatile__("movl %0,%%cr2" : :"r" (X));
//
// DR Macros
//
#define Ke386GetDr0() _Ke386GetDr(0)
#define Ke386GetDr1() _Ke386GetDr(1)
#define Ke386SetDr0(X) _Ke386SetDr(0,X)
#define Ke386SetDr1(X) _Ke386SetDr(1,X)
#define Ke386GetDr2() _Ke386GetDr(2)
#define Ke386SetDr2(X) _Ke386SetDr(2,X)
#define Ke386GetDr3() _Ke386GetDr(3)
#define Ke386SetDr3(X) _Ke386SetDr(3,X)
#define Ke386GetDr4() _Ke386GetDr(4)
#define Ke386SetDr4(X) _Ke386SetDr(4,X)
#define Ke386GetDr6() _Ke386GetDr(6)
#define Ke386SetDr6(X) _Ke386SetDr(6,X)
#define Ke386GetDr7() _Ke386GetDr(7)
#define Ke386SetDr7(X) _Ke386SetDr(7,X)
//
// Segment Macros
//
#define Ke386GetSs() _Ke386GetSeg(ss)
#define Ke386GetFs() _Ke386GetSeg(fs)
#define Ke386SetFs(X) _Ke386SetSeg(fs, X)
#define Ke386SetDs(X) _Ke386SetSeg(ds, X)
#define Ke386SetEs(X) _Ke386SetSeg(es, X)
#elif defined(_MSC_VER)
VOID
FORCEINLINE
Ke386Wrmsr(IN ULONG Register,
IN ULONG Var1,
IN ULONG Var2)
{
__asm mov eax, Var1;
__asm mov edx, Var2;
__asm wrmsr;
}
ULONGLONG
FORCEINLINE
Ke386Rdmsr(IN ULONG Register,
IN ULONG Var1,
IN ULONG Var2)
{
__asm mov eax, Var1;
__asm mov edx, Var2;
__asm rdmsr;
}
VOID
FORCEINLINE
Ki386Cpuid(IN ULONG Operation,
OUT PULONG Var1,
OUT PULONG Var2,
OUT PULONG Var3,
OUT PULONG Var4)
{
__asm mov eax, Operation;
__asm cpuid;
__asm mov [Var1], eax;
__asm mov [Var2], ebx;
__asm mov [Var3], ecx;
__asm mov [Var4], edx;
}
VOID
FORCEINLINE
Ke386FnInit(VOID)
{
__asm fninit;
}
VOID
FORCEINLINE
Ke386HaltProcessor(VOID)
{
__asm hlt;
}
VOID
FORCEINLINE
Ke386GetInterruptDescriptorTable(OUT KDESCRIPTOR Descriptor)
{
__asm sidt Descriptor;
}
VOID
FORCEINLINE
Ke386SetInterruptDescriptorTable(IN KDESCRIPTOR Descriptor)
{
__asm lidt Descriptor;
}
VOID
FORCEINLINE
Ke386GetGlobalDescriptorTable(OUT KDESCRIPTOR Descriptor)
{
__asm sgdt Descriptor;
}
VOID
FORCEINLINE
Ke386SetGlobalDescriptorTable(IN KDESCRIPTOR Descriptor)
{
__asm lgdt Descriptor;
}
VOID
FORCEINLINE
Ke386GetLocalDescriptorTable(OUT USHORT Descriptor)
{
__asm sldt Descriptor;
}
VOID
FORCEINLINE
Ke386SetLocalDescriptorTable(IN USHORT Descriptor)
{
__asm lldt Descriptor;
}
VOID
FORCEINLINE
Ke386SaveFlags(IN ULONG Flags)
{
__asm pushf;
__asm pop Flags;
}
VOID
FORCEINLINE
Ke386RestoreFlags(IN ULONG Flags)
{
__asm push Flags;
__asm popf;
}
VOID
FORCEINLINE
Ke386SetTr(IN USHORT Tr)
{
__asm ltr Tr;
}
USHORT
FORCEINLINE
Ke386GetTr(IN USHORT Tr)
{
__asm str Tr;
}
//
// CR Macros
//
VOID
FORCEINLINE
Ke386SetCr2(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov cr2, eax;
}
//
// DR Macros
//
ULONG
FORCEINLINE
Ke386GetDr0(VOID)
{
__asm mov eax, dr0;
}
ULONG
FORCEINLINE
Ke386GetDr1(VOID)
{
__asm mov eax, dr1;
}
ULONG
FORCEINLINE
Ke386GetDr2(VOID)
{
__asm mov eax, dr2;
}
ULONG
FORCEINLINE
Ke386GetDr3(VOID)
{
__asm mov eax, dr3;
}
ULONG
FORCEINLINE
Ke386GetDr6(VOID)
{
__asm mov eax, dr6;
}
ULONG
FORCEINLINE
Ke386GetDr7(VOID)
{
__asm mov eax, dr7;
}
VOID
FORCEINLINE
Ke386SetDr0(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr0, eax;
}
VOID
FORCEINLINE
Ke386SetDr1(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr1, eax;
}
VOID
FORCEINLINE
Ke386SetDr2(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr2, eax;
}
VOID
FORCEINLINE
Ke386SetDr3(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr3, eax;
}
VOID
FORCEINLINE
Ke386SetDr6(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr6, eax;
}
VOID
FORCEINLINE
Ke386SetDr7(IN ULONG Value)
{
__asm mov eax, Value;
__asm mov dr7, eax;
}
//
// Segment Macros
//
USHORT
FORCEINLINE
Ke386GetSs(VOID)
{
__asm mov ax, ss;
}
USHORT
FORCEINLINE
Ke386GetFs(VOID)
{
__asm mov ax, fs;
}
USHORT
FORCEINLINE
Ke386GetDs(VOID)
{
__asm mov ax, ds;
}
USHORT
FORCEINLINE
Ke386GetEs(VOID)
{
__asm mov ax, es;
}
VOID
FORCEINLINE
Ke386SetSs(IN USHORT Value)
{
__asm mov ax, Value;
__asm mov ss, ax;
}
VOID
FORCEINLINE
Ke386SetFs(IN USHORT Value)
{
__asm mov ax, Value;
__asm mov fs, ax;
}
VOID
FORCEINLINE
Ke386SetDs(IN USHORT Value)
{
__asm mov ax, Value;
__asm mov ds, ax;
}
VOID
FORCEINLINE
Ke386SetEs(IN USHORT Value)
{
__asm mov ax, Value;
__asm mov es, ax;
}
#else
#error Unknown compiler for inline assembler
#endif
#endif
/* EOF */
@@ -0,0 +1,141 @@
#ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H
#define __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H
#if __GNUC__ >=3
#pragma GCC system_header
#endif
#define X86_EFLAGS_TF 0x00000100 /* Trap flag */
#define X86_EFLAGS_IF 0x00000200 /* Interrupt Enable flag */
#define X86_EFLAGS_IOPL 0x00003000 /* I/O Privilege Level bits */
#define X86_EFLAGS_NT 0x00004000 /* Nested Task flag */
#define X86_EFLAGS_RF 0x00010000 /* Resume flag */
#define X86_EFLAGS_VM 0x00020000 /* Virtual Mode */
#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
#define X86_CR0_PE 0x00000001 /* enable Protected Mode */
#define X86_CR0_NE 0x00000020 /* enable native FPU error reporting */
#define X86_CR0_TS 0x00000008 /* enable exception on FPU instruction for task switch */
#define X86_CR0_EM 0x00000004 /* enable FPU emulation (disable FPU) */
#define X86_CR0_MP 0x00000002 /* enable FPU monitoring */
#define X86_CR0_WP 0x00010000 /* enable Write Protect (copy on write) */
#define X86_CR0_PG 0x80000000 /* enable Paging */
#define X86_CR4_PAE 0x00000020 /* enable physical address extensions */
#define X86_CR4_PGE 0x00000080 /* enable global pages */
#define X86_CR4_OSFXSR 0x00000200 /* enable FXSAVE/FXRSTOR instructions */
#define X86_CR4_OSXMMEXCPT 0x00000400 /* enable #XF exception */
#define X86_FEATURE_VME 0x00000002 /* Virtual 8086 Extensions are present */
#define X86_FEATURE_TSC 0x00000010 /* time stamp counters are present */
#define X86_FEATURE_PAE 0x00000040 /* physical address extension is present */
#define X86_FEATURE_CX8 0x00000100 /* CMPXCHG8B instruction present */
#define X86_FEATURE_SYSCALL 0x00000800 /* SYSCALL/SYSRET support present */
#define X86_FEATURE_PGE 0x00002000 /* Page Global Enable */
#define X86_FEATURE_MMX 0x00800000 /* MMX extension present */
#define X86_FEATURE_FXSR 0x01000000 /* FXSAVE/FXRSTOR instructions present */
#define X86_FEATURE_SSE 0x02000000 /* SSE extension present */
#define X86_FEATURE_SSE2 0x04000000 /* SSE2 extension present */
#define X86_FEATURE_HT 0x10000000 /* Hyper-Threading present */
#define X86_EXT_FEATURE_SSE3 0x00000001 /* SSE3 extension present */
#define X86_EXT_FEATURE_3DNOW 0x40000000 /* 3DNOW! extension present */
#define FRAME_EDITED 0xFFF8
#ifndef __ASM__
//#include "intrin_i.h"
#define KeArchFnInit() Ke386FnInit()
#define KeArchHaltProcessor() Ke386HaltProcessor()
extern ULONG Ke386CacheAlignment;
struct _KPCR;
VOID
KiInitializeGdt(struct _KPCR* Pcr);
VOID
Ki386ApplicationProcessorInitializeTSS(VOID);
VOID
FASTCALL
Ki386InitializeTss(
IN PKTSS Tss,
IN PKIDTENTRY Idt,
IN PKGDTENTRY Gdt
);
VOID
KiGdtPrepareForApplicationProcessorInit(ULONG Id);
VOID
Ki386InitializeLdt(VOID);
VOID
Ki386SetProcessorFeatures(VOID);
VOID
NTAPI
KiSetCR0Bits(VOID);
VOID
NTAPI
KiGetCacheInformation(VOID);
BOOLEAN
NTAPI
KiIsNpxPresent(
VOID
);
BOOLEAN
NTAPI
KiIsNpxErrataPresent(
VOID
);
VOID
NTAPI
KiSetProcessorType(VOID);
ULONG
NTAPI
KiGetFeatureBits(VOID);
ULONG KeAllocateGdtSelector(ULONG Desc[2]);
VOID KeFreeGdtSelector(ULONG Entry);
VOID
NtEarlyInitVdm(VOID);
VOID
KeApplicationProcessorInitDispatcher(VOID);
VOID
KeCreateApplicationProcessorIdleThread(ULONG Id);
typedef
VOID
(NTAPI*PKSYSTEM_ROUTINE)(PKSTART_ROUTINE StartRoutine,
PVOID StartContext);
VOID
NTAPI
Ke386InitThreadWithContext(PKTHREAD Thread,
PKSYSTEM_ROUTINE SystemRoutine,
PKSTART_ROUTINE StartRoutine,
PVOID StartContext,
PCONTEXT Context);
#define KeArchInitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context) \
Ke386InitThreadWithContext(Thread,SystemRoutine,StartRoutine,StartContext,Context)
#ifdef _NTOSKRNL_ /* FIXME: Move flags above to NDK instead of here */
VOID
NTAPI
KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine,
PKSTART_ROUTINE StartRoutine,
PVOID StartContext,
BOOLEAN UserThread,
KTRAP_FRAME TrapFrame);
#endif
#endif
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_KE_H */
/* EOF */
@@ -0,0 +1,31 @@
/*
* Lowlevel memory managment definitions
*/
#ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H
#define __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H
struct _EPROCESS;
PULONG MmGetPageDirectory(VOID);
#define PAGE_MASK(x) ((x)&(~0xfff))
#define PAE_PAGE_MASK(x) ((x)&(~0xfffLL))
/* Base addresses of PTE and PDE */
#define PAGETABLE_MAP (0xc0000000)
#define PAGEDIRECTORY_MAP (0xc0000000 + (PAGETABLE_MAP / (1024)))
/* Converting address to a corresponding PDE or PTE entry */
#define MiAddressToPde(x) \
((PMMPTE)(((((ULONG)(x)) >> 22) << 2) + PAGEDIRECTORY_MAP))
#define MiAddressToPte(x) \
((PMMPTE)(((((ULONG)(x)) >> 12) << 2) + PAGETABLE_MAP))
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
#define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE)
/* Easy accessing PFN in PTE */
#define PFN_FROM_PTE(v) ((v)->u.Hard.PageFrameNumber)
#endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_MM_H */
@@ -27,6 +27,8 @@
#include "../mips/intrin_i.h"
#elif defined(_M_ARM)
#include "../arm/intrin_i.h"
#elif defined(_M_AMD64)
#include "../amd64/intrin_i.h"
#else
#error "Unknown processor"
#endif
@@ -27,6 +27,8 @@
#include "../mips/ke.h"
#elif defined(_M_ARM)
#include "../arm/ke.h"
#elif defined(_M_AMD64)
#include "../amd64/ke.h"
#else
#error "Unknown processor"
#endif
@@ -27,6 +27,8 @@
#include <internal/mips/mm.h>
#elif defined(_M_ARM)
#include <internal/arm/mm.h>
#elif defined(_M_AMD64)
#include <internal/amd64/mm.h>
#else
#error "Unknown processor"
#endif
+5 -45
View File
@@ -17,7 +17,7 @@
#ifdef _NTOSKRNL_
#ifndef _ARM_
#if !defined (_ARM_) && !defined (_M_AMD64)
#define KeGetCurrentThread _KeGetCurrentThread
#define KeGetPreviousMode _KeGetPreviousMode
#endif
@@ -34,7 +34,7 @@
#define InterlockedExchange _InterlockedExchange
#define InterlockedExchangeAdd _InterlockedExchangeAdd
#include "ke.h"
//#include "ke.h"
#include "i386/mm.h"
#include "i386/fpu.h"
#include "i386/v86m.h"
@@ -102,49 +102,6 @@ RtlpLogException(IN PEXCEPTION_RECORD ExceptionRecord,
IN PVOID ContextData,
IN ULONG Size);
/* FIXME: Interlocked functions that need to be made into a public header */
#ifdef __GNUC__
FORCEINLINE
LONG
InterlockedAnd(IN OUT LONG volatile *Target,
IN LONG Set)
{
LONG i;
LONG j;
j = *Target;
do {
i = j;
j = InterlockedCompareExchange((PLONG)Target,
i & Set,
i);
} while (i != j);
return j;
}
FORCEINLINE
LONG
InterlockedOr(IN OUT LONG volatile *Target,
IN LONG Set)
{
LONG i;
LONG j;
j = *Target;
do {
i = j;
j = InterlockedCompareExchange((PLONG)Target,
i | Set,
i);
} while (i != j);
return j;
}
#endif
/*
* generic information class probing code
*/
@@ -309,6 +266,7 @@ DefaultQueryInfoBufferCheck(ULONG Class,
#endif
#ifndef _WIN64
C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
@@ -322,6 +280,8 @@ C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
//C_ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
//C_ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
#endif
#ifdef _M_IX86
C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
+1 -2
View File
@@ -2,7 +2,6 @@
<!DOCTYPE module SYSTEM "../tools/rbuild/project.dtd">
<group xmlns:xi="http://www.w3.org/2001/XInclude">
<module name="ntoskrnl" type="kernel" installbase="system32" installname="ntoskrnl.exe">
<!-- xi:include href="ntoskrnl-generic.rbuild" / -->
<importlibrary definition="ntoskrnl_$(ARCH).def" />
<xi:include href="ntoskrnl-generic.rbuild" />
</module>
</group>