Skip to content
Draft
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
23 changes: 23 additions & 0 deletions include/hal/hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef HAL_HAL
#define HAL_HAL

#include <stdbigos/address.h>
#include <stdbigos/error.h>

/// @addtogroup hal
/// @{

/**
* @param dtb Physical address of device tree blob
* @param physical_to_effective A pointer to a function that transalates physical addresses into effective ones
*
* @retval ERR_NONE Success
* @retval ERR_BAD_ARG @p dtb is null
* @retval ERR_NOT_VALID No valid device tree found at address @p dtb
* */
[[gnu::nonnull(2)]]
error_t hal_init(__phys void* dtb, void* (*physical_to_effective)(__phys void*));

/// @}

#endif // !HAL_HAL
30 changes: 30 additions & 0 deletions include/hal/memory_regions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef HAL_MEMORY_REGIONS
#define HAL_MEMORY_REGIONS

#include <stdbigos/error.h>
#include <stdbigos/memory_types.h>

/**
* This type is opaque to the caller.
* Fields of this struct should not be modified directly.
* */
typedef struct {
u32 idx;
bool in_memresblock;
} hal_reserved_iterator_t;

error_t hal_get_reserved_regions_iterator(hal_reserved_iterator_t* iterOUT);
error_t hal_get_next_reserved_region(hal_reserved_iterator_t iter, memory_area_t* areaOUT);

/**
* This type is opaque to the caller.
* Fields of this struct should not be modified directly.
* */
typedef struct {
u32 idx;
} hal_memory_iterator_t;

error_t hal_get_memory_regions_iterator(hal_memory_iterator_t* iterOUT);
error_t hal_get_next_memory_region(hal_memory_iterator_t iter, memory_area_t* areaOUT);

#endif // !HAL_MEMORY_REGIONS
1 change: 1 addition & 0 deletions include/stdbigos/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum [[nodiscard]] {
ERR_OUT_OF_MEMORY,
ERR_NOT_ENOUGH_MEMORY,
ERR_REPEATED_INITIALIZATION,
ERR_ALLOCATION_FAILED,
} error_t;

#endif // !BIGOS_INCLUDE_STDBIGOS_ERROR
1 change: 1 addition & 0 deletions src/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SETUP_EXECUTABLE(kernel)

target_compile_definitions(kernel PRIVATE $<IF:$<CONFIG:DEBUG>,__DEBUG__ __LOGLVL__=3, __LOGLVL__=1>)
target_compile_definitions(kernel PRIVATE __ARCH_RISCV__) # Make this an opt when we add support for other arches
target_link_libraries(kernel PRIVATE Debug stdbigos)

target_link_options(kernel PRIVATE -static-pie -e kinit)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SETUP_LIBRARY(hal)

target_link_libraries(hal
PUBLIC stdbigos
PRIVATE Debug
PRIVATE device_tree_access
)
38 changes: 38 additions & 0 deletions src/lib/hal/hal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <hal/hal.h>

#include "dt/dt.h"

//===========
// Internals
//===========

static bool g_is_init = false;
static __phys void* g_dtb = nullptr;
static void* (*g_physical_to_effective)(__phys void*) = nullptr;

bool ihal_is_init() {
return g_is_init;
}

error_t ihal_get_dtb(void** dtbOUT) {
if (!g_is_init)
return ERR_NOT_INITIALIZED;
*dtbOUT = g_physical_to_effective(g_dtb);
return ERR_NONE;
}

//========
// Public
//========

error_t hal_init(__phys void* dtb, void* (*physical_to_effective)(__phys void*)) {
if (dtb == nullptr)
return ERR_BAD_ARG;
fdt_t fdt = {0};
error_t err = dt_init(physical_to_effective(dtb), &fdt);
if (err)
return err;
g_physical_to_effective = physical_to_effective;
g_is_init = true;
return ERR_NONE;
}
4 changes: 4 additions & 0 deletions src/lib/hal/hal_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef LIB_HAL_HAL_INTERNAL
#define LIB_HAL_HAL_INTERNAL

#endif // !LIB_HAL_HAL_INTERNAL
24 changes: 24 additions & 0 deletions src/lib/hal/memory_region.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <hal/memory_regions.h>
#include <stdbigos/error.h>

error_t hal_get_reserved_regions_iterator(hal_reserved_iterator_t* iterOUT) {
(void)iterOUT;
return ERR_NOT_INITIALIZED;
}

error_t hal_get_next_reserved_region(hal_reserved_iterator_t iter, memory_area_t* areaOUT) {
(void)iter;
(void)areaOUT;
return ERR_NOT_INITIALIZED;
}

error_t hal_get_memory_regions_iterator(hal_memory_iterator_t* iterOUT) {
(void)iterOUT;
return ERR_NOT_INITIALIZED;
}

error_t hal_get_next_memory_region(hal_memory_iterator_t iter, memory_area_t* areaOUT) {
(void)iter;
(void)areaOUT;
return ERR_NOT_INITIALIZED;
}
Loading