18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __SPARC64_SWITCH_TO_64_H 38c2ecf20Sopenharmony_ci#define __SPARC64_SWITCH_TO_64_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/visasm.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define prepare_arch_switch(next) \ 88c2ecf20Sopenharmony_cido { \ 98c2ecf20Sopenharmony_ci flushw_all(); \ 108c2ecf20Sopenharmony_ci} while (0) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci /* See what happens when you design the chip correctly? 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * We tell gcc we clobber all non-fixed-usage registers except 158c2ecf20Sopenharmony_ci * for l0/l1. It will use one for 'next' and the other to hold 168c2ecf20Sopenharmony_ci * the output value of 'last'. 'next' is not referenced again 178c2ecf20Sopenharmony_ci * past the invocation of switch_to in the scheduler, so we need 188c2ecf20Sopenharmony_ci * not preserve it's value. Hairy, but it lets us remove 2 loads 198c2ecf20Sopenharmony_ci * and 2 stores in this critical code path. -DaveM 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci#define switch_to(prev, next, last) \ 228c2ecf20Sopenharmony_cido { save_and_clear_fpu(); \ 238c2ecf20Sopenharmony_ci /* If you are tempted to conditionalize the following */ \ 248c2ecf20Sopenharmony_ci /* so that ASI is only written if it changes, think again. */ \ 258c2ecf20Sopenharmony_ci __asm__ __volatile__("wr %%g0, %0, %%asi" \ 268c2ecf20Sopenharmony_ci : : "r" (task_thread_info(next)->current_ds));\ 278c2ecf20Sopenharmony_ci trap_block[current_thread_info()->cpu].thread = \ 288c2ecf20Sopenharmony_ci task_thread_info(next); \ 298c2ecf20Sopenharmony_ci __asm__ __volatile__( \ 308c2ecf20Sopenharmony_ci "mov %%g4, %%g7\n\t" \ 318c2ecf20Sopenharmony_ci "stx %%i6, [%%sp + 2047 + 0x70]\n\t" \ 328c2ecf20Sopenharmony_ci "stx %%i7, [%%sp + 2047 + 0x78]\n\t" \ 338c2ecf20Sopenharmony_ci "rdpr %%wstate, %%o5\n\t" \ 348c2ecf20Sopenharmony_ci "stx %%o6, [%%g6 + %6]\n\t" \ 358c2ecf20Sopenharmony_ci "stb %%o5, [%%g6 + %5]\n\t" \ 368c2ecf20Sopenharmony_ci "rdpr %%cwp, %%o5\n\t" \ 378c2ecf20Sopenharmony_ci "stb %%o5, [%%g6 + %8]\n\t" \ 388c2ecf20Sopenharmony_ci "wrpr %%g0, 15, %%pil\n\t" \ 398c2ecf20Sopenharmony_ci "mov %4, %%g6\n\t" \ 408c2ecf20Sopenharmony_ci "ldub [%4 + %8], %%g1\n\t" \ 418c2ecf20Sopenharmony_ci "wrpr %%g1, %%cwp\n\t" \ 428c2ecf20Sopenharmony_ci "ldx [%%g6 + %6], %%o6\n\t" \ 438c2ecf20Sopenharmony_ci "ldub [%%g6 + %5], %%o5\n\t" \ 448c2ecf20Sopenharmony_ci "ldub [%%g6 + %7], %%o7\n\t" \ 458c2ecf20Sopenharmony_ci "wrpr %%o5, 0x0, %%wstate\n\t" \ 468c2ecf20Sopenharmony_ci "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \ 478c2ecf20Sopenharmony_ci "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \ 488c2ecf20Sopenharmony_ci "ldx [%%g6 + %9], %%g4\n\t" \ 498c2ecf20Sopenharmony_ci "wrpr %%g0, 14, %%pil\n\t" \ 508c2ecf20Sopenharmony_ci "brz,pt %%o7, switch_to_pc\n\t" \ 518c2ecf20Sopenharmony_ci " mov %%g7, %0\n\t" \ 528c2ecf20Sopenharmony_ci "sethi %%hi(ret_from_fork), %%g1\n\t" \ 538c2ecf20Sopenharmony_ci "jmpl %%g1 + %%lo(ret_from_fork), %%g0\n\t" \ 548c2ecf20Sopenharmony_ci " nop\n\t" \ 558c2ecf20Sopenharmony_ci ".globl switch_to_pc\n\t" \ 568c2ecf20Sopenharmony_ci "switch_to_pc:\n\t" \ 578c2ecf20Sopenharmony_ci : "=&r" (last), "=r" (current), "=r" (current_thread_info_reg), \ 588c2ecf20Sopenharmony_ci "=r" (__local_per_cpu_offset) \ 598c2ecf20Sopenharmony_ci : "0" (task_thread_info(next)), \ 608c2ecf20Sopenharmony_ci "i" (TI_WSTATE), "i" (TI_KSP), "i" (TI_NEW_CHILD), \ 618c2ecf20Sopenharmony_ci "i" (TI_CWP), "i" (TI_TASK) \ 628c2ecf20Sopenharmony_ci : "cc", \ 638c2ecf20Sopenharmony_ci "g1", "g2", "g3", "g7", \ 648c2ecf20Sopenharmony_ci "l1", "l2", "l3", "l4", "l5", "l6", "l7", \ 658c2ecf20Sopenharmony_ci "i0", "i1", "i2", "i3", "i4", "i5", \ 668c2ecf20Sopenharmony_ci "o0", "o1", "o2", "o3", "o4", "o5", "o7"); \ 678c2ecf20Sopenharmony_ci} while(0) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_civoid synchronize_user_stack(void); 708c2ecf20Sopenharmony_cistruct pt_regs; 718c2ecf20Sopenharmony_civoid fault_in_user_windows(struct pt_regs *); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#endif /* __SPARC64_SWITCH_TO_64_H */ 74