added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / kernel.h
1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H
3
4 /*
5  * 'kernel.h' contains some often-used function prototypes etc
6  */
7
8 #ifdef __KERNEL__
9
10 #include <stdarg.h>
11 #include <linux/linkage.h>
12 #include <linux/stddef.h>
13 #include <linux/types.h>
14 #include <linux/compiler.h>
15 #include <asm/byteorder.h>
16
17 /* Optimization barrier */
18 /* The "volatile" is due to gcc bugs */
19 #define barrier() __asm__ __volatile__("": : :"memory")
20
21 #define INT_MAX         ((int)(~0U>>1))
22 #define INT_MIN         (-INT_MAX - 1)
23 #define UINT_MAX        (~0U)
24 #define LONG_MAX        ((long)(~0UL>>1))
25 #define LONG_MIN        (-LONG_MAX - 1)
26 #define ULONG_MAX       (~0UL)
27
28 #define STACK_MAGIC     0xdeadbeef
29
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31
32 #define KERN_EMERG      "<0>"   /* system is unusable                   */
33 #define KERN_ALERT      "<1>"   /* action must be taken immediately     */
34 #define KERN_CRIT       "<2>"   /* critical conditions                  */
35 #define KERN_ERR        "<3>"   /* error conditions                     */
36 #define KERN_WARNING    "<4>"   /* warning conditions                   */
37 #define KERN_NOTICE     "<5>"   /* normal but significant condition     */
38 #define KERN_INFO       "<6>"   /* informational                        */
39 #define KERN_DEBUG      "<7>"   /* debug-level messages                 */
40
41 extern int console_printk[];
42
43 #define console_loglevel (console_printk[0])
44 #define default_message_loglevel (console_printk[1])
45 #define minimum_console_loglevel (console_printk[2])
46 #define default_console_loglevel (console_printk[3])
47
48 # define NORET_TYPE    /**/
49 # define ATTRIB_NORET  __attribute__((noreturn))
50 # define NORET_AND     noreturn,
51
52 #ifdef __i386__
53 #define FASTCALL(x)     x __attribute__((regparm(3)))
54 #else
55 #define FASTCALL(x)     x
56 #endif
57
58 struct completion;
59
60 extern struct notifier_block *panic_notifier_list;
61 NORET_TYPE void panic(const char * fmt, ...)
62         __attribute__ ((NORET_AND format (printf, 1, 2)));
63 asmlinkage NORET_TYPE void do_exit(long error_code)
64         ATTRIB_NORET;
65 NORET_TYPE void complete_and_exit(struct completion *, long)
66         ATTRIB_NORET;
67 extern int abs(int);
68 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
69 extern long simple_strtol(const char *,char **,unsigned int);
70 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
71 extern long long simple_strtoll(const char *,char **,unsigned int);
72 extern int sprintf(char * buf, const char * fmt, ...)
73         __attribute__ ((format (printf, 2, 3)));
74 extern int vsprintf(char *buf, const char *, va_list);
75 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
76         __attribute__ ((format (printf, 3, 4)));
77 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
78
79 extern int sscanf(const char *, const char *, ...)
80         __attribute__ ((format (scanf,2,3)));
81 extern int vsscanf(const char *, const char *, va_list);
82
83 extern int get_option(char **str, int *pint);
84 extern char *get_options(char *str, int nints, int *ints);
85 extern unsigned long long memparse(char *ptr, char **retptr);
86 extern void dev_probe_lock(void);
87 extern void dev_probe_unlock(void);
88
89 extern int session_of_pgrp(int pgrp);
90
91 asmlinkage int printk(const char * fmt, ...)
92         __attribute__ ((format (printf, 1, 2)));
93
94 static inline void console_silent(void)
95 {
96         console_loglevel = 0;
97 }
98
99 static inline void console_verbose(void)
100 {
101         if (console_loglevel)
102                 console_loglevel = 15;
103 }
104
105 extern void bust_spinlocks(int yes);
106 extern int oops_in_progress;            /* If set, an oops, panic(), BUG() or die() is in progress */
107
108 extern int tainted;
109 extern const char *print_tainted(void);
110
111 extern void dump_stack(void);
112
113 #if DEBUG
114 #define pr_debug(fmt,arg...) \
115         printk(KERN_DEBUG fmt,##arg)
116 #else
117 #define pr_debug(fmt,arg...) \
118         do { } while (0)
119 #endif
120
121 #define pr_info(fmt,arg...) \
122         printk(KERN_INFO fmt,##arg)
123
124 /*
125  *      Display an IP address in readable format.
126  */
127
128 #define NIPQUAD(addr) \
129         ((unsigned char *)&addr)[0], \
130         ((unsigned char *)&addr)[1], \
131         ((unsigned char *)&addr)[2], \
132         ((unsigned char *)&addr)[3]
133
134 #if defined(__LITTLE_ENDIAN)
135 #define HIPQUAD(addr) \
136         ((unsigned char *)&addr)[3], \
137         ((unsigned char *)&addr)[2], \
138         ((unsigned char *)&addr)[1], \
139         ((unsigned char *)&addr)[0]
140 #elif defined(__BIG_ENDIAN)
141 #define HIPQUAD NIPQUAD
142 #else
143 #error "Please fix asm/byteorder.h"
144 #endif /* __LITTLE_ENDIAN */
145
146 /*
147  * min()/max() macros that also do
148  * strict type-checking.. See the
149  * "unnecessary" pointer comparison.
150  */
151 #define min(x,y) ({ \
152         const typeof(x) _x = (x);       \
153         const typeof(y) _y = (y);       \
154         (void) (&_x == &_y);            \
155         _x < _y ? _x : _y; })
156
157 #define max(x,y) ({ \
158         const typeof(x) _x = (x);       \
159         const typeof(y) _y = (y);       \
160         (void) (&_x == &_y);            \
161         _x > _y ? _x : _y; })
162
163 /*
164  * ..and if you can't take the strict
165  * types, you can specify one yourself.
166  *
167  * Or not use min/max at all, of course.
168  */
169 #define min_t(type,x,y) \
170         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
171 #define max_t(type,x,y) \
172         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
173
174 extern void __out_of_line_bug(int line) ATTRIB_NORET;
175 #define out_of_line_bug() __out_of_line_bug(__LINE__)
176
177 #endif /* __KERNEL__ */
178
179 #define SI_LOAD_SHIFT   16
180 struct sysinfo {
181         long uptime;                    /* Seconds since boot */
182         unsigned long loads[3];         /* 1, 5, and 15 minute load averages */
183         unsigned long totalram;         /* Total usable main memory size */
184         unsigned long freeram;          /* Available memory size */
185         unsigned long sharedram;        /* Amount of shared memory */
186         unsigned long bufferram;        /* Memory used by buffers */
187         unsigned long totalswap;        /* Total swap space size */
188         unsigned long freeswap;         /* swap space still available */
189         unsigned short procs;           /* Number of current processes */
190         unsigned short pad;             /* explicit padding for m68k */
191         unsigned long totalhigh;        /* Total high memory size */
192         unsigned long freehigh;         /* Available high memory size */
193         unsigned int mem_unit;          /* Memory unit size in bytes */
194         char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
195 };
196
197 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
198
199 #endif /* _LINUX_KERNEL_H */