From 99cfeb2584577b861f3820d8918951062de3960b Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 4 Feb 2022 17:35:49 +0100 Subject: [PATCH] Format the code via clang-format --- .clang-format | 67 +++++++++++++++++++ .github/workflows/ci.yml | 8 +++ .github/workflows/pr.yml | 8 +++ README.md | 8 ++- source/main.cpp | 135 ++++++++++++++++++++++----------------- 5 files changed, 166 insertions(+), 60 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 2bd293b..a83349c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,16 @@ on: - master jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source build-binary: runs-on: ubuntu-18.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 0413d45..19c3b14 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,8 +3,16 @@ name: CI-PR on: [pull_request] jobs: + clang-format: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/README.md b/README.md index 5423ee0..848c54d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![CI-Release](https://github.com/wiiu-env/KernelModule/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/KernelModule/actions/workflows/ci.yml) + ## Usage (`[ENVIRONMENT]` is a placeholder for the actual environment name.) @@ -17,4 +19,8 @@ docker run -it --rm -v ${PWD}:/project kernelmodule-builder make # make clean docker run -it --rm -v ${PWD}:/project kernelmodule-builder make clean -``` \ No newline at end of file +``` + +## Format the code via docker + +`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i` \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index e665ae6..97218a3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,9 +1,9 @@ +#include #include #include -#include -#include #include +#include WUMS_MODULE_EXPORT_NAME("homebrew_kernel"); WUMS_MODULE_SKIP_INIT_FINI(); @@ -38,39 +38,56 @@ void KernelReadSRsInternalFunc(sr_table_t *table) { asm volatile("eieio; isync"); - asm volatile("mfspr %0, 25" : "=r" (table->sdr1)); + asm volatile("mfspr %0, 25" + : "=r"(table->sdr1)); - asm volatile("mfsr %0, 0" : "=r" (table->value[i])); + asm volatile("mfsr %0, 0" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 1" : "=r" (table->value[i])); + asm volatile("mfsr %0, 1" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 2" : "=r" (table->value[i])); + asm volatile("mfsr %0, 2" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 3" : "=r" (table->value[i])); + asm volatile("mfsr %0, 3" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 4" : "=r" (table->value[i])); + asm volatile("mfsr %0, 4" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 5" : "=r" (table->value[i])); + asm volatile("mfsr %0, 5" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 6" : "=r" (table->value[i])); + asm volatile("mfsr %0, 6" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 7" : "=r" (table->value[i])); + asm volatile("mfsr %0, 7" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 8" : "=r" (table->value[i])); + asm volatile("mfsr %0, 8" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 9" : "=r" (table->value[i])); + asm volatile("mfsr %0, 9" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 10" : "=r" (table->value[i])); + asm volatile("mfsr %0, 10" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 11" : "=r" (table->value[i])); + asm volatile("mfsr %0, 11" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 12" : "=r" (table->value[i])); + asm volatile("mfsr %0, 12" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 13" : "=r" (table->value[i])); + asm volatile("mfsr %0, 13" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 14" : "=r" (table->value[i])); + asm volatile("mfsr %0, 14" + : "=r"(table->value[i])); i++; - asm volatile("mfsr %0, 15" : "=r" (table->value[i])); + asm volatile("mfsr %0, 15" + : "=r"(table->value[i])); i++; asm volatile("eieio; isync"); @@ -90,7 +107,9 @@ void KernelWriteSRsInternalFunc(sr_table_t *table) { asm volatile("mtsr 5, %0" : : "r" (table->value[i])); i++;*/ //asm volatile("mtsr 6, %0" : : "r" (table->value[6])); i++; /*asm volatile("mtsr 7, %0" : : "r" (table->value[i])); i++;*/ - asm volatile("mtsr 8, %0" : : "r" (table->value[8])); + asm volatile("mtsr 8, %0" + : + : "r"(table->value[8])); //i++; /*asm volatile("mtsr 9, %0" : : "r" (table->value[i])); i++; asm volatile("mtsr 10, %0" : : "r" (table->value[i])); i++; @@ -118,49 +137,47 @@ void KernelReadSRs(sr_table_t *table) { /* 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"); } /* Read a 32-bit word with kernel permissions */ -uint32_t __attribute__ ((noinline)) kern_read(const void *addr) { +uint32_t __attribute__((noinline)) kern_read(const void *addr) { uint32_t result; - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "li 5,0\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%1\n" - "li 0,0x3400\n" - "mr %0,1\n" - "sc\n" - "nop\n" - "mr 1,%0\n" - "mr %0,3\n" - : "=r"(result) - : "b"(addr) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); + asm volatile( + "li 3,1\n" + "li 4,0\n" + "li 5,0\n" + "li 6,0\n" + "li 7,0\n" + "lis 8,1\n" + "mr 9,%1\n" + "li 0,0x3400\n" + "mr %0,1\n" + "sc\n" + "nop\n" + "mr 1,%0\n" + "mr %0,3\n" + : "=r"(result) + : "b"(addr) + : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12"); return result; }