root / Whitix / branches / hybrid / include / typedefs.h

Revision 33, 2.4 kB (checked in by mwhitworth, 6 months ago)

Move /Devices to /System/Devices.

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#define SaveFlags(flags) \
33        asm volatile("pushfl ; popl %0" : "=g"(flags))
34
35#define RestoreFlags(flags) \
36        asm volatile("pushl %0 ; popfl" :: "g"(flags) : "memory","cc")
37
38#define IrqSaveFlags(flags) do{ SaveFlags(flags); cli(); } while(0)
39#define IrqRestoreFlags(flags) do{ RestoreFlags(flags); } while(0)
40
41#ifndef true
42#define true 1
43#endif
44
45
46#ifndef false
47#define false 0
48#endif
49
50
51#ifndef NULL
52#define NULL 0
53#endif
54
55
56typedef unsigned char BYTE;
57typedef unsigned short WORD;
58typedef unsigned long DWORD;
59typedef unsigned long long QWORD;
60
61#define PACKED __attribute__((packed))
62#define LIKELY(condition) __builtin_expect((condition),1)
63#define UNLIKELY(condition) __builtin_expect((condition),0)
64
65#define count(array) (sizeof(array)/sizeof(array[0]))
66
67/* More of a per-arch thing */
68struct SpinlockTag
69{
70        DWORD flags;
71};
72
73typedef struct SpinlockTag Spinlock;
74
75#define SpinlockIrqSave(sLock)
76#define SpinlockIrqRestore(sLock)
77#define SpinLockIrq(sLock) IrqSaveFlags((sLock)->flags)
78#define SpinUnlockIrq(sLock) IrqRestoreFlags((sLock)->flags)
79#define SpinLock(sLock)
80#define SpinUnlock(sLock)
81
82/* Useful */
83#define PTR_ERROR(ptr) ((!(ptr)) ? -EFAULT : 0)
84
85static inline int IrqsEnabled()
86{
87        DWORD flags;
88        SaveFlags(flags);
89        return (flags >> 9) & 1;
90}
91
92/* Place somewhere else */
93#define DEVICES_PATH "/System/Devices/"
94
95#endif
Note: See TracBrowser for help on using the browser.