1 | /* |
---|
2 | * hal_special.c - implementation of Generic Special Register Access API for TSAR-MIPS32 |
---|
3 | * |
---|
4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
5 | * Alain Greiner (2016) |
---|
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 | |
---|
26 | #include <hal_types.h> |
---|
27 | #include <hal_special.h> |
---|
28 | |
---|
29 | /**** Forward declarations ****/ |
---|
30 | |
---|
31 | struct thread_s; |
---|
32 | |
---|
33 | /////////////////// |
---|
34 | gid_t hal_get_gid() |
---|
35 | { |
---|
36 | uint32_t proc_id; |
---|
37 | |
---|
38 | asm volatile ("mfc0 %0, $15, 1" : "=&r" (proc_id)); |
---|
39 | |
---|
40 | return (proc_id & 0x3FF); // 4/4/2 format for TSAR |
---|
41 | } |
---|
42 | |
---|
43 | ///////////////////////// |
---|
44 | uint32_t hal_time_stamp() |
---|
45 | { |
---|
46 | uint32_t cycles; |
---|
47 | |
---|
48 | asm volatile ("mfc0 %0, $9 " : "=&r" (cycles)); |
---|
49 | |
---|
50 | return cycles; |
---|
51 | } |
---|
52 | |
---|
53 | ////////////////////////////////////////// |
---|
54 | struct thread_s * hal_get_current_thread() |
---|
55 | { |
---|
56 | void * thread_ptr; |
---|
57 | |
---|
58 | asm volatile |
---|
59 | ( "mfc0 %0, $4, 2 \n" |
---|
60 | : "=&r" (thread_ptr) ); |
---|
61 | |
---|
62 | return thread_ptr; |
---|
63 | } |
---|
64 | |
---|
65 | /////////////////////////////////////////////////////// |
---|
66 | void hal_set_current_thread( struct thread_s * thread ) |
---|
67 | { |
---|
68 | asm volatile |
---|
69 | ( "mtc0 %0, $4, 2 \n" |
---|
70 | : : "r" (thread) ); |
---|
71 | } |
---|
72 | |
---|
73 | ///////////////////// |
---|
74 | void hal_fpu_enable() |
---|
75 | { |
---|
76 | asm volatile |
---|
77 | ( ".set noat \n" |
---|
78 | "lui $27, 0x2000 \n" |
---|
79 | "mfc0 $1, $12 \n" |
---|
80 | "or $27, $1, $27 \n" |
---|
81 | "mtc0 $27, $12 \n" |
---|
82 | ".set at \n" ); |
---|
83 | } |
---|
84 | |
---|
85 | ////////////////////// |
---|
86 | void hal_fpu_disable() |
---|
87 | { |
---|
88 | asm volatile |
---|
89 | ( ".set noat \n" |
---|
90 | "lui $27, 0xDFFF \n" |
---|
91 | "ori $27, $27, 0xFFFF \n" |
---|
92 | "mfc0 $1, $12 \n" |
---|
93 | "and $27, $1, $27 \n" |
---|
94 | "mtc0 $27, $12 \n" |
---|
95 | ".set at \n"); |
---|
96 | } |
---|
97 | |
---|
98 | //////////////////////// |
---|
99 | uint32_t hal_get_stack() |
---|
100 | { |
---|
101 | register uint32_t sp; |
---|
102 | |
---|
103 | asm volatile |
---|
104 | ( "or %0, $0, $29 \n" |
---|
105 | : "=&r" (sp) ); |
---|
106 | |
---|
107 | return sp; |
---|
108 | } |
---|
109 | |
---|
110 | //////////////////////////////////////// |
---|
111 | uint32_t hal_set_stack( void * new_val ) |
---|
112 | { |
---|
113 | register uint32_t sp; |
---|
114 | |
---|
115 | asm volatile |
---|
116 | ( "or %0, $0, $29 \n" |
---|
117 | "or $29, $0, %1 \n" |
---|
118 | : "=&r" (sp) : "r" (new_val) ); |
---|
119 | |
---|
120 | return sp; |
---|
121 | } |
---|
122 | |
---|
123 | //////////////////////////// |
---|
124 | uint32_t hal_get_bad_vaddr() |
---|
125 | { |
---|
126 | register uint32_t bad_va; |
---|
127 | |
---|
128 | asm volatile |
---|
129 | ( "mfc0 %0, $8 \n" |
---|
130 | : "=&r" (bad_va) ); |
---|
131 | |
---|
132 | return bad_va; |
---|
133 | } |
---|
134 | |
---|
135 | //////////////////////////////////////////// |
---|
136 | uint32_t hal_uncached_read( uint32_t * ptr ) |
---|
137 | { |
---|
138 | register uint32_t val; |
---|
139 | |
---|
140 | asm volatile |
---|
141 | ( "ll %0, (%1) \n" |
---|
142 | : "=&r"(val) : "r" (ptr) ); |
---|
143 | |
---|
144 | return val; |
---|
145 | } |
---|
146 | |
---|
147 | ////////////////////////////////////////// |
---|
148 | void hal_invalid_dcache_line( void * ptr ) |
---|
149 | { |
---|
150 | asm volatile |
---|
151 | ( "cache %0, (%1) \n" |
---|
152 | "sync \n" |
---|
153 | : : "i" (0x11) , "r" (ptr) ); |
---|
154 | } |
---|
155 | |
---|
156 | ////////////////// |
---|
157 | void hal_wbflush() |
---|
158 | { |
---|
159 | asm volatile |
---|
160 | ( "sync \n":: ); |
---|
161 | } |
---|
162 | |
---|
163 | //////////////// |
---|
164 | void hal_rdbar() |
---|
165 | { |
---|
166 | asm volatile( "" ::: "memory" ); |
---|
167 | } |
---|
168 | |
---|
169 | ///////////////////// |
---|
170 | void hal_core_sleep() |
---|
171 | { |
---|
172 | asm volatile |
---|
173 | ("wait \n"::); |
---|
174 | } |
---|
175 | |
---|
176 | ////////////////////////////////////// |
---|
177 | void hal_fixed_delay( uint32_t delay ) |
---|
178 | { |
---|
179 | asm volatile |
---|
180 | ( "1: \n" |
---|
181 | "or $27, %0, $0 \n" |
---|
182 | "addi $27, $27, -1 \n" |
---|
183 | "bne $27, $0, 1b \n" |
---|
184 | "nop \n" |
---|
185 | : : "r" (delay) : "$27" ); |
---|
186 | } |
---|
187 | |
---|
188 | ////////////////////////////////////////////////// |
---|
189 | void hal_get_mmu_excp( intptr_t * mmu_ins_excp_code, |
---|
190 | intptr_t * mmu_ins_bad_vaddr, |
---|
191 | intptr_t * mmu_dat_excp_code, |
---|
192 | intptr_t * mmu_dat_bad_vaddr ) |
---|
193 | { |
---|
194 | asm volatile |
---|
195 | ( "mfc2 %0, $11 \n" |
---|
196 | "mfc2 %1, $13 \n" |
---|
197 | "mfc2 %2, $12 \n" |
---|
198 | "mfc2 %3, $14 \n" |
---|
199 | : "=&r"(mmu_ins_excp_code), |
---|
200 | "=&r"(mmu_ins_bad_vaddr), |
---|
201 | "=&r"(mmu_dat_excp_code), |
---|
202 | "=&r"(mmu_dat_bad_vaddr) ); |
---|
203 | } |
---|