Commit Graph

2205 Commits

Author SHA1 Message Date
Travis Geiselbrecht
c49e63e62c [app] make APP_START work with C++
Needs a __USED tag or the compiler will GC it apparently. Should do the
same thing for other section based trickery.
2021-05-27 03:15:30 -07:00
Travis Geiselbrecht
08aeb5a6ad [libc] fix the extension routine that adds entropy to the random pool
Worked for short entropy but actually would end up zeroing out the new
entropy word.
2021-05-26 02:15:59 -07:00
Travis Geiselbrecht
2c28605d0d [app] add a standalone routine and a command line app start routine 2021-05-26 02:15:59 -07:00
Travis Geiselbrecht
8251133b6d [github][irc] tweak the irc notifier to not use notice 2021-05-26 02:15:59 -07:00
Travis Geiselbrecht
0f04f252d5 [github][irc notify] switch to irc.libera.chat 2021-05-26 02:08:55 -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
Nick Bray
3f549a2e25 [make] Defer binding of EXTRA_BUILDDEPS to all::
Currently EXTRA_BUILDDEPS is evaluated before build.mk. This means that
userspace apps or other EXTRA_BUILDRULES cannot add items to
EXTRA_BUILDDEPS and have it function as would be expected.

Bug: 143636864
Change-Id: Idc1504b09f31b4c54148bb6892193d11f45e08ff
2021-04-08 23:55:27 -07:00
Andrei Homescu
7e502816f6 [include][compiler.h] Fix INCBIN/INCFILE macros
The compiler.h header defines two macros INCBIN and
INCFILE that can be used to include binary files
into C sources. This patch fixes a few issues with them:
* The .align directive is equivalent to .p2align
  on some architectures (ARM/AArch64) and to .balign
  on others (x86). INCBIN previously used .align and
  now uses .balign for correct alignment.
* .align 1 enforces a 2-byte alignment on ARM/AArch64,
  which caused the _end symbol for the binary to be off
  by 1 byte in some cases, which the macro previously
  accounted for (incorrectly). With the correct .balign
  directive the extra byte is never added, so the size
  is now correctly computed without the -1 addend.
* INCBIN should end in a .previous directive
  to restore the previous section, since the macro
  starts with .section.

Bug: 115420908
Change-Id: I2149e21d6f7157369a7b374a51af23933bff6b39
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
5a3d51e3e7 [assert] fix up a few places broken at DEBUG=0 after recent assert changes
Forgot to test at DEBUG=0. Both of these are basically cases where
the new DEBUG_ASSERT_COND should be used, since the default DEBUG_ASSERT
will now always emit code that gets cleaned up in the optimizer.
2021-04-02 20:16:53 -07:00
Travis Geiselbrecht
897240eb43 [lib][unittest] more improvements from zircon
Have the msg argument be optional in C++.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
9a796e868a [assert] update the assert macros
Pull some assert macro improvements back from zircon.

Added new variants that let you pass an arbitrary message.
Move most of the inner routine into a helper, makes for slightly
smaller codegen.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
461ecbb677 [make][cpp] bump cpp revision to C++14
Shouldn't be a large problem, since it's been standard in gcc and clang
for quite a few years at this point.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
ebdc1ea077 [lib][libcpp] move c++ specific shims out of libc and heap
Consolidate into a single library. Also renames legacy new.h to
the more standard new.

Possible that some C++ code will need to get this added to their
MODULE_DEPS.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
890504c922 [inc][compiler] update compiler.h with new bits from zircon
Mostly macros dealing with clang, which do not yet work, but lets
some other zircon code be compiled cleanly.
2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
c5ef3165e4 [libc] add LLONG_* to limits.h 2021-04-02 19:28:58 -07:00
Travis Geiselbrecht
d28e8dc3e0 [kernel][mutex] tweak a mutex routine to take a const 2021-04-02 19:28:58 -07:00
Michael Bishop
41f651268b [libc] allow arch string rules to be missing
[elf] add the constant for VC4
2021-04-01 21:34:29 -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
e3a43bb899 [lib][unittest] spiff up the unittest lib
Roll some improvements back from zircon kernel.
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
a319a1f68d [target][pico][ci] add pico-test to the build matrix 2021-02-15 21:07:00 -08:00
Travis Geiselbrecht
c8e4a56f00 [target][pico] switch the uart config to target driven
Uses the target/debugconfig.h file pattern laid down before,
which is a bit long in the tooth but for the moment still helps
us separate target from platform.
2021-02-15 21:06:05 -08:00
Travis Geiselbrecht
a0f34be4ec [project][pico-test] inherit all of the tests from the virtual test project 2021-02-15 21:06:05 -08: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
Brian Swetland
7d3f648e88 [rp20xx] quick and dirty early init using pico-sdk driver code
- pull in headers for essential modules
- init clocks, gpios, uart0 out of platform_early_init
- wire up debug getc/putc to uart0
- comment out "native" uart impl
2021-02-15 21:06:05 -08:00
Brian Swetland
9c769f6931 [rp20xx][pico-sdk] add some missing / generated headers
- sys/cdefs is wanted for __CONCAT()
- version.h and config_autogen.h are generated by the pico sdk
- config_autogen expects to include board file
- instead define PICO_xyz in target rules.mk
2021-02-15 21:06:05 -08:00
Brian Swetland
e65436dca9 [external][pico] import source from rpi pico sdk
Origin: https://github.com/raspberrypi/pico-sdk
Branch: develop
Change: ebb228bfeaec81dce3b8ebdbf6c7f5fd580e2e2f

This is the contents of src/boads, src/common,
src/rp2040, and src/rp2_common, excluding cmake
goop.

I suspect we'll trim it back closer to just the
register definitions, but for now leave it mostly
as-is to simplify updating as the pico sdk updates
and we figure out how deeply (or not) to integrate
it with lk.
2021-02-15 21:06:05 -08:00
Travis Geiselbrecht
b730a5ef5c [github][actions] Add a new action to build LK, replacing travis-ci
Use the new github actions to replace the travis-ci builders which
seem to no longer work and are being removed.

This first stab is fairly rough, just matches the explicit matrix
that was in the travis-ci hooks, but at least gets back to a buildable
state again.
2021-02-14 20:23:39 -08:00
Travis Geiselbrecht
7b0ca3c984 [make] print debug level on build 2021-02-14 20:08:35 -08:00
Brian Swetland
5434847c51 [libc] C style static_assert takes two arguments
Fix this up and fix up the one existening dependency on the
existing incorrect behaviour.
2021-02-06 20:30:34 -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
Travis Geiselbrecht
7c43f66169 [platform][pi20xx] Add a tool to convert the final .bin file to a UF2 file
Tool is MIT licensed, taken from
https://github.com/microsoft/uf2
2021-02-06 16:29:02 -08:00
Brian Swetland
b142c6bdcd [rp20xx][pico] platform and target for rp20xx and pico board
- just a skeleton to get us started
- cpu feature config and irq names / vectab2 setup done
- pulled in the second stage for pico as a blob for now
- seems to be hard faulting out of systick setup in platform_init()
2021-02-05 19:25:19 -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
Brian Swetland
6e3edb87de [app][mdebug] version 1.0
- protocol now correctly reports SWO and SWCLK clock rates on set
- remove some debug printfs that were causing fw hangs (investigate later)
- allow setting a 1MHz SWCLK rate
- CMD_ATTACH now supports an argument to select one of several special
  reset or escape sequences:
  ATTACH_SWD_RESET: 60 HI, 4 LO, basic line reset
  ATTACH_JTAG_SWD: escape sequence for JTAG -> SWD mode switch
  ATTACH_DORMANT_TO_SWD: escape squence to exit dormant mode
  ATTACH_SWD_TO_DORMANT: and go back again
- add special support for writing to DP TARGETSEL register
  (response phase must be ignored), needed for SWD multidrop support
- bump protocol version to 1.3
- bump firmware version to 1.0 (it's long overdue)
2021-02-01 17:46:33 -08:00