blob: 5a936566fd6155bdf1b4ba71ba26164e7d2eef63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Ravnborg0013a852005-09-09 20:57:26 +020026#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Marcelo Tosatti55b63322005-11-05 14:06:24 -020028#ifdef CONFIG_8xx
29#define ISYNC_8xx isync
30#else
31#define ISYNC_8xx
32#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 .text
34
35 .align 5
36_GLOBAL(__delay)
37 cmpwi 0,r3,0
38 mtctr r3
39 beqlr
401: 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
501: 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
631: 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
771: 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
1001: mflr r0
101 lis r4,1b@ha
102 addi r4,r4,1b@l
103 subf r0,r4,r0
104 add r7,r0,r7
1052: 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
1221:
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
1301:
131 addis r6,r3,cur_cpu_spec@ha
132 addi r6,r6,cur_cpu_spec@l
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 sub r8,r8,r3
Kumar Gala400d2212005-09-27 15:13:12 -0500134 stw r8,0(r6)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 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 */
1571: 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 */
1753: 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
1812: 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 Gala400d2212005-09-27 15:13:12 -0500193 * r4 = ptr to CPU spec (relocated)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 */
195_GLOBAL(call_setup_cpu)
Kumar Gala400d2212005-09-27 15:13:12 -0500196 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 Torvalds1da177e2005-04-16 15:20:36 -0700202 add r5,r5,r3
Kumar Gala400d2212005-09-27 15:13:12 -0500203 beqlr
204 mtctr r5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 bctr
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*
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
2371: 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)
27510: 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
31010:
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
32710:
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)
35610: 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
3911: 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 Gala33d9e9b2005-06-25 14:54:37 -0700399BEGIN_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
406END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 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 Gibson26ef5c02005-11-10 11:50:16 +1100428 * __flush_icache_range(unsigned long start, unsigned long stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 */
David Gibson26ef5c02005-11-10 11:50:16 +1100430_GLOBAL(__flush_icache_range)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431BEGIN_FTR_SECTION
432 blr /* for 601, do nothing */
Kumar Gala4481e8e2005-06-06 13:35:57 -0700433END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000434 li r5,L1_CACHE_BYTES-1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 andc r3,r3,r5
436 subf r4,r3,r4
437 add r4,r4,r5
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000438 srwi. r4,r4,L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 beqlr
440 mtctr r4
441 mr r6,r3
4421: dcbst 0,r3
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000443 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 bdnz 1b
445 sync /* wait for dcbst's to get to ram */
446 mtctr r4
4472: icbi 0,r6
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000448 addi r6,r6,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 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 Rothwell7dffb722005-10-17 11:50:32 +1000461 li r5,L1_CACHE_BYTES-1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 andc r3,r3,r5
463 subf r4,r3,r4
464 add r4,r4,r5
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000465 srwi. r4,r4,L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 beqlr
467 mtctr r4
468
4691: dcbst 0,r3
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000470 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 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 Rothwell7dffb722005-10-17 11:50:32 +1000482 li r5,L1_CACHE_BYTES-1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 andc r3,r3,r5
484 subf r4,r3,r4
485 add r4,r4,r5
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000486 srwi. r4,r4,L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 beqlr
488 mtctr r4
489
4901: dcbf 0,r3
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000491 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 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 Rothwell7dffb722005-10-17 11:50:32 +1000504 li r5,L1_CACHE_BYTES-1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 andc r3,r3,r5
506 subf r4,r3,r4
507 add r4,r4,r5
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000508 srwi. r4,r4,L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 beqlr
510 mtctr r4
511
5121: dcbi 0,r3
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000513 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 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
5331: lwz r3, 0(r5) /* Load one word from every line */
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000534 addi r5, r5, L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 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)
548BEGIN_FTR_SECTION
549 blr /* for 601, do nothing */
Kumar Gala4481e8e2005-06-06 13:35:57 -0700550END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 rlwinm r3,r3,0,0,19 /* Get page base address */
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000552 li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 mtctr r4
554 mr r6,r3
5550: dcbst 0,r3 /* Write line to ram */
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000556 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 bdnz 0b
558 sync
559 mtctr r4
5601: icbi 0,r6
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000561 addi r6,r6,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 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)
576BEGIN_FTR_SECTION
577 blr /* for 601, do nothing */
Kumar Gala4481e8e2005-06-06 13:35:57 -0700578END_FTR_SECTION_IFCLR(CPU_FTR_SPLIT_ID_CACHE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 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 Rothwell7dffb722005-10-17 11:50:32 +1000584 li r4,4096/L1_CACHE_BYTES /* Number of lines in a page */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 mtctr r4
586 mr r6,r3
5870: dcbst 0,r3 /* Write line to ram */
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000588 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 bdnz 0b
590 sync
591 mtctr r4
5921: icbi 0,r6
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000593 addi r6,r6,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 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 Rothwell7dffb722005-10-17 11:50:32 +1000608 li r0,4096/L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 slw r0,r0,r4
610 mtctr r0
611#ifdef CONFIG_8xx
612 li r4, 0
6131: stw r4, 0(r3)
614 stw r4, 4(r3)
615 stw r4, 8(r3)
616 stw r4, 12(r3)
617#else
6181: dcbz 0,r3
619#endif
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000620 addi r3,r3,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 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 Rothwell7dffb722005-10-17 11:50:32 +1000646 li r0,4096/L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 mtctr r0
6481: 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
65911: dcbt r11,r4
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000660 addi r11,r11,L1_CACHE_BYTES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 bdnz 11b
662#else /* MAX_COPY_PREFETCH == 1 */
663 dcbt r5,r4
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000664 li r11,L1_CACHE_BYTES+4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#endif /* MAX_COPY_PREFETCH */
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000666 li r0,4096/L1_CACHE_BYTES - MAX_COPY_PREFETCH
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 crclr 4*cr0+eq
6682:
669 mtctr r0
6701:
671 dcbt r11,r4
672 dcbz r5,r3
673 COPY_16_BYTES
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000674#if L1_CACHE_BYTES >= 32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 COPY_16_BYTES
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000676#if L1_CACHE_BYTES >= 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 COPY_16_BYTES
678 COPY_16_BYTES
Stephen Rothwell7dffb722005-10-17 11:50:32 +1000679#if L1_CACHE_BYTES >= 128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 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)
70010: 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)
70710: 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-
73500: lbz r5,0(r3)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020073601: eieio
73702: stbu r5,1(r4)
738 ISYNC_8xx
739 .section .fixup,"ax"
74003: 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 Torvalds1da177e2005-04-16 15:20:36 -0700748 bdnz 00b
749 blr
750
751_GLOBAL(_outsb)
752 cmpwi 0,r5,0
753 mtctr r5
754 subi r4,r4,1
755 blelr-
75600: lbzu r5,1(r4)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020075701: stb r5,0(r3)
75802: eieio
759 ISYNC_8xx
760 .section .fixup,"ax"
76103: 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 Torvalds1da177e2005-04-16 15:20:36 -0700769 bdnz 00b
770 blr
771
772_GLOBAL(_insw)
773 cmpwi 0,r5,0
774 mtctr r5
775 subi r4,r4,2
776 blelr-
77700: lhbrx r5,0,r3
Marcelo Tosatti55b63322005-11-05 14:06:24 -020077801: eieio
77902: sthu r5,2(r4)
780 ISYNC_8xx
781 .section .fixup,"ax"
78203: 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 Torvalds1da177e2005-04-16 15:20:36 -0700790 bdnz 00b
791 blr
792
793_GLOBAL(_outsw)
794 cmpwi 0,r5,0
795 mtctr r5
796 subi r4,r4,2
797 blelr-
79800: lhzu r5,2(r4)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020079901: eieio
80002: sthbrx r5,0,r3
801 ISYNC_8xx
802 .section .fixup,"ax"
80303: 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 Torvalds1da177e2005-04-16 15:20:36 -0700811 bdnz 00b
812 blr
813
814_GLOBAL(_insl)
815 cmpwi 0,r5,0
816 mtctr r5
817 subi r4,r4,4
818 blelr-
81900: lwbrx r5,0,r3
Marcelo Tosatti55b63322005-11-05 14:06:24 -020082001: eieio
82102: stwu r5,4(r4)
822 ISYNC_8xx
823 .section .fixup,"ax"
82403: 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 Torvalds1da177e2005-04-16 15:20:36 -0700832 bdnz 00b
833 blr
834
835_GLOBAL(_outsl)
836 cmpwi 0,r5,0
837 mtctr r5
838 subi r4,r4,4
839 blelr-
84000: lwzu r5,4(r4)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020084101: stwbrx r5,0,r3
84202: eieio
843 ISYNC_8xx
844 .section .fixup,"ax"
84503: 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 Torvalds1da177e2005-04-16 15:20:36 -0700853 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-
86200: lhz r5,0(r3)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020086301: eieio
86402: sthu r5,2(r4)
865 ISYNC_8xx
866 .section .fixup,"ax"
86703: 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 Torvalds1da177e2005-04-16 15:20:36 -0700875 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-
88400: lhzu r5,2(r4)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020088501: sth r5,0(r3)
88602: eieio
887 ISYNC_8xx
888 .section .fixup,"ax"
88903: 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 Torvalds1da177e2005-04-16 15:20:36 -0700897 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-
90600: lwz r5,0(r3)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020090701: eieio
90802: stwu r5,4(r4)
909 ISYNC_8xx
910 .section .fixup,"ax"
91103: 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 Torvalds1da177e2005-04-16 15:20:36 -0700919 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-
92800: lwzu r5,4(r4)
Marcelo Tosatti55b63322005-11-05 14:06:24 -020092901: stw r5,0(r3)
93002: eieio
931 ISYNC_8xx
932 .section .fixup,"ax"
93303: 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 Torvalds1da177e2005-04-16 15:20:36 -0700941 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 Torvalds1da177e2005-04-16 15:20:36 -07001004 * 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 Porterc9cf73a2005-07-31 22:34:52 -07001024 PPC440EP_ERR42
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 blrl
1026 li r0,__NR_exit /* exit if function returns */
1027 li r3,0
1028 sc
10291: 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
1050SYSCALL(execve)