Commit Graph

669 Commits

Author SHA1 Message Date
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
Travis Geiselbrecht
0d721ca245 [arch][m68k] add idle loop 2021-06-11 21:13:56 -07:00
Travis Geiselbrecht
d6fa4d5b80 [arch][m68k] add exception and irq processing
-Add interrupt controller and timer support for qemu virt machine
-Switch tty read to irq driven as well
2021-06-07 02:40:02 -07:00
Travis Geiselbrecht
12fee4b59a [arch][m68k] initial port to m68k
Uses the QEMU virt machine for 68k defined in qemu 6.0+.
Basic support that boots, prints to the console, takes input from
console, and context switches.

TODO: interrupt support, timer support.
2021-06-06 19:38:45 -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
Wencheng Yang
9f0d53f968 [arch][x86] Unset x86 inner page table entry G bit
The issue was found on AMD machine when run lk with qemu kvm, it
can't boot if kvm hardware is enable in qemu.

According to Intel system programming guild Chapter 4 "Paging",
if the page table entry is non-leaf entry, then the G bit will be
ignored.

However, According to AMD programmer mannul Volume 2, Chapter 5.3
"Long-Mode Page Translation", the non-leaf page table entry G bit
must be zero.

The patch sets inner page table entry G bit to zero so that it
works on both Intel and AMD CPU
2021-05-07 20:51:58 -07:00
Travis Geiselbrecht
035a15325a [arch][riscv] start of FPU support
Add build system support for at least being aware of the FPU on
the architecture, not building code to use it.

At the moment, only sets up the FPU into Initial state prior to
entering user space and then ignores it.
2021-04-13 02:39:34 -07:00
Travis Geiselbrecht
1772e7e890 [arch][riscv] move the iframe definitions into a separate header and add syscall support 2021-04-11 03:38:03 -07:00
Travis Geiselbrecht
38fa93cbbf [arch][riscv] update exception code to handle exceptions from user space
Added two paths in the exception code to deal with coming from user and
kernel space.
Added first stab at a functional arch_enter_uspace()
2021-04-11 02:56:06 -07:00
Travis Geiselbrecht
525d2e9c77 [arch][riscv] switch the percpu pointer to tp reg
For user space support, the sscratch register cannot hold the pointer to
the current cpu, as much as it is convenient.

Change the logic to use tp register (x4) to point to percpu, and
dereference the local thread from it directly.
2021-04-11 01:38:25 -07:00
Travis Geiselbrecht
29d41272b0 [arch][mmu] add more test code to the mmu routines
Create a user space address space, map some pages, query the pages,
context switch, to the new aspace, access the pages.

Basic test that the aspace abstraction is working.

Will generate errors on some of the arches that dont fully implement all
of this, but not a crash.
2021-04-10 15:34:48 -07:00
Travis Geiselbrecht
a3713e8b39 [arch][riscv] add simple support for context switching user space aspaces
Pretty inefficient but probably works well enough.
2021-04-09 02:00:57 -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
Travis Geiselbrecht
8b6a43945d [arch][riscv][mmu] permanently allocate top level buffers to help keep user space aspaces in sync
Kind of wasteful, but much simpler than having to manually sync every time something changes
in the kernel aspace. I think riscv machines with mmu can waste 1MB of page tables up front.

Can revisit later if needed.
2021-04-08 23:55:27 -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
f463f50e54 [arch][riscv] add trampoline page table and start user space address space support
Up until now the bottom part of ram has been identity mapped, left over
from initial bootstrapping. Set up two top level page tables: one with the
the identity map and one without. Once the kernel starts switch to the second
but keep the former around for bootstrapping secondary cpus.

Start adding support for user address spaces, currently mostly untested.

Still have to solve the problem of keeping the kernel parts of the page tables
in sync. Will probably preallocate all of the ones needed.
2021-04-03 02:40:32 -07:00
Travis Geiselbrecht
1db813d2f6 [arch][riscv] spiff up the spinlock code a bit
Move out of inline routines since the body is relatively
large and to keep the disassembly clean. Have spinlocks
store the holder cpu + 1 instead of just 1. Add an appropriate
barrier to the release.
2021-03-30 02:48:59 -07:00
Travis Geiselbrecht
3be4698671 [arch][test] add a new unittest for the arch mmu code
Just a skeleton at the moment, simply creates an arch aspace
and destroys it.
2021-03-30 02:48:59 -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
Travis Geiselbrecht
45a27cbf14 [arch][riscv] more work on riscv MMU code
Use a callback based shared walker to implement the
same page table walking code for different operations.

Add SBI hooks for TLB flushing.
2021-03-30 02:48:59 -07:00
Travis Geiselbrecht
c6d8476adb [arch][riscv] rename mmu.c -> mmu.cpp
Going to try an idea with the page table code that requires C++.

If it works out, I'll keep this commit.
2021-03-30 02:48:59 -07:00
Travis Geiselbrecht
6ea5645ca3 [arch][riscv] stub out arch_enter_uspace for riscv
Copied implementation from ARM and then stubbed it out.
2021-03-29 03:04:12 -07:00
Travis Geiselbrecht
7217848f45 [arch][arm-m] dont set up unused vectors on armv6m cores
Just saves a few hundred bytes of unused code.
2021-02-15 21:06:05 -08:00
Travis Geiselbrecht
c2574c46c6 [arch][arm-m] add logic to conditionally set VTOR if present
VTOR is optional on cortex-m0+, so let the platform or target set
a define to do it.

Move the RP20xx platform to this switch.
2021-02-15 21:06:05 -08:00
Travis Geiselbrecht
e231864e12 [arch][arm-m] disable -mthumb-interwork for cortex-m targets
If the cpu is always in thumb mode there's really no reason to pass
this switch and it can and does foul up libgcc selection.

Possible it can be removed entirely since the build system doesn't
really support anything prior to armv7 or armv6 where thumb interwork
became implicit. Unclear if it'll cause linking issues to not have it
set, however.
2021-02-06 17:32:13 -08:00
Brian Swetland
9270460385 [arm][cm][linkscripts] add a "secondstage" section
This provides a way for a platform or target to insert code or
other secret sauce in front of the vector table for targets that
need a second stage loader prepended or something like that.
2021-02-05 16:59:12 -08:00
Travis Geiselbrecht
7033559d38 [inc][c++] add some additional __BEGIN_CDECL/__END_CDECLS to various global headers
Just a few that were missed, and picked up with some additional C++ code.
2021-01-20 01:02:48 -08:00
Travis Geiselbrecht
3083f63253 [arch][riscv] fix accidental file rename in last commit
Have been fiddling with using some C++ in the riscv code, but didn't
intend to check this file rename in yet.
2021-01-14 20:21:22 -08:00
Travis Geiselbrecht
649ca7dd54 [make] encode the source file extension into the .o file
Instead of compiling each .c or .cpp or .S file into an equivalent .o file,
map it to a file with .c.o or .cpp.o extension.

IE,
    foo.c -> foo.c.o
    bar.cpp -> bar.cpp.o

Reason for this being that if you change the suffix of a file it'll
automatically pick it up and recompile.
2021-01-14 18:43:18 -08:00
Travis Geiselbrecht
6f5fe1efca [arch][riscv] add proper SBI extension support
-Add support for probing SBI extensions
-Switch to newer versions if present
-Add HBM extension which allows proper secondary cpu bootstrap
-Add support for secondary bootup via HBM.
2020-12-30 03:43:54 -08:00
Travis Geiselbrecht
d1c04827e9 [arch][riscv] make sure zero sized bsses work
-Skip looping if the bss size is actually zero

Issue #288
2020-12-30 02:15:26 -08:00
Travis Geiselbrecht
6bd5e9e857 [arch][riscv] tweak some of the start.S code that was recently modified
-Add a comment as to why a2 is used to hold the assigned cpu id
-Add a memory fence after releasing the secondary cpus
2020-12-30 02:02:50 -08:00
Travis Geiselbrecht
1e50428091 [arch][riscv] remove the last of the RISCV_BOOT_HART mechanism
Now the harts are dynamically numbered, so don't need
this mechanism anymore.
2020-12-30 01:09:24 -08:00
Travis Geiselbrecht
c2d77234c3 [arch][riscv] switch to using a boot lottery to dynamically assign cpu number
Turns out that in some cases we can't really rely on a particular boot cpu id
so go ahead and simply dynamically assign cpu numbers by having each cpu
increment an atomic number in the very top of start.S. The first one in gets
the worm.
2020-12-30 00:52:41 -08:00
Travis Geiselbrecht
3194e45807 [arch][riscv][sbi] add probe for new SRST extension 2020-12-09 02:15:29 -08:00
Travis Geiselbrecht
8869020ae2 [arch][riscv] fix bug with gcc 10.2 & binutils 2.35 with section padding
In a two segment binary was previously trying to use MAXPAGESIZE set to 4
to cram the sections in very tight for embedded. This seemed to with this
toolchain cause the linker to get confused and sometimes appear to stuff in
an extra 4 bytes in the output file, thus misaligning the data segment.

It's possible it's still a bug on my side in the linker, but setting
max_page_size to 8 seems to work around it for now. Possible there's some
implicit 64bit aligning slipped in a stage somewhere in binutils thats
causing it to get confused. Either way, 8 byte alignment is no large loss
here.
2020-12-09 01:59:16 -08:00
Travis Geiselbrecht
01f9a97dc1 [arch][openrisc] fix up and get the OpenRISC port working again
Previous to now it had always relied on a custom patched gcc
and a custom sim. In the interim since the initial port went in
some time in 2015 GCC and QEMU have both officially picked up support
for the architecture and the machine that was emulated in the previous
emultor.

Using gcc 10.2 fix up the build and get it basically working. Timers
seem to not be working right but it's probably fairly easy to fix.
2020-10-21 02:34:50 -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
60972b36c1 [arch][arm][cortex-m] select the simplified arch interrupt save/restore for armv6m too
Previously had only selected armv7m for the simplified version.
Forgot that cortex-m0s are armv6m and could use this version.
2020-10-11 03:27:27 -07:00
Michael Bishop
71687b4cbf [arch][arm] fix booting when in HYP mode 2020-10-10 00:58:38 -07:00
Venkatesh Srinivas
c4cdc17865 [platform][tms570-launchpad] Do not try to save d16-d31 on ARMv7-R
All shipping ARMv7-R processors include VFPv3-D16, a subset of VFPv3
with only 16 double-precision registers. The first -R profile CPU
with a complete VFP or NEON implementation is the Cortex-R52,
implementing ARMv8-R.

LK's context switch code had a dynamic check and would only save
d16-d31 if present, but gcc/gas will not assemble code that includes
references to d16-d31 when mcpu=cortex-r4f or other v7-R CPUs.

Ideally we'd key the #if off of __TARGET_FPU_VFPV3_D16, but that
only appears to be defined by the ARM compilers, not gcc. Use
V7-R as the key instead.
2020-10-09 00:58:32 -07:00