debuggers.hg

view extras/mini-os/arch/ia64/sched.c @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children 5c0bf00e371d
line source
1 /*
2 * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com
3 *
4 * Description: ia64 specific part of the scheduler for mini-os
5 *
6 ****************************************************************************
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
28 #include "types.h"
29 #include "sched.h"
30 #include "lib.h"
31 #include "xmalloc.h"
32 #include "mm.h"
34 /* The function is implemented in fw.S */
35 extern void thread_starter(void);
37 struct thread*
38 arch_create_thread(char *name, void (*function)(void *), void *data)
39 {
40 struct thread* _thread;
42 _thread = (struct thread*)_xmalloc(sizeof(struct thread), 16);
43 /* Allocate pages for stack, stack will be aligned */
44 _thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
45 _thread->name = name;
46 memset((void*)&(_thread->regs), 0, sizeof(_thread->regs));
47 _thread->regs.sp = ((uint64_t)_thread->stack) + STACK_SIZE - 16;
48 _thread->regs.bsp = ((uint64_t)_thread->stack) + 0x10;
49 _thread->regs.rp = FDESC_FUNC(thread_starter);
50 _thread->regs.pfs = 0x82;
51 _thread->regs.r4 = FDESC_FUNC(function);
52 _thread->regs.r6 = (uint64_t)data;
53 return _thread;
54 }
56 extern void restore_context(struct thread*);
57 extern int switch_context(struct thread*, struct thread*);
59 void
60 arch_switch_threads(struct thread* prev, struct thread* next)
61 {
62 ia64_set_r13((uint64_t)next);
63 switch_context(prev, next);
64 }
66 /* Everything initialised, start idle thread */
67 void
68 run_idle_thread(void)
69 {
70 //do_busy_loop();
71 ia64_set_r13((uint64_t)idle_thread);
72 restore_context(idle_thread);
73 printk("%s: restore_context() returned - bad!\n", __func__);
74 }