changes on .clang-format: no alignment of consecutive declarations and no alignment after comments or linebreaks

This commit is contained in:
Furkan Mudanyali 2023-12-27 00:40:48 +03:00
parent b96da58def
commit 7f0a207220
25 changed files with 144 additions and 119 deletions

View File

@ -1,8 +1,8 @@
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: AcrossComments
AlignConsecutiveDeclarations: AcrossComments
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveMacros: AcrossComments
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignConsecutiveBitFields: true
AlignConsecutiveMacros: true
AlignArrayOfStructures: Right
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
@ -30,7 +30,7 @@ BreakBeforeTernaryOperators: false
BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: false
ColumnLimit: 120
ColumnLimit: 100
ContinuationIndentWidth: 4
IncludeBlocks: Regroup

View File

@ -28,7 +28,7 @@
* can be passed via the mailbox */
volatile unsigned int __attribute__((aligned(16))) mbox[36];
unsigned int width, height, pitch, bpp, rgb;
unsigned int width, height, pitch, bpp, rgb;
unsigned char *fb;
void pixel_draw(int x, int y, int r, int g, int b) {
@ -38,7 +38,8 @@ void pixel_draw(int x, int y, int r, int g, int b) {
}
unsigned int mbox_call(unsigned char ch) {
unsigned int m = ((unsigned int)((long)&mbox) & ~0xF) | (ch & 0xF); /* 28-bit address (MSB), 4-bit value (LSB) */
unsigned int m = ((unsigned int)((long)&mbox) & ~0xF)
| (ch & 0xF); /* 28-bit address (MSB), 4-bit value (LSB) */
while (1)
if (!(mmio_read(MBOX_STATUS) & MBOX_FULL))

View File

@ -32,15 +32,15 @@ fdt_prop fdt_get_prop(uint32_t *addr) {
}
uint32_t *fdt_get_addr(const char *path) {
const char *fdt_strings = (char *)fdt + SWAP_UINT32(fdt->off_dt_strings);
uint32_t *fdt_struct = (uint32_t *)fdt + SWAP_UINT32(fdt->off_dt_struct);
const char *fdt_strings = (char *)fdt + SWAP_UINT32(fdt->off_dt_strings);
uint32_t *fdt_struct = (uint32_t *)fdt + SWAP_UINT32(fdt->off_dt_struct);
const uint32_t struct_size = SWAP_UINT32(fdt->size_dt_struct);
uint32_t *struct_ptr = fdt_struct;
uint32_t name_length = 0;
uint32_t prop_length = 0;
uint32_t prop_name_off = 0;
uint32_t *lastaddr = 0;
uint32_t *struct_ptr = fdt_struct;
uint32_t name_length = 0;
uint32_t prop_length = 0;
uint32_t prop_name_off = 0;
uint32_t *lastaddr = 0;
char path_copy[strlen(path) + 1];
strcpy(path_copy, path);
@ -98,17 +98,17 @@ uint32_t *fdt_get_addr(const char *path) {
}
void print_fdt() {
const char *fdt_strings = (char *)fdt + SWAP_UINT32(fdt->off_dt_strings);
uint32_t *fdt_struct = (uint32_t *)fdt + SWAP_UINT32(fdt->off_dt_struct);
const char *fdt_strings = (char *)fdt + SWAP_UINT32(fdt->off_dt_strings);
uint32_t *fdt_struct = (uint32_t *)fdt + SWAP_UINT32(fdt->off_dt_struct);
const uint32_t struct_size = SWAP_UINT32(fdt->size_dt_struct);
uint32_t *struct_ptr = fdt_struct;
uint32_t name_length = 0;
uint32_t prop_length = 0;
uint32_t prop_name_off = 0;
char intstr[10];
uint8_t tab_count = 0;
uint8_t first_elem = 0;
uint32_t *struct_ptr = fdt_struct;
uint32_t name_length = 0;
uint32_t prop_length = 0;
uint32_t prop_name_off = 0;
char intstr[10];
uint8_t tab_count = 0;
uint8_t first_elem = 0;
while (struct_ptr < fdt_struct + struct_size) {
/* Read token */

View File

@ -23,7 +23,10 @@ void hcf() {
}
void delay(int32_t count) {
asm("__delay_%=: subs %[count], %[count], #1; bne __delay_%=\n" : "=r"(count) : [count] "0"(count) : "cc");
asm("__delay_%=: subs %[count], %[count], #1; bne __delay_%=\n"
: "=r"(count)
: [count] "0"(count)
: "cc");
}
uint32_t mmio_read(uint64_t reg) {

View File

@ -34,22 +34,22 @@
#define __LLONG_MAX 0x7fffffffffffffffLL
#define __ULLONG_MAX 0xffffffffffffffffULL
typedef unsigned wint_t;
typedef int blksize_t;
typedef unsigned wint_t;
typedef int blksize_t;
typedef unsigned int nlink_t;
typedef float float_t;
typedef double double_t;
typedef int size_t;
typedef float float_t;
typedef double double_t;
typedef int size_t;
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long int64_t;
typedef unsigned long uint64_t;
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef long int64_t;
typedef unsigned long uint64_t;
typedef long intptr_t;
typedef unsigned long uintptr_t;
#endif

View File

@ -19,7 +19,8 @@
#ifndef _ASAGIRI_FDT_H
#define _ASAGIRI_FDT_H
#define SWAP_UINT32(x) (((x) >> 24) | (((x)&0x00FF0000) >> 8) | (((x)&0x0000FF00) << 8) | ((x) << 24))
#define SWAP_UINT32(x) \
(((x) >> 24) | (((x)&0x00FF0000) >> 8) | (((x)&0x0000FF00) << 8) | ((x) << 24))
#include <bits/alltypes.h>
@ -37,16 +38,16 @@ typedef struct fdt_header {
} fdt_header;
typedef struct fdt_prop {
uint32_t nameoff;
uint32_t len;
uint32_t nameoff;
uint32_t len;
uint32_t *data;
} fdt_prop;
enum { FDT_BEGIN_NODE = 0x1, FDT_END_NODE = 0x2, FDT_PROP = 0x3, FDT_NOP = 0x4, FDT_END = 0x9 };
fdt_prop fdt_get_prop(uint32_t *);
fdt_prop fdt_get_prop(uint32_t *);
uint32_t *fdt_get_addr(const char *);
void fdt_init();
void print_fdt();
void fdt_init();
void print_fdt();
#endif

View File

@ -23,9 +23,9 @@
#define asm __asm__ __volatile__
void hcf();
void delay(int32_t);
void hcf();
void delay(int32_t);
uint32_t mmio_read(uint64_t);
void mmio_write(uint64_t, uint32_t);
void mmio_write(uint64_t, uint32_t);
#endif

View File

@ -19,9 +19,9 @@
#ifndef _ASAGIRI_UART_H
#define _ASAGIRI_UART_H
void uart_init();
void uart_putc(unsigned char);
void uart_init();
void uart_putc(unsigned char);
unsigned char uart_getc();
void uart_puts(const char *);
void uart_puts(const char *);
#endif

View File

@ -69,7 +69,9 @@ void uart_init() {
/* Enable FIFO & 8 bit data transmission (1 stop bit, no parity). */
mmio_write(UART_LCRH, (1 << 4) | (1 << 5) | (1 << 6));
/* Mask all interrupts. */
mmio_write(UART_IMSC, (1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10));
mmio_write(UART_IMSC,
(1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9)
| (1 << 10));
/* Enable UART0, receive & transfer part of UART. */
mmio_write(UART_CR, 1 | (1 << 8) | (1 << 9));
}

View File

@ -6,7 +6,7 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -19,19 +19,19 @@
#ifndef _ASAGIRI_ALLTYPES_H
#define _ASAGIRI_ALLTYPES_H
#define _Addr long
#define _Addr long
#define _Int64 long
#define _Reg long
#define _Reg long
#define __CHAR_MAX 0x7f
#define __UCHAR_MAX 0xff
#define __SHRT_MAX 0x7fff
#define __USHRT_MAX 0xffff
#define __INT_MAX 0x7fffffff
#define __UINT_MAX 0xffffffff
#define __LONG_MAX 0x7fffffffffffffffL
#define __ULONG_MAX 0xffffffffffffffffUL
#define __LLONG_MAX 0x7fffffffffffffffLL
#define __CHAR_MAX 0x7f
#define __UCHAR_MAX 0xff
#define __SHRT_MAX 0x7fff
#define __USHRT_MAX 0xffff
#define __INT_MAX 0x7fffffff
#define __UINT_MAX 0xffffffff
#define __LONG_MAX 0x7fffffffffffffffL
#define __ULONG_MAX 0xffffffffffffffffUL
#define __LLONG_MAX 0x7fffffffffffffffLL
#define __ULLONG_MAX 0xffffffffffffffffULL
typedef unsigned wint_t;

View File

@ -6,7 +6,7 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -16,10 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#define va_copy(d,s) __builtin_va_copy(d,s)
#define va_start(v, l) __builtin_va_start(v, l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v, l) __builtin_va_arg(v, l)
#define va_copy(d, s) __builtin_va_copy(d, s)
typedef __builtin_va_list va_list;
typedef __builtin_va_list __isoc_va_list;

View File

@ -23,8 +23,8 @@
#define asm __asm__ __volatile__
void hcf();
void outb(uint16_t, uint8_t);
void hcf();
void outb(uint16_t, uint8_t);
uint8_t inb(uint16_t);
#endif

View File

@ -21,6 +21,7 @@
#include <stdlib.h>
#define assert(val) ((val) ? (void)0 : (printf("ASSERTION FAILED, " __FILE__ ":%d: " #val "\n", __LINE__), abort()))
#define assert(val) \
((val) ? (void)0 : (printf("ASSERTION FAILED, " __FILE__ ":%d: " #val "\n", __LINE__), abort()))
#endif

View File

@ -6,7 +6,7 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

View File

@ -23,6 +23,6 @@
#include <sys/cdefs.h>
double pow(double x, double y);
int abs(int x);
int abs(int x);
#endif

View File

@ -24,6 +24,6 @@
char *itoa(int value, char *buffer, int base);
char *uitoa(uint32_t value, char *buffer, int base);
void abort();
void abort();
#endif

View File

@ -21,8 +21,8 @@ double pow(double x, double y) {
return 1;
}
int count = 0;
double out = 1;
int count = 0;
double out = 1;
while (count < y) {
out = out * x;
count++;

View File

@ -64,7 +64,7 @@ int printf(const char *restrict format, ...) {
const char *format_begun_at = format++;
size_t len = 0;
char buf[11];
char buf[11];
switch (*format) {
case 'c':

View File

@ -53,8 +53,8 @@ char *itoa(int value, char *buffer, int base) {
buffer[index] = 0;
/* Reverse the buffer */
uint8_t len = index;
char temp = 0;
uint8_t len = index;
char temp = 0;
for (uint8_t i = 0; i < len >> 1; ++i) {
temp = buffer[i];
buffer[i] = buffer[len - i - 1];

View File

@ -41,8 +41,8 @@ char *uitoa(uint32_t value, char *buffer, int base) {
buffer[index] = 0;
/* Reverse the buffer */
uint8_t len = index;
char temp = 0;
uint8_t len = index;
char temp = 0;
for (uint8_t i = 0; i < len >> 1; ++i) {
temp = buffer[i];
buffer[i] = buffer[len - i - 1];

View File

@ -19,7 +19,7 @@
#include <string.h>
void *memcpy(void *restrict dstptr, const void *srcptr, size_t size) {
unsigned char *dst = (unsigned char *)dstptr;
unsigned char *dst = (unsigned char *)dstptr;
const unsigned char *src = (const unsigned char *)srcptr;
for (size_t i = 0; i < size; i++) {
dst[i] = src[i];

View File

@ -19,7 +19,7 @@
#include <string.h>
void *memmove(void *dstptr, const void *srcptr, size_t size) {
unsigned char *dst = (unsigned char *)dstptr;
unsigned char *dst = (unsigned char *)dstptr;
const unsigned char *src = (const unsigned char *)srcptr;
if (dst < src) {

View File

@ -23,17 +23,24 @@ EFI_FILE_PROTOCOL *EFIAPI OpenFile(CHAR16 *path) {
/* Locate handle supporting SFSP */
EFI_HANDLE *handles;
UINTN handleCnt;
EFI_GUID sfspGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
UINTN handleCnt;
EFI_GUID sfspGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
status = uefi_call_wrapper(*(void **)&BS->LocateHandleBuffer, 5, ByProtocol, &sfspGuid, NULL, &handleCnt, &handles);
status = uefi_call_wrapper(*(void **)&BS->LocateHandleBuffer,
5,
ByProtocol,
&sfspGuid,
NULL,
&handleCnt,
&handles);
PRINT_ERR(status);
/* TODO: Might need to iterate on all handles if
* multiple FAT32 images are connected
* Open Filesystem */
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs = NULL;
status = uefi_call_wrapper(*(void **)&BS->HandleProtocol, 3, handles[0], &sfspGuid, (VOID **)&fs);
status =
uefi_call_wrapper(*(void **)&BS->HandleProtocol, 3, handles[0], &sfspGuid, (VOID **)&fs);
PRINT_ERR(status);
/* Open ROOTDIR */
@ -42,7 +49,13 @@ EFI_FILE_PROTOCOL *EFIAPI OpenFile(CHAR16 *path) {
PRINT_ERR(status);
/* Open file */
status = uefi_call_wrapper(*(void **)&root->Open, 5, root, &root, path, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
status = uefi_call_wrapper(*(void **)&root->Open,
5,
root,
&root,
path,
EFI_FILE_MODE_READ,
EFI_FILE_READ_ONLY);
PRINT_ERR(status);
return root;

View File

@ -27,18 +27,18 @@
Print(L"%a:%d error: %r\n", __FILE__, __LINE__, status);
typedef struct {
UINTN memoryMapSize;
UINTN memoryMapSize;
EFI_MEMORY_DESCRIPTOR *memoryMap;
UINTN mapKey;
UINTN descriptorSize;
UINT32 descriptorVersion;
UINTN mapKey;
UINTN descriptorSize;
UINT32 descriptorVersion;
} UEFIMemoryMap;
EFI_STATUS EFIAPI SetMemoryMap(UEFIMemoryMap *);
EFI_STATUS EFIAPI SetMemoryMap(UEFIMemoryMap *);
EFI_FILE_PROTOCOL *EFIAPI OpenFile(CHAR16 *path);
EFI_STATUS EFIAPI SetPos(EFI_FILE_PROTOCOL *, UINTN);
EFI_STATUS EFIAPI Read(EFI_FILE_PROTOCOL *, UINTN *, VOID *);
EFI_STATUS EFIAPI Close(EFI_FILE_PROTOCOL *);
EFI_STATUS EFIAPI SetPos(EFI_FILE_PROTOCOL *, UINTN);
EFI_STATUS EFIAPI Read(EFI_FILE_PROTOCOL *, UINTN *, VOID *);
EFI_STATUS EFIAPI Close(EFI_FILE_PROTOCOL *);
/* elf.h */
#define EI_NIDENT (16)
@ -50,27 +50,27 @@ typedef uint64_t Elf64_Xword;
typedef struct {
unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
Elf64_Half e_type; /* Object file type */
Elf64_Half e_machine; /* Architecture */
Elf64_Word e_version; /* Object file version */
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Word e_flags; /* Processor-specific flags */
Elf64_Half e_ehsize; /* ELF header size in bytes */
Elf64_Half e_phentsize; /* Program header table entry size */
Elf64_Half e_phnum; /* Program header table entry count */
Elf64_Half e_shentsize; /* Section header table entry size */
Elf64_Half e_shnum; /* Section header table entry count */
Elf64_Half e_shstrndx; /* Section header string table index */
Elf64_Half e_type; /* Object file type */
Elf64_Half e_machine; /* Architecture */
Elf64_Word e_version; /* Object file version */
Elf64_Addr e_entry; /* Entry point virtual address */
Elf64_Off e_phoff; /* Program header table file offset */
Elf64_Off e_shoff; /* Section header table file offset */
Elf64_Word e_flags; /* Processor-specific flags */
Elf64_Half e_ehsize; /* ELF header size in bytes */
Elf64_Half e_phentsize; /* Program header table entry size */
Elf64_Half e_phnum; /* Program header table entry count */
Elf64_Half e_shentsize; /* Section header table entry size */
Elf64_Half e_shnum; /* Section header table entry count */
Elf64_Half e_shstrndx; /* Section header string table index */
} Elf64_Ehdr;
typedef struct {
Elf64_Word p_type; /* Segment type */
Elf64_Word p_flags; /* Segment flags */
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Word p_type; /* Segment type */
Elf64_Word p_flags; /* Segment flags */
Elf64_Off p_offset; /* Segment file offset */
Elf64_Addr p_vaddr; /* Segment virtual address */
Elf64_Addr p_paddr; /* Segment physical address */
Elf64_Xword p_filesz; /* Segment size in file */
Elf64_Xword p_memsz; /* Segment size in memory */
Elf64_Xword p_align; /* Segment alignment */

View File

@ -36,7 +36,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
EFI_FILE_PROTOCOL *kernelFile = OpenFile(L"yukari");
/* Read ELF Header */
UINTN EHeaderSize = sizeof(Elf64_Ehdr);
UINTN EHeaderSize = sizeof(Elf64_Ehdr);
Elf64_Ehdr *kernelElfHeader = AllocatePool(EHeaderSize);
SetPos(kernelFile, 0);
@ -45,7 +45,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
Print(L"ELF Header Loc: 0x%x\n", kernelElfHeader);
/* Read ELF Prog Header */
UINTN PHeaderSize = kernelElfHeader->e_phnum * kernelElfHeader->e_phentsize;
UINTN PHeaderSize = kernelElfHeader->e_phnum * kernelElfHeader->e_phentsize;
Elf64_Phdr *kernelProgHeader = AllocatePool(PHeaderSize);
SetPos(kernelFile, kernelElfHeader->e_phoff);
@ -57,12 +57,16 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
for (UINT16 i = 0; i < kernelElfHeader->e_phnum; ++i) {
if (kernelProgHeader[i].p_type == 1) {
/* Get count of pages needed */
int pages = (kernelProgHeader[i].p_memsz + EFI_PAGE_SIZE - 1) / EFI_PAGE_SIZE;
int pages = (kernelProgHeader[i].p_memsz + EFI_PAGE_SIZE - 1) / EFI_PAGE_SIZE;
/* Get segment address */
Elf64_Addr segment = kernelProgHeader[i].p_paddr;
/* Allocate pages to the segment address */
status =
uefi_call_wrapper(*(void **)&BS->AllocatePages, 4, AllocateAddress, EfiLoaderData, pages, &segment);
status = uefi_call_wrapper(*(void **)&BS->AllocatePages,
4,
AllocateAddress,
EfiLoaderData,
pages,
&segment);
PRINT_ERR(status);
/* Write program segment to the allocated address */
UINTN fileSize = kernelProgHeader[i].p_filesz;