2013-07-19 11:43:04 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
* arch/arm/src/armv7-a/arm_dataabort.c
|
|
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
2021-03-24 09:12:29 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2013-07-19 11:43:04 -06:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
|
|
2014-08-08 17:53:55 -06:00
|
|
|
#include "sched/sched.h"
|
2020-04-30 19:20:29 -06:00
|
|
|
#include "arm_internal.h"
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING
|
|
|
|
|
# include <nuttx/page.h>
|
|
|
|
|
# include "arm.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: arm_dataabort
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Input Parameters:
|
2013-07-19 11:43:04 -06:00
|
|
|
* regs - The standard, ARM register save array.
|
|
|
|
|
*
|
|
|
|
|
* If CONFIG_PAGING is selected in the NuttX configuration file, then these
|
|
|
|
|
* additional input values are expected:
|
|
|
|
|
*
|
2013-07-20 13:06:00 -06:00
|
|
|
* dfar - Fault address register. On a data abort, the ARM MMU places the
|
2021-03-24 09:12:51 +01:00
|
|
|
* miss virtual address (MVA) into the DFAR register. This is the
|
|
|
|
|
* address of the data which, when accessed, caused the fault.
|
2013-07-20 13:06:00 -06:00
|
|
|
* dfsr - Fault status register. On a data a abort, the ARM MMU places an
|
2013-07-19 11:43:04 -06:00
|
|
|
* encoded four-bit value, the fault status, along with the four-bit
|
2013-07-20 13:06:00 -06:00
|
|
|
* encoded domain number, in the data DFSR
|
2013-07-19 11:43:04 -06:00
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* This is the data abort exception handler. The ARM data abort exception
|
|
|
|
|
* occurs when a memory fault is detected during a data transfer.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PAGING
|
2013-07-24 07:47:51 -06:00
|
|
|
uint32_t *arm_dataabort(uint32_t *regs, uint32_t dfar, uint32_t dfsr)
|
2013-07-19 11:43:04 -06:00
|
|
|
{
|
2016-02-06 13:41:28 -06:00
|
|
|
struct tcb_s *tcb = this_task();
|
2013-07-19 11:43:04 -06:00
|
|
|
uint32_t *savestate;
|
|
|
|
|
|
2021-03-24 09:12:51 +01:00
|
|
|
/* Save the saved processor context in CURRENT_REGS where it can be
|
|
|
|
|
* accessed for register dumps and possibly context switching.
|
2013-07-19 11:43:04 -06:00
|
|
|
*/
|
|
|
|
|
|
2016-03-09 13:41:48 -06:00
|
|
|
savestate = (uint32_t *)CURRENT_REGS;
|
|
|
|
|
CURRENT_REGS = regs;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* In the NuttX on-demand paging implementation, only the read-only, .text
|
|
|
|
|
* section is paged. However, the ARM compiler generated PC-relative data
|
|
|
|
|
* fetches from within the .text sections. Also, it is customary to locate
|
|
|
|
|
* read-only data (.rodata) within the same section as .text so that it
|
|
|
|
|
* does not require copying to RAM. Misses in either of these case should
|
|
|
|
|
* cause a data abort.
|
|
|
|
|
*
|
|
|
|
|
* We are only interested in data aborts due to page translations faults.
|
|
|
|
|
* Sections should already be in place and permissions should already be
|
|
|
|
|
* be set correctly (to read-only) so any other data abort reason is a
|
|
|
|
|
* fatal error.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-20 11:59:15 -06:00
|
|
|
pginfo("DFSR: %08x DFAR: %08x\n", dfsr, dfar);
|
2013-07-20 13:06:00 -06:00
|
|
|
if ((dfsr & FSR_MASK) != FSR_PAGE)
|
2013-07-19 11:43:04 -06:00
|
|
|
{
|
|
|
|
|
goto segfault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check the (virtual) address of data that caused the data abort. When
|
2013-07-20 13:06:00 -06:00
|
|
|
* the exception occurred, this address was provided in the DFAR register.
|
2013-07-19 11:43:04 -06:00
|
|
|
* (It has not yet been saved in the register context save area).
|
|
|
|
|
*/
|
2014-04-13 16:22:22 -06:00
|
|
|
|
2016-06-20 11:59:15 -06:00
|
|
|
pginfo("VBASE: %08x VEND: %08x\n", PG_PAGED_VBASE, PG_PAGED_VEND);
|
2013-07-20 13:06:00 -06:00
|
|
|
if (dfar < PG_PAGED_VBASE || dfar >= PG_PAGED_VEND)
|
2013-07-19 11:43:04 -06:00
|
|
|
{
|
|
|
|
|
goto segfault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Save the offending data address as the fault address in the TCB of
|
|
|
|
|
* the currently task. This fault address is also used by the prefetch
|
|
|
|
|
* abort handling; this will allow common paging logic for both
|
|
|
|
|
* prefetch and data aborts.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-07-20 13:06:00 -06:00
|
|
|
tcb->xcp.dfar = regs[REG_R15];
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
/* Call pg_miss() to schedule the page fill. A consequences of this
|
|
|
|
|
* call are:
|
|
|
|
|
*
|
|
|
|
|
* (1) The currently executing task will be blocked and saved on
|
|
|
|
|
* on the g_waitingforfill task list.
|
|
|
|
|
* (2) An interrupt-level context switch will occur so that when
|
|
|
|
|
* this function returns, it will return to a different task,
|
|
|
|
|
* most likely the page fill worker thread.
|
|
|
|
|
* (3) The page fill worker task has been signalled and should
|
|
|
|
|
* execute immediately when we return from this exception.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
pg_miss();
|
|
|
|
|
|
2016-03-09 13:41:48 -06:00
|
|
|
/* Restore the previous value of CURRENT_REGS. NULL would indicate that
|
2013-07-19 11:43:04 -06:00
|
|
|
* we are no longer in an interrupt handler. It will be non-NULL if we
|
|
|
|
|
* are returning from a nested interrupt.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-09 13:41:48 -06:00
|
|
|
CURRENT_REGS = savestate;
|
2013-07-24 07:47:51 -06:00
|
|
|
return regs;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
|
|
|
|
segfault:
|
2016-06-16 12:38:05 -06:00
|
|
|
_alert("Data abort. PC: %08x DFAR: %08x DFSR: %08x\n",
|
2013-07-20 13:06:00 -06:00
|
|
|
regs[REG_PC], dfar, dfsr);
|
2023-04-10 21:19:12 +08:00
|
|
|
PANIC_WITH_REGS("panic", regs);
|
2013-07-24 07:47:51 -06:00
|
|
|
return regs; /* To keep the compiler happy */
|
2013-07-19 11:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* CONFIG_PAGING */
|
|
|
|
|
|
2013-07-24 07:47:51 -06:00
|
|
|
uint32_t *arm_dataabort(uint32_t *regs, uint32_t dfar, uint32_t dfsr)
|
2013-07-19 11:43:04 -06:00
|
|
|
{
|
2021-03-24 09:12:51 +01:00
|
|
|
/* Save the saved processor context in CURRENT_REGS where it can be
|
|
|
|
|
* accessed for register dumps and possibly context switching.
|
2013-07-19 11:43:04 -06:00
|
|
|
*/
|
|
|
|
|
|
2016-03-09 13:41:48 -06:00
|
|
|
CURRENT_REGS = regs;
|
2013-07-19 11:43:04 -06:00
|
|
|
|
2013-07-20 13:06:00 -06:00
|
|
|
/* Crash -- possibly showing diagnostic debug information. */
|
2013-07-19 11:43:04 -06:00
|
|
|
|
2016-06-16 12:38:05 -06:00
|
|
|
_alert("Data abort. PC: %08x DFAR: %08x DFSR: %08x\n",
|
2013-07-20 13:06:00 -06:00
|
|
|
regs[REG_PC], dfar, dfsr);
|
2023-04-10 21:19:12 +08:00
|
|
|
PANIC_WITH_REGS("panic", regs);
|
2013-07-24 07:47:51 -06:00
|
|
|
return regs; /* To keep the compiler happy */
|
2013-07-19 11:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_PAGING */
|