Skip to content

Commit

Permalink
[NTOS:KE][HALX86] Implement AP startup code
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Miller <[email protected]>
  • Loading branch information
Extravert-ir and DarkFire01 committed Nov 3, 2023
1 parent 64c5a7e commit e30969b
Show file tree
Hide file tree
Showing 19 changed files with 753 additions and 54 deletions.
24 changes: 20 additions & 4 deletions hal/halx86/apic/apicsmp.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/*
* PROJECT: ReactOS HAL
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* FILE: hal/halx86/apic/apicsmp.c
* PURPOSE: SMP specific APIC code
* PROGRAMMERS: Copyright 2021 Timo Kreuzer ([email protected])
* COPYRIGHT: Copyright 2021 Timo Kreuzer <[email protected]>
* Copyright 2021 Justin Miller <[email protected]>
*/

/* INCLUDES *******************************************************************/

#include <hal.h>
#include "apicp.h"
#include <smp.h>
#define NDEBUG
#include <debug.h>


extern PPROCESSOR_IDENTITY HalpProcessorIdentity;

/* INTERNAL FUNCTIONS *********************************************************/

/*!
Expand Down Expand Up @@ -84,7 +88,6 @@ ApicRequestGlobalInterrupt(

/* SMP SUPPORT FUNCTIONS ******************************************************/

// Should be called by SMP version of HalRequestIpi
VOID
NTAPI
HalpRequestIpi(KAFFINITY TargetProcessors)
Expand All @@ -93,4 +96,17 @@ HalpRequestIpi(KAFFINITY TargetProcessors)
__debugbreak();
}

// APIC specific SMP code here
VOID
ApicStartApplicationProcessor(ULONG NTProcessorNumber, PHYSICAL_ADDRESS StartupLoc)
{
/* Init IPI */
ApicRequestGlobalInterrupt(HalpProcessorIdentity[NTProcessorNumber].LapicId, 0,
APIC_MT_INIT, APIC_TGM_Edge, APIC_DSH_Destination);

/* Stall execution for a bit to give APIC time */
KeStallExecutionProcessor(1000);

/* Startup IPI */
ApicRequestGlobalInterrupt(NTProcessorNumber, (StartupLoc.LowPart) >> 12,
APIC_MT_Startup, APIC_TGM_Edge, APIC_DSH_Destination);
}
23 changes: 0 additions & 23 deletions hal/halx86/apic/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ HalAllProcessorsStarted(VOID)
return TRUE;
}

/*
* @implemented
*/
BOOLEAN
NTAPI
HalStartNextProcessor(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
IN PKPROCESSOR_STATE ProcessorState)
{
/* Ready to start */
return FALSE;
}

/*
* @implemented
*/
Expand All @@ -62,15 +50,4 @@ HalProcessorIdle(VOID)
__halt();
}

/*
* @implemented
*/
VOID
NTAPI
HalRequestIpi(KAFFINITY TargetProcessors)
{
UNIMPLEMENTED;
__debugbreak();
}

/* EOF */
32 changes: 32 additions & 0 deletions hal/halx86/generic/up.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Core source file for UP alternative functions
* COPYRIGHT: Copyright 2021 Justin Miller <[email protected]>
*/

/* INCLUDES ******************************************************************/

#include <hal.h>
#define NDEBUG
#include <debug.h>

/* FUNCTIONS *****************************************************************/

VOID
NTAPI
HalRequestIpi(KAFFINITY TargetProcessors)
{
/* This should never be called in UP mode */
__debugbreak();
}

BOOLEAN
NTAPI
HalStartNextProcessor(
IN PLOADER_PARAMETER_BLOCK LoaderBlock,
IN PKPROCESSOR_STATE ProcessorState)
{
/* Always return false on UP systems */
return FALSE;
}
9 changes: 9 additions & 0 deletions hal/halx86/include/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ HalpSetupProcessorsTable(

VOID
HalpPrintApicTables(VOID);

/* APIC specific functions inside apic/apicsmp.c */

VOID
ApicStartApplicationProcessor(ULONG NTProcessorNumber, PHYSICAL_ADDRESS StartupLoc);

VOID
NTAPI
HalpRequestIpi(KAFFINITY TargetProcessors);
23 changes: 0 additions & 23 deletions hal/halx86/pic/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ HalAllProcessorsStarted(VOID)
return TRUE;
}

/*
* @implemented
*/
BOOLEAN
NTAPI
HalStartNextProcessor(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
IN PKPROCESSOR_STATE ProcessorState)
{
/* Ready to start */
return FALSE;
}

/*
* @implemented
*/
Expand All @@ -62,15 +50,4 @@ HalProcessorIdle(VOID)
__halt();
}

/*
* @implemented
*/
VOID
NTAPI
HalRequestIpi(KAFFINITY TargetProcessors)
{
/* Not implemented on UP */
__debugbreak();
}

/* EOF */
17 changes: 15 additions & 2 deletions hal/halx86/smp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
list(APPEND HAL_SMP_SOURCE
generic/buildtype.c
generic/spinlock.c
smp/smp.c)
smp/smp.c
smp/ipi.c)

add_library(lib_hal_smp OBJECT ${HAL_SMP_SOURCE})
if(ARCH STREQUAL "i386")
list(APPEND HAL_SMP_ASM_SOURCE
smp/i386/apentry.S)
endif()


if(ARCH STREQUAL "amd64")
list(APPEND HAL_SMP_ASM_SOURCE
smp/amd64/apentry.S)
endif()

add_asm_files(lib_hal_smp_asm ${HAL_SMP_ASM_SOURCE})
add_library(lib_hal_smp OBJECT ${HAL_SMP_SOURCE} ${lib_hal_smp_asm})
add_dependencies(lib_hal_smp bugcodes xdk)
target_compile_definitions(lib_hal_smp PRIVATE CONFIG_SMP)
43 changes: 43 additions & 0 deletions hal/halx86/smp/amd64/apentry.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Assembly file for real mode AP code
* COPYRIGHT: Copyright 2021 Justin Miller <[email protected]>
*/

#include <asm.inc>

PUBLIC APEntry16
PUBLIC APEntry16End
PUBLIC APEntry32
PUBLIC APEntryJump32Offset
PUBLIC APEntryJump32Segment
PUBLIC TempPageTableAddr
PUBLIC APEntryCpuState

.code
APEntry16:
cli

xor ax, ax
mov ds, ax
mov ss, ax
mov fs, ax
mov gs, ax

hlt

APEntry16End:
.long HEX(0)
APEntry32:
.long HEX(0)
APEntryJump32Offset:
.long HEX(0)
APEntryJump32Segment:
.long HEX(0)
TempPageTableAddr:
.long HEX(0)
APEntryCpuState:
.long HEX(0)

END
Loading

0 comments on commit e30969b

Please sign in to comment.