Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alpha waves doesn't work #112

Closed
stsp opened this issue Sep 10, 2019 · 91 comments
Closed

alpha waves doesn't work #112

stsp opened this issue Sep 10, 2019 · 91 comments

Comments

@stsp
Copy link
Member

stsp commented Sep 10, 2019

Describe the bug
Hangs at start.
Works on 1.4.

To Reproduce
Just start.

Attach the binaries or provide an URL
http://www.abandonia.com/en/games/25594/Alpha+Waves.html

Almost no games seem to work.
Testing more looks like the waste of time.

@stsp
Copy link
Member Author

stsp commented Sep 10, 2019

Maybe the first beta doesn't need to run many games?

@jschwartzenberg
Copy link
Member

This one crashes on 1.4 here as well.

@stsp
Copy link
Member Author

stsp commented Sep 22, 2019

With freedos - yes.
But not with PC-DOS.

@stsp
Copy link
Member Author

stsp commented Sep 22, 2019

I created the "freedos" label to mark it as such.

@stsp
Copy link
Member Author

stsp commented Nov 16, 2019

Doesn't seem to work on 1.4 either,
but works on anything else but freedos.
Not interesting.

@stsp stsp closed this as completed Nov 16, 2019
@stsp stsp transferred this issue from dosemu2/dosemu2 Nov 17, 2019
@stsp
Copy link
Member Author

stsp commented Nov 17, 2019

It actually still doesn't work properly.
It says Please insert the disk labeled ALPHA WAVES DISK 1 in the current drive.
but works under PC-DOS.
Something FS-related, Andrew, want
to debug this?

@stsp stsp reopened this Nov 17, 2019
@andrewbird
Copy link
Member

okay will do.

@andrewbird
Copy link
Member

Under FDPP when the program tries to reopen the progs.cc1 file int21/3d returns with CF set and AX=04 which I believe is no file handles available. I tried setting FILES=50 in config.sys but it made no difference.

@stsp
Copy link
Member Author

stsp commented Nov 18, 2019

fdpp has by default FILES=64

@andrewbird
Copy link
Member

andrewbird commented Nov 23, 2019

A couple of further data points

  • Doesn't seem like it's an MFS problem as it's reproducible on FAT16
  • FreeDOS 1.20 crashes on both MFS and FAT16 with
Real-mode state dump:
EIP: 0000:00000018 ESP: 0056:00000006  VFLAGS(b): 01011 00000010 01000110
EAX: 00000000 EBX: 00000000 ECX: 00000000 EDX: 0000005c VFLAGS(h): 000b0246
ESI: 00000000 EDI: 00000000 EBP: 00000000 DS: 0000 ES: 1b80 FS: 0000 GS: 0000
FLAGS: PF ZF IF RF VM VIF  IOPL: 0
STACK: 00 00 00 00 00 00 00 00 80 1b -> 00 00 00 00 00 00 00 00 00 00 
OPS  : d8 00 06 f1 00 f0 07 f1 00 f0 -> c7 11 d8 00 09 f1 00 f0 0f 00 
	c711d800            0000:0018 mov  word [bx+di],00D8

@stsp
Copy link
Member Author

stsp commented Nov 23, 2019

If its really a result of int21/3d failure, must
be quite easy to follow with gdb, or?

@andrewbird
Copy link
Member

Not sure why I can't get GDB to run properly

(gdb) run
Starting program: /clients/common/dosemu2.git/2.0-pre8/bin/dosemu.bin -n -f test-imagedir/dosemu.conf -D+dRW\# -o test.log --Fimagedir /clients/common/dosemu2.git/test-imagedir --Flibdir /clients/common/dosemu2.git/test-libdir -I \'cpuemu vm86sim cpu_vm emulated\'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
warning: Error reading shared library list entry at 0x7670
warning: Error reading shared library list entry at 0x9d0
warning: Error reading shared library list entry at 0xffffea50
warning: Error reading shared library list entry at 0xffffffb0
warning: Error reading shared library list entry at 0xffffc280
[New Thread 0xb1d19b40 (LWP 24833)]
[New Thread 0xa4ef1b40 (LWP 24834)]
[New Thread 0xa42f0b40 (LWP 24835)]
warning: Error reading shared library list entry at 0xffff9b60
warning: Error reading shared library list entry at 0xffff8540
warning: Error reading shared library list entry at 0x90
warning: Error reading shared library list entry at 0x3e0
[New Thread 0x93aefb40 (LWP 24836)]
[New Thread 0x838ffb40 (LWP 24838)]
warning: Error reading shared library list entry at 0x5d80
ERROR: Your fluidsynth is too old and soundfonts not found
warning: Error reading shared library list entry at 0xffffb210
ERROR: alsa_midi (ALSA lib): rawmidi_hw.c:233:(snd_rawmidi_hw_open) : No such file or directory open /dev/snd/midiC0D0 failed
[New Thread 0x8287ab40 (LWP 24840)]
INFO: booting with comcom32, this is very experimental
INFO: fdpp booting, this is very experimental!

Thread 1 "dosemu.bin" received signal SIGUSR1, User defined signal 1.
0xb7fd7a7d in __kernel_vsyscall ()
(gdb) cont
Continuing.
Cannot find user-level thread for LWP 24804: generic error

I do this so infrequently, did I miss something?

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

Try handle SIGUSR1 nostop noprint.
I've seen such problem on 32bit systems,
I don't think they are properly maintained
these days.

Anyway, the problem is that the game
crates new PSP with func 26, which sets
parent_psp to 0. Then it uses func 0x50
to activate that PSP, and 0x31 to TSR it
(hell knows why). The problem is that 0
in parent_psp makes it into a current psp
on 0x31, which results in a junk in PSP,
hence the corrupted JFT and no free
handles.
Not sure what fix can fix that.

stsp added a commit to dosemu2/dosemu2 that referenced this issue Nov 24, 2019
dosemu2/fdpp#112

alpha waves does some anti-debugger trick by changing int 1 vector.
dosdebug doesn't use that vector, but it was not suppressing int 1
during rep XX stepping.
With this patch alpha waves is tracible.
@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

I applied a few patches to make this game
tracible with dosdebug. It uses some anti-debugger
tricks, which fooled our dosdebug.
It seems, this playing with PSP is also a part
of anti-debugging protection, because you can
set the breakpoint (in gdb) to int 1 vector, and
you'll see that the game alters it exactly before
playing with PSP, and restores immediately after.
This makes it very easy to get into a problematic
spot. We only need to start tracing after it altered
int 1.

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

Yep, it is an anti-debugger trick.
If I trace it under PC-DOS, then it also
says "please insert disk", just like under
fdpp. However, PC-DOS doesn't seem
to set parent_psp to 0 by fn 0x26:

INT 0x21, system state: emulated,stopped in real mode while in DPMI
AX=2650  BX=1b54  CX=c000  DX=0ba3  SI=09e3  DI=039f  SP=19ac  BP=091c
DS=09e3  ES=09e3  FS=543d  GS=7548  FL=000b3202
CS:IP=09e3:0dfc       SS:SP=09e3:19ac

09e3:0dfc CD21             int  21
dosdebug> t
dosdebug> 
system state: emulated,stopped in real mode while in DPMI
AX=26f0  BX=1b54  CX=c000  DX=0ba3  SI=09e3  DI=039f  SP=19ac  BP=091c
DS=09e3  ES=09e3  FS=543d  GS=7548  FL=000b3302
CS:IP=09e3:0dfe       SS:SP=09e3:19ac

09e3:0dfe BA8000           mov  dx,0080
dosdebug> d ba3:0
dosdebug> 

0ba3:0000 CD 20 F4 F4 F4 9A F0 FE 1D F0 EC 01 8B 09 0F F5  M ttt.p~.pl....u
0ba3:0010 00 F0 85 15 E3 09 F4 F4 06 7E 05 00 E8 9E 05 72  .p..c.tt.~..h..r
0ba3:0020 20 8D 77 1A E8 4F FD 73 06 B8 20 00 F4 F4 F4 F4   .w.hO}s.8 .tttt
0ba3:0030 F4 F4 14 00 18 00 A3 0B FF FF FF FF F4 F4 F4 F4  tt....#.tttt
0ba3:0040 07 00 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  ..tttttttttttttt
0ba3:0050 CD 21 CB F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  M!Kttttttttttttt
0ba3:0060 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  tttttttttttttttt
0ba3:0070 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  tttttttttttttttt

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

So it seems PC-DOS just doesn't zero
out parent_psp, keeping it as is.
But RBIL says it should be zeroed.
Andrew, would you like to test some DOSes
on that?

Note: by not zeroing parent_psp I am able
to avoid the "please insert disk" error, but
it still doesn't work.

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

Try $_cpu_vm_dpmi="kvm" to avoid gdb problems.

@andrewbird
Copy link
Member

andrewbird commented Nov 24, 2019

I've seen such problem on 32bit systems,
I don't think they are properly maintained
these days.

Yes, I'm getting pretty fed up with 32 bit support on Ubuntu. I even had Dosemu/FDPP/Alphawaves reboot my machine, which I can only guess means they've screwed up vm86() again. Spotify doesn't work anymore due to an incorrect library version which they refuse to fix in 32 bit, that's their problem I know, but it's probably time I joined the herd on 64 bit.

Well done on tracking down the PSP/JFT issue, I doubt I'd have got to that.

Try $_cpu_vm_dpmi="kvm" to avoid gdb problems.

Yes that fixed FDPP startup for me, so I've added it to my personal startup script, thanks.

So it seems PC-DOS just doesn't zero
out parent_psp, keeping it as is.
But RBIL says it should be zeroed.
Andrew, would you like to test some DOSes
on that?

I'll try to write a test for that, but I'm sorry it probably won't be today.

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

If there is a reboot, you need to
create a minimal test-case and we'll
call our friend Andy Lutomirski for help.
But no one will fix gdb on 32bits for sure.
You can also try lldb, but I dont think
its going to be much better.

@stsp
Copy link
Member Author

stsp commented Nov 24, 2019

Btw, the psp I dumped above, seems
to be severely corrupted. It all is
overwritten with F4s. It happens only
under dosdebug. Either some
anti-debugger trick works, or some bug.

@andrewbird
Copy link
Member

I started to write a little test program to find the behaviour of all the DOSes I have, but I don't see the non-zeroed parent_psp field that you mention.

Here's the program

.text
.code16

    .globl  _start16
_start16:

# designate target segment
    push    %cs
    pop     %ax
    addw    $0x0200, %ax
    movw    %ax, %es

# create PSP in memory
    movw    %es, %dx
    movw    $0x2600, %ax
    int     $0x21

# see what the parent PSP is set to
    movw    $0x0016, %di
    cmpw    $0x0000, %es:(%di)
    je      success

cmpfail:
    movb    $0x9, %ah
    movw    $cmpfailmsg, %dx
    int     $0x21
    jmp     exit

success:
    movb    $0x9, %ah
    movw    $successmsg, %dx
    int     $0x21
    jmp     exit

exit:
    movb    $0x4c, %ah
    int     $0x21

cmpfailmsg:
    .ascii  "PSP is not zero\r\n$"
successmsg:
    .ascii  "PSP is zero\r\n$"

I'm seeing that all the DOSes here zero the parent_psp field

Test DR-DOS-3.40 Create New PSP                                                  ... ok
Test DR-DOS-3.41 Create New PSP                                                  ... ok
Test DR-DOS-5.00-900615 Create New PSP                                           ... ok
Test DR-DOS-5.00-900814 Create New PSP                                           ... ok
Test DR-DOS-6.00-930319 Create New PSP                                           ... ok
Test DR-DOS-6.00 Create New PSP                                                  ... ok
Test DR-DOS-7.00 Create New PSP                                                  ... ok
Test DR-DOS-7.01 Create New PSP                                                  ... ok
Test DR-DOS-7.02-971119 Create New PSP                                           ... ok
Test DR-DOS-7.02-980123 Create New PSP                                           ... ok
Test DR-DOS-7.03 Create New PSP                                                  ... ok
Test DR-DOS-8.00 Create New PSP                                                  ... ok
Test FR-DOS-1.20 Create New PSP                                                  ... ok
Test MS-DOS-3.10 Create New PSP                                                  ... ok
Test MS-DOS-3.20 Create New PSP                                                  ... ok
Test MS-DOS-3.21 Create New PSP                                                  ... ok
Test MS-DOS-3.30-Nec Create New PSP                                              ... ok
Test MS-DOS-3.30 Create New PSP                                                  ... ok
Test MS-DOS-3.31 Create New PSP                                                  ... ok
Test MS-DOS-4.01 Create New PSP                                                  ... ok
Test MS-DOS-5.00 Create New PSP                                                  ... ok
Test MS-DOS-6.00 Create New PSP                                                  ... ok
Test MS-DOS-6.20 Create New PSP                                                  ... ok
Test MS-DOS-6.21 Create New PSP                                                  ... ok
Test MS-DOS-6.22 Create New PSP                                                  ... ok
Test MS-DOS-7.00 Create New PSP                                                  ... ok
Test MS-DOS-7.10 Create New PSP                                                  ... ok
Test PC-DOS-3.00-Compaq Create New PSP                                           ... ok
Test PC-DOS-3.00 Create New PSP                                                  ... ok
Test PC-DOS-3.10-850307 Create New PSP                                           ... ok
Test PC-DOS-3.10-850422 Create New PSP                                           ... ok
Test PC-DOS-3.10-Compaq Create New PSP                                           ... ok
Test PC-DOS-3.20-851230 Create New PSP                                           ... ok
Test PC-DOS-3.20-860221 Create New PSP                                           ... ok
Test PC-DOS-3.30 Create New PSP                                                  ... ok
Test PC-DOS-3.31-Compaq Create New PSP                                           ... ok
Test PC-DOS-4.00 Create New PSP                                                  ... ok
Test PC-DOS-4.01 Create New PSP                                                  ... ok
Test PC-DOS-5.00 Create New PSP                                                  ... ok
Test PC-DOS-5.02 Create New PSP                                                  ... ok
Test PC-DOS-6.10 Create New PSP                                                  ... ok
Test PC-DOS-6.30 Create New PSP                                                  ... ok
Test PC-DOS-7.00 Create New PSP                                                  ... ok
Test PC-DOS-7.10 Create New PSP                                                  ... ok
Test PC-DOS-7.2K Create New PSP                                                  ... ok
Test PP-DOS-GIT Create New PSP                                                   ... ok

Here's dosdebug running against FreeDOS 1.20, notice now the PSP is only partially populated

system state: stopped
AX=0000  BX=0000  CX=0000  DX=0000  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2382  FS=0000  GS=0000  FL=000a3346
CS:IP=2382:0100       SS:SP=2382:fffe

2382:0100 0E               push cs
dosdebug> t
dosdebug> 
system state: stopped
AX=0000  BX=0000  CX=0000  DX=0000  SI=0000  DI=0000  SP=fffc  BP=0000
DS=2382  ES=2382  FS=0000  GS=0000  FL=000a3346
CS:IP=2382:0101       SS:SP=2382:fffc

2382:0101 58               pop  ax
dosdebug> 
dosdebug> 
system state: stopped
AX=2382  BX=0000  CX=0000  DX=0000  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2382  FS=0000  GS=0000  FL=000a3346
CS:IP=2382:0102       SS:SP=2382:fffe

2382:0102 050002           add  ax,0200
dosdebug> 
dosdebug> 
system state: stopped
AX=2582  BX=0000  CX=0000  DX=0000  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2382  FS=0000  GS=0000  FL=000a3306
CS:IP=2382:0105       SS:SP=2382:fffe

2382:0105 8EC0             mov  es,ax
dosdebug> 
dosdebug> 
system state: stopped
AX=2582  BX=0000  CX=0000  DX=0000  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2582  FS=0000  GS=0000  FL=000a3306
CS:IP=2382:0107       SS:SP=2382:fffe

2382:0107 8CC2             mov  dx,es
dosdebug> 
dosdebug> 
system state: stopped
AX=2582  BX=0000  CX=0000  DX=2582  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2582  FS=0000  GS=0000  FL=000a3306
CS:IP=2382:0109       SS:SP=2382:fffe

2382:0109 B80026           mov  ax,2600
dosdebug> d es:0000
dosdebug> 

2582:0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
dosdebug> t
dosdebug> 
system state: stopped
AX=2600  BX=0000  CX=0000  DX=2582  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2582  FS=0000  GS=0000  FL=000a3306
CS:IP=2382:010c       SS:SP=2382:fffe

2382:010c CD21             int  21
dosdebug> t
dosdebug> 
system state: stopped
AX=2600  BX=0000  CX=0000  DX=2582  SI=0000  DI=0000  SP=fffe  BP=0000
DS=2382  ES=2582  FS=0000  GS=0000  FL=00083306
CS:IP=2382:010e       SS:SP=2382:fffe

2382:010e BF0000           mov  di,0000 # earlier version of my test program!

dosdebug> d es:0000
dosdebug> 

2582:0000 00 00 00 00 00 00 00 00 00 00 E7 F6 00 F0 C6 07  ..........gv.pF.
2582:0010 B2 10 47 02 C2 10 00 00 00 00 00 00 00 00 00 00  2.G.B...........
2582:0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2582:0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

dosdebug> d cs:0000 # our original PSP
dosdebug> 

2382:0000 CD 20 EF 9F 00 9A F0 FE 1D F0 E7 F6 00 F0 C6 07  M o...p~.pgv.pF.
2382:0010 B2 10 47 02 C2 10 B2 10 01 01 01 00 02 FF FF FF  2.G.B.2......
2382:0020 FF FF FF FF FF FF FF FF FF FF FF FF 74 23 E0 FF  t#`
2382:0030 82 23 14 00 18 00 82 23 00 00 B2 10 00 00 00 00  .#.....#..2.....
2382:0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
2382:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 20 20 20  M!K..........   
2382:0060 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20          .....   
2382:0070 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00          ........

@andrewbird
Copy link
Member

I just modified the test to check for CD20 at beginning of PSP, only FreeDOS 1.20 and FDPP don't populate this

Test DR-DOS-3.40 Create New PSP                                                  ... ok
Test DR-DOS-3.41 Create New PSP                                                  ... ok
Test DR-DOS-5.00-900615 Create New PSP                                           ... ok
Test DR-DOS-5.00-900814 Create New PSP                                           ... ok
Test DR-DOS-6.00-930319 Create New PSP                                           ... ok
Test DR-DOS-6.00 Create New PSP                                                  ... ok
Test DR-DOS-7.00 Create New PSP                                                  ... ok
Test DR-DOS-7.01 Create New PSP                                                  ... ok
Test DR-DOS-7.02-971119 Create New PSP                                           ... ok
Test DR-DOS-7.02-980123 Create New PSP                                           ... ok
Test DR-DOS-7.03 Create New PSP                                                  ... ok
Test DR-DOS-8.00 Create New PSP                                                  ... ok
Test FR-DOS-1.20 Create New PSP                                                  ... FAIL
Test MS-DOS-3.10 Create New PSP                                                  ... ok
Test MS-DOS-3.20 Create New PSP                                                  ... ok
Test MS-DOS-3.21 Create New PSP                                                  ... ok
Test MS-DOS-3.30-Nec Create New PSP                                              ... ok
Test MS-DOS-3.30 Create New PSP                                                  ... ok
Test MS-DOS-3.31 Create New PSP                                                  ... ok
Test MS-DOS-4.01 Create New PSP                                                  ... ok
Test MS-DOS-5.00 Create New PSP                                                  ... ok
Test MS-DOS-6.00 Create New PSP                                                  ... ok
Test MS-DOS-6.20 Create New PSP                                                  ... ok
Test MS-DOS-6.21 Create New PSP                                                  ... ok
Test MS-DOS-6.22 Create New PSP                                                  ... ok
Test MS-DOS-7.00 Create New PSP                                                  ... ok
Test MS-DOS-7.10 Create New PSP                                                  ... ok
Test PC-DOS-3.00-Compaq Create New PSP                                           ... ok
Test PC-DOS-3.00 Create New PSP                                                  ... ok
Test PC-DOS-3.10-850307 Create New PSP                                           ... ok
Test PC-DOS-3.10-850422 Create New PSP                                           ... ok
Test PC-DOS-3.10-Compaq Create New PSP                                           ... ok
Test PC-DOS-3.20-851230 Create New PSP                                           ... ok
Test PC-DOS-3.20-860221 Create New PSP                                           ... ok
Test PC-DOS-3.30 Create New PSP                                                  ... ok
Test PC-DOS-3.31-Compaq Create New PSP                                           ... ok
Test PC-DOS-4.00 Create New PSP                                                  ... ok
Test PC-DOS-4.01 Create New PSP                                                  ... ok
Test PC-DOS-5.00 Create New PSP                                                  ... ok
Test PC-DOS-5.02 Create New PSP                                                  ... ok
Test PC-DOS-6.10 Create New PSP                                                  ... ok
Test PC-DOS-6.30 Create New PSP                                                  ... ok
Test PC-DOS-7.00 Create New PSP                                                  ... ok
Test PC-DOS-7.10 Create New PSP                                                  ... ok
Test PC-DOS-7.2K Create New PSP                                                  ... ok
Test PP-DOS-GIT Create New PSP                                                   ... FAIL

Any other fields you'd like me to check whilst I have the test available?

BTW I don't think there's any point in adding this test permanently to the suite, do you?

@stsp
Copy link
Member Author

stsp commented Nov 26, 2019

Its absolutely impossible that it doesn't
populate CD20. Please attach your test-case.

@andrewbird
Copy link
Member

Will do later , In the meantime did you see the dosdebug dump of the new PSP above where Cd20 is not set?

@andrewbird
Copy link
Member

Perhaps it's where I chose to place the new PSP in memory that's the problem?

@stsp
Copy link
Member Author

stsp commented Nov 26, 2019

Of course I've seen it, but its not possible.
Maybe location is the problem, but you put
it after the code, so I dont know what overwrites
it.

@andrewbird
Copy link
Member

I'm thinking more about the comment regarding CS; it directly contradicts us using cu_psp, but suggests our intention of it needing to be the user's CS is correct.
https://github.com/the-grue/OpenDOS/blob/e8be6acdf8bdaa10ba87e98e789d3762515fb345/IBMDOS/PROCESS.A86#L124-L143

@andrewbird
Copy link
Member

So Alphawaves is looking a lot better on FDPP now, enough to run the demo anyway. I do see a corrupted vertically scrolling image immediately on entering the game, and it also hangs dosemu on exit, bu only after the game has been entered.

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

IBMDOS? So is this a pc-dos after all?
Yes, I see it using CS, and no I dont
see it zeroing parent_psp.

Is the exit crash specific to fdpp?

@andrewbird
Copy link
Member

Pretty sure about that IBMDOS directory being named so is because the target file is called 'ibmdos.com', it's certainly DR-DOS based.

I find this comment most interesting,

Get pointer to INT 21 structure of IP/CS/Flags and get the USER CS this is used as 
the PSP for this function call and NOT current_psp.

so if we shouldn't use cu_psp as the source segment for the copy, somehow we still need to get the user's real CS.

Doesn't seem to be just FDPP, I ran it on PCDOS 7.10 with gdb and got this on exit

ERROR: bad dos helper function: AX=0x4649
ERROR: EMU86: error 2

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

We can or can't get the real user's cs,
depending on who hooks int21 and how.
The biggest problem is that we never
know if the CS we got, is what we need.
If you want to intercept iret of int21,
you need to exclude 0x26 so that dos
can get a valid cs... I'd say its a mess,
and using cu_psp is the right thing
to do, but...

@andrewbird
Copy link
Member

Just for completeness I ran my testcase on several DOSes and it seems your latest fixes changed something. Now only FreeDOS 1.00, 1.10 and 1.20 zero the PSP parent whereas MSDOS 6.22, PCDOS 7.10, DRDOS 7.01 and FDPP don't.

To see what the new PSP looked like I ran MS-DOS 6.22 with the testcase under dosdebug. Now it seems to me that I'm seeing the effect you did earlier when running with dosdebug, in that the copy source is incorrect and only the explicitly set fields are valid. It's a little unsettling that using dosdebug can change things?

But I noticed the crap only occurs if I t over the interrupt

dosdebug> d dx:0000
dosdebug> 

122f:0000 CD 20 F4 F4 F4 9A F0 FE 1D F0 E8 F6 00 F0 4A 01  M ttt.p~.phv.pJ.
122f:0010 E3 0E 55 01 E3 0E F4 F4 D2 B0 D9 B2 32 A5 4A AA  c.U.c.ttR0Y22%J*
122f:0020 AB A9 A9 AE 0D 44 B5 40 0A 4D C1 40 F4 F4 F4 F4  +))..D5@.MA@tttt
122f:0030 F4 F4 14 00 18 00 2F 12 FF FF FF FF F4 F4 F4 F4  tt..../.tttt
122f:0040 06 16 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  ..tttttttttttttt
122f:0050 CD 21 CB F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  M!Kttttttttttttt
122f:0060 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  tttttttttttttttt
122f:0070 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4 F4  tttttttttttttttt

if I ti into it the result is good

004e:4236 07               pop  es
dosdebug> 
dosdebug> 
system state: emulated,stopped
AX=26f0  BX=0000  CX=0000  DX=122f  SI=0000  DI=0000  SP=fff8  BP=0000
DS=102f  ES=122f  FS=0000  GS=0000  FL=00133346
CS:IP=004e:4237       SS:SP=102f:fff8

004e:4237 CF               iret
dosdebug> 
dosdebug> 
system state: emulated,stopped
AX=26f0  BX=0000  CX=0000  DX=122f  SI=0000  DI=0000  SP=fffe  BP=0000
DS=102f  ES=122f  FS=0000  GS=0000  FL=00083302
CS:IP=102f:010e       SS:SP=102f:fffe

102f:010e BF0000           mov  di,0000
dosdebug> d dx:0
dosdebug> 

122f:0000 CD 20 00 A0 00 9A F0 FE 1D F0 E8 F6 00 F0 4A 01  M . ..p~.phv.pJ.
122f:0010 E3 0E 55 01 E3 0E E3 0E 01 01 01 00 02 FF FF FF  c.U.c.c......
122f:0020 FF FF FF FF FF FF FF FF FF FF FF FF 25 10 E6 FF  %.f
122f:0030 2F 10 14 00 18 00 2F 12 FF FF FF FF 00 00 00 00  /...../.....
122f:0040 06 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
122f:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 20 20 20  M!K..........   
122f:0060 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20          .....   
122f:0070 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00          ........

Helpful?

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

This is because earlier you did the
patch that catches retf 2 from
interrupt. Please exclude the ints
21,28,2f,33 from that machinery
and things be well.

@andrewbird
Copy link
Member

This one dosemu2/dosemu2@158fe96f8f4 ?

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

Yes.

@andrewbird
Copy link
Member

Adding this gives the correct results, but of course the overrunning of the following instruction is back

diff --git a/src/plugin/debugger/mhpdbgc.c b/src/plugin/debugger/mhpdbgc.c
index 11a2ad0ad..e7b0854dc 100644
--- a/src/plugin/debugger/mhpdbgc.c
+++ b/src/plugin/debugger/mhpdbgc.c
@@ -840,6 +840,8 @@ static void mhp_trace(int argc, char *argv[])
     switch (csp[0]) {
       case 0xcd:
         if (mhpdbgc.trapcmd != 1) { // plain 't'
+          if (csp[1] == 0x21 || csp[1] == 0x2f || csp[1] == 0x28 || csp[1] == 0x33)
+            break;
           LWORD(eip) += 2;
           trace_stack_push(_CS, _IP);
AX=2600  BX=0000  CX=0000  DX=122f  SI=0000  DI=0000  SP=fffe  BP=0000
DS=102f  ES=122f  FS=0000  GS=0000  FL=000b3302
CS:IP=102f:010c       SS:SP=102f:fffe

102f:010c CD21             int  21
dosdebug> t
dosdebug> 
system state: emulated,stopped
AX=26f0  BX=0000  CX=0000  DX=122f  SI=0000  DI=0000  SP=fffe  BP=0000
DS=102f  ES=122f  FS=0000  GS=0000  FL=000b3302
CS:IP=102f:0111       SS:SP=102f:fffe

102f:0111 26813DCD20       cmp  word es:[di],20CD
dosdebug> u 102f:010c
dosdebug> 

102f:010c CD21             int  21
102f:010e BF0000           mov  di,0000
102f:0111 26813DCD20       cmp  word es:[di],20CD
102f:0116 750C             jne  0124 ($+c)
102f:0118 26837D1600       cmp  word es:[di+16],0000
102f:011d 750A             jne  0129 ($+a)
102f:011f BA7001           mov  dx,0170
102f:0122 EB0A             jmp  short 012E ($+a)
102f:0124 BA3601           mov  dx,0136
102f:0127 EB05             jmp  short 012E ($+5)
102f:0129 BA5701           mov  dx,0157
dosdebug> d dx:0
dosdebug> 

122f:0000 CD 20 00 A0 00 9A F0 FE 1D F0 E8 F6 00 F0 4A 01  M . ..p~.phv.pJ.
122f:0010 E3 0E 55 01 E3 0E E3 0E 01 01 01 00 02 FF FF FF  c.U.c.c......
122f:0020 FF FF FF FF FF FF FF FF FF FF FF FF 25 10 E6 FF  %.f
122f:0030 2F 10 14 00 18 00 2F 12 FF FF FF FF 00 00 00 00  /...../.....
122f:0040 06 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
122f:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 20 20 20  M!K..........   
122f:0060 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20          .....   
122f:0070 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00          ........
dosdebug> 

Any other way to reimplement?

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

Many of them, with various limitations.
Add breakpoint, or exclude just the
problematic ones, like 0x26, or just
detect the over-run and print the
missing instruction, or try to catch
iret at VM86_STI or... plenty of ways.
Lets stick to something simple.

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

Or, more likely, nothing should be done but
to find out why the debugger is not pinged
after do_int_iret().

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

In fact, it seems to work for me:

2bed:0040 CD21             int  21
dosdebug> t
dosdebug> 
system state: emulated,stopped in real mode while in DPMI
AX=2c01  BX=339c  CX=1116  DX=193a  SI=0030  DI=4d0e  SP=4ab8  BP=4ab8
DS=339c  ES=62e6  FS=7461  GS=220a  FL=000b7302
CS:IP=2bed:0042       SS:SP=3f32:4ab8

2bed:0042 32E4             xor  ah,ah
dosdebug> 

40 and 42 are adjacent addresses.

@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

Sorry, was in a hurry, tried w/o your changes.
But anyway, do_int_iret() should be investigated.
Some debugger hook is missing somewhere.

@andrewbird
Copy link
Member

So should I do a PR for the fix above, then look at do_int_iret(), as I don't think it should stay as now since we get wrong DOS execution?

andrewbird added a commit to andrewbird/dosemu2 that referenced this issue Nov 29, 2019
Noticed in dosemu2/fdpp#112 tracing `t` can give
incorrect DOS execution, whereas tracing in `ti` behaves properly. It
has been isolated to the trace handler added in 158fe96, for now avoid
using that code on likely problem interrupts.
@stsp
Copy link
Member Author

stsp commented Nov 29, 2019

Good plan, will apply in a few days.

@stsp stsp closed this as completed in 9c4a468 Dec 2, 2019
@stsp
Copy link
Member Author

stsp commented Jan 8, 2020

I am not sure 9c4a468 was correct.
Andrew, you seem to have a PSP test,
could you please check if file table
pointer at offset 0x34 copied or updated
by int21/26h?

stsp added a commit that referenced this issue Jan 8, 2020
stsp added a commit that referenced this issue Jan 8, 2020
It appears Alpha Waves creates the new PSP from the corrupted one.
Checked with PC-DOS: it restores sig too.
PerditionC pushed a commit to FDOS/kernel that referenced this issue Jul 29, 2021
@stsp
Copy link
Member Author

stsp commented Oct 12, 2021

Broken again.

@stsp stsp reopened this Oct 12, 2021
@stsp
Copy link
Member Author

stsp commented Oct 13, 2021

Related to #184

@stsp stsp closed this as completed in 794030b Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants