littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 613 forks source link

[arch][arm64] replace the trampoline translation table with a trampol… #327

Closed pcc closed 1 year ago

pcc commented 2 years ago

…ine VBAR

I noticed that LK failed to boot on systems that do not support 64KB page sizes (e.g. Linux KVM guest on Apple M1) because the trampoline translation table used a compile-time hardcoded 64KB page size.

Instead of trying to make the trampoline translation table code look for a supported page size at runtime, I realized that it should be possible to remove the trampoline translation table entirely by replacing it with a VBAR that branches to the instruction following the MMU enable. That's what this patch does.

travisg commented 2 years ago

Yah I was thinking the same thing at some point, but was a little worried that some random cpu and/or emulator would freak out in that situation. May still be worth doing however.

travisg commented 2 years ago

re: the 64k thing, had to fix that in zircon by just forcing the trampoline code to use 4K pages. limits the physical address space to 39 bits if just wanting to use two levels of page tables.

Trusty seems to have gone in the different direction and moved the trampoline (and all the early mmu page tables) into C, much like what we did for zircon. Also thinking of picking that up as well.

pcc commented 2 years ago

Yah I was thinking the same thing at some point, but was a little worried that some random cpu and/or emulator would freak out in that situation. May still be worth doing however.

I was a bit worried about that as well. But this seems to work on a variety of systems: QEMU TCG, M1 and Cortex-A (in a downstream fork; I don't currently have a way of running upstream LK on a real Cortex-A). It seems to be supported by the architecture spec as well since the accesses up to the MMU enable are uncached. Maybe we can add a br to the VA of .Lmmu_on_pc after the msr to be safe though.

travisg commented 1 year ago

Was initially a little worried about it but the more I fiddle with this patch the more I'm pretty happy with it, so I think I'll take it pretty much as is. Thanks!