aboutsummaryrefslogtreecommitdiff
path: root/psr.h
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-12-17 17:01:41 +0100
committerWojtek Kosior <kwojtus@protonmail.com>2019-12-17 17:01:41 +0100
commit7dbdf1ee0a064e9b2c5fedd7bd4e2b67f0532b09 (patch)
tree1ff297ee593d14151d200ec6e4db30f360dabfd0 /psr.h
parent37821a7d49e78132e7bdf12e04a9ed339588650c (diff)
downloadrpi-MMU-example-7dbdf1ee0a064e9b2c5fedd7bd4e2b67f0532b09.tar.gz
rpi-MMU-example-7dbdf1ee0a064e9b2c5fedd7bd4e2b67f0532b09.zip
make things work again on real hw (setting system mode moved to boot.S)
Diffstat (limited to 'psr.h')
-rw-r--r--psr.h55
1 files changed, 0 insertions, 55 deletions
diff --git a/psr.h b/psr.h
index dfbb878..9809fc4 100644
--- a/psr.h
+++ b/psr.h
@@ -64,59 +64,4 @@ inline static PSR_t read_CPSR(void)
return CPSR;
}
-//// Write function not working for some reason... Assembly from gcc
-//// looks ok. Needs checking on real hw.
-
-//inline static void write_CPSR(PSR_t CPSR)
-//{
- // write to current program status register and synchronize context
- // asm("msr cpsr, %0\n\r"
- // "isb" :: "r" (CPSR.raw) : "memory");
-//}
-
-inline static void set_system_mode(void)
-{
- // hack to fix an unexplained bug; volatile needed in case of
- // compilation with optimizations
- volatile PSR_t CPSR __attribute__((unused)) = read_CPSR();
-
- //// there are 2 ways of changing mode, both with the same
- //// problem (see the long comment below)
-
- //// way 1
- // CPSR.fields.M_4_0 = MODE_SYSTEM;
- // write to current program status register and synchronize context
- // asm("msr cpsr, %0\n\r"
- // "isb":: "r" (CPSR.raw) : "memory");
-
- //// way 2
- asm("cps #0b11111\n\r"
- "isb" ::: "memory");
-}
-
-// The thing with writing to cpsr is weird. I used to have a single
-// function that would set the system mode by:
-// 1. reading the cpsr
-// 2. modifying the value using bit shifts and logical or
-// 3. writing the value back
-// When introducing structs and bitfields I wanted to have separate
-// functions for reading and writing the cpsr and have code up the
-// call stack handle value modification. For some reason this didn't
-// work - all would just hang when writing the CPSR. It turned out
-// everything works if i call read_CPSR() from the same function, in
-// which i write to cpsr. And I don't even need to use the value
-// I read. I can just discard it (we're compiling without
-// optimizations, so read_CPSR() is still called) and use the value
-// passed as argument. I noticed an even weirder thing: the 2nd way
-// of changing mode (cps instruction) doesn't work normally, but,
-// just as msr, it does work when I call read_CPSR() before it. Even
-// weirder - I cannot replace read_CPSR() with the actual assembly it
-// does, because it stops working again! Asm generated by gcc looks
-// ok, so Idk, maybe its some qemu issue (haven't tested on real RPi
-// yet). I seem to have experienced uart printing inserted here and
-// there do the same magic read_CPSR() does (but, again, not always).
-// Unfortunately, nop repeated several hundreds times (or a recursive
-// nop function, that just calls itself a given number of times)
-// doesn't have this magical property :(
-
#endif // PSR_H