Skip to content

Commit

Permalink
Plug attribute (CosmosOS#196)
Browse files Browse the repository at this point in the history
Plug required attribute.
  • Loading branch information
sgetaz authored and charlesbetros committed May 25, 2016
1 parent 720f618 commit 2de222b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
9 changes: 7 additions & 2 deletions source/Cosmos.Core/CPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Cosmos.IL2CPU.Plugs;
namespace Cosmos.Core {
// Non hardware class, only used by core and hardware drivers for ports etc.
public class CPU {
// Amount of RAM in MB's.
// needs to be static, as Heap needs it before we can instantiate objects
[PlugMethod(PlugRequired = true)]
public static uint GetAmountOfRAM() { return 0; } // Plugged
// needs to be static, as Heap needs it before we can instantiate objects
[PlugMethod(PlugRequired = true)]
public static uint GetEndOfKernel() { return 0; } // Plugged
[PlugMethod(PlugRequired = true)]
public void UpdateIDT(bool aEnableInterruptsImmediately) { } // Plugged
[PlugMethod(PlugRequired = true)]
public void InitFloat() { } // Plugged
[PlugMethod(PlugRequired = true)]
public static void ZeroFill(uint aStartAddress, uint aLength) { } // Plugged
[PlugMethod(PlugRequired = true)]
public void Halt() { } // Plugged

public void Reboot() {
// Disable all interrupts
DisableInterrupts();
Expand Down
9 changes: 7 additions & 2 deletions source/Cosmos.Core/IOPort.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using Cosmos.IL2CPU.Plugs;
namespace Cosmos.Core
{
public abstract class IOPortBase
Expand Down Expand Up @@ -29,12 +29,17 @@ protected IOPortBase(UInt16 aBase, UInt16 aOffset)
}

//TODO: Reads and writes can use this to get port instead of argument
[PlugMethod(PlugRequired = true)]
static protected void Write8(UInt16 aPort, byte aData) { } // Plugged
[PlugMethod(PlugRequired = true)]
static protected void Write16(UInt16 aPort, UInt16 aData) { } // Plugged
[PlugMethod(PlugRequired = true)]
static protected void Write32(UInt16 aPort, UInt32 aData) { } // Plugged

[PlugMethod(PlugRequired = true)]
static protected byte Read8(UInt16 aPort) { return 0; } // Plugged
[PlugMethod(PlugRequired = true)]
static protected UInt16 Read16(UInt16 aPort) { return 0; } // Plugged
[PlugMethod(PlugRequired = true)]
static protected UInt32 Read32(UInt16 aPort) { return 0; } // Plugged

//TODO: Plug these Reads with asm to read directly to RAM
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU.Plugs/PlugMethodAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class PlugMethodAttribute: Attribute {
public Type Assembler = null;
public bool IsMonoOnly = false;
public bool IsMicrosoftdotNETOnly = false;

public bool PlugRequired = false;
public bool IsWildcard = false;
public bool WildcardMatchParameters = false;
}
Expand Down
16 changes: 8 additions & 8 deletions source/Cosmos.IL2CPU/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Cosmos.IL2CPU.Plugs;
namespace Cosmos.IL2CPU {
partial class RuntimeEngine {
public static uint HeapHandle = 0;
public const uint InitialHeapSize = 4096;
public const uint MaximumHeapSize = 10 * 1024 * InitialHeapSize; // 10 megabytes
public static void Heap_Initialize() {
public static void Heap_Initialize() {
//HeapHandle = PInvokes.Kernel32_HeapCreate(0, InitialHeapSize, MaximumHeapSize);
}

public static uint Heap_AllocNewObject(uint aSize) {
[PlugMethod(PlugRequired = true)]
public static uint Heap_AllocNewObject(uint aSize) {
// if (aSize == 0) {
// aSize = 1;
// }
//return PInvokes.Kernel32_HeapAlloc(HeapHandle, 0x00000008, aSize);
return 0;
}

public static void Heap_Free(uint aObject) {
[PlugMethod(PlugRequired = true)]
public static void Heap_Free(uint aObject) {
//
}

public static void Heap_Shutdown() {
[PlugMethod(PlugRequired = true)]
public static void Heap_Shutdown() {
//PInvokes.Kernel32_HeapDestroy(HeapHandle);
//HeapHandle = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions source/Cosmos.IL2CPU/ILScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,10 @@ protected void Assemble()
{
continue;
}
else if(xAttrib.PlugRequired)
{
throw new Exception(string.Format("Method {0} requires a plug, but none is implemented",xMethod.Name));
}
xPlugAssembler = xAttrib.Assembler;
}

Expand Down

0 comments on commit 2de222b

Please sign in to comment.