From 6c1abfe0476284fc846b82b7337e2c8b1675551f Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Fri, 6 Sep 2019 15:40:20 +0200 Subject: [PATCH] device/arm: add support for System Control Block (SCB) registers and SystemReset() function Signed-off-by: Ron Evans --- src/device/arm/arm.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/device/arm/arm.go b/src/device/arm/arm.go index 3a726f73..1c3d4a64 100644 --- a/src/device/arm/arm.go +++ b/src/device/arm/arm.go @@ -73,8 +73,32 @@ func SVCall4(num uintptr, a1, a2, a3, a4 interface{}) uintptr const ( SCS_BASE = 0xE000E000 NVIC_BASE = SCS_BASE + 0x0100 + SCB_BASE = SCS_BASE + 0x0D00 ) +const ( + SCB_AIRCR_VECTKEY_Pos = 16 + SCB_AIRCR_SYSRESETREQ_Pos = 2 + SCB_AIRCR_SYSRESETREQ_Msk = 1 << SCB_AIRCR_SYSRESETREQ_Pos +) + +// System Control Block (SCB) +// +// SCB_Type provides the definitions for the System Control Block Registers. +type SCB_Type struct { + CPUID volatile.Register32 // CPUID Base Register + ICSR volatile.Register32 // Interrupt Control and State Register + VTOR volatile.Register32 // Vector Table Offset Register + AIRCR volatile.Register32 // Application Interrupt and Reset Control Register + SCR volatile.Register32 // System Control Register + CCR volatile.Register32 // Configuration Control Register + _ volatile.Register32 // RESERVED1; + SHP [2]volatile.Register32 // System Handlers Priority Registers. [0] is RESERVED + SHCSR volatile.Register32 // System Handler Control and State Register +} + +var SCB = (*SCB_Type)(unsafe.Pointer(uintptr(SCB_BASE))) + // Nested Vectored Interrupt Controller (NVIC). // // Source: @@ -134,3 +158,10 @@ func DisableInterrupts() uintptr { func EnableInterrupts(mask uintptr) { Asm("cpsie if") } + +// SystemReset performs a hard system reset. +func SystemReset() { + // SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | + // SCB_AIRCR_SYSRESETREQ_Msk); + SCB.AIRCR.Set((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk) +}