14#include "../../winldr.h"
21#define KIP0PCRADDRESS 0xffdff000
23#define SELFMAP_ENTRY 0x300
42#define TYPE_TSS16A 0x01
44#define TYPE_TSS16B 0x03
45#define TYPE_CALL16 0x04
47#define TYPE_INT16 0x06
48#define TYPE_TRAP16 0x07
50#define TYPE_TSS32A 0x09
52#define TYPE_TSS32B 0x0B
53#define TYPE_CALL32 0x0C
55#define TYPE_INT32 0x0E
56#define TYPE_TRAP32 0x0F
58#define DESCRIPTOR_ACCESSED 0x1
59#define DESCRIPTOR_READ_WRITE 0x2
60#define DESCRIPTOR_EXECUTE_READ 0x2
61#define DESCRIPTOR_EXPAND_DOWN 0x4
62#define DESCRIPTOR_CONFORMING 0x4
63#define DESCRIPTOR_CODE 0x8
65#define TYPE_CODE (0x10 | DESCRIPTOR_CODE | DESCRIPTOR_EXECUTE_READ)
66#define TYPE_DATA (0x10 | DESCRIPTOR_READ_WRITE)
79 "HighWord.Bytes.BaseMid = 0x%02x\n"
80 "HighWord.Bytes.Flags1 = 0x%02x\n"
81 "HighWord.Bytes.Flags2 = 0x%02x\n"
82 "HighWord.Bytes.BaseHi = 0x%02x\n"
113 ULONG NumPageTables, TotalSize;
122 TRACE(
"NumPageTables = %d\n", NumPageTables);
126 TotalSize = (1 + 1 + NumPageTables * 2) * MM_PAGE_SIZE;
134 NumPageTables*MM_PAGE_SIZE,
138 if (
Buffer + (TotalSize - NumPageTables*MM_PAGE_SIZE) !=
141 TRACE(
"There was a problem allocating two adjacent blocks of memory!\n");
146 UiMessageBox(
"Impossible to allocate memory block for page tables!");
216 TRACE(
"MempSetupPaging: SP 0x%X, Number: 0x%X, Kernel: %s\n",
217 StartPage, NumberOfPages, KernelMapping ?
"yes" :
"no");
253 if (KernelPT[
Page & 0x3ff].Valid)
WARN(
"KernelPT already mapped\n");
292 ULONG APICAddress, CpuInfo[4];
296 LocalAPIC = (((CpuInfo[3] >> 9) & 1) != 0);
304 APICAddress = (MsrValue.
LowPart & 0xFFFFF000);
306 TRACE(
"Local APIC detected at address 0x%x\n",
311 = APICAddress >> MM_PAGE_SHIFT;
346#define ExtendedBIOSDataArea ((PULONG)0x740)
347#define ExtendedBIOSDataSize ((PULONG)0x744)
348#define RomFontPointers ((PULONG)0x700)
363 WARN(
"Couldn't get address of extended BIOS data area\n");
377 ULONG BlockSize, NumPages;
392 TssSize = (
sizeof(
KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
405 NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
420 BugCheck(
"MempAllocatePageTables failed!\n");
435 GDTIDT GdtDesc, IdtDesc, OldIdt;
446 TRACE(
"GdtIdt %p, Pcr %p, Tss 0x%08x\n",
610#if defined(__GNUC__) || defined(__clang__)
611 asm(
"ljmp $0x08, $1f\n"
613#elif defined(_MSC_VER)
634 Ke386SetLocalDescriptorTable(Ldt);
665 for (
i=0;
i<128;
i++)
671 TRACE(
"0x%08X ", PDE_Addr[
i*8+
j]);
FORCEINLINE PKGDTENTRY64 KiGetGdtEntry(PVOID pGdt, USHORT Selector)
VOID WinLdrSetProcessorContext(_In_ USHORT OperatingSystemVersion)
BOOLEAN MempSetupPaging(IN PFN_NUMBER StartPage, IN PFN_NUMBER NumberOfPages, IN BOOLEAN KernelMapping)
static BOOLEAN MempAllocatePageTables(VOID)
static VOID WinLdrpMapApic(VOID)
VOID MempUnmapPage(PFN_NUMBER Page)
void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock)
PUCHAR KernelPageTablesBuffer
static void WinLdrSetupSpecialDataPointers(VOID)
#define DESCRIPTOR_ACCESSED
#define ExtendedBIOSDataArea
PUCHAR PhysicalPageTablesBuffer
static VOID MempAllocatePTE(ULONG Entry, PHARDWARE_PTE *PhysicalPT, PHARDWARE_PTE *KernelPT)
static BOOLEAN WinLdrMapSpecialPages(void)
#define ExtendedBIOSDataSize
PHARDWARE_PTE HalPageTable
#define BugCheck(fmt,...)
#define DBG_DEFAULT_CHANNEL(ch)
#define MachGetExtendedBIOSData(ExtendedBIOSDataArea, ExtendedBIOSDataSize)
#define MachVideoGetFontsFromFirmware(RomFontPointers)
VOID MmSetMemoryType(PVOID MemoryAddress, SIZE_T MemorySize, TYPE_OF_MEMORY NewType)
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
PFN_NUMBER TotalPagesInLookupTable
VOID UiMessageBox(_In_ PCSTR Format,...)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define Ke386GetGlobalDescriptorTable
#define Ke386SetGlobalDescriptorTable
FORCEINLINE VOID KiSetGdtEntryEx(_Inout_ PKGDTENTRY Entry, _In_ ULONG32 Base, _In_ ULONG Limit, _In_ UCHAR Type, _In_ UCHAR Dpl, _In_ BOOLEAN Granularity, _In_ UCHAR SegMode)
FORCEINLINE VOID KiSetGdtEntry(_Inout_ PKGDTENTRY Entry, _In_ ULONG32 Base, _In_ ULONG Limit, _In_ UCHAR Type, _In_ UCHAR Dpl, _In_ UCHAR SegMode)
void __cdecl _disable(void)
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
PPC_QUAL unsigned long long __readmsr()
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
__INTRIN_INLINE void __lidt(void *Source)
__INTRIN_INLINE unsigned long __readcr0(void)
__INTRIN_INLINE void __writecr3(unsigned int Data)
__INTRIN_INLINE void __writecr0(unsigned int Data)
__INTRIN_INLINE void __sidt(void *Destination)
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
static void push(calc_node_t *op)
@ LoaderFirmwareTemporary
#define KI_USER_SHARED_DATA
#define _WIN32_WINNT_VISTA
base of all file and directory entries
struct _KGDTENTRY::@2451::@2452 Bytes
union _KGDTENTRY::@2451 HighWord
union _LOADER_PARAMETER_BLOCK::@3369 u
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
static BOOL Write(PBYTE Address, PBYTE Data, SIZE_T Size)
int WINAPI StartPage(_In_ HDC)