From dff695e8a5ee8df7ba17bbb349a0509a025c03e1 Mon Sep 17 00:00:00 2001
From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498>
Date: Mon, 16 Aug 2010 02:58:18 +0000
Subject: [PATCH]
---
Docs/Kernel/Plugs.html | 27 +++++++-
source2/Users/Kudzu/Notes.html | 118 +++++++++++++++++++++++++--------
2 files changed, 115 insertions(+), 30 deletions(-)
diff --git a/Docs/Kernel/Plugs.html b/Docs/Kernel/Plugs.html
index 0af62b6f9..8b99cc27d 100644
--- a/Docs/Kernel/Plugs.html
+++ b/Docs/Kernel/Plugs.html
@@ -28,10 +28,33 @@
encounters a method or property for which a plug exists, instead of using the IL
contained in the existing implementation, it substitutes the plug version
instead.
+
+ Plug Targets
+
+ Plugs can be applied to:
+
+ - Non Source Targets (A class library without modifiable or available source) -
+ For example the Console class in the .NET Framework. The Console class uses the
+ Windows API, so plugs can be used to redefine the methods in the Console class
+ to use code which interacts with Cosmos instead. For these types of plug
+ targets, the attributes are specified on the plug implemenation since the source
+ cannot be modified of the target. If we coud modify the source, we wouldn't need
+ plugs. :)
+ - Source Targets - Empty methods which create a sort of "abstract" class are used
+ to define an interface to an assembly language plug. This type of plug is rare
+ and only for the core ring. For these types of plugs, the attributes are
+ specified on the target, rather than the implementation.
+
+
+ Non source targets should never need to use assembly language, but if they do
+ the plugs must be cascaded since assembly language plugs can only be applied to
+ classes with modifiable source.
Implementing a Plug
- Plugs can be applied at the class, or to an individual method or property.
+ Plugs can be applied at the class, or to an individual method or property. Plug
+ implementations are defined by applying attributes to the class which provides
+ the plug implementation.
Plug Assembly Naming in Cosmos
@@ -61,8 +84,6 @@
needed by the compiler, off hand I cannot think of any that should be
implemented in any ring lower than the system ring.
-
-
Plug Target
diff --git a/source2/Users/Kudzu/Notes.html b/source2/Users/Kudzu/Notes.html
index 074983692..3706dd86a 100644
--- a/source2/Users/Kudzu/Notes.html
+++ b/source2/Users/Kudzu/Notes.html
@@ -8,7 +8,7 @@
Guess Demo
- use INT3 for BP?
+ use INT3 for BP? Will save 3 bytes per call.. which is a lot...
Plugs
- To add a plug
- Cosmos.Build.MSBuild add ref to the plug asm
@@ -19,38 +19,54 @@
- Matthijs
+ Matthijs - Next Release
- - Next Release
- - Write a manual cleanup utility that runs as part of our install first
- - New projects should be: C# Operating System, VB.NET Operating System, C#
+
- Write a manual cleanup utility that runs as part of our install first
+ - New projects should be: C# Operating System, VB.NET Operating System, C#
Library, VB.NET Library, Cosmos Project (Empty)
- - Express
- - Change to new kernel lib format
-
-
- - Post Release:
+ - Express
+ - Change to new kernel lib format
+
+
+ Matthijs - Next Release + 1
+
- IL2CPU.AlwaysCompile attribute and get rid of IDT.Dummy
- - Change plugs to be included by assembly reference
- - Many kernel functions (TextScreen is linked to by console plug) requires
- rebuilding of bat each time? And thus wont trace either? We need to dynamically
- load the plugs etc so we can just rebuild and run and even trace them
+ - Change plugs to be included by assembly reference - but plugs will ref others,
+ can go two ways will have circular ref. ie Cosmos.System.Plugs.System will
+ already need to ref Cosmos.System. So how to drag in the plugs asm
+ automatically? Just add them to the project default refs? Yes.. do that...
+ - Non Source Plugs - Leave as they are
+ - Source Plugs - Change to have attribute on the TARGET instead of the
+ implementation and only allow assembly.. this cuts out the "proxy" class and
+ makes it easier to find plug impls. See Rings.html for more info. The assembly
+ level plugs can even go in the same assembly, source file and if we can the same
+ class? That is currently these assembly plugs require 3 classes to implement.
+ its ugly and messy... we can get it down to 2 - 1 + assembly (X# only!). Current
+ way is such a mess we even comment them as plugged, but then have to go guessing
+ where the impl is... See example down below....
+ - Convert all source plugs and disable old attributes...so for new ones use new
+ names
- - 2010 support
- - http://blogs.msdn.com/b/jacdavis/archive/2010/04/05/vs-2010-version-of-debugenginesample-is-now-available.aspx
- - Trivalik worked on some already
+
+ - We need to dynamically
+ load the plugs etc so we can just rebuild and run and even trace them wihout
+ rerunnig the bat for each change
-
- - Ring attributes and enforcement
- - Also allow restriction of assembly references
- - Only allow core to be /unsafe, no others
-
-
- - Ask on forums: How to debug the vsdebug pkg?
- - http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/6a9a307a-19fa-4c06-8728-303c1f4dd0bc/
-
-
+ - 2010 support
+ - http://blogs.msdn.com/b/jacdavis/archive/2010/04/05/vs-2010-version-of-debugenginesample-is-now-available.aspx
+ - Trivalik worked on some already
+
+
+ - Ring attributes and enforcement
+ - Also allow restriction of assembly references
+ - Only allow core to be /unsafe, no others
+
+
+ - Ask on forums: How to debug the vsdebug pkg?
+ - http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/6a9a307a-19fa-4c06-8728-303c1f4dd0bc/
+
+
Post MS5
@@ -81,5 +97,53 @@
+
+ Assembly Plug Example
+
+ Old way
+
+ (3 classes, often 3 source files as well)
+ public class CPUBus {
+ // Plugged
+ public static void Write8(UInt16 aPort, byte aData) { }
+...
+
+[Plug(Target = typeof(Cosmos.Kernel.CPUBus))]
+class CPUBus {
+ [PlugMethod(Assembler = typeof(Assemblers.IOWrite8))]
+ public static void Write8(UInt16 aPort, byte aData) { }
+...
+
+public sealed class IOWrite8: AssemblerMethod {
+ public override void AssembleNew(object aAssembler, object aMethodInfo) {
+ //TODO: This is a lot of work to write to a single port. We need to have some kind of inline ASM option that can emit a single out instruction
+ new CPUx86.Move { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EBP, SourceDisplacement = 0xC, SourceIsIndirect = true };
+ new CPUx86.Move { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.EBP, SourceDisplacement = 0x8, SourceIsIndirect = true };
+ new CPUx86.Out { DestinationReg = CPUx86.Registers.AL };
+ }
+}
+
+ New way
+
+ See how much neater and self contained this is? :)
+
+ public class CPUBus {
+
+
+ [AsmBody(Assembler = typeof(IOWrite8))]
+ public static void Write8(UInt16 aPort, byte aData) { }
+ // Nested class even... :) Keeps it all in one unit!
+ public class IOWrite8 : CodeBlock {
+
+ public override void Assemble() {
+ EDX = EBP + 0x0C;
+ EAX = EBP + 0x08;
+ Port[DX] = AL;
+ }
+ }
+
+
+ }
+