Merge branch 'merge' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc...
[deliverable/linux.git] / arch / powerpc / kernel / misc_32.S
CommitLineData
9994a338
PM
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 *
3d1229d6
ME
8 * kexec bits:
9 * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
10 * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
11 *
9994a338
PM
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 *
17 */
18
9994a338
PM
19#include <linux/sys.h>
20#include <asm/unistd.h>
21#include <asm/errno.h>
22#include <asm/reg.h>
23#include <asm/page.h>
24#include <asm/cache.h>
25#include <asm/cputable.h>
26#include <asm/mmu.h>
27#include <asm/ppc_asm.h>
28#include <asm/thread_info.h>
29#include <asm/asm-offsets.h>
3d1229d6
ME
30#include <asm/processor.h>
31#include <asm/kexec.h>
9994a338
PM
32
33 .text
34
85218827
KG
35#ifdef CONFIG_IRQSTACKS
36_GLOBAL(call_do_softirq)
37 mflr r0
38 stw r0,4(r1)
39 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
40 mr r1,r3
41 bl __do_softirq
42 lwz r1,0(r1)
43 lwz r0,4(r1)
44 mtlr r0
45 blr
46
47_GLOBAL(call_handle_irq)
48 mflr r0
49 stw r0,4(r1)
50 mtctr r6
51 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r5)
52 mr r1,r5
53 bctrl
54 lwz r1,0(r1)
55 lwz r0,4(r1)
56 mtlr r0
57 blr
58#endif /* CONFIG_IRQSTACKS */
59
f2783c15
PM
60/*
61 * This returns the high 64 bits of the product of two 64-bit numbers.
62 */
63_GLOBAL(mulhdu)
64 cmpwi r6,0
65 cmpwi cr1,r3,0
66 mr r10,r4
67 mulhwu r4,r4,r5
68 beq 1f
69 mulhwu r0,r10,r6
70 mullw r7,r10,r5
71 addc r7,r0,r7
72 addze r4,r4
731: beqlr cr1 /* all done if high part of A is 0 */
74 mr r10,r3
75 mullw r9,r3,r5
76 mulhwu r3,r3,r5
77 beq 2f
78 mullw r0,r10,r6
79 mulhwu r8,r10,r6
80 addc r7,r0,r7
81 adde r4,r4,r8
82 addze r3,r3
832: addc r4,r4,r9
84 addze r3,r3
85 blr
86
9994a338
PM
87/*
88 * sub_reloc_offset(x) returns x - reloc_offset().
89 */
90_GLOBAL(sub_reloc_offset)
91 mflr r0
92 bl 1f
931: mflr r5
94 lis r4,1b@ha
95 addi r4,r4,1b@l
96 subf r5,r4,r5
97 subf r3,r5,r3
98 mtlr r0
99 blr
100
101/*
102 * reloc_got2 runs through the .got2 section adding an offset
103 * to each entry.
104 */
105_GLOBAL(reloc_got2)
106 mflr r11
107 lis r7,__got2_start@ha
108 addi r7,r7,__got2_start@l
109 lis r8,__got2_end@ha
110 addi r8,r8,__got2_end@l
111 subf r8,r7,r8
112 srwi. r8,r8,2
113 beqlr
114 mtctr r8
115 bl 1f
1161: mflr r0
117 lis r4,1b@ha
118 addi r4,r4,1b@l
119 subf r0,r4,r0
120 add r7,r0,r7
1212: lwz r0,0(r7)
122 add r0,r0,r3
123 stw r0,0(r7)
124 addi r7,r7,4
125 bdnz 2b
126 mtlr r11
127 blr
128
9994a338
PM
129/*
130 * call_setup_cpu - call the setup_cpu function for this cpu
131 * r3 = data offset, r24 = cpu number
132 *
133 * Setup function is called with:
134 * r3 = data offset
135 * r4 = ptr to CPU spec (relocated)
136 */
137_GLOBAL(call_setup_cpu)
138 addis r4,r3,cur_cpu_spec@ha
139 addi r4,r4,cur_cpu_spec@l
140 lwz r4,0(r4)
141 add r4,r4,r3
142 lwz r5,CPU_SPEC_SETUP(r4)
b26f100d 143 cmpwi 0,r5,0
9994a338
PM
144 add r5,r5,r3
145 beqlr
146 mtctr r5
147 bctr
148
149#if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_6xx)
150
151/* This gets called by via-pmu.c to switch the PLL selection
152 * on 750fx CPU. This function should really be moved to some
153 * other place (as most of the cpufreq code in via-pmu
154 */
155_GLOBAL(low_choose_750fx_pll)
156 /* Clear MSR:EE */
157 mfmsr r7
158 rlwinm r0,r7,0,17,15
159 mtmsr r0
160
161 /* If switching to PLL1, disable HID0:BTIC */
162 cmplwi cr0,r3,0
163 beq 1f
164 mfspr r5,SPRN_HID0
165 rlwinm r5,r5,0,27,25
166 sync
167 mtspr SPRN_HID0,r5
168 isync
169 sync
170
1711:
172 /* Calc new HID1 value */
173 mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
174 rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
175 rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
176 or r4,r4,r5
177 mtspr SPRN_HID1,r4
178
179 /* Store new HID1 image */
f608600e 180 rlwinm r6,r1,0,0,(31-THREAD_SHIFT)
9994a338
PM
181 lwz r6,TI_CPU(r6)
182 slwi r6,r6,2
183 addis r6,r6,nap_save_hid1@ha
184 stw r4,nap_save_hid1@l(r6)
185
186 /* If switching to PLL0, enable HID0:BTIC */
187 cmplwi cr0,r3,0
188 bne 1f
189 mfspr r5,SPRN_HID0
190 ori r5,r5,HID0_BTIC
191 sync
192 mtspr SPRN_HID0,r5
193 isync
194 sync
195
1961:
197 /* Return */
198 mtmsr r7
199 blr
200
201_GLOBAL(low_choose_7447a_dfs)
202 /* Clear MSR:EE */
203 mfmsr r7
204 rlwinm r0,r7,0,17,15
205 mtmsr r0
206
207 /* Calc new HID1 value */
208 mfspr r4,SPRN_HID1
209 insrwi r4,r3,1,9 /* insert parameter into bit 9 */
210 sync
211 mtspr SPRN_HID1,r4
212 sync
213 isync
214
215 /* Return */
216 mtmsr r7
217 blr
218
219#endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_6xx */
220
221/*
222 * complement mask on the msr then "or" some values on.
223 * _nmask_and_or_msr(nmask, value_to_or)
224 */
225_GLOBAL(_nmask_and_or_msr)
226 mfmsr r0 /* Get current msr */
227 andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
228 or r0,r0,r4 /* Or on the bits in r4 (second parm) */
229 SYNC /* Some chip revs have problems here... */
230 mtmsr r0 /* Update machine state */
231 isync
232 blr /* Done */
233
9dae8afd
BH
234#ifdef CONFIG_40x
235
236/*
237 * Do an IO access in real mode
238 */
239_GLOBAL(real_readb)
240 mfmsr r7
241 ori r0,r7,MSR_DR
242 xori r0,r0,MSR_DR
243 sync
244 mtmsr r0
245 sync
246 isync
247 lbz r3,0(r3)
248 sync
249 mtmsr r7
250 sync
251 isync
252 blr
253
254 /*
255 * Do an IO access in real mode
256 */
257_GLOBAL(real_writeb)
258 mfmsr r7
259 ori r0,r7,MSR_DR
260 xori r0,r0,MSR_DR
261 sync
262 mtmsr r0
263 sync
264 isync
265 stb r3,0(r4)
266 sync
267 mtmsr r7
268 sync
269 isync
270 blr
271
272#endif /* CONFIG_40x */
9994a338
PM
273
274/*
275 * Flush MMU TLB
276 */
0ba3418b
KG
277#ifndef CONFIG_FSL_BOOKE
278_GLOBAL(_tlbil_all)
279_GLOBAL(_tlbil_pid)
280#endif
9994a338
PM
281_GLOBAL(_tlbia)
282#if defined(CONFIG_40x)
283 sync /* Flush to memory before changing mapping */
284 tlbia
285 isync /* Flush shadow TLB */
286#elif defined(CONFIG_44x)
287 li r3,0
288 sync
289
290 /* Load high watermark */
291 lis r4,tlb_44x_hwater@ha
292 lwz r5,tlb_44x_hwater@l(r4)
293
2941: tlbwe r3,r3,PPC44x_TLB_PAGEID
295 addi r3,r3,1
296 cmpw 0,r3,r5
297 ble 1b
298
299 isync
300#elif defined(CONFIG_FSL_BOOKE)
301 /* Invalidate all entries in TLB0 */
302 li r3, 0x04
303 tlbivax 0,3
304 /* Invalidate all entries in TLB1 */
305 li r3, 0x0c
306 tlbivax 0,3
9994a338
PM
307 msync
308#ifdef CONFIG_SMP
309 tlbsync
310#endif /* CONFIG_SMP */
311#else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
312#if defined(CONFIG_SMP)
f608600e 313 rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
9994a338
PM
314 lwz r8,TI_CPU(r8)
315 oris r8,r8,10
316 mfmsr r10
317 SYNC
318 rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
319 rlwinm r0,r0,0,28,26 /* clear DR */
320 mtmsr r0
321 SYNC_601
322 isync
323 lis r9,mmu_hash_lock@h
324 ori r9,r9,mmu_hash_lock@l
325 tophys(r9,r9)
32610: lwarx r7,0,r9
327 cmpwi 0,r7,0
328 bne- 10b
329 stwcx. r8,0,r9
330 bne- 10b
331 sync
332 tlbia
333 sync
334 TLBSYNC
335 li r0,0
336 stw r0,0(r9) /* clear mmu_hash_lock */
337 mtmsr r10
338 SYNC_601
339 isync
340#else /* CONFIG_SMP */
341 sync
342 tlbia
343 sync
344#endif /* CONFIG_SMP */
345#endif /* ! defined(CONFIG_40x) */
346 blr
347
348/*
349 * Flush MMU TLB for a particular address
350 */
0ba3418b
KG
351#ifndef CONFIG_FSL_BOOKE
352_GLOBAL(_tlbil_va)
353#endif
9994a338
PM
354_GLOBAL(_tlbie)
355#if defined(CONFIG_40x)
e701d269
BH
356 /* We run the search with interrupts disabled because we have to change
357 * the PID and I don't want to preempt when that happens.
358 */
359 mfmsr r5
360 mfspr r6,SPRN_PID
361 wrteei 0
362 mtspr SPRN_PID,r4
9994a338 363 tlbsx. r3, 0, r3
e701d269
BH
364 mtspr SPRN_PID,r6
365 wrtee r5
9994a338
PM
366 bne 10f
367 sync
368 /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is clear.
369 * Since 25 is the V bit in the TLB_TAG, loading this value will invalidate
370 * the TLB entry. */
371 tlbwe r3, r3, TLB_TAG
372 isync
37310:
e701d269 374
9994a338 375#elif defined(CONFIG_44x)
e701d269
BH
376 mfspr r5,SPRN_MMUCR
377 rlwimi r5,r4,0,24,31 /* Set TID */
9994a338 378
aa1cf632
DG
379 /* We have to run the search with interrupts disabled, even critical
380 * and debug interrupts (in fact the only critical exceptions we have
381 * are debug and machine check). Otherwise an interrupt which causes
382 * a TLB miss can clobber the MMUCR between the mtspr and the tlbsx. */
e701d269 383 mfmsr r4
aa1cf632
DG
384 lis r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@ha
385 addi r6,r6,(MSR_EE|MSR_CE|MSR_ME|MSR_DE)@l
e701d269 386 andc r6,r4,r6
aa1cf632 387 mtmsr r6
e701d269 388 mtspr SPRN_MMUCR,r5
9994a338 389 tlbsx. r3, 0, r3
e701d269 390 mtmsr r4
9994a338
PM
391 bne 10f
392 sync
393 /* There are only 64 TLB entries, so r3 < 64,
394 * which means bit 22, is clear. Since 22 is
395 * the V bit in the TLB_PAGEID, loading this
396 * value will invalidate the TLB entry.
397 */
398 tlbwe r3, r3, PPC44x_TLB_PAGEID
399 isync
40010:
401#elif defined(CONFIG_FSL_BOOKE)
402 rlwinm r4, r3, 0, 0, 19
403 ori r5, r4, 0x08 /* TLBSEL = 1 */
9994a338
PM
404 tlbivax 0, r4
405 tlbivax 0, r5
9994a338
PM
406 msync
407#if defined(CONFIG_SMP)
408 tlbsync
409#endif /* CONFIG_SMP */
410#else /* !(CONFIG_40x || CONFIG_44x || CONFIG_FSL_BOOKE) */
411#if defined(CONFIG_SMP)
f608600e 412 rlwinm r8,r1,0,0,(31-THREAD_SHIFT)
9994a338
PM
413 lwz r8,TI_CPU(r8)
414 oris r8,r8,11
415 mfmsr r10
416 SYNC
417 rlwinm r0,r10,0,17,15 /* clear bit 16 (MSR_EE) */
418 rlwinm r0,r0,0,28,26 /* clear DR */
419 mtmsr r0
420 SYNC_601
421 isync
422 lis r9,mmu_hash_lock@h
423 ori r9,r9,mmu_hash_lock@l
424 tophys(r9,r9)
42510: lwarx r7,0,r9
426 cmpwi 0,r7,0
427 bne- 10b
428 stwcx. r8,0,r9
429 bne- 10b
430 eieio
431 tlbie r3
432 sync
433 TLBSYNC
434 li r0,0
435 stw r0,0(r9) /* clear mmu_hash_lock */
436 mtmsr r10
437 SYNC_601
438 isync
439#else /* CONFIG_SMP */
440 tlbie r3
441 sync
442#endif /* CONFIG_SMP */
443#endif /* ! CONFIG_40x */
444 blr
445
0ba3418b
KG
446#if defined(CONFIG_FSL_BOOKE)
447/*
448 * Flush MMU TLB, but only on the local processor (no broadcast)
449 */
450_GLOBAL(_tlbil_all)
451#define MMUCSR0_TLBFI (MMUCSR0_TLB0FI | MMUCSR0_TLB1FI | \
452 MMUCSR0_TLB2FI | MMUCSR0_TLB3FI)
453 li r3,(MMUCSR0_TLBFI)@l
454 mtspr SPRN_MMUCSR0, r3
4551:
456 mfspr r3,SPRN_MMUCSR0
457 andi. r3,r3,MMUCSR0_TLBFI@l
458 bne 1b
459 blr
460
461/*
462 * Flush MMU TLB for a particular process id, but only on the local processor
463 * (no broadcast)
464 */
465_GLOBAL(_tlbil_pid)
466/* we currently do an invalidate all since we don't have per pid invalidate */
467 li r3,(MMUCSR0_TLBFI)@l
468 mtspr SPRN_MMUCSR0, r3
4691:
470 mfspr r3,SPRN_MMUCSR0
471 andi. r3,r3,MMUCSR0_TLBFI@l
472 bne 1b
b41d6fee
KG
473 msync
474 isync
0ba3418b
KG
475 blr
476
477/*
478 * Flush MMU TLB for a particular address, but only on the local processor
479 * (no broadcast)
480 */
481_GLOBAL(_tlbil_va)
482 slwi r4,r4,16
483 mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
484 tlbsx 0,r3
485 mfspr r4,SPRN_MAS1 /* check valid */
486 andis. r3,r4,MAS1_VALID@h
487 beqlr
488 rlwinm r4,r4,0,1,31
489 mtspr SPRN_MAS1,r4
490 tlbwe
b41d6fee
KG
491 msync
492 isync
0ba3418b
KG
493 blr
494#endif /* CONFIG_FSL_BOOKE */
495
496
9994a338
PM
497/*
498 * Flush instruction cache.
499 * This is a no-op on the 601.
500 */
501_GLOBAL(flush_instruction_cache)
502#if defined(CONFIG_8xx)
503 isync
504 lis r5, IDC_INVALL@h
505 mtspr SPRN_IC_CST, r5
506#elif defined(CONFIG_4xx)
507#ifdef CONFIG_403GCX
508 li r3, 512
509 mtctr r3
510 lis r4, KERNELBASE@h
5111: iccci 0, r4
512 addi r4, r4, 16
513 bdnz 1b
514#else
515 lis r3, KERNELBASE@h
516 iccci 0,r3
517#endif
518#elif CONFIG_FSL_BOOKE
519BEGIN_FTR_SECTION
520 mfspr r3,SPRN_L1CSR0
521 ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
522 /* msync; isync recommended here */
523 mtspr SPRN_L1CSR0,r3
524 isync
525 blr
4508dc21 526END_FTR_SECTION_IFSET(CPU_FTR_UNIFIED_ID_CACHE)
9994a338
PM
527 mfspr r3,SPRN_L1CSR1
528 ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
529 mtspr SPRN_L1CSR1,r3
530#else
531 mfspr r3,SPRN_PVR
532 rlwinm r3,r3,16,16,31
533 cmpwi 0,r3,1
534 beqlr /* for 601, do nothing */
535 /* 603/604 processor - use invalidate-all bit in HID0 */
536 mfspr r3,SPRN_HID0
537 ori r3,r3,HID0_ICFI
538 mtspr SPRN_HID0,r3
539#endif /* CONFIG_8xx/4xx */
540 isync
541 blr
542
543/*
544 * Write any modified data cache blocks out to memory
545 * and invalidate the corresponding instruction cache blocks.
546 * This is a no-op on the 601.
547 *
548 * flush_icache_range(unsigned long start, unsigned long stop)
549 */
b76e59d1 550_KPROBE(__flush_icache_range)
9994a338
PM
551BEGIN_FTR_SECTION
552 blr /* for 601, do nothing */
4508dc21 553END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
7dffb720 554 li r5,L1_CACHE_BYTES-1
9994a338
PM
555 andc r3,r3,r5
556 subf r4,r3,r4
557 add r4,r4,r5
7dffb720 558 srwi. r4,r4,L1_CACHE_SHIFT
9994a338
PM
559 beqlr
560 mtctr r4
561 mr r6,r3
5621: dcbst 0,r3
7dffb720 563 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
564 bdnz 1b
565 sync /* wait for dcbst's to get to ram */
566 mtctr r4
5672: icbi 0,r6
7dffb720 568 addi r6,r6,L1_CACHE_BYTES
9994a338
PM
569 bdnz 2b
570 sync /* additional sync needed on g4 */
571 isync
572 blr
573/*
574 * Write any modified data cache blocks out to memory.
575 * Does not invalidate the corresponding cache lines (especially for
576 * any corresponding instruction cache).
577 *
578 * clean_dcache_range(unsigned long start, unsigned long stop)
579 */
580_GLOBAL(clean_dcache_range)
7dffb720 581 li r5,L1_CACHE_BYTES-1
9994a338
PM
582 andc r3,r3,r5
583 subf r4,r3,r4
584 add r4,r4,r5
7dffb720 585 srwi. r4,r4,L1_CACHE_SHIFT
9994a338
PM
586 beqlr
587 mtctr r4
588
5891: dcbst 0,r3
7dffb720 590 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
591 bdnz 1b
592 sync /* wait for dcbst's to get to ram */
593 blr
594
595/*
596 * Write any modified data cache blocks out to memory and invalidate them.
597 * Does not invalidate the corresponding instruction cache blocks.
598 *
599 * flush_dcache_range(unsigned long start, unsigned long stop)
600 */
601_GLOBAL(flush_dcache_range)
7dffb720 602 li r5,L1_CACHE_BYTES-1
9994a338
PM
603 andc r3,r3,r5
604 subf r4,r3,r4
605 add r4,r4,r5
7dffb720 606 srwi. r4,r4,L1_CACHE_SHIFT
9994a338
PM
607 beqlr
608 mtctr r4
609
6101: dcbf 0,r3
7dffb720 611 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
612 bdnz 1b
613 sync /* wait for dcbst's to get to ram */
614 blr
615
616/*
617 * Like above, but invalidate the D-cache. This is used by the 8xx
618 * to invalidate the cache so the PPC core doesn't get stale data
619 * from the CPM (no cache snooping here :-).
620 *
621 * invalidate_dcache_range(unsigned long start, unsigned long stop)
622 */
623_GLOBAL(invalidate_dcache_range)
7dffb720 624 li r5,L1_CACHE_BYTES-1
9994a338
PM
625 andc r3,r3,r5
626 subf r4,r3,r4
627 add r4,r4,r5
7dffb720 628 srwi. r4,r4,L1_CACHE_SHIFT
9994a338
PM
629 beqlr
630 mtctr r4
631
6321: dcbi 0,r3
7dffb720 633 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
634 bdnz 1b
635 sync /* wait for dcbi's to get to ram */
636 blr
637
9994a338
PM
638/*
639 * Flush a particular page from the data cache to RAM.
640 * Note: this is necessary because the instruction cache does *not*
641 * snoop from the data cache.
642 * This is a no-op on the 601 which has a unified cache.
643 *
644 * void __flush_dcache_icache(void *page)
645 */
646_GLOBAL(__flush_dcache_icache)
647BEGIN_FTR_SECTION
4508dc21
DG
648 blr
649END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
9994a338 650 rlwinm r3,r3,0,0,19 /* Get page base address */
7dffb720 651 li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
9994a338
PM
652 mtctr r4
653 mr r6,r3
6540: dcbst 0,r3 /* Write line to ram */
7dffb720 655 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
656 bdnz 0b
657 sync
b98ac05d
BH
658#ifndef CONFIG_44x
659 /* We don't flush the icache on 44x. Those have a virtual icache
660 * and we don't have access to the virtual address here (it's
661 * not the page vaddr but where it's mapped in user space). The
662 * flushing of the icache on these is handled elsewhere, when
663 * a change in the address space occurs, before returning to
664 * user space
665 */
9994a338
PM
666 mtctr r4
6671: icbi 0,r6
7dffb720 668 addi r6,r6,L1_CACHE_BYTES
9994a338
PM
669 bdnz 1b
670 sync
671 isync
b98ac05d 672#endif /* CONFIG_44x */
9994a338
PM
673 blr
674
675/*
676 * Flush a particular page from the data cache to RAM, identified
677 * by its physical address. We turn off the MMU so we can just use
678 * the physical address (this may be a highmem page without a kernel
679 * mapping).
680 *
681 * void __flush_dcache_icache_phys(unsigned long physaddr)
682 */
683_GLOBAL(__flush_dcache_icache_phys)
684BEGIN_FTR_SECTION
685 blr /* for 601, do nothing */
4508dc21 686END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE)
9994a338
PM
687 mfmsr r10
688 rlwinm r0,r10,0,28,26 /* clear DR */
689 mtmsr r0
690 isync
691 rlwinm r3,r3,0,0,19 /* Get page base address */
7dffb720 692 li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
9994a338
PM
693 mtctr r4
694 mr r6,r3
6950: dcbst 0,r3 /* Write line to ram */
7dffb720 696 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
697 bdnz 0b
698 sync
699 mtctr r4
7001: icbi 0,r6
7dffb720 701 addi r6,r6,L1_CACHE_BYTES
9994a338
PM
702 bdnz 1b
703 sync
704 mtmsr r10 /* restore DR */
705 isync
706 blr
707
708/*
709 * Clear pages using the dcbz instruction, which doesn't cause any
710 * memory traffic (except to write out any cache lines which get
711 * displaced). This only works on cacheable memory.
712 *
713 * void clear_pages(void *page, int order) ;
714 */
715_GLOBAL(clear_pages)
7dffb720 716 li r0,4096/L1_CACHE_BYTES
9994a338
PM
717 slw r0,r0,r4
718 mtctr r0
719#ifdef CONFIG_8xx
720 li r4, 0
7211: stw r4, 0(r3)
722 stw r4, 4(r3)
723 stw r4, 8(r3)
724 stw r4, 12(r3)
725#else
7261: dcbz 0,r3
727#endif
7dffb720 728 addi r3,r3,L1_CACHE_BYTES
9994a338
PM
729 bdnz 1b
730 blr
731
732/*
733 * Copy a whole page. We use the dcbz instruction on the destination
734 * to reduce memory traffic (it eliminates the unnecessary reads of
735 * the destination into cache). This requires that the destination
736 * is cacheable.
737 */
738#define COPY_16_BYTES \
739 lwz r6,4(r4); \
740 lwz r7,8(r4); \
741 lwz r8,12(r4); \
742 lwzu r9,16(r4); \
743 stw r6,4(r3); \
744 stw r7,8(r3); \
745 stw r8,12(r3); \
746 stwu r9,16(r3)
747
748_GLOBAL(copy_page)
749 addi r3,r3,-4
750 addi r4,r4,-4
751
752#ifdef CONFIG_8xx
753 /* don't use prefetch on 8xx */
7dffb720 754 li r0,4096/L1_CACHE_BYTES
9994a338
PM
755 mtctr r0
7561: COPY_16_BYTES
757 bdnz 1b
758 blr
759
760#else /* not 8xx, we can prefetch */
761 li r5,4
762
763#if MAX_COPY_PREFETCH > 1
764 li r0,MAX_COPY_PREFETCH
765 li r11,4
766 mtctr r0
76711: dcbt r11,r4
7dffb720 768 addi r11,r11,L1_CACHE_BYTES
9994a338
PM
769 bdnz 11b
770#else /* MAX_COPY_PREFETCH == 1 */
771 dcbt r5,r4
7dffb720 772 li r11,L1_CACHE_BYTES+4
9994a338 773#endif /* MAX_COPY_PREFETCH */
7dffb720 774 li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
9994a338
PM
775 crclr 4*cr0+eq
7762:
777 mtctr r0
7781:
779 dcbt r11,r4
780 dcbz r5,r3
781 COPY_16_BYTES
7dffb720 782#if L1_CACHE_BYTES >= 32
9994a338 783 COPY_16_BYTES
7dffb720 784#if L1_CACHE_BYTES >= 64
9994a338
PM
785 COPY_16_BYTES
786 COPY_16_BYTES
7dffb720 787#if L1_CACHE_BYTES >= 128
9994a338
PM
788 COPY_16_BYTES
789 COPY_16_BYTES
790 COPY_16_BYTES
791 COPY_16_BYTES
792#endif
793#endif
794#endif
795 bdnz 1b
796 beqlr
797 crnot 4*cr0+eq,4*cr0+eq
798 li r0,MAX_COPY_PREFETCH
799 li r11,4
800 b 2b
801#endif /* CONFIG_8xx */
802
803/*
804 * void atomic_clear_mask(atomic_t mask, atomic_t *addr)
805 * void atomic_set_mask(atomic_t mask, atomic_t *addr);
806 */
807_GLOBAL(atomic_clear_mask)
80810: lwarx r5,0,r4
809 andc r5,r5,r3
810 PPC405_ERR77(0,r4)
811 stwcx. r5,0,r4
812 bne- 10b
813 blr
814_GLOBAL(atomic_set_mask)
81510: lwarx r5,0,r4
816 or r5,r5,r3
817 PPC405_ERR77(0,r4)
818 stwcx. r5,0,r4
819 bne- 10b
820 blr
821
9994a338
PM
822/*
823 * Extended precision shifts.
824 *
825 * Updated to be valid for shift counts from 0 to 63 inclusive.
826 * -- Gabriel
827 *
828 * R3/R4 has 64 bit value
829 * R5 has shift count
830 * result in R3/R4
831 *
832 * ashrdi3: arithmetic right shift (sign propagation)
833 * lshrdi3: logical right shift
834 * ashldi3: left shift
835 */
836_GLOBAL(__ashrdi3)
837 subfic r6,r5,32
838 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
839 addi r7,r5,32 # could be xori, or addi with -32
840 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
841 rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
842 sraw r7,r3,r7 # t2 = MSW >> (count-32)
843 or r4,r4,r6 # LSW |= t1
844 slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
845 sraw r3,r3,r5 # MSW = MSW >> count
846 or r4,r4,r7 # LSW |= t2
847 blr
848
849_GLOBAL(__ashldi3)
850 subfic r6,r5,32
851 slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
852 addi r7,r5,32 # could be xori, or addi with -32
853 srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
854 slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
855 or r3,r3,r6 # MSW |= t1
856 slw r4,r4,r5 # LSW = LSW << count
857 or r3,r3,r7 # MSW |= t2
858 blr
859
860_GLOBAL(__lshrdi3)
861 subfic r6,r5,32
862 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
863 addi r7,r5,32 # could be xori, or addi with -32
864 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
865 srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
866 or r4,r4,r6 # LSW |= t1
867 srw r3,r3,r5 # MSW = MSW >> count
868 or r4,r4,r7 # LSW |= t2
869 blr
870
95ff54f5
PM
871/*
872 * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
873 * Returns 0 if a < b, 1 if a == b, 2 if a > b.
874 */
875_GLOBAL(__ucmpdi2)
876 cmplw r3,r5
877 li r3,1
878 bne 1f
879 cmplw r4,r6
880 beqlr
8811: li r3,0
882 bltlr
883 li r3,2
884 blr
885
9994a338
PM
886_GLOBAL(abs)
887 srawi r4,r3,31
888 xor r3,r3,r4
889 sub r3,r3,r4
890 blr
891
9994a338
PM
892/*
893 * Create a kernel thread
894 * kernel_thread(fn, arg, flags)
895 */
896_GLOBAL(kernel_thread)
897 stwu r1,-16(r1)
898 stw r30,8(r1)
899 stw r31,12(r1)
900 mr r30,r3 /* function */
901 mr r31,r4 /* argument */
902 ori r3,r5,CLONE_VM /* flags */
903 oris r3,r3,CLONE_UNTRACED>>16
904 li r4,0 /* new sp (unused) */
905 li r0,__NR_clone
906 sc
41c2e949
JP
907 bns+ 1f /* did system call indicate error? */
908 neg r3,r3 /* if so, make return code negative */
9091: cmpwi 0,r3,0 /* parent or child? */
910 bne 2f /* return if parent */
9994a338
PM
911 li r0,0 /* make top-level stack frame */
912 stwu r0,-16(r1)
913 mtlr r30 /* fn addr in lr */
914 mr r3,r31 /* load arg and call fn */
915 PPC440EP_ERR42
916 blrl
917 li r0,__NR_exit /* exit if function returns */
918 li r3,0
919 sc
41c2e949 9202: lwz r30,8(r1)
9994a338
PM
921 lwz r31,12(r1)
922 addi r1,r1,16
923 blr
924
9994a338
PM
925/*
926 * This routine is just here to keep GCC happy - sigh...
927 */
928_GLOBAL(__main)
929 blr
3d1229d6
ME
930
931#ifdef CONFIG_KEXEC
932 /*
933 * Must be relocatable PIC code callable as a C function.
934 */
935 .globl relocate_new_kernel
936relocate_new_kernel:
937 /* r3 = page_list */
938 /* r4 = reboot_code_buffer */
939 /* r5 = start_address */
940
941 li r0, 0
942
943 /*
944 * Set Machine Status Register to a known status,
945 * switch the MMU off and jump to 1: in a single step.
946 */
947
948 mr r8, r0
949 ori r8, r8, MSR_RI|MSR_ME
950 mtspr SPRN_SRR1, r8
951 addi r8, r4, 1f - relocate_new_kernel
952 mtspr SPRN_SRR0, r8
953 sync
954 rfi
955
9561:
957 /* from this point address translation is turned off */
958 /* and interrupts are disabled */
959
960 /* set a new stack at the bottom of our page... */
961 /* (not really needed now) */
d9178f4c 962 addi r1, r4, KEXEC_CONTROL_PAGE_SIZE - 8 /* for LR Save+Back Chain */
3d1229d6
ME
963 stw r0, 0(r1)
964
965 /* Do the copies */
966 li r6, 0 /* checksum */
967 mr r0, r3
968 b 1f
969
9700: /* top, read another word for the indirection page */
971 lwzu r0, 4(r3)
972
9731:
974 /* is it a destination page? (r8) */
975 rlwinm. r7, r0, 0, 31, 31 /* IND_DESTINATION (1<<0) */
976 beq 2f
977
978 rlwinm r8, r0, 0, 0, 19 /* clear kexec flags, page align */
979 b 0b
980
9812: /* is it an indirection page? (r3) */
982 rlwinm. r7, r0, 0, 30, 30 /* IND_INDIRECTION (1<<1) */
983 beq 2f
984
985 rlwinm r3, r0, 0, 0, 19 /* clear kexec flags, page align */
986 subi r3, r3, 4
987 b 0b
988
9892: /* are we done? */
990 rlwinm. r7, r0, 0, 29, 29 /* IND_DONE (1<<2) */
991 beq 2f
992 b 3f
993
9942: /* is it a source page? (r9) */
995 rlwinm. r7, r0, 0, 28, 28 /* IND_SOURCE (1<<3) */
996 beq 0b
997
998 rlwinm r9, r0, 0, 0, 19 /* clear kexec flags, page align */
999
1000 li r7, PAGE_SIZE / 4
1001 mtctr r7
1002 subi r9, r9, 4
1003 subi r8, r8, 4
10049:
1005 lwzu r0, 4(r9) /* do the copy */
1006 xor r6, r6, r0
1007 stwu r0, 4(r8)
1008 dcbst 0, r8
1009 sync
1010 icbi 0, r8
1011 bdnz 9b
1012
1013 addi r9, r9, 4
1014 addi r8, r8, 4
1015 b 0b
1016
10173:
1018
1019 /* To be certain of avoiding problems with self-modifying code
1020 * execute a serializing instruction here.
1021 */
1022 isync
1023 sync
1024
1025 /* jump to the entry point, usually the setup routine */
1026 mtlr r5
1027 blrl
1028
10291: b 1b
1030
1031relocate_new_kernel_end:
1032
1033 .globl relocate_new_kernel_size
1034relocate_new_kernel_size:
1035 .long relocate_new_kernel_end - relocate_new_kernel
1036#endif
This page took 0.335583 seconds and 5 git commands to generate.