Skip to content

Commit

Permalink
Update efi constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nifanfa committed Feb 1, 2023
1 parent 303baae commit 513b799
Show file tree
Hide file tree
Showing 9 changed files with 900 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static unsafe void InitializeStatics(IntPtr rgnStart, IntPtr rgnEnd)
IntPtr pPreInitDataAddr = *(pBlock + 1);
fixed (byte* p = &obj.GetRawData())
{
memcpy(p, (byte*)pPreInitDataAddr, obj.GetRawDataSize());
InternalCalls.memcpy(p, (byte*)pPreInitDataAddr, obj.GetRawDataSize());
}
}

Expand Down
12 changes: 12 additions & 0 deletions CoreLib/System/Runtime/InternalCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ internal static int RhEndNoGCRegion()
internal static extern IntPtr RhHandleSet(IntPtr handle, object value);
*/

[RuntimeExport("memset")]
public static unsafe void memset(byte* ptr, byte c, ulong count)
{
for (ulong i = 0; i < count; i++) ptr[i] = c;
}

[RuntimeExport("memcpy")]
public static unsafe void memcpy(byte* dst, byte* src, ulong count)
{
for (ulong i = 0; i < count; i++) dst[i] = src[i];
}

//
// internal calls for allocation
//
Expand Down
6 changes: 3 additions & 3 deletions CoreLib/System/Runtime/RuntimeExports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static unsafe object RhBox(EEType* pEEType, ref byte data)
{
fixed (byte* pFields = &result.GetRawData())
fixed (byte* pData = &dataAdjustedForNullable)
efi.memcpy(pFields, pData, pEEType->ValueTypeSize);
InternalCalls.memcpy(pFields, pData, pEEType->ValueTypeSize);
}

return result;
Expand Down Expand Up @@ -266,7 +266,7 @@ public static unsafe void RhUnbox(object obj, ref byte data, EEType* pUnboxToEET

// Set HasValue to false and clear the value (in case there were GC references we wish to stop reporting).
fixed (byte* pdata = &data)
efi.memset(pdata, 0, pUnboxToEEType->ValueTypeSize);
InternalCalls.memset(pdata, 0, pUnboxToEEType->ValueTypeSize);
/*
InternalCalls.RhpInitMultibyte(
ref data,
Expand Down Expand Up @@ -308,7 +308,7 @@ public static unsafe void RhUnbox(object obj, ref byte data, EEType* pUnboxToEET
// Copy the boxed fields into the new location.
fixed (byte* pData = &data)
fixed (byte* pFields = &fields)
efi.memcpy(pData, pFields, pEEType->ValueTypeSize);
InternalCalls.memcpy(pData, pFields, pEEType->ValueTypeSize);
}
}

Expand Down
2 changes: 1 addition & 1 deletion CoreLib/System/Runtime/RuntimeImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal static unsafe void RhBulkMoveWithWriteBarrier(ref byte dmem, ref byte s
{
fixed (byte* pdst = &dmem)
fixed (byte* psrc = &smem)
efi.memcpy(pdst, psrc, size);
InternalCalls.memcpy(pdst, psrc, size);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion CoreLib/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static unsafe string Ctor(char* ptr, int index, int length)

fixed (char* c = &s._firstChar)
{
memcpy((byte*)c, (byte*)start, (ulong)length * sizeof(char));
InternalCalls.memcpy((byte*)c, (byte*)start, (ulong)length * sizeof(char));
c[length] = '\0';
}

Expand Down
901 changes: 882 additions & 19 deletions uefi-cs/efi.cs

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions uefi-cs/efiapi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ Revision History

using System.Runtime.InteropServices;

public partial class efi
{
public const uint EVT_TIMER = 0x80000000;
public const uint EVT_RUNTIME = 0x40000000;
public const uint EVT_RUNTIME_CONTEXT = 0x20000000;

public const uint EVT_NOTIFY_WAIT = 0x00000100;
public const uint EVT_NOTIFY_SIGNAL = 0x00000200;

public const uint EVT_SIGNAL_EXIT_BOOT_SERVICES = 0x00000201;
public const uint EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE = 0x60000202;

public const uint EVT_EFI_SIGNAL_MASK = 0x000000FF;
public const uint EVT_EFI_SIGNAL_MAX = 4;

public const uint TPL_APPLICATION = 4;
public const uint TPL_CALLBACK = 8;
public const uint TPL_NOTIFY = 16;
public const uint TPL_HIGH_LEVEL = 31;
}

public enum EFI_TIMER_DELAY
{
TimerCancel,
Expand Down Expand Up @@ -85,16 +64,6 @@ public unsafe struct EFI_LOADED_IMAGE
}
*/

public partial class efi
{
public const uint EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL = 0x00000001;
public const uint EFI_OPEN_PROTOCOL_GET_PROTOCOL = 0x00000002;
public const uint EFI_OPEN_PROTOCOL_TEST_PROTOCOL = 0x00000004;
public const uint EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER = 0x00000008;
public const uint EFI_OPEN_PROTOCOL_BY_DRIVER = 0x00000010;
public const uint EFI_OPEN_PROTOCOL_EXCLUSIVE = 0x00000020;
}

[StructLayout(LayoutKind.Sequential)]
public unsafe struct EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
{
Expand Down
35 changes: 0 additions & 35 deletions uefi-cs/efierr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,3 @@ Revision History
--*/

public partial class efi
{
public const ulong EFI_SUCCESS = 0;
public const ulong EFI_LOAD_ERROR = 0x8000000000000000 | 1;
public const ulong EFI_INVALID_PARAMETER = 0x8000000000000000 | 2;
public const ulong EFI_UNSUPPORTED = 0x8000000000000000 | 3;
public const ulong EFI_BAD_BUFFER_SIZE = 0x8000000000000000 | 4;
public const ulong EFI_BUFFER_TOO_SMALL = 0x8000000000000000 | 5;
public const ulong EFI_NOT_READY = 0x8000000000000000 | 6;
public const ulong EFI_DEVICE_ERROR = 0x8000000000000000 | 7;
public const ulong EFI_WRITE_PROTECTED = 0x8000000000000000 | 8;
public const ulong EFI_OUT_OF_RESOURCES = 0x8000000000000000 | 9;
public const ulong EFI_VOLUME_CORRUPTED = 0x8000000000000000 | 10;
public const ulong EFI_VOLUME_FULL = 0x8000000000000000 | 11;
public const ulong EFI_NO_MEDIA = 0x8000000000000000 | 12;
public const ulong EFI_MEDIA_CHANGED = 0x8000000000000000 | 13;
public const ulong EFI_NOT_FOUND = 0x8000000000000000 | 14;
public const ulong EFI_ACCESS_DENIED = 0x8000000000000000 | 15;
public const ulong EFI_NO_RESPONSE = 0x8000000000000000 | 16;
public const ulong EFI_NO_MAPPING = 0x8000000000000000 | 17;
public const ulong EFI_TIMEOUT = 0x8000000000000000 | 18;
public const ulong EFI_NOT_STARTED = 0x8000000000000000 | 19;
public const ulong EFI_ALREADY_STARTED = 0x8000000000000000 | 20;
public const ulong EFI_ABORTED = 0x8000000000000000 | 21;
public const ulong EFI_ICMP_ERROR = 0x8000000000000000 | 22;
public const ulong EFI_TFTP_ERROR = 0x8000000000000000 | 23;
public const ulong EFI_PROTOCOL_ERROR = 0x8000000000000000 | 24;
public const ulong EFI_INCOMPATIBLE_VERSION = 0x8000000000000000 | 25;
public const ulong EFI_SECURITY_VIOLATION = 0x8000000000000000 | 26;
public const ulong EFI_CRC_ERROR = 0x8000000000000000 | 27;
public const ulong EFI_END_OF_MEDIA = 0x8000000000000000 | 28;
public const ulong EFI_END_OF_FILE = 0x8000000000000000 | 31;
public const ulong EFI_INVALID_LANGUAGE = 0x8000000000000000 | 32;
public const ulong EFI_COMPROMISED_DATA = 0x8000000000000000 | 33;
}
17 changes: 0 additions & 17 deletions uefi-cs/efiprot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,6 @@ public unsafe struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
public readonly delegate* unmanaged<EFI_SIMPLE_FILE_SYSTEM_PROTOCOL*, EFI_FILE_HANDLE**, EFI_STATUS> OpenVolume;
}

public partial class efi
{
// Open modes
public const ulong EFI_FILE_MODE_READ = 0x0000000000000001;
public const ulong EFI_FILE_MODE_WRITE = 0x0000000000000002;
public const ulong EFI_FILE_MODE_CREATE = 0x8000000000000000;

// File attributes
public const ulong EFI_FILE_READ_ONLY = 0x0000000000000001;
public const ulong EFI_FILE_HIDDEN = 0x0000000000000002;
public const ulong EFI_FILE_SYSTEM = 0x0000000000000004;
public const ulong EFI_FILE_RESERVIED = 0x0000000000000008;
public const ulong EFI_FILE_DIRECTORY = 0x0000000000000010;
public const ulong EFI_FILE_ARCHIVE = 0x0000000000000020;
public const ulong EFI_FILE_VALID_ATTR = 0x0000000000000037;
}

[StructLayout(LayoutKind.Sequential)]
public unsafe struct EFI_FILE_IO_TOKEN
{
Expand Down

0 comments on commit 513b799

Please sign in to comment.