|
From: falcovorbis <fal...@us...> - 2024-05-30 19:06:31
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "A pseudo Operating System for the Dreamcast.".
The branch, master has been updated
via 34f7e943d311cd0105eb012571e7fcda41d3370d (commit)
from edcd7615c1d7ef0c88f8c0e601b9e11668b010e8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 34f7e943d311cd0105eb012571e7fcda41d3370d
Author: Paul Cercueil <pa...@cr...>
Date: Thu May 30 21:06:02 2024 +0200
Work around MMU issue with SQs (#598)
* mmu: Add functions mmu_disable() and mmu_restore()
These functions can be used to temporarily disable MMU address
translation.
Signed-off-by: Paul Cercueil <pa...@cr...>
* sq: Work around MMU issue by... disabling MMU
This change makes it possible to use SQs in a program that uses the MMU,
by disabling the MMU in sq_lock(), and re-enable it again in
mmu_restore().
This means that memory-mapped data must not be accessed while the SQ is
locked. This should be fine, as it wasn't working properly before, so
it's not a regression.
Signed-off-by: Paul Cercueil <pa...@cr...>
---------
Signed-off-by: Paul Cercueil <pa...@cr...>
-----------------------------------------------------------------------
Summary of changes:
kernel/arch/dreamcast/hardware/sq.c | 9 +++++++++
kernel/arch/dreamcast/include/arch/mmu.h | 17 +++++++++++++++++
kernel/arch/dreamcast/kernel/mmu.c | 12 ++++++++++++
3 files changed, 38 insertions(+)
diff --git a/kernel/arch/dreamcast/hardware/sq.c b/kernel/arch/dreamcast/hardware/sq.c
index 7f34633a..10ef13bd 100644
--- a/kernel/arch/dreamcast/hardware/sq.c
+++ b/kernel/arch/dreamcast/hardware/sq.c
@@ -8,6 +8,7 @@
*/
#include <arch/cache.h>
+#include <arch/mmu.h>
#include <dc/sq.h>
#include <kos/dbglog.h>
#include <kos/mutex.h>
@@ -40,12 +41,20 @@
static mutex_t sq_mutex = MUTEX_INITIALIZER;
+static mmu_token_t mmu_token;
+
void sq_lock(void *dest) {
mutex_lock(&sq_mutex);
+
+ /* Disable MMU, because SQs work differently when it's enabled, and we
+ * don't support it. */
+ mmu_token = mmu_disable();
+
SET_QACR_REGS(dest, dest);
}
void sq_unlock(void) {
+ mmu_restore(mmu_token);
mutex_unlock(&sq_mutex);
}
diff --git a/kernel/arch/dreamcast/include/arch/mmu.h b/kernel/arch/dreamcast/include/arch/mmu.h
index ad0c3aca..5b4a6cf8 100644
--- a/kernel/arch/dreamcast/include/arch/mmu.h
+++ b/kernel/arch/dreamcast/include/arch/mmu.h
@@ -195,6 +195,9 @@ typedef struct mmucontext {
to do so.
*/
extern mmucontext_t *mmu_cxt_current;
+
+struct mmu_token;
+typedef struct mmu_token *mmu_token_t;
/** \endcond */
/** \brief Set the "current" page tables for TLB handling.
@@ -370,6 +373,20 @@ void mmu_shutdown(void);
*/
void mmu_reset_itlb(void);
+/** \brief Temporarily disable MMU address translation.
+ \ingroup mmu
+
+ \return An opaque token to be passed to mmu_restore()
+ */
+mmu_token_t mmu_disable(void);
+
+/** \brief Restore MMU address translation.
+ \ingroup mmu
+
+ \param token The opaque token obtained from mmu_disable()
+ */
+void mmu_restore(mmu_token_t token);
+
__END_DECLS
#endif /* __ARCH_MMU_H */
diff --git a/kernel/arch/dreamcast/kernel/mmu.c b/kernel/arch/dreamcast/kernel/mmu.c
index 8d81fdef..466a1561 100644
--- a/kernel/arch/dreamcast/kernel/mmu.c
+++ b/kernel/arch/dreamcast/kernel/mmu.c
@@ -766,3 +766,15 @@ void mmu_shutdown(void) {
irq_set_handler(EXC_DTLB_PV_WRITE, NULL, NULL);
irq_set_handler(EXC_INITIAL_PAGE_WRITE, NULL, NULL);
}
+
+mmu_token_t mmu_disable(void) {
+ mmu_token_t token = (mmu_token_t)*mmucr;
+
+ *mmucr &= ~0x1;
+
+ return token;
+}
+
+void mmu_restore(mmu_token_t token) {
+ *mmucr = (uint32)token;
+}
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|