POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/sparc/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 
00023 #include <bsp.h>
00024 #include <libc.h>
00025 #include <errno.h>
00026 #include <core/thread.h>
00027 #include "thread.h"
00028 #include "context_offset.h"
00029 #include "ioports.h"
00030 
00031 #ifdef POK_NEEDS_THREADS
00032 
00033 extern char _idlestack;
00034 
00038 uint32_t pok_context_create (uint32_t id,
00039                              uint32_t stack_size,
00040                              uint32_t entry)
00041 {
00042   (void)stack_size;
00043   char *ctx = (char *)(&_idlestack - 0x40);
00044 
00045   *(uint32_t *)(ctx - RESTORE_CNT_OFFSET) = 1;
00046   *(uint32_t *)(ctx - PC_OFFSET) = entry;
00047   *(uint32_t *)(ctx - NPC_OFFSET) = entry + 4;
00048   *(uint32_t *)(ctx - I1_OFFSET) = id;
00049 
00050 #ifdef POK_NEEDS_DEBUG
00051   printf ("ctxt_create %d: sp=%x\n", id, ctx);
00052 #endif
00053 
00054   return (uint32_t)ctx;
00055 }
00056 
00061 uint32_t pok_arch_sp;
00062 
00068 void pok_context_switch (uint32_t* old_sp,
00069                          uint32_t new_sp)
00070 {
00071   *old_sp = pok_arch_sp;
00072   pok_arch_sp = new_sp;
00073 }
00074 
00075 void                    pok_context_reset(uint32_t stack_size,
00076                                           uint32_t stack_addr)
00077 {
00078   (void)stack_size;
00079   (void)stack_addr;
00080   uint32_t id;
00081   uint32_t entry;
00082 
00083   char *ctx = (char *)(&_idlestack - 0x40);
00084 
00085   id = *(uint32_t *)(ctx - PC_OFFSET);
00086   entry =  *(uint32_t *)(ctx - I1_OFFSET);
00087 
00088   *(uint32_t *)(ctx - RESTORE_CNT_OFFSET) = 1;
00089   *(uint32_t *)(ctx - PC_OFFSET) = entry;
00090   *(uint32_t *)(ctx - NPC_OFFSET) = entry + 4;
00091   *(uint32_t *)(ctx - I1_OFFSET) = id;
00092 }
00093 
00094 #endif