Subversion Repositories Kolibri OS

Rev

Rev 862 | Rev 888 | 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.  
  22. #define DBG(format,...) printf(format,##__VA_ARGS__)
  23.  
  24. #else
  25.  
  26. #       define panic(format, ...) \
  27.                 panic_printf("Kernel panic: " format, ##__VA_ARGS__);
  28.  
  29. # define ASSERT(expr)
  30.  
  31. # define DBG(format,...)
  32.  
  33. #endif
  34.  
  35.  
  36. static inline eflags_t safe_cli(void)
  37. {
  38.   eflags_t tmp;
  39.         asm volatile (
  40.     "pushfl\n\t"
  41.     "popl %0\n\t"
  42.                 "cli\n"
  43.     : "=r" (tmp)
  44.         );
  45.   return tmp;
  46. }
  47.  
  48. static inline void safe_sti(eflags_t efl)
  49. {
  50.         asm volatile (
  51.     "pushl %0\n\t"
  52.     "popfl\n"
  53.     : : "r" (efl)
  54.         );
  55. }
  56.  
  57. static inline count_t fnzb(u32_t arg)
  58. {
  59.   count_t n;
  60.   asm volatile ("xorl %0, %0 \n\t"
  61.                 "bsr %1, %0"
  62.                 :"=&r" (n)
  63.                 :"r"(arg)
  64.                 );
  65.         return n;
  66. }
  67.  
  68. static inline count_t _bsf(u32_t arg)
  69. {
  70.   count_t n;
  71.   asm volatile ("xorl %0, %0 \n\t"
  72.                 "bsf %1, %0"
  73.                 :"=&r" (n)
  74.                 :"r"(arg)
  75.                 );
  76.         return n;
  77. }
  78.  
  79. static inline void _bts(u32_t *data, count_t val)
  80. {
  81.   asm volatile ("bts %0, %1 \n\t"
  82.                 :
  83.                 :"g"(data), "r"(val)
  84.                 :"cc"
  85.                 );
  86. }
  87.  
  88. static inline void _btr(u32_t *data, count_t val)
  89. {
  90.   asm volatile ("btr %0, %1 \n\t"
  91.                 :
  92.                 :"g"(data), "r"(val)
  93.                 :"cc"
  94.                 );
  95. }
  96.