Skip to content

Instantly share code, notes, and snippets.

View kant2002's full-sized avatar

Andrii Kurdiumov kant2002

View GitHub Profile
@kant2002
kant2002 / SeeSharpSnake.csproj
Last active March 23, 2020 22:22
Package UEFI application in VHDX
<Target Name="GenerateVirtuaDisk" AfterTargets="Publish">
<PropertyGroup>
<VHD>$(MSBuildProjectDirectory)\$(NativeOutputPath)seesharpsnake.vhdx</VHD>
<CreatePartitionCommand>
create vdisk file=$(VHD) maximum=40
select vdisk file=$(VHD)
attach vdisk
convert gpt
create partition efi
format quick fs=fat32 label="System"
@kant2002
kant2002 / CoreRT.csproj
Created March 23, 2020 22:17
Linker parameters for UEFI application using CoreRT
<ItemGroup>
<LinkerArg Include="/subsystem:EFI_APPLICATION /entry:EfiMain" />
</ItemGroup>
@kant2002
kant2002 / CoreRT.csproj
Last active March 23, 2020 22:19
Disable standard runtime in CoreRT application
<PropertyGroup>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
<RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<IlcSystemModule>SeeSharpSnake</IlcSystemModule>
</PropertyGroup>
<Target Name="CustomizeReferences" BeforeTargets="BeforeCompile" AfterTargets="FindReferenceAssembliesForReferences">
@kant2002
kant2002 / UnmanagedType.cs
Created March 23, 2020 22:00
Unmanaged constraint
namespace System.Runtime.InteropServices
{
public class UnmanagedType { }
}
@kant2002
kant2002 / RawCalliHelper.cs
Created March 23, 2020 21:58
CoreRT Calli helper
[System.Runtime.InteropServices.McgIntrinsicsAttribute]
internal class RawCalliHelper
{
public static unsafe ulong StdCall<T, U, W, X>(IntPtr pfn, T* arg1, U* arg2, W* arg3, X* arg4) where T : unmanaged where U : unmanaged where W : unmanaged where X : unmanaged
{
// This will be filled in by an IL transform
return 0;
}
public static unsafe ulong StdCall<T, U, W, X>(IntPtr pfn, T arg1, U* arg2, W* arg3, X* arg4) where T : struct where U : unmanaged where W : unmanaged where X : unmanaged
{
@kant2002
kant2002 / EfiApplication.cs
Created March 23, 2020 21:44
CoreRT UEFI startup code
public unsafe static class EfiApplication
{
[System.Runtime.RuntimeExport("EfiMain")]
unsafe static long EfiMain(IntPtr imageHandle, EFI_SYSTEM_TABLE* systemTable)
{
EfiRuntimeHost.Initialize(systemTable);
Console.Clear();
Game.Main();
@kant2002
kant2002 / EFI_SIMPLE_TEXT_INPUT_PROTOCOL.cs
Created March 23, 2020 21:39
How to wrap UEFI functions
[StructLayout(LayoutKind.Sequential)]
public unsafe readonly struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL
{
private readonly IntPtr _reset;
private readonly IntPtr _readKeyStroke;
public readonly IntPtr WaitForKey;
public void Reset(void* handle, bool ExtendedVerification)
{
@kant2002
kant2002 / Console.cs
Created March 23, 2020 21:33
Trivial Port of Console operations
public unsafe static ConsoleColor ForegroundColor
{
set
{
s_consoleAttribute = (ushort)value;
uint color = s_consoleAttribute;
EfiRuntimeHost.SystemTable->ConOut->SetAttribute(EfiRuntimeHost.SystemTable->ConOut, color);
}
}
@kant2002
kant2002 / EfiRuntimeHost.cs
Last active March 23, 2020 21:26
UEFI in CoreRT
public unsafe static class EfiRuntimeHost
{
public static EFI_SYSTEM_TABLE* SystemTable { get; private set; }
public static void Initialize(EFI_SYSTEM_TABLE* systemTable)
{
SystemTable = systemTable;
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\"/>
</packageSources>
</configuration>