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