1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains miscellaneous low-level functions.
4 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6 * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
11 #include <linux/sys.h>
12 #include <asm/unistd.h>
13 #include <asm/errno.h>
16 #include <asm/cache.h>
17 #include <asm/cputable.h>
19 #include <asm/ppc_asm.h>
20 #include <asm/thread_info.h>
21 #include <asm/asm-offsets.h>
22 #include <asm/processor.h>
24 #include <asm/ptrace.h>
25 #include <asm/export.h>
26 #include <asm/feature-fixups.h>
31 * We store the saved ksp_limit in the unused part
32 * of the STACK_FRAME_OVERHEAD
34 _GLOBAL(call_do_softirq)
37 lwz r10,THREAD+KSP_LIMIT(r2)
38 stw r3, THREAD+KSP_LIMIT(r2)
39 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
46 stw r10,THREAD+KSP_LIMIT(r2)
51 * void call_do_irq(struct pt_regs *regs, void *sp);
56 lwz r10,THREAD+KSP_LIMIT(r2)
57 stw r4, THREAD+KSP_LIMIT(r2)
58 stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4)
65 stw r10,THREAD+KSP_LIMIT(r2)
70 * This returns the high 64 bits of the product of two 64-bit numbers.
82 1: beqlr cr1 /* all done if high part of A is 0 */
96 * reloc_got2 runs through the .got2 section adding an offset
101 lis r7,__got2_start@ha
102 addi r7,r7,__got2_start@l
104 addi r8,r8,__got2_end@l
124 * call_setup_cpu - call the setup_cpu function for this cpu
125 * r3 = data offset, r24 = cpu number
127 * Setup function is called with:
129 * r4 = ptr to CPU spec (relocated)
131 _GLOBAL(call_setup_cpu)
132 addis r4,r3,cur_cpu_spec@ha
133 addi r4,r4,cur_cpu_spec@l
136 lwz r5,CPU_SPEC_SETUP(r4)
143 #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_PPC_BOOK3S_32)
145 /* This gets called by via-pmu.c to switch the PLL selection
146 * on 750fx CPU. This function should really be moved to some
147 * other place (as most of the cpufreq code in via-pmu
149 _GLOBAL(low_choose_750fx_pll)
155 /* If switching to PLL1, disable HID0:BTIC */
166 /* Calc new HID1 value */
167 mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
168 rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
169 rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
174 /* Store new HID1 image */
180 addis r6,r6,nap_save_hid1@ha
181 stw r4,nap_save_hid1@l(r6)
183 /* If switching to PLL0, enable HID0:BTIC */
198 _GLOBAL(low_choose_7447a_dfs)
204 /* Calc new HID1 value */
206 insrwi r4,r3,1,9 /* insert parameter into bit 9 */
216 #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_PPC_BOOK3S_32 */
219 * complement mask on the msr then "or" some values on.
220 * _nmask_and_or_msr(nmask, value_to_or)
222 _GLOBAL(_nmask_and_or_msr)
223 mfmsr r0 /* Get current msr */
224 andc r0,r0,r3 /* And off the bits set in r3 (first parm) */
225 or r0,r0,r4 /* Or on the bits in r4 (second parm) */
226 SYNC /* Some chip revs have problems here... */
227 mtmsr r0 /* Update machine state */
234 * Do an IO access in real mode
238 rlwinm r0,r7,0,~MSR_DR
249 _ASM_NOKPROBE_SYMBOL(real_readb)
252 * Do an IO access in real mode
256 rlwinm r0,r7,0,~MSR_DR
267 _ASM_NOKPROBE_SYMBOL(real_writeb)
269 #endif /* CONFIG_40x */
273 * Flush instruction cache.
274 * This is a no-op on the 601.
276 #ifndef CONFIG_PPC_8xx
277 _GLOBAL(flush_instruction_cache)
278 #if defined(CONFIG_4xx)
281 #elif defined(CONFIG_FSL_BOOKE)
284 ori r3,r3,L1CSR0_CFI|L1CSR0_CLFC
285 /* msync; isync recommended here */
291 ori r3,r3,L1CSR1_ICFI|L1CSR1_ICLFR
293 #elif defined(CONFIG_PPC_BOOK3S_601)
294 blr /* for 601, do nothing */
296 /* 603/604 processor - use invalidate-all bit in HID0 */
300 #endif /* CONFIG_4xx */
303 EXPORT_SYMBOL(flush_instruction_cache)
304 #endif /* CONFIG_PPC_8xx */
307 * Copy a whole page. We use the dcbz instruction on the destination
308 * to reduce memory traffic (it eliminates the unnecessary reads of
309 * the destination into cache). This requires that the destination
312 #define COPY_16_BYTES \
323 rlwinm r5, r3, 0, L1_CACHE_BYTES - 1
326 0: twnei r5, 0 /* WARN if r3 is not cache aligned */
327 EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
333 #if MAX_COPY_PREFETCH > 1
334 li r0,MAX_COPY_PREFETCH
338 addi r11,r11,L1_CACHE_BYTES
340 #else /* MAX_COPY_PREFETCH == 1 */
342 li r11,L1_CACHE_BYTES+4
343 #endif /* MAX_COPY_PREFETCH */
344 li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
352 #if L1_CACHE_BYTES >= 32
354 #if L1_CACHE_BYTES >= 64
357 #if L1_CACHE_BYTES >= 128
367 crnot 4*cr0+eq,4*cr0+eq
368 li r0,MAX_COPY_PREFETCH
371 EXPORT_SYMBOL(copy_page)
374 * Extended precision shifts.
376 * Updated to be valid for shift counts from 0 to 63 inclusive.
379 * R3/R4 has 64 bit value
383 * ashrdi3: arithmetic right shift (sign propagation)
384 * lshrdi3: logical right shift
385 * ashldi3: left shift
389 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
390 addi r7,r5,32 # could be xori, or addi with -32
391 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
392 rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
393 sraw r7,r3,r7 # t2 = MSW >> (count-32)
394 or r4,r4,r6 # LSW |= t1
395 slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
396 sraw r3,r3,r5 # MSW = MSW >> count
397 or r4,r4,r7 # LSW |= t2
399 EXPORT_SYMBOL(__ashrdi3)
403 slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
404 addi r7,r5,32 # could be xori, or addi with -32
405 srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
406 slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
407 or r3,r3,r6 # MSW |= t1
408 slw r4,r4,r5 # LSW = LSW << count
409 or r3,r3,r7 # MSW |= t2
411 EXPORT_SYMBOL(__ashldi3)
415 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
416 addi r7,r5,32 # could be xori, or addi with -32
417 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
418 srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
419 or r4,r4,r6 # LSW |= t1
420 srw r3,r3,r5 # MSW = MSW >> count
421 or r4,r4,r7 # LSW |= t2
423 EXPORT_SYMBOL(__lshrdi3)
426 * 64-bit comparison: __cmpdi2(s64 a, s64 b)
427 * Returns 0 if a < b, 1 if a == b, 2 if a > b.
439 EXPORT_SYMBOL(__cmpdi2)
441 * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
442 * Returns 0 if a < b, 1 if a == b, 2 if a > b.
454 EXPORT_SYMBOL(__ucmpdi2)
461 rlwimi r9,r4,24,16,23
462 rlwimi r10,r3,24,16,23
466 EXPORT_SYMBOL(__bswapdi2)
469 _GLOBAL(start_secondary_resume)
471 rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT
472 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
474 stw r3,0(r1) /* Zero the stack frame pointer */
477 #endif /* CONFIG_SMP */
480 * This routine is just here to keep GCC happy - sigh...