2016-04-26 22:06:19 +02:00
|
|
|
/*
|
2016-07-05 16:24:00 +02:00
|
|
|
* This file is part of Luma3DS
|
2019-02-25 02:04:32 +01:00
|
|
|
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
2016-04-26 22:06:19 +02:00
|
|
|
*
|
2016-07-05 16:24:00 +02:00
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that 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/>.
|
|
|
|
*
|
2017-06-05 02:02:04 +02:00
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
* reasonable ways as different from the original version.
|
2016-04-26 22:06:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "handlers.h"
|
|
|
|
|
|
|
|
#define FINAL_BUFFER 0x25000000
|
2016-05-06 15:45:25 +02:00
|
|
|
|
2016-08-30 02:03:56 +02:00
|
|
|
#define REG_DUMP_SIZE 4 * 17
|
2016-05-06 15:45:25 +02:00
|
|
|
#define CODE_DUMP_SIZE 48
|
2016-04-26 22:06:19 +02:00
|
|
|
|
2018-01-04 18:40:11 +01:00
|
|
|
void __attribute__((noreturn)) mainHandler(u32 *registerDump, u32 type)
|
2016-04-26 22:06:19 +02:00
|
|
|
{
|
2016-06-08 21:44:04 +02:00
|
|
|
ExceptionDumpHeader dumpHeader;
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
u8 codeDump[CODE_DUMP_SIZE];
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
dumpHeader.magic[0] = 0xDEADC0DE;
|
|
|
|
dumpHeader.magic[1] = 0xDEADCAFE;
|
|
|
|
dumpHeader.versionMajor = 1;
|
2016-08-12 15:17:19 +02:00
|
|
|
dumpHeader.versionMinor = 2;
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
dumpHeader.processor = 9;
|
|
|
|
dumpHeader.core = 0;
|
|
|
|
dumpHeader.type = type;
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
dumpHeader.registerDumpSize = REG_DUMP_SIZE;
|
|
|
|
dumpHeader.codeDumpSize = CODE_DUMP_SIZE;
|
|
|
|
dumpHeader.additionalDataSize = 0;
|
2016-04-26 22:06:19 +02:00
|
|
|
|
2018-01-04 18:40:11 +01:00
|
|
|
u32 cpsr = registerDump[16];
|
|
|
|
u32 pc = registerDump[15] - (type < 3 ? (((cpsr & 0x20) != 0 && type == 1) ? 2 : 4) : 8);
|
2016-04-26 22:06:19 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
registerDump[15] = pc;
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-04-26 22:06:19 +02:00
|
|
|
//Dump code
|
2018-01-04 18:40:11 +01:00
|
|
|
u8 *instr = (u8 *)pc + ((cpsr & 0x20) ? 2 : 4) - dumpHeader.codeDumpSize; //wouldn't work well on 32-bit Thumb instructions, but it isn't much of a problem
|
|
|
|
dumpHeader.codeDumpSize = ((u32)instr & (((cpsr & 0x20) != 0) ? 1 : 3)) != 0 ? 0 : safecpy(codeDump, instr, dumpHeader.codeDumpSize);
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2018-01-04 18:40:11 +01:00
|
|
|
//Copy register dump and code dump
|
2016-08-12 15:17:19 +02:00
|
|
|
u8 *final = (u8 *)(FINAL_BUFFER + sizeof(ExceptionDumpHeader));
|
2018-01-04 18:40:11 +01:00
|
|
|
final += safecpy(final, registerDump, dumpHeader.registerDumpSize);
|
|
|
|
final += safecpy(final, codeDump, dumpHeader.codeDumpSize);
|
2016-09-06 13:43:00 +02:00
|
|
|
|
2016-06-08 21:44:04 +02:00
|
|
|
//Dump stack in place
|
2018-01-04 18:40:11 +01:00
|
|
|
dumpHeader.stackDumpSize = safecpy(final, (const void *)registerDump[13], 0x1000 - (registerDump[13] & 0xFFF));
|
2016-08-12 15:17:19 +02:00
|
|
|
|
|
|
|
dumpHeader.totalSize = sizeof(ExceptionDumpHeader) + dumpHeader.registerDumpSize + dumpHeader.codeDumpSize + dumpHeader.stackDumpSize + dumpHeader.additionalDataSize;
|
2016-09-06 19:17:45 +02:00
|
|
|
|
|
|
|
//Copy header (actually optimized by the compiler)
|
|
|
|
*(ExceptionDumpHeader *)FINAL_BUFFER = dumpHeader;
|
2016-04-26 22:06:19 +02:00
|
|
|
|
2017-09-07 05:24:43 +02:00
|
|
|
if(ARESCREENSINITIALIZED) i2cWriteRegister(I2C_DEV_MCU, 0x22, 1 << 0); //Shutdown LCD
|
2017-08-28 02:40:05 +02:00
|
|
|
|
2016-06-11 00:00:53 +02:00
|
|
|
((void (*)())0xFFFF0830)(); //Ensure that all memory transfers have completed and that the data cache has been flushed
|
2017-08-28 02:40:05 +02:00
|
|
|
|
2016-10-16 23:34:26 +02:00
|
|
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); //Reboot
|
2016-08-12 15:17:19 +02:00
|
|
|
while(true);
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|