Re: [hatari-devel] Cartridge code Pexec7 / AUTO issue

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On maanantai 20 huhtikuu 2015, Thomas Huth wrote:
> schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:
> > On maanantai 20 huhtikuu 2015, Thomas Huth wrote:
> > > schrieb Uwe Seimet <Uwe.Seimet@xxxxxxxxx>:
> > > > Looks as if the fact there is a a folder caused AUTO with
> > > > executable files in it causes the problem. The files themselves
> > > > are not the problem, they have worked before, until the latest
> > > > commits to the Hatari repository.
> > > > 
> > > > This is what I see after the memory test:
> > > > 
> > > > Bus error lget at 200000fc
> > > > M68000 Bus Error reading at address $200000fc PC=$fa0192.
> > > 
> > > I get a similar crash with one of my AUTO folder programs here now,
> > > too (after I enabled the AUTO folder).
....
> Feel free to debug it (set a breakpoint to the code before the pexec
> stuff in the cartridge, then step through to see how the pexec calls
> behave) ... I unfortunately won't have much spare time to do so during
> the next days :-(

The issue was easier to find just by comparing what the code
does according to trace output.

New cartridge version works when used after TOS has booted:
GEMDOS 0x4B Pexec(0, "C:\FVDI.PRG", [0]"", 0x0) at PC 0xFA002A
GEMDOS 0x2F Fgetdta() at PC 0xFA002A
GEMDOS 0x4E Fsfirst("C:\FVDI.PRG", 0x17) at PC 0xFA002A
GEMDOS 0x4F Fsnext() at PC 0xFA002A
GEMDOS 0x3D Fopen("C:\FVDI.PRG", read-only) at PC=0xFA002A
-> FD 64 (read-only -> read-only)
GEMDOS 0x3F Fread(64, 28, 0x7b02) at PC 0xFA002A
GEMDOS 0x4B Pexec(7, 0x7, 0xa542, 0x0) at PC 0xFA002A
GEMDOS 0x4B Pexec(5, 0x0, 0xa542, 0x0) at PC 0xFA002A
GEMDOS 0x3F Fread(64, 2147483647, 0x12596) at PC 0xFA002A
GEMDOS 0x3E Fclose(64) at PC 0xFA002A

But fails if used during boot:
....
GEMDOS 0x3D Fopen("\AUTO\FVDI.PRG", read-only) at PC=0xFA002A
-> FD 64 (read-only -> read-only)
GEMDOS 0x3F Fread(64, 28, 0xa8fe) at PC 0xFA002A
GEMDOS 0x4B Pexec(7, 0x7, 0xfc052b, 0xfc052b) at PC 0xFA002A
GEMDOS 0x4B Pexec(5, 0x0, 0x3002fc, 0xb0a03fc) at PC 0xFA002A
Bus error wget at 7ff22302

The difference between working and non-working cases is that
in boot case, those pointers change between Pexec7 & Pexec5.

There's no such change visible in the cartridge code:
        ; Let's call Pexec now to create the basepage, first try
        ; Pexec(7) and if that does not work fall back to mode 5
        move.l  10(a6),-(sp)
        move.l  6(a6),-(sp)
        move.l  22(a3),-(sp)    ; program flags in program header
        move.w  #7,-(sp)        ; Create basepage wrt program flags
        move.w  #$4b,-(sp)      ; Pexec (mode 7)
        trap    #1              ; Gemdos
        lea     16(sp),sp
        tst.l   d0
        bpl.s   pexec_ok

        move.l  10(a6),-(sp)
        move.l  6(a6),-(sp)
        clr.l   -(sp)
        move.w  #5,-(sp)        ; Create basepage
        move.w  #$4b,-(sp)      ; Pexec (mode 5)
        trap    #1              ; Gemdos

so it must be done by something else.

And indeed, A6 is zeroed after this Pexec7 call returns.
I.e. cmdline and environment pointers given to Pexec5 are
longs at adresses 6 and 10.  I assume they don't contain
valid input. :-)

The funny thing is that when run from Desktop, Pexec7
call does exactly the same things, but a6 is NOT
modified. Attached is a profile of instructions.


Is AUTO code run in some other mode which causes A6 to
be smashed on return from TOS, compared to running TOS
code from Desktop?


Note that A6 is used also afterwards by cartridge code:
        bsr     load_n_reloc
        clr.l   2(a6)
        clr.l   10(a6)
        move.l  d0,6(a6)

        move.w  #48,-(sp) ; Sversion: get GEMDOS version
        trap    #1        ; call GEMDOS
        addq    #2,sp
        ror.w   #8,d0     ; Major version to high, minor version to low byte
        cmp.w   #$0015,d0
        bge.s   use_gemdos_015
        move.w  #4,(a6)   ; pexec mode 4 for exec. prepared program
        bra.s   mode0_ok
use_gemdos_015:
        move.w  #6,(a6)   ; On GEMDOS 0.15 and higher, we can use mode 6


	- Eero

PS. Looking at different AUTO programs I have, about half of
them use 0x7 prgflags (both Falcon & ST programs), so skipping
Pexec7 call based on zero baseflags as I had suggested earlier
wouldn't help.
Hatari CPU profile (Hatari v1.8.0, WinUAE CPU core)
Cycles/second:	8021247
Field names:	Executed instructions, Used cycles, Instruction cache misses
Field regexp:	^\$([0-9a-f]+) :.*% \((.*)\)$
ST_RAM:		0x000000-0x400000
ROM_TOS:	0xfc0000-0xff0000
CARTRIDGE:	0xfa0000-0xfc0000
# disassembly with profile data: <instructions percentage>% (<sum of instructions>, <sum of cycles>, <sum of i-cache misses>)
$00fa002a :             DC.W      $0008                      0.71% (1, 4, 0)
$00fa002c :             bvs.s     $fa0038                    0.71% (1, 8, 0)
$00fa002e :             bne.s     $fa0032                    0.71% (1, 12, 0)
[...]
$00fa0032 :             move.l    $fa0024(pc),-(sp)          0.71% (1, 24, 0)
$00fa0036 :             rts                                  0.71% (1, 16, 0)
[...]
$00fa015a :             trap      #1                         0.71% (1, 72, 0)
[...]
$00fc81f6 :             link      a6,#$ffd2                  0.71% (1, 16, 0)
$00fc81fa :             clr.w     d0                         0.71% (1, 4, 0)
$00fc81fc :             ext.l     d0                         0.71% (1, 4, 0)
$00fc81fe :             move.l    d0,$ffde(a6)               0.71% (1, 16, 0)
$00fc8202 :             move.l    d0,$ffe2(a6)               0.71% (1, 16, 0)
$00fc8206 :             tst.w     8(a6)                      0.71% (1, 12, 0)
$00fc820a :             beq.s     $fc8222                    0.71% (1, 8, 0)
$00fc820c :             cmpi.w    #3,8(a6)                   0.71% (1, 16, 0)
$00fc8212 :             blt.s     $fc821c                    0.71% (1, 8, 0)
$00fc8214 :             cmpi.w    #6,8(a6)                   0.71% (1, 16, 0)
$00fc821a :             ble.s     $fc8222                    0.71% (1, 8, 0)
$00fc821c :             moveq     #$e0,d0                    0.71% (1, 4, 0)
$00fc821e :             bra       $fc8696                    0.71% (1, 12, 0)
[...]
$00fc8696 :             unlk      a6                         0.71% (1, 12, 0)
$00fc8698 :             rts                                  0.71% (1, 16, 0)
[...]
$00fc92a2 :             link      a6,#0                      0.71% (1, 16, 0)
$00fc92a6 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc92aa :             move.l    0(a6),(a0)+                0.71% (1, 24, 0)
$00fc92ae :             lea       8(a6),a1                   0.71% (1, 8, 0)
$00fc92b2 :             move.l    a1,(a0)+                   0.71% (1, 12, 0)
$00fc92b4 :             move.l    4(a6),(a0)                 0.71% (1, 24, 0)
$00fc92b8 :             clr.l     d0                         0.71% (1, 8, 0)
$00fc92ba :             unlk      a6                         0.71% (1, 12, 0)
$00fc92bc :             rts                                  0.71% (1, 16, 0)
[...]
$00fc92d8 :             btst      #5,(sp)                    0.71% (1, 12, 0)
$00fc92dc :             bne.s     $fc92ea                    0.71% (1, 12, 0)
[...]
$00fc92ea :             cmpi.w    #$20,6(sp)                 0.71% (1, 16, 0)
$00fc92f0 :             beq       $fc93a4                    0.71% (1, 12, 0)
$00fc92f4 :             move.l    a6,-(sp)                   0.71% (1, 12, 0)
$00fc92f6 :             movea.l   $5622,a6                   0.71% (1, 20, 0)
$00fc92fc :             movem.l   d0/a3-a5,$68(a6)           0.71% (1, 44, 0)
$00fc9302 :             move.l    (sp)+,$78(a6)              0.71% (1, 24, 0)
$00fc9306 :             move.w    (sp)+,d0                   0.71% (1, 8, 0)
$00fc9308 :             movea.l   (sp)+,a4                   0.71% (1, 12, 0)
$00fc930a :             btst      #$d,d0                     0.71% (1, 12, 0)
$00fc930e :             bne.s     $fc932e                    0.71% (1, 8, 0)
[...]
$00fc932e :             movem.l   d1-d7/a0-a2,-(sp)          0.71% (1, 88, 0)
$00fc9332 :             move.l    a4,-(sp)                   0.71% (1, 12, 0)
$00fc9334 :             move.w    d0,-(sp)                   0.71% (1, 8, 0)
$00fc9336 :             move      usp,a0                     0.71% (1, 4, 0)
$00fc9338 :             move.l    a0,-(sp)                   0.71% (1, 12, 0)
$00fc933a :             move.l    sp,$7c(a6)                 0.71% (1, 16, 0)
$00fc933e :             lea       $32(sp),a0                 0.71% (1, 8, 0)
$00fc9342 :             movea.l   #$1810,sp                  0.71% (1, 12, 0)
$00fc9348 :             move.l    a0,-(sp)                   0.71% (1, 12, 0)
$00fc934a :             jsr       $fc97c8                    0.71% (1, 20, 0)
$00fc9350 :             addq.l    #4,sp                      0.71% (1, 8, 0)
$00fc9352 :             movea.l   $5622,a5                   0.71% (1, 20, 0)
$00fc9358 :             move.l    d0,$68(a5)                 0.71% (1, 16, 0)
$00fc935c :             movea.l   $7c(a5),a6                 0.71% (1, 16, 0)
$00fc9360 :             movea.l   (a6)+,a4                   0.71% (1, 12, 0)
$00fc9362 :             move.w    (a6)+,d0                   0.71% (1, 8, 0)
$00fc9364 :             movea.l   (a6)+,a3                   0.71% (1, 12, 0)
$00fc9366 :             movem.l   (a6)+,d1-d7/a0-a2          0.71% (1, 92, 0)
$00fc936a :             btst      #$d,d0                     0.71% (1, 12, 0)
$00fc936e :             bne.s     $fc9380                    0.71% (1, 8, 0)
[...]
$00fc9374 :             move.l    a3,-(sp)                   0.71% (1, 12, 0)
$00fc9376 :             move.w    d0,-(sp)                   0.71% (1, 8, 0)
$00fc9378 :             movem.l   $68(a5),d0/a3-a6           0.71% (1, 56, 0)
$00fc937e :             rte                                  0.71% (1, 20, 0)
$00fc9380 :             movea.l   a6,sp                      0.71% (1, 4, 0)
$00fc9382 :             move      a4,usp                     0.71% (1, 4, 0)
$00fc9384 :             bra.s     $fc9374                    0.71% (1, 12, 0)
[...]
$00fc97c8 :             link      a6,#$ffc6                  0.71% (1, 16, 0)
$00fc97cc :             addq.b    #1,$5e90                   0.71% (1, 20, 0)
$00fc97d2 :             clr.w     $52c8                      0.71% (1, 20, 0)
$00fc97d8 :             addq.w    #1,$52c8                   0.71% (1, 20, 0)
$00fc97de :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc97e2 :             move.w    (a0),$ffe6(a6)             0.71% (1, 16, 0)
$00fc97e6 :             cmpi.w    #$57,$ffe6(a6)             0.71% (1, 16, 0)
$00fc97ec :             ble.s     $fc97f4                    0.71% (1, 12, 0)
[...]
$00fc97f4 :             move.l    #$5f36,(sp)                0.71% (1, 20, 0)
$00fc97fa :             jsr       $fc92a2                    0.71% (1, 20, 0)
$00fc9800 :             move.l    d0,$ffde(a6)               0.71% (1, 16, 0)
$00fc9804 :             beq       $fc9894                    0.71% (1, 12, 0)
[...]
$00fc9894 :             move.w    $ffe6(a6),d0               0.71% (1, 12, 0)
$00fc9898 :             muls.w    #6,d0                      0.71% (1, 48, 0)
$00fc989c :             add.l     #$fe856a,d0                0.71% (1, 16, 0)
$00fc98a2 :             move.l    d0,$ffd6(a6)               0.71% (1, 16, 0)
$00fc98a6 :             movea.l   $ffd6(a6),a0               0.71% (1, 16, 0)
$00fc98aa :             move.w    4(a0),$ffec(a6)            0.71% (1, 20, 0)
$00fc98b0 :             tst.w     $ffec(a6)                  0.71% (1, 12, 0)
$00fc98b4 :             beq       $fc9b22                    0.71% (1, 12, 0)
$00fc98b8 :             tst.w     $ffe6(a6)                  0.71% (1, 12, 0)
$00fc98bc :             beq       $fc9b22                    0.71% (1, 12, 0)
$00fc98c0 :             cmpi.w    #$c,$ffe6(a6)              0.71% (1, 16, 0)
$00fc98c6 :             blt.s     $fc98dc                    0.71% (1, 8, 0)
$00fc98c8 :             cmpi.w    #$10,$ffe6(a6)             0.71% (1, 16, 0)
$00fc98ce :             blt       $fc9b22                    0.71% (1, 12, 0)
$00fc98d2 :             cmpi.w    #$13,$ffe6(a6)             0.71% (1, 16, 0)
$00fc98d8 :             bgt       $fc9b22                    0.71% (1, 12, 0)
[...]
$00fc9b22 :             btst      #7,$ffed(a6)               0.71% (1, 16, 0)
$00fc9b28 :             beq       $fc9cba                    0.71% (1, 12, 0)
[...]
$00fc9cba :             clr.l     $ffde(a6)                  0.71% (1, 24, 0)
$00fc9cbe :             cmpi.w    #$3d,$ffe6(a6)             0.71% (1, 16, 0)
$00fc9cc4 :             beq.s     $fc9cd0                    0.71% (1, 8, 0)
$00fc9cc6 :             cmpi.w    #$3c,$ffe6(a6)             0.71% (1, 16, 0)
$00fc9ccc :             bne       $fc9d94                    0.71% (1, 12, 0)
[...]
$00fc9d94 :             tst.l     $ffde(a6)                  0.71% (1, 16, 0)
$00fc9d98 :             bne       $fc9ea6                    0.71% (1, 12, 0)
$00fc9d9c :             andi.w    #$7f,$ffec(a6)             0.71% (1, 20, 0)
$00fc9da2 :             move.w    $ffec(a6),d0               0.71% (1, 12, 0)
$00fc9da6 :             bra       $fc9e8a                    0.71% (1, 12, 0)
[...]
$00fc9e40 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e44 :             move.w    $e(a0),-(sp)               0.71% (1, 16, 0)
$00fc9e48 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e4c :             move.w    $c(a0),-(sp)               0.71% (1, 16, 0)
$00fc9e50 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e54 :             move.w    $a(a0),-(sp)               0.71% (1, 16, 0)
$00fc9e58 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e5c :             move.w    8(a0),-(sp)                0.71% (1, 16, 0)
$00fc9e60 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e64 :             move.w    6(a0),-(sp)                0.71% (1, 16, 0)
$00fc9e68 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e6c :             move.w    4(a0),-(sp)                0.71% (1, 16, 0)
$00fc9e70 :             movea.l   8(a6),a0                   0.71% (1, 16, 0)
$00fc9e74 :             move.w    2(a0),-(sp)                0.71% (1, 16, 0)
$00fc9e78 :             movea.l   $ffd6(a6),a0               0.71% (1, 16, 0)
$00fc9e7c :             movea.l   (a0),a0                    0.71% (1, 12, 0)
$00fc9e7e :             jsr       (a0)                       0.71% (1, 16, 0)
$00fc9e80 :             adda.w    #$e,sp                     0.71% (1, 12, 0)
$00fc9e84 :             move.l    d0,$ffde(a6)               0.71% (1, 16, 0)
$00fc9e88 :             bra.s     $fc9ea6                    0.71% (1, 12, 0)
$00fc9e8a :             tst.w     d0                         0.71% (1, 4, 0)
$00fc9e8c :             beq       $fc9daa                    0.71% (1, 12, 0)
$00fc9e90 :             cmp.w     #1,d0                      0.71% (1, 8, 0)
$00fc9e94 :             beq       $fc9dcc                    0.71% (1, 12, 0)
$00fc9e98 :             cmp.w     #2,d0                      0.71% (1, 8, 0)
$00fc9e9c :             beq       $fc9dfe                    0.71% (1, 12, 0)
$00fc9ea0 :             cmp.w     #3,d0                      0.71% (1, 8, 0)
$00fc9ea4 :             beq.s     $fc9e40                    0.71% (1, 12, 0)
$00fc9ea6 :             move.l    $ffde(a6),d0               0.71% (1, 16, 0)
$00fc9eaa :             unlk      a6                         0.71% (1, 12, 0)
$00fc9eac :             rts                                  0.71% (1, 16, 0)
# <callee>: <caller1> = <calls> <types>[ <inclusive/totals>[ <exclusive/totals>]], <caller2> ..., <callee name>
# types: u = unknown PC change, n = PC moved to next instruction, b = branch/jump, s = subroutine call, r = return from subroutine, e = exception, x = return from exception, 
# totals: calls/instructions/cycles/misses


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/