summaryrefslogtreecommitdiffstats
path: root/arch/mn10300/include/asm/frame.inc
blob: 406060e5e1c02364e4f0f10e619cb1f3f70c2891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* MN10300 Microcontroller core system register definitions -*- asm -*-
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public Licence
 * as published by the Free Software Foundation; either version
 * 2 of the Licence, or (at your option) any later version.
 */
#ifndef _ASM_FRAME_INC
#define _ASM_FRAME_INC

#ifndef __ASSEMBLY__
#error not for use in C files
#endif

#ifndef __ASM_OFFSETS_H__
#include <asm/asm-offsets.h>
#endif
#ifdef CONFIG_SMP
#include <proc/smp-regs.h>
#endif

#define pi break

#define fp a3

###############################################################################
#
# build a stack frame from the registers
# - the caller has subtracted 4 from SP before coming here
#
###############################################################################
.macro SAVE_ALL
	add	-4,sp				# next exception frame ptr save area
	movm	[other],(sp)
	mov	usp,a1
	mov	a1,(sp)				# USP in MOVM[other] dummy slot
	movm	[d2,d3,a2,a3,exreg0,exreg1,exother],(sp)
	mov	sp,fp				# FRAME pointer in A3
	add	-12,sp				# allow for calls to be made
#ifdef CONFIG_SMP
#ifdef CONFIG_PREEMPT /* FIXME */
	mov	epsw,d2
	and	~EPSW_IE,epsw
#endif
	mov	(CPUID),a0
	add	a0,a0
	add	a0,a0
	mov	(___frame,a0),a1
	mov	a1,(REG_NEXT,fp)
	mov	fp,(___frame,a0)
#ifdef CONFIG_PREEMPT /* FIXME */
	mov	d2,epsw
#endif
#else  /* CONFIG_SMP */
	mov	(__frame),a1
	mov	a1,(REG_NEXT,fp)
	mov	fp,(__frame)
#endif /* CONFIG_SMP */

	and	~EPSW_FE,epsw			# disable the FPU inside the kernel

	# we may be holding current in E2
#ifdef CONFIG_MN10300_CURRENT_IN_E2
	mov	(__current),e2
#endif
.endm

###############################################################################
#
# restore the registers from a stack frame
#
###############################################################################
.macro RESTORE_ALL
	# peel back the stack to the calling frame
	# - this permits execve() to discard extra frames due to kernel syscalls
#ifdef  CONFIG_SMP
#ifdef CONFIG_PREEMPT /* FIXME */
	mov	epsw,d2
	and	~EPSW_IE,epsw
#endif
	mov	(CPUID),a0
	add	a0,a0
	add	a0,a0
	mov	(___frame,a0),fp
	mov	fp,sp
	mov	(REG_NEXT,fp),d0                # userspace has regs->next == 0
	mov	d0,(___frame,a0)
#ifdef CONFIG_PREEMPT /* FIXME */
	mov	d2,epsw
#endif
#else   /* CONFIG_SMP */
	mov	(__frame),fp
	mov	fp,sp
	mov	(REG_NEXT,fp),d0                # userspace has regs->next == 0
	mov	d0,(__frame)
#endif  /* CONFIG_SMP */

#ifndef CONFIG_MN10300_USING_JTAG
	mov	(REG_EPSW,fp),d0
	btst	EPSW_T,d0
	beq	99f

	or	EPSW_NMID,epsw
	movhu	(DCR),d1
	or	0x0001, d1
	movhu	d1,(DCR)

99:
#endif
	movm	(sp),[d2,d3,a2,a3,exreg0,exreg1,exother]

	# must restore usp even if returning to kernel space,
	# when CONFIG_PREEMPT is enabled.
	mov	(sp),a1				# USP in MOVM[other] dummy slot
	mov	a1,usp

	movm	(sp),[other]
	add	8,sp
	rti

.endm


#endif /* _ASM_FRAME_INC */