BeRTOS
|
00001 00038 #ifndef CFG_OS_H 00039 #define CFG_OS_H 00040 00041 #include "cfg/cfg_proc.h" 00042 00043 /* 00044 * OS autodetection (Some systems trigger multiple OS definitions) 00045 */ 00046 #ifdef _WIN32 00047 #define OS_WIN32 1 00048 #define OS_ID win32 00049 00050 // FIXME: Maybe disable Win32 exceptions? 00051 typedef int cpu_flags_t; 00052 #define IRQ_DISABLE FIXME 00053 #define IRQ_ENABLE FIXME 00054 #define IRQ_SAVE_DISABLE(old_sigs) FIXME 00055 #define IRQ_RESTORE(old_sigs) FIXME 00056 00057 #else 00058 #define OS_WIN32 0 00059 #endif 00060 00061 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) 00062 #define OS_UNIX 1 00063 #define OS_POSIX 1 /* Not strictly UNIX, but no way to autodetect it. */ 00064 #define OS_ID posix 00065 00066 /* 00067 * The POSIX moral equivalent of disabling IRQs is disabling signals. 00068 */ 00069 #include <signal.h> 00070 typedef sigset_t cpu_flags_t; 00071 00072 #define SET_ALL_SIGNALS(sigs) \ 00073 do { \ 00074 sigfillset(&sigs); \ 00075 sigdelset(&sigs, SIGINT); \ 00076 sigdelset(&sigs, SIGSTOP); \ 00077 sigdelset(&sigs, SIGCONT); \ 00078 } while(0) 00079 00080 #define IRQ_DISABLE \ 00081 do { \ 00082 sigset_t sigs; \ 00083 SET_ALL_SIGNALS(sigs); \ 00084 sigprocmask(SIG_BLOCK, &sigs, NULL); \ 00085 } while (0) 00086 00087 #define IRQ_ENABLE \ 00088 do { \ 00089 sigset_t sigs; \ 00090 SET_ALL_SIGNALS(sigs); \ 00091 sigprocmask(SIG_UNBLOCK, &sigs, NULL); \ 00092 } while (0) 00093 00094 #define IRQ_SAVE_DISABLE(old_sigs) \ 00095 do { \ 00096 sigset_t sigs; \ 00097 SET_ALL_SIGNALS(sigs); \ 00098 sigprocmask(SIG_BLOCK, &sigs, &old_sigs); \ 00099 } while (0) 00100 00101 #define IRQ_RESTORE(old_sigs) \ 00102 do { \ 00103 sigprocmask(SIG_SETMASK, &old_sigs, NULL); \ 00104 } while (0) 00105 00106 #define IRQ_ENABLED() \ 00107 ({ \ 00108 sigset_t sigs__; \ 00109 sigprocmask(SIG_SETMASK, NULL, &sigs__); \ 00110 sigismember(&sigs__, SIGALRM) ? false : true; \ 00111 }) 00112 00113 #if (CONFIG_KERN && CONFIG_KERN_PREEMPT) 00114 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \ 00115 void vect(UNUSED_ARG(int, arg)); \ 00116 INLINE void __isr_##vect(void); \ 00117 void vect(UNUSED_ARG(int, arg)) \ 00118 { \ 00119 __isr_##vect(); \ 00120 IRQ_PREEMPT_HANDLER(); \ 00121 } \ 00122 INLINE void __isr_##vect(void) 00123 00133 #if CONFIG_KERN_PRI 00134 #define DECLARE_ISR(vect) \ 00135 DECLARE_ISR_CONTEXT_SWITCH(vect) 00136 #endif /* CONFIG_KERN_PRI */ 00137 #endif 00138 #ifndef DECLARE_ISR 00139 #define DECLARE_ISR(vect) \ 00140 void vect(UNUSED_ARG(int, arg)) 00141 #endif 00142 #ifndef DECLARE_ISR_CONTEXT_SWITCH 00143 #define DECLARE_ISR_CONTEXT_SWITCH(vect) \ 00144 void vect(UNUSED_ARG(int, arg)) 00145 #endif 00146 00147 #else 00148 #define OS_UNIX 0 00149 #define OS_POSIX 0 00150 #endif 00151 00152 #ifdef __linux__ 00153 #define OS_LINUX 1 00154 #else 00155 #define OS_LINUX 0 00156 #endif 00157 00158 #if defined(__APPLE__) && defined(__MACH__) 00159 #define OS_DARWIN 1 00160 #else 00161 #define OS_DARWIN 0 00162 #endif 00163 00164 00165 #include "cfg/cfg_arch.h" /* For ARCH_QT */ 00166 00167 /* 00168 * We want Qt and other frameworks to look like OSes because you would 00169 * tipically want their portable abstractions if you're using one of these. 00170 */ 00171 #if defined(_QT) || (defined(ARCH_QT) && (ARCH & ARCH_QT)) 00172 #define OS_QT 1 00173 #undef OS_ID 00174 #define OS_ID qt 00175 #else 00176 #define OS_QT 0 00177 #endif 00178 00179 /* 00180 * Summarize hosted environments as OS_HOSTED and embedded 00181 * environment with OS_EMBEDDED. 00182 */ 00183 #if OS_WIN32 || OS_UNIX || OS_DARWIN || OS_QT 00184 #define OS_HOSTED 1 00185 #define OS_EMBEDDED 0 00186 #else 00187 #define OS_HOSTED 0 00188 #define OS_EMBEDDED 1 00189 00190 /* Embedded environments fall back to CPU-specific code. */ 00191 #define OS_ID CPU_ID 00192 #endif 00193 00194 /* Self-check for the detection */ 00195 #if !defined(OS_ID) 00196 #error OS_ID not defined 00197 #endif 00198 #if OS_HOSTED && OS_EMBEDDED 00199 #error Both hosted and embedded OS environment 00200 #endif 00201 #if !OS_HOSTED && !OS_EMBEDDED 00202 #error Neither hosted nor embedded OS environment 00203 #endif 00204 00205 #if OS_HOSTED 00206 00208 #define OS_HEADER(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).h) 00209 00211 #define OS_CSOURCE(module) PP_STRINGIZE(emul/PP_CAT3(module, _, OS_ID).c) 00212 00213 #else 00214 // Fallbacks for embedded systems 00215 #define OS_HEADER(module) CPU_HEADER(module) 00216 #define OS_CSOURCE(module) CPU_CSOURCE(module) 00217 #endif 00218 00219 #endif /* CFG_OS_H */