ReactOS 0.4.15-dev-8339-g4028de8
spinup.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: i386 Application Processor (AP) spinup setup
5 * COPYRIGHT: Copyright 2021 Victor Perevertkin <victor.perevertkin@reactos.org>
6 * Copyright 2021-2023 Justin Miller <justin.miller@reactos.org>
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <hal.h>
12#include <smp.h>
13
14#define NDEBUG
15#include <debug.h>
16
17/* GLOBALS *******************************************************************/
18
21extern PVOID HalpLowStub;
22
23// The data necessary for a boot (stored inside HalpLowStub)
24extern PVOID HalpAPEntry16;
26extern PVOID HalpAPEntry32;
29
31
32#ifndef Add2Ptr
33#define Add2Ptr(P,I) ((PVOID)((PUCHAR)(P) + (I)))
34#endif
35#ifndef PtrOffset
36#define PtrOffset(B,O) ((ULONG)((ULONG_PTR)(O) - (ULONG_PTR)(B)))
37#endif
38
39typedef struct _AP_ENTRY_DATA
40{
49
50/* FUNCTIONS *****************************************************************/
51
52static
55 _In_ PKPROCESSOR_STATE ProcessorState)
56{
57 PMMPDE RootPageTable = Add2Ptr(HalpLowStub, PAGE_SIZE);
58 PMMPDE LowMapPde = Add2Ptr(HalpLowStub, 2 * PAGE_SIZE);
59 PMMPTE LowStubPte = MiAddressToPte(HalpLowStub);
61 ULONG StartPti;
62
63 /* Copy current mappings */
65
66 /* Set up low PDE */
69 RootPageTable[0].u.Hard.Valid = 1;
70 RootPageTable[0].u.Hard.Write = 1;
71
72 /* Copy low stub PTEs */
74 ASSERT(StartPti + HALP_LOW_STUB_SIZE_IN_PAGES < 1024);
75 for (ULONG i = 0; i < HALP_LOW_STUB_SIZE_IN_PAGES; i++)
76 {
77 LowMapPde[StartPti + i] = LowStubPte[i];
78 }
79
81 ASSERT(PhysicalAddress.QuadPart < 0x100000000);
83}
84
88 _In_ PLOADER_PARAMETER_BLOCK LoaderBlock,
89 _In_ PKPROCESSOR_STATE ProcessorState)
90{
92 return FALSE;
93
94 // Initalize the temporary page table
95 // TODO: clean it up after an AP boots successfully
96 ULONG initialCr3 = HalpSetupTemporaryMappings(ProcessorState);
97 if (!initialCr3)
98 return FALSE;
99
100 // Put the bootstrap code into low memory
102
103 // Get a pointer to apEntryData
105
106 *apEntryData = (AP_ENTRY_DATA){
108 .Jump32Segment = (ULONG)ProcessorState->ContextFrame.SegCs,
109 .SelfPtr = (PVOID)apEntryData,
110 .PageTableRoot = initialCr3,
111 .ProcessorState = ProcessorState,
112 .Gdtr = ProcessorState->SpecialRegisters.Gdtr,
113 .Idtr = ProcessorState->SpecialRegisters.Idtr,
114 };
115
117
119
120 return TRUE;
121}
unsigned char BOOLEAN
unsigned int UINT32
BOOLEAN NTAPI HalStartNextProcessor(_In_ PLOADER_PARAMETER_BLOCK LoaderBlock, _In_ PKPROCESSOR_STATE ProcessorState)
Definition: spinup.c:18
VOID ApicStartApplicationProcessor(_In_ ULONG NTProcessorNumber, _In_ PHYSICAL_ADDRESS StartupLoc)
Definition: apicsmp.c:110
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
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
Definition: glfuncs.h:248
#define HALP_LOW_STUB_SIZE_IN_PAGES
Definition: halp.h:67
ULONG HalpStartedProcessorCount
Definition: spinup.c:30
struct _AP_ENTRY_DATA AP_ENTRY_DATA
PVOID HalpAPEntryData
#define Add2Ptr(P, I)
Definition: spinup.c:33
PVOID HalpAPEntry32
HALP_APIC_INFO_TABLE HalpApicInfoTable
Definition: madt.c:22
PVOID HalpAPEntry16
PVOID HalpAPEntry16End
struct _AP_ENTRY_DATA * PAP_ENTRY_DATA
PPROCESSOR_IDENTITY HalpProcessorIdentity
Definition: madt.c:21
PVOID HalpLowStub
Definition: halacpi.c:32
static ULONG HalpSetupTemporaryMappings(_In_ PKPROCESSOR_STATE ProcessorState)
Definition: spinup.c:54
PHYSICAL_ADDRESS HalpLowStubPhysicalAddress
Definition: halacpi.c:29
#define MiAddressToPte(x)
Definition: mmx86.c:19
#define MiAddressToPteOffset(x)
Definition: mmx86.c:21
#define MiAddressToPde(x)
Definition: mmx86.c:20
#define ASSERT(a)
Definition: mode.c:44
#define _In_
Definition: ms_sal.h:308
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:685
Definition: spinup.c:40
PVOID SelfPtr
Definition: spinup.c:43
KDESCRIPTOR Gdtr
Definition: spinup.c:46
UINT32 Jump32Offset
Definition: spinup.c:41
ULONG PageTableRoot
Definition: spinup.c:44
PKPROCESSOR_STATE ProcessorState
Definition: spinup.c:45
KDESCRIPTOR Idtr
Definition: spinup.c:47
ULONG Jump32Segment
Definition: spinup.c:42
ULONG ProcessorCount
Definition: smp.h:25
ULONG64 Valid
Definition: mmtypes.h:150
ULONG64 Write
Definition: mmtypes.h:170
ULONG64 PageFrameNumber
Definition: mmtypes.h:171
union _MMPTE::@2342 u
MMPTE_HARDWARE Hard
Definition: mmtypes.h:217
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098