Skip to content

Commit

Permalink
Add phymem_wrappeer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zawawa committed Oct 11, 2017
1 parent 1c172b4 commit f181566
Show file tree
Hide file tree
Showing 14 changed files with 912 additions and 748 deletions.
1 change: 1 addition & 0 deletions Cloo/Cloo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<DocumentationFile>Cloo.xml</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
273 changes: 211 additions & 62 deletions GatelessGateSharp.sln

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion GatelessGateSharp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
using System.Windows.Forms;
using System.Data.SQLite;
using System.Collections;
using System.Runtime.InteropServices;
using Cloo;


namespace GatelessGateSharp
{
public partial class MainForm : Form
{
[DllImport("phymem_wrapper.dll")]
extern public static int LoadPhyMemDriver();
[DllImport("phymem_wrapper.dll")]
extern public static void UnloadPhyMemDriver();

public static String appName = "Gateless Gate #";
String databaseFileName = "GatelessGateSharp.sqlite";
String logFileName = "GatelessGateSharp.log";
const int richTextBoxLogMaxLines = 65536;
Expand Down Expand Up @@ -49,7 +56,7 @@ public void Logger(String lines)
public MainForm()
{
InitializeComponent();
Logger("Gateless Gate # started.");
Logger(appName + " started.");
labelGPUVendorArray = new Control[] { labelGPU0Vendor, labelGPU1Vendor, labelGPU2Vendor, labelGPU3Vendor, labelGPU4Vendor, labelGPU5Vendor, labelGPU6Vendor, labelGPU7Vendor };
labelGPUNameArray = new Control[] { labelGPU0Name, labelGPU1Name, labelGPU2Name, labelGPU3Name, labelGPU4Name, labelGPU5Name, labelGPU6Name, labelGPU7Name };
labelGPUIDArray = new Control[] { labelGPU0ID, labelGPU1ID, labelGPU2ID, labelGPU3ID, labelGPU4ID, labelGPU5ID, labelGPU6ID, labelGPU7ID };
Expand All @@ -58,6 +65,17 @@ public MainForm()
labelGPUFanArray = new Control[] { labelGPU0Fan, labelGPU1Fan, labelGPU2Fan, labelGPU3Fan, labelGPU4Fan, labelGPU5Fan, labelGPU6Fan, labelGPU7Fan };
labelGPUSpeedArray = new Control[] { labelGPU0Speed, labelGPU1Speed, labelGPU2Speed, labelGPU3Speed, labelGPU4Speed, labelGPU5Speed, labelGPU6Speed, labelGPU7Speed };
checkBoxGPUEnabledArray = new Control[] { checkBoxGPU0Enabled, checkBoxGPU1Enabled, checkBoxGPU2Enabled, checkBoxGPU3Enabled, checkBoxGPU4Enabled, checkBoxGPU5Enabled, checkBoxGPU6Enabled, checkBoxGPU7Enabled };

if (LoadPhyMemDriver() != 0)
{
Logger("Successfully loaded phymem.");
}
else
{
Logger("Failed to load phymem.");
MessageBox.Show("Failed to load phymem.", appName, MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}

private void CreateNewDatabase()
Expand Down Expand Up @@ -209,6 +227,7 @@ private void textBoxZcashAddress_TextChanged(object sender, EventArgs e)
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
UpdateDatabase();
//UnloadPhyMemDriver();
}
}
}
Binary file added GatelessGateSharp/Release
Binary file not shown.
Binary file added phymem/phymem.sys
Binary file not shown.
20 changes: 10 additions & 10 deletions phymem/phymem.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IntDir>$(ProjectDir)intermediate\$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(ProjectDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>intermediate\$(Platform)\$(Configuration)\</IntDir>
<OutDir>bin\$(Platform)\$(ConfigurationName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelWDbg|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
Expand All @@ -171,7 +171,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -181,7 +181,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -194,7 +194,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -206,7 +206,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -215,7 +215,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -225,7 +225,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -238,7 +238,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand All @@ -250,7 +250,7 @@
</ClCompile>
<Link />
<PostBuildEvent>
<Command>copy $(SolutionDir)$(ProjectName)\bin\$(Platform)\$(ConfigurationName)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
<Command>copy $(ProjectDir)\phymem.sys $(SolutionDir)GatelessGateSharp\bin\$(ConfigurationName)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions phymem_wrapper/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <Windows.h>

BOOL APIENTRY DllMain(HMODULE /* hModule */, DWORD ul_reason_for_call, LPVOID /* lpReserved */)
extern "C" CRITICAL_SECTION phymem_mutex;

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
InitializeCriticalSection(&phymem_mutex);;

switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
Expand Down
6 changes: 0 additions & 6 deletions phymem_wrapper/pch.cpp

This file was deleted.

26 changes: 0 additions & 26 deletions phymem_wrapper/pch.h

This file was deleted.

51 changes: 21 additions & 30 deletions phymem_wrapper/phymem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@
#define __PHYMEM_H


#ifdef __cplusplus
extern "C"
{
#endif

//driver initialize
BOOL LoadPhyMemDriver();
VOID UnloadPhyMemDriver();

//map physical memory to user space
PVOID MapPhyMem(DWORD64 phyAddr, DWORD memSize);
VOID UnmapPhyMem(PVOID pVirAddr, DWORD memSize);

//access port
BYTE ReadPortByte(WORD portAddr);
WORD ReadPortWord(WORD portAddr);
DWORD ReadPortLong(WORD portAddr);
VOID WritePortByte(WORD portAddr, BYTE portValue);
VOID WritePortWord(WORD portAddr, WORD portValue);
VOID WritePortLong(WORD portAddr, DWORD portValue);

//access PCI bus
BOOL ReadPCI(DWORD busNum, DWORD devNum, DWORD funcNum,
DWORD regOff, DWORD bytes, PVOID pValue);
BOOL WritePCI(DWORD busNum, DWORD devNum, DWORD funcNum,
DWORD regOff, DWORD bytes, PVOID pValue);

#ifdef __cplusplus
}
#endif
//driver initialize
__declspec(dllexport) BOOL LoadPhyMemDriver();
__declspec(dllexport) VOID UnloadPhyMemDriver();

//map physical memory to user space
PVOID MapPhyMem(DWORD64 phyAddr, DWORD memSize);
VOID UnmapPhyMem(PVOID pVirAddr, DWORD memSize);

//access port
BYTE ReadPortByte(WORD portAddr);
WORD ReadPortWord(WORD portAddr);
DWORD ReadPortLong(WORD portAddr);
VOID WritePortByte(WORD portAddr, BYTE portValue);
VOID WritePortWord(WORD portAddr, WORD portValue);
VOID WritePortLong(WORD portAddr, DWORD portValue);

//access PCI bus
BOOL ReadPCI(DWORD busNum, DWORD devNum, DWORD funcNum,
DWORD regOff, DWORD bytes, PVOID pValue);
BOOL WritePCI(DWORD busNum, DWORD devNum, DWORD funcNum,
DWORD regOff, DWORD bytes, PVOID pValue);

#endif //__PMDLL_H
Loading

0 comments on commit f181566

Please sign in to comment.