|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Prove CCR.DIV_0_TRP: a zero divisor must raise a decoded UsageFault. More...
#include <stddef.h>#include <stdint.h>#include "ra8_attributes.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_log.h"#include "ra8_mstp.h"Go to the source code of this file.
Enumerations | |
| enum | fd_consts_t : uint32_t { k_fd_uart_baud = 115200U , k_fd_dividend = 100U , k_fd_divisor = 0U } |
| Console + divide-test knobs (no magic numbers). More... | |
| enum | fd_scb_addr_t : uintptr_t { k_fd_scb_ccr_addr = 0xE000ED14UL } |
| ARMv8-M SCB register addresses this app reads. More... | |
| enum | fd_ccr_bits_t : uint32_t { k_fd_ccr_div_0_trp = 1UL << 4 } |
| CCR bits checked by the arming probe. More... | |
Functions | |
| static void | internal_print (const uint8_t *msg, uint32_t len) |
| Emit a byte run on the SCI8 console. | |
| static void | internal_log_sink (void *ctx, uint8_t byte) |
| ra8_log byte sink: forward every log byte to the SCI8 console. | |
| static void | internal_panic_halt (const uint8_t *msg, uint32_t len) |
| Print the fail banner and trap (ra8_emulator halts on the BKPT). | |
| static void | internal_print_uint (uint32_t value) |
| Print a small unsigned integer in decimal (quotient display). | |
| static void | internal_setup_or_halt (void) |
| Bring up clocks / MSTP + the SCI8 console; halt on failure. | |
| void | main (void) |
| The application entry point Reset_Handler hands control to. | |
Variables | |
| static const uint8_t | s_msg_boot [] = "fault-div0: boot\r\n" |
| static const uint8_t | s_msg_fail [] = "fault-div0: FAIL init\r\n" |
| static const uint8_t | s_msg_armed [] = "fault-div0: trap armed\r\n" |
| static const uint8_t | s_msg_unarmed [] = "fault-div0: FAIL trap not armed\r\n" |
| static const uint8_t | s_msg_survived [] = "fault-div0: survived divide quotient=" |
| static const uint8_t | s_msg_emu_tail [] = " (trap not modelled -- ra8_emulator)\r\n" |
| static volatile uint32_t | s_fd_dividend = (uint32_t)k_fd_dividend |
| Volatile numerator so the divide executes at run time. | |
| static volatile uint32_t | s_fd_divisor = (uint32_t)k_fd_divisor |
| Volatile zero divisor – the UDIV of this value must trap. | |
| volatile uint32_t | g_fd_quotient = 0U |
| Quotient observed when the trap did NOT fire (emulator survival path). | |
| volatile uint32_t | g_fd_heartbeat = 0U |
| Bumps forever in the survival idle loop – liveness for probes. | |
Prove CCR.DIV_0_TRP: a zero divisor must raise a decoded UsageFault.
The shared boot (libs/ra8_board_ek_ra8d2/src/boot/system_init.c) sets SHCSR.USGFAULTENA and CCR.DIV_0_TRP, so an integer SDIV/UDIV by zero must no longer silently return 0 – it must raise a UsageFault that the per-app vector table's trampoline forwards into ra8_exception_report(). This app closes the loop on real silicon:
On silicon the divide never completes: the CPU takes UsageFault, the decoded dump prints (exception=6, cfsr =33554432 – that is 0x02000000 = CFSR.DIVBYZERO – plus pc/lr/xpsr), and the handler parks at ra8_exception_halt_loop. The hil.conf gate scrapes that dump.
Definition in file main.c.
| enum fd_ccr_bits_t : uint32_t |
| enum fd_consts_t : uint32_t |
| enum fd_scb_addr_t : uintptr_t |
|
static |
ra8_log byte sink: forward every log byte to the SCI8 console.
The fault path (ra8_exception_report) logs through ra8_log, whose default ITM backend deliberately drops every byte in fault context (IPSR != 0). A registered byte sink bypasses that gate, so routing it at the console makes the decoded dump visible on the bench UART. The console write is polled (no IRQs needed), so it is safe from the fault handler.
| [in] | ctx | Unused opaque cookie (sink ABI). |
| [in] | byte | Log byte to emit. |
Definition at line 160 of file main.c.
References ra8_board_uart_console_write(), and RA8_INTERNAL.
|
static |
Print the fail banner and trap (ra8_emulator halts on the BKPT).
Mirrors the sibling apps' panic idiom: one negative banner the HIL gate can match, then a debugger-visible stop.
| [in] | msg | Banner bytes. |
| [in] | len | Banner length. |
Definition at line 180 of file main.c.
References internal_print(), and RA8_INTERNAL.
|
static |
Emit a byte run on the SCI8 console.
Thin wrapper discarding the write status: console loss is acceptable for a print helper, the HIL gate re-checks output.
| [in] | msg | Bytes to send (not NUL-inspected). |
| [in] | len | Number of bytes. |
Definition at line 134 of file main.c.
References ra8_board_uart_console_write(), and RA8_INTERNAL.
Referenced by internal_panic_halt(), internal_print_uint(), and main().
|
static |
Print a small unsigned integer in decimal (quotient display).
Emits at most 10 digits; 0 prints as "0". Digits are pushed LSB-first into a local buffer, then emitted MSB-first.
| [in] | value | Value to print. |
< Decimal base.
< Max digits in a uint32 (4G).
Definition at line 202 of file main.c.
References internal_print(), and RA8_INTERNAL.
Referenced by main().
|
static |
Bring up clocks / MSTP + the SCI8 console; halt on failure.
Minimal bring-up: CGC, MSTP, console. No timers – the app needs no delays, only one divide.
Definition at line 236 of file main.c.
References internal_panic_halt(), k_fd_uart_baud, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_init(), RA8_INTERNAL, ra8_mstp_init(), and s_msg_fail.
| void main | ( | void | ) |
The application entry point Reset_Handler hands control to.
Returns void, not int. This is a freestanding image: there is no hosted C environment, no process and nothing to report an exit status to. ISO C fixes main at int only for a hosted implementation; for a freestanding one (C23 5.1.2.1) the startup function's name and type are implementation-defined, and this is that definition. Reset_Handler discards no value because there is none to discard, and if main ever does return, startup halts the CPU rather than resuming anything.
The firmware lane is compiled -ffreestanding (see cmake/ra8_add_app.cmake) and the flag and this signature travel together: without it both GCC and clang reject a non-int main (-Wmain / -Wmain-return-type). Do not remove one without the other.
That coupling is why the declaration sits behind __STDC_HOSTED__ == 0, which -ffreestanding sets and a hosted build does not. The guard is not defensive dressing: this header is reachable from host builds (the unit tests compile ra8_core natively), and an unguarded void main(void); makes every hosted translation unit that includes it fail with conflicting types for 'main' against its own ISO int main. The declaration therefore exists exactly where its contract does.
Hosted first-party code – everything under tests/ and tools/ – uses the ISO int main(...) contract instead, because it genuinely does run under an OS that reads the exit status. scripts/checks/check_entry_points.py holds each domain to its own contract (#707).
Declared here, once, for the same reason SystemInit is: every vector_table.c used to restate it as a local extern int32_t main(void);, sixteen copies that no compiler ever compared against the definition – and roughly thirty of them had silently drifted out of agreement with the main they called.
The application entry point Reset_Handler hands control to.
Brings up CGC + BSP audio then plays blocks.
The application entry point Reset_Handler hands control to.
Brings up CGC + GPT triple, runs sweep.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART, then enters ThreadX.
The application entry point Reset_Handler hands control to.
Brings up LED, console, SDHI pins, then ThreadX.
The application entry point Reset_Handler hands control to.
Brings up CGC + USB-FS + UAC1, then enters the iso-IN feed loop forever.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Profiles power modes once a second.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, SPI, and SD card, then runs the shared ra8_io VFS round-trip over the SD-over-SPI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Initialises logging and the console, brings up the OSPI NOR volume, runs the erase-before-write round-trip, and prints a single PASS/FAIL verdict line over SCI8 before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Both USB controllers' clocks and pins come up before the kernel so the workers only deal with stack bring-up.
The application entry point Reset_Handler hands control to.
Brings up logging and the clock tree, releases the Cortex-M33 (which then blinks LED1 via ra8_pcntr_set_output()), and idles. See the file header.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the cacheable-SRAM round-trip with the D-cache that SystemInit() enabled through ra8_cache_dcache_enable(), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU + RA8_BOOT_CACHE_VIA_HAL).
The application entry point Reset_Handler hands control to.
Publishes the mailbox, releases the Cortex-M33 into the emitter, yields until it signals done, validates the blob the M33 built, then logs the PASS/FAIL verdict and the chapter count read back from the blob. See the file header for the offload narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Publishes the mailbox, arms the IPC0 wake and configures the LPM block, releases the Cortex-M33 into the reader, waits for the first held page, logs the page-0 verdict, then runs the #150 mode-switch cycle – parking in low-power WFI and waking on the M33's page-turn pokes – before logging the handoff verdict and parking for good. See the file header for the narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the timebase then measures forever.
The application entry point Reset_Handler hands control to.
Arms the RIIC1 target and polls the dispatcher.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up the LIN commander then drives frames.
The application entry point Reset_Handler hands control to.
Brings up logging, "renders" page 0 into the shared mailbox, releases the Cortex-M33 into its hold loop, and parks the M85 in low-power WFI sleep. See the file header for the power-saving narrative.
The application entry point Reset_Handler hands control to.
The USB clock, pins, console, and the SD card all come up before the kernel so the worker only deals with USB stack bring-up.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (MPU enabled, canonical boot map, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the wear-levelling + power-cycle-survival flow, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Initialises logging + console, brings up the MRAM volume, runs the program/erase round-trip, and prints a single PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then runs the full ra8_io VFS round-trip over the native-SDHI block device. On success it prints the exact PASS banner the HIL runner and ra8_emulator smoke gate scrape for; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
Brings up the console and both stdio sinks, retargets the engine's stdio to the in-RAM capture sink, runs the two-backend swap, replays the RAM capture out of the UART, and prints a single PASS/FAIL verdict per abstraction before parking in an infinite loop.
The application entry point Reset_Handler hands control to.
Brings up the clocks, console, and SDHI bus pins, runs the native SD card identification, fills the payload, then writes + reads + compares one raw 512-byte block straight against ra8_sdcard. On success it prints the exact PASS banner; on any failure it prints FAIL and parks the core.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII + RSIP, then ThreadX.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initializes and arms ADC_B, formats each successful channel sample without variadic I/O, emits the verdict, toggles LED1, and delays.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Brings up logging, releases the Cortex-M33 (which then blinks LED1), and idles. See the file header for the teaching narrative.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
See the file header for the full behaviour summary.
The application entry point Reset_Handler hands control to.
Brings up logging, the clock tree, and the VCOM console, runs the three-step self-test (cacheable SRAM, RO MRAM const, Device MMIO), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI. Every byte the self-test touches runs with the L1 caches and MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU).
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Lights HOCO + PLL, then runs a 1 Hz blink.
The application entry point Reset_Handler hands control to.
See file header for behaviour summary.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Initializes the demo, executes one comparison per period, increments the exported match or mismatch counter, and toggles the matching LED.
The application entry point Reset_Handler hands control to.
Brings up the clock tree, MSTP, ISR/ELC, and the VCOM console, programs a software-triggered DTC block copy, runs it with the L1 caches + MPU enabled by the shared boot (RA8_BOOT_ENABLE_CACHE_MPU), emits the matching PASS / FAIL banner over the console and ra8_log, then parks in WFI.
The application entry point Reset_Handler hands control to.
Brings up logging, zeros the shared control block, releases the Cortex-M33, waits for its boot signature, then yields while the M33 counts autonomously to k_bg_target_count. After the M33 sets done, the M85 reads the counter and logs the PASS/FAIL verdict.
The application entry point Reset_Handler hands control to.
Brings up logging, releases the Cortex-M33, confirms it booted, runs k_m85_demo_rounds narrated mailbox rounds, then drops into the idle heartbeat. See the file header for the teaching narrative.
The application entry point Reset_Handler hands control to.
Fires ELC software events once a second.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
The application entry point Reset_Handler hands control to.
Definition at line 249 of file main.c.
References g_fd_heartbeat, g_fd_quotient, internal_log_sink(), internal_panic_halt(), internal_print(), internal_print_uint(), internal_setup_or_halt(), k_fd_ccr_div_0_trp, k_fd_scb_ccr_addr, ra8_isr_globals_enable(), ra8_log_set_byte_sink(), s_fd_dividend, s_fd_divisor, s_msg_armed, s_msg_boot, s_msg_emu_tail, s_msg_survived, and s_msg_unarmed.
| volatile uint32_t g_fd_heartbeat = 0U |
| volatile uint32_t g_fd_quotient = 0U |
|
static |
Volatile numerator so the divide executes at run time.
Volatile (and file-scope) so the compiler can neither constant-fold the division nor prove the divisor zero and elide / poison the code path.
Definition at line 90 of file main.c.
Referenced by main().
|
static |
Volatile zero divisor – the UDIV of this value must trap.
See s_fd_dividend; same reasoning, opposite operand.
Definition at line 100 of file main.c.
Referenced by main().
|
static |
|
static |
|
static |
|
static |