diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index b25d74e..f95ae90 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -77,6 +77,8 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/mm/pool.cc ${XTOSKRNL_SOURCE_DIR}/mm/pte.cc ${XTOSKRNL_SOURCE_DIR}/po/idle.cc + ${XTOSKRNL_SOURCE_DIR}/ps/process.cc + ${XTOSKRNL_SOURCE_DIR}/ps/thread.cc ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/dispatch.cc ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/exsup.cc ${XTOSKRNL_SOURCE_DIR}/rtl/${ARCH}/intrin.cc diff --git a/xtoskrnl/includes/ps.hh b/xtoskrnl/includes/ps.hh new file mode 100644 index 0000000..c072314 --- /dev/null +++ b/xtoskrnl/includes/ps.hh @@ -0,0 +1,18 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ps.hh + * DESCRIPTION: Process and thread management + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_PS_HH +#define __XTOSKRNL_PS_HH + +#include + +#include +#include + + +#endif /* __XTOSKRNL_PS_HH */ diff --git a/xtoskrnl/includes/ps/process.hh b/xtoskrnl/includes/ps/process.hh new file mode 100644 index 0000000..1f5f626 --- /dev/null +++ b/xtoskrnl/includes/ps/process.hh @@ -0,0 +1,25 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ps/process.hh + * DESCRIPTION: Process Management + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_PS_PROCESS_HH +#define __XTOSKRNL_PS_PROCESS_HH + +#include + + +/* Process and thread management */ +namespace PS +{ + class Process + { + public: + STATIC XTAPI VOID CreateIdleProcess(IN PKPROCESSOR_CONTROL_BLOCK Prcb); + }; +} + +#endif /* __XTOSKRNL_PS_PROCESS_HH */ diff --git a/xtoskrnl/includes/ps/thread.hh b/xtoskrnl/includes/ps/thread.hh new file mode 100644 index 0000000..bb66808 --- /dev/null +++ b/xtoskrnl/includes/ps/thread.hh @@ -0,0 +1,26 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/ps/thread.hh + * DESCRIPTION: Thread Management + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_PS_THREAD_HH +#define __XTOSKRNL_PS_THREAD_HH + +#include + + +/* Process and thread management */ +namespace PS +{ + class Thread + { + public: + STATIC XTAPI XTSTATUS CreateIdleThread(IN PKPROCESSOR_CONTROL_BLOCK Prcb, + IN PVOID Stack); + }; +} + +#endif /* __XTOSKRNL_PS_THREAD_HH */ diff --git a/xtoskrnl/includes/xtos.hh b/xtoskrnl/includes/xtos.hh index 3363583..368357c 100644 --- a/xtoskrnl/includes/xtos.hh +++ b/xtoskrnl/includes/xtos.hh @@ -24,4 +24,5 @@ #include #include #include +#include #include diff --git a/xtoskrnl/ps/process.cc b/xtoskrnl/ps/process.cc new file mode 100644 index 0000000..5936ef4 --- /dev/null +++ b/xtoskrnl/ps/process.cc @@ -0,0 +1,43 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/po/process.cc + * DESCRIPTION: Process Management + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Creates the global IDLE process. + * + * @param Prcb + * Supplies a pointer to the Processor Control Block of the Bootstrap Processor. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +PS::Process::CreateIdleProcess(IN PKPROCESSOR_CONTROL_BLOCK Prcb) +{ + ULONG_PTR PageDirectory[2]; + PKPROCESS IdleProcess; + PKTHREAD IdleThread; + + /* Get initial IDLE thread */ + IdleThread = Prcb->CurrentThread; + + /* Get initial IDLE process */ + IdleProcess = IdleThread->ApcState.Process; + + /* Setup placeholder for page directory entries */ + PageDirectory[0] = 0; + PageDirectory[1] = 0; + + /* Initialize Idle process and Idle thread */ + KE::KProcess::InitializeIdleProcess(IdleProcess, PageDirectory); + KE::KThread::InitializeIdleThread(IdleProcess, IdleThread, Prcb, AR::ProcessorSupport::GetBootStack()); +} diff --git a/xtoskrnl/ps/thread.cc b/xtoskrnl/ps/thread.cc new file mode 100644 index 0000000..b22a646 --- /dev/null +++ b/xtoskrnl/ps/thread.cc @@ -0,0 +1,60 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/po/thread.cc + * DESCRIPTION: Thread Management + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Allocates and initializes a per-processor IDLE thread for an Application Processor (AP). + * + * @param Prcb + * Supplies a pointer to the Processor Control Block of the target processor. + * + * @param Stack + * Supplies a pointer to the pre-allocated kernel stack for the new idle thread. + * + * @return This routine returns a status code indicating the success or failure of the operation. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +PS::Thread::CreateIdleThread(IN PKPROCESSOR_CONTROL_BLOCK Prcb, + IN PVOID Stack) +{ + PKPROCESS IdleProcess; + PETHREAD IdleThread; + XTSTATUS Status; + + /* Retrieve the global IDLE process container */ + IdleProcess = KE::KProcess::GetIdleProcess(); + + /* Allocate the Executive Thread object */ + Status = MM::Allocator::AllocatePool(NonPagedPool, sizeof(ETHREAD), (PVOID*)&IdleThread); + if(Status != STATUS_SUCCESS) + { + /* Allocation failed, return the status code */ + return Status; + } + + /* Zero the allocated memory to prevent uninitialized data */ + RTL::Memory::ZeroMemory(IdleThread, sizeof(ETHREAD)); + + /* Register the new thread within the Processor Control Block */ + Prcb->CurrentThread = &IdleThread->ThreadControlBlock; + Prcb->IdleThread = &IdleThread->ThreadControlBlock; + + /* Initialize the IDLE thread */ + KE::KThread::InitializeIdleThread(IdleProcess, + &IdleThread->ThreadControlBlock, + Prcb, + Stack); + + /* Return success */ + return STATUS_SUCCESS; +}