HelenOS sources
This source file includes following definitions.
- dfsr_source_to_str
- get_memory_access_type
- data_abort
- prefetch_abort
#include <panic.h>
#include <arch/cp15.h>
#include <arch/exception.h>
#include <arch/mm/page_fault.h>
#include <mm/as.h>
#include <genarch/mm/page_pt.h>
#include <arch.h>
#include <interrupt.h>
typedef enum {
DFSR_SOURCE_ALIGN = 0x0001,
DFSR_SOURCE_CACHE_MAINTENANCE = 0x0004,
DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L1 = 0x000c,
DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L2 = 0x000e,
DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L1 = 0x040c,
DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L2 = 0x040e,
DFSR_SOURCE_TRANSLATION_L1 = 0x0005,
DFSR_SOURCE_TRANSLATION_L2 = 0x0007,
DFSR_SOURCE_ACCESS_FLAG_L1 = 0x0003,
DFSR_SOURCE_ACCESS_FLAG_L2 = 0x0006,
DFSR_SOURCE_DOMAIN_L1 = 0x0009,
DFSR_SOURCE_DOMAIN_L2 = 0x000b,
DFSR_SOURCE_PERMISSION_L1 = 0x000d,
DFSR_SOURCE_PERMISSION_L2 = 0x000f,
DFSR_SOURCE_DEBUG = 0x0002,
DFSR_SOURCE_SYNC_EXTERNAL = 0x0008,
DFSR_SOURCE_TLB_CONFLICT = 0x0400,
DFSR_SOURCE_LOCKDOWN = 0x0404,
DFSR_SOURCE_COPROCESSOR = 0x040a,
DFSR_SOURCE_SYNC_PARITY = 0x0409,
DFSR_SOURCE_ASYNC_EXTERNAL = 0x0406,
DFSR_SOURCE_ASYNC_PARITY = 0x0408,
DFSR_SOURCE_MASK = 0x0000040f,
} dfsr_source_t;
static inline const char *dfsr_source_to_str(dfsr_source_t source)
{
switch (source) {
case DFSR_SOURCE_TRANSLATION_L1:
return "Translation fault L1";
case DFSR_SOURCE_TRANSLATION_L2:
return "Translation fault L2";
case DFSR_SOURCE_PERMISSION_L1:
return "Permission fault L1";
case DFSR_SOURCE_PERMISSION_L2:
return "Permission fault L2";
case DFSR_SOURCE_ALIGN:
return "Alignment fault";
case DFSR_SOURCE_CACHE_MAINTENANCE:
return "Instruction cache maintenance fault";
case DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L1:
return "Synchronous external abort on translation table walk level 1";
case DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L2:
return "Synchronous external abort on translation table walk level 2";
case DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L1:
return "Synchronous parity error on translation table walk level 1";
case DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L2:
return "Synchronous parity error on translation table walk level 2";
case DFSR_SOURCE_ACCESS_FLAG_L1:
return "Access flag fault L1";
case DFSR_SOURCE_ACCESS_FLAG_L2:
return "Access flag fault L2";
case DFSR_SOURCE_DOMAIN_L1:
return "Domain fault L1";
case DFSR_SOURCE_DOMAIN_L2:
return "Domain flault L2";
case DFSR_SOURCE_DEBUG:
return "Debug event";
case DFSR_SOURCE_SYNC_EXTERNAL:
return "Synchronous external abort";
case DFSR_SOURCE_TLB_CONFLICT:
return "TLB conflict abort";
case DFSR_SOURCE_LOCKDOWN:
return "Lockdown (Implementation defined)";
case DFSR_SOURCE_COPROCESSOR:
return "Coprocessor abort (Implementation defined)";
case DFSR_SOURCE_SYNC_PARITY:
return "Synchronous parity error on memory access";
case DFSR_SOURCE_ASYNC_EXTERNAL:
return "Asynchronous external abort";
case DFSR_SOURCE_ASYNC_PARITY:
return "Asynchronous parity error on memory access";
case DFSR_SOURCE_MASK:
break;
}
return "Unknown data abort";
}
#if defined(PROCESSOR_ARCH_armv4) | defined(PROCESSOR_ARCH_armv5)
static pf_access_t get_memory_access_type(uint32_t instr_addr,
uintptr_t badvaddr)
{
instruction_union_t instr_union;
instr_union.pc = instr_addr;
instruction_t instr = *(instr_union.instr);
if (instr.condition == 0xf) {
panic("page_fault - instruction does not access memory "
"(instr_code: %#0" PRIx32 ", badvaddr:%p).",
*(uint32_t *)instr_union.instr, (void *) badvaddr);
return PF_ACCESS_EXEC;
}
static const struct {
uint32_t mask;
uint32_t value;
pf_access_t access;
} ls_inst[] = {
{ 0x0e100000, 0x04000000, PF_ACCESS_WRITE },
{ 0x0e100010, 0x06000000, PF_ACCESS_WRITE },
{ 0x0e100000, 0x04100000, PF_ACCESS_READ },
{ 0x0e100010, 0x06100000, PF_ACCESS_READ },
{ 0x0e1000b0, 0x000000b0, PF_ACCESS_WRITE },
{ 0x0e0000f0, 0x000000d0, PF_ACCESS_READ },
{ 0x0e1000b0, 0x001000b0, PF_ACCESS_READ },
{ 0x0e100000, 0x08000000, PF_ACCESS_WRITE },
{ 0x0e100000, 0x08100000, PF_ACCESS_READ },
{ 0x0fb00000, 0x01000000, PF_ACCESS_WRITE },
};
const uint32_t inst = *(uint32_t *)instr_addr;
for (unsigned i = 0; i < sizeof(ls_inst) / sizeof(ls_inst[0]); ++i) {
if ((inst & ls_inst[i].mask) == ls_inst[i].value) {
return ls_inst[i].access;
}
}
panic("page_fault - instruction doesn't access memory "
"(instr_code: %#0" PRIx32 ", badvaddr:%p).",
inst, (void *) badvaddr);
}
#endif
void data_abort(unsigned int exc_no, istate_t *istate)
{
const uintptr_t badvaddr = DFAR_read();
const fault_status_t fsr = { .raw = DFSR_read() };
const dfsr_source_t source = fsr.raw & DFSR_SOURCE_MASK;
switch (source) {
case DFSR_SOURCE_TRANSLATION_L1:
case DFSR_SOURCE_TRANSLATION_L2:
case DFSR_SOURCE_PERMISSION_L1:
case DFSR_SOURCE_PERMISSION_L2:
break;
case DFSR_SOURCE_ALIGN:
case DFSR_SOURCE_CACHE_MAINTENANCE:
case DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L1:
case DFSR_SOURCE_SYNC_EXTERNAL_TRANSLATION_L2:
case DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L1:
case DFSR_SOURCE_SYNC_PARITY_TRANSLATION_L2:
case DFSR_SOURCE_ACCESS_FLAG_L1:
case DFSR_SOURCE_ACCESS_FLAG_L2:
case DFSR_SOURCE_DOMAIN_L1:
case DFSR_SOURCE_DOMAIN_L2:
case DFSR_SOURCE_DEBUG:
case DFSR_SOURCE_SYNC_EXTERNAL:
case DFSR_SOURCE_TLB_CONFLICT:
case DFSR_SOURCE_LOCKDOWN:
case DFSR_SOURCE_COPROCESSOR:
case DFSR_SOURCE_SYNC_PARITY:
case DFSR_SOURCE_ASYNC_EXTERNAL:
case DFSR_SOURCE_ASYNC_PARITY:
case DFSR_SOURCE_MASK:
fault_if_from_uspace(istate, "Unhandled abort %s at address: "
"%#x.", dfsr_source_to_str(source), badvaddr);
panic("Unhandled abort %s at address: %#x.",
dfsr_source_to_str(source), badvaddr);
}
#if defined(PROCESSOR_ARCH_armv6) | defined(PROCESSOR_ARCH_armv7_a)
const pf_access_t access =
fsr.data.wr ? PF_ACCESS_WRITE : PF_ACCESS_READ;
#elif defined(PROCESSOR_ARCH_armv4) | defined(PROCESSOR_ARCH_armv5)
const pf_access_t access = get_memory_access_type(istate->pc, badvaddr);
#else
#error "Unsupported architecture"
#endif
as_page_fault(badvaddr, access, istate);
}
void prefetch_abort(unsigned int exc_no, istate_t *istate)
{
as_page_fault(istate->pc, PF_ACCESS_EXEC, istate);
}
HelenOS homepage, sources at GitHub