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
35 * \author Bernie Innocenti <bernie@codewiz.org>
41 #include "cfg/cfg_proc.h"
44 * OS autodetection (Some systems trigger multiple OS definitions)
50 // FIXME: Maybe disable Win32 exceptions?
51 typedef int cpu_flags_t;
52 #define IRQ_DISABLE FIXME
53 #define IRQ_ENABLE FIXME
54 #define IRQ_SAVE_DISABLE(old_sigs) FIXME
55 #define IRQ_RESTORE(old_sigs) FIXME
61 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
63 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
67 * The POSIX moral equivalent of disabling IRQs is disabling signals.
70 typedef sigset_t cpu_flags_t;
72 #define SET_ALL_SIGNALS(sigs) \
75 sigdelset(&sigs, SIGINT); \
76 sigdelset(&sigs, SIGSTOP); \
77 sigdelset(&sigs, SIGCONT); \
83 SET_ALL_SIGNALS(sigs); \
84 sigprocmask(SIG_BLOCK, &sigs, NULL); \
90 SET_ALL_SIGNALS(sigs); \
91 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
94 #define IRQ_SAVE_DISABLE(old_sigs) \
97 SET_ALL_SIGNALS(sigs); \
98 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
101 #define IRQ_RESTORE(old_sigs) \
103 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
106 #define IRQ_ENABLED() \
109 sigprocmask(SIG_SETMASK, NULL, &sigs__); \
110 sigismember(&sigs__, SIGALRM) ? false : true; \
113 #if (CONFIG_KERN && CONFIG_KERN_PREEMPT)
114 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
115 void vect(UNUSED_ARG(int, arg)); \
116 INLINE void __isr_##vect(void); \
117 void vect(UNUSED_ARG(int, arg)) \
120 IRQ_PREEMPT_HANDLER(); \
122 INLINE void __isr_##vect(void)
124 * With task priorities enabled each ISR is used a point to
125 * check if we need to perform a context switch.
127 * Instead, without priorities a context switch can occur only
128 * when the running task expires its time quantum. In this last
129 * case, the context switch can only occur in the timer ISR,
130 * that must be always declared with the
131 * DECLARE_ISR_CONTEXT_SWITCH() macro.
134 #define DECLARE_ISR(vect) \
135 DECLARE_ISR_CONTEXT_SWITCH(vect)
136 #endif /* CONFIG_KERN_PRI */
139 #define DECLARE_ISR(vect) \
140 void vect(UNUSED_ARG(int, arg))
142 #ifndef DECLARE_ISR_CONTEXT_SWITCH
143 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
144 void vect(UNUSED_ARG(int, arg))
158 #if defined(__APPLE__) && defined(__MACH__)
165 #include "cfg/cfg_arch.h" /* For ARCH_QT */
168 * We want Qt and other frameworks to look like OSes because you would
169 * tipically want their portable abstractions if you're using one of these.
171 #if defined(_QT) || (defined(ARCH_QT) && (ARCH & ARCH_QT))
180 * Summarize hosted environments as OS_HOSTED and embedded
181 * environment with OS_EMBEDDED.
183 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
185 #define OS_EMBEDDED 0
188 #define OS_EMBEDDED 1
190 /* Embedded environments fall back to CPU-specific code. */
194 /* Self-check for the detection */
196 #error OS_ID not defined
198 #if OS_HOSTED && OS_EMBEDDED
199 #error Both hosted and embedded OS environment
201 #if !OS_HOSTED && !OS_EMBEDDED
202 #error Neither hosted nor embedded OS environment
207 /// Macro to include OS-specific headers.
208 #define OS_HEADER(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).h)
210 /// Macro to include OS-specific source files.
211 #define OS_CSOURCE(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).c)
214 // Fallbacks for embedded systems
215 #define OS_HEADER(module) CPU_HEADER(module)
216 #define OS_CSOURCE(module) CPU_CSOURCE(module)
219 #endif /* CFG_OS_H */