Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / kernel / arch / arm / task.c
blob8e2bde1be18b2e6f68bfa2d8bfd68e8f65b15b8a
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <arch/ctx.h>
21 #include <task.h>
23 static task_t *task_old;
24 int arm_critical_section;
27 static void task_init ()
29 /* enable interrupts when we're in task entry point for first time */
30 int_enable ();
32 /* get current task */
33 task_t *c = _curr_task;
35 /* get non-real entry point - just function what we want to call */
36 task_handler_t *handler = (task_handler_t *) c->entry;
38 /* call our function */
39 handler ();
41 /* when non-real task function is finished, we should push out this task from task_list
42 * we won't schedule it now anymore
43 task_done (c);
45 /* scheduler switch _curr_task to next valid running task */
46 schedule ();
49 unsigned arch_task_init (task_t *task, unsigned entry)
51 /* we're not interested in exception, so we must check pointer and entry point address first */
52 if (!task || !entry)
53 return 0;
55 /* we have to point to top of stack */
56 unsigned *stack_top = (unsigned *) task->stacks + USER_STACK_SIZE;
58 /* stack must be 8byte aligned */
59 stack_top = (unsigned *) ARM_STACKALIGN ((unsigned) stack_top, 8);
61 struct arm_ctx_frame *frame = (struct arm_ctx_frame *) (stack_top);
63 /* decrease address - sizeof (arm_ctx_frame) : we want one empty frame at the top of stack */
64 frame --;
66 /* clear frame structure */
67 memset (frame, 0, sizeof (struct arm_ctx_frame));
69 /* set the entry point of new task */
70 frame->lr = (unsigned *) &task_init;
72 /* set the stack pointer for our task */
73 task->sp = (unsigned *) frame;
74 /* save entry point of function involved in our task */
75 task->entry = (unsigned *) entry;
77 return 1;
80 unsigned arch_task_set (task_t *task)
82 if (!task)
83 return 1;
85 if (task == task_old)
86 return 1;
88 /* this is important for save old task stack pointer */
89 task_old = task;
91 return 0;
94 unsigned arch_task_switch (task_t *task)
96 if (!task_old || !task->sp)
97 return 0;
99 if (!task_old->sp || !task->sp)
100 return 0;
102 /* call function for jump to new cs */
103 arm_task_switch (&task_old->sp, task->sp);
105 return 1;
108 void arch_task_preempt ()
110 printf ("We have preempt !\n");