4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
33 * \brief OS-specific definitions
37 * \author Bernardo Innocenti <bernie@develer.com>
42 *#* Revision 1.11 2007/09/29 16:19:47 bernie
43 *#* Changes to compile with sparse.
45 *#* Revision 1.10 2006/07/19 12:56:25 bernie
46 *#* Convert to new Doxygen style.
48 *#* Revision 1.9 2006/03/22 13:34:34 bernie
51 *#* Revision 1.8 2006/02/23 09:09:28 bernie
52 *#* Remove Linux specific hack.
54 *#* Revision 1.7 2006/02/20 01:46:59 bernie
57 *#* Revision 1.6 2006/02/15 09:12:33 bernie
58 *#* Don't mask useful user signals on UNIX.
60 *#* Revision 1.5 2005/11/27 23:32:42 bernie
61 *#* Add CPU fallback for OS_ID.
63 *#* Revision 1.4 2005/11/27 03:07:13 bernie
64 *#* IRQ_SAVE_DISABLE(): Really block signals.
66 *#* Revision 1.3 2005/11/27 03:02:40 bernie
67 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
69 *#* Revision 1.2 2005/11/04 16:20:01 bernie
70 *#* Fix reference to README.devlib in header.
72 *#* Revision 1.1 2005/04/11 19:04:13 bernie
73 *#* Move top-level headers to cfg/ subdir.
75 *#* Revision 1.1 2004/12/31 17:40:24 bernie
76 *#* Add OS detection code.
82 /** Macro to include OS-specific versions of the headers. */
83 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
84 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
87 * OS autodetection (Some systems trigger multiple OS definitions)
93 // FIXME: Maybe disable Win32 exceptions?
94 typedef int cpuflags_t;
95 #define IRQ_DISABLE /* FIXME */
96 #define IRQ_ENABLE /* FIXME */
97 #define IRQ_SAVE_DISABLE(old_sigs) /* FIXME */
98 #define IRQ_RESTORE(old_sigs) /* FIXME */
104 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
106 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
110 * The POSIX moral equivalent of disabling IRQs is disabling signals.
113 typedef sigset_t cpuflags_t;
115 #define SET_ALL_SIGNALS(sigs) \
118 sigdelset(&sigs, SIGINT); \
119 sigdelset(&sigs, SIGSTOP); \
120 sigdelset(&sigs, SIGCONT); \
123 #define IRQ_DISABLE \
126 SET_ALL_SIGNALS(sigs); \
127 sigprocmask(SIG_BLOCK, &sigs, NULL); \
133 SET_ALL_SIGNALS(sigs); \
134 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
137 #define IRQ_SAVE_DISABLE(old_sigs) \
140 SET_ALL_SIGNALS(sigs); \
141 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
144 #define IRQ_RESTORE(old_sigs) \
146 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
159 #if defined(__APPLE__) && defined(__MACH__)
166 * We want Qt and other frameworks to look like OSes because you would
167 * tipically want their portable abstractions if you're using one of these.
178 * Summarize hosted environments as OS_HOSTED and embedded
179 * environment with OS_EMBEDDED.
181 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
183 #define OS_EMBEDDED 0
186 #define OS_EMBEDDED 1
188 /* Embedded environments fall back to CPU-specific code. */
192 /* Self-check for the detection */
194 #error OS_ID not defined
196 #if OS_HOSTED && OS_EMBEDDED
197 #error Both hosted and embedded OS environment
199 #if !OS_HOSTED && !OS_EMBEDDED
200 #error Neither hosted nor embedded OS environment
203 #endif /* DEVLIB_OS_H */