Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file contains miscellaneous low-level functions. |
| 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * |
| 5 | * Largely rewritten by Cort Dougan (cort@cs.nmt.edu) |
| 6 | * and Paul Mackerras. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version |
| 11 | * 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/config.h> |
| 16 | #include <linux/sys.h> |
| 17 | #include <asm/unistd.h> |
| 18 | #include <asm/errno.h> |
| 19 | #include <asm/processor.h> |
| 20 | #include <asm/page.h> |
| 21 | #include <asm/cache.h> |
| 22 | #include <asm/cputable.h> |
| 23 | #include <asm/mmu.h> |
| 24 | #include <asm/ppc_asm.h> |
| 25 | #include <asm/thread_info.h> |
Sam Ravnborg | 0013a85 | 2005-09-09 20:57:26 +0200 | [diff] [blame] | 26 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 28 | #ifdef CONFIG_8xx |
| 29 | #define ISYNC_8xx isync |
| 30 | #else |
| 31 | #define ISYNC_8xx |
| 32 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | .text |
| 34 | |
| 35 | .align 5 |
| 36 | _GLOBAL(__delay) |
| 37 | cmpwi 0,r3,0 |
| 38 | mtctr r3 |
| 39 | beqlr |
| 40 | 1: bdnz 1b |
| 41 | blr |
| 42 | |
| 43 | /* |
| 44 | * Returns (address we're running at) - (address we were linked at) |
| 45 | * for use before the text and data are mapped to KERNELBASE. |
| 46 | */ |
| 47 | _GLOBAL(reloc_offset) |
| 48 | mflr r0 |
| 49 | bl 1f |
| 50 | 1: mflr r3 |
| 51 | lis r4,1b@ha |
| 52 | addi r4,r4,1b@l |
| 53 | subf r3,r4,r3 |
| 54 | mtlr r0 |
| 55 | blr |
| 56 | |
| 57 | /* |
| 58 | * add_reloc_offset(x) returns x + reloc_offset(). |
| 59 | */ |
| 60 | _GLOBAL(add_reloc_offset) |
| 61 | mflr r0 |
| 62 | bl 1f |
| 63 | 1: mflr r5 |
| 64 | lis r4,1b@ha |
| 65 | addi r4,r4,1b@l |
| 66 | subf r5,r4,r5 |
| 67 | add r3,r3,r5 |
| 68 | mtlr r0 |
| 69 | blr |
| 70 | |
| 71 | /* |
| 72 | * sub_reloc_offset(x) returns x - reloc_offset(). |
| 73 | */ |
| 74 | _GLOBAL(sub_reloc_offset) |
| 75 | mflr r0 |
| 76 | bl 1f |
| 77 | 1: mflr r5 |
| 78 | lis r4,1b@ha |
| 79 | addi r4,r4,1b@l |
| 80 | subf r5,r4,r5 |
| 81 | subf r3,r5,r3 |
| 82 | mtlr r0 |
| 83 | blr |
| 84 | |
| 85 | /* |
| 86 | * reloc_got2 runs through the .got2 section adding an offset |
| 87 | * to each entry. |
| 88 | */ |
| 89 | _GLOBAL(reloc_got2) |
| 90 | mflr r11 |
| 91 | lis r7,__got2_start@ha |
| 92 | addi r7,r7,__got2_start@l |
| 93 | lis r8,__got2_end@ha |
| 94 | addi r8,r8,__got2_end@l |
| 95 | subf r8,r7,r8 |
| 96 | srwi. r8,r8,2 |
| 97 | beqlr |
| 98 | mtctr r8 |
| 99 | bl 1f |
| 100 | 1: mflr r0 |
| 101 | lis r4,1b@ha |
| 102 | addi r4,r4,1b@l |
| 103 | subf r0,r4,r0 |
| 104 | add r7,r0,r7 |
| 105 | 2: lwz r0,0(r7) |
| 106 | add r0,r0,r3 |
| 107 | stw r0,0(r7) |
| 108 | addi r7,r7,4 |
| 109 | bdnz 2b |
| 110 | mtlr r11 |
| 111 | blr |
| 112 | |
| 113 | /* |
| 114 | * identify_cpu, |
| 115 | * called with r3 = data offset and r4 = CPU number |
| 116 | * doesn't change r3 |
| 117 | */ |
| 118 | _GLOBAL(identify_cpu) |
| 119 | addis r8,r3,cpu_specs@ha |
| 120 | addi r8,r8,cpu_specs@l |
| 121 | mfpvr r7 |
| 122 | 1: |
| 123 | lwz r5,CPU_SPEC_PVR_MASK(r8) |
| 124 | and r5,r5,r7 |
| 125 | lwz r6,CPU_SPEC_PVR_VALUE(r8) |
| 126 | cmplw 0,r6,r5 |
| 127 | beq 1f |
| 128 | addi r8,r8,CPU_SPEC_ENTRY_SIZE |
| 129 | b 1b |
| 130 | 1: |
| 131 | addis r6,r3,cur_cpu_spec@ha |
| 132 | addi r6,r6,cur_cpu_spec@l |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | sub r8,r8,r3 |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 134 | stw r8,0(r6) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | blr |
| 136 | |
| 137 | /* |
| 138 | * do_cpu_ftr_fixups - goes through the list of CPU feature fixups |
| 139 | * and writes nop's over sections of code that don't apply for this cpu. |
| 140 | * r3 = data offset (not changed) |
| 141 | */ |
| 142 | _GLOBAL(do_cpu_ftr_fixups) |
| 143 | /* Get CPU 0 features */ |
| 144 | addis r6,r3,cur_cpu_spec@ha |
| 145 | addi r6,r6,cur_cpu_spec@l |
| 146 | lwz r4,0(r6) |
| 147 | add r4,r4,r3 |
| 148 | lwz r4,CPU_SPEC_FEATURES(r4) |
| 149 | |
| 150 | /* Get the fixup table */ |
| 151 | addis r6,r3,__start___ftr_fixup@ha |
| 152 | addi r6,r6,__start___ftr_fixup@l |
| 153 | addis r7,r3,__stop___ftr_fixup@ha |
| 154 | addi r7,r7,__stop___ftr_fixup@l |
| 155 | |
| 156 | /* Do the fixup */ |
| 157 | 1: cmplw 0,r6,r7 |
| 158 | bgelr |
| 159 | addi r6,r6,16 |
| 160 | lwz r8,-16(r6) /* mask */ |
| 161 | and r8,r8,r4 |
| 162 | lwz r9,-12(r6) /* value */ |
| 163 | cmplw 0,r8,r9 |
| 164 | beq 1b |
| 165 | lwz r8,-8(r6) /* section begin */ |
| 166 | lwz r9,-4(r6) /* section end */ |
| 167 | subf. r9,r8,r9 |
| 168 | beq 1b |
| 169 | /* write nops over the section of code */ |
| 170 | /* todo: if large section, add a branch at the start of it */ |
| 171 | srwi r9,r9,2 |
| 172 | mtctr r9 |
| 173 | add r8,r8,r3 |
| 174 | lis r0,0x60000000@h /* nop */ |
| 175 | 3: stw r0,0(r8) |
| 176 | andi. r10,r4,CPU_FTR_SPLIT_ID_CACHE@l |
| 177 | beq 2f |
| 178 | dcbst 0,r8 /* suboptimal, but simpler */ |
| 179 | sync |
| 180 | icbi 0,r8 |
| 181 | 2: addi r8,r8,4 |
| 182 | bdnz 3b |
| 183 | sync /* additional sync needed on g4 */ |
| 184 | isync |
| 185 | b 1b |
| 186 | |
| 187 | /* |
| 188 | * call_setup_cpu - call the setup_cpu function for this cpu |
| 189 | * r3 = data offset, r24 = cpu number |
| 190 | * |
| 191 | * Setup function is called with: |
| 192 | * r3 = data offset |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 193 | * r4 = ptr to CPU spec (relocated) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | */ |
| 195 | _GLOBAL(call_setup_cpu) |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 196 | addis r4,r3,cur_cpu_spec@ha |
| 197 | addi r4,r4,cur_cpu_spec@l |
| 198 | lwz r4,0(r4) |
| 199 | add r4,r4,r3 |
| 200 | lwz r5,CPU_SPEC_SETUP(r4) |
| 201 | cmpi 0,r5,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | add r5,r5,r3 |
Kumar Gala | 400d221 | 2005-09-27 15:13:12 -0500 | [diff] [blame] | 203 | beqlr |
| 204 | mtctr r5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | bctr |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* |
| 208 | * complement mask on the msr then "or" some values on. |
| 209 | * _nmask_and_or_msr(nmask, value_to_or) |
| 210 | */ |
| 211 | _GLOBAL(_nmask_and_or_msr) |
| 212 | mfmsr r0 /* Get current msr */ |
| 213 | andc r0,r0,r3 /* And off the bits set in r3 (first parm) */ |
| 214 | or r0,r0,r4 /* Or on the bits in r4 (second parm) */ |
| 215 | SYNC /* Some chip revs have problems here... */ |
| 216 | mtmsr r0 /* Update machine state */ |
| 217 | isync |
| 218 | blr /* Done */ |
| 219 | |
| 220 | |
| 221 | /* |
| 222 | * Flush MMU TLB |
| 223 | */ |
| 224 | _GLOBAL(_tlbia) |
| 225 | #if defined(CONFIG_40x) |
| 226 | sync /* Flush to memory before changing mapping */ |
| 227 | tlbia |
| 228 | isync /* Flush shadow TLB */ |
| 229 | #elif defined(CONFIG_44x) |
| 230 | li r3,0 |
| 231 | sync |
| 232 | |
| 233 | /* Load high watermark */ |
| 234 | lis r4,tlb_44x_hwater@ha |
| 235 | lwz r5,tlb_44x_hwater@l(r4) |
| 236 | |
| 237 | 1: tlbwe r3,r3,PPC44x_TLB_PAGEID |
| 238 | addi r3,r3,1 |
| 239 | cmpw 0,r3,r5 |
| 240 | ble 1b |
| 241 | |
| 242 | isync |
| 243 | #elif defined(CONFIG_FSL_BOOKE) |
| 244 | /* Invalidate all entries in TLB0 */ |
| 245 | li r3, 0x04 |
| 246 | tlbivax 0,3 |
| 247 | /* Invalidate all entries in TLB1 */ |
| 248 | li r3, 0x0c |
| 249 | tlbivax 0,3 |
| 250 | /* Invalidate all entries in TLB2 */ |
| 251 | li r3, 0x14 |
| 252 | tlbivax 0,3 |
| 253 | /* Invalidate all entries in TLB3 */ |
| 254 | li r3, 0x1c |
| 255 | tlbivax 0,3 |
| 256 | msync |
| 257 | #ifdef CONFIG_SMP |
| 258 | tlbsync |
| 259 | #endif /* CONFIG_SMP */ |
| 260 | #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */ |
| 261 | #if defined(CONFIG_SMP) |
| 262 | rlwinm r8,r1,0,0,18 |
| 263 | lwz r8,TI_CPU(r8) |
| 264 | oris r8,r8,10 |
| 265 | mfmsr r10 |
| 266 | SYNC |
| 267 | rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */ |
| 268 | rlwinm r0,r0,0,28,26 /* clear DR */ |
| 269 | mtmsr r0 |
| 270 | SYNC_601 |
| 271 | isync |
| 272 | lis r9,mmu_hash_lock@h |
| 273 | ori r9,r9,mmu_hash_lock@l |
| 274 | tophys(r9,r9) |
| 275 | 10: lwarx r7,0,r9 |
| 276 | cmpwi 0,r7,0 |
| 277 | bne- 10b |
| 278 | stwcx. r8,0,r9 |
| 279 | bne- 10b |
| 280 | sync |
| 281 | tlbia |
| 282 | sync |
| 283 | TLBSYNC |
| 284 | li r0,0 |
| 285 | stw r0,0(r9) /* clear mmu_hash_lock */ |
| 286 | mtmsr r10 |
| 287 | SYNC_601 |
| 288 | isync |
| 289 | #else /* CONFIG_SMP */ |
| 290 | sync |
| 291 | tlbia |
| 292 | sync |
| 293 | #endif /* CONFIG_SMP */ |
| 294 | #endif /* ! defined(CONFIG_40x) */ |
| 295 | blr |
| 296 | |
| 297 | /* |
| 298 | * Flush MMU TLB for a particular address |
| 299 | */ |
| 300 | _GLOBAL(_tlbie) |
| 301 | #if defined(CONFIG_40x) |
| 302 | tlbsx. r3, 0, r3 |
| 303 | bne 10f |
| 304 | sync |
| 305 | /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear. |
| 306 | * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate |
| 307 | * the TLB entry. */ |
| 308 | tlbwe r3, r3, TLB_TAG |
| 309 | isync |
| 310 | 10: |
| 311 | #elif defined(CONFIG_44x) |
| 312 | mfspr r4,SPRN_MMUCR |
| 313 | mfspr r5,SPRN_PID /* Get PID */ |
| 314 | rlwimi r4,r5,0,24,31 /* Set TID */ |
| 315 | mtspr SPRN_MMUCR,r4 |
| 316 | |
| 317 | tlbsx. r3, 0, r3 |
| 318 | bne 10f |
| 319 | sync |
| 320 | /* There are only 64 TLB entries, so r3 < 64, |
| 321 | * which means bit 22, is clear. Since 22 is |
| 322 | * the V bit in the TLB_PAGEID, loading this |
| 323 | * value will invalidate the TLB entry. |
| 324 | */ |
| 325 | tlbwe r3, r3, PPC44x_TLB_PAGEID |
| 326 | isync |
| 327 | 10: |
| 328 | #elif defined(CONFIG_FSL_BOOKE) |
| 329 | rlwinm r4, r3, 0, 0, 19 |
| 330 | ori r5, r4, 0x08 /* TLBSEL = 1 */ |
| 331 | ori r6, r4, 0x10 /* TLBSEL = 2 */ |
| 332 | ori r7, r4, 0x18 /* TLBSEL = 3 */ |
| 333 | tlbivax 0, r4 |
| 334 | tlbivax 0, r5 |
| 335 | tlbivax 0, r6 |
| 336 | tlbivax 0, r7 |
| 337 | msync |
| 338 | #if defined(CONFIG_SMP) |
| 339 | tlbsync |
| 340 | #endif /* CONFIG_SMP */ |
| 341 | #else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */ |
| 342 | #if defined(CONFIG_SMP) |
| 343 | rlwinm r8,r1,0,0,18 |
| 344 | lwz r8,TI_CPU(r8) |
| 345 | oris r8,r8,11 |
| 346 | mfmsr r10 |
| 347 | SYNC |
| 348 | rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */ |
| 349 | rlwinm r0,r0,0,28,26 /* clear DR */ |
| 350 | mtmsr r0 |
| 351 | SYNC_601 |
| 352 | isync |
| 353 | lis r9,mmu_hash_lock@h |
| 354 | ori r9,r9,mmu_hash_lock@l |
| 355 | tophys(r9,r9) |
| 356 | 10: lwarx r7,0,r9 |
| 357 | cmpwi 0,r7,0 |
| 358 | bne- 10b |
| 359 | stwcx. r8,0,r9 |
| 360 | bne- 10b |
| 361 | eieio |
| 362 | tlbie r3 |
| 363 | sync |
| 364 | TLBSYNC |
| 365 | li r0,0 |
| 366 | stw r0,0(r9) /* clear mmu_hash_lock */ |
| 367 | mtmsr r10 |
| 368 | SYNC_601 |
| 369 | isync |
| 370 | #else /* CONFIG_SMP */ |
| 371 | tlbie r3 |
| 372 | sync |
| 373 | #endif /* CONFIG_SMP */ |
| 374 | #endif /* ! CONFIG_40x */ |
| 375 | blr |
| 376 | |
| 377 | /* |
| 378 | * Flush instruction cache. |
| 379 | * This is a no-op on the 601. |
| 380 | */ |
| 381 | _GLOBAL(flush_instruction_cache) |
| 382 | #if defined(CONFIG_8xx) |
| 383 | isync |
| 384 | lis r5, IDC_INVALL@h |
| 385 | mtspr SPRN_IC_CST, r5 |
| 386 | #elif defined(CONFIG_4xx) |
| 387 | #ifdef CONFIG_403GCX |
| 388 | li r3, 512 |
| 389 | mtctr r3 |
| 390 | lis r4, KERNELBASE@h |
| 391 | 1: iccci 0, r4 |
| 392 | addi r4, r4, 16 |
| 393 | bdnz 1b |
| 394 | #else |
| 395 | lis r3, KERNELBASE@h |
| 396 | iccci 0,r3 |
| 397 | #endif |
| 398 | #elif CONFIG_FSL_BOOKE |
Kumar Gala | 33d9e9b | 2005-06-25 14:54:37 -0700 | [diff] [blame] | 399 | BEGIN_FTR_SECTION |
| 400 | mfspr r3,SPRN_L1CSR0 |
| 401 | ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC |
| 402 | /* msync; isync recommended here */ |
| 403 | mtspr SPRN_L1CSR0,r3 |
| 404 | isync |
| 405 | blr |
| 406 | END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | mfspr r3,SPRN_L1CSR1 |
| 408 | ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR |
| 409 | mtspr SPRN_L1CSR1,r3 |
| 410 | #else |
| 411 | mfspr r3,SPRN_PVR |
| 412 | rlwinm r3,r3,16,16,31 |
| 413 | cmpwi 0,r3,1 |
| 414 | beqlr /* for 601, do nothing */ |
| 415 | /* 603/604 processor - use invalidate-all bit in HID0 */ |
| 416 | mfspr r3,SPRN_HID0 |
| 417 | ori r3,r3,HID0_ICFI |
| 418 | mtspr SPRN_HID0,r3 |
| 419 | #endif /* CONFIG_8xx/4xx */ |
| 420 | isync |
| 421 | blr |
| 422 | |
| 423 | /* |
| 424 | * Write any modified data cache blocks out to memory |
| 425 | * and invalidate the corresponding instruction cache blocks. |
| 426 | * This is a no-op on the 601. |
| 427 | * |
David Gibson | 26ef5c0 | 2005-11-10 11:50:16 +1100 | [diff] [blame] | 428 | * __flush_icache_range(unsigned long start, unsigned long stop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | */ |
David Gibson | 26ef5c0 | 2005-11-10 11:50:16 +1100 | [diff] [blame] | 430 | _GLOBAL(__flush_icache_range) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | BEGIN_FTR_SECTION |
| 432 | blr /* for 601, do nothing */ |
Kumar Gala | 4481e8e | 2005-06-06 13:35:57 -0700 | [diff] [blame] | 433 | END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE) |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 434 | li r5,L1_CACHE_BYTES-1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | andc r3,r3,r5 |
| 436 | subf r4,r3,r4 |
| 437 | add r4,r4,r5 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 438 | srwi. r4,r4,L1_CACHE_SHIFT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | beqlr |
| 440 | mtctr r4 |
| 441 | mr r6,r3 |
| 442 | 1: dcbst 0,r3 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 443 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | bdnz 1b |
| 445 | sync /* wait for dcbst's to get to ram */ |
| 446 | mtctr r4 |
| 447 | 2: icbi 0,r6 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 448 | addi r6,r6,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | bdnz 2b |
| 450 | sync /* additional sync needed on g4 */ |
| 451 | isync |
| 452 | blr |
| 453 | /* |
| 454 | * Write any modified data cache blocks out to memory. |
| 455 | * Does not invalidate the corresponding cache lines (especially for |
| 456 | * any corresponding instruction cache). |
| 457 | * |
| 458 | * clean_dcache_range(unsigned long start, unsigned long stop) |
| 459 | */ |
| 460 | _GLOBAL(clean_dcache_range) |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 461 | li r5,L1_CACHE_BYTES-1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | andc r3,r3,r5 |
| 463 | subf r4,r3,r4 |
| 464 | add r4,r4,r5 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 465 | srwi. r4,r4,L1_CACHE_SHIFT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | beqlr |
| 467 | mtctr r4 |
| 468 | |
| 469 | 1: dcbst 0,r3 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 470 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | bdnz 1b |
| 472 | sync /* wait for dcbst's to get to ram */ |
| 473 | blr |
| 474 | |
| 475 | /* |
| 476 | * Write any modified data cache blocks out to memory and invalidate them. |
| 477 | * Does not invalidate the corresponding instruction cache blocks. |
| 478 | * |
| 479 | * flush_dcache_range(unsigned long start, unsigned long stop) |
| 480 | */ |
| 481 | _GLOBAL(flush_dcache_range) |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 482 | li r5,L1_CACHE_BYTES-1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | andc r3,r3,r5 |
| 484 | subf r4,r3,r4 |
| 485 | add r4,r4,r5 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 486 | srwi. r4,r4,L1_CACHE_SHIFT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | beqlr |
| 488 | mtctr r4 |
| 489 | |
| 490 | 1: dcbf 0,r3 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 491 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | bdnz 1b |
| 493 | sync /* wait for dcbst's to get to ram */ |
| 494 | blr |
| 495 | |
| 496 | /* |
| 497 | * Like above, but invalidate the D-cache. This is used by the 8xx |
| 498 | * to invalidate the cache so the PPC core doesn't get stale data |
| 499 | * from the CPM (no cache snooping here :-). |
| 500 | * |
| 501 | * invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 502 | */ |
| 503 | _GLOBAL(invalidate_dcache_range) |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 504 | li r5,L1_CACHE_BYTES-1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | andc r3,r3,r5 |
| 506 | subf r4,r3,r4 |
| 507 | add r4,r4,r5 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 508 | srwi. r4,r4,L1_CACHE_SHIFT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | beqlr |
| 510 | mtctr r4 |
| 511 | |
| 512 | 1: dcbi 0,r3 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 513 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | bdnz 1b |
| 515 | sync /* wait for dcbi's to get to ram */ |
| 516 | blr |
| 517 | |
| 518 | #ifdef CONFIG_NOT_COHERENT_CACHE |
| 519 | /* |
| 520 | * 40x cores have 8K or 16K dcache and 32 byte line size. |
| 521 | * 44x has a 32K dcache and 32 byte line size. |
| 522 | * 8xx has 1, 2, 4, 8K variants. |
| 523 | * For now, cover the worst case of the 44x. |
| 524 | * Must be called with external interrupts disabled. |
| 525 | */ |
| 526 | #define CACHE_NWAYS 64 |
| 527 | #define CACHE_NLINES 16 |
| 528 | |
| 529 | _GLOBAL(flush_dcache_all) |
| 530 | li r4, (2 * CACHE_NWAYS * CACHE_NLINES) |
| 531 | mtctr r4 |
| 532 | lis r5, KERNELBASE@h |
| 533 | 1: lwz r3, 0(r5) /* Load one word from every line */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 534 | addi r5, r5, L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | bdnz 1b |
| 536 | blr |
| 537 | #endif /* CONFIG_NOT_COHERENT_CACHE */ |
| 538 | |
| 539 | /* |
| 540 | * Flush a particular page from the data cache to RAM. |
| 541 | * Note: this is necessary because the instruction cache does *not* |
| 542 | * snoop from the data cache. |
| 543 | * This is a no-op on the 601 which has a unified cache. |
| 544 | * |
| 545 | * void __flush_dcache_icache(void *page) |
| 546 | */ |
| 547 | _GLOBAL(__flush_dcache_icache) |
| 548 | BEGIN_FTR_SECTION |
| 549 | blr /* for 601, do nothing */ |
Kumar Gala | 4481e8e | 2005-06-06 13:35:57 -0700 | [diff] [blame] | 550 | END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | rlwinm r3,r3,0,0,19 /* Get page base address */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 552 | li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | mtctr r4 |
| 554 | mr r6,r3 |
| 555 | 0: dcbst 0,r3 /* Write line to ram */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 556 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | bdnz 0b |
| 558 | sync |
| 559 | mtctr r4 |
| 560 | 1: icbi 0,r6 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 561 | addi r6,r6,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | bdnz 1b |
| 563 | sync |
| 564 | isync |
| 565 | blr |
| 566 | |
| 567 | /* |
| 568 | * Flush a particular page from the data cache to RAM, identified |
| 569 | * by its physical address. We turn off the MMU so we can just use |
| 570 | * the physical address (this may be a highmem page without a kernel |
| 571 | * mapping). |
| 572 | * |
| 573 | * void __flush_dcache_icache_phys(unsigned long physaddr) |
| 574 | */ |
| 575 | _GLOBAL(__flush_dcache_icache_phys) |
| 576 | BEGIN_FTR_SECTION |
| 577 | blr /* for 601, do nothing */ |
Kumar Gala | 4481e8e | 2005-06-06 13:35:57 -0700 | [diff] [blame] | 578 | END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | mfmsr r10 |
| 580 | rlwinm r0,r10,0,28,26 /* clear DR */ |
| 581 | mtmsr r0 |
| 582 | isync |
| 583 | rlwinm r3,r3,0,0,19 /* Get page base address */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 584 | li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | mtctr r4 |
| 586 | mr r6,r3 |
| 587 | 0: dcbst 0,r3 /* Write line to ram */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 588 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | bdnz 0b |
| 590 | sync |
| 591 | mtctr r4 |
| 592 | 1: icbi 0,r6 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 593 | addi r6,r6,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | bdnz 1b |
| 595 | sync |
| 596 | mtmsr r10 /* restore DR */ |
| 597 | isync |
| 598 | blr |
| 599 | |
| 600 | /* |
| 601 | * Clear pages using the dcbz instruction, which doesn't cause any |
| 602 | * memory traffic (except to write out any cache lines which get |
| 603 | * displaced). This only works on cacheable memory. |
| 604 | * |
| 605 | * void clear_pages(void *page, int order) ; |
| 606 | */ |
| 607 | _GLOBAL(clear_pages) |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 608 | li r0,4096/L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | slw r0,r0,r4 |
| 610 | mtctr r0 |
| 611 | #ifdef CONFIG_8xx |
| 612 | li r4, 0 |
| 613 | 1: stw r4, 0(r3) |
| 614 | stw r4, 4(r3) |
| 615 | stw r4, 8(r3) |
| 616 | stw r4, 12(r3) |
| 617 | #else |
| 618 | 1: dcbz 0,r3 |
| 619 | #endif |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 620 | addi r3,r3,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | bdnz 1b |
| 622 | blr |
| 623 | |
| 624 | /* |
| 625 | * Copy a whole page. We use the dcbz instruction on the destination |
| 626 | * to reduce memory traffic (it eliminates the unnecessary reads of |
| 627 | * the destination into cache). This requires that the destination |
| 628 | * is cacheable. |
| 629 | */ |
| 630 | #define COPY_16_BYTES \ |
| 631 | lwz r6,4(r4); \ |
| 632 | lwz r7,8(r4); \ |
| 633 | lwz r8,12(r4); \ |
| 634 | lwzu r9,16(r4); \ |
| 635 | stw r6,4(r3); \ |
| 636 | stw r7,8(r3); \ |
| 637 | stw r8,12(r3); \ |
| 638 | stwu r9,16(r3) |
| 639 | |
| 640 | _GLOBAL(copy_page) |
| 641 | addi r3,r3,-4 |
| 642 | addi r4,r4,-4 |
| 643 | |
| 644 | #ifdef CONFIG_8xx |
| 645 | /* don't use prefetch on 8xx */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 646 | li r0,4096/L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | mtctr r0 |
| 648 | 1: COPY_16_BYTES |
| 649 | bdnz 1b |
| 650 | blr |
| 651 | |
| 652 | #else /* not 8xx, we can prefetch */ |
| 653 | li r5,4 |
| 654 | |
| 655 | #if MAX_COPY_PREFETCH > 1 |
| 656 | li r0,MAX_COPY_PREFETCH |
| 657 | li r11,4 |
| 658 | mtctr r0 |
| 659 | 11: dcbt r11,r4 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 660 | addi r11,r11,L1_CACHE_BYTES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | bdnz 11b |
| 662 | #else /* MAX_COPY_PREFETCH == 1 */ |
| 663 | dcbt r5,r4 |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 664 | li r11,L1_CACHE_BYTES+4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | #endif /* MAX_COPY_PREFETCH */ |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 666 | li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | crclr 4*cr0+eq |
| 668 | 2: |
| 669 | mtctr r0 |
| 670 | 1: |
| 671 | dcbt r11,r4 |
| 672 | dcbz r5,r3 |
| 673 | COPY_16_BYTES |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 674 | #if L1_CACHE_BYTES >= 32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | COPY_16_BYTES |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 676 | #if L1_CACHE_BYTES >= 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | COPY_16_BYTES |
| 678 | COPY_16_BYTES |
Stephen Rothwell | 7dffb72 | 2005-10-17 11:50:32 +1000 | [diff] [blame] | 679 | #if L1_CACHE_BYTES >= 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | COPY_16_BYTES |
| 681 | COPY_16_BYTES |
| 682 | COPY_16_BYTES |
| 683 | COPY_16_BYTES |
| 684 | #endif |
| 685 | #endif |
| 686 | #endif |
| 687 | bdnz 1b |
| 688 | beqlr |
| 689 | crnot 4*cr0+eq,4*cr0+eq |
| 690 | li r0,MAX_COPY_PREFETCH |
| 691 | li r11,4 |
| 692 | b 2b |
| 693 | #endif /* CONFIG_8xx */ |
| 694 | |
| 695 | /* |
| 696 | * void atomic_clear_mask(atomic_t mask, atomic_t *addr) |
| 697 | * void atomic_set_mask(atomic_t mask, atomic_t *addr); |
| 698 | */ |
| 699 | _GLOBAL(atomic_clear_mask) |
| 700 | 10: lwarx r5,0,r4 |
| 701 | andc r5,r5,r3 |
| 702 | PPC405_ERR77(0,r4) |
| 703 | stwcx. r5,0,r4 |
| 704 | bne- 10b |
| 705 | blr |
| 706 | _GLOBAL(atomic_set_mask) |
| 707 | 10: lwarx r5,0,r4 |
| 708 | or r5,r5,r3 |
| 709 | PPC405_ERR77(0,r4) |
| 710 | stwcx. r5,0,r4 |
| 711 | bne- 10b |
| 712 | blr |
| 713 | |
| 714 | /* |
| 715 | * I/O string operations |
| 716 | * |
| 717 | * insb(port, buf, len) |
| 718 | * outsb(port, buf, len) |
| 719 | * insw(port, buf, len) |
| 720 | * outsw(port, buf, len) |
| 721 | * insl(port, buf, len) |
| 722 | * outsl(port, buf, len) |
| 723 | * insw_ns(port, buf, len) |
| 724 | * outsw_ns(port, buf, len) |
| 725 | * insl_ns(port, buf, len) |
| 726 | * outsl_ns(port, buf, len) |
| 727 | * |
| 728 | * The *_ns versions don't do byte-swapping. |
| 729 | */ |
| 730 | _GLOBAL(_insb) |
| 731 | cmpwi 0,r5,0 |
| 732 | mtctr r5 |
| 733 | subi r4,r4,1 |
| 734 | blelr- |
| 735 | 00: lbz r5,0(r3) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 736 | 01: eieio |
| 737 | 02: stbu r5,1(r4) |
| 738 | ISYNC_8xx |
| 739 | .section .fixup,"ax" |
| 740 | 03: blr |
| 741 | .text |
| 742 | .section __ex_table, "a" |
| 743 | .align 2 |
| 744 | .long 00b, 03b |
| 745 | .long 01b, 03b |
| 746 | .long 02b, 03b |
| 747 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | bdnz 00b |
| 749 | blr |
| 750 | |
| 751 | _GLOBAL(_outsb) |
| 752 | cmpwi 0,r5,0 |
| 753 | mtctr r5 |
| 754 | subi r4,r4,1 |
| 755 | blelr- |
| 756 | 00: lbzu r5,1(r4) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 757 | 01: stb r5,0(r3) |
| 758 | 02: eieio |
| 759 | ISYNC_8xx |
| 760 | .section .fixup,"ax" |
| 761 | 03: blr |
| 762 | .text |
| 763 | .section __ex_table, "a" |
| 764 | .align 2 |
| 765 | .long 00b, 03b |
| 766 | .long 01b, 03b |
| 767 | .long 02b, 03b |
| 768 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | bdnz 00b |
| 770 | blr |
| 771 | |
| 772 | _GLOBAL(_insw) |
| 773 | cmpwi 0,r5,0 |
| 774 | mtctr r5 |
| 775 | subi r4,r4,2 |
| 776 | blelr- |
| 777 | 00: lhbrx r5,0,r3 |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 778 | 01: eieio |
| 779 | 02: sthu r5,2(r4) |
| 780 | ISYNC_8xx |
| 781 | .section .fixup,"ax" |
| 782 | 03: blr |
| 783 | .text |
| 784 | .section __ex_table, "a" |
| 785 | .align 2 |
| 786 | .long 00b, 03b |
| 787 | .long 01b, 03b |
| 788 | .long 02b, 03b |
| 789 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | bdnz 00b |
| 791 | blr |
| 792 | |
| 793 | _GLOBAL(_outsw) |
| 794 | cmpwi 0,r5,0 |
| 795 | mtctr r5 |
| 796 | subi r4,r4,2 |
| 797 | blelr- |
| 798 | 00: lhzu r5,2(r4) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 799 | 01: eieio |
| 800 | 02: sthbrx r5,0,r3 |
| 801 | ISYNC_8xx |
| 802 | .section .fixup,"ax" |
| 803 | 03: blr |
| 804 | .text |
| 805 | .section __ex_table, "a" |
| 806 | .align 2 |
| 807 | .long 00b, 03b |
| 808 | .long 01b, 03b |
| 809 | .long 02b, 03b |
| 810 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | bdnz 00b |
| 812 | blr |
| 813 | |
| 814 | _GLOBAL(_insl) |
| 815 | cmpwi 0,r5,0 |
| 816 | mtctr r5 |
| 817 | subi r4,r4,4 |
| 818 | blelr- |
| 819 | 00: lwbrx r5,0,r3 |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 820 | 01: eieio |
| 821 | 02: stwu r5,4(r4) |
| 822 | ISYNC_8xx |
| 823 | .section .fixup,"ax" |
| 824 | 03: blr |
| 825 | .text |
| 826 | .section __ex_table, "a" |
| 827 | .align 2 |
| 828 | .long 00b, 03b |
| 829 | .long 01b, 03b |
| 830 | .long 02b, 03b |
| 831 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | bdnz 00b |
| 833 | blr |
| 834 | |
| 835 | _GLOBAL(_outsl) |
| 836 | cmpwi 0,r5,0 |
| 837 | mtctr r5 |
| 838 | subi r4,r4,4 |
| 839 | blelr- |
| 840 | 00: lwzu r5,4(r4) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 841 | 01: stwbrx r5,0,r3 |
| 842 | 02: eieio |
| 843 | ISYNC_8xx |
| 844 | .section .fixup,"ax" |
| 845 | 03: blr |
| 846 | .text |
| 847 | .section __ex_table, "a" |
| 848 | .align 2 |
| 849 | .long 00b, 03b |
| 850 | .long 01b, 03b |
| 851 | .long 02b, 03b |
| 852 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | bdnz 00b |
| 854 | blr |
| 855 | |
| 856 | _GLOBAL(__ide_mm_insw) |
| 857 | _GLOBAL(_insw_ns) |
| 858 | cmpwi 0,r5,0 |
| 859 | mtctr r5 |
| 860 | subi r4,r4,2 |
| 861 | blelr- |
| 862 | 00: lhz r5,0(r3) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 863 | 01: eieio |
| 864 | 02: sthu r5,2(r4) |
| 865 | ISYNC_8xx |
| 866 | .section .fixup,"ax" |
| 867 | 03: blr |
| 868 | .text |
| 869 | .section __ex_table, "a" |
| 870 | .align 2 |
| 871 | .long 00b, 03b |
| 872 | .long 01b, 03b |
| 873 | .long 02b, 03b |
| 874 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | bdnz 00b |
| 876 | blr |
| 877 | |
| 878 | _GLOBAL(__ide_mm_outsw) |
| 879 | _GLOBAL(_outsw_ns) |
| 880 | cmpwi 0,r5,0 |
| 881 | mtctr r5 |
| 882 | subi r4,r4,2 |
| 883 | blelr- |
| 884 | 00: lhzu r5,2(r4) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 885 | 01: sth r5,0(r3) |
| 886 | 02: eieio |
| 887 | ISYNC_8xx |
| 888 | .section .fixup,"ax" |
| 889 | 03: blr |
| 890 | .text |
| 891 | .section __ex_table, "a" |
| 892 | .align 2 |
| 893 | .long 00b, 03b |
| 894 | .long 01b, 03b |
| 895 | .long 02b, 03b |
| 896 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | bdnz 00b |
| 898 | blr |
| 899 | |
| 900 | _GLOBAL(__ide_mm_insl) |
| 901 | _GLOBAL(_insl_ns) |
| 902 | cmpwi 0,r5,0 |
| 903 | mtctr r5 |
| 904 | subi r4,r4,4 |
| 905 | blelr- |
| 906 | 00: lwz r5,0(r3) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 907 | 01: eieio |
| 908 | 02: stwu r5,4(r4) |
| 909 | ISYNC_8xx |
| 910 | .section .fixup,"ax" |
| 911 | 03: blr |
| 912 | .text |
| 913 | .section __ex_table, "a" |
| 914 | .align 2 |
| 915 | .long 00b, 03b |
| 916 | .long 01b, 03b |
| 917 | .long 02b, 03b |
| 918 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | bdnz 00b |
| 920 | blr |
| 921 | |
| 922 | _GLOBAL(__ide_mm_outsl) |
| 923 | _GLOBAL(_outsl_ns) |
| 924 | cmpwi 0,r5,0 |
| 925 | mtctr r5 |
| 926 | subi r4,r4,4 |
| 927 | blelr- |
| 928 | 00: lwzu r5,4(r4) |
Marcelo Tosatti | 55b6332 | 2005-11-05 14:06:24 -0200 | [diff] [blame] | 929 | 01: stw r5,0(r3) |
| 930 | 02: eieio |
| 931 | ISYNC_8xx |
| 932 | .section .fixup,"ax" |
| 933 | 03: blr |
| 934 | .text |
| 935 | .section __ex_table, "a" |
| 936 | .align 2 |
| 937 | .long 00b, 03b |
| 938 | .long 01b, 03b |
| 939 | .long 02b, 03b |
| 940 | .text |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | bdnz 00b |
| 942 | blr |
| 943 | |
| 944 | /* |
| 945 | * Extended precision shifts. |
| 946 | * |
| 947 | * Updated to be valid for shift counts from 0 to 63 inclusive. |
| 948 | * -- Gabriel |
| 949 | * |
| 950 | * R3/R4 has 64 bit value |
| 951 | * R5 has shift count |
| 952 | * result in R3/R4 |
| 953 | * |
| 954 | * ashrdi3: arithmetic right shift (sign propagation) |
| 955 | * lshrdi3: logical right shift |
| 956 | * ashldi3: left shift |
| 957 | */ |
| 958 | _GLOBAL(__ashrdi3) |
| 959 | subfic r6,r5,32 |
| 960 | srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count |
| 961 | addi r7,r5,32 # could be xori, or addi with -32 |
| 962 | slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) |
| 963 | rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0 |
| 964 | sraw r7,r3,r7 # t2 = MSW >> (count-32) |
| 965 | or r4,r4,r6 # LSW |= t1 |
| 966 | slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2 |
| 967 | sraw r3,r3,r5 # MSW = MSW >> count |
| 968 | or r4,r4,r7 # LSW |= t2 |
| 969 | blr |
| 970 | |
| 971 | _GLOBAL(__ashldi3) |
| 972 | subfic r6,r5,32 |
| 973 | slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count |
| 974 | addi r7,r5,32 # could be xori, or addi with -32 |
| 975 | srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count) |
| 976 | slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32) |
| 977 | or r3,r3,r6 # MSW |= t1 |
| 978 | slw r4,r4,r5 # LSW = LSW << count |
| 979 | or r3,r3,r7 # MSW |= t2 |
| 980 | blr |
| 981 | |
| 982 | _GLOBAL(__lshrdi3) |
| 983 | subfic r6,r5,32 |
| 984 | srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count |
| 985 | addi r7,r5,32 # could be xori, or addi with -32 |
| 986 | slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) |
| 987 | srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32) |
| 988 | or r4,r4,r6 # LSW |= t1 |
| 989 | srw r3,r3,r5 # MSW = MSW >> count |
| 990 | or r4,r4,r7 # LSW |= t2 |
| 991 | blr |
| 992 | |
| 993 | _GLOBAL(abs) |
| 994 | srawi r4,r3,31 |
| 995 | xor r3,r3,r4 |
| 996 | sub r3,r3,r4 |
| 997 | blr |
| 998 | |
| 999 | _GLOBAL(_get_SP) |
| 1000 | mr r3,r1 /* Close enough */ |
| 1001 | blr |
| 1002 | |
| 1003 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | * Create a kernel thread |
| 1005 | * kernel_thread(fn, arg, flags) |
| 1006 | */ |
| 1007 | _GLOBAL(kernel_thread) |
| 1008 | stwu r1,-16(r1) |
| 1009 | stw r30,8(r1) |
| 1010 | stw r31,12(r1) |
| 1011 | mr r30,r3 /* function */ |
| 1012 | mr r31,r4 /* argument */ |
| 1013 | ori r3,r5,CLONE_VM /* flags */ |
| 1014 | oris r3,r3,CLONE_UNTRACED>>16 |
| 1015 | li r4,0 /* new sp (unused) */ |
| 1016 | li r0,__NR_clone |
| 1017 | sc |
| 1018 | cmpwi 0,r3,0 /* parent or child? */ |
| 1019 | bne 1f /* return if parent */ |
| 1020 | li r0,0 /* make top-level stack frame */ |
| 1021 | stwu r0,-16(r1) |
| 1022 | mtlr r30 /* fn addr in lr */ |
| 1023 | mr r3,r31 /* load arg and call fn */ |
Matt Porter | c9cf73a | 2005-07-31 22:34:52 -0700 | [diff] [blame] | 1024 | PPC440EP_ERR42 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | blrl |
| 1026 | li r0,__NR_exit /* exit if function returns */ |
| 1027 | li r3,0 |
| 1028 | sc |
| 1029 | 1: lwz r30,8(r1) |
| 1030 | lwz r31,12(r1) |
| 1031 | addi r1,r1,16 |
| 1032 | blr |
| 1033 | |
| 1034 | /* |
| 1035 | * This routine is just here to keep GCC happy - sigh... |
| 1036 | */ |
| 1037 | _GLOBAL(__main) |
| 1038 | blr |
| 1039 | |
| 1040 | #define SYSCALL(name) \ |
| 1041 | _GLOBAL(name) \ |
| 1042 | li r0,__NR_##name; \ |
| 1043 | sc; \ |
| 1044 | bnslr; \ |
| 1045 | lis r4,errno@ha; \ |
| 1046 | stw r3,errno@l(r4); \ |
| 1047 | li r3,-1; \ |
| 1048 | blr |
| 1049 | |
| 1050 | SYSCALL(execve) |