diff options
author | vetch <vetch97@gmail.com> | 2019-12-17 17:16:40 +0100 |
---|---|---|
committer | vetch <vetch97@gmail.com> | 2019-12-17 17:16:40 +0100 |
commit | 5cb10bcc7d0c6d4159103f05ba228a09ca365fac (patch) | |
tree | d248f2a519e7b2b4707b6889a971165c75c4af48 /psr.h | |
parent | 90d208f074626521118984902ca8d3ebfd17e62f (diff) | |
parent | 7dbdf1ee0a064e9b2c5fedd7bd4e2b67f0532b09 (diff) | |
download | rpi-MMU-example-5cb10bcc7d0c6d4159103f05ba228a09ca365fac.tar.gz rpi-MMU-example-5cb10bcc7d0c6d4159103f05ba228a09ca365fac.zip |
Merge branch 'bob' of https://repo.or.cz/RPi-MMU-example into alice
# Conflicts:
# kernel.c
Diffstat (limited to 'psr.h')
-rw-r--r-- | psr.h | 55 |
1 files changed, 0 insertions, 55 deletions
@@ -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 |