Further SMP initialization work (now boots all processors on SMP bochs)

Preparation for per-processor GDT

svn path=/trunk/; revision=1805
This commit is contained in:
David Welch 2001-04-16 16:29:03 +00:00
parent add5e2d89f
commit 85f85e8462
9 changed files with 150 additions and 124 deletions

View file

@ -16,4 +16,4 @@ DBG := 1
# #
# Whether to compile a multiprocessor or single processor version # Whether to compile a multiprocessor or single processor version
# #
MP := 0 MP := 1

View file

@ -1,4 +1,4 @@
/* $Id: mp.c,v 1.8 2001/04/16 02:02:04 dwelch Exp $ /* $Id: mp.c,v 1.9 2001/04/16 16:29:01 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -1362,7 +1362,7 @@ static VOID SetInterruptGate(
{ {
IDT_DESCRIPTOR *idt; IDT_DESCRIPTOR *idt;
idt = (IDT_DESCRIPTOR*)((ULONG)CURRENT_KPCR->IDT + index * sizeof(IDT_DESCRIPTOR)); idt = (IDT_DESCRIPTOR*)((ULONG)KeGetCurrentKPCR()->IDT + index * sizeof(IDT_DESCRIPTOR));
idt->a = (((ULONG)address)&0xffff) + (KERNEL_CS << 16); idt->a = (((ULONG)address)&0xffff) + (KERNEL_CS << 16);
idt->b = 0x8f00 + (((ULONG)address)&0xffff0000); idt->b = 0x8f00 + (((ULONG)address)&0xffff0000);
} }
@ -2020,8 +2020,9 @@ HaliReadMPConfigTable(
{ {
PUCHAR pc = (PUCHAR)&Table->Signature; PUCHAR pc = (PUCHAR)&Table->Signature;
DbgPrint("Bad MP configuration block signature: %c%c%c%c/%x/%x\n", pc[0], DbgPrint("Bad MP configuration block signature: %c%c%c%c/%x/%x\n",
pc[1], pc[2], pc[3], MPC_SIGNATURE, (ULONG)Table->Signature); pc[0], pc[1], pc[2], pc[3], MPC_SIGNATURE,
(ULONG)Table->Signature);
KeBugCheck(0); KeBugCheck(0);
return; return;
} }
@ -2049,10 +2050,11 @@ HaliReadMPConfigTable(
KeBugCheck(0); KeBugCheck(0);
} }
Entry = (PUCHAR)(Table + sizeof(MP_CONFIGURATION_TABLE)); Entry = (PUCHAR)((PVOID)Table + sizeof(MP_CONFIGURATION_TABLE));
Count = 0; Count = 0;
while (Count < Table->Length) 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)
{ {
@ -2091,6 +2093,9 @@ HaliReadMPConfigTable(
Count += sizeof(MP_CONFIGURATION_INTLOCAL); Count += sizeof(MP_CONFIGURATION_INTLOCAL);
break; break;
} }
default:
DbgPrint("Unknown entry in MPC table\n");
KeBugCheck(0);
} }
} }
} }

View file

@ -252,7 +252,7 @@ typedef struct __attribute__((packed)) _MP_CONFIGURATION_TABLE
USHORT ExtTableLength; /* Extended Table Length */ USHORT ExtTableLength; /* Extended Table Length */
UCHAR ExtTableChecksum; /* Extended Table Checksum */ UCHAR ExtTableChecksum; /* Extended Table Checksum */
UCHAR Reserved; /* Reserved */ UCHAR Reserved; /* Reserved */
} MP_CONFIGURATION_TABLE, *PMP_CONFIGURATION_TABLE; } __attribute__((packed)) MP_CONFIGURATION_TABLE, *PMP_CONFIGURATION_TABLE;
/* MP Configuration Table Entries */ /* MP Configuration Table Entries */
#define MPCTE_PROCESSOR 0 /* One entry per processor */ #define MPCTE_PROCESSOR 0 /* One entry per processor */
@ -271,7 +271,8 @@ typedef struct __attribute__((packed)) _MP_CONFIGURATION_PROCESSOR
ULONG CpuSignature; /* CPU signature */ ULONG CpuSignature; /* CPU signature */
ULONG FeatureFlags; /* CPUID feature value */ ULONG FeatureFlags; /* CPUID feature value */
ULONG Reserved[2]; /* Reserved (0) */ ULONG Reserved[2]; /* Reserved (0) */
} MP_CONFIGURATION_PROCESSOR, *PMP_CONFIGURATION_PROCESSOR; } __attribute__((packed)) MP_CONFIGURATION_PROCESSOR,
*PMP_CONFIGURATION_PROCESSOR;
#define CPU_FLAG_ENABLED 1 /* Processor is available */ #define CPU_FLAG_ENABLED 1 /* Processor is available */
#define CPU_FLAG_BSP 2 /* Processor is the bootstrap processor */ #define CPU_FLAG_BSP 2 /* Processor is the bootstrap processor */
@ -286,7 +287,7 @@ typedef struct __attribute__((packed)) _MP_CONFIGURATION_BUS
UCHAR Type; /* 1 */ UCHAR Type; /* 1 */
UCHAR BusId; /* Bus ID */ UCHAR BusId; /* Bus ID */
UCHAR BusType[6]; /* Bus type */ UCHAR BusType[6]; /* Bus type */
} MP_CONFIGURATION_BUS, *PMP_CONFIGURATION_BUS; } __attribute__((packed)) MP_CONFIGURATION_BUS, *PMP_CONFIGURATION_BUS;
#define MAX_BUS 32 #define MAX_BUS 32
@ -322,7 +323,7 @@ typedef struct __attribute__((packed)) _MP_CONFIGURATION_IOAPIC
UCHAR ApicVersion; /* I/O APIC version */ UCHAR ApicVersion; /* I/O APIC version */
UCHAR ApicFlags; /* I/O APIC flags */ UCHAR ApicFlags; /* I/O APIC flags */
ULONG ApicAddress; /* I/O APIC base address */ ULONG ApicAddress; /* I/O APIC base address */
} MP_CONFIGURATION_IOAPIC, *PMP_CONFIGURATION_IOAPIC; } __attribute__((packed)) MP_CONFIGURATION_IOAPIC, *PMP_CONFIGURATION_IOAPIC;
#define MAX_IOAPIC 2 #define MAX_IOAPIC 2
@ -338,7 +339,7 @@ typedef struct __attribute__((packed)) _MP_CONFIGURATION_INTSRC
UCHAR SrcBusIrq; /* Source bus interrupt */ UCHAR SrcBusIrq; /* Source bus interrupt */
UCHAR DstApicId; /* Destination APIC ID */ UCHAR DstApicId; /* Destination APIC ID */
UCHAR DstApicInt; /* Destination interrupt */ UCHAR DstApicInt; /* Destination interrupt */
} MP_CONFIGURATION_INTSRC, *PMP_CONFIGURATION_INTSRC; } __attribute__((packed)) MP_CONFIGURATION_INTSRC, *PMP_CONFIGURATION_INTSRC;
#define MAX_IRQ_SOURCE 128 #define MAX_IRQ_SOURCE 128

View file

@ -89,9 +89,7 @@ static inline PKPCR KeGetCurrentKPCR(VOID)
return((PKPCR)value); return((PKPCR)value);
} }
#define CURRENT_KPCR KeGetCurrentKPCR() #define KeGetCurrentProcessorNumber() (KeGetCurrentKPCR()->ProcessorNumber)
#define KeGetCurrentProcessorNumber (KeGetCurrentKPCR()->ProcessorNumber)
extern HANDLE SystemProcessHandle; extern HANDLE SystemProcessHandle;

View file

@ -1,4 +1,4 @@
/* $Id: irq.c,v 1.10 2001/04/16 02:02:05 dwelch Exp $ /* $Id: irq.c,v 1.11 2001/04/16 16:29:02 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -100,14 +100,14 @@ B16(7) B16(8) B16(9) B16(A)
B16(B) B16(C) B16(D) B16(E) B16(B) B16(C) B16(D) B16(E)
B16(F) B16(F)
#undef B; #undef B
#undef B16; #undef B16
/* Interrupt handler list */ /* Interrupt handler list */
#define L(x,y) \ #define L(x,y) \
(ULONG)&##INT_NAME2(x##y) (ULONG)& INT_NAME2(x##y)
#define L16(x) \ #define L16(x) \
L(x,0), L(x,1), L(x,2), L(x,3), \ L(x,0), L(x,1), L(x,2), L(x,3), \
@ -122,8 +122,8 @@ static ULONG irq_handler[NR_IRQS] = {
L16(F) L16(F)
}; };
#undef L; #undef L
#undef L16; #undef L16
#else /* MP */ #else /* MP */

View file

@ -183,14 +183,14 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
* FIXME: Why this? * FIXME: Why this?
*/ */
Thread->KernelApcDisable = 1; Thread->KernelApcDisable = 1;
Thread->UserAffinity = 0; Thread->UserAffinity = Process->Affinity;
Thread->SystemAffinityActive = 0; Thread->SystemAffinityActive = 0;
Thread->Queue = NULL; Thread->Queue = NULL;
KeInitializeSpinLock(&Thread->ApcQueueLock); KeInitializeSpinLock(&Thread->ApcQueueLock);
memset(&Thread->Timer, 0, sizeof(KTIMER)); memset(&Thread->Timer, 0, sizeof(KTIMER));
Thread->QueueListEntry.Flink = NULL; Thread->QueueListEntry.Flink = NULL;
Thread->QueueListEntry.Blink = NULL; Thread->QueueListEntry.Blink = NULL;
Thread->Affinity = 0; Thread->Affinity = Process->Affinity;
Thread->Preempted = 0; Thread->Preempted = 0;
Thread->ProcessReadyQueue = 0; Thread->ProcessReadyQueue = 0;
Thread->KernelStackResident = 1; Thread->KernelStackResident = 1;

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.89 2001/04/16 02:02:04 dwelch Exp $ /* $Id: main.c,v 1.90 2001/04/16 16:29:02 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/main.c * FILE: ntoskrnl/ke/main.c
@ -470,13 +470,6 @@ ExpInitializeExecutive(VOID)
} }
HalDisplayString(str); HalDisplayString(str);
#ifdef MP
DbgPrint("BSP halted\n");
for (;;);
#endif /* MP */
/* /*
* Initialize various critical subsystems * Initialize various critical subsystems
*/ */

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.61 2001/04/16 02:02:06 dwelch Exp $ /* $Id: process.c,v 1.62 2001/04/16 16:29:03 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -48,7 +48,8 @@ static GENERIC_MAPPING PiProcessMapping = {PROCESS_READ,
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
PEPROCESS PsGetNextProcess(PEPROCESS OldProcess) PEPROCESS
PsGetNextProcess(PEPROCESS OldProcess)
{ {
KIRQL oldIrql; KIRQL oldIrql;
PEPROCESS NextProcess; PEPROCESS NextProcess;
@ -87,7 +88,8 @@ PEPROCESS PsGetNextProcess(PEPROCESS OldProcess)
return(NextProcess); return(NextProcess);
} }
NTSTATUS STDCALL NtOpenProcessToken(IN HANDLE ProcessHandle, NTSTATUS STDCALL
NtOpenProcessToken(IN HANDLE ProcessHandle,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
OUT PHANDLE TokenHandle) OUT PHANDLE TokenHandle)
{ {
@ -109,7 +111,8 @@ NTSTATUS STDCALL NtOpenProcessToken(IN HANDLE ProcessHandle,
return(Status); return(Status);
} }
PACCESS_TOKEN STDCALL PsReferencePrimaryToken(PEPROCESS Process) PACCESS_TOKEN STDCALL
PsReferencePrimaryToken(PEPROCESS Process)
{ {
ObReferenceObjectByPointer(Process->Token, ObReferenceObjectByPointer(Process->Token,
TOKEN_ALL_ACCESS, TOKEN_ALL_ACCESS,
@ -118,7 +121,8 @@ PACCESS_TOKEN STDCALL PsReferencePrimaryToken(PEPROCESS Process)
return(Process->Token); return(Process->Token);
} }
NTSTATUS PsOpenTokenOfProcess(HANDLE ProcessHandle, NTSTATUS
PsOpenTokenOfProcess(HANDLE ProcessHandle,
PACCESS_TOKEN* Token) PACCESS_TOKEN* Token)
{ {
PEPROCESS Process; PEPROCESS Process;
@ -139,7 +143,8 @@ NTSTATUS PsOpenTokenOfProcess(HANDLE ProcessHandle,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
VOID PiKillMostProcesses(VOID) VOID
PiKillMostProcesses(VOID)
{ {
KIRQL oldIrql; KIRQL oldIrql;
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
@ -206,6 +211,8 @@ VOID PsInitProcessManagment(VOID)
PROCESS_ALL_ACCESS, PROCESS_ALL_ACCESS,
NULL, NULL,
PsProcessType); PsProcessType);
/* System threads may run on any processor. */
PsInitialSystemProcess->Pcb.Affinity = 0xFFFFFFFF;
PsInitialSystemProcess->Pcb.BasePriority = PROCESS_PRIO_NORMAL; PsInitialSystemProcess->Pcb.BasePriority = PROCESS_PRIO_NORMAL;
KeInitializeDispatcherHeader(&PsInitialSystemProcess->Pcb.DispatcherHeader, KeInitializeDispatcherHeader(&PsInitialSystemProcess->Pcb.DispatcherHeader,
InternalProcessType, InternalProcessType,
@ -391,7 +398,8 @@ NtCreateProcess (OUT PHANDLE ProcessHandle,
sizeof(EPROCESS), sizeof(EPROCESS),
FALSE); FALSE);
KProcess = &Process->Pcb; KProcess = &Process->Pcb;
/* Inherit parent process's affinity. */
KProcess->Affinity = ParentProcess->Pcb.Affinity;
KProcess->BasePriority = PROCESS_PRIO_NORMAL; KProcess->BasePriority = PROCESS_PRIO_NORMAL;
MmInitializeAddressSpace(Process, MmInitializeAddressSpace(Process,
&Process->AddressSpace); &Process->AddressSpace);

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.74 2001/04/16 02:02:07 dwelch Exp $ /* $Id: thread.c,v 1.75 2001/04/16 16:29:03 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -71,7 +71,8 @@ HANDLE STDCALL PsGetCurrentThreadId(VOID)
return(PsGetCurrentThread()->Cid.UniqueThread); return(PsGetCurrentThread()->Cid.UniqueThread);
} }
VOID PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread) VOID
PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread)
{ {
if (Priority >= MAXIMUM_PRIORITY || Priority < 0) if (Priority >= MAXIMUM_PRIORITY || Priority < 0)
{ {
@ -115,8 +116,9 @@ VOID PsDumpThreads(VOID)
} }
} }
static PETHREAD PsScanThreadList (KPRIORITY Priority) static PETHREAD PsScanThreadList (KPRIORITY Priority, ULONG Affinity)
{ {
#if 0
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PETHREAD current; PETHREAD current;
@ -132,6 +134,23 @@ static PETHREAD PsScanThreadList (KPRIORITY Priority)
} }
return(current); return(current);
#else
PLIST_ENTRY current_entry;
PETHREAD current;
current_entry = PriorityListHead[Priority].Flink;
while (current_entry != &PriorityListHead[Priority])
{
current = CONTAINING_RECORD(current_entry, ETHREAD,
Tcb.QueueListEntry);
if (current->Tcb.UserAffinity & Affinity)
{
return(current);
}
current_entry = current_entry->Flink;
}
return(NULL);
#endif
} }
@ -139,6 +158,7 @@ VOID PsDispatchThreadNoLock (ULONG NewThreadStatus)
{ {
KPRIORITY CurrentPriority; KPRIORITY CurrentPriority;
PETHREAD Candidate; PETHREAD Candidate;
ULONG Affinity;
CurrentThread->Tcb.State = NewThreadStatus; CurrentThread->Tcb.State = NewThreadStatus;
if (CurrentThread->Tcb.State == THREAD_STATE_RUNNABLE) if (CurrentThread->Tcb.State == THREAD_STATE_RUNNABLE)
@ -148,11 +168,12 @@ VOID PsDispatchThreadNoLock (ULONG NewThreadStatus)
CurrentThread); CurrentThread);
} }
Affinity = 1 << KeGetCurrentProcessorNumber();
for (CurrentPriority = HIGH_PRIORITY; for (CurrentPriority = HIGH_PRIORITY;
CurrentPriority >= LOW_PRIORITY; CurrentPriority >= LOW_PRIORITY;
CurrentPriority--) CurrentPriority--)
{ {
Candidate = PsScanThreadList(CurrentPriority); Candidate = PsScanThreadList(CurrentPriority, Affinity);
if (Candidate == CurrentThread) if (Candidate == CurrentThread)
{ {
KeReleaseSpinLockFromDpcLevel(&PiThreadListLock); KeReleaseSpinLockFromDpcLevel(&PiThreadListLock);
@ -313,7 +334,7 @@ PsInitThreadManagment(VOID)
FirstThread->Tcb.State = THREAD_STATE_RUNNING; FirstThread->Tcb.State = THREAD_STATE_RUNNING;
FirstThread->Tcb.FreezeCount = 0; FirstThread->Tcb.FreezeCount = 0;
CurrentThread = FirstThread; CurrentThread = FirstThread;
CURRENT_KPCR->CurrentThread = (PVOID)FirstThread; KeGetCurrentKPCR()->CurrentThread = (PVOID)FirstThread;
NtClose(FirstThreadHandle); NtClose(FirstThreadHandle);
DPRINT("FirstThread %x\n",FirstThread); DPRINT("FirstThread %x\n",FirstThread);