source: mainline/kernel/arch/ia64/include/arch/asm.h@ 128359eb

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

Replace get_stack_base() with builtin_frame_address(0)

The usage of an intrinsic function to obtain the current stack pointer
should provide the compuler more room for performance optimizations than
the hand-written (and volatile) inline assembly block.

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