Comments (10)
Thanks, I hadn't seen this before: https://github.com/nifanfa/MOOS/blob/master/NativeLib/io.cpp Yes, I was thinking exactly like this.
from patienceos.
@AnErrupTion FYI. I'm continuing my OS development here for the time being: https://github.com/FrankRay78/InstructionOS
from patienceos.
COSMOS Plug example
namespace Cosmos.Core
{
/// <summary>
/// IOPort static class.
/// </summary>
public static class IOPort
{
/// <summary>
/// Write byte to port.
/// Plugged.
/// </summary>
/// <param name="aPort">A port to write to.</param>
/// <param name="aData">A data.</param>
[PlugMethod(PlugRequired = true)]
public static void Write8(int aPort, byte aData) => throw null;
and also
namespace Cosmos.Core_Asm
{
[Plug(Target = typeof(IOPort))]
public class IOPortImpl
{
private class Write8Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler 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
XS.Set(XSRegisters.EDX, XSRegisters.EBP, sourceDisplacement: 0x0C);
XS.Set(XSRegisters.EAX, XSRegisters.EBP, sourceDisplacement: 0x08);
XS.WriteToPortDX(XSRegisters.AL);
}
}
[PlugMethod(Assembler = typeof(Write8Assembler))]
public static void Write8(ushort aPort, byte aData) => throw null;
FlingOS Plug example
/// <summary>
/// Writes a byte to the specified port.
/// </summary>
/// <param name="port">The port to write to.</param>
/// <param name="aVal">The value to write.</param>
[PluggedMethod(ASMFilePath = @"ASM\IO\IOPort\Write")]
public static void doWrite_Byte(ushort port, byte aVal)
{
}
and also
method_System_Void_RETEND_Kernel_IO_IOPort_DECLEND_doWrite_Byte_NAMEEND__System_UInt16_System_Byte_:
push dword ebp
mov dword ebp, esp
mov dword edx, [ebp+12]
mov dword eax, [ebp+8]
out dx, al
pop dword ebp
ret
Microsoft specific, C compiler directive
(could be compiled into a native object, and then linked into the native kernel, I guess).
void __outbyte(
unsigned short Port,
unsigned char Data
);
https://learn.microsoft.com/en-us/cpp/intrinsics/outbyte?view=msvc-160
from patienceos.
@FrankRay78 How would you plan on adding a custom plug architecture to NativeAOT? That requires hijacking the compiler, and I'm not sure if it's possible.
from patienceos.
How would you plan on adding a custom plug architecture to NativeAOT?
@AnErrupTion I've been thinking about this a lot, and at the moment, I'm favouring an architecture-specific library written in C/C++ with the required methods and inline assembly that I can compile and then somehow link the kernel with.
from patienceos.
I'm favouring an architecture-specific library written in C/C++ with the required methods and inline assembly that I can compile and then somehow link the kernel with.
So essentially the way MOOS did it with its NativeLib?
from patienceos.
I'm having difficulty writing to an IO port from assembly, as being discussed here: io port 0x80 - usage for debugging during OS development. I need to resolve this first, before attempting to call similar from within the C# kernel.
from patienceos.
Calling x86-64 Assembly code from C#.NET Program
How do I make a DLL file with NASM?
Minimal example for C# direct P/Invoke calls with static linking
from patienceos.
I'm not sure if I'm going to use the nativelib approach MOOS takes, as it seems that C# .Net does not support direct linking of an an AOT compiled object file to another native object file. Instead, .Net uses the DllImport
attribute as a primary way to call into unmanaged code, for example:
using System;
using System.Runtime.InteropServices;
// Declare the method signature
[DllImport("addThree.dll")]
static extern int addThree(int number);
Console.WriteLine($"addThree(5) = { addThree(5) }");
If I take this approach, then I need to explicitly implement the DllImport
attribute the compiler requires eg: https://github.com/nifanfa/MOOS/blob/master/Corlib/System/Runtime/InteropServices/DllImportAttribute.cs
And also implement a host of accompanying InteropHelpers eg:
https://github.com/nifanfa/MOOS/blob/master/Corlib/Internal/Runtime/CompilerHelpers/InteropHelpers.cs
https://github.com/nifanfa/MOOS/blob/master/Corlib/System/EETypePtr.cs
However, without this, I'm not sure there is any other way except for the plug (see above) approach COSMOS/FlingOS took.
from patienceos.
I wonder if a modified fork of the ILCompiler might be the way to go?
https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/aot
from patienceos.
Related Issues (10)
- Switch between VGA text modes (Real mode, INT10) HOT 5
- Better roadmap planning and information management
- Switch between VGA text modes (Protected mode, IO port)
- Enhanced terminal functionality HOT 1
- Better build toolchain
- Top Issues Dashboard
- Allocate new objects on the heap, not stack HOT 4
- Create a wiki to accompany the PatienceOS repo HOT 2
- IDE Intellisense for the custom zerolib
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from patienceos.