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
RevLine 
[2a99fa8]1/*
[df4ed85]2 * Copyright (c) 2005 Jakub Jermar
[2a99fa8]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
[0ffa3ef5]29/** @addtogroup sparc64
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[0ffa3ef5]35#ifndef KERN_sparc64_ASM_H_
36#define KERN_sparc64_ASM_H_
[2a99fa8]37
[b3f8fb7]38#include <arch/arch.h>
[f4c2b6a]39#include <typedefs.h>
[b3f8fb7]40#include <align.h>
[75e1db0]41#include <arch/register.h>
[2a99fa8]42#include <config.h>
[b254b3b]43#include <arch/stack.h>
[ff3b7da7]44#include <arch/barrier.h>
[2a99fa8]45
[7d60cf5]46static inline void pio_write_8(ioport8_t *port, uint8_t v)
[a2a5529]47{
[7d60cf5]48 *port = v;
[ff3b7da7]49 memory_barrier();
[a2a5529]50}
51
[7d60cf5]52static inline void pio_write_16(ioport16_t *port, uint16_t v)
[a2a5529]53{
[7d60cf5]54 *port = v;
[ff3b7da7]55 memory_barrier();
[a2a5529]56}
57
[7d60cf5]58static inline void pio_write_32(ioport32_t *port, uint32_t v)
[a2a5529]59{
[7d60cf5]60 *port = v;
[ff3b7da7]61 memory_barrier();
[a2a5529]62}
63
[7d60cf5]64static inline uint8_t pio_read_8(ioport8_t *port)
[a2a5529]65{
[ff3b7da7]66 uint8_t rv;
67
[7d60cf5]68 rv = *port;
[ff3b7da7]69 memory_barrier();
70
71 return rv;
[a2a5529]72}
73
[7d60cf5]74static inline uint16_t pio_read_16(ioport16_t *port)
[a2a5529]75{
[ff3b7da7]76 uint16_t rv;
77
[7d60cf5]78 rv = *port;
[ff3b7da7]79 memory_barrier();
80
81 return rv;
[a2a5529]82}
83
[7d60cf5]84static inline uint32_t pio_read_32(ioport32_t *port)
[a2a5529]85{
[ff3b7da7]86 uint32_t rv;
[a2a5529]87
[7d60cf5]88 rv = *port;
[ff3b7da7]89 memory_barrier();
[a2a5529]90
[ff3b7da7]91 return rv;
92}
[a2a5529]93
[75e1db0]94/** Read Processor State register.
95 *
96 * @return Value of PSTATE register.
97 */
[7f1c620]98static inline uint64_t pstate_read(void)
[75e1db0]99{
[7f1c620]100 uint64_t v;
[75e1db0]101
[e7b7be3f]102 asm volatile ("rdpr %%pstate, %0\n" : "=r" (v));
[75e1db0]103
104 return v;
105}
106
107/** Write Processor State register.
108 *
[abbc16e]109 * @param v New value of PSTATE register.
[75e1db0]110 */
[7f1c620]111static inline void pstate_write(uint64_t v)
[75e1db0]112{
[e7b7be3f]113 asm volatile ("wrpr %0, %1, %%pstate\n" : : "r" (v), "i" (0));
[75e1db0]114}
115
[096d11e5]116/** Read TICK_compare Register.
117 *
118 * @return Value of TICK_comapre register.
119 */
[7f1c620]120static inline uint64_t tick_compare_read(void)
[096d11e5]121{
[7f1c620]122 uint64_t v;
[096d11e5]123
[e7b7be3f]124 asm volatile ("rd %%tick_cmpr, %0\n" : "=r" (v));
[096d11e5]125
126 return v;
127}
128
129/** Write TICK_compare Register.
130 *
[abbc16e]131 * @param v New value of TICK_comapre register.
[096d11e5]132 */
[7f1c620]133static inline void tick_compare_write(uint64_t v)
[096d11e5]134{
[e7b7be3f]135 asm volatile ("wr %0, %1, %%tick_cmpr\n" : : "r" (v), "i" (0));
[096d11e5]136}
137
[965dc18]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
[096d11e5]160/** Read TICK Register.
161 *
162 * @return Value of TICK register.
163 */
[7f1c620]164static inline uint64_t tick_read(void)
[096d11e5]165{
[7f1c620]166 uint64_t v;
[096d11e5]167
[e7b7be3f]168 asm volatile ("rdpr %%tick, %0\n" : "=r" (v));
[096d11e5]169
170 return v;
171}
172
173/** Write TICK Register.
174 *
[abbc16e]175 * @param v New value of TICK register.
[096d11e5]176 */
[7f1c620]177static inline void tick_write(uint64_t v)
[096d11e5]178{
[e7b7be3f]179 asm volatile ("wrpr %0, %1, %%tick\n" : : "r" (v), "i" (0));
[096d11e5]180}
181
[6eabb6e6]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
[e7b7be3f]190 asm volatile ("rd %%fprs, %0\n" : "=r" (v));
[6eabb6e6]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{
[e7b7be3f]201 asm volatile ("wr %0, %1, %%fprs\n" : : "r" (v), "i" (0));
[6eabb6e6]202}
203
[39494010]204/** Read SOFTINT Register.
205 *
206 * @return Value of SOFTINT register.
207 */
[7f1c620]208static inline uint64_t softint_read(void)
[39494010]209{
[7f1c620]210 uint64_t v;
[39494010]211
[e7b7be3f]212 asm volatile ("rd %%softint, %0\n" : "=r" (v));
[39494010]213
214 return v;
215}
216
217/** Write SOFTINT Register.
218 *
[abbc16e]219 * @param v New value of SOFTINT register.
[39494010]220 */
[7f1c620]221static inline void softint_write(uint64_t v)
[39494010]222{
[e7b7be3f]223 asm volatile ("wr %0, %1, %%softint\n" : : "r" (v), "i" (0));
[39494010]224}
[75e1db0]225
[1120276]226/** Write CLEAR_SOFTINT Register.
227 *
228 * Bits set in CLEAR_SOFTINT register will be cleared in SOFTINT register.
229 *
[abbc16e]230 * @param v New value of CLEAR_SOFTINT register.
[1120276]231 */
[7f1c620]232static inline void clear_softint_write(uint64_t v)
[1120276]233{
[e7b7be3f]234 asm volatile ("wr %0, %1, %%clear_softint\n" : : "r" (v), "i" (0));
[1120276]235}
236
[f9a56c0]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{
[e7b7be3f]245 asm volatile ("wr %0, %1, %%set_softint\n" : : "r" (v), "i" (0));
[f9a56c0]246}
247
[2a99fa8]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) {
[75e1db0]256 pstate_reg_t pstate;
[7f1c620]257 uint64_t value;
[75e1db0]258
259 value = pstate_read();
260 pstate.value = value;
261 pstate.ie = true;
262 pstate_write(pstate.value);
263
264 return (ipl_t) value;
[2a99fa8]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) {
[75e1db0]275 pstate_reg_t pstate;
[7f1c620]276 uint64_t value;
[75e1db0]277
278 value = pstate_read();
279 pstate.value = value;
280 pstate.ie = false;
281 pstate_write(pstate.value);
282
283 return (ipl_t) value;
[2a99fa8]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) {
[75e1db0]293 pstate_reg_t pstate;
294
295 pstate.value = pstate_read();
296 pstate.ie = ((pstate_reg_t) ipl).ie;
297 pstate_write(pstate.value);
[2a99fa8]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) {
[75e1db0]307 return (ipl_t) pstate_read();
[2a99fa8]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 */
[7f1c620]316static inline uintptr_t get_stack_base(void)
[2a99fa8]317{
[b254b3b]318 uintptr_t unbiased_sp;
[437ee6a4]319
[e7b7be3f]320 asm volatile ("add %%sp, %1, %0\n" : "=r" (unbiased_sp) : "i" (STACK_BIAS));
[437ee6a4]321
[b254b3b]322 return ALIGN_DOWN(unbiased_sp, STACK_SIZE);
[2a99fa8]323}
324
[2cf87e50]325/** Read Version Register.
326 *
327 * @return Value of VER register.
328 */
[7f1c620]329static inline uint64_t ver_read(void)
[2cf87e50]330{
[7f1c620]331 uint64_t v;
[2cf87e50]332
[e7b7be3f]333 asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
[2cf87e50]334
335 return v;
336}
337
[d78d603]338/** Read Trap Program Counter register.
[8ac5fe7]339 *
[d78d603]340 * @return Current value in TPC.
[8ac5fe7]341 */
[d78d603]342static inline uint64_t tpc_read(void)
[8ac5fe7]343{
[7f1c620]344 uint64_t v;
[8ac5fe7]345
[e7b7be3f]346 asm volatile ("rdpr %%tpc, %0\n" : "=r" (v));
[8ac5fe7]347
348 return v;
349}
350
[d78d603]351/** Read Trap Level register.
[b6fba84]352 *
[d78d603]353 * @return Current value in TL.
[b6fba84]354 */
[d78d603]355static inline uint64_t tl_read(void)
[b6fba84]356{
[7f1c620]357 uint64_t v;
[b6fba84]358
[e7b7be3f]359 asm volatile ("rdpr %%tl, %0\n" : "=r" (v));
[b6fba84]360
361 return v;
362}
363
[d78d603]364/** Read Trap Base Address register.
[7cb53f62]365 *
[d78d603]366 * @return Current value in TBA.
[7cb53f62]367 */
[d78d603]368static inline uint64_t tba_read(void)
[7cb53f62]369{
[7f1c620]370 uint64_t v;
[7cb53f62]371
[e7b7be3f]372 asm volatile ("rdpr %%tba, %0\n" : "=r" (v));
[7cb53f62]373
374 return v;
375}
[b6fba84]376
[8ac5fe7]377/** Write Trap Base Address register.
378 *
[abbc16e]379 * @param v New value of TBA.
[8ac5fe7]380 */
[7f1c620]381static inline void tba_write(uint64_t v)
[8ac5fe7]382{
[e7b7be3f]383 asm volatile ("wrpr %0, %1, %%tba\n" : : "r" (v), "i" (0));
[8ac5fe7]384}
385
[7f1c620]386/** Load uint64_t from alternate space.
[b00fdde]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 */
[7f1c620]393static inline uint64_t asi_u64_read(asi_t asi, uintptr_t va)
[b00fdde]394{
[7f1c620]395 uint64_t v;
[b00fdde]396
[e7b7be3f]397 asm volatile ("ldxa [%1] %2, %0\n" : "=r" (v) : "r" (va), "i" ((unsigned) asi));
[b00fdde]398
399 return v;
400}
401
[7f1c620]402/** Store uint64_t to alternate space.
[b00fdde]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 */
[7f1c620]408static inline void asi_u64_write(asi_t asi, uintptr_t va, uint64_t v)
[b00fdde]409{
[e7b7be3f]410 asm volatile ("stxa %0, [%1] %2\n" : : "r" (v), "r" (va), "i" ((unsigned) asi) : "memory");
[b00fdde]411}
412
[0fa6044]413/** Flush all valid register windows to memory. */
414static inline void flushw(void)
415{
[e7b7be3f]416 asm volatile ("flushw\n");
[0fa6044]417}
418
[fd85ae5]419/** Switch to nucleus by setting TL to 1. */
420static inline void nucleus_enter(void)
421{
[e7b7be3f]422 asm volatile ("wrpr %g0, 1, %tl\n");
[fd85ae5]423}
424
425/** Switch from nucleus by setting TL to 0. */
426static inline void nucleus_leave(void)
427{
[e7b7be3f]428 asm volatile ("wrpr %g0, %g0, %tl\n");
[fd85ae5]429}
430
[82474ef]431extern void cpu_halt(void) __attribute__((noreturn));
[e11ae91]432extern void cpu_sleep(void);
[9a5b556]433extern void asm_delay_loop(const uint32_t usec);
[e11ae91]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);
[2a99fa8]439
[cfa70add]440extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
[ed166f7]441
[2a99fa8]442#endif
[b45c443]443
[0ffa3ef5]444/** @}
[b45c443]445 */
Note: See TracBrowser for help on using the repository browser.