Skip to content

hal/armv7a: Adding IO mapping functionality in HAL initialization#787

Merged
jmaksymowicz merged 5 commits into
masterfrom
jmaksymowicz/armv7a-map-device
Jun 16, 2026
Merged

hal/armv7a: Adding IO mapping functionality in HAL initialization#787
jmaksymowicz merged 5 commits into
masterfrom
jmaksymowicz/armv7a-map-device

Conversation

@jmaksymowicz

Copy link
Copy Markdown
Contributor

Add IO memory mapping functionality similar to aarch64
Adjust code for imx6ull, zynq7000 targets to use this mapping functionality
Copy syspage to named object in .bss section instead of memory mapped past-the-end of .bss

Description

Previously the way memory-mapped IO devices were made available to the kernel on armv7a platforms was very unintuitive. Code within _init.S mapped them past-the-end of .bss section at arbitrarily chosen offsets, which made it difficult for someone reading the code to understand what was going on.

To solve this, memory-mapped IO is now mapped near the top of the address space (range 0xFFC00000 - 0xFFFF0000) using unused entries in the page table excptab. It is done using _pmap_halMapDevice function with the same API as aarch64, riscv64 and sparcv8leon targets. The physical addresses of peripherals are now declared in C code close to the driver where they are actually used, which helps readability and maintainability.

There are almost 4 MB of address space available through excptab which should be more than enough considering our OS has a microkernel design with few built-in drivers.

Additionally, memory for the syspage was also mapped past-the-end of .bss - which was not necessary considering that syspage could simply be stored to a named object within .bss. After changing this, there is nothing more mapped past .bss on armv7a and this unintuitive mechanism could be removed.

Other changes:

  • On zynq7000 the entry for exception vectors in excptab was removed - it was unused because this target supports Security extensions and thus exception vector address is set using the VBAR register. This doesn't change the functioning of the system.
  • The console driver for IMX6ULL was changed so that now it respects the UART_CONSOLE_KERNEL definition from board_config.h.

Motivation and Context

Part of the work for phoenix-rtos/phoenix-rtos-project#1500

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: armv7a-imx6ull, armv7a-zynq7000-qemu

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the ARMv7a HAL to dynamically map device memory using a new _pmap_halMapDevice function, replacing the previous approach of hardcoding virtual addresses relative to _end in boot assembly. Feedback on these changes focuses on addressing potential edge cases in _pmap_halMapDevice (such as zero-size mappings, page alignment spans, and slot exhaustion assertions), ensuring inline assembly consistency, using addr_t for physical addresses, and appending the U suffix to various hexadecimal constants to prevent signedness issues.

Comment thread hal/armv7a/pmap.c
Comment thread hal/armv7a/arch/cpu.h Outdated
Comment thread hal/armv7a/imx6ull/console.c Outdated
Comment thread hal/armv7a/zynq7000/timer.c Outdated
Comment thread hal/armv7a/zynq7000/zynq.c Outdated
Comment thread hal/armv7a/zynq7000/console.c Outdated
Comment thread hal/armv7a/zynq7000/console.c Outdated
Comment thread hal/armv7a/imx6ull/console.c Fixed
Comment thread hal/armv7a/imx6ull/console.c Fixed
Comment thread hal/armv7a/imx6ull/interrupts.c Fixed
@jmaksymowicz jmaksymowicz marked this pull request as draft May 29, 2026 10:52
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/armv7a-map-device branch from a9000e2 to 79086f2 Compare May 29, 2026 11:27
Comment thread hal/armv7a/imx6ull/interrupts.c Fixed
@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

Unit Test Results

10 860 tests  +275   10 190 ✅ +275   52m 59s ⏱️ +51s
   670 suites + 21      670 💤 ±  0 
     1 files   ±  0        0 ❌ ±  0 

Results for commit ad0cef8. ± Comparison against base commit 57b3041.

This pull request removes 3 and adds 278 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m7-imxrt106x-evk:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m7-imxrt117x-evk:phoenix-rtos-tests/libcache/unit
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_cleanCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_flushCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_read_readCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_write_readCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_callback_err.cache_write_writeCallbackErr
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_addrOutOfScope
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_addrPartiallyInScope
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_badAddrRange
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_clean.cache_clean_lines
phoenix-rtos-tests/libcache/unit ‑ armv7m4-stm32l4x6-nucleo:phoenix-rtos-tests/libcache/unit.test_deinit.cache_deinit_initalizedCache
…

♻️ This comment has been updated with latest results.

@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/armv7a-map-device branch from 79086f2 to c197c89 Compare May 29, 2026 13:28
Comment thread hal/armv7a/pmap.c Fixed
Comment thread hal/armv7a/pmap.c Fixed
Comment thread hal/armv7a/pmap.c Fixed
Comment thread hal/aarch64/pmap.c Fixed
Comment thread hal/aarch64/pmap.c Fixed
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/armv7a-map-device branch from c197c89 to 7401084 Compare May 29, 2026 13:45
@jmaksymowicz jmaksymowicz marked this pull request as ready for review May 29, 2026 14:03
Comment thread hal/armv7a/imx6ull/interrupts.c
Comment thread hal/armv7a/zynq7000/interrupts.c
Comment thread hal/aarch64/pmap.c Outdated
Comment thread hal/armv7a/imx6ull/console.c
Comment thread hal/armv7a/imx6ull/imx6ull.c
Create _pmap_halMapDevice() function similar to AArch64 implementation.

YT: RTOS-1337
Change IMX6ULL console driver to respect UART_CONSOLE_KERNEL definition.

YT: RTOS-1337
Change from previous method of copying syspage to the page after the end
of kernel data to copying to a named object in .bss section.
Remove SIZE_EXTEND_BSS from pmap.c as it is no longer necessary.

YT: RTOS-1337
Fix incorrect mapping that could happen if offset within the page
is not 0.

YT: RTOS-1337
@jmaksymowicz jmaksymowicz force-pushed the jmaksymowicz/armv7a-map-device branch from 7401084 to ad0cef8 Compare June 10, 2026 16:01
@jmaksymowicz jmaksymowicz requested a review from Darchiv June 12, 2026 12:48
@jmaksymowicz jmaksymowicz merged commit a7b0cf1 into master Jun 16, 2026
51 checks passed
@jmaksymowicz jmaksymowicz deleted the jmaksymowicz/armv7a-map-device branch June 16, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants