mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-15 09:36:35 +00:00
thermosphere: handle stage2 data aborts, trap gicd accesses
This commit is contained in:
parent
1775d59977
commit
f9ec21e99e
6 changed files with 116 additions and 3 deletions
61
thermosphere/src/data_abort.c
Normal file
61
thermosphere/src/data_abort.c
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "data_abort.h"
|
||||||
|
#include "sysreg.h"
|
||||||
|
#include "debug_log.h"
|
||||||
|
#include "irq.h"
|
||||||
|
|
||||||
|
// Lower el
|
||||||
|
|
||||||
|
void dumpUnhandledDataAbort(DataAbortIss dabtIss, u64 far, const char *msg)
|
||||||
|
{
|
||||||
|
DEBUG("Unhandled");
|
||||||
|
DEBUG(" %s ", msg);
|
||||||
|
DEBUG("%s at ", dabtIss.wnr ? "write" : "read");
|
||||||
|
if (dabtIss.fnv) {
|
||||||
|
DEBUG("<unk>");
|
||||||
|
} else {
|
||||||
|
DEBUG("%016llx", far);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dabtIss.isv) {
|
||||||
|
DEBUG(" size %u Rt=%u", BIT(dabtIss.sas), dabtIss.srt);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleLowerElDataAbortException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
||||||
|
{
|
||||||
|
DataAbortIss dabtIss;
|
||||||
|
memcpy(&dabtIss, &esr, 4);
|
||||||
|
|
||||||
|
u64 far = GET_SYSREG(far_el2);
|
||||||
|
|
||||||
|
if (!dabtIss.isv || dabtIss.fnv) {
|
||||||
|
dumpUnhandledDataAbort(dabtIss, far, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
if ((far & ~0xFFFull) == (uintptr_t)g_irqManager.gic.gicd) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
dumpUnhandledDataAbort(dabtIss, far, "(fallback)");
|
||||||
|
}
|
42
thermosphere/src/data_abort.h
Normal file
42
thermosphere/src/data_abort.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "exceptions.h"
|
||||||
|
|
||||||
|
typedef struct DataAbortIss {
|
||||||
|
u32 dfsc : 6; // Fault status code
|
||||||
|
|
||||||
|
u32 wnr : 1; // Write, not Read
|
||||||
|
u32 s1ptw : 1; // Stage1 page table walk fault
|
||||||
|
u32 cm : 1; // Cache maintenance
|
||||||
|
u32 ea : 1; // External abort
|
||||||
|
u32 fnv : 1; // FAR not Valid
|
||||||
|
u32 set : 2; // Synchronous error type
|
||||||
|
u32 vncr : 1; // vncr_el2 trap
|
||||||
|
|
||||||
|
u32 ar : 1; // Acquire/release. Bit 14
|
||||||
|
u32 sf : 1; // 64-bit register used
|
||||||
|
u32 srt : 1; // Syndrome register transfer (register used)
|
||||||
|
u32 sse : 1; // Syndrome sign extend
|
||||||
|
u32 sas : 2; // Syndrome access size. Bit 23
|
||||||
|
|
||||||
|
u32 isv : 1; // Instruction syndrome valid (ISS[23:14] valid)
|
||||||
|
} DataAbortIss;
|
||||||
|
|
||||||
|
void dumpUnhandledDataAbort(DataAbortIss dabtIss, u64 far, const char *msg);
|
||||||
|
void handleLowerElDataAbortException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr);
|
|
@ -20,6 +20,7 @@
|
||||||
#include "smc.h"
|
#include "smc.h"
|
||||||
#include "core_ctx.h"
|
#include "core_ctx.h"
|
||||||
#include "single_step.h"
|
#include "single_step.h"
|
||||||
|
#include "data_abort.h"
|
||||||
|
|
||||||
#include "debug_log.h"
|
#include "debug_log.h"
|
||||||
|
|
||||||
|
@ -110,7 +111,10 @@ void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeReg
|
||||||
case Exception_SystemRegisterTrap:
|
case Exception_SystemRegisterTrap:
|
||||||
handleMsrMrsTrap(frame, esr);
|
handleMsrMrsTrap(frame, esr);
|
||||||
break;
|
break;
|
||||||
|
case Exception_DataAbortLowerEl:
|
||||||
|
// Basically, stage2 translation faults
|
||||||
|
handleLowerElDataAbortException(frame, esr);
|
||||||
|
break;
|
||||||
case Exception_SoftwareStepLowerEl:
|
case Exception_SoftwareStepLowerEl:
|
||||||
handleSingleStep(frame, esr);
|
handleSingleStep(frame, esr);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -105,3 +105,7 @@ static inline void spsrSetT32ItFlags(u64 *spsr, u32 itFlags)
|
||||||
bool spsrEvaluateConditionCode(u64 spsr, u32 conditionCode);
|
bool spsrEvaluateConditionCode(u64 spsr, u32 conditionCode);
|
||||||
void skipFaultingInstruction(ExceptionStackFrame *frame, u32 size);
|
void skipFaultingInstruction(ExceptionStackFrame *frame, u32 size);
|
||||||
void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl);
|
void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl);
|
||||||
|
|
||||||
|
void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr);
|
||||||
|
void handleSameElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr);
|
||||||
|
void handleUnknownException(u32 offset);
|
||||||
|
|
|
@ -72,7 +72,8 @@ uintptr_t configureStage2MemoryMap(u32 *addrSpaceSize)
|
||||||
|
|
||||||
identityMapL3(g_vttbl_l3_0, 0x08000000ull, BITL(21), unchanged);
|
identityMapL3(g_vttbl_l3_0, 0x08000000ull, BITL(21), unchanged);
|
||||||
|
|
||||||
// GICv2 CPU -> vCPU interface
|
// GICD -> trapped, GICv2 CPU -> vCPU interface
|
||||||
|
mmu_unmap_range(3, g_vttbl_l3_0, 0x08000000, 0x10000ull);
|
||||||
mmu_map_page_range(g_vttbl_l3_0, 0x08010000ull, 0x08040000ull, 0x10000ull, devattrs);
|
mmu_map_page_range(g_vttbl_l3_0, 0x08010000ull, 0x08040000ull, 0x10000ull, devattrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ uintptr_t configureStage2MemoryMap(u32 *addrSpaceSize)
|
||||||
|
|
||||||
identityMapL3(g_vttbl_l3_0, 0x00000000ull, BITL(21), unchanged);
|
identityMapL3(g_vttbl_l3_0, 0x00000000ull, BITL(21), unchanged);
|
||||||
|
|
||||||
// GICv2 CPU -> vCPU interface
|
// GICD -> trapped, GICv2 CPU -> vCPU interface
|
||||||
|
mmu_unmap_page(g_vttbl_l3_0, 0x50401000ull);
|
||||||
mmu_map_page_range(g_vttbl_l3_0, 0x50042000ull, 0x50046000ull, 0x2000ull, devattrs);
|
mmu_map_page_range(g_vttbl_l3_0, 0x50042000ull, 0x50046000ull, 0x2000ull, devattrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue