2023-10-21 20:27:23 +03:00
|
|
|
|
/**
|
|
|
|
|
* tool.h
|
|
|
|
|
* Заголовок содержащий определения вспомогательных функций
|
|
|
|
|
*
|
|
|
|
|
* Данный заголовочный файл содержит определения которые используются для
|
|
|
|
|
* упрощения написания кода
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef TOOL_H
|
|
|
|
|
#define TOOL_H
|
|
|
|
|
|
2023-09-30 22:53:47 +03:00
|
|
|
|
#include <stdarg.h>
|
2023-10-21 20:27:23 +03:00
|
|
|
|
#include <stdint.h>
|
2023-09-30 22:53:47 +03:00
|
|
|
|
|
2023-10-17 15:12:22 +03:00
|
|
|
|
#define abs(x) ((x) < 0 ? -(x) : (x))
|
|
|
|
|
|
2023-10-25 00:07:32 +03:00
|
|
|
|
#define assert(check) \
|
|
|
|
|
do { \
|
|
|
|
|
if (!(check)) { \
|
|
|
|
|
fb_printf("\nassert() failed in %s() (%s:%d)\n", __func__, \
|
|
|
|
|
__FILE__, __LINE__); \
|
|
|
|
|
for (;;) asm volatile("hlt"); \
|
|
|
|
|
} \
|
2023-10-21 20:27:23 +03:00
|
|
|
|
} while (0)
|
2023-10-07 18:28:48 +03:00
|
|
|
|
|
|
|
|
|
#define ALIGN_UP(NUM, ALIGN) (((NUM) + ALIGN - 1) & ~(ALIGN - 1))
|
|
|
|
|
#define ALIGN_DOWN(NUM, ALIGN) ((NUM) & ~(ALIGN - 1))
|
2023-10-25 00:07:32 +03:00
|
|
|
|
#define CONTAINER_OF(PTR, TYPE, MEMBER) \
|
|
|
|
|
((TYPE *)((void *)PTR - offsetof(TYPE, MEMBER)))
|
2023-10-07 18:28:48 +03:00
|
|
|
|
|
|
|
|
|
#define BIT_SET(BIT) (bitmap[(BIT) / 8] |= (1 << ((BIT) % 8)))
|
|
|
|
|
#define BIT_CLEAR(BIT) (bitmap[(BIT) / 8] &= ~(1 << ((BIT) % 8)))
|
|
|
|
|
#define BIT_GET(BIT) ((bitmap[(BIT) / 8] >> ((BIT) % 8)) & 1)
|
2023-09-30 22:53:47 +03:00
|
|
|
|
|
2023-10-17 15:12:22 +03:00
|
|
|
|
static inline void pause( ) {
|
|
|
|
|
for (uint64_t i = 0; i < 1024; i++) {
|
2023-10-31 19:06:56 +03:00
|
|
|
|
for (uint64_t j = 0; j < 4; j++) { asm volatile("pause"); }
|
2023-10-17 15:12:22 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-21 20:27:23 +03:00
|
|
|
|
void tool_memcpy(void *dest, void *src, uint64_t n);
|
|
|
|
|
void *tool_memset(void *ptr, uint8_t n, uint64_t size);
|
|
|
|
|
uint64_t tool_strlen(const char *str);
|
|
|
|
|
uint64_t tool_starts_with(const char *str, const char *prefix);
|
|
|
|
|
void tool_format(void (*putc)(char c), const char *format_string, va_list args);
|
|
|
|
|
|
|
|
|
|
#endif // tool.h
|