1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the GNU General Public License version 2. Note that NO WARRANTY is provided. 8 * See "LICENSE_GPLv2.txt" for details. 9 * 10 * @TAG(DATA61_GPL) 11 */ 12 13#ifndef __MODE_MODEL_SMP_H_ 14#define __MODE_MODEL_SMP_H_ 15 16#include <config.h> 17 18#ifdef ENABLE_SMP_SUPPORT 19 20extern char kernel_stack_alloc[CONFIG_MAX_NUM_NODES][BIT(CONFIG_KERNEL_STACK_BITS)]; 21 22/* Get current stack pointer */ 23static inline void* 24getCurESP(void) 25{ 26 word_t stack; 27 void *result; 28 asm ("movl %[stack_address], %[result]" : [result] "=r"(result) : [stack_address] "r"(&stack)); 29 return result; 30} 31 32static inline CONST cpu_id_t 33getCurrentCPUIndex(void) 34{ 35 cpu_id_t cpu_id; 36 uint32_t esp = (uint32_t)getCurESP(); 37 38 esp -= (uint32_t)kernel_stack_alloc; 39 cpu_id = esp >> CONFIG_KERNEL_STACK_BITS; 40 return cpu_id; 41} 42 43static inline BOOT_CODE void 44mode_init_tls(cpu_id_t cpu_index) 45{ 46 /* Nothing to be done on ia32 */ 47} 48 49#endif /* ENABLE_SMP_SUPPORT */ 50 51#endif /* __MODE_MODEL_SMP_H_ */ 52