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 "hbl.h"
#include <cstdint>
#include <cstddef>
#include <cstdint>
int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle);
int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr);

View File

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

View File

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

View File

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

View File

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

View File

@ -29,8 +29,7 @@ void KernelWriteU32(uint32_t addr, uint32_t value) {
}
/* 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(
"li 3,1\n"
"li 4,0\n"
@ -47,8 +46,7 @@ void __attribute__ ((noinline)) kern_write(uint32_t addr, uint32_t value)
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12"
);
"11", "12");
}
void PatchSyscall(int index, uint32_t addr) {

View File

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

View File

@ -1,9 +1,9 @@
#include "cafe/vpad.h"
#include "menu.h"
#include "screen.h"
#include "input.h"
#include "cafe/vpad.h"
#include "color.h"
#include "input.h"
#include "screen.h"
Menu::Menu(Screen *screen) : screen(screen) {
currentOption = LaunchDisk;
@ -17,8 +17,7 @@ Menu::Option Menu::show() {
if (buttons & VPAD_BUTTON_A) return (Option) currentOption;
else if (buttons & VPAD_BUTTON_DOWN) {
if (currentOption < 2) currentOption++;
}
else if (buttons & VPAD_BUTTON_UP) {
} else if (buttons & VPAD_BUTTON_UP) {
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
}
}
}
else { //Dynamic function
} else { //Dynamic function
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t instr = *(uint32_t *) addr;
if ((instr & 0xFC000002) == 0x48000000) { //b or bl

View File

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

View File

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