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