]> rtime.felk.cvut.cz Git - arc.git/blob - arch/ppc/mpc55xx/kernel/arch.c
Cleanup of makefiles. Cleanup of merge.
[arc.git] / arch / ppc / mpc55xx / kernel / arch.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 /* ----------------------------[includes]------------------------------------*/\r
18 \r
19 #include "internal.h"\r
20 #include "asm_ppc.h"\r
21 #include "mpc55xx.h"\r
22 #include "arch_stack.h"\r
23 #include "arch_offset.h"\r
24 \r
25 #define USE_LDEBUG_PRINTF\r
26 #include "debug.h"\r
27 \r
28 /* ----------------------------[includes]------------------------------------*/\r
29 /* ----------------------------[private define]------------------------------*/\r
30 /* ----------------------------[private macro]-------------------------------*/\r
31 /* ----------------------------[private typedef]-----------------------------*/\r
32 /* ----------------------------[private function prototypes]-----------------*/\r
33 /* ----------------------------[private variables]---------------------------*/\r
34 /* ----------------------------[private functions]---------------------------*/\r
35 /* ----------------------------[public functions]----------------------------*/\r
36 \r
37 \r
38 \r
39 /**\r
40  * NOT complete yet.....\r
41  *\r
42  * @param err                   The error code.\r
43  * @param errFramePtr   Pointer to extra information about the error, if any.\r
44  * @param excFramePtr   Pointer to the exception frame, that cause the error.\r
45  */\r
46 void Os_ArchPanic( uint32_t err, void *errFramePtr , Os_ExceptionFrameType *excFramePtr) {\r
47         switch(err) {\r
48         case OS_ERR_BAD_CONTEXT:\r
49                 while(1);\r
50                 break;\r
51         case OS_ERR_SPURIOUS_INTERRUPT:\r
52                 fputs("Spurious interrupt\n",stdout);\r
53                 printf(" vector : %02lx\n", excFramePtr->vector);\r
54                 printf(" srr0   : %08lx\n", excFramePtr->srr0);\r
55                 printf(" srr1   : %08lx\n", excFramePtr->srr1);\r
56                 while(1);\r
57                 break;\r
58         default:\r
59                 while(1);\r
60                 break;\r
61         }\r
62 }\r
63 \r
64 /**\r
65  * Function make sure that we switch to supervisor mode(rfi) before\r
66  * we call a task for the first time.\r
67  */\r
68 void Os_ArchFirstCall( void )\r
69 {\r
70 #if USE_MM_USER_MODE\r
71 \r
72         // Assume that regs[0] is setup before and contains the settings\r
73         // to switch to user mode.\r
74         register uint32_t msr asm("r3") = os_sys.curr_pcb->regs[0];\r
75         register void *ea asm("r4") = (void *) os_sys.curr_pcb->entry;\r
76 \r
77         // Do the switch\r
78         asm volatile(\r
79                         "mtspr 26,%0;\r\t"      // srr0\r
80                         "mtspr 27,%1;\r\t"      // srr1\r
81                         "rfi;\r\t"\r
82                         :\r
83                         : "r" (ea), "r" (msr)   );\r
84 #else\r
85 // TODO: This really depends on if scheduling policy\r
86         Irq_Enable();\r
87         os_sys.curr_pcb->entry();\r
88 #endif\r
89 }\r
90 \r
91 \r
92 /* TODO: This actually gives the stack ptr here...not the callers stack ptr\r
93  * Should probably be a macro instead..... in some arch part..\r
94  */\r
95 void *Os_ArchGetStackPtr( void ) {\r
96         void *stackp;\r
97         // Get stack ptr(r1) from current context\r
98         asm volatile(" mr %0,1":"=r" (stackp));\r
99 \r
100         return stackp;\r
101 }\r
102 \r
103 unsigned int Os_ArchGetScSize( void ) {\r
104         return FUNC_FRM_SIZE;\r
105 }\r
106 \r
107 \r
108 /**\r
109  * Setup a context for a task.\r
110  *\r
111  * @param pcb Pointer to the pcb to setup\r
112  */\r
113 void Os_ArchSetupContext( OsPcbType *pcbPtr ) {\r
114         Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;\r
115         uint32_t msr;\r
116         msr = MSR_EE;\r
117 \r
118 #if defined(CFG_SPE)\r
119         msr |= MSR_SPE;\r
120 #endif\r
121 \r
122 #if (  OS_SC3 == STD_ON) || (  OS_SC4== STD_ON)\r
123         if( !pcb->application->trusted ) {\r
124                 // Non-trusted = User mode..\r
125                 msr |= MSR_PR | MSR_DS | MSR_IS;\r
126         }\r
127 #endif\r
128         pcbPtr->regs[0] = msr;\r
129 \r
130         cPtr->pattern = FUNC_PATTERN;\r
131 }\r
132 \r
133 /**\r
134  *\r
135  * @param pcbPtr\r
136  */\r
137 \r
138 void Os_ArchSetTaskEntry(OsPcbType *pcbPtr ) {\r
139         Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;\r
140 \r
141         if( pcbPtr->proc_type == PROC_EXTENDED ) {\r
142                 cPtr->lr = (uint32_t)Os_TaskStartExtended;\r
143         } else if( pcbPtr->proc_type == PROC_BASIC ) {\r
144                 cPtr->lr = (uint32_t)Os_TaskStartBasic;\r
145         }\r
146 \r
147 }\r
148 \r
149 void Os_ArchInit( void ) {\r
150 #if defined(CFG_SPE)\r
151         uint32_t msr = get_msr();\r
152         msr |= MSR_SPE;\r
153         set_msr(msr);\r
154 #endif\r
155 }\r
156 \r
157 \r
158 \r