Skip to content

Implement pvalues#32

Merged
mkobetic merged 19 commits intomainfrom
pvalue
Feb 8, 2026
Merged

Implement pvalues#32
mkobetic merged 19 commits intomainfrom
pvalue

Conversation

@mkobetic
Copy link
Owner

@mkobetic mkobetic commented Feb 5, 2026

Implements #7

Heart of the implementation is in core/pvalue.s (and core/amforth32.ld). Two main API points

  1. pv.store ( x xt -- ) updates pvalue identified by its XT with value x. This is what needs to be used to update pvalues; deliberately using XT to make it easy to use in ITC.
  2. pv.init needs to run in WARM after the normal value initialization, it replays the pvalue records to set the pvalues to the latest know state

The rest happens automatically although it may be sometimes useful to run pvarena.swap explicitly, which is fine. If the MCU is reset during the swap, it is implemented to be safe to rerun as many times as needed until it succeeds. No persistent state should be lost in any circumstance.

The framework relies on few primitves for modifying and reading the flash

  1. DEFER "!pvf", STORE_PVF, XT_STORE /* (x addr -- ) store x at addr in the PV flash */
  2. DEFER "@pvf", FETCH_PVF, XT_FETCH /* (addr -- x) load cell at addr in the PV flash */
  3. DEFER "pvflash.erase", PVFLASH_ERASE, XT_FAUXERASE /* ( addr -- ) erase PV flash page at addr */

The 2) is probably unnecessary, since it's unlikely to be anything but regular fetch but is there for now for balance

Quick summary of the rest of the changes:

  • added new pvarena1/2 linker sections that require each MCU to define PVFLASH memory region.
  • setting LENGTH(PVFLASH) to 0 effectively dissables persistency of pvalues
  • PVFLASH_PAGE must be defined, it is needed for erasing the PVFLASH arenas (pvflash.erase)
  • new PVALUE macro, like VALUE but sets new flag.pvalue, new word pv.do helps iterating over all pvalues in forth-worldlist
  • tests/pvalue.frt tests the basic pvalue operations (QEMU faux PVFLASH only), included in CI tests
  • previously missing to word now duplicates is functionality
  • added build/amforth.map for the linker map
  • dropped symbols and source from build/amforth.lst, it was redundant and made the file hard to use
  • other cleanup and comment additions
  • split lm4f120 into two TARGETS, with different PVFLASH configurations:
    • QEMU emulated lm3s
    • original lm4f

TODO

  • tests
  • deal with pvarena.size zero
  • test on real flash (CH32, RA4?)

@mkobetic mkobetic marked this pull request as ready for review February 8, 2026 01:28
@mkobetic mkobetic merged commit 1f24d73 into main Feb 8, 2026
3 checks passed
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.

1 participant