proc.h
Go to the documentation of this file.00001
00092 #ifndef KERN_PROC_H
00093 #define KERN_PROC_H
00094
00095 #include "cfg/cfg_proc.h"
00096 #include "cfg/cfg_signal.h"
00097 #include "cfg/cfg_monitor.h"
00098 #include "sem.h"
00099
00100 #include <struct/list.h>
00101
00102 #include <cfg/compiler.h>
00103 #include <cfg/debug.h>
00104
00105 #include <cpu/types.h>
00106 #include <cpu/frame.h>
00107
00108
00109
00110
00111 #ifndef CONFIG_KERN_PRI_INHERIT
00112 #define CONFIG_KERN_PRI_INHERIT 0
00113 #endif
00114
00115
00116
00117
00118
00119
00120
00121
00122 typedef struct Process
00123 {
00124 #if CONFIG_KERN_PRI
00125 PriNode link;
00126 # if CONFIG_KERN_PRI_INHERIT
00127 PriNode inh_link;
00128 List inh_list;
00129 Semaphore *inh_blocked_by;
00130 int orig_pri;
00131 # endif
00132 #else
00133 Node link;
00134 #endif
00135 cpu_stack_t *stack;
00136 iptr_t user_data;
00138 #if CONFIG_KERN_SIGNALS
00139 Signal sig;
00140 #endif
00141
00142 #if CONFIG_KERN_HEAP
00143 uint16_t flags;
00144 #endif
00145
00146 #if CONFIG_KERN_HEAP | CONFIG_KERN_MONITOR
00147 cpu_stack_t *stack_base;
00148 size_t stack_size;
00149 #endif
00150
00151
00152 void (*user_entry)(void);
00153
00154 #if CONFIG_KERN_MONITOR
00155 struct ProcMonitor
00156 {
00157 Node link;
00158 const char *name;
00159 } monitor;
00160 #endif
00161
00162 } Process;
00163
00168 void proc_init(void);
00169
00170 struct Process *proc_new_with_name(const char *name, void (*entry)(void), iptr_t data, size_t stacksize, cpu_stack_t *stack);
00171
00172 #if !CONFIG_KERN_MONITOR
00173
00192 #define proc_new(entry,data,size,stack) proc_new_with_name(NULL,(entry),(data),(size),(stack))
00193 #else
00194 #define proc_new(entry,data,size,stack) proc_new_with_name(#entry,(entry),(data),(size),(stack))
00195 #endif
00196
00200 void proc_exit(void);
00201
00202
00203
00204
00205 void proc_yield(void);
00206
00207 #if CONFIG_KERN_PREEMPT
00208 bool proc_needPreempt(void);
00209 void proc_preempt(void);
00210 #else
00211 INLINE bool proc_needPreempt(void)
00212 {
00213 return false;
00214 }
00215
00216 INLINE void proc_preempt(void)
00217 {
00218 }
00219 #endif
00220
00221 void proc_rename(struct Process *proc, const char *name);
00222 const char *proc_name(struct Process *proc);
00223 const char *proc_currentName(void);
00224
00232 INLINE iptr_t proc_currentUserData(void)
00233 {
00234 extern struct Process *current_process;
00235 return current_process->user_data;
00236 }
00237
00238 int proc_testSetup(void);
00239 int proc_testRun(void);
00240 int proc_testTearDown(void);
00241
00249 INLINE struct Process *proc_current(void)
00250 {
00251 extern struct Process *current_process;
00252 return current_process;
00253 }
00254
00255 #if CONFIG_KERN_PRI
00256 void proc_setPri(struct Process *proc, int pri);
00257 #else
00258 INLINE void proc_setPri(UNUSED_ARG(struct Process *,proc), UNUSED_ARG(int, pri))
00259 {
00260 }
00261 #endif
00262
00263 #if CONFIG_KERN_PREEMPT
00264
00282 INLINE void proc_forbid(void)
00283 {
00284 extern cpu_atomic_t preempt_count;
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 ++preempt_count;
00309
00310
00311
00312
00313
00314 MEMORY_BARRIER;
00315 }
00316
00322 INLINE void proc_permit(void)
00323 {
00324 extern cpu_atomic_t preempt_count;
00325
00326
00327
00328
00329
00330 MEMORY_BARRIER;
00331
00332 ASSERT(preempt_count > 0);
00333 --preempt_count;
00334
00335
00336
00337
00338 MEMORY_BARRIER;
00339 }
00340
00346 INLINE bool proc_preemptAllowed(void)
00347 {
00348 extern cpu_atomic_t preempt_count;
00349 return (preempt_count == 0);
00350 }
00351 #else
00352 #define proc_forbid()
00353 #define proc_permit()
00354 #define proc_preemptAllowed() (true)
00355 #endif
00356
00358 #define proc_allowed() proc_preemptAllowed()
00359
00363 #define PROC_ATOMIC(CODE) \
00364 do { \
00365 proc_forbid(); \
00366 CODE; \
00367 proc_permit(); \
00368 } while(0)
00369
00388 #if (ARCH & ARCH_EMUL)
00389
00390 #define KERN_MINSTACKSIZE 65536
00391 #else
00392 #if CONFIG_KERN_PREEMPT
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 #define KERN_MINSTACKSIZE \
00406 (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
00407 + 32 * sizeof(int) * 2)
00408 #else
00409 #define KERN_MINSTACKSIZE \
00410 (sizeof(Process) + CPU_SAVED_REGS_CNT * 2 * sizeof(cpu_stack_t) \
00411 + 32 * sizeof(int))
00412 #endif
00413
00414 #endif
00415
00416 #ifndef CONFIG_KERN_MINSTACKSIZE
00417
00418 #define CONFIG_KERN_MINSTACKSIZE KERN_MINSTACKSIZE
00419 #else
00420 #warning FIXME: This macro is deprecated, use KERN_MINSTACKSIZE instead
00421 #endif
00422
00434 #define PROC_DEFINE_STACK(name, size) \
00435 cpu_stack_t name[((size) + sizeof(cpu_stack_t) - 1) / sizeof(cpu_stack_t)]; \
00436 STATIC_ASSERT((size) >= KERN_MINSTACKSIZE);
00437
00438
00439 #if CONFIG_KERN_MONITOR
00440 #include <cpu/types.h>
00441 #if (SIZEOF_CPUSTACK_T == 1)
00442
00443 #define CONFIG_KERN_STACKFILLCODE 0xA5
00444 #define CONFIG_KERN_MEMFILLCODE 0xDB
00445 #elif (SIZEOF_CPUSTACK_T == 2)
00446
00447 #define CONFIG_KERN_STACKFILLCODE 0xA5A5
00448 #define CONFIG_KERN_MEMFILLCODE 0xDBDB
00449 #elif (SIZEOF_CPUSTACK_T == 4)
00450
00451 #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5UL
00452 #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBUL
00453 #elif (SIZEOF_CPUSTACK_T == 8)
00454
00455 #define CONFIG_KERN_STACKFILLCODE 0xA5A5A5A5A5A5A5A5ULL
00456 #define CONFIG_KERN_MEMFILLCODE 0xDBDBDBDBDBDBDBDBULL
00457 #else
00458 #error No cpu_stack_t size supported!
00459 #endif
00460 #endif
00461
00462
00463 #endif