Subversion Repositories Kolibri OS

Rev

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