18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Preliminary support for HW exception handing for Microblaze
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
68c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 PetaLogix
78c2ecf20Sopenharmony_ci * Copyright (C) 2005 John Williams <jwilliams@itee.uq.edu.au>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _ASM_MICROBLAZE_EXCEPTIONS_H
118c2ecf20Sopenharmony_ci#define _ASM_MICROBLAZE_EXCEPTIONS_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifdef __KERNEL__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef CONFIG_MMU
168c2ecf20Sopenharmony_ci#define EX_HANDLER_STACK_SIZ	(4*19)
178c2ecf20Sopenharmony_ci#endif
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* Macros to enable and disable HW exceptions in the MSR */
228c2ecf20Sopenharmony_ci/* Define MSR enable bit for HW exceptions */
238c2ecf20Sopenharmony_ci#define HWEX_MSR_BIT (1 << 8)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
268c2ecf20Sopenharmony_ci#define __enable_hw_exceptions()					\
278c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("	msrset	r0, %0;				\
288c2ecf20Sopenharmony_ci				nop;"					\
298c2ecf20Sopenharmony_ci				:					\
308c2ecf20Sopenharmony_ci				: "i" (HWEX_MSR_BIT)			\
318c2ecf20Sopenharmony_ci				: "memory")
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define __disable_hw_exceptions()					\
348c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("	msrclr r0, %0;				\
358c2ecf20Sopenharmony_ci				nop;"					\
368c2ecf20Sopenharmony_ci				:					\
378c2ecf20Sopenharmony_ci				: "i" (HWEX_MSR_BIT)			\
388c2ecf20Sopenharmony_ci				: "memory")
398c2ecf20Sopenharmony_ci#else /* !CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR */
408c2ecf20Sopenharmony_ci#define __enable_hw_exceptions()					\
418c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("						\
428c2ecf20Sopenharmony_ci				mfs	r12, rmsr;			\
438c2ecf20Sopenharmony_ci				nop;					\
448c2ecf20Sopenharmony_ci				ori	r12, r12, %0;			\
458c2ecf20Sopenharmony_ci				mts	rmsr, r12;			\
468c2ecf20Sopenharmony_ci				nop;"					\
478c2ecf20Sopenharmony_ci				:					\
488c2ecf20Sopenharmony_ci				: "i" (HWEX_MSR_BIT)			\
498c2ecf20Sopenharmony_ci				: "memory", "r12")
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define __disable_hw_exceptions()					\
528c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("						\
538c2ecf20Sopenharmony_ci				mfs	r12, rmsr;			\
548c2ecf20Sopenharmony_ci				nop;					\
558c2ecf20Sopenharmony_ci				andi	r12, r12, ~%0;			\
568c2ecf20Sopenharmony_ci				mts	rmsr, r12;			\
578c2ecf20Sopenharmony_ci				nop;"					\
588c2ecf20Sopenharmony_ci				:					\
598c2ecf20Sopenharmony_ci				: "i" (HWEX_MSR_BIT)			\
608c2ecf20Sopenharmony_ci				: "memory", "r12")
618c2ecf20Sopenharmony_ci#endif /* CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciasmlinkage void full_exception(struct pt_regs *regs, unsigned int type,
648c2ecf20Sopenharmony_ci							int fsr, int addr);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciasmlinkage void sw_exception(struct pt_regs *regs);
678c2ecf20Sopenharmony_civoid bad_page_fault(struct pt_regs *regs, unsigned long address, int sig);
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_civoid die(const char *str, struct pt_regs *fp, long err);
708c2ecf20Sopenharmony_civoid _exception(int signr, struct pt_regs *regs, int code, unsigned long addr);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#endif /*__ASSEMBLY__ */
738c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
748c2ecf20Sopenharmony_ci#endif /* _ASM_MICROBLAZE_EXCEPTIONS_H */
75