openarch 0.8.0 —— 第四台机器,与第一个部分后端 - #334
Merged
Merged
Conversation
## The action the trap group was missing
`arch_trap_set_handler` lets a kernel SEE a trap and
`arch_trap_enable_interrupts` lets it MASK one. Neither lets it change what the
trap returns to — and that is the whole of preemption, which is the principal
reason to use this layer on a microcontroller.
void arch_trap_switch(arch_trap_frame* f, void* from, void* to);
Called from a handler. It returns normally; the switch happens when the trap
does. Same storage and same `arch_context_init` as `arch_context_switch`, so a
task can be resumed by either — the two differ only in WHEN.
## ⭐⭐ Four machines, four implementations, one name
riscv64 saves `mepc` across a cooperative switch inside its dispatcher; aarch64
saves `ELR_EL1` and `SPSR_EL1`; x86_64 saves nothing because its `iret` frame
travels with the stack. Cortex-M does none of that: its handler runs on MSP
while the task runs on PSP, so it pends PendSV and the hardware performs the
switch at exception exit. Three of four share a mechanism; the fourth cannot,
and that is exactly what an interface function earns its place by hiding.
## The first PARTIAL backend
`openarch-cortex-m` declares `openarch-backend` and `openarch:preemption`, and
NOT `openarch:address-space` or `openarch:percpu-register`: M-profile has a
region-based MPU with no page-table entry to construct, and no TPIDR-class
register. A kernel that needs either is refused BY NAME at resolution rather
than by a wall of `undefined reference to arch_pte_*` at link time.
Splitting the capability made admitting the machine possible;
`openarch:preemption` made it worth doing.
## Measured
`examples/switch` on riscv64, aarch64 and x86_64 — each now asserting that a
trap resumed a DIFFERENT context, via a counter the other context advanced.
`examples/preempt` on `mps2-an385` under `xim:qemu-arm@9.2.4-1`: two tasks that
never yield, each proving it was interrupted, 15 consecutive runs.
Tarball sha256 verified against the bytes and re-fetched from the CN mirror,
byte-identical. Index lints: mirror-urls, package-name, platform parity,
duplicate versions and cross-package refs all pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
openarch 0.8.0 — a fourth machine, and the first partial backend
The action the trap group was missing
arch_trap_set_handlerlets a kernel SEE a trap andarch_trap_enable_interruptslets it MASK one. Neither lets it change what thetrap returns to — and that is the whole of preemption, which is the principal
reason to use this layer on a microcontroller.
Called from a handler. It returns normally; the switch happens when the trap
does. Same storage and same
arch_context_initasarch_context_switch, so atask can be resumed by either — the two differ only in WHEN.
⭐⭐ Four machines, four implementations, one name
riscv64 saves
mepcacross a cooperative switch inside its dispatcher; aarch64saves
ELR_EL1andSPSR_EL1; x86_64 saves nothing because itsiretframetravels with the stack. Cortex-M does none of that: its handler runs on MSP
while the task runs on PSP, so it pends PendSV and the hardware performs the
switch at exception exit. Three of four share a mechanism; the fourth cannot,
and that is exactly what an interface function earns its place by hiding.
The first PARTIAL backend
openarch-cortex-mdeclaresopenarch-backendandopenarch:preemption, andNOT
openarch:address-spaceoropenarch:percpu-register: M-profile has aregion-based MPU with no page-table entry to construct, and no TPIDR-class
register. A kernel that needs either is refused BY NAME at resolution rather
than by a wall of
undefined reference to arch_pte_*at link time.Splitting the capability made admitting the machine possible;
openarch:preemptionmade it worth doing.Measured
examples/switchon riscv64, aarch64 and x86_64 — each now asserting that atrap resumed a DIFFERENT context, via a counter the other context advanced.
examples/preemptonmps2-an385underxim:qemu-arm@9.2.4-1: two tasks thatnever yield, each proving it was interrupted, 15 consecutive runs.
Tarball sha256 verified against the bytes and re-fetched from the CN mirror,
byte-identical. Index lints: mirror-urls, package-name, platform parity,
duplicate versions and cross-package refs all pass.