os.h
Go to the documentation of this file.00001
00039 #ifndef CFG_OS_H
00040 #define CFG_OS_H
00041
00042 #include "cfg/cfg_proc.h"
00043
00044
00045
00046
00047 #ifdef _WIN32
00048 #define OS_WIN32 1
00049 #define OS_ID win32
00050
00051
00052 typedef int cpu_flags_t;
00053 #define IRQ_DISABLE FIXME
00054 #define IRQ_ENABLE FIXME
00055 #define IRQ_SAVE_DISABLE(old_sigs) FIXME
00056 #define IRQ_RESTORE(old_sigs) FIXME
00057
00058 #else
00059 #define OS_WIN32 0
00060 #endif
00061
00062 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
00063 #define OS_UNIX 1
00064 #define OS_POSIX 1
00065 #define OS_ID posix
00066
00067
00068
00069
00070 #include <signal.h>
00071 typedef sigset_t cpu_flags_t;
00072
00073 #define SET_ALL_SIGNALS(sigs) \
00074 do { \
00075 sigfillset(&sigs); \
00076 sigdelset(&sigs, SIGINT); \
00077 sigdelset(&sigs, SIGSTOP); \
00078 sigdelset(&sigs, SIGCONT); \
00079 } while(0)
00080
00081 #define IRQ_DISABLE \
00082 do { \
00083 sigset_t sigs; \
00084 SET_ALL_SIGNALS(sigs); \
00085 sigprocmask(SIG_BLOCK, &sigs, NULL); \
00086 } while (0)
00087
00088 #define IRQ_ENABLE \
00089 do { \
00090 sigset_t sigs; \
00091 SET_ALL_SIGNALS(sigs); \
00092 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \
00093 } while (0)
00094
00095 #define IRQ_SAVE_DISABLE(old_sigs) \
00096 do { \
00097 sigset_t sigs; \
00098 SET_ALL_SIGNALS(sigs); \
00099 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \
00100 } while (0)
00101
00102 #define IRQ_RESTORE(old_sigs) \
00103 do { \
00104 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \
00105 } while (0)
00106
00107 #define IRQ_ENABLED() \
00108 ({ \
00109 sigset_t sigs__; \
00110 sigprocmask(SIG_SETMASK, NULL, &sigs__); \
00111 sigismember(&sigs__, SIGALRM) ? false : true; \
00112 })
00113
00114 #if CONFIG_KERN_PREEMPT
00115 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
00116 void vect(UNUSED_ARG(int, arg)); \
00117 INLINE void __isr_##vect(void); \
00118 void vect(UNUSED_ARG(int, arg)) \
00119 { \
00120 __isr_##vect(); \
00121 IRQ_PREEMPT_HANDLER(); \
00122 } \
00123 INLINE void __isr_##vect(void)
00124
00134 #if CONFIG_KERN_PRI
00135 #define DECLARE_ISR(vect) \
00136 DECLARE_ISR_CONTEXT_SWITCH(vect)
00137 #endif
00138 #endif
00139 #ifndef DECLARE_ISR
00140 #define DECLARE_ISR(vect) \
00141 void vect(UNUSED_ARG(int, arg))
00142 #endif
00143 #ifndef DECLARE_ISR_CONTEXT_SWITCH
00144 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \
00145 void vect(UNUSED_ARG(int, arg))
00146 #endif
00147
00148 #else
00149 #define OS_UNIX 0
00150 #define OS_POSIX 0
00151 #endif
00152
00153 #ifdef __linux__
00154 #define OS_LINUX 1
00155 #else
00156 #define OS_LINUX 0
00157 #endif
00158
00159 #if defined(__APPLE__) && defined(__MACH__)
00160 #define OS_DARWIN 1
00161 #else
00162 #define OS_DARWIN 0
00163 #endif
00164
00165
00166 #include "cfg/cfg_arch.h"
00167
00168
00169
00170
00171
00172 #if defined(_QT) || (defined(ARCH_QT) && (ARCH & ARCH_QT))
00173 #define OS_QT 1
00174 #undef OS_ID
00175 #define OS_ID qt
00176 #else
00177 #define OS_QT 0
00178 #endif
00179
00180
00181
00182
00183
00184 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT
00185 #define OS_HOSTED 1
00186 #define OS_EMBEDDED 0
00187 #else
00188 #define OS_HOSTED 0
00189 #define OS_EMBEDDED 1
00190
00191
00192 #define OS_ID CPU_ID
00193 #endif
00194
00195
00196 #if !defined(OS_ID)
00197 #error OS_ID not defined
00198 #endif
00199 #if OS_HOSTED && OS_EMBEDDED
00200 #error Both hosted and embedded OS environment
00201 #endif
00202 #if !OS_HOSTED && !OS_EMBEDDED
00203 #error Neither hosted nor embedded OS environment
00204 #endif
00205
00206 #if OS_HOSTED
00207
00209 #define OS_HEADER(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).h)
00210
00212 #define OS_CSOURCE(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).c)
00213
00214 #else
00215
00216 #define OS_HEADER(module) CPU_HEADER(module)
00217 #define OS_CSOURCE(module) CPU_CSOURCE(module)
00218 #endif
00219
00220 #endif