4 * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5 * This file is part of DevLib - See README.devlib for information.
8 * \brief OS-specific definitions
12 * \author Bernardo Innocenti <bernie@develer.com>
17 *#* Revision 1.11 2007/09/29 16:19:47 bernie
18 *#* Changes to compile with sparse.
20 *#* Revision 1.10 2006/07/19 12:56:25 bernie
21 *#* Convert to new Doxygen style.
23 *#* Revision 1.9 2006/03/22 13:34:34 bernie
26 *#* Revision 1.8 2006/02/23 09:09:28 bernie
27 *#* Remove Linux specific hack.
29 *#* Revision 1.7 2006/02/20 01:46:59 bernie
32 *#* Revision 1.6 2006/02/15 09:12:33 bernie
33 *#* Don't mask useful user signals on UNIX.
35 *#* Revision 1.5 2005/11/27 23:32:42 bernie
36 *#* Add CPU fallback for OS_ID.
38 *#* Revision 1.4 2005/11/27 03:07:13 bernie
39 *#* IRQ_SAVE_DISABLE(): Really block signals.
41 *#* Revision 1.3 2005/11/27 03:02:40 bernie
42 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
44 *#* Revision 1.2 2005/11/04 16:20:01 bernie
45 *#* Fix reference to README.devlib in header.
47 *#* Revision 1.1 2005/04/11 19:04:13 bernie
48 *#* Move top-level headers to cfg/ subdir.
50 *#* Revision 1.1 2004/12/31 17:40:24 bernie
51 *#* Add OS detection code.
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)
62 * OS autodetection (Some systems trigger multiple OS definitions)
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 */
79 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
81 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
85 * The POSIX moral equivalent of disabling IRQs is disabling signals.
88 typedef sigset_t cpuflags_t;
90 #define SET_ALL_SIGNALS(sigs) \
93 sigdelset(&sigs, SIGINT); \
94 sigdelset(&sigs, SIGSTOP); \
95 sigdelset(&sigs, SIGCONT); \
101 SET_ALL_SIGNALS(sigs); \
102 sigprocmask(SIG_BLOCK, &sigs, NULL); \
108 SET_ALL_SIGNALS(sigs); \
109 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
112 #define IRQ_SAVE_DISABLE(old_sigs) \
115 SET_ALL_SIGNALS(sigs); \
116 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
119 #define IRQ_RESTORE(old_sigs) \
121 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
134 #if defined(__APPLE__) && defined(__MACH__)
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.
153 * Summarize hosted environments as OS_HOSTED and embedded
154 * environment with OS_EMBEDDED.
156 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
158 #define OS_EMBEDDED 0
161 #define OS_EMBEDDED 1
163 /* Embedded environments fall back to CPU-specific code. */
167 /* Self-check for the detection */
169 #error OS_ID not defined
171 #if OS_HOSTED && OS_EMBEDDED
172 #error Both hosted and embedded OS environment
174 #if !OS_HOSTED && !OS_EMBEDDED
175 #error Neither hosted nor embedded OS environment
178 #endif /* DEVLIB_OS_H */