source: mainline/kernel/arch/sparc64/include/asm.h@ 1b1164e8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b1164e8 was d99c1d2, checked in by Martin Decky <martin@…>, 15 years ago

use [u]int{8|16|32|64}_t type definitions as detected by the autotool
replace direct usage of arch/types.h with typedefs.h

  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup sparc64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_sparc64_ASM_H_
36#define KERN_sparc64_ASM_H_
37
38#include <arch/arch.h>
39#include <typedefs.h>
40#include <align.h>
41#include <arch/register.h>
42#include <config.h>
43#include <arch/stack.h>
44#include <arch/barrier.h>
45
46static inline void pio_write_8(ioport8_t *port, uint8_t v)
47{
48 *port = v;
49 memory_barrier();
50}
51
52static inline void pio_write_16(ioport16_t *port, uint16_t v)
53{
54 *port = v;
55 memory_barrier();
56}
57
58static inline void pio_write_32(ioport32_t *port, uint32_t v)
59{
60 *port = v;
61 memory_barrier();
62}
63
64static inline uint8_t pio_read_8(ioport8_t *port)
65{
66 uint8_t rv;
67
68 rv = *port;
69 memory_barrier();
70
71 return rv;
72}
73
74static inline uint16_t pio_read_16(ioport16_t *port)
75{
76 uint16_t rv;
77
78 rv = *port;
79 memory_barrier();
80
81 return rv;
82}
83
84static inline uint32_t pio_read_32(ioport32_t *port)
85{
86 uint32_t rv;
87
88 rv = *port;
89 memory_barrier();
90
91 return rv;
92}
93
94/** Read Processor State register.
95 *
96 * @return Value of PSTATE register.
97 */
98static inline uint64_t pstate_read(void)
99{
100 uint64_t v;
101
102 asm volatile ("rdpr %%pstate, %0\n" : "=r" (v));
103
104 return v;
105}
106
107/** Write Processor State register.
108 *
109 * @param v New value of PSTATE register.
110 */
111static inline void pstate_write(uint64_t v)
112{
113 asm volatile ("wrpr %0, %1, %%pstate\n" : : "r" (v), "i" (0));
114}
115
116/** Read TICK_compare Register.
117 *
118 * @return Value of TICK_comapre register.
119 */
120static inline uint64_t tick_compare_read(void)
121{
122 uint64_t v;
123
124 asm volatile ("rd %%tick_cmpr, %0\n" : "=r" (v));
125
126 return v;
127}
128
129/** Write TICK_compare Register.
130 *
131 * @param v New value of TICK_comapre register.
132 */
133static inline void tick_compare_write(uint64_t v)
134{
135 asm volatile ("wr %0, %1, %%tick_cmpr\n" : : "r" (v), "i" (0));
136}
137
138/** Read STICK_compare Register.
139 *
140 * @return Value of STICK_compare register.
141 */
142static inline uint64_t stick_compare_read(void)
143{
144 uint64_t v;
145
146 asm volatile ("rd %%asr25, %0\n" : "=r" (v));
147
148 return v;
149}
150
151/** Write STICK_compare Register.
152 *
153 * @param v New value of STICK_comapre register.
154 */
155static inline void stick_compare_write(uint64_t v)
156{
157 asm volatile ("wr %0, %1, %%asr25\n" : : "r" (v), "i" (0));
158}
159
160/** Read TICK Register.
161 *
162 * @return Value of TICK register.
163 */
164static inline uint64_t tick_read(void)
165{
166 uint64_t v;
167
168 asm volatile ("rdpr %%tick, %0\n" : "=r" (v));
169
170 return v;
171}
172
173/** Write TICK Register.
174 *
175 * @param v New value of TICK register.
176 */
177static inline void tick_write(uint64_t v)
178{
179 asm volatile ("wrpr %0, %1, %%tick\n" : : "r" (v), "i" (0));
180}
181
182/** Read FPRS Register.
183 *
184 * @return Value of FPRS register.
185 */
186static inline uint64_t fprs_read(void)
187{
188 uint64_t v;
189
190 asm volatile ("rd %%fprs, %0\n" : "=r" (v));
191
192 return v;
193}
194
195/** Write FPRS Register.
196 *
197 * @param v New value of FPRS register.
198 */
199static inline void fprs_write(uint64_t v)
200{
201 asm volatile ("wr %0, %1, %%fprs\n" : : "r" (v), "i" (0));
202}
203
204/** Read SOFTINT Register.
205 *
206 * @return Value of SOFTINT register.
207 */
208static inline uint64_t softint_read(void)
209{
210 uint64_t v;
211
212 asm volatile ("rd %%softint, %0\n" : "=r" (v));
213
214 return v;
215}
216
217/** Write SOFTINT Register.
218 *
219 * @param v New value of SOFTINT register.
220 */
221static inline void softint_write(uint64_t v)
222{
223 asm volatile ("wr %0, %1, %%softint\n" : : "r" (v), "i" (0));
224}
225
226/** Write CLEAR_SOFTINT Register.
227 *
228 * Bits set in CLEAR_SOFTINT register will be cleared in SOFTINT register.
229 *
230 * @param v New value of CLEAR_SOFTINT register.
231 */
232static inline void clear_softint_write(uint64_t v)
233{
234 asm volatile ("wr %0, %1, %%clear_softint\n" : : "r" (v), "i" (0));
235}
236
237/** Write SET_SOFTINT Register.
238 *
239 * Bits set in SET_SOFTINT register will be set in SOFTINT register.
240 *
241 * @param v New value of SET_SOFTINT register.
242 */
243static inline void set_softint_write(uint64_t v)
244{
245 asm volatile ("wr %0, %1, %%set_softint\n" : : "r" (v), "i" (0));
246}
247
248/** Enable interrupts.
249 *
250 * Enable interrupts and return previous
251 * value of IPL.
252 *
253 * @return Old interrupt priority level.
254 */
255static inline ipl_t interrupts_enable(void) {
256 pstate_reg_t pstate;
257 uint64_t value;
258
259 value = pstate_read();
260 pstate.value = value;
261 pstate.ie = true;
262 pstate_write(pstate.value);
263
264 return (ipl_t) value;
265}
266
267/** Disable interrupts.
268 *
269 * Disable interrupts and return previous
270 * value of IPL.
271 *
272 * @return Old interrupt priority level.
273 */
274static inline ipl_t interrupts_disable(void) {
275 pstate_reg_t pstate;
276 uint64_t value;
277
278 value = pstate_read();
279 pstate.value = value;
280 pstate.ie = false;
281 pstate_write(pstate.value);
282
283 return (ipl_t) value;
284}
285
286/** Restore interrupt priority level.
287 *
288 * Restore IPL.
289 *
290 * @param ipl Saved interrupt priority level.
291 */
292static inline void interrupts_restore(ipl_t ipl) {
293 pstate_reg_t pstate;
294
295 pstate.value = pstate_read();
296 pstate.ie = ((pstate_reg_t) ipl).ie;
297 pstate_write(pstate.value);
298}
299
300/** Return interrupt priority level.
301 *
302 * Return IPL.
303 *
304 * @return Current interrupt priority level.
305 */
306static inline ipl_t interrupts_read(void) {
307 return (ipl_t) pstate_read();
308}
309
310/** Return base address of current stack.
311 *
312 * Return the base address of the current stack.
313 * The stack is assumed to be STACK_SIZE bytes long.
314 * The stack must start on page boundary.
315 */
316static inline uintptr_t get_stack_base(void)
317{
318 uintptr_t unbiased_sp;
319
320 asm volatile ("add %%sp, %1, %0\n" : "=r" (unbiased_sp) : "i" (STACK_BIAS));
321
322 return ALIGN_DOWN(unbiased_sp, STACK_SIZE);
323}
324
325/** Read Version Register.
326 *
327 * @return Value of VER register.
328 */
329static inline uint64_t ver_read(void)
330{
331 uint64_t v;
332
333 asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
334
335 return v;
336}
337
338/** Read Trap Program Counter register.
339 *
340 * @return Current value in TPC.
341 */
342static inline uint64_t tpc_read(void)
343{
344 uint64_t v;
345
346 asm volatile ("rdpr %%tpc, %0\n" : "=r" (v));
347
348 return v;
349}
350
351/** Read Trap Level register.
352 *
353 * @return Current value in TL.
354 */
355static inline uint64_t tl_read(void)
356{
357 uint64_t v;
358
359 asm volatile ("rdpr %%tl, %0\n" : "=r" (v));
360
361 return v;
362}
363
364/** Read Trap Base Address register.
365 *
366 * @return Current value in TBA.
367 */
368static inline uint64_t tba_read(void)
369{
370 uint64_t v;
371
372 asm volatile ("rdpr %%tba, %0\n" : "=r" (v));
373
374 return v;
375}
376
377/** Write Trap Base Address register.
378 *
379 * @param v New value of TBA.
380 */
381static inline void tba_write(uint64_t v)
382{
383 asm volatile ("wrpr %0, %1, %%tba\n" : : "r" (v), "i" (0));
384}
385
386/** Load uint64_t from alternate space.
387 *
388 * @param asi ASI determining the alternate space.
389 * @param va Virtual address within the ASI.
390 *
391 * @return Value read from the virtual address in the specified address space.
392 */
393static inline uint64_t asi_u64_read(asi_t asi, uintptr_t va)
394{
395 uint64_t v;
396
397 asm volatile ("ldxa [%1] %2, %0\n" : "=r" (v) : "r" (va), "i" ((unsigned) asi));
398
399 return v;
400}
401
402/** Store uint64_t to alternate space.
403 *
404 * @param asi ASI determining the alternate space.
405 * @param va Virtual address within the ASI.
406 * @param v Value to be written.
407 */
408static inline void asi_u64_write(asi_t asi, uintptr_t va, uint64_t v)
409{
410 asm volatile ("stxa %0, [%1] %2\n" : : "r" (v), "r" (va), "i" ((unsigned) asi) : "memory");
411}
412
413/** Flush all valid register windows to memory. */
414static inline void flushw(void)
415{
416 asm volatile ("flushw\n");
417}
418
419/** Switch to nucleus by setting TL to 1. */
420static inline void nucleus_enter(void)
421{
422 asm volatile ("wrpr %g0, 1, %tl\n");
423}
424
425/** Switch from nucleus by setting TL to 0. */
426static inline void nucleus_leave(void)
427{
428 asm volatile ("wrpr %g0, %g0, %tl\n");
429}
430
431extern void cpu_halt(void) __attribute__((noreturn));
432extern void cpu_sleep(void);
433extern void asm_delay_loop(const uint32_t usec);
434
435extern uint64_t read_from_ag_g7(void);
436extern void write_to_ag_g6(uint64_t val);
437extern void write_to_ag_g7(uint64_t val);
438extern void write_to_ig_g6(uint64_t val);
439
440extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
441
442#endif
443
444/** @}
445 */
Note: See TracBrowser for help on using the repository browser.