Moshe
Moshe

Reputation: 113

Read/Write to Debug Port (0x80h) using C#

I'm trying to write a simple C# program on Windows to display a character or digit on the Debug Port (address at: 0x80h, also known as the POST code display) of any supported motherboard (as shown here and here). This has already been done before in Linux, C, Assembly, and via a freeware called "TempLCD":

C (__outword command example): What does the 0x80 port address connect to?

Assembly: Is there a way to manually change BIOS POST codes on motherboard LCD?

Linux: Writing LCD Temperatures in Linux to Debug Port

In this screenshot, you can see the debug port at 80 (Device Manager > View > Resource by type): Device Manager with Port 80

How can I target this port for read/writes using any high-level programming language, such as C#? The SerialPort class fails, since it expects COM1, COM2, etc.

Upvotes: 1

Views: 887

Answers (1)

Cody Gray
Cody Gray

Reputation: 244672

You can only write to this I/O port in kernel mode. Read/writes to these I/O ports are not supported in a normal user-mode application.

You can see even in the solutions to the linked question that these all require a kernel-mode driver. In particular, the Windows solution __outword is just a MSVC-specific intrinsic that causes the x86 OUT instruction to be emitted, and, as the Intel x86 documentation says, OUT is a privileged instruction that is not allowed to be executed in Ring 3 (which is where user-mode applications are run).

Since it can't be executed from user mode, it cannot be executed at all from a .NET application. You cannot use .NET to write a Windows driver that runs in Ring 0. You will need to use a different programming language that can generate native (i.e., unmanaged) code. C and C++ are the typical choices.

If you wrote the driver in an unmanaged language like C or C++, you could then call it from a C# application using the P/Invoke (DllImport) mechanism. See: Accessing Device Drivers from C# and similar resources.

Upvotes: 4

Related Questions