blob: e6890b1f8650647774b48678c88e805f6b16de3a [file] [log] [blame]
Vineet Guptabf90e1e2013-01-18 15:12:18 +05301/*
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
Vineet Guptaba259152014-06-24 19:33:39 +053013#include <linux/linkage.h>
Vineet Guptabf90e1e2013-01-18 15:12:18 +053014#include <asm/entry.h> /* For the SAVE_* macros */
15#include <asm/asm-offsets.h>
Vineet Guptabf90e1e2013-01-18 15:12:18 +053016
Vineet Gupta57e26e52013-11-01 10:46:40 +053017#define KSP_WORD_OFF ((TASK_THREAD + THREAD_KSP) / 4)
18
Vineet Guptabf90e1e2013-01-18 15:12:18 +053019;################### Low Level Context Switch ##########################
20
21 .section .sched.text,"ax",@progbits
22 .align 4
23 .global __switch_to
24 .type __switch_to, @function
25__switch_to:
26
27 /* Save regs on kernel mode stack of task */
28 st.a blink, [sp, -4]
29 st.a fp, [sp, -4]
30 SAVE_CALLEE_SAVED_KERNEL
31
32 /* Save the now KSP in task->thread.ksp */
Vineet Gupta57e26e52013-11-01 10:46:40 +053033#if KSP_WORD_OFF <= 255
34 st.as sp, [r0, KSP_WORD_OFF]
35#else
36 /* Workaround for NR_CPUS=4k as ST.as can only take s9 offset */
37 add2 r24, r0, KSP_WORD_OFF
38 st sp, [r24]
39#endif
Vineet Guptabf90e1e2013-01-18 15:12:18 +053040 /*
41 * Return last task in r0 (return reg)
42 * On ARC, Return reg = First Arg reg = r0.
43 * Since we already have last task in r0,
44 * don't need to do anything special to return it
45 */
46
Vineet Guptabf90e1e2013-01-18 15:12:18 +053047 /*
48 * switch to new task, contained in r1
49 * Temp reg r3 is required to get the ptr to store val
50 */
51 SET_CURR_TASK_ON_CPU r1, r3
52
53 /* reload SP with kernel mode stack pointer in task->thread.ksp */
54 ld.as sp, [r1, (TASK_THREAD + THREAD_KSP)/4]
55
56 /* restore the registers */
57 RESTORE_CALLEE_SAVED_KERNEL
58 ld.ab fp, [sp, 4]
59 ld.ab blink, [sp, 4]
60 j [blink]
61
Vineet Guptaec7ac6a2014-02-07 13:47:43 +053062END(__switch_to)