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>
42 #include "cfg/cfg_proc.h"
45 * OS autodetection (Some systems trigger multiple OS definitions)
51 // FIXME: Maybe disable Win32 exceptions?
52 typedef int cpu_flags_t;
53 #define IRQ_DISABLE FIXME
54 #define IRQ_ENABLE FIXME
55 #define IRQ_SAVE_DISABLE(old_sigs) FIXME
56 #define IRQ_RESTORE(old_sigs) FIXME
62 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
64 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */
68 * The POSIX moral equivalent of disabling IRQs is disabling signals.
71 typedef sigset_t cpu_flags_t;
73 #define SET_ALL_SIGNALS(sigs) \
76 sigdelset(&sigs, SIGINT); \
77 sigdelset(&sigs, SIGSTOP); \
78 sigdelset(&sigs, SIGCONT); \
84 SET_ALL_SIGNALS(sigs); \
85 sigprocmask(SIG_BLOCK, &sigs, NULL); \
91 SET_ALL_SIGNALS(sigs); \
92 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
95 #define IRQ_SAVE_DISABLE(old_sigs) \
98 SET_ALL_SIGNALS(sigs); \
99 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
102 #define IRQ_RESTORE(old_sigs) \
104 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
107 #define IRQ_ENABLED() \
110 sigprocmask(SIG_SETMASK, NULL, &sigs__); \
111 sigismember(&sigs__, SIGALRM) ? false : true; \
114 #if CONFIG_KERN_PREEMPT
115 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
116 void vect(UNUSED_ARG(int, arg)); \
117 INLINE void __isr_##vect(void); \
118 void vect(UNUSED_ARG(int, arg)) \
121 IRQ_PREEMPT_HANDLER(); \
123 INLINE void __isr_##vect(void)
125 * With task priorities enabled each ISR is used a point to
126 * check if we need to perform a context switch.
128 * Instead, without priorities a context switch can occur only
129 * when the running task expires its time quantum. In this last
130 * case, the context switch can only occur in the timer ISR,
131 * that must be always declared with the
132 * DECLARE_ISR_CONTEXT_SWITCH() macro.
135 #define DECLARE_ISR(vect) \
136 DECLARE_ISR_CONTEXT_SWITCH(vect)
137 #endif /* CONFIG_KERN_PRI */
140 #define DECLARE_ISR(vect) \
141 void vect(UNUSED_ARG(int, arg))
143 #ifndef DECLARE_ISR_CONTEXT_SWITCH
144 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
145 void vect(UNUSED_ARG(int, arg))
159 #if defined(__APPLE__) && defined(__MACH__)
166 #include "cfg/cfg_arch.h" /* For ARCH_QT */
169 * We want Qt and other frameworks to look like OSes because you would
170 * tipically want their portable abstractions if you're using one of these.
172 #if defined(_QT) || (defined(ARCH_QT) && (ARCH & ARCH_QT))
181 * Summarize hosted environments as OS_HOSTED and embedded
182 * environment with OS_EMBEDDED.
184 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
186 #define OS_EMBEDDED 0
189 #define OS_EMBEDDED 1
191 /* Embedded environments fall back to CPU-specific code. */
195 /* Self-check for the detection */
197 #error OS_ID not defined
199 #if OS_HOSTED && OS_EMBEDDED
200 #error Both hosted and embedded OS environment
202 #if !OS_HOSTED && !OS_EMBEDDED
203 #error Neither hosted nor embedded OS environment
208 /// Macro to include OS-specific headers.
209 #define OS_HEADER(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).h)
211 /// Macro to include OS-specific source files.
212 #define OS_CSOURCE(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).c)
215 // Fallbacks for embedded systems
216 #define OS_HEADER(module) CPU_HEADER(module)
217 #define OS_CSOURCE(module) CPU_CSOURCE(module)
220 #endif /* CFG_OS_H */