Basic PS/2 keyboard driver, and ...
[lunaix-os.git] / lunaix-os / includes / lunaix / spike.h
1 #ifndef __LUNAIX_SPIKE_H
2 #define __LUNAIX_SPIKE_H
3
4 // Some helper functions. As helpful as Spike the Dragon! :)
5
6 // 除法向上取整
7 #define CEIL(v, k)          (((v) + (1 << (k)) - 1) >> (k))
8
9 // 除法向下取整
10 #define FLOOR(v, k)         ((v) >> (k))
11
12 // 获取v最近的最大k倍数
13 #define ROUNDUP(v, k)       (((v) + (k) - 1) & ~((k) - 1))
14
15 // 获取v最近的最小k倍数
16 #define ROUNDDOWN(v, k)     ((v) & ~((k) - 1))
17
18 inline static void spin() {
19     while(1);
20 }
21
22 #ifdef __LUNAIXOS_DEBUG__
23 #define assert(cond)                                  \
24     if (!(cond)) {                                    \
25         __assert_fail(#cond, __FILE__, __LINE__);     \
26     }
27
28 #define assert_msg(cond, msg)                         \
29     if (!(cond)) {                                    \
30         __assert_fail(msg, __FILE__, __LINE__);       \
31     }
32 void __assert_fail(const char* expr, const char* file, unsigned int line) __attribute__((noinline, noreturn));
33 #else
34 #define assert(cond) (void)(cond); //assert nothing
35 #define assert_msg(cond, msg) (void)(cond);  //assert nothing
36 #endif
37
38 void panick(const char* msg);
39
40
41 #define wait_until(cond)    while(!(cond));
42 #define loop_until(cond)    while(!(cond));
43
44
45 #endif /* __LUNAIX_SPIKE_H */