mamiri
Posts: 2
Joined: Fri Nov 25, 2016 11:48 pm

RPI2 ARM MMU address translations

Sat Nov 26, 2016 12:45 am

Hi, All!
I'm trying to remap the ARM peripheral address with the help of ARM MMU from the address 0x3F000000 to the virtual address of 0xFE000000. The code works on Cortex-A9 modeled by DS5, but it doesn't function on RPI2. I'm not sure if the MMU is working or not, and most of the available bare-metal projects on the Internet are all having a 1 to 1 mapping, so they don't show that MMU can do some virtual address to physical address mappings.
I have tried to work with address 0xFE000000 instead of 0x3F000000 to address peripherals such as the status led and uart but only the real address (0x3F000000) does work for me.

Thank you in advance for your valuable advice!

mamiri
Posts: 2
Joined: Fri Nov 25, 2016 11:48 pm

Re: RPI2 ARM MMU address translations

Sun Nov 27, 2016 6:44 am

I found the solution. The current firmware of RPI2 boots processor in HYP mode and at the HYP mode, MMU operations varies from other privileged ARM modes such as SVC and system.

dradford
Posts: 18
Joined: Mon Feb 15, 2016 3:33 pm

Re: RPI2 ARM MMU address translations

Mon Nov 28, 2016 11:10 am

Yes, the HYP mode thing is very frustrating. I don't really see why the Linux kernel can't do the change to HYP mode itself if it wants, and let the device boot in secure-SVC mode as standard (which IMO is far more sensible).

AlfredJingle
Posts: 69
Joined: Thu Mar 03, 2016 10:43 pm

Re: RPI2 ARM MMU address translations

Tue Nov 29, 2016 4:23 pm

You can use the HTCR and HTTBR registers if you want to enable the MMU from HYP-mode. That is how I used the MMU before I learned how to leave HYP-mode, and basically the translation stuff works exactly the same as in other modes. You can even share the Translation table between the different modes. But as leaving HYP-mode takes only 14 opcodes I find it somehow difficult to see how starting in HYP-mode is a relevant problem.
It is not by the way not Linux which switches to HYP-mode, it is the bootcode of the Raspberry. The first thing every LINUX distro does is to switch away from Hyp-mode, as LINUX needs acces to the secure registers to set up a waterproof system. And HYP=mode is not-safe per definition. I have no clue why the boot-process does the switch to HYP, but there must be a good reason behind it.

But the big question I still have is: why would you want to remap the mapped registers in the 3F... range to another range? I am really curious!
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5537
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: RPI2 ARM MMU address translations

Tue Nov 29, 2016 4:41 pm

AlfredJingle wrote:I have no clue why the boot-process does the switch to HYP, but there must be a good reason behind it.
See: https://github.com/raspberrypi/firmware/issues/369

AlfredJingle
Posts: 69
Joined: Thu Mar 03, 2016 10:43 pm

Re: RPI2 ARM MMU address translations

Wed Nov 30, 2016 12:42 pm

@dom: Many thanks for the link to the interesting discussion!

I have read it all carefully now, but there doesn't seem to be an answer to why the bootcode starts in Hyp-mode. It talks about the need to enable HYP-mode, ie having that feature available for use by the programmer. It does not explain why HYP-mode is enabled by having the Raspi start in HYP-mode. But I am for sure missing a point somewhere.
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5537
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: RPI2 ARM MMU address translations

Wed Nov 30, 2016 6:19 pm

AlfredJingle wrote:I have read it all carefully now, but there doesn't seem to be an answer to why the bootcode starts in Hyp-mode. It talks about the need to enable HYP-mode, ie having that feature available for use by the programmer. It does not explain why HYP-mode is enabled by having the Raspi start in HYP-mode. But I am for sure missing a point somewhere.
I believe if you leave HYP mode without setting any HYP mode interrupts or exceptions, then you can never get back into HYP mode.
Think about how virtualbox works with multiple guest OS's. You don't want those OS's to break free - that is the hypervisor's job to control.

AlfredJingle
Posts: 69
Joined: Thu Mar 03, 2016 10:43 pm

Re: RPI2 ARM MMU address translations

Tue Dec 13, 2016 11:11 pm

@dom: Yeah, sounds reasonable. I am presently playing with cache-cleaning and interrupts for my windowing-system. But after that I will play a bit with HYP-mode again. Thanks for your replies!
going from a 6502 on an Oric-1 to an ARMv8 is quite a big step...

Return to “Bare metal, Assembly language”