xref: /openbmc/linux/arch/microblaze/kernel/entry.S (revision 25f6e59657211b3f7d912520c53fb7d98ebe960b)
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	nop
53ca54502bSMichal Simek	.endm
54ca54502bSMichal Simek
55ca54502bSMichal Simek	.macro	set_bip
5666f7de86SMichal Simek	msrset	r0, MSR_BIP
57ca54502bSMichal Simek	nop
58ca54502bSMichal Simek	.endm
59ca54502bSMichal Simek
60ca54502bSMichal Simek	.macro	clear_eip
6166f7de86SMichal Simek	msrclr	r0, MSR_EIP
62ca54502bSMichal Simek	nop
63ca54502bSMichal Simek	.endm
64ca54502bSMichal Simek
65ca54502bSMichal Simek	.macro	set_ee
6666f7de86SMichal Simek	msrset	r0, MSR_EE
67ca54502bSMichal Simek	nop
68ca54502bSMichal Simek	.endm
69ca54502bSMichal Simek
70ca54502bSMichal Simek	.macro	disable_irq
7166f7de86SMichal Simek	msrclr	r0, MSR_IE
72ca54502bSMichal Simek	nop
73ca54502bSMichal Simek	.endm
74ca54502bSMichal Simek
75ca54502bSMichal Simek	.macro	enable_irq
7666f7de86SMichal Simek	msrset	r0, MSR_IE
77ca54502bSMichal Simek	nop
78ca54502bSMichal Simek	.endm
79ca54502bSMichal Simek
80ca54502bSMichal Simek	.macro	set_ums
8166f7de86SMichal Simek	msrset	r0, MSR_UMS
82ca54502bSMichal Simek	nop
8366f7de86SMichal Simek	msrclr	r0, MSR_VMS
84ca54502bSMichal Simek	nop
85ca54502bSMichal Simek	.endm
86ca54502bSMichal Simek
87ca54502bSMichal Simek	.macro	set_vms
8866f7de86SMichal Simek	msrclr	r0, MSR_UMS
89ca54502bSMichal Simek	nop
9066f7de86SMichal Simek	msrset	r0, MSR_VMS
91ca54502bSMichal Simek	nop
92ca54502bSMichal Simek	.endm
93ca54502bSMichal Simek
94b318067eSMichal Simek	.macro	clear_ums
9566f7de86SMichal Simek	msrclr	r0, MSR_UMS
96b318067eSMichal Simek	nop
97b318067eSMichal Simek	.endm
98b318067eSMichal Simek
99ca54502bSMichal Simek	.macro	clear_vms_ums
10066f7de86SMichal Simek	msrclr	r0, MSR_VMS | MSR_UMS
101ca54502bSMichal Simek	nop
102ca54502bSMichal Simek	.endm
103ca54502bSMichal Simek#else
104ca54502bSMichal Simek	.macro	clear_bip
105ca54502bSMichal Simek	mfs	r11, rmsr
106ca54502bSMichal Simek	nop
107ca54502bSMichal Simek	andi	r11, r11, ~MSR_BIP
108ca54502bSMichal Simek	mts	rmsr, r11
109ca54502bSMichal Simek	nop
110ca54502bSMichal Simek	.endm
111ca54502bSMichal Simek
112ca54502bSMichal Simek	.macro	set_bip
113ca54502bSMichal Simek	mfs	r11, rmsr
114ca54502bSMichal Simek	nop
115ca54502bSMichal Simek	ori	r11, r11, MSR_BIP
116ca54502bSMichal Simek	mts	rmsr, r11
117ca54502bSMichal Simek	nop
118ca54502bSMichal Simek	.endm
119ca54502bSMichal Simek
120ca54502bSMichal Simek	.macro	clear_eip
121ca54502bSMichal Simek	mfs	r11, rmsr
122ca54502bSMichal Simek	nop
123ca54502bSMichal Simek	andi	r11, r11, ~MSR_EIP
124ca54502bSMichal Simek	mts	rmsr, r11
125ca54502bSMichal Simek	nop
126ca54502bSMichal Simek	.endm
127ca54502bSMichal Simek
128ca54502bSMichal Simek	.macro	set_ee
129ca54502bSMichal Simek	mfs	r11, rmsr
130ca54502bSMichal Simek	nop
131ca54502bSMichal Simek	ori	r11, r11, MSR_EE
132ca54502bSMichal Simek	mts	rmsr, r11
133ca54502bSMichal Simek	nop
134ca54502bSMichal Simek	.endm
135ca54502bSMichal Simek
136ca54502bSMichal Simek	.macro	disable_irq
137ca54502bSMichal Simek	mfs	r11, rmsr
138ca54502bSMichal Simek	nop
139ca54502bSMichal Simek	andi	r11, r11, ~MSR_IE
140ca54502bSMichal Simek	mts	rmsr, r11
141ca54502bSMichal Simek	nop
142ca54502bSMichal Simek	.endm
143ca54502bSMichal Simek
144ca54502bSMichal Simek	.macro	enable_irq
145ca54502bSMichal Simek	mfs	r11, rmsr
146ca54502bSMichal Simek	nop
147ca54502bSMichal Simek	ori	r11, r11, MSR_IE
148ca54502bSMichal Simek	mts	rmsr, r11
149ca54502bSMichal Simek	nop
150ca54502bSMichal Simek	.endm
151ca54502bSMichal Simek
152ca54502bSMichal Simek	.macro set_ums
153ca54502bSMichal Simek	mfs	r11, rmsr
154ca54502bSMichal Simek	nop
155ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
156ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
157ca54502bSMichal Simek	mts	rmsr, r11
158ca54502bSMichal Simek	nop
159ca54502bSMichal Simek	.endm
160ca54502bSMichal Simek
161ca54502bSMichal Simek	.macro	set_vms
162ca54502bSMichal Simek	mfs	r11, rmsr
163ca54502bSMichal Simek	nop
164ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
165ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
166ca54502bSMichal Simek	mts	rmsr, r11
167ca54502bSMichal Simek	nop
168ca54502bSMichal Simek	.endm
169ca54502bSMichal Simek
170b318067eSMichal Simek	.macro	clear_ums
171b318067eSMichal Simek	mfs	r11, rmsr
172b318067eSMichal Simek	nop
173b318067eSMichal Simek	andni	r11, r11, MSR_UMS
174b318067eSMichal Simek	mts	rmsr,r11
175b318067eSMichal Simek	nop
176b318067eSMichal Simek	.endm
177b318067eSMichal Simek
178ca54502bSMichal Simek	.macro	clear_vms_ums
179ca54502bSMichal Simek	mfs	r11, rmsr
180ca54502bSMichal Simek	nop
181ca54502bSMichal Simek	andni	r11, r11, (MSR_VMS|MSR_UMS)
182ca54502bSMichal Simek	mts	rmsr,r11
183ca54502bSMichal Simek	nop
184ca54502bSMichal Simek	.endm
185ca54502bSMichal Simek#endif
186ca54502bSMichal Simek
187ca54502bSMichal Simek/* Define how to call high-level functions. With MMU, virtual mode must be
188ca54502bSMichal Simek * enabled when calling the high-level function. Clobbers R11.
189ca54502bSMichal Simek * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
190ca54502bSMichal Simek */
191ca54502bSMichal Simek
192ca54502bSMichal Simek/* turn on virtual protected mode save */
193ca54502bSMichal Simek#define VM_ON		\
194ca54502bSMichal Simek	set_ums;	\
195ca54502bSMichal Simek	rted	r0, 2f;	\
196a4a94dbfSMichal Simek	nop; \
197a4a94dbfSMichal Simek2:
198ca54502bSMichal Simek
199ca54502bSMichal Simek/* turn off virtual protected mode save and user mode save*/
200ca54502bSMichal Simek#define VM_OFF			\
201ca54502bSMichal Simek	clear_vms_ums;		\
202ca54502bSMichal Simek	rted	r0, TOPHYS(1f);	\
203a4a94dbfSMichal Simek	nop; \
204a4a94dbfSMichal Simek1:
205ca54502bSMichal Simek
206ca54502bSMichal Simek#define SAVE_REGS \
207ca54502bSMichal Simek	swi	r2, r1, PTO+PT_R2;	/* Save SDA */			\
20836f60954SMichal Simek	swi	r3, r1, PTO+PT_R3;					\
20936f60954SMichal Simek	swi	r4, r1, PTO+PT_R4;					\
210ca54502bSMichal Simek	swi	r5, r1, PTO+PT_R5;					\
211ca54502bSMichal Simek	swi	r6, r1, PTO+PT_R6;					\
212ca54502bSMichal Simek	swi	r7, r1, PTO+PT_R7;					\
213ca54502bSMichal Simek	swi	r8, r1, PTO+PT_R8;					\
214ca54502bSMichal Simek	swi	r9, r1, PTO+PT_R9;					\
215ca54502bSMichal Simek	swi	r10, r1, PTO+PT_R10;					\
216ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R11;	/* save clobbered regs after rval */\
217ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R12;					\
218ca54502bSMichal Simek	swi	r13, r1, PTO+PT_R13;	/* Save SDA2 */			\
219ca54502bSMichal Simek	swi	r14, r1, PTO+PT_PC;	/* PC, before IRQ/trap */	\
220ca54502bSMichal Simek	swi	r15, r1, PTO+PT_R15;	/* Save LP */			\
221ca54502bSMichal Simek	swi	r18, r1, PTO+PT_R18;	/* Save asm scratch reg */	\
222ca54502bSMichal Simek	swi	r19, r1, PTO+PT_R19;					\
223ca54502bSMichal Simek	swi	r20, r1, PTO+PT_R20;					\
224ca54502bSMichal Simek	swi	r21, r1, PTO+PT_R21;					\
225ca54502bSMichal Simek	swi	r22, r1, PTO+PT_R22;					\
226ca54502bSMichal Simek	swi	r23, r1, PTO+PT_R23;					\
227ca54502bSMichal Simek	swi	r24, r1, PTO+PT_R24;					\
228ca54502bSMichal Simek	swi	r25, r1, PTO+PT_R25;					\
229ca54502bSMichal Simek	swi	r26, r1, PTO+PT_R26;					\
230ca54502bSMichal Simek	swi	r27, r1, PTO+PT_R27;					\
231ca54502bSMichal Simek	swi	r28, r1, PTO+PT_R28;					\
232ca54502bSMichal Simek	swi	r29, r1, PTO+PT_R29;					\
233ca54502bSMichal Simek	swi	r30, r1, PTO+PT_R30;					\
234ca54502bSMichal Simek	swi	r31, r1, PTO+PT_R31;	/* Save current task reg */	\
235ca54502bSMichal Simek	mfs	r11, rmsr;		/* save MSR */			\
236ca54502bSMichal Simek	nop;								\
237ca54502bSMichal Simek	swi	r11, r1, PTO+PT_MSR;
238ca54502bSMichal Simek
239ca54502bSMichal Simek#define RESTORE_REGS \
240ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_MSR;					\
241ca54502bSMichal Simek	mts	rmsr , r11;						\
242ca54502bSMichal Simek	nop;								\
243ca54502bSMichal Simek	lwi	r2, r1, PTO+PT_R2;	/* restore SDA */		\
24436f60954SMichal Simek	lwi	r3, r1, PTO+PT_R3;					\
24536f60954SMichal Simek	lwi	r4, r1, PTO+PT_R4;					\
246ca54502bSMichal Simek	lwi	r5, r1, PTO+PT_R5;					\
247ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R6;					\
248ca54502bSMichal Simek	lwi	r7, r1, PTO+PT_R7;					\
249ca54502bSMichal Simek	lwi	r8, r1, PTO+PT_R8;					\
250ca54502bSMichal Simek	lwi	r9, r1, PTO+PT_R9;					\
251ca54502bSMichal Simek	lwi	r10, r1, PTO+PT_R10;					\
252ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_R11;	/* restore clobbered regs after rval */\
253ca54502bSMichal Simek	lwi	r12, r1, PTO+PT_R12;					\
254ca54502bSMichal Simek	lwi	r13, r1, PTO+PT_R13;	/* restore SDA2 */		\
255ca54502bSMichal Simek	lwi	r14, r1, PTO+PT_PC;	/* RESTORE_LINK PC, before IRQ/trap */\
256ca54502bSMichal Simek	lwi	r15, r1, PTO+PT_R15;	/* restore LP */		\
257ca54502bSMichal Simek	lwi	r18, r1, PTO+PT_R18;	/* restore asm scratch reg */	\
258ca54502bSMichal Simek	lwi	r19, r1, PTO+PT_R19;					\
259ca54502bSMichal Simek	lwi	r20, r1, PTO+PT_R20;					\
260ca54502bSMichal Simek	lwi	r21, r1, PTO+PT_R21;					\
261ca54502bSMichal Simek	lwi	r22, r1, PTO+PT_R22;					\
262ca54502bSMichal Simek	lwi	r23, r1, PTO+PT_R23;					\
263ca54502bSMichal Simek	lwi	r24, r1, PTO+PT_R24;					\
264ca54502bSMichal Simek	lwi	r25, r1, PTO+PT_R25;					\
265ca54502bSMichal Simek	lwi	r26, r1, PTO+PT_R26;					\
266ca54502bSMichal Simek	lwi	r27, r1, PTO+PT_R27;					\
267ca54502bSMichal Simek	lwi	r28, r1, PTO+PT_R28;					\
268ca54502bSMichal Simek	lwi	r29, r1, PTO+PT_R29;					\
269ca54502bSMichal Simek	lwi	r30, r1, PTO+PT_R30;					\
270ca54502bSMichal Simek	lwi	r31, r1, PTO+PT_R31;	/* Restore cur task reg */
271ca54502bSMichal Simek
272e5d2af2bSMichal Simek#define SAVE_STATE	\
273e5d2af2bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */	\
274e5d2af2bSMichal Simek	/* See if already in kernel mode.*/				\
275e5d2af2bSMichal Simek	mfs	r1, rmsr;						\
276e5d2af2bSMichal Simek	nop;								\
277e5d2af2bSMichal Simek	andi	r1, r1, MSR_UMS;					\
278e5d2af2bSMichal Simek	bnei	r1, 1f;						\
279e5d2af2bSMichal Simek	/* Kernel-mode state save.  */					\
280e5d2af2bSMichal Simek	/* Reload kernel stack-ptr. */					\
281e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
282287503faSMichal Simek	/* FIXME: I can add these two lines to one */			\
283287503faSMichal Simek	/* tophys(r1,r1); */						\
284287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
285287503faSMichal Simek	addik	r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
286e5d2af2bSMichal Simek	SAVE_REGS							\
287e5d2af2bSMichal Simek	brid	2f;							\
288da233552SMichal Simek	swi	r1, r1, PTO+PT_MODE; 	 				\
289e5d2af2bSMichal Simek1:	/* User-mode state save.  */					\
290e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
291e5d2af2bSMichal Simek	tophys(r1,r1);							\
292e5d2af2bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */	\
293287503faSMichal Simek	/* MS these three instructions can be added to one */		\
294287503faSMichal Simek	/* addik	r1, r1, THREAD_SIZE; */				\
295287503faSMichal Simek	/* tophys(r1,r1); */						\
296287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
297287503faSMichal Simek	addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
298e5d2af2bSMichal Simek	SAVE_REGS							\
299e5d2af2bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
300e5d2af2bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */		\
301e7741075SMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */		\
302e5d2af2bSMichal Simek	/* MS: I am clearing UMS even in case when I come from kernel space */ \
303e5d2af2bSMichal Simek	clear_ums; 							\
304e5d2af2bSMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
305e5d2af2bSMichal Simek
306ca54502bSMichal Simek.text
307ca54502bSMichal Simek
308ca54502bSMichal Simek/*
309ca54502bSMichal Simek * User trap.
310ca54502bSMichal Simek *
311ca54502bSMichal Simek * System calls are handled here.
312ca54502bSMichal Simek *
313ca54502bSMichal Simek * Syscall protocol:
314ca54502bSMichal Simek * Syscall number in r12, args in r5-r10
315ca54502bSMichal Simek * Return value in r3
316ca54502bSMichal Simek *
317ca54502bSMichal Simek * Trap entered via brki instruction, so BIP bit is set, and interrupts
318ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save
319ca54502bSMichal Simek */
320ca54502bSMichal SimekC_ENTRY(_user_exception):
321ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
322ca54502bSMichal Simek	addi	r14, r14, 4	/* return address is 4 byte after call */
323ca54502bSMichal Simek
324653e447eSMichal Simek	mfs	r1, rmsr
3255c0d72b1SMichal Simek	nop
326653e447eSMichal Simek	andi	r1, r1, MSR_UMS
327653e447eSMichal Simek	bnei	r1, 1f
3285c0d72b1SMichal Simek
3295c0d72b1SMichal Simek/* Kernel-mode state save - kernel execve */
330653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
331653e447eSMichal Simek	tophys(r1,r1);
332ca54502bSMichal Simek
333ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
334ca54502bSMichal Simek	SAVE_REGS
335ca54502bSMichal Simek
33677f6d226SMichal Simek	swi	r1, r1, PTO + PT_MODE; /* pt_regs -> kernel mode */
337ca54502bSMichal Simek	brid	2f;
338ca54502bSMichal Simek	nop;				/* Fill delay slot */
339ca54502bSMichal Simek
340ca54502bSMichal Simek/* User-mode state save.  */
341ca54502bSMichal Simek1:
342ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
343ca54502bSMichal Simek	tophys(r1,r1);
344ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get stack from task_struct */
345ca54502bSMichal Simek/* calculate kernel stack pointer from task struct 8k */
346ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;
347ca54502bSMichal Simek	tophys(r1,r1);
348ca54502bSMichal Simek
349ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
350ca54502bSMichal Simek	SAVE_REGS
351ca54502bSMichal Simek
352ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE;			/* Was in user-mode. */
353ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
354ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;		/* Store user SP.  */
355*25f6e596SMichal Simek	clear_ums;
356b1d70c62SMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
357ca54502bSMichal Simek	/* Save away the syscall number.  */
358ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R0;
359ca54502bSMichal Simek	tovirt(r1,r1)
360ca54502bSMichal Simek
361ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/
362ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12
363ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP
364ca54502bSMichal Simek * register should point to the location where
365ca54502bSMichal Simek * the called function should return.  [note that MAKE_SYS_CALL uses label 1] */
36623575483SMichal Simek
367*25f6e596SMichal Simek	/* Step into virtual mode */
368*25f6e596SMichal Simek	rtbd	r0, 3f
36923575483SMichal Simek	nop
37023575483SMichal Simek3:
371b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
37223575483SMichal Simek	lwi	r11, r11, TI_FLAGS	 /* get flags in thread info */
37323575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
37423575483SMichal Simek	beqi	r11, 4f
37523575483SMichal Simek
37623575483SMichal Simek	addik	r3, r0, -ENOSYS
37723575483SMichal Simek	swi	r3, r1, PTO + PT_R3
37823575483SMichal Simek	brlid	r15, do_syscall_trace_enter
37923575483SMichal Simek	addik	r5, r1, PTO + PT_R0
38023575483SMichal Simek
38123575483SMichal Simek	# do_syscall_trace_enter returns the new syscall nr.
38223575483SMichal Simek	addk	r12, r0, r3
38323575483SMichal Simek	lwi	r5, r1, PTO+PT_R5;
38423575483SMichal Simek	lwi	r6, r1, PTO+PT_R6;
38523575483SMichal Simek	lwi	r7, r1, PTO+PT_R7;
38623575483SMichal Simek	lwi	r8, r1, PTO+PT_R8;
38723575483SMichal Simek	lwi	r9, r1, PTO+PT_R9;
38823575483SMichal Simek	lwi	r10, r1, PTO+PT_R10;
38923575483SMichal Simek4:
39023575483SMichal Simek/* Jump to the appropriate function for the system call number in r12
39123575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid.
39223575483SMichal Simek * The LP register should point to the location where the called function
39323575483SMichal Simek * should return.  [note that MAKE_SYS_CALL uses label 1] */
39423575483SMichal Simek	/* See if the system call number is valid */
395ca54502bSMichal Simek	addi	r11, r12, -__NR_syscalls;
39623575483SMichal Simek	bgei	r11,5f;
397ca54502bSMichal Simek	/* Figure out which function to use for this system call.  */
398ca54502bSMichal Simek	/* Note Microblaze barrel shift is optional, so don't rely on it */
399ca54502bSMichal Simek	add	r12, r12, r12;			/* convert num -> ptr */
400ca54502bSMichal Simek	add	r12, r12, r12;
401ca54502bSMichal Simek
40211d51360SMichal Simek#ifdef DEBUG
403ca54502bSMichal Simek	/* Trac syscalls and stored them to r0_ram */
40423575483SMichal Simek	lwi	r3, r12, 0x400 + r0_ram
405ca54502bSMichal Simek	addi	r3, r3, 1
40623575483SMichal Simek	swi	r3, r12, 0x400 + r0_ram
40711d51360SMichal Simek#endif
408ca54502bSMichal Simek
40923575483SMichal Simek	# Find and jump into the syscall handler.
41023575483SMichal Simek	lwi	r12, r12, sys_call_table
41123575483SMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
412b9ea77e2SMichal Simek	addi	r15, r0, ret_from_trap-8
41323575483SMichal Simek	bra	r12
41423575483SMichal Simek
415ca54502bSMichal Simek	/* The syscall number is invalid, return an error.  */
41623575483SMichal Simek5:
417ca54502bSMichal Simek	rtsd	r15, 8;		/* looks like a normal subroutine return */
4189814cc11SMichal Simek	addi	r3, r0, -ENOSYS;
419ca54502bSMichal Simek
42023575483SMichal Simek/* Entry point used to return from a syscall/trap */
421ca54502bSMichal Simek/* We re-enable BIP bit before state restore */
422ca54502bSMichal SimekC_ENTRY(ret_from_trap):
423b1d70c62SMichal Simek	swi	r3, r1, PTO + PT_R3
424b1d70c62SMichal Simek	swi	r4, r1, PTO + PT_R4
425b1d70c62SMichal Simek
42636f60954SMichal Simek	lwi	r11, r1, PTO + PT_MODE;
42736f60954SMichal Simek/* See if returning to kernel mode, if so, skip resched &c.  */
42836f60954SMichal Simek	bnei	r11, 2f;
429ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
430ca54502bSMichal Simek	 * trigger rescheduling. */
431b1d70c62SMichal Simek	/* FIXME: Restructure all these flag checks. */
432b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
43323575483SMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
43423575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
43523575483SMichal Simek	beqi	r11, 1f
43623575483SMichal Simek
43723575483SMichal Simek	brlid	r15, do_syscall_trace_leave
43823575483SMichal Simek	addik	r5, r1, PTO + PT_R0
43923575483SMichal Simek1:
44023575483SMichal Simek	/* We're returning to user mode, so check for various conditions that
44123575483SMichal Simek	 * trigger rescheduling. */
442b1d70c62SMichal Simek	/* get thread info from current task */
443b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
444ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
445ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
446ca54502bSMichal Simek	beqi	r11, 5f;
447ca54502bSMichal Simek
448ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
449ca54502bSMichal Simek	nop;				/* delay slot */
450ca54502bSMichal Simek
451ca54502bSMichal Simek	/* Maybe handle a signal */
452b1d70c62SMichal Simek5:	/* get thread info from current task*/
453b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
454ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
455ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
456ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
457ca54502bSMichal Simek
458b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
459ca54502bSMichal Simek	addi	r7, r0, 1;		/* Arg 3: int in_syscall */
460ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
461841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
462b1d70c62SMichal Simek
463b1d70c62SMichal Simek/* Finally, return to user state.  */
46496014cc3SMichal Simek1:	set_bip;			/*  Ints masked for state restore */
4658633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
466ca54502bSMichal Simek	VM_OFF;
467ca54502bSMichal Simek	tophys(r1,r1);
468ca54502bSMichal Simek	RESTORE_REGS;
469ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
470ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
471ca54502bSMichal Simek	bri	6f;
472ca54502bSMichal Simek
473ca54502bSMichal Simek/* Return to kernel state.  */
47496014cc3SMichal Simek2:	set_bip;			/*  Ints masked for state restore */
47596014cc3SMichal Simek	VM_OFF;
476ca54502bSMichal Simek	tophys(r1,r1);
477ca54502bSMichal Simek	RESTORE_REGS;
478ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
479ca54502bSMichal Simek	tovirt(r1,r1);
480ca54502bSMichal Simek6:
481ca54502bSMichal SimekTRAP_return:		/* Make global symbol for debugging */
482ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
483ca54502bSMichal Simek	nop;
484ca54502bSMichal Simek
485ca54502bSMichal Simek
486ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we
487ca54502bSMichal Simek   implement them in assembly (they're basically all wrappers anyway).  */
488ca54502bSMichal Simek
489ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper):
490ca54502bSMichal Simek	addi	r5, r0, SIGCHLD			/* Arg 0: flags */
491ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R1	/* Arg 1: child SP (use parent's) */
492b9ea77e2SMichal Simek	addik	r7, r1, PTO			/* Arg 2: parent context */
493ca54502bSMichal Simek	add	r8. r0, r0			/* Arg 3: (unused) */
494ca54502bSMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
495ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
4969814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
497ca54502bSMichal Simek
498ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate
499ca54502bSMichal Simek   stack in place that makes it look the the child is in the middle of an
500ca54502bSMichal Simek   syscall.  This function is actually `returned to' from switch_thread
501ca54502bSMichal Simek   (copy_thread makes ret_from_fork the return address in each new thread's
502ca54502bSMichal Simek   saved context).  */
503ca54502bSMichal SimekC_ENTRY(ret_from_fork):
504ca54502bSMichal Simek	bralid	r15, schedule_tail; /* ...which is schedule_tail's arg */
505ca54502bSMichal Simek	add	r3, r5, r0;	/* switch_thread returns the prev task */
506ca54502bSMichal Simek				/* ( in the delay slot ) */
507ca54502bSMichal Simek	brid	ret_from_trap;	/* Do normal trap return */
5089814cc11SMichal Simek	add	r3, r0, r0;	/* Child's fork call should return 0. */
509ca54502bSMichal Simek
510e513588fSArnd BergmannC_ENTRY(sys_vfork):
511e513588fSArnd Bergmann	brid	microblaze_vfork	/* Do real work (tail-call) */
512b9ea77e2SMichal Simek	addik	r5, r1, PTO
513ca54502bSMichal Simek
514e513588fSArnd BergmannC_ENTRY(sys_clone):
515ca54502bSMichal Simek	bnei	r6, 1f;			/* See if child SP arg (arg 1) is 0. */
516ca54502bSMichal Simek	lwi	r6, r1, PTO + PT_R1;	/* If so, use paret's stack ptr */
517b9ea77e2SMichal Simek1:	addik	r7, r1, PTO;			/* Arg 2: parent context */
518b9ea77e2SMichal Simek	add	r8, r0, r0;			/* Arg 3: (unused) */
519b9ea77e2SMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
520ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
5219814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
522ca54502bSMichal Simek
523e513588fSArnd BergmannC_ENTRY(sys_execve):
524e513588fSArnd Bergmann	brid	microblaze_execve;	/* Do real work (tail-call).*/
5259814cc11SMichal Simek	addik	r8, r1, PTO;		/* add user context as 4th arg */
526ca54502bSMichal Simek
527ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper):
528ca54502bSMichal Simek	swi	r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
529ca54502bSMichal Simek	swi	r4, r1, PTO+PT_R4;
530ca54502bSMichal Simek	brlid	r15, sys_rt_sigreturn	/* Do real work */
5319814cc11SMichal Simek	addik	r5, r1, PTO;		/* add user context as 1st arg */
532ca54502bSMichal Simek	lwi	r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
533ca54502bSMichal Simek	lwi	r4, r1, PTO+PT_R4;
534ca54502bSMichal Simek	bri ret_from_trap /* fall through will not work here due to align */
535ca54502bSMichal Simek	nop;
536ca54502bSMichal Simek
537ca54502bSMichal Simek/*
538ca54502bSMichal Simek * HW EXCEPTION rutine start
539ca54502bSMichal Simek */
540ca54502bSMichal SimekC_ENTRY(full_exception_trap):
541ca54502bSMichal Simek	/* adjust exception address for privileged instruction
542ca54502bSMichal Simek	 * for finding where is it */
543ca54502bSMichal Simek	addik	r17, r17, -4
544ca54502bSMichal Simek	SAVE_STATE /* Save registers */
54506a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
54606a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
54706a54604SMichal Simek	tovirt(r1,r1)
548ca54502bSMichal Simek	/* FIXME this can be store directly in PT_ESR reg.
549ca54502bSMichal Simek	 * I tested it but there is a fault */
550ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
551b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc - 8
552ca54502bSMichal Simek	mfs	r6, resr
553ca54502bSMichal Simek	nop
554ca54502bSMichal Simek	mfs	r7, rfsr;		/* save FSR */
555ca54502bSMichal Simek	nop
556131e4e97SMichal Simek	mts	rfsr, r0;	/* Clear sticky fsr */
557131e4e97SMichal Simek	nop
558c318d483SMichal Simek	rted	r0, full_exception
5599814cc11SMichal Simek	addik	r5, r1, PTO		 /* parameter struct pt_regs * regs */
560ca54502bSMichal Simek
561ca54502bSMichal Simek/*
562ca54502bSMichal Simek * Unaligned data trap.
563ca54502bSMichal Simek *
564ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here.
565ca54502bSMichal Simek *
566ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts
567ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
568ca54502bSMichal Simek *
569ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
570ca54502bSMichal Simek */
571ca54502bSMichal SimekC_ENTRY(unaligned_data_trap):
5728b110d15SMichal Simek	/* MS: I have to save r11 value and then restore it because
5738b110d15SMichal Simek	 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
5748b110d15SMichal Simek	 * instructions are not used. We don't need to do if MSR instructions
5758b110d15SMichal Simek	 * are used and they use r0 instead of r11.
5768b110d15SMichal Simek	 * I am using ENTRY_SP which should be primary used only for stack
5778b110d15SMichal Simek	 * pointer saving. */
5788b110d15SMichal Simek	swi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
5798b110d15SMichal Simek	set_bip;        /* equalize initial state for all possible entries */
5808b110d15SMichal Simek	clear_eip;
5818b110d15SMichal Simek	set_ee;
5828b110d15SMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
583ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
58406a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
58506a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
58606a54604SMichal Simek	tovirt(r1,r1)
587ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
588b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
589ca54502bSMichal Simek	mfs	r3, resr		/* ESR */
590ca54502bSMichal Simek	nop
591ca54502bSMichal Simek	mfs	r4, rear		/* EAR */
592ca54502bSMichal Simek	nop
593c318d483SMichal Simek	rtbd	r0, _unaligned_data_exception
594b9ea77e2SMichal Simek	addik	r7, r1, PTO		/* parameter struct pt_regs * regs */
595ca54502bSMichal Simek
596ca54502bSMichal Simek/*
597ca54502bSMichal Simek * Page fault traps.
598ca54502bSMichal Simek *
599ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find
600ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation.
601ca54502bSMichal Simek *
602ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts
603ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
604ca54502bSMichal Simek *
605ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors.  All TLB exceptions
606ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault.
607ca54502bSMichal Simek *
608ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as:
609ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs,
610ca54502bSMichal Simek *				unsigned long address,
611ca54502bSMichal Simek *				unsigned long error_code)
612ca54502bSMichal Simek */
613ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */
614ca54502bSMichal SimekC_ENTRY(page_fault_data_trap):
615ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
61606a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
61706a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
61806a54604SMichal Simek	tovirt(r1,r1)
619ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
620b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
621ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
622ca54502bSMichal Simek	nop
623ca54502bSMichal Simek	mfs	r7, resr		/* parameter unsigned long error_code */
624ca54502bSMichal Simek	nop
625c318d483SMichal Simek	rted	r0, do_page_fault
6269814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
627ca54502bSMichal Simek
628ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap):
629ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
63006a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
63106a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
63206a54604SMichal Simek	tovirt(r1,r1)
633ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
634b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
635ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
636ca54502bSMichal Simek	nop
637ca54502bSMichal Simek	ori	r7, r0, 0		/* parameter unsigned long error_code */
6389814cc11SMichal Simek	rted	r0, do_page_fault
6399814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
640ca54502bSMichal Simek
641ca54502bSMichal Simek/* Entry point used to return from an exception.  */
642ca54502bSMichal SimekC_ENTRY(ret_from_exc):
643ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
644ca54502bSMichal Simek	bnei	r11, 2f;		/* See if returning to kernel mode, */
645ca54502bSMichal Simek					/* ... if so, skip resched &c.  */
646ca54502bSMichal Simek
647ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
648ca54502bSMichal Simek	   trigger rescheduling. */
649b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
650ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
651ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
652ca54502bSMichal Simek	beqi	r11, 5f;
653ca54502bSMichal Simek
654ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */
655ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
656ca54502bSMichal Simek	nop;				/* delay slot */
657ca54502bSMichal Simek
658ca54502bSMichal Simek	/* Maybe handle a signal */
659b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
660ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
661ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
662ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
663ca54502bSMichal Simek
664ca54502bSMichal Simek	/*
665ca54502bSMichal Simek	 * Handle a signal return; Pending signals should be in r18.
666ca54502bSMichal Simek	 *
667ca54502bSMichal Simek	 * Not all registers are saved by the normal trap/interrupt entry
668ca54502bSMichal Simek	 * points (for instance, call-saved registers (because the normal
669ca54502bSMichal Simek	 * C-compiler calling sequence in the kernel makes sure they're
670ca54502bSMichal Simek	 * preserved), and call-clobbered registers in the case of
671ca54502bSMichal Simek	 * traps), but signal handlers may want to examine or change the
672ca54502bSMichal Simek	 * complete register state.  Here we save anything not saved by
673ca54502bSMichal Simek	 * the normal entry sequence, so that it may be safely restored
67436f60954SMichal Simek	 * (in a possibly modified form) after do_signal returns. */
675b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
676ca54502bSMichal Simek	addi	r7, r0, 0;		/* Arg 3: int in_syscall */
677ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
678841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
679ca54502bSMichal Simek
680ca54502bSMichal Simek/* Finally, return to user state.  */
68196014cc3SMichal Simek1:	set_bip;			/* Ints masked for state restore */
6828633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
683ca54502bSMichal Simek	VM_OFF;
684ca54502bSMichal Simek	tophys(r1,r1);
685ca54502bSMichal Simek
686ca54502bSMichal Simek	RESTORE_REGS;
687ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
688ca54502bSMichal Simek
689ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
690ca54502bSMichal Simek	bri	6f;
691ca54502bSMichal Simek/* Return to kernel state.  */
69296014cc3SMichal Simek2:	set_bip;			/* Ints masked for state restore */
69396014cc3SMichal Simek	VM_OFF;
694ca54502bSMichal Simek	tophys(r1,r1);
695ca54502bSMichal Simek	RESTORE_REGS;
696ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
697ca54502bSMichal Simek
698ca54502bSMichal Simek	tovirt(r1,r1);
699ca54502bSMichal Simek6:
700ca54502bSMichal SimekEXC_return:		/* Make global symbol for debugging */
701ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
702ca54502bSMichal Simek	nop;
703ca54502bSMichal Simek
704ca54502bSMichal Simek/*
705ca54502bSMichal Simek * HW EXCEPTION rutine end
706ca54502bSMichal Simek */
707ca54502bSMichal Simek
708ca54502bSMichal Simek/*
709ca54502bSMichal Simek * Hardware maskable interrupts.
710ca54502bSMichal Simek *
711ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory
712ca54502bSMichal Simek * location PER_CPU(ENTRY_SP).
713ca54502bSMichal Simek */
714ca54502bSMichal SimekC_ENTRY(_interrupt):
715ca54502bSMichal Simek/* MS: we are in physical address */
716ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/
717ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
718ca54502bSMichal Simek	/* MS: See if already in kernel mode. */
719653e447eSMichal Simek	mfs	r1, rmsr
7205c0d72b1SMichal Simek	nop
721653e447eSMichal Simek	andi	r1, r1, MSR_UMS
722653e447eSMichal Simek	bnei	r1, 1f
723ca54502bSMichal Simek
724ca54502bSMichal Simek/* Kernel-mode state save. */
725653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
726653e447eSMichal Simek	tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
727ca54502bSMichal Simek	/* save registers */
728ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */
729ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
730ca54502bSMichal Simek	SAVE_REGS
73177f6d226SMichal Simek	swi	r1, r1, PTO + PT_MODE; /* 0 - user mode, 1 - kernel mode */
732ca54502bSMichal Simek	brid	2f;
733ca54502bSMichal Simek	nop; /* MS: Fill delay slot */
734ca54502bSMichal Simek
735ca54502bSMichal Simek1:
736ca54502bSMichal Simek/* User-mode state save. */
737ca54502bSMichal Simek /* MS: get the saved current */
738ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
739ca54502bSMichal Simek	tophys(r1,r1);
740ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;
741ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;
742ca54502bSMichal Simek	tophys(r1,r1);
743ca54502bSMichal Simek	/* save registers */
744ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
745ca54502bSMichal Simek	SAVE_REGS
746ca54502bSMichal Simek	/* calculate mode */
747ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE;
748ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
749ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;
750ca54502bSMichal Simek2:
751b1d70c62SMichal Simek	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
752ca54502bSMichal Simek	tovirt(r1,r1)
753b9ea77e2SMichal Simek	addik	r5, r1, PTO;
754ca54502bSMichal Simek	set_vms;
755b9ea77e2SMichal Simek	addik	r11, r0, do_IRQ;
756b9ea77e2SMichal Simek	addik	r15, r0, irq_call;
757ca54502bSMichal Simekirq_call:rtbd	r11, 0;
758ca54502bSMichal Simek	nop;
759ca54502bSMichal Simek
760ca54502bSMichal Simek/* MS: we are in virtual mode */
761ca54502bSMichal Simekret_from_irq:
762ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
763ca54502bSMichal Simek	bnei	r11, 2f;
764ca54502bSMichal Simek
765b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
766ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* MS: get flags from thread info */
767ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
768ca54502bSMichal Simek	beqi	r11, 5f
769ca54502bSMichal Simek	bralid	r15, schedule;
770ca54502bSMichal Simek	nop; /* delay slot */
771ca54502bSMichal Simek
772ca54502bSMichal Simek    /* Maybe handle a signal */
773b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */
774ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* get flags in thread info */
775ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
776ca54502bSMichal Simek	beqid	r11, no_intr_resched
777ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */
778ca54502bSMichal Simek	addi	r7, r0, 0; /* Arg 3: int in_syscall */
779b9ea77e2SMichal Simek	addik	r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
780ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
781ca54502bSMichal Simek	add	r6, r0, r0; /* Arg 2: sigset_t *oldset */
782ca54502bSMichal Simek
783ca54502bSMichal Simek/* Finally, return to user state. */
784ca54502bSMichal Simekno_intr_resched:
785ca54502bSMichal Simek    /* Disable interrupts, we are now committed to the state restore */
786ca54502bSMichal Simek	disable_irq
7878633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
788ca54502bSMichal Simek	VM_OFF;
789ca54502bSMichal Simek	tophys(r1,r1);
790ca54502bSMichal Simek	RESTORE_REGS
791ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */
792ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;
793ca54502bSMichal Simek	bri	6f;
794ca54502bSMichal Simek/* MS: Return to kernel state. */
79577753790SMichal Simek2:
79677753790SMichal Simek#ifdef CONFIG_PREEMPT
797b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
79877753790SMichal Simek	/* MS: get preempt_count from thread info */
79977753790SMichal Simek	lwi	r5, r11, TI_PREEMPT_COUNT;
80077753790SMichal Simek	bgti	r5, restore;
80177753790SMichal Simek
80277753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
80377753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
80477753790SMichal Simek	beqi	r5, restore /* if zero jump over */
80577753790SMichal Simek
80677753790SMichal Simekpreempt:
80777753790SMichal Simek	/* interrupts are off that's why I am calling preempt_chedule_irq */
80877753790SMichal Simek	bralid	r15, preempt_schedule_irq
80977753790SMichal Simek	nop
810b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
81177753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
81277753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
81377753790SMichal Simek	bnei	r5, preempt /* if non zero jump to resched */
81477753790SMichal Simekrestore:
81577753790SMichal Simek#endif
81677753790SMichal Simek	VM_OFF /* MS: turn off MMU */
817ca54502bSMichal Simek	tophys(r1,r1)
818ca54502bSMichal Simek	RESTORE_REGS
819ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE	/* MS: Clean up stack space. */
820ca54502bSMichal Simek	tovirt(r1,r1);
821ca54502bSMichal Simek6:
822ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */
823ca54502bSMichal Simek	rtid	r14, 0
824ca54502bSMichal Simek	nop
825ca54502bSMichal Simek
826ca54502bSMichal Simek/*
827ca54502bSMichal Simek * `Debug' trap
828ca54502bSMichal Simek *  We enter dbtrap in "BIP" (breakpoint) mode.
829ca54502bSMichal Simek *  So we exit the breakpoint mode with an 'rtbd' and proceed with the
830ca54502bSMichal Simek *  original dbtrap.
831ca54502bSMichal Simek *  however, wait to save state first
832ca54502bSMichal Simek */
833ca54502bSMichal SimekC_ENTRY(_debug_exception):
834ca54502bSMichal Simek	/* BIP bit is set on entry, no interrupts can occur */
835ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
836ca54502bSMichal Simek
837653e447eSMichal Simek	mfs	r1, rmsr
8385c0d72b1SMichal Simek	nop
839653e447eSMichal Simek	andi	r1, r1, MSR_UMS
840653e447eSMichal Simek	bnei	r1, 1f
841ca54502bSMichal Simek	/* Kernel-mode state save.  */
842653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
843653e447eSMichal Simek	tophys(r1,r1);
844ca54502bSMichal Simek
845ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
846ca54502bSMichal Simek	SAVE_REGS;
847ca54502bSMichal Simek
84877f6d226SMichal Simek	swi	r1, r1, PTO + PT_MODE;
849ca54502bSMichal Simek	brid	2f;
850ca54502bSMichal Simek	nop;				/* Fill delay slot */
851ca54502bSMichal Simek1:      /* User-mode state save.  */
852ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
853ca54502bSMichal Simek	tophys(r1,r1);
854ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */
855ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;	/* calculate kernel stack pointer */
856ca54502bSMichal Simek	tophys(r1,r1);
857ca54502bSMichal Simek
858ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
859ca54502bSMichal Simek	SAVE_REGS;
860ca54502bSMichal Simek
861ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */
862ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
863ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */
864653e447eSMichal Simek2:
865ca54502bSMichal Simek	tovirt(r1,r1)
866ca54502bSMichal Simek
86706b28640SMichal Simek	set_vms;
868ca54502bSMichal Simek	addi	r5, r0, SIGTRAP		     /* send the trap signal */
869ca54502bSMichal Simek	add	r6, r0, CURRENT_TASK; /* Get current task ptr into r11 */
870ca54502bSMichal Simek	addk	r7, r0, r0		     /* 3rd param zero */
87106b28640SMichal Simekdbtrap_call:	rtbd	r0, send_sig;
872b9ea77e2SMichal Simek	addik	r15, r0, dbtrap_call;
873ca54502bSMichal Simek
874ca54502bSMichal Simek	set_bip;			/*  Ints masked for state restore*/
875ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
876ca54502bSMichal Simek	bnei	r11, 2f;
877ca54502bSMichal Simek
878ca54502bSMichal Simek	/* Get current task ptr into r11 */
879b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
880ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
881ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
882ca54502bSMichal Simek	beqi	r11, 5f;
883ca54502bSMichal Simek
884ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */
885ca54502bSMichal Simek
886ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
887ca54502bSMichal Simek	nop;				/* delay slot */
888ca54502bSMichal Simek	/* XXX Is PT_DTRACE handling needed here? */
889ca54502bSMichal Simek	/* XXX m68knommu also checks TASK_STATE & TASK_COUNTER here.  */
890ca54502bSMichal Simek
891ca54502bSMichal Simek	/* Maybe handle a signal */
892b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
893ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
894ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
895ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
896ca54502bSMichal Simek
897ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18.  */
898ca54502bSMichal Simek	/* Not all registers are saved by the normal trap/interrupt entry
899ca54502bSMichal Simek	   points (for instance, call-saved registers (because the normal
900ca54502bSMichal Simek	   C-compiler calling sequence in the kernel makes sure they're
901ca54502bSMichal Simek	   preserved), and call-clobbered registers in the case of
902ca54502bSMichal Simek	   traps), but signal handlers may want to examine or change the
903ca54502bSMichal Simek	   complete register state.  Here we save anything not saved by
904ca54502bSMichal Simek	   the normal entry sequence, so that it may be safely restored
905ca54502bSMichal Simek	   (in a possibly modified form) after do_signal returns.  */
906ca54502bSMichal Simek
907b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
908ca54502bSMichal Simek	addi  r7, r0, 0;	/* Arg 3: int in_syscall */
909ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
910841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
911ca54502bSMichal Simek
912ca54502bSMichal Simek
913ca54502bSMichal Simek/* Finally, return to user state.  */
9145c0d72b1SMichal Simek1:
9158633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
916ca54502bSMichal Simek	VM_OFF;
917ca54502bSMichal Simek	tophys(r1,r1);
918ca54502bSMichal Simek
919ca54502bSMichal Simek	RESTORE_REGS
920ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
921ca54502bSMichal Simek
922ca54502bSMichal Simek
923ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;
924ca54502bSMichal Simek					/* Restore user stack pointer. */
925ca54502bSMichal Simek	bri	6f;
926ca54502bSMichal Simek
927ca54502bSMichal Simek/* Return to kernel state.  */
928ca54502bSMichal Simek2:	VM_OFF;
929ca54502bSMichal Simek	tophys(r1,r1);
930ca54502bSMichal Simek	RESTORE_REGS
931ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
932ca54502bSMichal Simek
933ca54502bSMichal Simek	tovirt(r1,r1);
934ca54502bSMichal Simek6:
935ca54502bSMichal SimekDBTRAP_return:		/* Make global symbol for debugging */
936ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
937ca54502bSMichal Simek	nop;
938ca54502bSMichal Simek
939ca54502bSMichal Simek
940ca54502bSMichal Simek
941ca54502bSMichal SimekENTRY(_switch_to)
942ca54502bSMichal Simek	/* prepare return value */
943b1d70c62SMichal Simek	addk	r3, r0, CURRENT_TASK
944ca54502bSMichal Simek
945ca54502bSMichal Simek	/* save registers in cpu_context */
946ca54502bSMichal Simek	/* use r11 and r12, volatile registers, as temp register */
947ca54502bSMichal Simek	/* give start of cpu_context for previous process */
948ca54502bSMichal Simek	addik	r11, r5, TI_CPU_CONTEXT
949ca54502bSMichal Simek	swi	r1, r11, CC_R1
950ca54502bSMichal Simek	swi	r2, r11, CC_R2
951ca54502bSMichal Simek	/* skip volatile registers.
952ca54502bSMichal Simek	 * they are saved on stack when we jumped to _switch_to() */
953ca54502bSMichal Simek	/* dedicated registers */
954ca54502bSMichal Simek	swi	r13, r11, CC_R13
955ca54502bSMichal Simek	swi	r14, r11, CC_R14
956ca54502bSMichal Simek	swi	r15, r11, CC_R15
957ca54502bSMichal Simek	swi	r16, r11, CC_R16
958ca54502bSMichal Simek	swi	r17, r11, CC_R17
959ca54502bSMichal Simek	swi	r18, r11, CC_R18
960ca54502bSMichal Simek	/* save non-volatile registers */
961ca54502bSMichal Simek	swi	r19, r11, CC_R19
962ca54502bSMichal Simek	swi	r20, r11, CC_R20
963ca54502bSMichal Simek	swi	r21, r11, CC_R21
964ca54502bSMichal Simek	swi	r22, r11, CC_R22
965ca54502bSMichal Simek	swi	r23, r11, CC_R23
966ca54502bSMichal Simek	swi	r24, r11, CC_R24
967ca54502bSMichal Simek	swi	r25, r11, CC_R25
968ca54502bSMichal Simek	swi	r26, r11, CC_R26
969ca54502bSMichal Simek	swi	r27, r11, CC_R27
970ca54502bSMichal Simek	swi	r28, r11, CC_R28
971ca54502bSMichal Simek	swi	r29, r11, CC_R29
972ca54502bSMichal Simek	swi	r30, r11, CC_R30
973ca54502bSMichal Simek	/* special purpose registers */
974ca54502bSMichal Simek	mfs	r12, rmsr
975ca54502bSMichal Simek	nop
976ca54502bSMichal Simek	swi	r12, r11, CC_MSR
977ca54502bSMichal Simek	mfs	r12, rear
978ca54502bSMichal Simek	nop
979ca54502bSMichal Simek	swi	r12, r11, CC_EAR
980ca54502bSMichal Simek	mfs	r12, resr
981ca54502bSMichal Simek	nop
982ca54502bSMichal Simek	swi	r12, r11, CC_ESR
983ca54502bSMichal Simek	mfs	r12, rfsr
984ca54502bSMichal Simek	nop
985ca54502bSMichal Simek	swi	r12, r11, CC_FSR
986ca54502bSMichal Simek
987b1d70c62SMichal Simek	/* update r31, the current-give me pointer to task which will be next */
988b1d70c62SMichal Simek	lwi	CURRENT_TASK, r6, TI_TASK
989ca54502bSMichal Simek	/* stored it to current_save too */
990b1d70c62SMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
991ca54502bSMichal Simek
992ca54502bSMichal Simek	/* get new process' cpu context and restore */
993ca54502bSMichal Simek	/* give me start where start context of next task */
994ca54502bSMichal Simek	addik	r11, r6, TI_CPU_CONTEXT
995ca54502bSMichal Simek
996ca54502bSMichal Simek	/* non-volatile registers */
997ca54502bSMichal Simek	lwi	r30, r11, CC_R30
998ca54502bSMichal Simek	lwi	r29, r11, CC_R29
999ca54502bSMichal Simek	lwi	r28, r11, CC_R28
1000ca54502bSMichal Simek	lwi	r27, r11, CC_R27
1001ca54502bSMichal Simek	lwi	r26, r11, CC_R26
1002ca54502bSMichal Simek	lwi	r25, r11, CC_R25
1003ca54502bSMichal Simek	lwi	r24, r11, CC_R24
1004ca54502bSMichal Simek	lwi	r23, r11, CC_R23
1005ca54502bSMichal Simek	lwi	r22, r11, CC_R22
1006ca54502bSMichal Simek	lwi	r21, r11, CC_R21
1007ca54502bSMichal Simek	lwi	r20, r11, CC_R20
1008ca54502bSMichal Simek	lwi	r19, r11, CC_R19
1009ca54502bSMichal Simek	/* dedicated registers */
1010ca54502bSMichal Simek	lwi	r18, r11, CC_R18
1011ca54502bSMichal Simek	lwi	r17, r11, CC_R17
1012ca54502bSMichal Simek	lwi	r16, r11, CC_R16
1013ca54502bSMichal Simek	lwi	r15, r11, CC_R15
1014ca54502bSMichal Simek	lwi	r14, r11, CC_R14
1015ca54502bSMichal Simek	lwi	r13, r11, CC_R13
1016ca54502bSMichal Simek	/* skip volatile registers */
1017ca54502bSMichal Simek	lwi	r2, r11, CC_R2
1018ca54502bSMichal Simek	lwi	r1, r11, CC_R1
1019ca54502bSMichal Simek
1020ca54502bSMichal Simek	/* special purpose registers */
1021ca54502bSMichal Simek	lwi	r12, r11, CC_FSR
1022ca54502bSMichal Simek	mts	rfsr, r12
1023ca54502bSMichal Simek	nop
1024ca54502bSMichal Simek	lwi	r12, r11, CC_MSR
1025ca54502bSMichal Simek	mts	rmsr, r12
1026ca54502bSMichal Simek	nop
1027ca54502bSMichal Simek
1028ca54502bSMichal Simek	rtsd	r15, 8
1029ca54502bSMichal Simek	nop
1030ca54502bSMichal Simek
1031ca54502bSMichal SimekENTRY(_reset)
1032ca54502bSMichal Simek	brai	0x70; /* Jump back to FS-boot */
1033ca54502bSMichal Simek
1034ca54502bSMichal SimekENTRY(_break)
1035ca54502bSMichal Simek	mfs	r5, rmsr
1036ca54502bSMichal Simek	nop
1037ca54502bSMichal Simek	swi	r5, r0, 0x250 + TOPHYS(r0_ram)
1038ca54502bSMichal Simek	mfs	r5, resr
1039ca54502bSMichal Simek	nop
1040ca54502bSMichal Simek	swi	r5, r0, 0x254 + TOPHYS(r0_ram)
1041ca54502bSMichal Simek	bri	0
1042ca54502bSMichal Simek
1043ca54502bSMichal Simek	/* These are compiled and loaded into high memory, then
1044ca54502bSMichal Simek	 * copied into place in mach_early_setup */
1045ca54502bSMichal Simek	.section	.init.ivt, "ax"
1046ca54502bSMichal Simek	.org	0x0
1047ca54502bSMichal Simek	/* this is very important - here is the reset vector */
1048ca54502bSMichal Simek	/* in current MMU branch you don't care what is here - it is
1049ca54502bSMichal Simek	 * used from bootloader site - but this is correct for FS-BOOT */
1050ca54502bSMichal Simek	brai	0x70
1051ca54502bSMichal Simek	nop
1052ca54502bSMichal Simek	brai	TOPHYS(_user_exception); /* syscall handler */
1053ca54502bSMichal Simek	brai	TOPHYS(_interrupt);	/* Interrupt handler */
1054ca54502bSMichal Simek	brai	TOPHYS(_break);		/* nmi trap handler */
1055ca54502bSMichal Simek	brai	TOPHYS(_hw_exception_handler);	/* HW exception handler */
1056ca54502bSMichal Simek
1057ca54502bSMichal Simek	.org	0x60
1058ca54502bSMichal Simek	brai	TOPHYS(_debug_exception);	/* debug trap handler*/
1059ca54502bSMichal Simek
1060ca54502bSMichal Simek.section .rodata,"a"
1061ca54502bSMichal Simek#include "syscall_table.S"
1062ca54502bSMichal Simek
1063ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table)
1064ca54502bSMichal Simek
1065ce3266c0SSteven J. Magnanitype_SYSCALL:
1066ce3266c0SSteven J. Magnani	.ascii "SYSCALL\0"
1067ce3266c0SSteven J. Magnanitype_IRQ:
1068ce3266c0SSteven J. Magnani	.ascii "IRQ\0"
1069ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT:
1070ce3266c0SSteven J. Magnani	.ascii "IRQ (PREEMPTED)\0"
1071ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT:
1072ce3266c0SSteven J. Magnani	.ascii " SYSCALL (PREEMPTED)\0"
1073ce3266c0SSteven J. Magnani
1074ce3266c0SSteven J. Magnani	/*
1075ce3266c0SSteven J. Magnani	 * Trap decoding for stack unwinder
1076ce3266c0SSteven J. Magnani	 * Tuples are (start addr, end addr, string)
1077ce3266c0SSteven J. Magnani	 * If return address lies on [start addr, end addr],
1078ce3266c0SSteven J. Magnani	 * unwinder displays 'string'
1079ce3266c0SSteven J. Magnani	 */
1080ce3266c0SSteven J. Magnani
1081ce3266c0SSteven J. Magnani	.align 4
1082ce3266c0SSteven J. Magnani.global microblaze_trap_handlers
1083ce3266c0SSteven J. Magnanimicroblaze_trap_handlers:
1084ce3266c0SSteven J. Magnani	/* Exact matches come first */
1085ce3266c0SSteven J. Magnani	.word ret_from_trap; .word ret_from_trap   ; .word type_SYSCALL
1086ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word ret_from_irq    ; .word type_IRQ
1087ce3266c0SSteven J. Magnani	/* Fuzzy matches go here */
1088ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1089ce3266c0SSteven J. Magnani	.word ret_from_trap; .word TRAP_return     ; .word type_SYSCALL_PREEMPT
1090ce3266c0SSteven J. Magnani	/* End of table */
1091ce3266c0SSteven J. Magnani	.word 0               ; .word 0               ; .word 0
1092