Skip to content

Commit

Permalink
🚀 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ascpixi committed Aug 30, 2023
1 parent 30c06d4 commit 2e49290
Show file tree
Hide file tree
Showing 74 changed files with 4,074 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tools/*.exe


## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down
Empty file added readme.md
Empty file.
3 changes: 3 additions & 0 deletions shaderpkg.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
"./tools/shader_minifier.exe" -o compressed.glsl --format text --smoothstep --aggressive-inlining %1
"./src/ShaderCompressor/bin/x64/Release/ShaderCompressor.exe" minified.glsl compressed.txt
50 changes: 50 additions & 0 deletions src/BFlat.ZeroLib/BFlat.ZeroLib.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>5898fe8d-6758-42d0-9303-2aeaae32c47b</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>BFlat.ZeroLib</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Internal\Startup.Efi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\Startup.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\Startup.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\Stubs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\AppContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Array.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Attribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Console.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Console.Efi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Console.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Console.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Delegate.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Enum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Efi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Nullable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Object.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Primitives.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ReadOnlySpan.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ReflectionAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\RuntimeHandles.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ClassConstructorRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\CompilerAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\Unsafe.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\InteropAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\String.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Thread.Efi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Thread.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Thread.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Type.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ValueTuple.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ValueType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UnmanagedExports.cs" />
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions src/BFlat.ZeroLib/BFlat.ZeroLib.shproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>5898fe8d-6758-42d0-9303-2aeaae32c47b</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="BFlat.ZeroLib.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
172 changes: 172 additions & 0 deletions src/BFlat.ZeroLib/Internal/Startup.Efi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// bflat minimal runtime library
// Copyright (C) 2021-2022 Michal Strehovsky
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#if UEFI

using System;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Internal.Runtime.CompilerHelpers
{
unsafe partial class StartupCodeHelpers
{
internal static EFI_SYSTEM_TABLE* s_efiSystemTable;

[RuntimeImport("*", "__managed__Main")]
[MethodImpl(MethodImplOptions.InternalCall)]
static extern int ManagedMain(int argc, char** argv);

[RuntimeExport("EfiMain")]
static long EfiMain(IntPtr imageHandle, EFI_SYSTEM_TABLE* systemTable)
{
s_efiSystemTable = systemTable;
ManagedMain(0, null);

while (true) ;
}

internal static unsafe void InitializeCommandLineArgsW(int argc, char** argv)
{
// argc and argv are garbage because EfiMain didn't pass any
}

private static string[] GetMainMethodArguments()
{
return new string[0];
}
}

[StructLayout(LayoutKind.Sequential)]
struct EFI_HANDLE
{
private IntPtr _handle;
}

[StructLayout(LayoutKind.Sequential)]
unsafe readonly struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
{
private readonly IntPtr _pad0;
public readonly delegate* unmanaged<void*, char*, void*> OutputString;
private readonly IntPtr _pad1;
private readonly IntPtr _pad2;
private readonly IntPtr _pad3;
public readonly delegate* unmanaged<void*, uint, void> SetAttribute;
private readonly IntPtr _pad4;
public readonly delegate* unmanaged<void*, uint, uint, void> SetCursorPosition;
}

[StructLayout(LayoutKind.Sequential)]
readonly struct EFI_INPUT_KEY
{
public readonly ushort ScanCode;
public readonly ushort UnicodeChar;
}

[StructLayout(LayoutKind.Sequential)]
unsafe readonly struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL
{
private readonly IntPtr _pad0;
public readonly delegate*<void*, EFI_INPUT_KEY*, ulong> ReadKeyStroke;
}

[StructLayout(LayoutKind.Sequential)]
readonly struct EFI_TABLE_HEADER
{
public readonly ulong Signature;
public readonly uint Revision;
public readonly uint HeaderSize;
public readonly uint Crc32;
public readonly uint Reserved;
}

[StructLayout(LayoutKind.Sequential)]
unsafe readonly struct EFI_SYSTEM_TABLE
{
public readonly EFI_TABLE_HEADER Hdr;
public readonly char* FirmwareVendor;
public readonly uint FirmwareRevision;
public readonly EFI_HANDLE ConsoleInHandle;
public readonly EFI_SIMPLE_TEXT_INPUT_PROTOCOL* ConIn;
public readonly EFI_HANDLE ConsoleOutHandle;
public readonly EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* ConOut;
public readonly EFI_HANDLE StandardErrorHandle;
public readonly EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* StdErr;
public readonly EFI_RUNTIME_SERVICES* RuntimeServices;
public readonly EFI_BOOT_SERVICES* BootServices;
}

[StructLayout(LayoutKind.Sequential)]
struct EFI_TIME
{
public ushort Year;
public byte Month;
public byte Day;
public byte Hour;
public byte Minute;
public byte Second;
public byte Pad1;
public uint Nanosecond;
public short TimeZone;
public byte Daylight;
public byte PAD2;
}

[StructLayout(LayoutKind.Sequential)]
unsafe readonly struct EFI_RUNTIME_SERVICES
{
public readonly EFI_TABLE_HEADER Hdr;
public readonly delegate*<EFI_TIME*, void*, ulong> GetTime;
}

[StructLayout(LayoutKind.Sequential)]
unsafe readonly struct EFI_BOOT_SERVICES
{
readonly EFI_TABLE_HEADER Hdr;
private readonly void* pad0;
private readonly void* pad1;
private readonly void* pad2;
private readonly void* pad3;
private readonly void* pad4;
public readonly delegate*<int, nint, void**, ulong> AllocatePool;
private readonly void* pad6;
private readonly void* pad7;
private readonly void* pad8;
private readonly void* pad9;
private readonly void* pad10;
private readonly void* pad11;
private readonly void* pad12;
private readonly void* pad13;
private readonly void* pad14;
private readonly void* pad15;
private readonly void* pad16;
private readonly void* pad17;
private readonly void* pad18;
private readonly void* pad19;
private readonly void* pad20;
private readonly void* pad21;
private readonly void* pad22;
private readonly void* pad23;
private readonly void* pad24;
private readonly void* pad25;
private readonly void* pad26;
private readonly void* pad27;
public readonly delegate*<uint, ulong> Stall;
}
}

#endif
49 changes: 49 additions & 0 deletions src/BFlat.ZeroLib/Internal/Startup.Unix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// bflat minimal runtime library
// Copyright (C) 2021-2022 Michal Strehovsky
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#if LINUX

using System;
using System.Runtime;
using System.Runtime.InteropServices;

namespace Internal.Runtime.CompilerHelpers
{
unsafe partial class StartupCodeHelpers
{
static int s_argc;
static sbyte** s_argv;

internal static unsafe void InitializeCommandLineArgs(int argc, sbyte** argv)
{
s_argc = argc;
s_argv = argv;
}

private static string[] GetMainMethodArguments()
{
string[] args = new string[s_argc - 1];
for (int i = 1; i < s_argc; ++i)
{
args[i - 1] = new string(s_argv[i]);
}

return args;
}
}
}

#endif
54 changes: 54 additions & 0 deletions src/BFlat.ZeroLib/Internal/Startup.Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// bflat minimal runtime library
// Copyright (C) 2021-2022 Michal Strehovsky
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#if WINDOWS

using System;
using System.Runtime;
using System.Runtime.InteropServices;

namespace Internal.Runtime.CompilerHelpers
{
unsafe partial class StartupCodeHelpers
{
internal static unsafe void InitializeCommandLineArgsW(int argc, char** argv)
{
// argc and argv are a lie because CRT didn't start the process on Windows
}

private static string[] GetMainMethodArguments()
{
int argc;
char** argv = CommandLineToArgvW(GetCommandLineW(), &argc);

[DllImport("kernel32")]
static extern char* GetCommandLineW();

[DllImport("shell32")]
static extern char** CommandLineToArgvW(char* lpCmdLine, int* pNumArgs);

string[] args = new string[argc - 1];
for (int i = 1; i < argc; ++i)
{
args[i - 1] = new string(argv[i]);
}

return args;
}
}
}

#endif
Loading

0 comments on commit 2e49290

Please sign in to comment.