per processor TSS

svn path=/trunk/; revision=1807
This commit is contained in:
David Welch 2001-04-16 23:29:55 +00:00
parent 2dfc5cfcd4
commit 2cfadf3b41
15 changed files with 406 additions and 146 deletions

View file

@ -26,7 +26,8 @@ OBJECTS_KE_I386 := \
ke/i386/ldt.o \ ke/i386/ldt.o \
ke/i386/brkpoint.o \ ke/i386/brkpoint.o \
ke/i386/kernel.o \ ke/i386/kernel.o \
ke/i386/fpu.o ke/i386/fpu.o \
ke/i386/tss.o
OBJECTS_MM_I386 := \ OBJECTS_MM_I386 := \
mm/i386/memsafe.o \ mm/i386/memsafe.o \

View file

@ -1,4 +1,4 @@
/* $Id: mp.c,v 1.9 2001/04/16 16:29:01 dwelch Exp $ /* $Id: mp.c,v 1.10 2001/04/16 23:29:54 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -43,6 +43,7 @@ typedef struct __attribute__((packed)) _COMMON_AREA_INFO
ULONG Debug[16]; /* For debugging */ ULONG Debug[16]; /* For debugging */
} COMMON_AREA_INFO, *PCOMMON_AREA_INFO; } COMMON_AREA_INFO, *PCOMMON_AREA_INFO;
extern PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS];
CPU_INFO CPUMap[MAX_CPU]; /* Map of all CPUs in the system */ CPU_INFO CPUMap[MAX_CPU]; /* Map of all CPUs in the system */
ULONG CPUCount; /* Total number of CPUs */ ULONG CPUCount; /* Total number of CPUs */
@ -1636,6 +1637,7 @@ HalInitializeProcessor (
/* Write the location of the AP stack */ /* Write the location of the AP stack */
Common->Stack = (ULONG)ExAllocatePool(NonPagedPool, MM_STACK_SIZE) + MM_STACK_SIZE; Common->Stack = (ULONG)ExAllocatePool(NonPagedPool, MM_STACK_SIZE) + MM_STACK_SIZE;
Ki386InitialStackArray[CPU] = (PVOID)(Common->Stack - MM_STACK_SIZE);
DPRINT("CPU %d got stack at 0x%X\n", CPU, Common->Stack); DPRINT("CPU %d got stack at 0x%X\n", CPU, Common->Stack);
#if 0 #if 0
@ -2020,9 +2022,8 @@ HaliReadMPConfigTable(
{ {
PUCHAR pc = (PUCHAR)&Table->Signature; PUCHAR pc = (PUCHAR)&Table->Signature;
DbgPrint("Bad MP configuration block signature: %c%c%c%c/%x/%x\n", DbgPrint("Bad MP configuration block signature: %c%c%c%c\n",
pc[0], pc[1], pc[2], pc[3], MPC_SIGNATURE, pc[0], pc[1], pc[2], pc[3]);
(ULONG)Table->Signature);
KeBugCheck(0); KeBugCheck(0);
return; return;
} }
@ -2054,7 +2055,6 @@ HaliReadMPConfigTable(
Count = 0; Count = 0;
while (Count < (Table->Length - sizeof(MP_CONFIGURATION_TABLE))) while (Count < (Table->Length - sizeof(MP_CONFIGURATION_TABLE)))
{ {
DbgPrint("Scanning entry %x/%x Count %x\n", Entry, *Entry, Count);
/* Switch on type */ /* Switch on type */
switch (*Entry) switch (*Entry)
{ {

View file

@ -190,6 +190,15 @@ KiDispatchException(PEXCEPTION_RECORD Er,
BOOLEAN SearchFrames); BOOLEAN SearchFrames);
VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame, VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
PCONTEXT Context); PCONTEXT Context);
struct _KPCR;
VOID
KiInitializeGdt(struct _KPCR* Pcr);
VOID
KeApplicationProcessorInit();
VOID
Ki386ApplicationProcessorInitializeTSS(VOID);
VOID
Ki386BootInitializeTSS(VOID);
#endif /* not __ASM__ */ #endif /* not __ASM__ */

View file

@ -44,6 +44,7 @@
#define KPCR_EXCEPTION_LIST 0x0 #define KPCR_EXCEPTION_LIST 0x0
#define KPCR_SELF 0x18 #define KPCR_SELF 0x18
#define KPCR_TSS 0x28
#define KPCR_CURRENT_THREAD 0x124 #define KPCR_CURRENT_THREAD 0x124
#ifndef __ASM__ #ifndef __ASM__
@ -62,20 +63,21 @@ struct _KTRAPFRAME;
*/ */
typedef struct _KPCR typedef struct _KPCR
{ {
PVOID ExceptionList; /* 00 */ PVOID ExceptionList; /* 00 */
PVOID StackBase; /* 04 */ PVOID StackBase; /* 04 */
PVOID StackLimit; /* 08 */ PVOID StackLimit; /* 08 */
PVOID SubSystemTib; /* 0C */ PVOID SubSystemTib; /* 0C */
PVOID Reserved1; /* 10 */ PVOID Reserved1; /* 10 */
PVOID ArbitraryUserPointer; /* 14 */ PVOID ArbitraryUserPointer; /* 14 */
struct _KPCR* Self; /* 18 */ struct _KPCR* Self; /* 18 */
UCHAR ProcessorNumber; /* 1C */ UCHAR ProcessorNumber; /* 1C */
KIRQL Irql; /* 1D */ KIRQL Irql; /* 1D */
UCHAR Reserved2[0x2]; /* 1E */ UCHAR Reserved2[0x2]; /* 1E */
PUSHORT IDT; /* 20 */ PUSHORT IDT; /* 20 */
PUSHORT GDT; /* 24 */ PUSHORT GDT; /* 24 */
UCHAR Reserved3[0xFC]; /* 28 */ KTSS* TSS; /* 28 */
struct _KTHREAD* CurrentThread; /* 124 */ UCHAR Reserved3[0xF8]; /* 2C */
struct _KTHREAD* CurrentThread; /* 124 */
} __attribute__((packed)) KPCR, *PKPCR; } __attribute__((packed)) KPCR, *PKPCR;
static inline PKPCR KeGetCurrentKPCR(VOID) static inline PKPCR KeGetCurrentKPCR(VOID)

View file

@ -339,11 +339,11 @@ KiDoubleFaultHandler(VOID)
ULONG StackLimit; ULONG StackLimit;
ULONG Esp0; ULONG Esp0;
ULONG ExceptionNr = 8; ULONG ExceptionNr = 8;
extern KTSS KiTss; KTSS* OldTss;
/* Use the address of the trap frame as approximation to the ring0 esp */ /* Use the address of the trap frame as approximation to the ring0 esp */
Esp0 = KiTss.Esp0; OldTss = KeGetCurrentKPCR()->TSS;
Esp0 = OldTss->Esp0;
/* Get CR2 */ /* Get CR2 */
__asm__("movl %%cr2,%0\n\t" : "=d" (cr2)); __asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
@ -371,10 +371,10 @@ KiDoubleFaultHandler(VOID)
{ {
DbgPrint("Exception: %d(%x)\n", ExceptionNr, 0); DbgPrint("Exception: %d(%x)\n", ExceptionNr, 0);
} }
DbgPrint("CS:EIP %x:%x ", KiTss.Cs, KiTss.Eip); DbgPrint("CS:EIP %x:%x ", OldTss->Cs, OldTss->Eip);
print_address((PVOID)KiTss.Eip); print_address((PVOID)OldTss->Eip);
DbgPrint("\n"); DbgPrint("\n");
DbgPrint("cr2 %x cr3 %x ", cr2, KiTss.Cr3); DbgPrint("cr2 %x cr3 %x ", cr2, OldTss->Cr3);
DbgPrint("Proc: %x ",PsGetCurrentProcess()); DbgPrint("Proc: %x ",PsGetCurrentProcess());
if (PsGetCurrentProcess() != NULL) if (PsGetCurrentProcess() != NULL)
{ {
@ -388,14 +388,14 @@ KiDoubleFaultHandler(VOID)
PsGetCurrentThread()->Cid.UniqueThread); PsGetCurrentThread()->Cid.UniqueThread);
} }
DbgPrint("\n"); DbgPrint("\n");
DbgPrint("DS %x ES %x FS %x GS %x\n", KiTss.Ds, KiTss.Es, DbgPrint("DS %x ES %x FS %x GS %x\n", OldTss->Ds, OldTss->Es,
KiTss.Fs, KiTss.Gs); OldTss->Fs, OldTss->Gs);
DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", KiTss.Eax, KiTss.Ebx, DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", OldTss->Eax, OldTss->Ebx,
KiTss.Ecx); OldTss->Ecx);
DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x\n", KiTss.Edx, KiTss.Ebp, DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x\n", OldTss->Edx, OldTss->Ebp,
KiTss.Esi); OldTss->Esi);
DbgPrint("EDI: %.8x EFLAGS: %.8x ", KiTss.Edi, KiTss.Eflags); DbgPrint("EDI: %.8x EFLAGS: %.8x ", OldTss->Edi, OldTss->Eflags);
if (KiTss.Cs == KERNEL_CS) if (OldTss->Cs == KERNEL_CS)
{ {
DbgPrint("kESP %.8x ", Esp0); DbgPrint("kESP %.8x ", Esp0);
if (PsGetCurrentThread() != NULL) if (PsGetCurrentThread() != NULL)
@ -407,9 +407,9 @@ KiDoubleFaultHandler(VOID)
} }
else else
{ {
DbgPrint("User ESP %.8x\n", KiTss.Esp); DbgPrint("User ESP %.8x\n", OldTss->Esp);
} }
if ((KiTss.Cs & 0xffff) == KERNEL_CS) if ((OldTss->Cs & 0xffff) == KERNEL_CS)
{ {
DbgPrint("ESP %x\n", Esp0); DbgPrint("ESP %x\n", Esp0);
stack = (PULONG) (Esp0 + 24); stack = (PULONG) (Esp0 + 24);
@ -528,7 +528,8 @@ KiTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr)
{ {
DbgPrint("Exception: %d(%x)\n", ExceptionNr, Tf->ErrorCode&0xffff); DbgPrint("Exception: %d(%x)\n", ExceptionNr, Tf->ErrorCode&0xffff);
} }
DbgPrint("CS:EIP %x:%x ", Tf->Cs&0xffff, Tf->Eip); DbgPrint("Processor: %d CS:EIP %x:%x ", KeGetCurrentProcessorNumber(),
Tf->Cs&0xffff, Tf->Eip);
print_address((PVOID)Tf->Eip); print_address((PVOID)Tf->Eip);
DbgPrint("\n"); DbgPrint("\n");
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3)); __asm__("movl %%cr3,%0\n\t" : "=d" (cr3));
@ -665,15 +666,9 @@ void KeInitExceptions(void)
int i; int i;
ULONG base, length; ULONG base, length;
extern USHORT KiBootGdt[]; extern USHORT KiBootGdt[];
extern unsigned int trap_stack_top;
extern KTSS KiTss;
extern KTSS KiTrapTss;
ULONG cr3;
DPRINT("KeInitExceptions()\n",0); DPRINT("KeInitExceptions()\n",0);
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3));
/* /*
* Set up an a descriptor for the LDT * Set up an a descriptor for the LDT
*/ */
@ -687,64 +682,6 @@ void KeInitExceptions(void)
KiBootGdt[(LDT_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) | KiBootGdt[(LDT_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16); ((base & 0xFF000000) >> 16);
/*
* Set up a descriptor for the TSS
*/
memset(&KiTss, 0, sizeof(KiTss));
base = (unsigned int)&KiTss;
length = sizeof(KiTss) - 1;
KiBootGdt[(TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
KiBootGdt[(TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
KiBootGdt[(TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
KiBootGdt[(TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
/*
* Initialize the TSS
*/
KiTss.Esp0 = (ULONG)&init_stack_top;
KiTss.Ss0 = KERNEL_DS;
// KiTss.IoMapBase = FIELD_OFFSET(KTSS, IoBitmap);
KiTss.IoMapBase = 0xFFFF; /* No i/o bitmap */
KiTss.IoBitmap[0] = 0xFF;
KiTss.Ldt = LDT_SELECTOR;
/*
* Load the task register
*/
__asm__("ltr %%ax"
: /* no output */
: "a" (TSS_SELECTOR));
/*
* Set up the TSS for handling double faults
*/
memset(&KiTrapTss, 0, sizeof(KiTrapTss));
base = (unsigned int)&KiTrapTss;
length = sizeof(KiTrapTss) - 1;
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
KiTrapTss.Eflags = 0;
KiTrapTss.Esp0 = (ULONG)&trap_stack_top;
KiTrapTss.Ss0 = KERNEL_DS;
KiTrapTss.Esp = (ULONG)&trap_stack_top;
KiTrapTss.Cs = KERNEL_CS;
KiTrapTss.Eip = (ULONG)KiTrap8;
KiTrapTss.Ss = KERNEL_DS;
KiTrapTss.Ds = KERNEL_DS;
KiTrapTss.Es = KERNEL_DS;
KiTrapTss.Fs = PCR_SELECTOR;
KiTrapTss.IoMapBase = 0xFFFF; /* No i/o bitmap */
KiTrapTss.IoBitmap[0] = 0xFF;
KiTrapTss.Ldt = LDT_SELECTOR;
KiTrapTss.Cr3 = cr3;
/* /*
* Set up the other gates * Set up the other gates
*/ */

View file

@ -30,6 +30,7 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <internal/ke.h> #include <internal/ke.h>
#include <internal/ps.h> #include <internal/ps.h>
#include <internal/i386/segment.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
@ -64,11 +65,18 @@ static KSPIN_LOCK GdtLock;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID VOID
KiInitializeGdt(ULONG Id, PKPCR Pcr) KiInitializeGdt(PKPCR Pcr)
{ {
PUSHORT Gdt; PUSHORT Gdt;
struct
{
USHORT Length;
ULONG Base;
} __attribute__((packed)) Descriptor;
ULONG Entry;
ULONG Base;
if (Id == 0) if (Pcr == NULL)
{ {
KiGdtArray[0] = KiBootGdt; KiGdtArray[0] = KiBootGdt;
return; return;
@ -89,8 +97,45 @@ KiInitializeGdt(ULONG Id, PKPCR Pcr)
* We will be initializing these later so their current values are * We will be initializing these later so their current values are
* irrelevant. * irrelevant.
*/ */
memcpy(Gdt, KiGdtArray, sizeof(USHORT) * 4 * 11); memcpy(Gdt, KiBootGdt, sizeof(USHORT) * 4 * 11);
KiGdtArray[Id] = Gdt; KiGdtArray[Pcr->ProcessorNumber] = Gdt;
Pcr->GDT = Gdt;
/*
* Set the base address of the PCR
*/
Base = (ULONG)Pcr;
Entry = PCR_SELECTOR / 2;
Gdt[Entry + 1] = ((ULONG)Base) & 0xffff;
Gdt[Entry + 2] = Gdt[Entry + 2] & ~(0xff);
Gdt[Entry + 2] = Gdt[Entry + 2] | ((((ULONG)Base) & 0xff0000) >> 16);
Gdt[Entry + 3] = Gdt[Entry + 3] & ~(0xff00);
Gdt[Entry + 3] = Gdt[Entry + 3] | ((((ULONG)Base) & 0xff000000) >> 16);
/*
* Load the GDT
*/
Descriptor.Length = 8 * 11;
Descriptor.Base = (ULONG)Gdt;
__asm__ ("lgdt %0\n\t" : /* no output */ : "m" (Descriptor));
/*
* Reload the selectors
*/
__asm__ ("movl %0, %%ds\n\t"
"movl %0, %%es\n\t"
"movl %1, %%fs\n\t"
"movl %0, %%gs\n\t"
: /* no output */
: "a" (KERNEL_DS), "b" (PCR_SELECTOR));
__asm__ ("pushl %0\n\t"
"pushl $.l4\n\t"
"lret\n\t"
".l4:\n\t"
: /* no output */
: "a" (KERNEL_CS));
} }
VOID VOID

View file

@ -18,7 +18,7 @@
*/ */
/* /*
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/kernel.c * FILE: ntoskrnl/ke/i386/kernel.c
* PURPOSE: Initializes the kernel * PURPOSE: Initializes the kernel
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY: * UPDATE HISTORY:
@ -39,17 +39,52 @@
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
ULONG KiPcrInitDone = 0; ULONG KiPcrInitDone = 0;
static ULONG PcrsAllocated = 0;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID
KeApplicationProcessorInit()
{
PKPCR KPCR;
ULONG Offset;
/*
* Create a PCR for this processor
*/
Offset = InterlockedIncrement(&PcrsAllocated);
KPCR = (PKPCR)(KPCR_BASE + (Offset * PAGESIZE));
MmCreateVirtualMapping(NULL,
(PVOID)KPCR,
PAGE_READWRITE,
(ULONG)MmAllocPage(0));
memset(KPCR, 0, PAGESIZE);
KPCR->ProcessorNumber = Offset;
KPCR->Self = KPCR;
KPCR->Irql = HIGH_LEVEL;
/*
* Initialize the GDT
*/
KiInitializeGdt(KPCR);
/*
* Initialize the TSS
*/
Ki386ApplicationProcessorInitializeTSS();
}
VOID VOID
KeInit1(VOID) KeInit1(VOID)
{ {
PKPCR KPCR; PKPCR KPCR;
extern USHORT KiBootGdt[]; extern USHORT KiBootGdt[];
extern KTSS KiBootTss;
KiCheckFPU(); KiCheckFPU();
KiInitializeGdt (NULL);
Ki386BootInitializeTSS();
KeInitExceptions (); KeInitExceptions ();
KeInitInterrupts (); KeInitInterrupts ();
@ -64,7 +99,10 @@ KeInit1(VOID)
KPCR->Irql = HIGH_LEVEL; KPCR->Irql = HIGH_LEVEL;
KPCR->GDT = (PUSHORT)&KiBootGdt; KPCR->GDT = (PUSHORT)&KiBootGdt;
KPCR->IDT = (PUSHORT)&KiIdt; KPCR->IDT = (PUSHORT)&KiIdt;
KPCR->TSS = &KiBootTss;
KPCR->ProcessorNumber = 0;
KiPcrInitDone = 1; KiPcrInitDone = 1;
PcrsAllocated++;
} }
VOID VOID

View file

@ -1,9 +1,26 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * ReactOS kernel
* Copyright (C) 2000 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/ldt.c * FILE: ntoskrnl/ke/i386/ldt.c
* PURPOSE: LDT managment * PURPOSE: LDT managment
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 22/05/98 * Created 22/05/98
*/ */
@ -11,18 +28,27 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <internal/ke.h>
#include <internal/ps.h>
#include <internal/i386/segment.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLOBALS *******************************************************************/
/*
*
*/
//STATIC UCHAR KiNullLdt[8] = {0,};
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS STDCALL NTSTATUS STDCALL
NtSetLdtEntries(HANDLE Thread, ULONG FirstEntry, PULONG Entries) NtSetLdtEntries (HANDLE Thread,
ULONG FirstEntry,
PULONG Entries)
{ {
UNIMPLEMENTED; return(STATUS_NOT_IMPLEMENTED);
} }

View file

@ -197,7 +197,7 @@ _multiboot_entry:
* Load the GDTR and IDTR with new tables located above * Load the GDTR and IDTR with new tables located above
* 0xc0000000 * 0xc0000000
*/ */
/* FIXME: Application processors should have their own GDT/IDT */ /* FIXME: Application processors should have their own GDT/IDT */
lgdt _KiGdtDescriptor lgdt _KiGdtDescriptor
lidt _KiIdtDescriptor lidt _KiIdtDescriptor
@ -236,12 +236,12 @@ _multiboot_entry:
pushl $KERNEL_CS pushl $KERNEL_CS
pushl $_KiSystemStartup pushl $_KiSystemStartup
lret lret
popl %eax
/* /*
* Catch illegal returns from KiSystemStartup * Catch illegal returns from KiSystemStartup
*/ */
.l7: .l7:
popl %eax
pushl $0 pushl $0
call _KeBugCheck@4 call _KeBugCheck@4
popl %eax popl %eax
@ -274,14 +274,14 @@ _multiboot_entry:
pushl $KERNEL_CS pushl $KERNEL_CS
pushl $__main pushl $__main
lret lret
popl %eax
popl %eax
/* /*
* Catch illegal returns from main, try bug checking the system, * Catch illegal returns from main, try bug checking the system,
* if that fails then loop forever. * if that fails then loop forever.
*/ */
.l5: .l5:
popl %eax
popl %eax
pushl $0 pushl $0
call _KeBugCheck@4 call _KeBugCheck@4
popl %eax popl %eax

View file

@ -37,15 +37,6 @@
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLOBALS ***************************************************************/
KTSS KiTss;
KTSS KiTrapTss;
extern USHORT KiGdt[];
extern unsigned int init_stack_top;
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
#define FLAG_NT (1<<14) #define FLAG_NT (1<<14)

View file

@ -80,7 +80,7 @@ _Ki386ContextSwitch:
/* /*
* Set the current thread information in the PCR * Set the current thread information in the PCR
*/ */
movl %ebx, %fs:KPCR_CURRENT_THREAD movl %ebx, %fs:KPCR_CURRENT_THREAD
/* /*
* FIXME: Save debugging state. * FIXME: Save debugging state.
@ -102,7 +102,8 @@ _Ki386ContextSwitch:
* Set the stack pointer in this processors TSS * Set the stack pointer in this processors TSS
*/ */
movl KTHREAD_INITIAL_STACK(%ebx), %eax movl KTHREAD_INITIAL_STACK(%ebx), %eax
movl %eax, (_KiTss + KTSS_ESP0) movl %fs:KPCR_TSS, %esi
movl %eax, KTSS_ESP0(%esi)
/* /*
* Change the address space * Change the address space

View file

@ -0,0 +1,209 @@
/*
* ReactOS kernel
* Copyright (C) 2000 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/i386/tss.c
* PURPOSE: TSS managment
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ke.h>
#include <internal/ps.h>
#include <internal/i386/segment.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
static KTSS* Ki386TssArray[MAXIMUM_PROCESSORS];
PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS];
static KTSS* Ki386TrapTssArray[MAXIMUM_PROCESSORS];
static PVOID Ki386TrapStackArray[MAXIMUM_PROCESSORS];
KTSS KiBootTss;
static KTSS KiBootTrapTss;
extern USHORT KiBootGdt[];
extern VOID KiTrap8(VOID);
/* FUNCTIONS *****************************************************************/
VOID
Ki386ApplicationProcessorInitializeTSS(VOID)
{
ULONG cr3;
KTSS* Tss;
KTSS* TrapTss;
PVOID TrapStack;
ULONG Id;
PUSHORT Gdt;
ULONG base, length;
Id = KeGetCurrentProcessorNumber();
Gdt = KeGetCurrentKPCR()->GDT;
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3));
Tss = ExAllocatePool(NonPagedPool, sizeof(KTSS));
TrapTss = ExAllocatePool(NonPagedPool, sizeof(KTSS));
TrapStack = ExAllocatePool(NonPagedPool, MM_STACK_SIZE);
Ki386TssArray[Id] = Tss;
Ki386TrapTssArray[Id] = TrapTss;
Ki386TrapStackArray[Id] = TrapStack;
KeGetCurrentKPCR()->TSS = Tss;
/* Initialize the boot TSS. */
Tss->Esp0 = (ULONG)Ki386InitialStackArray[Id];
Tss->Ss0 = KERNEL_DS;
// Tss.IoMapBase = FIELD_OFFSET(KTSS, IoBitmap);
Tss->IoMapBase = 0xFFFF; /* No i/o bitmap */
Tss->IoBitmap[0] = 0xFF;
Tss->Ldt = LDT_SELECTOR;
/*
* Initialize a descriptor for the TSS
*/
base = (ULONG)Tss;
length = sizeof(KTSS) - 1;
Gdt[(TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
Gdt[(TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
Gdt[(TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
Gdt[(TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
/* Initialize the TSS used for handling double faults. */
TrapTss->Eflags = 0;
TrapTss->Esp0 = ((ULONG)TrapStack + MM_STACK_SIZE);
TrapTss->Ss0 = KERNEL_DS;
TrapTss->Esp = ((ULONG)TrapStack + MM_STACK_SIZE);
TrapTss->Cs = KERNEL_CS;
TrapTss->Eip = (ULONG)KiTrap8;
TrapTss->Ss = KERNEL_DS;
TrapTss->Ds = KERNEL_DS;
TrapTss->Es = KERNEL_DS;
TrapTss->Fs = PCR_SELECTOR;
TrapTss->IoMapBase = 0xFFFF; /* No i/o bitmap */
TrapTss->IoBitmap[0] = 0xFF;
TrapTss->Ldt = LDT_SELECTOR;
TrapTss->Cr3 = cr3;
/*
* Initialize a descriptor for the trap TSS.
*/
base = (ULONG)TrapTss;
length = sizeof(KTSS) - 1;
Gdt[(TRAP_TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
Gdt[(TRAP_TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
Gdt[(TRAP_TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
Gdt[(TRAP_TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
/*
* Load the task register
*/
__asm__("ltr %%ax"
: /* no output */
: "a" (TSS_SELECTOR));
}
VOID
Ki386BootInitializeTSS(VOID)
{
ULONG cr3;
extern unsigned int init_stack, init_stack_top;
extern unsigned int trap_stack, trap_stack_top;
unsigned int base, length;
__asm__("movl %%cr3,%0\n\t" : "=d" (cr3));
Ki386TssArray[0] = &KiBootTss;
Ki386TrapTssArray[0] = &KiBootTrapTss;
Ki386TrapStackArray[0] = (PVOID)&trap_stack;
Ki386InitialStackArray[0] = (PVOID)&init_stack;
/* Initialize the boot TSS. */
KiBootTss.Esp0 = (ULONG)&init_stack_top;
KiBootTss.Ss0 = KERNEL_DS;
// KiBootTss.IoMapBase = FIELD_OFFSET(KTSS, IoBitmap);
KiBootTss.IoMapBase = 0xFFFF; /* No i/o bitmap */
KiBootTss.IoBitmap[0] = 0xFF;
KiBootTss.Ldt = LDT_SELECTOR;
/*
* Initialize a descriptor for the TSS
*/
base = (unsigned int)&KiBootTss;
length = sizeof(KiBootTss) - 1;
KiBootGdt[(TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
KiBootGdt[(TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
KiBootGdt[(TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
KiBootGdt[(TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
/* Initialize the TSS used for handling double faults. */
KiBootTrapTss.Eflags = 0;
KiBootTrapTss.Esp0 = (ULONG)&trap_stack_top;
KiBootTrapTss.Ss0 = KERNEL_DS;
KiBootTrapTss.Esp = (ULONG)&trap_stack_top;
KiBootTrapTss.Cs = KERNEL_CS;
KiBootTrapTss.Eip = (ULONG)KiTrap8;
KiBootTrapTss.Ss = KERNEL_DS;
KiBootTrapTss.Ds = KERNEL_DS;
KiBootTrapTss.Es = KERNEL_DS;
KiBootTrapTss.Fs = PCR_SELECTOR;
KiBootTrapTss.IoMapBase = 0xFFFF; /* No i/o bitmap */
KiBootTrapTss.IoBitmap[0] = 0xFF;
KiBootTrapTss.Ldt = LDT_SELECTOR;
KiBootTrapTss.Cr3 = cr3;
/*
* Initialize a descriptor for the trap TSS.
*/
base = (unsigned int)&KiBootTrapTss;
length = sizeof(KiBootTrapTss) - 1;
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 0] = (length & 0xFFFF);
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 1] = (base & 0xFFFF);
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 2] = ((base & 0xFF0000) >> 16) | 0x8900;
KiBootGdt[(TRAP_TSS_SELECTOR / 2) + 3] = ((length & 0xF0000) >> 16) |
((base & 0xFF000000) >> 16);
/*
* Load the task register
*/
__asm__("ltr %%ax"
: /* no output */
: "a" (TSS_SELECTOR));
}

View file

@ -89,7 +89,7 @@ _Ki386RetToV86Mode:
* will be the current stack adjusted so we don't overwrite the * will be the current stack adjusted so we don't overwrite the
* existing stack frames * existing stack frames
*/ */
movl $_KiTss, %esi movl %fs:KPCR_TSS, %esi
movl %esp, KTSS_ESP0(%esi) movl %esp, KTSS_ESP0(%esi)
/* /*
@ -181,7 +181,7 @@ _KiV86Complete:
* Restore the initial stack * Restore the initial stack
*/ */
popl %eax popl %eax
movl $_KiTss, %esi movl %fs:KPCR_TSS, %esi
movl %eax, KTSS_ESP0(%esi) movl %eax, KTSS_ESP0(%esi)
/* /*

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: main.c,v 1.90 2001/04/16 16:29:02 dwelch Exp $ /* $Id: main.c,v 1.91 2001/04/16 23:29:54 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/main.c * FILE: ntoskrnl/ke/main.c
@ -576,6 +576,7 @@ KiSystemStartup(BOOLEAN BootProcessor)
KeBugCheck(0); KeBugCheck(0);
} }
/* Do application processor initialization */ /* Do application processor initialization */
KeApplicationProcessorInit();
for(;;); for(;;);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: page.c,v 1.27 2001/04/16 02:02:05 dwelch Exp $ /* $Id: page.c,v 1.28 2001/04/16 23:29:55 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/i386/page.c * FILE: ntoskrnl/mm/i386/page.c
@ -661,16 +661,16 @@ MmCreateVirtualMapping(PEPROCESS Process,
ULONG flProtect, ULONG flProtect,
ULONG PhysicalAddress) ULONG PhysicalAddress)
{ {
if (!MmIsUsablePage((PVOID)PhysicalAddress)) if (!MmIsUsablePage((PVOID)PhysicalAddress))
{ {
DPRINT1("Page at address %x not usable\n", PhysicalAddress); DPRINT1("Page at address %x not usable\n", PhysicalAddress);
KeBugCheck(0); KeBugCheck(0);
} }
return(MmCreateVirtualMappingUnsafe(Process, return(MmCreateVirtualMappingUnsafe(Process,
Address, Address,
flProtect, flProtect,
PhysicalAddress)); PhysicalAddress));
} }
ULONG ULONG