[hatari-devel] GEMDOS HD emulation, Hatari cartridge program load code and TT-RAM

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


Hi,

Attached is a patch which "should" add support for profiling
code in TT-RAM, but at least with plain TOS v3 & v4, I don't
see anything getting executed from TT-RAM, either with OpenTTD
or ScummVm.

ScummVm: http://atari-forum.com/viewtopic.php?f=26&t=27728&start=25#p271220
OpenTTD: http://atari-forum.com/viewtopic.php?f=26&t=13658&start=25#p271268


ScummVm (17MB TTP) startup actually fails to error #35.  Same
thing happens with OpenTTD (5MB TTP) if I limit ST-RAM amount
to smaller than the binary size.

Program flags is set to 0x27, i.e. it should have these set:
- fastload (clear only BSS, not whole heap)
- program may be loaded into alternative RAM
- program's Malloc() requests may be satisfied from alternative RAM

I think the problem is the Hatari cartridge GEMDOS HD program load
code, it doesn't respect program header alt-RAM flags.

Thomas?


	- Eero

Ps. I hadn't yet time to check whether things work better
from disk image (no Hatari cartridge code involved, program
is loaded completely by TOS).
diff -r be78790417ca src/debug/profilecpu.c
--- a/src/debug/profilecpu.c	Mon Apr 06 22:32:57 2015 +0200
+++ b/src/debug/profilecpu.c	Wed Apr 08 00:14:16 2015 +0300
@@ -1,7 +1,7 @@
 /*
  * Hatari - profilecpu.c
  * 
- * Copyright (C) 2010-2013 by Eero Tamminen
+ * Copyright (C) 2010-2015 by Eero Tamminen
  *
  * This file is distributed under the GNU General Public License, version 2
  * or at your option any later version. Read the file gpl.txt for details.
@@ -34,6 +34,7 @@
 #define CART_END	0xFC0000
 #define CART_SIZE	(CART_END - CART_START)
 
+#define TTRAM_START	0x01000000
 
 /* if non-zero, output (more) warnings on suspicious:
  * - cycle/instruction counts
@@ -63,6 +64,7 @@
 	Uint32 miss_counts[MAX_MISS];  /* cache miss counts */
 	cpu_profile_item_t *data; /* profile data items */
 	Uint32 size;          /* number of allocated profile data items */
+	profile_area_t ttram; /* TT-RAM stats */
 	profile_area_t ram;   /* normal RAM stats */
 	profile_area_t rom;   /* cartridge ROM stats */
 	profile_area_t tos;   /* ROM TOS stats */
@@ -114,10 +116,14 @@
 			/* and after TOS as it's higher */
 			pc += TosSize;
 		}
+#if ENABLE_WINUAE_CPU
+	} else if (TTmemory && pc >= TTRAM_START && pc < TTRAM_START + 1024*1024*(unsigned)ConfigureParams.Memory.nTTRamSize) {
+		pc += STRamEnd + TosSize + CART_SIZE - TTRAM_START;
+#endif
 	} else {
 		fprintf(stderr, "WARNING: 'invalid' CPU PC profile instruction address 0x%x!\n", pc);
 		/* extra entry at end is reserved for invalid PC values */
-		pc = STRamEnd + TosSize + 0x20000;
+		pc = STRamEnd + TosSize + CART_SIZE;
 #if DEBUG
 		skip_assert = true;
 		DebugUI(REASON_CPU_EXCEPTION);
@@ -146,7 +152,10 @@
 		}
 		idx -= TosSize;
 		/* ROM */
-		return idx + CART_START;
+		if (idx < CART_SIZE) {
+			return idx + CART_START;
+		}
+		idx -= CART_SIZE;
 	} else {
 		/* ROM */
 		if (idx < CART_SIZE) {
@@ -154,8 +163,12 @@
 		}
 		idx -= CART_SIZE;
 		/* TOS */
-		return idx + TosAddress;
+		if (idx < TosSize) {
+			return idx + TosAddress;
+		}
+		idx -= TosSize;
 	}
+	return idx + TTRAM_START;
 }
 
 /* ------------------ CPU profile results ----------------- */
@@ -231,6 +244,13 @@
 	fprintf(stderr, "Cartridge ROM (0x%X-%X):\n", CART_START, CART_END);
 	show_cpu_area_stats(&cpu_profile.rom);
 
+#if ENABLE_WINUAE_CPU
+	if (TTmemory && ConfigureParams.Memory.nTTRamSize) {
+		fprintf(stderr, "TT-RAM (0x%X-%X):\n", TTRAM_START, TTRAM_START + 1024*1024*ConfigureParams.Memory.nTTRamSize);
+		show_cpu_area_stats(&cpu_profile.ttram);
+	}
+#endif
+
 	fprintf(stderr, "\n= %.5fs\n",
 		(double)cpu_profile.all.cycles / MachineClocks.CPU_Freq);
 
@@ -575,6 +595,12 @@
 		fprintf(out, "PROGRAM_TEXT:\t0x%06x-0x%06x\n", text, DebugInfo_GetTEXTEnd());
 	}
 	fprintf(out, "CARTRIDGE:\t0x%06x-0x%06x\n", CART_START, CART_END);
+#if ENABLE_WINUAE_CPU
+	if (TTmemory && ConfigureParams.Memory.nTTRamSize) {
+		end = TTRAM_START + 1024*1024*ConfigureParams.Memory.nTTRamSize;
+	}
+	else
+#endif
 	if (end < CART_END) {
 		end = CART_END;
 	}
@@ -607,7 +633,12 @@
 	memset(&cpu_profile, 0, sizeof(cpu_profile));
 
 	/* Shouldn't change within same debug session */
-	size = (STRamEnd + 0x20000 + TosSize) / 2;
+	size = (STRamEnd + CART_SIZE + TosSize) / 2;
+#if ENABLE_WINUAE_CPU
+	if (TTmemory && ConfigureParams.Memory.nTTRamSize) {
+		size += ConfigureParams.Memory.nTTRamSize * 1024*1024/2;
+	}
+#endif
 
 	/* Add one entry for catching invalid PC values */
 	cpu_profile.data = calloc(size + 1, sizeof(*cpu_profile.data));
@@ -631,9 +662,9 @@
 	cpu_profile.prev_cycles = CyclesGlobalClockCounter;
 	cpu_profile.prev_family = OpcodeFamily;
 	cpu_profile.prev_pc = M68000_GetPC();
-	if ( ConfigureParams.System.bAddressSpace24 )
+	if (ConfigureParams.System.bAddressSpace24) {
 		cpu_profile.prev_pc &= 0xffffff;
-
+	}
 	cpu_profile.loop_start = PC_UNDEFINED;
 	cpu_profile.loop_end = PC_UNDEFINED;
 	cpu_profile.loop_count = 0;
@@ -821,9 +852,9 @@
 	 * emulation itself does that too when PC value is used
 	 */
 	cpu_profile.prev_pc = pc = M68000_GetPC();
-	if ( ConfigureParams.System.bAddressSpace24 )
+	if (unlikely(ConfigureParams.System.bAddressSpace24)) {
 		cpu_profile.prev_pc &= 0xffffff;
-
+	}
 	if (unlikely(profile_loop.fp)) {
 		if (pc < prev_pc) {
 			if (pc == cpu_profile.loop_start && prev_pc == cpu_profile.loop_end) {
@@ -836,7 +867,7 @@
 		} else {
 			if (pc > cpu_profile.loop_end) {
 				log_last_loop();
-				cpu_profile.loop_end = 0xffffffff;			
+				cpu_profile.loop_end = 0xffffffff;
 				cpu_profile.loop_count = 0;
 			}
 		}
@@ -980,6 +1011,7 @@
 void Profile_CpuStop(void)
 {
 	Uint32 *sort_arr, next;
+	unsigned int size, stsize;
 	int active;
 
 	if (cpu_profile.processed || !cpu_profile.enabled) {
@@ -992,7 +1024,13 @@
 	}
 
 	/* user didn't change RAM or TOS size in the meanwhile? */
-	assert(cpu_profile.size == (STRamEnd + 0x20000 + TosSize) / 2);
+	size = stsize = (STRamEnd + CART_SIZE + TosSize) / 2;
+#if ENABLE_WINUAE_CPU
+	if (TTmemory && ConfigureParams.Memory.nTTRamSize) {
+		size += ConfigureParams.Memory.nTTRamSize * 1024*1024/2;
+	}
+#endif
+	assert(cpu_profile.size == size);
 
 	Profile_FinalizeCalls(&(cpu_callinfo), &(cpu_profile.all), Symbols_GetByCpuAddress);
 
@@ -1000,12 +1038,13 @@
 	next = update_area(&cpu_profile.ram, 0, STRamEnd/2);
 	if (TosAddress < CART_START) {
 		next = update_area(&cpu_profile.tos, next, (STRamEnd + TosSize)/2);
-		next = update_area(&cpu_profile.rom, next, cpu_profile.size);
+		next = update_area(&cpu_profile.rom, next, stsize);
 	} else {
 		next = update_area(&cpu_profile.rom, next, (STRamEnd + CART_SIZE)/2);
-		next = update_area(&cpu_profile.tos, next, cpu_profile.size);
+		next = update_area(&cpu_profile.tos, next, stsize);
 	}
-	assert(next == cpu_profile.size);
+	next = update_area(&cpu_profile.ttram, next, size);
+	assert(next == size);
 
 #if DEBUG
 	if (skip_assert) {
@@ -1013,13 +1052,13 @@
 	} else
 #endif
 	{
-		assert(cpu_profile.all.misses == cpu_profile.ram.counters.misses + cpu_profile.tos.counters.misses + cpu_profile.rom.counters.misses);
-		assert(cpu_profile.all.cycles == cpu_profile.ram.counters.cycles + cpu_profile.tos.counters.cycles + cpu_profile.rom.counters.cycles);
-		assert(cpu_profile.all.count == cpu_profile.ram.counters.count + cpu_profile.tos.counters.count + cpu_profile.rom.counters.count);
+		assert(cpu_profile.all.misses == cpu_profile.ttram.counters.misses + cpu_profile.ram.counters.misses + cpu_profile.tos.counters.misses + cpu_profile.rom.counters.misses);
+		assert(cpu_profile.all.cycles == cpu_profile.ttram.counters.cycles + cpu_profile.ram.counters.cycles + cpu_profile.tos.counters.cycles + cpu_profile.rom.counters.cycles);
+		assert(cpu_profile.all.count == cpu_profile.ttram.counters.count + cpu_profile.ram.counters.count + cpu_profile.tos.counters.count + cpu_profile.rom.counters.count);
 	}
 
 	/* allocate address array for sorting */
-	active = cpu_profile.ram.active + cpu_profile.rom.active + cpu_profile.tos.active;
+	active = cpu_profile.ttram.active + cpu_profile.ram.active + cpu_profile.rom.active + cpu_profile.tos.active;
 	sort_arr = calloc(active, sizeof(*sort_arr));
 
 	if (!sort_arr) {
@@ -1037,6 +1076,7 @@
 	sort_arr = index_area(&cpu_profile.ram, sort_arr);
 	sort_arr = index_area(&cpu_profile.tos, sort_arr);
 	sort_arr = index_area(&cpu_profile.rom, sort_arr);
+	sort_arr = index_area(&cpu_profile.ttram, sort_arr);
 	assert(sort_arr == cpu_profile.sort_arr + cpu_profile.active);
 	//printf("%d/%d/%d\n", area->active, sort_arr-cpu_profile.sort_arr, active);
 


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