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

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

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

Postby Battler » Mon 24 Jul, 2017 7:13 am

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: 88
Joined: Tue 22 Mar, 2016 10:03 am
Location: Korea
Contact:

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

Postby Greatpsycho » Mon 24 Jul, 2017 8:54 am

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 13 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Postby Battler » Mon 24 Jul, 2017 9:12 am

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.
SarahWalker
Site Admin
Posts: 1327
Joined: Thu 24 Apr, 2014 4:18 pm

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

Postby SarahWalker » Mon 24 Jul, 2017 5:10 pm

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

Postby Battler » Mon 24 Jul, 2017 5:20 pm

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.
SarahWalker
Site Admin
Posts: 1327
Joined: Thu 24 Apr, 2014 4:18 pm

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

Postby SarahWalker » Mon 24 Jul, 2017 6:01 pm

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

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

Postby SarahWalker » Mon 24 Jul, 2017 6:04 pm

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

Postby Battler » Mon 24 Jul, 2017 6:42 pm

- 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.
SarahWalker
Site Admin
Posts: 1327
Joined: Thu 24 Apr, 2014 4:18 pm

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

Postby SarahWalker » Mon 24 Jul, 2017 6:52 pm

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

Postby Battler » Mon 24 Jul, 2017 7:56 pm

Gentoo was named in this thread: viewtopic.php?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.

Return to “Development”

Who is online

Users browsing this forum: No registered users and 4 guests