mirror of
https://github.com/reactos/reactos.git
synced 2025-01-07 14:51:00 +00:00
- Add Ke386SetInterruptDescriptorTable inlined function to set the IDT.
- Rename and fixup initial stacks, instead of using 16 different variables all with confusining meanings and values. Define P0BootStack as the initial kernel stack, and KiDoubleFaultStack as the double-fault trap (and initial DPC) stack. - Fix call to KiInitializePcr which was setting an incorrect DPC stack. - Make space on the initial stack for a KTRAP_FRAME as well, not only for the FPU save area. - Also push initial CR0 NPX state on the initial stack. - Load the IDT and GDT directly in KiRosPrepareForSystemStartup. - Completely rewrite main_asm.S in Intel syntax and clean it up. svn path=/trunk/; revision=23901
This commit is contained in:
parent
4eebe5e53f
commit
c65323691c
10 changed files with 56 additions and 64 deletions
|
@ -493,6 +493,11 @@ Author:
|
|||
// Kernel Feature Bits
|
||||
//
|
||||
#define KF_RDTSC 0x00000002
|
||||
|
||||
//
|
||||
// Kernel Stack Size
|
||||
//
|
||||
#define KERNEL_STACK_SIZE 0x3000
|
||||
#endif
|
||||
|
||||
//
|
||||
|
|
|
@ -145,6 +145,10 @@ KiThreadStartup(PKSYSTEM_ROUTINE SystemRoutine,
|
|||
__asm__("lldt %0\n\t" \
|
||||
: /* no outputs */ \
|
||||
: "m" (X));
|
||||
#define Ke386SetInterruptDescriptorTable(X) \
|
||||
__asm__("lidt %0\n\t" \
|
||||
: /* no outputs */ \
|
||||
: "m" (X));
|
||||
#define Ke386SetGlobalDescriptorTable(X) \
|
||||
__asm__("lgdt %0\n\t" \
|
||||
: /* no outputs */ \
|
||||
|
|
|
@ -96,7 +96,11 @@ extern ULONG KeI386EFlagsOrMaskV86;
|
|||
extern BOOLEAN KeI386VirtualIntExtensions;
|
||||
extern KIDTENTRY KiIdt[];
|
||||
extern KGDTENTRY KiBootGdt[];
|
||||
extern KDESCRIPTOR KiGdtDescriptor;
|
||||
extern KDESCRIPTOR KiIdtDescriptor;
|
||||
extern KTSS KiBootTss;
|
||||
extern UCHAR P0BootStack[];
|
||||
extern UCHAR KiDoubleFaultStack[];
|
||||
extern FAST_MUTEX KernelAddressSpaceLock;
|
||||
extern ULONG KiMaximumDpcQueueDepth;
|
||||
extern ULONG KiMinimumDpcRate;
|
||||
|
@ -119,7 +123,6 @@ extern KEVENT KiSwapEvent;
|
|||
extern PKPRCB KiProcessorBlock[];
|
||||
extern ULONG KiMask32Array[MAXIMUM_PRIORITY];
|
||||
extern ULONG IdleProcessorMask;
|
||||
extern ULONG trap_stack_top;
|
||||
extern VOID KiTrap8(VOID);
|
||||
extern VOID KiTrap2(VOID);
|
||||
|
||||
|
|
|
@ -582,7 +582,7 @@ Ki386InitializeTss(VOID)
|
|||
Tss = (PKTSS)KiDoubleFaultTSS;
|
||||
KiInitializeTSS(Tss);
|
||||
Tss->CR3 = _Ke386GetCr(3);
|
||||
Tss->Esp0 = trap_stack_top;
|
||||
Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
|
||||
Tss->Eip = PtrToUlong(KiTrap8);
|
||||
Tss->Cs = KGDT_R0_CODE;
|
||||
Tss->Fs = KGDT_R0_PCR;
|
||||
|
@ -613,7 +613,7 @@ Ki386InitializeTss(VOID)
|
|||
Tss = (PKTSS)KiNMITSS;
|
||||
KiInitializeTSS(Tss);
|
||||
Tss->CR3 = _Ke386GetCr(3);
|
||||
Tss->Esp0 = trap_stack_top;
|
||||
Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
|
||||
Tss->Eip = PtrToUlong(KiTrap2);
|
||||
Tss->Cs = KGDT_R0_CODE;
|
||||
Tss->Fs = KGDT_R0_PCR;
|
||||
|
|
|
@ -26,7 +26,7 @@ ETHREAD KiInitialThread;
|
|||
EPROCESS KiInitialProcess;
|
||||
|
||||
extern ULONG Ke386GlobalPagesEnabled;
|
||||
extern PVOID trap_stack, init_stack;
|
||||
extern PVOID trap_stack;
|
||||
|
||||
/* System-defined Spinlocks */
|
||||
KSPIN_LOCK KiDispatcherLock;
|
||||
|
@ -514,7 +514,7 @@ KiSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock)
|
|||
KiBootGdt,
|
||||
&KiBootTss,
|
||||
&KiInitialThread.Tcb,
|
||||
trap_stack);
|
||||
KiDoubleFaultStack);
|
||||
|
||||
/* Set us as the current process */
|
||||
KiInitialThread.Tcb.ApcState.Process = &KiInitialProcess.Pcb;
|
||||
|
@ -554,7 +554,7 @@ AppCpuInit:
|
|||
/* Call main kernel intialization */
|
||||
KiInitializeKernel(&KiInitialProcess.Pcb,
|
||||
&KiInitialThread.Tcb,
|
||||
init_stack,
|
||||
P0BootStack,
|
||||
Prcb,
|
||||
Cpu,
|
||||
LoaderBlock);
|
||||
|
|
|
@ -1,46 +1,45 @@
|
|||
#include <roscfg.h>
|
||||
#include <ndk/asm.h>
|
||||
/*
|
||||
* FILE: ntoskrnl/ke/i386/main_asm.S
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PURPOSE: Kernel Bootstrap Code
|
||||
* PROGRAMMER: Alex Ionescu (alex@relsoft.net)
|
||||
*/
|
||||
|
||||
#define AP_MAGIC (0x12481020)
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
.global _kernel_stack
|
||||
.global _kernel_stack_top
|
||||
.global _kernel_trap_stack
|
||||
.global _kernel_trap_stack_top
|
||||
#include <asm.h>
|
||||
.intel_syntax noprefix
|
||||
|
||||
.globl _NtProcessStartup
|
||||
/* GLOBALS *******************************************************************/
|
||||
|
||||
.bss
|
||||
.align 4096
|
||||
.align 16
|
||||
|
||||
/* Kernel Boot Stack */
|
||||
.globl _P0BootStack
|
||||
.space KERNEL_STACK_SIZE
|
||||
_P0BootStack:
|
||||
|
||||
/* guard page for the kernel stack */
|
||||
.fill 4096, 1, 0
|
||||
/* Kernel Double-Fault and Temporary DPC Stack */
|
||||
.globl _KiDoubleFaultStack
|
||||
.space KERNEL_STACK_SIZE
|
||||
_KiDoubleFaultStack:
|
||||
|
||||
_kernel_stack:
|
||||
.fill 3*4096, 1, 0
|
||||
_kernel_stack_top:
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
/* guard page for the trap stack */
|
||||
.fill 4096, 1, 0
|
||||
|
||||
_kernel_trap_stack:
|
||||
.fill 3*4096, 1, 0
|
||||
_kernel_trap_stack_top:
|
||||
|
||||
.text
|
||||
|
||||
.func NtProcessStartup
|
||||
_NtProcessStartup:
|
||||
|
||||
/* FIXME: Application processors should have their own GDT/IDT */
|
||||
lgdt _KiGdtDescriptor
|
||||
lidt _KiIdtDescriptor
|
||||
|
||||
/* Load the initial kernel stack */
|
||||
lea _kernel_stack_top, %eax
|
||||
sub $(SIZEOF_FX_SAVE_AREA), %eax
|
||||
movl %eax, %esp
|
||||
lea eax, _P0BootStack
|
||||
sub eax, (NPX_FRAME_LENGTH + KTRAP_FRAME_LENGTH + KTRAP_FRAME_ALIGN)
|
||||
mov esp, eax
|
||||
|
||||
/* Save initial CR0 state */
|
||||
push CR0_EM + CR0_TS + CR0_MP
|
||||
|
||||
/* Call the main kernel initialization */
|
||||
pushl %edx
|
||||
push edx
|
||||
call _KiRosPrepareForSystemStartup@4
|
||||
.endfunc
|
||||
|
|
|
@ -86,9 +86,6 @@ _KiUnexpectedEntrySize:
|
|||
_UnexpectedMsg:
|
||||
.asciz "\n\x7\x7!!! Unexpected Interrupt %02lx !!!\n"
|
||||
|
||||
Broken:
|
||||
.asciz "\n\x7\x7!!! Broken TrapFrame. Magic: %08lx MagicB: %08lx!!!\n"
|
||||
|
||||
/* SOFTWARE INTERRUPT SERVICES ***********************************************/
|
||||
|
||||
_KiGetTickCount:
|
||||
|
|
|
@ -48,18 +48,6 @@ PVOID KeRaiseUserExceptionDispatcher = NULL;
|
|||
|
||||
ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
|
||||
|
||||
/* the initial stacks are declared in main_asm.S */
|
||||
extern ULONG kernel_stack;
|
||||
extern ULONG kernel_stack_top;
|
||||
extern ULONG kernel_trap_stack;
|
||||
extern ULONG kernel_trap_stack_top;
|
||||
|
||||
/* These point to the aligned 3 pages */
|
||||
ULONG init_stack = (ULONG)&kernel_stack;
|
||||
ULONG init_stack_top = (ULONG)&kernel_stack_top;
|
||||
ULONG trap_stack = (ULONG)&kernel_trap_stack;
|
||||
ULONG trap_stack_top = (ULONG)&kernel_trap_stack_top;
|
||||
|
||||
/* Cached modules from the loader block */
|
||||
PLOADER_MODULE CachedModules[MaximumCachedModuleType];
|
||||
|
||||
|
@ -97,6 +85,10 @@ KiRosPrepareForSystemStartup(IN PROS_LOADER_PARAMETER_BLOCK LoaderBlock)
|
|||
PIMAGE_OPTIONAL_HEADER OptHead;
|
||||
CHAR* s;
|
||||
|
||||
/* Load the GDT and IDT */
|
||||
Ke386SetGlobalDescriptorTable(KiGdtDescriptor);
|
||||
Ke386SetInterruptDescriptorTable(KiIdtDescriptor);
|
||||
|
||||
/* Copy the Loader Block Data locally since Low-Memory will be wiped */
|
||||
memcpy(&KeLoaderBlock, LoaderBlock, sizeof(ROS_LOADER_PARAMETER_BLOCK));
|
||||
memcpy(&KeLoaderModules[1],
|
||||
|
|
|
@ -36,10 +36,6 @@ PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
|
|||
PVOID MiNonPagedPoolStart;
|
||||
ULONG MiNonPagedPoolLength;
|
||||
|
||||
extern ULONG init_stack;
|
||||
extern ULONG init_stack_top;
|
||||
extern ULONG trap_stack;
|
||||
|
||||
VOID INIT_FUNCTION NTAPI MmInitVirtualMemory(ULONG_PTR LastKernelAddress, ULONG KernelLength);
|
||||
|
||||
#if defined (ALLOC_PRAGMA)
|
||||
|
@ -394,10 +390,6 @@ MmInit1(ULONG_PTR FirstKrnlPhysAddr,
|
|||
AddressRangeCount);
|
||||
kernel_len = LastKrnlPhysAddr - FirstKrnlPhysAddr;
|
||||
|
||||
/* Unmap the guard pages from the initial stacks */
|
||||
MmDeleteVirtualMapping(NULL, (PVOID)(init_stack - PAGE_SIZE), FALSE, NULL, NULL);
|
||||
MmDeleteVirtualMapping(NULL, (PVOID)(trap_stack - PAGE_SIZE), FALSE, NULL, NULL);
|
||||
|
||||
/*
|
||||
* Unmap low memory
|
||||
*/
|
||||
|
|
|
@ -59,19 +59,19 @@ PsInitializeIdleOrFirstThread(PEPROCESS Process,
|
|||
BOOLEAN First)
|
||||
{
|
||||
PETHREAD Thread;
|
||||
ULONG_PTR KernelStack;
|
||||
extern unsigned int init_stack_top;
|
||||
PVOID KernelStack;
|
||||
|
||||
Thread = ExAllocatePool(NonPagedPool, sizeof(ETHREAD));
|
||||
RtlZeroMemory(Thread, sizeof(ETHREAD));
|
||||
Thread->ThreadsProcess = Process;
|
||||
if (First)
|
||||
{
|
||||
KernelStack = init_stack_top;
|
||||
KernelStack = P0BootStack;
|
||||
}
|
||||
else
|
||||
{
|
||||
KernelStack = (ULONG_PTR)MmCreateKernelStack(FALSE) + KERNEL_STACK_SIZE;
|
||||
KernelStack = (PVOID)((ULONG_PTR)MmCreateKernelStack(FALSE) +
|
||||
KERNEL_STACK_SIZE);
|
||||
}
|
||||
KeInitializeThread(&Process->Pcb,
|
||||
&Thread->Tcb,
|
||||
|
@ -80,7 +80,7 @@ PsInitializeIdleOrFirstThread(PEPROCESS Process,
|
|||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(PVOID)KernelStack);
|
||||
KernelStack);
|
||||
InitializeListHead(&Thread->IrpList);
|
||||
*ThreadPtr = Thread;
|
||||
return STATUS_SUCCESS;
|
||||
|
|
Loading…
Reference in a new issue