xref: /openbmc/linux/arch/microblaze/kernel/entry.S (revision d8748e73e882106ff0ffa0fa2192dab111a9f9f8)
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
42*d8748e73SMichal Simek#ifdef DEBUG
43*d8748e73SMichal Simek/* Create space for syscalls counting. */
44*d8748e73SMichal Simek.section .data
45*d8748e73SMichal Simek.global syscall_debug_table
46*d8748e73SMichal Simek.align 4
47*d8748e73SMichal Simeksyscall_debug_table:
48*d8748e73SMichal Simek	.space	(__NR_syscalls * 4)
49*d8748e73SMichal Simek#endif /* DEBUG */
50*d8748e73SMichal Simek
51ca54502bSMichal Simek#define C_ENTRY(name)	.globl name; .align 4; name
52ca54502bSMichal Simek
53ca54502bSMichal Simek/*
54ca54502bSMichal Simek * Various ways of setting and clearing BIP in flags reg.
55ca54502bSMichal Simek * This is mucky, but necessary using microblaze version that
56ca54502bSMichal Simek * allows msr ops to write to BIP
57ca54502bSMichal Simek */
58ca54502bSMichal Simek#if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
59ca54502bSMichal Simek	.macro	clear_bip
6066f7de86SMichal Simek	msrclr	r0, MSR_BIP
61ca54502bSMichal Simek	.endm
62ca54502bSMichal Simek
63ca54502bSMichal Simek	.macro	set_bip
6466f7de86SMichal Simek	msrset	r0, MSR_BIP
65ca54502bSMichal Simek	.endm
66ca54502bSMichal Simek
67ca54502bSMichal Simek	.macro	clear_eip
6866f7de86SMichal Simek	msrclr	r0, MSR_EIP
69ca54502bSMichal Simek	.endm
70ca54502bSMichal Simek
71ca54502bSMichal Simek	.macro	set_ee
7266f7de86SMichal Simek	msrset	r0, MSR_EE
73ca54502bSMichal Simek	.endm
74ca54502bSMichal Simek
75ca54502bSMichal Simek	.macro	disable_irq
7666f7de86SMichal Simek	msrclr	r0, MSR_IE
77ca54502bSMichal Simek	.endm
78ca54502bSMichal Simek
79ca54502bSMichal Simek	.macro	enable_irq
8066f7de86SMichal Simek	msrset	r0, MSR_IE
81ca54502bSMichal Simek	.endm
82ca54502bSMichal Simek
83ca54502bSMichal Simek	.macro	set_ums
8466f7de86SMichal Simek	msrset	r0, MSR_UMS
8566f7de86SMichal Simek	msrclr	r0, MSR_VMS
86ca54502bSMichal Simek	.endm
87ca54502bSMichal Simek
88ca54502bSMichal Simek	.macro	set_vms
8966f7de86SMichal Simek	msrclr	r0, MSR_UMS
9066f7de86SMichal Simek	msrset	r0, MSR_VMS
91ca54502bSMichal Simek	.endm
92ca54502bSMichal Simek
93b318067eSMichal Simek	.macro	clear_ums
9466f7de86SMichal Simek	msrclr	r0, MSR_UMS
95b318067eSMichal Simek	.endm
96b318067eSMichal Simek
97ca54502bSMichal Simek	.macro	clear_vms_ums
9866f7de86SMichal Simek	msrclr	r0, MSR_VMS | MSR_UMS
99ca54502bSMichal Simek	.endm
100ca54502bSMichal Simek#else
101ca54502bSMichal Simek	.macro	clear_bip
102ca54502bSMichal Simek	mfs	r11, rmsr
103ca54502bSMichal Simek	andi	r11, r11, ~MSR_BIP
104ca54502bSMichal Simek	mts	rmsr, r11
105ca54502bSMichal Simek	.endm
106ca54502bSMichal Simek
107ca54502bSMichal Simek	.macro	set_bip
108ca54502bSMichal Simek	mfs	r11, rmsr
109ca54502bSMichal Simek	ori	r11, r11, MSR_BIP
110ca54502bSMichal Simek	mts	rmsr, r11
111ca54502bSMichal Simek	.endm
112ca54502bSMichal Simek
113ca54502bSMichal Simek	.macro	clear_eip
114ca54502bSMichal Simek	mfs	r11, rmsr
115ca54502bSMichal Simek	andi	r11, r11, ~MSR_EIP
116ca54502bSMichal Simek	mts	rmsr, r11
117ca54502bSMichal Simek	.endm
118ca54502bSMichal Simek
119ca54502bSMichal Simek	.macro	set_ee
120ca54502bSMichal Simek	mfs	r11, rmsr
121ca54502bSMichal Simek	ori	r11, r11, MSR_EE
122ca54502bSMichal Simek	mts	rmsr, r11
123ca54502bSMichal Simek	.endm
124ca54502bSMichal Simek
125ca54502bSMichal Simek	.macro	disable_irq
126ca54502bSMichal Simek	mfs	r11, rmsr
127ca54502bSMichal Simek	andi	r11, r11, ~MSR_IE
128ca54502bSMichal Simek	mts	rmsr, r11
129ca54502bSMichal Simek	.endm
130ca54502bSMichal Simek
131ca54502bSMichal Simek	.macro	enable_irq
132ca54502bSMichal Simek	mfs	r11, rmsr
133ca54502bSMichal Simek	ori	r11, r11, MSR_IE
134ca54502bSMichal Simek	mts	rmsr, r11
135ca54502bSMichal Simek	.endm
136ca54502bSMichal Simek
137ca54502bSMichal Simek	.macro set_ums
138ca54502bSMichal Simek	mfs	r11, rmsr
139ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
140ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
141ca54502bSMichal Simek	mts	rmsr, r11
142ca54502bSMichal Simek	.endm
143ca54502bSMichal Simek
144ca54502bSMichal Simek	.macro	set_vms
145ca54502bSMichal Simek	mfs	r11, rmsr
146ca54502bSMichal Simek	ori	r11, r11, MSR_VMS
147ca54502bSMichal Simek	andni	r11, r11, MSR_UMS
148ca54502bSMichal Simek	mts	rmsr, r11
149ca54502bSMichal Simek	.endm
150ca54502bSMichal Simek
151b318067eSMichal Simek	.macro	clear_ums
152b318067eSMichal Simek	mfs	r11, rmsr
153b318067eSMichal Simek	andni	r11, r11, MSR_UMS
154b318067eSMichal Simek	mts	rmsr,r11
155b318067eSMichal Simek	.endm
156b318067eSMichal Simek
157ca54502bSMichal Simek	.macro	clear_vms_ums
158ca54502bSMichal Simek	mfs	r11, rmsr
159ca54502bSMichal Simek	andni	r11, r11, (MSR_VMS|MSR_UMS)
160ca54502bSMichal Simek	mts	rmsr,r11
161ca54502bSMichal Simek	.endm
162ca54502bSMichal Simek#endif
163ca54502bSMichal Simek
164ca54502bSMichal Simek/* Define how to call high-level functions. With MMU, virtual mode must be
165ca54502bSMichal Simek * enabled when calling the high-level function. Clobbers R11.
166ca54502bSMichal Simek * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
167ca54502bSMichal Simek */
168ca54502bSMichal Simek
169ca54502bSMichal Simek/* turn on virtual protected mode save */
170ca54502bSMichal Simek#define VM_ON		\
171ca54502bSMichal Simek	set_ums;	\
172ca54502bSMichal Simek	rted	r0, 2f;	\
173a4a94dbfSMichal Simek	nop; \
174a4a94dbfSMichal Simek2:
175ca54502bSMichal Simek
176ca54502bSMichal Simek/* turn off virtual protected mode save and user mode save*/
177ca54502bSMichal Simek#define VM_OFF			\
178ca54502bSMichal Simek	clear_vms_ums;		\
179ca54502bSMichal Simek	rted	r0, TOPHYS(1f);	\
180a4a94dbfSMichal Simek	nop; \
181a4a94dbfSMichal Simek1:
182ca54502bSMichal Simek
183ca54502bSMichal Simek#define SAVE_REGS \
184ca54502bSMichal Simek	swi	r2, r1, PTO+PT_R2;	/* Save SDA */			\
18536f60954SMichal Simek	swi	r3, r1, PTO+PT_R3;					\
18636f60954SMichal Simek	swi	r4, r1, PTO+PT_R4;					\
187ca54502bSMichal Simek	swi	r5, r1, PTO+PT_R5;					\
188ca54502bSMichal Simek	swi	r6, r1, PTO+PT_R6;					\
189ca54502bSMichal Simek	swi	r7, r1, PTO+PT_R7;					\
190ca54502bSMichal Simek	swi	r8, r1, PTO+PT_R8;					\
191ca54502bSMichal Simek	swi	r9, r1, PTO+PT_R9;					\
192ca54502bSMichal Simek	swi	r10, r1, PTO+PT_R10;					\
193ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R11;	/* save clobbered regs after rval */\
194ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R12;					\
195ca54502bSMichal Simek	swi	r13, r1, PTO+PT_R13;	/* Save SDA2 */			\
196ca54502bSMichal Simek	swi	r14, r1, PTO+PT_PC;	/* PC, before IRQ/trap */	\
197ca54502bSMichal Simek	swi	r15, r1, PTO+PT_R15;	/* Save LP */			\
198600eb611SMichal Simek	swi	r16, r1, PTO+PT_R16;					\
199600eb611SMichal Simek	swi	r17, r1, PTO+PT_R17;					\
200ca54502bSMichal Simek	swi	r18, r1, PTO+PT_R18;	/* Save asm scratch reg */	\
201ca54502bSMichal Simek	swi	r19, r1, PTO+PT_R19;					\
202ca54502bSMichal Simek	swi	r20, r1, PTO+PT_R20;					\
203ca54502bSMichal Simek	swi	r21, r1, PTO+PT_R21;					\
204ca54502bSMichal Simek	swi	r22, r1, PTO+PT_R22;					\
205ca54502bSMichal Simek	swi	r23, r1, PTO+PT_R23;					\
206ca54502bSMichal Simek	swi	r24, r1, PTO+PT_R24;					\
207ca54502bSMichal Simek	swi	r25, r1, PTO+PT_R25;					\
208ca54502bSMichal Simek	swi	r26, r1, PTO+PT_R26;					\
209ca54502bSMichal Simek	swi	r27, r1, PTO+PT_R27;					\
210ca54502bSMichal Simek	swi	r28, r1, PTO+PT_R28;					\
211ca54502bSMichal Simek	swi	r29, r1, PTO+PT_R29;					\
212ca54502bSMichal Simek	swi	r30, r1, PTO+PT_R30;					\
213ca54502bSMichal Simek	swi	r31, r1, PTO+PT_R31;	/* Save current task reg */	\
214ca54502bSMichal Simek	mfs	r11, rmsr;		/* save MSR */			\
215ca54502bSMichal Simek	swi	r11, r1, PTO+PT_MSR;
216ca54502bSMichal Simek
217ca54502bSMichal Simek#define RESTORE_REGS \
218ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_MSR;					\
219ca54502bSMichal Simek	mts	rmsr , r11;						\
220ca54502bSMichal Simek	lwi	r2, r1, PTO+PT_R2;	/* restore SDA */		\
22136f60954SMichal Simek	lwi	r3, r1, PTO+PT_R3;					\
22236f60954SMichal Simek	lwi	r4, r1, PTO+PT_R4;					\
223ca54502bSMichal Simek	lwi	r5, r1, PTO+PT_R5;					\
224ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R6;					\
225ca54502bSMichal Simek	lwi	r7, r1, PTO+PT_R7;					\
226ca54502bSMichal Simek	lwi	r8, r1, PTO+PT_R8;					\
227ca54502bSMichal Simek	lwi	r9, r1, PTO+PT_R9;					\
228ca54502bSMichal Simek	lwi	r10, r1, PTO+PT_R10;					\
229ca54502bSMichal Simek	lwi	r11, r1, PTO+PT_R11;	/* restore clobbered regs after rval */\
230ca54502bSMichal Simek	lwi	r12, r1, PTO+PT_R12;					\
231ca54502bSMichal Simek	lwi	r13, r1, PTO+PT_R13;	/* restore SDA2 */		\
232ca54502bSMichal Simek	lwi	r14, r1, PTO+PT_PC;	/* RESTORE_LINK PC, before IRQ/trap */\
233ca54502bSMichal Simek	lwi	r15, r1, PTO+PT_R15;	/* restore LP */		\
234600eb611SMichal Simek	lwi	r16, r1, PTO+PT_R16;					\
235600eb611SMichal Simek	lwi	r17, r1, PTO+PT_R17;					\
236ca54502bSMichal Simek	lwi	r18, r1, PTO+PT_R18;	/* restore asm scratch reg */	\
237ca54502bSMichal Simek	lwi	r19, r1, PTO+PT_R19;					\
238ca54502bSMichal Simek	lwi	r20, r1, PTO+PT_R20;					\
239ca54502bSMichal Simek	lwi	r21, r1, PTO+PT_R21;					\
240ca54502bSMichal Simek	lwi	r22, r1, PTO+PT_R22;					\
241ca54502bSMichal Simek	lwi	r23, r1, PTO+PT_R23;					\
242ca54502bSMichal Simek	lwi	r24, r1, PTO+PT_R24;					\
243ca54502bSMichal Simek	lwi	r25, r1, PTO+PT_R25;					\
244ca54502bSMichal Simek	lwi	r26, r1, PTO+PT_R26;					\
245ca54502bSMichal Simek	lwi	r27, r1, PTO+PT_R27;					\
246ca54502bSMichal Simek	lwi	r28, r1, PTO+PT_R28;					\
247ca54502bSMichal Simek	lwi	r29, r1, PTO+PT_R29;					\
248ca54502bSMichal Simek	lwi	r30, r1, PTO+PT_R30;					\
249ca54502bSMichal Simek	lwi	r31, r1, PTO+PT_R31;	/* Restore cur task reg */
250ca54502bSMichal Simek
251e5d2af2bSMichal Simek#define SAVE_STATE	\
252e5d2af2bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */	\
253e5d2af2bSMichal Simek	/* See if already in kernel mode.*/				\
254e5d2af2bSMichal Simek	mfs	r1, rmsr;						\
255e5d2af2bSMichal Simek	andi	r1, r1, MSR_UMS;					\
256e5d2af2bSMichal Simek	bnei	r1, 1f;						\
257e5d2af2bSMichal Simek	/* Kernel-mode state save.  */					\
258e5d2af2bSMichal Simek	/* Reload kernel stack-ptr. */					\
259e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
260287503faSMichal Simek	/* FIXME: I can add these two lines to one */			\
261287503faSMichal Simek	/* tophys(r1,r1); */						\
262287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
263287503faSMichal Simek	addik	r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
264e5d2af2bSMichal Simek	SAVE_REGS							\
265e5d2af2bSMichal Simek	brid	2f;							\
266da233552SMichal Simek	swi	r1, r1, PTO+PT_MODE; 	 				\
267e5d2af2bSMichal Simek1:	/* User-mode state save.  */					\
268e5d2af2bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
269e5d2af2bSMichal Simek	tophys(r1,r1);							\
270e5d2af2bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */	\
271287503faSMichal Simek	/* MS these three instructions can be added to one */		\
272287503faSMichal Simek	/* addik	r1, r1, THREAD_SIZE; */				\
273287503faSMichal Simek	/* tophys(r1,r1); */						\
274287503faSMichal Simek	/* addik	r1, r1, -STATE_SAVE_SIZE; */			\
275287503faSMichal Simek	addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE; \
276e5d2af2bSMichal Simek	SAVE_REGS							\
277e5d2af2bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));			\
278e5d2af2bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */		\
279e7741075SMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */		\
280e5d2af2bSMichal Simek	/* MS: I am clearing UMS even in case when I come from kernel space */ \
281e5d2af2bSMichal Simek	clear_ums; 							\
282e5d2af2bSMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
283e5d2af2bSMichal Simek
284ca54502bSMichal Simek.text
285ca54502bSMichal Simek
286ca54502bSMichal Simek/*
287ca54502bSMichal Simek * User trap.
288ca54502bSMichal Simek *
289ca54502bSMichal Simek * System calls are handled here.
290ca54502bSMichal Simek *
291ca54502bSMichal Simek * Syscall protocol:
292ca54502bSMichal Simek * Syscall number in r12, args in r5-r10
293ca54502bSMichal Simek * Return value in r3
294ca54502bSMichal Simek *
295ca54502bSMichal Simek * Trap entered via brki instruction, so BIP bit is set, and interrupts
296ca54502bSMichal Simek * are masked. This is nice, means we don't have to CLI before state save
297ca54502bSMichal Simek */
298ca54502bSMichal SimekC_ENTRY(_user_exception):
2990e41c909SMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
3009da63458SMichal Simek	addi	r14, r14, 4	/* return address is 4 byte after call */
301ca54502bSMichal Simek
3029da63458SMichal Simek	mfs	r1, rmsr
3039da63458SMichal Simek	nop
3049da63458SMichal Simek	andi	r1, r1, MSR_UMS
3059da63458SMichal Simek	bnei	r1, 1f
3069da63458SMichal Simek
3079da63458SMichal Simek/* Kernel-mode state save - kernel execve */
3089da63458SMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
3099da63458SMichal Simek	tophys(r1,r1);
3109da63458SMichal Simek
3119da63458SMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
3129da63458SMichal Simek	SAVE_REGS
3139da63458SMichal Simek
3149da63458SMichal Simek	swi	r1, r1, PTO + PT_MODE; /* pt_regs -> kernel mode */
3159da63458SMichal Simek	brid	2f;
3169da63458SMichal Simek	nop;				/* Fill delay slot */
3179da63458SMichal Simek
3189da63458SMichal Simek/* User-mode state save.  */
3199da63458SMichal Simek1:
320ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
321ca54502bSMichal Simek	tophys(r1,r1);
322ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get stack from task_struct */
3239da63458SMichal Simek/* calculate kernel stack pointer from task struct 8k */
3249da63458SMichal Simek	addik	r1, r1, THREAD_SIZE;
3259da63458SMichal Simek	tophys(r1,r1);
3269da63458SMichal Simek
3279da63458SMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
328ca54502bSMichal Simek	SAVE_REGS
3297d432095SMichal Simek	swi	r0, r1, PTO + PT_R3
3307d432095SMichal Simek	swi	r0, r1, PTO + PT_R4
331ca54502bSMichal Simek
3329da63458SMichal Simek	swi	r0, r1, PTO + PT_MODE;			/* Was in user-mode. */
333ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
334ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;		/* Store user SP.  */
33525f6e596SMichal Simek	clear_ums;
3369da63458SMichal Simek2:	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
337ca54502bSMichal Simek	/* Save away the syscall number.  */
338ca54502bSMichal Simek	swi	r12, r1, PTO+PT_R0;
339ca54502bSMichal Simek	tovirt(r1,r1)
340ca54502bSMichal Simek
341ca54502bSMichal Simek/* where the trap should return need -8 to adjust for rtsd r15, 8*/
342ca54502bSMichal Simek/* Jump to the appropriate function for the system call number in r12
343ca54502bSMichal Simek * (r12 is not preserved), or return an error if r12 is not valid. The LP
344ca54502bSMichal Simek * register should point to the location where
345ca54502bSMichal Simek * the called function should return.  [note that MAKE_SYS_CALL uses label 1] */
34623575483SMichal Simek
34725f6e596SMichal Simek	/* Step into virtual mode */
34825f6e596SMichal Simek	rtbd	r0, 3f
34923575483SMichal Simek	nop
35023575483SMichal Simek3:
351b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
35223575483SMichal Simek	lwi	r11, r11, TI_FLAGS	 /* get flags in thread info */
35323575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
35423575483SMichal Simek	beqi	r11, 4f
35523575483SMichal Simek
35623575483SMichal Simek	addik	r3, r0, -ENOSYS
35723575483SMichal Simek	swi	r3, r1, PTO + PT_R3
35823575483SMichal Simek	brlid	r15, do_syscall_trace_enter
35923575483SMichal Simek	addik	r5, r1, PTO + PT_R0
36023575483SMichal Simek
36123575483SMichal Simek	# do_syscall_trace_enter returns the new syscall nr.
36223575483SMichal Simek	addk	r12, r0, r3
36323575483SMichal Simek	lwi	r5, r1, PTO+PT_R5;
36423575483SMichal Simek	lwi	r6, r1, PTO+PT_R6;
36523575483SMichal Simek	lwi	r7, r1, PTO+PT_R7;
36623575483SMichal Simek	lwi	r8, r1, PTO+PT_R8;
36723575483SMichal Simek	lwi	r9, r1, PTO+PT_R9;
36823575483SMichal Simek	lwi	r10, r1, PTO+PT_R10;
36923575483SMichal Simek4:
37023575483SMichal Simek/* Jump to the appropriate function for the system call number in r12
37123575483SMichal Simek * (r12 is not preserved), or return an error if r12 is not valid.
37223575483SMichal Simek * The LP register should point to the location where the called function
37323575483SMichal Simek * should return.  [note that MAKE_SYS_CALL uses label 1] */
37423575483SMichal Simek	/* See if the system call number is valid */
375ca54502bSMichal Simek	addi	r11, r12, -__NR_syscalls;
37623575483SMichal Simek	bgei	r11,5f;
377ca54502bSMichal Simek	/* Figure out which function to use for this system call.  */
378ca54502bSMichal Simek	/* Note Microblaze barrel shift is optional, so don't rely on it */
379ca54502bSMichal Simek	add	r12, r12, r12;			/* convert num -> ptr */
380ca54502bSMichal Simek	add	r12, r12, r12;
381ca54502bSMichal Simek
38211d51360SMichal Simek#ifdef DEBUG
383*d8748e73SMichal Simek	/* Trac syscalls and stored them to syscall_debug_table */
384*d8748e73SMichal Simek	/* The first syscall location stores total syscall number */
385*d8748e73SMichal Simek	lwi	r3, r0, syscall_debug_table
386ca54502bSMichal Simek	addi	r3, r3, 1
387*d8748e73SMichal Simek	swi	r3, r0, syscall_debug_table
388*d8748e73SMichal Simek	lwi	r3, r12, syscall_debug_table
389*d8748e73SMichal Simek	addi	r3, r3, 1
390*d8748e73SMichal Simek	swi	r3, r12, syscall_debug_table
39111d51360SMichal Simek#endif
392ca54502bSMichal Simek
39323575483SMichal Simek	# Find and jump into the syscall handler.
39423575483SMichal Simek	lwi	r12, r12, sys_call_table
39523575483SMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
396b9ea77e2SMichal Simek	addi	r15, r0, ret_from_trap-8
39723575483SMichal Simek	bra	r12
39823575483SMichal Simek
399ca54502bSMichal Simek	/* The syscall number is invalid, return an error.  */
40023575483SMichal Simek5:
401ca54502bSMichal Simek	rtsd	r15, 8;		/* looks like a normal subroutine return */
4029814cc11SMichal Simek	addi	r3, r0, -ENOSYS;
403ca54502bSMichal Simek
40423575483SMichal Simek/* Entry point used to return from a syscall/trap */
405ca54502bSMichal Simek/* We re-enable BIP bit before state restore */
406ca54502bSMichal SimekC_ENTRY(ret_from_trap):
407b1d70c62SMichal Simek	swi	r3, r1, PTO + PT_R3
408b1d70c62SMichal Simek	swi	r4, r1, PTO + PT_R4
409b1d70c62SMichal Simek
4109da63458SMichal Simek	lwi	r11, r1, PTO + PT_MODE;
4119da63458SMichal Simek/* See if returning to kernel mode, if so, skip resched &c.  */
4129da63458SMichal Simek	bnei	r11, 2f;
413ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
414ca54502bSMichal Simek	 * trigger rescheduling. */
415b1d70c62SMichal Simek	/* FIXME: Restructure all these flag checks. */
416b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
41723575483SMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
41823575483SMichal Simek	andi	r11, r11, _TIF_WORK_SYSCALL_MASK
41923575483SMichal Simek	beqi	r11, 1f
42023575483SMichal Simek
42123575483SMichal Simek	brlid	r15, do_syscall_trace_leave
42223575483SMichal Simek	addik	r5, r1, PTO + PT_R0
42323575483SMichal Simek1:
42423575483SMichal Simek	/* We're returning to user mode, so check for various conditions that
42523575483SMichal Simek	 * trigger rescheduling. */
426b1d70c62SMichal Simek	/* get thread info from current task */
427b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
428ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;		/* get flags in thread info */
429ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
430ca54502bSMichal Simek	beqi	r11, 5f;
431ca54502bSMichal Simek
432ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
433ca54502bSMichal Simek	nop;				/* delay slot */
434ca54502bSMichal Simek
435ca54502bSMichal Simek	/* Maybe handle a signal */
436b1d70c62SMichal Simek5:	/* get thread info from current task*/
437b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
438ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
439ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
440ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
441ca54502bSMichal Simek
442b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
443ca54502bSMichal Simek	addi	r7, r0, 1;		/* Arg 3: int in_syscall */
444ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
445841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
446b1d70c62SMichal Simek
447b1d70c62SMichal Simek/* Finally, return to user state.  */
44896014cc3SMichal Simek1:	set_bip;			/*  Ints masked for state restore */
4498633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
450ca54502bSMichal Simek	VM_OFF;
451ca54502bSMichal Simek	tophys(r1,r1);
452ca54502bSMichal Simek	RESTORE_REGS;
453ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
454ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
4559da63458SMichal Simek	bri	6f;
4569da63458SMichal Simek
4579da63458SMichal Simek/* Return to kernel state.  */
4589da63458SMichal Simek2:	set_bip;			/*  Ints masked for state restore */
4599da63458SMichal Simek	VM_OFF;
4609da63458SMichal Simek	tophys(r1,r1);
4619da63458SMichal Simek	RESTORE_REGS;
4629da63458SMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
4639da63458SMichal Simek	tovirt(r1,r1);
4649da63458SMichal Simek6:
465ca54502bSMichal SimekTRAP_return:		/* Make global symbol for debugging */
466ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
467ca54502bSMichal Simek	nop;
468ca54502bSMichal Simek
469ca54502bSMichal Simek
470ca54502bSMichal Simek/* These syscalls need access to the struct pt_regs on the stack, so we
471ca54502bSMichal Simek   implement them in assembly (they're basically all wrappers anyway).  */
472ca54502bSMichal Simek
473ca54502bSMichal SimekC_ENTRY(sys_fork_wrapper):
474ca54502bSMichal Simek	addi	r5, r0, SIGCHLD			/* Arg 0: flags */
475ca54502bSMichal Simek	lwi	r6, r1, PTO+PT_R1	/* Arg 1: child SP (use parent's) */
476b9ea77e2SMichal Simek	addik	r7, r1, PTO			/* Arg 2: parent context */
477ca54502bSMichal Simek	add	r8. r0, r0			/* Arg 3: (unused) */
478ca54502bSMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
479ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
4809814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
481ca54502bSMichal Simek
482ca54502bSMichal Simek/* This the initial entry point for a new child thread, with an appropriate
483ca54502bSMichal Simek   stack in place that makes it look the the child is in the middle of an
484ca54502bSMichal Simek   syscall.  This function is actually `returned to' from switch_thread
485ca54502bSMichal Simek   (copy_thread makes ret_from_fork the return address in each new thread's
486ca54502bSMichal Simek   saved context).  */
487ca54502bSMichal SimekC_ENTRY(ret_from_fork):
488ca54502bSMichal Simek	bralid	r15, schedule_tail; /* ...which is schedule_tail's arg */
489ca54502bSMichal Simek	add	r3, r5, r0;	/* switch_thread returns the prev task */
490ca54502bSMichal Simek				/* ( in the delay slot ) */
491ca54502bSMichal Simek	brid	ret_from_trap;	/* Do normal trap return */
4929814cc11SMichal Simek	add	r3, r0, r0;	/* Child's fork call should return 0. */
493ca54502bSMichal Simek
494e513588fSArnd BergmannC_ENTRY(sys_vfork):
495e513588fSArnd Bergmann	brid	microblaze_vfork	/* Do real work (tail-call) */
496b9ea77e2SMichal Simek	addik	r5, r1, PTO
497ca54502bSMichal Simek
498e513588fSArnd BergmannC_ENTRY(sys_clone):
499ca54502bSMichal Simek	bnei	r6, 1f;			/* See if child SP arg (arg 1) is 0. */
500ca54502bSMichal Simek	lwi	r6, r1, PTO + PT_R1;	/* If so, use paret's stack ptr */
501b9ea77e2SMichal Simek1:	addik	r7, r1, PTO;			/* Arg 2: parent context */
502b9ea77e2SMichal Simek	add	r8, r0, r0;			/* Arg 3: (unused) */
503b9ea77e2SMichal Simek	add	r9, r0, r0;			/* Arg 4: (unused) */
504ca54502bSMichal Simek	brid	do_fork		/* Do real work (tail-call) */
5059814cc11SMichal Simek	add	r10, r0, r0;			/* Arg 5: (unused) */
506ca54502bSMichal Simek
507e513588fSArnd BergmannC_ENTRY(sys_execve):
508e513588fSArnd Bergmann	brid	microblaze_execve;	/* Do real work (tail-call).*/
5099814cc11SMichal Simek	addik	r8, r1, PTO;		/* add user context as 4th arg */
510ca54502bSMichal Simek
511ca54502bSMichal SimekC_ENTRY(sys_rt_sigreturn_wrapper):
512791d0a16SMichal Simek	brid	sys_rt_sigreturn	/* Do real work */
5139814cc11SMichal Simek	addik	r5, r1, PTO;		/* add user context as 1st arg */
514ca54502bSMichal Simek
515ca54502bSMichal Simek/*
516ca54502bSMichal Simek * HW EXCEPTION rutine start
517ca54502bSMichal Simek */
518ca54502bSMichal SimekC_ENTRY(full_exception_trap):
519ca54502bSMichal Simek	/* adjust exception address for privileged instruction
520ca54502bSMichal Simek	 * for finding where is it */
521ca54502bSMichal Simek	addik	r17, r17, -4
522ca54502bSMichal Simek	SAVE_STATE /* Save registers */
52306a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
52406a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
52506a54604SMichal Simek	tovirt(r1,r1)
526ca54502bSMichal Simek	/* FIXME this can be store directly in PT_ESR reg.
527ca54502bSMichal Simek	 * I tested it but there is a fault */
528ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
529b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc - 8
530ca54502bSMichal Simek	mfs	r6, resr
531ca54502bSMichal Simek	mfs	r7, rfsr;		/* save FSR */
532131e4e97SMichal Simek	mts	rfsr, r0;	/* Clear sticky fsr */
533c318d483SMichal Simek	rted	r0, full_exception
5349814cc11SMichal Simek	addik	r5, r1, PTO		 /* parameter struct pt_regs * regs */
535ca54502bSMichal Simek
536ca54502bSMichal Simek/*
537ca54502bSMichal Simek * Unaligned data trap.
538ca54502bSMichal Simek *
539ca54502bSMichal Simek * Unaligned data trap last on 4k page is handled here.
540ca54502bSMichal Simek *
541ca54502bSMichal Simek * Trap entered via exception, so EE bit is set, and interrupts
542ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
543ca54502bSMichal Simek *
544ca54502bSMichal Simek * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
545ca54502bSMichal Simek */
546ca54502bSMichal SimekC_ENTRY(unaligned_data_trap):
5478b110d15SMichal Simek	/* MS: I have to save r11 value and then restore it because
5488b110d15SMichal Simek	 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
5498b110d15SMichal Simek	 * instructions are not used. We don't need to do if MSR instructions
5508b110d15SMichal Simek	 * are used and they use r0 instead of r11.
5518b110d15SMichal Simek	 * I am using ENTRY_SP which should be primary used only for stack
5528b110d15SMichal Simek	 * pointer saving. */
5538b110d15SMichal Simek	swi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
5548b110d15SMichal Simek	set_bip;        /* equalize initial state for all possible entries */
5558b110d15SMichal Simek	clear_eip;
5568b110d15SMichal Simek	set_ee;
5578b110d15SMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
558ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
55906a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
56006a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
56106a54604SMichal Simek	tovirt(r1,r1)
562ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
563b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
564ca54502bSMichal Simek	mfs	r3, resr		/* ESR */
565ca54502bSMichal Simek	mfs	r4, rear		/* EAR */
566c318d483SMichal Simek	rtbd	r0, _unaligned_data_exception
567b9ea77e2SMichal Simek	addik	r7, r1, PTO		/* parameter struct pt_regs * regs */
568ca54502bSMichal Simek
569ca54502bSMichal Simek/*
570ca54502bSMichal Simek * Page fault traps.
571ca54502bSMichal Simek *
572ca54502bSMichal Simek * If the real exception handler (from hw_exception_handler.S) didn't find
573ca54502bSMichal Simek * the mapping for the process, then we're thrown here to handle such situation.
574ca54502bSMichal Simek *
575ca54502bSMichal Simek * Trap entered via exceptions, so EE bit is set, and interrupts
576ca54502bSMichal Simek * are masked.  This is nice, means we don't have to CLI before state save
577ca54502bSMichal Simek *
578ca54502bSMichal Simek * Build a standard exception frame for TLB Access errors.  All TLB exceptions
579ca54502bSMichal Simek * will bail out to this point if they can't resolve the lightweight TLB fault.
580ca54502bSMichal Simek *
581ca54502bSMichal Simek * The C function called is in "arch/microblaze/mm/fault.c", declared as:
582ca54502bSMichal Simek * void do_page_fault(struct pt_regs *regs,
583ca54502bSMichal Simek *				unsigned long address,
584ca54502bSMichal Simek *				unsigned long error_code)
585ca54502bSMichal Simek */
586ca54502bSMichal Simek/* data and intruction trap - which is choose is resolved int fault.c */
587ca54502bSMichal SimekC_ENTRY(page_fault_data_trap):
588ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
58906a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
59006a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
59106a54604SMichal Simek	tovirt(r1,r1)
592ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
593b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
594ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
595ca54502bSMichal Simek	mfs	r7, resr		/* parameter unsigned long error_code */
596c318d483SMichal Simek	rted	r0, do_page_fault
5979814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
598ca54502bSMichal Simek
599ca54502bSMichal SimekC_ENTRY(page_fault_instr_trap):
600ca54502bSMichal Simek	SAVE_STATE		/* Save registers.*/
60106a54604SMichal Simek	/* PC, before IRQ/trap - this is one instruction above */
60206a54604SMichal Simek	swi	r17, r1, PTO+PT_PC;
60306a54604SMichal Simek	tovirt(r1,r1)
604ca54502bSMichal Simek	/* where the trap should return need -8 to adjust for rtsd r15, 8 */
605b9ea77e2SMichal Simek	addik	r15, r0, ret_from_exc-8
606ca54502bSMichal Simek	mfs	r6, rear		/* parameter unsigned long address */
607ca54502bSMichal Simek	ori	r7, r0, 0		/* parameter unsigned long error_code */
6089814cc11SMichal Simek	rted	r0, do_page_fault
6099814cc11SMichal Simek	addik	r5, r1, PTO		/* parameter struct pt_regs * regs */
610ca54502bSMichal Simek
611ca54502bSMichal Simek/* Entry point used to return from an exception.  */
612ca54502bSMichal SimekC_ENTRY(ret_from_exc):
613ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
614ca54502bSMichal Simek	bnei	r11, 2f;		/* See if returning to kernel mode, */
615ca54502bSMichal Simek					/* ... if so, skip resched &c.  */
616ca54502bSMichal Simek
617ca54502bSMichal Simek	/* We're returning to user mode, so check for various conditions that
618ca54502bSMichal Simek	   trigger rescheduling. */
619b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
620ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
621ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
622ca54502bSMichal Simek	beqi	r11, 5f;
623ca54502bSMichal Simek
624ca54502bSMichal Simek/* Call the scheduler before returning from a syscall/trap. */
625ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
626ca54502bSMichal Simek	nop;				/* delay slot */
627ca54502bSMichal Simek
628ca54502bSMichal Simek	/* Maybe handle a signal */
629b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
630ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
631ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
632ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
633ca54502bSMichal Simek
634ca54502bSMichal Simek	/*
635ca54502bSMichal Simek	 * Handle a signal return; Pending signals should be in r18.
636ca54502bSMichal Simek	 *
637ca54502bSMichal Simek	 * Not all registers are saved by the normal trap/interrupt entry
638ca54502bSMichal Simek	 * points (for instance, call-saved registers (because the normal
639ca54502bSMichal Simek	 * C-compiler calling sequence in the kernel makes sure they're
640ca54502bSMichal Simek	 * preserved), and call-clobbered registers in the case of
641ca54502bSMichal Simek	 * traps), but signal handlers may want to examine or change the
642ca54502bSMichal Simek	 * complete register state.  Here we save anything not saved by
643ca54502bSMichal Simek	 * the normal entry sequence, so that it may be safely restored
64436f60954SMichal Simek	 * (in a possibly modified form) after do_signal returns. */
645b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
646ca54502bSMichal Simek	addi	r7, r0, 0;		/* Arg 3: int in_syscall */
647ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
648841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
649ca54502bSMichal Simek
650ca54502bSMichal Simek/* Finally, return to user state.  */
65196014cc3SMichal Simek1:	set_bip;			/* Ints masked for state restore */
6528633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
653ca54502bSMichal Simek	VM_OFF;
654ca54502bSMichal Simek	tophys(r1,r1);
655ca54502bSMichal Simek
656ca54502bSMichal Simek	RESTORE_REGS;
657ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
658ca54502bSMichal Simek
659ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
660ca54502bSMichal Simek	bri	6f;
661ca54502bSMichal Simek/* Return to kernel state.  */
66296014cc3SMichal Simek2:	set_bip;			/* Ints masked for state restore */
66396014cc3SMichal Simek	VM_OFF;
664ca54502bSMichal Simek	tophys(r1,r1);
665ca54502bSMichal Simek	RESTORE_REGS;
666ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE		/* Clean up stack space.  */
667ca54502bSMichal Simek
668ca54502bSMichal Simek	tovirt(r1,r1);
669ca54502bSMichal Simek6:
670ca54502bSMichal SimekEXC_return:		/* Make global symbol for debugging */
671ca54502bSMichal Simek	rtbd	r14, 0;	/* Instructions to return from an IRQ */
672ca54502bSMichal Simek	nop;
673ca54502bSMichal Simek
674ca54502bSMichal Simek/*
675ca54502bSMichal Simek * HW EXCEPTION rutine end
676ca54502bSMichal Simek */
677ca54502bSMichal Simek
678ca54502bSMichal Simek/*
679ca54502bSMichal Simek * Hardware maskable interrupts.
680ca54502bSMichal Simek *
681ca54502bSMichal Simek * The stack-pointer (r1) should have already been saved to the memory
682ca54502bSMichal Simek * location PER_CPU(ENTRY_SP).
683ca54502bSMichal Simek */
684ca54502bSMichal SimekC_ENTRY(_interrupt):
685ca54502bSMichal Simek/* MS: we are in physical address */
686ca54502bSMichal Simek/* Save registers, switch to proper stack, convert SP to virtual.*/
687ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
688ca54502bSMichal Simek	/* MS: See if already in kernel mode. */
689653e447eSMichal Simek	mfs	r1, rmsr
6905c0d72b1SMichal Simek	nop
691653e447eSMichal Simek	andi	r1, r1, MSR_UMS
692653e447eSMichal Simek	bnei	r1, 1f
693ca54502bSMichal Simek
694ca54502bSMichal Simek/* Kernel-mode state save. */
695653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
696653e447eSMichal Simek	tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
697ca54502bSMichal Simek	/* save registers */
698ca54502bSMichal Simek/* MS: Make room on the stack -> activation record */
699ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
700ca54502bSMichal Simek	SAVE_REGS
701ca54502bSMichal Simek	brid	2f;
7020a6b08fdSMichal Simek	swi	r1, r1, PTO + PT_MODE; /* 0 - user mode, 1 - kernel mode */
703ca54502bSMichal Simek1:
704ca54502bSMichal Simek/* User-mode state save. */
705ca54502bSMichal Simek /* MS: get the saved current */
706ca54502bSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
707ca54502bSMichal Simek	tophys(r1,r1);
708ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;
709ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;
710ca54502bSMichal Simek	tophys(r1,r1);
711ca54502bSMichal Simek	/* save registers */
712ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE;
713ca54502bSMichal Simek	SAVE_REGS
714ca54502bSMichal Simek	/* calculate mode */
715ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE;
716ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
717ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1;
71880c5ff6bSMichal Simek	clear_ums;
719ca54502bSMichal Simek2:
720b1d70c62SMichal Simek	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
721ca54502bSMichal Simek	tovirt(r1,r1)
722b9ea77e2SMichal Simek	addik	r15, r0, irq_call;
72380c5ff6bSMichal Simekirq_call:rtbd	r0, do_IRQ;
72480c5ff6bSMichal Simek	addik	r5, r1, PTO;
725ca54502bSMichal Simek
726ca54502bSMichal Simek/* MS: we are in virtual mode */
727ca54502bSMichal Simekret_from_irq:
728ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
729ca54502bSMichal Simek	bnei	r11, 2f;
730ca54502bSMichal Simek
731b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
732ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* MS: get flags from thread info */
733ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
734ca54502bSMichal Simek	beqi	r11, 5f
735ca54502bSMichal Simek	bralid	r15, schedule;
736ca54502bSMichal Simek	nop; /* delay slot */
737ca54502bSMichal Simek
738ca54502bSMichal Simek    /* Maybe handle a signal */
739b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */
740ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS; /* get flags in thread info */
741ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
742ca54502bSMichal Simek	beqid	r11, no_intr_resched
743ca54502bSMichal Simek/* Handle a signal return; Pending signals should be in r18. */
744ca54502bSMichal Simek	addi	r7, r0, 0; /* Arg 3: int in_syscall */
745b9ea77e2SMichal Simek	addik	r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
746ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
747ca54502bSMichal Simek	add	r6, r0, r0; /* Arg 2: sigset_t *oldset */
748ca54502bSMichal Simek
749ca54502bSMichal Simek/* Finally, return to user state. */
750ca54502bSMichal Simekno_intr_resched:
751ca54502bSMichal Simek    /* Disable interrupts, we are now committed to the state restore */
752ca54502bSMichal Simek	disable_irq
7538633bebcSMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
754ca54502bSMichal Simek	VM_OFF;
755ca54502bSMichal Simek	tophys(r1,r1);
756ca54502bSMichal Simek	RESTORE_REGS
757ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */
758ca54502bSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE;
759ca54502bSMichal Simek	bri	6f;
760ca54502bSMichal Simek/* MS: Return to kernel state. */
76177753790SMichal Simek2:
76277753790SMichal Simek#ifdef CONFIG_PREEMPT
763b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;
76477753790SMichal Simek	/* MS: get preempt_count from thread info */
76577753790SMichal Simek	lwi	r5, r11, TI_PREEMPT_COUNT;
76677753790SMichal Simek	bgti	r5, restore;
76777753790SMichal Simek
76877753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
76977753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
77077753790SMichal Simek	beqi	r5, restore /* if zero jump over */
77177753790SMichal Simek
77277753790SMichal Simekpreempt:
77377753790SMichal Simek	/* interrupts are off that's why I am calling preempt_chedule_irq */
77477753790SMichal Simek	bralid	r15, preempt_schedule_irq
77577753790SMichal Simek	nop
776b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
77777753790SMichal Simek	lwi	r5, r11, TI_FLAGS;		/* get flags in thread info */
77877753790SMichal Simek	andi	r5, r5, _TIF_NEED_RESCHED;
77977753790SMichal Simek	bnei	r5, preempt /* if non zero jump to resched */
78077753790SMichal Simekrestore:
78177753790SMichal Simek#endif
78277753790SMichal Simek	VM_OFF /* MS: turn off MMU */
783ca54502bSMichal Simek	tophys(r1,r1)
784ca54502bSMichal Simek	RESTORE_REGS
785ca54502bSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE	/* MS: Clean up stack space. */
786ca54502bSMichal Simek	tovirt(r1,r1);
787ca54502bSMichal Simek6:
788ca54502bSMichal SimekIRQ_return: /* MS: Make global symbol for debugging */
789ca54502bSMichal Simek	rtid	r14, 0
790ca54502bSMichal Simek	nop
791ca54502bSMichal Simek
792ca54502bSMichal Simek/*
7932d5973cbSMichal Simek * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
7942d5973cbSMichal Simek * and call handling function with saved pt_regs
795ca54502bSMichal Simek */
796ca54502bSMichal SimekC_ENTRY(_debug_exception):
797ca54502bSMichal Simek	/* BIP bit is set on entry, no interrupts can occur */
798ca54502bSMichal Simek	swi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
799ca54502bSMichal Simek
800653e447eSMichal Simek	mfs	r1, rmsr
8015c0d72b1SMichal Simek	nop
802653e447eSMichal Simek	andi	r1, r1, MSR_UMS
803653e447eSMichal Simek	bnei	r1, 1f
8042d5973cbSMichal Simek/* MS: Kernel-mode state save - kgdb */
805653e447eSMichal Simek	lwi	r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
806ca54502bSMichal Simek
8072d5973cbSMichal Simek	/* BIP bit is set on entry, no interrupts can occur */
8082d5973cbSMichal Simek	addik   r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - STATE_SAVE_SIZE;
809ca54502bSMichal Simek	SAVE_REGS;
8102d5973cbSMichal Simek	/* save all regs to pt_reg structure */
8112d5973cbSMichal Simek	swi	r0, r1, PTO+PT_R0;	/* R0 must be saved too */
8122d5973cbSMichal Simek	swi	r14, r1, PTO+PT_R14	/* rewrite saved R14 value */
8132d5973cbSMichal Simek	swi	r16, r1, PTO+PT_PC; /* PC and r16 are the same */
8142d5973cbSMichal Simek	/* save special purpose registers to pt_regs */
8152d5973cbSMichal Simek	mfs	r11, rear;
8162d5973cbSMichal Simek	swi	r11, r1, PTO+PT_EAR;
8172d5973cbSMichal Simek	mfs	r11, resr;
8182d5973cbSMichal Simek	swi	r11, r1, PTO+PT_ESR;
8192d5973cbSMichal Simek	mfs	r11, rfsr;
8202d5973cbSMichal Simek	swi	r11, r1, PTO+PT_FSR;
821ca54502bSMichal Simek
8222d5973cbSMichal Simek	/* stack pointer is in physical address at it is decrease
8232d5973cbSMichal Simek	 * by STATE_SAVE_SIZE but we need to get correct R1 value */
8242d5973cbSMichal Simek	addik   r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + STATE_SAVE_SIZE;
8252d5973cbSMichal Simek	swi	r11, r1, PTO+PT_R1
8262d5973cbSMichal Simek	/* MS: r31 - current pointer isn't changed */
8272d5973cbSMichal Simek	tovirt(r1,r1)
8282d5973cbSMichal Simek#ifdef CONFIG_KGDB
8292d5973cbSMichal Simek	addi	r5, r1, PTO /* pass pt_reg address as the first arg */
8302d5973cbSMichal Simek	la	r15, r0, dbtrap_call; /* return address */
8312d5973cbSMichal Simek	rtbd	r0, microblaze_kgdb_break
8322d5973cbSMichal Simek	nop;
8332d5973cbSMichal Simek#endif
8342d5973cbSMichal Simek	/* MS: Place handler for brki from kernel space if KGDB is OFF.
8352d5973cbSMichal Simek	 * It is very unlikely that another brki instruction is called. */
8362d5973cbSMichal Simek	bri 0
8372d5973cbSMichal Simek
8382d5973cbSMichal Simek/* MS: User-mode state save - gdb */
8392d5973cbSMichal Simek1:	lwi	r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
840ca54502bSMichal Simek	tophys(r1,r1);
841ca54502bSMichal Simek	lwi	r1, r1, TS_THREAD_INFO;	/* get the thread info */
842ca54502bSMichal Simek	addik	r1, r1, THREAD_SIZE;	/* calculate kernel stack pointer */
843ca54502bSMichal Simek	tophys(r1,r1);
844ca54502bSMichal Simek
845ca54502bSMichal Simek	addik	r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack.  */
846ca54502bSMichal Simek	SAVE_REGS;
847751f1605SMichal Simek	swi	r16, r1, PTO+PT_PC;	/* Save LP */
848ca54502bSMichal Simek	swi	r0, r1, PTO + PT_MODE; /* Was in user-mode.  */
849ca54502bSMichal Simek	lwi	r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
850ca54502bSMichal Simek	swi	r11, r1, PTO+PT_R1; /* Store user SP.  */
8512d5973cbSMichal Simek	lwi	CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
852ca54502bSMichal Simek	tovirt(r1,r1)
85306b28640SMichal Simek	set_vms;
854751f1605SMichal Simek	addik	r5, r1, PTO;
855b9ea77e2SMichal Simek	addik	r15, r0, dbtrap_call;
8562d5973cbSMichal Simekdbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
857751f1605SMichal Simek	rtbd	r0, sw_exception
858751f1605SMichal Simek	nop
859ca54502bSMichal Simek
8602d5973cbSMichal Simek	/* MS: The first instruction for the second part of the gdb/kgdb */
861ca54502bSMichal Simek	set_bip; /* Ints masked for state restore */
862ca54502bSMichal Simek	lwi	r11, r1, PTO + PT_MODE;
863ca54502bSMichal Simek	bnei	r11, 2f;
8642d5973cbSMichal Simek/* MS: Return to user space - gdb */
865ca54502bSMichal Simek	/* Get current task ptr into r11 */
866b1d70c62SMichal Simek	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
867ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
868ca54502bSMichal Simek	andi	r11, r11, _TIF_NEED_RESCHED;
869ca54502bSMichal Simek	beqi	r11, 5f;
870ca54502bSMichal Simek
871ca54502bSMichal Simek	/* Call the scheduler before returning from a syscall/trap. */
872ca54502bSMichal Simek	bralid	r15, schedule;	/* Call scheduler */
873ca54502bSMichal Simek	nop;				/* delay slot */
874ca54502bSMichal Simek
875ca54502bSMichal Simek	/* Maybe handle a signal */
876b1d70c62SMichal Simek5:	lwi	r11, CURRENT_TASK, TS_THREAD_INFO;	/* get thread info */
877ca54502bSMichal Simek	lwi	r11, r11, TI_FLAGS;	/* get flags in thread info */
878ca54502bSMichal Simek	andi	r11, r11, _TIF_SIGPENDING;
879ca54502bSMichal Simek	beqi	r11, 1f;		/* Signals to handle, handle them */
880ca54502bSMichal Simek
881b9ea77e2SMichal Simek	addik	r5, r1, PTO;		/* Arg 1: struct pt_regs *regs */
882ca54502bSMichal Simek	addi  r7, r0, 0;	/* Arg 3: int in_syscall */
883ca54502bSMichal Simek	bralid	r15, do_signal;	/* Handle any signals */
884841d6e8cSMichal Simek	add	r6, r0, r0;		/* Arg 2: sigset_t *oldset */
885ca54502bSMichal Simek
886ca54502bSMichal Simek/* Finally, return to user state.  */
8872d5973cbSMichal Simek1:	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
888ca54502bSMichal Simek	VM_OFF;
889ca54502bSMichal Simek	tophys(r1,r1);
8902d5973cbSMichal Simek	/* MS: Restore all regs */
891ca54502bSMichal Simek	RESTORE_REGS
8922d5973cbSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE	 /* Clean up stack space */
8932d5973cbSMichal Simek	lwi	r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
8942d5973cbSMichal SimekDBTRAP_return_user: /* MS: Make global symbol for debugging */
8952d5973cbSMichal Simek	rtbd	r16, 0; /* MS: Instructions to return from a debug trap */
8962d5973cbSMichal Simek	nop;
897ca54502bSMichal Simek
8982d5973cbSMichal Simek/* MS: Return to kernel state - kgdb */
899ca54502bSMichal Simek2:	VM_OFF;
900ca54502bSMichal Simek	tophys(r1,r1);
9012d5973cbSMichal Simek	/* MS: Restore all regs */
902ca54502bSMichal Simek	RESTORE_REGS
9032d5973cbSMichal Simek	lwi	r14, r1, PTO+PT_R14;
9042d5973cbSMichal Simek	lwi	r16, r1, PTO+PT_PC;
9052d5973cbSMichal Simek	addik	r1, r1, STATE_SAVE_SIZE; /* MS: Clean up stack space */
906ca54502bSMichal Simek	tovirt(r1,r1);
9072d5973cbSMichal SimekDBTRAP_return_kernel: /* MS: Make global symbol for debugging */
9082d5973cbSMichal Simek	rtbd	r16, 0; /* MS: Instructions to return from a debug trap */
909ca54502bSMichal Simek	nop;
910ca54502bSMichal Simek
911ca54502bSMichal Simek
912ca54502bSMichal SimekENTRY(_switch_to)
913ca54502bSMichal Simek	/* prepare return value */
914b1d70c62SMichal Simek	addk	r3, r0, CURRENT_TASK
915ca54502bSMichal Simek
916ca54502bSMichal Simek	/* save registers in cpu_context */
917ca54502bSMichal Simek	/* use r11 and r12, volatile registers, as temp register */
918ca54502bSMichal Simek	/* give start of cpu_context for previous process */
919ca54502bSMichal Simek	addik	r11, r5, TI_CPU_CONTEXT
920ca54502bSMichal Simek	swi	r1, r11, CC_R1
921ca54502bSMichal Simek	swi	r2, r11, CC_R2
922ca54502bSMichal Simek	/* skip volatile registers.
923ca54502bSMichal Simek	 * they are saved on stack when we jumped to _switch_to() */
924ca54502bSMichal Simek	/* dedicated registers */
925ca54502bSMichal Simek	swi	r13, r11, CC_R13
926ca54502bSMichal Simek	swi	r14, r11, CC_R14
927ca54502bSMichal Simek	swi	r15, r11, CC_R15
928ca54502bSMichal Simek	swi	r16, r11, CC_R16
929ca54502bSMichal Simek	swi	r17, r11, CC_R17
930ca54502bSMichal Simek	swi	r18, r11, CC_R18
931ca54502bSMichal Simek	/* save non-volatile registers */
932ca54502bSMichal Simek	swi	r19, r11, CC_R19
933ca54502bSMichal Simek	swi	r20, r11, CC_R20
934ca54502bSMichal Simek	swi	r21, r11, CC_R21
935ca54502bSMichal Simek	swi	r22, r11, CC_R22
936ca54502bSMichal Simek	swi	r23, r11, CC_R23
937ca54502bSMichal Simek	swi	r24, r11, CC_R24
938ca54502bSMichal Simek	swi	r25, r11, CC_R25
939ca54502bSMichal Simek	swi	r26, r11, CC_R26
940ca54502bSMichal Simek	swi	r27, r11, CC_R27
941ca54502bSMichal Simek	swi	r28, r11, CC_R28
942ca54502bSMichal Simek	swi	r29, r11, CC_R29
943ca54502bSMichal Simek	swi	r30, r11, CC_R30
944ca54502bSMichal Simek	/* special purpose registers */
945ca54502bSMichal Simek	mfs	r12, rmsr
946ca54502bSMichal Simek	swi	r12, r11, CC_MSR
947ca54502bSMichal Simek	mfs	r12, rear
948ca54502bSMichal Simek	swi	r12, r11, CC_EAR
949ca54502bSMichal Simek	mfs	r12, resr
950ca54502bSMichal Simek	swi	r12, r11, CC_ESR
951ca54502bSMichal Simek	mfs	r12, rfsr
952ca54502bSMichal Simek	swi	r12, r11, CC_FSR
953ca54502bSMichal Simek
954b1d70c62SMichal Simek	/* update r31, the current-give me pointer to task which will be next */
955b1d70c62SMichal Simek	lwi	CURRENT_TASK, r6, TI_TASK
956ca54502bSMichal Simek	/* stored it to current_save too */
957b1d70c62SMichal Simek	swi	CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
958ca54502bSMichal Simek
959ca54502bSMichal Simek	/* get new process' cpu context and restore */
960ca54502bSMichal Simek	/* give me start where start context of next task */
961ca54502bSMichal Simek	addik	r11, r6, TI_CPU_CONTEXT
962ca54502bSMichal Simek
963ca54502bSMichal Simek	/* non-volatile registers */
964ca54502bSMichal Simek	lwi	r30, r11, CC_R30
965ca54502bSMichal Simek	lwi	r29, r11, CC_R29
966ca54502bSMichal Simek	lwi	r28, r11, CC_R28
967ca54502bSMichal Simek	lwi	r27, r11, CC_R27
968ca54502bSMichal Simek	lwi	r26, r11, CC_R26
969ca54502bSMichal Simek	lwi	r25, r11, CC_R25
970ca54502bSMichal Simek	lwi	r24, r11, CC_R24
971ca54502bSMichal Simek	lwi	r23, r11, CC_R23
972ca54502bSMichal Simek	lwi	r22, r11, CC_R22
973ca54502bSMichal Simek	lwi	r21, r11, CC_R21
974ca54502bSMichal Simek	lwi	r20, r11, CC_R20
975ca54502bSMichal Simek	lwi	r19, r11, CC_R19
976ca54502bSMichal Simek	/* dedicated registers */
977ca54502bSMichal Simek	lwi	r18, r11, CC_R18
978ca54502bSMichal Simek	lwi	r17, r11, CC_R17
979ca54502bSMichal Simek	lwi	r16, r11, CC_R16
980ca54502bSMichal Simek	lwi	r15, r11, CC_R15
981ca54502bSMichal Simek	lwi	r14, r11, CC_R14
982ca54502bSMichal Simek	lwi	r13, r11, CC_R13
983ca54502bSMichal Simek	/* skip volatile registers */
984ca54502bSMichal Simek	lwi	r2, r11, CC_R2
985ca54502bSMichal Simek	lwi	r1, r11, CC_R1
986ca54502bSMichal Simek
987ca54502bSMichal Simek	/* special purpose registers */
988ca54502bSMichal Simek	lwi	r12, r11, CC_FSR
989ca54502bSMichal Simek	mts	rfsr, r12
990ca54502bSMichal Simek	lwi	r12, r11, CC_MSR
991ca54502bSMichal Simek	mts	rmsr, r12
992ca54502bSMichal Simek
993ca54502bSMichal Simek	rtsd	r15, 8
994ca54502bSMichal Simek	nop
995ca54502bSMichal Simek
996ca54502bSMichal SimekENTRY(_reset)
997ca54502bSMichal Simek	brai	0x70; /* Jump back to FS-boot */
998ca54502bSMichal Simek
999ca54502bSMichal Simek	/* These are compiled and loaded into high memory, then
1000ca54502bSMichal Simek	 * copied into place in mach_early_setup */
1001ca54502bSMichal Simek	.section	.init.ivt, "ax"
1002ca54502bSMichal Simek	.org	0x0
1003ca54502bSMichal Simek	/* this is very important - here is the reset vector */
1004ca54502bSMichal Simek	/* in current MMU branch you don't care what is here - it is
1005ca54502bSMichal Simek	 * used from bootloader site - but this is correct for FS-BOOT */
1006ca54502bSMichal Simek	brai	0x70
1007ca54502bSMichal Simek	nop
1008ca54502bSMichal Simek	brai	TOPHYS(_user_exception); /* syscall handler */
1009ca54502bSMichal Simek	brai	TOPHYS(_interrupt);	/* Interrupt handler */
1010ca54502bSMichal Simek	brai	TOPHYS(_debug_exception);	/* debug trap handler */
1011751f1605SMichal Simek	brai	TOPHYS(_hw_exception_handler);	/* HW exception handler */
1012ca54502bSMichal Simek
1013ca54502bSMichal Simek.section .rodata,"a"
1014ca54502bSMichal Simek#include "syscall_table.S"
1015ca54502bSMichal Simek
1016ca54502bSMichal Simeksyscall_table_size=(.-sys_call_table)
1017ca54502bSMichal Simek
1018ce3266c0SSteven J. Magnanitype_SYSCALL:
1019ce3266c0SSteven J. Magnani	.ascii "SYSCALL\0"
1020ce3266c0SSteven J. Magnanitype_IRQ:
1021ce3266c0SSteven J. Magnani	.ascii "IRQ\0"
1022ce3266c0SSteven J. Magnanitype_IRQ_PREEMPT:
1023ce3266c0SSteven J. Magnani	.ascii "IRQ (PREEMPTED)\0"
1024ce3266c0SSteven J. Magnanitype_SYSCALL_PREEMPT:
1025ce3266c0SSteven J. Magnani	.ascii " SYSCALL (PREEMPTED)\0"
1026ce3266c0SSteven J. Magnani
1027ce3266c0SSteven J. Magnani	/*
1028ce3266c0SSteven J. Magnani	 * Trap decoding for stack unwinder
1029ce3266c0SSteven J. Magnani	 * Tuples are (start addr, end addr, string)
1030ce3266c0SSteven J. Magnani	 * If return address lies on [start addr, end addr],
1031ce3266c0SSteven J. Magnani	 * unwinder displays 'string'
1032ce3266c0SSteven J. Magnani	 */
1033ce3266c0SSteven J. Magnani
1034ce3266c0SSteven J. Magnani	.align 4
1035ce3266c0SSteven J. Magnani.global microblaze_trap_handlers
1036ce3266c0SSteven J. Magnanimicroblaze_trap_handlers:
1037ce3266c0SSteven J. Magnani	/* Exact matches come first */
1038ce3266c0SSteven J. Magnani	.word ret_from_trap; .word ret_from_trap   ; .word type_SYSCALL
1039ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word ret_from_irq    ; .word type_IRQ
1040ce3266c0SSteven J. Magnani	/* Fuzzy matches go here */
1041ce3266c0SSteven J. Magnani	.word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1042ce3266c0SSteven J. Magnani	.word ret_from_trap; .word TRAP_return     ; .word type_SYSCALL_PREEMPT
1043ce3266c0SSteven J. Magnani	/* End of table */
1044ce3266c0SSteven J. Magnani	.word 0               ; .word 0               ; .word 0
1045