OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: io port 0x80 - usage for debugging during OS development
PostPosted: Tue Dec 28, 2021 1:14 pm 
Offline
Member
Member

Joined: Thu Feb 09, 2012 6:53 am
Posts: 67
Location: Czechoslovakia
I have an ASUS workstation MB with G.P. Diagnosis Card. Firmware displays some hexadecimal codes during initialization so in case of fail you can see the failing code and consult MB manual what is the meaning of the displayed code. By reversing firmware binary I found that the firmware writes the 1 byte hexadecimal code into io port 0x80.

Searching forum I found only this topic where they discussed usage of port 0x80 for linux delay
viewtopic.php?f=1&t=33812

Ralf Brown information about this port:
Quote:
----------P0080------------------------------
PORT 0080 - MANUFACTURING DIAGNOSTICS PORT
Note: sometimes used for a POST hex display

0080 -W Manufacturing Diagnostics port

Of course sending debugging information through serial port transfers more information than 1 displayed byte = 8 bits. There could be a situation when you appreciate this very limited possibility as a last instance choice, e.g. display not yet in working stage, serial port not available, everything runs OK in emulator but you need to run on real hardware where you reveal a problem which was previously silent in emulator. I do not know more MB vendors which use/display this information about POST stage. Newer ASUS MB do not have this G.P. cards included anymore. In my MB the card is inserted into pins dedicated for TPM module (TPM module is not present at my old MB and should be purchased separately). I found that some of newer ASUS Gaming MB have this hexadecimal display wired onto motherboard, e.g. ASUS ROG STRIX X570-E GAMING, its marketing name is Q-code LED. They are usefull when you cause an instability due overclocking settings.
Another usage of this port is to quickly find some interesting parts of firmware during reversing, like this part of code from my firmware which is executed at initializing memory of system:
Quote:
loc_FFFFF83C:
mov al, 2
out 80h, al ; manufacture's diagnostic checkpoint (POST code)
mov esi, offset loc_FFFFF84D
movd mm7, esi
jmp loc_FFFFF912

Consulting error codes in your motherboard manual you can quickly find the part you are interested in reversing, you just scan for hexadecimal sequence
B0 XX E6 80 (where XX is the hexadecimal error code you found in your motherboard manual, e.g. 02 would be used in the above code sample).

For ASUS you need some older workstation (WS) motherboard type and for newer you need to find some from GAMING series.
I wonder if there is another vendor with this feature. If you have any MB with such a feature please let us know its name.

There is also POST card (PCI add-in card), which is installed in PCI bus connector 1.
https://www.intel.com/content/www/us/en ... -kits.html

I prepared a small 512 bytes boot sector which just teletypes hexadecimal characters written on keyboard into this diagnostic device. Pressing ESC on keyboard continues the booting process.
Attachment:
File comment: io port 0x80 diagnostic message
io_port_80h_POST_diagnostic_message.zip [1.03 KiB]
Downloaded 27 times

Here a video what does it do:
https://youtu.be/NKjZQtSTzAM

_________________
hypervisor-based solutions developer (Intel, AMD)


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Tue Dec 28, 2021 3:02 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Just keep in mind you might not be able to debug ACPI this way.

Here's the list of affected systems.


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Tue Dec 28, 2021 3:47 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
Interesting find.

Many years ago I've seen lots of usage of the PCI POST card at a custom PC builder whose business also include repairing computers.

From what I can remember the usage was simple:
For example the BIOS might determine that a RAM module is no good and refuse to boot. It might also generate a few random beeps but to a typical consumer the computer is simply broken.
The consumer would then bring it in, the PC builder's people would plug in the POST card and try to power on, this time the BIOS will display a special code about it.
They would then read the manual, determine that the code means that the RAM is no good and replace the DIMMs one by one.
The POST cards paid for themselves really fast:)

feryno wrote:
I wonder if there is another vendor with this feature. If you have any MB with such a feature please let us know its name.


Rare to see in consumer space now, the TPM connector is LPC (ISA) and most consumer boards no longer have ISA slots.

You can buy the PCI version on Ebay for cheap, but my feeling is that the BIOS has to route it instead of just pushing numbers out of the port to make it work, thus a board without this feature might have a BIOS that doesn't do the routing. Nowadays vendors making the boards and writing FW all have access to Intel/AMD's JTAG boxes, it's much easier to use that instead so I can't imagine them too excited to keep the PCI POST code feature around in the code.

Simnow still has support and also shows that there are (were?) more ports designated for this purpose, see the screenshot below:


Attachments:
diag_ports.jpg
diag_ports.jpg [ 6.27 KiB | Viewed 1890 times ]
Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Tue Dec 28, 2021 4:03 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
I've not made use of it, but my AMD Threadripper motherboard has a two-digit hex-display that outputs various codes during boot.

Still, at my stage of stability, the crash screen is far more useful and it works in virtually all stages of the kernel startup. However, to be able to inspect things after a crash, I need a PS/2 keyboard, and so I typically only buy motherboards that have a PS/2 connector.


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Fri Dec 31, 2021 11:08 am 
Offline
Member
Member

Joined: Thu Feb 09, 2012 6:53 am
Posts: 67
Location: Czechoslovakia
Octocontrabass - interesting info, thank you very much.
xeyes - maybe I should try to buy such PCI card, then I have more possibilities which motherboards to buy. I used SimNow public 4.6.2 a lot, pity that there is no newer public version available. Only one of all the included processors has SVM virtualization present (vp_bd_phase1.bsd) luckily this was enough for my development.
rdos - what is your motherboard vendor and type? PS/2 keyboard is also a must for me, together with serial port (COM).
If possible I will always buy motherboard with this hexadecimal code display feature.

_________________
hypervisor-based solutions developer (Intel, AMD)


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Fri Dec 31, 2021 7:25 pm 
Offline
Member
Member

Joined: Mon Dec 07, 2020 8:09 am
Posts: 212
feryno wrote:
xeyes - maybe I should try to buy such PCI card, then I have more possibilities which motherboards to buy. I used SimNow public 4.6.2 a lot, pity that there is no newer public version available. Only one of all the included processors has SVM virtualization present (vp_bd_phase1.bsd) luckily this was enough for my development.


I can also run SVM on a CPU called "Family10hDR-L1_B2.id", but you are absolutely correct, would be nice to have a version that's not more than a decade old.


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Sat Jan 01, 2022 2:49 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
feryno wrote:
rdos - what is your motherboard vendor and type? PS/2 keyboard is also a must for me, together with serial port (COM).
If possible I will always buy motherboard with this hexadecimal code display feature.


It's this motherboard:
https://www.msi.com/Motherboard/X399-SLI-PLUS


Top
 Profile  
 
 Post subject: Re: io port 0x80 - usage for debugging during OS development
PostPosted: Tue Jan 16, 2024 9:31 am 
Offline
Member
Member

Joined: Thu Feb 09, 2012 6:53 am
Posts: 67
Location: Czechoslovakia
Code:
out 80h,al
does not work anymore on newer motherboards, but writing word or doubleword works, it just writes the low byte (AL) and the higher bits are ignored:
Code:
out 80h,eax

Although there are TL631 cards available, they display only the last one hexadecimal character.
There is a better solution which records the whole stream of data written into i/o port 80h.

ASUS motherboards have 6-1 header named COM_DEBUG which I'm using successfully.
ASROCK has a 4-1 header UART1. I did not test it yet.

The ASUS pinout is here:
https://dlcdnets.asus.com/pub/ASUS/mb/E ... UM_WEB.pdf
chapter 2-17
Attachment:
COM_DEBUG_ASUS.png
COM_DEBUG_ASUS.png [ 3.18 KiB | Viewed 600 times ]

The motherboard from the above link has also a jumper to enable the debug port to work (at the cost of redirection of TxD from COM3 to COM_DEBUG - chapter 2-9) so for your motherboard you should very likely adjust some jumper or change some menu in UEFI setup.

For ASROCK I found a settings in UEFI menu to enable the UART1:
https://download.asrock.com/Manual/H510M-HDVM.2.pdf
Quote:
Serial Port/UART Switch
Select Serial Port or UART for Port 80 debug.


The ASROCK pinout is described here without any guarantee:
https://www.reddit.com/r/buildapc/comme ... re_i_have/
Quote:
There's three pins, pinout appears to be:
1. 5.1V
2. 3.7V
3. Empty
4. GND

and this:
Quote:
It spews random data on pin #2 (3.7V, 115200 8N1)


Then you need a USB to TTL adapter or real serial port on your target machine which receives the data. Something like this, it is very cheap, this one costed less than 2 EUR https://pajenicko.cz/prevodnik-wch-ch340g-usb-na-ttl-uart
Buy a TTL which chip is supported in your OS and download necessary drivers to make it working.

Connect GND (pin 2) from MB to GND pin of TTL (the black cable). Connect TxD (pin 1, transmit data) from MB to RxD pin (receive) of TTL (the white cable, sorry for the white color but I did not have any other color)
Attachment:
IMG_20240116_110041.jpg
IMG_20240116_110041.jpg [ 117.24 KiB | Viewed 600 times ]


On the target machine run putty utility to read the data. If your target machine runs ms win, download it e.g. from here:
https://www.chiark.greenend.org.uk/~sgt ... atest.html

If your target machine runs ms win, launch cmd.exe and this command:
Quote:
reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM


The output of the command looks like:
Quote:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
\Device\Serial2 REG_SZ COM4


Use the putty to record data and also to save a log file as the data are binary (but displayed ASCII), so for reading full hexa values you need to look into the log file using binary viewer. The data are transmitted using this settings:
Code:
baudrate: 115200
data bits: 8
stop bits: 1
parity: none
flow control: none


Attachment:
putty.png
putty.png [ 76.75 KiB | Viewed 600 times ]


This is useful for finding a problem when starting a machine or for reversing a firmware (you can find which uefi module sent a hexa code of your interest e.g. using UEFItool and its search menu).
I hope this will be useful for at least someone. It is required in unusual and strange situation. All my machines have serial port, but I have to let it be used by hyper-v and kernel debugger, graphics card is used by guest OS, so for my parent hypervisor this is a way to go.

Here a video (quite low quality)
https://youtu.be/Gnm_tuARqVI

Here the uefi debugging tool with the capability of writing into i/o port 80:
https://board.flatassembler.net/topic.php?t=9689

_________________
hypervisor-based solutions developer (Intel, AMD)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot], MichaelPetch and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group