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

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


Hi,

On tiistai 21 huhtikuu 2015, Eero Tamminen wrote:
....
> 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?

This happens also with TOS versions that do support Pexec7,
when it's called during bootup, from AUTO folder:
------------------------------------
CPU=$fa015a, VBL=961, FrameCycles=13350, HBL=59, LineCycles=134, DSP=N/A
$00fa015a : 4e41                               trap      #1
> m a7
0000FA9E: 00 4b 00 07 00 00 00 07 00 e0 08 55 00 e0 08 55   .K.........U...U
> r
  D0 0000001C   D1 00E0117C   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000040   D7 00000008 
  A0 00000AF0   A1 00000B2F   A2 00E010F4   A3 0000FAAE 
  A4 00008870   A5 00000000   A6 0000FAF0   A7 0000FA9E 
....
> n
GEMDOS 0x4B Pexec(7, 0x7, 0xe00855, 0xe00855) at PC 0xFA002A

CPU=$fa015c, VBL=961, FrameCycles=21156, HBL=94, LineCycles=100, DSP=N/A
$00fa015c : 4fef 0010                          lea       $10(sp),sp
> r
  D0 0000FB6C   D1 00E0117C   D2 00000000   D3 00000000 
  D4 FA6C0000   D5 00000000   D6 00000040   D7 00000008 
  A0 00000AF0   A1 00000B2F   A2 00E010F4   A3 230000FA 
  A4 015C00E0   A5 117C0000   A6 00000000   A7 0000FA9E 
------------------------------------

A6 isn't the only register smashed, from above one can
see that at last D4, A3, A4, A5 get also changed
(above is with TOS v4).


Same doesn't happen after booting has finished, registers
are preserved (except for scratch ones / D0 return value):
------------------------------------
> r
  D0 0000001C   D1 00009124   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000040   D7 00000001 
  A0 0000F804   A1 0000C6EA   A2 0000A250   A3 0000C69A 
  A4 00000000   A5 0000BF2A   A6 0000C6DC   A7 0000C68A 
....
00FA015A 4e41                     TRAP #$00000001
Next PC: 00fa015c
> n
GEMDOS 0x4B Pexec(7, 0x7, 0xf730, 0x0) at PC 0xFA002A

CPU=$fa015c, VBL=3170, FrameCycles=60154, HBL=502, LineCycles=59930, DSP=N/A
$00fa015c : 4fef 0010                          lea       $10(sp),sp
> r
  D0 0001CFCC   D1 00009124   D2 00000000   D3 00000000 
  D4 00000000   D5 00000000   D6 00000040   D7 00000001 
  A0 0000F804   A1 0000C6EA   A2 0000A250   A3 0000C69A 
  A4 00000000   A5 0000BF2A   A6 0000C6DC   A7 0000C68A
------------------------------------


I.e. checking GEMDOS version and skipping Pexec7 for
GEMDOS versions missing it, wouldn't fix the issue.


> 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

Above probably explains why AUTO folder program execution
fails also for TOS v3 & v4 which do implement Pexec7.

Only reason I could think of, why Pexec7 doesn't work during
bootup is lack of parent basepage.  Until bootup has finished,
there's no valid basepage.


So, the only real solution seems to be skipping Pexec7 call
until TOS has fully booted up.  Basepage check would be one
way to check for that if nobody has better ideas for it.

In C, basepage check would go like this:
------------------------------------
	#define OS_SYSBASE 0x4F2
....
    Uint32 sysbase = STMemory_ReadLong(OS_SYSBASE);
	Uint16 osversion = STMemory_ReadWord(sysbase+0x02);
	/* version of TOS/HW that supports alternate RAM? */
	if (osversion >= 0x0300) {
		Uint32 basepage = STMemory_ReadLong(sysbase+0x28);
		/* valid system basepage for Pexec7? */
		if (STMemory_ReadLong(basepage) == basepage))
			/* use Pexec7 */
			return;
		}
	}
	/* use pexec5 instead */
------------------------------------

Thomas, would you have time to try something like that?

As your code already works after boot, it seems otherwise fine.


	- Eero



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