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 
17 
18 #include <bsp.h>
19 #include <libc.h>
20 #include <errno.h>
21 #include <core/thread.h>
22 
23 #include "thread.h"
24 
25 #ifdef POK_NEEDS_THREADS
26 
27 extern void pok_arch_thread_start(void);
28 
30  uint32_t stack_size,
31  uint32_t entry)
32 {
33  context_t* sp;
34  char* stack_addr;
35 
36  stack_addr = pok_bsp_mem_alloc (stack_size);
37 
38  sp = (context_t *) (stack_addr + stack_size - sizeof (context_t));
39 
40  memset (sp, 0, sizeof (context_t));
41 
42  sp->r14 = entry;
43  sp->r15 = id;
44  sp->lr = (uint32_t) pok_arch_thread_start;
45  sp->sp = (uint32_t) &sp->back_chain;
46 
47 #ifdef POK_NEEDS_DEBUG
48  printf ("ctxt_create %d: sp=%x\n", id, sp);
49 #endif
50 
51  return (uint32_t)sp;
52 }
53 
54 #endif