Skip to content

Commit

Permalink
FIXED: Exception reporting from FIQ mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rsta2 committed Nov 8, 2018
1 parent ec20c93 commit 66909aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/circle/exceptionstub.h
Expand Up @@ -2,7 +2,7 @@
// exceptionstub.h
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014-2017 R. Stange <rsta2@o2online.de>
// Copyright (C) 2014-2018 R. Stange <rsta2@o2online.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,6 +47,8 @@ struct TAbortFrame
{
u32 sp_irq;
u32 lr_irq;
u32 sp_fiq;
u32 lr_fiq;
u32 r0;
u32 r1;
u32 r2;
Expand Down
5 changes: 3 additions & 2 deletions lib/debug.cpp
Expand Up @@ -2,7 +2,7 @@
// debug.cpp
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2016 R. Stange <rsta2@o2online.de>
// Copyright (C) 2016-2018 R. Stange <rsta2@o2online.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -80,7 +80,8 @@ void debug_stacktrace (const u32 *pStackPtr, const char *pSource)
extern unsigned char _etext;

if ( *pStackPtr >= MEM_KERNEL_START
&& *pStackPtr < (u32) &_etext)
&& *pStackPtr < (u32) &_etext
&& (*pStackPtr & 3) == 0)
{
CLogger::Get ()->Write (pSource, LogDebug, "stack[%u] is 0x%X", i, (unsigned) *pStackPtr);
}
Expand Down
15 changes: 13 additions & 2 deletions lib/exceptionhandler.cpp
Expand Up @@ -106,12 +106,19 @@ void CExceptionHandler::Throw (unsigned nException, TAbortFrame *pFrame)
u32 lr = pFrame->lr;
u32 sp = pFrame->sp;

if ((pFrame->spsr & 0x1F) == 0x12) // IRQ mode?
switch (pFrame->spsr & 0x1F)
{
case 0x11: // FIQ mode?
lr = pFrame->lr_fiq;
sp = pFrame->sp_fiq;
break;

case 0x12: // IRQ mode?
lr = pFrame->lr_irq;
sp = pFrame->sp_irq;
break;
}

#ifndef NDEBUG
debug_stacktrace ((u32 *) sp, FromExcept);
#endif
Expand All @@ -133,6 +140,10 @@ void ExceptionHandler (u32 nException, TAbortFrame *pFrame)
{
PeripheralExit (); // exit from interrupted peripheral

// if an exception occurs on FIQ_LEVEL, the system would otherwise hang in the next spin lock
CInterruptSystem::DisableFIQ ();
EnableFIQs ();

CExceptionHandler::Get ()->Throw (nException, pFrame);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/exceptionstub.S
Expand Up @@ -35,9 +35,12 @@
cps #0x12 /* set IRQ mode to access sp_irq and lr_irq */
mov r2, sp
mov r3, lr
cps #0x11 /* set FIQ mode to access sp_fiq and lr_fiq */
mov r4, sp
mov r5, lr
cps #0x1F /* our abort handler runs in system mode */
mov sp, r1 /* set sp_sys to stack top of abort stack */
stmfd sp!, {r2, r3} /* store lr_irq and sp_irq onto stack */
stmfd sp!, {r2-r5} /* store lr_fiq, sp_fiq, lr_irq, sp_irq onto stack */
mov r1, sp /* r1: pointer to register frame */
mov r0, #\exception /* r0: exception identifier */
b ExceptionHandler /* jump to ExceptionHandler (never returns) */
Expand Down

0 comments on commit 66909aa

Please sign in to comment.