clang-format

This commit is contained in:
Maschell 2022-02-08 14:44:53 +01:00
parent 8e2a431827
commit 4993b321ce
26 changed files with 1824 additions and 1855 deletions

View File

@ -1,8 +1,8 @@
#include "cafe/coreinit.h" #include "cafe/coreinit.h"
#include "hbl.h" #include "hbl.h"
#include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdint>
int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle); int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle);
int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr); int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr);

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdint>
// Timers // Timers
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4) #define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
@ -226,7 +226,6 @@ struct OSThread {
const char *name; const char *name;
char _5C4[0x6A0 - 0x5C4]; char _5C4[0x6A0 - 0x5C4];
}; };
// Messages // Messages

View File

@ -7,7 +7,7 @@ namespace nn::act {
uint8_t (*GetSlotNo)(); uint8_t (*GetSlotNo)();
uint32_t (*GetPersistentIdEx)(uint8_t slot); uint32_t (*GetPersistentIdEx)(uint8_t slot);
uint32_t (*Finalize)(); uint32_t (*Finalize)();
} } // namespace nn::act
void nnactInitialize() { void nnactInitialize() {
uint32_t handle; uint32_t handle;

View File

@ -6,6 +6,6 @@ namespace nn::act {
extern uint8_t (*GetSlotNo)(); extern uint8_t (*GetSlotNo)();
extern uint32_t (*GetPersistentIdEx)(uint8_t slot); extern uint32_t (*GetPersistentIdEx)(uint8_t slot);
extern uint32_t (*Finalize)(); extern uint32_t (*Finalize)();
} } // namespace nn::act
void nnactInitialize(); void nnactInitialize();

View File

@ -6,8 +6,8 @@
#include "debugger.h" #include "debugger.h"
#include "exceptions.h" #include "exceptions.h"
#include "screen.h"
#include "input.h" #include "input.h"
#include "screen.h"
#include <cstring> #include <cstring>
@ -66,8 +66,7 @@ bool BreakPointMgr::isSoftware(uint32_t addr) {
uint32_t opcode = instr >> 26; uint32_t opcode = instr >> 26;
if (opcode == 3) { //twi if (opcode == 3) { //twi
return true; return true;
} } else if (opcode == 31) {
else if (opcode == 31) {
return (instr & 0x7FF) == 8; //tw return (instr & 0x7FF) == 8; //tw
} }
return false; return false;
@ -88,8 +87,7 @@ void BreakPointMgr::enable(BreakPoint *bp, uint32_t addr) {
BreakPoint *other = find(addr, true); BreakPoint *other = find(addr, true);
if (other) { if (other) {
bp->instruction = other->instruction; bp->instruction = other->instruction;
} } else {
else {
bp->instruction = *(uint32_t *) addr; bp->instruction = *(uint32_t *) addr;
KernelWriteU32(addr, TRAP); KernelWriteU32(addr, TRAP);
} }
@ -131,8 +129,7 @@ void BreakPointMgr::read(void *buffer, uint32_t addr, uint32_t length) {
bufptr[i] = value >> 24; bufptr[i] = value >> 24;
value <<= 8; value <<= 8;
} }
} } else {
else {
*(uint32_t *) bufptr = bp->instruction; *(uint32_t *) bufptr = bp->instruction;
} }
bp = findRange(addr, length, &index, true); bp = findRange(addr, length, &index, true);
@ -148,8 +145,7 @@ void BreakPointMgr::write(const void *buffer, uint32_t addr, uint32_t length) {
int index = 0; int index = 0;
if (!findRange(addr, length, &index, true)) { if (!findRange(addr, length, &index, true)) {
KernelWrite(addr, buffer, length); KernelWrite(addr, buffer, length);
} } else {
else {
for (uint32_t i = 0; i < length; i += 4) { for (uint32_t i = 0; i < length; i += 4) {
uint32_t value = *(uint32_t *) ((char *) buffer + i); uint32_t value = *(uint32_t *) ((char *) buffer + i);
@ -157,8 +153,7 @@ void BreakPointMgr::write(const void *buffer, uint32_t addr, uint32_t length) {
BreakPoint *bp = findRange(addr + i, 4, &index, true); BreakPoint *bp = findRange(addr + i, 4, &index, true);
if (!bp) { if (!bp) {
KernelWriteU32(addr + i, value); KernelWriteU32(addr + i, value);
} } else {
else {
while (bp) { while (bp) {
bp->instruction = value; bp->instruction = value;
bp = findRange(addr + i, 4, &index, true); bp = findRange(addr + i, 4, &index, true);
@ -176,8 +171,7 @@ void BreakPointMgr::toggle(uint32_t addr) {
BreakPoint *bp = find(addr, false); BreakPoint *bp = find(addr, false);
if (bp) { if (bp) {
disable(bp); disable(bp);
} } else {
else {
BreakPoint *bp = breakpoints.alloc(); BreakPoint *bp = breakpoints.alloc();
bp->isSpecial = false; bp->isSpecial = false;
enable(bp, addr); enable(bp, addr);
@ -192,8 +186,7 @@ uint32_t BreakPointMgr::getInstr(uint32_t addr) {
BreakPoint *bp = find(addr, true); BreakPoint *bp = find(addr, true);
if (bp) { if (bp) {
instruction = bp->instruction; instruction = bp->instruction;
} } else {
else {
instruction = *(uint32_t *) addr; instruction = *(uint32_t *) addr;
} }
unlock(); unlock();
@ -257,7 +250,8 @@ void BreakPointMgr::predictStep(ExceptionState *state, bool stepOver) {
if (!LK || !stepOver) { if (!LK || !stepOver) {
if (XO == 16) target2 = state->context.lr; if (XO == 16) target2 = state->context.lr;
else if (XO == 528) target2 = state->context.ctr; else if (XO == 528)
target2 = state->context.ctr;
} }
} }
@ -449,8 +443,7 @@ void StepMgr::singleStep(ExceptionState *state, uint32_t instruction) {
if (XO == 16) { if (XO == 16) {
branchConditional(state, instruction, state->context.lr, true); branchConditional(state, instruction, state->context.lr, true);
return; return;
} } else if (XO == 528) {
else if (XO == 528) {
branchConditional(state, instruction, state->context.ctr, false); branchConditional(state, instruction, state->context.ctr, false);
return; return;
} }
@ -549,8 +542,7 @@ void Debugger::handleBreakPoint(ExceptionState *state) {
screen.drawText( screen.drawText(
0, 0, "Waiting for debugger connection.\n" 0, 0, "Waiting for debugger connection.\n"
"Press the home button to continue without debugger.\n" "Press the home button to continue without debugger.\n"
"You can still connect while the game is running." "You can still connect while the game is running.");
);
screen.flip(); screen.flip();
while (!connected) { while (!connected) {
@ -596,8 +588,7 @@ void Debugger::handleCrash(ExceptionState *state) {
while (true) { while (true) {
OSReceiveMessage(&state->queue, &message, OS_MESSAGE_FLAGS_BLOCKING); OSReceiveMessage(&state->queue, &message, OS_MESSAGE_FLAGS_BLOCKING);
} }
} } else {
else {
handleFatalCrash(&state->context, state->type); handleFatalCrash(&state->context, state->type);
} }
} }
@ -605,7 +596,8 @@ void Debugger::handleCrash(ExceptionState *state) {
void Debugger::handleFatalCrash(OSContext *context, ExceptionState::Type type) { void Debugger::handleFatalCrash(OSContext *context, ExceptionState::Type type) {
const char *name; const char *name;
if (type == ExceptionState::DSI) name = "A DSI"; if (type == ExceptionState::DSI) name = "A DSI";
else if (type == ExceptionState::ISI) name = "An ISI"; else if (type == ExceptionState::ISI)
name = "An ISI";
else { else {
name = "A program"; name = "A program";
} }
@ -627,8 +619,7 @@ void Debugger::handleException(OSContext *context, ExceptionState::Type type) {
if (state->isBreakpoint()) { if (state->isBreakpoint()) {
handleBreakPoint(state); handleBreakPoint(state);
} } else {
else {
handleCrash(state); handleCrash(state);
} }
} }
@ -669,7 +660,8 @@ void Debugger::cleanup() {
exceptions.cleanup(); exceptions.cleanup();
OSMessage message; OSMessage message;
while (OSReceiveMessage(&eventQueue, &message, OS_MESSAGE_FLAGS_NONE)); while (OSReceiveMessage(&eventQueue, &message, OS_MESSAGE_FLAGS_NONE))
;
} }
void Debugger::mainLoop(Client *client) { void Debugger::mainLoop(Client *client) {
@ -690,14 +682,12 @@ void Debugger::mainLoop(Client *client) {
return; return;
} }
delete buffer; delete buffer;
} } else if (cmd == COMMAND_WRITE) {
else if (cmd == COMMAND_WRITE) {
uint32_t addr, length; uint32_t addr, length;
if (!client->recvall(&addr, 4)) return; if (!client->recvall(&addr, 4)) return;
if (!client->recvall(&length, 4)) return; if (!client->recvall(&length, 4)) return;
if (!client->recvall((void *) addr, length)) return; if (!client->recvall((void *) addr, length)) return;
} } else if (cmd == COMMAND_WRITE_CODE) {
else if (cmd == COMMAND_WRITE_CODE) {
uint32_t addr, length; uint32_t addr, length;
if (!client->recvall(&addr, 4)) return; if (!client->recvall(&addr, 4)) return;
if (!client->recvall(&length, 4)) return; if (!client->recvall(&length, 4)) return;
@ -709,8 +699,7 @@ void Debugger::mainLoop(Client *client) {
} }
breakpoints.write(buffer, addr, length); breakpoints.write(buffer, addr, length);
delete buffer; delete buffer;
} } else if (cmd == COMMAND_GET_MODULE_NAME) {
else if (cmd == COMMAND_GET_MODULE_NAME) {
char name[0x40]; char name[0x40];
int length = 0x40; int length = 0x40;
OSDynLoad_GetModuleName(-1, name, &length); OSDynLoad_GetModuleName(-1, name, &length);
@ -718,8 +707,7 @@ void Debugger::mainLoop(Client *client) {
length = strlen(name); length = strlen(name);
if (!client->sendall(&length, 4)) return; if (!client->sendall(&length, 4)) return;
if (!client->sendall(name, length)) return; if (!client->sendall(name, length)) return;
} } else if (cmd == COMMAND_GET_MODULE_LIST) {
else if (cmd == COMMAND_GET_MODULE_LIST) {
OSLockMutex(OSDynLoad_gLoaderLock); OSLockMutex(OSDynLoad_gLoaderLock);
char buffer[0x1000]; //This should be enough char buffer[0x1000]; //This should be enough
@ -750,8 +738,7 @@ void Debugger::mainLoop(Client *client) {
if (!client->sendall(&offset, 4)) return; if (!client->sendall(&offset, 4)) return;
if (!client->sendall(buffer, offset)) return; if (!client->sendall(buffer, offset)) return;
} } else if (cmd == COMMAND_GET_THREAD_LIST) {
else if (cmd == COMMAND_GET_THREAD_LIST) {
int state = OSDisableInterrupts(); int state = OSDisableInterrupts();
__OSLockScheduler(this); __OSLockScheduler(this);
@ -773,8 +760,7 @@ void Debugger::mainLoop(Client *client) {
int priority = current->basePriority; int priority = current->basePriority;
if (current->type == 1) { if (current->type == 1) {
priority -= 0x20; priority -= 0x20;
} } else if (current->type == 2) {
else if (current->type == 2) {
priority -= 0x40; priority -= 0x40;
} }
@ -797,8 +783,7 @@ void Debugger::mainLoop(Client *client) {
if (!client->sendall(&offset, 4)) return; if (!client->sendall(&offset, 4)) return;
if (!client->sendall(buffer, offset)) return; if (!client->sendall(buffer, offset)) return;
} } else if (cmd == COMMAND_GET_STACK_TRACE) {
else if (cmd == COMMAND_GET_STACK_TRACE) {
OSThread *thread; OSThread *thread;
if (!client->recvall(&thread, 4)) return; if (!client->recvall(&thread, 4)) return;
@ -817,19 +802,16 @@ void Debugger::mainLoop(Client *client) {
if (!client->sendall(&index, 4)) return; if (!client->sendall(&index, 4)) return;
if (!client->sendall(trace, index * 4)) return; if (!client->sendall(trace, index * 4)) return;
} } else {
else {
int index = 0; int index = 0;
if (!client->sendall(&index, 4)) return; if (!client->sendall(&index, 4)) return;
} }
} } else if (cmd == COMMAND_TOGGLE_BREAKPOINT) {
else if (cmd == COMMAND_TOGGLE_BREAKPOINT) {
uint32_t address; uint32_t address;
if (!client->recvall(&address, 4)) return; if (!client->recvall(&address, 4)) return;
breakpoints.toggle(address); breakpoints.toggle(address);
} } else if (cmd == COMMAND_POKE_REGISTERS) {
else if (cmd == COMMAND_POKE_REGISTERS) {
OSThread *thread; OSThread *thread;
if (!client->recvall(&thread, 4)) return; if (!client->recvall(&thread, 4)) return;
@ -845,8 +827,7 @@ void Debugger::mainLoop(Client *client) {
memcpy(state->context.fpr, fpr, 8 * 32); memcpy(state->context.fpr, fpr, 8 * 32);
} }
exceptions.unlock(); exceptions.unlock();
} } else if (cmd == COMMAND_RECEIVE_MESSAGES) {
else if (cmd == COMMAND_RECEIVE_MESSAGES) {
OSMessage messages[10]; OSMessage messages[10];
int count = 0; int count = 0;
@ -866,8 +847,7 @@ void Debugger::mainLoop(Client *client) {
if (!client->sendall(data, length)) return; if (!client->sendall(data, length)) return;
} }
} }
} } else if (cmd == COMMAND_SEND_MESSAGE) {
else if (cmd == COMMAND_SEND_MESSAGE) {
OSMessage message; OSMessage message;
if (!client->recvall(&message, sizeof(OSMessage))) return; if (!client->recvall(&message, sizeof(OSMessage))) return;
@ -932,8 +912,7 @@ void Debugger::start() {
OSCreateThread( OSCreateThread(
serverThread, threadEntry, 0, 0, serverThread, threadEntry, 0, 0,
stack + STACK_SIZE, STACK_SIZE, stack + STACK_SIZE, STACK_SIZE,
0, 12 0, 12);
);
OSSetThreadName(serverThread, "Debug Server"); OSSetThreadName(serverThread, "Debug Server");
OSResumeThread(serverThread); OSResumeThread(serverThread);

View File

@ -24,8 +24,7 @@ void DumpContext(OSContext *context, const char *excType) {
context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27], context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27],
context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31], context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31],
context->lr, context->ctr, context->xer, context->srr0, context->srr1, context->lr, context->ctr, context->xer, context->srr0, context->srr1,
context->dsisr, context->dar context->dsisr, context->dar);
);
OSFatal(buffer); OSFatal(buffer);
} }

View File

@ -29,8 +29,7 @@ void KernelWriteU32(uint32_t addr, uint32_t value) {
} }
/* Write a 32-bit word with kernel permissions */ /* Write a 32-bit word with kernel permissions */
void __attribute__ ((noinline)) kern_write(uint32_t addr, uint32_t value) void __attribute__((noinline)) kern_write(uint32_t addr, uint32_t value) {
{
asm volatile( asm volatile(
"li 3,1\n" "li 3,1\n"
"li 4,0\n" "li 4,0\n"
@ -47,8 +46,7 @@ void __attribute__ ((noinline)) kern_write(uint32_t addr, uint32_t value)
: :
: "r"(addr), "r"(value) : "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12" "11", "12");
);
} }
void PatchSyscall(int index, uint32_t addr) { void PatchSyscall(int index, uint32_t addr) {

View File

@ -1,18 +1,18 @@
#include "cafe/coreinit.h" #include "cafe/coreinit.h"
#include "cafe/sysapp.h"
#include "cafe/nsysnet.h"
#include "cafe/vpad.h"
#include "cafe/nn_save.h"
#include "cafe/nn_act.h" #include "cafe/nn_act.h"
#include "kernel.h" #include "cafe/nn_save.h"
#include "cafe/nsysnet.h"
#include "cafe/sysapp.h"
#include "cafe/vpad.h"
#include "hbl.h" #include "hbl.h"
#include "kernel.h"
#include "patches.h"
#include "debugger.h" #include "debugger.h"
#include "exceptions.h" #include "exceptions.h"
#include "screen.h"
#include "menu.h" #include "menu.h"
#include "patches.h"
#include "screen.h"
bool GetTitleIdOnDisk(uint64_t *titleId) { bool GetTitleIdOnDisk(uint64_t *titleId) {
@ -42,12 +42,10 @@ int MenuMain() {
uint64_t titleId; uint64_t titleId;
if (GetTitleIdOnDisk(&titleId)) { if (GetTitleIdOnDisk(&titleId)) {
SYSLaunchTitle(titleId); SYSLaunchTitle(titleId);
} } else {
else {
menu.setMessage("Please insert a valid disk"); menu.setMessage("Please insert a valid disk");
} }
} } else if (result == Menu::ReturnToMenu) {
else if (result == Menu::ReturnToMenu) {
SYSLaunchMenu(); SYSLaunchMenu();
} }
return EXIT_RELAUNCH_ON_LOAD; return EXIT_RELAUNCH_ON_LOAD;
@ -76,8 +74,7 @@ int start() {
int result; int result;
if (firstRun) { if (firstRun) {
result = MenuMain(); result = MenuMain();
} } else {
else {
result = DebuggerMain(); result = DebuggerMain();
} }
firstRun = false; firstRun = false;

View File

@ -1,9 +1,9 @@
#include "cafe/vpad.h"
#include "menu.h" #include "menu.h"
#include "screen.h" #include "cafe/vpad.h"
#include "input.h"
#include "color.h" #include "color.h"
#include "input.h"
#include "screen.h"
Menu::Menu(Screen *screen) : screen(screen) { Menu::Menu(Screen *screen) : screen(screen) {
currentOption = LaunchDisk; currentOption = LaunchDisk;
@ -17,8 +17,7 @@ Menu::Option Menu::show() {
if (buttons & VPAD_BUTTON_A) return (Option) currentOption; if (buttons & VPAD_BUTTON_A) return (Option) currentOption;
else if (buttons & VPAD_BUTTON_DOWN) { else if (buttons & VPAD_BUTTON_DOWN) {
if (currentOption < 2) currentOption++; if (currentOption < 2) currentOption++;
} } else if (buttons & VPAD_BUTTON_UP) {
else if (buttons & VPAD_BUTTON_UP) {
if (currentOption > 0) currentOption--; if (currentOption > 0) currentOption--;
} }
} }

View File

@ -33,8 +33,7 @@ void Patch(void *funcPtr, void *patchPtr) {
KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l
} }
} }
} } else { //Dynamic function
else { //Dynamic function
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) { for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t instr = *(uint32_t *) addr; uint32_t instr = *(uint32_t *) addr;
if ((instr & 0xFC000002) == 0x48000000) { //b or bl if ((instr & 0xFC000002) == 0x48000000) { //b or bl

View File

@ -1,6 +1,6 @@
#include "cafe/coreinit.h"
#include "screen.h" #include "screen.h"
#include "cafe/coreinit.h"
#include "memory.h" #include "memory.h"
Screen::Screen() : screenBuffer(0) {} Screen::Screen() : screenBuffer(0) {}

View File

@ -14,8 +14,7 @@ Socket::~Socket() {
bool Socket::init(Type type) { bool Socket::init(Type type) {
if (type == TCP) { if (type == TCP) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
} } else {
else {
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
} }
return sock >= 0; return sock >= 0;