source: mainline/kernel/arch/sparc64/include/asm.h@ 7cb567cd

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

huge type system cleanup
remove cyclical type dependencies across multiple header files
many minor coding style fixes

  • Property mode set to 100644
File size: 8.2 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>
[2a99fa8]39#include <arch/types.h>
[b3f8fb7]40#include <align.h>
[75e1db0]41#include <arch/register.h>
[2a99fa8]42#include <config.h>
[b254b3b]43#include <arch/stack.h>
[2a99fa8]44
[75e1db0]45/** Read Processor State register.
46 *
47 * @return Value of PSTATE register.
48 */
[7f1c620]49static inline uint64_t pstate_read(void)
[75e1db0]50{
[7f1c620]51 uint64_t v;
[75e1db0]52
[e7b7be3f]53 asm volatile ("rdpr %%pstate, %0\n" : "=r" (v));
[75e1db0]54
55 return v;
56}
57
58/** Write Processor State register.
59 *
[abbc16e]60 * @param v New value of PSTATE register.
[75e1db0]61 */
[7f1c620]62static inline void pstate_write(uint64_t v)
[75e1db0]63{
[e7b7be3f]64 asm volatile ("wrpr %0, %1, %%pstate\n" : : "r" (v), "i" (0));
[75e1db0]65}
66
[096d11e5]67/** Read TICK_compare Register.
68 *
69 * @return Value of TICK_comapre register.
70 */
[7f1c620]71static inline uint64_t tick_compare_read(void)
[096d11e5]72{
[7f1c620]73 uint64_t v;
[096d11e5]74
[e7b7be3f]75 asm volatile ("rd %%tick_cmpr, %0\n" : "=r" (v));
[096d11e5]76
77 return v;
78}
79
80/** Write TICK_compare Register.
81 *
[abbc16e]82 * @param v New value of TICK_comapre register.
[096d11e5]83 */
[7f1c620]84static inline void tick_compare_write(uint64_t v)
[096d11e5]85{
[e7b7be3f]86 asm volatile ("wr %0, %1, %%tick_cmpr\n" : : "r" (v), "i" (0));
[096d11e5]87}
88
89/** Read TICK Register.
90 *
91 * @return Value of TICK register.
92 */
[7f1c620]93static inline uint64_t tick_read(void)
[096d11e5]94{
[7f1c620]95 uint64_t v;
[096d11e5]96
[e7b7be3f]97 asm volatile ("rdpr %%tick, %0\n" : "=r" (v));
[096d11e5]98
99 return v;
100}
101
102/** Write TICK Register.
103 *
[abbc16e]104 * @param v New value of TICK register.
[096d11e5]105 */
[7f1c620]106static inline void tick_write(uint64_t v)
[096d11e5]107{
[e7b7be3f]108 asm volatile ("wrpr %0, %1, %%tick\n" : : "r" (v), "i" (0));
[096d11e5]109}
110
[6eabb6e6]111/** Read FPRS Register.
112 *
113 * @return Value of FPRS register.
114 */
115static inline uint64_t fprs_read(void)
116{
117 uint64_t v;
118
[e7b7be3f]119 asm volatile ("rd %%fprs, %0\n" : "=r" (v));
[6eabb6e6]120
121 return v;
122}
123
124/** Write FPRS Register.
125 *
126 * @param v New value of FPRS register.
127 */
128static inline void fprs_write(uint64_t v)
129{
[e7b7be3f]130 asm volatile ("wr %0, %1, %%fprs\n" : : "r" (v), "i" (0));
[6eabb6e6]131}
132
[39494010]133/** Read SOFTINT Register.
134 *
135 * @return Value of SOFTINT register.
136 */
[7f1c620]137static inline uint64_t softint_read(void)
[39494010]138{
[7f1c620]139 uint64_t v;
[39494010]140
[e7b7be3f]141 asm volatile ("rd %%softint, %0\n" : "=r" (v));
[39494010]142
143 return v;
144}
145
146/** Write SOFTINT Register.
147 *
[abbc16e]148 * @param v New value of SOFTINT register.
[39494010]149 */
[7f1c620]150static inline void softint_write(uint64_t v)
[39494010]151{
[e7b7be3f]152 asm volatile ("wr %0, %1, %%softint\n" : : "r" (v), "i" (0));
[39494010]153}
[75e1db0]154
[1120276]155/** Write CLEAR_SOFTINT Register.
156 *
157 * Bits set in CLEAR_SOFTINT register will be cleared in SOFTINT register.
158 *
[abbc16e]159 * @param v New value of CLEAR_SOFTINT register.
[1120276]160 */
[7f1c620]161static inline void clear_softint_write(uint64_t v)
[1120276]162{
[e7b7be3f]163 asm volatile ("wr %0, %1, %%clear_softint\n" : : "r" (v), "i" (0));
[1120276]164}
165
[f9a56c0]166/** Write SET_SOFTINT Register.
167 *
168 * Bits set in SET_SOFTINT register will be set in SOFTINT register.
169 *
170 * @param v New value of SET_SOFTINT register.
171 */
172static inline void set_softint_write(uint64_t v)
173{
[e7b7be3f]174 asm volatile ("wr %0, %1, %%set_softint\n" : : "r" (v), "i" (0));
[f9a56c0]175}
176
[2a99fa8]177/** Enable interrupts.
178 *
179 * Enable interrupts and return previous
180 * value of IPL.
181 *
182 * @return Old interrupt priority level.
183 */
184static inline ipl_t interrupts_enable(void) {
[75e1db0]185 pstate_reg_t pstate;
[7f1c620]186 uint64_t value;
[75e1db0]187
188 value = pstate_read();
189 pstate.value = value;
190 pstate.ie = true;
191 pstate_write(pstate.value);
192
193 return (ipl_t) value;
[2a99fa8]194}
195
196/** Disable interrupts.
197 *
198 * Disable interrupts and return previous
199 * value of IPL.
200 *
201 * @return Old interrupt priority level.
202 */
203static inline ipl_t interrupts_disable(void) {
[75e1db0]204 pstate_reg_t pstate;
[7f1c620]205 uint64_t value;
[75e1db0]206
207 value = pstate_read();
208 pstate.value = value;
209 pstate.ie = false;
210 pstate_write(pstate.value);
211
212 return (ipl_t) value;
[2a99fa8]213}
214
215/** Restore interrupt priority level.
216 *
217 * Restore IPL.
218 *
219 * @param ipl Saved interrupt priority level.
220 */
221static inline void interrupts_restore(ipl_t ipl) {
[75e1db0]222 pstate_reg_t pstate;
223
224 pstate.value = pstate_read();
225 pstate.ie = ((pstate_reg_t) ipl).ie;
226 pstate_write(pstate.value);
[2a99fa8]227}
228
229/** Return interrupt priority level.
230 *
231 * Return IPL.
232 *
233 * @return Current interrupt priority level.
234 */
235static inline ipl_t interrupts_read(void) {
[75e1db0]236 return (ipl_t) pstate_read();
[2a99fa8]237}
238
239/** Return base address of current stack.
240 *
241 * Return the base address of the current stack.
242 * The stack is assumed to be STACK_SIZE bytes long.
243 * The stack must start on page boundary.
244 */
[7f1c620]245static inline uintptr_t get_stack_base(void)
[2a99fa8]246{
[b254b3b]247 uintptr_t unbiased_sp;
[437ee6a4]248
[e7b7be3f]249 asm volatile ("add %%sp, %1, %0\n" : "=r" (unbiased_sp) : "i" (STACK_BIAS));
[437ee6a4]250
[b254b3b]251 return ALIGN_DOWN(unbiased_sp, STACK_SIZE);
[2a99fa8]252}
253
[2cf87e50]254/** Read Version Register.
255 *
256 * @return Value of VER register.
257 */
[7f1c620]258static inline uint64_t ver_read(void)
[2cf87e50]259{
[7f1c620]260 uint64_t v;
[2cf87e50]261
[e7b7be3f]262 asm volatile ("rdpr %%ver, %0\n" : "=r" (v));
[2cf87e50]263
264 return v;
265}
266
[d78d603]267/** Read Trap Program Counter register.
[8ac5fe7]268 *
[d78d603]269 * @return Current value in TPC.
[8ac5fe7]270 */
[d78d603]271static inline uint64_t tpc_read(void)
[8ac5fe7]272{
[7f1c620]273 uint64_t v;
[8ac5fe7]274
[e7b7be3f]275 asm volatile ("rdpr %%tpc, %0\n" : "=r" (v));
[8ac5fe7]276
277 return v;
278}
279
[d78d603]280/** Read Trap Level register.
[b6fba84]281 *
[d78d603]282 * @return Current value in TL.
[b6fba84]283 */
[d78d603]284static inline uint64_t tl_read(void)
[b6fba84]285{
[7f1c620]286 uint64_t v;
[b6fba84]287
[e7b7be3f]288 asm volatile ("rdpr %%tl, %0\n" : "=r" (v));
[b6fba84]289
290 return v;
291}
292
[d78d603]293/** Read Trap Base Address register.
[7cb53f62]294 *
[d78d603]295 * @return Current value in TBA.
[7cb53f62]296 */
[d78d603]297static inline uint64_t tba_read(void)
[7cb53f62]298{
[7f1c620]299 uint64_t v;
[7cb53f62]300
[e7b7be3f]301 asm volatile ("rdpr %%tba, %0\n" : "=r" (v));
[7cb53f62]302
303 return v;
304}
[b6fba84]305
[8ac5fe7]306/** Write Trap Base Address register.
307 *
[abbc16e]308 * @param v New value of TBA.
[8ac5fe7]309 */
[7f1c620]310static inline void tba_write(uint64_t v)
[8ac5fe7]311{
[e7b7be3f]312 asm volatile ("wrpr %0, %1, %%tba\n" : : "r" (v), "i" (0));
[8ac5fe7]313}
314
[7f1c620]315/** Load uint64_t from alternate space.
[b00fdde]316 *
317 * @param asi ASI determining the alternate space.
318 * @param va Virtual address within the ASI.
319 *
320 * @return Value read from the virtual address in the specified address space.
321 */
[7f1c620]322static inline uint64_t asi_u64_read(asi_t asi, uintptr_t va)
[b00fdde]323{
[7f1c620]324 uint64_t v;
[b00fdde]325
[e7b7be3f]326 asm volatile ("ldxa [%1] %2, %0\n" : "=r" (v) : "r" (va), "i" ((unsigned) asi));
[b00fdde]327
328 return v;
329}
330
[7f1c620]331/** Store uint64_t to alternate space.
[b00fdde]332 *
333 * @param asi ASI determining the alternate space.
334 * @param va Virtual address within the ASI.
335 * @param v Value to be written.
336 */
[7f1c620]337static inline void asi_u64_write(asi_t asi, uintptr_t va, uint64_t v)
[b00fdde]338{
[e7b7be3f]339 asm volatile ("stxa %0, [%1] %2\n" : : "r" (v), "r" (va), "i" ((unsigned) asi) : "memory");
[b00fdde]340}
341
[0fa6044]342/** Flush all valid register windows to memory. */
343static inline void flushw(void)
344{
[e7b7be3f]345 asm volatile ("flushw\n");
[0fa6044]346}
347
[fd85ae5]348/** Switch to nucleus by setting TL to 1. */
349static inline void nucleus_enter(void)
350{
[e7b7be3f]351 asm volatile ("wrpr %g0, 1, %tl\n");
[fd85ae5]352}
353
354/** Switch from nucleus by setting TL to 0. */
355static inline void nucleus_leave(void)
356{
[e7b7be3f]357 asm volatile ("wrpr %g0, %g0, %tl\n");
[fd85ae5]358}
359
[45b26dad]360/** Read UPA_CONFIG register.
361 *
362 * @return Value of the UPA_CONFIG register.
363 */
364static inline uint64_t upa_config_read(void)
365{
366 return asi_u64_read(ASI_UPA_CONFIG, 0);
367}
368
[e11ae91]369extern void cpu_halt(void);
370extern void cpu_sleep(void);
[9a5b556]371extern void asm_delay_loop(const uint32_t usec);
[e11ae91]372
373extern uint64_t read_from_ag_g7(void);
374extern void write_to_ag_g6(uint64_t val);
375extern void write_to_ag_g7(uint64_t val);
376extern void write_to_ig_g6(uint64_t val);
[2a99fa8]377
[cfa70add]378extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
[ed166f7]379
[2a99fa8]380#endif
[b45c443]381
[0ffa3ef5]382/** @}
[b45c443]383 */
Note: See TracBrowser for help on using the repository browser.