File tree Expand file tree Collapse file tree 8 files changed +121
-0
lines changed
Expand file tree Collapse file tree 8 files changed +121
-0
lines changed Original file line number Diff line number Diff line change 1+ #ifndef HAL_HAL
2+ #define HAL_HAL
3+
4+ #include <stdbigos/address.h>
5+ #include <stdbigos/error.h>
6+
7+ /// @addtogroup hal
8+ /// @{
9+
10+ /**
11+ * @param dtb Physical address of device tree blob
12+ * @param physical_to_effective A pointer to a function that transalates physical addresses into effective ones
13+ *
14+ * @retval ERR_NONE Success
15+ * @retval ERR_BAD_ARG @p dtb is null
16+ * @retval ERR_NOT_VALID No valid device tree found at address @p dtb
17+ * */
18+ [[gnu ::nonnull (2 )]]
19+ error_t hal_init (__phys void * dtb , void * (* physical_to_effective )(__phys void * ));
20+
21+ /// @}
22+
23+ #endif // !HAL_HAL
Original file line number Diff line number Diff line change 1+ #ifndef HAL_MEMORY_REGIONS
2+ #define HAL_MEMORY_REGIONS
3+
4+ #include <stdbigos/error.h>
5+ #include <stdbigos/memory_types.h>
6+
7+ /**
8+ * This type is opaque to the caller.
9+ * Fields of this struct should not be modified directly.
10+ * */
11+ typedef struct {
12+ u32 idx ;
13+ bool in_memresblock ;
14+ }
15+ hal_reserved_iterator_t ;
16+
17+ error_t hal_get_reserved_regions_iterator (hal_reserved_iterator_t * iterOUT );
18+ error_t hal_get_next_reserved_region (hal_reserved_iterator_t iter , memory_area_t * areaOUT );
19+
20+ /**
21+ * This type is opaque to the caller.
22+ * Fields of this struct should not be modified directly.
23+ * */
24+ typedef struct {
25+ u32 idx ;
26+ } hal_memory_iterator_t ;
27+
28+ error_t hal_get_memory_regions_iterator (hal_memory_iterator_t * iterOUT );
29+ error_t hal_get_next_memory_region (hal_memory_iterator_t iter , memory_area_t * areaOUT );
30+
31+ #endif // !HAL_MEMORY_REGIONS
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ typedef enum [[nodiscard]] {
1616 ERR_OUT_OF_MEMORY ,
1717 ERR_NOT_ENOUGH_MEMORY ,
1818 ERR_REPEATED_INITIALIZATION ,
19+ ERR_ALLOCATION_FAILED ,
1920} error_t ;
2021
2122#endif // !BIGOS_INCLUDE_STDBIGOS_ERROR
Original file line number Diff line number Diff line change 11SETUP_EXECUTABLE (kernel )
22
33target_compile_definitions (kernel PRIVATE $<IF :$<CONFIG :DEBUG >,__DEBUG__ __LOGLVL__ =3, __LOGLVL__ =1>)
4+ target_compile_definitions (kernel PRIVATE __ARCH_RISCV__ ) # Make this an opt when we add support for other arches
45target_link_libraries (kernel PRIVATE Debug stdbigos )
56
67target_link_options (kernel PRIVATE -static-pie -e kinit )
Original file line number Diff line number Diff line change 1+ SETUP_LIBRARY (hal )
2+
3+ target_link_libraries (hal
4+ PUBLIC stdbigos
5+ PRIVATE Debug
6+ PRIVATE device_tree_access
7+ )
Original file line number Diff line number Diff line change 1+ #include <hal/hal.h>
2+ #include "dt/dt.h"
3+
4+ //===========
5+ // Internals
6+ //===========
7+
8+ static bool g_is_init = false;
9+ static __phys void * g_dtb = nullptr ;
10+ static void * (* g_physical_to_effective )(__phys void * ) = nullptr ;
11+
12+ bool ihal_is_init () {
13+ return g_is_init ;
14+ }
15+
16+ error_t ihal_get_dtb (void * * dtbOUT ) {
17+ if (!g_is_init )
18+ return ERR_NOT_INITIALIZED ;
19+ * dtbOUT = g_physical_to_effective (g_dtb );
20+ return ERR_NONE ;
21+ }
22+
23+ //========
24+ // Public
25+ //========
26+
27+ error_t hal_init (__phys void * dtb , void * (* physical_to_effective )(__phys void * )) {
28+ if (dtb == nullptr )
29+ return ERR_BAD_ARG ;
30+ fdt_t fdt = {0 };
31+ error_t err = dt_init (physical_to_effective (dtb ), & fdt );
32+ if (err ) return err ;
33+ g_physical_to_effective = physical_to_effective ;
34+ g_is_init = true;
35+ return ERR_NONE ;
36+ }
Original file line number Diff line number Diff line change 1+ #ifndef LIB_HAL_HAL_INTERNAL
2+ #define LIB_HAL_HAL_INTERNAL
3+
4+
5+ #endif // !LIB_HAL_HAL_INTERNAL
Original file line number Diff line number Diff line change 1+ #include <hal/memory_regions.h>
2+
3+ error_t hal_get_reserved_regions_iterator (hal_reserved_iterator_t * iterOUT ) {
4+
5+ }
6+
7+ error_t hal_get_next_reserved_region (hal_reserved_iterator_t iter , memory_area_t * areaOUT ) {
8+
9+ }
10+
11+ error_t hal_get_memory_regions_iterator (hal_memory_iterator_t * iterOUT ) {
12+
13+ }
14+
15+ error_t hal_get_next_memory_region (hal_memory_iterator_t iter , memory_area_t * areaOUT ) {
16+
17+ }
You can’t perform that action at this time.
0 commit comments