ctx_sw_asm.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * Vineetg: Aug 2009
  6. * -Moved core context switch macro out of entry.S into this file.
  7. * -This is the more "natural" hand written assembler
  8. */
  9. #include <linux/linkage.h>
  10. #include <asm/entry.h> /* For the SAVE_* macros */
  11. #include <asm/asm-offsets.h>
  12. #define KSP_WORD_OFF ((TASK_THREAD + THREAD_KSP) / 4)
  13. ;################### Low Level Context Switch ##########################
  14. .section .sched.text,"ax",@progbits
  15. .align 4
  16. .global __switch_to
  17. .type __switch_to, @function
  18. __switch_to:
  19. CFI_STARTPROC
  20. /* Save regs on kernel mode stack of task */
  21. st.a blink, [sp, -4]
  22. st.a fp, [sp, -4]
  23. SAVE_CALLEE_SAVED_KERNEL
  24. /* Save the now KSP in task->thread.ksp */
  25. #if KSP_WORD_OFF <= 255
  26. st.as sp, [r0, KSP_WORD_OFF]
  27. #else
  28. /* Workaround for NR_CPUS=4k as ST.as can only take s9 offset */
  29. add2 r24, r0, KSP_WORD_OFF
  30. st sp, [r24]
  31. #endif
  32. /*
  33. * Return last task in r0 (return reg)
  34. * On ARC, Return reg = First Arg reg = r0.
  35. * Since we already have last task in r0,
  36. * don't need to do anything special to return it
  37. */
  38. /*
  39. * switch to new task, contained in r1
  40. * Temp reg r3 is required to get the ptr to store val
  41. */
  42. SET_CURR_TASK_ON_CPU r1, r3
  43. /* reload SP with kernel mode stack pointer in task->thread.ksp */
  44. ld.as sp, [r1, (TASK_THREAD + THREAD_KSP)/4]
  45. /* restore the registers */
  46. RESTORE_CALLEE_SAVED_KERNEL
  47. ld.ab fp, [sp, 4]
  48. ld.ab blink, [sp, 4]
  49. j [blink]
  50. END_CFI(__switch_to)