1 /*****************************************************************************
2 * © 2014 Microchip Technology Inc. and its subsidiaries.
3 * You may use this software and any derivatives exclusively with
5 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".
6 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
7 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
8 * AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP
9 * PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.
14 * TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
15 * CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF
16 * FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
19 *****************************************************************************/
22 *MEC14xx platform/cpu abstractions
30 #if defined(__GNUC__) && defined(__mips__)
32 #if defined(__XC32__) // Microchip XC32 GCC
34 /* Pull in MIPS32 specific special instructions instrinsics for
35 * interrupt control, NOP, Wait-for-Interrupt and accessing
37 * Issue: MPLAB-X IDE editor and the CPU macros in xc.h & cp0defs.h.
38 * The IDE editor will show red ! on every line of code using the above
39 * macros due to a bug in the IDE's C language preprocessor.
43 #define CPU_DISABLE_INTERRUPTS() __builtin_disable_interrupts()
44 #define CPU_GET_DISABLE_INTERRUPTS(x) { x=_CP0_GET_STATUS()&0x1ul; __builtin_disable_interrupts() }
45 #define CPU_ENABLE_INTERRUPTS() __builtin_enable_interrupts()
46 #define CPU_RESTORE_INTERRUPTS(x) { if (x) { __builtin_enable_interrupts(); } }
48 #define Disable_Irq() CPU_DISABLE_INTERRUPTS()
49 #define Enable_Irq() CPU_ENABLE_INTERRUPTS()
51 #define __CLZ(x) __builtin_clz(x)
52 #define __CTZ(x) __builtin_ctz (x)
53 #define __CLO(x) _clo(x)
55 #define __INS(tgt,val,pos,sz) _ins(tgt,val,pos,sz)
56 #define __EXT(x,pos,sz) _ext(x,pos,sz)
58 #define CPU_NOP() __asm__ __volatile ("%(ssnop%)" : :)
60 #define CPU_WAIT_FOR_INTR() __asm__ __volatile ("wait")
62 #define __REV(x) _bswapw(x)
64 #define __EHB() _ehb()
68 /* Include MIPS specific inline assembly functions for accessing
69 * MIPS CP0 registers, NOP, WAIT, ASET, ACLR, byte-reverse, etc.
74 #define CPU_DISABLE_INTERRUPTS() mips32r2_dis_intr()
75 #define CPU_GET_DISABLE_INTERRUPTS(x) x=mips32r2_dis_intr()
76 #define CPU_ENABLE_INTERRUPTS() mips32r2_en_intr()
77 #define CPU_RESTORE_INTERRUPTS(x) mips32r2_restore_intr(x)
79 #define Disable_Irq() CPU_DISABLE_INTERRUPTS()
80 #define Enable_Irq() CPU_ENABLE_INTERRUPTS()
82 #define __CLZ(x) __builtin_clz(x)
83 #define __CTZ(x) __builtin_ctz (x)
85 #define __CLO(x) __extension__({ \
86 unsigned int __x = (x); \
88 __asm__ ("clo %0,%1" : "=d" (__v) : "d" (__x)); \
92 /* MIPS32r2 insert bits */
93 #define __INS(tgt,val,pos,sz) __extension__({ \
94 unsigned int __t = (tgt), __v = (val); \
95 __asm__ ("ins %0,%z1,%2,%3" \
97 : "dJ" (__v), "I" (pos), "I" (sz)); \
101 /* MIPS32r2 extract bits */
102 #define __EXT(x,pos,sz) __extension__({ \
103 unsigned int __x = (x), __v; \
104 __asm__ ("ext %0,%z1,%2,%3" \
106 : "dJ" (__x), "I" (pos), "I" (sz)); \
110 #define CPU_NOP() __asm__ __volatile ("%(ssnop%)" : :)
112 #define CPU_WAIT_FOR_INTR() __asm__ __volatile ("wait")
114 #define __REV(x) mips32r2_rev_word(x)
116 #define __EHB() __asm__ __volatile__ ("%(ehb%)" : :)
118 #define _CP0_GET_BADVADDR() mips32r2_cp0_badvaddr_get()
120 #define _CP0_GET_COUNT() mips32r2_cp0_count_get()
121 #define _CP0_SET_COUNT(val) mips32r2_cp0_count_set((unsigned long)val)
123 #define _CP0_GET_COMPARE() mips32r2_cp0_compare_get()
124 #define _CP0_SET_COMPARE(val) mips32r2_cp0_compare_set((unsigned long)val)
126 #define _CP0_GET_STATUS() mips32r2_cp0_status_get()
127 #define _CP0_SET_STATUS(val) mips32r2_cp0_status_set((unsigned long)val)
128 #define _CP0_BIC_STATUS(val) mips32r2_cp0_status_bic(val)
129 #define _CP0_BIS_STATUS(val) mips32r2_cp0_status_bis(val)
131 #define _CP0_GET_INTCTL() mips32r2_cp0_intctl_get()
132 #define _CP0_SET_INTCTL(val) mips32r2_cp0_intctl_set((unsigned long)val)
134 #define _CP0_GET_VIEW_IPL() mips32r2_cp0_view_ipl_get()
135 #define _CP0_SET_VIEW_IPL(val) mips32r2_cp0_view_ipl_set((unsigned long)val)
137 #define _CP0_GET_CAUSE() mips32r2_cp0_cause_get()
138 #define _CP0_SET_CAUSE(val) mips32r2_cp0_cause_set((unsigned long)val)
139 #define _CP0_BIC_CAUSE(val) mips32r2_cp0_cause_bic((unsigned long)val)
140 #define _CP0_BIS_CAUSE(val) mips32r2_cp0_cause_bis((unsigned long)val)
142 #define _CP0_GET_VIEW_RIPL() mips32r2_cp0_view_ripl_get()
143 #define _CP0_SET_VIEW_RIPL(val) mips32r2_cp0_view_ripl_set((unsigned long)val)
145 #define _CP0_GET_EPC() mips32r2_cp0_epc_get()
146 #define _CP0_SET_EPC(val) mips32r2_cp0_epc_set((unsigned long)val)
148 #define _CP0_GET_EBASE() mips32r2_cp0_ebase_get()
149 #define _CP0_SET_EBASE(val) mips32r2_cp0_ebase_set((unsigned long)val)
151 #define _CP0_GET_CONFIG() mips32r2_cp0_config_get()
152 #define _CP0_GET_CONFIG3() mips32r2_cp0_config3_get()
154 #define _CP0_GET_DEPC() mips32r2_cp0_depc_get()
158 #else // Any other compiler
160 #error "FORCED BUILD ERROR: Unknown compiler"
171 #define NULL ((void *)0)
175 #endif // #ifndef _PLATFORM_H