Re: [hatari-devel] Adding Aranym features for Hatari?

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


Hi,

On lauantai 20 lokakuu 2012, Thomas Huth wrote:
> For Bus Error, you can use M68000_BusError(), for priviledge exception
> you could try something like Exception(8,0,M68000_EXC_SRC_CPU).
> Anyway, you've got to make sure to skip the m68k_incpc() and other
> remaining code when you did that, so that the CPU can correctly
> continue with the exception handler.

Does the attached patch look OK?


	- Eero
diff -r 1321d493b6f2 src/cpu/hatari-glue.c
--- a/src/cpu/hatari-glue.c	Sat Oct 20 23:35:48 2012 +0300
+++ b/src/cpu/hatari-glue.c	Sat Oct 20 23:47:21 2012 +0300
@@ -219,11 +219,14 @@
  */
 unsigned long OpCode_NatFeat_ID(uae_u32 opcode)
 {
-	Uint32 stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
+	Uint32 ret, stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
 	Uint16 SR = M68000_GetSR();
 
-	Regs[REG_D0] = NatFeat_ID(stack);
+	ret = NatFeat_ID(stack);
+	if (NatFeat_HadException())
+		return 4 * CYCLE_UNIT / 2;
 
+	Regs[REG_D0] = ret;
 	M68000_SetSR(SR);
 
 	m68k_incpc(2);
@@ -238,13 +241,16 @@
  */
 unsigned long OpCode_NatFeat_Call(uae_u32 opcode)
 {
-	Uint32 stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
+	Uint32 ret, stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
 	Uint16 SR = M68000_GetSR();
 	bool super;
 
 	super = ((SR & SR_SUPERMODE) == SR_SUPERMODE);
-	Regs[REG_D0] = NatFeat_Call(stack, super);
+	ret = NatFeat_Call(stack, super);
+	if (NatFeat_HadException())
+		return 4 * CYCLE_UNIT / 2;
 
+	Regs[REG_D0] = ret;
 	M68000_SetSR(SR);
 
 	m68k_incpc(2);
diff -r 1321d493b6f2 src/debug/natfeats.c
--- a/src/debug/natfeats.c	Sat Oct 20 23:35:48 2012 +0300
+++ b/src/debug/natfeats.c	Sat Oct 20 23:47:21 2012 +0300
@@ -17,6 +17,7 @@
 #include "main.h"
 #include "configuration.h"
 #include "stMemory.h"
+#include "m68000.h"
 #include "natfeats.h"
 
 #define NF_DEBUG 1
@@ -26,8 +27,9 @@
 # define Dprintf(a)
 #endif
 
+static bool had_exception;
+
 /* TODO:
- * - bus error / priviledge exception, not just error return
  * - supervisor vs. user stack handling?
  * - clipboard and hostfs native features?
  */
@@ -44,7 +46,8 @@
 	Dprintf(("NF name[%d](0x%x, %d)\n", subid, ptr, len));
 
 	if (!STMemory_ValidArea(ptr, len)) {
-		/* TODO: bus error */
+		M68000_BusError(ptr, BUS_ERROR_WRITE);
+		had_exception = true;
 		return 0;
 	}
 	if (subid) {
@@ -71,7 +74,8 @@
 	//Dprintf(("NF stderr(0x%x)\n", ptr));
 
 	if (!STMemory_ValidArea(ptr, 1)) {
-		/* TODO: bus error */
+		M68000_BusError(ptr, BUS_ERROR_READ);
+		had_exception = true;
 		return 0;
 	}
 	str = (const char *)STRAM_ADDR(ptr);
@@ -109,6 +113,10 @@
 #define MASTERID2IDX(id)        (((id) >> ID_SHIFT)-1)
 #define MASKOUTMASTERID(id)     ((id) & ((1L << ID_SHIFT)-1))
 
+bool NatFeat_HadException(void)
+{
+	return had_exception;
+}
 
 Uint32 NatFeat_ID(Uint32 stack)
 {
@@ -118,9 +126,12 @@
 
 	ptr = STMemory_ReadLong(stack);
 	if (!STMemory_ValidArea(ptr, FEATNAME_MAX)) {
-		/* TODO: bus error */
+		M68000_BusError(ptr, BUS_ERROR_READ);
+		had_exception = true;
 		return 0;
 	}
+	had_exception = false;
+
 	name = (const char *)STRAM_ADDR(ptr);
 	Dprintf(("NF ID(0x%x)\n", ptr));
 	Dprintf(("   \"%s\"\n", name));
@@ -139,6 +150,7 @@
 	Uint32 subid = STMemory_ReadLong(stack);
 	unsigned int idx = MASTERID2IDX(subid);
 	subid = MASKOUTMASTERID(subid);
+	had_exception = false;
 
 	if (idx >= ARRAYSIZE(features)) {
 		Dprintf(("ERROR: invalid NF ID %d requested\n", idx));
@@ -146,7 +158,8 @@
 	}
 	if (features[idx].super && !super) {
 		Dprintf(("ERROR: NF function %d called without supervisor mode\n", idx));
-		/* TODO: priviledge exception */
+		Exception(8, 0, M68000_EXC_SRC_CPU);
+		had_exception = true;
 		return 0;
 	}
 	stack += SIZE_LONG;
diff -r 1321d493b6f2 src/debug/natfeats.h
--- a/src/debug/natfeats.h	Sat Oct 20 23:35:48 2012 +0300
+++ b/src/debug/natfeats.h	Sat Oct 20 23:47:21 2012 +0300
@@ -10,5 +10,6 @@
 
 extern Uint32 NatFeat_ID(Uint32);
 extern Uint32 NatFeat_Call(Uint32, bool isSuper);
+extern bool NatFeat_HadException(void);
 
 #endif /* HATARI_NATFEATS_H */
diff -r 1321d493b6f2 src/uae-cpu/hatari-glue.c
--- a/src/uae-cpu/hatari-glue.c	Sat Oct 20 23:35:48 2012 +0300
+++ b/src/uae-cpu/hatari-glue.c	Sat Oct 20 23:47:21 2012 +0300
@@ -213,13 +213,16 @@
  */
 unsigned long OpCode_NatFeat_ID(uae_u32 opcode)
 {
-	Uint32 stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
+	Uint32 ret, stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
 	Uint16 SR = M68000_GetSR();
 
-	Regs[REG_D0] = NatFeat_ID(stack);
+	ret = NatFeat_ID(stack);
+	if (NatFeat_HadException())
+		return 4;
 
+	Regs[REG_D0] = ret;
 	M68000_SetSR(SR);
-
+	
 	m68k_incpc(2);
 	fill_prefetch_0();
 	return 4;
@@ -230,13 +233,16 @@
  */
 unsigned long OpCode_NatFeat_Call(uae_u32 opcode)
 {
-	Uint32 stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
+	Uint32 ret, stack = Regs[REG_A7] + SIZE_LONG;	/* skip return address */
 	Uint16 SR = M68000_GetSR();
 	bool super;
 
 	super = ((SR & SR_SUPERMODE) == SR_SUPERMODE);
-	Regs[REG_D0] = NatFeat_Call(stack, super);
+	ret = NatFeat_Call(stack, super);
+	if (NatFeat_HadException())
+		return 4;
 
+	Regs[REG_D0] = ret;
 	M68000_SetSR(SR);
 
 	m68k_incpc(2);


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