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/>.
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 */
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 */
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
45 /* scheduler switch _curr_task to next valid running task */
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 */
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 */
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
;
80 unsigned arch_task_set (task_t
*task
)
88 /* this is important for save old task stack pointer */
94 unsigned arch_task_switch (task_t
*task
)
96 if (!task_old
|| !task
->sp
)
99 if (!task_old
->sp
|| !task
->sp
)
102 /* call function for jump to new cs */
103 arm_task_switch (&task_old
->sp
, task
->sp
);
108 void arch_task_preempt ()
110 puts ("We have preempt !\n");