Skip to content

Commit

Permalink
style: yet another style unifying change
Browse files Browse the repository at this point in the history
* Set AlignConsecutiveDeclarations to false to disable declarations
  alignment.
* Disable clang-format for some definitions and declaration that I
  find more readable now.

The modifications are a result of running the GitHub's clang-format
action workflow locally and patch all outstanding files:

docker run --rm --workdir /src -v $(pwd):/src clang-format-lint \
    --clang-format-executable /clang-format/clang-format10 -r   \
    --exclude .git $(find . -name \*.c -or -name \*.h -print) | patch -p1

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 17, 2020
1 parent 3274bd8 commit d3f5f39
Show file tree
Hide file tree
Showing 32 changed files with 313 additions and 345 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
Expand Down
17 changes: 8 additions & 9 deletions arch/x86/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <console.h>
#include <ktf.h>
#include <lib.h>
#include <page.h>
#include <console.h>
#include <processor.h>

#include <apic.h>

apic_mode_t apic_mode = APIC_MODE_UNKNOWN;

static const char *apic_mode_names[] = {
[APIC_MODE_UNKNOWN] = "Unknown",
[APIC_MODE_NONE] = "None",
[APIC_MODE_DISABLED] = "Disabled",
[APIC_MODE_XAPIC] = "XAPIC",
[APIC_MODE_X2APIC] = "X2APIC",
[APIC_MODE_UNKNOWN] = "Unknown", [APIC_MODE_NONE] = "None",
[APIC_MODE_DISABLED] = "Disabled", [APIC_MODE_XAPIC] = "XAPIC",
[APIC_MODE_X2APIC] = "X2APIC",
};

int init_apic(enum apic_mode mode) {
Expand Down Expand Up @@ -71,8 +69,8 @@ int init_apic(enum apic_mode mode) {
}
}

printk("Initializing APIC mode: %s -> %s\n",
apic_mode_names[apic_mode], apic_mode_names[mode]);
printk("Initializing APIC mode: %s -> %s\n", apic_mode_names[apic_mode],
apic_mode_names[mode]);

/* Disable APIC */
apic_base &= ~(APIC_BASE_EXTD | APIC_BASE_ENABLE);
Expand All @@ -90,7 +88,8 @@ int init_apic(enum apic_mode mode) {
* X2APIC uses MSRs for accesses, so no mapping needed.
*/
if (apic_mode == APIC_MODE_XAPIC)
vmap(_ptr(DEFAULT_APIC_BASE), paddr_to_mfn(DEFAULT_APIC_BASE), PAGE_ORDER_4K, L1_PROT);
vmap(_ptr(DEFAULT_APIC_BASE), paddr_to_mfn(DEFAULT_APIC_BASE), PAGE_ORDER_4K,
L1_PROT);

apic_write(APIC_SPIV, APIC_SPIV_APIC_ENABLED | 0xff);
return 0;
Expand Down
28 changes: 13 additions & 15 deletions arch/x86/boot/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ktf.h>
#include <string.h>
#include <console.h>
#include <ktf.h>
#include <multiboot.h>
#include <string.h>

static multiboot_info_t *multiboot_info;

static multiboot_memory_map_t *multiboot_mmap;
static unsigned multiboot_mmap_num;

static const char *multiboot_region_type_name[] = {
[MULTIBOOT_MEMORY_UNDEFINED] = "Undefined",
[MULTIBOOT_MEMORY_AVAILABLE] = "Available",
[MULTIBOOT_MEMORY_RESERVED] = "Reserved",
[MULTIBOOT_MEMORY_UNDEFINED] = "Undefined",
[MULTIBOOT_MEMORY_AVAILABLE] = "Available",
[MULTIBOOT_MEMORY_RESERVED] = "Reserved",
[MULTIBOOT_MEMORY_ACPI_RECLAIMABLE] = "ACPI Reclaimable",
[MULTIBOOT_MEMORY_NVS] = "NVS",
[MULTIBOOT_MEMORY_BADRAM] = "Bad RAM",
[MULTIBOOT_MEMORY_NVS] = "NVS",
[MULTIBOOT_MEMORY_BADRAM] = "Bad RAM",
};

static inline bool has_mbi_flag(unsigned flag) {
Expand All @@ -52,20 +52,19 @@ void display_multiboot_mmap(void) {
printk("\nPhysical Memory Map\n");

if (!has_mbi_flag(MULTIBOOT_INFO_MEM_MAP)) {
printk("REGION: [0x%016lx - 0x%016lx] Lower memory\n",
0, multiboot_info->mem_lower * KB(1));
printk("REGION: [0x%016lx - 0x%016lx] Upper memory\n",
MB(1), MB(1) + (multiboot_info->mem_upper * KB(1)));
printk("REGION: [0x%016lx - 0x%016lx] Lower memory\n", 0,
multiboot_info->mem_lower * KB(1));
printk("REGION: [0x%016lx - 0x%016lx] Upper memory\n", MB(1),
MB(1) + (multiboot_info->mem_upper * KB(1)));
return;
}

for (int i = 0; i < multiboot_mmap_num; i++) {
multiboot_memory_map_t *entry = &multiboot_mmap[i];

if (entry->type != MULTIBOOT_MEMORY_UNDEFINED) {
printk("REGION: [0x%016lx - 0x%016lx] %s\n",
entry->addr, entry->addr + entry->len,
multiboot_region_type_name[entry->type]);
printk("REGION: [0x%016lx - 0x%016lx] %s\n", entry->addr,
entry->addr + entry->len, multiboot_region_type_name[entry->type]);
}
}
}
Expand Down Expand Up @@ -114,7 +113,6 @@ int mbi_get_avail_memory_range(unsigned index, addr_range_t *r) {
r->end = _ptr(_paddr(r->start + entry->len));
return 0;
}

}
}
else if (has_mbi_flag(MULTIBOOT_INFO_MEMORY)) {
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/boot/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ktf.h>
#include <asm-macros.h>
#include <ktf.h>
#include <segment.h>

gdt_desc_t boot_gdt[] __aligned(16) __data_init = {
/* clang-format off */
[GDT_NULL].desc = GDT_ENTRY(0x0, 0x0, 0x0),
[GDT_KERN_CS32].desc = GDT_ENTRY(DESC_FLAGS(GR, SZ, P, DPL0, S, CODE, R, A), 0x0, 0xfffff),
[GDT_KERN_DS32].desc = GDT_ENTRY(DESC_FLAGS(GR, SZ, P, DPL0, S, DATA, W, A), 0x0, 0xfffff),
[GDT_KERN_CS64].desc = GDT_ENTRY(DESC_FLAGS(GR, L, P, DPL0, S, CODE, R, A), 0x0, 0x00000),
/* clang-format on */
};

gdt_ptr_t boot_gdt_ptr __data_init = {
Expand Down
24 changes: 11 additions & 13 deletions arch/x86/pagetables.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <console.h>
#include <ktf.h>
#include <page.h>
#include <console.h>
#include <setup.h>
#include <string.h>
#include <pagetable.h>
#include <setup.h>
#include <spinlock.h>
#include <string.h>

cr3_t __data_init cr3;

static inline const char *dump_pte_flags(char *buf, size_t size, pte_t pte) {
/* clang-format off */
snprintf(buf, size, "%c %c%c%c%c%c%c%c%c%c",
pte.NX ? 'X' : '-',
pte.G ? 'G' : '-',
Expand All @@ -44,6 +45,7 @@ static inline const char *dump_pte_flags(char *buf, size_t size, pte_t pte) {
pte.US ? 'U' : 'S',
pte.RW ? 'W' : 'R',
pte.P ? 'P' : '-');
/* clang-format on */

return buf;
}
Expand Down Expand Up @@ -76,8 +78,8 @@ static inline void dump_page_table(void *table, int level) {

dump_pte_flags(flags, sizeof(flags), pt[i]);
paddr_t paddr = mfn_to_paddr(pt[i].mfn);
printk("[%p] %*s%d[%03u] paddr: 0x%016lx flags: %s\n",
virt_to_paddr(pt), (4 - level) * 2, "L", level, i, paddr, flags);
printk("[%p] %*s%d[%03u] paddr: 0x%016lx flags: %s\n", virt_to_paddr(pt),
(4 - level) * 2, "L", level, i, paddr, flags);

if (level == 2 && ((pde_t *) pt)[i].PS)
continue;
Expand Down Expand Up @@ -144,7 +146,7 @@ void *vmap(void *va, mfn_t mfn, unsigned int order, unsigned long flags) {

spin_lock(&lock);

#if defined (__x86_64__)
#if defined(__x86_64__)
l3t_mfn = get_pgentry_mfn(get_cr3_mfn(&cr3), l4_table_index(va), L4_PROT_USER);
#else
l3t_mfn = get_cr3_mfn(&cr3);
Expand Down Expand Up @@ -177,20 +179,16 @@ void *vmap(void *va, mfn_t mfn, unsigned int order, unsigned long flags) {
return va;
}

void *vunmap(void *va, unsigned int order) {
return vmap(va, MFN_INVALID, order, 0x0);
}
void *vunmap(void *va, unsigned int order) { return vmap(va, MFN_INVALID, order, 0x0); }

void *kmap(mfn_t mfn, unsigned int order, unsigned long flags) {
return vmap(mfn_to_virt_kern(mfn), mfn, order, flags);
}

void *kunmap(void *va, unsigned int order) {
return vmap(va, MFN_INVALID, order, 0x0);
}
void *kunmap(void *va, unsigned int order) { return vmap(va, MFN_INVALID, order, 0x0); }

void init_pagetables(void) {
for_each_memory_range(r) {
for_each_memory_range (r) {
switch (r->base) {
case VIRT_IDENT_BASE:
for (mfn_t mfn = virt_to_mfn(r->start); mfn < virt_to_mfn(r->end); mfn++)
Expand Down
Loading

0 comments on commit d3f5f39

Please sign in to comment.