Subversion Repositories Kolibri OS

Rev

Rev 889 | Rev 897 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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