kolibrios/kernel/branches/kolibri_pe/include/core.h
Sergey Semyonov (Serge) b7083f5742 new memory management for kernel heap
git-svn-id: svn://kolibrios.org@888 a494cfbc-eb01-0410-851d-a64ba20cac60
2008-10-29 15:55:39 +00:00

103 lines
2.0 KiB
C

#define OS_BASE 0xE0000000
void printf (const char *format, ...);
#define CALLER ((addr_t) __builtin_return_address(0))
extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
#ifdef CONFIG_DEBUG
# define panic(format, ...) \
panic_printf("Kernel panic in %s() at %s:%u: " format, __func__, \
__FILE__, __LINE__, ##__VA_ARGS__);
# define ASSERT(expr) \
if (!(expr)) { \
panic("assertion failed (%s), caller=%p\n", #expr, CALLER); \
}
#define DBG(format,...) printf(format,##__VA_ARGS__)
#else
# define panic(format, ...) \
panic_printf("Kernel panic: " format, ##__VA_ARGS__);
# define ASSERT(expr)
# define DBG(format,...)
# define PANIC(expr) \
if (!(expr)) { \
panic_printf("Kernel panic in %s() at %s:%u: " \
"assertion failed (%s)",__func__ ,__FILE__,__LINE__, \
#expr); \
};
#endif
static inline eflags_t safe_cli(void)
{
eflags_t tmp;
asm volatile (
"pushfl\n\t"
"popl %0\n\t"
"cli\n"
: "=r" (tmp)
);
return tmp;
}
static inline void safe_sti(eflags_t efl)
{
asm volatile (
"pushl %0\n\t"
"popfl\n"
: : "r" (efl)
);
}
static inline count_t fnzb(u32_t arg)
{
count_t n;
asm volatile ("xorl %0, %0 \n\t"
"bsr %1, %0"
:"=&r" (n)
:"r"(arg)
);
return n;
}
static inline count_t _bsf(u32_t arg)
{
count_t n;
asm volatile ("xorl %0, %0 \n\t"
"bsf %1, %0"
:"=&r" (n)
:"r"(arg)
);
return n;
}
static inline void _bts(u32_t *data, count_t val)
{
asm volatile ("bts %0, %1 \n\t"
:
:"g"(data), "r"(val)
:"cc"
);
}
static inline void _btr(u32_t *data, count_t val)
{
asm volatile ("btr %0, %1 \n\t"
:
:"g"(data), "r"(val)
:"cc"
);
}