Skip to content

Commit

Permalink
style: add .clang-format config file (#37)
Browse files Browse the repository at this point in the history
* style: add .clang-format config file

It can be used with clang-format tool for formatting.

Disable clang auto formatting for places where current format is
better.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>

* style: apply style reformatting generated by clang-format

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>

Co-authored-by: Bjoern Doebel <[email protected]>
  • Loading branch information
wipawel and bjoernd authored Aug 12, 2020
1 parent 98b4353 commit 0b75f5a
Show file tree
Hide file tree
Showing 26 changed files with 1,072 additions and 1,045 deletions.
133 changes: 133 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 90
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- 'for_each_memory_range'
- 'for_each_order'
- 'list_for_each'
- 'list_for_each_entry'
- 'list_for_each_entry_safe'
- 'list_for_each_safe'
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
...

12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ vcpus=1

You need to generate a bootable ISO for this.

## Style

The style for this project is defined in `.clang-format` file in the main directory of this repository.

Use the following command to apply the style automatically to the file you modify:

```
clang-format -style=file -Werror -i MODIFIED_FILE
```

For more information refer to: https://clang.llvm.org/docs/ClangFormat.html

## Credits and Attributions

* Parts of the KTF project are inspired by and based on XTF project [1] developed by Andrew Cooper of Citrix.
Expand Down
32 changes: 16 additions & 16 deletions include/apic.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@

#define DEFAULT_APIC_BASE _U32(0xfee00000)

#define APIC_BASE_BSP (_U64(1) << 8)
#define APIC_BASE_EXTD (_U64(1) << 10)
#define APIC_BASE_ENABLE (_U64(1) << 11)
#define APIC_BASE_BSP (_U64(1) << 8)
#define APIC_BASE_EXTD (_U64(1) << 10)
#define APIC_BASE_ENABLE (_U64(1) << 11)

/* Local APIC definitions */
#define APIC_ID 0x020
#define APIC_LVR 0x030
#define APIC_SPIV 0x0f0
#define APIC_SPIV_APIC_ENABLED 0x00100

#define APIC_ICR 0x300
#define APIC_ICR2 0x310
#define APIC_LVT_TIMER 0x320
#define APIC_LVT_LINT0 0x350
#define APIC_LVT_LINT1 0x360
#define APIC_DM_NMI 0x00400
#define APIC_DM_INIT 0x00500
#define APIC_DM_STARTUP 0x00600
#define APIC_ICR_BUSY 0x01000
#define APIC_DISABLE 0x10000
#define APIC_DEST_SELF 0x40000
#define APIC_ICR 0x300
#define APIC_ICR2 0x310
#define APIC_LVT_TIMER 0x320
#define APIC_LVT_LINT0 0x350
#define APIC_LVT_LINT1 0x360
#define APIC_DM_NMI 0x00400
#define APIC_DM_INIT 0x00500
#define APIC_DM_STARTUP 0x00600
#define APIC_ICR_BUSY 0x01000
#define APIC_DISABLE 0x10000
#define APIC_DEST_SELF 0x40000

#define GET_APIC_DEST_FIELD(x) (((x) >> 24) & 0xFF)
#define SET_APIC_DEST_FIELD(x) ((x) << 24)
Expand Down Expand Up @@ -88,7 +88,7 @@ static inline void apic_mmio_write(uint32_t reg, uint32_t val) {
}

static inline void apic_mmio_icr_write(uint64_t val) {
apic_mmio_write(APIC_ICR2, (uint32_t) (val >> 32));
apic_mmio_write(APIC_ICR2, (uint32_t)(val >> 32));
apic_mmio_write(APIC_ICR, (uint32_t) val);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ static inline uint32_t apic_read(uint32_t reg) {

static inline void apic_icr_write(uint64_t val) {
if (apic_mode == APIC_MODE_XAPIC) {
apic_mmio_write(APIC_ICR2, (uint32_t) (val >> 32));
apic_mmio_write(APIC_ICR2, (uint32_t)(val >> 32));
apic_mmio_write(APIC_ICR, (uint32_t) val);
}
else
Expand Down
26 changes: 14 additions & 12 deletions include/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@
#define KTF_ASM_MACROS_H

#if defined(__i386__)
#define _ASM_REG(reg) e ## reg
#define _ASM_REG(reg) e##reg
#elif defined(__x86_64__)
#define _ASM_REG(reg) r ## reg
#define _ASM_REG(reg) r##reg
#else
#define _ASM_REG(reg) reg
#endif

#define _ASM_AX _ASM_REG(ax)
#define _ASM_BX _ASM_REG(bx)
#define _ASM_CX _ASM_REG(cx)
#define _ASM_DX _ASM_REG(dx)
#define _ASM_SI _ASM_REG(si)
#define _ASM_DI _ASM_REG(di)
#define _ASM_BP _ASM_REG(bp)
#define _ASM_SP _ASM_REG(sp)
#define _ASM_IP _ASM_REG(ip)
#define _ASM_AX _ASM_REG(ax)
#define _ASM_BX _ASM_REG(bx)
#define _ASM_CX _ASM_REG(cx)
#define _ASM_DX _ASM_REG(dx)
#define _ASM_SI _ASM_REG(si)
#define _ASM_DI _ASM_REG(di)
#define _ASM_BP _ASM_REG(bp)
#define _ASM_SP _ASM_REG(sp)
#define _ASM_IP _ASM_REG(ip)
#define _ASM_FLAGS _ASM_REG(flags)

#ifdef __ASSEMBLY__

/* clang-format off */
.macro putc val
movw $0x3f8, %dx;
movb $\val, %al;
Expand Down Expand Up @@ -120,12 +121,13 @@
.section .note.name, "a"; \
.align 4; \
.long 2f - 1f; /* namesz */ \
.long 4f - 3f; /* descsz */ \
.long 4f - 3f; /* descsz */ \
.long type; /* type */ \
1:.asciz #name; /* name */ \
2:.align 4; \
3:size addr; /* desc */ \
4:.align 4;
/* clang-format on */

#endif

Expand Down
48 changes: 20 additions & 28 deletions include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,47 @@
static inline bool test_bit(unsigned int bit, volatile void *addr) {
bool status;

asm volatile (
"bt %[bit], %[addr];"
"setc %[status];"
: [status] "=r" (status)
: [bit] "Ir" (bit), [addr] "m" (* (uint8_t *) addr)
: "cc", "memory"
);
asm volatile("bt %[bit], %[addr];"
"setc %[status];"
: [ status ] "=r"(status)
: [ bit ] "Ir"(bit), [ addr ] "m"(*(uint8_t *) addr)
: "cc", "memory");

return status;
}

static inline bool test_and_set_bit(unsigned int bit, volatile void *addr) {
bool status;

asm volatile (
"lock bts %[bit], %[addr];"
"setc %[status];"
: [status] "=r" (status)
: [bit] "Ir" (bit), [addr] "m" (* (uint8_t *) addr)
: "cc", "memory"
);
asm volatile("lock bts %[bit], %[addr];"
"setc %[status];"
: [ status ] "=r"(status)
: [ bit ] "Ir"(bit), [ addr ] "m"(*(uint8_t *) addr)
: "cc", "memory");

return status;
}

static inline bool test_and_reset_bit(unsigned int bit, volatile void *addr) {
bool status;

asm volatile (
"lock btr %[bit], %[addr];"
"setc %[status];"
: [status] "=r" (status)
: [bit] "Ir" (bit), [addr] "m" (* (uint8_t *) addr)
: "cc", "memory"
);
asm volatile("lock btr %[bit], %[addr];"
"setc %[status];"
: [ status ] "=r"(status)
: [ bit ] "Ir"(bit), [ addr ] "m"(*(uint8_t *) addr)
: "cc", "memory");

return status;
}

static inline bool test_and_complement_bit(unsigned int bit, volatile void *addr) {
bool status;

asm volatile (
"lock btc %[bit], %[addr];"
"setc %[status];"
: [status] "=r" (status)
: [bit] "Ir" (bit), [addr] "m" (* (uint8_t *) addr)
: "cc", "memory"
);
asm volatile("lock btc %[bit], %[addr];"
"setc %[status];"
: [ status ] "=r"(status)
: [ bit ] "Ir"(bit), [ addr ] "m"(*(uint8_t *) addr)
: "cc", "memory");

return status;
}
Expand Down
Loading

0 comments on commit 0b75f5a

Please sign in to comment.