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

CGS Update (part 2) #3034

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4de75d
Drawing Raw Point (raw argb)
Szymekk44 Jun 20, 2024
f6937c9
Faster DrawRectangle
Szymekk44 Jun 20, 2024
4b3ee4d
GetRawPoint & Basic GetImage
Szymekk44 Jun 20, 2024
e47e504
Finished GetRawColor and faster SVGAII GetImage
Szymekk44 Jun 20, 2024
5d9e075
VBE DrawImage change and added CroppedDrawImage
Szymekk44 Jun 20, 2024
2feb8c1
Merge branch 'CosmosOS:master' into master
Szymekk44 Jun 20, 2024
dda9df1
More summaries, alpha rectangles
Szymekk44 Jul 8, 2024
7bad71f
Merge branch 'master' into master
MishaProductions Jul 10, 2024
289270e
added preventOffBoundPixels in summary
Szymekk44 Jul 12, 2024
a3540b0
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Szymekk44 Jul 12, 2024
f064006
Fixed VBE getimage()
Szymekk44 Jul 28, 2024
2036880
Faster VBE GetImage
Szymekk44 Jul 29, 2024
f1bedae
Fixed SVGAII image drawing (x and y < 0)
Szymekk44 Jul 29, 2024
d290822
Merge branch 'master' into master
MishaProductions Aug 9, 2024
6f38e13
New DrawArray methods, VBE bugfix
Szymekk44 Aug 9, 2024
da5e7ac
Small VBE bugfix
Szymekk44 Aug 12, 2024
b00577e
Added PCIE
Samma2009 Aug 13, 2024
8d6fa08
Update PCIExpress.cs
Samma2009 Aug 13, 2024
c5b44ce
Delete source/Cosmos.Debug.Kernel.Plugs.Asm/packages.lock.json
Samma2009 Aug 13, 2024
a770c34
fix power stuff
Samma2009 Aug 13, 2024
155b893
change of comments
Samma2009 Aug 13, 2024
f047cd9
Merge branch 'master' of https://github.com/SzymekkYT/Cosmos
Samma2009 Aug 13, 2024
98406c5
Fixed namespaceing
Samma2009 Aug 13, 2024
01342ae
Update PCIExpress.cs
Samma2009 Aug 13, 2024
7f19fbd
Merge branch 'master' into master
Szymekk44 Aug 16, 2024
d8f0aad
Add files via upload
Samma2009 Aug 16, 2024
d117063
Update packages.lock.json
Samma2009 Aug 16, 2024
98bb00f
Update packages.lock.json
Samma2009 Aug 16, 2024
3375aab
Update packages.lock.json
Samma2009 Aug 16, 2024
ac464df
Update packages.lock.json
Samma2009 Aug 16, 2024
b84f8a4
Graphics drivers are public, FileSystemType enum
Szymekk44 Sep 21, 2024
e80d1e0
Graphics drivers are public, FilsSystemType enum
Szymekk44 Sep 21, 2024
e0e7f0b
Merge pull request #1 from Szymekk44/CGE-Update
Szymekk44 Sep 21, 2024
e58fdc5
Merge pull request #2 from Szymekk44/CGE-Update2
Szymekk44 Sep 21, 2024
fb59494
Disk format - removed FIleTypeFormat enum
Szymekk44 Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
668 changes: 269 additions & 399 deletions source/Cosmos.Core/ACPI.cs

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions source/Cosmos.Core/ManagedMemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ public unsafe void Copy(int aStart, int[] aData, int aIndex, int aCount)
}
}

public unsafe void Get(int aStart, int[] aData, int aIndex, int aCount)
{
// TODO throw exception if aStart and aCount are not in bound. I've tried to do this but Bochs dies :-(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should no longer be an issue and can be checked

int* xSrc;
fixed (byte* aArrayPtr = memory)
{
xSrc = (int*)aArrayPtr + aStart;
}
fixed (int* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSrc, aCount);
}
}

/// <summary>
/// Copy MemoryBlock into ManagedMemoryBlock
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,38 @@ public unsafe void Copy(ManagedMemoryBlock block)
MemoryOperations.Copy(xDest, aDataPtr, (int)block.Size);
}

Szymekk44 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Copies a specified number of integers from the memory block into an integer array.
/// </summary>
/// <param name="aByteOffset">The byte offset in the memory block from where the copy starts.</param>
/// <param name="aData">The integer array where the data will be copied to.</param>
/// <param name="aIndex">The starting index in the destination integer array.</param>
/// <param name="aCount">The number of integers to copy.</param>
public unsafe void Get(int aByteOffset, int[] aData, int aIndex, int aCount)
{
int* xSource = (int*)(Base + aByteOffset);
fixed (int* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSource, aCount);
}
}

/// <summary>
/// Copies a specified number of bytes from the memory block into an array.
/// </summary>
/// <param name="aByteOffset">The byte offset in the memory block from where the copy starts.</param>
/// <param name="aData">The array where the data will be copied to.</param>
/// <param name="aIndex">The starting index in the destination array.</param>
/// <param name="aCount">The number of bytes to copy.</param>
public unsafe void Get(int aByteOffset, byte[] aData, int aIndex, int aCount)
{
byte* xSource = (byte*)(Base + aByteOffset);
fixed (byte* aDataPtr = aData)
{
MemoryOperations.Copy(aDataPtr + aIndex, xSource, aCount);
}
}

/// <summary>
/// Move bytes array down the memory block.
/// </summary>
Expand Down
200 changes: 200 additions & 0 deletions source/Cosmos.Core/PCIE/PCIDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using System.Collections.Generic;
using System;
using Cosmos.Core;

namespace Cosmos.Core.PCIE
{
public class PCIDevice
{
public ushort Bus;
public ushort Slot;
public ushort Function;
public ushort VendorID;

public ushort DeviceID;

public byte ClassID;
public byte SubClassID;
public byte ProgIF;
public byte IRQ;

public uint Bar0;
public uint Bar1;
public uint Bar2;
public uint Bar3;
public uint Bar4;
public uint Bar5;

//PCI Express
public ushort Segment;
public bool IsPCIEDevice;

public void WriteRegister(ushort Register, ushort Value)
{
PCI.WriteRegister16(Bus, Slot, Function, (byte)Register, (ushort)(ReadRegister(Register) | Value));
}

public ushort ReadRegister(ushort Register)
{
return PCI.ReadRegister16(Bus, Slot, Function, (byte)Register);
}
}

public static unsafe class PCI
{
public static List<PCIDevice> Devices;

public static PCIDevice GetDevice(ushort VendorID, ushort DeviceID)
{
for (int i = 0; i < Devices.Count; i++)
{
if (
Devices[i] != null &&
Devices[i].VendorID == VendorID &&
Devices[i].DeviceID == DeviceID
)
{
return Devices[i];
}
}
return null;
}

public static PCIDevice GetDevice(byte ClassID, byte SubClassID, byte ProgIF)
{
for (int i = 0; i < Devices.Count; i++)
{
if (
Devices[i] != null &&
Devices[i].ClassID == ClassID &&
Devices[i].SubClassID == SubClassID &&
Devices[i].ProgIF == ProgIF
)
{
return Devices[i];
}
}
return null;
}

public static void Initialise()
{
Devices = new List<PCIDevice>();
if ((GetHeaderType(0x0, 0x0, 0x0) & 0x80) == 0)
{
CheckBus(0);
}
else
{
for (ushort fn = 0; fn < 8; fn++)
{
if (GetVendorID(0x0, 0x0, fn) != 0xFFFF)
break;

CheckBus(fn);
}
}

PCIExpress.Initialize();

Console.Write("[PCI] PCI Initialized. ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this writes?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, leaving them there is best practice because you will have feedback of the PCI and PCIE initialization

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we allow the user to enable this feedback when they want it but also give them a way to disable it?

Console.Write(((ulong)Devices.Count).ToString());
Console.WriteLine(" Devices");
}

public static void CheckBus(ushort Bus)
{
for (ushort slot = 0; slot < 32; slot++)
{
ushort vendorID = GetVendorID(Bus, slot, 0);
if (vendorID == 0xFFFF)
{
continue;
}

PCIDevice device = new PCIDevice();
device.Bus = Bus;
device.Slot = slot;
device.Function = 0;
device.VendorID = vendorID;
device.Segment = 0;
device.IsPCIEDevice = false;

device.Bar0 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x10);
device.Bar1 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x14);
device.Bar2 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x18);
device.Bar3 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x1C);
device.Bar4 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x20);
device.Bar5 = ReadRegister32(device.Bus, device.Slot, device.Function, 0x24);

device.ClassID = ReadRegister8(device.Bus, device.Slot, device.Function, 11);
device.SubClassID = ReadRegister8(device.Bus, device.Slot, device.Function, 10);
device.ProgIF = ReadRegister8(device.Bus, device.Slot, device.Function, 9);
device.IRQ = (byte)(0x20 + ReadRegister8(device.Bus, device.Slot, device.Function, 60));

device.DeviceID = ReadRegister16(device.Bus, device.Slot, device.Function, 2);

Devices.Add(device);

if (device.ClassID == 0x06 && device.SubClassID == 0x04)
{
CheckBus(ReadRegister8(device.Bus, device.Slot, device.Function, 25));
}
}
}

public static void WriteRegister32(ushort Bus, ushort Slot, ushort Function, byte aRegister, uint Value)
{
uint xAddr = GetAddressBase(Bus, Slot, Function) | ((uint)(aRegister & 0xFC));
IOPort.Write32(0xCF8, xAddr);
IOPort.Write32(0xCFC, Value);
}

public static uint ReadRegister32(ushort Bus, ushort Slot, ushort Function, byte aRegister)
{
uint xAddr = PCI.GetAddressBase(Bus, Slot, Function) | ((uint)(aRegister & 0xFC));
IOPort.Write32(0xCF8, xAddr);
return IOPort.Read32(0xCFC);
}

public static ushort ReadRegister16(ushort Bus, ushort Slot, ushort Function, byte aRegister)
{
uint xAddr = PCI.GetAddressBase(Bus, Slot, Function) | ((uint)(aRegister & 0xFC));
IOPort.Write32(0xCF8, xAddr);
return (ushort)(IOPort.Read32(0xCFC) >> ((aRegister % 4) * 8) & 0xFFFF);
}

public static byte ReadRegister8(ushort Bus, ushort Slot, ushort Function, byte aRegister)
{
uint xAddr = PCI.GetAddressBase(Bus, Slot, Function) | ((uint)(aRegister & 0xFC));
IOPort.Write32(0xCF8, xAddr);
return ((byte)(IOPort.Read32(0xCFC) >> ((aRegister % 4) * 8) & 0xFF));
}

public static void WriteRegister16(ushort Bus, ushort Slot, ushort Function, byte aRegister, ushort Value)
{
uint xAddr = GetAddressBase(Bus, Slot, Function) | ((uint)(aRegister & 0xFC));
IOPort.Write32(0xCF8, xAddr);
IOPort.Write16(0xCFC, Value);
}

public static ushort GetVendorID(ushort Bus, ushort Slot, ushort Function)
{
uint xAddr = GetAddressBase(Bus, Slot, Function) | 0x0 & 0xFC;
IOPort.Write32(0xCF8, xAddr);
return (ushort)(IOPort.Read32(0xCFC) >> ((0x0 % 4) * 8) & 0xFFFF);
}

public static ushort GetHeaderType(ushort Bus, ushort Slot, ushort Function)
{
uint xAddr = GetAddressBase(Bus, Slot, Function) | 0xE & 0xFC;
IOPort.Write32(0xCF8, xAddr);
return (byte)(IOPort.Read32(0xCFC) >> ((0xE % 4) * 8) & 0xFF);
}

public static uint GetAddressBase(ushort Bus, uint Slot, uint Function)
{
return (uint)(0x80000000 | (Bus << 16) | ((Slot & 0x1F) << 11) | ((Function & 0x07) << 8));
}
}
}
Loading
Loading