dosemu2 / fdpp

FreeDOS plus-plus, 64bit DOS
GNU General Public License v3.0
198 stars 18 forks source link

alpha waves doesn't work #112

Closed stsp closed 3 years ago

stsp commented 5 years ago

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 commented 5 years ago

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

jschwartzenberg commented 5 years ago

This one crashes on 1.4 here as well.

stsp commented 5 years ago

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

stsp commented 5 years ago

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

stsp commented 5 years ago

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

stsp commented 5 years ago

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?

andrewbird commented 5 years ago

okay will do.

andrewbird commented 5 years ago

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 commented 5 years ago

fdpp has by default FILES=64

andrewbird commented 5 years ago

A couple of further data points

stsp commented 5 years ago

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

andrewbird commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

andrewbird commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

andrewbird commented 5 years ago

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

andrewbird commented 5 years ago

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

stsp commented 5 years ago

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.

stsp commented 5 years ago

Oh wait, IIRC CS points to PSP and IP points to 200, so you do not put it after the code, but over the code??

andrewbird commented 5 years ago

I thought I added 200 to segment not offset , but to be honest it was just a guess that it would be safe. I'd tried to allocate memory before using int21/48 but it failed with no more mem I think because I'm assembling to a .com.

stsp commented 5 years ago

You, so you added 8K, and then I don't know what fails.

andrewbird commented 5 years ago

Here's the test case for parent_psp == zero, easily modifiable to test start for CD20 parentpspzero.zip.

andrewbird commented 5 years ago

The CS passed to new_psp() is incorrect (under FDPP it's 0xf000) as it should be the caller's CS, consequently the fmemcpy() in new_psp() copies crap not the old PSP.

see kernel/inthndlr.c

      /* Dos Create New Psp                                           */        
    case 0x26:                                                                  
      new_psp(lr.DX, r->CS);                                                    
      break;                                                                    

I tried using lr.CS, but it seems that lregs has no CS field, so how should I get the caller's CS?

andrewbird commented 5 years ago

Since I have a .com file for the test I temporarily swapped the r->CS for lr.DS in the call to new_psp() and now the new psp is populated properly.

dosdebug> d es:0000
dosdebug> 

0f09:0000 CD 20 00 A0 00 9A F0 FE 1D F0 E7 F6 00 F0 0F F5  M . ..p~.pgv.p.u
0f09:0010 00 F0 11 F5 00 F0 00 00 01 01 01 00 02 FF FF FF  .p.u.p.......
0f09:0020 FF FF FF FF FF FF FF FF FF FF FF FF F9 0C E0 FF  y.`
0f09:0030 09 0D 14 00 18 00 09 0D 00 00 F0 07 00 00 00 00  ..........p.....
0f09:0040 07 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0f09:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 20 20 20  M!K..........   
0f09:0060 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20          .....   
0f09:0070 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00          ........
andrewbird commented 5 years ago

Doing this gives proper PSP data.

commit bafae8f5dd18332b615ea9ec091ab295705b6bcd (HEAD -> newpsp01)
Author: Andrew Bird <ajb@spheresystems.co.uk>
Date:   Wed Nov 27 12:25:01 2019 +0000

    inthndlr.c: Pass the user's CS to new_psp()

diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c
index 8a6c5de..18d8cad 100644
--- a/kernel/inthndlr.c
+++ b/kernel/inthndlr.c
@@ -681,7 +681,7 @@ dispatch:

       /* Dos Create New Psp                                           */
     case 0x26:
-      new_psp(lr.DX, r->CS);
+      new_psp(lr.DX, cu_psp);
       break;
stsp commented 5 years ago

Darn, you posted it 1 second before I pushed that patch!

stsp commented 5 years ago

Yes, that's the right fix, thanks. Unbelievable that 0x26 didn't work!

andrewbird commented 5 years ago

You have a better commit message! Alpha Waves still doesn't work for me though!

stsp commented 5 years ago

Can you try by not zeroing PSP?

andrewbird commented 5 years ago

Sure, but I wonder if when the PSP is activated by function 0x50 it should be populated. In your PC-DOS PSP dump above was that before or after 0x50, because in my tests all the other DOSes zero it on 0x26?

stsp commented 5 years ago

The crash indeed happened after 0x50, and even after 0x30 where the corruption starts to happen. But I added prints into a function msdos() in int.c and IIRC was not seeing 0 even when 0x50 was just called. (but may be a wrong recollection)

andrewbird commented 5 years ago

Not zeroing allows the program to move on past the insert disk stage to this alpha1

Actually it's an assumption that this is further on, it may also be stopping sooner, at least we can say it's different!

stsp commented 5 years ago

Interesting. Because w/o the patch we just did and with not zeroing, I think it went even further - up to setting the gfx mode.

andrewbird commented 5 years ago

Upon exit of that test I saw MCB corruption

dos mem corrupt, first_mcb=0292
prev 07e7:0000|4d f0 07 07 00 00 00 00 00 00 00 00 00 00 00 00 M≡..............
notMZ07ef:0000|20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00         ........

fdpp crashed.
Press any key to exit.
stsp commented 5 years ago

Maybe the prog corrupted it because of the wrong PSP or something. We need to get it working first.

andrewbird commented 5 years ago

With zeroing, by the time I get the 'no more handles error' the PSP appears to have a proper parent

dosdebug> d cs:0000
dosdebug> 

0d5a:0000 CD 20 00 A0 00 9A F0 FE 1D F0 E7 F6 00 F0 0F F5  M . ..p~.pgv.p.u
0d5a:0010 00 F0 11 F5 00 F0 09 0D 01 01 01 00 02 FF FF FF  .p.u.p.......
0d5a:0020 FF FF FF FF FF FF FF FF FF FF FF FF 4A 0D E2 03  J.b.
0d5a:0030 09 0D 14 00 18 00 5A 0D 00 00 09 0D 00 00 00 00  ......Z.........
0d5a:0040 07 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0d5a:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 00 B0 C0  M!K...........0@
0d5a:0060 B4 02 CD E6 72 08 B0 C1 B4 02 CD E6 00 00 B0 C0  4.Mfr.0A4.Mf..0@
0d5a:0070 B4 02 CD E6 72 08 B0 C1 B4 02 CD E6 00 00 00 00  4.Mfr.0A4.Mf....

if I look at the parent PSP

dosdebug> d 0d09:0000
dosdebug> 

0d09:0000 CD 20 00 A0 00 9A F0 FE 1D F0 E7 F6 00 F0 0F F5  M . ..p~.pgv.p.u
0d09:0010 00 F0 11 F5 00 F0 F0 07 01 01 01 00 02 FF FF FF  .p.u.pp......
0d09:0020 FF FF FF FF FF FF FF FF FF FF FF FF F9 0C E2 01  y.b.
0d09:0030 01 0C 14 00 18 00 09 0D 00 00 F0 07 00 00 00 00  ..........p.....
0d09:0040 07 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0d09:0050 CD 21 CB 00 00 00 00 00 00 00 00 00 00 20 20 20  M!K..........   
0d09:0060 20 20 20 20 20 20 20 20 00 00 00 00 00 20 20 20          .....   
0d09:0070 20 20 20 20 20 20 20 20 00 00 00 00 00 00 00 00          ........
dosdebug> mcbs
dosdebug> 

ADDR(LOW) PARAS  OWNER
0292:0000 0x04a9 [DOS]
  => ADDR      PARAS TYPE USAGE
     0293:0000 0x000c [F] Files
     02a0:0000 0x000a [D] Driver (EMUFS)
     02ab:0000 0x029e [B] Buffers
     054a:0000 0x00cf [F] Files
     061a:0000 0x008f [L] CDS Array
     06aa:0000 0x0080 [S] Stacks
     072b:0000 0x0010 [B] Buffers
073c:0000 ------ [LINK]
07e7:0000 0x0007 [FREE]
07ef:0000 0x0410 [COMMAND]
0c00:0000 0x00e6 [02032]
0ce7:0000 0x0010 [02032]
0cf8:0000 0x000f [03337]
0d08:0000 0x0040 [ALPHA]
0d49:0000 0x000f [03418]
0d59:0000 0x01bf [ALPHA_E]
0f19:0000 0x00f5 [03866]
100f:0000 0x8ff0 [FREE] (END)
stsp commented 5 years ago

You need to see it at the time of 0x31 call. After that, it starts "creating" PSP at 0, and maybe even properly, but... :)

andrewbird commented 5 years ago

Edited - removed incorrect statement CF wasn't set so return value was file handle, not error

BTW dosdebug always seems to report 'stopped in real mode while in DPMI' now, though I don't think I'm running any DPMI program.

stsp commented 5 years ago

comcom32

andrewbird commented 5 years ago

Ahh, okay thanks.

andrewbird commented 5 years ago

I noticed that at the int21/3d call cu_psp is zero, so I wondered where else it gets set. I see that return_user() does set this and is called by int21/31 service. This is the line that's suspicious https://github.com/stsp/fdpp/blob/425729abd915881b2ed06d15e5f679d4f7f73021/kernel/task.c#L566 Making it conditional on not being zero allowed program to get further, but I think someone that understands properly what's required here (@stsp) should look at this function closely.

stsp commented 5 years ago

It is exactly the function that is called by 0x31 or 0x4c. It gets to the parent psp which is zero. You are back to the beginning. :)