[Bug] The REP reorganization broke NT 3.1 on 386DX

Discussion of development and patch submission.
Post Reply
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

[Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Battler »

NT 3.1 now just shows a blue screen saying you might be using an early version of the 386DX.

It's probably this: set TF bit (0x0100) in eflags causes Debug exception (interrupt 0x01) only at completion of rep movsb (taken from here: https://www.geoffchappell.com/studies/w ... cation.htm ).

Edit: And there's also the fact REP with invalid instruction should just ignore and return pointing to the next instruction, something PCem did before but no longer does.

Also this:

Code: Select all

        if (x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32])
                return x86_opcodes_REPNE[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8);
        return x86_opcodes[(fetchdat & 0xff) | cpu_state.op32](fetchdat >> 8);
Is this correct? Because every element of x86_opcodes_REPNE and x86_opcodes_REPE is xet to at least ILLEGAL, so it's never NULL, therefore that second return never gets executed.
Greatpsycho
Posts: 151
Joined: Tue 22 Mar, 2016 10:03 am
Location: Korea
Contact:

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Greatpsycho »

This patch applies non-string instruction followed by REP instruction to be processed as real machine does. REP prefix should not occur exception #6 even if non-string instruction is followed.
Attachments
386_ops.h.patch
Patch for REP prefix.
(77.44 KiB) Downloaded 332 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Battler »

Thank you very much, this fixes one half of the problem. The other half remains, which is REP not issuing the debug exception on every repeat when the trap flag is set, but only on command completion.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by SarahWalker »

Fixed the invalid opcode value in the REP tables in rev 814 - it should always have been NULL/0.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Battler »

Actually, Greatpsycho did it correctly - it should be a simple ignore of the instruction, not a NULL which according to your code will just execute whatever the instruction there is, which is incorrect behavior.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by SarahWalker »

Rev 815 fixes the trap issue.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by SarahWalker »

Actually the behaviour with the REP prefix is undefined. However some stuff does use REP RET and expect a normal RET to be executed - the old REP code had specific handling for this.
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Battler »

- SarahWalker: Then add a specific handler for RET. Some Linuxes expect REP on invalid instruction to be ignored, and I think reenigne said that happens as well.
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by SarahWalker »

Care to name one?
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

Re: [Bug] The REP reorganization broke NT 3.1 on 386DX

Post by Battler »

Gentoo was named in this thread: https://pcem-emulator.co.uk/phpBB3/view ... ?f=3&t=423 where I posted my original REP fix patch that you accepted.

Edit: OK, after doing some tests in VirtualBox, it seems that when REP is used with a non-string instruction, the REP prefix is ignored and the instruction is executed as if there was no REP prefix, which means, Sarah, that your fix was actually the correct one.

Edit #2: And it seems that's precisely what both my old patch and Greatpsycho's patch also do, except in slightly different ways.
Post Reply