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/)
30 * Copyright 2008 Bernie Innocenti <bernie@codewiz.org>
33 * \brief OS-specific definitions
36 * \author Bernie Innocenti <bernie@codewiz.org>
43 * OS autodetection (Some systems trigger multiple OS definitions)
49 // FIXME: Maybe disable Win32 exceptions?
50 typedef int cpu_flags_t;
51 #define IRQ_DISABLE FIXME
52 #define IRQ_ENABLE FIXME
53 #define IRQ_SAVE_DISABLE(old_sigs) FIXME
54 #define IRQ_RESTORE(old_sigs) FIXME
60 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
62 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
66 * The POSIX moral equivalent of disabling IRQs is disabling signals.
69 typedef sigset_t cpu_flags_t;
71 #define SET_ALL_SIGNALS(sigs) \
74 sigdelset(&sigs, SIGINT); \
75 sigdelset(&sigs, SIGSTOP); \
76 sigdelset(&sigs, SIGCONT); \
82 SET_ALL_SIGNALS(sigs); \
83 sigprocmask(SIG_BLOCK, &sigs, NULL); \
89 SET_ALL_SIGNALS(sigs); \
90 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
93 #define IRQ_SAVE_DISABLE(old_sigs) \
96 SET_ALL_SIGNALS(sigs); \
97 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
100 #define IRQ_RESTORE(old_sigs) \
102 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
105 #define IRQ_ENABLED() \
108 sigprocmask(SIG_SETMASK, NULL, &sigs__); \
109 sigismember(&sigs__, SIGALRM) ? false : true; \
123 #if defined(__APPLE__) && defined(__MACH__)
130 #include "cfg/cfg_arch.h" /* For ARCH_QT */
133 * We want Qt and other frameworks to look like OSes because you would
134 * tipically want their portable abstractions if you're using one of these.
136 #if defined(_QT) || (defined(ARCH_QT) && (ARCH & ARCH_QT))
145 * Summarize hosted environments as OS_HOSTED and embedded
146 * environment with OS_EMBEDDED.
148 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
150 #define OS_EMBEDDED 0
153 #define OS_EMBEDDED 1
155 /* Embedded environments fall back to CPU-specific code. */
159 /* Self-check for the detection */
161 #error OS_ID not defined
163 #if OS_HOSTED && OS_EMBEDDED
164 #error Both hosted and embedded OS environment
166 #if !OS_HOSTED && !OS_EMBEDDED
167 #error Neither hosted nor embedded OS environment
172 /// Macro to include OS-specific headers.
173 #define OS_HEADER(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).h)
175 /// Macro to include OS-specific source files.
176 #define OS_CSOURCE(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).c)
179 // Fallbacks for embedded systems
180 #define OS_HEADER(module) CPU_HEADER(module)
181 #define OS_CSOURCE(module) CPU_CSOURCE(module)
184 #endif /* CFG_OS_H */