-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add and remove (i.e. rewrite) pmm code again
- Loading branch information
1 parent
b6c4d87
commit 1030091
Showing
7 changed files
with
166 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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 zerOS_KERNEL_COMPILER_STRUCT_H_INCLUDED | ||
#define zerOS_KERNEL_COMPILER_STRUCT_H_INCLUDED | ||
|
||
#undef sizeof_field | ||
/** | ||
* @def sizeof_field(type, field) | ||
* @brief Get the size of a field in a struct. | ||
* @param type The type of the struct. | ||
* @param field The field in the struct. | ||
*/ | ||
#define sizeof_field(type, field) sizeof(((type*)0)->field) | ||
|
||
#undef container_of | ||
/** | ||
* @def container_of(ptr, type, field) | ||
* @brief Get the container of a field in a struct. | ||
* @param ptr The pointer to the field. | ||
* @param type The type of the struct. | ||
* @param field The field in the struct. | ||
*/ | ||
#define container_of(ptr, type, field) ((type*)((char*)(ptr) - offsetof(type, field))) | ||
|
||
#endif |
This file contains 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 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 |
---|---|---|
@@ -1,13 +1,42 @@ | ||
#ifndef zerOS_KERNEL_MEMORY_ALIGN_H_INCLUDED | ||
#define zerOS_KERNEL_MEMORY_ALIGN_H_INCLUDED | ||
|
||
#undef ALIGN_UP | ||
/** | ||
* @def ALIGN_UP(x, align) | ||
* @brief Aligns a value up to the specified alignment. | ||
* @param x The value to align. | ||
* @param align The alignment to use. | ||
*/ | ||
#define ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1)) | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <stdalign.h> | ||
|
||
#include <misc/unique_ident.h> | ||
|
||
static inline bool zerOS_is_pow_two(uintptr_t x) | ||
{ | ||
if (unlikely(x == 0)) | ||
return false; | ||
return (x & (x - 1)) == 0; | ||
} | ||
|
||
static inline uintptr_t zerOS_align_up(uintptr_t x, size_t align) | ||
{ | ||
if (likely(zerOS_is_pow_two(align))) | ||
return (x + (align - 1)) & ~(align - 1); | ||
else | ||
return x + ((align - (x % align)) % align); | ||
} | ||
|
||
static inline uintptr_t zerOS_align_down(uintptr_t x, size_t align) | ||
{ | ||
if (likely(zerOS_is_pow_two(align))) | ||
return x & ~(align - 1); | ||
else | ||
return x - (x % align); | ||
} | ||
|
||
static inline uintptr_t zerOS_is_aligned(uintptr_t x, size_t align) | ||
{ | ||
if (likely(zerOS_is_pow_two(align))) | ||
return (x & (align - 1)) == 0; | ||
else | ||
return x % align == 0; | ||
} | ||
|
||
#endif |
This file contains 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 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 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 |
---|---|---|
|
@@ -27,7 +27,5 @@ extern void zerOS_hcf(void) | |
{ | ||
zerOS_cli(); | ||
while (true) | ||
{ | ||
zerOS_halt(); | ||
} | ||
} |
This file contains 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