Commit Graph

659 Commits

Author SHA1 Message Date
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
Wencheng Yang
fbb838d1f8 [arch][x86] left shift 32 bits rather 31 bits to construct msr value 2022-02-09 12:22:30 -08:00
Travis Geiselbrecht
18330c5948 [arch][x86] start of cpu detection and feature detection 2022-01-09 18:20:14 -08:00
Travis Geiselbrecht
522e62f648 [arch][x86][mmu] squelch an extraneous printf 2021-12-27 22:24:31 -08:00
Travis Geiselbrecht
dd438d2f1f [arch][test][mmu] add a simple test case to map a page and query the restult
Currently x86 fails the test but arm64 and riscv pass.
2021-12-05 23:24:04 -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
1a54b73e84 [arch][x86] don't set the G bit on inner page table entries
This is ignored on Intel cpus, but triggers a page fault on AMD cores.
2021-11-21 02:08:58 -08:00
Travis Geiselbrecht
2bb32fe813 [libc][assert] add __PRINTFLIKE to assert_fail_msg()
Fix a warning as a result of this.

fixes issue #302
2021-11-12 22:07:14 -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
911900f3df [arch][m68k] Merge in Motorola 68k port 2021-11-08 23:24:37 -08:00
Travis Geiselbrecht
a6ddffd80b [arch][warnings] fix -Wmissing-declarations warnings 2021-10-21 23:08:38 -07:00
Travis Geiselbrecht
daf1d671b5 [arch][arm-m] fix the pendsv handler for leaving a misaligned stack
The pendsv_ asm handler has been pushing 9 words on the stack prior to
calling into C code. This violates the ABI which requires 8 byte
alignment. It has worked mostly fine and thus hasn't been caught before.

Add an extra bump of the stack to align it after pushing the registers.
2021-10-17 23:01:37 -07:00
Travis Geiselbrecht
11a39f545b [arch][arm] add debug asserts to the non SMP spinlock routines
This should assert that the spinlock is not already held when acquiring
and vice-versa and that interrupts are disabled.
2021-10-07 00:00:22 -07:00
Travis Geiselbrecht
e7c42e22ce [arch][arm-m] Fix a bug with a mismatched acquire/release of the thread lock
Release the thread lock before context switching to a thread that was
preempted and thus not holding the thread lock. Add a few asserts to
make sure this invariant is maintained in the context switch and PENDSV
handler.

This has never mattered before because the thread lock (and other
spinlocks) were not being tested for validity on by definition single
processor cortex-m systems. After adding some code to test the
spinlocks' values this discrepancy was uncovered.
2021-10-07 00:00:22 -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
Michael Bishop
d1787042f7 [arch][arm] improve arm chainload
arch_mmu_map was failing hard, because the identity mapping does not fall within the `vmm_get_kernel_aspace`

this creates a new aspace covering the loader, so it can identity map

linux is also unable to use the FPU if lazy FPU context switching had turned it off prior to the chainload, `arm_fpu_set_enable()` is used to turn it back on
2021-09-18 17:14:55 -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
Travis Geiselbrecht
4b508cecc9 [arch][m68k] use a jsr in the initial start routine to main
It's non ideal, since there's no relaxation done in the linker so we
have to assume the branch target is > 16 bits away and do what the
compiler usually does and emit a full 32bit jsr.
2021-06-11 21:34:34 -07:00
Travis Geiselbrecht
bd12570f3c [arch][m68k] fix and optimize interrupt disable/enable/restore
Mostly rewrote to be cleaner and more obvious what it's doing, but turns
out the real problem was a lack of "memory" and/or volatile. In one of
the test cases the compiler was rearranging the arch_ints_disabled()
check.
2021-06-11 21:14:22 -07:00