Commit Graph

677 Commits

Author SHA1 Message Date
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
c66ad44efa WIP [target][visionfive2] Add initial support for a VisionFive 2 RISC-V board
Still TODO:
-Set the timer rate properly
-Fix nonzero based hart secondary cpu boot
-Try to parse the device tree for some information
2023-03-06 01:06:27 -08:00
Travis Geiselbrecht
81d6014493 [arch][riscv] Add more defines and optimize fpu context switch
Add a few more #defines for the status register
Tweak the FPU context switch to not rewrite the entire status register,
      which may not be a generally safe thing to do.
2023-02-18 16:39:45 -08:00
Travis Geiselbrecht
3dd8a32e92 [arch][riscv] a few small tweaks
Updated comment regarding clobbers on the SBI call.
Tweak a boot time print of SBI version.
Add a commented out line to the do-qemuriscv to assist in dumping future
device trees.
2023-02-18 14:42:59 -08:00
Travis Geiselbrecht
bcfad25587 [arch][x86][mmu] update how mmu code accesses physical pages
Move the mmu_initial_mapping from platform into arch/x86. For this
architecture the default mappings are basically hard coded in arch/x86
anyway, so move ownership of this data there, closer to where it's
actually initialized.
Update the 32 and 64bit paging code to properly use the paddr_to_kvaddr
and vice versa routines.
Update to allocate page tables directly from the pmm instead of the heap
(on 32bit code).
2022-11-02 23:48:49 -07:00
Travis Geiselbrecht
7742bd021b [arch][x86] general cleanup
Clean up the x86.h file a bit with how constants are defined
Switch rdtsc to builtin
Added all of the known bits for the main CR registers.
Move the invlpg macro over to the common header.
Update comments in start.S
2022-11-02 23:02:24 -07:00
Travis Geiselbrecht
7ddde308a3 [arch][x86][mmu] fix unmap routines to actually work
also additionally invlpg the address.
2022-11-02 02:09:46 -07:00
Travis Geiselbrecht
2367686854 [make] add a way for a module to opt into additional warnings
Move -Wmissing-declarations and -Wmissing-prototypes into this bucket.
Opt in most of the core top level modules in the system. More to follow.
2022-10-23 23:16:48 -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
5377fcbd12 [kernel][vm] add error handling with failed arch mmu mappings
In the 3 places in the upper VMM where it calls arch_mmu_map, try to
gracefully handle errors by unwinding the region creation.
2022-10-23 21:02:22 -07:00
Travis Geiselbrecht
2e81bfd55f [arch][x86] remove an extra printf left in the x86 mmu code 2022-10-23 21:00:15 -07:00
Travis Geiselbrecht
08b3238952 [arch][x86] clean up of mmu code
-Large cleanup of both the 32 and 64bit mmu code. Still the same general
flow but tighten up usage of mixing physical addresses with virtual
addresses.
-Remove the PAE code path from 32bit mmu, which was unused.
2022-10-23 20:37:33 -07:00
Travis Geiselbrecht
3a6b43cb32 [arch][mmu][tests] slight tweaks 2022-10-21 01:35:28 -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
Travis Geiselbrecht
f1dad5f4c8 [arch][mmu] remove arch_mmu_disable which is currently unused 2022-10-20 23:26:45 -07:00
Travis Geiselbrecht
0b5202362d [arch][mmu][test] change the arch mmu test file to c++
This lets us more easily use some C++ for test cleanup.
Updated the arch mmu flags to be explicitly unsigned to make C++
happier.
2022-10-20 23:24:33 -07:00
Travis Geiselbrecht
f6a2610aef [arch][mmu][test] update a few of the expects to asserts in these tests
In a few places where it's dangerous to proceed, raise to an assert so the
test stops.
2022-10-19 21:02:06 -07:00
Travis Geiselbrecht
d36f5ab8d8 [arch][x86] fix a bug in the unmap routine on 32bit mmu code
Was apparently already fixed on the 64bit side, but never rolled back.
2022-10-19 20:58:32 -07:00
Travis Geiselbrecht
318673348f [arch][x86][32] fix a bug in the exception report
Some of the 16 bit values the cpu pushes on the stack are aligned to
32bit offsets but actually only 16 bits were pushed. Make sure printf
masks off the top 16 bits when printing these fields out.
2022-10-19 20:22:10 -07:00
Travis Geiselbrecht
b7d7215030 [arch][x86][fpu] clean up the fpu init code to print info later 2022-10-19 20:17:05 -07:00
Travis Geiselbrecht
77d8622268 [arch][x86] clean up a bit of the cpuid detection
Save the model/family information in a new structure.
Move the printing portion of the detection to the arch_init runtime
so it gets a chance to print after the uart is initialized.
2022-10-19 20:03:49 -07:00
Travis Geiselbrecht
2ac68a56a8 [arch][x86] no need to "memory" clobber simple in instructions
They only read data into the eax register instead of memory.
2022-10-19 19:27:57 -07:00
Travis Geiselbrecht
5f9e6fdefc [arch][x86][cpuid] clamp number of cpuid entries to read at boot
Make sure we only read up to the max amount of cpuid values we have
preallocated in our static array.
2022-10-18 23:56:52 -07:00
Travis Geiselbrecht
e02401e4bf [arch][x86] fix up some in instruction macros
Turns out all of the in and rep ins/outs instruction macros have been wrong
since they were first added.

-Make sure they clobber memory
-Make sure edi/esi/ecx registers are marked as both read and written by
the instruction.

The latter was causing a codegen problem in the ide driver where the
pointer was pushed forward by a rep ins but the compiler didn't know the
register was modified.
2022-10-18 23:07:32 -07:00
Travis Geiselbrecht
62e2e7dba0 [platform][pc] move the multiboot header into generic space
Share the header with arch/x86 code
Clean up the use of the boot flags
Add code to print the framebuffer information, if present
2022-08-07 23:04:23 -07:00
Travis Geiselbrecht
8643334914 [platform][pc] update the multiboot memory detection code
Parse up to 16 pmm arenas from the multiboot memory data structure. Roll
the 32bit code to properly trim at 1GB as before, but using new logic.
Remove conditional checks on WITH_KERNEL_VM in x86 code, which only
really compiles with the mmu and the vm on.
2022-08-07 16:28:03 -07:00
Travis Geiselbrecht
fb373eb4de [arch][x86] drop march to x86-64
-march=x86-64-v2 is not supported on old compilers.

Can fix in the future, but for the moment may as well just drop -v2
since it's not really being used.
2022-07-24 20:03:46 -07:00
Travis Geiselbrecht
7505c3087a [arch][x86][fpu] spiff up the fpu code to detect things more cleanly
Doesn't really change the functionality of the code except it'll try to
work with less fpu features present.
2022-07-24 19:56:24 -07:00
Travis Geiselbrecht
c429ffcc7a [arch][x86] add more comprehensive feature bit routine
Cache copies of the first few cpuid leaves from each bank at bootup if
present. Add a fast routine to test feature bits out of this array.
2022-07-24 16:59:45 -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
cd96c43006 [make] define and undefine some make variables
Based on building with --warn-undefined-variables, find a few places in
the build system where undefined variables were used incorrectly, or
never set due to unused code.
2022-07-22 23:45:42 -07:00
Travis Geiselbrecht
8372f46055 [arch][riscv64] fix build with older toolchains (gcc 7.5.0)
When building fpu variant, use -march=rv64imafdc instead of rc64gc
since some older compilers and/or mainline do not understand the
equivalence when selecting libgcc.

This is only an issue on rv64 due to the need to pick out the medany
variant of libgcc.
2022-07-22 23:08:44 -07:00
Travis Geiselbrecht
b0d8aeed18 [arch][riscv] add fpu context switch support
Currently only implemented for double precision floating point.

Caveat: currently unable to only compile some code with or without
float. The linker is extremely picky about mixing float and no-float
objects, so stick with all on or off for now.

It's not as much of a problem currently because the toolchain is not
using any riscv vector instructions to assist normal code, so it's
generally only emitting fpu instructions for floating point code.
2022-07-17 23:27:42 -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
Travis Geiselbrecht
c580451e83 [arch][riscv] more interrupt cause debugging strings 2022-05-29 17:55:41 -07:00
Travis Geiselbrecht
095aca80f1 [arch][riscv][sbi] add the pmu extension, tweak boot messages, qemu-virt use reset calls 2022-05-29 14:48:04 -07:00
Travis Geiselbrecht
a8e460f847 [arch][riscv] add -misa-spec=2.2 to the compile switches
This works around an issue with newer compilers that default to an
earlier ISA spec that doesn't by default include the zicsr extension by
default.

If the compiler doesn't support the switch, then it's assumed that it
has the extension by default, as older gcc compilers did.
2022-05-22 15:14:34 -07:00
Travis Geiselbrecht
4695035505 [arch][riscv] C++ header guard the core riscv header 2022-05-13 01:06:58 -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
Travis Geiselbrecht
479d989185 [make] default WITH_LINKER_GC to false at the place it is used
Also switch the test logic to the TOBOOL macro.
2022-04-18 01:15:45 -07:00
Travis Geiselbrecht
8028512833 [arch][m68k] add more switches for cpu models 2022-04-12 17:26:33 -07:00
Travis Geiselbrecht
49644a2c39 [platform][rosco-m68k] Add port to the Rosco M68k board
Port to the really neat 68010 based board at https://rosco-m68k.com/

Port Features:
-10Mhz 68010
-1MB ram
-Dual UART + timer implemented as a 68c681 chip
-timer running at 1Khz, UART A for console
-interrupt driven RX support

Some amount of extending of the 68k exceptinon code was needed to
support the autovectored irqs that the 68681 uart uses. Added build
system support for 68010.
2022-04-12 00:25: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
ce9f4f6db2 [arch][riscv] using a new trick utilize real instructions to zero fpu state
Previously was hard coding the instructions to work around a limitation
of the assembler that did not allow using fpu instructions when the code
was being compiled without support. Move the zeroing routine into a
separate assembly file and override the architure at the top.
2022-03-12 17:39:00 -08:00
Travis Geiselbrecht
cc21c06eb6 [platform][m68k-virt] parse the BOOTINFO structure qemu uses to pass info
Pull out the memory size of the system and use it to initialize the
novm.
2022-02-11 00:37:51 -08: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