POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/ppc/thread.c
Go to the documentation of this file.
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 
00018 #include <bsp.h>
00019 #include <libc.h>
00020 #include <errno.h>
00021 #include <core/thread.h>
00022 
00023 #include "thread.h"
00024 
00025 #ifdef POK_NEEDS_THREADS
00026 
00027 extern void pok_arch_thread_start(void);
00028 
00029 uint32_t                pok_context_create (uint32_t id,
00030                                 uint32_t stack_size,
00031                                 uint32_t entry)
00032 {
00033   context_t* sp;
00034   char*      stack_addr;
00035 
00036   stack_addr = pok_bsp_mem_alloc (stack_size);
00037 
00038   sp = (context_t *) (stack_addr + stack_size - sizeof (context_t));
00039 
00040   memset (sp, 0, sizeof (context_t));
00041 
00042   sp->r14     = entry;
00043   sp->r15     = id;
00044   sp->lr      = (uint32_t) pok_arch_thread_start;
00045   sp->sp      = (uint32_t) &sp->back_chain;
00046 
00047 #ifdef POK_NEEDS_DEBUG
00048   printf ("ctxt_create %d: sp=%x\n", id, sp);
00049 #endif
00050 
00051   return (uint32_t)sp;
00052 }
00053 
00054 uint32_t pok_context_reset(uint32_t stack_size,
00055                             uint32_t stack_addr)
00056 {
00057   context_t* sp;
00058   uint32_t id;
00059   uint32_t entry;
00060   
00061   sp = (context_t *) (stack_addr + stack_size - 4 - sizeof (context_t));
00062 
00063   id = sp->r15;
00064   entry = sp->r14;
00065   memset (sp, 0, sizeof (context_t));
00066 
00067   sp->r14     = entry;
00068   sp->r15     = id;
00069   sp->lr      = (uint32_t) pok_arch_thread_start;
00070   sp->sp      = (uint32_t) &sp->back_chain;
00071   return 0;
00072 }
00073 
00074 #endif