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
22 #include "asm_ppc.h"
\r
23 #include "mpc55xx.h"
\r
24 #include "arch_stack.h"
\r
25 #include "arch_offset.h"
\r
27 #define USE_LDEBUG_PRINTF
\r
30 /* ----------------------------[private define]------------------------------*/
\r
31 /* ----------------------------[private macro]-------------------------------*/
\r
32 /* ----------------------------[private typedef]-----------------------------*/
\r
33 /* ----------------------------[private function prototypes]-----------------*/
\r
34 /* ----------------------------[private variables]---------------------------*/
\r
35 /* ----------------------------[private functions]---------------------------*/
\r
36 /* ----------------------------[public functions]----------------------------*/
\r
41 * NOT complete yet.....
\r
43 * @param err The error code.
\r
44 * @param errFramePtr Pointer to extra information about the error, if any.
\r
45 * @param excFramePtr Pointer to the exception frame, that caused the error.
\r
47 void Os_ArchPanic( uint32_t err, void *errFramePtr , Os_ExceptionFrameType *excFramePtr) {
\r
51 case OS_ERR_BAD_CONTEXT:
\r
54 case OS_ERR_SPURIOUS_INTERRUPT:
\r
55 fputs("Spurious interrupt\n",stdout);
\r
56 printf(" vector : %02lx\n", excFramePtr->vector);
\r
57 printf(" srr0 : %08lx\n", excFramePtr->srr0);
\r
58 printf(" srr1 : %08lx\n", excFramePtr->srr1);
\r
68 * Function make sure that we switch to supervisor mode(rfi) before
\r
69 * we call a task for the first time.
\r
71 void Os_ArchFirstCall( void )
\r
73 #if USE_MM_USER_MODE
\r
75 // Assume that regs[0] is setup before and contains the settings
\r
76 // to switch to user mode.
\r
77 register uint32_t msr asm("r3") = os_sys.curr_pcb->regs[0];
\r
78 register void *ea asm("r4") = (void *) os_sys.curr_pcb->entry;
\r
82 "mtspr 26,%0;\r\t" // srr0
\r
83 "mtspr 27,%1;\r\t" // srr1
\r
86 : "r" (ea), "r" (msr) );
\r
88 // TODO: This really depends on if scheduling policy
\r
90 Os_Sys.currTaskPtr->constPtr->entry();
\r
91 //os_sys.curr_pcb->entry();
\r
96 /* TODO: This actually gives the stack ptr here...not the callers stack ptr
\r
97 * Should probably be a macro instead..... in some arch part..
\r
99 void *Os_ArchGetStackPtr( void ) {
\r
101 // Get stack ptr(r1) from current context
\r
102 asm volatile(" mr %0,1":"=r" (stackp));
\r
107 unsigned int Os_ArchGetScSize( void ) {
\r
108 return FUNC_FRM_SIZE;
\r
113 * Setup a context for a task.
\r
115 * @param pcb Pointer to the pcb to setup
\r
117 void Os_ArchSetupContext( OsTaskVarType *pcbPtr ) {
\r
118 Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;
\r
122 #if defined(CFG_SPE)
\r
126 #if (OS_USE_APPLICATIONS == STD_ON)
\r
128 if( !pcb->application->trusted ) {
\r
129 // Non-trusted = User mode..
\r
130 msr |= MSR_PR | MSR_DS | MSR_IS;
\r
134 pcbPtr->regs[0] = msr;
\r
136 cPtr->pattern = FUNC_PATTERN;
\r
144 void Os_ArchSetTaskEntry(OsTaskVarType *pcbPtr ) {
\r
145 Os_FuncFrameType *cPtr = (Os_FuncFrameType *)pcbPtr->stack.curr;
\r
147 if( pcbPtr->constPtr->proc_type == PROC_EXTENDED ) {
\r
148 cPtr->lr = (uint32_t)Os_TaskStartExtended;
\r
149 } else if( pcbPtr->constPtr->proc_type == PROC_BASIC ) {
\r
150 cPtr->lr = (uint32_t)Os_TaskStartBasic;
\r
155 void Os_ArchInit( void ) {
\r
156 #if defined(CFG_SPE)
\r
157 uint32_t msr = get_msr();
\r