Skip to content

Commit

Permalink
Merge pull request #2831 from CosmosOS/fix/acpi-overwrite
Browse files Browse the repository at this point in the history
Fix ACPI table overwrite
  • Loading branch information
valentinbreiz authored Dec 4, 2023
2 parents ca0897a + c5f7428 commit 977139e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
7 changes: 0 additions & 7 deletions source/Cosmos.Core/GCImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ public static unsafe void Init()
{
memPtr = (byte*)largestBlock->Address;
memLength = largestBlock->Length;
if ((uint)memPtr < CPU.GetEndOfKernel() + 1024)
{
memPtr = (byte*)CPU.GetEndOfKernel() + 1024;
memPtr += RAT.PageSize - (uint)memPtr % RAT.PageSize;
memLength = largestBlock->Length - ((uint)memPtr - (uint)largestBlock->Address);
memLength += RAT.PageSize - memLength % RAT.PageSize;
}
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions source/Cosmos.Core/Memory/RAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public static void Init(byte* aStartPtr, uint aSize)
uint xRatTotalSize = xRatPageCount * PageSize;
mRAT = RamStart + RamSize - xRatTotalSize;

if (mRAT > HeapEnd)
{
throw new Exception("mRAT is greater than heap. rattotalsize is "+xRatTotalSize);
}

// Mark empty pages as such in the RAT Table
for (byte* p = mRAT; p < mRAT + TotalPageCount - xRatPageCount; p++)
{
Expand Down
10 changes: 9 additions & 1 deletion source/Cosmos.Core/Multiboot/Multiboot2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public unsafe class Multiboot2
public static bool IsVBEAvailable => Framebuffer->Address != 753664; // Some kinda default number.
public static Framebuffer* Framebuffer { get; set; }
public static MemoryMap* MemoryMap { get; set; }
public static EFI64* EFI64 { get; set; }
public static EFI64* EFI64 { get; set; }
public static AcpiOld* AcpiOld { get; set; }
public static AcpiNew* AcpiNew { get; set; }

#endregion

Expand Down Expand Up @@ -59,6 +61,12 @@ public static void Init()
break;
case 12:
EFI64 = (EFI64*)Tag;
break;
case 14:
AcpiOld = (AcpiOld*)Tag;
break;
case 15:
AcpiNew = (AcpiNew*)Tag;
break;
default:
break;
Expand Down
37 changes: 37 additions & 0 deletions source/Cosmos.Core/Multiboot/Tags/AcpiNew.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Cosmos.Core.Multiboot.Tags
{
/// <summary>
/// Tag AcpiOld
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 44)]
public unsafe readonly struct AcpiNew
{
[FieldOffset(0)]
public readonly uint Type;
[FieldOffset(4)]
public readonly uint Size;
[FieldOffset(8)]
public readonly ulong Signature;
[FieldOffset(16)]
public readonly byte Checksum;
[FieldOffset(17)]
public readonly uint OEMID;
[FieldOffset(23)]
public readonly byte Revision;
[FieldOffset(24)]
public readonly uint RsdtAddress;
[FieldOffset(28)]
public readonly uint Length;
[FieldOffset(32)]
public readonly ulong XsdtAddress;
[FieldOffset(40)]
public readonly byte ExtendedChecksum;
}
}
31 changes: 31 additions & 0 deletions source/Cosmos.Core/Multiboot/Tags/AcpiOld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Cosmos.Core.Multiboot.Tags
{
/// <summary>
/// Tag AcpiOld
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 28)]
public unsafe readonly struct AcpiOld
{
[FieldOffset(0)]
public readonly uint Type;
[FieldOffset(4)]
public readonly uint Size;
[FieldOffset(8)]
public readonly ulong Signature;
[FieldOffset(16)]
public readonly byte Checksum;
[FieldOffset(17)]
public readonly uint OEMID;
[FieldOffset(23)]
public readonly byte Revision;
[FieldOffset(24)]
public readonly uint RsdtAddress;
}
}

0 comments on commit 977139e

Please sign in to comment.