Remove cvs logs.
[bertos.git] / cfg / os.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief OS-specific definitions
34  *
35  * \version $Id$
36  *
37  * \author Bernardo Innocenti <bernie@develer.com>
38  */
39
40 #ifndef DEVLIB_OS_H
41 #define DEVLIB_OS_H
42
43 /** Macro to include OS-specific versions of the headers. */
44 #define OS_HEADER(module)  PP_STRINGIZE(PP_CAT3(module, _, OS_ID).h)
45 #define OS_CSOURCE(module) PP_STRINGIZE(PP_CAT3(module, _, OS_ID).c)
46
47 /*
48  * OS autodetection (Some systems trigger multiple OS definitions)
49  */
50 #ifdef _WIN32
51         #define OS_WIN32  1
52         #define OS_ID     win32
53
54         // FIXME: Maybe disable Win32 exceptions?
55         typedef int cpuflags_t;
56         #define IRQ_DISABLE                /* FIXME */
57         #define IRQ_ENABLE                 /* FIXME */
58         #define IRQ_SAVE_DISABLE(old_sigs) /* FIXME */
59         #define IRQ_RESTORE(old_sigs)      /* FIXME */
60
61 #else
62         #define OS_WIN32  0
63 #endif
64
65 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
66         #define OS_UNIX   1
67         #define OS_POSIX  1  /* Not strictly UNIX, but no way to autodetect it. */
68         #define OS_ID     posix
69
70         /*
71          * The POSIX moral equivalent of disabling IRQs is disabling signals.
72          */
73         #include <signal.h>
74         typedef sigset_t cpuflags_t;
75
76         #define SET_ALL_SIGNALS(sigs) \
77         do { \
78                 sigfillset(&sigs); \
79                 sigdelset(&sigs, SIGINT); \
80                 sigdelset(&sigs, SIGSTOP); \
81                 sigdelset(&sigs, SIGCONT); \
82         } while(0)
83
84         #define IRQ_DISABLE \
85         do { \
86                 sigset_t sigs; \
87                 SET_ALL_SIGNALS(sigs); \
88                 sigprocmask(SIG_BLOCK, &sigs, NULL); \
89         } while (0)
90
91         #define IRQ_ENABLE \
92         do { \
93                 sigset_t sigs; \
94                 SET_ALL_SIGNALS(sigs); \
95                 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
96         } while (0)
97
98         #define IRQ_SAVE_DISABLE(old_sigs) \
99         do { \
100                 sigset_t sigs; \
101                 SET_ALL_SIGNALS(sigs); \
102                 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
103         } while (0)
104
105         #define IRQ_RESTORE(old_sigs) \
106         do { \
107                 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
108         } while (0)
109 #else
110         #define OS_UNIX   0
111         #define OS_POSIX  0
112 #endif
113
114 #ifdef __linux__
115         #define OS_LINUX  1
116 #else
117         #define OS_LINUX  0
118 #endif
119
120 #if defined(__APPLE__) && defined(__MACH__)
121         #define OS_DARWIN 1
122 #else
123         #define OS_DARWIN 0
124 #endif
125
126 /*
127  * We want Qt and other frameworks to look like OSes because you would
128  * tipically want their portable abstractions if you're using one of these.
129  */
130 #if defined(_QT)
131         #define OS_QT 1
132         #undef  OS_ID
133         #define OS_ID qt
134 #else
135         #define OS_QT 0
136 #endif
137
138 /*
139  * Summarize hosted environments as OS_HOSTED and embedded
140  * environment with OS_EMBEDDED.
141  */
142 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
143         #define OS_HOSTED   1
144         #define OS_EMBEDDED 0
145 #else
146         #define OS_HOSTED   0
147         #define OS_EMBEDDED 1
148
149         /* Embedded environments fall back to CPU-specific code. */
150         #define OS_ID       CPU_ID
151 #endif
152
153 /* Self-check for the detection */
154 #if !defined(OS_ID)
155         #error OS_ID not defined
156 #endif
157 #if OS_HOSTED && OS_EMBEDDED
158         #error Both hosted and embedded OS environment
159 #endif
160 #if !OS_HOSTED && !OS_EMBEDDED
161         #error Neither hosted nor embedded OS environment
162 #endif
163
164 #endif /* DEVLIB_OS_H */