Sistema l'errore da me commesso in fase di conversione...
[bertos.git] / cfg / os.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5  * This file is part of DevLib - See README.devlib for information.
6  * -->
7  *
8  * \brief OS-specific definitions
9  *
10  * \version $Id$
11  *
12  * \author Bernardo Innocenti <bernie@develer.com>
13  */
14
15 /*#*
16  *#* $Log$
17  *#* Revision 1.11  2007/09/29 16:19:47  bernie
18  *#* Changes to compile with sparse.
19  *#*
20  *#* Revision 1.10  2006/07/19 12:56:25  bernie
21  *#* Convert to new Doxygen style.
22  *#*
23  *#* Revision 1.9  2006/03/22 13:34:34  bernie
24  *#* MSVC support.
25  *#*
26  *#* Revision 1.8  2006/02/23 09:09:28  bernie
27  *#* Remove Linux specific hack.
28  *#*
29  *#* Revision 1.7  2006/02/20 01:46:59  bernie
30  *#* Port to MacOSX.
31  *#*
32  *#* Revision 1.6  2006/02/15 09:12:33  bernie
33  *#* Don't mask useful user signals on UNIX.
34  *#*
35  *#* Revision 1.5  2005/11/27 23:32:42  bernie
36  *#* Add CPU fallback for OS_ID.
37  *#*
38  *#* Revision 1.4  2005/11/27 03:07:13  bernie
39  *#* IRQ_SAVE_DISABLE(): Really block signals.
40  *#*
41  *#* Revision 1.3  2005/11/27 03:02:40  bernie
42  *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
43  *#*
44  *#* Revision 1.2  2005/11/04 16:20:01  bernie
45  *#* Fix reference to README.devlib in header.
46  *#*
47  *#* Revision 1.1  2005/04/11 19:04:13  bernie
48  *#* Move top-level headers to cfg/ subdir.
49  *#*
50  *#* Revision 1.1  2004/12/31 17:40:24  bernie
51  *#* Add OS detection code.
52  *#*
53  *#*/
54 #ifndef DEVLIB_OS_H
55 #define DEVLIB_OS_H
56
57 /** Macro to include OS-specific versions of the headers. */
58 #define OS_HEADER(module)  PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
59 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
60
61 /*
62  * OS autodetection (Some systems trigger multiple OS definitions)
63  */
64 #ifdef _WIN32
65         #define OS_WIN32  1
66         #define OS_ID     win32
67
68         // FIXME: Maybe disable Win32 exceptions?
69         typedef int cpuflags_t;
70         #define IRQ_DISABLE                /* FIXME */
71         #define IRQ_ENABLE                 /* FIXME */
72         #define IRQ_SAVE_DISABLE(old_sigs) /* FIXME */
73         #define IRQ_RESTORE(old_sigs)      /* FIXME */
74
75 #else
76         #define OS_WIN32  0
77 #endif
78
79 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
80         #define OS_UNIX   1
81         #define OS_POSIX  1  /* Not strictly UNIX, but no way to autodetect it. */
82         #define OS_ID     posix
83
84         /*
85          * The POSIX moral equivalent of disabling IRQs is disabling signals.
86          */
87         #include <signal.h>
88         typedef sigset_t cpuflags_t;
89
90         #define SET_ALL_SIGNALS(sigs) \
91         do { \
92                 sigfillset(&sigs); \
93                 sigdelset(&sigs, SIGINT); \
94                 sigdelset(&sigs, SIGSTOP); \
95                 sigdelset(&sigs, SIGCONT); \
96         } while(0)
97
98         #define IRQ_DISABLE \
99         do { \
100                 sigset_t sigs; \
101                 SET_ALL_SIGNALS(sigs); \
102                 sigprocmask(SIG_BLOCK, &sigs, NULL); \
103         } while (0)
104
105         #define IRQ_ENABLE \
106         do { \
107                 sigset_t sigs; \
108                 SET_ALL_SIGNALS(sigs); \
109                 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
110         } while (0)
111
112         #define IRQ_SAVE_DISABLE(old_sigs) \
113         do { \
114                 sigset_t sigs; \
115                 SET_ALL_SIGNALS(sigs); \
116                 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
117         } while (0)
118
119         #define IRQ_RESTORE(old_sigs) \
120         do { \
121                 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
122         } while (0)
123 #else
124         #define OS_UNIX   0
125         #define OS_POSIX  0
126 #endif
127
128 #ifdef __linux__
129         #define OS_LINUX  1
130 #else
131         #define OS_LINUX  0
132 #endif
133
134 #if defined(__APPLE__) && defined(__MACH__)
135         #define OS_DARWIN 1
136 #else
137         #define OS_DARWIN 0
138 #endif
139
140 /*
141  * We want Qt and other frameworks to look like OSes because you would
142  * tipically want their portable abstractions if you're using one of these.
143  */
144 #if defined(_QT)
145         #define OS_QT 1
146         #undef  OS_ID
147         #define OS_ID qt
148 #else
149         #define OS_QT 0
150 #endif
151
152 /*
153  * Summarize hosted environments as OS_HOSTED and embedded
154  * environment with OS_EMBEDDED.
155  */
156 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
157         #define OS_HOSTED   1
158         #define OS_EMBEDDED 0
159 #else
160         #define OS_HOSTED   0
161         #define OS_EMBEDDED 1
162
163         /* Embedded environments fall back to CPU-specific code. */
164         #define OS_ID       CPU_ID
165 #endif
166
167 /* Self-check for the detection */
168 #if !defined(OS_ID)
169         #error OS_ID not defined
170 #endif
171 #if OS_HOSTED && OS_EMBEDDED
172         #error Both hosted and embedded OS environment
173 #endif
174 #if !OS_HOSTED && !OS_EMBEDDED
175         #error Neither hosted nor embedded OS environment
176 #endif
177
178 #endif /* DEVLIB_OS_H */