Implemented setting the fs register to point to the TEB

svn path=/trunk/; revision=1062
This commit is contained in:
David Welch 2000-03-16 18:44:57 +00:00
parent 15c9809105
commit 337952bfb9
13 changed files with 308 additions and 280 deletions

View file

@ -17,8 +17,7 @@ include rules.mak
COMPONENTS = iface_native iface_additional ntoskrnl COMPONENTS = iface_native iface_additional ntoskrnl
DLLS = ntdll kernel32 crtdll advapi32 fmifs gdi32 DLLS = ntdll kernel32 crtdll advapi32 fmifs gdi32
#DLLS = mingw32 #DLLS = mingw32
SUBSYS = smss win32k SUBSYS = smss win32k csrss
#SUBSYS = csrss
# #
# Select the server(s) you want to build # Select the server(s) you want to build

View file

@ -1,4 +1,4 @@
/* $Id: shell.c,v 1.33 2000/03/12 23:24:51 ekohl Exp $ /* $Id: shell.c,v 1.34 2000/03/16 18:44:55 dwelch Exp $
* *
* PROJECT : ReactOS Operating System * PROJECT : ReactOS Operating System
* DESCRIPTION: ReactOS' Native Shell * DESCRIPTION: ReactOS' Native Shell
@ -178,11 +178,11 @@ int ExecuteProcess(char* name, char* cmdline, BOOL detached)
{ {
if (ret) if (ret)
{ {
debug_printf("ProcessInformation.hThread %x\n", // debug_printf("ProcessInformation.hThread %x\n",
ProcessInformation.hThread); // ProcessInformation.hThread);
WaitForSingleObject(ProcessInformation.hProcess, INFINITE); WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
CloseHandle(ProcessInformation.hProcess); CloseHandle(ProcessInformation.hProcess);
debug_printf("Thandle %x\n", ProcessInformation.hThread); // debug_printf("Thandle %x\n", ProcessInformation.hThread);
CloseHandle(ProcessInformation.hThread); CloseHandle(ProcessInformation.hThread);
} }
} }

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.2 2000/02/21 22:34:26 ekohl Exp $ # $Id: makefile,v 1.3 2000/03/16 18:44:55 dwelch Exp $
# #
# ReactOS Operating System # ReactOS Operating System
# #
@ -32,7 +32,7 @@ BASE_CFLAGS = -I../../include
all: $(SVC_FILES) all: $(SVC_FILES)
$(TARGETNAME)$(EXE_POSTFIX): $(TARGETNAME).c $(TARGETNAME)$(EXE_POSTFIX): $(TARGETNAME).c
$(CC) \ $(NATIVE_CC) \
$(CFLAGS) \ $(CFLAGS) \
-o $(TARGETNAME) \ -o $(TARGETNAME) \
-O2 \ -O2 \

12
reactos/install-system.sh Normal file
View file

@ -0,0 +1,12 @@
mkdir -p $1/reactos
mkdir -p $1/reactos/system32
mkdir -p $1/reactos/system32/drivers
mkdir -p $1/reactos/bin
cp loaders/dos/loadros.com $1
cp ntoskrnl/ntoskrnl.exe $1
cp services/fs/vfat/vfatfs.sys $1
cp services/dd/ide/ide.sys $1
cp services/dd/keyboard/keyboard.sys $1/reactos/system32/drivers
cp services/dd/blue/blue.sys $1/reactos/system32/drivers
cp services/dd/vga/vgamp.sys $1/reactos/system32/drivers
cp services/dd/vidport/vidport.sys $1/reactos/system32/drivers

7
reactos/install.bochs Normal file
View file

@ -0,0 +1,7 @@
#!/bin/sh
mount -t vfat /bochs/1.44a /mnt/floppy -o loop,rw
./install-system.sh /mnt/floppy
umount /mnt/floppy
mount -t vfat /bochs/10M.vga /mnt/floppy -o loop,rw
./install.sh /mnt/floppy
umount /mnt/floppy

View file

@ -1,4 +1,4 @@
/* $Id: curdir.c,v 1.21 2000/03/14 23:09:23 ekohl Exp $ /* $Id: curdir.c,v 1.22 2000/03/16 18:44:55 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -28,12 +28,8 @@ UNICODE_STRING WindowsDirectory;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
DWORD DWORD STDCALL GetCurrentDirectoryA (DWORD nBufferLength,
STDCALL LPSTR lpBuffer)
GetCurrentDirectoryA (
DWORD nBufferLength,
LPSTR lpBuffer
)
{ {
ANSI_STRING AnsiString; ANSI_STRING AnsiString;
UNICODE_STRING UnicodeString; UNICODE_STRING UnicodeString;
@ -75,12 +71,8 @@ GetCurrentDirectoryA (
} }
DWORD DWORD STDCALL GetCurrentDirectoryW (DWORD nBufferLength,
STDCALL LPWSTR lpBuffer)
GetCurrentDirectoryW (
DWORD nBufferLength,
LPWSTR lpBuffer
)
{ {
ULONG Length; ULONG Length;
@ -127,7 +119,6 @@ SetCurrentDirectoryA (
return TRUE; return TRUE;
} }
WINBOOL WINBOOL
STDCALL STDCALL
SetCurrentDirectoryW ( SetCurrentDirectoryW (
@ -233,13 +224,7 @@ GetTempPathW (
return Value.Length / sizeof(WCHAR); return Value.Length / sizeof(WCHAR);
} }
WINBOOL STDCALL SetCurrentDirectoryW (LPCWSTR lpPathName)
UINT
STDCALL
GetSystemDirectoryA (
LPSTR lpBuffer,
UINT uSize
)
{ {
ANSI_STRING String; ANSI_STRING String;
ULONG Length; ULONG Length;
@ -269,6 +254,7 @@ GetSystemDirectoryA (
} }
UINT UINT
STDCALL STDCALL
GetSystemDirectoryW ( GetSystemDirectoryW (

View file

@ -1,4 +1,4 @@
/* $Id: path.c,v 1.3 2000/03/13 17:54:23 ekohl Exp $ /* $Id: path.c,v 1.4 2000/03/16 18:44:55 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -19,7 +19,6 @@
#define NDEBUG #define NDEBUG
#include <ntdll/ntdll.h> #include <ntdll/ntdll.h>
/* DEFINITONS and MACROS ******************************************************/ /* DEFINITONS and MACROS ******************************************************/
#define MAX_PFX_SIZE 16 #define MAX_PFX_SIZE 16
@ -30,9 +29,7 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
static static ULONG RtlpGetDotSequence (PWSTR p)
ULONG
RtlpGetDotSequence (PWSTR p)
{ {
ULONG Count = 0; ULONG Count = 0;
@ -50,11 +47,7 @@ RtlpGetDotSequence (PWSTR p)
} }
static static VOID RtlpEatPath (PWSTR Path)
VOID
RtlpEatPath (
PWSTR Path
)
{ {
PWSTR p, prev; PWSTR p, prev;
@ -114,9 +107,7 @@ RtlpEatPath (
} }
ULONG ULONG STDCALL RtlGetLongestNtPathLength (VOID)
STDCALL
RtlGetLongestNtPathLength (VOID)
{ {
return (MAX_PATH + 9); return (MAX_PATH + 9);
} }
@ -282,11 +273,7 @@ RtlGetCurrentDirectory_U (
} }
NTSTATUS NTSTATUS STDCALL RtlSetCurrentDirectory_U (PUNICODE_STRING name)
STDCALL
RtlSetCurrentDirectory_U (
PUNICODE_STRING name
)
{ {
UNICODE_STRING full; UNICODE_STRING full;
OBJECT_ATTRIBUTES Attr; OBJECT_ATTRIBUTES Attr;
@ -301,7 +288,7 @@ RtlSetCurrentDirectory_U (
DPRINT ("RtlSetCurrentDirectory %wZ\n", name); DPRINT ("RtlSetCurrentDirectory %wZ\n", name);
RtlAcquirePebLock (); RtlAcquirePebLock ();
cd = &(NtCurrentPeb ()->ProcessParameters->CurrentDirectory); cd = &NtCurrentPeb ()->ProcessParameters->CurrentDirectory;
size = cd->DosPath.MaximumLength; size = cd->DosPath.MaximumLength;
buf = RtlAllocateHeap (RtlGetProcessHeap(), buf = RtlAllocateHeap (RtlGetProcessHeap(),

View file

@ -26,7 +26,7 @@ USHORT KiGdt[(8 + NR_TASKS) * 4] = {0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0xf200, 0xcc, 0x0, 0x0, 0xf200, 0xcc,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0}; 0x1000, 0x0, 0xf200, 0x0};
static KSPIN_LOCK GdtLock; static KSPIN_LOCK GdtLock;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -36,18 +36,29 @@ VOID KeSetBaseGdtSelector(ULONG Entry,
{ {
KIRQL oldIrql; KIRQL oldIrql;
DPRINT("KeSetBaseGdtSelector(Entry %x, Base %x)\n",
Entry, Base);
KeAcquireSpinLock(&GdtLock, &oldIrql); KeAcquireSpinLock(&GdtLock, &oldIrql);
KiGdt[Entry*4 + 1] = ((ULONG)Base) & 0xffff; Entry = (Entry & (~0x3)) / 2;
KiGdt[Entry*4 + 2] = KiGdt[Entry*4 + 2] & ~(0xff); KiGdt[Entry + 1] = ((ULONG)Base) & 0xffff;
KiGdt[Entry*4 + 2] = KiGdt[Entry*4 + 2] |
KiGdt[Entry + 2] = KiGdt[Entry + 2] & ~(0xff);
KiGdt[Entry + 2] = KiGdt[Entry + 2] |
((((ULONG)Base) & 0xff0000) >> 16); ((((ULONG)Base) & 0xff0000) >> 16);
KiGdt[Entry*4 + 3] = KiGdt[Entry*4 + 3] & ~(0xff00); KiGdt[Entry + 3] = KiGdt[Entry + 3] & ~(0xff00);
KiGdt[Entry*4 + 3] = KiGdt[Entry*4 + 3] | KiGdt[Entry + 3] = KiGdt[Entry + 3] |
((((ULONG)Base) & 0xff000000) >> 16); ((((ULONG)Base) & 0xff000000) >> 16);
DPRINT("%x %x %x %x\n",
KiGdt[Entry + 0],
KiGdt[Entry + 1],
KiGdt[Entry + 2],
KiGdt[Entry + 3]);
KeReleaseSpinLock(&GdtLock, oldIrql); KeReleaseSpinLock(&GdtLock, oldIrql);
} }

View file

@ -34,6 +34,8 @@ static char KiNullLdt[8] = {0,};
static unsigned int KiNullLdtSel = 0; static unsigned int KiNullLdtSel = 0;
static PETHREAD FirstThread = NULL; static PETHREAD FirstThread = NULL;
extern ULONG KeSetBaseGdtSelector(ULONG Entry, PVOID Base);
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
VOID HalTaskSwitch(PKTHREAD thread) VOID HalTaskSwitch(PKTHREAD thread)
@ -45,15 +47,14 @@ VOID HalTaskSwitch(PKTHREAD thread)
* again (possibly never) * again (possibly never)
*/ */
{ {
#if 0 // PETHREAD Thread;
PETHREAD Thread; // PVOID Teb;
Thread = CONTAINING_RECORD(thread, ETHREAD, Tcb);
if (Thread->Cid.UniqueThread != (HANDLE)1) /* Set the base of the TEB selector to the base of the TEB for the
{ * new thread
DPRINT1("Scheduling thread %x (id %d)\n",Thread, */
Thread->Cid.UniqueThread); KeSetBaseGdtSelector(TEB_SELECTOR, thread->Teb);
} /* Switch to the new thread's context and stack */
#endif
__asm__("pushfl\n\t" __asm__("pushfl\n\t"
"cli\n\t" "cli\n\t"
"ljmp %0\n\t" "ljmp %0\n\t"
@ -61,6 +62,31 @@ VOID HalTaskSwitch(PKTHREAD thread)
: /* No outputs */ : /* No outputs */
: "m" (*(((unsigned char *)(&(thread->Context.nr)))-4) ) : "m" (*(((unsigned char *)(&(thread->Context.nr)))-4) )
: "ax","dx"); : "ax","dx");
/* Reload the TEB selector */
__asm__("movw %0, %%ax\n\t"
"movw %%ax, %%fs\n\t"
: /* No outputs */
: "i" (TEB_SELECTOR)
: "ax");
#if 0
Thread = PsGetCurrentThread();
if (Thread->Cid.UniqueThread != (HANDLE)1)
{
// DbgPrint("Scheduling thread %x (id %d) teb %x\n",Thread,
// Thread->Cid.UniqueThread, Thread->Tcb.Teb);
}
if (Thread->Tcb.Teb != NULL)
{
// DbgPrint("cr3 %x\n", Thread->ThreadsProcess->Pcb.PageTableDirectory);
__asm__("movl %%fs:0x18, %0\n\t"
: "=g" (Teb)
: /* No inputs */
);
// DbgPrint("Teb %x\n", Teb);
}
#endif
} }
#define FLAG_NT (1<<14) #define FLAG_NT (1<<14)
@ -175,6 +201,7 @@ NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context)
} }
stack_start = kernel_stack + 3*PAGESIZE - sizeof(CONTEXT); stack_start = kernel_stack + 3*PAGESIZE - sizeof(CONTEXT);
Context->SegFs = TEB_SELECTOR;
memcpy(stack_start, Context, sizeof(CONTEXT)); memcpy(stack_start, Context, sizeof(CONTEXT));
/* /*

View file

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.39 2000/03/04 22:03:01 ekohl Exp $ /* $Id: main.c,v 1.40 2000/03/16 18:44:56 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -30,13 +30,10 @@
/* DATA *********************************************************************/ /* DATA *********************************************************************/
USHORT USHORT __declspec(dllexport) NtBuildNumber = KERNEL_VERSION_BUILD;
__declspec(dllexport) /* EXPORTED */
NtBuildNumber = KERNEL_VERSION_BUILD; /* EXPORTED */
ULONG ULONG __declspec(dllexport) NtGlobalFlag = 0; /* FIXME: EXPORTED */
__declspec(dllexport)
NtGlobalFlag = 0; /* FIXME: EXPORTED */
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/

View file

@ -243,13 +243,15 @@ ULONG MmPageFault(ULONG cs, ULONG eip, ULONG error_code)
MEMORY_AREA* MemoryArea; MEMORY_AREA* MemoryArea;
NTSTATUS Status; NTSTATUS Status;
unsigned int cr2; unsigned int cr2;
// unsigned int cr3;
/* /*
* Get the address for the page fault * Get the address for the page fault
*/ */
__asm__("movl %%cr2,%0\n\t" : "=d" (cr2)); __asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
DPRINT("Page fault address %x eip %x process %x code %x\n",cr2,eip, // __asm__("movl %%cr3,%0\n\t" : "=d" (cr3));
PsGetCurrentProcess(), error_code); // DPRINT1("Page fault address %x eip %x process %x code %x cr3 %x\n",cr2,eip,
// PsGetCurrentProcess(), error_code, cr3);
MmSetPageProtect(PsGetCurrentProcess(), MmSetPageProtect(PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(PsGetCurrentProcess()), (PVOID)PAGE_ROUND_DOWN(PsGetCurrentProcess()),

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.10 2000/02/14 14:13:33 dwelch Exp $ /* $Id: create.c,v 1.11 2000/03/16 18:44:57 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -369,8 +369,8 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
Thread->Tcb.WaitBlockList = NULL; Thread->Tcb.WaitBlockList = NULL;
InsertTailList(&Thread->ThreadsProcess->Pcb.ThreadListHead, InsertTailList(&Thread->ThreadsProcess->Pcb.ThreadListHead,
&Thread->Tcb.ProcessThreadListEntry ); &Thread->Tcb.ProcessThreadListEntry );
DPRINT1("Inserting %x into process %x list\n", // DPRINT1("Inserting %x into process %x list\n",
Thread, Thread->ThreadsProcess); // Thread, Thread->ThreadsProcess);
KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader, KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader,
InternalThreadType, InternalThreadType,
sizeof(ETHREAD), sizeof(ETHREAD),
@ -422,7 +422,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
PAGE_READWRITE); PAGE_READWRITE);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
DPRINT ("TEB allocated at %x\n", TebBase); DPRINT1 ("TEB allocated at %x\n", TebBase);
break; break;
} }
else else
@ -477,7 +477,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* free TEB */ /* free TEB */
DPRINT ("Writing TEB failed!\n"); DPRINT1 ("Writing TEB failed!\n");
RegionSize = 0; RegionSize = 0;
NtFreeVirtualMemory(ProcessHandle, NtFreeVirtualMemory(ProcessHandle,
@ -492,10 +492,10 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
if (TebPtr != NULL) if (TebPtr != NULL)
{ {
// *TebPtr = (PNT_TEB)TebBase; *TebPtr = (PNT_TEB)TebBase;
} }
DPRINT ("TEB allocated at %p\n", TebBase); DPRINT1 ("TEB allocated at %p\n", TebBase);
return Status; return Status;
} }
@ -540,7 +540,7 @@ NTSTATUS STDCALL NtCreateThread (PHANDLE ThreadHandle,
} }
/* Attention: TebBase is in user memory space */ /* Attention: TebBase is in user memory space */
// Thread->Tcb.Teb = TebBase; Thread->Tcb.Teb = TebBase;
Thread->StartAddress=NULL; Thread->StartAddress=NULL;

View file

@ -321,7 +321,7 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
InternalProcessType, InternalProcessType,
sizeof(EPROCESS), sizeof(EPROCESS),
FALSE); FALSE);
KProcess = &(Process->Pcb); KProcess = &Process->Pcb;
KProcess->BasePriority = PROCESS_PRIO_NORMAL; KProcess->BasePriority = PROCESS_PRIO_NORMAL;
InitializeListHead(&(KProcess->MemoryAreaList)); InitializeListHead(&(KProcess->MemoryAreaList));