2008-08-13 21:13:40 +02:00
|
|
|
|
|
|
|
#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); \
|
|
|
|
}
|
2008-09-12 12:56:47 +02:00
|
|
|
|
|
|
|
#define DBG(format,...) printf(format,##__VA_ARGS__)
|
|
|
|
|
2008-08-13 21:13:40 +02:00
|
|
|
#else
|
2008-09-12 12:56:47 +02:00
|
|
|
|
2008-08-13 21:13:40 +02:00
|
|
|
# define panic(format, ...) \
|
|
|
|
panic_printf("Kernel panic: " format, ##__VA_ARGS__);
|
|
|
|
|
|
|
|
# define ASSERT(expr)
|
2008-09-12 12:56:47 +02:00
|
|
|
|
|
|
|
# define DBG(format,...)
|
|
|
|
|
2008-10-29 16:55:39 +01:00
|
|
|
# define PANIC(expr) \
|
|
|
|
if (!(expr)) { \
|
|
|
|
panic_printf("Kernel panic in %s() at %s:%u: " \
|
|
|
|
"assertion failed (%s)",__func__ ,__FILE__,__LINE__, \
|
|
|
|
#expr); \
|
|
|
|
};
|
|
|
|
|
2008-08-13 21:13:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static inline eflags_t safe_cli(void)
|
|
|
|
{
|
|
|
|
eflags_t tmp;
|
|
|
|
asm volatile (
|
2008-10-27 21:47:58 +01:00
|
|
|
"pushfl\n\t"
|
|
|
|
"popl %0\n\t"
|
2008-08-13 21:13:40 +02:00
|
|
|
"cli\n"
|
|
|
|
: "=r" (tmp)
|
|
|
|
);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void safe_sti(eflags_t efl)
|
|
|
|
{
|
|
|
|
asm volatile (
|
2008-10-27 21:47:58 +01:00
|
|
|
"pushl %0\n\t"
|
|
|
|
"popfl\n"
|
2008-08-13 21:13:40 +02:00
|
|
|
: : "r" (efl)
|
|
|
|
);
|
|
|
|
}
|
2008-09-10 15:04:24 +02:00
|
|
|
|
|
|
|
static inline count_t fnzb(u32_t arg)
|
|
|
|
{
|
|
|
|
count_t n;
|
2008-10-27 21:47:58 +01:00
|
|
|
asm volatile ("xorl %0, %0 \n\t"
|
|
|
|
"bsr %1, %0"
|
2008-09-10 15:04:24 +02:00
|
|
|
:"=&r" (n)
|
|
|
|
:"r"(arg)
|
|
|
|
);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline count_t _bsf(u32_t arg)
|
|
|
|
{
|
|
|
|
count_t n;
|
2008-10-27 21:47:58 +01:00
|
|
|
asm volatile ("xorl %0, %0 \n\t"
|
|
|
|
"bsf %1, %0"
|
2008-09-10 15:04:24 +02:00
|
|
|
:"=&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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-10-30 07:30:13 +01:00
|
|
|
extern inline void _btr(u32_t *data, count_t val)
|
2008-09-10 15:04:24 +02:00
|
|
|
{
|
|
|
|
asm volatile ("btr %0, %1 \n\t"
|
|
|
|
:
|
|
|
|
:"g"(data), "r"(val)
|
|
|
|
:"cc"
|
|
|
|
);
|
|
|
|
}
|
2008-10-30 07:30:13 +01:00
|
|
|
|
|
|
|
extern inline void* load_file(const char *path, size_t *size)
|
|
|
|
{
|
|
|
|
void* retval;
|
|
|
|
size_t tmp;
|
|
|
|
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
"pushl %%eax \n\t"
|
|
|
|
"call _load_file@4 \n\t"
|
|
|
|
:"=eax" (retval), "=ebx"(tmp)
|
|
|
|
:"a" (path) );
|
|
|
|
|
|
|
|
if(size)
|
|
|
|
*size = tmp;
|
|
|
|
return retval;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//extern __fastcall void* load_file(const char *path, size_t *size);
|