From ca1e99b0b2d7983a2e8c48f52c7456b819a5d3cc Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 7 Apr 2023 19:49:34 +0200 Subject: [PATCH] Add .clang-format --- .clang-format | 67 ++++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 8 +++++ .github/workflows/pr.yml | 12 +++++-- README.md | 4 +++ source/main.cpp | 67 ++++++++++++++++++++-------------------- 5 files changed, 122 insertions(+), 36 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..56cc685 --- /dev/null +++ b/.clang-format @@ -0,0 +1,67 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveMacros: AcrossEmptyLinesAndComments +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27224e6..68373e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,16 @@ on: - main jobs: + clang-format: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source build-binary: runs-on: ubuntu-22.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 4e726ce..62ab121 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,10 +3,18 @@ name: CI-PR on: [pull_request] jobs: - build-binary: + clang-format: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source + build-binary: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 - name: build binary run: | docker build . -t builder diff --git a/README.md b/README.md index 1adea8c..a4138ab 100644 --- a/README.md +++ b/README.md @@ -36,5 +36,9 @@ docker run -it --rm -v ${PWD}:/project usb_serial_logging-builder make docker run -it --rm -v ${PWD}:/project usb_serial_logging-builder make clean ``` +## Format the code via docker + +`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source -i` + ## Credits Maschell \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index fbde281..4eb2f4e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,14 +1,14 @@ -#include -#include -#include -#include -#include -#include -#include -#include #include #include +#include #include +#include +#include +#include +#include +#include +#include +#include extern "C" void SCKernelCopyData(uint32_t dst, uint32_t src, uint32_t len); extern "C" void KernelCopyDataInternal(uint32_t dst, uint32_t src, uint32_t len); @@ -27,50 +27,49 @@ void KernelNOPAtPhysicalAddress(uint32_t addr) { } /* Write a 32-bit word with kernel permissions */ -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) { - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "mr 5,%1\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%0\n" - "mr %1,1\n" - "li 0,0x3500\n" - "sc\n" - "nop\n" - "mr 1,%1\n" - : - : "r"(addr), "r"(value) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); +void __attribute__((noinline)) kern_write(void *addr, uint32_t value) { + asm volatile( + "li 3,1\n" + "li 4,0\n" + "mr 5,%1\n" + "li 6,0\n" + "li 7,0\n" + "lis 8,1\n" + "mr 9,%0\n" + "mr %1,1\n" + "li 0,0x3500\n" + "sc\n" + "nop\n" + "mr 1,%1\n" + : + : "r"(addr), "r"(value) + : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12"); } -int main(int argc, char **argv) { - // Start syslogging on iosu side +int main(int argc, char **argv) { + // Start syslogging on iosu side int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); if (mcpFd >= 0) { - int in = 0xFA; // IPC_CUSTOM_START_USB_LOGGING + int in = 0xFA; // IPC_CUSTOM_START_USB_LOGGING int out = 0; IOS_Ioctl(mcpFd, 100, &in, sizeof(in), &out, sizeof(out)); IOS_Close(mcpFd); } - + kern_write((void *) (KERN_SYSCALL_TBL1 + 0x25 * 4), (uint32_t) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL2 + 0x25 * 4), (uint32_t) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL3 + 0x25 * 4), (uint32_t) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL4 + 0x25 * 4), (uint32_t) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL5 + 0x25 * 4), (uint32_t) SCKernelCopyData); - - // Patch loader.elf to spit out less warnings when loading .rpx built with wut + + // Patch loader.elf to spit out less warnings when loading .rpx built with wut KernelNOPAtPhysicalAddress(0x0100b770 - 0x01000000 + 0x32000000); KernelNOPAtPhysicalAddress(0x0100b800 - 0x01000000 + 0x32000000); KernelNOPAtPhysicalAddress(0x0100b7b8 - 0x01000000 + 0x32000000); ICInvalidateRange(reinterpret_cast(0x0100b770), 0x04); ICInvalidateRange(reinterpret_cast(0x0100b800), 0x04); ICInvalidateRange(reinterpret_cast(0x0100b7b8), 0x04); - + return 0; }