source: mainline/kernel/arch/sparc64/include/arch/asm.h@ 8addb24a

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8addb24a was 8addb24a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Turn spin look hint into a function

  • Property mode set to 100644
File size: 10.0 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 kernel_sparc64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_sparc64_ASM_H_
36#define KERN_sparc64_ASM_H_
37
38#include <typedefs.h>
39#include <align.h>
40#include <arch/register.h>
41#include <config.h>
42#include <arch/stack.h>
43#include <barrier.h>
44#include <trace.h>
45
46_NO_TRACE static inline void cpu_spin_hint(void)
47{
48}
49
50_NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
51{
52 *port = v;
53 memory_barrier();
54}
55
56_NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
57{
58 *port = v;
59 memory_barrier();
60}
61
62_NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
63{
64 *port = v;
65 memory_barrier();
66}
67
68_NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
69{
70 uint8_t rv = *port;
71 memory_barrier();
72 return rv;
73}
74
75_NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
76{
77 uint16_t rv = *port;
78 memory_barrier();
79 return rv;
80}
81
82_NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
83{
84 uint32_t rv = *port;
85 memory_barrier();
86 return rv;
87}
88
89/** Read Processor State register.
90 *
91 * @return Value of PSTATE register.
92 *
93 */
94_NO_TRACE static inline uint64_t pstate_read(void)
95{
96 uint64_t v;
97
98 asm volatile (
99 "rdpr %%pstate, %[v]\n"
100 : [v] "=r" (v)
101 );
102
103 return v;
104}
105
106/** Write Processor State register.
107 *
108 * @param v New value of PSTATE register.
109 *
110 */
111_NO_TRACE static inline void pstate_write(uint64_t v)
112{
113 asm volatile (
114 "wrpr %[v], %[zero], %%pstate\n"
115 :: [v] "r" (v),
116 [zero] "i" (0)
117 );
118}
119
120/** Read TICK_compare Register.
121 *
122 * @return Value of TICK_comapre register.
123 *
124 */
125_NO_TRACE static inline uint64_t tick_compare_read(void)
126{
127 uint64_t v;
128
129 asm volatile (
130 "rd %%tick_cmpr, %[v]\n"
131 : [v] "=r" (v)
132 );
133
134 return v;
135}
136
137/** Write TICK_compare Register.
138 *
139 * @param v New value of TICK_comapre register.
140 *
141 */
142_NO_TRACE static inline void tick_compare_write(uint64_t v)
143{
144 asm volatile (
145 "wr %[v], %[zero], %%tick_cmpr\n"
146 :: [v] "r" (v),
147 [zero] "i" (0)
148 );
149}
150
151/** Read STICK_compare Register.
152 *
153 * @return Value of STICK_compare register.
154 *
155 */
156_NO_TRACE static inline uint64_t stick_compare_read(void)
157{
158 uint64_t v;
159
160 asm volatile (
161 "rd %%asr25, %[v]\n"
162 : [v] "=r" (v)
163 );
164
165 return v;
166}
167
168/** Write STICK_compare Register.
169 *
170 * @param v New value of STICK_comapre register.
171 *
172 */
173_NO_TRACE static inline void stick_compare_write(uint64_t v)
174{
175 asm volatile (
176 "wr %[v], %[zero], %%asr25\n"
177 :: [v] "r" (v),
178 [zero] "i" (0)
179 );
180}
181
182/** Read TICK Register.
183 *
184 * @return Value of TICK register.
185 *
186 */
187_NO_TRACE static inline uint64_t tick_read(void)
188{
189 uint64_t v;
190
191 asm volatile (
192 "rdpr %%tick, %[v]\n"
193 : [v] "=r" (v)
194 );
195
196 return v;
197}
198
199/** Write TICK Register.
200 *
201 * @param v New value of TICK register.
202 *
203 */
204_NO_TRACE static inline void tick_write(uint64_t v)
205{
206 asm volatile (
207 "wrpr %[v], %[zero], %%tick\n"
208 :: [v] "r" (v),
209 [zero] "i" (0)
210 );
211}
212
213/** Read FPRS Register.
214 *
215 * @return Value of FPRS register.
216 *
217 */
218_NO_TRACE static inline uint64_t fprs_read(void)
219{
220 uint64_t v;
221
222 asm volatile (
223 "rd %%fprs, %[v]\n"
224 : [v] "=r" (v)
225 );
226
227 return v;
228}
229
230/** Write FPRS Register.
231 *
232 * @param v New value of FPRS register.
233 *
234 */
235_NO_TRACE static inline void fprs_write(uint64_t v)
236{
237 asm volatile (
238 "wr %[v], %[zero], %%fprs\n"
239 :: [v] "r" (v),
240 [zero] "i" (0)
241 );
242}
243
244/** Read SOFTINT Register.
245 *
246 * @return Value of SOFTINT register.
247 *
248 */
249_NO_TRACE static inline uint64_t softint_read(void)
250{
251 uint64_t v;
252
253 asm volatile (
254 "rd %%softint, %[v]\n"
255 : [v] "=r" (v)
256 );
257
258 return v;
259}
260
261/** Write SOFTINT Register.
262 *
263 * @param v New value of SOFTINT register.
264 *
265 */
266_NO_TRACE static inline void softint_write(uint64_t v)
267{
268 asm volatile (
269 "wr %[v], %[zero], %%softint\n"
270 :: [v] "r" (v),
271 [zero] "i" (0)
272 );
273}
274
275/** Write CLEAR_SOFTINT Register.
276 *
277 * Bits set in CLEAR_SOFTINT register will be cleared in SOFTINT register.
278 *
279 * @param v New value of CLEAR_SOFTINT register.
280 *
281 */
282_NO_TRACE static inline void clear_softint_write(uint64_t v)
283{
284 asm volatile (
285 "wr %[v], %[zero], %%clear_softint\n"
286 :: [v] "r" (v),
287 [zero] "i" (0)
288 );
289}
290
291/** Write SET_SOFTINT Register.
292 *
293 * Bits set in SET_SOFTINT register will be set in SOFTINT register.
294 *
295 * @param v New value of SET_SOFTINT register.
296 *
297 */
298_NO_TRACE static inline void set_softint_write(uint64_t v)
299{
300 asm volatile (
301 "wr %[v], %[zero], %%set_softint\n"
302 :: [v] "r" (v),
303 [zero] "i" (0)
304 );
305}
306
307/** Enable interrupts.
308 *
309 * Enable interrupts and return previous
310 * value of IPL.
311 *
312 * @return Old interrupt priority level.
313 *
314 */
315_NO_TRACE static inline ipl_t interrupts_enable(void)
316{
317 pstate_reg_t pstate;
318 uint64_t value = pstate_read();
319
320 pstate.value = value;
321 pstate.ie = true;
322 pstate_write(pstate.value);
323
324 return (ipl_t) value;
325}
326
327/** Disable interrupts.
328 *
329 * Disable interrupts and return previous
330 * value of IPL.
331 *
332 * @return Old interrupt priority level.
333 *
334 */
335_NO_TRACE static inline ipl_t interrupts_disable(void)
336{
337 pstate_reg_t pstate;
338 uint64_t value = pstate_read();
339
340 pstate.value = value;
341 pstate.ie = false;
342 pstate_write(pstate.value);
343
344 return (ipl_t) value;
345}
346
347/** Restore interrupt priority level.
348 *
349 * Restore IPL.
350 *
351 * @param ipl Saved interrupt priority level.
352 *
353 */
354_NO_TRACE static inline void interrupts_restore(ipl_t ipl)
355{
356 pstate_reg_t pstate;
357
358 pstate.value = pstate_read();
359 pstate.ie = ((pstate_reg_t)(uint64_t) ipl).ie;
360 pstate_write(pstate.value);
361}
362
363/** Return interrupt priority level.
364 *
365 * Return IPL.
366 *
367 * @return Current interrupt priority level.
368 *
369 */
370_NO_TRACE static inline ipl_t interrupts_read(void)
371{
372 return (ipl_t) pstate_read();
373}
374
375/** Check interrupts state.
376 *
377 * @return True if interrupts are disabled.
378 *
379 */
380_NO_TRACE static inline bool interrupts_disabled(void)
381{
382 pstate_reg_t pstate;
383
384 pstate.value = pstate_read();
385 return !pstate.ie;
386}
387
388/** Read Version Register.
389 *
390 * @return Value of VER register.
391 *
392 */
393_NO_TRACE static inline uint64_t ver_read(void)
394{
395 uint64_t v;
396
397 asm volatile (
398 "rdpr %%ver, %[v]\n"
399 : [v] "=r" (v)
400 );
401
402 return v;
403}
404
405/** Read Trap Program Counter register.
406 *
407 * @return Current value in TPC.
408 *
409 */
410_NO_TRACE static inline uint64_t tpc_read(void)
411{
412 uint64_t v;
413
414 asm volatile (
415 "rdpr %%tpc, %[v]\n"
416 : [v] "=r" (v)
417 );
418
419 return v;
420}
421
422/** Read Trap Level register.
423 *
424 * @return Current value in TL.
425 *
426 */
427_NO_TRACE static inline uint64_t tl_read(void)
428{
429 uint64_t v;
430
431 asm volatile (
432 "rdpr %%tl, %[v]\n"
433 : [v] "=r" (v)
434 );
435
436 return v;
437}
438
439/** Read Trap Base Address register.
440 *
441 * @return Current value in TBA.
442 *
443 */
444_NO_TRACE static inline uint64_t tba_read(void)
445{
446 uint64_t v;
447
448 asm volatile (
449 "rdpr %%tba, %[v]\n"
450 : [v] "=r" (v)
451 );
452
453 return v;
454}
455
456/** Write Trap Base Address register.
457 *
458 * @param v New value of TBA.
459 *
460 */
461_NO_TRACE static inline void tba_write(uint64_t v)
462{
463 asm volatile (
464 "wrpr %[v], %[zero], %%tba\n"
465 :: [v] "r" (v),
466 [zero] "i" (0)
467 );
468}
469
470/** Load uint64_t from alternate space.
471 *
472 * @param asi ASI determining the alternate space.
473 * @param va Virtual address within the ASI.
474 *
475 * @return Value read from the virtual address in
476 * the specified address space.
477 *
478 */
479_NO_TRACE static inline uint64_t asi_u64_read(asi_t asi, uintptr_t va)
480{
481 uint64_t v;
482
483 asm volatile (
484 "ldxa [%[va]] %[asi], %[v]\n"
485 : [v] "=r" (v)
486 : [va] "r" (va),
487 [asi] "i" ((unsigned int) asi)
488 );
489
490 return v;
491}
492
493/** Store uint64_t to alternate space.
494 *
495 * @param asi ASI determining the alternate space.
496 * @param va Virtual address within the ASI.
497 * @param v Value to be written.
498 *
499 */
500_NO_TRACE static inline void asi_u64_write(asi_t asi, uintptr_t va, uint64_t v)
501{
502 asm volatile (
503 "stxa %[v], [%[va]] %[asi]\n"
504 :: [v] "r" (v),
505 [va] "r" (va),
506 [asi] "i" ((unsigned int) asi)
507 : "memory"
508 );
509}
510
511/** Flush all valid register windows to memory. */
512_NO_TRACE static inline void flushw(void)
513{
514 asm volatile ("flushw\n");
515}
516
517/** Switch to nucleus by setting TL to 1. */
518_NO_TRACE static inline void nucleus_enter(void)
519{
520 asm volatile ("wrpr %g0, 1, %tl\n");
521}
522
523/** Switch from nucleus by setting TL to 0. */
524_NO_TRACE static inline void nucleus_leave(void)
525{
526 asm volatile ("wrpr %g0, %g0, %tl\n");
527}
528
529extern void cpu_halt(void) __attribute__((noreturn));
530extern void cpu_sleep(void);
531extern void asm_delay_loop(const uint32_t usec);
532
533extern uint64_t read_from_ag_g6(void);
534extern uint64_t read_from_ag_g7(void);
535extern void write_to_ag_g6(uint64_t val);
536extern void write_to_ag_g7(uint64_t val);
537extern void write_to_ig_g6(uint64_t val);
538
539extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
540
541#endif
542
543/** @}
544 */
Note: See TracBrowser for help on using the repository browser.