X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=bertos%2Fkern%2Fproc.c;h=3f2548923dbc1527660cdf3138a091c285f00aee;hb=6a60d159530b29a6f60edbad42d0e31c1f1994d9;hp=9aa04546c35eb02e5ee425f02914a5c7839a68cb;hpb=87302355709b6d5ac0592024b84207ba86baa82e;p=bertos.git diff --git a/bertos/kern/proc.c b/bertos/kern/proc.c index 9aa04546..3f254892 100644 --- a/bertos/kern/proc.c +++ b/bertos/kern/proc.c @@ -26,9 +26,8 @@ * invalidate any other reasons why the executable file might be covered by * the GNU General Public License. * - * Copyright 2001,2004 Develer S.r.l. (http://www.develer.com/) - * Copyright 1999,2000,2001 Bernie Innocenti - * + * Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/) + * Copyright 1999, 2000, 2001, 2008 Bernie Innocenti * --> * * \brief Simple realtime multitasking scheduler. @@ -43,6 +42,7 @@ #include "proc.h" #include "cfg/cfg_arch.h" /* ARCH_EMUL */ +#include "cfg/cfg_kern.h" #include #include @@ -52,6 +52,7 @@ #include /* memset() */ + /* * The scheduer tracks ready processes by enqueuing them in the * ready list. @@ -117,6 +118,10 @@ void proc_init(void) monitor_add(CurrentProcess, "main"); #endif +#if CONFIG_KERN_PREEMPTIVE + preempt_init(); +#endif + MOD_INIT(proc); } @@ -164,8 +169,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi #if CONFIG_KERN_MONITOR /* Fill-in the stack with a special marker to help debugging */ -#warning size incorrect - memset(stack_base, CONFIG_KERN_STACKFILLCODE, stack_size / sizeof(cpustack_t)); + memset(stack_base, CONFIG_KERN_STACKFILLCODE, stack_size); #endif /* Initialize the process control block */ @@ -196,6 +200,15 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi #endif #endif +#if CONFIG_KERN_PREEMPT + // FIXME: proc_exit + getcontext(&proc->context); + proc->context.uc_stack.ss_sp = stack_base; + proc->context.uc_stack.ss_size = stack_size; + proc->context.uc_link = NULL; + makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry); + +#else // !CONFIG_KERN_PREEMPT /* Initialize process stack frame */ CPU_PUSH_CALL_FRAME(proc->stack, proc_exit); CPU_PUSH_CALL_FRAME(proc->stack, entry); @@ -207,6 +220,7 @@ struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(voi /* Add to ready list */ ATOMIC(SCHED_ENQUEUE(proc)); ATOMIC(LIST_ASSERT_VALID(&ProcReadyList)); +#endif // CONFIG_KERN_PREEMPT #if CONFIG_KERN_MONITOR monitor_add(proc, name); @@ -231,7 +245,7 @@ void proc_rename(struct Process *proc, const char *name) */ void proc_exit(void) { - TRACE; + TRACEMSG("%p:%s", CurrentProcess, CurrentProcess->monitor.name); #if CONFIG_KERN_MONITOR monitor_remove(CurrentProcess);