1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci */ 15425bb815Sopenharmony_ci 16425bb815Sopenharmony_ci#include "jerryscript-port.h" 17425bb815Sopenharmony_ci#include "jerryscript-port-default.h" 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ci#if (JERRY_EXTERNAL_CONTEXT == 1) 20425bb815Sopenharmony_ci 21425bb815Sopenharmony_ciextern jerry_context_t *jerry_dynamic_global_context_p; 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci#if defined (JERRY_FOR_IAR_CONFIG) 24425bb815Sopenharmony_ci 25425bb815Sopenharmony_ci#include "generate-bytecode.h" 26425bb815Sopenharmony_ci#include "los_task.h" 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ci/** 29425bb815Sopenharmony_ci * use dynamic size array to record the correspondence between task id and jerry-heap/context 30425bb815Sopenharmony_ci */ 31425bb815Sopenharmony_ciextern ContextRecord* g_contextRecords; 32425bb815Sopenharmony_ci 33425bb815Sopenharmony_ci/** 34425bb815Sopenharmony_ci * obtain the task ID with the highest priority in the task readiness queue 35425bb815Sopenharmony_ci */ 36425bb815Sopenharmony_ciextern UINT32 LOS_NextTaskIDGet(VOID); 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_civoid jerry_switch_context(); 39425bb815Sopenharmony_ci 40425bb815Sopenharmony_ci/** 41425bb815Sopenharmony_ci * set context function: store task id and context 42425bb815Sopenharmony_ci */ 43425bb815Sopenharmony_civoid 44425bb815Sopenharmony_cijerry_port_default_set_current_context (jerry_context_t *context_p) /**< store created context */ 45425bb815Sopenharmony_ci{ 46425bb815Sopenharmony_ci uint32_t curTaskId = LOS_CurTaskIDGet(); 47425bb815Sopenharmony_ci g_contextRecords[curTaskId].context_p = context_p; 48425bb815Sopenharmony_ci jerry_dynamic_global_context_p = context_p; 49425bb815Sopenharmony_ci} 50425bb815Sopenharmony_ci 51425bb815Sopenharmony_civoid jerry_switch_context() 52425bb815Sopenharmony_ci{ 53425bb815Sopenharmony_ci jerry_dynamic_global_context_p = g_contextRecords[LOS_NextTaskIDGet()].context_p; 54425bb815Sopenharmony_ci} 55425bb815Sopenharmony_ci 56425bb815Sopenharmony_ci/** 57425bb815Sopenharmony_ci * when task ends, the context_pointer point to NULL 58425bb815Sopenharmony_ci */ 59425bb815Sopenharmony_civoid 60425bb815Sopenharmony_cijerry_port_default_remove_current_context_record () /**< remove current task's context record in Array */ 61425bb815Sopenharmony_ci{ 62425bb815Sopenharmony_ci uint32_t curTaskId = LOS_CurTaskIDGet(); 63425bb815Sopenharmony_ci g_contextRecords[curTaskId].context_p = NULL; 64425bb815Sopenharmony_ci jerry_dynamic_global_context_p = NULL; 65425bb815Sopenharmony_ci} 66425bb815Sopenharmony_ci 67425bb815Sopenharmony_ci/** 68425bb815Sopenharmony_ci * key: global dynamic context_p for current context 69425bb815Sopenharmony_ci */ 70425bb815Sopenharmony_cijerry_context_t * 71425bb815Sopenharmony_cijerry_port_get_current_context (void) /**< points to current task's context */ 72425bb815Sopenharmony_ci{ 73425bb815Sopenharmony_ci return jerry_dynamic_global_context_p; 74425bb815Sopenharmony_ci} 75425bb815Sopenharmony_ci 76425bb815Sopenharmony_ci#else // not defined JERRY_FOR_IAR_CONFIG, but enabled JERRY_EXTERNAL_CONTEXT 77425bb815Sopenharmony_ci 78425bb815Sopenharmony_ci/** 79425bb815Sopenharmony_ci * Set the current_context_p as the passed pointer. 80425bb815Sopenharmony_ci */ 81425bb815Sopenharmony_civoid 82425bb815Sopenharmony_cijerry_port_default_set_current_context (jerry_context_t *context_p) /**< points to the created context */ 83425bb815Sopenharmony_ci{ 84425bb815Sopenharmony_ci jerry_dynamic_global_context_p = context_p; 85425bb815Sopenharmony_ci} /* jerry_port_default_set_current_context */ 86425bb815Sopenharmony_ci 87425bb815Sopenharmony_ci/** 88425bb815Sopenharmony_ci * Get the current context. 89425bb815Sopenharmony_ci * 90425bb815Sopenharmony_ci * @return the pointer to the current context 91425bb815Sopenharmony_ci */ 92425bb815Sopenharmony_cijerry_context_t * 93425bb815Sopenharmony_cijerry_port_get_current_context (void) 94425bb815Sopenharmony_ci{ 95425bb815Sopenharmony_ci return jerry_dynamic_global_context_p; 96425bb815Sopenharmony_ci} /* jerry_port_get_current_context */ 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ci#endif // defined (JERRY_FOR_IAR_CONFIG) 99425bb815Sopenharmony_ci 100425bb815Sopenharmony_ci#else // (JERRY_EXTERNAL_CONTEXT == 0) 101425bb815Sopenharmony_ci 102425bb815Sopenharmony_cistatic jerry_context_t *current_context_p = NULL; 103425bb815Sopenharmony_ci 104425bb815Sopenharmony_ci/** 105425bb815Sopenharmony_ci * Set the current_context_p as the passed pointer. 106425bb815Sopenharmony_ci */ 107425bb815Sopenharmony_civoid 108425bb815Sopenharmony_cijerry_port_default_set_current_context (jerry_context_t *context_p) /**< points to the created context */ 109425bb815Sopenharmony_ci{ 110425bb815Sopenharmony_ci current_context_p = context_p; 111425bb815Sopenharmony_ci} /* jerry_port_default_set_current_context */ 112425bb815Sopenharmony_ci 113425bb815Sopenharmony_ci/** 114425bb815Sopenharmony_ci * Get the current context. 115425bb815Sopenharmony_ci * 116425bb815Sopenharmony_ci * @return the pointer to the current context 117425bb815Sopenharmony_ci */ 118425bb815Sopenharmony_cijerry_context_t * 119425bb815Sopenharmony_cijerry_port_get_current_context (void) 120425bb815Sopenharmony_ci{ 121425bb815Sopenharmony_ci return current_context_p; 122425bb815Sopenharmony_ci} /* jerry_port_get_current_context */ 123425bb815Sopenharmony_ci 124425bb815Sopenharmony_ci#endif // (JERRY_EXTERNAL_CONTEXT == 0) 125