source: trunk/hal/generic/hal_special.h @ 623

Last change on this file since 623 was 623, checked in by alain, 3 years ago

Introduce three new types of vsegs (KCODE,KDATA,KDEV)
to map the kernel vsegs in the process VSL and GPT.
This now used by both the TSAR and the I86 architectures.

File size: 8.9 KB
Line 
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_shared_types.h>
28#include <hal_kernel_types.h>
29
30/****  Forward declarations  ***/
31
32struct thread_s;
33struct gpt_s;
34
35///////////////////////////////////////////////////////////////////////////////////////////
36//      Generic Special Registers Access API (implementation in hal_special.c)
37//
38// ALMOS-MKH uses the following API to access the core protected registers.
39///////////////////////////////////////////////////////////////////////////////////////////
40
41/*****************************************************************************************
42 * This function initialise - for architectures requiring it - the protected register(s)
43 * containing the kernel_entry adresse(s) for interrupts / exceptions / syscalls.
44 ****************************************************************************************/
45void hal_set_kentry( void );
46
47/*****************************************************************************************
48 * This function initializes - for architectures requiring it - the MMU registers
49 * as required by the target architecture to execute the kernel threads attached
50 * to kernel process zero. It is called by all cores in the kernel_init() function.
51 *****************************************************************************************
52 * @ gpt :  local pointer on the kernel page table descriptor.
53 ****************************************************************************************/
54void hal_mmu_init( struct gpt_s * gpt );
55
56/*****************************************************************************************
57 * This function returns the calling core status register value.
58 ****************************************************************************************/
59inline reg_t hal_get_sr( void );
60
61/*****************************************************************************************
62 * This function returns the global core identifier from the calling core register.
63 ****************************************************************************************/
64inline gid_t hal_get_gid( void );
65
66/*****************************************************************************************
67 * This function returns the current value of the hardware cycles counter.
68 * This cycle counter is reset when the core is initialised (at each boot).
69 ****************************************************************************************/
70inline reg_t hal_time_stamp( void );
71
72/*****************************************************************************************
73 * This function returns the content of the calling core private cycles counter,
74 * taking into account overflow if the core hardware register is not 64 bits.
75 * This cycle counter is reset when the core is initialised (at each boot).
76 ****************************************************************************************/
77cycle_t hal_get_cycles( void );
78
79/*****************************************************************************************
80 * This function returns the current thread pointer from the calling core register.
81 ****************************************************************************************/
82inline struct thread_s * hal_get_current_thread( void );
83
84/*****************************************************************************************
85 * This function registers a thread pointer in the calling core register.
86 ****************************************************************************************/
87void hal_set_current_thread( struct thread_s * thread );
88
89/*****************************************************************************************
90 * This function writes into the proper core register to enable the floating point unit.
91 ****************************************************************************************/
92void hal_fpu_enable( void );
93
94/*****************************************************************************************
95 * This function writes into the proper core register to disable the floating point unit.
96 ****************************************************************************************/
97void hal_fpu_disable( void );
98
99/*****************************************************************************************
100 * This function returns the current value of stack pointer from core register.
101 ****************************************************************************************/
102uint32_t hal_get_sp( void );
103
104/*****************************************************************************************
105 * This function returns the current value of the return adddress from core register.
106 ****************************************************************************************/
107uint32_t hal_get_ra( void );
108
109/*****************************************************************************************
110 * This function registers a new value in the core stack pointer and returns previous one.
111 ****************************************************************************************/
112inline uint32_t hal_set_sp( void * new_val );
113
114/*****************************************************************************************
115 * This function returns the faulty address in case of address exception.
116 ****************************************************************************************/
117uint32_t hal_get_bad_vaddr( void );
118
119/*****************************************************************************************
120 * This function makes an uncachable read to a 32 bits variable in local memory.
121 *****************************************************************************************
122 * @ ptr     : pointer on the variable
123 * @ returns the value
124 ****************************************************************************************/
125uint32_t hal_uncached_read( uint32_t * ptr );
126
127/*****************************************************************************************
128 * This function invalidates the cache line containing a given address.
129 * @ ptr     : address in local memory
130 ****************************************************************************************/
131void hal_invalid_dcache_line( void * ptr );
132
133/*****************************************************************************************
134 * This blocking function flushes the write buffer to synchronize all pending writes.
135 ****************************************************************************************/
136void hal_fence( void );
137
138/*****************************************************************************************
139 * This forbids code reordering accross this barrier by the compiler.
140 ****************************************************************************************/
141void hal_rdbar( void );
142
143/*****************************************************************************************
144 * This function forces the calling core in idle-low-power mode.
145 ****************************************************************************************/
146void hal_core_sleep( void ) __attribute__((__noreturn__));
147
148/*****************************************************************************************
149 * This function returns after approximately <delay> cycles.
150 * @ delay  : number of cycles.
151 ****************************************************************************************/
152void hal_fixed_delay( uint32_t delay );
153
154/*****************************************************************************************
155 * This function returns information on MMU exceptions :
156 *****************************************************************************************
157 * @ mmu_ins_excp_code : [out] instruction fetch exception code
158 * @ mmu_ins_bad_vaddr : [out] instruction fetch faulty virtual address
159 * @ mmu_dat_excp_code : [out] data access exception code
160 * @ mmu_dat_bad_vaddr : [out] data access faulty virtual address
161 ****************************************************************************************/
162void hal_get_mmu_excp( intptr_t * mmu_ins_excp_code,
163                       intptr_t * mmu_ins_bad_vaddr,
164                       intptr_t * mmu_dat_excp_code,
165                       intptr_t * mmu_dat_bad_vaddr );
166
167
168#endif  /* _HAL_SPECIAL_H_ */
Note: See TracBrowser for help on using the repository browser.