[acc25ee] | 1 | |
---|
| 2 | /* cpu_asm.s 1.1 - 95/12/04 |
---|
| 3 | * |
---|
| 4 | * This file contains the assembly code for the PowerPC implementation |
---|
| 5 | * of RTEMS. |
---|
| 6 | * |
---|
| 7 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
| 8 | * |
---|
| 9 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
| 10 | * |
---|
| 11 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 12 | * without any express or implied warranty: |
---|
| 13 | * permission to use, copy, modify, and distribute this file |
---|
| 14 | * for any purpose is hereby granted without fee, provided that |
---|
| 15 | * the above copyright notice and this notice appears in all |
---|
| 16 | * copies, and that the name of i-cubed limited not be used in |
---|
| 17 | * advertising or publicity pertaining to distribution of the |
---|
| 18 | * software without specific, written prior permission. |
---|
| 19 | * i-cubed limited makes no representations about the suitability |
---|
| 20 | * of this software for any purpose. |
---|
| 21 | * |
---|
| 22 | * Derived from c/src/exec/cpu/no_cpu/cpu_asm.c: |
---|
| 23 | * |
---|
| 24 | * COPYRIGHT (c) 1989-1997. |
---|
| 25 | * On-Line Applications Research Corporation (OAR). |
---|
| 26 | * |
---|
| 27 | * The license and distribution terms for this file may in |
---|
| 28 | * the file LICENSE in this distribution or at |
---|
| 29 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 30 | * |
---|
| 31 | * $Id$ |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include <asm.h> |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * Offsets for various Contexts |
---|
| 38 | */ |
---|
| 39 | .set GP_1, 0 |
---|
| 40 | .set GP_2, (GP_1 + 4) |
---|
| 41 | .set GP_13, (GP_2 + 4) |
---|
| 42 | .set GP_14, (GP_13 + 4) |
---|
| 43 | |
---|
| 44 | .set GP_15, (GP_14 + 4) |
---|
| 45 | .set GP_16, (GP_15 + 4) |
---|
| 46 | .set GP_17, (GP_16 + 4) |
---|
| 47 | .set GP_18, (GP_17 + 4) |
---|
| 48 | |
---|
| 49 | .set GP_19, (GP_18 + 4) |
---|
| 50 | .set GP_20, (GP_19 + 4) |
---|
| 51 | .set GP_21, (GP_20 + 4) |
---|
| 52 | .set GP_22, (GP_21 + 4) |
---|
| 53 | |
---|
| 54 | .set GP_23, (GP_22 + 4) |
---|
| 55 | .set GP_24, (GP_23 + 4) |
---|
| 56 | .set GP_25, (GP_24 + 4) |
---|
| 57 | .set GP_26, (GP_25 + 4) |
---|
| 58 | |
---|
| 59 | .set GP_27, (GP_26 + 4) |
---|
| 60 | .set GP_28, (GP_27 + 4) |
---|
| 61 | .set GP_29, (GP_28 + 4) |
---|
| 62 | .set GP_30, (GP_29 + 4) |
---|
| 63 | |
---|
| 64 | .set GP_31, (GP_30 + 4) |
---|
| 65 | .set GP_CR, (GP_31 + 4) |
---|
| 66 | .set GP_PC, (GP_CR + 4) |
---|
| 67 | .set GP_MSR, (GP_PC + 4) |
---|
| 68 | |
---|
[3ddf3b5] | 69 | #if (PPC_HAS_DOUBLE==1) |
---|
| 70 | .set FP_SIZE, 8 |
---|
| 71 | #define LDF lfd |
---|
| 72 | #define STF stfd |
---|
| 73 | #else |
---|
| 74 | .set FP_SIZE, 4 |
---|
| 75 | #define LDF lfs |
---|
| 76 | #define STF stfs |
---|
| 77 | #endif |
---|
| 78 | |
---|
[acc25ee] | 79 | .set FP_0, 0 |
---|
[3ddf3b5] | 80 | .set FP_1, (FP_0 + FP_SIZE) |
---|
| 81 | .set FP_2, (FP_1 + FP_SIZE) |
---|
| 82 | .set FP_3, (FP_2 + FP_SIZE) |
---|
| 83 | .set FP_4, (FP_3 + FP_SIZE) |
---|
| 84 | .set FP_5, (FP_4 + FP_SIZE) |
---|
| 85 | .set FP_6, (FP_5 + FP_SIZE) |
---|
| 86 | .set FP_7, (FP_6 + FP_SIZE) |
---|
| 87 | .set FP_8, (FP_7 + FP_SIZE) |
---|
| 88 | .set FP_9, (FP_8 + FP_SIZE) |
---|
| 89 | .set FP_10, (FP_9 + FP_SIZE) |
---|
| 90 | .set FP_11, (FP_10 + FP_SIZE) |
---|
| 91 | .set FP_12, (FP_11 + FP_SIZE) |
---|
| 92 | .set FP_13, (FP_12 + FP_SIZE) |
---|
| 93 | .set FP_14, (FP_13 + FP_SIZE) |
---|
| 94 | .set FP_15, (FP_14 + FP_SIZE) |
---|
| 95 | .set FP_16, (FP_15 + FP_SIZE) |
---|
| 96 | .set FP_17, (FP_16 + FP_SIZE) |
---|
| 97 | .set FP_18, (FP_17 + FP_SIZE) |
---|
| 98 | .set FP_19, (FP_18 + FP_SIZE) |
---|
| 99 | .set FP_20, (FP_19 + FP_SIZE) |
---|
| 100 | .set FP_21, (FP_20 + FP_SIZE) |
---|
| 101 | .set FP_22, (FP_21 + FP_SIZE) |
---|
| 102 | .set FP_23, (FP_22 + FP_SIZE) |
---|
| 103 | .set FP_24, (FP_23 + FP_SIZE) |
---|
| 104 | .set FP_25, (FP_24 + FP_SIZE) |
---|
| 105 | .set FP_26, (FP_25 + FP_SIZE) |
---|
| 106 | .set FP_27, (FP_26 + FP_SIZE) |
---|
| 107 | .set FP_28, (FP_27 + FP_SIZE) |
---|
| 108 | .set FP_29, (FP_28 + FP_SIZE) |
---|
| 109 | .set FP_30, (FP_29 + FP_SIZE) |
---|
| 110 | .set FP_31, (FP_30 + FP_SIZE) |
---|
| 111 | .set FP_FPSCR, (FP_31 + FP_SIZE) |
---|
[acc25ee] | 112 | |
---|
| 113 | .set IP_LINK, 0 |
---|
| 114 | .set IP_0, (IP_LINK + 8) |
---|
| 115 | .set IP_2, (IP_0 + 4) |
---|
| 116 | |
---|
| 117 | .set IP_3, (IP_2 + 4) |
---|
| 118 | .set IP_4, (IP_3 + 4) |
---|
| 119 | .set IP_5, (IP_4 + 4) |
---|
| 120 | .set IP_6, (IP_5 + 4) |
---|
| 121 | |
---|
| 122 | .set IP_7, (IP_6 + 4) |
---|
| 123 | .set IP_8, (IP_7 + 4) |
---|
| 124 | .set IP_9, (IP_8 + 4) |
---|
| 125 | .set IP_10, (IP_9 + 4) |
---|
| 126 | |
---|
| 127 | .set IP_11, (IP_10 + 4) |
---|
| 128 | .set IP_12, (IP_11 + 4) |
---|
| 129 | .set IP_13, (IP_12 + 4) |
---|
| 130 | .set IP_28, (IP_13 + 4) |
---|
| 131 | |
---|
| 132 | .set IP_29, (IP_28 + 4) |
---|
| 133 | .set IP_30, (IP_29 + 4) |
---|
| 134 | .set IP_31, (IP_30 + 4) |
---|
| 135 | .set IP_CR, (IP_31 + 4) |
---|
| 136 | |
---|
| 137 | .set IP_CTR, (IP_CR + 4) |
---|
| 138 | .set IP_XER, (IP_CTR + 4) |
---|
| 139 | .set IP_LR, (IP_XER + 4) |
---|
| 140 | .set IP_PC, (IP_LR + 4) |
---|
| 141 | |
---|
| 142 | .set IP_MSR, (IP_PC + 4) |
---|
| 143 | .set IP_END, (IP_MSR + 16) |
---|
| 144 | |
---|
| 145 | BEGIN_CODE |
---|
| 146 | /* |
---|
| 147 | * _CPU_Context_save_fp_context |
---|
| 148 | * |
---|
| 149 | * This routine is responsible for saving the FP context |
---|
| 150 | * at *fp_context_ptr. If the point to load the FP context |
---|
| 151 | * from is changed then the pointer is modified by this routine. |
---|
| 152 | * |
---|
| 153 | * Sometimes a macro implementation of this is in cpu.h which dereferences |
---|
| 154 | * the ** and a similarly named routine in this file is passed something |
---|
| 155 | * like a (Context_Control_fp *). The general rule on making this decision |
---|
| 156 | * is to avoid writing assembly language. |
---|
| 157 | */ |
---|
| 158 | |
---|
| 159 | ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER) |
---|
| 160 | PUBLIC_PROC (_CPU_Context_save_fp) |
---|
| 161 | PROC (_CPU_Context_save_fp): |
---|
| 162 | #if (PPC_HAS_FPU == 1) |
---|
| 163 | lwz r3, 0(r3) |
---|
[3ddf3b5] | 164 | STF f0, FP_0(r3) |
---|
| 165 | STF f1, FP_1(r3) |
---|
| 166 | STF f2, FP_2(r3) |
---|
| 167 | STF f3, FP_3(r3) |
---|
| 168 | STF f4, FP_4(r3) |
---|
| 169 | STF f5, FP_5(r3) |
---|
| 170 | STF f6, FP_6(r3) |
---|
| 171 | STF f7, FP_7(r3) |
---|
| 172 | STF f8, FP_8(r3) |
---|
| 173 | STF f9, FP_9(r3) |
---|
| 174 | STF f10, FP_10(r3) |
---|
| 175 | STF f11, FP_11(r3) |
---|
| 176 | STF f12, FP_12(r3) |
---|
| 177 | STF f13, FP_13(r3) |
---|
| 178 | STF f14, FP_14(r3) |
---|
| 179 | STF f15, FP_15(r3) |
---|
| 180 | STF f16, FP_16(r3) |
---|
| 181 | STF f17, FP_17(r3) |
---|
| 182 | STF f18, FP_18(r3) |
---|
| 183 | STF f19, FP_19(r3) |
---|
| 184 | STF f20, FP_20(r3) |
---|
| 185 | STF f21, FP_21(r3) |
---|
| 186 | STF f22, FP_22(r3) |
---|
| 187 | STF f23, FP_23(r3) |
---|
| 188 | STF f24, FP_24(r3) |
---|
| 189 | STF f25, FP_25(r3) |
---|
| 190 | STF f26, FP_26(r3) |
---|
| 191 | STF f27, FP_27(r3) |
---|
| 192 | STF f28, FP_28(r3) |
---|
| 193 | STF f29, FP_29(r3) |
---|
| 194 | STF f30, FP_30(r3) |
---|
| 195 | STF f31, FP_31(r3) |
---|
[acc25ee] | 196 | mffs f2 |
---|
[3ddf3b5] | 197 | STF f2, FP_FPSCR(r3) |
---|
[acc25ee] | 198 | #endif |
---|
| 199 | blr |
---|
| 200 | |
---|
| 201 | /* |
---|
| 202 | * _CPU_Context_restore_fp_context |
---|
| 203 | * |
---|
| 204 | * This routine is responsible for restoring the FP context |
---|
| 205 | * at *fp_context_ptr. If the point to load the FP context |
---|
| 206 | * from is changed then the pointer is modified by this routine. |
---|
| 207 | * |
---|
| 208 | * Sometimes a macro implementation of this is in cpu.h which dereferences |
---|
| 209 | * the ** and a similarly named routine in this file is passed something |
---|
| 210 | * like a (Context_Control_fp *). The general rule on making this decision |
---|
| 211 | * is to avoid writing assembly language. |
---|
| 212 | */ |
---|
| 213 | |
---|
| 214 | ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER) |
---|
| 215 | PUBLIC_PROC (_CPU_Context_restore_fp) |
---|
| 216 | PROC (_CPU_Context_restore_fp): |
---|
| 217 | #if (PPC_HAS_FPU == 1) |
---|
| 218 | lwz r3, 0(r3) |
---|
[3ddf3b5] | 219 | LDF f2, FP_FPSCR(r3) |
---|
[acc25ee] | 220 | mtfsf 255, f2 |
---|
[3ddf3b5] | 221 | LDF f0, FP_0(r3) |
---|
| 222 | LDF f1, FP_1(r3) |
---|
| 223 | LDF f2, FP_2(r3) |
---|
| 224 | LDF f3, FP_3(r3) |
---|
| 225 | LDF f4, FP_4(r3) |
---|
| 226 | LDF f5, FP_5(r3) |
---|
| 227 | LDF f6, FP_6(r3) |
---|
| 228 | LDF f7, FP_7(r3) |
---|
| 229 | LDF f8, FP_8(r3) |
---|
| 230 | LDF f9, FP_9(r3) |
---|
| 231 | LDF f10, FP_10(r3) |
---|
| 232 | LDF f11, FP_11(r3) |
---|
| 233 | LDF f12, FP_12(r3) |
---|
| 234 | LDF f13, FP_13(r3) |
---|
| 235 | LDF f14, FP_14(r3) |
---|
| 236 | LDF f15, FP_15(r3) |
---|
| 237 | LDF f16, FP_16(r3) |
---|
| 238 | LDF f17, FP_17(r3) |
---|
| 239 | LDF f18, FP_18(r3) |
---|
| 240 | LDF f19, FP_19(r3) |
---|
| 241 | LDF f20, FP_20(r3) |
---|
| 242 | LDF f21, FP_21(r3) |
---|
| 243 | LDF f22, FP_22(r3) |
---|
| 244 | LDF f23, FP_23(r3) |
---|
| 245 | LDF f24, FP_24(r3) |
---|
| 246 | LDF f25, FP_25(r3) |
---|
| 247 | LDF f26, FP_26(r3) |
---|
| 248 | LDF f27, FP_27(r3) |
---|
| 249 | LDF f28, FP_28(r3) |
---|
| 250 | LDF f29, FP_29(r3) |
---|
| 251 | LDF f30, FP_30(r3) |
---|
| 252 | LDF f31, FP_31(r3) |
---|
[acc25ee] | 253 | #endif |
---|
| 254 | blr |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | /* _CPU_Context_switch |
---|
| 258 | * |
---|
| 259 | * This routine performs a normal non-FP context switch. |
---|
| 260 | */ |
---|
| 261 | ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER) |
---|
| 262 | PUBLIC_PROC (_CPU_Context_switch) |
---|
| 263 | PROC (_CPU_Context_switch): |
---|
| 264 | sync |
---|
| 265 | isync |
---|
| 266 | /* This assumes that all the registers are in the given order */ |
---|
| 267 | li r5, 32 |
---|
| 268 | addi r3,r3,-4 |
---|
| 269 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 270 | dcbz r5, r3 |
---|
| 271 | #endif |
---|
| 272 | stw r1, GP_1+4(r3) |
---|
| 273 | stw r2, GP_2+4(r3) |
---|
| 274 | #if (PPC_USE_MULTIPLE == 1) |
---|
| 275 | addi r3, r3, GP_18+4 |
---|
| 276 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 277 | dcbz r5, r3 |
---|
| 278 | #endif |
---|
| 279 | stmw r13, GP_13-GP_18(r3) |
---|
| 280 | #else |
---|
| 281 | stw r13, GP_13+4(r3) |
---|
| 282 | stw r14, GP_14+4(r3) |
---|
| 283 | stw r15, GP_15+4(r3) |
---|
| 284 | stw r16, GP_16+4(r3) |
---|
| 285 | stw r17, GP_17+4(r3) |
---|
| 286 | stwu r18, GP_18+4(r3) |
---|
| 287 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 288 | dcbz r5, r3 |
---|
| 289 | #endif |
---|
| 290 | stw r19, GP_19-GP_18(r3) |
---|
| 291 | stw r20, GP_20-GP_18(r3) |
---|
| 292 | stw r21, GP_21-GP_18(r3) |
---|
| 293 | stw r22, GP_22-GP_18(r3) |
---|
| 294 | stw r23, GP_23-GP_18(r3) |
---|
| 295 | stw r24, GP_24-GP_18(r3) |
---|
| 296 | stw r25, GP_25-GP_18(r3) |
---|
| 297 | stw r26, GP_26-GP_18(r3) |
---|
| 298 | stw r27, GP_27-GP_18(r3) |
---|
| 299 | stw r28, GP_28-GP_18(r3) |
---|
| 300 | stw r29, GP_29-GP_18(r3) |
---|
| 301 | stw r30, GP_30-GP_18(r3) |
---|
| 302 | stw r31, GP_31-GP_18(r3) |
---|
| 303 | #endif |
---|
| 304 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 305 | dcbt r0, r4 |
---|
| 306 | #endif |
---|
| 307 | mfcr r6 |
---|
| 308 | stw r6, GP_CR-GP_18(r3) |
---|
| 309 | mflr r7 |
---|
| 310 | stw r7, GP_PC-GP_18(r3) |
---|
| 311 | mfmsr r8 |
---|
| 312 | stw r8, GP_MSR-GP_18(r3) |
---|
| 313 | |
---|
| 314 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 315 | dcbt r5, r4 |
---|
| 316 | #endif |
---|
| 317 | lwz r1, GP_1(r4) |
---|
| 318 | lwz r2, GP_2(r4) |
---|
| 319 | #if (PPC_USE_MULTIPLE == 1) |
---|
| 320 | addi r4, r4, GP_19 |
---|
| 321 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 322 | dcbt r5, r4 |
---|
| 323 | #endif |
---|
| 324 | lmw r13, GP_13-GP_19(r4) |
---|
| 325 | #else |
---|
| 326 | lwz r13, GP_13(r4) |
---|
| 327 | lwz r14, GP_14(r4) |
---|
| 328 | lwz r15, GP_15(r4) |
---|
| 329 | lwz r16, GP_16(r4) |
---|
| 330 | lwz r17, GP_17(r4) |
---|
| 331 | lwz r18, GP_18(r4) |
---|
| 332 | lwzu r19, GP_19(r4) |
---|
| 333 | #if ( PPC_USE_DATA_CACHE ) |
---|
| 334 | dcbt r5, r4 |
---|
| 335 | #endif |
---|
| 336 | lwz r20, GP_20-GP_19(r4) |
---|
| 337 | lwz r21, GP_21-GP_19(r4) |
---|
| 338 | lwz r22, GP_22-GP_19(r4) |
---|
| 339 | lwz r23, GP_23-GP_19(r4) |
---|
| 340 | lwz r24, GP_24-GP_19(r4) |
---|
| 341 | lwz r25, GP_25-GP_19(r4) |
---|
| 342 | lwz r26, GP_26-GP_19(r4) |
---|
| 343 | lwz r27, GP_27-GP_19(r4) |
---|
| 344 | lwz r28, GP_28-GP_19(r4) |
---|
| 345 | lwz r29, GP_29-GP_19(r4) |
---|
| 346 | lwz r30, GP_30-GP_19(r4) |
---|
| 347 | lwz r31, GP_31-GP_19(r4) |
---|
| 348 | #endif |
---|
| 349 | lwz r6, GP_CR-GP_19(r4) |
---|
| 350 | lwz r7, GP_PC-GP_19(r4) |
---|
| 351 | lwz r8, GP_MSR-GP_19(r4) |
---|
| 352 | mtcrf 255, r6 |
---|
| 353 | mtlr r7 |
---|
| 354 | mtmsr r8 |
---|
| 355 | |
---|
| 356 | blr |
---|
| 357 | |
---|
| 358 | /* |
---|
| 359 | * _CPU_Context_restore |
---|
| 360 | * |
---|
| 361 | * This routine is generallu used only to restart self in an |
---|
| 362 | * efficient manner. It may simply be a label in _CPU_Context_switch. |
---|
| 363 | * |
---|
| 364 | * NOTE: May be unnecessary to reload some registers. |
---|
| 365 | */ |
---|
| 366 | /* |
---|
| 367 | * ACB: Don't worry about cache optimisation here - this is not THAT critical. |
---|
| 368 | */ |
---|
| 369 | ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER) |
---|
| 370 | PUBLIC_PROC (_CPU_Context_restore) |
---|
| 371 | PROC (_CPU_Context_restore): |
---|
| 372 | lwz r5, GP_CR(r3) |
---|
| 373 | lwz r6, GP_PC(r3) |
---|
| 374 | lwz r7, GP_MSR(r3) |
---|
| 375 | mtcrf 255, r5 |
---|
| 376 | mtlr r6 |
---|
| 377 | mtmsr r7 |
---|
| 378 | lwz r1, GP_1(r3) |
---|
| 379 | lwz r2, GP_2(r3) |
---|
| 380 | #if (PPC_USE_MULTIPLE == 1) |
---|
| 381 | lmw r13, GP_13(r3) |
---|
| 382 | #else |
---|
| 383 | lwz r13, GP_13(r3) |
---|
| 384 | lwz r14, GP_14(r3) |
---|
| 385 | lwz r15, GP_15(r3) |
---|
| 386 | lwz r16, GP_16(r3) |
---|
| 387 | lwz r17, GP_17(r3) |
---|
| 388 | lwz r18, GP_18(r3) |
---|
| 389 | lwz r19, GP_19(r3) |
---|
| 390 | lwz r20, GP_20(r3) |
---|
| 391 | lwz r21, GP_21(r3) |
---|
| 392 | lwz r22, GP_22(r3) |
---|
| 393 | lwz r23, GP_23(r3) |
---|
| 394 | lwz r24, GP_24(r3) |
---|
| 395 | lwz r25, GP_25(r3) |
---|
| 396 | lwz r26, GP_26(r3) |
---|
| 397 | lwz r27, GP_27(r3) |
---|
| 398 | lwz r28, GP_28(r3) |
---|
| 399 | lwz r29, GP_29(r3) |
---|
| 400 | lwz r30, GP_30(r3) |
---|
| 401 | lwz r31, GP_31(r3) |
---|
| 402 | #endif |
---|
| 403 | |
---|
| 404 | blr |
---|
| 405 | |
---|