source: mainline/kernel/arch/sparc64/include/asm.h@ 9a5b556

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9a5b556 was 9a5b556, checked in by Jakub Jermar <jakub@…>, 19 years ago

sparc64 work:

  • find a CPU node and read its clock_frequency attribute
  • implement asm_delay_loop()
  • set TICK_COMPARE register according to processor frequency
  • small improvements at random places

OpenFirmware work:

  • two new functions for walking the device tree

Generic boot loader work:

  • added basic string functions

Usual pile of indentation and formatting fixes.

  • Property mode set to 100644
File size: 7.7 KB
RevLine 
[2a99fa8]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
[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
[9a5b556]38#include <arch.h>
[75e1db0]39#include <typedefs.h>
[2a99fa8]40#include <arch/types.h>
[75e1db0]41#include <arch/register.h>
[2a99fa8]42#include <config.h>
[9a5b556]43#include <time/clock.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
53 __asm__ volatile ("rdpr %%pstate, %0\n" : "=r" (v));
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{
64 __asm__ volatile ("wrpr %0, %1, %%pstate\n" : : "r" (v), "i" (0));
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
75 __asm__ volatile ("rd %%tick_cmpr, %0\n" : "=r" (v));
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{
86 __asm__ volatile ("wr %0, %1, %%tick_cmpr\n" : : "r" (v), "i" (0));
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
97 __asm__ volatile ("rdpr %%tick, %0\n" : "=r" (v));
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{
108 __asm__ volatile ("wrpr %0, %1, %%tick\n" : : "r" (v), "i" (0));
109}
110
[39494010]111/** Read SOFTINT Register.
112 *
113 * @return Value of SOFTINT register.
114 */
[7f1c620]115static inline uint64_t softint_read(void)
[39494010]116{
[7f1c620]117 uint64_t v;
[39494010]118
119 __asm__ volatile ("rd %%softint, %0\n" : "=r" (v));
120
121 return v;
122}
123
124/** Write SOFTINT Register.
125 *
[abbc16e]126 * @param v New value of SOFTINT register.
[39494010]127 */
[7f1c620]128static inline void softint_write(uint64_t v)
[39494010]129{
130 __asm__ volatile ("wr %0, %1, %%softint\n" : : "r" (v), "i" (0));
131}
[75e1db0]132
[1120276]133/** Write CLEAR_SOFTINT Register.
134 *
135 * Bits set in CLEAR_SOFTINT register will be cleared in SOFTINT register.
136 *
[abbc16e]137 * @param v New value of CLEAR_SOFTINT register.
[1120276]138 */
[7f1c620]139static inline void clear_softint_write(uint64_t v)
[1120276]140{
141 __asm__ volatile ("wr %0, %1, %%clear_softint\n" : : "r" (v), "i" (0));
142}
143
[f9a56c0]144/** Write SET_SOFTINT Register.
145 *
146 * Bits set in SET_SOFTINT register will be set in SOFTINT register.
147 *
148 * @param v New value of SET_SOFTINT register.
149 */
150static inline void set_softint_write(uint64_t v)
151{
152 __asm__ volatile ("wr %0, %1, %%set_softint\n" : : "r" (v), "i" (0));
153}
154
[2a99fa8]155/** Enable interrupts.
156 *
157 * Enable interrupts and return previous
158 * value of IPL.
159 *
160 * @return Old interrupt priority level.
161 */
162static inline ipl_t interrupts_enable(void) {
[75e1db0]163 pstate_reg_t pstate;
[7f1c620]164 uint64_t value;
[75e1db0]165
166 value = pstate_read();
167 pstate.value = value;
168 pstate.ie = true;
169 pstate_write(pstate.value);
170
171 return (ipl_t) value;
[2a99fa8]172}
173
174/** Disable interrupts.
175 *
176 * Disable interrupts and return previous
177 * value of IPL.
178 *
179 * @return Old interrupt priority level.
180 */
181static inline ipl_t interrupts_disable(void) {
[75e1db0]182 pstate_reg_t pstate;
[7f1c620]183 uint64_t value;
[75e1db0]184
185 value = pstate_read();
186 pstate.value = value;
187 pstate.ie = false;
188 pstate_write(pstate.value);
189
190 return (ipl_t) value;
[2a99fa8]191}
192
193/** Restore interrupt priority level.
194 *
195 * Restore IPL.
196 *
197 * @param ipl Saved interrupt priority level.
198 */
199static inline void interrupts_restore(ipl_t ipl) {
[75e1db0]200 pstate_reg_t pstate;
201
202 pstate.value = pstate_read();
203 pstate.ie = ((pstate_reg_t) ipl).ie;
204 pstate_write(pstate.value);
[2a99fa8]205}
206
207/** Return interrupt priority level.
208 *
209 * Return IPL.
210 *
211 * @return Current interrupt priority level.
212 */
213static inline ipl_t interrupts_read(void) {
[75e1db0]214 return (ipl_t) pstate_read();
[2a99fa8]215}
216
217/** Return base address of current stack.
218 *
219 * Return the base address of the current stack.
220 * The stack is assumed to be STACK_SIZE bytes long.
221 * The stack must start on page boundary.
222 */
[7f1c620]223static inline uintptr_t get_stack_base(void)
[2a99fa8]224{
[7f1c620]225 uintptr_t v;
[437ee6a4]226
[7bb6b06]227 __asm__ volatile ("andn %%sp, %1, %0\n" : "=r" (v) : "r" (STACK_SIZE-1));
[437ee6a4]228
229 return v;
[2a99fa8]230}
231
[2cf87e50]232/** Read Version Register.
233 *
234 * @return Value of VER register.
235 */
[7f1c620]236static inline uint64_t ver_read(void)
[2cf87e50]237{
[7f1c620]238 uint64_t v;
[2cf87e50]239
240 __asm__ volatile ("rdpr %%ver, %0\n" : "=r" (v));
241
242 return v;
243}
244
[8ac5fe7]245/** Read Trap Base Address register.
246 *
247 * @return Current value in TBA.
248 */
[7f1c620]249static inline uint64_t tba_read(void)
[8ac5fe7]250{
[7f1c620]251 uint64_t v;
[8ac5fe7]252
253 __asm__ volatile ("rdpr %%tba, %0\n" : "=r" (v));
254
255 return v;
256}
257
[b6fba84]258/** Read Trap Program Counter register.
259 *
260 * @return Current value in TPC.
261 */
[7f1c620]262static inline uint64_t tpc_read(void)
[b6fba84]263{
[7f1c620]264 uint64_t v;
[b6fba84]265
266 __asm__ volatile ("rdpr %%tpc, %0\n" : "=r" (v));
267
268 return v;
269}
270
[7cb53f62]271/** Read Trap Level register.
272 *
273 * @return Current value in TL.
274 */
[7f1c620]275static inline uint64_t tl_read(void)
[7cb53f62]276{
[7f1c620]277 uint64_t v;
[7cb53f62]278
279 __asm__ volatile ("rdpr %%tl, %0\n" : "=r" (v));
280
281 return v;
282}
[b6fba84]283
[8ac5fe7]284/** Write Trap Base Address register.
285 *
[abbc16e]286 * @param v New value of TBA.
[8ac5fe7]287 */
[7f1c620]288static inline void tba_write(uint64_t v)
[8ac5fe7]289{
290 __asm__ volatile ("wrpr %0, %1, %%tba\n" : : "r" (v), "i" (0));
291}
292
[7f1c620]293/** Load uint64_t from alternate space.
[b00fdde]294 *
295 * @param asi ASI determining the alternate space.
296 * @param va Virtual address within the ASI.
297 *
298 * @return Value read from the virtual address in the specified address space.
299 */
[7f1c620]300static inline uint64_t asi_u64_read(asi_t asi, uintptr_t va)
[b00fdde]301{
[7f1c620]302 uint64_t v;
[b00fdde]303
304 __asm__ volatile ("ldxa [%1] %2, %0\n" : "=r" (v) : "r" (va), "i" (asi));
305
306 return v;
307}
308
[7f1c620]309/** Store uint64_t to alternate space.
[b00fdde]310 *
311 * @param asi ASI determining the alternate space.
312 * @param va Virtual address within the ASI.
313 * @param v Value to be written.
314 */
[7f1c620]315static inline void asi_u64_write(asi_t asi, uintptr_t va, uint64_t v)
[b00fdde]316{
[c52ed6b]317 __asm__ volatile ("stxa %0, [%1] %2\n" : : "r" (v), "r" (va), "i" (asi) : "memory");
[b00fdde]318}
319
[0fa6044]320/** Flush all valid register windows to memory. */
321static inline void flushw(void)
322{
323 __asm__ volatile ("flushw\n");
324}
325
[fd85ae5]326/** Switch to nucleus by setting TL to 1. */
327static inline void nucleus_enter(void)
328{
329 __asm__ volatile ("wrpr %g0, 1, %tl\n");
330}
331
332/** Switch from nucleus by setting TL to 0. */
333static inline void nucleus_leave(void)
334{
335 __asm__ volatile ("wrpr %g0, %g0, %tl\n");
336}
337
[e11ae91]338extern void cpu_halt(void);
339extern void cpu_sleep(void);
[9a5b556]340extern void asm_delay_loop(const uint32_t usec);
[e11ae91]341
342extern uint64_t read_from_ag_g7(void);
343extern void write_to_ag_g6(uint64_t val);
344extern void write_to_ag_g7(uint64_t val);
345extern void write_to_ig_g6(uint64_t val);
[2a99fa8]346
[cfa70add]347extern void switch_to_userspace(uint64_t pc, uint64_t sp, uint64_t uarg);
[ed166f7]348
[2a99fa8]349#endif
[b45c443]350
[0ffa3ef5]351/** @}
[b45c443]352 */
Note: See TracBrowser for help on using the repository browser.