Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 80
UseTab: Never
BreakBeforeBraces: Linux

AlignTrailingComments: false
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false

AllowAllArgumentsOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowAllParametersOfDeclarationOnNextLine: false

SortIncludes: false

IndentCaseLabels: false
PointerAlignment: Right
ContinuationIndentWidth: 4
MaxEmptyLinesToKeep: 2
BraceWrapping:
AfterFunction: true
SpaceAfterCStyleCast: false
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
95165c5566cb37c7c3b9a9deb345ec2e8922c4fa
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: clang-format Check
on: [push, pull_request]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
strategy:
matrix:
path:
- 'bindings'
- 'tests'
- 'include'
- 'tenders'
- 'elftool'
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for Solo5.
uses: jidicula/clang-format-action@v4.16.0
with:
clang-format-version: '22'
check-path: ${{ matrix.path }}
32 changes: 16 additions & 16 deletions bindings/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* This header file is included by all bindings, and apart from the common
* internal interfaces includes and defines all necessary C99 runtime
* interfaces used by bindings.
*/
*/

#ifndef __BINDINGS_H__
#define __BINDINGS_H__
Expand All @@ -48,28 +48,28 @@
#endif

/* alignment macros */
#define ALIGN_4K __attribute__((aligned(0x1000)))
#define ALIGN_4K __attribute__((aligned(0x1000)))
#define ALIGN_64_BIT __attribute__((aligned(0x8)))

/* convenient macro stringification */
#define STR_EXPAND(y) #y
#define STR(x) STR_EXPAND(x)
#define STR(x) STR_EXPAND(x)

/* abort.c */
void _assert_fail(const char *, const char *, const char *)
__attribute__((noreturn));
void _abort(const char *, const char *, const char *, void *)
__attribute__((noreturn));

#define PANIC(s, r) \
do { \
_abort(__FILE__, STR(__LINE__), s, r); \
#define PANIC(s, r) \
do { \
_abort(__FILE__, STR(__LINE__), s, r); \
} while (0)

#define assert(e) \
do { \
if (!(e)) \
_assert_fail(__FILE__, STR(__LINE__), #e); \
#define assert(e) \
do { \
if (!(e)) \
_assert_fail(__FILE__, STR(__LINE__), #e); \
} while (0)

/* cpu_<architecture>.c: low-level CPU functions */
Expand Down Expand Up @@ -123,19 +123,19 @@ const char *cmdline_parse(const char *cmdline);

/* log.c: */
typedef enum {
ERROR=0,
WARN,
INFO,
ERROR = 0,
WARN,
INFO,
DEBUG,
} log_level_t;
int log(log_level_t level, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
__attribute__((format(printf, 2, 3)));
void log_set_level(log_level_t level);

/* compiler-only memory "barrier" */
#define cc_barrier() __asm__ __volatile__("" : : : "memory")

#define NSEC_PER_SEC 1000000000ULL
#define NSEC_PER_SEC 1000000000ULL

/*
* Atomically test-and-set bit (nr) in (*bits). Fully synchronous.
Expand Down Expand Up @@ -182,7 +182,7 @@ static inline bool sync_bt(int nr, const volatile void *bits)
* Fully synchronous.
*/
static inline void atomic_sync_xchg(volatile unsigned long *ptr,
unsigned long val, unsigned long *result)
unsigned long val, unsigned long *result)
{
__atomic_exchange(ptr, &val, result, __ATOMIC_SEQ_CST);
}
Expand Down
26 changes: 11 additions & 15 deletions bindings/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,31 @@ const char *cmdline_parse(const char *cmdline)
matched = false;
/* --solo5:quiet is slightly misleading as errors are still logged. */
if (strncmp(p, opt_quiet, (sizeof(opt_quiet) - 1)) == 0 ||
strncmp(p, opt_error, (sizeof(opt_error) - 1)) == 0) {
strncmp(p, opt_error, (sizeof(opt_error) - 1)) == 0) {
_Static_assert(sizeof(opt_quiet) == sizeof(opt_error),
"sizeof(--solo5:quiet) != sizeof(--solo5:error");
after = (const char *) (p + (sizeof(opt_quiet) - 1));
"sizeof(--solo5:quiet) != sizeof(--solo5:error");
after = (const char *)(p + (sizeof(opt_quiet) - 1));
if (isspace(*after) || *after == '\0') {
log_set_level(ERROR);
p += (sizeof(opt_quiet) - 1);
matched = true;
}
}
else if (strncmp(p, opt_warn, (sizeof(opt_warn) - 1)) == 0) {
after = (const char *) (p + (sizeof(opt_warn) - 1));
} else if (strncmp(p, opt_warn, (sizeof(opt_warn) - 1)) == 0) {
after = (const char *)(p + (sizeof(opt_warn) - 1));
if (isspace(*after) || *after == '\0') {
log_set_level(WARN);
p += (sizeof(opt_warn) - 1);
matched = true;
}
}
else if (strncmp(p, opt_info, (sizeof(opt_info) - 1)) == 0) {
after = (const char *) (p + (sizeof(opt_info) - 1));
} else if (strncmp(p, opt_info, (sizeof(opt_info) - 1)) == 0) {
after = (const char *)(p + (sizeof(opt_info) - 1));
if (isspace(*after) || *after == '\0') {
log_set_level(INFO);
p += (sizeof(opt_info) - 1);
matched = true;
}
}
else if (strncmp(p, opt_debug, (sizeof(opt_debug) - 1)) == 0) {
after = (const char *) (p + (sizeof(opt_debug) - 1));
} else if (strncmp(p, opt_debug, (sizeof(opt_debug) - 1)) == 0) {
after = (const char *)(p + (sizeof(opt_debug) - 1));
if (isspace(*after) || *after == '\0') {
log_set_level(DEBUG);
p += (sizeof(opt_debug) - 1);
Expand All @@ -75,11 +72,10 @@ const char *cmdline_parse(const char *cmdline)
if (matched) {
while (*p && isspace(*p))
p++;
}
else {
} else {
break;
}
}

return (const char *) p;
return (const char *)p;
}
33 changes: 14 additions & 19 deletions bindings/cpu_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ struct regs {
uint64_t esr_el1;
};

static const char *exception_modes[]= {
"Synchronous Abort",
"IRQ",
"FIQ",
"Error"
};
static const char *exception_modes[] = {"Synchronous Abort", "IRQ", "FIQ",
"Error"};

void cpu_init(void)
{
__asm__ __volatile__("msr VBAR_EL1, %0"
:
: "r" ((uint64_t)&cpu_exception_vectors)
: "memory");
:
: "r"((uint64_t)&cpu_exception_vectors)
: "memory");
}

static void dump_registers(struct regs *regs)
Expand All @@ -56,27 +52,26 @@ static void dump_registers(struct regs *regs)
log(INFO, "\t LR : 0x%016lx\n", regs->lr);
log(INFO, "\t PSTATE : 0x%016lx\n", regs->spsr_el1);

for (idx = 0; idx < 28; idx+=4)
for (idx = 0; idx < 28; idx += 4)
log(INFO, "\t x%02d ~ x%02d: 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n",
idx, idx + 3, regs->xreg[idx], regs->xreg[idx + 1],
regs->xreg[idx + 2], regs->xreg[idx + 3]);

log(INFO, "\t x28 ~ x29: 0x%016lx 0x%016lx\n", regs->xreg[28], regs->xreg[29]);
log(INFO, "\t x28 ~ x29: 0x%016lx 0x%016lx\n", regs->xreg[28],
regs->xreg[29]);
}

void cpu_trap_handler(struct regs *regs, int el, int mode, int is_valid)
{
const uint32_t exception_cls = ESR_EC(regs->esr_el1);

log(INFO, "Solo5: Trap: EL%d %s%s caught\n",
el, is_valid ? "" : "Invalid ", exception_modes[mode]);
log(INFO, "Solo5: Trap: EL%d %s%s caught\n", el, is_valid ? "" : "Invalid ",
exception_modes[mode]);

if (exception_cls == ESR_EC_DABT_LOW ||
exception_cls == ESR_EC_DABT_CUR) {
uint64_t addr;
__asm__ __volatile__("mrs %0, FAR_EL1"
:"=&r"(addr) ::);
log(INFO, "Data Abort Address: 0x%016lx\n", addr);
if (exception_cls == ESR_EC_DABT_LOW || exception_cls == ESR_EC_DABT_CUR) {
uint64_t addr;
__asm__ __volatile__("mrs %0, FAR_EL1" : "=&r"(addr)::);
log(INFO, "Data Abort Address: 0x%016lx\n", addr);
}

dump_registers(regs);
Expand Down
38 changes: 19 additions & 19 deletions bindings/cpu_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@
#define __CPU_AARCH64_H__

/* memory defines */
#define PAGE_SIZE 4096
#define PAGE_SHIFT 12
#define PAGE_MASK ~(0xfff)
#define PAGE_SIZE 4096
#define PAGE_SHIFT 12
#define PAGE_MASK ~(0xfff)

#ifndef _BITUL

#ifdef ASM_FILE
#define _AC(X,Y) X
#define _AT(T,X) X
#define _AC(X, Y) X
#define _AT(T, X) X
#else
#define __AC(X,Y) (X##Y)
#define _AC(X,Y) __AC(X,Y)
#define _AT(T,X) ((T)(X))
#define __AC(X, Y) (X##Y)
#define _AC(X, Y) __AC(X, Y)
#define _AT(T, X) ((T)(X))
#endif

#define _BITUL(x) (_AC(1,UL) << (x))
#define _BITULL(x) (_AC(1,ULL) << (x))
#define _BITUL(x) (_AC(1, UL) << (x))
#define _BITULL(x) (_AC(1, ULL) << (x))

#endif

#define ESR_EC_IABT_LOW _AC(0x20, UL)
#define ESR_EC_IABT_CUR _AC(0x21, UL)
#define ESR_EC_DABT_LOW _AC(0x24, UL)
#define ESR_EC_DABT_CUR _AC(0x25, UL)
#define ESR_EC_IABT_LOW _AC(0x20, UL)
#define ESR_EC_IABT_CUR _AC(0x21, UL)
#define ESR_EC_DABT_LOW _AC(0x24, UL)
#define ESR_EC_DABT_CUR _AC(0x25, UL)

#define ESR_EC_SHIFT _AC(26, UL)
#define ESR_EC_MASK (_AC(0x3F, UL) << ESR_EC_SHIFT)
#define ESR_EC(esr) (((esr) & ESR_EC_MASK) >> ESR_EC_SHIFT)
#define ESR_EC_SHIFT _AC(26, UL)
#define ESR_EC_MASK (_AC(0x3F, UL) << ESR_EC_SHIFT)
#define ESR_EC(esr) (((esr) & ESR_EC_MASK) >> ESR_EC_SHIFT)

#ifndef ASM_FILE

Expand All @@ -59,7 +59,7 @@ static inline uint64_t cpu_cntvct(void)
{
uint64_t val;

__asm__ __volatile__("mrs %0, cntvct_el0" : "=r" (val)::);
__asm__ __volatile__("mrs %0, cntvct_el0" : "=r"(val)::);
return val;
}

Expand All @@ -71,7 +71,7 @@ static inline uint64_t mul64_32(uint64_t a, uint32_t b, uint8_t s)

static inline void cpu_set_tls_base(uint64_t base)
{
__asm__ __volatile("msr tpidr_el0, %0" :: "r"(base));
__asm__ __volatile("msr tpidr_el0, %0" ::"r"(base));
}

#endif /* __CPU_AARCH64_H__ */
23 changes: 8 additions & 15 deletions bindings/cpu_ppc64.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#define __CPU_PPC64_H__

/* memory defines */
#define PAGE_SIZE (64 * 1024)
#define PAGE_SHIFT 16
#define PAGE_MASK ~(0xffff)
#define PAGE_SIZE (64 * 1024)
#define PAGE_SHIFT 16
#define PAGE_MASK ~(0xffff)

#define CR0_SO (0x80000000 >> 3) /* summary overflow;
indicates syscall error */
#define CR0_SO \
(0x80000000 >> 3) /* summary overflow; \
indicates syscall error */

#ifndef ASM_FILE

Expand All @@ -37,22 +38,14 @@ static inline uint64_t cpu_cntvct(void)
{
uint64_t val;

__asm__ __volatile__(
"mfspr %0, 268\n"
: "=r" (val)
:
:);
__asm__ __volatile__("mfspr %0, 268\n" : "=r"(val) : :);

return val;
}

static inline void cpu_set_tls_base(uint64_t base)
{
__asm__ __volatile(
"mr 13, %0\n"
:
: "a" (base)
: "r13");
__asm__ __volatile("mr 13, %0\n" : : "a"(base) : "r13");
}

#endif /* !ASM_FILE */
Expand Down
Loading
Loading