Initial revision

svn path=/trunk/; revision=8046
This commit is contained in:
Aleksey Bragin 2004-02-06 08:21:52 +00:00
parent a4b76f805d
commit b1adc9e47f
23 changed files with 7489 additions and 0 deletions

2
msvc6/.cvsignore Normal file
View file

@ -0,0 +1,2 @@
*.ncb
*.opt

102
msvc6/README.txt Normal file
View file

@ -0,0 +1,102 @@
ReactOS Microsoft Visual C/C++ 6.0 IDE files
This is the Microsoft Visual C/C++ 6.0 project workspace and project
files for a few of the ReactOS binaries. They are ONLY included as a
convenience, and is NOT to be considered supported, or even correct.
If you build a binary that misbehaves using these files, you _might_
be able to get in touch with someone to fix the problem
BUT DO NOT COUNT ON IT!
The only supported build system for ReactOS is the one documented at
www.reactos.com.
------------------------------------------------------------------
Please, before you start playing with this, read the whole of
this document.
Before you can use these project files, you _need_ to make a successful
build using the normal ReactOS build system. There are some vital files
that needs to be created, and currently only the normal build creates these.
Once that is done, you need to generate the kernel-mode service "table"
file by running nmake (from this point on you can use the "native"
MSVC tools) from the directory MSVC6\iface\native.
This will generate MSVC6\ntoskrnl\nt_zw_msvc.c, an MSVC compatible inline-
assembler version of the file otherwise known as reactos\ntoskrnl\nt\zw.c.
Next, go to def_converter and run nmake. This builds the tool to convert
the .def files for HAL and the kernel from the MinGW format to something
more suitable for the MSVC linker, and also generates these .def files
to their target location [1].
Now you should be set to fire up the IDE and load the project workspace.
When building HAL or the kernel for the first time using these
project files, just doing it the "normal" way _will not work_.
The linker will complain about missing library, and it will fail.
The reason for this is a circular dependency between these two binaries.
Currently you need to follow these procedures [2]:
- Select hal as your active project.
- Select Project/Settings.
- Select the Link tab.
- Select "General" from the Category drop-list.
- Temporary remove the explicit linker library
(e.g. "..\ntoskrnl\Debug\ntoskrnl.lib")
- Select "Customize" from the Category drop-list.
- Check the "Force file output" checkbox.
- Build hal.
- Uncheck "Force file output".
- Put back the removed import library.
- Now build the ntoskrnl. Do NOT try to build hal again until
you have sucessfully built the kernel, and the linker has
generated its import library!
- Now you can "Clean" hal, and build it as usual.
If everything worked as expected, you should now have both ntoskrnl.exe
and hal.dll freshly built.
LIMITATIONS/DEVIATIONS (from the MinGW build):
- Since there can only be one resource file/project, the kernel had
to choose between either its version resource, or its message table.
The messages won.
- Do NOT open the .rc files in the IDE's resource editor. Chances are
it will assume ownership over them and fill them up with at least
conditional compilation macros.
NOTES:
[1] This is needed due to differences in handling of decorated names
in .def files. While both MinGW GCC and MSVC generates decorated names
in the same way for at least plain cdecl and stdcall C functions, the
MSVC linker expects names in the .def file to be either
- an exact match of the decorated name, in case it exports the
decorated name from the linked binary, or
- just the name without any decoration, in case it exports just the
name of the symbol from the linked binary (to allow for e.g.
GetProcAddress using the undecorated name) - but keeps the decorated
names in the import library to handle and "redirect" linker requests
for those decorated symbols, and point them to the undercorated names
in the binary exporting them - so that a binary A, at link time,
importing symbols from binary B of the form "_name@0" will resolve
that symbol from the import library, but the linked binary A will
reference it as just "name".
The ROS .def files contains a mix, "half-decorated", where the leading
undescores are missing, but the trailing "@n" (for stdcall functions)
are present.
[2] Theoretically it could be possible to use a hal.lib generated by the
following procedure, removing the need for the manual steps above.
cd MSVC6\hal\Debug
lib \def:..\..\..\reactos\hal\hal\hal.def
but I have not tested it, and take no responsibility for its effectiveness.

41
msvc6/ReactOS.dsw Normal file
View file

@ -0,0 +1,41 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "hal"=.\hal\hal.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "ntoskrnl"=.\ntoskrnl\ntoskrnl.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View file

@ -0,0 +1,64 @@
// Uses hard-coded filenames to require a minimum of input.
// You think this file should be licensed? OK then,
// Copyright (C) 2004, Mike Nordell. Use as you whish.
#include <fstream>
#include <string>
#include <algorithm>
const char szSrc1[] = "..\\..\\reactos\\ntoskrnl\\ntoskrnl.def";
const char szDst1[] = "..\\ntoskrnl\\ntoskrnl.def";
const char szSrc2[] = "..\\..\\reactos\\hal\\hal\\hal.def";
const char szDst2[] = "..\\hal\\hal.def";
enum File
{
Kernel,
HAL
};
std::string do_kernel_replacements(std::string& s)
{
std::string s2 = s.c_str(); // to fixup size after replacements
if (s2 == "ExAllocateFromPagedLookasideList") {
s2 += "=ExiAllocateFromPagedLookasideList";
} else
if (s2 == "ExFreeToPagedLookasideList") {
s2 += "=ExiFreeToPagedLookasideList";
} else
if (s2 == "MmLockPagableImageSection") {
s2 += "=MmLockPagableDataSection";
}
return s2;
}
void convert_def(const char* szSrc, const char* szDst, File file)
{
using namespace std;
ifstream in(szSrc);
ofstream out(szDst);
string s;
while (getline(in, s).good()) {
if (!s.size()) {
continue;
}
if (s[0] != ';') { // only replace non-comment lines
if (s[0] == '@') {
s.erase(0, 1);
}
replace(s.begin(), s.end(), '@', '\0');
if (file == Kernel) {
s = do_kernel_replacements(s);
}
}
out << s << endl;
}
}
int main()
{
convert_def(szSrc1, szDst1, Kernel);
convert_def(szSrc2, szDst2, HAL);
return 0;
}

View file

@ -0,0 +1,19 @@
# $Id: makefile,v 1.1 2004/02/06 08:21:54 fireball Exp $
#
# ReactOS Operating System - .def converter for HAL and the kernel
#
DEF_HAL = ..\hal\hal.def
DEF_KRNL = ..\ntoskrnl\ntoskrnl.def
CPPFLAGS = /GX
all: def_converter.exe $(DEF_HAL) $(DEF_KRNL)
$(DEF_HAL) : ..\..\reactos\hal\hal\hal.def
def_converter.exe
$(DEF_KRNL) : ..\..\reactos\ntoskrnl\ntoskrnl.def
def_converter.exe
def_converter.exe : def_converter.cpp

3
msvc6/hal/.cvsignore Normal file
View file

@ -0,0 +1,3 @@
Debug
Release
hal.def

243
msvc6/hal/hal.dsp Normal file
View file

@ -0,0 +1,243 @@
# Microsoft Developer Studio Project File - Name="hal" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=hal - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "hal.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "hal.mak" CFG="hal - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "hal - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "hal - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "hal - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HAL_EXPORTS" /YX /FD /c
# ADD CPP /nologo /MT /W3 /Ot /Og /Os /Ob1 /I "..\..\reactos\include" /I "..\..\reactos\hal\halx86\include" /I "..\..\reactos\ntoskrnl\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "i386" /D "__NTHAL__" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x41d /d "NDEBUG"
# ADD RSC /l 0x417 /i "..\..\reactos\include" /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /dll /machine:I386
# ADD LINK32 ..\ntoskrnl\Release\ntoskrnl.lib /nologo /dll /machine:I386 /fixed:no
# SUBTRACT LINK32 /pdb:none /force
!ELSEIF "$(CFG)" == "hal - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HAL_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Z7 /Od /I "..\..\reactos\include" /I "..\..\reactos\hal\halx86\include" /I "..\..\reactos\ntoskrnl\include" /D "_WINDOWS" /D "__NTHAL__" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "i386" /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x41d /d "_DEBUG"
# ADD RSC /l 0x417 /i "..\..\reactos\include" /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\ntoskrnl\Debug\ntoskrnl.lib /nologo /dll /incremental:no /debug /machine:I386 /pdbtype:sept /fixed:no
# SUBTRACT LINK32 /pdb:none
!ENDIF
# Begin Target
# Name "hal - Win32 Release"
# Name "hal - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\adapter.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\beep.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\bus.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\display.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\dma.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\drive.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\enum.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\fmutex.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\fmutex_tmn.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\halinit.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\halx86mp.rc
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\halx86up.rc
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\irql.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\isa.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\kdbg.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\mca.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\misc.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\mp.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\mpsirql.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\pci.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\portio.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\pwroff.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\reboot.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\spinlock.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\spinlock_tmn.c
# PROP Exclude_From_Build 1
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\sysbus.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\sysinfo.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\time.c
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\timer.c
# End Source File
# End Group
# Begin Group "include"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\include\bus.h
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\include\hal.h
# End Source File
# Begin Source File
SOURCE=..\..\reactos\hal\halx86\include\mps.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Source File
SOURCE=.\hal.def
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,392 @@
/* $Id: genntdll.c,v 1.1 2004/02/06 08:21:56 fireball Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS version of ntdll
* FILE: iface/native/genntdll.c
* PURPOSE: Generates the system call stubs in ntdll
* CHANGE HISTORY: Added a '@xx' to deal with stdcall [ Ariadne ]
* 19990616 (ea)
* Four arguments now required; 4th is the file
* for ntoskrnl ZwXXX functions (which are merely calls
* to twin NtXXX calls, via int 0x2e (x86).
* 19990617 (ea)
* Fixed a bug in function numbers in kernel ZwXXX stubs.
*
*/
/* INCLUDE ******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PARAMETERIZED_LIBS
/* #define VERBOSE */
#define INPUT_BUFFER_SIZE 255
/* FUNCTIONS ****************************************************************/
void write_syscall_stub(FILE* out, FILE* out3, char* name, char* name2,
char* nr_args, unsigned int sys_call_idx)
{
int i;
int nArgBytes = atoi(nr_args);
#ifdef PARAMETERIZED_LIBS
fprintf(out,"__asm__(\"\\n\\t.global _%s@%s\\n\\t\"\n",name,nr_args);
fprintf(out,"\".global _%s@%s\\n\\t\"\n",name2,nr_args);
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name,nr_args);
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name2,nr_args);
#else
fprintf(out,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
fprintf(out,"\".global _%s\\n\\t\"\n",name2);
fprintf(out,"\"_%s:\\n\\t\"\n",name);
fprintf(out,"\"_%s:\\n\\t\"\n",name2);
#endif
fprintf(out,"\t\"pushl\t%%ebp\\n\\t\"\n");
fprintf(out,"\t\"movl\t%%esp, %%ebp\\n\\t\"\n");
fprintf(out,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx);
fprintf(out,"\t\"lea\t8(%%ebp),%%edx\\n\\t\"\n");
fprintf(out,"\t\"int\t$0x2E\\n\\t\"\n");
fprintf(out,"\t\"popl\t%%ebp\\n\\t\"\n");
fprintf(out,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args);
/*
* Now write the NTOSKRNL stub for the
* current system call. ZwXXX does NOT
* alias the corresponding NtXXX call.
*/
#if 0
fprintf(out3,"__asm__(\n");
fprintf(out3,"\".global _%s@%s\\n\\t\"\n",name2,nr_args);
fprintf(out3,"\"_%s@%s:\\n\\t\"\n",name2,nr_args);
fprintf(out3,"\t\"pushl\t%%ebp\\n\\t\"\n");
fprintf(out3,"\t\"movl\t%%esp, %%ebp\\n\\t\"\n");
fprintf(out3,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx);
fprintf(out3,"\t\"lea\t8(%%ebp),%%edx\\n\\t\"\n");
fprintf(out3,"\t\"int\t$0x2E\\n\\t\"\n");
fprintf(out3,"\t\"popl\t%%ebp\\n\\t\"\n");
fprintf(out3,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args);
#else
fprintf(out3,"__declspec(naked) __stdcall\n");
fprintf(out3,"%s(", name2); // make it emit callconv, reval and full signature too
for (i=0; i*4 < nArgBytes; ++i) {
fprintf(out3,"int dummy%d", i);
if (((i+1)*4) < nArgBytes) fprintf(out3,",");
}
fprintf(out3,")\n{\n");
fprintf(out3,"\t__asm {\n");
fprintf(out3,"\t\tpush\tebp\n");
fprintf(out3,"\t\tmov\tebp, esp\n");
fprintf(out3,"\t\tmov\teax,%d\n",sys_call_idx);
fprintf(out3,"\t\tlea\tedx, 8[ebp]\n");
fprintf(out3,"\t\tint\t0x2E\n");
fprintf(out3,"\t\tpop\tebp\n");
fprintf(out3,"\t\tret\t%s\n",nr_args);
fprintf(out3,"\t}\n");
fprintf(out3,"}\n\n");
#endif
}
int makeSystemServiceTable(FILE *in, FILE *out)
{
char line [INPUT_BUFFER_SIZE];
char *s;
char *name;
char *name2;
int sys_call_idx;
char *nr_args;
char *stmp;
/*
* Main SSDT Header
*/
fprintf(out,"// Machine generated, don't edit\n");
fprintf(out,"\n\n");
/*
* First we build the Main SSDT
*/
fprintf(out,"\n\n\n");
fprintf(out,"SSDT MainSSDT[] = {\n");
for ( /* First system call has index zero */
sys_call_idx = 0;
/* Go on until EOF or read zero bytes */
( (!feof(in))
&& (fgets(line, sizeof line, in) != NULL)
);
/* Next system call index */
sys_call_idx++
)
{
if ((s = (char *) strchr(line,'\r')) != NULL)
{
*s = '\0';
}
/*
* Skip comments (#) and empty lines.
*/
s = & line[0];
if ((*s) != '#' && (*s) != '\0')
{
/* Extract the NtXXX name */
name = (char *)strtok(s," \t");
/* Extract the ZwXXX name */
name2 = (char *)strtok(NULL," \t");
//value = strtok(NULL," \t");
/* Extract the stack size */
nr_args = (char *)strtok(NULL," \t");
/*
* Remove, if present, the trailing LF.
*/
if ((stmp = strchr(nr_args, '\n')) != NULL)
{
*stmp = '\0';
}
#ifdef VERBOSE
printf("%3d \"%s\"\n",sys_call_idx,name);
#endif
if (sys_call_idx > 0)
{
fprintf(out,",\n");
}
/*
* Now write the current system call's name
* in the service table.
*/
fprintf(out,"\t\t{ (ULONG)%s }",name);
}
}
/* Close the service table (C syntax) */
fprintf(out,"\n};\n");
/*
* Now we build the Main SSPT
*/
rewind(in);
fprintf(out,"\n\n\n");
fprintf(out,"SSPT MainSSPT[] = {\n");
for ( /* First system call has index zero */
sys_call_idx = 0;
/* Go on until EOF or read zero bytes */
( (!feof(in))
&& (fgets(line, sizeof line, in) != NULL)
);
/* Next system call index */
sys_call_idx++
)
{
if ((s = (char *) strchr(line,'\r')) != NULL)
{
*s = '\0';
}
/*
* Skip comments (#) and empty lines.
*/
s = & line[0];
if ((*s) != '#' && (*s) != '\0')
{
/* Extract the NtXXX name */
name = (char *)strtok(s," \t");
/* Extract the ZwXXX name */
name2 = (char *)strtok(NULL," \t");
//value = strtok(NULL," \t");
/* Extract the stack size */
nr_args = (char *)strtok(NULL," \t");
/*
* Remove, if present, the trailing LF.
*/
if ((stmp = strchr(nr_args, '\n')) != NULL)
{
*stmp = '\0';
}
#ifdef VERBOSE
printf("%3d \"%s\"\n",sys_call_idx,name);
#endif
if (sys_call_idx > 0)
{
fprintf(out,",\n");
}
/*
* Now write the current system call's ID
* in the service table along with its Parameters Size.
*/
fprintf(out,"\t\t{ %s }",nr_args);
}
}
/*
* Close the service table (C syntax)
*/
fprintf(out,"\n};\n");
/*
* We write some useful defines
*/
fprintf(out, "\n\n#define MIN_SYSCALL_NUMBER 0\n");
fprintf(out, "#define MAX_SYSCALL_NUMBER %d\n", sys_call_idx-1);
fprintf(out, "#define NUMBER_OF_SYSCALLS %d\n", sys_call_idx);
return(0);
}
int
process(
FILE * in,
FILE * out,
FILE * out2,
FILE * out3
)
{
char line [INPUT_BUFFER_SIZE];
char * s;
char * name; /* NtXXX name */
char * name2; /* ZwXXX name */
int sys_call_idx; /* NtXXX index number in the service table */
char * nr_args; /* stack_size / machine_word_size */
char * stmp;
/*
* NTDLL stubs file header
*/
fprintf(out,"// Machine generated, don't edit\n");
fprintf(out,"\n\n");
/*
* NTOSKRNL Zw functions stubs header
*/
fprintf(out3,"// Machine generated by genntdll, don't edit\n");
fprintf(out3,"\n\n");
/*
* Scan the database. DB is a text file; each line
* is a record, which contains data for one system
* function. Each record has three columns:
*
* NT_NAME (e.g. NtCreateProcess)
* ZW_NAME (e.g. ZwCreateProcess)
* STACK_SIZE (in machine words: for x[3456]86
* processors a machine word is 4 bytes)
*/
for ( /* First system call has index zero */
sys_call_idx = 0;
/* Go on until EOF or read zero bytes */
( (!feof(in))
&& (fgets(line, sizeof line, in) != NULL)
);
/* Next system call index */
sys_call_idx++
)
{
/*
* Remove, if present, the trailing CR.
* (os specific?)
*/
if ((s = (char *) strchr(line,'\r')) != NULL)
{
*s = '\0';
}
/*
* Skip comments (#) and empty lines.
*/
s = & line[0];
if ((*s) != '#' && (*s) != '\0')
{
/* Extract the NtXXX name */
name = (char *)strtok(s," \t");
/* Extract the ZwXXX name */
name2 = (char *)strtok(NULL," \t");
//value = strtok(NULL," \t");
/* Extract the stack size */
nr_args = (char *)strtok(NULL," \t");
/*
* Remove, if present, the trailing LF.
*/
if ((stmp = strchr(nr_args, '\n')) != NULL)
{
*stmp = '\0';
}
#ifdef VERBOSE
printf("%3d \"%s\"\n",sys_call_idx,name);
#endif
/*
* Write the NTDLL stub for the current
* system call: NtXXX and ZwXXX symbols
* are aliases.
*/
write_syscall_stub(out, out3, name, name2,
nr_args, sys_call_idx);
}
}
return(0);
}
void usage(char * argv0)
{
printf("Usage: %s sysfuncs.lst napi.c napi.h zw.c\n"
" sysfuncs.lst system functions database\n"
" napi.c NTDLL stubs\n"
" napi.h NTOSKRNL service table\n"
" zw.c NTOSKRNL Zw stubs\n",
argv0
);
}
int main(int argc, char* argv[])
{
FILE * in; /* System calls database */
FILE * out1; /* NTDLL stubs */
FILE * out2; /* SERVICE_TABLE */
FILE * out3; /* NTOSKRNL Zw stubs */
int ret;
if (argc != 5)
{
usage(argv[0]);
return(1);
}
in = fopen(argv[1],"rb");
if (in == NULL)
{
perror("Failed to open input file (system calls database)");
return(1);
}
out1 = fopen(argv[2],"wb");
if (out1 == NULL)
{
perror("Failed to open output file (NTDLL stubs)");
return(1);
}
out2 = fopen(argv[3],"wb");
if (out2 == NULL)
{
perror("Failed to open output file (NTOSKRNL service table)");
return(1);
}
out3 = fopen(argv[4],"wb");
if (out3 == NULL)
{
perror("Failed to open output file (NTOSKRNL Zw stubs)");
return(1);
}
ret = process(in,out1,out2,out3);
rewind(in);
ret = makeSystemServiceTable(in, out2);
fclose(in);
fclose(out1);
fclose(out2);
fclose(out3);
return(ret);
}

View file

@ -0,0 +1,22 @@
# $Id: makefile,v 1.1 2004/02/06 08:21:56 fireball Exp $
#
# ReactOS Operating System - MSVC6 Zw functions stubs to call generator
#
SYSTEM_CALLS_DB = ..\..\..\reactos\iface\native\sysfuncs.lst
KERNEL_ZW_CALLS =..\..\ntoskrnl\nt_zw_msvc.c
all: genntdll.exe $(KERNEL_ZW_CALLS)
$(KERNEL_ZW_CALLS) : $(SYSTEM_CALLS_DB)
genntdll.exe $(SYSTEM_CALLS_DB) foo1 foo2 $(KERNEL_ZW_CALLS)
-@del foo1
-@del foo2
genntdll.exe : genntdll.c
clean:
-@del *.exe
-@del *.obj
-@del $(KERNEL_ZW_CALLS)

View file

@ -0,0 +1,4 @@
Debug
Release
nt_zw_msvc.c
ntoskrnl.def

View file

@ -0,0 +1,167 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-25
*
* 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.
*/
/* $Id: ke_i386_bthread.c,v 1.1 2004/02/06 08:21:56 fireball Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/i386/bthread.S
* PURPOSE: Trap handlers
* PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
*/
/* INCLUDES ******************************************************************/
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
/* Values for contextflags */
#define CONTEXT_i386 0x10000
#ifndef CONTEXT_CONTROL
#define CONTEXT_CONTROL (CONTEXT_i386 | 1)
#endif
#ifndef CONTEXT_INTEGER
#define CONTEXT_INTEGER (CONTEXT_i386 | 2)
#endif
#ifndef CONTEXT_SEGMENTS
#define CONTEXT_SEGMENTS (CONTEXT_i386 | 4)
#endif
#ifndef CONTEXT_FLOATING_POINT
#define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 8)
#endif
#ifndef CONTEXT_DEBUG_REGISTERS
#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x10)
#endif
#ifndef CONTEXT_FULL
#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS)
#endif
/* FUNCTIONS *****************************************************************/
void KeReturnFromSystemCallWithHook();
VOID PiBeforeBeginThread(CONTEXT c);
/*
*
*/
__declspec(naked)
VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
{
/*
* This isn't really a function, we are called as the return address
* of the context switch function
*/
/*
* Do the necessary prolog after a context switch
*/
__asm
{
call PiBeforeBeginThread
/*
* Call the actual start of the thread
*/
// We must NOT use the arguments by name. VC then uses EBP-relative
// addressing, and with an EBP of 0 you can imagine what happens.
mov ebx, 4[esp] // StartRoutine
mov eax, 8[esp] // StartContext
push eax
call ebx /* Call the start routine */
add esp, 4
/*
* Terminate the thread
*/
push eax
call PsTerminateSystemThread
add esp, 4
}
/* If that fails then bug check */
KeBugCheck(0);
/* And if that fails then loop */
for (;;)
; // forever
}
__declspec(naked)
VOID PsBeginThreadWithContextInternal(VOID)
{
/*
* This isn't really a function, we are called as the return
* address of a context switch
*/
/*
* Do the necessary prolog before the context switch
*/
__asm
{
call PiBeforeBeginThread
/*
* Load the context flags.
*/
pop ebx
/*
* Load the debugging registers
*/
test ebx, (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)
jz L1
pop eax __asm mov dr0, eax
pop eax __asm mov dr1, eax
pop eax __asm mov dr2, eax
pop eax __asm mov dr3, eax
pop eax __asm mov dr6, eax
pop eax __asm mov dr7, eax
jmp L3
L1:
add esp, 24
L3:
/*
* Load the floating point registers
*/
mov eax, HardwareMathSupport
test eax,eax
jz L2
test ebx, (CONTEXT_FLOATING_POINT & ~CONTEXT_i386)
jz L2
frstor [esp]
L2:
add esp, 112
/* Load the rest of the thread's user mode context. */
mov eax, 0
jmp KeReturnFromSystemCallWithHook
}
}

View file

@ -0,0 +1,114 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
// no arg-list, but asm doesn't care anyway
void KiInterruptDispatch();
#define DEFINE_INT_HANDLER(N) \
__declspec(naked) \
void irq_handler_##N() \
{ \
__asm pushad \
__asm push ds \
__asm push es \
__asm push fs \
__asm mov eax, 0xceafbeef \
__asm push eax \
__asm mov ax, KERNEL_DS \
__asm mov ds, ax \
__asm mov es, ax \
__asm mov ax, PCR_SELECTOR \
__asm mov fs, ax \
__asm push esp \
__asm push N \
__asm call KiInterruptDispatch \
__asm pop eax \
__asm pop eax \
__asm pop eax \
__asm pop fs \
__asm pop es \
__asm pop ds \
__asm popad \
__asm iretd
// NOTE: The inline assembler can't deal with having the final brace,
// ending the function, on the same line as an __asm, why there is
// none here and it MUST be added when using the macro!
DEFINE_INT_HANDLER(0)
}
DEFINE_INT_HANDLER(1)
}
DEFINE_INT_HANDLER(2)
}
DEFINE_INT_HANDLER(3)
}
DEFINE_INT_HANDLER(4)
}
DEFINE_INT_HANDLER(5)
}
DEFINE_INT_HANDLER(6)
}
DEFINE_INT_HANDLER(7)
}
DEFINE_INT_HANDLER(8)
}
DEFINE_INT_HANDLER(9)
}
DEFINE_INT_HANDLER(10)
}
DEFINE_INT_HANDLER(11)
}
DEFINE_INT_HANDLER(12)
}
DEFINE_INT_HANDLER(13)
}
DEFINE_INT_HANDLER(14)
}
DEFINE_INT_HANDLER(15)
}

View file

@ -0,0 +1,655 @@
/*
* ReactOS kernel
* Copyright (C) 2003 Mike Nordell
* Based on multiboot.S (no copyright note present), but so heavily
* modified that it bears close to no resemblance to the original work.
*
* MSVC compatible combination of plain C and inline assembler to:
* 1 Relocated all the sections in the kernel - something I feel the
* bootloader should have done, but multiboot being just a "raw image"
* loader, it unfortunately had to be done here - in-place.
* 2 Set up page directories and stuff.
* 3 Load IDT, GDT and turn on paging, making us execute at the intended
* target address (as if the image was PE-loaded and parsed into that addr.)
* 4 Call _main, and let the rest of the startup run...
*
* 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.
*/
//
// TODO: Fix the MP parts
//
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <pe.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
#include <internal/ps.h>
#include <internal/ldr.h>
// some notes:
// The MSVC linker (by defult) emits no special .bss section, but uses the data
// section with a rawsize smaller than virtualsize. The "slack" is BSS.
//////////////////////////////////////////////////////////////////
// Some macros we need
// some stuff straight from freeloaders multiboot.h
#define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
#define MULTIBOOT_HEADER_FLAGS (0x00010003)
#define TARGET_LOAD_ADDR 0x00200000
#define BASE_TO_PHYS_DIST (KERNEL_BASE - TARGET_LOAD_ADDR)
#define V2P(x) (x - BASE_TO_PHYS_DIST)
#ifdef MP
#define AP_MAGIC (0x12481020)
#endif /* MP */
void initialize_page_directory(void);
void* relocate_pointer_log_to_phys(const void* p)
{
// DON'T CALL this function until relocation of .data and/or .rdata,
// is completed - but still be sure that we have not yet enabled paging!
return (void*)((DWORD)p - BASE_TO_PHYS_DIST);
}
#ifdef _DEBUG
// Macro to emit one character to Bochs debug-port (0x9e).
// We need to do it this way, since at this point of the startup, obviously
// we have neither HAL nor DbgPrint support.
#define BOCHS_OUT_CHAR(c1) __asm push eax __asm push edx __asm mov dx, 0xe9 __asm mov al, c1 __asm out dx, al __asm pop edx __asm pop eax
void boch_out_hex_digit(unsigned char ch1)
{
if (ch1 <= 9) { ch1 += '0'; } else { ch1 += 'a' - 10; }
BOCHS_OUT_CHAR(ch1)
}
void bochs_dump_hex(DWORD p)
{
unsigned char ch3 = (unsigned char)((p >> 28) & 0x0f);
unsigned char cl3 = (unsigned char)((p >> 24) & 0x0f);
unsigned char ch2 = (unsigned char)((p >> 20) & 0x0f);
unsigned char cl2 = (unsigned char)((p >> 16) & 0x0f);
unsigned char ch1 = (unsigned char)((p >> 12) & 0x0f);
unsigned char cl1 = (unsigned char)((p >> 8) & 0x0f);
unsigned char ch0 = (unsigned char)((p >> 4) & 0x0f);
unsigned char cl0 = (unsigned char)((p >> 0) & 0x0f);
BOCHS_OUT_CHAR('0') BOCHS_OUT_CHAR('x')
boch_out_hex_digit(ch3);
boch_out_hex_digit(cl3);
boch_out_hex_digit(ch2);
boch_out_hex_digit(cl2);
boch_out_hex_digit(ch1);
boch_out_hex_digit(cl1);
boch_out_hex_digit(ch0);
boch_out_hex_digit(cl0);
BOCHS_OUT_CHAR('\n')
}
static void bochs_out_string(const char* s /* logical address! */)
{
s = relocate_pointer_log_to_phys(s);
__asm
{
pushad
mov dx, 0xe9
mov ebx, s
L1:
cmp byte ptr[ebx], 0
je end
mov al, [ebx]
out dx, al
inc ebx
jmp L1
end:
popad
}
}
#else
#define BOCHS_OUT_CHAR(c1)
#define bochs_dump_hex(VAL)
#define bochs_out_string(STR)
#endif // _DEBUG
//////////////////////////////////////////////////////////////////
typedef char kernel_page_t[4096];
// Use 4096 (pagesize) more bytes that actually needed for each *_holder,
// to be able to make sure that the other stuff is page aligned.
// No other way to do this portably... :-(
//
// TODO: Consider allocating just one large block of BSS memory here, align
// just the first pointer, and then get the other ones just as offsets from
// this (now-aligned) pointer. That way we could get away with wasting just
// one page of memory, instead of 4 (like 16KB would matter... but still)
static kernel_page_t* startup_pagedirectory_holder[1024 * 2];
static kernel_page_t* lowmem_pagetable_holder[1024 * 2];
static kernel_page_t* kernel_pagetable_holder[32*1024 + 1];
static __int32 kpcr_pagetable_holder[4096/4 * 2];
#ifdef MP
char apic_pagetable[4096];
#endif /* MP */
__int32 unmap_me[4096/4];
__int32 unmap_me2[4096/4];
__int32 unmap_me3[4096/4];
__int32 init_stack[3*4096/4];
int init_stack_top;
__int32 trap_stack[3*4096/4];
int trap_stack_top;
void _main();
// lie a bit about types - since C is basically typeless anyway, it
// doesn't really matter what type we say it is here...
extern int KiGdtDescriptor;
extern int KiIdtDescriptor;
/*
* This is called by the realmode loader, with protected mode
* enabled, paging disabled and the segment registers pointing
* a 4Gb, 32-bit segment starting at zero.
*
* EAX = Multiboot magic or application processor magic
*
* EBX = Points to a structure in lowmem with data from the
* loader
*/
#pragma intrinsic(memset)
// We need to implement this ourself, to be able to get to it by short call's
void our_memmove(void* pDest, const void* pSrc, DWORD size)
{
char* pD = (char*)pDest;
const char* pS = (char*)pSrc;
if (pDest < pSrc)
{
while (size--)
{
*pD++ = *pS++;
}
}
else if (pSrc < pDest)
{
while (size--)
{
pD[size] = pS[size];
}
}
}
void dummy_placeholder(void)
{
// NOTE: This function MUST be placed JUST AFTER MultibootStub in memory.
// Yes, it's BEFORE it in this file, but linkorder.txt fixes this for us.
}
// This one is needed, since the boot loader hasn't relocated us
__declspec(naked)
void MultibootStub()
{
__asm
{
jmp _multiboot_entry
// This sucks, I know...
#define EMIT_DWORD(x) __asm __emit ((x) >> 0) & 0xff __asm _emit ((x) >> 8) & 0xff __asm _emit ((x) >> 16) & 0xff __asm _emit ((x) >> 24) & 0xff
ALIGN 4
EMIT_DWORD(MULTIBOOT_HEADER_MAGIC)
EMIT_DWORD(MULTIBOOT_HEADER_FLAGS)
EMIT_DWORD(-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS))
EMIT_DWORD(TARGET_LOAD_ADDR + 0x0400 + 0x04)
// Now just make something up, since there is no way we can know, beforehand,
// where any BSS data is...
EMIT_DWORD((TARGET_LOAD_ADDR))
EMIT_DWORD((TARGET_LOAD_ADDR + 1*1024*1024)) /* assume ntoskrnel.exe is < 1MB! */
EMIT_DWORD((TARGET_LOAD_ADDR + 2*1024*1024)) /* just to have something, let's say BSS is 1MB too */
/* This is *REALLY* ugly! If MultibootStub is *EVER* at */
/* any other offset, this will crash like crazy! */
/* 0x0400 is the file alignment of the binary (ntoskrnl.exe) */
EMIT_DWORD((TARGET_LOAD_ADDR + 0x0400)) // entry_addr
_multiboot_entry:
cld // just for good measure
}
{
/* Save the multiboot or application processor magic */
DWORD saved_eax;
DWORD saved_ebx;
__asm mov saved_eax, eax
__asm mov saved_ebx, ebx
// bochs_out_string("MultibootStub()\n");
// OK, time to relocate the brute-loaded image in-place...
// If we don't watch it, we will overwrite ourselves here - imagine
// the fireworks! :-) That's why the function dummy_placeholder()
// MUST be placed JUST JUST AFTER this function.
{
PIMAGE_NT_HEADERS NtHeader = RtlImageNtHeader((PVOID)TARGET_LOAD_ADDR);
PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(NtHeader);
const int count = NtHeader->FileHeader.NumberOfSections;
int i;
Section += count - 1; // make it point to the last section
// NOTE: We MUST walk the sections "backwards".
for (i = count-1; i >= 0; --i, --Section)
{
DWORD dwSrc = TARGET_LOAD_ADDR + Section->PointerToRawData;
DWORD dwDst = TARGET_LOAD_ADDR + Section->VirtualAddress;
DWORD dwSiz = Section->SizeOfRawData;
const char* pEndThisFunc;
if (dwSrc == dwDst)
{
continue;
}
//bochs_out_string("MultibootStub: relocating section\n");
if (Section->Characteristics & IMAGE_SCN_MEM_EXECUTE)
{
// can't get a pointer to a label from plain C :-(
__asm mov pEndThisFunc, offset dummy_placeholder
pEndThisFunc -= BASE_TO_PHYS_DIST;
if (dwDst < (DWORD)pEndThisFunc)
{
// We must not move the code from under our feet!
// This can only happen in the code segment - the first segment
DWORD diff = (DWORD)pEndThisFunc - dwDst;
dwDst += diff;
dwSrc += diff;
dwSiz -= diff;
}
}
// obviously we must use memmove, since memory can overlap
our_memmove((void*)dwDst, (void*)dwSrc, dwSiz);
// While at it, we might as well zero any uninitialized data in the section...
if (Section->SizeOfRawData < Section->Misc.VirtualSize)
{
memset((char*)(Section->VirtualAddress + Section->SizeOfRawData + TARGET_LOAD_ADDR),
0,
Section->Misc.VirtualSize - Section->SizeOfRawData);
}
}
// Now all sections are relocated to their intended in-memory layout,
// but we are still running int the low TARGET_LOAD_ADDR memory.
{
// Time to jump to the real startup, the entry-point function.
// We must do this using assembler, since both eax and ebx are assumed
// to hold some magic values.
typedef VOID (STDCALL* pfn_t)(PPEB);
pfn_t pfn = (pfn_t)(NtHeader->OptionalHeader.AddressOfEntryPoint + TARGET_LOAD_ADDR);
#if 1
__asm mov eax, saved_eax
__asm mov ebx, saved_ebx
__asm mov ecx, pfn
__asm jmp ecx
#else
__asm mov ebx, saved_ebx
(*pfn)((PPEB)saved_eax);
#endif
}
}
}
}
// TMN: TODO: Convert this to the extent possible to plain C code
// Due to the "magic" above, we enter this function with all kernel sections
// properly relocated wrt. offsets from start-of-mem. But, we are still running
// without paging, meaning that the address that is to be KERNEL_BASE+xyz is
// currently still TARGET_LOAD_ADDR+xyz.
// We get aways with a few of the functions call here since they are near calls
// (PC-relative), but don't even _think_ about calling any other functions
// until we have turned on paging!
VOID STDCALL
NtProcessStartup(
IN PPEB Peb
)
{
DWORD saved_ebx;
DWORD saved_eax;
__asm mov saved_ebx, ebx
__asm mov saved_eax, eax
bochs_out_string("NtProcessStartup: Just entered\n");
#ifdef MP
if (saved_eax != AP_MAGIC)
{
#endif /* MP */
bochs_out_string("NtProcessStartup: Calling initialize_page_directory()\n");
initialize_page_directory(); // Initialize the page directory
bochs_out_string("NtProcessStartup: Page directory initialized\n");
#ifdef MP
__asm
{
/*
* Initialize the page table that maps the APIC register address space
*/
/*
* FIXME: APIC register address space can be non-standard so do the
* mapping later
*/
mov esi, V2P(apic_pagetable)
mov edi, 0
mov eax, 0xFEC0001B
mov [esi+edi], eax
mov edi, 0x800
mov eax, 0xFEE0001B
mov [esi+edi], eax
}
}
#endif /* MP */
{
bochs_out_string("NtProcessStartup: Enabling paging...\n");
/*
* Enable paging and set write protect
* bit 31: PG, bit 16: WP
*/
__asm mov eax, cr0
__asm or eax, 0x80010000
__asm mov cr0, eax
bochs_out_string("NtProcessStartup: Paging enabled!\n");
bochs_out_string("NtProcessStartup: But we're still at the \"low\" address\n");
/*
* Do an absolute jump because we now want to execute above KERNEL_BASE
*/
__asm mov eax, offset l2_
__asm jmp eax
}
l2_:
bochs_out_string("We have now left \"low\" memory, and is flying at an altitude of...\n");
bochs_out_string("OK, we're not flying, we're just executing above KERNEL_BASE\n");
/*
* Load the GDTR and IDTR with new tables located above
* KERNEL_BASE
*/
#ifdef _DEBUG
{
DWORD val = (DWORD)&KiGdtDescriptor;
bochs_out_string("&KiGdtDescriptor: ");
bochs_dump_hex(val);
val = (DWORD)&KiIdtDescriptor;
bochs_out_string("&KiIdtDescriptor: ");
bochs_dump_hex(val);
}
#endif
bochs_out_string("Loading GDT and IDT...\n");
/* FIXME: Application processors should have their own GDT/IDT */
__asm lgdt KiGdtDescriptor
__asm lidt KiIdtDescriptor
bochs_out_string("GDT and IDT loaded\n");
__asm
{
/*
* Reload the data segment registers
*/
mov eax, KERNEL_DS
mov ds, ax
mov es, ax
mov gs, ax
mov ss, ax
mov eax, 0
mov fs, ax
}
bochs_out_string("NtProcessStartup: segment registers loaded\n");
#ifdef MP
if (saved_eax == AP_MAGIC)
{
__asm
{
/*
* This is an application processor executing
*/
/*
* Initialize EFLAGS
*/
push 0
popfd
/*
* Call the application processor initialization code
*/
push 0
push offset l7_
push KERNEL_CS
push KiSystemStartup
retf
/*
* Catch illegal returns from KiSystemStartup
*/
l7_:
pop eax
}
KeBugCheck(0);
for (;;)
; /*forever */
}
#endif /* MP */
bochs_out_string("Loading fs with PCR_SELECTOR\n");
/* Load the PCR selector */
__asm mov eax, PCR_SELECTOR
__asm mov fs, ax
bochs_out_string("Loading esp with init_stack_top : "); bochs_dump_hex((DWORD)&init_stack_top);
bochs_out_string("Just for interest, init_stack is at: "); bochs_dump_hex((DWORD)init_stack);
bochs_out_string("Meaing the init_stack in bytes is : "); bochs_dump_hex((DWORD)&init_stack_top - (DWORD)init_stack);
/* Load the initial kernel stack */
__asm mov esp, offset init_stack_top
bochs_out_string("Loaded esp with init_stack_top\n");
/*
* Initialize EFLAGS
*/
__asm push 0
__asm popfd
bochs_out_string("Loaded eflags\n");
/*
* Call the main kernel initialization
*/
bochs_out_string("TMN: Calling _main...\n");
__asm
{
xor ebp,ebp
push ebx
push edx
push offset l5_
push KERNEL_CS
push offset _main
retf
/*
* Catch illegal returns from main, try bug checking the system,
* if that fails then loop forever.
*/
l5_:
pop eax
pop eax
} // end of __asm block
bochs_out_string("TMN: Back from _main ?! Let's crash!\n");
KeBugCheck(0);
for (;;)
; /*forever */
}
void initialize_page_directory(void)
{
/*
* Initialize the page directory
*/
// First convert the pointers from the virtual address the compiler generated
// code thinks we are at, to the currently active physical address we actually
// got loaded into by the loader. At this point we have been relocated, so
// that there is a 1:1 mapping between KERNEL_BASE+n and TARGET_LOAD_ADDR+n.
kernel_page_t** startup_pagedirectory = startup_pagedirectory_holder;
kernel_page_t** lowmem_pagetable = lowmem_pagetable_holder;
kernel_page_t** kernel_pagetable = kernel_pagetable_holder;
__int32* kpcr_pagetable = kpcr_pagetable_holder;
bochs_out_string("startup_pagedirectory before reloc: ");
bochs_dump_hex((DWORD)startup_pagedirectory);
startup_pagedirectory = (kernel_page_t**)relocate_pointer_log_to_phys(startup_pagedirectory);
lowmem_pagetable = (kernel_page_t**)relocate_pointer_log_to_phys(lowmem_pagetable);
kernel_pagetable = (kernel_page_t**)relocate_pointer_log_to_phys(kernel_pagetable);
kpcr_pagetable = (__int32*) relocate_pointer_log_to_phys(kpcr_pagetable);
bochs_out_string("startup_pagedirectory after reloc : ");
bochs_dump_hex((DWORD)startup_pagedirectory);
// Now align the pointers to PAGE_SIZE...
startup_pagedirectory = (kernel_page_t**)(((ULONG_PTR)startup_pagedirectory + 4095) & ~4095);
lowmem_pagetable = (kernel_page_t**)(((ULONG_PTR)lowmem_pagetable + 4095) & ~4095);
kernel_pagetable = (kernel_page_t**)(((ULONG_PTR)kernel_pagetable + 4095) & ~4095);
kpcr_pagetable = (__int32* ) (((ULONG_PTR)kpcr_pagetable + 4095) & ~4095);
#ifdef _DEBUG
bochs_out_string("startup_pagedirectory aligned : ");
bochs_dump_hex((DWORD)startup_pagedirectory);
#endif
// Ugly macros, I know...
#define DEST(PAGE) startup_pagedirectory[(PAGE) + 0xc00 / 4]
#define SRC(PAGE) (kernel_page_t*)((char*)kernel_pagetable + (PAGE)*4096 + 0x7)
startup_pagedirectory[0] = (kernel_page_t*)((char*)lowmem_pagetable + 0x7);
{
unsigned int i;
for (i=0; i<32; ++i)
{
DEST(i) = SRC(i);
}
}
DEST( 64) = (kernel_page_t*)((char*)lowmem_pagetable + 0x7);
DEST(192) = (kernel_page_t*)((char*)startup_pagedirectory + 0x7);
#ifdef MP
DEST(251) = (kernel_page_t*)((char*)apic_pagetable + 0x7);
#endif /* MP */
DEST(252) = (kernel_page_t*)((char*)kpcr_pagetable + 0x7);
{
unsigned int i;
/* Initialize the page table that maps low memory */
for (i=0; i<1024; ++i) {
lowmem_pagetable[i] = (kernel_page_t*)(i*4096 + 7);
}
/* Initialize the page table that maps kernel memory */
for (i=0; i<6144/4 /* 1536 pages = 6MB */; ++i) {
kernel_pagetable[i] = (kernel_page_t*)(i*4096 + TARGET_LOAD_ADDR + 0x7);
}
/* Initialize the page table that maps the initial KPCR (at FF000000) */
kpcr_pagetable[0] = 0x1007;
}
/*
* Set up the PDBR
*/
__asm mov eax, startup_pagedirectory
__asm mov cr3, eax
}

View file

@ -0,0 +1,110 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
//#include <ntos/service.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
void KeReturnFromSystemCall();
/*
* FUNCTION: KeStackSwitchAndRet
* PURPOSE: Switch to a new stack and return from the first frame on
* the new stack which was assumed to a stdcall function with
* 8 bytes of arguments and which saved edi, esi and ebx.
*/
__declspec(naked)
VOID STDCALL
KeStackSwitchAndRet(PVOID NewStack)
{
__asm
{
push ebp
mov ebp, esp
cli
mov esp, NewStack
sti
pop edi
pop esi
pop ebx
pop ebp
ret 8
}
}
__declspec(naked)
VOID STDCALL
KePushAndStackSwitchAndSysRet(ULONG Push, PVOID NewStack)
{
__asm
{
push ebp
mov ebp, esp
push ebx
push esi
push edi
cli
push 8[ebp]
mov ebx, fs:KPCR_CURRENT_THREAD
mov KTHREAD_CALLBACK_STACK[ebx], esp
mov esp, 12[ebp]
sti
push 0
call KeLowerIrql
jmp KeReturnFromSystemCall
}
}

View file

@ -0,0 +1,325 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Converted to MSVC-compatible inline assembler by Mike Nordell, 2003.
*
* 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.
*/
/*
* FILE: MSVC6/ntoskrnl/ke_i386_syscall.c
* based on ntoskrnl/ke/i386/syscall.s
* PURPOSE: syscall dispatching and support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
//#include <ntos/service.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
#define KernelMode (0)
#define UserMode (1)
// TMN: Replicated here to reduce mess-time
#ifdef STATUS_INVALID_SYSTEM_SERVICE
#undef STATUS_INVALID_SYSTEM_SERVICE
#endif
#define STATUS_INVALID_SYSTEM_SERVICE 0xc000001c
/*
*
*/
void KiServiceCheck (ULONG Nr);
ULONG KiAfterSystemCallHook(ULONG NtStatus, PKTRAP_FRAME TrapFrame);
VOID KiSystemCallHook(ULONG Nr, ...);
void KeReturnFromSystemCallWithHook();
void KeReturnFromSystemCall();
__declspec(naked)
void interrupt_handler2e(void)
{
__asm
{
/* Construct a trap frame on the stack */
/* Error code */
push 0
push ebp
push ebx
push esi
push edi
push fs
/* Load PCR selector into fs */
mov ebx, PCR_SELECTOR
mov fs, bx
/* Save the old exception list */
mov ebx, fs:KPCR_EXCEPTION_LIST
push ebx
/* Set the exception handler chain terminator */
mov dword ptr fs:KPCR_EXCEPTION_LIST, 0xffffffff
/* Get a pointer to the current thread */
mov esi, fs:KPCR_CURRENT_THREAD
/* Save the old previous mode */
xor ebx,ebx
mov bl, ss:KTHREAD_PREVIOUS_MODE[esi]
push ebx
/* Set the new previous mode based on the saved CS selector */
mov ebx, 0x24[esp]
and ebx, 0x0000FFFF
cmp ebx, KERNEL_CS
#if 0
// TODO: Verify implementation change and use this code path
// to remove two conditional jumps.
setnz bl
mov ss:KTHREAD_PREVIOUS_MODE[esi], bl
#else
jne L1
mov ss:KTHREAD_PREVIOUS_MODE[esi], KernelMode
jmp L3
L1:
mov ss:KTHREAD_PREVIOUS_MODE[esi], UserMode
L3:
#endif
/* Save other registers */
push eax
push ecx
push edx
push ds
push es
push gs
push 0 /* DR7 */
push 0 /* DR6 */
push 0 /* DR3 */
push 0 /* DR2 */
push 0 /* DR1 */
push 0 /* DR0 */
push 0 /* XXX: TempESP */
push 0 /* XXX: TempCS */
push 0 /* XXX: DebugPointer */
push 0 /* XXX: DebugArgMark */
mov ebx, 0x60[esp]
push ebx /* DebugEIP */
push ebp /* DebugEBP */
/* Load the segment registers */
mov bx, KERNEL_DS
mov ds, bx
mov es, bx
mov gs, bx
/*
* Save the old trap frame pointer over where we would save the EDX
* register.
*/
mov ebx, KTHREAD_TRAP_FRAME[esi]
mov 0x3C[esp], ebx
/* Save a pointer to the trap frame in the TCB */
mov KTHREAD_TRAP_FRAME[esi], esp
/* Set ES to kernel segment */
mov bx, KERNEL_DS
mov es, bx
/* Allocate new Kernel stack frame */
mov ebp, esp
/* Users's current stack frame pointer is source */
mov esi, edx
/* Determine system service table to use */
cmp eax, 0x0fff
ja new_useShadowTable
/* Check to see if EAX is valid/inrange */
cmp eax, es:KeServiceDescriptorTable + 8
jbe new_serviceInRange
mov eax, STATUS_INVALID_SYSTEM_SERVICE
jmp KeReturnFromSystemCall
new_serviceInRange:
/* Allocate room for argument list from kernel stack */
mov ecx, es:KeServiceDescriptorTable + 12
mov ecx, es:[ecx + eax * 4]
sub esp, ecx
/* Copy the arguments from the user stack to the kernel stack */
mov edi, esp
cld
repe movsb
/* DS is now also kernel segment */
mov ds, bx
/* Call system call hook */
push eax
call KiSystemCallHook
pop eax
/* Make the system service call */
mov ecx, es:KeServiceDescriptorTable
mov eax, es:[ecx + eax * 4]
call eax
#if CHECKED
/* Bump Service Counter */
#endif
/* Deallocate the kernel stack frame */
mov esp, ebp
/* Call the post system call hook and deliver any pending APCs */
push ebp
push eax
call KiAfterSystemCallHook
add esp, 8
jmp KeReturnFromSystemCall
new_useShadowTable:
sub eax, 0x1000
/* Check to see if EAX is valid/inrange */
cmp eax, es:KeServiceDescriptorTableShadow + 24
jbe new_shadowServiceInRange
mov eax, STATUS_INVALID_SYSTEM_SERVICE
jmp KeReturnFromSystemCall
new_shadowServiceInRange:
/* Allocate room for argument list from kernel stack */
mov ecx, es:KeServiceDescriptorTableShadow + 28
mov ecx, es:[ecx + eax * 4]
sub esp, ecx
/* Copy the arguments from the user stack to the kernel stack */
mov edi, esp
cld
repe movsb
/* DS is now also kernel segment */
mov ds, bx
/* Call system call hook */
// pushl %eax
// call _KiSystemCallHook
// popl %eax
/* Call service check routine */
push eax
call KiServiceCheck
pop eax
/* Make the system service call */
mov ecx, es:KeServiceDescriptorTableShadow + 16
mov eax, es:[ecx + eax * 4]
call eax
#if CHECKED
/* Bump Service Counter */
#endif
/* Deallocate the kernel stack frame */
mov esp, ebp
// TMN: Added, to be able to separate this into different functions
jmp KeReturnFromSystemCallWithHook
}
}
__declspec(naked)
void KeReturnFromSystemCallWithHook()
{
__asm
{
/* Call the post system call hook and deliver any pending APCs */
push esp
push eax
call KiAfterSystemCallHook
add esp, 8
// TMN: Added, to be able to separate this into different functions
jmp KeReturnFromSystemCall
}
}
__declspec(naked)
void KeReturnFromSystemCall()
{
__asm
{
/* Restore the user context */
/* Get a pointer to the current thread */
mov esi, fs:0x124
/* Restore the old trap frame pointer */
mov ebx, 0x3c[esp]
mov KTHREAD_TRAP_FRAME[esi], ebx
/* Skip debug information and unsaved registers */
add esp, 0x30
pop gs
pop es
pop ds
pop edx
pop ecx
add esp, 4 /* Don't restore eax */
/* Restore the old previous mode */
pop ebx
mov ss:KTHREAD_PREVIOUS_MODE[esi], bl
/* Restore the old exception handler list */
pop ebx
mov fs:KPCR_EXCEPTION_LIST, ebx
pop fs
pop edi
pop esi
pop ebx
pop ebp
add esp, 4 /* Ignore error code */
iretd
}
}

View file

@ -0,0 +1,468 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
void KiV86Complete(void);
void KiTrapHandler(void);
void KiDoubleFaultHandler(void);
extern int KiPcrInitDone;
/*
* Epilog for exception handlers
*/
__declspec(naked)
void KiTrapEpilog()
{
__asm
{
cmp eax, 1 /* Check for v86 recovery */
jne _KiTrapRet
jmp KiV86Complete
_KiTrapRet:
/* Skip debug information and unsaved registers */
add esp, 0x30
pop gs
pop es
pop ds
pop edx
pop ecx
pop eax
/* Restore the old previous mode */
pop ebx
mov ss:KTHREAD_PREVIOUS_MODE[esi], bl
/* Restore the old exception handler list */
pop ebx
mov fs:KPCR_EXCEPTION_LIST, ebx
pop fs
pop edi
pop esi
pop ebx
pop ebp
add esp, 4 /* Ignore error code */
iretd
}
}
__declspec(naked)
void KiTrapProlog()
{
__asm
{
push edi
push fs
/*
* Check that the PCR exists, very early in the boot process it may
* not
*/
cmp ss:KiPcrInitDone, 0
je L5_
/* Load the PCR selector into fs */
mov ebx, PCR_SELECTOR
mov fs, bx
/* Save the old exception list */
mov ebx, fs:KPCR_EXCEPTION_LIST
push ebx
/* Put the exception handler chain terminator */
mov dword ptr fs:KPCR_EXCEPTION_LIST, 0xffffffff
/* Get a pointer to the current thread */
mov edi, fs:KPCR_CURRENT_THREAD
/* The current thread may be NULL early in the boot process */
cmp edi, 0
je L4_
/* Save the old previous mode */
xor ebx, ebx
mov bl, ss:KTHREAD_PREVIOUS_MODE[edi]
push ebx
/* Set the new previous mode based on the saved CS selector */
mov ebx, 0x24[esp]
and ebx, 0x0000FFFF
cmp ebx, KERNEL_CS
jne L1_
mov ss:KTHREAD_PREVIOUS_MODE[edi], KernelMode
jmp L3_
L1_:
mov ss:KTHREAD_PREVIOUS_MODE[edi], UserMode
L3_:
/* Save other registers */
push eax
push ecx
push edx
push ds
push es
push gs
push 0 /* DR7 */
push 0 /* DR6 */
push 0 /* DR3 */
push 0 /* DR2 */
push 0 /* DR1 */
push 0 /* DR0 */
push 0 /* XXX: TempESP */
push 0 /* XXX: TempCS */
push 0 /* XXX: DebugPointer */
push 0 /* XXX: DebugArgMark */
mov ebx, 0x60[esp]
push ebx /* XXX: DebugEIP */
push ebp /* XXX: DebugEBP */
/* Load the segment registers */
mov ebx, KERNEL_DS
mov ds, bx
mov es, bx
mov gs, bx
/* Set ES to kernel segment */
mov bx, KERNEL_DS
mov es, bx
mov ebx, esp
mov ebp, esp
/* Save the old trap frame. */
cmp edi, 0
je L7_
mov edx, ss:KTHREAD_TRAP_FRAME[edi]
push edx
jmp L8_
L7_:
push 0
L8_:
/* Save a pointer to the trap frame in the current KTHREAD */
cmp edi, 0
je L6_
mov ss:KTHREAD_TRAP_FRAME[edi], ebx
L6_:
/* Call the C exception handler */
push esi
push ebx
call KiTrapHandler
add esp, 8
/* Get a pointer to the current thread */
mov esi, fs:KPCR_CURRENT_THREAD
/* Restore the old trap frame pointer */
pop ebx
mov KTHREAD_TRAP_FRAME[esi], ebx
/* Return to the caller */
jmp KiTrapEpilog
/* Handle the no-pcr case out of line */
L5_:
push 0
/* Handle the no-thread case out of line */
L4_:
push 0
jmp L3_
} // end of __asm block
}
__declspec(naked)
void KiTrap0()
{
__asm
{
/* No error code */
push 0
push ebp
push ebx
push esi
mov esi, 0
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap1()
{
__asm
{
/* No error code */
push 0
push ebp
push ebx
push esi
mov esi, 1
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap2()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 2
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap3()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 3
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap4()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 4
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap5()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 5
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap6()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 6
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap7()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 7
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap8()
{
__asm
{
call KiDoubleFaultHandler
iretd
}
}
__declspec(naked)
void KiTrap9()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 9
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap10()
{
__asm
{
push ebp
push ebx
push esi
mov esi, 10
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap11()
{
__asm
{
push ebp
push ebx
push esi
mov esi, 11
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap12()
{
__asm
{
push ebp
push ebx
push esi
mov esi, 12
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap13()
{
__asm
{
push ebp
push ebx
push esi
mov esi, 13
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap14()
{
__asm
{
push ebp
push ebx
push esi
mov esi, 14
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap15()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 15
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrap16()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 16
jmp KiTrapProlog
}
}
__declspec(naked)
void KiTrapUnknown()
{
__asm
{
push 0
push ebp
push ebx
push esi
mov esi, 255
jmp KiTrapProlog
}
}
/* EOF */

View file

@ -0,0 +1,217 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
//#include <ntos/service.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
extern KSPIN_LOCK PiThreadListLock;
extern ULONG PiNrThreadsAwaitingReaping;
extern ULONG MmGlobalKernelPageDirectory[1024];
VOID STDCALL PiWakeupReaperThread(VOID);
VOID KeSetBaseGdtSelector(ULONG Entry, PVOID Base);
/*
* FUNCTIONS: Switches to another thread's context
* ARGUMENTS:
* Thread = Thread to switch to
* OldThread = Thread to switch from
*/
__declspec(naked)
VOID
Ki386ContextSwitch(struct _KTHREAD* NewThread, struct _KTHREAD* OldThread)
{
__asm
{
push ebp
mov ebp, esp
/* Save callee save registers. */
push ebx
push esi
push edi
cli /* This is a critical section for this processor. */
/* Get the pointer to the new thread. */
mov ebx, NewThread
/*
* Set the base of the TEB selector to the base of the TEB for
* this thread.
*/
push ebx
push KTHREAD_TEB[ebx]
push TEB_SELECTOR
call KeSetBaseGdtSelector
add esp, 8
pop ebx
/*
* Load the PCR selector.
*/
mov eax, PCR_SELECTOR
mov fs, ax
/*
* Set the current thread information in the PCR.
*/
mov fs:KPCR_CURRENT_THREAD, ebx
/*
* Set the current LDT
*/
xor eax, eax
mov edi, ETHREAD_THREADS_PROCESS[ebx]
test word ptr KPROCESS_LDT_DESCRIPTOR0[edi], 0xFFFF
jz L4
push KPROCESS_LDT_DESCRIPTOR1[edi]
push KPROCESS_LDT_DESCRIPTOR0[edi]
push LDT_SELECTOR
call KeSetGdtSelector
add esp, 12
mov eax, LDT_SELECTOR
L4:
lldt ax
/*
* Load up the iomap offset for this thread in
* preparation for setting it below.
*/
mov eax, KPROCESS_IOPM_OFFSET[edi]
/*
* FIXME: Save debugging state.
*/
/*
* FIXME: Save floating point state.
*/
/*
* Switch stacks
*/
mov ebx, 12[ebp]
mov KTHREAD_KERNEL_STACK[ebx], esp
mov ebx, 8[ebp]
mov esp, KTHREAD_KERNEL_STACK[ebx]
mov edi, KTHREAD_STACK_LIMIT[ebx]
/*
* Set the stack pointer in this processors TSS
*/
mov esi, fs:KPCR_TSS
/*
* Set current IOPM offset in the TSS
*/
mov KTSS_IOMAPBASE[esi], ax
mov eax, KTHREAD_INITIAL_STACK[ebx]
mov KTSS_ESP0[esi], eax
/*
* Change the address space
*/
mov ebx, ETHREAD_THREADS_PROCESS[ebx]
mov eax, KPROCESS_DIRECTORY_TABLE_BASE[ebx]
mov cr3, eax
/*
* Set up the PDE for the top of the new stack.
*/
mov ebx, 0
L2:
mov esi, edi
shr esi, 22
mov eax, 0xF03C0000[esi*4]
cmp eax, 0
jne L1
mov eax, MmGlobalKernelPageDirectory[esi*4]
mov 0xF03C0000[esi*4], eax
L1:
add edi, 4096
inc ebx
cmp ebx, (MM_STACK_SIZE / 4096)
jl L2
/*
* FIXME: Restore floating point state
*/
/*
* FIXME: Restore debugging state
*/
/*
* Exit the critical section
*/
sti
}
KeReleaseSpinLockFromDpcLevel(&PiThreadListLock);
if (PiNrThreadsAwaitingReaping) {
PiWakeupReaperThread();
}
__asm
{
/*
* Restore the saved register and exit
*/
pop edi
pop esi
pop ebx
pop ebp
ret
}
}

View file

@ -0,0 +1,256 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-25
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
#include <internal/ps.h>
// Taken from ntoskrnl/include/internal/v86m.h, since that one must be fixed
// a bit before it could be used from here.
#define KV86M_REGISTERS_EBP (0x0)
#define KV86M_REGISTERS_EDI (0x4)
#define KV86M_REGISTERS_ESI (0x8)
#define KV86M_REGISTERS_EDX (0xC)
#define KV86M_REGISTERS_ECX (0x10)
#define KV86M_REGISTERS_EBX (0x14)
#define KV86M_REGISTERS_EAX (0x18)
#define KV86M_REGISTERS_DS (0x1C)
#define KV86M_REGISTERS_ES (0x20)
#define KV86M_REGISTERS_FS (0x24)
#define KV86M_REGISTERS_GS (0x28)
#define KV86M_REGISTERS_EIP (0x2C)
#define KV86M_REGISTERS_CS (0x30)
#define KV86M_REGISTERS_EFLAGS (0x34)
#define KV86M_REGISTERS_ESP (0x38)
#define KV86M_REGISTERS_SS (0x3C)
void KiV86Complete();
/*
* Starts in v86 mode with the registers set to the
* specified values.
*/
__declspec(naked)
VOID Ki386RetToV86Mode(KV86M_REGISTERS* InRegs,
KV86M_REGISTERS* OutRegs)
{
__asm
{
/*
* Setup a stack frame
*/
push ebp
mov ebp, esp
pushad /* Save registers */
mov ebx, InRegs
/*
* Save ebp
*/
push ebp
/*
* Save a pointer to IN_REGS which the v86m exception handler will
* use to handle exceptions
*/
push ebx
/*
* Since we are going to fiddle with the stack pointer this must be
* a critical section for this processor
*/
/*
* Save the old initial stack
*/
mov esi, fs:KPCR_CURRENT_THREAD
mov edi, KTHREAD_INITIAL_STACK[esi]
push edi
/*
* We also need to set the stack in the kthread structure
*/
mov KTHREAD_INITIAL_STACK[esi], esp
/*
* The stack used for handling exceptions from v86 mode in this thread
* will be the current stack adjusted so we don't overwrite the
* existing stack frames
*/
mov esi, fs:KPCR_TSS
mov KTSS_ESP0[esi], esp
/*
* Create the stack frame for an iret to v86 mode
*/
push KV86M_REGISTERS_GS[ebx]
push KV86M_REGISTERS_FS[ebx]
push KV86M_REGISTERS_DS[ebx]
push KV86M_REGISTERS_ES[ebx]
push KV86M_REGISTERS_SS[ebx]
push KV86M_REGISTERS_ESP[ebx]
push KV86M_REGISTERS_EFLAGS[ebx]
push KV86M_REGISTERS_CS[ebx]
push KV86M_REGISTERS_EIP[ebx]
/*
* Setup the CPU registers
*/
mov eax, KV86M_REGISTERS_EAX[ebx]
mov ecx, KV86M_REGISTERS_ECX[ebx]
mov edx, KV86M_REGISTERS_EDX[ebx]
mov esi, KV86M_REGISTERS_ESI[ebx]
mov edi, KV86M_REGISTERS_EDI[ebx]
mov ebp, KV86M_REGISTERS_EBP[ebx]
mov ebx, KV86M_REGISTERS_EBX[ebx]
/*
* Go to v86 mode
*/
iretd
/*
* Handle the completion of a vm86 routine. We are called from
* an exception handler with the registers at the point of the
* exception on the stack.
*/
jmp KiV86Complete // TMN: Function-splitting
}
}
__declspec(naked)
void KiV86Complete()
{
__asm
{
/* Restore the original ebp */
mov ebp, TF_ORIG_EBP[esp]
/* Get a pointer to the OUT_REGS structure */
mov ebx, 12[ebp] // OutRegs
/* Skip debug information and unsaved registers */
add esp, 0x30
/* Ignore 32-bit segment registers */
add esp, 12
/* Save the vm86 registers into the OUT_REGS structure */
pop dword ptr KV86M_REGISTERS_EDX[ebx]
pop dword ptr KV86M_REGISTERS_ECX[ebx]
pop dword ptr KV86M_REGISTERS_EAX[ebx]
/* Restore the old previous mode */
pop eax
mov ss:KTHREAD_PREVIOUS_MODE[esi], al
/* Restore the old exception handler list */
pop eax
mov fs:KPCR_EXCEPTION_LIST, eax
/* Ignore the 32-bit fs register */
add esp, 4
pop dword ptr KV86M_REGISTERS_EDI[ebx]
pop dword ptr KV86M_REGISTERS_ESI[ebx]
pop dword ptr KV86M_REGISTERS_EBX[ebx]
pop dword ptr KV86M_REGISTERS_EBP[ebx]
/* Ignore error code */
add esp, 4
pop dword ptr KV86M_REGISTERS_EIP[ebx]
pop dword ptr KV86M_REGISTERS_CS[ebx]
pop dword ptr KV86M_REGISTERS_EFLAGS[ebx]
pop dword ptr KV86M_REGISTERS_ESP[ebx]
pop dword ptr KV86M_REGISTERS_SS[ebx]
pop dword ptr KV86M_REGISTERS_ES[ebx]
pop dword ptr KV86M_REGISTERS_DS[ebx]
pop dword ptr KV86M_REGISTERS_FS[ebx]
pop dword ptr KV86M_REGISTERS_GS[ebx]
/*
* We are going to fiddle with the stack so this must be a critical
* section for this process
*/
cli
/*
* Restore the initial stack
*/
pop eax
mov esi, fs:KPCR_TSS
mov KTSS_ESP0[esi], eax
/*
* We also need to set the stack in the kthread structure
*/
mov esi, fs:KPCR_CURRENT_THREAD
mov edi, KTHREAD_INITIAL_STACK[esi]
mov KTHREAD_INITIAL_STACK[esi], eax
/* Exit the critical section */
sti
/* Ignore IN_REGS pointer */
add esp, 4
/* Ignore ebp restored above */
add esp, 4
/* Return to caller */
popad
mov esp, ebp
pop ebp
ret
} // end of __asm block
}

View file

@ -0,0 +1,15 @@
; This file is vital. It tells the linker how to order some functions
; and some data, that unfortunately is assumed to be at low location
; and in known order to eachother respectively?
MultibootStub
our_memmove
dummy_placeholder
NtProcessStartup@4
initialize_page_directory
relocate_pointer_log_to_phys
; Order some data that there is some assumptions about...
init_stack
init_stack_top
trap_stack
trap_stack_top

View file

@ -0,0 +1,126 @@
#include <ddk/ntddk.h>
void MmSafeCopyToUserRestart();
void MmSafeCopyToUserUnsafeStart();
void MmSafeCopyFromUserUnsafeStart();
void MmSafeCopyFromUserRestart();
/*
* NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src,
* ULONG NumberOfBytes)
*/
__declspec(naked)
NTSTATUS MmSafeCopyFromUser(PVOID Dest, const VOID *Src, ULONG Count)
{
__asm
{
push ebp
mov ebp,esp
push esi
push edi
push ecx
mov edi, 8[ebp]
mov esi, 12[ebp]
mov ecx, 16[ebp]
/*
* Default return code
*/
xor eax,eax
jmp MmSafeCopyFromUserUnsafeStart
}
}
__declspec(naked)
void MmSafeCopyFromUserUnsafeStart()
{
__asm
{
/*
* This is really a synthetic instruction since if we incur a
* pagefault then eax will be set to an appropiate STATUS code
*/
cld
rep movsb
jmp MmSafeCopyFromUserRestart
}
}
__declspec(naked)
void MmSafeCopyFromUserRestart()
{
__asm
{
pop ecx
pop edi
pop esi
pop ebp
ret
}
}
/*****************************************************************************/
/*
* NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src,
* ULONG NumberOfBytes)
*/
NTSTATUS MmSafeCopyToUser(PVOID Dest, const VOID *Src, ULONG Count)
{
__asm
{
push ebp
mov esp,ebp
push esi
push edi
push ecx
mov edi, 8[ebp]
mov esi, 12[ebp]
mov ecx, 16[ebp]
/*
* Default return code
*/
xor eax,eax
jmp MmSafeCopyToUserUnsafeStart
}
}
__declspec(naked)
void MmSafeCopyToUserUnsafeStart()
{
__asm
{
/*
* This is really a synthetic instruction since if we incur a
* pagefault then eax will be set to an appropiate STATUS code
*/
cld
rep movsb
jmp MmSafeCopyToUserRestart
}
}
__declspec(naked)
void MmSafeCopyToUserRestart()
{
__asm
{
pop ecx
pop edi
pop esi
pop ebp
ret
}
}

View file

@ -0,0 +1,574 @@
/* $Id: mm_mminit_msvc.c,v 1.1 2004/02/06 08:22:01 fireball Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/mminit.c
* PURPOSE: kernel memory managment initialization functions
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 9/4/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <roscfg.h>
#include <internal/i386/segment.h>
#include <internal/mm.h>
#include <internal/ntoskrnl.h>
#include <internal/io.h>
#include <internal/ps.h>
#include <internal/pool.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
/*
* Size of extended memory (kb) (fixed for now)
*/
#define EXTENDED_MEMORY_SIZE (3*1024*1024)
/*
* Compiler defined symbols
*/
#if defined(_MSC_VER)
#pragma intrinsic(strcmp)
static PIMAGE_SECTION_HEADER FindSection(const char* szSeg)
{
PIMAGE_NT_HEADERS NtHeader = RtlImageNtHeader((PVOID)KERNEL_BASE);
PIMAGE_SECTION_HEADER Section = IMAGE_FIRST_SECTION(NtHeader);
const int count = NtHeader->FileHeader.NumberOfSections;
int i;
for (i = 0; i < count; ++i, ++Section)
{
if (!strcmp(szSeg, Section->Name))
{
return Section;
}
}
return NULL;
}
static void* FindSegmentStart(const char* szSeg)
{
PIMAGE_SECTION_HEADER Section = FindSection(szSeg);
if (Section)
{
return (void*)(KERNEL_BASE + Section->VirtualAddress);
}
return NULL;
}
static void* FindSegmentEnd(const char* szSeg)
{
PIMAGE_SECTION_HEADER Section = FindSection(szSeg);
if (Section)
{
return (void*)(KERNEL_BASE + Section->VirtualAddress + Section->Misc.VirtualSize);
}
return NULL;
}
#endif // defined(_MSC_VER)
static BOOLEAN IsThisAnNtAsSystem = FALSE;
static MM_SYSTEM_SIZE MmSystemSize = MmSmallSystem;
static MEMORY_AREA* kernel_text_desc = NULL;
static MEMORY_AREA* kernel_init_desc = NULL;
static MEMORY_AREA* kernel_map_desc = NULL;
static MEMORY_AREA* kernel_kpcr_desc = NULL;
static MEMORY_AREA* kernel_data_desc = NULL;
static MEMORY_AREA* kernel_param_desc = NULL;
static MEMORY_AREA* kernel_pool_desc = NULL;
static MEMORY_AREA* kernel_shared_data_desc = NULL;
static MEMORY_AREA* kernel_mapped_low_mem_desc = NULL;
static MEMORY_AREA* MiKernelMapDescriptor = NULL;
static MEMORY_AREA* MiPagedPoolDescriptor = NULL;
PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength;
PVOID MiKernelMapStart;
ULONG MiKernelMapLength;
/* FUNCTIONS ****************************************************************/
/*
* @implemented
*/
BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
{
return(IsThisAnNtAsSystem);
}
/*
* @implemented
*/
MM_SYSTEM_SIZE STDCALL MmQuerySystemSize(VOID)
{
return(MmSystemSize);
}
VOID MiShutdownMemoryManager(VOID)
{
}
VOID INIT_FUNCTION
MmInitVirtualMemory(ULONG LastKernelAddress,
ULONG KernelLength)
/*
* FUNCTION: Intialize the memory areas list
* ARGUMENTS:
* bp = Pointer to the boot parameters
* kernel_len = Length of the kernel
*/
{
PVOID BaseAddress;
ULONG Length;
ULONG ParamLength = KernelLength;
NTSTATUS Status;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
//ULONG i;
DPRINT("MmInitVirtualMemory(%x, %x)\n",LastKernelAddress, KernelLength);
BoundaryAddressMultiple.QuadPart = 0;
LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
MmInitMemoryAreas();
/* Don't change the start of kernel map. Pte's must always exist for this region. */
MiKernelMapStart = (char*)LastKernelAddress + PAGE_SIZE;
MiKernelMapLength = MM_KERNEL_MAP_SIZE;
MiNonPagedPoolStart = (char*)MiKernelMapStart + MiKernelMapLength + PAGE_SIZE;
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
MmPagedPoolBase = (char*)MiNonPagedPoolStart + MiNonPagedPoolLength + PAGE_SIZE;
MmPagedPoolSize = MM_PAGED_POOL_SIZE;
MiInitKernelMap();
MiInitializeNonPagedPool();
/*
* Setup the system area descriptor list
*/
BaseAddress = (PVOID)0xf0000000;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
0x400000,
0,
&kernel_map_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = (PVOID)KPCR_BASE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
PAGE_SIZE * MAXIMUM_PROCESSORS,
0,
&kernel_kpcr_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = (PVOID)0xd0000000;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
0x100000,
0,
&kernel_mapped_low_mem_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = (PVOID)KERNEL_BASE;
Length = PAGE_ROUND_UP(((ULONG)FindSegmentEnd(".text"))) - KERNEL_BASE;
ParamLength = ParamLength - Length;
/*
* No need to lock the address space at this point since no
* other threads are running.
*/
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_text_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
// TODO: Here we REALLY should iterate the PE's sections and set protection
// accordingly for each and every one of them.
// NOTE This code ONLY works because of the assumption that the .text
// segment is the first in the PE, and the .reloc segment is the last.
// Link in a way to make this assumtion false, and the kernel won't work.
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)FindSegmentEnd(".text")));
Length = PAGE_ROUND_UP(((ULONG)FindSegmentStart(".reloc"))) - (ULONG_PTR)BaseAddress;
ParamLength = ParamLength - Length;
DPRINT1("Data Length %x\n",Length);
DPRINT1("Data BaseAddress %x\n",BaseAddress);
/*
* No need to lock the address space at this point since we are
* the only thread running.
*/
// For GCC-compiled, kernel_data_desc contains:
// .data, .edata, .idata, .bss and .rsrc. E.i. all but .text and .reloc
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_data_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
// BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)FindSegmentEnd(".edata")));
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)FindSegmentStart(".reloc")));
Length = LastKernelAddress - (ULONG)BaseAddress;
// For GCC-compiled, kernel_param_desc contains .reloc
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_param_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = MiNonPagedPoolStart;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
MiNonPagedPoolLength,
0,
&kernel_pool_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = MiKernelMapStart;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
MiKernelMapLength,
0,
&MiKernelMapDescriptor,
FALSE,
FALSE,
BoundaryAddressMultiple);
BaseAddress = MmPagedPoolBase;
Status = MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_PAGED_POOL,
&BaseAddress,
MmPagedPoolSize,
0,
&MiPagedPoolDescriptor,
FALSE,
FALSE,
BoundaryAddressMultiple);
MmInitializePagedPool();
/*
* Create the kernel mapping of the user/kernel shared memory.
*/
BaseAddress = (PVOID)KI_USER_SHARED_DATA;
Length = PAGE_SIZE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_shared_data_desc,
FALSE,
FALSE,
BoundaryAddressMultiple);
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE,
&MmSharedDataPagePhysicalAddress);
Status = MmCreateVirtualMapping(NULL,
(PVOID)KI_USER_SHARED_DATA,
PAGE_READWRITE,
MmSharedDataPagePhysicalAddress,
TRUE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
KEBUGCHECK(0);
}
RtlZeroMemory(BaseAddress, Length);
/*
*
*/
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
}
VOID INIT_FUNCTION
MmInit1(ULONG FirstKrnlPhysAddr,
ULONG LastKrnlPhysAddr,
ULONG LastKernelAddress,
PADDRESS_RANGE BIOSMemoryMap,
ULONG AddressRangeCount,
ULONG MaxMem)
/*
* FUNCTION: Initalize memory managment
*/
{
ULONG i;
ULONG kernel_len;
#ifndef MP
extern unsigned int unmap_me, unmap_me2, unmap_me3;
#endif
DPRINT("MmInit1(FirstKrnlPhysAddr, %x, LastKrnlPhysAddr %x, LastKernelAddress %x)\n",
FirstKrnlPhysAddr,
LastKrnlPhysAddr,
LastKernelAddress);
if ((BIOSMemoryMap != NULL) && (AddressRangeCount > 0))
{
// If we have a bios memory map, recalulate the memory size
ULONG last = 0;
for (i = 0; i < AddressRangeCount; i++)
{
if (BIOSMemoryMap[i].Type == 1
&& (BIOSMemoryMap[i].BaseAddrLow + BIOSMemoryMap[i].LengthLow + PAGE_SIZE -1) / PAGE_SIZE > last)
{
last = (BIOSMemoryMap[i].BaseAddrLow + BIOSMemoryMap[i].LengthLow + PAGE_SIZE -1) / PAGE_SIZE;
}
}
if ((last - 256) * 4 > KeLoaderBlock.MemHigher)
{
KeLoaderBlock.MemHigher = (last - 256) * 4;
}
}
if (KeLoaderBlock.MemHigher >= (MaxMem - 1) * 1024)
{
KeLoaderBlock.MemHigher = (MaxMem - 1) * 1024;
}
/*
* FIXME: Set this based on the system command line
*/
MmSystemRangeStart = (PVOID)KERNEL_BASE; // 0xC0000000
MmUserProbeAddress = (PVOID)0x7fff0000;
MmHighestUserAddress = (PVOID)0x7ffeffff;
MmInitGlobalKernelPageDirectory();
/*
* Initialize memory managment statistics
*/
MmStats.NrTotalPages = 0;
MmStats.NrSystemPages = 0;
MmStats.NrUserPages = 0;
MmStats.NrReservedPages = 0;
MmStats.NrUserPages = 0;
MmStats.NrFreePages = 0;
MmStats.NrLockedPages = 0;
MmStats.PagingRequestsInLastMinute = 0;
MmStats.PagingRequestsInLastFiveMinutes = 0;
MmStats.PagingRequestsInLastFifteenMinutes = 0;
/*
* Initialize the kernel address space
*/
MmInitializeKernelAddressSpace();
/*
* Unmap low memory
*/
#ifndef MP
/* In SMP mode we unmap the low memory in MmInit3.
The APIC needs the mapping of the first pages
while the processors are starting up. */
MmDeletePageTable(NULL, 0);
#endif
/*
* Free all pages not used for kernel memory
* (we assume the kernel occupies a continuous range of physical
* memory)
*/
DPRINT("first krnl %x\nlast krnl %x\n",FirstKrnlPhysAddr,
LastKrnlPhysAddr);
/*
* Free physical memory not used by the kernel
*/
MmStats.NrTotalPages = KeLoaderBlock.MemHigher/4;
if (!MmStats.NrTotalPages)
{
DbgPrint("Memory not detected, default to 8 MB\n");
MmStats.NrTotalPages = 2048;
}
else
{
/* add 1MB for standard memory (not extended) */
MmStats.NrTotalPages += 256;
}
#ifdef BIOS_MEM_FIX
MmStats.NrTotalPages += 16;
#endif
DbgPrint("Used memory %dKb\n", (MmStats.NrTotalPages * PAGE_SIZE) / 1024);
LastKernelAddress = (ULONG)MmInitializePageList((PVOID)FirstKrnlPhysAddr,
(PVOID)LastKrnlPhysAddr,
MmStats.NrTotalPages,
PAGE_ROUND_UP(LastKernelAddress),
BIOSMemoryMap,
AddressRangeCount);
kernel_len = LastKrnlPhysAddr - FirstKrnlPhysAddr;
/*
* Create a trap for null pointer references and protect text
* segment
*/
CHECKPOINT;
#if defined(_MSC_VER)
DPRINT(".text start: %x, .data start: %x\n",
(int)FindSegmentStart(".text"),
(int)FindSegmentStart(".data"));
{
const char* pCode = FindSegmentStart(".text");
const char* pData = FindSegmentEnd(".text");
while (pCode < pData)
{
MmSetPageProtect(NULL, (PVOID)pCode, PAGE_EXECUTE_READ);
pCode += PAGE_SIZE;
}
}
#else
DPRINT("_text_start__ %x _init_end__ %x\n",(int)&_text_start__,(int)&_init_end__);
for (i=PAGE_ROUND_DOWN(((int)&_text_start__));
i<PAGE_ROUND_UP(((int)&_init_end__));i=i+PAGE_SIZE)
{
MmSetPageProtect(NULL,
(PVOID)i,
PAGE_EXECUTE_READ);
}
#endif
DPRINT("Invalidating between %x and %x\n",
LastKernelAddress, 0xc0600000);
for (i=(LastKernelAddress); i<0xc0600000; i+=PAGE_SIZE)
{
MmRawDeleteVirtualMapping((PVOID)(i));
}
DPRINT("Invalidating between %x and %x\n",
0xd0100000, 0xd0400000);
for (i=0xd0100000; i<0xd0400000; i+=PAGE_SIZE)
{
MmRawDeleteVirtualMapping((PVOID)(i));
}
DPRINT("Almost done MmInit()\n");
#ifndef MP
/* FIXME: This is broken in SMP mode */
#if !defined(_MSC_VER) // FIXME: I don't trust using this from MSVC yet!
MmDeleteVirtualMapping(NULL, (PVOID)&unmap_me, TRUE, NULL, NULL);
MmDeleteVirtualMapping(NULL, (PVOID)&unmap_me2, TRUE, NULL, NULL);
MmDeleteVirtualMapping(NULL, (PVOID)&unmap_me3, TRUE, NULL, NULL);
#endif // _MSC_VER
#endif
/*
* Intialize memory areas
*/
MmInitVirtualMemory(LastKernelAddress, kernel_len);
MmInitializeMdlImplementation();
}
VOID INIT_FUNCTION
MmInit2(VOID)
{
MmInitializeRmapList();
MmInitializePageOp();
MmInitSectionImplementation();
MmInitPagingFile();
}
VOID INIT_FUNCTION
MmInit3(VOID)
{
/*
* Unmap low memory
*/
#ifdef MP
/* In SMP mode we can unmap the low memory
if all processors are started. */
MmDeletePageTable(NULL, 0);
#endif
MmInitZeroPageThread();
MmCreatePhysicalMemorySection();
MiInitBalancerThread();
/*
* Initialise the modified page writer.
*/
MmInitMpwThread();
/* FIXME: Read parameters from memory */
}
VOID STATIC
MiFreeInitMemoryPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
PHYSICAL_ADDRESS PhysAddr, SWAPENTRY SwapEntry,
BOOLEAN Dirty)
{
assert(SwapEntry == 0);
if (PhysAddr.QuadPart != 0)
{
MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
}
}
VOID
MiFreeInitMemory(VOID)
{
#if defined(_MSC_VER)
DPRINT1("Can not yet free .init memory for MSVC compiled kernel\n");
#else
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
(PVOID)&_init_start__,
PAGE_ROUND_UP((ULONG)&_init_end__) - (ULONG)_init_start__,
MiFreeInitMemoryPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
#endif
}

3271
msvc6/ntoskrnl/ntoskrnl.dsp Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,299 @@
/*
* ReactOS kernel
* Copyright (C) 2000 David Welch <welch@cwcom.net>
*
* Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
*
* 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.
*/
/*
* FILE: ntoskrnl/ke/i386/vm86_sup.S
* PURPOSE: V86 mode support
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 09/10/00
*/
/* INCLUDES ******************************************************************/
#pragma hdrstop
#include <ddk/ntddk.h>
#include <ddk/status.h>
#include <internal/i386/segment.h>
#include <internal/i386/fpu.h>
#include <internal/ps.h>
#include <ddk/defines.h>
#include <internal/v86m.h>
#include <ntos/tss.h>
//#include <ntos/service.h>
#include <internal/trap.h>
#include <internal/ps.h>
#include <roscfg.h>
#include <internal/ntoskrnl.h>
#include <internal/i386/segment.h>
#define EXCEPTION_UNWINDING 0x02
#define EREC_FLAGS 0x04
#define ExceptionContinueExecution 0
#define ExceptionContinueSearch 1
#define ExceptionNestedException 2
#define ExceptionCollidedUnwind 3
//.globl _RtlpExecuteHandlerForException
//.globl _RtlpExecuteHandlerForUnwind
#define CONTEXT_FLAGS 0x00
#define CONTEXT_SEGGS 0x8C
#define CONTEXT_SEGFS 0x90
#define CONTEXT_SEGES 0x94
#define CONTEXT_SEGDS 0x98
#define CONTEXT_EDI 0x9C
#define CONTEXT_ESI 0xA0
#define CONTEXT_EBX 0xA4
#define CONTEXT_EDX 0xA8
#define CONTEXT_ECX 0xAC
#define CONTEXT_EAX 0xB0
#define CONTEXT_EBP 0xB4
#define CONTEXT_EIP 0xB8
#define CONTEXT_SEGCS 0xBC
#define CONTEXT_EFLAGS 0xC0
#define CONTEXT_ESP 0xC4
#define CONTEXT_SEGSS 0xC8
#define RCC_CONTEXT 0x08
VOID STDCALL
AsmDebug(ULONG Value);
// EAX = value to print
__declspec(naked)
void do_debug()
{
__asm
{
pusha
push eax
call AsmDebug
popa
ret
}
}
#define REH_ERECORD 0x08
#define REH_RFRAME 0x0C
#define REH_CONTEXT 0x10
#define REH_DCONTEXT 0x14
#define REH_EROUTINE 0x18
// Parameters:
// None
// Registers:
// [EBP+08h] - PEXCEPTION_RECORD ExceptionRecord
// [EBP+0Ch] - PEXCEPTION_REGISTRATION RegistrationFrame
// [EBP+10h] - PVOID Context
// [EBP+14h] - PVOID DispatcherContext
// [EBP+18h] - PEXCEPTION_HANDLER ExceptionRoutine
// EDX - Address of protecting exception handler
// Returns:
// EXCEPTION_DISPOSITION
// Notes:
// Setup the protecting exception handler and call the exception
// handler in the right context.
__declspec(naked)
void RtlpExecuteHandler()
{
__asm
{
push ebp
mov ebp, esp
push REH_RFRAME[ebp]
push edx
push fs:0x0
mov fs:0x0, esp
// Prepare to call the exception handler
push REH_DCONTEXT[ebp]
push REH_CONTEXT[ebp]
push REH_RFRAME[ebp]
push REH_ERECORD[ebp]
// Now call the exception handler
mov eax, REH_EROUTINE[ebp]
call eax
cmp fs:0x0, -1
jne reh_stack_looks_ok
// This should not happen
push 0
push 0
push 0
push 0
call RtlAssert
reh_loop:
jmp reh_loop
reh_stack_looks_ok:
mov esp, fs:0x0
// Return to the 'front-end' for this function
pop dword ptr fs:0x0
mov esp, ebp
pop ebp
ret
}
}
#if 0
#endif // 0
#define REP_ERECORD 0x04
#define REP_RFRAME 0x08
#define REP_CONTEXT 0x0C
#define REP_DCONTEXT 0x10
// Parameters:
// [ESP+04h] - PEXCEPTION_RECORD ExceptionRecord
// [ESP+08h] - PEXCEPTION_REGISTRATION RegistrationFrame
// [ESP+0Ch] - PCONTEXT Context
// [ESP+10h] - PVOID DispatcherContext
// Registers:
// None
// Returns:
// EXCEPTION_DISPOSITION
// Notes:
// This exception handler protects the exception handling
// mechanism by detecting nested exceptions.
__declspec(naked)
void RtlpExceptionProtector()
{
__asm
{
mov eax, ExceptionContinueSearch
mov ecx, REP_ERECORD[esp]
test EREC_FLAGS[ecx], EXCEPTION_UNWINDING
jnz rep_end
// Unwinding is not taking place, so return ExceptionNestedException
// Set DispatcherContext field to the exception registration for the
// exception handler that executed when a nested exception occurred
mov ecx, REP_DCONTEXT[esp]
mov eax, REP_RFRAME[esp]
mov [ecx], eax
mov eax, ExceptionNestedException
rep_end:
ret
}
}
// Parameters:
// [ESP+04h] - PEXCEPTION_RECORD ExceptionRecord
// [ESP+08h] - PEXCEPTION_REGISTRATION RegistrationFrame
// [ESP+0Ch] - PCONTEXT Context
// [ESP+10h] - PVOID DispatcherContext
// [ESP+14h] - PEXCEPTION_HANDLER ExceptionHandler
// Registers:
// None
// Returns:
// EXCEPTION_DISPOSITION
// Notes:
// Front-end
__declspec(naked)
void RtlpExecuteHandlerForException()
{
__asm
{
mov edx, RtlpExceptionProtector
jmp RtlpExecuteHandler
}
}
#define RUP_ERECORD 0x04
#define RUP_RFRAME 0x08
#define RUP_CONTEXT 0x0C
#define RUP_DCONTEXT 0x10
// Parameters:
// [ESP+04h] - PEXCEPTION_RECORD ExceptionRecord
// [ESP+08h] - PEXCEPTION_REGISTRATION RegistrationFrame
// [ESP+0Ch] - PCONTEXT Context
// [ESP+10h] - PVOID DispatcherContext
// Registers:
// None
// Returns:
// EXCEPTION_DISPOSITION
// Notes:
// This exception handler protects the exception handling
// mechanism by detecting collided unwinds.
__declspec(naked)
void RtlpUnwindProtector()
{
__asm
{
mov eax, ExceptionContinueSearch
mov RUP_ERECORD[esp], ecx
test EREC_FLAGS[ecx], EXCEPTION_UNWINDING
jz rup_end
// Unwinding is taking place, so return ExceptionCollidedUnwind
mov ecx, RUP_RFRAME[esp]
mov edx, RUP_DCONTEXT[esp]
// Set DispatcherContext field to the exception registration for the
// exception handler that executed when a collision occurred
mov eax, RUP_RFRAME[ecx]
mov [edx], eax
mov eax, ExceptionCollidedUnwind
rup_end:
ret
}
}
// Parameters:
// [ESP+04h] - PEXCEPTION_RECORD ExceptionRecord
// [ESP+08h] - PEXCEPTION_REGISTRATION RegistrationFrame
// [ESP+0Ch] - PCONTEXT Context
// [ESP+10h] - PVOID DispatcherContext
// [ESP+14h] - PEXCEPTION_HANDLER ExceptionHandler
// Registers:
// None
// Returns:
// EXCEPTION_DISPOSITION
__declspec(naked)
void RtlpExecuteHandlerForUnwind()
{
__asm mov edx, RtlpUnwindProtector
__asm jmp RtlpExecuteHandler
}