From fd5780610bf8c07dd02e28665ba6791c2cfbeda9 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sun, 25 Mar 2018 14:06:25 -0700 Subject: [PATCH] Format using clang-format --- .clang-format | 21 ++++++++++++++ src/boot/console.c | 64 +++++++++++++++++------------------------ src/boot/console.h | 8 +++--- src/boot/loader.c | 29 +++++++++---------- src/boot/main.c | 30 +++++++------------ src/boot/memory.c | 61 ++++++++++++++++++++------------------- src/boot/memory.h | 15 +++------- src/boot/utility.c | 7 +++-- src/boot/utility.h | 40 ++++++++++++-------------- src/modules/main/main.c | 4 ++- src/modules/main/vga.c | 41 +++++++++++++++++--------- src/modules/main/vga.h | 14 +++++---- 12 files changed, 173 insertions(+), 161 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a598150 --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +ColumnLimit: 100 +IndentWidth: 4 +TabWidth: 4 +UseTab: Always + +AccessModifierOffset: -4 + +AlignEscapedNewlinesLeft: true + +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true + +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true + +BreakBeforeBraces: Linux diff --git a/src/boot/console.c b/src/boot/console.c index 31e3165..0c6cfe0 100644 --- a/src/boot/console.c +++ b/src/boot/console.c @@ -9,7 +9,7 @@ UINTN ROWS = 0; UINTN COLS = 0; EFI_STATUS -con_initialize (const CHAR16 *version) +con_initialize(const CHAR16 *version) { EFI_STATUS status; @@ -18,14 +18,12 @@ con_initialize (const CHAR16 *version) EFI_GRAPHICS_OUTPUT_PROTOCOL *gfx_out_proto; EFI_GUID gfx_out_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - status = ST->BootServices->LocateProtocol( - &gfx_out_guid, NULL, (void**)&gfx_out_proto); + status = ST->BootServices->LocateProtocol(&gfx_out_guid, NULL, (void **)&gfx_out_proto); CHECK_EFI_STATUS_OR_RETURN(status, "LocateProtocol gfx"); const uint32_t modes = gfx_out_proto->Mode->MaxMode; - uint32_t res = - gfx_out_proto->Mode->Info->HorizontalResolution * - gfx_out_proto->Mode->Info->VerticalResolution; + uint32_t res = gfx_out_proto->Mode->Info->HorizontalResolution * + gfx_out_proto->Mode->Info->VerticalResolution; uint32_t best = gfx_out_proto->Mode->Mode; for (uint32_t i = 0; i < modes; ++i) { @@ -35,13 +33,10 @@ con_initialize (const CHAR16 *version) CHECK_EFI_STATUS_OR_RETURN(status, "QueryMode"); #ifdef MAX_HRES - if (info->HorizontalResolution > MAX_HRES) - continue; + if (info->HorizontalResolution > MAX_HRES) continue; #endif - const uint32_t new_res = - info->HorizontalResolution * - info->VerticalResolution; + const uint32_t new_res = info->HorizontalResolution * info->VerticalResolution; if (new_res > res) { best = i; @@ -52,69 +47,64 @@ con_initialize (const CHAR16 *version) status = gfx_out_proto->SetMode(gfx_out_proto, best); CHECK_EFI_STATUS_OR_RETURN(status, "SetMode %d/%d", best, modes); - status = ST->ConOut->QueryMode( - ST->ConOut, - ST->ConOut->Mode->Mode, - &COLS, &ROWS); + status = ST->ConOut->QueryMode(ST->ConOut, ST->ConOut->Mode->Mode, &COLS, &ROWS); CHECK_EFI_STATUS_OR_RETURN(status, "QueryMode"); status = ST->ConOut->ClearScreen(ST->ConOut); CHECK_EFI_STATUS_OR_RETURN(status, "ClearScreen"); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTCYAN); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"Popcorn loader "); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"Popcorn loader "); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTMAGENTA); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)version); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)version); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L" booting...\r\n\n"); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L" booting...\r\n\n"); con_status_begin(L"Setting console display mode: "); - Print(L"\n %ux%u (%ux%u chars)", - gfx_out_proto->Mode->Info->HorizontalResolution, - gfx_out_proto->Mode->Info->VerticalResolution, - ROWS, COLS); + Print(L"\n %ux%u (%ux%u chars)", gfx_out_proto->Mode->Info->HorizontalResolution, + gfx_out_proto->Mode->Info->VerticalResolution, ROWS, COLS); con_status_ok(); return status; } void -con_status_begin (const CHAR16 *message) +con_status_begin(const CHAR16 *message) { ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)message); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)message); } void -con_status_ok () +con_status_ok() { UINTN row = ST->ConOut->Mode->CursorRow; ST->ConOut->SetCursorPosition(ST->ConOut, 4, ++row); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"["); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"["); ST->ConOut->SetAttribute(ST->ConOut, EFI_GREEN); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L" ok "); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L" ok "); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"]\r"); - ST->ConOut->SetCursorPosition(ST->ConOut, 0, ++row+1); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"]\r"); + ST->ConOut->SetCursorPosition(ST->ConOut, 0, ++row + 1); } void -con_status_fail (const CHAR16 *error) +con_status_fail(const CHAR16 *error) { UINTN row = ST->ConOut->Mode->CursorRow; - ST->ConOut->SetCursorPosition(ST->ConOut, COLS-8, row); + ST->ConOut->SetCursorPosition(ST->ConOut, COLS - 8, row); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"["); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"["); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTRED); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"failed"); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"failed"); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)L"]\r"); - ST->ConOut->SetCursorPosition(ST->ConOut, 2, row+1); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)L"]\r"); + ST->ConOut->SetCursorPosition(ST->ConOut, 2, row + 1); ST->ConOut->SetAttribute(ST->ConOut, EFI_RED); - ST->ConOut->OutputString(ST->ConOut, (CHAR16*)error); - ST->ConOut->SetCursorPosition(ST->ConOut, 0, row+2); + ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)error); + ST->ConOut->SetCursorPosition(ST->ConOut, 0, row + 2); ST->ConOut->SetAttribute(ST->ConOut, EFI_LIGHTGRAY); } diff --git a/src/boot/console.h b/src/boot/console.h index 4e4129a..83f7b8d 100644 --- a/src/boot/console.h +++ b/src/boot/console.h @@ -1,7 +1,7 @@ #pragma once #include -EFI_STATUS con_initialize (const CHAR16 *version); -void con_status_begin (const CHAR16 *message); -void con_status_ok (); -void con_status_fail (const CHAR16 *error); +EFI_STATUS con_initialize(const CHAR16 *version); +void con_status_begin(const CHAR16 *message); +void con_status_ok(); +void con_status_fail(const CHAR16 *error); diff --git a/src/boot/loader.c b/src/boot/loader.c index e18b324..d2dfbd0 100644 --- a/src/boot/loader.c +++ b/src/boot/loader.c @@ -3,7 +3,9 @@ static CHAR16 kernel_name[] = KERNEL_FILENAME; -EFI_STATUS loader_load_kernel(void **kernel_image, uint64_t *length) { +EFI_STATUS +loader_load_kernel(void **kernel_image, uint64_t *length) +{ if (kernel_image == 0 || length == 0) CHECK_EFI_STATUS_OR_RETURN(EFI_INVALID_PARAMETER, "NULL kernel_image or length pointer"); @@ -12,15 +14,13 @@ EFI_STATUS loader_load_kernel(void **kernel_image, uint64_t *length) { EFI_HANDLE *handles = NULL; UINTN handleCount = 0; - status = ST->BootServices->LocateHandleBuffer( - ByProtocol, &guid, NULL, &handleCount, &handles); + status = ST->BootServices->LocateHandleBuffer(ByProtocol, &guid, NULL, &handleCount, &handles); CHECK_EFI_STATUS_OR_RETURN(status, "LocateHandleBuffer"); - for (unsigned i=0; iBootServices->HandleProtocol( - handles[i], &guid, (void**)&fileSystem); + status = ST->BootServices->HandleProtocol(handles[i], &guid, (void **)&fileSystem); CHECK_EFI_STATUS_OR_RETURN(status, "HandleProtocol"); EFI_FILE_PROTOCOL *root = NULL; @@ -28,12 +28,8 @@ EFI_STATUS loader_load_kernel(void **kernel_image, uint64_t *length) { CHECK_EFI_STATUS_OR_RETURN(status, "OpenVolume"); EFI_FILE_PROTOCOL *file = NULL; - status = root->Open( - root, - &file, - kernel_name, - EFI_FILE_MODE_READ, - EFI_FILE_READ_ONLY|EFI_FILE_HIDDEN|EFI_FILE_SYSTEM); + status = root->Open(root, &file, kernel_name, EFI_FILE_MODE_READ, + EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM); if (!EFI_ERROR(status)) { void *buffer = NULL; @@ -46,22 +42,23 @@ EFI_STATUS loader_load_kernel(void **kernel_image, uint64_t *length) { status = file->GetInfo(file, &file_info_guid, &buffer_size, buffer); CHECK_EFI_STATUS_OR_RETURN(status, "Getting kernel file info"); - buffer_size = ((EFI_FILE_INFO*)buffer)->FileSize; + buffer_size = ((EFI_FILE_INFO *)buffer)->FileSize; status = ST->BootServices->FreePool(buffer); CHECK_EFI_STATUS_OR_RETURN(status, "Freeing kernel file info memory"); UINTN page_count = ((buffer_size - 1) / 0x1000) + 1; EFI_PHYSICAL_ADDRESS addr = KERNEL_PHYS_ADDRESS; // Try to load the kernel in at 1MiB - EFI_MEMORY_TYPE mem_type = KERNEL_MEMTYPE; // Special value to tell the kernel it's here + EFI_MEMORY_TYPE mem_type = KERNEL_MEMTYPE; // Special value to tell the kernel it's here status = ST->BootServices->AllocatePages(AllocateAddress, mem_type, page_count, &addr); if (status == EFI_NOT_FOUND) { // couldn't get the address we wanted, try loading the kernel anywhere - status = ST->BootServices->AllocatePages(AllocateAnyPages, mem_type, page_count, &addr); + status = + ST->BootServices->AllocatePages(AllocateAnyPages, mem_type, page_count, &addr); } CHECK_EFI_STATUS_OR_RETURN(status, "Allocating kernel pages"); - buffer = (void*)addr; + buffer = (void *)addr; status = file->Read(file, &buffer_size, buffer); CHECK_EFI_STATUS_OR_RETURN(status, "Reading kernel file"); diff --git a/src/boot/main.c b/src/boot/main.c index 023d2bb..0b172a7 100644 --- a/src/boot/main.c +++ b/src/boot/main.c @@ -7,7 +7,7 @@ #include "utility.h" #ifndef GIT_VERSION - #define GIT_VERSION L"no version" +#define GIT_VERSION L"no version" #endif #define KERNEL_MAGIC 0x600db007 @@ -24,7 +24,7 @@ struct kernel_version { #pragma pack(pop) EFI_STATUS -efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) +efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { EFI_STATUS status; @@ -45,19 +45,14 @@ efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) CHECK_EFI_STATUS_OR_FAIL(status); Print(L"\n %u bytes at 0x%x", kernel_length, kernel_image); - struct kernel_version *version = (struct kernel_version*)kernel_image; + struct kernel_version *version = (struct kernel_version *)kernel_image; if (version->magic != KERNEL_MAGIC) { Print(L"\n bad magic %x", version->magic); CHECK_EFI_STATUS_OR_FAIL(EFI_CRC_ERROR); } - Print(L"\n Kernel version %d.%d.%d %x%s", - version->major, - version->minor, - version->patch, - version->gitsha & 0x0fffffff, - version->gitsha & 0xf0000000 ? "*" : "" - ); + Print(L"\n Kernel version %d.%d.%d %x%s", version->major, version->minor, version->patch, + version->gitsha & 0x0fffffff, version->gitsha & 0xf0000000 ? "*" : ""); Print(L"\n Entrypoint %d", version->entrypoint); void (*kernel_main)() = version->entrypoint; @@ -71,29 +66,24 @@ efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) UINT32 desc_version = 0; EFI_MEMORY_DESCRIPTOR *memory_map; - status = memory_mark_address_for_update((void**)&ST); + status = memory_mark_address_for_update((void **)&ST); CHECK_EFI_STATUS_OR_FAIL(status); - status = memory_mark_address_for_update((void**)&kernel_image); + status = memory_mark_address_for_update((void **)&kernel_image); CHECK_EFI_STATUS_OR_FAIL(status); - status = memory_mark_address_for_update((void**)&kernel_main); + status = memory_mark_address_for_update((void **)&kernel_main); CHECK_EFI_STATUS_OR_FAIL(status); - status = memory_get_map(&memory_map, - &memmap_size, &memmap_key, - &desc_size, &desc_version); + status = memory_get_map(&memory_map, &memmap_size, &memmap_key, &desc_size, &desc_version); CHECK_EFI_STATUS_OR_FAIL(status); status = ST->BootServices->ExitBootServices(ImageHandle, memmap_key); CHECK_EFI_STATUS_OR_ASSERT(status, 0); - status = memory_virtualize( - memory_map, memmap_size, - desc_size, desc_version); + status = memory_virtualize(memory_map, memmap_size, desc_size, desc_version); CHECK_EFI_STATUS_OR_ASSERT(status, 0); kernel_main(); return EFI_LOAD_ERROR; } - diff --git a/src/boot/memory.c b/src/boot/memory.c index 8b6c34b..fc323d9 100644 --- a/src/boot/memory.c +++ b/src/boot/memory.c @@ -1,8 +1,8 @@ #include #include -#include "memory.h" #include "loader.h" +#include "memory.h" #include "utility.h" const UINTN PAGE_SIZE = 4096; @@ -25,63 +25,65 @@ const CHAR16 *memory_type_names[] = { L"EfiPersistentMemory", }; -static const CHAR16 *memory_type_name(UINT32 value) { - if (value >= (sizeof(memory_type_names)/sizeof(CHAR16*))) { - if (value == KERNEL_MEMTYPE) - return L"Kernel Image"; +static const CHAR16 * +memory_type_name(UINT32 value) +{ + if (value >= (sizeof(memory_type_names) / sizeof(CHAR16 *))) { + if (value == KERNEL_MEMTYPE) return L"Kernel Image"; return L"Bad Type Value"; } return memory_type_names[value]; } -void EFIAPI memory_update_addresses(EFI_EVENT UNUSED *event, void *context) { +void EFIAPI +memory_update_addresses(EFI_EVENT UNUSED *event, void *context) +{ EFI_STATUS status; status = ST->RuntimeServices->ConvertPointer(0, (void **)context); - CHECK_EFI_STATUS_OR_ASSERT(status, *((void**)context)); + CHECK_EFI_STATUS_OR_ASSERT(status, *((void **)context)); } -EFI_STATUS memory_mark_address_for_update(void **pointer) { +EFI_STATUS +memory_mark_address_for_update(void **pointer) +{ EFI_EVENT event; EFI_STATUS status; - status = ST->BootServices->CreateEvent( - EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, - TPL_CALLBACK, - (EFI_EVENT_NOTIFY)&memory_update_addresses, - (void*)pointer, - &event); + status = ST->BootServices->CreateEvent(EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, TPL_CALLBACK, + (EFI_EVENT_NOTIFY)&memory_update_addresses, + (void *)pointer, &event); CHECK_EFI_STATUS_OR_ASSERT(status, pointer); } EFI_STATUS -memory_virtualize( - EFI_MEMORY_DESCRIPTOR *memory_map, - UINTN memmap_size, - UINTN desc_size, - UINT32 desc_version) { +memory_virtualize(EFI_MEMORY_DESCRIPTOR *memory_map, UINTN memmap_size, UINTN desc_size, + UINT32 desc_version) +{ EFI_MEMORY_DESCRIPTOR *end = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)memory_map + memmap_size); EFI_MEMORY_DESCRIPTOR *d = memory_map; while (d < end) { if (d->Type == KERNEL_MEMTYPE) { - //d->VirtualStart = (EFI_VIRTUAL_ADDRESS)KERNEL_VIRT_ADDRESS; + // d->VirtualStart = (EFI_VIRTUAL_ADDRESS)KERNEL_VIRT_ADDRESS; d->VirtualStart = (EFI_VIRTUAL_ADDRESS)d->PhysicalStart; d->Attribute |= EFI_MEMORY_RUNTIME; - } - else /*if (d->Attribute & EFI_MEMORY_RUNTIME)*/ { + } else /*if (d->Attribute & EFI_MEMORY_RUNTIME)*/ { d->VirtualStart = (EFI_VIRTUAL_ADDRESS)d->PhysicalStart; } d = (EFI_MEMORY_DESCRIPTOR *)((uint8_t *)d + desc_size); } - return ST->RuntimeServices->SetVirtualAddressMap(memmap_size, desc_size, desc_version, memory_map); + return ST->RuntimeServices->SetVirtualAddressMap(memmap_size, desc_size, desc_version, + memory_map); } -EFI_STATUS memory_get_map(EFI_MEMORY_DESCRIPTOR **buffer, UINTN *buffer_size, - UINTN *key, UINTN *desc_size, UINT32 *desc_version) { +EFI_STATUS +memory_get_map(EFI_MEMORY_DESCRIPTOR **buffer, UINTN *buffer_size, UINTN *key, UINTN *desc_size, + UINT32 *desc_version) +{ EFI_STATUS status; UINTN needs_size = 0; @@ -92,7 +94,7 @@ EFI_STATUS memory_get_map(EFI_MEMORY_DESCRIPTOR **buffer, UINTN *buffer_size, // Give some extra buffer to account for changes. *buffer_size = needs_size + 256; - status = ST->BootServices->AllocatePool(EfiLoaderData, *buffer_size, (void**)buffer); + status = ST->BootServices->AllocatePool(EfiLoaderData, *buffer_size, (void **)buffer); CHECK_EFI_STATUS_OR_RETURN(status, "Failed to allocate space for memory map"); status = ST->BootServices->GetMemoryMap(buffer_size, *buffer, key, desc_size, desc_version); @@ -100,13 +102,14 @@ EFI_STATUS memory_get_map(EFI_MEMORY_DESCRIPTOR **buffer, UINTN *buffer_size, return EFI_SUCCESS; } -EFI_STATUS memory_dump_map() { +EFI_STATUS +memory_dump_map() +{ EFI_MEMORY_DESCRIPTOR *buffer; UINTN buffer_size, desc_size, key; UINT32 desc_version; - EFI_STATUS status = memory_get_map(&buffer, &buffer_size, &key, - &desc_size, &desc_version); + EFI_STATUS status = memory_get_map(&buffer, &buffer_size, &key, &desc_size, &desc_version); CHECK_EFI_STATUS_OR_RETURN(status, "Failed to get memory map"); const UINTN count = buffer_size / desc_size; diff --git a/src/boot/memory.h b/src/boot/memory.h index de8613b..f4f3486 100644 --- a/src/boot/memory.h +++ b/src/boot/memory.h @@ -3,17 +3,10 @@ EFI_STATUS memory_mark_address_for_update(void **pointer); -EFI_STATUS memory_virtualize( - EFI_MEMORY_DESCRIPTOR *memory_map, - UINTN memmap_size, - UINTN desc_size, - UINT32 desc_version); +EFI_STATUS memory_virtualize(EFI_MEMORY_DESCRIPTOR *memory_map, UINTN memmap_size, UINTN desc_size, + UINT32 desc_version); -EFI_STATUS memory_get_map( - EFI_MEMORY_DESCRIPTOR **buffer, - UINTN *buffer_size, - UINTN *key, - UINTN *desc_size, - UINT32 *desc_version); +EFI_STATUS memory_get_map(EFI_MEMORY_DESCRIPTOR **buffer, UINTN *buffer_size, UINTN *key, + UINTN *desc_size, UINT32 *desc_version); EFI_STATUS memory_dump_map(); diff --git a/src/boot/utility.c b/src/boot/utility.c index e71d8ab..f35f029 100644 --- a/src/boot/utility.c +++ b/src/boot/utility.c @@ -7,11 +7,12 @@ struct ErrorCode { extern struct ErrorCode ErrorCodeTable[]; -const CHAR16 *util_error_message(EFI_STATUS status) { +const CHAR16 * +util_error_message(EFI_STATUS status) +{ int32_t i = -1; while (ErrorCodeTable[++i].desc != NULL) { - if (ErrorCodeTable[i].code == status) - return ErrorCodeTable[i].desc; + if (ErrorCodeTable[i].code == status) return ErrorCodeTable[i].desc; } return L"Unknown"; diff --git a/src/boot/utility.h b/src/boot/utility.h index b8c8ced..c6d5dfd 100644 --- a/src/boot/utility.h +++ b/src/boot/utility.h @@ -1,34 +1,32 @@ +#include "console.h" #include #include -#include "console.h" #define UNUSED __attribute__((unused)) const CHAR16 *util_error_message(EFI_STATUS status); -#define CHECK_EFI_STATUS_OR_RETURN(s, msg, ...) \ - if (EFI_ERROR((s))) { \ - Print(L"EFI_ERROR: " msg L": %s\n", ## __VA_ARGS__, util_error_message(s)); \ - return (s); \ +#define CHECK_EFI_STATUS_OR_RETURN(s, msg, ...) \ + if (EFI_ERROR((s))) { \ + Print(L"EFI_ERROR: " msg L": %s\n", ##__VA_ARGS__, util_error_message(s)); \ + return (s); \ } -#define CHECK_EFI_STATUS_OR_FAIL(s) \ - if (EFI_ERROR((s))) { \ +#define CHECK_EFI_STATUS_OR_FAIL(s) \ + if (EFI_ERROR((s))) { \ con_status_fail(util_error_message(s)); \ - while (1) __asm__("hlt"); \ + while (1) __asm__("hlt"); \ } -#define CHECK_EFI_STATUS_OR_ASSERT(s, d) \ - if (EFI_ERROR((s))) { \ - __asm__ __volatile__ ( \ - "movq %0, %%r8;" \ - "movq %1, %%r9;" \ - "movq %2, %%r10;" \ - "movq $0, %%rdx;" \ - "divq %%rdx;" \ - : \ - :"r"((uint64_t)s), "r"((uint64_t)d), "r"((uint64_t)__LINE__) \ - :"rax", "rdx", "r8", "r9", "r10" \ - ); \ +#define CHECK_EFI_STATUS_OR_ASSERT(s, d) \ + if (EFI_ERROR((s))) { \ + __asm__ __volatile__( \ + "movq %0, %%r8;" \ + "movq %1, %%r9;" \ + "movq %2, %%r10;" \ + "movq $0, %%rdx;" \ + "divq %%rdx;" \ + : \ + : "r"((uint64_t)s), "r"((uint64_t)d), "r"((uint64_t)__LINE__) \ + : "rax", "rdx", "r8", "r9", "r10"); \ } - diff --git a/src/modules/main/main.c b/src/modules/main/main.c index 115e723..cca5512 100644 --- a/src/modules/main/main.c +++ b/src/modules/main/main.c @@ -2,7 +2,9 @@ void do_the_set_registers(); -void kernel_main() { +void +kernel_main() +{ volatile register int foo = 0x1a1b1c10; volatile register int bar = 0; diff --git a/src/modules/main/vga.c b/src/modules/main/vga.c index 2f058a3..3ebad31 100644 --- a/src/modules/main/vga.c +++ b/src/modules/main/vga.c @@ -8,47 +8,60 @@ static size_t terminal_column; static uint8_t terminal_color; /* Note the use of the volatile keyword to prevent the compiler from eliminating dead stores. */ -static volatile uint16_t* terminal_buffer; +static volatile uint16_t *terminal_buffer; uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg); uint16_t vga_entry(unsigned char uc, uint8_t color); -static size_t strlen(const char* str) { +static size_t +strlen(const char *str) +{ size_t len = 0; - while (str[len++]); + while (str[len++]) + ; return len; } -void terminal_initialize(size_t startrow) { +void +terminal_initialize(size_t startrow) +{ terminal_row = startrow; terminal_column = 0; terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK); - terminal_buffer = (uint16_t*) 0xB8000; + terminal_buffer = (uint16_t *)0xB8000; } -void terminal_setcolor(uint8_t color) { +void +terminal_setcolor(uint8_t color) +{ terminal_color = color; } -void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) { +void +terminal_putentryat(char c, uint8_t color, size_t x, size_t y) +{ const size_t index = y * VGA_WIDTH + x; terminal_buffer[index] = vga_entry(c, color); } -void terminal_putchar(char c) { +void +terminal_putchar(char c) +{ terminal_putentryat(c, terminal_color, terminal_column, terminal_row); if (++terminal_column == VGA_WIDTH) { terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) - terminal_row = 0; + if (++terminal_row == VGA_HEIGHT) terminal_row = 0; } } -void terminal_write(const char* data, size_t size) { - for (size_t i = 0; i < size; i++) - terminal_putchar(data[i]); +void +terminal_write(const char *data, size_t size) +{ + for (size_t i = 0; i < size; i++) terminal_putchar(data[i]); } -void terminal_writestring(const char* data) { +void +terminal_writestring(const char *data) +{ terminal_write(data, strlen(data)); } diff --git a/src/modules/main/vga.h b/src/modules/main/vga.h index 4be8b71..07584bd 100644 --- a/src/modules/main/vga.h +++ b/src/modules/main/vga.h @@ -22,17 +22,21 @@ enum vga_color { VGA_COLOR_WHITE = 15, }; -inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) { +inline uint8_t +vga_entry_color(enum vga_color fg, enum vga_color bg) +{ return fg | bg << 4; } -inline uint16_t vga_entry(unsigned char uc, uint8_t color) { - return (uint16_t) uc | (uint16_t) color << 8; +inline uint16_t +vga_entry(unsigned char uc, uint8_t color) +{ + return (uint16_t)uc | (uint16_t)color << 8; } void terminal_initialize(size_t rowstart); void terminal_setcolor(uint8_t color); void terminal_putentryat(char c, uint8_t color, size_t x, size_t y); void terminal_putchar(char c); -void terminal_write(const char* data, size_t size); -void terminal_writestring(const char* data); +void terminal_write(const char *data, size_t size); +void terminal_writestring(const char *data);