source: mainline/kernel/arch/ia64/include/asm.h@ 1d2a1a9

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

Fix ia64 regression introduced in mainline,966.
The ia64 stack is actually two stacks in one:

  • the regular memory stack, which is now STACK_SIZE / 2 bytes long
  • and the equally sized RSE stack

Note that ia64 is now the only architecture which effectively uses
only one memory frame for its memory stack.

  • Property mode set to 100644
File size: 8.3 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 ia64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_ia64_ASM_H_
36#define KERN_ia64_ASM_H_
37
38#include <config.h>
39#include <typedefs.h>
40#include <typedefs.h>
41#include <arch/register.h>
42#include <trace.h>
43
44#define IA64_IOSPACE_ADDRESS 0xE001000000000000ULL
45
46NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
47{
48 uintptr_t prt = (uintptr_t) port;
49
50 *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
51 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
52
53 asm volatile (
54 "mf\n"
55 ::: "memory"
56 );
57}
58
59NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
60{
61 uintptr_t prt = (uintptr_t) port;
62
63 *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
64 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
65
66 asm volatile (
67 "mf\n"
68 ::: "memory"
69 );
70}
71
72NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
73{
74 uintptr_t prt = (uintptr_t) port;
75
76 *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
77 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
78
79 asm volatile (
80 "mf\n"
81 ::: "memory"
82 );
83}
84
85NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
86{
87 uintptr_t prt = (uintptr_t) port;
88
89 asm volatile (
90 "mf\n"
91 ::: "memory"
92 );
93
94 return *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
95 ((prt & 0xfff) | ((prt >> 2) << 12))));
96}
97
98NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
99{
100 uintptr_t prt = (uintptr_t) port;
101
102 asm volatile (
103 "mf\n"
104 ::: "memory"
105 );
106
107 return *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
108 ((prt & 0xfff) | ((prt >> 2) << 12))));
109}
110
111NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
112{
113 uintptr_t prt = (uintptr_t) port;
114
115 asm volatile (
116 "mf\n"
117 ::: "memory"
118 );
119
120 return *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
121 ((prt & 0xfff) | ((prt >> 2) << 12))));
122}
123
124/** Return base address of current memory stack.
125 *
126 * The memory stack is assumed to be STACK_SIZE / 2 long. Note that there is
127 * also the RSE stack, which takes up the upper half of STACK_SIZE.
128 * The memory stack must start on page boundary.
129 */
130NO_TRACE static inline uintptr_t get_stack_base(void)
131{
132 uint64_t value;
133
134 asm volatile (
135 "mov %[value] = r12"
136 : [value] "=r" (value)
137 );
138
139 return (value & (~(STACK_SIZE / 2 - 1)));
140}
141
142/** Return Processor State Register.
143 *
144 * @return PSR.
145 *
146 */
147NO_TRACE static inline uint64_t psr_read(void)
148{
149 uint64_t v;
150
151 asm volatile (
152 "mov %[value] = psr\n"
153 : [value] "=r" (v)
154 );
155
156 return v;
157}
158
159/** Read IVA (Interruption Vector Address).
160 *
161 * @return Return location of interruption vector table.
162 *
163 */
164NO_TRACE static inline uint64_t iva_read(void)
165{
166 uint64_t v;
167
168 asm volatile (
169 "mov %[value] = cr.iva\n"
170 : [value] "=r" (v)
171 );
172
173 return v;
174}
175
176/** Write IVA (Interruption Vector Address) register.
177 *
178 * @param v New location of interruption vector table.
179 *
180 */
181NO_TRACE static inline void iva_write(uint64_t v)
182{
183 asm volatile (
184 "mov cr.iva = %[value]\n"
185 :: [value] "r" (v)
186 );
187}
188
189/** Read IVR (External Interrupt Vector Register).
190 *
191 * @return Highest priority, pending, unmasked external
192 * interrupt vector.
193 *
194 */
195NO_TRACE static inline uint64_t ivr_read(void)
196{
197 uint64_t v;
198
199 asm volatile (
200 "mov %[value] = cr.ivr\n"
201 : [value] "=r" (v)
202 );
203
204 return v;
205}
206
207NO_TRACE static inline uint64_t cr64_read(void)
208{
209 uint64_t v;
210
211 asm volatile (
212 "mov %[value] = cr64\n"
213 : [value] "=r" (v)
214 );
215
216 return v;
217}
218
219/** Write ITC (Interval Timer Counter) register.
220 *
221 * @param v New counter value.
222 *
223 */
224NO_TRACE static inline void itc_write(uint64_t v)
225{
226 asm volatile (
227 "mov ar.itc = %[value]\n"
228 :: [value] "r" (v)
229 );
230}
231
232/** Read ITC (Interval Timer Counter) register.
233 *
234 * @return Current counter value.
235 *
236 */
237NO_TRACE static inline uint64_t itc_read(void)
238{
239 uint64_t v;
240
241 asm volatile (
242 "mov %[value] = ar.itc\n"
243 : [value] "=r" (v)
244 );
245
246 return v;
247}
248
249/** Write ITM (Interval Timer Match) register.
250 *
251 * @param v New match value.
252 *
253 */
254NO_TRACE static inline void itm_write(uint64_t v)
255{
256 asm volatile (
257 "mov cr.itm = %[value]\n"
258 :: [value] "r" (v)
259 );
260}
261
262/** Read ITM (Interval Timer Match) register.
263 *
264 * @return Match value.
265 *
266 */
267NO_TRACE static inline uint64_t itm_read(void)
268{
269 uint64_t v;
270
271 asm volatile (
272 "mov %[value] = cr.itm\n"
273 : [value] "=r" (v)
274 );
275
276 return v;
277}
278
279/** Read ITV (Interval Timer Vector) register.
280 *
281 * @return Current vector and mask bit.
282 *
283 */
284NO_TRACE static inline uint64_t itv_read(void)
285{
286 uint64_t v;
287
288 asm volatile (
289 "mov %[value] = cr.itv\n"
290 : [value] "=r" (v)
291 );
292
293 return v;
294}
295
296/** Write ITV (Interval Timer Vector) register.
297 *
298 * @param v New vector and mask bit.
299 *
300 */
301NO_TRACE static inline void itv_write(uint64_t v)
302{
303 asm volatile (
304 "mov cr.itv = %[value]\n"
305 :: [value] "r" (v)
306 );
307}
308
309/** Write EOI (End Of Interrupt) register.
310 *
311 * @param v This value is ignored.
312 *
313 */
314NO_TRACE static inline void eoi_write(uint64_t v)
315{
316 asm volatile (
317 "mov cr.eoi = %[value]\n"
318 :: [value] "r" (v)
319 );
320}
321
322/** Read TPR (Task Priority Register).
323 *
324 * @return Current value of TPR.
325 *
326 */
327NO_TRACE static inline uint64_t tpr_read(void)
328{
329 uint64_t v;
330
331 asm volatile (
332 "mov %[value] = cr.tpr\n"
333 : [value] "=r" (v)
334 );
335
336 return v;
337}
338
339/** Write TPR (Task Priority Register).
340 *
341 * @param v New value of TPR.
342 *
343 */
344NO_TRACE static inline void tpr_write(uint64_t v)
345{
346 asm volatile (
347 "mov cr.tpr = %[value]\n"
348 :: [value] "r" (v)
349 );
350}
351
352/** Disable interrupts.
353 *
354 * Disable interrupts and return previous
355 * value of PSR.
356 *
357 * @return Old interrupt priority level.
358 *
359 */
360NO_TRACE static ipl_t interrupts_disable(void)
361{
362 uint64_t v;
363
364 asm volatile (
365 "mov %[value] = psr\n"
366 "rsm %[mask]\n"
367 : [value] "=r" (v)
368 : [mask] "i" (PSR_I_MASK)
369 );
370
371 return (ipl_t) v;
372}
373
374/** Enable interrupts.
375 *
376 * Enable interrupts and return previous
377 * value of PSR.
378 *
379 * @return Old interrupt priority level.
380 *
381 */
382NO_TRACE static ipl_t interrupts_enable(void)
383{
384 uint64_t v;
385
386 asm volatile (
387 "mov %[value] = psr\n"
388 "ssm %[mask]\n"
389 ";;\n"
390 "srlz.d\n"
391 : [value] "=r" (v)
392 : [mask] "i" (PSR_I_MASK)
393 );
394
395 return (ipl_t) v;
396}
397
398/** Restore interrupt priority level.
399 *
400 * Restore PSR.
401 *
402 * @param ipl Saved interrupt priority level.
403 *
404 */
405NO_TRACE static inline void interrupts_restore(ipl_t ipl)
406{
407 if (ipl & PSR_I_MASK)
408 (void) interrupts_enable();
409 else
410 (void) interrupts_disable();
411}
412
413/** Return interrupt priority level.
414 *
415 * @return PSR.
416 *
417 */
418NO_TRACE static inline ipl_t interrupts_read(void)
419{
420 return (ipl_t) psr_read();
421}
422
423/** Check interrupts state.
424 *
425 * @return True if interrupts are disabled.
426 *
427 */
428NO_TRACE static inline bool interrupts_disabled(void)
429{
430 return !(psr_read() & PSR_I_MASK);
431}
432
433/** Disable protection key checking. */
434NO_TRACE static inline void pk_disable(void)
435{
436 asm volatile (
437 "rsm %[mask]\n"
438 ";;\n"
439 "srlz.d\n"
440 :: [mask] "i" (PSR_PK_MASK)
441 );
442}
443
444extern void cpu_halt(void) __attribute__((noreturn));
445extern void cpu_sleep(void);
446extern void asm_delay_loop(uint32_t t);
447
448extern void switch_to_userspace(uintptr_t, uintptr_t, uintptr_t, uintptr_t,
449 uint64_t, uint64_t);
450
451#endif
452
453/** @}
454 */
Note: See TracBrowser for help on using the repository browser.