* KernelModeDriver module support

* Build afd.sys


svn path=/branches/xmlbuildsystem/; revision=13078
This commit is contained in:
Casper Hornstrup 2005-01-16 13:51:33 +00:00
parent 41c7d92f46
commit 40a6da67c4
11 changed files with 198 additions and 59 deletions

View file

@ -19,6 +19,7 @@
<include>include</include> <include>include</include>
<include>w32api/include</include> <include>w32api/include</include>
<include>w32api/include/ddk</include>
<directory name="drivers"> <directory name="drivers">
<xi:include href="drivers/directory.xml" /> <xi:include href="drivers/directory.xml" />

View file

@ -1,3 +1,6 @@
<directory name="lib"> <directory name="lib">
<xi:include href="lib/directory.xml" /> <xi:include href="lib/directory.xml" />
</directory> </directory>
<directory name="net">
<xi:include href="net/directory.xml" />
</directory>

View file

@ -0,0 +1,24 @@
<module name="afd" type="kernelmodedriver">
<importlibrary definition="afd.def" />
<include base="afd">include</include>
<include base="ReactOS">include/afd</include>
<define name="__USE_W32API" />
<library>ntoskrnl</library>
<library>hal</library>
<library>pseh</library>
<directory name="afd">
<file>bind.c</file>
<file>connect.c</file>
<file>context.c</file>
<file>info.c</file>
<file>listen.c</file>
<file>lock.c</file>
<file>main.c</file>
<file>read.c</file>
<file>select.c</file>
<file>tdi.c</file>
<file>tdiconn.c</file>
<file>write.c</file>
</directory>
<file>afd.rc</file>
</module>

View file

@ -0,0 +1,3 @@
<directory name="afd">
<xi:include href="afd/afd.xml" />
</directory>

View file

@ -1 +1,5 @@
#ifdef __USE_W32API
#include_next <ndis.h>
#else
#include "net/ndis.h" #include "net/ndis.h"
#endif

View file

@ -1,4 +1,5 @@
<module name="ntoskrnl" type="kernel"> <module name="ntoskrnl" type="kernel">
<importlibrary definition="ntoskrnl.def" />
<dependency>buildno</dependency> <dependency>buildno</dependency>
<dependency>genntdll</dependency> <dependency>genntdll</dependency>
<dependency>wmc</dependency> <dependency>wmc</dependency>

View file

@ -640,6 +640,13 @@ MingwModuleHandler::GenerateArchiveTarget ( const Module& module,
return archiveFilename; return archiveFilename;
} }
string
MingwModuleHandler::GetCFlagsMacro ( const Module& module ) const
{
return ssprintf ( "$(%s_CFLAGS)",
module.name.c_str () );
}
string string
MingwModuleHandler::GetObjectsMacro ( const Module& module ) const MingwModuleHandler::GetObjectsMacro ( const Module& module ) const
{ {
@ -658,7 +665,8 @@ void
MingwModuleHandler::GenerateMacrosAndTargets ( MingwModuleHandler::GenerateMacrosAndTargets (
const Module& module, const Module& module,
const string& cc, const string& cc,
const string& ar ) const const string& ar,
const string* cflags ) const
{ {
string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ()); string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ()); string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
@ -673,12 +681,20 @@ MingwModuleHandler::GenerateMacrosAndTargets (
linkerFlagsMacro, linkerFlagsMacro,
objectsMacro ); objectsMacro );
if ( cflags != NULL )
{
fprintf ( fMakefile,
"%s += %s\n\n",
cflagsMacro.c_str (),
cflags->c_str () );
}
// generate phony target for module name // generate phony target for module name
fprintf ( fMakefile, ".PHONY: %s\n", fprintf ( fMakefile, ".PHONY: %s\n",
module.name.c_str() ); module.name.c_str () );
fprintf ( fMakefile, "%s: %s\n\n", fprintf ( fMakefile, "%s: %s\n\n",
module.name.c_str(), module.name.c_str (),
module.GetPath().c_str() ); module.GetPath ().c_str () );
// future references to the macros will be to get their values // future references to the macros will be to get their values
cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ()); cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
@ -710,13 +726,21 @@ MingwModuleHandler::GenerateMacrosAndTargets (
void void
MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const
{ {
GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}" ); GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}", NULL );
} }
void void
MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const
{ {
GenerateMacrosAndTargets ( module, "${gcc}", "${ar}" ); GenerateMacrosAndTargetsTarget ( module,
NULL );
}
void
MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,
const string* clags ) const
{
GenerateMacrosAndTargets ( module, "${gcc}", "${ar}", clags );
} }
string string
@ -857,6 +881,22 @@ MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) co
fprintf ( fMakefile, "\n" ); fprintf ( fMakefile, "\n" );
} }
void
MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module& module ) const
{
if ( module.importLibrary != NULL )
{
fprintf ( fMakefile, "%s:\n",
module.GetDependencyPath ().c_str () );
fprintf ( fMakefile,
"\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
module.GetTargetName ().c_str (),
FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
}
}
static MingwBuildToolModuleHandler buildtool_handler; static MingwBuildToolModuleHandler buildtool_handler;
@ -922,6 +962,8 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
GenerateMacrosAndTargetsTarget ( module ); GenerateMacrosAndTargetsTarget ( module );
GenerateImportLibraryTargetIfNeeded ( module );
fprintf ( fMakefile, "%s: %s %s\n", fprintf ( fMakefile, "%s: %s %s\n",
target.c_str (), target.c_str (),
objectsMacro.c_str (), objectsMacro.c_str (),
@ -1005,19 +1047,9 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
string archiveFilename = GetModuleArchiveFilename ( module ); string archiveFilename = GetModuleArchiveFilename ( module );
string importLibraryDependencies = GetImportLibraryDependencies ( module ); string importLibraryDependencies = GetImportLibraryDependencies ( module );
if (module.importLibrary != NULL) GenerateImportLibraryTargetIfNeeded ( module );
{
fprintf ( fMakefile, "%s:\n",
module.GetDependencyPath ().c_str () );
fprintf ( fMakefile, if ( module.files.size () > 0 )
"\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
module.GetTargetName ().c_str (),
FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
}
if (module.files.size () > 0)
{ {
GenerateMacrosAndTargetsTarget ( module ); GenerateMacrosAndTargetsTarget ( module );
@ -1045,6 +1077,63 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Modul
} }
static MingwKernelModeDriverModuleHandler kernelmodedriver_handler;
MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
: MingwModuleHandler ( KernelModeDriver )
{
}
void
MingwKernelModeDriverModuleHandler::Process ( const Module& module )
{
GeneratePreconditionDependencies ( module );
GenerateKernelModeDriverModuleTarget ( module );
GenerateInvocations ( module );
}
void
MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module& module )
{
static string ros_junk ( "$(ROS_TEMPORARY)" );
string target ( FixupTargetFilename ( module.GetPath () ) );
string workingDirectory = GetWorkingDirectory ( );
string archiveFilename = GetModuleArchiveFilename ( module );
string importLibraryDependencies = GetImportLibraryDependencies ( module );
GenerateImportLibraryTargetIfNeeded ( module );
if ( module.files.size () > 0 )
{
string* cflags = new string ( "-D__NTDRIVER__" );
GenerateMacrosAndTargetsTarget ( module,
cflags );
delete cflags;
fprintf ( fMakefile, "%s: %s %s\n",
target.c_str (),
archiveFilename.c_str (),
importLibraryDependencies.c_str () );
string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
string linkerCommand = GenerateLinkerCommand ( module,
"${gcc}",
linkerParameters,
archiveFilename );
fprintf ( fMakefile,
"\t%s\n\n",
linkerCommand.c_str () );
}
else
{
fprintf ( fMakefile, "%s:\n",
target.c_str ());
fprintf ( fMakefile, ".PHONY: %s\n\n",
target.c_str ());
}
}
static MingwNativeDLLModuleHandler nativedll_handler; static MingwNativeDLLModuleHandler nativedll_handler;
MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler () MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
@ -1068,20 +1157,10 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& modul
string workingDirectory = GetWorkingDirectory ( ); string workingDirectory = GetWorkingDirectory ( );
string archiveFilename = GetModuleArchiveFilename ( module ); string archiveFilename = GetModuleArchiveFilename ( module );
string importLibraryDependencies = GetImportLibraryDependencies ( module ); string importLibraryDependencies = GetImportLibraryDependencies ( module );
GenerateImportLibraryTargetIfNeeded ( module );
if (module.importLibrary != NULL) if ( module.files.size () > 0 )
{
fprintf ( fMakefile, "%s:\n",
module.GetDependencyPath ().c_str () );
fprintf ( fMakefile,
"\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
module.GetTargetName ().c_str (),
FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
}
if (module.files.size () > 0)
{ {
GenerateMacrosAndTargetsTarget ( module ); GenerateMacrosAndTargetsTarget ( module );
@ -1133,19 +1212,9 @@ MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module
string archiveFilename = GetModuleArchiveFilename ( module ); string archiveFilename = GetModuleArchiveFilename ( module );
string importLibraryDependencies = GetImportLibraryDependencies ( module ); string importLibraryDependencies = GetImportLibraryDependencies ( module );
if (module.importLibrary != NULL) GenerateImportLibraryTargetIfNeeded ( module );
{
fprintf ( fMakefile, "%s:\n",
module.GetDependencyPath ().c_str () );
fprintf ( fMakefile, if ( module.files.size () > 0 )
"\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
module.GetTargetName ().c_str (),
FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
}
if (module.files.size () > 0)
{ {
GenerateMacrosAndTargetsTarget ( module ); GenerateMacrosAndTargetsTarget ( module );
@ -1197,7 +1266,9 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module
string objectFilenames = GetObjectFilenames ( module ); string objectFilenames = GetObjectFilenames ( module );
string importLibraryDependencies = GetImportLibraryDependencies ( module ); string importLibraryDependencies = GetImportLibraryDependencies ( module );
if (module.files.size () > 0) GenerateImportLibraryTargetIfNeeded ( module );
if ( module.files.size () > 0 )
{ {
GenerateMacrosAndTargetsTarget ( module ); GenerateMacrosAndTargetsTarget ( module );

View file

@ -32,16 +32,20 @@ protected:
std::string GetObjectFilenames ( const Module& module ) const; std::string GetObjectFilenames ( const Module& module ) const;
void GenerateMacrosAndTargetsHost ( const Module& module ) const; void GenerateMacrosAndTargetsHost ( const Module& module ) const;
void GenerateMacrosAndTargetsTarget ( const Module& module ) const; void GenerateMacrosAndTargetsTarget ( const Module& module ) const;
void GenerateMacrosAndTargetsTarget ( const Module& module,
const std::string* clags ) const;
std::string GetInvocationDependencies ( const Module& module ) const; std::string GetInvocationDependencies ( const Module& module ) const;
std::string GetInvocationParameters ( const Invoke& invoke ) const; std::string GetInvocationParameters ( const Invoke& invoke ) const;
void GenerateInvocations ( const Module& module ) const; void GenerateInvocations ( const Module& module ) const;
void GeneratePreconditionDependencies ( const Module& module ) const; void GeneratePreconditionDependencies ( const Module& module ) const;
std::string GetCFlagsMacro ( const Module& module ) const;
std::string GetObjectsMacro ( const Module& module ) const; std::string GetObjectsMacro ( const Module& module ) const;
std::string GetLinkerMacro ( const Module& module ) const; std::string GetLinkerMacro ( const Module& module ) const;
std::string GenerateLinkerCommand ( const Module& module, std::string GenerateLinkerCommand ( const Module& module,
const std::string& linker, const std::string& linker,
const std::string& linkerParameters, const std::string& linkerParameters,
const std::string& objectFilenames ) const; const std::string& objectFilenames ) const;
void GenerateImportLibraryTargetIfNeeded ( const Module& module ) const;
static FILE* fMakefile; static FILE* fMakefile;
private: private:
std::string ConcatenatePaths ( const std::string& path1, std::string ConcatenatePaths ( const std::string& path1,
@ -115,7 +119,8 @@ private:
const std::string& objs_macro ) const; const std::string& objs_macro ) const;
void GenerateMacrosAndTargets ( const Module& module, void GenerateMacrosAndTargets ( const Module& module,
const std::string& cc, const std::string& cc,
const std::string& ar ) const; const std::string& ar,
const std::string* clags ) const;
std::string GetPreconditionDependenciesName ( const Module& module ) const; std::string GetPreconditionDependenciesName ( const Module& module ) const;
}; };
@ -160,6 +165,16 @@ private:
}; };
class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
{
public:
MingwKernelModeDriverModuleHandler ();
virtual void Process ( const Module& module );
private:
void GenerateKernelModeDriverModuleTarget ( const Module& module );
};
class MingwNativeDLLModuleHandler : public MingwModuleHandler class MingwNativeDLLModuleHandler : public MingwModuleHandler
{ {
public: public:

View file

@ -8,10 +8,9 @@ using std::vector;
Include::Include ( const Project& project_, Include::Include ( const Project& project_,
const XMLElement& includeNode ) const XMLElement& includeNode )
: project(project_), : project (project_),
module(NULL), module (NULL),
node(includeNode), node (includeNode)
base(NULL)
{ {
Initialize(); Initialize();
} }
@ -19,10 +18,9 @@ Include::Include ( const Project& project_,
Include::Include ( const Project& project_, Include::Include ( const Project& project_,
const Module* module_, const Module* module_,
const XMLElement& includeNode ) const XMLElement& includeNode )
: project(project_), : project (project_),
module(module_), module (module_),
node(includeNode), node (includeNode)
base(NULL)
{ {
Initialize(); Initialize();
} }
@ -48,13 +46,27 @@ Include::ProcessXML()
throw InvalidBuildFileException ( throw InvalidBuildFileException (
node.location, node.location,
"'base' attribute illegal from global <include>" ); "'base' attribute illegal from global <include>" );
base = project.LocateModule ( att->value ); bool referenceResolved = false;
if ( !base ) if ( att->value == project.name )
{
basePath = ".";
referenceResolved = true;
}
else
{
const Module* base = project.LocateModule ( att->value );
if ( base != NULL )
{
basePath = base->GetBasePath ();
referenceResolved = true;
}
}
if ( !referenceResolved )
throw InvalidBuildFileException ( throw InvalidBuildFileException (
node.location, node.location,
"<include> attribute 'base' references non-existant module '%s'", "<include> attribute 'base' references non-existant project or module '%s'",
att->value.c_str() ); att->value.c_str() );
directory = FixSeparator ( base->GetBasePath() + "/" + node.value ); directory = FixSeparator ( basePath + "/" + node.value );
} }
else else
directory = FixSeparator ( node.value ); directory = FixSeparator ( node.value );

View file

@ -214,6 +214,8 @@ Module::GetModuleType ( const string& location, const XMLAttribute& attribute )
return Kernel; return Kernel;
if ( attribute.value == "kernelmodedll" ) if ( attribute.value == "kernelmodedll" )
return KernelModeDLL; return KernelModeDLL;
if ( attribute.value == "kernelmodedriver" )
return KernelModeDriver;
if ( attribute.value == "nativedll" ) if ( attribute.value == "nativedll" )
return NativeDLL; return NativeDLL;
if ( attribute.value == "win32dll" ) if ( attribute.value == "win32dll" )
@ -241,6 +243,8 @@ Module::GetDefaultModuleExtension () const
case NativeDLL: case NativeDLL:
case Win32DLL: case Win32DLL:
return ".dll"; return ".dll";
case KernelModeDriver:
return ".sys";
} }
throw InvalidOperationException ( __FILE__, throw InvalidOperationException ( __FILE__,
__LINE__ ); __LINE__ );

View file

@ -73,6 +73,7 @@ enum ModuleType
StaticLibrary, StaticLibrary,
Kernel, Kernel,
KernelModeDLL, KernelModeDLL,
KernelModeDriver,
NativeDLL, NativeDLL,
Win32DLL, Win32DLL,
Win32GUI Win32GUI
@ -128,7 +129,7 @@ public:
const Module* module; const Module* module;
const XMLElement& node; const XMLElement& node;
std::string directory; std::string directory;
const Module* base; std::string basePath;
Include ( const Project& project, Include ( const Project& project,
const XMLElement& includeNode ); const XMLElement& includeNode );