18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Port on Texas Instruments TMS320C6x architecture
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
68c2ecf20Sopenharmony_ci *  Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#ifndef _ASM_C6X_SPECIAL_INSNS_H
98c2ecf20Sopenharmony_ci#define _ASM_C6X_SPECIAL_INSNS_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define get_creg(reg) \
138c2ecf20Sopenharmony_ci	({ unsigned int __x; \
148c2ecf20Sopenharmony_ci	   asm volatile ("mvc .s2 " #reg ",%0\n" : "=b"(__x)); __x; })
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define set_creg(reg, v) \
178c2ecf20Sopenharmony_ci	do { unsigned int __x = (unsigned int)(v); \
188c2ecf20Sopenharmony_ci		asm volatile ("mvc .s2 %0," #reg "\n" : : "b"(__x)); \
198c2ecf20Sopenharmony_ci	} while (0)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define or_creg(reg, n) \
228c2ecf20Sopenharmony_ci	do { unsigned __x, __n = (unsigned)(n);		  \
238c2ecf20Sopenharmony_ci		asm volatile ("mvc .s2 " #reg ",%0\n"	  \
248c2ecf20Sopenharmony_ci			      "or  .l2 %1,%0,%0\n"	  \
258c2ecf20Sopenharmony_ci			      "mvc .s2 %0," #reg "\n"	  \
268c2ecf20Sopenharmony_ci			      "nop\n"			  \
278c2ecf20Sopenharmony_ci			      : "=&b"(__x) : "b"(__n));	  \
288c2ecf20Sopenharmony_ci	} while (0)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define and_creg(reg, n) \
318c2ecf20Sopenharmony_ci	do { unsigned __x, __n = (unsigned)(n);		  \
328c2ecf20Sopenharmony_ci		asm volatile ("mvc .s2 " #reg ",%0\n"	  \
338c2ecf20Sopenharmony_ci			      "and .l2 %1,%0,%0\n"	  \
348c2ecf20Sopenharmony_ci			      "mvc .s2 %0," #reg "\n"	  \
358c2ecf20Sopenharmony_ci			      "nop\n"    \
368c2ecf20Sopenharmony_ci			      : "=&b"(__x) : "b"(__n));	  \
378c2ecf20Sopenharmony_ci	} while (0)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define get_coreid() (get_creg(DNUM) & 0xff)
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* Set/get IST */
428c2ecf20Sopenharmony_ci#define set_ist(x)	set_creg(ISTP, x)
438c2ecf20Sopenharmony_ci#define get_ist()       get_creg(ISTP)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Exception management
478c2ecf20Sopenharmony_ci */
488c2ecf20Sopenharmony_ci#define disable_exception()
498c2ecf20Sopenharmony_ci#define get_except_type()        get_creg(EFR)
508c2ecf20Sopenharmony_ci#define ack_exception(type)      set_creg(ECR, 1 << (type))
518c2ecf20Sopenharmony_ci#define get_iexcept()            get_creg(IERR)
528c2ecf20Sopenharmony_ci#define set_iexcept(mask)        set_creg(IERR, (mask))
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define _extu(x, s, e)							\
558c2ecf20Sopenharmony_ci	({      unsigned int __x;					\
568c2ecf20Sopenharmony_ci		asm volatile ("extu .S2 %3,%1,%2,%0\n" :		\
578c2ecf20Sopenharmony_ci			      "=b"(__x) : "n"(s), "n"(e), "b"(x));	\
588c2ecf20Sopenharmony_ci	       __x; })
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#endif /* _ASM_C6X_SPECIAL_INSNS_H */
61