Subversion Repositories Kolibri OS

Rev

Rev 854 | Rev 862 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #define OS_BASE 0xE0000000
  3.  
  4.  
  5. void printf (const char *format, ...);
  6.  
  7. #define CALLER ((addr_t) __builtin_return_address(0))
  8.  
  9. extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
  10.  
  11. #ifdef CONFIG_DEBUG
  12.  
  13. # define panic(format, ...) \
  14.                 panic_printf("Kernel panic in %s() at %s:%u: " format, __func__, \
  15.                 __FILE__, __LINE__, ##__VA_ARGS__);
  16.  
  17. #       define ASSERT(expr) \
  18.                 if (!(expr)) { \
  19.                         panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
  20.                 }
  21. #else
  22. #       define panic(format, ...) \
  23.                 panic_printf("Kernel panic: " format, ##__VA_ARGS__);
  24.  
  25. # define ASSERT(expr)
  26. #endif
  27.  
  28.  
  29. static inline eflags_t safe_cli(void)
  30. {
  31.   eflags_t tmp;
  32.         asm volatile (
  33.     "pushf\n\t"
  34.     "pop %0\n\t"
  35.                 "cli\n"
  36.     : "=r" (tmp)
  37.         );
  38.   return tmp;
  39. }
  40.  
  41. static inline void safe_sti(eflags_t efl)
  42. {
  43.         asm volatile (
  44.     "push %0\n\t"
  45.                 "popf\n"
  46.     : : "r" (efl)
  47.         );
  48. }
  49.  
  50. static inline count_t fnzb(u32_t arg)
  51. {
  52.   count_t n;
  53.   asm volatile ("xor %0, %0 \n\t"
  54.                 "bsr %0, %1"
  55.                 :"=&r" (n)
  56.                 :"r"(arg)
  57.                 );
  58.         return n;
  59. }
  60.  
  61. static inline count_t _bsf(u32_t arg)
  62. {
  63.   count_t n;
  64.   asm volatile ("xor %0, %0 \n\t"
  65.                 "bsf %0, %1"
  66.                 :"=&r" (n)
  67.                 :"r"(arg)
  68.                 );
  69.         return n;
  70. }
  71.  
  72. static inline void _bts(u32_t *data, count_t val)
  73. {
  74.   asm volatile ("bts %0, %1 \n\t"
  75.                 :
  76.                 :"g"(data), "r"(val)
  77.                 :"cc"
  78.                 );
  79. }
  80.  
  81. static inline void _btr(u32_t *data, count_t val)
  82. {
  83.   asm volatile ("btr %0, %1 \n\t"
  84.                 :
  85.                 :"g"(data), "r"(val)
  86.                 :"cc"
  87.                 );
  88. }
  89.