[hatari-devel] Some patch suggestions

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


while looking at the recently added test support, i have some suggestions 
which should be changed.

The first patch makes sure that a0 is zero when the program is called (which 
is the GEMDOS convention for calling ordinary programs, otherwise the startup 
routine might think it is an accessory, and expects the value of the Basepage 
there).

The second aborts a test program when calling unsupported GEMDOS functions, 
since the handler in the cartridge would otherwise try to jump to the original 
routine, which isn't there. It also adds the names of the MiNT functions for 
this purpose.

The third uses the PC that was pushed by the exception for traces instead of 
the current PC. The current PC in that function will always be the return 
address from the cartridge, and is rather useless.

# HG changeset patch
# User Thorsten Otto <admin@xxxxxxxxxxx>
# Date 1524383700 -7200
#      Sun Apr 22 09:55:00 2018 +0200
# Node ID 14f583a046cb0f0e8b8758a09a417886d595711b
# Parent  8b561454cd5954d9714f582a321d4bef566ad992
Fix setting of p_hitpa for test programs, and make sure a0 is zero on enter

diff -r 8b561454cd59 -r 14f583a046cb src/gemdos.c
--- a/src/gemdos.c	Sat Apr 21 08:11:43 2018 +0200
+++ b/src/gemdos.c	Sun Apr 22 09:55:00 2018 +0200
@@ -3617,6 +3617,7 @@
 	uint8_t *prg;
 	uint32_t nTextLen, nDataLen, nBssLen, nSymLen;
 	uint32_t nRelOff, nRelTabIdx, nCurrAddr;
+	uint32_t memtop;
 
 	prg = File_Read(psPrgName, &nFileSize, NULL);
 	if (!prg || nFileSize < 30)
@@ -3636,16 +3637,23 @@
 	nBssLen = (prg[10] << 24) | (prg[11] << 16) | (prg[12] << 8) | prg[13];
 	nSymLen = (prg[14] << 24) | (prg[15] << 16) | (prg[16] << 8) | prg[17];
 
+	memtop = STMemory_ReadLong(0x436);
+	if ((baseaddr + 0x100 + nTextLen + nDataLen + nBssLen) > memtop)
+	{
+		Log_Printf(LOG_ERROR, "Program too large: '%s'.\n", psPrgName);
+		return -1;
+	}
+
 	if (!STMemory_SafeCopy(baseaddr + 0x100, prg + 28, nTextLen + nDataLen, psPrgName))
 		return -1;
 
 	/* Clear BSS */
 	memset(&STRam[baseaddr + 0x100 + nTextLen + nDataLen], 0, nBssLen);
 
+	memtop = STMemory_ReadLong(0x436);
 	/* Set up basepage - note: some of these values are rather dummies */
 	STMemory_WriteLong(baseaddr, baseaddr);                                    /* p_lowtpa */
-	STMemory_WriteLong(baseaddr + 4, baseaddr + 0x100 + nTextLen + nDataLen
-	                                 + nBssLen + 0x2000);                      /* p_hitpa */
+	STMemory_WriteLong(baseaddr + 4, memtop);                                  /* p_hitpa */
 	STMemory_WriteLong(baseaddr + 8, baseaddr + 0x100);                        /* p_tbase */
 	STMemory_WriteLong(baseaddr + 12, nTextLen);                               /* p_tlen */
 	STMemory_WriteLong(baseaddr + 16, baseaddr + 0x100 + nTextLen);            /* p_dbase */
diff -r 8b561454cd59 -r 14f583a046cb src/tos.c
--- a/src/tos.c	Sat Apr 21 08:11:43 2018 +0200
+++ b/src/tos.c	Sun Apr 22 09:55:00 2018 +0200
@@ -701,6 +701,7 @@
 		0x4f, 0xf9, 0x00, 0x01, 0x80, 0x00, /* lea 0x18000,sp (USP) */
 		0x48, 0x78, TEST_PRG_BASEPAGE >> 8, TEST_PRG_BASEPAGE & 0xff, /* pea 0x1000  (basepage) */
 		0x48, 0x79, 0x00, 0xe0, 0x00, 0x00, /* pea 0xe00000 */
+		0x91, 0xc8,                         /* suba.l a0,a0 */
 		0x4e, 0xf8, TEST_PRG_START >> 8, TEST_PRG_START & 0xff        /* jmp 0x1100 */
 	};
 
# HG changeset patch
# User Thorsten Otto <admin@xxxxxxxxxxx>
# Date 1524389810 -7200
#      Sun Apr 22 11:36:50 2018 +0200
# Node ID 4ef12e215f8948e38e74bb5a50b721c019200dcc
# Parent  14f583a046cb0f0e8b8758a09a417886d595711b
Abort test programs on unsupported GEMDOS calls

diff -r 14f583a046cb -r 4ef12e215f89 src/gemdos.c
--- a/src/gemdos.c	Sun Apr 22 09:55:00 2018 +0200
+++ b/src/gemdos.c	Sun Apr 22 11:36:50 2018 +0200
@@ -3174,8 +3174,309 @@
 		"-", /* 54 */
 		"-", /* 55 */
 		"Frename",
-		"Fdatime"
+		"Fdatime",
+		"-", /* 58 */
+		"-", /* 59 */
+		"-", /* 5A */
+		"-", /* 5B */
+		"Flock", /* 5C */
+		"-", /* 5D */
+		"-", /* 5E */
+		"-", /* 5F */
+		"Nversion", /* 60 */
+		"-", /* 61 */
+		"-", /* 62 */
+		"-", /* 63 */
+		"-", /* 64 */
+		"-", /* 65 */
+		"-", /* 66 */
+		"-", /* 67 */
+		"-", /* 68 */
+		"-", /* 69 */
+		"-", /* 6A */
+		"-", /* 6B */
+		"-", /* 6C */
+		"-", /* 6D */
+		"-", /* 6E */
+		"-", /* 6F */
+		"-", /* 70 */
+		"-", /* 71 */
+		"-", /* 72 */
+		"-", /* 73 */
+		"-", /* 74 */
+		"-", /* 75 */
+		"-", /* 76 */
+		"-", /* 77 */
+		"-", /* 78 */
+		"-", /* 79 */
+		"-", /* 7A */
+		"-", /* 7B */
+		"-", /* 7C */
+		"-", /* 7D */
+		"-", /* 7E */
+		"-", /* 7F */
+		"-", /* 80 */
+		"-", /* 81 */
+		"-", /* 82 */
+		"-", /* 83 */
+		"-", /* 84 */
+		"-", /* 85 */
+		"-", /* 86 */
+		"-", /* 87 */
+		"-", /* 88 */
+		"-", /* 89 */
+		"-", /* 8A */
+		"-", /* 8B */
+		"-", /* 8C */
+		"-", /* 8D */
+		"-", /* 8E */
+		"-", /* 8F */
+		"-", /* 90 */
+		"-", /* 91 */
+		"-", /* 92 */
+		"-", /* 93 */
+		"-", /* 94 */
+		"-", /* 95 */
+		"-", /* 96 */
+		"-", /* 97 */
+		"-", /* 98 */
+		"-", /* 99 */
+		"-", /* 9A */
+		"-", /* 9B */
+		"-", /* 9C */
+		"-", /* 9D */
+		"-", /* 9E */
+		"-", /* 9F */
+		"-", /* A0 */
+		"-", /* A1 */
+		"-", /* A2 */
+		"-", /* A3 */
+		"-", /* A4 */
+		"-", /* A5 */
+		"-", /* A6 */
+		"-", /* A7 */
+		"-", /* A8 */
+		"-", /* A9 */
+		"-", /* AA */
+		"-", /* AB */
+		"-", /* AC */
+		"-", /* AD */
+		"-", /* AE */
+		"-", /* AF */
+		"-", /* B0 */
+		"-", /* B1 */
+		"-", /* B2 */
+		"-", /* B3 */
+		"-", /* B4 */
+		"-", /* B5 */
+		"-", /* B6 */
+		"-", /* B7 */
+		"-", /* B8 */
+		"-", /* B9 */
+		"-", /* BA */
+		"-", /* BB */
+		"-", /* BC */
+		"-", /* BD */
+		"-", /* BE */
+		"-", /* BF */
+		"-", /* C0 */
+		"-", /* C1 */
+		"-", /* C2 */
+		"-", /* C3 */
+		"-", /* C4 */
+		"-", /* C5 */
+		"-", /* C6 */
+		"-", /* C7 */
+		"-", /* C8 */
+		"-", /* C9 */
+		"-", /* CA */
+		"-", /* CB */
+		"-", /* CC */
+		"-", /* CD */
+		"-", /* CE */
+		"-", /* CF */
+		"-", /* D0 */
+		"-", /* D1 */
+		"-", /* D2 */
+		"-", /* D3 */
+		"-", /* D4 */
+		"-", /* D5 */
+		"-", /* D6 */
+		"-", /* D7 */
+		"-", /* D8 */
+		"-", /* D9 */
+		"-", /* DA */
+		"-", /* DB */
+		"-", /* DC */
+		"-", /* DD */
+		"-", /* DE */
+		"-", /* DF */
+		"-", /* E0 */
+		"-", /* E1 */
+		"-", /* E2 */
+		"-", /* E3 */
+		"-", /* E4 */
+		"-", /* E5 */
+		"-", /* E6 */
+		"-", /* E7 */
+		"-", /* E8 */
+		"-", /* E9 */
+		"-", /* EA */
+		"-", /* EB */
+		"-", /* EC */
+		"-", /* ED */
+		"-", /* EE */
+		"-", /* EF */
+		"-", /* F0 */
+		"-", /* F1 */
+		"-", /* F2 */
+		"-", /* F3 */
+		"-", /* F4 */
+		"-", /* F5 */
+		"-", /* F6 */
+		"-", /* F7 */
+		"-", /* F8 */
+		"-", /* F9 */
+		"-", /* FA */
+		"-", /* FB */
+		"-", /* FC */
+		"-", /* FD */
+		"-", /* FE */
+		"Syield", /* FF */
+		"Fpipe", /* 100 */
+		"Ffchown", /* 101 */
+		"Ffchmod", /* 102 */
+		"Fsync", /* 103 */
+		"Fcntl", /* 104 */
+		"Finstat", /* 105 */
+		"Foutstat", /* 106 */
+		"Fgetchar", /* 107 */
+		"Fputchar", /* 108 */
+		"Pwait", /* 109 */
+		"Pnice", /* 10A */
+		"Pgetpid", /* 10B */
+		"Pgetppid", /* 10C */
+		"Pgetpgrp", /* 10D */
+		"Psetpgrp", /* 10E */
+		"Pgetuid", /* 10F */
+		"Psetuid", /* 110 */
+		"Pkill", /* 111 */
+		"Psignal", /* 112 */
+		"Pvfork", /* 113 */
+		"Pgetgid", /* 114 */
+		"Psetgid", /* 115 */
+		"Psigblock", /* 116 */
+		"Psigsetmask", /* 117 */
+		"Pusrval", /* 118 */
+		"Pdomain", /* 119 */
+		"Psigreturn", /* 11A */
+		"Pfork", /* 11B */
+		"Pwait3", /* 11C */
+		"Fselect", /* 11D */
+		"Prusage", /* 11E */
+		"Psetlimit", /* 11F */
+		"Talarm", /* 120 */
+		"Pause", /* 121 */
+		"Sysconf", /* 122 */
+		"Psigpending", /* 123 */
+		"Dpathconf", /* 124 */
+		"Pmsg", /* 125 */
+		"Fmidipipe", /* 126 */
+		"Prenice", /* 127 */
+		"Dopendir", /* 128 */
+		"Dreaddir", /* 129 */
+		"Drewinddir", /* 12A */
+		"Dclosedir", /* 12B */
+		"Fxattr", /* 12C */
+		"Flink", /* 12D */
+		"Fsymlink", /* 12E */
+		"Freadlink", /* 12F */
+		"Dcntl", /* 130 */
+		"Fchown", /* 131 */
+		"Fchmod", /* 132 */
+		"Pumask", /* 133 */
+		"Psemaphore", /* 134 */
+		"Dlock", /* 135 */
+		"Psigpause", /* 136 */
+		"Psigaction", /* 137 */
+		"Pgeteuid", /* 138 */
+		"Pgetegid", /* 139 */
+		"Pwaitpid", /* 13A */
+		"Dgetcwd", /* 13B */
+		"Salert", /* 13C */
+		"Tmalarm", /* 13D */
+		"Psigintr", /* 13E */
+		"Suptime", /* 13F */
+		"Ptrace", /* 140 */
+		"Mvalidate", /* 141 */
+		"Dxreaddir", /* 142 */
+		"Pseteuid", /* 143 */
+		"Psetegid", /* 144 */
+		"Pgetauid", /* 145 */
+		"Psetauid", /* 146 */
+		"Pgetgroups", /* 147 */
+		"Psetgroups", /* 148 */
+		"Tsetitimer", /* 149 */
+		"Dchroot", /* 14A; was Scookie */
+		"Fstat64", /* 14B */
+		"Fseek64", /* 14C */
+		"Dsetkey", /* 14D */
+		"Psetreuid", /* 14E */
+		"Psetregid", /* 14F */
+		"Sync", /* 150 */
+		"Shutdown", /* 151 */
+		"Dreadlabel", /* 152 */
+		"Dwritelabel", /* 153 */
+		"Ssystem", /* 154 */
+		"Tgettimeofday", /* 155 */
+		"Tsettimeofday", /* 156 */
+		"Tadjtime", /* 157 */
+		"Pgetpriority", /* 158 */
+		"Psetpriority", /* 159 */
+		"Fpoll", /* 15A */
+		"Fwritev", /* 15B */
+		"Freadv", /* 15C */
+		"Ffstat64", /* 15D */
+		"Psysctl", /* 15E */
+		"Semulation", /* 15F */
+		"Fsocket", /* 160 */
+		"Fsocketpair", /* 161 */
+		"Faccept", /* 162 */
+		"Fconnect", /* 163 */
+		"Fbind", /* 164 */
+		"Flisten", /* 165 */
+		"Frecvmsg", /* 166 */
+		"Fsendmsg", /* 167 */
+		"Frecvfrom", /* 168 */
+		"Fsendto", /* 169 */
+		"Fsetsockopt", /* 16A */
+		"Fgetsockopt", /* 16B */
+		"Fgetpeername", /* 16C */
+		"Fgetsockname", /* 16D */
+		"Fshutdown", /* 16E */
+		"-", /* 16F */
+		"Pshmget", /* 170 */
+		"Pshmctl", /* 171 */
+		"Pshmat", /* 172 */
+		"Pshmdt", /* 173 */
+		"Psemget", /* 174 */
+		"Psemctl", /* 175 */
+		"Psemop", /* 176 */
+		"Psemconfig", /* 177 */
+		"Pmsgget", /* 178 */
+		"Pmsgctl", /* 179 */
+		"Pmsgsnd", /* 17A */
+		"Pmsgrcv", /* 17B */
+		"-", /* 17C */
+		"Maccess", /* 17D */
+		"-", /* 17E */
+		"-", /* 17F */
+		"Fchown16", /* 180 */
+		"Fchdir", /* 181 */
+		"Ffdopendir", /* 182 */
+		"Fdirfd" /* 183 */
 	};
+
 	if (opcode < ARRAY_SIZE(names))
 		return names[opcode];
 	return "MiNT?";
@@ -3557,6 +3858,15 @@
 		/* branch to pexec, then redirect to old gemdos. */
 		SR |= SR_OVERFLOW;
 		break;
+	 case false:
+		if (!bUseTos)
+		{
+			Log_Printf(LOG_FATAL, "GEMDOS 0x%02hX %s at PC 0x%X unsupported in test mode\n",
+				  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
+				  M68000_GetPC());
+			Main_RequestQuit(1);
+		}
+		break;
 	}
 
 	M68000_SetSR(SR);   /* update the flags in the SR register */
# HG changeset patch
# User Thorsten Otto <admin@xxxxxxxxxxx>
# Date 1524390838 -7200
#      Sun Apr 22 11:53:58 2018 +0200
# Node ID a061d1d94495dab22fbd6285628abf892c8c7cf7
# Parent  4ef12e215f8948e38e74bb5a50b721c019200dcc
Use real PC of caller rather than current PC (which will always be the address from the cartridge) when tracing GEMDOS calls

diff -r 4ef12e215f89 -r a061d1d94495 src/gemdos.c
--- a/src/gemdos.c	Sun Apr 22 11:36:50 2018 +0200
+++ b/src/gemdos.c	Sun Apr 22 11:53:58 2018 +0200
@@ -1426,13 +1426,13 @@
  * GEMDOS Set drive (0=A,1=B,2=C etc...)
  * Call 0xE
  */
-static bool GemDOS_SetDrv(Uint32 Params)
+static bool GemDOS_SetDrv(Uint32 Params, Uint32 CallingPC)
 {
 	/* Read details from stack for our own use */
 	CurrentDrive = STMemory_ReadWord(Params);
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x0E Dsetdrv(0x%x) at PC=0x%X\n", (int)CurrentDrive,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* Still re-direct to TOS */
 	return false;
@@ -1444,7 +1444,7 @@
  * GEMDOS Dfree Free disk space.
  * Call 0x36
  */
-static bool GemDOS_DFree(Uint32 Params)
+static bool GemDOS_DFree(Uint32 Params, Uint32 CallingPC)
 {
 #ifdef HAVE_STATVFS
 	struct statvfs buf;
@@ -1457,7 +1457,7 @@
 
 	/* Note: Drive = 0 means current drive, 1 = A:, 2 = B:, 3 = C:, etc. */
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x36 Dfree(0x%x, %i) at PC 0x%X\n", Address, Drive,
-		  M68000_GetPC());
+		  CallingPC);
 	if (Drive == 0)
 		Drive = CurrentDrive;
 	else
@@ -1564,7 +1564,7 @@
  * GEMDOS MkDir
  * Call 0x39
  */
-static bool GemDOS_MkDir(Uint32 Params)
+static bool GemDOS_MkDir(Uint32 Params, Uint32 CallingPC)
 {
 	char *pDirName, *psDirPath;
 	int Drive;
@@ -1573,7 +1573,7 @@
 	pDirName = (char *)STMemory_STAddrToPointer(STMemory_ReadLong(Params));
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x39 Dcreate(\"%s\") at PC 0x%X\n", pDirName,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pDirName);
 
@@ -1616,7 +1616,7 @@
  * GEMDOS RmDir
  * Call 0x3A
  */
-static bool GemDOS_RmDir(Uint32 Params)
+static bool GemDOS_RmDir(Uint32 Params, Uint32 CallingPC)
 {
 	char *pDirName, *psDirPath;
 	int Drive;
@@ -1625,7 +1625,7 @@
 	pDirName = (char *)STMemory_STAddrToPointer(STMemory_ReadLong(Params));
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x3A Ddelete(\"%s\") at PC 0x%X\n", pDirName,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pDirName);
 
@@ -1669,7 +1669,7 @@
  * GEMDOS ChDir
  * Call 0x3B
  */
-static bool GemDOS_ChDir(Uint32 Params)
+static bool GemDOS_ChDir(Uint32 Params, Uint32 CallingPC)
 {
 	char *pDirName, *psTempDirPath;
 	struct stat buf;
@@ -1679,7 +1679,7 @@
 	pDirName = (char *)STMemory_STAddrToPointer(STMemory_ReadLong(Params));
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x3B Dsetpath(\"%s\") at PC 0x%X\n", pDirName,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pDirName);
 
@@ -1757,7 +1757,7 @@
  * GEMDOS Create file
  * Call 0x3C
  */
-static bool GemDOS_Create(Uint32 Params)
+static bool GemDOS_Create(Uint32 Params, Uint32 CallingPC)
 {
 	/* TODO: host filenames might not fit into this */
 	char szActualFileName[MAX_GEMDOS_PATH];
@@ -1769,7 +1769,7 @@
 	Mode = STMemory_ReadWord(Params+SIZE_LONG);
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x3C Fcreate(\"%s\", 0x%x) at PC 0x%X\n", pszFileName, Mode,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pszFileName);
 
@@ -1878,7 +1878,7 @@
  * GEMDOS Open file
  * Call 0x3D
  */
-static bool GemDOS_Open(Uint32 Params)
+static bool GemDOS_Open(Uint32 Params, Uint32 CallingPC)
 {
 	/* TODO: host filenames might not fit into this */
 	char szActualFileName[MAX_GEMDOS_PATH];
@@ -1898,7 +1898,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE,
 		  "GEMDOS 0x3D Fopen(\"%s\", %s) at PC=0x%X\n",
-		  pszFileName, Modes[Mode], M68000_GetPC());
+		  pszFileName, Modes[Mode], CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pszFileName);
 
@@ -2017,7 +2017,7 @@
  * GEMDOS Close file
  * Call 0x3E
  */
-static bool GemDOS_Close(Uint32 Params)
+static bool GemDOS_Close(Uint32 Params, Uint32 CallingPC)
 {
 	int i, Handle;
 
@@ -2026,7 +2026,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE,
 		  "GEMDOS 0x3E Fclose(%i) at PC 0x%X\n",
-		  Handle, M68000_GetPC());
+		  Handle, CallingPC);
 
 	/* Get internal handle */
 	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
@@ -2058,7 +2058,7 @@
  * GEMDOS Read file
  * Call 0x3F
  */
-static bool GemDOS_Read(Uint32 Params)
+static bool GemDOS_Read(Uint32 Params, Uint32 CallingPC)
 {
 	char *pBuffer;
 	off_t CurrentPos, FileSize;
@@ -2074,7 +2074,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x3F Fread(%i, %i, 0x%x) at PC 0x%X\n",
 	          Handle, Size, Addr,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* Get internal handle */
 	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
@@ -2153,7 +2153,7 @@
  * GEMDOS Write file
  * Call 0x40
  */
-static bool GemDOS_Write(Uint32 Params)
+static bool GemDOS_Write(Uint32 Params, Uint32 CallingPC)
 {
 	char *pBuffer;
 	long nBytesWritten;
@@ -2169,7 +2169,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x40 Fwrite(%i, %i, 0x%x) at PC 0x%X\n",
 	          Handle, Size, Addr,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* Get internal handle */
 	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
@@ -2217,7 +2217,7 @@
  * GEMDOS Delete file
  * Call 0x41
  */
-static bool GemDOS_FDelete(Uint32 Params)
+static bool GemDOS_FDelete(Uint32 Params, Uint32 CallingPC)
 {
 	char *pszFileName, *psActualFileName;
 	int Drive;
@@ -2226,7 +2226,7 @@
 	pszFileName = (char *)STMemory_STAddrToPointer(STMemory_ReadLong(Params));
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x41 Fdelete(\"%s\") at PC 0x%X\n", pszFileName,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pszFileName);
 
@@ -2271,7 +2271,7 @@
  * GEMDOS File seek
  * Call 0x42
  */
-static bool GemDOS_LSeek(Uint32 Params)
+static bool GemDOS_LSeek(Uint32 Params, Uint32 CallingPC)
 {
 	long Offset;
 	int Handle, Mode;
@@ -2285,7 +2285,7 @@
 	Mode = STMemory_ReadWord(Params+SIZE_LONG+SIZE_WORD);
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x42 Fseek(%li, %i, %i) at PC 0x%X\n", Offset, Handle, Mode,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* get internal handle */
 	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
@@ -2338,7 +2338,7 @@
  * GEMDOS Fattrib() - get or set file and directory attributes
  * Call 0x43
  */
-static bool GemDOS_Fattrib(Uint32 Params)
+static bool GemDOS_Fattrib(Uint32 Params, Uint32 CallingPC)
 {
 	/* TODO: host filenames might not fit into this */
 	char sActualFileName[MAX_GEMDOS_PATH];
@@ -2356,7 +2356,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x43 Fattrib(\"%s\", %d, 0x%x) at PC 0x%X\n",
 	          psFileName, nRwFlag, nAttrib,
-		  M68000_GetPC());
+		  CallingPC);
 
 	if (!ISHARDDRIVE(nDrive))
 	{
@@ -2448,7 +2448,7 @@
  * GEMDOS Force (file handle aliasing)
  * Call 0x46
  */
-static bool GemDOS_Force(Uint32 Params)
+static bool GemDOS_Force(Uint32 Params, Uint32 CallingPC)
 {
 	int std, own;
 
@@ -2457,7 +2457,7 @@
         own = STMemory_ReadWord(Params+SIZE_WORD);
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x46 Fforce(%d, %d) at PC 0x%X\n", std, own,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* Get internal handle */
 	if (std > own)
@@ -2490,7 +2490,7 @@
  * GEMDOS Get Directory
  * Call 0x47
  */
-static bool GemDOS_GetDir(Uint32 Params)
+static bool GemDOS_GetDir(Uint32 Params, Uint32 CallingPC)
 {
 	Uint32 Address;
 	Uint16 Drive;
@@ -2500,7 +2500,7 @@
 
 	/* Note: Drive = 0 means current drive, 1 = A:, 2 = B:, 3 = C:, etc. */
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x47 Dgetpath(0x%x, %i) at PC 0x%X\n", Address, (int)Drive,
-		  M68000_GetPC());
+		  CallingPC);
 	if (Drive == 0)
 		Drive = CurrentDrive;
 	else
@@ -2546,7 +2546,7 @@
  * GEMDOS PExec handler
  * Call 0x4B
  */
-static int GemDOS_Pexec(Uint32 Params)
+static int GemDOS_Pexec(Uint32 Params, Uint32 CallingPC)
 {
 	int Drive;
 	Uint16 Mode;
@@ -2573,13 +2573,13 @@
 			memcpy(str, cmd, cmdlen);
 			str[cmdlen] = '\0';
 			LOG_TRACE_PRINT ( "GEMDOS 0x4B Pexec(%i, \"%s\", [%d]\"%s\", 0x%x) at PC 0x%X\n", Mode, name, cmdlen, str, env_string,
-				M68000_GetPC());
+				CallingPC);
 			free(str);
 		}
 		else
 		{
 			LOG_TRACE_PRINT ( "GEMDOS 0x4B Pexec(%i, 0x%x, 0x%x, 0x%x) at PC 0x%X\n", Mode, fname, cmdline, env_string,
-				M68000_GetPC());
+				CallingPC);
 		}
 	}
 
@@ -2617,7 +2617,7 @@
  * GEMDOS Search Next
  * Call 0x4F
  */
-static bool GemDOS_SNext(void)
+static bool GemDOS_SNext(Uint32 CallingPC)
 {
 	struct dirent **temp;
 	int Index;
@@ -2625,7 +2625,7 @@
 	DTA *pDTA;
 	Uint32 DTA_Gemdos;
 
-	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x4F Fsnext() at PC 0x%X\n" , M68000_GetPC());
+	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x4F Fsnext() at PC 0x%X\n" , CallingPC);
 
 	/* Refresh pDTA pointer (from the current basepage) */
 	DTA_Gemdos = STMemory_ReadLong(STMemory_ReadLong(act_pd) + BASEPAGE_OFFSET_DTA);
@@ -2686,7 +2686,7 @@
  * GEMDOS Find first file
  * Call 0x4E
  */
-static bool GemDOS_SFirst(Uint32 Params)
+static bool GemDOS_SFirst(Uint32 Params, Uint32 CallingPC)
 {
 	/* TODO: host filenames might not fit into this */
 	char szActualFileName[MAX_GEMDOS_PATH];
@@ -2704,7 +2704,7 @@
 	nAttrSFirst = STMemory_ReadWord(Params+SIZE_LONG);
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x4E Fsfirst(\"%s\", 0x%x) at PC 0x%X\n", pszFileName, nAttrSFirst,
-		  M68000_GetPC());
+		  CallingPC);
 
 	Drive = GemDOS_FileName2HardDriveID(pszFileName);
 	if (!ISHARDDRIVE(Drive))
@@ -2805,7 +2805,7 @@
 	}
 
 	/* Scan for first file (SNext uses no parameters) */
-	GemDOS_SNext();
+	GemDOS_SNext(CallingPC);
 	/* increment DTA index */
 	DTAIndex++;
 	DTAIndex &= MAX_DTAS_MASK;
@@ -2819,7 +2819,7 @@
  * GEMDOS Rename
  * Call 0x56
  */
-static bool GemDOS_Rename(Uint32 Params)
+static bool GemDOS_Rename(Uint32 Params, Uint32 CallingPC)
 {
 	char *pszNewFileName,*pszOldFileName;
 	/* TODO: host filenames might not fit into this */
@@ -2832,7 +2832,7 @@
 	pszNewFileName = (char *)STMemory_STAddrToPointer(STMemory_ReadLong(Params+SIZE_WORD+SIZE_LONG));
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x56 Frename(\"%s\", \"%s\") at PC 0x%X\n", pszOldFileName, pszNewFileName,
-		  M68000_GetPC());
+		  CallingPC);
 
 	NewDrive = GemDOS_FileName2HardDriveID(pszNewFileName);
 	OldDrive = GemDOS_FileName2HardDriveID(pszOldFileName);
@@ -2870,7 +2870,7 @@
  * GEMDOS GSDToF
  * Call 0x57
  */
-static bool GemDOS_GSDToF(Uint32 Params)
+static bool GemDOS_GSDToF(Uint32 Params, Uint32 CallingPC)
 {
 	DATETIME DateTime;
 	Uint32 pBuffer;
@@ -2883,7 +2883,7 @@
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x57 Fdatime(0x%x, %i, %i) at PC 0x%X\n", pBuffer,
 	          Handle, Flag,
-		  M68000_GetPC());
+		  CallingPC);
 
 	/* get internal handle */
 	if ((Handle = GemDOS_GetValidFileHandle(Handle)) < 0)
@@ -2970,10 +2970,10 @@
  * GEMDOS Pterm0
  * Call 0x00
  */
-static bool GemDOS_Pterm0(Uint32 Params)
+static bool GemDOS_Pterm0(Uint32 Params, Uint32 CallingPC)
 {
 	LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE, "GEMDOS 0x00 Pterm0() at PC 0x%X\n",
-		  M68000_GetPC());
+		  CallingPC);
 	GemDOS_TerminateClose();
 	Symbols_RemoveCurrentProgram();
 
@@ -2990,11 +2990,11 @@
  * GEMDOS Ptermres
  * Call 0x31
  */
-static bool GemDOS_Ptermres(Uint32 Params)
+static bool GemDOS_Ptermres(Uint32 Params, Uint32 CallingPC)
 {
 	LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE, "GEMDOS 0x31 Ptermres(0x%X, %hd) at PC 0x%X\n",
 		  STMemory_ReadLong(Params), (Sint16)STMemory_ReadWord(Params+SIZE_WORD),
-		  M68000_GetPC());
+		  CallingPC);
 	GemDOS_TerminateClose();
 	return false;
 }
@@ -3003,12 +3003,12 @@
  * GEMDOS Pterm
  * Call 0x4c
  */
-static bool GemDOS_Pterm(Uint32 Params)
+static bool GemDOS_Pterm(Uint32 Params, Uint32 CallingPC)
 {
 	uint16_t nExitVal = STMemory_ReadWord(Params);
 
 	LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE, "GEMDOS 0x4C Pterm(%hd) at PC 0x%X\n",
-		  nExitVal, M68000_GetPC());
+		  nExitVal, CallingPC);
 
 	GemDOS_TerminateClose();
 	Symbols_RemoveCurrentProgram();
@@ -3026,14 +3026,14 @@
  * GEMDOS Super
  * Call 0x20
  */
-static bool GemDOS_Super(Uint32 Params)
+static bool GemDOS_Super(Uint32 Params, Uint32 CallingPC)
 {
 	uint32_t nParam = STMemory_ReadLong(Params);
 	uint32_t nExcFrameSize, nRetAddr;
 	uint16_t nSR, nVec = 0;
 
 	LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x20 Super(0x%X) at PC 0x%X\n",
-		  nParam, M68000_GetPC());
+		  nParam, CallingPC);
 
 	/* This call is normally fully handled by TOS - we only
 	 * need to emulate it for TOS-less testing mode */
@@ -3645,11 +3645,13 @@
 	Uint32 Params;
 	int Finished;
 	Uint16 SR;
+	Uint32 CallingPC;
 
 	SR = M68000_GetSR();
 
 	/* Read SReg from stack to see if parameters are on User or Super stack  */
 	CallingSReg = STMemory_ReadWord(Regs[REG_A7]);
+	CallingPC = STMemory_ReadLong(Regs[REG_A7]+SIZE_WORD);
 	if ((CallingSReg&SR_SUPERMODE)==0)      /* Calling from user mode */
 		Params = regs.usp;
 	else
@@ -3673,77 +3675,77 @@
 	switch(GemDOSCall)
 	{
 	 case 0x00:
-		Finished = GemDOS_Pterm0(Params);
+		Finished = GemDOS_Pterm0(Params, CallingPC);
 		break;
 	 case 0x0e:
-		Finished = GemDOS_SetDrv(Params);
+		Finished = GemDOS_SetDrv(Params, CallingPC);
 		break;
 	 case 0x20:
-		Finished = GemDOS_Super(Params);
+		Finished = GemDOS_Super(Params, CallingPC);
 		break;
 	 case 0x31:
-		Finished = GemDOS_Ptermres(Params);
+		Finished = GemDOS_Ptermres(Params, CallingPC);
 		break;
 	 case 0x36:
-		Finished = GemDOS_DFree(Params);
+		Finished = GemDOS_DFree(Params, CallingPC);
 		break;
 	 case 0x39:
-		Finished = GemDOS_MkDir(Params);
+		Finished = GemDOS_MkDir(Params, CallingPC);
 		break;
 	 case 0x3a:
-		Finished = GemDOS_RmDir(Params);
+		Finished = GemDOS_RmDir(Params, CallingPC);
 		break;
 	 case 0x3b:	/* Dsetpath */
-		Finished = GemDOS_ChDir(Params);
+		Finished = GemDOS_ChDir(Params, CallingPC);
 		break;
 	 case 0x3c:
-		Finished = GemDOS_Create(Params);
+		Finished = GemDOS_Create(Params, CallingPC);
 		break;
 	 case 0x3d:
-		Finished = GemDOS_Open(Params);
+		Finished = GemDOS_Open(Params, CallingPC);
 		break;
 	 case 0x3e:
-		Finished = GemDOS_Close(Params);
+		Finished = GemDOS_Close(Params, CallingPC);
 		break;
 	 case 0x3f:
-		Finished = GemDOS_Read(Params);
+		Finished = GemDOS_Read(Params, CallingPC);
 		break;
 	 case 0x40:
-		Finished = GemDOS_Write(Params);
+		Finished = GemDOS_Write(Params, CallingPC);
 		break;
 	 case 0x41:
-		Finished = GemDOS_FDelete(Params);
+		Finished = GemDOS_FDelete(Params, CallingPC);
 		break;
 	 case 0x42:
-		Finished = GemDOS_LSeek(Params);
+		Finished = GemDOS_LSeek(Params, CallingPC);
 		break;
 	 case 0x43:
-		Finished = GemDOS_Fattrib(Params);
+		Finished = GemDOS_Fattrib(Params, CallingPC);
 		break;
 	 case 0x46:
-		Finished = GemDOS_Force(Params);
+		Finished = GemDOS_Force(Params, CallingPC);
 		break;
 	 case 0x47:	/* Dgetpath */
-		Finished = GemDOS_GetDir(Params);
+		Finished = GemDOS_GetDir(Params, CallingPC);
 		break;
 	 case 0x4b:
 		/* Either false or CALL_PEXEC_ROUTINE */
-		Finished = GemDOS_Pexec(Params);
+		Finished = GemDOS_Pexec(Params, CallingPC);
 		break;
 	 case 0x4c:
-		Finished = GemDOS_Pterm(Params);
+		Finished = GemDOS_Pterm(Params, CallingPC);
 		break;
 	 case 0x4e:
-		Finished = GemDOS_SFirst(Params);
+		Finished = GemDOS_SFirst(Params, CallingPC);
 		break;
 	 case 0x4f:
-		Finished = GemDOS_SNext();
+		Finished = GemDOS_SNext(CallingPC);
 		break;
 	 case 0x56:
-		Finished = GemDOS_Rename(Params);
+		Finished = GemDOS_Rename(Params, CallingPC);
 		break;
 	 case 0x57:
-		Finished = GemDOS_GSDToF(Params);
+		Finished = GemDOS_GSDToF(Params, CallingPC);
 		break;
 
 	/* print args for other calls */
@@ -3765,7 +3767,7 @@
 		/* commands with no args */
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x%02hX %s() at PC 0x%X\n",
 			  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
-			  M68000_GetPC());
+			  CallingPC);
 		break;
 		
 	case 0x02:	/* Cconout */
@@ -3779,7 +3781,7 @@
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x%02hX %s(0x%hX) at PC 0x%X\n",
 			  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
 			  STMemory_ReadWord(Params),
-			  M68000_GetPC());
+			  CallingPC);
 		break;
 
 	case 0x09:	/* Cconws */
@@ -3791,7 +3793,7 @@
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x%02hX %s(0x%X) at PC 0x%X\n",
 			  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
 			  STMemory_ReadLong(Params),
-			  M68000_GetPC());
+			  CallingPC);
 		break;
 
 	case 0x44:	/* Mxalloc */
@@ -3799,14 +3801,14 @@
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x44 Mxalloc(0x%X, 0x%hX) at PC 0x%X\n",
 			  STMemory_ReadLong(Params),
 			  STMemory_ReadWord(Params+SIZE_LONG),
-			  M68000_GetPC());
+			  CallingPC);
 		break;
 	case 0x14:	/* Maddalt */
 		/* commands taking 2 longs/pointers */
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x14 Maddalt(0x%X, 0x%X) at PC 0x%X\n",
 			  STMemory_ReadLong(Params),
 			  STMemory_ReadLong(Params+SIZE_LONG),
-			  M68000_GetPC());
+			  CallingPC);
 		break;
 	case 0x4A:	/* Mshrink */
 		/* Mshrink's two pointers are prefixed by reserved zero word:
@@ -3815,7 +3817,7 @@
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x4A Mshrink(0x%X, 0x%X) at PC 0x%X\n",
 			  STMemory_ReadLong(Params+SIZE_WORD),
 			  STMemory_ReadLong(Params+SIZE_WORD+SIZE_LONG),
-			  M68000_GetPC());
+			  CallingPC);
 		if (!bUseTos)
 			Finished = true;
 		break;
@@ -3824,7 +3826,7 @@
 		/* rest of commands */
 		LOG_TRACE(TRACE_OS_GEMDOS, "GEMDOS 0x%02hX (%s) at PC 0x%X\n",
 			  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
-			  M68000_GetPC());
+			  CallingPC);
 	}
 
 	switch(Finished)
@@ -3863,7 +3865,7 @@
 		{
 			Log_Printf(LOG_FATAL, "GEMDOS 0x%02hX %s at PC 0x%X unsupported in test mode\n",
 				  GemDOSCall, GemDOS_Opcode2Name(GemDOSCall),
-				  M68000_GetPC());
+				  CallingPC);
 			Main_RequestQuit(1);
 		}
 		break;


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