forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tiger
committed
Apr 15, 2021
1 parent
54d821f
commit a9d5525
Showing
11 changed files
with
697 additions
and
614 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,90 @@ | ||
#if DEBUG | ||
//#define GC_DEBUG | ||
#endif | ||
using System; | ||
using System.Diagnostics; | ||
using IL2CPU.API; | ||
using IL2CPU.API.Attribs; | ||
|
||
namespace Cosmos.Core | ||
{ | ||
/// <summary> | ||
/// GCImplementation class. Garbage collector. Mostly not implemented. | ||
/// </summary> | ||
/// <remarks>Most of the class is yet to be implemented.</remarks> | ||
[DebuggerStepThrough] | ||
public static class GCImplementation | ||
{ | ||
/// <summary> | ||
/// Acquire lock. Not implemented. | ||
/// </summary> | ||
/// <exception cref="NotImplementedException">Thrown always.</exception> | ||
private static void AcquireLock() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Release lock. Not implemented. | ||
/// </summary> | ||
/// <exception cref="NotImplementedException">Thrown always.</exception> | ||
private static void ReleaseLock() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Alloc new object. Plugged. | ||
/// </summary> | ||
[PlugMethod(PlugRequired = true)] | ||
public static uint AllocNewObject(uint aSize) | ||
{ | ||
throw new NotImplementedException(); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Increase reference count of an given object. Plugged. | ||
/// </summary> | ||
/// <param name="aObject">An object to increase to reference count of.</param> | ||
/// <exception cref="NotImplementedException">Thrown on fatal error, contact support.</exception> | ||
public static unsafe void IncRefCount(uint aObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Decrease reference count of an given object. Plugged. | ||
/// </summary> | ||
/// <param name="aObject">An object to decrease to reference count of.</param> | ||
/// <exception cref="NotImplementedException">Thrown on fatal error, contact support.</exception> | ||
public static unsafe void DecRefCount(uint aObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
#if DEBUG | ||
//#define GC_DEBUG | ||
#endif | ||
using System; | ||
using System.Diagnostics; | ||
using IL2CPU.API; | ||
using IL2CPU.API.Attribs; | ||
|
||
namespace Cosmos.Core | ||
{ | ||
/// <summary> | ||
/// GCImplementation class. Garbage collector. Mostly not implemented. | ||
/// </summary> | ||
/// <remarks>Most of the class is yet to be implemented.</remarks> | ||
[DebuggerStepThrough] | ||
public static class GCImplementation | ||
{ | ||
private static bool isInitialized; | ||
/// <summary> | ||
/// Acquire lock. Not implemented. | ||
/// </summary> | ||
/// <exception cref="NotImplementedException">Thrown always.</exception> | ||
private static void AcquireLock() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Release lock. Not implemented. | ||
/// </summary> | ||
/// <exception cref="NotImplementedException">Thrown always.</exception> | ||
private static void ReleaseLock() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Alloc new object. | ||
/// </summary> | ||
public unsafe static uint AllocNewObject(uint aSize) | ||
{ | ||
|
||
|
||
if (!isInitialized) | ||
{ | ||
isInitialized = true; | ||
Init(); | ||
return (uint)Memory.Heap.Alloc(aSize); | ||
} | ||
|
||
else | ||
{ | ||
return (uint)Memory.Heap.Alloc(aSize); | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Increase reference count of an given object. Plugged. | ||
/// </summary> | ||
/// <param name="aObject">An object to increase to reference count of.</param> | ||
/// <exception cref="NotImplementedException">Thrown on fatal error, contact support.</exception> | ||
public static unsafe void IncRefCount(uint aObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Decrease reference count of an given object. Plugged. | ||
/// </summary> | ||
/// <param name="aObject">An object to decrease to reference count of.</param> | ||
/// <exception cref="NotImplementedException">Thrown on fatal error, contact support.</exception> | ||
public static unsafe void DecRefCount(uint aObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static unsafe void Init() | ||
{ | ||
|
||
|
||
byte* memPtr = (byte*)CPU.GetEndOfKernel(); | ||
memPtr += Memory.RAT.PageSize - (uint)memPtr % Memory.RAT.PageSize; | ||
Debug.Kernel.Debugger.DoSendNumber((uint)CPU.GetMemoryMap()[3].Length - (128 * 1024 * 1024)); | ||
Memory.RAT.Init(memPtr, (uint)CPU.GetMemoryMap()[3].Length - (128 * 1024 * 1024)); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,78 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Native = System.UInt32; | ||
|
||
namespace Cosmos.Core.Memory | ||
{ | ||
/// <summary> | ||
/// HeapLarge class. Used to alloc and free large memory blocks on the heap. | ||
/// </summary> | ||
unsafe static public class HeapLarge | ||
{ | ||
/// <summary> | ||
/// Prefix block. Used to store meta information. | ||
/// </summary> | ||
public const Native PrefixBytes = 4 * sizeof(Native); | ||
|
||
/// <summary> | ||
/// Init HeapLarge instance. | ||
/// </summary> | ||
/// <remarks>Empty function</remarks> | ||
static public void Init() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Alloc memory block, of a given size. | ||
/// </summary> | ||
/// <param name="aSize">A size of block to alloc, in bytes.</param> | ||
/// <returns>Byte pointer to the start of the block.</returns> | ||
static public byte* Alloc(Native aSize) | ||
{ | ||
Native xPages = (Native)((aSize + PrefixBytes) / RAT.PageSize) + 1; | ||
var xPtr = (Native*)RAT.AllocPages(RAT.PageType.HeapLarge, xPages); | ||
|
||
xPtr[0] = xPages * RAT.PageSize - PrefixBytes; // Allocated data size | ||
xPtr[1] = aSize; // Actual data size | ||
xPtr[2] = 0; // Ref count | ||
xPtr[3] = 0; // Ptr to first | ||
|
||
return (byte*)xPtr + PrefixBytes; | ||
} | ||
|
||
/// <summary> | ||
/// Free block. | ||
/// </summary> | ||
/// <param name="aPtr">A pointer to the block.</param> | ||
/// <exception cref="Exception">Thrown if page type is not found.</exception> | ||
static public void Free(void* aPtr) | ||
{ | ||
// TODO - Should check the page type before freeing to make sure it is a Large? | ||
// or just trust the caller to avoid adding overhead? | ||
var xPageIdx = RAT.GetFirstRAT(aPtr); | ||
RAT.Free(xPageIdx); | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Native = System.UInt32; | ||
|
||
namespace Cosmos.Core.Memory | ||
{ | ||
/// <summary> | ||
/// HeapLarge class. Used to alloc and free large memory blocks on the heap. | ||
/// </summary> | ||
unsafe static public class HeapLarge | ||
{ | ||
/// <summary> | ||
/// Prefix block. Used to store meta information. | ||
/// </summary> | ||
public const Native PrefixBytes = 4 * sizeof(Native); | ||
|
||
/// <summary> | ||
/// Init HeapLarge instance. | ||
/// </summary> | ||
/// <remarks>Empty function</remarks> | ||
static public void Init() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Alloc memory block, of a given size. | ||
/// </summary> | ||
/// <param name="aSize">A size of block to alloc, in bytes.</param> | ||
/// <returns>Byte pointer to the start of the block.</returns> | ||
/// Debug.Kernel.Debugger.DoSendNumber(PrefixBytes); | ||
//Debug.Kernel.Debugger.DoSendNumber((uint) xPtr); | ||
static public byte* Alloc(Native aSize) | ||
{ | ||
//Debug.Kernel.Debugger.DoSendNumber(aSize); | ||
//Debug.Kernel.Debugger.DoBochsBreak(); | ||
Native xPages = (Native)((aSize + PrefixBytes) / RAT.PageSize) + 1; | ||
if(xPages == 0) | ||
{ | ||
//Debug.Kernel.Debugger.DoSendNumber(xPages); | ||
//Debug.Kernel.Debugger.DoBochsBreak(); | ||
} | ||
var xPtr = (Native*)RAT.AllocPages(RAT.PageType.HeapLarge, xPages); | ||
Debug.Kernel.Debugger.DoSendNumber((uint)xPtr); | ||
if ((uint)xPtr == 0) | ||
{ | ||
|
||
// Debug.Kernel.Debugger.DoSendNumber((uint)xPtr); | ||
//Debug.Kernel.Debugger.DoSendNumber(2); | ||
// Debug.Kernel.Debugger.DoBochsBreak(); | ||
} | ||
if(PrefixBytes == 0) | ||
{ | ||
//Debug.Kernel.Debugger.DoSendNumber(3); | ||
//Debug.Kernel.Debugger.DoBochsBreak(); | ||
} | ||
xPtr[0] = xPages * RAT.PageSize - PrefixBytes; // Allocated data size | ||
xPtr[1] = aSize; // Actual data size | ||
xPtr[2] = 0; // Ref count | ||
xPtr[3] = 0; // Ptr to first, | ||
//Debug.Kernel.Debugger.DoSendNumber((uint)xPtr + PrefixBytes); | ||
return (byte*)xPtr + PrefixBytes; | ||
} | ||
|
||
/// <summary> | ||
/// Free block. | ||
/// </summary> | ||
/// <param name="aPtr">A pointer to the block.</param> | ||
/// <exception cref="Exception">Thrown if page type is not found.</exception> | ||
static public void Free(void* aPtr) | ||
{ | ||
// TODO - Should check the page type before freeing to make sure it is a Large? | ||
// or just trust the caller to avoid adding overhead? | ||
var xPageIdx = RAT.GetFirstRAT(aPtr); | ||
RAT.Free(xPageIdx); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.