|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Drives each ra8_mem (#147) memory-hierarchy layer in isolation (#263). More...
#include <stddef.h>#include <stdint.h>#include <string.h>#include "ra8_arena.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_slab.h"#include "ra8_tile_cache.h"#include "ra8_time.h"#include "ra8_vmem_stream.h"#include "ra8_vsource.h"Go to the source code of this file.
Data Structures | |
| struct | mem_report_t |
| Observables gathered from the four exercises. More... | |
Functions | |
| static void | mem_print (const uint8_t *msg, uint32_t len) |
| Emit a byte run on the board console. | |
| static void | mem_panic_halt (const uint8_t *msg, uint32_t len) |
| Print the fail banner and trap (ra8_emulator halts on the BKPT). | |
| static uint32_t | mem_crc32_byte (uint32_t crc, uint8_t b) |
| Fold one byte into a running CRC-32 (reflected, poly 0xEDB88320). | |
| static uint8_t | mem_gen_byte (uint64_t off) |
Deterministic backing byte at absolute off (host/emulator/silicon-equal). | |
| static void | mem_print_hex (uint32_t value) |
| Print a 32-bit value as 8 upper-case hex digits. | |
| static void | mem_print_uint (uint32_t value) |
| Print a small unsigned integer in decimal. | |
| static bool | mem_run_slab (mem_report_t *r) |
| Exercise 1: slab alloc-to-exhaustion, free, and reset-by-reinit. | |
| static bool | mem_run_arena (mem_report_t *r) |
| Exercise 2: arena bump carves, over-subscription, and reset-by-reinit. | |
| static ra8_err_t | mem_tile_decode (void *ctx, const ra8_tile_key_t *key, uint8_t *cell, uint32_t cell_bytes, uint16_t *out_w, uint16_t *out_h) |
| Synthetic tile decoder: stamps the key column into the cell. | |
| static ra8_err_t | mem_tile_touch (ra8_tile_cache_t *tc, uint16_t tx) |
Fetch (get + immediately put) tile column tx, so it is unpinned. | |
| static bool | mem_run_tiles (mem_report_t *r) |
| Exercise 3: overfill the tile cache to observe LRU eviction. | |
| static ra8_err_t | mem_backing_read (void *ctx, uint64_t offset, uint8_t *buf, uint32_t len) |
Backing read callback: fill buf with the deterministic generator. | |
| static bool | mem_stream_window (ra8_vmem_stream_t *st, uint64_t off, uint32_t len, uint32_t *crc, size_t *out_got) |
| Read one byte window through the stream, verify it, and fold it in. | |
| static bool | mem_vmem_read_windows (ra8_vmem_stream_t *st, uint32_t *crc) |
| Read every window and confirm the stream returned the expected lengths. | |
| static bool | mem_run_vmem (mem_report_t *r) |
| Exercise 4: stream byte windows out of a 1 MiB object via a 2 KiB cache. | |
| static void | mem_setup_or_halt (void) |
| Bring up clocks / MSTP / time + the board console; halt on failure. | |
| void | main (void) |
| App entry: drive each ra8_mem layer, then print the observables banner. | |
Variables | |
| static uint8_t | s_slab_pool [k_mem_slab_pool_bytes] |
| Slab-exercise pool. | |
| static uint8_t | s_arena_pool [k_mem_arena_pool_bytes] |
| Arena-exercise region. | |
| static uint8_t | s_tile_cells [(size_t) k_mem_tile_cells *(size_t) k_mem_tile_cell_bytes] |
| Tile-cache decoded-pixel cells. | |
| static ra8_tile_key_t | s_tile_keys [k_mem_tile_cells] |
| Tile-cache per-cell key storage. | |
| static ra8_tile_dims_t | s_tile_dims [k_mem_tile_cells] |
| Tile-cache per-cell dimension descriptors. | |
| static ra8_keycache_cell_t | s_tile_meta [k_mem_tile_cells] |
| Tile-cache per-cell link metadata. | |
| static int32_t | s_tile_buckets [k_mem_tile_buckets] |
| Tile-cache hash buckets. | |
| static uint8_t | s_vmem_frames [(size_t) k_mem_vmem_frames *(size_t) k_mem_vmem_frame_bytes] |
| Page-cache frame storage (2 KiB resident). | |
| static ra8_vmem_frame_t | s_vmem_fmeta [k_mem_vmem_frames] |
| Page-cache per-frame metadata. | |
| static ra8_vmem_key_t | s_vmem_fkeys [k_mem_vmem_frames] |
| Page-cache per-frame key storage. | |
| static int32_t | s_vmem_fbuckets [k_mem_vmem_buckets] |
| Page-cache hash buckets. | |
| static ra8_vsource_obj_t | s_vmem_objs [k_mem_vmem_objs] |
| Object-source registry slots. | |
| static uint8_t | s_win_buf [k_mem_win_buf_bytes] |
| Stream read scratch (>= the widest window). | |
| static const uint8_t | k_msg_boot [] = "mem-subsystem: boot 2KiB-resident-1MiB-paged\r\n" |
| static const uint8_t | k_msg_fail_init [] = "mem: FAIL init\r\n" |
| static const uint8_t | k_msg_fail_slab [] = "mem: FAIL slab\r\n" |
| static const uint8_t | k_msg_fail_arena [] = "mem: FAIL arena\r\n" |
| static const uint8_t | k_msg_fail_tile [] = "mem: FAIL tile\r\n" |
| static const uint8_t | k_msg_fail_vmem [] = "mem: FAIL vmem\r\n" |
| static const uint8_t | k_msg_slab [] = "mem: slab_free=" |
| static const uint8_t | k_msg_arena [] = " arena_free=" |
| static const uint8_t | k_msg_tile [] = " tile_evict=" |
| static const uint8_t | k_msg_vmem [] = " vmem_crc=" |
| static const uint8_t | k_msg_ok [] = " PASS\r\n" |
Drives each ra8_mem (#147) memory-hierarchy layer in isolation (#263).
The #147 memory primitives (ra8_slab, ra8_arena, ra8_tile_cache, and the ra8_vmem / ra8_vsource / ra8_vmem_stream page cache) are exercised inside the e-reader but had no direct example. This app drives each one on its own so the behaviour is observable without the whole reader stack:
The console banner is:
mem: slab_free=8 arena_free=4096 tile_evict=5 vmem_crc=<8hex> PASS
Every value is computed by the deterministic ra8_mem library from fixed inputs with no MMIO, so the banner is byte-identical on the host unit test (tests/mocks/src/test_app_mem_subsystem.c), ra8_emulator, and silicon. Any failure on any layer prints a FAIL banner and traps on a BKPT before the PASS line, so the EIL / HIL gate is exact.
[Ring 7 / App] {World: NS}
Definition in file main.c.
| enum mem_arena_cfg_t : uint32_t |
| enum mem_console_t : uint32_t |
Console + banner-format knobs (no magic numbers).
| enum mem_gen_t : uint32_t |
| enum mem_slab_cfg_t : uint32_t |
| enum mem_tile_cfg_t : uint32_t |
Tile-cache-exercise sizing + expected counters.
| enum mem_tile_dim_t : uint16_t |
| enum mem_vmem_cfg_t : uint32_t |
vmem_stream-exercise sizing + read windows.
| void main | ( | void | ) |
App entry: drive each ra8_mem layer, then print the observables banner.
The application entry point Reset_Handler hands control to.
Definition at line 582 of file main.c.
References mem_report_t::arena_free, k_msg_arena, k_msg_boot, k_msg_fail_arena, k_msg_fail_slab, k_msg_fail_tile, k_msg_fail_vmem, k_msg_ok, k_msg_slab, k_msg_tile, k_msg_vmem, mem_panic_halt(), mem_print(), mem_print_hex(), mem_print_uint(), mem_run_arena(), mem_run_slab(), mem_run_tiles(), mem_run_vmem(), mem_setup_or_halt(), ra8_isr_globals_enable(), mem_report_t::slab_free, mem_report_t::tile_evictions, and mem_report_t::vmem_crc.
|
static |
Backing read callback: fill buf with the deterministic generator.
Definition at line 427 of file main.c.
References k_ra8_err_null_ptr, k_ra8_ok, and mem_gen_byte().
Referenced by mem_run_vmem().
|
static |
Fold one byte into a running CRC-32 (reflected, poly 0xEDB88320).
Definition at line 210 of file main.c.
References k_mem_crc_bits, and k_mem_crc_poly.
Referenced by mem_stream_window().
|
static |
Deterministic backing byte at absolute off (host/emulator/silicon-equal).
Definition at line 221 of file main.c.
References k_mem_gen_add, k_mem_gen_mul, k_mem_gen_shift_a, k_mem_gen_shift_b, and k_mem_gen_shift_out.
Referenced by mem_backing_read(), and mem_stream_window().
|
static |
Print the fail banner and trap (ra8_emulator halts on the BKPT).
Definition at line 200 of file main.c.
References mem_print().
Referenced by main(), and mem_setup_or_halt().
|
static |
Emit a byte run on the board console.
Definition at line 194 of file main.c.
References ra8_board_uart_console_write().
Referenced by main(), mem_panic_halt(), mem_print_hex(), and mem_print_uint().
|
static |
Print a 32-bit value as 8 upper-case hex digits.
Definition at line 230 of file main.c.
References k_mem_dec_base, k_mem_hex_nibbles, k_mem_nibble_bits, k_mem_nibble_mask, and mem_print().
Referenced by main().
|
static |
Print a small unsigned integer in decimal.
Definition at line 243 of file main.c.
References k_mem_dec_base, and mem_print().
Referenced by main().
|
static |
Exercise 2: arena bump carves, over-subscription, and reset-by-reinit.
| [out] | r | Report to update with the bytes remaining after the reset. |
Definition at line 316 of file main.c.
References mem_report_t::arena_free, k_mem_arena_align0, k_mem_arena_align1, k_mem_arena_big, k_mem_arena_carve0, k_mem_arena_carve1, k_mem_arena_pool_bytes, k_ra8_err_no_mem, k_ra8_ok, ra8_arena_carve(), ra8_arena_init(), ra8_arena_remaining(), and s_arena_pool.
Referenced by main().
|
static |
Exercise 1: slab alloc-to-exhaustion, free, and reset-by-reinit.
| [out] | r | Report to update with the free-cell count after the reset. |
Definition at line 267 of file main.c.
References k_mem_slab_cell_bytes, k_mem_slab_cells, k_mem_slab_freed, k_ra8_err_no_mem, k_ra8_ok, ra8_slab_alloc(), ra8_slab_free(), ra8_slab_init(), ra8_slab_stats(), s_slab_pool, and mem_report_t::slab_free.
Referenced by main().
|
static |
Exercise 3: overfill the tile cache to observe LRU eviction.
| [out] | r | Report to update with the hit / miss / eviction counters. |
Definition at line 382 of file main.c.
References k_mem_tile_buckets, k_mem_tile_cell_bytes, k_mem_tile_cells, k_mem_tile_distinct, k_mem_tile_exp_evict, k_mem_tile_exp_hits, k_mem_tile_exp_miss, k_ra8_ok, mem_tile_decode(), mem_tile_touch(), ra8_tile_cache_init(), ra8_tile_cache_stats(), s_tile_buckets, s_tile_cells, s_tile_dims, s_tile_keys, s_tile_meta, mem_report_t::tile_evictions, mem_report_t::tile_hits, and mem_report_t::tile_misses.
Referenced by main().
|
static |
Exercise 4: stream byte windows out of a 1 MiB object via a 2 KiB cache.
| [out] | r | Report to update with the window CRC + page-cache evictions. |
Definition at line 510 of file main.c.
References k_mem_crc_init, k_mem_crc_xorout, k_mem_vmem_buckets, k_mem_vmem_frame_bytes, k_mem_vmem_frames, k_mem_vmem_obj_bytes, k_mem_vmem_objs, k_ra8_ok, mem_backing_read(), mem_vmem_read_windows(), ra8_vmem_init(), ra8_vmem_stats(), ra8_vmem_stream_init(), ra8_vsource_add_paged(), ra8_vsource_init(), ra8_vsource_loader(), s_vmem_fbuckets, s_vmem_fkeys, s_vmem_fmeta, s_vmem_frames, s_vmem_objs, mem_report_t::vmem_crc, and mem_report_t::vmem_evictions.
Referenced by main().
|
static |
Bring up clocks / MSTP / time + the board console; halt on failure.
Definition at line 557 of file main.c.
References k_mem_uart_baud, k_msg_fail_init, k_ra8_clock_id_cpuclk0, k_ra8_ok, mem_panic_halt(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().
Referenced by main().
|
static |
Read one byte window through the stream, verify it, and fold it in.
| [in] | st | Bound vmem stream. |
| [in] | off | Absolute object offset to read from. |
| [in] | len | Bytes requested. |
| [in,out] | crc | Running CRC-32 the read bytes are folded into. |
| [out] | out_got | Bytes the stream actually returned. |
Definition at line 450 of file main.c.
References k_mem_win_buf_bytes, mem_crc32_byte(), mem_gen_byte(), ra8_vmem_stream_read(), and s_win_buf.
Referenced by mem_vmem_read_windows().
|
static |
Synthetic tile decoder: stamps the key column into the cell.
Definition at line 348 of file main.c.
References k_mem_tile_dim, k_ra8_ok, memset(), and ra8_tile_key_t::tile_x.
Referenced by mem_run_tiles().
|
static |
Fetch (get + immediately put) tile column tx, so it is unpinned.
Definition at line 364 of file main.c.
References k_ra8_ok, ra8_tile_t::pixels, ra8_tile_cache_get(), ra8_tile_cache_put(), and ra8_tile_key_t::tile_x.
Referenced by mem_run_tiles().
|
static |
Read every window and confirm the stream returned the expected lengths.
| [in] | st | Bound vmem stream. |
| [in,out] | crc | Running CRC-32 the read bytes are folded into. |
Definition at line 473 of file main.c.
References k_mem_vmem_obj_bytes, k_mem_win0_len, k_mem_win0_off, k_mem_win1_len, k_mem_win1_off, k_mem_win2_len, k_mem_win2_off, k_mem_win_eof_back, k_mem_win_eof_len, k_mem_win_past_len, and mem_stream_window().
Referenced by mem_run_vmem().
|
static |
|
static |
|
static |
|
static |
Definition at line 182 of file main.c.
Referenced by mem_setup_or_halt().
|
static |
|
static |
|
static |
|
static |
|
static |
Definition at line 189 of file main.c.
Referenced by ez_print_banner(), and main().
|
static |
|
static |
|
static |
|
static |
|
static |
Tile-cache decoded-pixel cells.
Definition at line 158 of file main.c.
Referenced by mem_run_tiles().
|
static |
Tile-cache per-cell dimension descriptors.
Definition at line 162 of file main.c.
Referenced by mem_run_tiles().
|
static |
Tile-cache per-cell key storage.
Definition at line 160 of file main.c.
Referenced by mem_run_tiles().
|
static |
Tile-cache per-cell link metadata.
Definition at line 164 of file main.c.
Referenced by mem_run_tiles().
|
static |
|
static |
Page-cache per-frame key storage.
Definition at line 173 of file main.c.
Referenced by mem_run_vmem().
|
static |
|
static |
Page-cache frame storage (2 KiB resident).
Definition at line 169 of file main.c.
Referenced by mem_run_vmem().
|
static |
|
static |
Stream read scratch (>= the widest window).
Definition at line 179 of file main.c.
Referenced by mem_stream_window().