Initial implementation of the thread initialization
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
9c083dc050
commit
c4d1f1cd0d
@ -16,6 +16,11 @@
|
||||
#include ARCH_HEADER(ketypes.h)
|
||||
|
||||
|
||||
/* Exception types and handling mechanisms */
|
||||
#define EXCEPTION_CONTINUE_SEARCH 0x00
|
||||
#define EXCEPTION_EXECUTE_HANDLER 0x01
|
||||
#define EXCEPTION_CONTINUE_EXECUTION 0xFF
|
||||
|
||||
/* Maximum number of exception parameters */
|
||||
#define EXCEPTION_MAXIMUM_PARAMETERS 15
|
||||
|
||||
@ -34,6 +39,14 @@
|
||||
#define KTIMER_WAIT_BLOCK 3
|
||||
#define SEMAPHORE_WAIT_BLOCK 2
|
||||
|
||||
/* Adjust reason */
|
||||
typedef enum _ADJUST_REASON
|
||||
{
|
||||
AdjustNone = 0,
|
||||
AdjustUnwait = 1,
|
||||
AdjustBoost = 2
|
||||
} ADJUST_REASON, *PADJUST_REASON;
|
||||
|
||||
/* Exception disposition return values */
|
||||
typedef enum _EXCEPTION_DISPOSITION
|
||||
{
|
||||
@ -83,6 +96,19 @@ typedef enum _KOBJECTS
|
||||
MaximumKernelObject = 25
|
||||
} KOBJECTS, *PKOBJECTS;
|
||||
|
||||
/* Thread state */
|
||||
typedef enum _KTHREAD_STATE
|
||||
{
|
||||
Initialized,
|
||||
Ready,
|
||||
Running,
|
||||
Standby,
|
||||
Terminated,
|
||||
Waiting,
|
||||
Transition,
|
||||
DeferredReady
|
||||
} KTHREAD_STATE, *PKTHREAD_STATE;
|
||||
|
||||
/* Timer type */
|
||||
typedef enum _KTIMER_TYPE
|
||||
{
|
||||
@ -98,6 +124,13 @@ typedef enum _MODE
|
||||
MaximumMode
|
||||
} MODE, *PMODE;
|
||||
|
||||
/* Wait type */
|
||||
typedef enum _WAIT_TYPE
|
||||
{
|
||||
WaitAll,
|
||||
WaitAny
|
||||
} WAIT_TYPE, *PWAIT_TYPE;
|
||||
|
||||
/* Kernel routine callbacks */
|
||||
typedef EXCEPTION_DISPOSITION (*PEXCEPTION_ROUTINE)(IN PEXCEPTION_RECORD ExceptionRecord, IN PVOID EstablisherFrame, IN OUT PCONTEXT ContextRecord, IN OUT PVOID DispatcherContext);
|
||||
typedef VOID (*PKNORMAL_ROUTINE)(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2);
|
||||
|
@ -48,10 +48,12 @@
|
||||
|
||||
/* XT status code definitions */
|
||||
#define STATUS_SUCCESS ((XTSTATUS) 0x00000000L)
|
||||
#define STATUS_UNSUCCESSFUL ((XTSTATUS) 0xC0000001L)
|
||||
#define STATUS_NOT_IMPLEMENTED ((XTSTATUS) 0xC0000002L)
|
||||
#define STATUS_INVALID_PARAMETER ((XTSTATUS) 0xC000000DL)
|
||||
#define STATUS_INSUFFICIENT_RESOURCES ((XTSTATUS) 0xC000009AL)
|
||||
#define STATUS_DEVICE_NOT_READY ((XTSTATUS) 0xC00000A3L)
|
||||
#define STATUS_TIMEOUT ((XTSTATUS) 0x00000102L)
|
||||
#define STATUS_IO_DEVICE_ERROR ((XTSTATUS) 0xC0000185L)
|
||||
#define STATUS_NOT_FOUND ((XTSTATUS) 0xC0000225L)
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
/* Enumeration lists forward references */
|
||||
typedef enum _ADJUST_REASON ADJUST_REASON, *PADJUST_REASON;
|
||||
typedef enum _BOOLEAN BOOLEAN, *PBOOLEAN;
|
||||
typedef enum _EXCEPTION_DISPOSITION EXCEPTION_DISPOSITION, *PEXCEPTION_DISPOSITION;
|
||||
typedef enum _EFI_ALLOCATE_TYPE EFI_ALLOCATE_TYPE, *PEFI_ALLOCATE_TYPE;
|
||||
@ -39,10 +40,12 @@ typedef enum _EFI_UART_STOP_BITS_TYPE EFI_UART_STOP_BITS_TYPE, *PEFI_UART_STOP_B
|
||||
typedef enum _EFI_UNIVERSA_GRAPHICS_BLT_OPERATION EFI_UNIVERSA_GRAPHICS_BLT_OPERATION, *PEFI_UNIVERSA_GRAPHICS_BLT_OPERATION;
|
||||
typedef enum _KAPC_ENVIRONMENT KAPC_ENVIRONMENT, *PKAPC_ENVIRONMENT;
|
||||
typedef enum _KOBJECTS KOBJECTS, *PKOBJECTS;
|
||||
typedef enum _KTHREAD_STATE KTHREAD_STATE, *PKTHREAD_STATE;
|
||||
typedef enum _KTIMER_TYPE KTIMER_TYPE, *PKTIMER_TYPE;
|
||||
typedef enum _LOADER_MEMORY_TYPE LOADER_MEMORY_TYPE, *PLOADER_MEMORY_TYPE;
|
||||
typedef enum _MODE MODE, *PMODE;
|
||||
typedef enum _SYSTEM_FIRMWARE_TYPE SYSTEM_FIRMWARE_TYPE, *PSYSTEM_FIRMWARE_TYPE;
|
||||
typedef enum _WAIT_TYPE WAIT_TYPE, *PWAIT_TYPE;
|
||||
|
||||
/* Structures forward references */
|
||||
typedef struct _ANSI_STRING ANSI_STRING, *PANSI_STRING;
|
||||
|
@ -24,6 +24,7 @@ list(APPEND XTOSKRNL_SOURCE
|
||||
${XTOSKRNL_SOURCE_DIR}/ke/spinlock.c
|
||||
${XTOSKRNL_SOURCE_DIR}/ke/timer.c
|
||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/krnlinit.c
|
||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/kthread.c
|
||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/proc.c
|
||||
${XTOSKRNL_SOURCE_DIR}/mm/kpools.c
|
||||
${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pages.c
|
||||
|
@ -28,6 +28,14 @@ XTAPI
|
||||
VOID
|
||||
KepArchInitialize(VOID);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepInitializeThreadContext(IN PKTHREAD Thread,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT ContextRecord);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepStartKernel(VOID);
|
||||
|
@ -28,4 +28,7 @@ EXTERN EPROCESS KeInitialProcess;
|
||||
/* Kernel initial thread */
|
||||
EXTERN ETHREAD KeInitialThread;
|
||||
|
||||
/* Kernel service descriptor table */
|
||||
EXTERN KSERVICE_DESCRIPTOR_TABLE KeServiceDescriptorTable[KSERVICE_TABLES_COUNT];
|
||||
|
||||
#endif /* __XTOSKRNL_GLOBALS_H */
|
||||
|
@ -25,19 +25,16 @@ PKTHREAD
|
||||
KeGetCurrentThread(VOID);
|
||||
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
KeInitializeThread(IN PKTHREAD Thread,
|
||||
IN PVOID Stack,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT Context,
|
||||
IN PVOID EnvironmentBlock,
|
||||
IN PKPROCESS Process);
|
||||
VOID
|
||||
KepArchInitialize(VOID);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepArchInitialize(VOID);
|
||||
KepInitializeThreadContext(IN PKTHREAD Thread,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT ContextRecord);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
|
@ -10,7 +10,39 @@
|
||||
#define __XTOSKRNL_KEPFUNCS_H
|
||||
|
||||
#include <xtos.h>
|
||||
#include ARCH_HEADER(kepfuncs.h)
|
||||
|
||||
|
||||
XTAPI
|
||||
XTSTATUS
|
||||
KeInitializeThread(IN PKTHREAD Thread,
|
||||
IN PVOID Stack,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT Context,
|
||||
IN PVOID EnvironmentBlock,
|
||||
IN PKPROCESS Process);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KeStartThread(IN PKTHREAD Thread);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendNop(IN PKAPC Apc,
|
||||
IN OUT PKNORMAL_ROUTINE *NormalRoutine,
|
||||
IN OUT PVOID *NormalContext,
|
||||
IN OUT PVOID *SystemArgument1,
|
||||
IN OUT PVOID *SystemArgument2);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendRundown(IN PKAPC Apc);
|
||||
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendThread(IN PVOID NormalContext,
|
||||
IN PVOID SystemArgument1,
|
||||
IN PVOID SystemArgument2);
|
||||
|
||||
#endif /* __XTOSKRNL_KEPFUNCS_H */
|
||||
|
@ -13,3 +13,6 @@
|
||||
#include "globals.h"
|
||||
#include "arpfuncs.h"
|
||||
#include "kepfuncs.h"
|
||||
|
||||
#include ARCH_HEADER(arpfuncs.h)
|
||||
#include ARCH_HEADER(kepfuncs.h)
|
||||
|
43
xtoskrnl/ke/amd64/kthread.c
Normal file
43
xtoskrnl/ke/amd64/kthread.c
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/ke/amd64/kthread.c
|
||||
* DESCRIPTION: AMD64 thread manipulation support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
|
||||
|
||||
/**
|
||||
* Initializes CPU architecture dependent context of a thread.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread being initialized.
|
||||
*
|
||||
* @param SystemRoutine
|
||||
* Supplies a pointer to the routine called during first scheduling.
|
||||
*
|
||||
* @param StartRoutine
|
||||
* Supplies a pointer to the routine called during thread startup.
|
||||
*
|
||||
* @param StartContext
|
||||
* Supplies a pointer to a context data that will be passed to start routine.
|
||||
*
|
||||
* @param ContextRecord
|
||||
* Supplies a pointer to a context record which stores the initial state of the user mode thread.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepInitializeThreadContext(IN PKTHREAD Thread,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT ContextRecord)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
@ -20,3 +20,6 @@ EPROCESS KeInitialProcess;
|
||||
|
||||
/* Kernel initial thread */
|
||||
ETHREAD KeInitialThread;
|
||||
|
||||
/* Kernel service descriptor table */
|
||||
KSERVICE_DESCRIPTOR_TABLE KeServiceDescriptorTable[KSERVICE_TABLES_COUNT];
|
||||
|
43
xtoskrnl/ke/i686/kthread.c
Normal file
43
xtoskrnl/ke/i686/kthread.c
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtoskrnl/ke/i686/kthread.c
|
||||
* DESCRIPTION: I686 thread manipulation support
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtos.h>
|
||||
|
||||
|
||||
/**
|
||||
* Initializes CPU architecture dependent context of a thread.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread being initialized.
|
||||
*
|
||||
* @param SystemRoutine
|
||||
* Supplies a pointer to the routine called during first scheduling.
|
||||
*
|
||||
* @param StartRoutine
|
||||
* Supplies a pointer to the routine called during thread startup.
|
||||
*
|
||||
* @param StartContext
|
||||
* Supplies a pointer to a context data that will be passed to start routine.
|
||||
*
|
||||
* @param ContextRecord
|
||||
* Supplies a pointer to a context record which stores the initial state of the user mode thread.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepInitializeThreadContext(IN PKTHREAD Thread,
|
||||
IN PKSYSTEM_ROUTINE SystemRoutine,
|
||||
IN PKSTART_ROUTINE StartRoutine,
|
||||
IN PVOID StartContext,
|
||||
IN PCONTEXT ContextRecord)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
@ -51,6 +51,178 @@ KeInitializeThread(IN PKTHREAD Thread,
|
||||
IN PVOID EnvironmentBlock,
|
||||
IN PKPROCESS Process)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
PKWAIT_BLOCK TimerWaitBlock;
|
||||
BOOLEAN Allocation;
|
||||
XTSTATUS Status;
|
||||
ULONG Index;
|
||||
|
||||
/* Initialize thread dispatcher header */
|
||||
Thread->Header.Type = ThreadObject;
|
||||
Thread->Header.SignalState = 0;
|
||||
|
||||
/* Initialize thread wait list */
|
||||
RtlInitializeListHead(&Thread->Header.WaitListHead);
|
||||
|
||||
/* Initialize thread mutant list head */
|
||||
RtlInitializeListHead(&Thread->MutantListHead);
|
||||
|
||||
/* Initialize the builtin wait blocks */
|
||||
for(Index = 0; Index <= KTHREAD_WAIT_BLOCK; Index++)
|
||||
{
|
||||
Thread->WaitBlock[Index].Thread = Thread;
|
||||
}
|
||||
|
||||
/* Initialize stack resident and stack swap */
|
||||
Thread->AutoAlignment = Process->AutoAlignment;
|
||||
Thread->StackResident = TRUE;
|
||||
Thread->StackSwap = TRUE;
|
||||
Thread->SwapBusy = FALSE;
|
||||
|
||||
/* Set priority adjustment reason */
|
||||
Thread->AdjustReason = AdjustNone;
|
||||
|
||||
/* Initialize thread lock */
|
||||
KeInitializeSpinLock(&Thread->ThreadLock);
|
||||
|
||||
/* Set thread service table */
|
||||
Thread->ServiceTable = KeServiceDescriptorTable;
|
||||
|
||||
/* Initialize thread APC */
|
||||
Thread->ApcStatePointer[0] = &Thread->ApcState;
|
||||
Thread->ApcStatePointer[1] = &Thread->SavedApcState;
|
||||
Thread->ApcQueueable = TRUE;
|
||||
Thread->ApcState.Process = Process;
|
||||
Thread->Process = Process;
|
||||
|
||||
/* Initialize APC list heads */
|
||||
RtlInitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
|
||||
RtlInitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
|
||||
|
||||
/* Initialize APC queue lock */
|
||||
KeInitializeSpinLock(&Thread->ApcQueueLock);
|
||||
|
||||
/* Initialize kernel-mode suspend APC */
|
||||
KeInitializeApc(&Thread->SuspendApc, Thread, OriginalApcEnvironment, KepSuspendNop,
|
||||
KepSuspendRundown, KepSuspendThread, KernelMode, NULL);
|
||||
|
||||
/* Initialize suspend semaphore */
|
||||
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 2);
|
||||
|
||||
/* Initialize the builtin timer */
|
||||
KeInitializeTimer(&Thread->Timer);
|
||||
TimerWaitBlock = &Thread->WaitBlock[KTIMER_WAIT_BLOCK];
|
||||
TimerWaitBlock->Object = &Thread->Timer;
|
||||
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
|
||||
TimerWaitBlock->WaitType = WaitAny;
|
||||
TimerWaitBlock->WaitListEntry.Flink = &(&Thread->Timer)->Header.WaitListHead;
|
||||
TimerWaitBlock->WaitListEntry.Blink = &(&Thread->Timer)->Header.WaitListHead;
|
||||
|
||||
/* Initialize Thread Environment Block*/
|
||||
Thread->EnvironmentBlock = EnvironmentBlock;
|
||||
|
||||
Thread->InitialStack = Stack;
|
||||
Thread->StackBase = Stack;
|
||||
Thread->StackLimit = Stack - KERNEL_STACK_SIZE;
|
||||
|
||||
/* Initialize thread context */
|
||||
KepInitializeThreadContext(Thread, SystemRoutine, StartRoutine, StartContext, Context);
|
||||
|
||||
/* Mark thread as initialized and run it */
|
||||
Thread->State = Initialized;
|
||||
KeStartThread(Thread);
|
||||
|
||||
/* Return success */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the thread.
|
||||
*
|
||||
* @param Thread
|
||||
* Supplies a pointer to the thread.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since NT 5.1
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KeStartThread(IN PKTHREAD Thread)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend APC-built thread NOP routine. It takes no actions.
|
||||
*
|
||||
* @param Apc
|
||||
* Supplies a pointer to the APC object.
|
||||
*
|
||||
* @param NormalRoutine
|
||||
* Supplies a pointer to the normal routine set during the APC initialization. Unused by this routine.
|
||||
*
|
||||
* @param NormalContext
|
||||
* Supplies a pointer a context data set during the APC initialization. Unused by this routine.
|
||||
*
|
||||
* @param SystemArgument1
|
||||
* Supplies a pointer to an unused system argument.
|
||||
*
|
||||
* @param SystemArgument2
|
||||
* Supplies a pointer to an unused system argument.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendNop(IN PKAPC Apc,
|
||||
IN OUT PKNORMAL_ROUTINE *NormalRoutine,
|
||||
IN OUT PVOID *NormalContext,
|
||||
IN OUT PVOID *SystemArgument1,
|
||||
IN OUT PVOID *SystemArgument2)
|
||||
{
|
||||
/* No action here */
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend APC-built thread rundown routine. It takes no actions.
|
||||
*
|
||||
* @param Apc
|
||||
* Supplies a pointer to the APC object.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendRundown(IN PKAPC Apc)
|
||||
{
|
||||
/* No action here */
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspends thread execution by waiting on the thread's semaphore.
|
||||
*
|
||||
* @param NormalContext
|
||||
* Supplies a pointer a context data set during the APC initialization. Unused by this routine.
|
||||
*
|
||||
* @param SystemArgument1
|
||||
* Supplies a pointer to an unused system argument.
|
||||
*
|
||||
* @param SystemArgument2
|
||||
* Supplies a pointer to an unused system argument.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
KepSuspendThread(IN PVOID NormalContext,
|
||||
IN PVOID SystemArgument1,
|
||||
IN PVOID SystemArgument2)
|
||||
{
|
||||
UNIMPLEMENTED;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user