Commit graph

300 commits

Author SHA1 Message Date
bunnie
8f0634845e add more userspace maps for loader-managed swap maps 2024-05-03 18:46:11 +08:00
bunnie
228558a722 add platform specific hw inits & key retrieval
- swap session key has to be stored so we can pass it on to
the kernel to access swap

- setup all PT maps necessary for swapper to be functional
before the swapper is started.

This is to break circular dependencies mapping pages inside the
swapper, especially during boot.

We might also need to statically map the LRU swap count structure,
not sure. We'll burn that bridge when we get there, right now,
let's just get a non count-managed swap even working...
2024-05-03 18:43:57 +08:00
bunnie
ef6a73d329 use the correct session key for swap ram
and also call platform-specific swap init
2024-05-03 18:43:19 +08:00
bunnie
d434e70075 move the IFRAM specifiers to a more public location
The IFRAM allocation used by the loader is now exposed so
we can pick it up and use it in the actual HAL implementation
in usermode.
2024-05-03 16:04:37 +08:00
bunnie
c8d4123ed7 fix the debug printout to walk the virtual addresses in swap PT
The check of mapping sanity happens after the VA mapping, so this
undoes that. I think this is a good idea, because we're also
checking the PA->VA mapping of the PTEs as well now.
2024-05-03 16:03:14 +08:00
bunnie
be98a88a75 patch PTEs mapped to swapper with virtual addresses
The addresses put into the swapper's page table are physical
addresses, which are unusable by the swapper itself. This
patches the PTEs with the repsective virtual address, so we
don't have to do a PT walk inside the swapper when handling
a swap event.

Also fix an off-by-one on the processes count. This is sort of
an old architectural bug in the loader that would be nice to fix
someday.
2024-05-03 16:01:25 +08:00
bunnie
b4d1b4e5bb add swap lib interface to loader
for use by the swapper
2024-05-02 22:15:32 +08:00
bunnie
67685db741 create the SwapSpec structure and mappings 2024-05-02 22:14:58 +08:00
bunnie
cd43157d1e refactor loader mac accessor interfaces
traits are kind of awful in Rust...it's true, they don't
know how big they are at compile time, so they have to be dyn,
reference, lifetimes, etc...

lot of baggage for a static structure. I guess there's probably
some idk bounds I could put on the traits to make it less poopy
but also just as easy to make it a static structure and not deal
with traits.
2024-05-02 22:13:11 +08:00
bunnie
51dd3b897b map arguments and rpt into loader memory space
this allows us to avoid the dance of getting args/values back
on boot through a syscall
2024-05-02 22:12:07 +08:00
bunnie
e201574eb8 put the verification in the right area 2024-04-30 17:47:57 +08:00
bunnie
c68e351bcc incorporate latest changes into the swap init routine 2024-04-30 17:47:36 +08:00
bunnie
7ae34ed717 add features for alt spi channel on bringup 2024-04-30 17:14:22 +08:00
bunnie
1810880723 add SPIM loader bringup code 2024-04-30 17:13:42 +08:00
bunnie
fd9f85ef58 adjust speeds to reflect actual spec 2024-04-30 17:13:21 +08:00
bunnie
4499097c74 add remainder of test code for spim 2024-04-29 04:13:01 +08:00
bunnie
c1b6f479d4 add some test code for SPIM interface 2024-04-29 04:10:54 +08:00
bunnie
31c51a2a7f add spim-test flag for loader 2024-04-29 04:09:53 +08:00
bunnie
506bcdc7b9 add pio tester feature flag 2024-04-29 03:44:46 +08:00
bunnie
0adb20b3d8 add a test stub for the quantum timer in the loader
a little easier to do low level peripheral testing here than in
the kernel
2024-04-29 03:42:34 +08:00
bunnie
4926e61fec cleanup mut warning 2024-04-28 02:57:44 +08:00
bunnie
07c9890919 fix location of kernel; attempt to debug loader 2024-04-28 02:43:11 +08:00
bunnie
c491c63e42 add PLL computation code 2024-04-27 22:24:27 +08:00
bunnie
2702b94c93 include signature block in kernel offset constant 2024-04-26 18:20:14 +08:00
bunnie
d85ff12ca2 rework the kernel offset 2024-04-26 18:19:59 +08:00
bunnie
6c2cb85a44 make sram-margin and boot delay feature flags 2024-04-26 18:16:56 +08:00
bunnie
a781b2e15d start to lay in code rework for booting on real chips 2024-04-26 18:16:12 +08:00
bunnie
05d2f3d6a9 configure boot addresses 2024-04-26 18:15:05 +08:00
bunnie
c407db877e change DUART ports to accommodate jtag breakout 2024-04-22 11:00:06 +08:00
bunnie
73c834d067 start debugging of swap in kernel
switching contexts to bringing up hardware.
2024-04-22 10:58:37 +08:00
bunnie
799d1554ae chore: CI fixes 2024-04-09 18:51:36 +08:00
bunnie
4ace363abc this resolves comments from @xobs' code review 2024-04-09 18:23:09 +08:00
bunnie
336e47eabe remove comment 2024-04-09 15:46:48 +08:00
bunnie
6735312444 add some more asserts & checks; undo kernel load last patch
kernel load last isn't necessary

add some asserts to help sanity check things. In particular,
the kernel mapped memory can't exceed 0xA000 in length, otherwise
it bumps into hard-coded constants in the kernel for where hardware
mapped pages should go (i.e., panic framebuffer, debug UART, etc.)
2024-04-09 15:30:21 +08:00
bunnie
d367c99a1f fix page mapping; allow kernel to load in arg order; swap_root breakout
Page mapping just can't be done during the phase 1 loading, because
we move the loading point by an unpredictable amount which messes
up phase 2. I mean, we could try to predict the amount, but it's easier
if we just stick with the current algorithm instead of trying to
do both at once. Basically, phase 1 must be "no-alloc" entirely
as it copies.

Phase 2 can allocate page table entries, because all the data
is copied to RAM and you know where that starts; and you can start
to append data to the end of that without affecting the loading
points of programs.

Undo a previous patch to force kernel to load last. Turns out
this is legal, it was only problematic because of other bugs.

Also, reflect swap_root in the BootConfig structure and not
in InitialProcess structure.

+ Various other debug fixes
2024-04-09 15:26:38 +08:00
bunnie
8c82d710bb reflect swap offset patches in atamsam5d27 arch 2024-04-09 15:25:59 +08:00
bunnie
8abb126577 break out swap_root & improve debug 2024-04-09 15:25:37 +08:00
bunnie
a66e4f5901 modify stack smash check to detect if non-PID is written
this is more robust, and should work across all architectures.

Note that the reliability of the check is slightly impacted
since we're now checking for a subset of valid numbers, so
the number of bytes checked is doubled.
2024-04-09 15:24:22 +08:00
bunnie
d6e7f7ce16 add debugging and asserts to detect stack smash in loader
In swap configuration, the loader does a lot more: it has
to decrypt full pages of RAM and hold them temporarily;
up to two pages at once, once for the decrypt of the source
swap image, and one for the encrypt to swap memory.

This causes a lot more stack to be used than the original loader.

Add some debugging for this, and an assert based on a heuristic
that the RPT (runtime page tracker) last few entries ought to
be 0. This I think is probably true on most platforms. If this
fails to be true, then, we can probably modify the assert to
fail if any number in the RPT is greater than the number of
processes: this should be true in *all* cases, but a stack smash
is very likely to write something in there that's larger than
the number of allowable processes in the system.
2024-04-09 15:17:49 +08:00
bunnie
630a81b185 we need more stack to decrypt memory in the loader. 2024-04-09 15:17:21 +08:00
bunnie
30202d962c don't build swap_root into the InitialProcess structure
the kernel doesn't use it, so it just ends up being wasted
space.
2024-04-09 15:16:26 +08:00
bunnie
9992d29b40 chore: cleanup warning in non-swap mode 2024-04-09 00:06:18 +08:00
bunnie
d318134bdc fix default flags for swap; add load checking for swap
load checking is aware of all three types of sections, and
can natively call the encrypt/decrypt ops to ensure that
the encrypted swap is set up correctly.
2024-04-09 00:04:47 +08:00
bunnie
62f1ad09f0 ensure that the kernel is loaded last, even after argument extension
The kernel is supposed to be loaded last, but, when we append
arguments that isn't true anymore. This fix makes sure the
kernel is loaded last.
2024-04-09 00:03:48 +08:00
bunnie
dbacbb609b fix argument appending and mutability issues
The argument appending code in copy_args() is truly abominable.
Suspect more latent bugs in there. Definitely some deep technical
debt in this routine, it's basically just a pile of unsafe pointers
jammed together with no checks. This has to do in part with the
underlying implementation of the argument iterators, which
understandably try to do a lot with no allocations, but it's
brittle and does not play nicely with the idea of extending
the argument records.
2024-04-09 00:01:08 +08:00
bunnie
d6a9c85acb extended debugging; make check_load aware of swap 2024-04-08 23:58:19 +08:00
bunnie
bd58d9187e make secboot's stack test adjust to the platform-defined RAM available 2024-04-08 23:56:35 +08:00
bunnie
8811114a9b remove unused alignment feature
we're not passing pages around like I thought I would. svae
the stack space, so in the future if we do stuff with e.g.
suspend/resume we don't have to reserve such a huge
chunk of RAM for boot.
2024-04-08 23:55:40 +08:00
bunnie
1d0f34779a extend debug to print swap bits 2024-04-08 23:55:24 +08:00
bunnie
03c3f61ba3 fixes to encrypt/decrypt routines to adjust offsets etc. 2024-04-08 23:54:36 +08:00