1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 /* ----------------------------[includes]------------------------------------*/
\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
25 #define USE_LDEBUG_PRINTF
\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
40 * NOT complete yet.....
\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
46 void Os_ArchPanic( uint32_t err, void *errFramePtr , Os_ExceptionFrameType *excFramePtr) {
\r
48 case OS_ERR_BAD_CONTEXT:
\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
65 * Function make sure that we switch to supervisor mode(rfi) before
\r
66 * we call a task for the first time.
\r
68 void Os_ArchFirstCall( void )
\r
70 #if USE_MM_USER_MODE
\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
79 "mtspr 26,%0;\r\t" // srr0
\r
80 "mtspr 27,%1;\r\t" // srr1
\r
83 : "r" (ea), "r" (msr) );
\r
85 // TODO: This really depends on if scheduling policy
\r
87 os_sys.curr_pcb->entry();
\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
95 void *Os_ArchGetStackPtr( void ) {
\r
97 // Get stack ptr(r1) from current context
\r
98 asm volatile(" mr %0,1":"=r" (stackp));
\r
103 unsigned int Os_ArchGetScSize( void ) {
\r
104 return FUNC_FRM_SIZE;
\r
109 * Setup a context for a task.
\r
111 * @param pcb Pointer to the pcb to setup
\r
113 void Os_ArchSetupContext( OsPcbType *pcbPtr ) {
\r
114 Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;
\r
118 #if defined(CFG_SPE)
\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
128 pcbPtr->regs[0] = msr;
\r
130 cPtr->pattern = FUNC_PATTERN;
\r
138 void Os_ArchSetTaskEntry(OsPcbType *pcbPtr ) {
\r
139 Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;
\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
149 void Os_ArchInit( void ) {
\r
150 #if defined(CFG_SPE)
\r
151 uint32_t msr = get_msr();
\r