Subversion Repositories Kolibri OS

Rev

Rev 888 | Rev 890 | 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. # define PANIC(expr)   \
  34.       if (!(expr)) {   \
  35.          panic_printf("Kernel panic in %s() at %s:%u: " \
  36.                       "assertion failed (%s)",__func__ ,__FILE__,__LINE__, \
  37.                        #expr); \
  38.       };
  39.  
  40. #endif
  41.  
  42.  
  43. static inline eflags_t safe_cli(void)
  44. {
  45.   eflags_t tmp;
  46.         asm volatile (
  47.     "pushfl\n\t"
  48.     "popl %0\n\t"
  49.                 "cli\n"
  50.     : "=r" (tmp)
  51.         );
  52.   return tmp;
  53. }
  54.  
  55. static inline void safe_sti(eflags_t efl)
  56. {
  57.         asm volatile (
  58.     "pushl %0\n\t"
  59.     "popfl\n"
  60.     : : "r" (efl)
  61.         );
  62. }
  63.  
  64. static inline count_t fnzb(u32_t arg)
  65. {
  66.   count_t n;
  67.   asm volatile ("xorl %0, %0 \n\t"
  68.                 "bsr %1, %0"
  69.                 :"=&r" (n)
  70.                 :"r"(arg)
  71.                 );
  72.         return n;
  73. }
  74.  
  75. static inline count_t _bsf(u32_t arg)
  76. {
  77.   count_t n;
  78.   asm volatile ("xorl %0, %0 \n\t"
  79.                 "bsf %1, %0"
  80.                 :"=&r" (n)
  81.                 :"r"(arg)
  82.                 );
  83.         return n;
  84. }
  85.  
  86. static inline void _bts(u32_t *data, count_t val)
  87. {
  88.   asm volatile ("bts %0, %1 \n\t"
  89.                 :
  90.                 :"g"(data), "r"(val)
  91.                 :"cc"
  92.                 );
  93. }
  94.  
  95. extern inline void _btr(u32_t *data, count_t val)
  96. {
  97.   asm volatile ("btr %0, %1 \n\t"
  98.                 :
  99.                 :"g"(data), "r"(val)
  100.                 :"cc"
  101.                 );
  102. }
  103.  
  104. extern inline void* load_file(const char *path, size_t *size)
  105. {
  106.      void* retval;
  107.      size_t tmp;
  108.  
  109.      __asm__ __volatile__ (
  110.      "pushl %%eax           \n\t"
  111.      "call _load_file@4     \n\t"
  112.      :"=eax" (retval), "=ebx"(tmp)
  113.      :"a" (path) );
  114.  
  115.      if(size)
  116.         *size = tmp;
  117.      return retval;
  118. };
  119.  
  120.  
  121. //extern __fastcall void* load_file(const char *path, size_t *size);
  122.