root/Whitix/trunk/include/typedefs.h

Revision 1929, 2.5 KB (checked in by mwhitworth, 3 years ago)

Add RESULT_CHECK macro. Will be used a lot in upcoming releases.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#ifndef TYPEDEFS_H
20#define TYPEDEFS_H
21
22#define MIN(a,b) (((a < b) ? a : b))
23#define MAX(a,b) (((a > b) ? a : b))
24
25/* Some i386-isms */
26
27#define hlt() asm volatile("hlt" ::: "memory")
28#define cli() asm volatile("cli" ::: "memory")
29#define sti() asm volatile("sti" ::: "memory")
30#define nop() asm volatile("nop" ::: "memory")
31
32/* EFLAGS functions. */
33#define SaveFlags(flags) \
34        asm volatile("pushfl ; popl %0" : "=g"(flags))
35
36#define RestoreFlags(flags) \
37        asm volatile("pushl %0 ; popfl" :: "g"(flags) : "memory","cc")
38
39#define IrqSaveFlags(flags) do{ SaveFlags(flags); cli(); } while(0)
40#define IrqRestoreFlags(flags) do{ RestoreFlags(flags); } while(0)
41
42#ifndef true
43#define true 1
44#endif
45
46#ifndef false
47#define false 0
48#endif
49
50#ifndef NULL
51#define NULL 0
52#endif
53
54typedef unsigned char BYTE;
55typedef unsigned short WORD;
56typedef unsigned long DWORD;
57typedef unsigned long long QWORD;
58
59/* GCC functions */
60#define PACKED __attribute__((packed))
61#define LIKELY(condition) __builtin_expect((condition),1)
62#define UNLIKELY(condition) __builtin_expect((condition),0)
63
64#define count(array) (sizeof(array)/sizeof(array[0]))
65
66/* Useful */
67#define PTR_ERROR(ptr) ((!(ptr)) ? -EFAULT : 0)
68
69/* Check if IRQs are enabled, by looking at the EFLAGS register. */
70static inline int IrqsEnabled()
71{
72        DWORD flags;
73        SaveFlags(flags);
74        return (flags >> 9) & 1;
75}
76
77/* Place somewhere else */
78#define DEVICES_PATH "/System/Devices/"
79
80#define USED(x) ((void)x)
81
82#define RESULT_CHECK __attribute__((warn_unused_result))
83
84/* General macros */
85#define OffsetOf(type, member) __builtin_offsetof(type, member)
86
87#define ContainerOf(ptr, type, member) ({ \
88        const typeof( ((type *)NULL)->member ) * memPtr = (ptr);        \
89        (type *)( (char *)memPtr - OffsetOf(type, member) );})
90
91#define SIZE_ALIGN_UP(size, align) (((size)+(align-1)) & (~(align-1)))
92
93#endif
Note: See TracBrowser for help on using the browser.