2018-02-17 22:54:00 +00:00
|
|
|
#ifndef EXOSPHERE_UTILS_H
|
|
|
|
#define EXOSPHERE_UTILS_H
|
|
|
|
|
2018-02-23 03:58:39 +00:00
|
|
|
#include <stdbool.h>
|
2018-02-18 23:02:37 +00:00
|
|
|
#include <stddef.h>
|
2018-02-23 03:58:39 +00:00
|
|
|
#include <stdint.h>
|
2018-02-18 02:50:39 +00:00
|
|
|
|
2018-02-20 22:44:10 +00:00
|
|
|
#define BIT(x) (1u << (x))
|
|
|
|
#define BITL(x) (1ull << (x))
|
|
|
|
|
2018-02-17 22:54:00 +00:00
|
|
|
void panic(void);
|
|
|
|
|
2018-02-19 09:27:50 +00:00
|
|
|
uint32_t get_physical_address(void *vaddr);
|
|
|
|
|
2018-02-18 23:02:37 +00:00
|
|
|
static inline uint32_t read32le(const void *dword, size_t offset) {
|
|
|
|
return *(uint32_t *)((uintptr_t)dword + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t read32be(const unsigned char *dword, size_t offset) {
|
|
|
|
return __builtin_bswap32(read32le(dword, offset));
|
|
|
|
}
|
2018-02-17 22:54:00 +00:00
|
|
|
|
2018-02-23 03:58:39 +00:00
|
|
|
static __attribute__((noinline)) bool check_32bit_additive_overflow(uint32_t a, uint32_t b) {
|
2018-02-21 21:38:55 +00:00
|
|
|
uint64_t x = (uint64_t)a + (uint64_t)b;
|
|
|
|
return x > (uint64_t)(UINT32_MAX);
|
|
|
|
}
|
|
|
|
|
2018-02-23 03:58:39 +00:00
|
|
|
static __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be)
|
2018-02-21 21:38:55 +00:00
|
|
|
{
|
|
|
|
if(as <= bs && bs <= ae)
|
2018-02-23 03:58:39 +00:00
|
|
|
return true;
|
2018-02-21 21:38:55 +00:00
|
|
|
if(bs <= as && as <= be)
|
2018-02-23 03:58:39 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2018-02-21 21:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-18 23:02:37 +00:00
|
|
|
static inline unsigned int get_core_id(void) {
|
|
|
|
unsigned int core_id;
|
|
|
|
__asm__ __volatile__ ("mrs %0, MPIDR_EL1" : "=r"(core_id));
|
2018-02-19 08:41:19 +00:00
|
|
|
return core_id & 3;
|
2018-02-18 02:50:39 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 23:02:37 +00:00
|
|
|
#endif
|