Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions .github/workflows/hardware-workspace.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
name: Reaper Hardware Workspace v1
name: Reaper Linux UIO Physical MMIO

on:
push:
branches: [main, "feat/**", "integration/**"]
paths:
- "selfhost/hardware_workspace.rpr"
- "tests/hardware_workspace_conformance.rpr"
- "tests/test_hardware_workspace.py"
- "include/reaper/hardware.h"
- "include/reaper/hardware_uio.h"
- "src/hardware.c"
- "src/hardware_uio.c"
- "tests/test_hardware.c"
- "tests/test_hardware_uio.c"
- "CMakeLists.txt"
- ".github/workflows/hardware-workspace.yml"
pull_request:
paths:
- "selfhost/hardware_workspace.rpr"
- "tests/hardware_workspace_conformance.rpr"
- "tests/test_hardware_workspace.py"
- "include/reaper/hardware.h"
- "include/reaper/hardware_uio.h"
- "src/hardware.c"
- "src/hardware_uio.c"
- "tests/test_hardware.c"
- "tests/test_hardware_uio.c"
- "CMakeLists.txt"
- ".github/workflows/hardware-workspace.yml"

permissions:
contents: read

jobs:
conformance:
name: Execute Reaper hardware contracts
linux-uio:
name: Build and test Linux physical MMIO transport
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Compile the hardware test harness
run: python -m py_compile tests/test_hardware_workspace.py
- name: Execute Reaper-native hardware contract fixtures
run: python -m unittest tests.test_hardware_workspace -v
- name: Configure native C17 build and UIO tests
run: cmake -S . -B build-uio -DCMAKE_BUILD_TYPE=Release -DREAPER_BUILD_TESTS=ON
- name: Build UIO backend and checked MMIO tests
run: cmake --build build-uio --parallel --target reaper-hardware-tests reaper-hardware-uio-tests
- name: Execute fake-bus and file-backed physical MMIO tests
run: ctest --test-dir build-uio --output-on-failure -R '^native-hardware(-uio)?$'
44 changes: 25 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ set(CMAKE_C_EXTENSIONS OFF)
add_library(reaper_hardware STATIC src/hardware.c)
target_include_directories(reaper_hardware PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_library(reaper_hardware_uio STATIC src/hardware_uio.c)
target_include_directories(reaper_hardware_uio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(reaper_hardware_uio PUBLIC reaper_hardware)
set_target_properties(reaper_hardware_uio PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(reaper_hardware_uio PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow)
endif()

add_library(reaper_locale_tag STATIC src/locale_tag.c)
target_include_directories(reaper_locale_tag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(reaper_evolution STATIC src/evolution.c)
target_include_directories(reaper_evolution PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(reaper_token_catalog STATIC src/token_catalog.c)
target_include_directories(reaper_token_catalog PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

Expand Down Expand Up @@ -52,9 +57,6 @@ reaper_add_source_module(reaper_frontend_objects
src/ast_json.c
)

add_library(reaper_snapshot_audit STATIC src/snapshot_audit.c)
target_include_directories(reaper_snapshot_audit PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

reaper_add_source_module(reaper_data_objects
src/harw.c
src/harw_value.c
Expand All @@ -77,18 +79,6 @@ reaper_add_source_module(reaper_architecture_services_objects
# dependency verification.
# Static leaves extracted from the broader object groups after verifying their
# public-header and symbol dependencies. The aggregate remains a compatibility target.
add_library(reaper_locale_tag STATIC src/locale_tag.c)
target_include_directories(reaper_locale_tag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(reaper_capability_suite STATIC src/capability_suite.c)
target_include_directories(reaper_capability_suite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(UNIX)
target_link_libraries(reaper_capability_suite PUBLIC m)
endif()

add_library(reaper_hardware STATIC src/hardware.c)
target_include_directories(reaper_hardware PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(reaper_system_features STATIC src/system_features.c)
target_include_directories(reaper_system_features PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

Expand Down Expand Up @@ -129,6 +119,9 @@ add_library(reaper_core STATIC
)
target_include_directories(reaper_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(reaper_core PUBLIC reaper_division reaper_locale_tag reaper_capability_suite reaper_hardware reaper_system_features reaper_evolution reaper_lineage reaper_architecture reaper_snapshot_audit)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(reaper_core PUBLIC reaper_hardware_uio)
endif()
if(UNIX)
target_link_libraries(reaper_core PUBLIC m)
endif()
Expand Down Expand Up @@ -316,6 +309,15 @@ if(REAPER_BUILD_TESTS)
target_link_libraries(reaper-hardware-tests PRIVATE reaper_core)
reaper_enable_native_test_assertions(reaper-hardware-tests)
add_test(NAME native-hardware COMMAND reaper-hardware-tests)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_executable(reaper-hardware-uio-tests tests/test_hardware_uio.c src/hardware_uio.c)
target_include_directories(reaper-hardware-uio-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_compile_definitions(reaper-hardware-uio-tests PRIVATE REAPER_HW_UIO_TESTING=1)
target_link_libraries(reaper-hardware-uio-tests PRIVATE reaper_hardware)
target_compile_options(reaper-hardware-uio-tests PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow)
reaper_enable_native_test_assertions(reaper-hardware-uio-tests)
add_test(NAME native-hardware-uio COMMAND reaper-hardware-uio-tests)
endif()
add_executable(reaper-hw-graph-tests tests/test_hw_graph.c)
target_link_libraries(reaper-hw-graph-tests PRIVATE reaper_core)
add_test(NAME native-hardware-graph COMMAND reaper-hw-graph-tests)
Expand Down Expand Up @@ -449,6 +451,10 @@ install(TARGETS reaper_ffi_shared
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)
install(TARGETS reaper_hardware ARCHIVE DESTINATION lib)
install(TARGETS reaper_system ARCHIVE DESTINATION lib)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
install(TARGETS reaper_hardware_uio ARCHIVE DESTINATION lib)
endif()
install(TARGETS reaper_dabi64_desktop ARCHIVE DESTINATION lib)
install(FILES include/reaper/ffi.h include/reaper/system.h include/reaper/intrinsics.h include/reaper/dabi64_desktop.h include/reaper/architecture.h include/reaper/snapshot_audit.h include/reaper/system_features.h include/reaper/godra.h include/reaper/locale_tag.h include/reaper/linguistic_system.h include/reaper/harw.h include/reaper/harw_value.h include/reaper/harw_context.h DESTINATION include/reaper)
install(FILES include/reaper/ffi.h include/reaper/system.h include/reaper/intrinsics.h include/reaper/dabi64_desktop.h include/reaper/architecture.h include/reaper/snapshot_audit.h include/reaper/system_features.h include/reaper/godra.h include/reaper/locale_tag.h include/reaper/linguistic_system.h include/reaper/harw.h include/reaper/harw_value.h include/reaper/harw_context.h include/reaper/hardware.h include/reaper/hardware_uio.h DESTINATION include/reaper)
7 changes: 6 additions & 1 deletion docs/EMBEDDED_C_WORKBENCH.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Embedded C workbench

Reference MCU profiles, FLASH/SRAM budgets and starter templates are advisory. MMIO is simulated only. No firmware, bootloader, physical register or device is flashed or written. Verify vendor documentation before hardware use.
Reference MCU profiles, FLASH/SRAM budgets and starter templates remain advisory. A Linux UIO physical MMIO backend is now available for peripherals exported by a reviewed UIO kernel driver; the native fake-bus API remains available for tests. This does not add MCU probe programming, firmware flashing, bootloader writes, interrupts or DMA. Verify the vendor memory map and driver configuration before accessing hardware.


## Processor/kernel control model
Expand All @@ -16,3 +16,8 @@ The native core now exposes a checked MMIO descriptor and host-adapter API in in
The versioned, executable Reaper contract is in `selfhost/hardware_workspace.rpr`; its schema, exact data shapes and trust boundaries are documented in [HARDWARE_WORKSPACE_V1.md](HARDWARE_WORKSPACE_V1.md). It validates target triples and ABI metadata, typed peripheral/register manifests, non-overlapping Flash/SRAM/ROM/MMIO/reserved/DMA maps, linker-section placement, stack/heap/static/IRQ/DMA budgets, typed inspection-IR projections, simulator argv plans, captured register/memory snapshots, and per-project authorization preflight. The contract suite runs as `python -m unittest tests.test_hardware_workspace -v`.

This remains a policy/validation layer: it does not run a compiler, launch QEMU, connect a probe, map physical addresses, flash firmware, or enforce privileged OS/driver authorization.


## Linux UIO physical backend

On Linux, include/reaper/hardware_uio.h and src/hardware_uio.c implement a real UIO-backed MMIO transport for reviewed UIO_MEM_PHYS drivers. The backend checks the character-device major/minor identity, requires expected_base = sysfs addr + offset, limits expected_size to size - offset, maps only the pages intersecting the grant, and rejects writes unless REAPER_HW_CAP_MMIO_WRITE is explicitly granted and the process can open the node writable. The sysfs ABI does not expose map memory type, so audit the selected driver's registration before use. No /dev/mem fallback. See [Linux UIO physical MMIO backend](LINUX_UIO_HARDWARE_BACKEND.md). Hosted CI uses a file-backed mapping, not a physical board.
10 changes: 6 additions & 4 deletions docs/HARDWARE_LANGUAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The language is not allowed to imply that user-space code can safely access arbi
| Native compiler | scalar AOT subset emits C17 and invokes a host GCC/Clang-compatible compiler | no full native parity, no direct ELF/PE/Mach-O emitter |
| C17 core | native lexer, expression parser, owned AST, checked integer IR, constant folding and limited lowering | IR and parser cover only a small subset |
| QCS | separate hardware-domain lexer/parser and JSON AST | design/validation frontend, not device execution |
| Embedded workbench | MCU profiles, Flash/SRAM maps, linker-script generation and cross-compiler process invocation | no board flashing or physical MMIO |
| Reaper-native Hardware Workspace v1 | Reaper-source contracts for target tuples, typed manifests, section maps, budgets, inspection IR, simulator plans, debug snapshots and authorization preflight | no target-qualified backend, live probe, physical MMIO or OS authorization |
| Embedded workbench | MCU profiles, Flash/SRAM maps, linker-script generation, cross-compiler process plans and Linux UIO physical MMIO transport | UIO-backed MMIO only; no MCU probe, flashing, interrupts or DMA |
| Reaper-native Hardware Workspace v1 | Reaper-source contracts for target tuples, typed manifests, section maps, budgets, inspection IR, simulator plans, debug snapshots and authorization preflight | contracts remain policy metadata; see Linux UIO native transport below |
| Studio | Windows editor/debugger foundation plus a Systems/Hardware overview showing MCU profiles and current access limits | no live device inspector or complete hardware IDE |
| Native capability catalogue | versioned module and operation descriptions with a small set of C primitives | catalogue entries are not automatically executable handlers |

Expand Down Expand Up @@ -113,7 +113,9 @@ The C API in include/reaper/hardware.h provides:
- capability checks before read/write callbacks;
- a host-supplied bus adapter, enabling deterministic fake-device tests.

The API does **not** map physical memory, execute privileged instructions, register real interrupts, allocate DMA memory or communicate with a real device by itself. A trusted OS driver/HAL must supply the adapter and enforce platform-specific mapping, cache, barrier and privilege rules. W1C/W1S writes are passed as explicit values; clients must not implement them as an implicit read-modify-write sequence.
The Linux UIO backend in include/reaper/hardware_uio.h and src/hardware_uio.c now supplies a physical MMIO bus for a reviewed UIO map. It verifies the /dev/uioN character-device identity against sysfs, pins the expected physical base and size, bounds every access, honours the selected read/write grant and applies target-specific I/O barriers. It never falls back to /dev/mem. See [Linux UIO physical MMIO backend](LINUX_UIO_HARDWARE_BACKEND.md).

The backend does **not** flash firmware, speak SWD/JTAG, enumerate CMSIS-DAP/J-Link/ST-Link probes, register interrupts, allocate/synchronize DMA memory or enforce a cryptographic per-project broker. The kernel UIO driver owns the physical mapping and memory attributes; OS device-node permissions remain the effective privilege boundary. W1C/W1S writes are passed as explicit values; clients must not implement them as an implicit read-modify-write sequence.

## Current native hardware graph planner

Expand Down Expand Up @@ -213,4 +215,4 @@ The downstream DuckOS integration is specified separately in [DUCKOS_SYSTEM_SERV

The Reaper-native contract module is `selfhost/hardware_workspace.rpr`; its versioned data shapes, checks and evidence boundaries are documented in [HARDWARE_WORKSPACE_V1.md](HARDWARE_WORKSPACE_V1.md). The new conformance fixture executes the contracts with the reference runtime and checks valid and rejected project descriptions. This adds executable validation for target/triple/ABI tuples, typed peripheral registers, region/section layout, resource budgets, annotated inspection IR, shell-free simulator plans, captured debugger data, and project authorization preflight.

This is not a claim of live device access or completed compiler backends. The native C MMIO API remains the separate checked bus-adapter surface; this Reaper module does not perform physical mapping. QEMU plans are not launched, snapshots are supplied by adapters, and the host OS/driver remains the actual privilege authority.
This is not a claim of live device access or completed compiler backends. The Reaper-source policy module does not itself perform physical mapping. A separate Linux native C transport now provides bounded UIO-backed MMIO for reviewed UIO_MEM_PHYS kernel drivers; see [Linux UIO physical MMIO backend](LINUX_UIO_HARDWARE_BACKEND.md). The UIO sysfs ABI does not expose map memory type, so the selected kernel driver must be audited before use. This does not add MCU probe programming, firmware flashing, interrupts or DMA. QEMU plans are not launched, snapshots are supplied by adapters, and the host OS/driver remains the actual privilege authority.
2 changes: 1 addition & 1 deletion docs/HARDWARE_WORKSPACE_V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ The fixtures cover valid STM32F0-style target/project data and negative cases fo

## Explicit non-claims

This milestone does not implement physical MMIO mapping, board flashing, firmware deployment, interrupt registration, DMA transfer, privileged driver loading, vendor-probe discovery, or live target debugging. It does not claim that every target in the existing advisory MCU catalogue has an installed cross-compiler. A future host adapter must separately prove executable path resolution, target/ABI compatibility, process lifecycle, privilege checks, audit persistence and hardware-in-the-loop qualification before any live action is enabled.
The Reaper-source policy module itself does not perform physical MMIO mapping, board flashing, firmware deployment, interrupt registration, DMA transfer, privileged driver loading, vendor-probe discovery, or live target debugging. A separate Linux native C transport is now available for UIO-exported MMIO maps; see [Linux UIO physical MMIO backend](LINUX_UIO_HARDWARE_BACKEND.md). That transport still requires a reviewed kernel UIO driver, exact map identity, OS device-node permissions and board-specific hardware-in-the-loop qualification. The repository does not claim that every target in the advisory MCU catalogue has an installed cross-compiler or a physical transport.
Loading
Loading