Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #define OS_BASE     0xE0000000
  3. #define IMAGE_BASE  0xE0100000
  4. #define LOAD_BASE   0x00100000
  5.  
  6. void printf (const char *format, ...);
  7.  
  8. #define CALLER ((addr_t) __builtin_return_address(0))
  9.  
  10. extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
  11.  
  12. #ifdef CONFIG_DEBUG
  13.  
  14. # define panic(format, ...) \
  15.                 panic_printf("Kernel panic in %s() at %s:%u: " format, __func__, \
  16.                 __FILE__, __LINE__, ##__VA_ARGS__);
  17.  
  18. #       define ASSERT(expr) \
  19.                 if (!(expr)) { \
  20.                         panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
  21.                 }
  22.  
  23. #define DBG(format,...) printf(format,##__VA_ARGS__)
  24.  
  25. #else
  26.  
  27. #       define panic(format, ...) \
  28.                 panic_printf("Kernel panic: " format, ##__VA_ARGS__);
  29.  
  30. # define ASSERT(expr)
  31.  
  32. # define DBG(format,...)
  33.  
  34. # define PANIC(expr)   \
  35.       if (!(expr)) {   \
  36.          panic_printf("Kernel panic in %s() at %s:%u: " \
  37.                       "assertion failed (%s)",__func__ ,__FILE__,__LINE__, \
  38.                        #expr); \
  39.       };
  40.  
  41. #endif
  42.  
  43.  
  44. static inline eflags_t safe_cli(void)
  45. {
  46.   eflags_t tmp;
  47.         asm volatile (
  48.     "pushfl\n\t"
  49.     "popl %0\n\t"
  50.                 "cli\n"
  51.     : "=r" (tmp)
  52.         );
  53.   return tmp;
  54. }
  55.  
  56. static inline void safe_sti(eflags_t efl)
  57. {
  58.         asm volatile (
  59.     "pushl %0\n\t"
  60.     "popfl\n"
  61.     : : "r" (efl)
  62.         );
  63. }
  64.  
  65. static inline count_t fnzb(u32_t arg)
  66. {
  67.   count_t n;
  68.   asm volatile ("xorl %0, %0 \n\t"
  69.                 "bsr %1, %0"
  70.                 :"=&r" (n)
  71.                 :"r"(arg)
  72.                 );
  73.         return n;
  74. }
  75.  
  76. static inline count_t _bsf(u32_t arg)
  77. {
  78.   count_t n;
  79.   asm volatile ("xorl %0, %0 \n\t"
  80.                 "bsf %1, %0"
  81.                 :"=&r" (n)
  82.                 :"r"(arg)
  83.                 );
  84.         return n;
  85. }
  86.  
  87. static inline void _bts(u32_t *data, count_t val)
  88. {
  89.   asm volatile ("bts %0, %1 \n\t"
  90.                 :
  91.                 :"g"(data), "r"(val)
  92.                 :"cc"
  93.                 );
  94. }
  95.  
  96. extern inline void _btr(u32_t *data, count_t val)
  97. {
  98.   asm volatile ("btr %0, %1 \n\t"
  99.                 :
  100.                 :"g"(data), "r"(val)
  101.                 :"cc"
  102.                 );
  103. }
  104.  
  105. extern inline void* load_file(const char *path, size_t *size)
  106. {
  107.      void* retval;
  108.      size_t tmp;
  109.  
  110.      __asm__ __volatile__ (
  111.      "pushl %%eax           \n\t"
  112.      "call _load_file@4     \n\t"
  113.      :"=eax" (retval), "=ebx"(tmp)
  114.      :"a" (path) );
  115.  
  116.      if(size)
  117.         *size = tmp;
  118.      return retval;
  119. };
  120.  
  121.  
  122. //extern __fastcall void* load_file(const char *path, size_t *size);
  123.