###############################################################################1#2# MN10300 Context switch operation3#4# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.5# Written by David Howells ([email protected])6#7# This program is free software; you can redistribute it and/or8# modify it under the terms of the GNU General Public Licence9# as published by the Free Software Foundation; either version10# 2 of the Licence, or (at your option) any later version.11#12###############################################################################13#include <linux/sys.h>14#include <linux/linkage.h>15#include <asm/thread_info.h>16#include <asm/cpu-regs.h>17#ifdef CONFIG_SMP18#include <proc/smp-regs.h>19#endif /* CONFIG_SMP */2021.text2223###############################################################################24#25# struct task_struct *__switch_to(struct thread_struct *prev,26# struct thread_struct *next,27# struct task_struct *prev_task)28#29###############################################################################30ENTRY(__switch_to)31movm [d2,d3,a2,a3,exreg1],(sp)32or EPSW_NMID,epsw3334mov (44,sp),d23536mov d0,a037mov d1,a13839# save prev context40mov __switch_back,d041mov sp,a242mov a2,(THREAD_SP,a0)43mov a3,(THREAD_A3,a0)4445#ifdef CONFIG_KGDB46btst 0xff,(kgdb_single_step)47bne __switch_to__lift_sstep_bp48__switch_to__continue:49#endif50mov d0,(THREAD_PC,a0)5152mov (THREAD_A3,a1),a353mov (THREAD_SP,a1),a25455# switch56mov a2,sp5758# load next context59GET_THREAD_INFO a260mov a2,(__current_ti)61mov (TI_task,a2),a262mov a2,(__current)63#ifdef CONFIG_MN10300_CURRENT_IN_E264mov a2,e265#endif6667mov (THREAD_PC,a1),a268mov d2,d0 # for ret_from_fork69mov d0,a0 # for __switch_to7071jmp (a2)7273__switch_back:74and ~EPSW_NMID,epsw75ret [d2,d3,a2,a3,exreg1],327677#ifdef CONFIG_KGDB78###############################################################################79#80# Lift the single-step breakpoints when the task being traced is switched out81# A0 = prev82# A1 = next83#84###############################################################################85__switch_to__lift_sstep_bp:86add -12,sp87mov a0,e488mov a1,e58990# Clear the single-step flag to prevent us coming this way until we get91# switched back in92bclr 0xff,(kgdb_single_step)9394# Remove first breakpoint95mov (kgdb_sstep_bp_addr),a296cmp 0,a297beq 1f98movbu (kgdb_sstep_bp),d099movbu d0,(a2)100#if defined(CONFIG_MN10300_CACHE_FLUSH_ICACHE) || defined(CONFIG_MN10300_CACHE_INV_ICACHE)101mov a2,d0102mov a2,d1103add 1,d1104calls flush_icache_range105#endif1061:107108# Remove second breakpoint109mov (kgdb_sstep_bp_addr+4),a2110cmp 0,a2111beq 2f112movbu (kgdb_sstep_bp+1),d0113movbu d0,(a2)114#if defined(CONFIG_MN10300_CACHE_FLUSH_ICACHE) || defined(CONFIG_MN10300_CACHE_INV_ICACHE)115mov a2,d0116mov a2,d1117add 1,d1118calls flush_icache_range119#endif1202:121122# Change the resumption address and return123mov __switch_back__reinstall_sstep_bp,d0124mov e4,a0125mov e5,a1126add 12,sp127bra __switch_to__continue128129###############################################################################130#131# Reinstall the single-step breakpoints when the task being traced is switched132# back in (A1 points to the new thread_struct).133#134###############################################################################135__switch_back__reinstall_sstep_bp:136add -12,sp137mov a0,e4 # save the return value138mov 0xff,d3139140# Reinstall first breakpoint141mov (kgdb_sstep_bp_addr),a2142cmp 0,a2143beq 1f144movbu (a2),d0145movbu d0,(kgdb_sstep_bp)146movbu d3,(a2)147#if defined(CONFIG_MN10300_CACHE_FLUSH_ICACHE) || defined(CONFIG_MN10300_CACHE_INV_ICACHE)148mov a2,d0149mov a2,d1150add 1,d1151calls flush_icache_range152#endif1531:154155# Reinstall second breakpoint156mov (kgdb_sstep_bp_addr+4),a2157cmp 0,a2158beq 2f159movbu (a2),d0160movbu d0,(kgdb_sstep_bp+1)161movbu d3,(a2)162#if defined(CONFIG_MN10300_CACHE_FLUSH_ICACHE) || defined(CONFIG_MN10300_CACHE_INV_ICACHE)163mov a2,d0164mov a2,d1165add 1,d1166calls flush_icache_range167#endif1682:169170mov d3,(kgdb_single_step)171172# Restore the return value (the previous thread_struct pointer)173mov e4,a0174mov a0,d0175add 12,sp176bra __switch_back177178#endif /* CONFIG_KGDB */179180181