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.10 2006/07/19 12:56:25 bernie
18 *#* Convert to new Doxygen style.
20 *#* Revision 1.9 2006/03/22 13:34:34 bernie
23 *#* Revision 1.8 2006/02/23 09:09:28 bernie
24 *#* Remove Linux specific hack.
26 *#* Revision 1.7 2006/02/20 01:46:59 bernie
29 *#* Revision 1.6 2006/02/15 09:12:33 bernie
30 *#* Don't mask useful user signals on UNIX.
32 *#* Revision 1.5 2005/11/27 23:32:42 bernie
33 *#* Add CPU fallback for OS_ID.
35 *#* Revision 1.4 2005/11/27 03:07:13 bernie
36 *#* IRQ_SAVE_DISABLE(): Really block signals.
38 *#* Revision 1.3 2005/11/27 03:02:40 bernie
39 *#* Add POSIX emulation for IRQ_* macros; Add Qt support.
41 *#* Revision 1.2 2005/11/04 16:20:01 bernie
42 *#* Fix reference to README.devlib in header.
44 *#* Revision 1.1 2005/04/11 19:04:13 bernie
45 *#* Move top-level headers to cfg/ subdir.
47 *#* Revision 1.1 2004/12/31 17:40:24 bernie
48 *#* Add OS detection code.
54 /** Macro to include OS-specific versions of the headers. */
55 #define OS_HEADER(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
56 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
59 * OS autodetection (Some systems trigger multiple OS definitions)
65 // FIXME: Maybe disable Win32 exceptions?
66 typedef int cpuflags_t;
67 #define IRQ_DISABLE /* FIXME */
68 #define IRQ_ENABLE /* FIXME */
69 #define IRQ_SAVE_DISABLE(old_sigs) /* FIXME */
70 #define IRQ_RESTORE(old_sigs) /* FIXME */
76 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
78 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
82 * The POSIX moral equivalent of disabling IRQs is disabling signals.
85 typedef sigset_t cpuflags_t;
87 #define SET_ALL_SIGNALS(sigs) \
90 sigdelset(&sigs, SIGINT); \
91 sigdelset(&sigs, SIGSTOP); \
92 sigdelset(&sigs, SIGCONT); \
98 SET_ALL_SIGNALS(sigs); \
99 sigprocmask(SIG_BLOCK, &sigs, NULL); \
105 SET_ALL_SIGNALS(sigs); \
106 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
109 #define IRQ_SAVE_DISABLE(old_sigs) \
112 SET_ALL_SIGNALS(sigs); \
113 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
116 #define IRQ_RESTORE(old_sigs) \
118 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
131 #if defined(__APPLE__) && defined(__MACH__)
138 * We want Qt and other frameworks to look like OSes because you would
139 * tipically want their portable abstractions if you're using one of these.
150 * Summarize hosted environments as OS_HOSTED and embedded
151 * environment with OS_EMBEDDED.
153 #if OS_WIN32 || OS_UNIX || OS_DARWIN
155 #define OS_EMBEDDED 0
158 #define OS_EMBEDDED 1
160 /* Embedded environments fall back to CPU-specific code. */
164 /* Self-check for the detection */
166 #error OS_ID not defined
168 #if OS_HOSTED && OS_EMBEDDED
169 #error Both hosted and embedded OS environment
171 #if !OS_HOSTED && !OS_EMBEDDED
172 #error Neither hosted nor embedded OS environment
175 #endif /* DEVLIB_OS_H */