POK(kernelpart)
thread.c
Go to the documentation of this file.
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
23 #include <bsp.h>
24 #include <libc.h>
25 #include <errno.h>
26 #include <core/thread.h>
27 #include "thread.h"
28 #include "context_offset.h"
29 #include "ioports.h"
30 
31 #ifdef POK_NEEDS_THREADS
32 
33 extern char _idlestack;
34 
39  uint32_t stack_size,
40  uint32_t entry)
41 {
42  (void)stack_size;
43  char *ctx = (char *)(&_idlestack - 0x40);
44 
45  *(uint32_t *)(ctx - RESTORE_CNT_OFFSET) = 1;
46  *(uint32_t *)(ctx - PC_OFFSET) = entry;
47  *(uint32_t *)(ctx - NPC_OFFSET) = entry + 4;
48  *(uint32_t *)(ctx - I1_OFFSET) = id;
49 
50 #ifdef POK_NEEDS_DEBUG
51  printf ("ctxt_create %d: sp=%x\n", id, ctx);
52 #endif
53 
54  return (uint32_t)ctx;
55 }
56 
62 
68 void pok_context_switch (uint32_t* old_sp,
69  uint32_t new_sp)
70 {
71  *old_sp = pok_arch_sp;
72  pok_arch_sp = new_sp;
73 }
74 
75 #endif