1/* MN10300 Microcontroller core system register definitions -*- asm -*-
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11#ifndef _ASM_FRAME_INC
12#define _ASM_FRAME_INC
13
14#ifndef __ASSEMBLY__
15#error not for use in C files
16#endif
17
18#ifndef __ASM_OFFSETS_H__
19#include <asm/asm-offsets.h>
20#endif
21#include <asm/thread_info.h>
22
23#define pi break
24
25#define fp a3
26
27###############################################################################
28#
29# build a stack frame from the registers
30# - the caller has subtracted 4 from SP before coming here
31#
32###############################################################################
33.macro SAVE_ALL
34	add	-4,sp				# next exception frame ptr save area
35	movm	[other],(sp)
36	mov	usp,a1
37	mov	a1,(sp)				# USP in MOVM[other] dummy slot
38	movm	[d2,d3,a2,a3,exreg0,exreg1,exother],(sp)
39	mov	sp,fp				# FRAME pointer in A3
40	add	-12,sp				# allow for calls to be made
41
42	# push the exception frame onto the front of the list
43	GET_THREAD_INFO a1
44	mov	(TI_frame,a1),a0
45	mov	a0,(REG_NEXT,fp)
46	mov	fp,(TI_frame,a1)
47
48	# disable the FPU inside the kernel
49	and	~EPSW_FE,epsw
50
51	# we may be holding current in E2
52#ifdef CONFIG_MN10300_CURRENT_IN_E2
53	mov	(__current),e2
54#endif
55.endm
56
57###############################################################################
58#
59# restore the registers from a stack frame
60#
61###############################################################################
62.macro RESTORE_ALL
63	# peel back the stack to the calling frame
64	# - this permits execve() to discard extra frames due to kernel syscalls
65	GET_THREAD_INFO a0
66	mov	(TI_frame,a0),fp
67	mov	fp,sp
68	mov	(REG_NEXT,fp),d0
69	mov	d0,(TI_frame,a0)                # userspace has regs->next == 0
70
71#ifndef CONFIG_MN10300_USING_JTAG
72	mov	(REG_EPSW,fp),d0
73	btst	EPSW_T,d0
74	beq	99f
75
76	or	EPSW_NMID,epsw
77	movhu	(DCR),d1
78	or	0x0001, d1
79	movhu	d1,(DCR)
80
8199:
82#endif
83	movm	(sp),[d2,d3,a2,a3,exreg0,exreg1,exother]
84
85	# must restore usp even if returning to kernel space,
86	# when CONFIG_PREEMPT is enabled.
87	mov	(sp),a1				# USP in MOVM[other] dummy slot
88	mov	a1,usp
89
90	movm	(sp),[other]
91	add	8,sp
92	rti
93
94.endm
95
96
97#endif /* _ASM_FRAME_INC */
98