Skip to content

Commit

Permalink
Some bug fixes (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnErrupTion committed Jun 4, 2023
1 parent 5a5dce2 commit 7e487d1
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Mosa.Demo.SVGAWorld.x86": {
"commandName": "Executable",
"executablePath": "..\\bin\\Mosa.Tool.Launcher.exe",
"commandLineArgs": "-autostart -include Include -vmware -output-map -output-asm -output-debug -vmdk -oMax Mosa.Demo.SVGAWorld.x86.dll",
"commandLineArgs": "-autostart -include Include -output-map -output-asm -output-debug -vmware-svga -oMax Mosa.Demo.SVGAWorld.x86.dll",
"workingDirectory": "..\\..\\bin"
}
}
Expand Down
13 changes: 7 additions & 6 deletions Source/Mosa.DeviceDriver/ISA/ACPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Mosa.Runtime;

namespace Mosa.DeviceDriver.ISA;

// Portions of this code are from Cosmos

//https://wiki.osdev.org/ACPI
Expand Down Expand Up @@ -116,7 +117,7 @@ public unsafe struct FADT
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct GenericAddressStructure
public struct GenericAddressStructure
{
public byte AddressSpace;
public byte BitWidth;
Expand All @@ -140,7 +141,7 @@ public unsafe struct XSDT
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct MADT
public struct MADT
{
public ACPISDTHeader h;

Expand All @@ -149,14 +150,14 @@ public unsafe struct MADT
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct MADTEntry
public struct MADTEntry
{
public byte Type;
public byte Length;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct ProcessorLocalAPICEntry
public struct ProcessorLocalAPICEntry
{
public MADTEntry Entry;

Expand All @@ -167,7 +168,7 @@ public unsafe struct ProcessorLocalAPICEntry
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct IOAPICEntry
public struct IOAPICEntry
{
public MADTEntry Entry;

Expand All @@ -179,7 +180,7 @@ public unsafe struct IOAPICEntry
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct LongLocalAPICEntry
public struct LongLocalAPICEntry
{
public MADTEntry Entry;

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.BareMetal.x86/GDTTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Mosa.Kernel.BareMetal.x86;
/// </summary>
public struct GDTTable
{
private readonly Pointer Entry;
private Pointer Entry;

#region GDT Entry Offsets

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.BareMetal.x86/PageTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Initialize()
}

// Clear the Page Tables
for (uint index = 0; index < 1024; index++)
for (uint index = 0; index < PhysicalPageAllocator.TotalPages; index++)
{
PageTables.Store32(index << 2, (index * Page.Size) | 0x04 | 0x02 | 0x01);
}
Expand Down
19 changes: 5 additions & 14 deletions Source/Mosa.Kernel.BareMetal/Boot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,21 @@ public static void EntryPoint()
Console.SetBackground(ConsoleColor.Blue);
Console.SetForground(ConsoleColor.White);
Console.ClearScreen();
Console.Write("Booting...");

Console.WriteLine("Initializing boot page allocator...");
BootPageAllocator.Setup();

Console.Write("1...");
Console.WriteLine("Initializing memory map...");
BootMemoryMap.Initialize();

Console.Write("3...");
BootMemoryMap.ImportPlatformMemoryMap();

Console.Write("2...");
BootMemoryMap.ImportMultibootV1MemoryMap();
BootMemoryMap.Dump();

//BootMemoryMap.Dump();

Console.Write("4...");
Console.WriteLine("Initializing physical page allocator...");
PhysicalPageAllocator.Setup();

Console.WriteLine("5...");
Console.WriteLine("Initializing page table...");
PageTable.Setup();

Console.WriteLine("6...");

while (true) { }
}

[Plug("Mosa.Runtime.StartUp::GarbageCollectionInitialization")]
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Kernel.BareMetal/BootMemory/BootMemoryMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void ImportMultibootV1MemoryMap()
if (Multiboot.MultibootV1.MemoryMapStart.IsNull)
return;

AvailableMemory = new Pointer(Multiboot.MultibootV1.MemoryUpper * 1024 + 1024 * 1024); // assuming all of lower memory
AvailableMemory = new Pointer(Multiboot.MultibootV1.MemoryUpper * 1024);

var memoryMapEnd = Multiboot.MultibootV1.MemoryMapStart + Multiboot.MultibootV1.MemoryMapLength;

Expand Down
7 changes: 0 additions & 7 deletions Source/Mosa.Kernel.BareMetal/PageTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ public static class PageTable
public static void Setup()
{
Platform.PageTableSetup();

Platform.PageTableInitialize();

// Unmap the first page for null pointer exceptions
MapVirtualAddressToPhysical(0x0, 0x0, false);

Console.WriteLine("Mosa.Kernel.BareMetal.PageTable.Setup:1");

while (true) { } // Platform.PageTableEnable() crashes

Platform.PageTableEnable();

Console.WriteLine("Mosa.Kernel.BareMetal.PageTable.Setup:2");
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Source/Mosa.Kernel.BareMetal/PhysicalPageAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Mosa.Kernel.BareMetal;

public static class PhysicalPageAllocator
{
public static uint TotalPages { get; private set; }

private static BitMapIndexTable BitMapIndexTable;

private static Pointer AvailableMemory;

private static uint TotalPages;

private static uint MinimumAvailablePage;
private static uint MaximumAvailablePage;
private static uint MinimumReservedPage;
Expand All @@ -27,7 +27,7 @@ public static void Setup()

AvailableMemory = BootMemoryMap.GetAvailableMemory();

TotalPages = (uint)(AvailableMemory.ToInt64() / Page.Size);
TotalPages = (uint)(AvailableMemory.ToUInt64() / Page.Size);
var bitMapCount = TotalPages / (Page.Size * 8);

for (uint i = 0; i < bitMapCount; i++)
Expand Down
12 changes: 12 additions & 0 deletions Source/Mosa.Korlib/System/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ public unsafe string ToLower()
// TODO: Seems some compiler bugs prevent the original algorithms from working...
public unsafe static string Concat(string a, string b)
{
a ??= Empty;
b ??= Empty;

string result = InternalAllocateString(a.length + b.length);
char* chars = result.first_char;

Expand All @@ -490,6 +493,10 @@ public unsafe static string Concat(string a, string b)

public unsafe static string Concat(string a, string b, string c)
{
a ??= Empty;
b ??= Empty;
c ??= Empty;

string result = InternalAllocateString(a.length + b.length + c.length);
char* chars = result.first_char;

Expand Down Expand Up @@ -517,6 +524,11 @@ public unsafe static string Concat(string a, string b, string c)

public unsafe static string Concat(string a, string b, string c, string d)
{
a ??= Empty;
b ??= Empty;
c ??= Empty;
d ??= Empty;

string result = InternalAllocateString(a.length + b.length + c.length + d.length);
char* chars = result.first_char;

Expand Down
59 changes: 5 additions & 54 deletions Source/Mosa.Utility.Launcher/AppLocationsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ namespace Mosa.Utility.Launcher;

public static class AppLocationsSettings
{
private static readonly string MosaEnvironmentalVariable = Environment.GetEnvironmentVariable("MOSA");
private static readonly string ProgramFiles86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
private static readonly string ProgramFiles = Environment.GetEnvironmentVariable("ProgramFiles");
private static readonly string UserProfile = Environment.GetEnvironmentVariable("UserProfile");
private static readonly string CurrentDirectory = Directory.GetCurrentDirectory();
private static readonly string AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
private static readonly string MosaTools = @"%ProgramFiles(x86)%\MOSA-Project\Tools";

private static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static string[] LinuxDirectories = new string[] { "/bin", "/usr/bin" };
private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
private static readonly string[] LinuxDirectories = new string[] { "/bin", "/usr/bin" };

public static Settings GetAppLocations()
{
Expand Down Expand Up @@ -55,9 +53,6 @@ private static string FindQemu()
@"%APPDIR%\Tools\qemu",
@"%APPDIR%\..\Tools\qemu",

@"%MOSA%\Tools\qemu",
@"%MOSATOOLS%\qemu",

@"%ProgramFiles%\qemu",
@"%ProgramFiles(x86)%\qemu",
})
Expand All @@ -75,9 +70,6 @@ private static string FindGDB()
@"%APPDIR%\Tools\gdb",
@"%APPDIR%\..\Tools\gdb",

@"%MOSA%\Tools\gdb",
@"%MOSATOOLS%\gdb",

@"C:\cygwin64\bin",
@"C:\mingw64\bin",
@"C:\cygwin\bin",
Expand All @@ -98,9 +90,6 @@ private static string FindMkisofs()
@"%APPDIR%\Tools\mkisofs",
@"%APPDIR%\..\Tools\mkisofs",

@"%MOSA%\Tools\mkisofs",
@"%MOSATOOLS%\mkisofs",

@"%ProgramFiles%\VMware\VMware Player",
@"%ProgramFiles(x86)%\VMware\VMware Player",
@"%ProgramFiles%\cdrtools",
Expand All @@ -118,10 +107,7 @@ private static string FindNdisasm()
@"%CURRENT%\Tools\ndisasm",

@"%APPDIR%\Tools\ndisasm",
@"%APPDIR%\..\Tools\ndisasm",

@"%MOSA%\Tools\ndisasm",
@"%MOSATOOLS%\ndisasm",
@"%APPDIR%\..\Tools\ndisasm"
})
: TryFind("ndisasm", LinuxDirectories);
}
Expand Down Expand Up @@ -179,10 +165,7 @@ private static string FindBochs()
@"%CURRENT%\Tools\Bochs",

@"%APPDIR%\Tools\Bochs",
@"%APPDIR%\..\Tools\Bochs",

@"%MOSA%\Tools\Bochs",
@"%MOSATOOLS%\Bochs",
@"%APPDIR%\..\Tools\Bochs"
})
: TryFind("bochs", LinuxDirectories);
}
Expand All @@ -199,9 +182,6 @@ private static string FindQemuImg()
@"%APPDIR%\Tools\qemu",
@"%APPDIR%\..\Tools\qemu",

@"%MOSA%\Tools\qemu",
@"%MOSATOOLS%\qemu",

@"%ProgramFiles%\qemu",
@"%ProgramFiles(x86)%\qemu",
@"%ProgramFiles(x86)%\Mosa-Project\Tools\qemu",
Expand All @@ -221,11 +201,6 @@ private static string FindQemuBIOS()
@"%APPDIR%\Tools\qemu\share",
@"%APPDIR%\..\Tools\qemu\share",

@"%MOSA%\qemu",
@"%MOSA%\qemu\share",
@"%MOSATOOLS%\qemu",
@"%MOSATOOLS%\qemu\share",

@"%ProgramFiles%\qemu",
@"%ProgramFiles%\qemu\share",
@"%ProgramFiles(x86)%\qemu",
Expand All @@ -250,12 +225,6 @@ private static string FindQemuEDK2X86()
@"%APPDIR%\Tools\qemu\share",
@"%APPDIR%\..\Tools\qemu\share",

@"%MOSA%\qemu",
@"%MOSA%\qemu\share",

@"%MOSATOOLS%\qemu",
@"%MOSATOOLS%\qemu\share",

@"%ProgramFiles%\qemu",
@"%ProgramFiles%\qemu\share",
@"%ProgramFiles(x86)%\qemu",
Expand All @@ -280,16 +249,10 @@ private static string FindQemuEDK2X64()
@"%APPDIR%\Tools\qemu\share",
@"%APPDIR%\..\Tools\qemu\share",

@"%MOSA%\qemu",
@"%MOSA%\qemu\share",

@"%MOSATOOLS%\qemu",
@"%MOSATOOLS%\qemu\share",

@"%ProgramFiles%\qemu",
@"%ProgramFiles%\qemu\share",
@"%ProgramFiles(x86)%\qemu",
@"%ProgramFiles(x86)%\qemu\share",
@"%ProgramFiles(x86)%\qemu\share"
})
: TryFind("edk2-x86_64-code.fd",
new string[] {
Expand All @@ -310,12 +273,6 @@ private static string FindQemuEDK2ARM()
@"%APPDIR%\Tools\qemu\share",
@"%APPDIR%\..\Tools\qemu\share",

@"%MOSA%\qemu",
@"%MOSA%\qemu\share",

@"%MOSATOOLS%\qemu",
@"%MOSATOOLS%\qemu\share",

@"%ProgramFiles%\qemu",
@"%ProgramFiles%\qemu\share",
@"%ProgramFiles(x86)%\qemu",
Expand All @@ -340,12 +297,6 @@ private static void Set(Settings settings, string name, string value)

public static string ReplaceWithParameters(string directory)
{
if (!string.IsNullOrWhiteSpace(MosaEnvironmentalVariable))
directory = directory.Replace("%MOSA%", MosaEnvironmentalVariable);

if (!string.IsNullOrWhiteSpace(MosaTools))
directory = directory.Replace("%MOSATOOLS%", MosaTools);

if (!string.IsNullOrWhiteSpace(ProgramFiles))
directory = directory.Replace("%PROGRAMFILES%", ProgramFiles);

Expand Down

0 comments on commit 7e487d1

Please sign in to comment.