|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Cortex-M85 / RA8D2/RA8P1 core bring-up (called from Reset_Handler). More...
#include <stdint.h>#include "ra8_attributes.h"#include "ra8_boot_entry.h"#include "ra8_boot_intrinsics.h"#include "ra8_cache.h"#include "trustzone_init.h"Go to the source code of this file.
Functions | |
| static void | internal_set_vtor (void) |
| Point VTOR at the physical vector table base. | |
| static void | internal_enable_fpu (void) |
| Grant full access to CP10 / CP11 (the FPU coprocessors). | |
| static void | internal_enable_fpu_lazy_stack (void) |
| Turn on FPU lazy stacking (FPCCR.LSPEN = 1, ASPEN = 1). | |
| static void | internal_enable_icache (void) |
| Invalidate and enable the Cortex-M85 I-cache. | |
| static void | internal_enable_dcache (void) |
| Invalidate and enable the Cortex-M85 D-cache. | |
| static void | internal_enable_branch_predictor (void) |
| Enable branch-target prediction (CCR.BP on Cortex-M85). | |
| static void | internal_enable_fault_handlers (void) |
| Enable the configurable-fault handlers so faults decode by class. | |
| static void | internal_enable_div0_trap (void) |
| Make integer divide-by-zero trap as a decoded UsageFault. | |
| static void | internal_set_priority_grouping (void) |
| Set NVIC priority grouping to 4 preempt bits / 0 sub-priority. | |
| static void | internal_mpu_set_region (uint32_t region, uint32_t base_attr, uint32_t limit_enable, uint32_t attr_idx) |
| Program a single MPU region via RNR/RBAR/RLAR. | |
| static void | internal_mpu_init (void) |
| Programme and enable the Cortex-M85 core MPU. | |
| void | SystemInit (void) |
| Earliest C code the image runs: bring the core up before RAM init. | |
Variables | |
| const uint32_t | g_ra8_vector_table_start [] |
| uint32_t | g_ra8_ls_stack_top |
Cortex-M85 / RA8D2/RA8P1 core bring-up (called from Reset_Handler).
SystemInit() follows the CMSIS naming convention and runs as the first C function out of reset, before Reset_Handler copies .data or zeroes .bss. Its responsibilities are strictly CPU-core level – anything peripheral-bus-side belongs in ra8_infrastructure_init() called from main() after the C runtime is live.
The function is C, not naked asm, so stack and BSS must already be usable. Reset_Handler loads SP from the vector table before calling SystemInit(), so the stack is fine; BSS is zeroed only after SystemInit() returns but SystemInit() writes to no BSS or data-section variables, so the ordering is safe.
Definition in file system_init.c.
| anonymous enum : uint32_t |
Programme and enable the Cortex-M85 core MPU.
Installs five regions and enables the MPU with PRIVDEFENA so privileged mode still sees the default memory map for anything not explicitly covered. Activated (with the caches) behind the RA8_BOOT_ENABLE_CACHE_MPU build flag; default OFF leaves the MPU disabled and the boot unchanged.
Attribute indirection table:
Per ARMv8-M PMSAv8: RBAR[4:0] = SH[4:3] | AP[2:1] | XN[0] (permissions); RLAR = LIMIT[31:5] | AttrIndx[3:1] | EN[0], where AttrIndx selects the MAIR byte that sets the region's memory TYPE (cacheable vs Device).
| Enumerator | |
|---|---|
| k_ra8_rbar_attr_ro_x | AP=RO any-priv, SH=none, XN=0 (executable). |
| k_ra8_rbar_attr_rw_xn | AP=RW any-priv, SH=none, XN=1 (no execute). |
| k_ra8_mpu_rlar_enable | RA8 MPU rlar enable. |
Definition at line 393 of file system_init.c.
| anonymous enum : uint32_t |
Definition at line 404 of file system_init.c.
| anonymous enum : uint32_t |
Definition at line 413 of file system_init.c.
| enum ra8_core_addr_t : uintptr_t |
Definition at line 66 of file system_init.c.
|
static |
Enable branch-target prediction (CCR.BP on Cortex-M85).
Sets the architectural branch-prediction enable bit and retires the control-register update with data and instruction barriers.
< RA8 ccr bp.
Definition at line 229 of file system_init.c.
References k_ra8_scb_ccr_addr, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), and ra8_boot_write32().
|
static |
Invalidate and enable the Cortex-M85 D-cache.
Runs the full CCSIDR-driven invalidate-by-set/way pass (ra8_cache_dcache_invalidate_all()) BEFORE setting CCR.DC, so no random power-on line content is ever treated as valid once the cache is enabled. This replaces the earlier "bulk CCR.DC = 1" shortcut, which relied on an unverified boot-ROM guarantee that the lines came up invalid. The function stays gated off (only address-taken in SystemInit) until the coherency substrate – clean-before-DMA and the non-cacheable region – lands; the actual enable is T4-06.
< RA8 ccr dc.
Definition at line 205 of file system_init.c.
References k_ra8_scb_ccr_addr, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), ra8_boot_write32(), and ra8_cache_dcache_invalidate_all().
|
static |
Make integer divide-by-zero trap as a decoded UsageFault.
Out of reset CCR.DIV_0_TRP is 0 and an SDIV/UDIV by zero silently returns 0 – the strongest possible "garbage in, garbage onward" failure mode for control code. Setting the trap makes a zero divisor raise UsageFault with CFSR.DIVBYZERO, which internal_enable_fault_handlers() has already routed to the decoding UsageFault_Handler trampoline, so the faulting PC and the cause land in g_ra8_exception_last instead of propagating a bogus quotient.
CCR.UNALIGN_TRP (bit 3) is deliberately NOT set. Evidence: this tree compiles with arm-none-eabi-gcc's default -munaligned-access (confirmed [enabled] for -mcpu=cortex-m85 via -Q --help=target), under which the compiler is entitled to emit hardware-supported unaligned word accesses – and does, e.g. when expanding the small fixed-size memcpy() idiom the vendored SOUP decoders (miniz via MINIZ_UNALIGNED_USE_MEMCPY, stb) use for byte-buffer reads, and for packed-struct field access. The prebuilt newlib libc is compiled the same way. Trapping unaligned accesses would therefore fault legitimate generated code; it can only ever be enabled together with a whole-tree (and libc) rebuild under -mno-unaligned-access.
< RA8 ccr div 0 trp.
Definition at line 324 of file system_init.c.
References k_ra8_scb_ccr_addr, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), ra8_boot_write32(), and RA8_INTERNAL.
|
static |
Enable the configurable-fault handlers so faults decode by class.
Out of reset SHCSR.{MEM,BUS,USG,SECURE}FAULTENA are 0, so MemManage, BusFault, UsageFault and SecureFault all escalate to HardFault and the per-class exception trampolines (exc 4/5/6/7, which forward into ra8_exception_report) never fire – the real fault class is lost. Set the four enables so each configurable fault is taken by its own handler and reported with its true class. Always-on diagnostics, independent of the cache / MPU build flag.
SECUREFAULTENA (bit 19) scoping decision: the bit is banked and exists only in the Secure view of SHCSR (from the Non-secure state it is RES0, so a misplaced write is architecturally ignored). This shared SystemInit runs out of reset, and the RA8D2 core always resets into the Secure state – flat (non-TrustZone) apps simply never leave it – so the write always lands in the Secure bank. It is enabled unconditionally (no build flag) because every image in this repository carries a decoded SecureFault handler: the shared boot secure_exception.c trampoline, or a per-app secure_exception.c override (all of which decode SFSR). With the bit off, a TrustZone security violation (SG check, attribution mismatch, INVTRAN) halts as an anonymous HardFault; with it on, the same violation reaches SecureFault_Handler and is recorded with its true class + SFSR/SFAR. No non-fault code path changes, so HW-validated apps see identical behaviour until something actually faults.
< RA8 shcsr memfaultena.
< RA8 shcsr busfaultena.
< RA8 shcsr usgfaultena.
< RA8 shcsr securefaultena.
Definition at line 273 of file system_init.c.
References k_ra8_scb_shcsr_addr, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), ra8_boot_write32(), and RA8_INTERNAL.
|
static |
Grant full access to CP10 / CP11 (the FPU coprocessors).
Sets the CPACR access bits then barriers so the FPU is usable before any floating-point instruction executes.
< RA8 cpacr cp10 cp11 full access.
Definition at line 125 of file system_init.c.
References k_ra8_scb_cpacr_addr, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), and ra8_boot_write32().
|
static |
Turn on FPU lazy stacking (FPCCR.LSPEN = 1, ASPEN = 1).
Lets ISRs skip the full FP-state save unless they touch the FPU, reducing worst-case interrupt latency.
< RA8 fpccr lspen.
< RA8 fpccr aspen.
Definition at line 148 of file system_init.c.
References k_ra8_fpu_fpccr_addr, ra8_boot_read32(), and ra8_boot_write32().
|
static |
Invalidate and enable the Cortex-M85 I-cache.
Invalidates all instruction-cache lines before setting CCR.IC and retires the state transition with data and instruction barriers.
< RA8 ccr ic.
Definition at line 170 of file system_init.c.
References k_ra8_scb_ccr_addr, k_ra8_scb_iciallu, ra8_boot_dsb(), ra8_boot_isb(), ra8_boot_read32(), and ra8_boot_write32().
|
static |
Programme and enable the Cortex-M85 core MPU.
Installs code, private SRAM, SDRAM, peripheral, and shared-memory regions with explicit MAIR types before enabling the privileged map.
< RA8 MPU control enable.
< RA8 MPU control privdefena.
< RA8 mair0 default.
Definition at line 464 of file system_init.c.
References internal_mpu_set_region(), k_ra8_mpu_attridx_device, k_ra8_mpu_attridx_noncacheable, k_ra8_mpu_attridx_normal_wbwa, k_ra8_mpu_ctrl_addr, k_ra8_mpu_ctrl_enable, k_ra8_mpu_ctrl_privdefena, k_ra8_mpu_mair0_addr, k_ra8_mpu_mair1_addr, k_ra8_mpu_mram_base, k_ra8_mpu_mram_limit, k_ra8_mpu_peri_base, k_ra8_mpu_peri_limit, k_ra8_mpu_rlar_enable, k_ra8_mpu_sdram_base, k_ra8_mpu_sdram_limit, k_ra8_mpu_shram_base, k_ra8_mpu_shram_limit, k_ra8_mpu_sram_base, k_ra8_mpu_sram_limit, k_ra8_rbar_attr_ro_x, k_ra8_rbar_attr_rw_xn, ra8_boot_dsb(), ra8_boot_isb(), and ra8_boot_write32().
|
static |
Program a single MPU region via RNR/RBAR/RLAR.
attr_idx (written into RLAR AttrIndx, bits[3:1]) selects the region's MAIR byte and therefore its memory type – this is what makes the peripheral region Device-nGnRE rather than Normal cacheable.
| [in] | region | MPU region number to select. |
| [in] | base_attr | Aligned base address combined with RBAR attributes. |
| [in] | limit_enable | Aligned limit combined with RLAR enable. |
| [in] | attr_idx | MAIR attribute index for the region's memory type. |
Definition at line 443 of file system_init.c.
References k_ra8_mpu_rbar_addr, k_ra8_mpu_rlar_addr, k_ra8_mpu_rlar_attridx_shift, k_ra8_mpu_rnr_addr, and ra8_boot_write32().
|
static |
Set NVIC priority grouping to 4 preempt bits / 0 sub-priority.
Writes AIRCR with the VECTKEY and PRIGROUP=3, the standard embedded split (all priority bits are preempt, none sub-priority).
< Required write key.
< PRIGROUP = 3 -> 4 bits.
Definition at line 350 of file system_init.c.
References k_ra8_nvic_aircr, and ra8_boot_write32().
|
static |
Point VTOR at the physical vector table base.
Writes the absolute vector-table address into SCB->VTOR so exceptions dispatch through the linker-pinned table in MRAM.
Definition at line 106 of file system_init.c.
References g_ra8_vector_table_start, k_ra8_scb_vtor_addr, and ra8_boot_write32().
| void SystemInit | ( | void | ) |
Earliest C code the image runs: bring the core up before RAM init.
Called by Reset_Handler before .data is copied and .bss is zeroed, so it must not touch initialised or zero-initialised statics. Each image supplies its own definition – the shared board one under the board boot directories, or an application-local system_init.c where the clock tree or memory map diverges.
The name is the CMSIS convention; the startup code reaches it by that name, which is why it has external linkage.
Definition at line 518 of file system_init.c.
References internal_enable_branch_predictor(), internal_enable_dcache(), internal_enable_div0_trap(), internal_enable_fault_handlers(), internal_enable_fpu(), internal_enable_fpu_lazy_stack(), internal_enable_icache(), internal_mpu_init(), internal_set_priority_grouping(), internal_set_vtor(), ra8_boot_disable_irq(), and ra8_trustzone_init().
|
extern |
|
extern |
Definition at line 294 of file vector_table.c.