Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / magpie_1_1 / sboot / athos / src / xtos / init.c
1 /* init.c - context initialization */
2
3 /*
4  * Copyright (c) 1999-2006 Tensilica Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #include <xtensa/config/core.h>
27 #if XCHAL_NUM_CONTEXTS > 1
28 #include <stdlib.h>
29 #endif
30
31
32
33 #if 0 /* XCHAL_NUM_CONTEXTS > 1 */
34 extern  void    _xtos_setup_context(int context_num, SetupInfo *info);
35 extern  void    _xtos_start_context(void);
36
37 /*
38  *  Sets up a context for running code.
39  *
40  *  Returns PC at which to set the new context, or 0 on error.
41  */
42 unsigned        _xtos_init_context(int context_num, int stack_size,
43                                    _xtos_handler_func *start_func, int arg1)
44 {
45     SetupInfo info;
46
47     /*  Allocate stack:  */
48     char *sp;
49     char *stack = malloc(stack_size);
50     if (stack == NULL)
51         return 0;
52
53     /*  Setup stack for call8:  */
54     sp = stack + stack_size - 16;
55     *(unsigned*)(sp - 12) = (unsigned)(sp + 32);
56
57     info.sp = (unsigned)sp;
58     info.funcpc = (unsigned)start_func;
59     info.arg1 = arg1;
60     _xtos_setup_context(context_num, &info);
61     return (unsigned) &_xtos_start_context;
62 }
63 #endif /* multiple contexts */
64