proc.h
Go to the documentation of this file.00001
00043 #ifndef KERN_PROC_H
00044 #define KERN_PROC_H
00045
00046 #include "cfg/cfg_proc.h"
00047 #include "cfg/cfg_signal.h"
00048 #include "cfg/cfg_monitor.h"
00049
00050 #include <struct/list.h>
00051
00052 #include <cfg/compiler.h>
00053 #include <cfg/debug.h>
00054
00055 #include <cpu/types.h>
00056 #include <cpu/frame.h>
00057
00058
00059
00060
00061
00062
00063
00064
00065 typedef struct Process
00066 {
00067 #if CONFIG_KERN_PRI
00068 PriNode link;
00069 #else
00070 Node link;
00071 #endif
00072 cpu_stack_t *stack;
00073 iptr_t user_data;
00075 #if CONFIG_KERN_SIGNALS
00076 sigmask_t sig_wait;
00077 sigmask_t sig_recv;
00078 #endif
00079
00080 #if CONFIG_KERN_HEAP
00081 uint16_t flags;
00082 #endif
00083
00084 #if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR
00085 cpu_stack_t *stack_base;
00086 size_t stack_size;
00087 #endif
00088
00089
00090 void (*user_entry)(void);
00091
00092 #if CONFIG_KERN_MONITOR
00093 struct ProcMonitor
00094 {
00095 Node link;
00096 const char *name;
00097 } monitor;
00098 #endif
00099
00100 } Process;
00101
00106 void proc_init(void);
00107
00108 struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t data, size_t stacksize, cpu_stack_t *stack);
00109
00110 #if !CONFIG_KERN_MONITOR
00111
00130 #define proc_new(entry,data,size,stack) proc_new_with_name(NULL,(entry),(data),(size),(stack))
00131 #else
00132 #define proc_new(entry,data,size,stack) proc_new_with_name(#entry,(entry),(data),(size),(stack))
00133 #endif
00134
00138 void proc_exit(void);
00139
00143 void proc_yield(void);
00144
00145 #if CONFIG_KERN_PREEMPT
00146 bool proc_needPreempt(void);
00147 void proc_preempt(void);
00148 #else
00149 INLINE bool proc_needPreempt(void)
00150 {
00151 return false;
00152 }
00153
00154 INLINE void proc_preempt(void)
00155 {
00156 }
00157 #endif
00158
00159 void proc_rename(struct Process *proc, const char *name);
00160 const char *proc_name(struct Process *proc);
00161 const char *proc_currentName(void);
00162
00170 INLINE iptr_t proc_currentUserData(void)
00171 {
00172 extern struct Process *current_process;
00173 return current_process->user_data;
00174 }
00175
00176 int proc_testSetup(void);
00177 int proc_testRun(void);
00178 int proc_testTearDown(void);
00179
00187 INLINE struct Process *proc_current(void)
00188 {
00189 extern struct Process *current_process;
00190 return current_process;
00191 }
00192
00193 #if CONFIG_KERN_PRI
00194 void proc_setPri(struct Process *proc, int pri);
00195 #else
00196 INLINE void proc_setPri(UNUSED_ARG(struct Process *,proc), UNUSED_ARG(int, pri))
00197 {
00198 }
00199 #endif
00200
00201 #if CONFIG_KERN_PREEMPT
00202
00220 INLINE void proc_forbid(void)
00221 {
00222 extern cpu_atomic_t preempt_count;
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 ++preempt_count;
00247
00248
00249
00250
00251
00252 MEMORY_BARRIER;
00253 }
00254
00260 INLINE void proc_permit(void)
00261 {
00262 extern cpu_atomic_t preempt_count;
00263
00264
00265
00266
00267
00268 MEMORY_BARRIER;
00269
00270 ASSERT(preempt_count > 0);
00271 --preempt_count;
00272
00273
00274
00275
00276 MEMORY_BARRIER;
00277 }
00278
00284 INLINE bool proc_preemptAllowed(void)
00285 {
00286 extern cpu_atomic_t preempt_count;
00287 return (preempt_count == 0);
00288 }
00289 #else
00290 #define proc_forbid()
00291 #define proc_permit()
00292 #define proc_preemptAllowed() (true)
00293 #endif
00294
00296 #define proc_allowed() proc_preemptAllowed()
00297
00301 #define PROC_ATOMIC(CODE) \
00302 do { \
00303 proc_forbid(); \
00304 CODE; \
00305 proc_permit(); \
00306 } while(0)
00307
00326 #if (ARCH & ARCH_EMUL)
00327
00328 #define KERN_MINSTACKSIZE 65536
00329 #else
00330 #if CONFIG_KERN_PREEMPT
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 #define KERN_MINSTACKSIZE \
00344 (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
00345 + 32 * sizeof(int) * 2)
00346 #else
00347 #define KERN_MINSTACKSIZE \
00348 (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
00349 + 32 * sizeof(int))
00350 #endif
00351
00352 #endif
00353
00354 #ifndef CONFIG_KERN_MINSTACKSIZE
00355
00356 #define CONFIG_KERN_MINSTACKSIZE KERN_MINSTACKSIZE
00357 #else
00358 #warning FIXME: This macro is deprecated, use KERN_MINSTACKSIZE instead
00359 #endif
00360
00372 #define PROC_DEFINE_STACK(name, size) \
00373 cpu_stack_t name[((size) + sizeof(cpu_stack_t) - 1) / sizeof(cpu_stack_t)]; \
00374 STATIC_ASSERT((size) >= KERN_MINSTACKSIZE);
00375
00376
00377 #if CONFIG_KERN_MONITOR
00378 #include <cpu/types.h>
00379 #if (SIZEOF_CPUSTACK_T == 1)
00380
00381 #define CONFIG_KERN_STACKFILLCODE 0xA5
00382 #define CONFIG_KERN_MEMFILLCODE 0xDB
00383 #elif (SIZEOF_CPUSTACK_T == 2)
00384
00385 #define CONFIG_KERN_STACKFILLCODE 0xA5A5
00386 #define CONFIG_KERN_MEMFILLCODE 0xDBDB
00387 #elif (SIZEOF_CPUSTACK_T == 4)
00388
00389 #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5UL
00390 #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBUL
00391 #elif (SIZEOF_CPUSTACK_T == 8)
00392
00393 #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5A5A5A5A5ULL
00394 #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBDBDBDBDBULL
00395 #else
00396 #error No cpu_stack_t size supported!
00397 #endif
00398 #endif
00399
00400 #endif