2019-07-21 23:04:53 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-07-22 22:54:35 +00:00
|
|
|
#include "hvc.h"
|
2019-07-21 23:04:53 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
2019-07-22 22:54:35 +00:00
|
|
|
void dumpStackFrame(const ExceptionStackFrame *frame, bool sameEl)
|
2019-07-21 23:04:53 +00:00
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (u32 i = 0; i < 30; i += 2) {
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("x%u\t\t%08llx\t\tx%u\t\t%08llx\r\n", i, frame->x[i], i + 1, frame->x[i + 1]);
|
2019-07-21 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("x30\t\t%08llx\r\n\r\n", frame->x[30]);
|
|
|
|
serialLog("elr_el2\t\t%08llx\r\n", frame->elr_el2);
|
|
|
|
serialLog("spsr_el2\t%08llx\r\n", frame->spsr_el2);
|
2019-07-21 23:04:53 +00:00
|
|
|
if (sameEl) {
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("sp_el2\t\t%08llx\r\n", frame->sp_el2);
|
2019-07-21 23:04:53 +00:00
|
|
|
} else {
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("sp_el0\t\t%08llx\r\n", frame->sp_el0);
|
2019-07-21 23:04:53 +00:00
|
|
|
}
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("sp_el1\t\t%08llx\r\n", frame->sp_el1);
|
2019-07-21 23:04:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:01:21 +00:00
|
|
|
void handleLowerElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
2019-07-21 23:04:53 +00:00
|
|
|
{
|
2019-07-22 22:54:35 +00:00
|
|
|
|
|
|
|
switch (esr.ec) {
|
|
|
|
case Exception_HypervisorCallA64:
|
|
|
|
case Exception_HypervisorCallA32:
|
|
|
|
handleHypercall(frame, esr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
serialLog("Lower EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\r\n", (u64)esr.ec, esr.il, esr.iss);
|
|
|
|
dumpStackFrame(frame, false);
|
|
|
|
break;
|
|
|
|
}
|
2019-07-21 23:04:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 20:01:21 +00:00
|
|
|
void handleSameElSyncException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
2019-07-21 23:04:53 +00:00
|
|
|
{
|
2019-07-22 20:01:21 +00:00
|
|
|
serialLog("Same EL sync exception, EC = 0x%02llx IL=%llu ISS=0x%06llx\r\n", (u64)esr.ec, esr.il, esr.iss);
|
2019-07-21 23:04:53 +00:00
|
|
|
dumpStackFrame(frame, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleUnknownException(u32 offset)
|
|
|
|
{
|
|
|
|
serialLog("Unknown exception! (offset 0x%03lx)\r\n", offset);
|
2019-07-22 20:01:21 +00:00
|
|
|
}
|