| 1 | /* |
|---|
| 2 | * hal_special.h - Generic Special Registers Access API definition. |
|---|
| 3 | * |
|---|
| 4 | * Authors Ghassan Almaless (2008,2009,2010,2011,2012) |
|---|
| 5 | * Alain Greiner (2016,2017) |
|---|
| 6 | * |
|---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
|---|
| 8 | * |
|---|
| 9 | * This file is part of ALMOS-MKH. |
|---|
| 10 | * |
|---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
|---|
| 12 | * under the terms of the GNU General Public License as published by |
|---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
|---|
| 14 | * |
|---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
|---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 18 | * General Public License for more details. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU General Public License |
|---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
|---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | #ifndef _HAL_CPU_H_ |
|---|
| 26 | #define _HAL_CPU_H_ |
|---|
| 27 | |
|---|
| 28 | #include <hal_types.h> |
|---|
| 29 | |
|---|
| 30 | /**** Forward declarations ***/ |
|---|
| 31 | |
|---|
| 32 | struct thread_s; |
|---|
| 33 | |
|---|
| 34 | /////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 35 | // Generic Special Registers Access API (implementation in hal_special.c) |
|---|
| 36 | // |
|---|
| 37 | // ALMOS-MKH uses the following API to access the MMU and other core protected registers. |
|---|
| 38 | /////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 39 | |
|---|
| 40 | /***************************************************************************************** |
|---|
| 41 | * This function returns the global core identifier from the calling core register. |
|---|
| 42 | ****************************************************************************************/ |
|---|
| 43 | gid_t hal_get_gid(); |
|---|
| 44 | |
|---|
| 45 | /***************************************************************************************** |
|---|
| 46 | * This function returns the content of the calling core cycles counter. |
|---|
| 47 | * This cycle counter is reset when the core is initialised (at reboot). |
|---|
| 48 | * If the hardware counter is not a 64 bits register, this function is in charge |
|---|
| 49 | * of handling overflow. |
|---|
| 50 | ****************************************************************************************/ |
|---|
| 51 | uint64_t hal_time_stamp(); |
|---|
| 52 | |
|---|
| 53 | /***************************************************************************************** |
|---|
| 54 | * This function returns the current thread pointer from the calling core register. |
|---|
| 55 | ****************************************************************************************/ |
|---|
| 56 | struct thread_s * hal_get_current_thread(); |
|---|
| 57 | |
|---|
| 58 | /***************************************************************************************** |
|---|
| 59 | * This function registers a thread pointer in the calling core register. |
|---|
| 60 | ****************************************************************************************/ |
|---|
| 61 | void hal_set_current_thread( struct thread_s * thread ); |
|---|
| 62 | |
|---|
| 63 | /***************************************************************************************** |
|---|
| 64 | * This function writes into the proper core register to enable the floating point unit. |
|---|
| 65 | ****************************************************************************************/ |
|---|
| 66 | void hal_fpu_enable(); |
|---|
| 67 | |
|---|
| 68 | /***************************************************************************************** |
|---|
| 69 | * This function writes into the proper core register to disable the floating point unit. |
|---|
| 70 | ****************************************************************************************/ |
|---|
| 71 | void hal_fpu_disable(); |
|---|
| 72 | |
|---|
| 73 | /***************************************************************************************** |
|---|
| 74 | * This function returns the current value of stack pointer from core register. |
|---|
| 75 | ****************************************************************************************/ |
|---|
| 76 | uint32_t hal_get_stack(); |
|---|
| 77 | |
|---|
| 78 | /***************************************************************************************** |
|---|
| 79 | * This function registers a new value in the core stack pointer and returns previous one. |
|---|
| 80 | ****************************************************************************************/ |
|---|
| 81 | extern inline uint32_t hal_set_stack( void * new_val ); |
|---|
| 82 | |
|---|
| 83 | /***************************************************************************************** |
|---|
| 84 | * This function returns the faulty address in case of address exception. |
|---|
| 85 | ****************************************************************************************/ |
|---|
| 86 | uint32_t hal_get_bad_vaddr(); |
|---|
| 87 | |
|---|
| 88 | /***************************************************************************************** |
|---|
| 89 | * This function makes an uncachable read to a 32 bits variable in local memory. |
|---|
| 90 | * @ ptr : pointer on the variable |
|---|
| 91 | * @ returns the value |
|---|
| 92 | ****************************************************************************************/ |
|---|
| 93 | uint32_t hal_uncached_read( uint32_t * ptr ); |
|---|
| 94 | |
|---|
| 95 | /***************************************************************************************** |
|---|
| 96 | * This function invalidates the cache line containing a given address. |
|---|
| 97 | * @ ptr : address in local memory |
|---|
| 98 | ****************************************************************************************/ |
|---|
| 99 | void hal_invalid_dcache_line( void * ptr ); |
|---|
| 100 | |
|---|
| 101 | /***************************************************************************************** |
|---|
| 102 | * This blocking function flushes the write buffer to synchronize all pending writes. |
|---|
| 103 | ****************************************************************************************/ |
|---|
| 104 | void hal_wbflush(); |
|---|
| 105 | |
|---|
| 106 | /***************************************************************************************** |
|---|
| 107 | * This forbids code reordering by the compiler. |
|---|
| 108 | ****************************************************************************************/ |
|---|
| 109 | void hal_rdbar(); |
|---|
| 110 | |
|---|
| 111 | /***************************************************************************************** |
|---|
| 112 | * This function forces the calling core in idle-low-power mode. |
|---|
| 113 | ****************************************************************************************/ |
|---|
| 114 | void hal_core_sleep(); |
|---|
| 115 | |
|---|
| 116 | /***************************************************************************************** |
|---|
| 117 | * This function returns after a fixed delay of (4 * delay) cycles. |
|---|
| 118 | ****************************************************************************************/ |
|---|
| 119 | void hal_fixed_delay(); |
|---|
| 120 | |
|---|
| 121 | /***************************************************************************************** |
|---|
| 122 | * This function returns information on MMU exceptions : |
|---|
| 123 | * @ mmu_ins_excp_code : [out] instruction fetch exception code |
|---|
| 124 | * @ mmu_ins_bad_vaddr : [out] instruction fetch faulty virtual address |
|---|
| 125 | * @ mmu_dat_excp_code : [out] data access exception code |
|---|
| 126 | * @ mmu_dat_bad_vaddr : [out] data access faulty virtual address |
|---|
| 127 | ****************************************************************************************/ |
|---|
| 128 | void hal_get_mmu_excp( intptr_t * mmu_ins_excp_code, |
|---|
| 129 | intptr_t * mmu_ins_bad_vaddr, |
|---|
| 130 | intptr_t * mmu_dat_excp_code, |
|---|
| 131 | intptr_t * mmu_dat_bad_vaddr ); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | #endif /* _HAL_SPECIAL_H_ */ |
|---|