Creating a bootloader that writes to CPUACTLR?


5 posts
by jtan » Fri Oct 28, 2016 9:12 pm
I have a Raspberry Pi 3B running Raspbian Jessie Lite, and I'm trying to write to the CPU Auxiliary Control Register (CPUACTLR).
Based on what I've read and researched, I need a bootloader that executes in EL3, writes to CPUACTLR on all four cores, and then boots Raspbian.
Did I understand it correctly, and is this possible? If so, what's the simplest way to implement a bootloader that can do this task?
Posts: 2
Joined: Fri Oct 28, 2016 8:52 pm
by AlfredJingle » Sat Oct 29, 2016 3:01 pm
Interesting register, I had not yet come across it. I played around with it and both in HYP mode as well as in secure supervisor mode I can read and write to it. Especially the prefetch control bits seem worth playing with. A quick preliminary test showed that copying blocks of memory to screen-memory (i.e. for a windowing system) is faster with the data-prefetch throttle disabled (bit 21). I will certainly experiment around with this one!
Now for your question: To me it seems easiest to insert the code you want in the early boot routine of Debian. I think I remember that Debian starts with leaving HYP-mode and I would try adding your code around there. I have no clue whether the rest of Debian has any problems with it.
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...
Posts: 44
Joined: Thu Mar 03, 2016 10:43 pm
by jtan » Mon Oct 31, 2016 6:46 pm
Thanks for the reply.
You're saying that you can set CPUACTLR in EL2 without having to set any other registers first? That's interesting, and it does open up the option of setting CPUACTLR while the kernel is in HYP mode.

Unfortunately, it seems like the kernel leaves HYP mode really early, in particular before the secondary CPUs start up. I'm looking into getting the kernel to jump into HYP mode, writing CPUACTLR, and then back into SVC mode, but it doesn't seem easy.
Posts: 2
Joined: Fri Oct 28, 2016 8:52 pm
by AlfredJingle » Tue Nov 01, 2016 9:10 pm
ARM specifically states that CPUACTLR should only be changed before anything else has happened. I interpret this in such a way that the only change you have to use this register is by either writing your own bootloader which in it's place starts Debain, or you change the early code of Debian by adding your own code and than rebuilding Debian.
I can access the register without changing anything else, but this is on my own bare metal Forth OS before or just after leaving HYP-mode, before the MMU is activated etc.
I now as a standard step during start-up disable the pre-fetch throttle, mostly to see whether anything untoward happens. Till now everything is ok, and cpu-temperature is between 43 and 45 degrees.

Out of curiosity: Is there any specific reason why you want to write to the register? It seems irrelevant for most users.
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...
Posts: 44
Joined: Thu Mar 03, 2016 10:43 pm
by koparasy » Wed Jun 14, 2017 8:28 am
Have u managed to write on CPUACTLR_EL1? I am using https://github.com/rsta2/circle a bare metal library and added the instructions which modify the register in HYP mode. However, when i read the register the value is not changed. Could u plz inform me on how you managed to disable prefetch/

Thank u.
Posts: 7
Joined: Wed Jun 14, 2017 8:21 am