Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Remove Debug Output Option #2439

Merged
merged 31 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0691806
Driver Optimize And added fast boost option
TheFocusMan Oct 4, 2022
e329af5
Reqested changes
TheFocusMan Oct 5, 2022
b9bb435
Reqested Changes
TheFocusMan Oct 5, 2022
100996f
Update CPU.cs
TheFocusMan Oct 5, 2022
c3ffbb9
Revet Changes
TheFocusMan Oct 5, 2022
47fe5f7
Merge branch 'master' into master
TheFocusMan Oct 6, 2022
9ff43f2
Update CosmosDebugEnginePackage.cs
TheFocusMan Oct 6, 2022
dd03d64
Opps
TheFocusMan Oct 6, 2022
dd38d88
Merge branch 'master' into master
TheFocusMan Oct 6, 2022
e02cef1
Rename
TheFocusMan Oct 6, 2022
0fc130c
Rename
TheFocusMan Oct 7, 2022
7040ae2
More write
TheFocusMan Oct 7, 2022
e2485e9
Added infomation
TheFocusMan Oct 8, 2022
eb4b42f
Fixed desciptions
TheFocusMan Oct 8, 2022
b9cd14d
Clean
TheFocusMan Oct 8, 2022
e8143c2
.
TheFocusMan Oct 8, 2022
755a115
.
TheFocusMan Oct 8, 2022
3f22f1d
.
TheFocusMan Oct 8, 2022
36fe9d0
Update Startup.md
TheFocusMan Oct 9, 2022
20f3e93
Merge branch 'master' into master
TheFocusMan Oct 11, 2022
b65d7ea
Update Kernel.cs
TheFocusMan Oct 11, 2022
06b92af
Update Kernel.cs
TheFocusMan Oct 11, 2022
38536e7
Update Kernel.cs
TheFocusMan Oct 11, 2022
c8429ec
Update Kernel.cs
TheFocusMan Oct 11, 2022
82a704e
Rephrase
TheFocusMan Oct 11, 2022
4c8387a
Update Startup.md
TheFocusMan Oct 11, 2022
f4f2d5c
Update ATAPI.cs
TheFocusMan Oct 11, 2022
0fa1a84
Update Disk.cs
TheFocusMan Oct 11, 2022
3bc4e00
Added a test for delete partition
TheFocusMan Oct 11, 2022
ed0bf46
Merge branch 'master' of https://github.com/TheFocusMan/Cosmos
TheFocusMan Oct 11, 2022
fe3c3cf
Delete AdvancedObject.cs
TheFocusMan Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Docs/articles/Kernel/Startup.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
On startup, there is some hand-coded assembly that runs before the Cosmos layer kicks in. From there, the C# entry point Cosmos.System.Kernel.Start() is called.

Cosmos.System.Kernel is an abstract class that forms the Cosmos framework upon which your OS is built upon.

You can override the Kernel.Start() method to suppress the standard Cosmos boot routines.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static void Execute(Debugger mDebugger)
Directory.CreateDirectory(@"0:\SYS\");
Assert.IsTrue(Directory.GetDirectories(@"0:\SYS\").Length == 0, "Can create a directory and its content is emtpy");

ourDisk.DeletePartition(0);
mDebugger.Send("Partion is Deleted");

mDebugger.Send("END TEST");
}
}
Expand Down
3 changes: 3 additions & 0 deletions source/Cosmos.Build.Tasks/IL2CPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class IL2CPU : ToolTask

public bool CompileVBEMultiboot { get; set; }

public bool RemoveBootDebugOutput { get; set; }

public string VBEResolution { get; set; }

#endregion
Expand Down Expand Up @@ -97,6 +99,7 @@ protected override string GenerateResponseFileCommands()
["IgnoreDebugStubAttribute"] = IgnoreDebugStubAttribute.ToString(),
["CompileVBEMultiboot"] = CompileVBEMultiboot.ToString(),
["VBEResolution"] = VBEResolution.ToString(),
["RemoveBootDebugOutput"] = RemoveBootDebugOutput.ToString()
}.ToList();

foreach (var reference in References)
Expand Down
3 changes: 3 additions & 0 deletions source/Cosmos.Build.Tasks/build/Cosmos.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@

<CompileVBEMultiboot Condition="'$(CompileVBEMultiboot)' == ''">False</CompileVBEMultiboot>


<RemoveBootDebugOutput Condition="'$(RemoveBootDebugOutput)' == ''">ELF</RemoveBootDebugOutput>

</PropertyGroup>

<PropertyGroup>
Expand Down
10 changes: 10 additions & 0 deletions source/Cosmos.Core/CPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public static uint GetAmountOfRAM()
[PlugMethod(PlugRequired = true)]
public static uint GetEBPValue() => throw null;

/// <summary>
/// Get position of current ESP register
/// </summary>
/// <returns></returns>
[PlugMethod(PlugRequired = true)]
internal static uint GetESPValue() => throw null;

[PlugMethod(PlugRequired = true)]
internal static void SetESPValue(uint val) => throw null;

/// <summary>
/// Get the address at which the stack starts
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions source/Cosmos.Core_Asm/CPU/CPUGetESPValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XSharp;
using XSharp.Assembler;
using static XSharp.XSRegisters;

namespace Cosmos.Core_Asm
{
public class CPUGetESPValue : AssemblerMethod
{
public override void AssembleNew(Assembler aAssembler, object aMethodInfo)
{
XS.Push(ESP);
}
}
}
20 changes: 20 additions & 0 deletions source/Cosmos.Core_Asm/CPU/CPUSetESPValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XSharp;
using XSharp.Assembler;
using static XSharp.XSRegisters;

namespace Cosmos.Core_Asm
{
public class CPUSetESPValue : AssemblerMethod
{
public override void AssembleNew(Assembler aAssembler, object aMethodInfo)
{
XS.Set(EAX, EBP,sourceDisplacement:8);
XS.Set(ESP,EAX,destinationDisplacement:4);
}
}
}
7 changes: 7 additions & 0 deletions source/Cosmos.Core_Asm/CPUImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public class CPUImpl
public static uint GetEndOfKernel() => throw null;
[PlugMethod(Assembler = typeof(CPUGetEBPValue))]
public static uint GetEBPValue() => throw null;

[PlugMethod(Assembler = typeof(CPUGetESPValue))]
public static uint GetESPValue() => throw null;

[PlugMethod(Assembler = typeof(CPUSetESPValue))]
public static void SetESPValue(uint val) => throw null;

[PlugMethod(Assembler = typeof(CPUGetStackStart))]
public static uint GetStackStart() => throw null;
[PlugMethod(Assembler = typeof(CPUZeroFillAsm))]
Expand Down
51 changes: 49 additions & 2 deletions source/Cosmos.HAL2/BlockDevice/ATAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Cosmos.HAL.BlockDevice;
using System;
using System.Collections.Generic;
using System.IO;
using static Cosmos.HAL.BlockDevice.Ata;
using static Cosmos.HAL.BlockDevice.ATA_PIO;

Expand All @@ -22,15 +23,20 @@ public class ATAPI : BlockDevice
/// <summary>
/// Is the ATAPI drive on the Primary or Secondary channel of the IDE controller.
/// </summary>
private bool Primary { get; set; }
public bool Primary { get; private set; }

/// <summary>
/// Get The max lba
/// </summary>
public ulong MaxLBA { get; private set; }

/// <summary>
/// Each IDE channel also has a Master or a Slave. This just gets or sets which position it is at.
/// </summary>
private BusPositionEnum BusPosition { get; set; }
public override BlockDeviceType Type => BlockDeviceType.RemovableCD;

private ATA_PIO device;
public ATA_PIO device;

/// <summary>
/// Collection of predefined command packets to be sent to the ATAPI device
Expand All @@ -39,6 +45,7 @@ public class PacketCommands
{
public static byte[] ReadSector = { (byte)ATA_PIO.Cmd.Read, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 };
public static byte[] Unload = { (byte)ATA_PIO.Cmd.Eject, 0, 0, 0, 0x02, 0, 0, 0, 0, 0, 0, 0 };
public static byte[] GetMaxLBA = { 0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
}

/// <summary>
Expand All @@ -56,6 +63,7 @@ public ATAPI(ATA_PIO parentDevice)
var p = BusPosition == BusPositionEnum.Master;
Ata.AtaDebugger.Send("ATAPI: Primary controller: " + this.Primary + " Bus postion: IsMaster: " + p);

MaxLBA = GetMaxLBA();
Init();
}

Expand Down Expand Up @@ -264,5 +272,44 @@ private void CheckForErrors()
//throw new Exception("ATAPI DRQ not set");
}
}
/// <summary>
/// The function returns the max LBA value of the ATAPI device. Code is based on https://forum.osdev.org/viewtopic.php?f=1&t=14604"
/// </summary>
/// <returns>The maximum LBA</returns>
private ulong GetMaxLBA()
{
//Select the ATAPI device
IO.DeviceSelect.Byte = (byte)(((byte)BusPosition << 4) +(1 << 6));

//Wait for the select complete
IO.Wait();

// get max lba
ulong Max_LBA;
if (device.LBA48Bit)
{
device.SendCmd(Cmd.ReadNativeMaxAdressExt,false); // says not check errors

Max_LBA = (ulong)IO.LBA0.Byte;
Max_LBA += (ulong)(IO.LBA1.Byte << 8);
Max_LBA += (ulong)(IO.LBA2.Byte << 16);

IO.Control.Byte = 0x80; // Set HOB to 1

Max_LBA += (ulong)(IO.LBA0.Byte << 24);
Max_LBA += (ulong)(IO.LBA1.Byte << 32);
Max_LBA += (ulong)(IO.LBA2.Byte << 40);
}
else
{
device.SendCmd(Cmd.ReadNativeMaxAdress,false); // says not check errors

Max_LBA = (ulong)(IO.LBA0.Byte);
Max_LBA += (ulong)(IO.LBA1.Byte << 8);
Max_LBA += (ulong)(IO.LBA2.Byte << 16);
Max_LBA += ((ulong)(IO.DeviceSelect.Byte & 0xF) << 24);
}
return Max_LBA;
}
}
}
12 changes: 7 additions & 5 deletions source/Cosmos.HAL2/BlockDevice/ATA_PIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public string ModelNo
{
get { return mModelNo; }
}
#endregion
#region Enums
[Flags]
#endregion
#region Enums
[Flags]
public enum Status : byte
{
None = 0x00,
Expand Down Expand Up @@ -102,6 +102,7 @@ public enum Cmd : byte
ReadPioExt = 0x24,
ReadDma = 0xC8,
ReadDmaExt = 0x25,
ReadNativeMaxAdressExt =0x27,
WritePio = 0x30,
WritePioExt = 0x34,
WriteDma = 0xCA,
Expand All @@ -112,8 +113,9 @@ public enum Cmd : byte
IdentifyPacket = 0xA1,
Identify = 0xEC,
Read = 0xA8,
Eject = 0x1B
}
Eject = 0x1B,
ReadNativeMaxAdress = 0xF8
}

public enum Ident : byte
{
Expand Down
1 change: 0 additions & 1 deletion source/Cosmos.HAL2/BlockDevice/IDE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ private static void Initialize(Ata.ControllerIdEnum aControllerID, Ata.BusPositi
else if (xATA.DriveType == ATA_PIO.SpecLevel.ATAPI)
{
var atapi = new ATAPI(xATA);

//TODO: Replace 1000000 with proper size once ATAPI driver implements it
//Add the atapi device to an array so we reorder them to be last
ATAPIDevices.Add(atapi);
Expand Down
12 changes: 11 additions & 1 deletion source/Cosmos.System2/FileSystem/Disk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<ManagedPartition> Partitions
return converted;
}
}

/// <summary>
/// List of file systems.
/// </summary>
Expand Down Expand Up @@ -200,6 +201,11 @@ public void CreatePartition(int size)
mbrData[510] = boot[0];
mbrData[511] = boot[1];

var partion = new Partition(Host, (ulong)startingSector, amountOfSectors);

Partition.Partitions.Add(partion);
parts.Add(new ManagedPartition(partion));

//Save the data
Host.WriteBlock(0, 1, ref mbrData);
}
Expand All @@ -222,6 +228,10 @@ public void DeletePartition(int index)
mbr[i] = 0;
}
Host.WriteBlock(0, 1, ref mbr);

var part = parts[index];
Partition.Partitions.Remove(part.Host);
parts.RemoveAt(index);
}
/// <summary>
/// Deletes all partitions on the disk.
Expand Down Expand Up @@ -279,7 +289,7 @@ public void MountPartition(int index)
Kernel.PrintDebug("Mounted partition.");

//We would have done Partitions[i].MountedFS = item.Create(...), but since the array is not cached, we need to store the mounted partitions in a list
MountedPartitions[index] = item.Create(part.Host, xRootPath, xSize);
MountedPartitions[index] = item.Create(part.Host, xRootPath, xSize);
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ISO9660FileSystem(Partition aDevice, string aRootPath, long aSize)
//Read primary descriptor
var primaryDescriptor = aDevice.NewBlockArray(1);
aDevice.ReadBlock(0x10, 1, ref primaryDescriptor);
var r = new BinaryReader(new MemoryStream(primaryDescriptor));
using var r = new BinaryReader(new MemoryStream(primaryDescriptor));

var volType = r.ReadByte();
var id = r.ReadBytes(5);
Expand All @@ -54,7 +54,7 @@ public ISO9660FileSystem(Partition aDevice, string aRootPath, long aSize)

r.BaseStream.Position = 156;
var b = r.ReadBytes(34);
BinaryReader rootdir = new BinaryReader(new MemoryStream(b));
using BinaryReader rootdir = new BinaryReader(new MemoryStream(b));
RootDir = ReadDirectoryEntry(rootdir);
}
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
Category="Compile">
</BoolProperty>

<BoolProperty Name="RemoveBootDebugOutput"
DisplayName="Remove Boot Debug Output"
Description="Removes The boot Debug output for faster startup"
Category="Compile">
</BoolProperty>

<StringProperty Name="VBEResolution"
DisplayName="VBE Resolution"
Description="Example format: 800x600x32"
Expand Down