shithub: n900

Download patch

ref: 5d67920090391e724e120796c49867b5d9a16e10
parent: 5eb781093b052df92bc4ab4c052e8d4c23ca17f6
author: mia soweli <[email protected]>
date: Wed Sep 13 10:53:20 EDT 2023

trap: add probeaddr() to check for missing uart

--- a/sys/src/9/omap/fns.h
+++ b/sys/src/9/omap/fns.h
@@ -12,7 +12,8 @@
 int cas(long *, long, long);
 int tas(void *);
 
-void evenaddr(uintptr va);
+void evenaddr(uintptr a);
+int probeaddr(uintptr a);
 void procrestore(Proc *);
 void procsave(Proc *);
 void procsetup(Proc *);
--- a/sys/src/9/omap/trap.c
+++ b/sys/src/9/omap/trap.c
@@ -9,6 +9,9 @@
 #include "tos.h"
 #include "ureg.h"
 
+static volatile int probing;
+static volatile int probed;
+
 void
 callwithureg(void (*f) (Ureg *))
 {
@@ -447,6 +450,12 @@
 
 	case PsrMdabt:
 		ureg->pc -= 8;
+		if(probing && !user) {
+			ureg->pc += 4;
+			probed = 0;
+			goto out;
+		}
+
 		traparm(ureg, getdfsr(), getdfar());
 		break;
 
@@ -477,6 +486,7 @@
 		break;
 	}
 
+out:
 	splhi();
 	if(user) {
 		if(up->procctl || up->nnote)
@@ -574,4 +584,26 @@
 
 	kexit(ureg);
 	splhi();
+}
+
+int
+probeaddr(uintptr a)
+{
+	static Lock l;
+	volatile ulong v;
+
+	ilock(&l);
+	probing = 1;
+	probed = 1;
+
+	v = *(ulong*)a;
+
+	coherence();
+	if(!probed) {
+		iunlock(&l);
+		return 0;
+	}
+
+	iunlock(&l);
+	return 1;
 }