Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
mempler committed Dec 16, 2023
1 parent 12e72c1 commit 3c60968
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 190 deletions.
4 changes: 2 additions & 2 deletions kernel/include/Kernel/Bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#endif

VOID
CommonStartupRoutine(
PAGE_ALLOCATOR *BumpAllocator
CommonStartupRoutine (
PAGE_ALLOCATOR* BumpAllocator
);
44 changes: 44 additions & 0 deletions kernel/include/Kernel/Logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#ifndef __KERNEL_H__
#error "This file should be included from Kernel.h"
#endif

#include <RuntimeLib.h>

#define LOG_LEVEL_DEBUG 0
#define LOG_LEVEL_INFO 1
#define LOG_LEVEL_WARNING 2
#define LOG_LEVEL_ERROR 3

/**
* @brief Logs a message.
*
* @param[in] _ID The Filter ID. LFID_DEFAULT for default filter.
* @param[in] _LEVEL The log level.
* @param[in] _Format The format string.
**/
#define LOG(_ID, _LEVEL, _Format, ...)

/// Default filter, used to everything that doesn't have a specific filter.
DEFINE_GUID (LFID_DEFAULT, 0x8BA890B8, 0xF167, 0x4AFD, 0x86, 0x45, 0x44, 0x07, 0x43, 0xA0, 0x30, 0x6A);

/// Memory filter, used to log memory related messages.
DEFINE_GUID (LFID_MEMORY, 0x8BA890B8, 0xF167, 0x4AFD, 0x86, 0x45, 0x44, 0x07, 0x43, 0xA0, 0x30, 0x6B);

typedef struct _LOG_FILTER {
GUID ID;
CHAR8 Name[64];
BOOLEAN Enabled;
UINT8 Level;
} LOG_FILTER;

typedef struct _LOG_ENTRY {
GUID FilterID;
UINTN Level;
CHAR8* Message;
} LOG_ENTRY;

typedef VOID (* LOG_CALLBACK)(
LOG_ENTRY* Entry
);
4 changes: 2 additions & 2 deletions kernel/source/Bootstrap/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
PAGE_ALLOCATOR* g_PageAllocator;

VOID
CommonStartupRoutine(
PAGE_ALLOCATOR *BumpAllocator
CommonStartupRoutine (
PAGE_ALLOCATOR* BumpAllocator
)
{
// TODO: g_PageAllocator = BuddyAllocatorInit (BumpAllocator);
Expand Down
21 changes: 9 additions & 12 deletions kernel/source/Bootstrap/Limine.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ BUMP_ALLOCATOR g_BumpAllocator;
// See specification for further info.
//

LIMINE_BASE_REVISION(1);
LIMINE_BASE_REVISION (1);

//
// Memory map
//

struct limine_memmap_request g_LimineMemmap = {
.id = LIMINE_MEMMAP_REQUEST,
.id = LIMINE_MEMMAP_REQUEST,
.revision = 0
};

Expand All @@ -33,17 +33,14 @@ StartupRoutine (
IDTInit ();

BumperIdx = 0;
for (UINT64 i = 0; i < g_LimineMemmap.response->entry_count; i++)
{
if (g_LimineMemmap.response->entries[i]->type == LIMINE_MEMMAP_USABLE)
{
BUMPER *bumper = &g_BumpAllocator.bumpers[BumperIdx++];
for (UINT64 i = 0; i < g_LimineMemmap.response->entry_count; i++) {
if (g_LimineMemmap.response->entries[i]->type == LIMINE_MEMMAP_USABLE) {
BUMPER* bumper = &g_BumpAllocator.bumpers[BumperIdx++];
bumper->heap_start = g_LimineMemmap.response->entries[i]->base;
bumper->heap_end = g_LimineMemmap.response->entries[i]->base + g_LimineMemmap.response->entries[i]->length;
bumper->next = bumper->heap_start;
bumper->heap_end = g_LimineMemmap.response->entries[i]->base + g_LimineMemmap.response->entries[i]->length;
bumper->next = bumper->heap_start;

if (BumperIdx == MAXIMUM_BUMPERS)
{
if (BumperIdx == MAXIMUM_BUMPERS) {
// Memory is too fragmented, we can't continue. This is fine but we'll use
// some usable memory.

Expand All @@ -53,5 +50,5 @@ StartupRoutine (
}
}

CommonStartupRoutine ((PAGE_ALLOCATOR *)&g_BumpAllocator);
CommonStartupRoutine ((PAGE_ALLOCATOR*)&g_BumpAllocator);
}
10 changes: 5 additions & 5 deletions lib/compat_c/include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <RuntimeLib.h>

typedef INT8 int8_t;
typedef INT16 int16_t;
typedef INT32 int32_t;
typedef INT64 int64_t;
typedef INT8 int8_t;
typedef INT16 int16_t;
typedef INT32 int32_t;
typedef INT64 int64_t;

typedef UINT8 uint8_t;
typedef UINT8 uint8_t;
typedef UINT16 uint16_t;
typedef UINT32 uint32_t;
typedef UINT64 uint64_t;
14 changes: 7 additions & 7 deletions lib/runtime/include/RuntimeLib/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ EXTERN_C_START
#define STATUS_FACILITY(_Status) (((_Status) >> 16) & 0x1FFF)
#define STATUS_ERROR_CODE(_Status) ((_Status) & 0xFFFF)

#define IS_SUCCESS(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_SUCCESS)
#define IS_WARNING(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_WARNING)
#define IS_INFORMATIONAL(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_INFORMATIONAL)
#define IS_ERROR(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_ERROR)
#define IS_SUCCESS(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_SUCCESS)
#define IS_WARNING(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_WARNING)
#define IS_INFORMATIONAL(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_INFORMATIONAL)
#define IS_ERROR(_Status) (STATUS_SEVERITY(_Status) == STATUS_SEVERITY_ERROR)

#define SUCCEEDED(_Status) (IS_SUCCESS(_Status) || IS_INFORMATIONAL(_Status) || IS_WARNING(_Status))
#define FAILED(_Status) (IS_ERROR(_Status))
#define SUCCEEDED(_Status) (IS_SUCCESS(_Status) || IS_INFORMATIONAL(_Status) || IS_WARNING(_Status))
#define FAILED(_Status) (IS_ERROR(_Status))

#define QUICK_CHECK(_F) Status = (_F); if (FAILED(Status)) { goto Exit; }
#define QUICK_CHECK(_F) Status = (_F); if (FAILED(Status)) { goto Exit; }

// -------------------------------------------------------------------- Generic

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime/include/RuntimeLib/TypeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ EXTERN_C_START

// ------------------------------------------------------------------- Typedefs

typedef VOID* HANDLE;
typedef VOID* HANDLE;
#define NULL_HANDLE ((HANDLE) NULL)

// --------------------------------------------------------------------- Macros
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime/source/Memory/SlabAllocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ RtlDestroySlabCache (
goto Exit;
}

if (CachePtr->Empty != NULL || CachePtr->Partial != NULL || CachePtr->Full != NULL) {
if ((CachePtr->Empty != NULL) || (CachePtr->Partial != NULL) || (CachePtr->Full != NULL)) {
SLAB* Slab;
SLAB* Next;

Expand All @@ -125,7 +125,7 @@ RtlDestroySlabCache (
Slab = CachePtr->Full;
while (Slab != NULL) {
Next = Slab->Next; // Save the next slab
DestroySlab(Slab);
DestroySlab (Slab);
Slab = Next;
}

Expand All @@ -135,7 +135,7 @@ RtlDestroySlabCache (
Slab = CachePtr->Partial;
while (Slab != NULL) {
Next = Slab->Next;
DestroySlab(Slab);
DestroySlab (Slab);
Slab = Next;
}

Expand All @@ -145,7 +145,7 @@ RtlDestroySlabCache (
Slab = CachePtr->Empty;
while (Slab != NULL) {
Next = Slab->Next;
DestroySlab(Slab);
DestroySlab (Slab);
Slab = Next;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime/source/Memory/SlabAllocatorUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ DestroySlab (
IN OUT SLAB* Slab
)
{
STATUS Status;
UINTN SlabPages;
UINTN SlabDataPages;
STATUS Status;
UINTN SlabPages;
UINTN SlabDataPages;
SLAB_CACHE* Cache;

Status = STATUS_SUCCESS;
Expand All @@ -88,7 +88,7 @@ DestroySlab (
// Destroy all objects inside
//
for (UINTN i = 0; i < Cache->ObjectCount; i++) {
Status = FreeObjectInSlab(Slab, Cache->Flags, i);
Status = FreeObjectInSlab (Slab, Cache->Flags, i);
if (FAILED (Status)) {
goto Exit;
}
Expand Down
50 changes: 28 additions & 22 deletions lib/runtime/tests/Allocators/BumpAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
TEST_CASE ("AllocatePages", "[BumpAllocator]") {
BUMP_ALLOCATOR allocator { };

SECTION("Make sure allocator cannot be NULL") {
SECTION ("Make sure allocator cannot be NULL") {
STATUS status = RtlBumpAllocatorInitialize (NULL);

REQUIRE (status == STATUS_INVALID_PARAMETER);
}

Expand All @@ -23,12 +24,12 @@ TEST_CASE ("AllocatePages", "[BumpAllocator]") {
allocator.bumpers[1].heap_end = allocator.bumpers[1].heap_start + PAGE_SIZE_4K * 2;
allocator.bumpers[1].next = allocator.bumpers[1].heap_start;

SECTION("Make sure we cannot allocate using NULL as Self") {
SECTION ("Make sure we cannot allocate using NULL as Self") {
VOID* address = NULL;
STATUS status = allocator.AllocatePages(NULL, &address, 1, PAGE_SIZE_4K);
STATUS status = allocator.AllocatePages (NULL, &address, 1, PAGE_SIZE_4K);

assert(address == NULL);
assert(status == STATUS_NOT_INITIALIZED);
assert (address == NULL);
assert (status == STATUS_NOT_INITIALIZED);
}

SECTION ("Allocates 4K page") {
Expand Down Expand Up @@ -126,8 +127,9 @@ TEST_CASE ("AllocatePages", "[BumpAllocator]") {
TEST_CASE ("FreePages", "[BumpAllocator]") {
BUMP_ALLOCATOR allocator { };

SECTION("Make sure allocator cannot be NULL") {
SECTION ("Make sure allocator cannot be NULL") {
STATUS status = RtlBumpAllocatorInitialize (NULL);

REQUIRE (status == STATUS_INVALID_PARAMETER);
}

Expand All @@ -142,33 +144,37 @@ TEST_CASE ("FreePages", "[BumpAllocator]") {
allocator.bumpers[1].heap_end = allocator.bumpers[1].heap_start + PAGE_SIZE_4K * 2;
allocator.bumpers[1].next = allocator.bumpers[1].heap_start;

SECTION("Make sure we cannot free while using NULL as Self") {
STATUS status = allocator.FreePages(NULL, NULL, 1, PAGE_SIZE_4K);
assert(status == STATUS_NOT_INITIALIZED);
SECTION ("Make sure we cannot free while using NULL as Self") {
STATUS status = allocator.FreePages (NULL, NULL, 1, PAGE_SIZE_4K);

assert (status == STATUS_NOT_INITIALIZED);
}

SECTION("Free should always succeed") {
SECTION ("Free should always succeed") {
VOID* address = NULL;
STATUS status = PA_ALLOCATE(&allocator, &address, 1, PAGE_SIZE_4K);
REQUIRE(status == STATUS_SUCCESS);
STATUS status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K);

status = PA_FREE(&allocator, &address, 1, PAGE_SIZE_4K);
REQUIRE(status == STATUS_SUCCESS);
REQUIRE (status == STATUS_SUCCESS);

status = PA_FREE (&allocator, &address, 1, PAGE_SIZE_4K);
REQUIRE (status == STATUS_SUCCESS);
REQUIRE (address == NULL);
}

SECTION("Free cannot be NULL") {
STATUS status = PA_FREE(&allocator, NULL, 1, PAGE_SIZE_4K);
REQUIRE(status == STATUS_INVALID_PARAMETER);
SECTION ("Free cannot be NULL") {
STATUS status = PA_FREE (&allocator, NULL, 1, PAGE_SIZE_4K);

REQUIRE (status == STATUS_INVALID_PARAMETER);
}

SECTION("Free cannot be zero") {
SECTION ("Free cannot be zero") {
VOID* address = NULL;
STATUS status = PA_ALLOCATE(&allocator, &address, 1, PAGE_SIZE_4K);
REQUIRE(status == STATUS_SUCCESS);
STATUS status = PA_ALLOCATE (&allocator, &address, 1, PAGE_SIZE_4K);

status = PA_FREE(&allocator, &address, 0, PAGE_SIZE_4K);
REQUIRE(status == STATUS_INVALID_PARAMETER);
REQUIRE (status == STATUS_SUCCESS);

status = PA_FREE (&allocator, &address, 0, PAGE_SIZE_4K);
REQUIRE (status == STATUS_INVALID_PARAMETER);
}

delete[] (UINT8*)allocator.bumpers[0].heap_start;
Expand Down
Loading

0 comments on commit 3c60968

Please sign in to comment.