[current revisions] ATAPI/IDE handling bugs

Support and general discussion.
kazblox
Posts: 12
Joined: Sun 30 Aug, 2015 7:03 pm

[current revisions] ATAPI/IDE handling bugs

Post by kazblox »

The current ATAPI/IDE code is handled in a way that prevents some accurate CD-ROM checks from passing, causing some software not to work.
OS used: NetBSD 6.1.5 Setup CD
Description:
I decided to install NetBSD 6.1.5 for random occasional reasons.
When booting it up, it unexpectedly hit "unknown device" trying to read the emulated CD.
Returns to a boot prompt where a boot device can be selected afterwards.
NOTE: NetBSD 4.0 passes the checks fine but cannot install it's own packages from it's CD. ends up with "mount_cd9660: /dev/cd0a on /mnt2: Device not configured".

Configuration - Award 430VX PCI with PCem's CD emulation + WinCDEmu (mounter)
Dynamic Recompiler used? - Yes
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

kazblox wrote:The current ATAPI/IDE code is handled in a way that prevents some accurate CD-ROM checks from passing, causing some software not to work.
OS used: NetBSD 6.1.5 Setup CD
Description:
I decided to install NetBSD 6.1.5 for random occasional reasons.
When booting it up, it unexpectedly hit "unknown device" trying to read the emulated CD.
Returns to a boot prompt where a boot device can be selected afterwards.
NOTE: NetBSD 4.0 passes the checks fine but cannot install it's own packages from it's CD. ends up with "mount_cd9660: /dev/cd0a on /mnt2: Device not configured".

Configuration - Award 430VX PCI with PCem's CD emulation + WinCDEmu (mounter)
Dynamic Recompiler used? - Yes
That doesn't sound good. I bet that the ATAPI/IDE handline bug is also causing OS/2 Warp 3 and OS/2 Warp 4 CD emulation to not work correctly. I used IMDisk to mount the CD-ROM ISOs by the way. It may not work with some software, but it's worth it.
SA1988
Posts: 274
Joined: Wed 30 Apr, 2014 9:38 am

Re: [current revisions] ATAPI/IDE handling bugs

Post by SA1988 »

use Daemon Tools.
kazblox
Posts: 12
Joined: Sun 30 Aug, 2015 7:03 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by kazblox »

SA1988 wrote:use Daemon Tools.
I get same thing.

Also, screenshots with NetBSD 6.1.5:
Image
neozeed
Posts: 176
Joined: Tue 08 Jul, 2014 4:41 am
Location: Hong Kong SAR
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by neozeed »

Y'all going to need to run the DEBUG version and go through the log file to see what is going on.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

Other ATAPI/IDE issues:
- I tried to add 430HX support to PCem, but the BIOS wouldn't detect the drive at all. It sens command A0 (send packet command) to the IDE controller but even if the currently selected drive is ATAPI, the command is not processed;
Edit: No, the A0 was on the other port and was the select drive thing. But still, something isn't done correctly so the BIOS doesn't even issue an PACKET DEVICE IDENTIFY command.
Edit #2: Turns out PCem only sets cylinder for ATAPI device to 0xEB14 when IDENTIFY command is issued, which however the Award 430HX BIOS I used (of an ASUS board) does not issue unless the device is not ATAPI. Having selecting drive at port 1F6h/176h also set cylinder to 0xEB14 if the device is a CD-ROM drive made it detect the CD-ROM correctly.
- All MS-DOS CD-ROM drivers other than versions of OAKCDROM.SYS cause freezes at random points, most noticably when running LBA 1.
Last edited by Battler on Sun 06 Sep, 2015 7:25 pm, edited 2 times in total.
kazblox
Posts: 12
Joined: Sun 30 Aug, 2015 7:03 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by kazblox »

neozeed wrote:Y'all going to need to run the DEBUG version and go through the log file to see what is going on.
PCem's logger didn't report errors. The last command it reported was 28, which is Read (10).
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

CD Audio gets stuck at playing! For example, run LBA 1, and get to the main menu. CD Audio will start playing (the background music). Quit the game. Restart it. Current subchannel will be returned as 0x1200 because it's still playing (or in paused mode), which cause VIDE-CDD.SYS to, for some reason, issue a "send DVD structure" command, which will return a packet error, and the game will freeze.

Edit: For some reason, PCem doesn't mark CD Audio as stopped on either the Atapi Reset command or a hard reset of the emulated machine. And I'm quite sure it should. LBA 1 deliberately resets the CD-ROM drive on quitting, and obviously CD Audio should be reset on hard reset.
Last edited by Battler on Mon 07 Sep, 2015 12:38 am, edited 1 time in total.
neozeed
Posts: 176
Joined: Tue 08 Jul, 2014 4:41 am
Location: Hong Kong SAR
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by neozeed »

kazblox wrote:
neozeed wrote:Y'all going to need to run the DEBUG version and go through the log file to see what is going on.
PCem's logger didn't report errors. The last command it reported was 28, which is Read (10).
I just tried NetBSD and saw this:

ide.c Set multiple mode - 16

I just changed all the pclog stuff to say where it was.. maybe that is something that should be overall?

**edit looks like this is accessing the harddisk. Needs more debug stuff..

onesec
onesec
ide.c New IDE command - EC 0 0
ide.c win_identify
ide.c device is cdrom 0 command is 236
ide.c WIN_IDENTIFY DISK
ide.c New IDE command - EC 1 0
ide.c win_identify
ide.c device is cdrom 1 command is 236
ide.c WIN_IDENTIFY CDROM
onesec
onesec

So I can see it going through the motion of asking what is there. The CD-ROM passes it's magic...
ide->secount=1;
ide->sector=1;
ide->cylinder=0xEB14; //ATAPI CD-ROM magic
ide->drive=ide->head=0x0;
Then it does an abort, which looks right. Still not sure why NetBSD isn't happy though. Maybe it's 'aborting too hard'??

I tried to match bochs
case WIN_IDENTIFY: /* Identify Device */
pclog("ide.c WIN_IDENTIFY\t");
if (IDE_DRIVE_IS_CDROM(ide)) {
pclog("CDROM\n");
ide->head=0; //missing...
ide->secount=1;
ide->sector=1;
ide->cylinder=0xEB14; //ATAPI CD-ROM magic
ide->drive=ide->head=0x0;

/* BOCHS
controller->status.busy = 0;
controller->status.drive_ready = 1;
controller->status.err = 1; */
ide->atastat = READY_STAT | ERR_STAT;// | DSC_STAT;
ide->error = ABRT_ERR; //0x04 command ABORTED
ide_irq_raise(ide);
return;
}

Code: Select all

onesec
onesec
onesec
onesec
onesec
ide.c New IDE command - EC 0 0
ide.c win_identify
ide.c device is cdrom 0 command is 236
ide.c WIN_IDENTIFY	DISK
ide.c New IDE command - EC 1 0
ide.c win_identify
ide.c device is cdrom 1 command is 236
ide.c WIN_IDENTIFY	CDROM
onesec
onesec
onesec
onesec
ide.c New IDE command - EC 1 0
ide.c win_identify
ide.c device is cdrom 1 command is 236
ide.c WIN_IDENTIFY	CDROM
onesec
onesec
onesec
ide.c New IDE command - EC 0 0
ide.c win_identify
ide.c device is cdrom 0 command is 236
ide.c WIN_IDENTIFY	DISK
ide.c New IDE command - EC 0 0
ide.c win_identify
ide.c device is cdrom 0 command is 236
ide.c WIN_IDENTIFY	DISK
ide.c New IDE command - 10 0 0
ide.c New IDE command - C6 0 0
ide.c device is cdrom 0 command is 198
ide.c WIN_SET_MULTIPLE_MODE
ide.c Set multiple mode - 16
ide.c New IDE command - 20 0 0
ide.c device is cdrom 0 command is 32
ide.c WIN_READ
ide.c WIN_READ_NORETRY
ide.c New IDE command - C4 0 0
ide.c device is cdrom 0 command is 196
ide.c WIN_READ_MULTIPLE
So it asks for the disk, and cd-rom. Then re-queries the CD-ROM, then reads the partition table from the hard disk.

Maybe an older NetBSD?
kazblox
Posts: 12
Joined: Sun 30 Aug, 2015 7:03 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by kazblox »

neozeed wrote: Maybe an older NetBSD?
NetBSD 4.0 works actually, but fails to install it's packages due to a mounting error.

Battler conjured up some experimental private test patches to fix LBA1 CD reading, which somewhat also fixed NetBSD 4.0. The whole packages are now installable, meaning NetBSD 4 is installable.
Meanwhile, NetBSD 6.1.5 still refuses to boot, but atleast it recognizes the ATAPI now with the patch. But it's starting to spam ATAPI read warnings, and eventually, locking up the machine with it.

We're getting somewhere.

I think NetBSD 6's ATAPI code is expecting something we're missing completely, maybe an undocumented ioctl function? Someone should go check the cvs repository....
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

So far, I have managed to find solutions to two issues:
1. Some software not detecting the CD-ROM - make PCem set the cylinder to 0xEB14 when the drive is selected by write to port 1F6 or 176;
2. LBA 1 freezing at second run with, say, VIDE-CDD.SYS - make PCem set CD Audio status to STOPPED on both the ATAPI Reset command (which LBA 1 has the driver deliberately issue) and hard reset of the emulated machine.
neozeed
Posts: 176
Joined: Tue 08 Jul, 2014 4:41 am
Location: Hong Kong SAR
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by neozeed »

Battler wrote:So far, I have managed to find solutions to two issues:
1. Some software not detecting the CD-ROM - make PCem set the cylinder to 0xEB14 when the drive is selected by write to port 1F6 or 176;
2. LBA 1 freezing at second run with, say, VIDE-CDD.SYS - make PCem set CD Audio status to STOPPED on both the ATAPI Reset command (which LBA 1 has the driver deliberately issue) and hard reset of the emulated machine.
Sounds like you made a lot more progress than me! So 0xeb14 needs to be constantly placed in the cylinder on every CD access?
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

- neozeed: No, constantly placing 0xEB14 as cylinder number makes DOS CD-ROM drivers such as OAKCDROM.SYS unable to detect the drive. I also tried by simply setting 0xEB14 as the initial cylinder value for the CD-ROM drive, but then got stuck at figuring out at how to make it also apply on soft reset. I made softresetx86() call resetide() but it behaved as if resetide() was never called.
neozeed
Posts: 176
Joined: Tue 08 Jul, 2014 4:41 am
Location: Hong Kong SAR
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by neozeed »

Battler wrote:- neozeed: No, constantly placing 0xEB14 as cylinder number makes DOS CD-ROM drivers such as OAKCDROM.SYS unable to detect the drive. I also tried by simply setting 0xEB14 as the initial cylinder value for the CD-ROM drive, but then got stuck at figuring out at how to make it also apply on soft reset. I made softresetx86() call resetide() but it behaved as if resetide() was never called.
Maybe the dozen+ sections that read like

Code: Select all

                if (IDE_DRIVE_IS_CDROM(ide)) {
                        goto abort_cmd;
Need the cylinder and other magical values in place?

Nah that would be crazy. Although looking at the soft reset.

Code: Select all

        case WIN_SRST: /*ATAPI Device Reset */
		pclog("ide.c WIN_SRST\n");
                ide->atastat = READY_STAT | DSC_STAT;
                ide->error=1; /*Device passed*/
                ide->secount = ide->sector = 1;
                if (IDE_DRIVE_IS_CDROM(ide)) {
                        ide->cylinder = 0xeb14;
                        ide->atastat = 0;
And later... no magic!

Code: Select all

        case WIN_PIDENTIFY: /* Identify Packet Device */
		pclog("ide.c WIN_PIDENTIFY\n");
                if (IDE_DRIVE_IS_CDROM(ide)) {
                        pclog("ide.c ATAPI identify\n");
                        ide_atapi_identify(ide);
                        ide->pos=0;
                        ide->error=0;
                        ide->atastat = DRQ_STAT | READY_STAT | DSC_STAT;
                        ide_irq_raise(ide);
                        return;
I would imagine they should all look more like :

Code: Select all

        case WIN_IDENTIFY: /* Identify Device */
		pclog("ide.c WIN_IDENTIFY\t");
                if (IDE_DRIVE_IS_CDROM(ide)) {
			pclog("CDROM\n");
			ide->head=0;	//missing...
                        ide->secount=1;
                        ide->sector=1;
                        ide->cylinder=0xEB14;	//ATAPI CD-ROM magic
                        //ide->drive=ide->head=0x0;
                        //JASON goto abort_cmd;	//CD-ROM's abort this command
			/*    BOCHS
			controller->status.busy = 0;
			controller->status.drive_ready = 1;
			controller->status.err = 1;	*/
                        ide->atastat = READY_STAT | ERR_STAT;// | DSC_STAT;
			ide->error = ABRT_ERR;	//0x04 command ABORTED
			ide_irq_raise(ide);
			return;
                }
Even though I've contaminated the above.....
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

ATAPI Device Reset != x86 CPU soft reset. I can set cylinder to 0xEB14 on the former without problems, but I am stuck making it happen on the latter.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by SarahWalker »

Absolutely nothing will happen to anything on the IDE bus on an x86 soft reset. An x86 soft reset only affects the processor, peripheral devices are not affected.
SA1988
Posts: 274
Joined: Wed 30 Apr, 2014 9:38 am

Re: [current revisions] ATAPI/IDE handling bugs

Post by SA1988 »

also, documentation of the "packet statuses"?
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

Speaking of soft reset, this happens on real PCs.

On PCem, however. If you select Ctrl+Alt+Del from the File menu, this soft resets the emulated PCem machine, but not in a appropriate matter. This is what happens on the AMI WinBIOS 486 66MHz machine for example:
Soft reset bug.png
Soft reset bug.png (36.83 KiB) Viewed 23419 times
The Ctrl+Alt+Del bug (also known as the "soft reset bug") in the PCem emulation causes the keyboard, FDD and HDD controller to not recognise itself. In any event when the emulated machine stops responding (hang), the keyboard, FDD and HDD controllers are sometimes recognised in the BIOS.

So...it looks like that the Ctrl+Alt+Del soft reset is not handling ATAPI/IDE and keyboard features properly as it should. I sure hope that issue gets fixed.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by SarahWalker »

Rev 336 should fix the issue with NetBSD 6.1.5, and possibly a few others.
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

Okay, I updated to r347, and pressing Ctrl+Alt+Del in the File menu still threw out the FDD and HDD controller failures as well as the keyboard not responding. :(

I hoping that you have the time to look into this bug and fix it soon.
User avatar
FredPJ
Posts: 31
Joined: Tue 15 Sep, 2015 1:55 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by FredPJ »

I also confirm the "Ctrl+Alt+Del" FDD and HDD bug. This is what appears in Award SiS 496/497 and Award 430VX PCI after a long pause:
Image
Image
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

FredPJ wrote:I also confirm the "Ctrl+Alt+Del" FDD and HDD bug. This is what appears in Award SiS 496/497 and Award 430VX PCI after a long pause:
Image
Image
Oh, no! That doesn't sound good. Thanks for the heads up.

With the Award SiS 496/497 and 430VIX machines, you can expect the emulated machine to not respond for a long time if all four emulated hard drives are installed.
Last edited by ppgrainbow on Wed 16 Sep, 2015 5:32 pm, edited 1 time in total.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

I have done some logging on the issue and it seems that sometimes, some IRQ's raised by the emulated IDE controller, get lost, and end up causing this kind of issue. I have observed that a very similar issue also causes LBA 1 to freeze on transferring speech files from the CD when the DOS CD-ROM driver used is GSCDROM.SYS. It issues a "write to hard disk" IDE command after reading from CD, and then gets stuck waiting for it.
User avatar
FredPJ
Posts: 31
Joined: Tue 15 Sep, 2015 1:55 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by FredPJ »

Speaking of GSCDROM.SYS, I've noticed that when the driver is loading (from the hard drive or floppy) and the CD-ROM is set to "Empty", it will freeze for a long while. This only seems to happen in PCem.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by SarahWalker »

Got a fix for the reset issue. Just waiting for the repo to come back online.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

- FredPJ: That happens with any DOS CD driver. It will freeze for a long while, and then I think claim no drive has been detected.

- TomWalker: Awesome, can't want for the repo to come back online. :D
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

I too can't wait for the repository to come back online.
User avatar
FredPJ
Posts: 31
Joined: Tue 15 Sep, 2015 1:55 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by FredPJ »

TomWalker wrote:Got a fix for the reset issue. Just waiting for the repo to come back online.
That sounds great, thanks!
Battler wrote:- FredPJ: That happens with any DOS CD driver. It will freeze for a long while, and then I think claim no drive has been detected.
Yes, the following error messages appear:

Error: No CD-ROM drives detected al all.
Error: Device driver aborts loading.


It also happens with an empty physical drive. The driver will fail to load and not enable the CD-ROM drive in DOS or Windows 3.11.
So you mean that it's a known bug? Shouldn't it be reporting a drive with no disc in it instead of a no drive at all?
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [current revisions] ATAPI/IDE handling bugs

Post by Battler »

- FredPJ: Yes, it's known bug in PCem. On real hardware but also in other emulators and virtualizers, when the CD-ROM drive is empty, the driver will still detect it normally.
User avatar
ppgrainbow
Posts: 479
Joined: Thu 04 Sep, 2014 7:03 am
Contact:

Re: [current revisions] ATAPI/IDE handling bugs

Post by ppgrainbow »

Is the patch available for the reset issue especially since the repository isn't going to come back online?
Post Reply