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/export.h>
12 #include <linux/sys.h>
13 #include <asm/unistd.h>
14 #include <asm/errno.h>
17 #include <asm/cache.h>
18 #include <asm/cputable.h>
20 #include <asm/ppc_asm.h>
21 #include <asm/thread_info.h>
22 #include <asm/asm-offsets.h>
23 #include <asm/processor.h>
25 #include <asm/ptrace.h>
26 #include <asm/feature-fixups.h>
31 * This returns the high 64 bits of the product of two 64-bit numbers.
43 1: beqlr cr1 /* all done if high part of A is 0 */
57 * reloc_got2 runs through the .got2 section adding an offset
62 lis r7,__got2_start@ha
63 addi r7,r7,__got2_start@l
65 addi r8,r8,__got2_end@l
85 * call_setup_cpu - call the setup_cpu function for this cpu
86 * r3 = data offset, r24 = cpu number
88 * Setup function is called with:
90 * r4 = ptr to CPU spec (relocated)
92 _GLOBAL(call_setup_cpu)
93 addis r4,r3,cur_cpu_spec@ha
94 addi r4,r4,cur_cpu_spec@l
97 lwz r5,CPU_SPEC_SETUP(r4)
104 #if defined(CONFIG_CPU_FREQ_PMAC) && defined(CONFIG_PPC_BOOK3S_32)
106 /* This gets called by via-pmu.c to switch the PLL selection
107 * on 750fx CPU. This function should really be moved to some
108 * other place (as most of the cpufreq code in via-pmu
110 _GLOBAL(low_choose_750fx_pll)
116 /* If switching to PLL1, disable HID0:BTIC */
127 /* Calc new HID1 value */
128 mfspr r4,SPRN_HID1 /* Build a HID1:PS bit from parameter */
129 rlwinm r5,r3,16,15,15 /* Clear out HID1:PS from value read */
130 rlwinm r4,r4,0,16,14 /* Could have I used rlwimi here ? */
135 /* Store new HID1 image */
141 addis r6,r6,nap_save_hid1@ha
142 stw r4,nap_save_hid1@l(r6)
144 /* If switching to PLL0, enable HID0:BTIC */
159 _GLOBAL(low_choose_7447a_dfs)
165 /* Calc new HID1 value */
167 insrwi r4,r3,1,9 /* insert parameter into bit 9 */
177 #endif /* CONFIG_CPU_FREQ_PMAC && CONFIG_PPC_BOOK3S_32 */
180 * Copy a whole page. We use the dcbz instruction on the destination
181 * to reduce memory traffic (it eliminates the unnecessary reads of
182 * the destination into cache). This requires that the destination
185 #define COPY_16_BYTES \
196 rlwinm r5, r3, 0, L1_CACHE_BYTES - 1
199 0: twnei r5, 0 /* WARN if r3 is not cache aligned */
200 EMIT_WARN_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
206 #if MAX_COPY_PREFETCH > 1
207 li r0,MAX_COPY_PREFETCH
211 addi r11,r11,L1_CACHE_BYTES
213 #else /* MAX_COPY_PREFETCH == 1 */
215 li r11,L1_CACHE_BYTES+4
216 #endif /* MAX_COPY_PREFETCH */
217 li r0,PAGE_SIZE/L1_CACHE_BYTES - MAX_COPY_PREFETCH
225 #if L1_CACHE_BYTES >= 32
227 #if L1_CACHE_BYTES >= 64
230 #if L1_CACHE_BYTES >= 128
240 crnot 4*cr0+eq,4*cr0+eq
241 li r0,MAX_COPY_PREFETCH
244 EXPORT_SYMBOL(copy_page)
247 * Extended precision shifts.
249 * Updated to be valid for shift counts from 0 to 63 inclusive.
252 * R3/R4 has 64 bit value
256 * ashrdi3: arithmetic right shift (sign propagation)
257 * lshrdi3: logical right shift
258 * ashldi3: left shift
262 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
263 addi r7,r5,32 # could be xori, or addi with -32
264 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
265 rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0
266 sraw r7,r3,r7 # t2 = MSW >> (count-32)
267 or r4,r4,r6 # LSW |= t1
268 slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2
269 sraw r3,r3,r5 # MSW = MSW >> count
270 or r4,r4,r7 # LSW |= t2
272 EXPORT_SYMBOL(__ashrdi3)
276 slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count
277 addi r7,r5,32 # could be xori, or addi with -32
278 srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count)
279 slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32)
280 or r3,r3,r6 # MSW |= t1
281 slw r4,r4,r5 # LSW = LSW << count
282 or r3,r3,r7 # MSW |= t2
284 EXPORT_SYMBOL(__ashldi3)
288 srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count
289 addi r7,r5,32 # could be xori, or addi with -32
290 slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count)
291 srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32)
292 or r4,r4,r6 # LSW |= t1
293 srw r3,r3,r5 # MSW = MSW >> count
294 or r4,r4,r7 # LSW |= t2
296 EXPORT_SYMBOL(__lshrdi3)
299 * 64-bit comparison: __cmpdi2(s64 a, s64 b)
300 * Returns 0 if a < b, 1 if a == b, 2 if a > b.
312 EXPORT_SYMBOL(__cmpdi2)
314 * 64-bit comparison: __ucmpdi2(u64 a, u64 b)
315 * Returns 0 if a < b, 1 if a == b, 2 if a > b.
327 EXPORT_SYMBOL(__ucmpdi2)
334 rlwimi r9,r4,24,16,23
335 rlwimi r10,r3,24,16,23
339 EXPORT_SYMBOL(__bswapdi2)
342 _GLOBAL(start_secondary_resume)
344 rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT
345 addi r1,r1,THREAD_SIZE-STACK_FRAME_MIN_SIZE
347 stw r3,0(r1) /* Zero the stack frame pointer */
350 #endif /* CONFIG_SMP */