ctx_sw_asm.S 1.7 KB

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