• Please review our updated Terms and Rules here

IBM PC AT 5170 BIOS patches

Blazer

Member
Joined
Jul 27, 2019
Messages
19
Location
UK
Apologies if this has been posted or mentioned before but has anyone tried the IBM 5170 BIOS patches that are available at:

https://archive.org/details/ibm-5170-type-3-bios-cover

A summary of the patches:

This BIOS is an unofficial recompile of the IBM BIOS, and not a decompiled or hex-edited version of the original BIOS.

I used the IBM PC BIOS source code reconstruction project code for the AT version 3 from here: https://sites.google.com/site/pcdosretro/ibmpcbios

I will use this source for references of the changes. At the end is the development environment used to build and test the BIOS.

Fixes:

There are five fixes; three really, and two requests. Below is a description of each, and what was done.

1) '162-System Options Not Set-(Run SETUP)'

As part of the startup the BIOS retrieves the configured FDD settings from the nvram, and tries to compare that to what it discovers by querying the hardware.

In the file TEST2.ASM, line 1376, it calls DSKETTE_SETUP, which is in DISKETTE.ASM, line 2650, which then calls DRIVE_DET on line 2581. This tries to determine the drive type based on the number of tracks, and data rates, then based on the two decides what type of drive it is. My opinion is that the data rates is the issue comes in, that newer FDDs have data rates it does not recognize, so throws it off and thinks the drive is an 'Unknown' type. This 'Unknown' type will not match what was set in the BIOS, so it throws the 'System Options Not Set' due to the mismatch.

The "fix" was basically just to ignore the error. I still let it go through the process of trying to determine the drive, as this is the boot up seek you get (trying to determine the tracks) and wanted to keep that. So in TEST2.ASM, line 1399, I changed the conditional jump "JNZ F15D" to the permanent jump "JMP SHORT F15D", so it never gets to the "CONFIG_BAD" call.

2) ' 601-Diskette Error'

This message appears when the BIOS is looking for a specific drive controller, and does not find it. The IBM BIOS looks for two specific cards that support "Multiple Data Rate Compatibility", in TEST2.ASM, line 1322. It does this by reading the diagnostics registry at 03F1H and then comparing the result against two known results. The first seems to be a special card (IBM specific) that it knows supports Multiple Data Rate, and the second it looks for a generic card and tries to test if it supports Multiple Data Rate. Like above, I think newer cards would normally pass the second (generic) test, but since it cannot correctly verify the modern data rates, it fails and says the card cannot support it.

The "fix" for this was to take the test for the IBM original card, where it conditionally jumps on line 1326 with "JZ J_OK3" only if it is found, and make it a permanent jump "JMP SHORT J_OK3" regardless of the type of card found.

3) Accessing files larger than 1024 bytes.

If there is only a small amount of data required (less than 1K) the BIOS has no issue reading it in all at once. However, when it gets larger files, it has to read it in chunks, making multiple requests to the HDD. Whenever the HDD completes the request, it tells the BIOS is done by sending out an interrupt. So, what normally happens is the BIOS requests the data (DISK.ASM line 972), then gets ready and at line 977 calls for a "WAIT". This is done on line 1125, then on line 1130 is waits for the HDD's interrupt to say the data has been sent. This worked find on much older hard drives, where the time between the request of the data and waiting for the HDD to say it was done through an interrupt, was long enough for the BIOS to be waiting to receive the interrupt.

The problem is newer hard drives are so fast, that the next block of data was sent (and the interrupt sent) before the BIOS was waiting. So, it was waiting for a message that had already passed, and eventually times out, and you get a timeout error on line 1142.

The fix for this was a little different. There is the possibility that the drive was not finished when the BIOS starts the request, so just bypassing the wait could cause stability issues. Instead, I switched from the "WAIT" function to the "NOT_BUSY" check on line 1153. This basically queries the controller to see if it is busy or not. If the drive is still fetching data, then it pauses for a bit until it is no longer busy. This works as a direct replacement for "WAIT", as it would stall processing if the new HDD is still working, or if it is already done (and not busy) then it continues. So, line 982 changed from "CALL WAIT" to "CALL NOT_BUSY" and the following "JNZ TM_OUT" on 978 is replaced with two NOPs.

4) Using a larger HDD

Not really a fix, but the IBM BIOS does not support a custom hard drive type. So the last change was to replace the TYPE 24 drive, as defined in ORGS.ASM line 522 to 533, to have 1023 cylinders (01023D), 16 heads (016D), no precomp (0FFFFH), no landing zone (0), and 63 sectors per track (63D)

5) Remove the speed check to allow overclocking

The IBM 5170 Type-3 BIOS uses a timing loop to check for the machine being overclocked.

It allows for 10% below and 5% above stock clock. It if finds anything outside of that, it will either beep (for under clock) or halt the machine for an overclock.

In the full 64k BIOS file at offset 5BC, change bytes 73 07 (Jnb 0575) to EB 0D which will bypass both checks.

(Or download the files that say "no speed check" which have this check removed."

Use romwak utility to combine/split the BIOS files if you don't want to run my fully patched BIOS.

Thsnks to Stewart for finding and patching this. I am able to run my Type-1 IBM 5170 board at 10mhz -- which is a 66.7% overclock! I did swap out the CPU with a 12mhz part and used a 20mhz crystal. In addition, I used 120ns EPROM chips It is still running the stock 200ns RAM.


Compiling vs modifying:

Compiling this code creates a BIOS without the built in BASIC.

To patch the original BIOS files you can use a hex editor. For the full files :

Fix 1 : Change 13DE from 75 to EB
Fix 2 : Change 1362 from 74 to EB
Fix 3 : Change 313C through 313F from ED 00 75 2D to 1E 01 90 90
Fix 4 : Change E571 through E57F
from 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
to FF 03 10 00 00 FF FF 00 00 00 00 00 00 00 3F

For split files, on U27 (Even) :

Fix 1 : Change 9EF from 75 to EB
Fix 2 : Change 9B1 from 74 to EB
Fix 3 : Change 189E and 189F from ED 75 to 1E 90
Fix 4 : Change 7201 through 7207
from 00 00 00 00 00 00 00
to 03 00 FF 00 00 00 00

For split files, on U47 (Odd) :

Fix 1 : NONE!
Fix 2 : NONE!
Fix 3 : Change 189E and 189F from 00 2D to 01 90
Fix 4 : Change 7200 through 7207
from 00 00 00 00 00 00 00 00
to FF 10 00 FF 00 00 00 3F

Finally, the checksum. Change the last byte of the full file or the U47 file, from B7 to CB

Or..... [BONUS CONTENT!!!]

In TEST1.ASM, line 464, replace the "HLT" with "NOP"
-OR-
In the full binary change 19E from F4 to 90
-OR-
In the split file U27 change CF from F4 to 90

.... and never worry about your CHECKSUMS again! That way you can change text, like the ROM BASIC version number for fun.



Development environment:

Virtual Box 6.1 running MS-DOS 6.22 and IBM MASM 2.0. Used this to compile the code and generate the BIN (without correct checksum).
https://www.virtualbox.org/

Managed disk images with WinImage 10.00
https://www.winimage.com/

Used HxD Hex Editor 2.4 to do binary file editing, and perform the 8-bit checksums correcting the last byte
https://mh-nexus.de/en/hxd/

Used RomWak to split/merge the binary files into odd/even version
https://github.com/freem/romwak

RomWak was complied on the PC using TCC 0.9.27
https://bellard.org/tcc/

To run a virtual 5170 I used Mame 0.207 (version is important)
https://www.mamedev.org/oldrel.html

Then downloaded the Ibm 5170 rom pack for MAME. You can leave the pack in the .zip file, but for the process I unzipped it into an ibm5170 folder, which allowed me to drop the split BIOS straight in, overwriting the existing 6181028.u27 (even) and 6181029.u47 (odd) files.
 
Thanks! I changed BIOS to Phoenix in my 5170, because it wasn't working with IDE with native BIOS. I'd like to try your patched BIOS. Is there a link to download it?
 
Just to be clear. I'm not the author or compiler of these patches, I found them while searching for information about the IBM PC AT 5170 BIOS.

The download link can be found in the first link in the opening post.
 
Just to be clear. I'm not the author or compiler of these patches, I found them while searching for information about the IBM PC AT 5170 BIOS.

The download link can be found in the first link in the opening post.
Thank you! I will test "IBM 5170 Type 3 BIOS - Fully patched with Type 24 no speed check-u27.BIN" / "IBM 5170 Type 3 BIOS - Fully patched with Type 24 no speed check-u47.BIN" and share my experience.
 
Number 2 at least is done completely wrong. The correct way to make "generic" cards work without compromising the full testing procedure would be to remove this code block at 1328 in TEST2:

Code:
    MOV    DX,05F7H        ; FIXED DISK DIAGNOSTIC REGISTER
    IN    AL,DX            ; READ FIXED DISK TYPE CODE
    AND    AL,11110000B        ; KEEP ONLY UNIQUE CODE FOR F/D
    CMP    AL,10100000B        ; FIXED DISK ADAPTER ?
    JZ    J_FAIL            ; MUST BE COMBO ELSE ERROR
 
I also wonder, if you try to build it with masm 6, it's multi-pass and if you do short jumps, it doesn't pad it with nop like it does with 2-pass masm up to 5.1. This should save a few hundred bytes.
 
Back
Top