Rev 2787 | Rev 3597 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
173 | jermar | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2005 Jakub Jermar |
173 | 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 | |||
1888 | jermar | 29 | /** @addtogroup ia64 |
1702 | cejka | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
1888 | jermar | 35 | #ifndef KERN_ia64_ASM_H_ |
36 | #define KERN_ia64_ASM_H_ |
||
173 | jermar | 37 | |
747 | jermar | 38 | #include <config.h> |
173 | jermar | 39 | #include <arch/types.h> |
432 | jermar | 40 | #include <arch/register.h> |
173 | jermar | 41 | |
2515 | vana | 42 | |
2726 | vana | 43 | #define IA64_IOSPACE_ADDRESS 0xE001000000000000ULL |
2515 | vana | 44 | |
45 | static inline void outb(uint64_t port,uint8_t v) |
||
46 | { |
||
3536 | svoboda | 47 | *((uint8_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))) = v; |
2726 | vana | 48 | |
2515 | vana | 49 | asm volatile ("mf\n" ::: "memory"); |
50 | } |
||
51 | |||
3536 | svoboda | 52 | static inline void outw(uint64_t port,uint16_t v) |
53 | { |
||
54 | *((uint16_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))) = v; |
||
2515 | vana | 55 | |
3536 | svoboda | 56 | asm volatile ("mf\n" ::: "memory"); |
57 | } |
||
58 | |||
59 | static inline void outl(uint64_t port,uint32_t v) |
||
60 | { |
||
61 | *((uint32_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))) = v; |
||
62 | |||
63 | asm volatile ("mf\n" ::: "memory"); |
||
64 | } |
||
65 | |||
66 | |||
67 | |||
2515 | vana | 68 | static inline uint8_t inb(uint64_t port) |
69 | { |
||
70 | asm volatile ("mf\n" ::: "memory"); |
||
2726 | vana | 71 | |
3536 | svoboda | 72 | return *((uint8_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))); |
2515 | vana | 73 | } |
74 | |||
3536 | svoboda | 75 | static inline uint16_t inw(uint64_t port) |
76 | { |
||
77 | asm volatile ("mf\n" ::: "memory"); |
||
2515 | vana | 78 | |
3536 | svoboda | 79 | return *((uint16_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xffE) | ( (port >> 2) << 12 )))); |
80 | } |
||
2515 | vana | 81 | |
3536 | svoboda | 82 | static inline uint32_t inl(uint64_t port) |
83 | { |
||
84 | asm volatile ("mf\n" ::: "memory"); |
||
85 | |||
86 | return *((uint32_t *)(IA64_IOSPACE_ADDRESS + ( (port & 0xfff) | ( (port >> 2) << 12 )))); |
||
87 | } |
||
88 | |||
89 | |||
90 | |||
180 | jermar | 91 | /** Return base address of current stack |
92 | * |
||
93 | * Return the base address of the current stack. |
||
94 | * The stack is assumed to be STACK_SIZE long. |
||
95 | * The stack must start on page boundary. |
||
96 | */ |
||
1780 | jermar | 97 | static inline uintptr_t get_stack_base(void) |
173 | jermar | 98 | { |
1780 | jermar | 99 | uint64_t v; |
180 | jermar | 100 | |
2082 | decky | 101 | asm volatile ("and %0 = %1, r12" : "=r" (v) : "r" (~(STACK_SIZE-1))); |
180 | jermar | 102 | |
103 | return v; |
||
173 | jermar | 104 | } |
105 | |||
919 | jermar | 106 | /** Return Processor State Register. |
107 | * |
||
108 | * @return PSR. |
||
109 | */ |
||
1780 | jermar | 110 | static inline uint64_t psr_read(void) |
919 | jermar | 111 | { |
1780 | jermar | 112 | uint64_t v; |
919 | jermar | 113 | |
2082 | decky | 114 | asm volatile ("mov %0 = psr\n" : "=r" (v)); |
919 | jermar | 115 | |
116 | return v; |
||
117 | } |
||
118 | |||
470 | jermar | 119 | /** Read IVA (Interruption Vector Address). |
120 | * |
||
121 | * @return Return location of interruption vector table. |
||
122 | */ |
||
1780 | jermar | 123 | static inline uint64_t iva_read(void) |
470 | jermar | 124 | { |
1780 | jermar | 125 | uint64_t v; |
470 | jermar | 126 | |
2082 | decky | 127 | asm volatile ("mov %0 = cr.iva\n" : "=r" (v)); |
470 | jermar | 128 | |
129 | return v; |
||
130 | } |
||
131 | |||
132 | /** Write IVA (Interruption Vector Address) register. |
||
133 | * |
||
1708 | jermar | 134 | * @param v New location of interruption vector table. |
470 | jermar | 135 | */ |
1780 | jermar | 136 | static inline void iva_write(uint64_t v) |
470 | jermar | 137 | { |
2082 | decky | 138 | asm volatile ("mov cr.iva = %0\n" : : "r" (v)); |
470 | jermar | 139 | } |
140 | |||
141 | |||
432 | jermar | 142 | /** Read IVR (External Interrupt Vector Register). |
431 | jermar | 143 | * |
144 | * @return Highest priority, pending, unmasked external interrupt vector. |
||
145 | */ |
||
1780 | jermar | 146 | static inline uint64_t ivr_read(void) |
431 | jermar | 147 | { |
1780 | jermar | 148 | uint64_t v; |
431 | jermar | 149 | |
2082 | decky | 150 | asm volatile ("mov %0 = cr.ivr\n" : "=r" (v)); |
431 | jermar | 151 | |
432 | jermar | 152 | return v; |
431 | jermar | 153 | } |
195 | vana | 154 | |
432 | jermar | 155 | /** Write ITC (Interval Timer Counter) register. |
156 | * |
||
1708 | jermar | 157 | * @param v New counter value. |
432 | jermar | 158 | */ |
1780 | jermar | 159 | static inline void itc_write(uint64_t v) |
432 | jermar | 160 | { |
2082 | decky | 161 | asm volatile ("mov ar.itc = %0\n" : : "r" (v)); |
432 | jermar | 162 | } |
431 | jermar | 163 | |
432 | jermar | 164 | /** Read ITC (Interval Timer Counter) register. |
165 | * |
||
166 | * @return Current counter value. |
||
167 | */ |
||
1780 | jermar | 168 | static inline uint64_t itc_read(void) |
432 | jermar | 169 | { |
1780 | jermar | 170 | uint64_t v; |
432 | jermar | 171 | |
2082 | decky | 172 | asm volatile ("mov %0 = ar.itc\n" : "=r" (v)); |
432 | jermar | 173 | |
174 | return v; |
||
175 | } |
||
195 | vana | 176 | |
432 | jermar | 177 | /** Write ITM (Interval Timer Match) register. |
178 | * |
||
1708 | jermar | 179 | * @param v New match value. |
432 | jermar | 180 | */ |
1780 | jermar | 181 | static inline void itm_write(uint64_t v) |
432 | jermar | 182 | { |
2082 | decky | 183 | asm volatile ("mov cr.itm = %0\n" : : "r" (v)); |
432 | jermar | 184 | } |
195 | vana | 185 | |
1488 | vana | 186 | /** Read ITM (Interval Timer Match) register. |
187 | * |
||
188 | * @return Match value. |
||
189 | */ |
||
1780 | jermar | 190 | static inline uint64_t itm_read(void) |
1488 | vana | 191 | { |
1780 | jermar | 192 | uint64_t v; |
1488 | vana | 193 | |
2082 | decky | 194 | asm volatile ("mov %0 = cr.itm\n" : "=r" (v)); |
1488 | vana | 195 | |
196 | return v; |
||
197 | } |
||
198 | |||
433 | jermar | 199 | /** Read ITV (Interval Timer Vector) register. |
200 | * |
||
201 | * @return Current vector and mask bit. |
||
202 | */ |
||
1780 | jermar | 203 | static inline uint64_t itv_read(void) |
433 | jermar | 204 | { |
1780 | jermar | 205 | uint64_t v; |
433 | jermar | 206 | |
2082 | decky | 207 | asm volatile ("mov %0 = cr.itv\n" : "=r" (v)); |
433 | jermar | 208 | |
209 | return v; |
||
210 | } |
||
211 | |||
432 | jermar | 212 | /** Write ITV (Interval Timer Vector) register. |
213 | * |
||
1708 | jermar | 214 | * @param v New vector and mask bit. |
432 | jermar | 215 | */ |
1780 | jermar | 216 | static inline void itv_write(uint64_t v) |
432 | jermar | 217 | { |
2082 | decky | 218 | asm volatile ("mov cr.itv = %0\n" : : "r" (v)); |
432 | jermar | 219 | } |
238 | vana | 220 | |
432 | jermar | 221 | /** Write EOI (End Of Interrupt) register. |
222 | * |
||
1708 | jermar | 223 | * @param v This value is ignored. |
432 | jermar | 224 | */ |
1780 | jermar | 225 | static inline void eoi_write(uint64_t v) |
432 | jermar | 226 | { |
2082 | decky | 227 | asm volatile ("mov cr.eoi = %0\n" : : "r" (v)); |
432 | jermar | 228 | } |
229 | |||
230 | /** Read TPR (Task Priority Register). |
||
231 | * |
||
232 | * @return Current value of TPR. |
||
233 | */ |
||
1780 | jermar | 234 | static inline uint64_t tpr_read(void) |
432 | jermar | 235 | { |
1780 | jermar | 236 | uint64_t v; |
432 | jermar | 237 | |
2082 | decky | 238 | asm volatile ("mov %0 = cr.tpr\n" : "=r" (v)); |
432 | jermar | 239 | |
240 | return v; |
||
241 | } |
||
242 | |||
243 | /** Write TPR (Task Priority Register). |
||
244 | * |
||
1708 | jermar | 245 | * @param v New value of TPR. |
432 | jermar | 246 | */ |
1780 | jermar | 247 | static inline void tpr_write(uint64_t v) |
432 | jermar | 248 | { |
2082 | decky | 249 | asm volatile ("mov cr.tpr = %0\n" : : "r" (v)); |
432 | jermar | 250 | } |
251 | |||
252 | /** Disable interrupts. |
||
253 | * |
||
254 | * Disable interrupts and return previous |
||
255 | * value of PSR. |
||
256 | * |
||
257 | * @return Old interrupt priority level. |
||
258 | */ |
||
259 | static ipl_t interrupts_disable(void) |
||
260 | { |
||
1780 | jermar | 261 | uint64_t v; |
432 | jermar | 262 | |
2082 | decky | 263 | asm volatile ( |
432 | jermar | 264 | "mov %0 = psr\n" |
265 | "rsm %1\n" |
||
266 | : "=r" (v) |
||
267 | : "i" (PSR_I_MASK) |
||
268 | ); |
||
269 | |||
270 | return (ipl_t) v; |
||
271 | } |
||
272 | |||
273 | /** Enable interrupts. |
||
274 | * |
||
275 | * Enable interrupts and return previous |
||
276 | * value of PSR. |
||
277 | * |
||
278 | * @return Old interrupt priority level. |
||
279 | */ |
||
280 | static ipl_t interrupts_enable(void) |
||
281 | { |
||
1780 | jermar | 282 | uint64_t v; |
432 | jermar | 283 | |
2082 | decky | 284 | asm volatile ( |
432 | jermar | 285 | "mov %0 = psr\n" |
286 | "ssm %1\n" |
||
287 | ";;\n" |
||
288 | "srlz.d\n" |
||
289 | : "=r" (v) |
||
290 | : "i" (PSR_I_MASK) |
||
291 | ); |
||
292 | |||
293 | return (ipl_t) v; |
||
294 | } |
||
295 | |||
296 | /** Restore interrupt priority level. |
||
297 | * |
||
298 | * Restore PSR. |
||
299 | * |
||
300 | * @param ipl Saved interrupt priority level. |
||
301 | */ |
||
302 | static inline void interrupts_restore(ipl_t ipl) |
||
303 | { |
||
472 | jermar | 304 | if (ipl & PSR_I_MASK) |
305 | (void) interrupts_enable(); |
||
306 | else |
||
307 | (void) interrupts_disable(); |
||
432 | jermar | 308 | } |
309 | |||
310 | /** Return interrupt priority level. |
||
311 | * |
||
312 | * @return PSR. |
||
313 | */ |
||
314 | static inline ipl_t interrupts_read(void) |
||
315 | { |
||
919 | jermar | 316 | return (ipl_t) psr_read(); |
432 | jermar | 317 | } |
318 | |||
746 | jermar | 319 | /** Disable protection key checking. */ |
320 | static inline void pk_disable(void) |
||
321 | { |
||
2082 | decky | 322 | asm volatile ("rsm %0\n" : : "i" (PSR_PK_MASK)); |
746 | jermar | 323 | } |
324 | |||
432 | jermar | 325 | extern void cpu_halt(void); |
326 | extern void cpu_sleep(void); |
||
1780 | jermar | 327 | extern void asm_delay_loop(uint32_t t); |
238 | vana | 328 | |
1780 | jermar | 329 | extern void switch_to_userspace(uintptr_t entry, uintptr_t sp, uintptr_t bsp, uintptr_t uspace_uarg, uint64_t ipsr, uint64_t rsc); |
919 | jermar | 330 | |
173 | jermar | 331 | #endif |
1702 | cejka | 332 | |
1888 | jermar | 333 | /** @} |
1702 | cejka | 334 | */ |