Commit Graph

659 Commits

Author SHA1 Message Date
Travis Geiselbrecht
6e0762fb53 [arch][arm] remove some old dead code for pre armv6 compiles
Haven't built for a pre-armv6 or v6 + thumb machine in a long time and
the effort needed to maintain that is not really worth it. Officially
remove the old support code.
2020-05-16 15:07:55 -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
f8effeba66 [arch][x86] switch x86 to the builtin atomics
Easy to do except for the legacy compile case for i386, in which case we
have to start defining fallthrough atomic routines that the compiler
will call.

At the moment only implement __atomic_fetch_add_4 since its the only one
in use.
2020-05-16 14:29:21 -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
3e66ea6361 [arch][riscv] simplify the exception decoding logic
Use the sign bit on the cause register to separate interrupts from
exceptions.
2020-05-16 14:29:21 -07:00
Travis Geiselbrecht
a5e6261e48 [arch][riscv] optimize the bss fill and data copy in start.S
Use full width load/stores based on the bitness of the build. Previous
linker script changes made sure the start/stop symbols are always
aligned.
2020-05-15 02:06:47 -07:00
Travis Geiselbrecht
225bef5a4b [riscv][linker] general cleanup of the linker scripts
Start using PHDRS and MAXPAGESIZE, remove some extraneous stuff.

Possible we can combine a lot of these linker scripts for various arches
if we're careful.
2020-05-15 02:06:23 -07:00
Travis Geiselbrecht
7c9906a5ff [arch][riscv] Initial implementation of MMU for RISC-V
Implements both SV39 and SV48. No 32bit support yet.

Currently implements basic setup of paging in start.S by mapping a large
chunk of memory into both an identity map and to the bottom of the
kernel address space. Run the kernel out of this physical mapping.

Added basic arch mmu support for querying existing paging structures and
mapping 4K pages. No unmap support as of yet.

System boots with mmu on when running supervisor test on qemu. Untested
on real hardware as of yet.
2020-05-10 17:09:48 -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
d6bba37cec [arch][riscv] make sure the stack is 16 byte aligned for new threads
This is according to the RISC-V ABI, even in 32bit mode.
2020-05-03 19:34:32 -07:00
Travis Geiselbrecht
5fd7168ab9 [arch][riscv] use a simpler access method for current_thread 2020-05-03 18:50:12 -07:00
Travis Geiselbrecht
6dee5a1303 [arch][riscv] add a per cpu structure and point the scratch register at it
Generally spiff up and clean up the MP code and how the cpu to hart and
vice versa translation is handled.
2020-05-03 17:57:46 -07:00
Travis Geiselbrecht
17037d258d [riscv] add a max HART define to deal with offset hart numbering
Add a define that sets the maximum allowed hart number, potentially
higher than the maximum number of allowed cpus.

This lets us more cleanly deal with having a higher HART number than the
logical cpu numbering. Only really works where it's still fairly packed
around 0, but in the case of the Sifive Unleased board it's just offset
by 1 so it's not a huge loss.

Generally clean up RISCV SMP boot code by rearranging things a bit as
well.
2020-03-28 20:33:04 -07:00
Travis Geiselbrecht
5969063a52 [arch][x86][64] Get the 64bit build working again
Set -fno-builtin to keep the compiler from generating load/stores using
sse outside of floating point code. Not ideal for a lot of reasons but
it's difficult to segregate kernel code and user code such that it only
generates SSE instructions there.

Will probably need to do some work to let certain flags be set per
module, and then have only some of the modules be marked as user vs
kernel.
2020-03-07 18:06:01 -08:00
Travis Geiselbrecht
8fbac4302c [arch][riscv] add proper barriers 2020-01-19 16:58:46 -08:00
Travis Geiselbrecht
96359bd05e [arch][riscv] stub out cache and memory barrier ops
Need to implement the barrier ops, but for the moment they're only used
in virtual machines.
2020-01-19 16:16:59 -08:00
Travis Geiselbrecht
dfcc7c3970 [arch][riscv] move some of the riscv specific headers another level deeper 2020-01-19 15:15:59 -08:00
Travis Geiselbrecht
4d080aaef9 [arch][riscv] fix up the smp reschedule ipi delivery 2020-01-19 14:48:25 -08:00
Travis Geiselbrecht
6dbe2b04a7 [arch][riscv] tweak the SMP start code
-Fix a race in start.S depending on which secondary cpus start first
-Add routine to let a platform/target set the cpu count dynamically
2020-01-19 14:47:07 -08:00
Travis Geiselbrecht
90dc9e50ef [platform][sifive-e] get the hifive1 hardware working again
Had rotted a bit. Had to reimplement a few tweaks.
Also generally #if out a lot of the SMP code when unused on riscv.
2020-01-18 18:39:07 -08:00
Travis Geiselbrecht
36afd4e095 [arch][riscv] code formatting
using ./scripts/codestyle which is an astyle wrapper
2020-01-16 23:17:34 -08:00
Travis Geiselbrecht
ccf46eefba [arch][riscv] add timer hack back
For one of the riscv embedded targets, the clock ticks at such a slow
rate that the compiler will warn of a div by zero. Add a compile time
hack for this.
2020-01-16 23:10:35 -08:00
Elliot Berman
e50d7db612 [arch][riscv] Add support for running in supervisor mode
Add support for running LK in supervisor mode or machine mode.
- Macro-ify CSR access to use correct CSR # or use SBI call as req'd
- Add support to make SBI calls
- Split CLINT and lk timer abstraction so that RISC-V timer can use SBI
  as required.
- Add support for booting other harts as primary since hart0 on U540
  does not support S-mode. A map is used to get LK cpu number from
  hartid.
2020-01-16 23:06:28 -08:00
Elliot Berman
acfe991c7f [arch][riscv] Expose RISC-V mp kernel start
Support mp lk start on RISC-V. Several changes throughout were required:
- Add signal in asm start to force secondary harts to wait for bss to be
  cleared.
- Use mhartid in arch_curr_cpu_num, PLIC, and CLINT
- Use tp register as thread pointer instead of global variable.
- Support sending IPIs between harts using CLINT
- Add spinlock implementation
2020-01-16 23:06:28 -08:00
Elliot Berman
d239adf839 [arch][riscv] Add basic support for SiFive HiFive Unleashed
Most of changes were moving around where macros were defined, plus the
following:
- Remove requirement for floating point on RV64 to support booting
  monitor core on U54 SoC.
- Add support for Debug LEDs on HiFive Unleashed Board
2020-01-16 23:06:28 -08:00
Venkatesh Srinivas
128890f8a8 [platform][tms570-launchpad] Skeleton of port to TI LaunchXL2-TMS57012
* Adds target tms570-launchpad, for TI TMS570 Launchpad Dev Kit
(https://www.ti.com/store/ti/en/p/product/?p=LAUNCHXL2-TMS57012)

* Adds CPU definitions for Cortex R4F (BE) CPU, implementing
  ARMv7-R ISA. Does not yet add definitions for ARMv7 arch entry
  functions.

* Board does not yet build - platform.c/uart.c are empty, no GIC
  entry points provided.
2019-11-18 15:36:28 -08:00
Travis Geiselbrecht
bff17f7e99 [platform][riscv] add code to read the size of memory from the FDT
Tweak the novm allocator to let us more easily add a variable sized
arena at boot.

Also added code to trap secondary cpus and reenable the use of WFI
instruction.
2019-11-02 18:13:02 -07:00
Travis Geiselbrecht
fdc08a8446 [arch][riscv] port to riscv64
Very little needed to port except to conditionalize some assembly in the
context switch and exception code. Mostly needed to move build system
stuff around and add a new project.
2019-11-02 17:21:13 -07:00
Travis Geiselbrecht
ae5200595c [platform][riscv-virt] added support for QEMU's riscv 'virt' machine
The virt machine is a generic target, much like the arm virt machine.
Intended to be simple to use and a good target to run large systems like
linux on. At the moment simply support booting and simple uart and timer
support.
2019-11-02 14:19:36 -07:00
Travis Geiselbrecht
6cb02526b7 [include][console] split lib/console.h into two
TL;DR most uses of lib/console.h -> lk/console_cmd.h

Move the part that lets a piece of code somewhere in the system to
define a console command from the actual lib/console api to start an
instance of the console. Move in almost every place the user of the
console command definition to the new header, lk/console_cmd.h which is
always in the include path.

Also remove most uses of testing for WITH_LIB_CONSOLE since you can
almost always just safely define it and then let the linker remove it.
2019-07-13 16:56:33 -07:00
Travis Geiselbrecht
35a8d555a3 [include] move almost all of the remainder of top level includes into a subdir
Examples are include/platform.h -> platform/include/platform.h
include/target.h -> target/include/target.h

The old model generally considered these to be Always There includes,
but they're starting to stick out more and more so may as well actually
follow the model that most of the rest of the system follows.
2019-07-13 16:09:27 -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
b3450e6e57 [arch][x86] make sure the direction bit is clear on irq entry 2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
220b91fe55 Merge pull request #211 from James-Zzz/master
[arch][x86] Bug fix and feature enhancement
2019-06-19 18:44:05 -07:00
Travis Geiselbrecht
a8d82f3ab0 [arch][arm-m] move some hand coded register inits to the CMSIS struct
No functional change.
2019-06-12 14:26:48 -07:00
Travis Geiselbrecht
1a45b90077 [arch][arm-m] clean up the low level exception code
Removes a need for a large #if for armv7-m vs armv6-m. Combine the
two paths with conditional assembly code.
2019-06-11 14:47:03 -07:00
Travis Geiselbrecht
39d02cf01f [build][arch][arm] squelch additional LIBGCC and compile flags echoing
Already printed elsewhere, quiet down the build a bit.
2019-03-23 09:57:19 -07:00
Travis Geiselbrecht
63be190d8b [target][sifive-e] Get LK working on a Sifive Hifive1 board
-added support for bringing up the clocks and setting up the gpio bits
before starting the uart.
-add a proper target init routine
-add scripts to flash board via openocd
-fixed bug in riscv interrupt save state where it wasn't saving mstatus
on irq entry.
-comment out cycle enabling, not implemented on this core
2019-02-18 22:13:22 -08:00
Travis Geiselbrecht
a0a6b10e0b [arch][riscv32] rename the qemu target sifive-e
The initial port is really a Sifive E platform. Call it what it is and
make space for bringing up the Sifive U and virt qemu target.
2019-02-17 20:29:50 -08:00
Travis Geiselbrecht
a53ce0c42c [arch][arm] move -Mreg-names-raw behind an arch specific flag 2019-02-17 20:27:54 -08:00
Travis Geiselbrecht
dc2fe55fa9 [arch][riscv] set up the global pointer register
The linker will automatically relax any dereferences and calculations
for symbols located near the symbol __global_pointer$.
2019-02-17 18:55:42 -08:00
Travis Geiselbrecht
1fbb67228d [platform][pc] get working on legacy 386 PC
-Add support for x86 legacy mode, designed for 386+ instead of pentium+
-Fixup uart driver to support com2
-Stub out PCI driver properly
-Fixup IDE driver to detect legacy disks
2018-12-30 21:08:58 -08:00
Travis Geiselbrecht
7bbf6d5831 [nit] fix extraneous trailing ; in CDECLS lines 2018-12-16 16:49:40 -08:00
Travis Geiselbrecht
8cf28bbdcf [arch][riscv] Initial port to a riscv32 sifive target
Currently targets qemu's sifive_e machine, which is a split flash/ram
machine, much like the Sifive HiFive1. Untested as of yet on a real
HiFive1.

Basic support including interrupts and architectural timers in place.
2018-12-16 16:44:23 -08: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
Travis Geiselbrecht
18d501fdcb [arch][arm] fix start.S to make sure r12 has 0 in it 2018-10-13 11:15:54 -07:00