Skip to content

Commit

Permalink
BareMetal OS (#1074)
Browse files Browse the repository at this point in the history
* - Added Debug.Assert + Virtual Memory Manager
- Added unit test
  • Loading branch information
tgiphil committed Jul 5, 2023
1 parent 7771aa4 commit 41f2161
Show file tree
Hide file tree
Showing 30 changed files with 2,806 additions and 177 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ jobs:
with:
name: Nuget Packages
path: bin\nupkg

- name: Unit Test
run: dotnet test Source/Mosa.sln

windows-build-packaging:
name: Windows Build Packaging
needs: [windows-build, linux-build, generate-docs, windows-unit-testing, linux-unit-testing, windows-demo-testing, linux-demo-testing]
Expand Down Expand Up @@ -130,6 +132,8 @@ jobs:
run: dotnet restore Source/Mosa.Linux.sln
- name: Build
run: dotnet build Source/Mosa.Linux.sln
#- name: Unit Test
# run: dotnet test Source/Mosa.Linux.sln
- name: Store Build Artifact
uses: actions/upload-artifact@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<WarningLevel>2</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.analyzers" Version="1.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.BareMetal.ARMv8A32/PlatformPlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void PageTableEnable()
}

[Plug("Mosa.Kernel.BareMetal.Platform::PageTableMapVirtualAddressToPhysical")]
public static void PageTableMapVirtualAddressToPhysical(uint virtualAddress, uint physicalAddress, bool present = true)
public static void PageTableMapVirtualAddressToPhysical(Pointer virtualAddress, Pointer physicalAddress, bool present = true)
{
PageTable.MapVirtualAddressToPhysical(virtualAddress, physicalAddress, present);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.BareMetal.x64/PlatformPlug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void PageTableEnable()
}

[Plug("Mosa.Kernel.BareMetal.Platform::PageTableMapVirtualAddressToPhysical")]
public static void PageTableMapVirtualAddressToPhysical(uint virtualAddress, uint physicalAddress, bool present = true)
public static void PageTableMapVirtualAddressToPhysical(Pointer virtualAddress, Pointer physicalAddress, bool present = true)
{
PageTable.MapVirtualAddressToPhysical(virtualAddress, physicalAddress, present);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Mosa.Kernel.BareMetal.x86;
/// <summary>
/// GDT
/// </summary>
public struct GDTTable
public struct GDT
{
private Pointer Entry;
private Pointer GDTTable;

#region GDT Entry Offsets

Expand All @@ -28,24 +28,18 @@ internal struct GDTEntryOffset

#endregion GDT Entry Offsets

public GDTTable(Pointer entry)
{
Entry = entry;
}

public void Setup()
{
Entry.Store16(0, GDTEntryOffset.TotalSize * 3 - 1);
Entry.StorePointer(2, Entry + 6);
GDTTable = BootPageAllocator.AllocatePage(); // PhysicalPageAllocator is okay too

GDTTable.Store16(0, GDTEntryOffset.TotalSize * 3 - 1);
GDTTable.StorePointer(2, GDTTable + 6);

Set(0, 0, 0, 0, 0); // Null segment
Set(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); // Code segment
Set(2, 0, 0xFFFFFFFF, 0x92, 0xCF); // Data segment
}

public void Enable()
{
SetLgdt(Entry);
SetLgdt(GDTTable);
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand All @@ -58,7 +52,7 @@ private void SetLgdt(Pointer address)

private void Set(uint index, uint address, uint limit, byte access, byte granularity)
{
var entry = Entry + (6 + index * GDTEntryOffset.TotalSize);
var entry = GDTTable + (6 + index * GDTEntryOffset.TotalSize);

entry.Store16(GDTEntryOffset.BaseLow, (ushort)(address & 0xFFFF));
entry.Store8(GDTEntryOffset.BaseMiddle, (byte)((address >> 16) & 0xFF));
Expand Down

0 comments on commit 41f2161

Please sign in to comment.