Commit Graph

115 Commits

Author SHA1 Message Date
Michael Shavit
284f83af11 [arch][arm64] Fix mmu_unmap issue when FEAT_TTL is implemented
Precisely set bits [55:22] of the vaddress in bits [43:0] for the vae1is
and vaee1is TLBI commands.

On platforms where FEAT_TLL is implemented, bits [47:44] of the command
accept a TTL parameter which can optionally be set to hint the
translation table level containing the address being invalidated.
Implementations aren't architecturally required to perform the
invalidation if the hint is incorrect however. Invalidations may
therefore fail with the current implementation if the vaddress has bits
set in [58:55].

This is notably an issue on ARM fastmodels which doesn't perform the
invalidation when the TTL parameter is incorrect.
2023-09-25 16:03:45 -07:00
Alex Richardson
82e565e232 [arm64] Allow assembling with clang
Clang does not accept this .if condition since phys_offset is a register
alias and not an absolute expression. We can keep these two instructions
here if the argument is zero since the result will be the same.
Additionally, this macro is only called once and always passes a non-zero
argument. If more calls are added in the future and avoiding these two
instructions just before a loop is really important, we could use
`.ifnc \phys_offset,0` instead, but that looks rather obscure to me.
2023-06-01 17:50:50 -07:00
Alex Richardson
6bbdcd5a09 [arm64][clang] Silence a register size mismatch warning
Even though we only need 32 bits here, clang warns that we should be
using a "w" register in the inline assembly (which is not legal with
mrs/msr). Silence the warning by declaring the value as unsigned long.

(cherry picked from commit a0de5d88dfc67b3ba34c0455b1619e12e6cfccae)
2023-04-23 17:23:31 -07:00
Travis Geiselbrecht
7017a8fff9 [arch][mmu] add another routine to query if the arch supports user aspaces
Trim the arch mmu unit tests accordingly.

Should probably switch this to a #define, but it's possible some of
these queries could be dynamically detected (XN for example). May
revisit at some point.
2022-10-23 22:40:00 -07:00
Travis Geiselbrecht
d5451cc8e6 [arch][tests] add a way to query some arch mmu features
Allow asking the arch layer if it supports NX pages or NS pages.
Have the arch mmu test code test accordingly.
Also tweak the tests to pass on arm32 mmu, which does not precisely
match the return semantics of the rest of the mmu routines on map/unmap.
2022-10-21 00:00:49 -07:00
Peter Collingbourne
576a7a7c82 [arch][arm64] determine the correct TCR_EL1.IPS at runtime
Change the early startup code to set TCR_EL1.IPS to
ID_AA64MMFR0_EL1.PARange if it has a defined value (the currently
defined values have the same meanings), but use 48-bit PAs if 52-bit
PAs are supported because 52-bit PAs have a different translation
table format that we don't support. Stash the computed TCR_EL1 in a
variable and use it in the context switch code.
2022-07-22 23:54:03 -07:00
Travis Geiselbrecht
6462cbf51c [arch][fpu] add ability to specify per file or module if code needs fpu
Have the arch define additional compiler flags to explicit support or
not support a floating point unit.

Add ability for modules to per file or for the whole module mark code
as needing floating point support.

Add default flags for arm64, riscv, and x86 toolchains.

Needed because gcc 12 is getting much more aggressive about using vector
instructions for non float code, so getting away with avoiding it was
no longer working.

Still not perfect: printf code is being compiled with float, so it's
possible to use floating point instructions inside core kernel or
interrupt handling code if a printf is used.

Possibly will have problems on architectures where mixing float and non
float code at the linker generates issues, but so far seems to be okay.
2022-07-17 16:32:24 -07:00
Peter Collingbourne
b7af2cdf26 [arch][arm64] replace the trampoline translation table with a trampoline 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.
2022-07-17 13:49:59 -07:00
Travis Geiselbrecht
a007f66728 [arch][arm64] update some comments in assembly 2022-07-17 13:21:31 -07:00
Aaron Odell
be0ba2ca14 [arch][arm64] cache maintainance on page tables during boot
Add cache clean + invalidate on the page tables that get modified during
startup before the MMU is enabled. Without this, if these memory regions
were present in cache before LK started, the CPU will see the stale
cached values as soon as the MMU is enabled. Invalidating these forces
the CPU to fetch the correct values from memory after the MMU is enabled.
2022-07-17 13:18:59 -07:00
Peter Collingbourne
4a15661ee0 [arch][arm64] use SMC when booted at EL2 in QEMU
If we were booted at EL2 (e.g. when passing -machine
virt,virtualization=on), we need to use SMC instead of HVC for PSCI
calls. Change psci_call() to do this and add a flag to do-qemuarm to
allow testing this scenario.
2022-04-19 18:32:12 -07:00
Peter Collingbourne
bce9599d80 [arch][arm64] disable EL1 FPU traps even when starting at EL1
It is possible for early initialization functions such as lk_main()
to contain NEON instructions because we don't build the kernel with
-mgeneral-regs-only. As a result we can end up taking an FPU exception
before we are ready to handle it.

We didn't have this problem when starting at a higher exception level
than EL1 because we turned off FPU traps in arm64_elX_to_el1(). But we
neglected to do so when starting at EL1. Fix the problem by moving the
CPACR_EL1 manipulation out of arm64_elX_to_el1() and into arm_reset().
2022-03-30 11:04:11 -07:00
Travis Geiselbrecht
3db7e86b59 [arch][arm64] save the boot arg registers (x0-x3) in a temporary spot in the boot path
Much of the start.S path avoids using these registers up until now to
avoid trashing any state, but its getting fairly difficult and error
prone to keep this up. Save the args as soon as its known that its the
boot cpu in a temporary place prior to calling lk_main. Wastes 32 bytes
of memory but should be more solid.
2022-02-10 22:34:02 -08:00
Travis Geiselbrecht
e2cda72095 [arch][arm64] tweak the arm64_elX_to_el1 routine to avoid using x0-x3
It's called immediately upon entering the kernel entry vector, prior
to knowing if it's the boot cpu or needing to save any boot arguments,
so avoid using these registers
2022-02-10 22:34:02 -08:00
Travis Geiselbrecht
a01c181ea7 [arch][arm64] fix setting of UXN and PXN bits for NX permission
Previously would only set both UXN and PXN for no execute pages, but for
pages not marked no execute, neither bit was set. Change to mask out the
other privilege mode.
2021-12-05 23:22:54 -08:00
Travis Geiselbrecht
7285a2d1fd [bus][pci] convert the pci driver's back end to simple C++ objects
It was already rolling a vtable so go ahead and just implement it as
actual c++ objects.
2021-11-12 20:44:47 -08:00
Travis Geiselbrecht
a6ddffd80b [arch][warnings] fix -Wmissing-declarations warnings 2021-10-21 23:08:38 -07:00
Travis Geiselbrecht
9d2d6feffb [arch][arm64] add cache flush by way/set
Pulled code from Fuchsia to implement way/set cache flush for arm64.

Issue #307
2021-09-29 23:22:25 -07:00
Travis Geiselbrecht
6973ff8bee [build][arch] have arm, arm64, and x86 resort to a default toolchain
Previously if they couldn't find the toolchain they would full stop the
build. Change to print a warning and then go with the default prefix.

Hopefully this doesn't break anyone downstream but it's helpful for the
CI builder which wants to read from the build system which toolchain to
grab prior to having it in the path.
2021-09-18 16:52:38 -07:00
Jorge Troncoso
685f557c18 [arch][arm64] unmask_interrupt needs the same numbers as register_int_handler
Signed-off-by: Jorge Troncoso <jatron@users.noreply.github.com>
2021-06-03 18:52:26 -07:00
Travis Geiselbrecht
790916d14e [arch][arm64] fix up a bug introduced in a cherry-pick
display_pc is not defined in LK, so remove it for now.
2021-04-09 00:06:45 -07:00
Marco Nelissen
63b6d95cc9 [arch][arm64] Parse BRK exception
When a crash is because of a BRK instruction, print that instead of
the default "unhandled synchronous exception".

Bug: 179516283


Change-Id: I9667d7157d24a79e2b2ceb7ef283ebc2b09398d0
2021-04-08 23:55:27 -07:00
Travis Geiselbrecht
7102838b49 [arch] have each arch define ARCH_HAS_MMU
This lets some code decide whether or not there's any mmu
present to use. Also kernel VM will complain if it isn't set
as an extra safety.
2021-03-30 02:48:59 -07:00
vannapurve
945cd5ecdb [ARCH][ARM64] Dump more information during aborts
1) Decode FSC and dump more human readable status
2) Add support of stack unwinding as referred from
arm64 procedure call standard and frame pointer usage.
3) Compiler options for not omitting frame pointer
are enabled to ensure usage of frame pointers even
with higher optimization levels enabled.

Signed-off-by: vannapurve <vannapurve@google.com>
2020-10-13 16:16:15 -07:00
Travis Geiselbrecht
80967e78a6 [arch] tweak arch_cycle_count prototype to return a ulong
This lets some arches return a 64bit counter.

As a result of fixing this, removed -Wno-format switch in the test app
which caused the need to fix a lot of printfs.
2020-05-16 17:55:50 -07:00
Travis Geiselbrecht
f371fa246b [arch] move the atomic ops into a separate header
Now you need to include arch/atomic.h to get to the atomic routines.
This simplifies a recusion issue in the way arch/ops.h included
arch_ops. Also just generally makes things cleaner.
2020-05-16 15:05:34 -07:00
Travis Geiselbrecht
556c985b0c [arch][arm64] remove some extraneous copy-pasta in the ops header 2020-05-16 14:40:51 -07:00
Travis Geiselbrecht
d0f1944038 [arch] define the atomic routines in arch-neutral headers and use builtins
Generally move most arches over to using the builtin atomics except for
the few that still require a little bit of work.
2020-05-16 14:29:21 -07:00
Travis Geiselbrecht
c57b661c93 [kernel][thread] change the way get_current_thread is inlined
Previously, was relying on a regular definition with the arch_ops.h code
overriding it with a static inline. This has been annoying for some
years since it forces the declarations to be in order. Change it to
simple declare an inline wrapper around an arch_ routine that does
whatever it needs to do.
2020-05-16 14:29:21 -07:00
Travis Geiselbrecht
0b6866830d [arch][arm64][mmu] use slightly more efficient pmm_alloc_page routine
Only used when allocating page size aligned page tables, which is the
common case.
2020-05-10 16:51:58 -07:00
Travis Geiselbrecht
cba9e47987 [license] replace the longer full MIT license with a shorter one
Used scripts/replacelic. Everything seems to build fine.
2019-07-05 17:22:23 -07:00
Travis Geiselbrecht
d8fa82cb91 [formatting] run everything through codestyle
Almost nothing changes here except moving braces to the same line as the
function declaration. Everything else is largely whitespace changes and
a few dangling files with tab indents.

See scripts/codestyle
2019-06-19 21:02:24 -07:00
Travis Geiselbrecht
1b7a28efb8 [include][lk] fixup lk/ include path move 2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
5d43aa25eb [arch][rules] create ARCH_LDFLAGS and clean up all the arch rules files to consistently use ARCH_* vars 2018-11-30 22:00:45 -08:00
Antonio Nino Diaz
6792c9e143 [arch][arm64] Fix barriers in startup code
After a TLBI instruction the right thing to do is to execute DSB
followed by ISB. DSB ensures that the TLBI is seen by all observers of
the system and ISB ensures that the DSB has finished before continuing.

Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2018-09-12 13:12:26 -07:00
Travis Geiselbrecht
1d63a772a9 [arch][arm64] rename a register alias from index to idx
index apparently collides with a new assembler builtin in a newer
binutils/gcc version.
2018-03-15 13:44:22 -07:00
Ashok Kumar Sekar
f781ba7494 [arch][arm64] change CACHE_LINE to 64 for cortex a53,57 and 72
Signed-off-by: Ashok Kumar Sekar <ashokkumar.sekar@gmail.com>
2017-06-05 10:41:45 -07:00
Eric Holland
e724ff9707 [aarch64] Fix stack pointer misalignment (#159)
sp can become misaligned from 16 byte boundry because context frame
is not a multiple of 16 bytes.
2016-09-06 12:21:34 -07:00
Travis Geiselbrecht
f2c90720f3 [merge] Merge remote-tracking branch 'pr/rpi3' 2016-08-25 17:36:50 -07:00
klemens
d0b90c2d68 [spelling] spelling-fixes. (not external/) 2016-08-25 17:30:34 -07:00
Gurjant Kalsi
173046ecca [squash] Use x4 as early scratch register in case args are passed in x0-x3 (changes as per code review). 2016-08-25 15:51:34 -07:00
Gurjant Kalsi
2072cfe8f1 [arm64] Backport changes from magenta 2016-08-25 15:50:52 -07:00
Gurjant Kalsi
5c6554165e [squash] Fix typo in IPI code 2016-08-23 15:58:32 -07:00
Gurjant Kalsi
c6e2c28c86 [bcm28xx][arm64] Fix some type warnings. 2016-08-23 15:15:43 -07:00
Gurjant Kalsi
c5b427333a [bcm28xx][arm64][ipi] Fix IPI on non-GIC based BCM28xx 2016-08-23 12:56:40 -07:00
Eric Holland
5e5e2ac50c [rpi3][bcm28xx][smp] fixes to bring up all cores 2016-08-23 12:28:42 -07:00
Eric Holland
1164bc17bc [rpi3]64bit platform support 2016-08-23 12:28:13 -07:00
Eric Holland
c3c48e6bb1 [arm64][mmu] fix asid shift in tlbi 2016-08-02 22:07:29 -07:00
Travis Geiselbrecht
c705e4d0ff [arch][arm64] add multi-aspace and general bugfixes to arm64 2016-02-23 21:07:17 -08:00
Travis Geiselbrecht
14a4c60172 [kernel][vm] get rid of external declaration of address_to_page 2016-02-16 15:25:31 -08:00