]> rtime.felk.cvut.cz Git - arc.git/blob - arch/ppc/mpc55xx/kernel/arch.c
Isr almost done
[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.currTaskPtr->constPtr->entry();\r
88         //os_sys.curr_pcb->entry();\r
89 #endif\r
90 }\r
91 \r
92 \r
93 /* TODO: This actually gives the stack ptr here...not the callers stack ptr\r
94  * Should probably be a macro instead..... in some arch part..\r
95  */\r
96 void *Os_ArchGetStackPtr( void ) {\r
97         void *stackp;\r
98         // Get stack ptr(r1) from current context\r
99         asm volatile(" mr %0,1":"=r" (stackp));\r
100 \r
101         return stackp;\r
102 }\r
103 \r
104 unsigned int Os_ArchGetScSize( void ) {\r
105         return FUNC_FRM_SIZE;\r
106 }\r
107 \r
108 \r
109 /**\r
110  * Setup a context for a task.\r
111  *\r
112  * @param pcb Pointer to the pcb to setup\r
113  */\r
114 void Os_ArchSetupContext( OsTaskVarType *pcbPtr ) {\r
115         Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;\r
116         uint32_t msr;\r
117         msr = MSR_EE;\r
118 \r
119 #if defined(CFG_SPE)\r
120         msr |= MSR_SPE;\r
121 #endif\r
122 \r
123 #if (OS_USE_APPLICATIONS == STD_ON)\r
124 #if 0\r
125         if( !pcb->application->trusted ) {\r
126                 // Non-trusted = User mode..\r
127                 msr |= MSR_PR | MSR_DS | MSR_IS;\r
128         }\r
129 #endif\r
130 #endif\r
131         pcbPtr->regs[0] = msr;\r
132 \r
133         cPtr->pattern = FUNC_PATTERN;\r
134 }\r
135 \r
136 /**\r
137  *\r
138  * @param pcbPtr\r
139  */\r
140 \r
141 void Os_ArchSetTaskEntry(OsTaskVarType *pcbPtr ) {\r
142         Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;\r
143 \r
144         if( pcbPtr->constPtr->proc_type == PROC_EXTENDED ) {\r
145                 cPtr->lr = (uint32_t)Os_TaskStartExtended;\r
146         } else if( pcbPtr->constPtr->proc_type == PROC_BASIC ) {\r
147                 cPtr->lr = (uint32_t)Os_TaskStartBasic;\r
148         }\r
149 \r
150 }\r
151 \r
152 void Os_ArchInit( void ) {\r
153 #if defined(CFG_SPE)\r
154         uint32_t msr = get_msr();\r
155         msr |= MSR_SPE;\r
156         set_msr(msr);\r
157 #endif\r
158 }\r
159 \r
160 \r
161 \r