1 /* 2 * Copyright (C) 2016 YunOS Project. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <k_api.h> 18 19 #undef PSR_SP 20 #define PSR_SP (1UL << 29) 21 static ktask_t *tee_caller_task = NULL; 22 getcurrentpsr(void)23static inline uint32_t getcurrentpsr(void) 24 { 25 uint32_t flags = 0; 26 27 __asm__ __volatile__( 28 "ebreak\n" /* TODO */ 29 ); 30 31 return flags; 32 } 33 clear_psr_sp(void)34static inline void clear_psr_sp(void) 35 { 36 __asm__ __volatile__ ( 37 "ebreak\n" /* TODO */ 38 ); 39 } 40 set_psr_sp(void)41static inline void set_psr_sp(void) 42 { 43 __asm__ __volatile__ ( 44 "ebreak\n" /* TODO */ 45 ); 46 } 47 csky_get_tee_caller_task(void)48void csky_get_tee_caller_task(void) 49 { 50 uint32_t temp_psr; 51 52 temp_psr = getcurrentpsr(); 53 if (temp_psr & PSR_SP) { 54 tee_caller_task = (tee_caller_task == NULL) ? g_active_task[cpu_cur_get()] : tee_caller_task; 55 } 56 } 57 csky_deal_tee_caller_task(void)58void csky_deal_tee_caller_task(void) 59 { 60 uint32_t temp_psr; 61 62 temp_psr = getcurrentpsr(); 63 if (temp_psr & PSR_SP) { 64 if (tee_caller_task != NULL) { 65 if (tee_caller_task == g_active_task[cpu_cur_get()]) { 66 tee_caller_task = NULL; 67 } else { 68 clear_psr_sp(); 69 } 70 } 71 } else { 72 if (tee_caller_task != NULL) { 73 if (tee_caller_task == g_active_task[cpu_cur_get()]) { 74 tee_caller_task = NULL; 75 set_psr_sp(); 76 } 77 } 78 } 79 } 80