xref: /openbmc/linux/arch/microblaze/kernel/entry.S (revision 9da6345885e4f33437d74314f9db592da157d65d)
1ca54502bSMichal Simek/*
2ca54502bSMichal Simek * Low-level system-call handling, trap handlers and context-switching
3ca54502bSMichal Simek *
4ca54502bSMichal Simek * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5ca54502bSMichal Simek * Copyright (C) 2008-2009 PetaLogix
6ca54502bSMichal Simek * Copyright (C) 2003		John Williams <jwilliams@itee.uq.edu.au>
7ca54502bSMichal Simek * Copyright (C) 2001,2002	NEC Corporation
8ca54502bSMichal Simek * Copyright (C) 2001,2002	Miles Bader <miles@gnu.org>
9ca54502bSMichal Simek *
10ca54502bSMichal Simek * This file is subject to the terms and conditions of the GNU General
11ca54502bSMichal Simek * Public License. See the file COPYING in the main directory of this
12ca54502bSMichal Simek * archive for more details.
13ca54502bSMichal Simek *
14ca54502bSMichal Simek * Written by Miles Bader <miles@gnu.org>
15ca54502bSMichal Simek * Heavily modified by John Williams for Microblaze
16ca54502bSMichal Simek */
17ca54502bSMichal Simek
18ca54502bSMichal Simek#include <linux/sys.h>
19ca54502bSMichal Simek#include <linux/linkage.h>
20ca54502bSMichal Simek
21ca54502bSMichal Simek#include <asm/entry.h>
22ca54502bSMichal Simek#include <asm/current.h>
23ca54502bSMichal Simek#include <asm/processor.h>
24ca54502bSMichal Simek#include <asm/exceptions.h>
25ca54502bSMichal Simek#include <asm/asm-offsets.h>
26ca54502bSMichal Simek#include <asm/thread_info.h>
27ca54502bSMichal Simek
28ca54502bSMichal Simek#include <asm/page.h>
29ca54502bSMichal Simek#include <asm/unistd.h>
30ca54502bSMichal Simek
31ca54502bSMichal Simek#include <linux/errno.h>
32ca54502bSMichal Simek#include <asm/signal.h>
33ca54502bSMichal Simek
3411d51360SMichal Simek#undef DEBUG
3511d51360SMichal Simek
36ca54502bSMichal Simek/* The size of a state save frame. */
37ca54502bSMichal Simek#define STATE_SAVE_SIZE		(PT_SIZE + STATE_SAVE_ARG_SPACE)
38ca54502bSMichal Simek
39ca54502bSMichal Simek/* The offset of the struct pt_regs in a `state save frame' on the stack. */
40ca54502bSMichal Simek#define PTO	STATE_SAVE_ARG_SPACE /* 24 the space for args */
41ca54502bSMichal Simek
42ca54502bSMichal Simek#define C_ENTRY(name)	.globl name; .align 4; name
43ca54502bSMichal Simek
44ca54502bSMichal Simek/*
45ca54502bSMichal Simek * Various ways of setting and clearing BIP in flags reg.
46ca54502bSMichal Simek * This is mucky, but necessary using microblaze version that
47ca54502bSMichal Simek * allows msr ops to write to BIP
48ca54502bSMichal Simek */
49ca54502bSMichal Simek#if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
50ca54502bSMichal Simek	.macro	clear_bip
5166f7de86SMichal Simek	msrclr	r0, MSR_BIP
52ca54502bSMichal Simek	.endm
53ca54502bSMichal Simek
54ca54502bSMichal Simek	.macro	set_bip
5566f7de86SMichal Simek	msrset	r0, MSR_BIP
56ca54502bSMichal Simek	.endm
57ca54502bSMichal Simek
58ca54502bSMichal Simek	.macro	clear_eip
5966f7de86SMichal Simek	msrclr	r0, MSR_EIP
60ca54502bSMichal Simek	.endm
61ca54502bSMichal Simek
62ca54502bSMichal Simek	.macro	set_ee
6366f7de86SMichal Simek	msrset	r0, MSR_EE
64ca54502bSMichal Simek	.endm
65ca54502bSMichal Simek
66ca54502bSMichal Simek	.macro	disable_irq
6766f7de86SMichal Simek	msrclr	r0, MSR_IE
68ca54502bSMichal Simek	.endm
69ca54502bSMichal Simek
70ca54502bSMichal Simek	.macro	enable_irq
7166f7de86SMichal Simek	msrset	r0, MSR_IE
72ca54502bSMichal Simek	.endm
73ca54502bSMichal Simek
74ca54502bSMichal Simek	.macro	set_ums
7566f7de86SMichal Simek	msrset	r0, MSR_UMS
7666f7de86SMichal Simek	msrclr	r0, MSR_VMS
77ca54502bSMichal Simek	.endm
78ca54502bSMichal Simek
79ca54502bSMichal Simek	.macro	set_vms
8066f7de86SMichal Simek	msrclr	r0, MSR_UMS
8166f7de86SMichal Simek	msrset	r0, MSR_VMS
82ca54502bSMichal Simek	.endm
83ca54502bSMichal Simek
84b318067eSMichal Simek	.macro	clear_ums
8566f7de86SMichal Simek	msrclr	r0, MSR_UMS
86b318067eSMichal Simek	.endm
87b318067eSMichal Simek
88ca54502bSMichal Simek	.macro	clear_vms_ums
8966f7de86SMichal Simek	msrclr	r0, MSR_VMS | MSR_UMS
90ca54502bSMichal Simek	.endm
91ca54502bSMichal Simek#else
92ca54502bSMichal Simek	.macro	clear_bip
93ca54502bSMichal Simek	mfs	r11, rmsr
94ca54502bSMichal Simek	andi	r11, r11, ~MSR_BIP
95ca54502bSMichal Simek	mts	rmsr, r11
96ca54502bSMichal Simek	.endm
97ca54502bSMichal Simek
98ca54502bSMichal Simek	.macro	set_bip
99ca54502bSMichal Simek	mfs	r11, rmsr
100ca54502bSMichal Simek	ori	r11, r11, MSR_BIP
101ca54502bSMichal Simek	mts	rmsr, r11
102ca54502bSMichal Simek	.endm
103ca54502bSMichal Simek
104ca54502bSMichal Simek	.macro	clear_eip
105ca54502bSMichal Simek	mfs	r11, rmsr
106ca54502bSMichal Simek	andi	r11, r11, ~MSR_EIP
107ca54502bSMichal Simek	mts	rmsr, r11
108ca54502bSMichal Simek	.endm
109ca54502bSMichal Simek
110ca54502bSMichal Simek	.macro	set_ee
111ca54502bSMichal Simek	mfs	r11, rmsr
112ca54502bSMichal Simek	ori	r11, r11, MSR_EE
113ca54502bSMichal Simek	mts	rmsr, r11
114ca54502bSMichal Simek	.endm
115ca54502bSMichal Simek
116ca54502bSMichal Simek	.macro	disable_irq
117ca54502bSMichal Simek	mfs	r11, rmsr
118ca54502bSMichal Simek	andi	r11, r11, ~MSR_IE
119ca54502bSMichal Simek	mts	rmsr, r11
120ca54502bSMichal Simek	.endm
121ca54502bSMichal Simek
122ca54502bSMichal Simek	.macro	enable_irq
123ca54502bSMichal Simek	mfs	r11, rmsr
124ca54502bSMichal Simek	ori	r11, r11, MSR_IE
125ca54502bSMichal Simek	mts	rmsr, r11
126ca54502bSMichal Simek	.endm
127ca54502bSMichal Simek
128ca54502bSMichal Simek	.macro set_ums
129ca54502bSMichal Simek	mfs	r11, rmsr
130ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
131ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
132ca54502bSMichal Simek	mts	rmsr, r11
133ca54502bSMichal Simek	.endm
134ca54502bSMichal Simek
135ca54502bSMichal Simek	.macro	set_vms
136ca54502bSMichal Simek	mfs	r11, rmsr
137ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
138ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
139ca54502bSMichal Simek	mts	rmsr, r11
140ca54502bSMichal Simek	.endm
141ca54502bSMichal Simek
142b318067eSMichal Simek	.macro	clear_ums
143b318067eSMichal Simek	mfs	r11, rmsr
144b318067eSMichal Simek	andni	r11, r11, MSR_UMS
145b318067eSMichal Simek	mts	rmsr,r11
146b318067eSMichal Simek	.endm
147b318067eSMichal Simek
148ca54502bSMichal Simek	.macro	clear_vms_ums
149ca54502bSMichal Simek	mfs	r11, rmsr
150ca54502bSMichal Simek	andni	r11, r11, (MSR_VMS|MSR_UMS)
151ca54502bSMichal Simek	mts	rmsr,r11
152ca54502bSMichal Simek	.endm
153ca54502bSMichal Simek#endif
154ca54502bSMichal Simek
155ca54502bSMichal Simek/* Define how to call high-level functions. With MMU, virtual mode must be
156ca54502bSMichal Simek * enabled when calling the high-level function. Clobbers R11.
157ca54502bSMichal Simek * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
158ca54502bSMichal Simek */
159ca54502bSMichal Simek
160ca54502bSMichal Simek/* turn on virtual protected mode save */
161ca54502bSMichal Simek#define VM_ON		\
162ca54502bSMichal Simek	set_ums;	\
163ca54502bSMichal Simek	rted	r0, 2f;	\
164a4a94dbfSMichal Simek	nop; \
165a4a94dbfSMichal Simek2:
166ca54502bSMichal Simek
167ca54502bSMichal Simek/* turn off virtual protected mode save and user mode save*/
168ca54502bSMichal Simek#define VM_OFF			\
169ca54502bSMichal Simek	clear_vms_ums;		\
170ca54502bSMichal Simek	rted	r0, TOPHYS(1f);	\
171a4a94dbfSMichal Simek	nop; \
172a4a94dbfSMichal Simek1:
173ca54502bSMichal Simek
174ca54502bSMichal Simek#define SAVE_REGS \
175ca54502bSMichal Simek	swi	r2, r1, PTO+PT_R2;	/* Save SDA */			\
17636f60954SMichal Simek	swi	r3, r1, PTO+PT_R3;					\
17736f60954SMichal Simek	swi	r4, r1, PTO+PT_R4;					\
178ca54502bSMichal Simek	swi	r5, r1, PTO+PT_R5;					\
179ca54502bSMichal Simek	swi	r6, r1, PTO+PT_R6;					\
180ca54502bSMichal Simek	swi	r7, r1, PTO+PT_R7;					\
181ca54502bSMichal Simek	swi	r8, r1, PTO+PT_R8;					\
182ca54502bSMichal Simek	swi	r9, r1, PTO+PT_R9;					\
183ca54502bSMichal Simek	swi	r10, r1, PTO+PT_R10;					\
184ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R11;	/* save clobbered regs after rval */\
185ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R12;					\
186ca54502bSMichal Simek	swi	r13, r1, PTO+PT_R13;	/* Save SDA2 */			\
187ca54502bSMichal Simek	swi	r14, r1, PTO+PT_PC;	/* PC, before IRQ/trap */	\
188ca54502bSMichal Simek	swi	r15, r1, PTO+PT_R15;	/* Save LP */			\
189600eb611SMichal Simek	swi	r16, r1, PTO+PT_R16;					\
190600eb611SMichal Simek	swi	r17, r1, PTO+PT_R17;					\
191ca54502bSMichal Simek	swi	r18, r1, PTO+PT_R18;	/* Save asm scratch reg */	\
192ca54502bSMichal Simek	swi	r19, r1, PTO+PT_R19;					\
193ca54502bSMichal Simek	swi	r20, r1, PTO+PT_R20;					\
194ca54502bSMichal Simek	swi	r21, r1, PTO+PT_R21;					\
195ca54502bSMichal Simek	swi	r22, r1, PTO+PT_R22;					\
196ca54502bSMichal Simek	swi	r23, r1, PTO+PT_R23;					\
197ca54502bSMichal Simek	swi	r24, r1, PTO+PT_R24;					\
198ca54502bSMichal Simek	swi	r25, r1, PTO+PT_R25;					\
199ca54502bSMichal Simek	swi	r26, r1, PTO+PT_R26;					\
200ca54502bSMichal Simek	swi	r27, r1, PTO+PT_R27;					\
201ca54502bSMichal Simek	swi	r28, r1, PTO+PT_R28;					\
202ca54502bSMichal Simek	swi	r29, r1, PTO+PT_R29;					\
203ca54502bSMichal Simek	swi	r30, r1, PTO+PT_R30;					\
204ca54502bSMichal Simek	swi	r31, r1, PTO+PT_R31;	/* Save current task reg */	\
205ca54502bSMichal Simek	mfs	r11, rmsr;		/* save MSR */			\
206ca54502bSMichal Simek	swi	r11, r1, PTO+PT_MSR;
207ca54502bSMichal Simek
208ca54502bSMichal Simek#define RESTORE_REGS \
209ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_MSR;					\
210ca54502bSMichal Simek	mts	rmsr , r11;						\
211ca54502bSMichal Simek	lwi	r2, r1, PTO+PT_R2;	/* restore SDA */		\
21236f60954SMichal Simek	lwi	r3, r1, PTO+PT_R3;					\
21336f60954SMichal Simek	lwi	r4, r1, PTO+PT_R4;					\
214ca54502bSMichal Simek	lwi	r5, r1, PTO+PT_R5;					\
215ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R6;					\
216ca54502bSMichal Simek	lwi	r7, r1, PTO+PT_R7;					\
217ca54502bSMichal Simek	lwi	r8, r1, PTO+PT_R8;					\
218ca54502bSMichal Simek	lwi	r9, r1, PTO+PT_R9;					\
219ca54502bSMichal Simek	lwi	r10, r1, PTO+PT_R10;					\
220ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_R11;	/* restore clobbered regs after rval */\
221ca54502bSMichal Simek	lwi	r12, r1, PTO+PT_R12;					\
222ca54502bSMichal Simek	lwi	r13, r1, PTO+PT_R13;	/* restore SDA2 */		\
223ca54502bSMichal Simek	lwi	r14, r1, PTO+PT_PC;	/* RESTORE_LINK PC, before IRQ/trap */\
224ca54502bSMichal Simek	lwi	r15, r1, PTO+PT_R15;	/* restore LP */		\
225600eb611SMichal Simek	lwi	r16, r1, PTO+PT_R16;					\
226600eb611SMichal Simek	lwi	r17, r1, PTO+PT_R17;					\
227ca54502bSMichal Simek	lwi	r18, r1, PTO+PT_R18;	/* restore asm scratch reg */	\
228ca54502bSMichal Simek	lwi	r19, r1, PTO+PT_R19;					\
229ca54502bSMichal Simek	lwi	r20, r1, PTO+PT_R20;					\
230ca54502bSMichal Simek	lwi	r21, r1, PTO+PT_R21;					\
231ca54502bSMichal Simek	lwi	r22, r1, PTO+PT_R22;					\
232ca54502bSMichal Simek	lwi	r23, r1, PTO+PT_R23;					\
233ca54502bSMichal Simek	lwi	r24, r1, PTO+PT_R24;					\
234ca54502bSMichal Simek	lwi	r25, r1, PTO+PT_R25;					\
235ca54502bSMichal Simek	lwi	r26, r1, PTO+PT_R26;					\
236ca54502bSMichal Simek	lwi	r27, r1, PTO+PT_R27;					\
237ca54502bSMichal Simek	lwi	r28, r1, PTO+PT_R28;					\
238ca54502bSMichal Simek	lwi	r29, r1, PTO+PT_R29;					\
239ca54502bSMichal Simek	lwi	r30, r1, PTO+PT_R30;					\
240ca54502bSMichal Simek	lwi	r31, r1, PTO+PT_R31;	/* Restore cur task reg */
241ca54502bSMichal Simek
242e5d2af2bSMichal Simek#define SAVE_STATE	\
243e5d2af2bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */	\
244e5d2af2bSMichal Simek	/* See if already in kernel mode.*/				\
245e5d2af2bSMichal Simek	mfs	r1, rmsr;						\
246e5d2af2bSMichal Simek	andi	r1, r1, MSR_UMS;					\
247e5d2af2bSMichal Simek	bnei	r1, 1f;						\
248e5d2af2bSMichal Simek	/* Kernel-mode state save.  */					\
249e5d2af2bSMichal Simek	/* Reload kernel stack-ptr. */					\
250e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
251287503faSMichal Simek	/* FIXME: I can add these two lines to one */			\
252287503faSMichal Simek	/* tophys(r1,r1); */						\
253287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
254287503faSMichal Simek	addik	r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
255e5d2af2bSMichal Simek	SAVE_REGS							\
256e5d2af2bSMichal Simek	brid	2f;							\
257da233552SMichal Simek	swi	r1, r1, PTO+PT_MODE; 	 				\
258e5d2af2bSMichal Simek1:	/* User-mode state save.  */					\
259e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
260e5d2af2bSMichal Simek	tophys(r1,r1);							\
261e5d2af2bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */	\
262287503faSMichal Simek	/* MS these three instructions can be added to one */		\
263287503faSMichal Simek	/* addik	r1, r1, THREAD_SIZE; */				\
264287503faSMichal Simek	/* tophys(r1,r1); */						\
265287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
266287503faSMichal Simek	addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
267e5d2af2bSMichal Simek	SAVE_REGS							\
268e5d2af2bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
269e5d2af2bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */		\
270e7741075SMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */		\
271e5d2af2bSMichal Simek	/* MS: I am clearing UMS even in case when I come from kernel space */ \
272e5d2af2bSMichal Simek	clear_ums; 							\
273e5d2af2bSMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
274e5d2af2bSMichal Simek
275ca54502bSMichal Simek.text
276ca54502bSMichal Simek
277ca54502bSMichal Simek/*
278ca54502bSMichal Simek * User trap.
279ca54502bSMichal Simek *
280ca54502bSMichal Simek * System calls are handled here.
281ca54502bSMichal Simek *
282ca54502bSMichal Simek * Syscall protocol:
283ca54502bSMichal Simek * Syscall number in r12, args in r5-r10
284ca54502bSMichal Simek * Return value in r3
285ca54502bSMichal Simek *
286ca54502bSMichal Simek * Trap entered via brki instruction, so BIP bit is set, and interrupts
287ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save
288ca54502bSMichal Simek */
289ca54502bSMichal SimekC_ENTRY(_user_exception):
2900e41c909SMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
291*9da63458SMichal Simek	addi	r14, r14, 4	/* return address is 4 byte after call */
292ca54502bSMichal Simek
293*9da63458SMichal Simek	mfs	r1, rmsr
294*9da63458SMichal Simek	nop
295*9da63458SMichal Simek	andi	r1, r1, MSR_UMS
296*9da63458SMichal Simek	bnei	r1, 1f
297*9da63458SMichal Simek
298*9da63458SMichal Simek/* Kernel-mode state save - kernel execve */
299*9da63458SMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
300*9da63458SMichal Simek	tophys(r1,r1);
301*9da63458SMichal Simek
302*9da63458SMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
303*9da63458SMichal Simek	SAVE_REGS
304*9da63458SMichal Simek
305*9da63458SMichal Simek	swi	r1, r1, PTO + PT_MODE; /* pt_regs -> kernel mode */
306*9da63458SMichal Simek	brid	2f;
307*9da63458SMichal Simek	nop;				/* Fill delay slot */
308*9da63458SMichal Simek
309*9da63458SMichal Simek/* User-mode state save.  */
310*9da63458SMichal Simek1:
311ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
312ca54502bSMichal Simek	tophys(r1,r1);
313ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get stack from task_struct */
314*9da63458SMichal Simek/* calculate kernel stack pointer from task struct 8k */
315*9da63458SMichal Simek	addik	r1, r1, THREAD_SIZE;
316*9da63458SMichal Simek	tophys(r1,r1);
317*9da63458SMichal Simek
318*9da63458SMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
319ca54502bSMichal Simek	SAVE_REGS
3207d432095SMichal Simek	swi	r0, r1, PTO + PT_R3
3217d432095SMichal Simek	swi	r0, r1, PTO + PT_R4
322ca54502bSMichal Simek
323*9da63458SMichal Simek	swi	r0, r1, PTO + PT_MODE;			/* Was in user-mode. */
324ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
325ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;		/* Store user SP.  */
32625f6e596SMichal Simek	clear_ums;
327*9da63458SMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
328ca54502bSMichal Simek	/* Save away the syscall number.  */
329ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R0;
330ca54502bSMichal Simek	tovirt(r1,r1)
331ca54502bSMichal Simek
332ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/
333ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12
334ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP
335ca54502bSMichal Simek * register should point to the location where
336ca54502bSMichal Simek * the called function should return.  [note that MAKE_SYS_CALL uses label 1] */
33723575483SMichal Simek
33825f6e596SMichal Simek	/* Step into virtual mode */
33925f6e596SMichal Simek	rtbd	r0, 3f
34023575483SMichal Simek	nop
34123575483SMichal Simek3:
342b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
34323575483SMichal Simek	lwi	r11, r11, TI_FLAGS	 /* get flags in thread info */
34423575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
34523575483SMichal Simek	beqi	r11, 4f
34623575483SMichal Simek
34723575483SMichal Simek	addik	r3, r0, -ENOSYS
34823575483SMichal Simek	swi	r3, r1, PTO + PT_R3
34923575483SMichal Simek	brlid	r15, do_syscall_trace_enter
35023575483SMichal Simek	addik	r5, r1, PTO + PT_R0
35123575483SMichal Simek
35223575483SMichal Simek	# do_syscall_trace_enter returns the new syscall nr.
35323575483SMichal Simek	addk	r12, r0, r3
35423575483SMichal Simek	lwi	r5, r1, PTO+PT_R5;
35523575483SMichal Simek	lwi	r6, r1, PTO+PT_R6;
35623575483SMichal Simek	lwi	r7, r1, PTO+PT_R7;
35723575483SMichal Simek	lwi	r8, r1, PTO+PT_R8;
35823575483SMichal Simek	lwi	r9, r1, PTO+PT_R9;
35923575483SMichal Simek	lwi	r10, r1, PTO+PT_R10;
36023575483SMichal Simek4:
36123575483SMichal Simek/* Jump to the appropriate function for the system call number in r12
36223575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid.
36323575483SMichal Simek * The LP register should point to the location where the called function
36423575483SMichal Simek * should return.  [note that MAKE_SYS_CALL uses label 1] */
36523575483SMichal Simek	/* See if the system call number is valid */
366ca54502bSMichal Simek	addi	r11, r12, -__NR_syscalls;
36723575483SMichal Simek	bgei	r11,5f;
368ca54502bSMichal Simek	/* Figure out which function to use for this system call.  */
369ca54502bSMichal Simek	/* Note Microblaze barrel shift is optional, so don't rely on it */
370ca54502bSMichal Simek	add	r12, r12, r12;			/* convert num -> ptr */
371ca54502bSMichal Simek	add	r12, r12, r12;
372ca54502bSMichal Simek
37311d51360SMichal Simek#ifdef DEBUG
374ca54502bSMichal Simek	/* Trac syscalls and stored them to r0_ram */
37523575483SMichal Simek	lwi	r3, r12, 0x400 + r0_ram
376ca54502bSMichal Simek	addi	r3, r3, 1
37723575483SMichal Simek	swi	r3, r12, 0x400 + r0_ram
37811d51360SMichal Simek#endif
379ca54502bSMichal Simek
38023575483SMichal Simek	# Find and jump into the syscall handler.
38123575483SMichal Simek	lwi	r12, r12, sys_call_table
38223575483SMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
383b9ea77e2SMichal Simek	addi	r15, r0, ret_from_trap-8
38423575483SMichal Simek	bra	r12
38523575483SMichal Simek
386ca54502bSMichal Simek	/* The syscall number is invalid, return an error.  */
38723575483SMichal Simek5:
388ca54502bSMichal Simek	rtsd	r15, 8;		/* looks like a normal subroutine return */
3899814cc11SMichal Simek	addi	r3, r0, -ENOSYS;
390ca54502bSMichal Simek
39123575483SMichal Simek/* Entry point used to return from a syscall/trap */
392ca54502bSMichal Simek/* We re-enable BIP bit before state restore */
393ca54502bSMichal SimekC_ENTRY(ret_from_trap):
394b1d70c62SMichal Simek	swi	r3, r1, PTO + PT_R3
395b1d70c62SMichal Simek	swi	r4, r1, PTO + PT_R4
396b1d70c62SMichal Simek
397*9da63458SMichal Simek	lwi	r11, r1, PTO + PT_MODE;
398*9da63458SMichal Simek/* See if returning to kernel mode, if so, skip resched &c.  */
399*9da63458SMichal Simek	bnei	r11, 2f;
400ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
401ca54502bSMichal Simek	 * trigger rescheduling. */
402b1d70c62SMichal Simek	/* FIXME: Restructure all these flag checks. */
403b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
40423575483SMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
40523575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
40623575483SMichal Simek	beqi	r11, 1f
40723575483SMichal Simek
40823575483SMichal Simek	brlid	r15, do_syscall_trace_leave
40923575483SMichal Simek	addik	r5, r1, PTO + PT_R0
41023575483SMichal Simek1:
41123575483SMichal Simek	/* We're returning to user mode, so check for various conditions that
41223575483SMichal Simek	 * trigger rescheduling. */
413b1d70c62SMichal Simek	/* get thread info from current task */
414b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
415ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
416ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
417ca54502bSMichal Simek	beqi	r11, 5f;
418ca54502bSMichal Simek
419ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
420ca54502bSMichal Simek	nop;				/* delay slot */
421ca54502bSMichal Simek
422ca54502bSMichal Simek	/* Maybe handle a signal */
423b1d70c62SMichal Simek5:	/* get thread info from current task*/
424b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
425ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
426ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
427ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
428ca54502bSMichal Simek
429b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
430ca54502bSMichal Simek	addi	r7, r0, 1;		/* Arg 3: int in_syscall */
431ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
432841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
433b1d70c62SMichal Simek
434b1d70c62SMichal Simek/* Finally, return to user state.  */
43596014cc3SMichal Simek1:	set_bip;			/*  Ints masked for state restore */
4368633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
437ca54502bSMichal Simek	VM_OFF;
438ca54502bSMichal Simek	tophys(r1,r1);
439ca54502bSMichal Simek	RESTORE_REGS;
440ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
441ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
442*9da63458SMichal Simek	bri	6f;
443*9da63458SMichal Simek
444*9da63458SMichal Simek/* Return to kernel state.  */
445*9da63458SMichal Simek2:	set_bip;			/*  Ints masked for state restore */
446*9da63458SMichal Simek	VM_OFF;
447*9da63458SMichal Simek	tophys(r1,r1);
448*9da63458SMichal Simek	RESTORE_REGS;
449*9da63458SMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
450*9da63458SMichal Simek	tovirt(r1,r1);
451*9da63458SMichal Simek6:
452ca54502bSMichal SimekTRAP_return:		/* Make global symbol for debugging */
453ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
454ca54502bSMichal Simek	nop;
455ca54502bSMichal Simek
456ca54502bSMichal Simek
457ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we
458ca54502bSMichal Simek   implement them in assembly (they're basically all wrappers anyway).  */
459ca54502bSMichal Simek
460ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper):
461ca54502bSMichal Simek	addi	r5, r0, SIGCHLD			/* Arg 0: flags */
462ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R1	/* Arg 1: child SP (use parent's) */
463b9ea77e2SMichal Simek	addik	r7, r1, PTO			/* Arg 2: parent context */
464ca54502bSMichal Simek	add	r8. r0, r0			/* Arg 3: (unused) */
465ca54502bSMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
466ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
4679814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
468ca54502bSMichal Simek
469ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate
470ca54502bSMichal Simek   stack in place that makes it look the the child is in the middle of an
471ca54502bSMichal Simek   syscall.  This function is actually `returned to' from switch_thread
472ca54502bSMichal Simek   (copy_thread makes ret_from_fork the return address in each new thread's
473ca54502bSMichal Simek   saved context).  */
474ca54502bSMichal SimekC_ENTRY(ret_from_fork):
475ca54502bSMichal Simek	bralid	r15, schedule_tail; /* ...which is schedule_tail's arg */
476ca54502bSMichal Simek	add	r3, r5, r0;	/* switch_thread returns the prev task */
477ca54502bSMichal Simek				/* ( in the delay slot ) */
478ca54502bSMichal Simek	brid	ret_from_trap;	/* Do normal trap return */
4799814cc11SMichal Simek	add	r3, r0, r0;	/* Child's fork call should return 0. */
480ca54502bSMichal Simek
481e513588fSArnd BergmannC_ENTRY(sys_vfork):
482e513588fSArnd Bergmann	brid	microblaze_vfork	/* Do real work (tail-call) */
483b9ea77e2SMichal Simek	addik	r5, r1, PTO
484ca54502bSMichal Simek
485e513588fSArnd BergmannC_ENTRY(sys_clone):
486ca54502bSMichal Simek	bnei	r6, 1f;			/* See if child SP arg (arg 1) is 0. */
487ca54502bSMichal Simek	lwi	r6, r1, PTO + PT_R1;	/* If so, use paret's stack ptr */
488b9ea77e2SMichal Simek1:	addik	r7, r1, PTO;			/* Arg 2: parent context */
489b9ea77e2SMichal Simek	add	r8, r0, r0;			/* Arg 3: (unused) */
490b9ea77e2SMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
491ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
4929814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
493ca54502bSMichal Simek
494e513588fSArnd BergmannC_ENTRY(sys_execve):
495e513588fSArnd Bergmann	brid	microblaze_execve;	/* Do real work (tail-call).*/
4969814cc11SMichal Simek	addik	r8, r1, PTO;		/* add user context as 4th arg */
497ca54502bSMichal Simek
498ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper):
499791d0a16SMichal Simek	brid	sys_rt_sigreturn	/* Do real work */
5009814cc11SMichal Simek	addik	r5, r1, PTO;		/* add user context as 1st arg */
501ca54502bSMichal Simek
502ca54502bSMichal Simek/*
503ca54502bSMichal Simek * HW EXCEPTION rutine start
504ca54502bSMichal Simek */
505ca54502bSMichal SimekC_ENTRY(full_exception_trap):
506ca54502bSMichal Simek	/* adjust exception address for privileged instruction
507ca54502bSMichal Simek	 * for finding where is it */
508ca54502bSMichal Simek	addik	r17, r17, -4
509ca54502bSMichal Simek	SAVE_STATE /* Save registers */
51006a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
51106a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
51206a54604SMichal Simek	tovirt(r1,r1)
513ca54502bSMichal Simek	/* FIXME this can be store directly in PT_ESR reg.
514ca54502bSMichal Simek	 * I tested it but there is a fault */
515ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
516b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc - 8
517ca54502bSMichal Simek	mfs	r6, resr
518ca54502bSMichal Simek	mfs	r7, rfsr;		/* save FSR */
519131e4e97SMichal Simek	mts	rfsr, r0;	/* Clear sticky fsr */
520c318d483SMichal Simek	rted	r0, full_exception
5219814cc11SMichal Simek	addik	r5, r1, PTO		 /* parameter struct pt_regs * regs */
522ca54502bSMichal Simek
523ca54502bSMichal Simek/*
524ca54502bSMichal Simek * Unaligned data trap.
525ca54502bSMichal Simek *
526ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here.
527ca54502bSMichal Simek *
528ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts
529ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
530ca54502bSMichal Simek *
531ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
532ca54502bSMichal Simek */
533ca54502bSMichal SimekC_ENTRY(unaligned_data_trap):
5348b110d15SMichal Simek	/* MS: I have to save r11 value and then restore it because
5358b110d15SMichal Simek	 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
5368b110d15SMichal Simek	 * instructions are not used. We don't need to do if MSR instructions
5378b110d15SMichal Simek	 * are used and they use r0 instead of r11.
5388b110d15SMichal Simek	 * I am using ENTRY_SP which should be primary used only for stack
5398b110d15SMichal Simek	 * pointer saving. */
5408b110d15SMichal Simek	swi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
5418b110d15SMichal Simek	set_bip;        /* equalize initial state for all possible entries */
5428b110d15SMichal Simek	clear_eip;
5438b110d15SMichal Simek	set_ee;
5448b110d15SMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
545ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
54606a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
54706a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
54806a54604SMichal Simek	tovirt(r1,r1)
549ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
550b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
551ca54502bSMichal Simek	mfs	r3, resr		/* ESR */
552ca54502bSMichal Simek	mfs	r4, rear		/* EAR */
553c318d483SMichal Simek	rtbd	r0, _unaligned_data_exception
554b9ea77e2SMichal Simek	addik	r7, r1, PTO		/* parameter struct pt_regs * regs */
555ca54502bSMichal Simek
556ca54502bSMichal Simek/*
557ca54502bSMichal Simek * Page fault traps.
558ca54502bSMichal Simek *
559ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find
560ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation.
561ca54502bSMichal Simek *
562ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts
563ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
564ca54502bSMichal Simek *
565ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors.  All TLB exceptions
566ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault.
567ca54502bSMichal Simek *
568ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as:
569ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs,
570ca54502bSMichal Simek *				unsigned long address,
571ca54502bSMichal Simek *				unsigned long error_code)
572ca54502bSMichal Simek */
573ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */
574ca54502bSMichal SimekC_ENTRY(page_fault_data_trap):
575ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
57606a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
57706a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
57806a54604SMichal Simek	tovirt(r1,r1)
579ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
580b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
581ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
582ca54502bSMichal Simek	mfs	r7, resr		/* parameter unsigned long error_code */
583c318d483SMichal Simek	rted	r0, do_page_fault
5849814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
585ca54502bSMichal Simek
586ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap):
587ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
58806a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
58906a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
59006a54604SMichal Simek	tovirt(r1,r1)
591ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
592b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
593ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
594ca54502bSMichal Simek	ori	r7, r0, 0		/* parameter unsigned long error_code */
5959814cc11SMichal Simek	rted	r0, do_page_fault
5969814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
597ca54502bSMichal Simek
598ca54502bSMichal Simek/* Entry point used to return from an exception.  */
599ca54502bSMichal SimekC_ENTRY(ret_from_exc):
600ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
601ca54502bSMichal Simek	bnei	r11, 2f;		/* See if returning to kernel mode, */
602ca54502bSMichal Simek					/* ... if so, skip resched &c.  */
603ca54502bSMichal Simek
604ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
605ca54502bSMichal Simek	   trigger rescheduling. */
606b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
607ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
608ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
609ca54502bSMichal Simek	beqi	r11, 5f;
610ca54502bSMichal Simek
611ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */
612ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
613ca54502bSMichal Simek	nop;				/* delay slot */
614ca54502bSMichal Simek
615ca54502bSMichal Simek	/* Maybe handle a signal */
616b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
617ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
618ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
619ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
620ca54502bSMichal Simek
621ca54502bSMichal Simek	/*
622ca54502bSMichal Simek	 * Handle a signal return; Pending signals should be in r18.
623ca54502bSMichal Simek	 *
624ca54502bSMichal Simek	 * Not all registers are saved by the normal trap/interrupt entry
625ca54502bSMichal Simek	 * points (for instance, call-saved registers (because the normal
626ca54502bSMichal Simek	 * C-compiler calling sequence in the kernel makes sure they're
627ca54502bSMichal Simek	 * preserved), and call-clobbered registers in the case of
628ca54502bSMichal Simek	 * traps), but signal handlers may want to examine or change the
629ca54502bSMichal Simek	 * complete register state.  Here we save anything not saved by
630ca54502bSMichal Simek	 * the normal entry sequence, so that it may be safely restored
63136f60954SMichal Simek	 * (in a possibly modified form) after do_signal returns. */
632b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
633ca54502bSMichal Simek	addi	r7, r0, 0;		/* Arg 3: int in_syscall */
634ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
635841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
636ca54502bSMichal Simek
637ca54502bSMichal Simek/* Finally, return to user state.  */
63896014cc3SMichal Simek1:	set_bip;			/* Ints masked for state restore */
6398633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
640ca54502bSMichal Simek	VM_OFF;
641ca54502bSMichal Simek	tophys(r1,r1);
642ca54502bSMichal Simek
643ca54502bSMichal Simek	RESTORE_REGS;
644ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
645ca54502bSMichal Simek
646ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
647ca54502bSMichal Simek	bri	6f;
648ca54502bSMichal Simek/* Return to kernel state.  */
64996014cc3SMichal Simek2:	set_bip;			/* Ints masked for state restore */
65096014cc3SMichal Simek	VM_OFF;
651ca54502bSMichal Simek	tophys(r1,r1);
652ca54502bSMichal Simek	RESTORE_REGS;
653ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
654ca54502bSMichal Simek
655ca54502bSMichal Simek	tovirt(r1,r1);
656ca54502bSMichal Simek6:
657ca54502bSMichal SimekEXC_return:		/* Make global symbol for debugging */
658ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
659ca54502bSMichal Simek	nop;
660ca54502bSMichal Simek
661ca54502bSMichal Simek/*
662ca54502bSMichal Simek * HW EXCEPTION rutine end
663ca54502bSMichal Simek */
664ca54502bSMichal Simek
665ca54502bSMichal Simek/*
666ca54502bSMichal Simek * Hardware maskable interrupts.
667ca54502bSMichal Simek *
668ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory
669ca54502bSMichal Simek * location PER_CPU(ENTRY_SP).
670ca54502bSMichal Simek */
671ca54502bSMichal SimekC_ENTRY(_interrupt):
672ca54502bSMichal Simek/* MS: we are in physical address */
673ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/
674ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
675ca54502bSMichal Simek	/* MS: See if already in kernel mode. */
676653e447eSMichal Simek	mfs	r1, rmsr
6775c0d72b1SMichal Simek	nop
678653e447eSMichal Simek	andi	r1, r1, MSR_UMS
679653e447eSMichal Simek	bnei	r1, 1f
680ca54502bSMichal Simek
681ca54502bSMichal Simek/* Kernel-mode state save. */
682653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
683653e447eSMichal Simek	tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
684ca54502bSMichal Simek	/* save registers */
685ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */
686ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
687ca54502bSMichal Simek	SAVE_REGS
688ca54502bSMichal Simek	brid	2f;
6890a6b08fdSMichal Simek	swi	r1, r1, PTO + PT_MODE; /* 0 - user mode, 1 - kernel mode */
690ca54502bSMichal Simek1:
691ca54502bSMichal Simek/* User-mode state save. */
692ca54502bSMichal Simek /* MS: get the saved current */
693ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
694ca54502bSMichal Simek	tophys(r1,r1);
695ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;
696ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;
697ca54502bSMichal Simek	tophys(r1,r1);
698ca54502bSMichal Simek	/* save registers */
699ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
700ca54502bSMichal Simek	SAVE_REGS
701ca54502bSMichal Simek	/* calculate mode */
702ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE;
703ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
704ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;
70580c5ff6bSMichal Simek	clear_ums;
706ca54502bSMichal Simek2:
707b1d70c62SMichal Simek	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
708ca54502bSMichal Simek	tovirt(r1,r1)
709b9ea77e2SMichal Simek	addik	r15, r0, irq_call;
71080c5ff6bSMichal Simekirq_call:rtbd	r0, do_IRQ;
71180c5ff6bSMichal Simek	addik	r5, r1, PTO;
712ca54502bSMichal Simek
713ca54502bSMichal Simek/* MS: we are in virtual mode */
714ca54502bSMichal Simekret_from_irq:
715ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
716ca54502bSMichal Simek	bnei	r11, 2f;
717ca54502bSMichal Simek
718b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
719ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* MS: get flags from thread info */
720ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
721ca54502bSMichal Simek	beqi	r11, 5f
722ca54502bSMichal Simek	bralid	r15, schedule;
723ca54502bSMichal Simek	nop; /* delay slot */
724ca54502bSMichal Simek
725ca54502bSMichal Simek    /* Maybe handle a signal */
726b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */
727ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* get flags in thread info */
728ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
729ca54502bSMichal Simek	beqid	r11, no_intr_resched
730ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */
731ca54502bSMichal Simek	addi	r7, r0, 0; /* Arg 3: int in_syscall */
732b9ea77e2SMichal Simek	addik	r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
733ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
734ca54502bSMichal Simek	add	r6, r0, r0; /* Arg 2: sigset_t *oldset */
735ca54502bSMichal Simek
736ca54502bSMichal Simek/* Finally, return to user state. */
737ca54502bSMichal Simekno_intr_resched:
738ca54502bSMichal Simek    /* Disable interrupts, we are now committed to the state restore */
739ca54502bSMichal Simek	disable_irq
7408633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
741ca54502bSMichal Simek	VM_OFF;
742ca54502bSMichal Simek	tophys(r1,r1);
743ca54502bSMichal Simek	RESTORE_REGS
744ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */
745ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;
746ca54502bSMichal Simek	bri	6f;
747ca54502bSMichal Simek/* MS: Return to kernel state. */
74877753790SMichal Simek2:
74977753790SMichal Simek#ifdef CONFIG_PREEMPT
750b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
75177753790SMichal Simek	/* MS: get preempt_count from thread info */
75277753790SMichal Simek	lwi	r5, r11, TI_PREEMPT_COUNT;
75377753790SMichal Simek	bgti	r5, restore;
75477753790SMichal Simek
75577753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
75677753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
75777753790SMichal Simek	beqi	r5, restore /* if zero jump over */
75877753790SMichal Simek
75977753790SMichal Simekpreempt:
76077753790SMichal Simek	/* interrupts are off that's why I am calling preempt_chedule_irq */
76177753790SMichal Simek	bralid	r15, preempt_schedule_irq
76277753790SMichal Simek	nop
763b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
76477753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
76577753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
76677753790SMichal Simek	bnei	r5, preempt /* if non zero jump to resched */
76777753790SMichal Simekrestore:
76877753790SMichal Simek#endif
76977753790SMichal Simek	VM_OFF /* MS: turn off MMU */
770ca54502bSMichal Simek	tophys(r1,r1)
771ca54502bSMichal Simek	RESTORE_REGS
772ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE	/* MS: Clean up stack space. */
773ca54502bSMichal Simek	tovirt(r1,r1);
774ca54502bSMichal Simek6:
775ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */
776ca54502bSMichal Simek	rtid	r14, 0
777ca54502bSMichal Simek	nop
778ca54502bSMichal Simek
779ca54502bSMichal Simek/*
7802d5973cbSMichal Simek * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
7812d5973cbSMichal Simek * and call handling function with saved pt_regs
782ca54502bSMichal Simek */
783ca54502bSMichal SimekC_ENTRY(_debug_exception):
784ca54502bSMichal Simek	/* BIP bit is set on entry, no interrupts can occur */
785ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
786ca54502bSMichal Simek
787653e447eSMichal Simek	mfs	r1, rmsr
7885c0d72b1SMichal Simek	nop
789653e447eSMichal Simek	andi	r1, r1, MSR_UMS
790653e447eSMichal Simek	bnei	r1, 1f
7912d5973cbSMichal Simek/* MS: Kernel-mode state save - kgdb */
792653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
793ca54502bSMichal Simek
7942d5973cbSMichal Simek	/* BIP bit is set on entry, no interrupts can occur */
7952d5973cbSMichal Simek	addik   r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE;
796ca54502bSMichal Simek	SAVE_REGS;
7972d5973cbSMichal Simek	/* save all regs to pt_reg structure */
7982d5973cbSMichal Simek	swi	r0, r1, PTO+PT_R0;	/* R0 must be saved too */
7992d5973cbSMichal Simek	swi	r14, r1, PTO+PT_R14	/* rewrite saved R14 value */
8002d5973cbSMichal Simek	swi	r16, r1, PTO+PT_PC; /* PC and r16 are the same */
8012d5973cbSMichal Simek	/* save special purpose registers to pt_regs */
8022d5973cbSMichal Simek	mfs	r11, rear;
8032d5973cbSMichal Simek	swi	r11, r1, PTO+PT_EAR;
8042d5973cbSMichal Simek	mfs	r11, resr;
8052d5973cbSMichal Simek	swi	r11, r1, PTO+PT_ESR;
8062d5973cbSMichal Simek	mfs	r11, rfsr;
8072d5973cbSMichal Simek	swi	r11, r1, PTO+PT_FSR;
808ca54502bSMichal Simek
8092d5973cbSMichal Simek	/* stack pointer is in physical address at it is decrease
8102d5973cbSMichal Simek	 * by STATE_SAVE_SIZE but we need to get correct R1 value */
8112d5973cbSMichal Simek	addik   r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + STATE_SAVE_SIZE;
8122d5973cbSMichal Simek	swi	r11, r1, PTO+PT_R1
8132d5973cbSMichal Simek	/* MS: r31 - current pointer isn't changed */
8142d5973cbSMichal Simek	tovirt(r1,r1)
8152d5973cbSMichal Simek#ifdef CONFIG_KGDB
8162d5973cbSMichal Simek	addi	r5, r1, PTO /* pass pt_reg address as the first arg */
8172d5973cbSMichal Simek	la	r15, r0, dbtrap_call; /* return address */
8182d5973cbSMichal Simek	rtbd	r0, microblaze_kgdb_break
8192d5973cbSMichal Simek	nop;
8202d5973cbSMichal Simek#endif
8212d5973cbSMichal Simek	/* MS: Place handler for brki from kernel space if KGDB is OFF.
8222d5973cbSMichal Simek	 * It is very unlikely that another brki instruction is called. */
8232d5973cbSMichal Simek	bri 0
8242d5973cbSMichal Simek
8252d5973cbSMichal Simek/* MS: User-mode state save - gdb */
8262d5973cbSMichal Simek1:	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
827ca54502bSMichal Simek	tophys(r1,r1);
828ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */
829ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;	/* calculate kernel stack pointer */
830ca54502bSMichal Simek	tophys(r1,r1);
831ca54502bSMichal Simek
832ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
833ca54502bSMichal Simek	SAVE_REGS;
834751f1605SMichal Simek	swi	r16, r1, PTO+PT_PC;	/* Save LP */
835ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */
836ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
837ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */
8382d5973cbSMichal Simek	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
839ca54502bSMichal Simek	tovirt(r1,r1)
84006b28640SMichal Simek	set_vms;
841751f1605SMichal Simek	addik	r5, r1, PTO;
842b9ea77e2SMichal Simek	addik	r15, r0, dbtrap_call;
8432d5973cbSMichal Simekdbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
844751f1605SMichal Simek	rtbd	r0, sw_exception
845751f1605SMichal Simek	nop
846ca54502bSMichal Simek
8472d5973cbSMichal Simek	/* MS: The first instruction for the second part of the gdb/kgdb */
848ca54502bSMichal Simek	set_bip; /* Ints masked for state restore */
849ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
850ca54502bSMichal Simek	bnei	r11, 2f;
8512d5973cbSMichal Simek/* MS: Return to user space - gdb */
852ca54502bSMichal Simek	/* Get current task ptr into r11 */
853b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
854ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
855ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
856ca54502bSMichal Simek	beqi	r11, 5f;
857ca54502bSMichal Simek
858ca54502bSMichal Simek	/* Call the scheduler before returning from a syscall/trap. */
859ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
860ca54502bSMichal Simek	nop;				/* delay slot */
861ca54502bSMichal Simek
862ca54502bSMichal Simek	/* Maybe handle a signal */
863b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
864ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
865ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
866ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
867ca54502bSMichal Simek
868b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
869ca54502bSMichal Simek	addi  r7, r0, 0;	/* Arg 3: int in_syscall */
870ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
871841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
872ca54502bSMichal Simek
873ca54502bSMichal Simek/* Finally, return to user state.  */
8742d5973cbSMichal Simek1:	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
875ca54502bSMichal Simek	VM_OFF;
876ca54502bSMichal Simek	tophys(r1,r1);
8772d5973cbSMichal Simek	/* MS: Restore all regs */
878ca54502bSMichal Simek	RESTORE_REGS
8792d5973cbSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE	 /* Clean up stack space */
8802d5973cbSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
8812d5973cbSMichal SimekDBTRAP_return_user: /* MS: Make global symbol for debugging */
8822d5973cbSMichal Simek	rtbd	r16, 0; /* MS: Instructions to return from a debug trap */
8832d5973cbSMichal Simek	nop;
884ca54502bSMichal Simek
8852d5973cbSMichal Simek/* MS: Return to kernel state - kgdb */
886ca54502bSMichal Simek2:	VM_OFF;
887ca54502bSMichal Simek	tophys(r1,r1);
8882d5973cbSMichal Simek	/* MS: Restore all regs */
889ca54502bSMichal Simek	RESTORE_REGS
8902d5973cbSMichal Simek	lwi	r14, r1, PTO+PT_R14;
8912d5973cbSMichal Simek	lwi	r16, r1, PTO+PT_PC;
8922d5973cbSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE; /* MS: Clean up stack space */
893ca54502bSMichal Simek	tovirt(r1,r1);
8942d5973cbSMichal SimekDBTRAP_return_kernel: /* MS: Make global symbol for debugging */
8952d5973cbSMichal Simek	rtbd	r16, 0; /* MS: Instructions to return from a debug trap */
896ca54502bSMichal Simek	nop;
897ca54502bSMichal Simek
898ca54502bSMichal Simek
899ca54502bSMichal SimekENTRY(_switch_to)
900ca54502bSMichal Simek	/* prepare return value */
901b1d70c62SMichal Simek	addk	r3, r0, CURRENT_TASK
902ca54502bSMichal Simek
903ca54502bSMichal Simek	/* save registers in cpu_context */
904ca54502bSMichal Simek	/* use r11 and r12, volatile registers, as temp register */
905ca54502bSMichal Simek	/* give start of cpu_context for previous process */
906ca54502bSMichal Simek	addik	r11, r5, TI_CPU_CONTEXT
907ca54502bSMichal Simek	swi	r1, r11, CC_R1
908ca54502bSMichal Simek	swi	r2, r11, CC_R2
909ca54502bSMichal Simek	/* skip volatile registers.
910ca54502bSMichal Simek	 * they are saved on stack when we jumped to _switch_to() */
911ca54502bSMichal Simek	/* dedicated registers */
912ca54502bSMichal Simek	swi	r13, r11, CC_R13
913ca54502bSMichal Simek	swi	r14, r11, CC_R14
914ca54502bSMichal Simek	swi	r15, r11, CC_R15
915ca54502bSMichal Simek	swi	r16, r11, CC_R16
916ca54502bSMichal Simek	swi	r17, r11, CC_R17
917ca54502bSMichal Simek	swi	r18, r11, CC_R18
918ca54502bSMichal Simek	/* save non-volatile registers */
919ca54502bSMichal Simek	swi	r19, r11, CC_R19
920ca54502bSMichal Simek	swi	r20, r11, CC_R20
921ca54502bSMichal Simek	swi	r21, r11, CC_R21
922ca54502bSMichal Simek	swi	r22, r11, CC_R22
923ca54502bSMichal Simek	swi	r23, r11, CC_R23
924ca54502bSMichal Simek	swi	r24, r11, CC_R24
925ca54502bSMichal Simek	swi	r25, r11, CC_R25
926ca54502bSMichal Simek	swi	r26, r11, CC_R26
927ca54502bSMichal Simek	swi	r27, r11, CC_R27
928ca54502bSMichal Simek	swi	r28, r11, CC_R28
929ca54502bSMichal Simek	swi	r29, r11, CC_R29
930ca54502bSMichal Simek	swi	r30, r11, CC_R30
931ca54502bSMichal Simek	/* special purpose registers */
932ca54502bSMichal Simek	mfs	r12, rmsr
933ca54502bSMichal Simek	swi	r12, r11, CC_MSR
934ca54502bSMichal Simek	mfs	r12, rear
935ca54502bSMichal Simek	swi	r12, r11, CC_EAR
936ca54502bSMichal Simek	mfs	r12, resr
937ca54502bSMichal Simek	swi	r12, r11, CC_ESR
938ca54502bSMichal Simek	mfs	r12, rfsr
939ca54502bSMichal Simek	swi	r12, r11, CC_FSR
940ca54502bSMichal Simek
941b1d70c62SMichal Simek	/* update r31, the current-give me pointer to task which will be next */
942b1d70c62SMichal Simek	lwi	CURRENT_TASK, r6, TI_TASK
943ca54502bSMichal Simek	/* stored it to current_save too */
944b1d70c62SMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
945ca54502bSMichal Simek
946ca54502bSMichal Simek	/* get new process' cpu context and restore */
947ca54502bSMichal Simek	/* give me start where start context of next task */
948ca54502bSMichal Simek	addik	r11, r6, TI_CPU_CONTEXT
949ca54502bSMichal Simek
950ca54502bSMichal Simek	/* non-volatile registers */
951ca54502bSMichal Simek	lwi	r30, r11, CC_R30
952ca54502bSMichal Simek	lwi	r29, r11, CC_R29
953ca54502bSMichal Simek	lwi	r28, r11, CC_R28
954ca54502bSMichal Simek	lwi	r27, r11, CC_R27
955ca54502bSMichal Simek	lwi	r26, r11, CC_R26
956ca54502bSMichal Simek	lwi	r25, r11, CC_R25
957ca54502bSMichal Simek	lwi	r24, r11, CC_R24
958ca54502bSMichal Simek	lwi	r23, r11, CC_R23
959ca54502bSMichal Simek	lwi	r22, r11, CC_R22
960ca54502bSMichal Simek	lwi	r21, r11, CC_R21
961ca54502bSMichal Simek	lwi	r20, r11, CC_R20
962ca54502bSMichal Simek	lwi	r19, r11, CC_R19
963ca54502bSMichal Simek	/* dedicated registers */
964ca54502bSMichal Simek	lwi	r18, r11, CC_R18
965ca54502bSMichal Simek	lwi	r17, r11, CC_R17
966ca54502bSMichal Simek	lwi	r16, r11, CC_R16
967ca54502bSMichal Simek	lwi	r15, r11, CC_R15
968ca54502bSMichal Simek	lwi	r14, r11, CC_R14
969ca54502bSMichal Simek	lwi	r13, r11, CC_R13
970ca54502bSMichal Simek	/* skip volatile registers */
971ca54502bSMichal Simek	lwi	r2, r11, CC_R2
972ca54502bSMichal Simek	lwi	r1, r11, CC_R1
973ca54502bSMichal Simek
974ca54502bSMichal Simek	/* special purpose registers */
975ca54502bSMichal Simek	lwi	r12, r11, CC_FSR
976ca54502bSMichal Simek	mts	rfsr, r12
977ca54502bSMichal Simek	lwi	r12, r11, CC_MSR
978ca54502bSMichal Simek	mts	rmsr, r12
979ca54502bSMichal Simek
980ca54502bSMichal Simek	rtsd	r15, 8
981ca54502bSMichal Simek	nop
982ca54502bSMichal Simek
983ca54502bSMichal SimekENTRY(_reset)
984ca54502bSMichal Simek	brai	0x70; /* Jump back to FS-boot */
985ca54502bSMichal Simek
986ca54502bSMichal Simek	/* These are compiled and loaded into high memory, then
987ca54502bSMichal Simek	 * copied into place in mach_early_setup */
988ca54502bSMichal Simek	.section	.init.ivt, "ax"
989ca54502bSMichal Simek	.org	0x0
990ca54502bSMichal Simek	/* this is very important - here is the reset vector */
991ca54502bSMichal Simek	/* in current MMU branch you don't care what is here - it is
992ca54502bSMichal Simek	 * used from bootloader site - but this is correct for FS-BOOT */
993ca54502bSMichal Simek	brai	0x70
994ca54502bSMichal Simek	nop
995ca54502bSMichal Simek	brai	TOPHYS(_user_exception); /* syscall handler */
996ca54502bSMichal Simek	brai	TOPHYS(_interrupt);	/* Interrupt handler */
997ca54502bSMichal Simek	brai	TOPHYS(_debug_exception);	/* debug trap handler */
998751f1605SMichal Simek	brai	TOPHYS(_hw_exception_handler);	/* HW exception handler */
999ca54502bSMichal Simek
1000ca54502bSMichal Simek.section .rodata,"a"
1001ca54502bSMichal Simek#include "syscall_table.S"
1002ca54502bSMichal Simek
1003ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table)
1004ca54502bSMichal Simek
1005ce3266c0SSteven J. Magnanitype_SYSCALL:
1006ce3266c0SSteven J. Magnani	.ascii "SYSCALL\0"
1007ce3266c0SSteven J. Magnanitype_IRQ:
1008ce3266c0SSteven J. Magnani	.ascii "IRQ\0"
1009ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT:
1010ce3266c0SSteven J. Magnani	.ascii "IRQ (PREEMPTED)\0"
1011ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT:
1012ce3266c0SSteven J. Magnani	.ascii " SYSCALL (PREEMPTED)\0"
1013ce3266c0SSteven J. Magnani
1014ce3266c0SSteven J. Magnani	/*
1015ce3266c0SSteven J. Magnani	 * Trap decoding for stack unwinder
1016ce3266c0SSteven J. Magnani	 * Tuples are (start addr, end addr, string)
1017ce3266c0SSteven J. Magnani	 * If return address lies on [start addr, end addr],
1018ce3266c0SSteven J. Magnani	 * unwinder displays 'string'
1019ce3266c0SSteven J. Magnani	 */
1020ce3266c0SSteven J. Magnani
1021ce3266c0SSteven J. Magnani	.align 4
1022ce3266c0SSteven J. Magnani.global microblaze_trap_handlers
1023ce3266c0SSteven J. Magnanimicroblaze_trap_handlers:
1024ce3266c0SSteven J. Magnani	/* Exact matches come first */
1025ce3266c0SSteven J. Magnani	.word ret_from_trap; .word ret_from_trap   ; .word type_SYSCALL
1026ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word ret_from_irq    ; .word type_IRQ
1027ce3266c0SSteven J. Magnani	/* Fuzzy matches go here */
1028ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1029ce3266c0SSteven J. Magnani	.word ret_from_trap; .word TRAP_return     ; .word type_SYSCALL_PREEMPT
1030ce3266c0SSteven J. Magnani	/* End of table */
1031ce3266c0SSteven J. Magnani	.word 0               ; .word 0               ; .word 0
1032