-
Notifications
You must be signed in to change notification settings - Fork 17
Add hardware abstraction layer. #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
frogrammer9
wants to merge
1
commit into
Operacja-System:main
Choose a base branch
from
frogrammer9:hal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.