blob: 17381301ec9e8314f8339ca92866bea75e779809 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
wdenk4fc95692003-02-28 00:49:47 +00002/*
wdenk4fc95692003-02-28 00:49:47 +00003 * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
4 * Copyright (C) 2000 Silicon Graphics, Inc.
5 * Modified for further R[236]000 support by Paul M. Antoine, 1996.
6 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
Shinya Kuribayashi179f9742008-05-30 00:53:38 +09007 * Copyright (C) 2000, 07 MIPS Technologies, Inc.
8 * Copyright (C) 2003, 2004 Maciej W. Rozycki
wdenk4fc95692003-02-28 00:49:47 +00009 */
10#ifndef _ASM_MIPSREGS_H
11#define _ASM_MIPSREGS_H
12
wdenk4fc95692003-02-28 00:49:47 +000013/*
14 * The following macros are especially useful for __asm__
15 * inline assembler.
16 */
17#ifndef __STR
18#define __STR(x) #x
19#endif
20#ifndef STR
21#define STR(x) __STR(x)
22#endif
23
24/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090025 * Configure language
26 */
27#ifdef __ASSEMBLY__
28#define _ULCAST_
29#else
Simon Glass4dcacfc2020-05-10 11:40:13 -060030#include <linux/bitops.h>
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090031#define _ULCAST_ (unsigned long)
32#endif
33
34/*
wdenk4fc95692003-02-28 00:49:47 +000035 * Coprocessor 0 register names
36 */
37#define CP0_INDEX $0
38#define CP0_RANDOM $1
39#define CP0_ENTRYLO0 $2
40#define CP0_ENTRYLO1 $3
41#define CP0_CONF $3
Paul Burtonfcdc1fb2016-09-21 14:59:54 +010042#define CP0_GLOBALNUMBER $3, 1
wdenk4fc95692003-02-28 00:49:47 +000043#define CP0_CONTEXT $4
44#define CP0_PAGEMASK $5
45#define CP0_WIRED $6
46#define CP0_INFO $7
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010047#define CP0_HWRENA $7, 0
wdenk4fc95692003-02-28 00:49:47 +000048#define CP0_BADVADDR $8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010049#define CP0_BADINSTR $8, 1
wdenk4fc95692003-02-28 00:49:47 +000050#define CP0_COUNT $9
51#define CP0_ENTRYHI $10
52#define CP0_COMPARE $11
53#define CP0_STATUS $12
54#define CP0_CAUSE $13
55#define CP0_EPC $14
56#define CP0_PRID $15
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010057#define CP0_EBASE $15, 1
58#define CP0_CMGCRBASE $15, 3
wdenk4fc95692003-02-28 00:49:47 +000059#define CP0_CONFIG $16
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010060#define CP0_CONFIG3 $16, 3
61#define CP0_CONFIG5 $16, 5
wdenk4fc95692003-02-28 00:49:47 +000062#define CP0_LLADDR $17
63#define CP0_WATCHLO $18
64#define CP0_WATCHHI $19
65#define CP0_XCONTEXT $20
66#define CP0_FRAMEMASK $21
67#define CP0_DIAGNOSTIC $22
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090068#define CP0_DEBUG $23
69#define CP0_DEPC $24
wdenk4fc95692003-02-28 00:49:47 +000070#define CP0_PERFORMANCE $25
71#define CP0_ECC $26
72#define CP0_CACHEERR $27
73#define CP0_TAGLO $28
74#define CP0_TAGHI $29
75#define CP0_ERROREPC $30
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090076#define CP0_DESAVE $31
wdenk4fc95692003-02-28 00:49:47 +000077
78/*
79 * R4640/R4650 cp0 register names. These registers are listed
80 * here only for completeness; without MMU these CPUs are not useable
81 * by Linux. A future ELKS port might take make Linux run on them
82 * though ...
83 */
84#define CP0_IBASE $0
85#define CP0_IBOUND $1
86#define CP0_DBASE $2
87#define CP0_DBOUND $3
88#define CP0_CALG $17
89#define CP0_IWATCH $18
90#define CP0_DWATCH $19
91
wdenk57b2d802003-06-27 21:31:46 +000092/*
wdenk4fc95692003-02-28 00:49:47 +000093 * Coprocessor 0 Set 1 register names
94 */
95#define CP0_S1_DERRADDR0 $26
96#define CP0_S1_DERRADDR1 $27
97#define CP0_S1_INTCONTROL $20
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090098
99/*
100 * Coprocessor 0 Set 2 register names
101 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100102#define CP0_S2_SRSCTL $12 /* MIPSR2 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900103
104/*
105 * Coprocessor 0 Set 3 register names
106 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100107#define CP0_S3_SRSMAP $12 /* MIPSR2 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900108
109/*
110 * TX39 Series
111 */
112#define CP0_TX39_CACHE $7
113
wdenk4fc95692003-02-28 00:49:47 +0000114
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100115/* Generic EntryLo bit definitions */
116#define ENTRYLO_G (_ULCAST_(1) << 0)
117#define ENTRYLO_V (_ULCAST_(1) << 1)
118#define ENTRYLO_D (_ULCAST_(1) << 2)
119#define ENTRYLO_C_SHIFT 3
120#define ENTRYLO_C (_ULCAST_(7) << ENTRYLO_C_SHIFT)
wdenk4fc95692003-02-28 00:49:47 +0000121
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100122/* R3000 EntryLo bit definitions */
123#define R3K_ENTRYLO_G (_ULCAST_(1) << 8)
124#define R3K_ENTRYLO_V (_ULCAST_(1) << 9)
125#define R3K_ENTRYLO_D (_ULCAST_(1) << 10)
126#define R3K_ENTRYLO_N (_ULCAST_(1) << 11)
wdenk4fc95692003-02-28 00:49:47 +0000127
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100128/* MIPS32/64 EntryLo bit definitions */
129#define MIPS_ENTRYLO_PFN_SHIFT 6
130#define MIPS_ENTRYLO_XI (_ULCAST_(1) << (BITS_PER_LONG - 2))
131#define MIPS_ENTRYLO_RI (_ULCAST_(1) << (BITS_PER_LONG - 1))
wdenk4fc95692003-02-28 00:49:47 +0000132
133/*
134 * Values for PageMask register
135 */
wdenk4fc95692003-02-28 00:49:47 +0000136#ifdef CONFIG_CPU_VR41XX
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900137
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900138/* Why doesn't stupidity hurt ... */
139
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900140#define PM_1K 0x00000000
141#define PM_4K 0x00001800
142#define PM_16K 0x00007800
143#define PM_64K 0x0001f800
144#define PM_256K 0x0007f800
145
wdenk4fc95692003-02-28 00:49:47 +0000146#else
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900147
148#define PM_4K 0x00000000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100149#define PM_8K 0x00002000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900150#define PM_16K 0x00006000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100151#define PM_32K 0x0000e000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900152#define PM_64K 0x0001e000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100153#define PM_128K 0x0003e000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900154#define PM_256K 0x0007e000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100155#define PM_512K 0x000fe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900156#define PM_1M 0x001fe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100157#define PM_2M 0x003fe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900158#define PM_4M 0x007fe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100159#define PM_8M 0x00ffe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900160#define PM_16M 0x01ffe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100161#define PM_32M 0x03ffe000
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900162#define PM_64M 0x07ffe000
163#define PM_256M 0x1fffe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100164#define PM_1G 0x7fffe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900165
wdenk4fc95692003-02-28 00:49:47 +0000166#endif
167
168/*
169 * Values used for computation of new tlb entries
170 */
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900171#define PL_4K 12
172#define PL_16K 14
173#define PL_64K 16
174#define PL_256K 18
175#define PL_1M 20
176#define PL_4M 22
177#define PL_16M 24
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900178#define PL_64M 26
179#define PL_256M 28
wdenk4fc95692003-02-28 00:49:47 +0000180
181/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100182 * PageGrain bits
183 */
184#define PG_RIE (_ULCAST_(1) << 31)
185#define PG_XIE (_ULCAST_(1) << 30)
186#define PG_ELPA (_ULCAST_(1) << 29)
187#define PG_ESP (_ULCAST_(1) << 28)
188#define PG_IEC (_ULCAST_(1) << 27)
189
190/* MIPS32/64 EntryHI bit definitions */
191#define MIPS_ENTRYHI_EHINV (_ULCAST_(1) << 10)
192
193/*
wdenk4fc95692003-02-28 00:49:47 +0000194 * R4x00 interrupt enable / cause bits
195 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100196#define IE_SW0 (_ULCAST_(1) << 8)
197#define IE_SW1 (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900198#define IE_IRQ0 (_ULCAST_(1) << 10)
199#define IE_IRQ1 (_ULCAST_(1) << 11)
200#define IE_IRQ2 (_ULCAST_(1) << 12)
201#define IE_IRQ3 (_ULCAST_(1) << 13)
202#define IE_IRQ4 (_ULCAST_(1) << 14)
203#define IE_IRQ5 (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000204
205/*
206 * R4x00 interrupt cause bits
207 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100208#define C_SW0 (_ULCAST_(1) << 8)
209#define C_SW1 (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900210#define C_IRQ0 (_ULCAST_(1) << 10)
211#define C_IRQ1 (_ULCAST_(1) << 11)
212#define C_IRQ2 (_ULCAST_(1) << 12)
213#define C_IRQ3 (_ULCAST_(1) << 13)
214#define C_IRQ4 (_ULCAST_(1) << 14)
215#define C_IRQ5 (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000216
wdenk4fc95692003-02-28 00:49:47 +0000217/*
218 * Bitfields in the R4xx0 cp0 status register
219 */
220#define ST0_IE 0x00000001
221#define ST0_EXL 0x00000002
222#define ST0_ERL 0x00000004
223#define ST0_KSU 0x00000018
224# define KSU_USER 0x00000010
225# define KSU_SUPERVISOR 0x00000008
226# define KSU_KERNEL 0x00000000
227#define ST0_UX 0x00000020
228#define ST0_SX 0x00000040
Wolfgang Denka1be4762008-05-20 16:00:29 +0200229#define ST0_KX 0x00000080
wdenk4fc95692003-02-28 00:49:47 +0000230#define ST0_DE 0x00010000
231#define ST0_CE 0x00020000
232
233/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900234 * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
235 * cacheops in userspace. This bit exists only on RM7000 and RM9000
236 * processors.
237 */
238#define ST0_CO 0x08000000
239
240/*
wdenk4fc95692003-02-28 00:49:47 +0000241 * Bitfields in the R[23]000 cp0 status register.
242 */
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900243#define ST0_IEC 0x00000001
wdenk4fc95692003-02-28 00:49:47 +0000244#define ST0_KUC 0x00000002
245#define ST0_IEP 0x00000004
246#define ST0_KUP 0x00000008
247#define ST0_IEO 0x00000010
248#define ST0_KUO 0x00000020
249/* bits 6 & 7 are reserved on R[23]000 */
250#define ST0_ISC 0x00010000
251#define ST0_SWC 0x00020000
252#define ST0_CM 0x00080000
253
254/*
255 * Bits specific to the R4640/R4650
256 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100257#define ST0_UM (_ULCAST_(1) << 4)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900258#define ST0_IL (_ULCAST_(1) << 23)
259#define ST0_DL (_ULCAST_(1) << 24)
wdenk4fc95692003-02-28 00:49:47 +0000260
261/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900262 * Enable the MIPS MDMX and DSP ASEs
263 */
264#define ST0_MX 0x01000000
265
266/*
wdenk4fc95692003-02-28 00:49:47 +0000267 * Status register bits available in all MIPS CPUs.
268 */
269#define ST0_IM 0x0000ff00
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100270#define STATUSB_IP0 8
271#define STATUSF_IP0 (_ULCAST_(1) << 8)
272#define STATUSB_IP1 9
273#define STATUSF_IP1 (_ULCAST_(1) << 9)
274#define STATUSB_IP2 10
275#define STATUSF_IP2 (_ULCAST_(1) << 10)
276#define STATUSB_IP3 11
277#define STATUSF_IP3 (_ULCAST_(1) << 11)
278#define STATUSB_IP4 12
279#define STATUSF_IP4 (_ULCAST_(1) << 12)
280#define STATUSB_IP5 13
281#define STATUSF_IP5 (_ULCAST_(1) << 13)
282#define STATUSB_IP6 14
283#define STATUSF_IP6 (_ULCAST_(1) << 14)
284#define STATUSB_IP7 15
285#define STATUSF_IP7 (_ULCAST_(1) << 15)
286#define STATUSB_IP8 0
287#define STATUSF_IP8 (_ULCAST_(1) << 0)
288#define STATUSB_IP9 1
289#define STATUSF_IP9 (_ULCAST_(1) << 1)
290#define STATUSB_IP10 2
291#define STATUSF_IP10 (_ULCAST_(1) << 2)
292#define STATUSB_IP11 3
293#define STATUSF_IP11 (_ULCAST_(1) << 3)
294#define STATUSB_IP12 4
295#define STATUSF_IP12 (_ULCAST_(1) << 4)
296#define STATUSB_IP13 5
297#define STATUSF_IP13 (_ULCAST_(1) << 5)
298#define STATUSB_IP14 6
299#define STATUSF_IP14 (_ULCAST_(1) << 6)
300#define STATUSB_IP15 7
301#define STATUSF_IP15 (_ULCAST_(1) << 7)
Daniel Schwierzeckecf0d792016-02-08 00:37:59 +0100302#define ST0_IMPL (_ULCAST_(3) << 16)
wdenk4fc95692003-02-28 00:49:47 +0000303#define ST0_CH 0x00040000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100304#define ST0_NMI 0x00080000
wdenk4fc95692003-02-28 00:49:47 +0000305#define ST0_SR 0x00100000
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900306#define ST0_TS 0x00200000
wdenk4fc95692003-02-28 00:49:47 +0000307#define ST0_BEV 0x00400000
308#define ST0_RE 0x02000000
309#define ST0_FR 0x04000000
310#define ST0_CU 0xf0000000
311#define ST0_CU0 0x10000000
312#define ST0_CU1 0x20000000
313#define ST0_CU2 0x40000000
314#define ST0_CU3 0x80000000
315#define ST0_XX 0x80000000 /* MIPS IV naming */
316
317/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100318 * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
319 */
320#define INTCTLB_IPFDC 23
321#define INTCTLF_IPFDC (_ULCAST_(7) << INTCTLB_IPFDC)
322#define INTCTLB_IPPCI 26
323#define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
324#define INTCTLB_IPTI 29
325#define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
326
327/*
wdenk4fc95692003-02-28 00:49:47 +0000328 * Bitfields and bit numbers in the coprocessor 0 cause register.
329 *
330 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
331 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100332#define CAUSEB_EXCCODE 2
333#define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
334#define CAUSEB_IP 8
335#define CAUSEF_IP (_ULCAST_(255) << 8)
336#define CAUSEB_IP0 8
337#define CAUSEF_IP0 (_ULCAST_(1) << 8)
338#define CAUSEB_IP1 9
339#define CAUSEF_IP1 (_ULCAST_(1) << 9)
340#define CAUSEB_IP2 10
341#define CAUSEF_IP2 (_ULCAST_(1) << 10)
342#define CAUSEB_IP3 11
343#define CAUSEF_IP3 (_ULCAST_(1) << 11)
344#define CAUSEB_IP4 12
345#define CAUSEF_IP4 (_ULCAST_(1) << 12)
346#define CAUSEB_IP5 13
347#define CAUSEF_IP5 (_ULCAST_(1) << 13)
348#define CAUSEB_IP6 14
349#define CAUSEF_IP6 (_ULCAST_(1) << 14)
350#define CAUSEB_IP7 15
351#define CAUSEF_IP7 (_ULCAST_(1) << 15)
352#define CAUSEB_FDCI 21
353#define CAUSEF_FDCI (_ULCAST_(1) << 21)
354#define CAUSEB_IV 23
355#define CAUSEF_IV (_ULCAST_(1) << 23)
356#define CAUSEB_PCI 26
357#define CAUSEF_PCI (_ULCAST_(1) << 26)
358#define CAUSEB_CE 28
359#define CAUSEF_CE (_ULCAST_(3) << 28)
360#define CAUSEB_TI 30
361#define CAUSEF_TI (_ULCAST_(1) << 30)
362#define CAUSEB_BD 31
363#define CAUSEF_BD (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000364
365/*
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100366 * Bits in the coprocessor 0 EBase register.
367 */
368#define EBASE_CPUNUM 0x3ff
Stefan Roesefb79cbd2020-05-14 11:59:06 +0200369#define EBASE_WG (_ULCAST_(1) << 11)
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100370
371/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900372 * Bits in the coprocessor 0 config register.
wdenk4fc95692003-02-28 00:49:47 +0000373 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900374/* Generic bits. */
wdenk4fc95692003-02-28 00:49:47 +0000375#define CONF_CM_CACHABLE_NO_WA 0
376#define CONF_CM_CACHABLE_WA 1
377#define CONF_CM_UNCACHED 2
378#define CONF_CM_CACHABLE_NONCOHERENT 3
379#define CONF_CM_CACHABLE_CE 4
380#define CONF_CM_CACHABLE_COW 5
381#define CONF_CM_CACHABLE_CUW 6
382#define CONF_CM_CACHABLE_ACCELERATED 7
383#define CONF_CM_CMASK 7
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900384#define CONF_BE (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000385
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900386/* Bits common to various processors. */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100387#define CONF_CU (_ULCAST_(1) << 3)
388#define CONF_DB (_ULCAST_(1) << 4)
389#define CONF_IB (_ULCAST_(1) << 5)
390#define CONF_DC (_ULCAST_(7) << 6)
391#define CONF_IC (_ULCAST_(7) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900392#define CONF_EB (_ULCAST_(1) << 13)
393#define CONF_EM (_ULCAST_(1) << 14)
394#define CONF_SM (_ULCAST_(1) << 16)
395#define CONF_SC (_ULCAST_(1) << 17)
396#define CONF_EW (_ULCAST_(3) << 18)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100397#define CONF_EP (_ULCAST_(15) << 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900398#define CONF_EC (_ULCAST_(7) << 28)
399#define CONF_CM (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000400
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100401/* Bits specific to the R4xx0. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900402#define R4K_CONF_SW (_ULCAST_(1) << 20)
403#define R4K_CONF_SS (_ULCAST_(1) << 21)
404#define R4K_CONF_SB (_ULCAST_(3) << 22)
405
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100406/* Bits specific to the R5000. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900407#define R5K_CONF_SE (_ULCAST_(1) << 12)
408#define R5K_CONF_SS (_ULCAST_(3) << 20)
409
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100410/* Bits specific to the RM7000. */
411#define RM7K_CONF_SE (_ULCAST_(1) << 3)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900412#define RM7K_CONF_TE (_ULCAST_(1) << 12)
413#define RM7K_CONF_CLK (_ULCAST_(1) << 16)
414#define RM7K_CONF_TC (_ULCAST_(1) << 17)
415#define RM7K_CONF_SI (_ULCAST_(3) << 20)
416#define RM7K_CONF_SC (_ULCAST_(1) << 31)
417
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100418/* Bits specific to the R10000. */
419#define R10K_CONF_DN (_ULCAST_(3) << 3)
420#define R10K_CONF_CT (_ULCAST_(1) << 5)
421#define R10K_CONF_PE (_ULCAST_(1) << 6)
422#define R10K_CONF_PM (_ULCAST_(3) << 7)
423#define R10K_CONF_EC (_ULCAST_(15) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900424#define R10K_CONF_SB (_ULCAST_(1) << 13)
425#define R10K_CONF_SK (_ULCAST_(1) << 14)
426#define R10K_CONF_SS (_ULCAST_(7) << 16)
427#define R10K_CONF_SC (_ULCAST_(7) << 19)
428#define R10K_CONF_DC (_ULCAST_(7) << 26)
429#define R10K_CONF_IC (_ULCAST_(7) << 29)
430
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100431/* Bits specific to the VR41xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900432#define VR41_CONF_CS (_ULCAST_(1) << 12)
433#define VR41_CONF_P4K (_ULCAST_(1) << 13)
434#define VR41_CONF_BP (_ULCAST_(1) << 16)
435#define VR41_CONF_M16 (_ULCAST_(1) << 20)
436#define VR41_CONF_AD (_ULCAST_(1) << 23)
437
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100438/* Bits specific to the R30xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900439#define R30XX_CONF_FDM (_ULCAST_(1) << 19)
440#define R30XX_CONF_REV (_ULCAST_(1) << 22)
441#define R30XX_CONF_AC (_ULCAST_(1) << 23)
442#define R30XX_CONF_RF (_ULCAST_(1) << 24)
443#define R30XX_CONF_HALT (_ULCAST_(1) << 25)
444#define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
445#define R30XX_CONF_DBR (_ULCAST_(1) << 29)
446#define R30XX_CONF_SB (_ULCAST_(1) << 30)
447#define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
448
449/* Bits specific to the TX49. */
450#define TX49_CONF_DC (_ULCAST_(1) << 16)
451#define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
452#define TX49_CONF_HALT (_ULCAST_(1) << 18)
453#define TX49_CONF_CWFON (_ULCAST_(1) << 27)
454
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100455/* Bits specific to the MIPS32/64 PRA. */
456#define MIPS_CONF_MT (_ULCAST_(7) << 7)
457#define MIPS_CONF_MT_TLB (_ULCAST_(1) << 7)
458#define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900459#define MIPS_CONF_AR (_ULCAST_(7) << 10)
460#define MIPS_CONF_AT (_ULCAST_(3) << 13)
Paul Burton4f5561c2016-09-21 11:18:50 +0100461#define MIPS_CONF_IMPL (_ULCAST_(0x1ff) << 16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900462#define MIPS_CONF_M (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000463
464/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900465 * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
wdenk4fc95692003-02-28 00:49:47 +0000466 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100467#define MIPS_CONF1_FP (_ULCAST_(1) << 0)
468#define MIPS_CONF1_EP (_ULCAST_(1) << 1)
469#define MIPS_CONF1_CA (_ULCAST_(1) << 2)
470#define MIPS_CONF1_WR (_ULCAST_(1) << 3)
471#define MIPS_CONF1_PC (_ULCAST_(1) << 4)
472#define MIPS_CONF1_MD (_ULCAST_(1) << 5)
473#define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
474#define MIPS_CONF1_DA_SHF 7
475#define MIPS_CONF1_DA_SZ 3
476#define MIPS_CONF1_DA (_ULCAST_(7) << 7)
477#define MIPS_CONF1_DL_SHF 10
478#define MIPS_CONF1_DL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900479#define MIPS_CONF1_DL (_ULCAST_(7) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100480#define MIPS_CONF1_DS_SHF 13
481#define MIPS_CONF1_DS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900482#define MIPS_CONF1_DS (_ULCAST_(7) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100483#define MIPS_CONF1_IA_SHF 16
484#define MIPS_CONF1_IA_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900485#define MIPS_CONF1_IA (_ULCAST_(7) << 16)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100486#define MIPS_CONF1_IL_SHF 19
487#define MIPS_CONF1_IL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900488#define MIPS_CONF1_IL (_ULCAST_(7) << 19)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100489#define MIPS_CONF1_IS_SHF 22
490#define MIPS_CONF1_IS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900491#define MIPS_CONF1_IS (_ULCAST_(7) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100492#define MIPS_CONF1_TLBS_SHIFT (25)
493#define MIPS_CONF1_TLBS_SIZE (6)
494#define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900495
Paul Burton81560782016-09-21 11:18:54 +0100496#define MIPS_CONF2_SA_SHF 0
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100497#define MIPS_CONF2_SA (_ULCAST_(15) << 0)
Paul Burton81560782016-09-21 11:18:54 +0100498#define MIPS_CONF2_SL_SHF 4
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100499#define MIPS_CONF2_SL (_ULCAST_(15) << 4)
Paul Burton81560782016-09-21 11:18:54 +0100500#define MIPS_CONF2_SS_SHF 8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100501#define MIPS_CONF2_SS (_ULCAST_(15) << 8)
Paul Burton81560782016-09-21 11:18:54 +0100502#define MIPS_CONF2_L2B (_ULCAST_(1) << 12)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100503#define MIPS_CONF2_SU (_ULCAST_(15) << 12)
504#define MIPS_CONF2_TA (_ULCAST_(15) << 16)
505#define MIPS_CONF2_TL (_ULCAST_(15) << 20)
506#define MIPS_CONF2_TS (_ULCAST_(15) << 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900507#define MIPS_CONF2_TU (_ULCAST_(7) << 28)
508
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100509#define MIPS_CONF3_TL (_ULCAST_(1) << 0)
510#define MIPS_CONF3_SM (_ULCAST_(1) << 1)
511#define MIPS_CONF3_MT (_ULCAST_(1) << 2)
512#define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
513#define MIPS_CONF3_SP (_ULCAST_(1) << 4)
514#define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
515#define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
516#define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
517#define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
518#define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900519#define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100520#define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
521#define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900522#define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100523#define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
524#define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
525#define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
526#define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
527#define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
528#define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
529#define MIPS_CONF3_PW (_ULCAST_(1) << 24)
530#define MIPS_CONF3_SC (_ULCAST_(1) << 25)
531#define MIPS_CONF3_BI (_ULCAST_(1) << 26)
532#define MIPS_CONF3_BP (_ULCAST_(1) << 27)
533#define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
534#define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
535#define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
536
537#define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
538#define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
539#define MIPS_CONF4_FTLBSETS_SHIFT (0)
540#define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
541#define MIPS_CONF4_FTLBWAYS_SHIFT (4)
542#define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
543#define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
544/* bits 10:8 in FTLB-only configurations */
545#define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
546/* bits 12:8 in VTLB-FTLB only configurations */
547#define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
548#define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
549#define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
550#define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
551#define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
552#define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << 16)
553#define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
554#define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
555#define MIPS_CONF4_AE (_ULCAST_(1) << 28)
556#define MIPS_CONF4_IE (_ULCAST_(3) << 29)
557#define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
558
559#define MIPS_CONF5_NF (_ULCAST_(1) << 0)
560#define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
561#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)
562#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)
563#define MIPS_CONF5_MVH (_ULCAST_(1) << 5)
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100564#define MIPS_CONF5_VP (_ULCAST_(1) << 7)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100565#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)
566#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)
Paul Burton81560782016-09-21 11:18:54 +0100567#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100568#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
569#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
570#define MIPS_CONF5_CV (_ULCAST_(1) << 29)
571#define MIPS_CONF5_K (_ULCAST_(1) << 30)
572
573#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
574/* proAptiv FTLB on/off bit */
575#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
576/* FTLB probability bits */
577#define MIPS_CONF6_FTLBP_SHIFT (16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900578
579#define MIPS_CONF7_WII (_ULCAST_(1) << 31)
580
581#define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
wdenk4fc95692003-02-28 00:49:47 +0000582
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100583#define MIPS_CONF7_IAR (_ULCAST_(1) << 10)
584#define MIPS_CONF7_AR (_ULCAST_(1) << 16)
585/* FTLB probability bits for R6 */
586#define MIPS_CONF7_FTLBP_SHIFT (18)
587
588/* MAAR bit definitions */
589#define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12)
590#define MIPS_MAAR_ADDR_SHIFT 12
591#define MIPS_MAAR_S (_ULCAST_(1) << 1)
592#define MIPS_MAAR_V (_ULCAST_(1) << 0)
593
594/* CMGCRBase bit definitions */
595#define MIPS_CMGCRB_BASE 11
596#define MIPS_CMGCRF_BASE (~_ULCAST_((1 << MIPS_CMGCRB_BASE) - 1))
597
598/*
599 * Bits in the MIPS32 Memory Segmentation registers.
600 */
601#define MIPS_SEGCFG_PA_SHIFT 9
602#define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
603#define MIPS_SEGCFG_AM_SHIFT 4
604#define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
605#define MIPS_SEGCFG_EU_SHIFT 3
606#define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
607#define MIPS_SEGCFG_C_SHIFT 0
608#define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
609
610#define MIPS_SEGCFG_UUSK _ULCAST_(7)
611#define MIPS_SEGCFG_USK _ULCAST_(5)
612#define MIPS_SEGCFG_MUSUK _ULCAST_(4)
613#define MIPS_SEGCFG_MUSK _ULCAST_(3)
614#define MIPS_SEGCFG_MSK _ULCAST_(2)
615#define MIPS_SEGCFG_MK _ULCAST_(1)
616#define MIPS_SEGCFG_UK _ULCAST_(0)
617
618#define MIPS_PWFIELD_GDI_SHIFT 24
619#define MIPS_PWFIELD_GDI_MASK 0x3f000000
620#define MIPS_PWFIELD_UDI_SHIFT 18
621#define MIPS_PWFIELD_UDI_MASK 0x00fc0000
622#define MIPS_PWFIELD_MDI_SHIFT 12
623#define MIPS_PWFIELD_MDI_MASK 0x0003f000
624#define MIPS_PWFIELD_PTI_SHIFT 6
625#define MIPS_PWFIELD_PTI_MASK 0x00000fc0
626#define MIPS_PWFIELD_PTEI_SHIFT 0
627#define MIPS_PWFIELD_PTEI_MASK 0x0000003f
628
629#define MIPS_PWSIZE_GDW_SHIFT 24
630#define MIPS_PWSIZE_GDW_MASK 0x3f000000
631#define MIPS_PWSIZE_UDW_SHIFT 18
632#define MIPS_PWSIZE_UDW_MASK 0x00fc0000
633#define MIPS_PWSIZE_MDW_SHIFT 12
634#define MIPS_PWSIZE_MDW_MASK 0x0003f000
635#define MIPS_PWSIZE_PTW_SHIFT 6
636#define MIPS_PWSIZE_PTW_MASK 0x00000fc0
637#define MIPS_PWSIZE_PTEW_SHIFT 0
638#define MIPS_PWSIZE_PTEW_MASK 0x0000003f
639
640#define MIPS_PWCTL_PWEN_SHIFT 31
641#define MIPS_PWCTL_PWEN_MASK 0x80000000
642#define MIPS_PWCTL_DPH_SHIFT 7
643#define MIPS_PWCTL_DPH_MASK 0x00000080
644#define MIPS_PWCTL_HUGEPG_SHIFT 6
645#define MIPS_PWCTL_HUGEPG_MASK 0x00000060
646#define MIPS_PWCTL_PSN_SHIFT 0
647#define MIPS_PWCTL_PSN_MASK 0x0000003f
648
649/* CDMMBase register bit definitions */
650#define MIPS_CDMMBASE_SIZE_SHIFT 0
651#define MIPS_CDMMBASE_SIZE (_ULCAST_(511) << MIPS_CDMMBASE_SIZE_SHIFT)
652#define MIPS_CDMMBASE_CI (_ULCAST_(1) << 9)
653#define MIPS_CDMMBASE_EN (_ULCAST_(1) << 10)
654#define MIPS_CDMMBASE_ADDR_SHIFT 11
655#define MIPS_CDMMBASE_ADDR_START 15
656
657/*
658 * Bitfields in the TX39 family CP0 Configuration Register 3
659 */
660#define TX39_CONF_ICS_SHIFT 19
661#define TX39_CONF_ICS_MASK 0x00380000
662#define TX39_CONF_ICS_1KB 0x00000000
663#define TX39_CONF_ICS_2KB 0x00080000
664#define TX39_CONF_ICS_4KB 0x00100000
665#define TX39_CONF_ICS_8KB 0x00180000
666#define TX39_CONF_ICS_16KB 0x00200000
667
668#define TX39_CONF_DCS_SHIFT 16
669#define TX39_CONF_DCS_MASK 0x00070000
670#define TX39_CONF_DCS_1KB 0x00000000
671#define TX39_CONF_DCS_2KB 0x00010000
672#define TX39_CONF_DCS_4KB 0x00020000
673#define TX39_CONF_DCS_8KB 0x00030000
674#define TX39_CONF_DCS_16KB 0x00040000
675
676#define TX39_CONF_CWFON 0x00004000
677#define TX39_CONF_WBON 0x00002000
678#define TX39_CONF_RF_SHIFT 10
679#define TX39_CONF_RF_MASK 0x00000c00
680#define TX39_CONF_DOZE 0x00000200
681#define TX39_CONF_HALT 0x00000100
682#define TX39_CONF_LOCK 0x00000080
683#define TX39_CONF_ICE 0x00000020
684#define TX39_CONF_DCE 0x00000010
685#define TX39_CONF_IRSIZE_SHIFT 2
686#define TX39_CONF_IRSIZE_MASK 0x0000000c
687#define TX39_CONF_DRSIZE_SHIFT 0
688#define TX39_CONF_DRSIZE_MASK 0x00000003
689
690/*
691 * Interesting Bits in the R10K CP0 Branch Diagnostic Register
692 */
693/* Disable Branch Target Address Cache */
694#define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27)
695/* Enable Branch Prediction Global History */
696#define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26)
697/* Disable Branch Return Cache */
698#define R10K_DIAG_D_BRC (_ULCAST_(1) << 22)
699
wdenk4fc95692003-02-28 00:49:47 +0000700/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100701 * Coprocessor 1 (FPU) register names
702 */
703#define CP1_REVISION $0
704#define CP1_UFR $1
705#define CP1_UNFR $4
706#define CP1_FCCR $25
707#define CP1_FEXR $26
708#define CP1_FENR $28
709#define CP1_STATUS $31
710
711
712/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900713 * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
wdenk4fc95692003-02-28 00:49:47 +0000714 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900715#define MIPS_FPIR_S (_ULCAST_(1) << 16)
716#define MIPS_FPIR_D (_ULCAST_(1) << 17)
717#define MIPS_FPIR_PS (_ULCAST_(1) << 18)
718#define MIPS_FPIR_3D (_ULCAST_(1) << 19)
719#define MIPS_FPIR_W (_ULCAST_(1) << 20)
720#define MIPS_FPIR_L (_ULCAST_(1) << 21)
721#define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100722#define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
723#define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
724#define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
725
726/*
727 * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
728 */
729#define MIPS_FCCR_CONDX_S 0
730#define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
731#define MIPS_FCCR_COND0_S 0
732#define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
733#define MIPS_FCCR_COND1_S 1
734#define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
735#define MIPS_FCCR_COND2_S 2
736#define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
737#define MIPS_FCCR_COND3_S 3
738#define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
739#define MIPS_FCCR_COND4_S 4
740#define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
741#define MIPS_FCCR_COND5_S 5
742#define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
743#define MIPS_FCCR_COND6_S 6
744#define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
745#define MIPS_FCCR_COND7_S 7
746#define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
747
748/*
749 * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
750 */
751#define MIPS_FENR_FS_S 2
752#define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
753
754/*
755 * FPU Status Register Values
756 */
757#define FPU_CSR_COND_S 23 /* $fcc0 */
758#define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
759
760#define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
761#define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
762
763#define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
764#define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
765#define FPU_CSR_COND1_S 25 /* $fcc1 */
766#define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
767#define FPU_CSR_COND2_S 26 /* $fcc2 */
768#define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
769#define FPU_CSR_COND3_S 27 /* $fcc3 */
770#define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
771#define FPU_CSR_COND4_S 28 /* $fcc4 */
772#define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
773#define FPU_CSR_COND5_S 29 /* $fcc5 */
774#define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
775#define FPU_CSR_COND6_S 30 /* $fcc6 */
776#define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
777#define FPU_CSR_COND7_S 31 /* $fcc7 */
778#define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
779
780/*
781 * Bits 22:20 of the FPU Status Register will be read as 0,
782 * and should be written as zero.
783 */
784#define FPU_CSR_RSVD (_ULCAST_(7) << 20)
785
786#define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
787#define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
788
789/*
790 * X the exception cause indicator
791 * E the exception enable
792 * S the sticky/flag bit
793*/
794#define FPU_CSR_ALL_X 0x0003f000
795#define FPU_CSR_UNI_X 0x00020000
796#define FPU_CSR_INV_X 0x00010000
797#define FPU_CSR_DIV_X 0x00008000
798#define FPU_CSR_OVF_X 0x00004000
799#define FPU_CSR_UDF_X 0x00002000
800#define FPU_CSR_INE_X 0x00001000
801
802#define FPU_CSR_ALL_E 0x00000f80
803#define FPU_CSR_INV_E 0x00000800
804#define FPU_CSR_DIV_E 0x00000400
805#define FPU_CSR_OVF_E 0x00000200
806#define FPU_CSR_UDF_E 0x00000100
807#define FPU_CSR_INE_E 0x00000080
808
809#define FPU_CSR_ALL_S 0x0000007c
810#define FPU_CSR_INV_S 0x00000040
811#define FPU_CSR_DIV_S 0x00000020
812#define FPU_CSR_OVF_S 0x00000010
813#define FPU_CSR_UDF_S 0x00000008
814#define FPU_CSR_INE_S 0x00000004
815
816/* Bits 0 and 1 of FPU Status Register specify the rounding mode */
817#define FPU_CSR_RM 0x00000003
818#define FPU_CSR_RN 0x0 /* nearest */
819#define FPU_CSR_RZ 0x1 /* towards zero */
820#define FPU_CSR_RU 0x2 /* towards +Infinity */
821#define FPU_CSR_RD 0x3 /* towards -Infinity */
822
wdenk4fc95692003-02-28 00:49:47 +0000823
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900824#ifndef __ASSEMBLY__
825
826/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100827 * Macros for handling the ISA mode bit for MIPS16 and microMIPS.
828 */
829#if defined(CONFIG_SYS_SUPPORTS_MIPS16) || \
830 defined(CONFIG_SYS_SUPPORTS_MICROMIPS)
831#define get_isa16_mode(x) ((x) & 0x1)
832#define msk_isa16_mode(x) ((x) & ~0x1)
833#define set_isa16_mode(x) do { (x) |= 0x1; } while (0)
834#else
835#define get_isa16_mode(x) 0
836#define msk_isa16_mode(x) (x)
837#define set_isa16_mode(x) do { } while (0)
838#endif
839
840/*
841 * microMIPS instructions can be 16-bit or 32-bit in length. This
842 * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
843 */
844static inline int mm_insn_16bit(u16 insn)
845{
846 u16 opcode = (insn >> 10) & 0x7;
847
848 return (opcode >= 1 && opcode <= 3) ? 1 : 0;
849}
850
851/*
852 * TLB Invalidate Flush
853 */
854static inline void tlbinvf(void)
855{
856 __asm__ __volatile__(
857 ".set push\n\t"
858 ".set noreorder\n\t"
859 ".word 0x42000004\n\t" /* tlbinvf */
860 ".set pop");
861}
862
863
864/*
865 * Functions to access the R10000 performance counters. These are basically
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900866 * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
867 * performance counter number encoded into bits 1 ... 5 of the instruction.
868 * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
869 * disassembler these will look like an access to sel 0 or 1.
870 */
871#define read_r10k_perf_cntr(counter) \
872({ \
873 unsigned int __res; \
874 __asm__ __volatile__( \
875 "mfpc\t%0, %1" \
876 : "=r" (__res) \
877 : "i" (counter)); \
878 \
879 __res; \
880})
881
882#define write_r10k_perf_cntr(counter,val) \
883do { \
884 __asm__ __volatile__( \
885 "mtpc\t%0, %1" \
886 : \
887 : "r" (val), "i" (counter)); \
888} while (0)
889
890#define read_r10k_perf_event(counter) \
891({ \
892 unsigned int __res; \
893 __asm__ __volatile__( \
894 "mfps\t%0, %1" \
895 : "=r" (__res) \
896 : "i" (counter)); \
897 \
898 __res; \
899})
900
901#define write_r10k_perf_cntl(counter,val) \
902do { \
903 __asm__ __volatile__( \
904 "mtps\t%0, %1" \
905 : \
906 : "r" (val), "i" (counter)); \
907} while (0)
908
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100909
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900910/*
911 * Macros to access the system control coprocessor
912 */
913
914#define __read_32bit_c0_register(source, sel) \
Chris Packham36c624a2015-07-14 22:54:41 +1200915({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900916 if (sel == 0) \
917 __asm__ __volatile__( \
918 "mfc0\t%0, " #source "\n\t" \
919 : "=r" (__res)); \
920 else \
921 __asm__ __volatile__( \
922 ".set\tmips32\n\t" \
923 "mfc0\t%0, " #source ", " #sel "\n\t" \
924 ".set\tmips0\n\t" \
925 : "=r" (__res)); \
926 __res; \
927})
928
929#define __read_64bit_c0_register(source, sel) \
930({ unsigned long long __res; \
931 if (sizeof(unsigned long) == 4) \
932 __res = __read_64bit_c0_split(source, sel); \
933 else if (sel == 0) \
934 __asm__ __volatile__( \
935 ".set\tmips3\n\t" \
936 "dmfc0\t%0, " #source "\n\t" \
937 ".set\tmips0" \
938 : "=r" (__res)); \
939 else \
940 __asm__ __volatile__( \
941 ".set\tmips64\n\t" \
942 "dmfc0\t%0, " #source ", " #sel "\n\t" \
943 ".set\tmips0" \
944 : "=r" (__res)); \
945 __res; \
946})
947
948#define __write_32bit_c0_register(register, sel, value) \
949do { \
950 if (sel == 0) \
951 __asm__ __volatile__( \
952 "mtc0\t%z0, " #register "\n\t" \
953 : : "Jr" ((unsigned int)(value))); \
954 else \
955 __asm__ __volatile__( \
956 ".set\tmips32\n\t" \
957 "mtc0\t%z0, " #register ", " #sel "\n\t" \
958 ".set\tmips0" \
959 : : "Jr" ((unsigned int)(value))); \
960} while (0)
961
962#define __write_64bit_c0_register(register, sel, value) \
963do { \
964 if (sizeof(unsigned long) == 4) \
965 __write_64bit_c0_split(register, sel, value); \
966 else if (sel == 0) \
967 __asm__ __volatile__( \
968 ".set\tmips3\n\t" \
969 "dmtc0\t%z0, " #register "\n\t" \
970 ".set\tmips0" \
971 : : "Jr" (value)); \
972 else \
973 __asm__ __volatile__( \
974 ".set\tmips64\n\t" \
975 "dmtc0\t%z0, " #register ", " #sel "\n\t" \
976 ".set\tmips0" \
977 : : "Jr" (value)); \
978} while (0)
979
980#define __read_ulong_c0_register(reg, sel) \
981 ((sizeof(unsigned long) == 4) ? \
982 (unsigned long) __read_32bit_c0_register(reg, sel) : \
983 (unsigned long) __read_64bit_c0_register(reg, sel))
984
985#define __write_ulong_c0_register(reg, sel, val) \
986do { \
987 if (sizeof(unsigned long) == 4) \
988 __write_32bit_c0_register(reg, sel, val); \
989 else \
990 __write_64bit_c0_register(reg, sel, val); \
991} while (0)
992
993/*
994 * On RM7000/RM9000 these are uses to access cop0 set 1 registers
995 */
996#define __read_32bit_c0_ctrl_register(source) \
Chris Packham36c624a2015-07-14 22:54:41 +1200997({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900998 __asm__ __volatile__( \
999 "cfc0\t%0, " #source "\n\t" \
1000 : "=r" (__res)); \
1001 __res; \
1002})
1003
1004#define __write_32bit_c0_ctrl_register(register, value) \
1005do { \
1006 __asm__ __volatile__( \
1007 "ctc0\t%z0, " #register "\n\t" \
1008 : : "Jr" ((unsigned int)(value))); \
1009} while (0)
1010
1011/*
1012 * These versions are only needed for systems with more than 38 bits of
1013 * physical address space running the 32-bit kernel. That's none atm :-)
1014 */
1015#define __read_64bit_c0_split(source, sel) \
1016({ \
1017 unsigned long long __val; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001018 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001019 if (sel == 0) \
1020 __asm__ __volatile__( \
1021 ".set\tmips64\n\t" \
1022 "dmfc0\t%M0, " #source "\n\t" \
1023 "dsll\t%L0, %M0, 32\n\t" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001024 "dsra\t%M0, %M0, 32\n\t" \
1025 "dsra\t%L0, %L0, 32\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001026 ".set\tmips0" \
1027 : "=r" (__val)); \
1028 else \
1029 __asm__ __volatile__( \
1030 ".set\tmips64\n\t" \
1031 "dmfc0\t%M0, " #source ", " #sel "\n\t" \
1032 "dsll\t%L0, %M0, 32\n\t" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001033 "dsra\t%M0, %M0, 32\n\t" \
1034 "dsra\t%L0, %L0, 32\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001035 ".set\tmips0" \
1036 : "=r" (__val)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001037 \
1038 __val; \
1039})
1040
1041#define __write_64bit_c0_split(source, sel, val) \
1042do { \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001043 if (sel == 0) \
1044 __asm__ __volatile__( \
1045 ".set\tmips64\n\t" \
1046 "dsll\t%L0, %L0, 32\n\t" \
1047 "dsrl\t%L0, %L0, 32\n\t" \
1048 "dsll\t%M0, %M0, 32\n\t" \
1049 "or\t%L0, %L0, %M0\n\t" \
1050 "dmtc0\t%L0, " #source "\n\t" \
1051 ".set\tmips0" \
1052 : : "r" (val)); \
1053 else \
1054 __asm__ __volatile__( \
1055 ".set\tmips64\n\t" \
1056 "dsll\t%L0, %L0, 32\n\t" \
1057 "dsrl\t%L0, %L0, 32\n\t" \
1058 "dsll\t%M0, %M0, 32\n\t" \
1059 "or\t%L0, %L0, %M0\n\t" \
1060 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
1061 ".set\tmips0" \
1062 : : "r" (val)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001063} while (0)
1064
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001065#define __readx_32bit_c0_register(source) \
1066({ \
1067 unsigned int __res; \
1068 \
1069 __asm__ __volatile__( \
1070 " .set push \n" \
1071 " .set noat \n" \
1072 " .set mips32r2 \n" \
1073 " .insn \n" \
1074 " # mfhc0 $1, %1 \n" \
1075 " .word (0x40410000 | ((%1 & 0x1f) << 11)) \n" \
1076 " move %0, $1 \n" \
1077 " .set pop \n" \
1078 : "=r" (__res) \
1079 : "i" (source)); \
1080 __res; \
1081})
1082
1083#define __writex_32bit_c0_register(register, value) \
1084({ \
1085 __asm__ __volatile__( \
1086 " .set push \n" \
1087 " .set noat \n" \
1088 " .set mips32r2 \n" \
1089 " move $1, %0 \n" \
1090 " # mthc0 $1, %1 \n" \
1091 " .insn \n" \
1092 " .word (0x40c10000 | ((%1 & 0x1f) << 11)) \n" \
1093 " .set pop \n" \
1094 : \
1095 : "r" (value), "i" (register)); \
1096})
1097
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001098#define read_c0_index() __read_32bit_c0_register($0, 0)
1099#define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
1100
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001101#define read_c0_random() __read_32bit_c0_register($1, 0)
1102#define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
1103
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001104#define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
1105#define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
1106
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001107#define readx_c0_entrylo0() __readx_32bit_c0_register(2)
1108#define writex_c0_entrylo0(val) __writex_32bit_c0_register(2, val)
1109
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001110#define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
1111#define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
1112
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001113#define readx_c0_entrylo1() __readx_32bit_c0_register(3)
1114#define writex_c0_entrylo1(val) __writex_32bit_c0_register(3, val)
1115
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001116#define read_c0_conf() __read_32bit_c0_register($3, 0)
1117#define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
1118
1119#define read_c0_context() __read_ulong_c0_register($4, 0)
1120#define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
1121
1122#define read_c0_userlocal() __read_ulong_c0_register($4, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001123#define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001124
1125#define read_c0_pagemask() __read_32bit_c0_register($5, 0)
1126#define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
1127
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001128#define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
1129#define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
1130
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001131#define read_c0_wired() __read_32bit_c0_register($6, 0)
1132#define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
1133
1134#define read_c0_info() __read_32bit_c0_register($7, 0)
1135
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001136#define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001137#define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
1138
1139#define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
1140#define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
1141
1142#define read_c0_count() __read_32bit_c0_register($9, 0)
1143#define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
1144
1145#define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
1146#define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
1147
1148#define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
1149#define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
1150
1151#define read_c0_entryhi() __read_ulong_c0_register($10, 0)
1152#define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
1153
1154#define read_c0_compare() __read_32bit_c0_register($11, 0)
1155#define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
1156
1157#define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
1158#define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
1159
1160#define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
1161#define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
1162
1163#define read_c0_status() __read_32bit_c0_register($12, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001164
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001165#define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001166
1167#define read_c0_cause() __read_32bit_c0_register($13, 0)
1168#define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
1169
1170#define read_c0_epc() __read_ulong_c0_register($14, 0)
1171#define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
1172
1173#define read_c0_prid() __read_32bit_c0_register($15, 0)
1174
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001175#define read_c0_cmgcrbase() __read_ulong_c0_register($15, 3)
1176
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001177#define read_c0_config() __read_32bit_c0_register($16, 0)
1178#define read_c0_config1() __read_32bit_c0_register($16, 1)
1179#define read_c0_config2() __read_32bit_c0_register($16, 2)
1180#define read_c0_config3() __read_32bit_c0_register($16, 3)
1181#define read_c0_config4() __read_32bit_c0_register($16, 4)
1182#define read_c0_config5() __read_32bit_c0_register($16, 5)
1183#define read_c0_config6() __read_32bit_c0_register($16, 6)
1184#define read_c0_config7() __read_32bit_c0_register($16, 7)
1185#define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
1186#define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
1187#define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
1188#define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
1189#define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
1190#define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
1191#define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
1192#define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
1193
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001194#define read_c0_lladdr() __read_ulong_c0_register($17, 0)
1195#define write_c0_lladdr(val) __write_ulong_c0_register($17, 0, val)
1196#define read_c0_maar() __read_ulong_c0_register($17, 1)
1197#define write_c0_maar(val) __write_ulong_c0_register($17, 1, val)
1198#define read_c0_maari() __read_32bit_c0_register($17, 2)
1199#define write_c0_maari(val) __write_32bit_c0_register($17, 2, val)
1200
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001201/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001202 * The WatchLo register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001203 */
1204#define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
1205#define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
1206#define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
1207#define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
1208#define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
1209#define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
1210#define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
1211#define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
1212#define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
1213#define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
1214#define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
1215#define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
1216#define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
1217#define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
1218#define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
1219#define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
1220
1221/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001222 * The WatchHi register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001223 */
1224#define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
1225#define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
1226#define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
1227#define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
1228#define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
1229#define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
1230#define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
1231#define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
1232
1233#define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
1234#define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
1235#define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
1236#define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
1237#define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
1238#define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
1239#define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
1240#define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
1241
1242#define read_c0_xcontext() __read_ulong_c0_register($20, 0)
1243#define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
1244
1245#define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
1246#define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
1247
1248#define read_c0_framemask() __read_32bit_c0_register($21, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001249#define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001250
1251#define read_c0_diag() __read_32bit_c0_register($22, 0)
1252#define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
1253
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001254/* R10K CP0 Branch Diagnostic register is 64bits wide */
1255#define read_c0_r10k_diag() __read_64bit_c0_register($22, 0)
1256#define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val)
1257
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001258#define read_c0_diag1() __read_32bit_c0_register($22, 1)
1259#define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
1260
1261#define read_c0_diag2() __read_32bit_c0_register($22, 2)
1262#define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
1263
1264#define read_c0_diag3() __read_32bit_c0_register($22, 3)
1265#define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
1266
1267#define read_c0_diag4() __read_32bit_c0_register($22, 4)
1268#define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
1269
1270#define read_c0_diag5() __read_32bit_c0_register($22, 5)
1271#define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
1272
1273#define read_c0_debug() __read_32bit_c0_register($23, 0)
1274#define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
1275
1276#define read_c0_depc() __read_ulong_c0_register($24, 0)
1277#define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
1278
1279/*
1280 * MIPS32 / MIPS64 performance counters
1281 */
1282#define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001283#define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001284#define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001285#define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
1286#define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
1287#define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001288#define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001289#define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001290#define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001291#define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
1292#define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
1293#define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001294#define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001295#define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001296#define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001297#define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
1298#define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
1299#define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001300#define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001301#define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001302#define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001303#define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
1304#define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
1305#define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001306
1307#define read_c0_ecc() __read_32bit_c0_register($26, 0)
1308#define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
1309
1310#define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001311#define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001312
1313#define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
1314
1315#define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001316#define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001317
1318#define read_c0_taglo() __read_32bit_c0_register($28, 0)
1319#define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
1320
1321#define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
1322#define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
1323
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001324#define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
1325#define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
1326
1327#define read_c0_staglo() __read_32bit_c0_register($28, 4)
1328#define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
1329
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001330#define read_c0_taghi() __read_32bit_c0_register($29, 0)
1331#define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
1332
1333#define read_c0_errorepc() __read_ulong_c0_register($30, 0)
1334#define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
1335
1336/* MIPSR2 */
1337#define read_c0_hwrena() __read_32bit_c0_register($7, 0)
1338#define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
1339
1340#define read_c0_intctl() __read_32bit_c0_register($12, 1)
1341#define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
1342
1343#define read_c0_srsctl() __read_32bit_c0_register($12, 2)
1344#define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
1345
1346#define read_c0_srsmap() __read_32bit_c0_register($12, 3)
1347#define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
1348
1349#define read_c0_ebase() __read_32bit_c0_register($15, 1)
1350#define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
1351
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001352#define read_c0_cdmmbase() __read_ulong_c0_register($15, 2)
1353#define write_c0_cdmmbase(val) __write_ulong_c0_register($15, 2, val)
1354
1355/* MIPSR3 */
1356#define read_c0_segctl0() __read_32bit_c0_register($5, 2)
1357#define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
1358
1359#define read_c0_segctl1() __read_32bit_c0_register($5, 3)
1360#define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
1361
1362#define read_c0_segctl2() __read_32bit_c0_register($5, 4)
1363#define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
1364
1365/* Hardware Page Table Walker */
1366#define read_c0_pwbase() __read_ulong_c0_register($5, 5)
1367#define write_c0_pwbase(val) __write_ulong_c0_register($5, 5, val)
1368
1369#define read_c0_pwfield() __read_ulong_c0_register($5, 6)
1370#define write_c0_pwfield(val) __write_ulong_c0_register($5, 6, val)
1371
1372#define read_c0_pwsize() __read_ulong_c0_register($5, 7)
1373#define write_c0_pwsize(val) __write_ulong_c0_register($5, 7, val)
1374
1375#define read_c0_pwctl() __read_32bit_c0_register($6, 6)
1376#define write_c0_pwctl(val) __write_32bit_c0_register($6, 6, val)
1377
1378/* Cavium OCTEON (cnMIPS) */
1379#define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
1380#define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
1381
1382#define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
1383#define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
1384
1385#define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
1386#define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001387/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001388 * The cacheerr registers are not standardized. On OCTEON, they are
1389 * 64 bits wide.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001390 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001391#define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
1392#define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001393
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001394#define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
1395#define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
1396
1397/* BMIPS3300 */
1398#define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
1399#define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
1400
1401#define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
1402#define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
1403
1404#define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
1405#define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
1406
1407/* BMIPS43xx */
1408#define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
1409#define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
1410
1411#define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
1412#define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
1413
1414#define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
1415#define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
1416
1417#define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
1418#define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
1419
1420#define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
1421#define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
1422
1423/* BMIPS5000 */
1424#define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
1425#define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
1426
1427#define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
1428#define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
1429
1430#define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
1431#define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
1432
1433#define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
1434#define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
1435
1436#define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
1437#define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
1438
1439#define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
1440#define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
1441
1442/*
1443 * Macros to access the floating point coprocessor control registers
1444 */
1445#define _read_32bit_cp1_register(source, gas_hardfloat) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001446({ \
1447 unsigned int __res; \
1448 \
1449 __asm__ __volatile__( \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001450 " .set push \n" \
1451 " .set reorder \n" \
1452 " # gas fails to assemble cfc1 for some archs, \n" \
1453 " # like Octeon. \n" \
1454 " .set mips1 \n" \
1455 " "STR(gas_hardfloat)" \n" \
1456 " cfc1 %0,"STR(source)" \n" \
1457 " .set pop \n" \
1458 : "=r" (__res)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001459 __res; \
1460})
1461
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001462#define _write_32bit_cp1_register(dest, val, gas_hardfloat) \
1463({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001464 __asm__ __volatile__( \
1465 " .set push \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001466 " .set reorder \n" \
1467 " "STR(gas_hardfloat)" \n" \
1468 " ctc1 %0,"STR(dest)" \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001469 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001470 : : "r" (val)); \
1471})
1472
1473#ifdef GAS_HAS_SET_HARDFLOAT
1474#define read_32bit_cp1_register(source) \
1475 _read_32bit_cp1_register(source, .set hardfloat)
1476#define write_32bit_cp1_register(dest, val) \
1477 _write_32bit_cp1_register(dest, val, .set hardfloat)
1478#else
1479#define read_32bit_cp1_register(source) \
1480 _read_32bit_cp1_register(source, )
1481#define write_32bit_cp1_register(dest, val) \
1482 _write_32bit_cp1_register(dest, val, )
1483#endif
1484
1485#ifdef HAVE_AS_DSP
1486#define rddsp(mask) \
1487({ \
1488 unsigned int __dspctl; \
1489 \
1490 __asm__ __volatile__( \
1491 " .set push \n" \
1492 " .set dsp \n" \
1493 " rddsp %0, %x1 \n" \
1494 " .set pop \n" \
1495 : "=r" (__dspctl) \
1496 : "i" (mask)); \
1497 __dspctl; \
1498})
1499
1500#define wrdsp(val, mask) \
1501({ \
1502 __asm__ __volatile__( \
1503 " .set push \n" \
1504 " .set dsp \n" \
1505 " wrdsp %0, %x1 \n" \
1506 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001507 : \
1508 : "r" (val), "i" (mask)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001509})
1510
1511#define mflo0() \
1512({ \
1513 long mflo0; \
1514 __asm__( \
1515 " .set push \n" \
1516 " .set dsp \n" \
1517 " mflo %0, $ac0 \n" \
1518 " .set pop \n" \
1519 : "=r" (mflo0)); \
1520 mflo0; \
1521})
1522
1523#define mflo1() \
1524({ \
1525 long mflo1; \
1526 __asm__( \
1527 " .set push \n" \
1528 " .set dsp \n" \
1529 " mflo %0, $ac1 \n" \
1530 " .set pop \n" \
1531 : "=r" (mflo1)); \
1532 mflo1; \
1533})
1534
1535#define mflo2() \
1536({ \
1537 long mflo2; \
1538 __asm__( \
1539 " .set push \n" \
1540 " .set dsp \n" \
1541 " mflo %0, $ac2 \n" \
1542 " .set pop \n" \
1543 : "=r" (mflo2)); \
1544 mflo2; \
1545})
1546
1547#define mflo3() \
1548({ \
1549 long mflo3; \
1550 __asm__( \
1551 " .set push \n" \
1552 " .set dsp \n" \
1553 " mflo %0, $ac3 \n" \
1554 " .set pop \n" \
1555 : "=r" (mflo3)); \
1556 mflo3; \
1557})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001558
1559#define mfhi0() \
1560({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001561 long mfhi0; \
1562 __asm__( \
1563 " .set push \n" \
1564 " .set dsp \n" \
1565 " mfhi %0, $ac0 \n" \
1566 " .set pop \n" \
1567 : "=r" (mfhi0)); \
1568 mfhi0; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001569})
1570
1571#define mfhi1() \
1572({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001573 long mfhi1; \
1574 __asm__( \
1575 " .set push \n" \
1576 " .set dsp \n" \
1577 " mfhi %0, $ac1 \n" \
1578 " .set pop \n" \
1579 : "=r" (mfhi1)); \
1580 mfhi1; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001581})
1582
1583#define mfhi2() \
1584({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001585 long mfhi2; \
1586 __asm__( \
1587 " .set push \n" \
1588 " .set dsp \n" \
1589 " mfhi %0, $ac2 \n" \
1590 " .set pop \n" \
1591 : "=r" (mfhi2)); \
1592 mfhi2; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001593})
1594
1595#define mfhi3() \
1596({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001597 long mfhi3; \
1598 __asm__( \
1599 " .set push \n" \
1600 " .set dsp \n" \
1601 " mfhi %0, $ac3 \n" \
1602 " .set pop \n" \
1603 : "=r" (mfhi3)); \
1604 mfhi3; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001605})
1606
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001607
1608#define mtlo0(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001609({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001610 __asm__( \
1611 " .set push \n" \
1612 " .set dsp \n" \
1613 " mtlo %0, $ac0 \n" \
1614 " .set pop \n" \
1615 : \
1616 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001617})
1618
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001619#define mtlo1(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001620({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001621 __asm__( \
1622 " .set push \n" \
1623 " .set dsp \n" \
1624 " mtlo %0, $ac1 \n" \
1625 " .set pop \n" \
1626 : \
1627 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001628})
1629
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001630#define mtlo2(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001631({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001632 __asm__( \
1633 " .set push \n" \
1634 " .set dsp \n" \
1635 " mtlo %0, $ac2 \n" \
1636 " .set pop \n" \
1637 : \
1638 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001639})
1640
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001641#define mtlo3(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001642({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001643 __asm__( \
1644 " .set push \n" \
1645 " .set dsp \n" \
1646 " mtlo %0, $ac3 \n" \
1647 " .set pop \n" \
1648 : \
1649 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001650})
1651
1652#define mthi0(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001653({ \
1654 __asm__( \
1655 " .set push \n" \
1656 " .set dsp \n" \
1657 " mthi %0, $ac0 \n" \
1658 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001659 : \
1660 : "r" (x)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001661})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001662
1663#define mthi1(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001664({ \
1665 __asm__( \
1666 " .set push \n" \
1667 " .set dsp \n" \
1668 " mthi %0, $ac1 \n" \
1669 " .set pop \n" \
1670 : \
1671 : "r" (x)); \
1672})
1673
1674#define mthi2(x) \
1675({ \
1676 __asm__( \
1677 " .set push \n" \
1678 " .set dsp \n" \
1679 " mthi %0, $ac2 \n" \
1680 " .set pop \n" \
1681 : \
1682 : "r" (x)); \
1683})
1684
1685#define mthi3(x) \
1686({ \
1687 __asm__( \
1688 " .set push \n" \
1689 " .set dsp \n" \
1690 " mthi %0, $ac3 \n" \
1691 " .set pop \n" \
1692 : \
1693 : "r" (x)); \
1694})
1695
1696#else
1697
1698#ifdef CONFIG_CPU_MICROMIPS
1699#define rddsp(mask) \
1700({ \
1701 unsigned int __res; \
1702 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001703 __asm__ __volatile__( \
1704 " .set push \n" \
1705 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001706 " # rddsp $1, %x1 \n" \
1707 " .hword ((0x0020067c | (%x1 << 14)) >> 16) \n" \
1708 " .hword ((0x0020067c | (%x1 << 14)) & 0xffff) \n" \
1709 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001710 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001711 : "=r" (__res) \
1712 : "i" (mask)); \
1713 __res; \
1714})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001715
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001716#define wrdsp(val, mask) \
1717({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001718 __asm__ __volatile__( \
1719 " .set push \n" \
1720 " .set noat \n" \
1721 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001722 " # wrdsp $1, %x1 \n" \
1723 " .hword ((0x0020167c | (%x1 << 14)) >> 16) \n" \
1724 " .hword ((0x0020167c | (%x1 << 14)) & 0xffff) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001725 " .set pop \n" \
1726 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001727 : "r" (val), "i" (mask)); \
1728})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001729
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001730#define _umips_dsp_mfxxx(ins) \
1731({ \
1732 unsigned long __treg; \
1733 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001734 __asm__ __volatile__( \
1735 " .set push \n" \
1736 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001737 " .hword 0x0001 \n" \
1738 " .hword %x1 \n" \
1739 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001740 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001741 : "=r" (__treg) \
1742 : "i" (ins)); \
1743 __treg; \
1744})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001745
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001746#define _umips_dsp_mtxxx(val, ins) \
1747({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001748 __asm__ __volatile__( \
1749 " .set push \n" \
1750 " .set noat \n" \
1751 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001752 " .hword 0x0001 \n" \
1753 " .hword %x1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001754 " .set pop \n" \
1755 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001756 : "r" (val), "i" (ins)); \
1757})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001758
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001759#define _umips_dsp_mflo(reg) _umips_dsp_mfxxx((reg << 14) | 0x107c)
1760#define _umips_dsp_mfhi(reg) _umips_dsp_mfxxx((reg << 14) | 0x007c)
1761
1762#define _umips_dsp_mtlo(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x307c))
1763#define _umips_dsp_mthi(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x207c))
1764
1765#define mflo0() _umips_dsp_mflo(0)
1766#define mflo1() _umips_dsp_mflo(1)
1767#define mflo2() _umips_dsp_mflo(2)
1768#define mflo3() _umips_dsp_mflo(3)
1769
1770#define mfhi0() _umips_dsp_mfhi(0)
1771#define mfhi1() _umips_dsp_mfhi(1)
1772#define mfhi2() _umips_dsp_mfhi(2)
1773#define mfhi3() _umips_dsp_mfhi(3)
1774
1775#define mtlo0(x) _umips_dsp_mtlo(x, 0)
1776#define mtlo1(x) _umips_dsp_mtlo(x, 1)
1777#define mtlo2(x) _umips_dsp_mtlo(x, 2)
1778#define mtlo3(x) _umips_dsp_mtlo(x, 3)
1779
1780#define mthi0(x) _umips_dsp_mthi(x, 0)
1781#define mthi1(x) _umips_dsp_mthi(x, 1)
1782#define mthi2(x) _umips_dsp_mthi(x, 2)
1783#define mthi3(x) _umips_dsp_mthi(x, 3)
1784
1785#else /* !CONFIG_CPU_MICROMIPS */
1786#define rddsp(mask) \
1787({ \
1788 unsigned int __res; \
1789 \
1790 __asm__ __volatile__( \
1791 " .set push \n" \
1792 " .set noat \n" \
1793 " # rddsp $1, %x1 \n" \
1794 " .word 0x7c000cb8 | (%x1 << 16) \n" \
1795 " move %0, $1 \n" \
1796 " .set pop \n" \
1797 : "=r" (__res) \
1798 : "i" (mask)); \
1799 __res; \
1800})
1801
1802#define wrdsp(val, mask) \
1803({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001804 __asm__ __volatile__( \
1805 " .set push \n" \
1806 " .set noat \n" \
1807 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001808 " # wrdsp $1, %x1 \n" \
1809 " .word 0x7c2004f8 | (%x1 << 11) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001810 " .set pop \n" \
1811 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001812 : "r" (val), "i" (mask)); \
1813})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001814
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001815#define _dsp_mfxxx(ins) \
1816({ \
1817 unsigned long __treg; \
1818 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001819 __asm__ __volatile__( \
1820 " .set push \n" \
1821 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001822 " .word (0x00000810 | %1) \n" \
1823 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001824 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001825 : "=r" (__treg) \
1826 : "i" (ins)); \
1827 __treg; \
1828})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001829
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001830#define _dsp_mtxxx(val, ins) \
1831({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001832 __asm__ __volatile__( \
1833 " .set push \n" \
1834 " .set noat \n" \
1835 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001836 " .word (0x00200011 | %1) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001837 " .set pop \n" \
1838 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001839 : "r" (val), "i" (ins)); \
1840})
1841
1842#define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
1843#define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
1844
1845#define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
1846#define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
1847
1848#define mflo0() _dsp_mflo(0)
1849#define mflo1() _dsp_mflo(1)
1850#define mflo2() _dsp_mflo(2)
1851#define mflo3() _dsp_mflo(3)
1852
1853#define mfhi0() _dsp_mfhi(0)
1854#define mfhi1() _dsp_mfhi(1)
1855#define mfhi2() _dsp_mfhi(2)
1856#define mfhi3() _dsp_mfhi(3)
1857
1858#define mtlo0(x) _dsp_mtlo(x, 0)
1859#define mtlo1(x) _dsp_mtlo(x, 1)
1860#define mtlo2(x) _dsp_mtlo(x, 2)
1861#define mtlo3(x) _dsp_mtlo(x, 3)
1862
1863#define mthi0(x) _dsp_mthi(x, 0)
1864#define mthi1(x) _dsp_mthi(x, 1)
1865#define mthi2(x) _dsp_mthi(x, 2)
1866#define mthi3(x) _dsp_mthi(x, 3)
1867
1868#endif /* CONFIG_CPU_MICROMIPS */
1869#endif
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001870
1871/*
1872 * TLB operations.
1873 *
1874 * It is responsibility of the caller to take care of any TLB hazards.
1875 */
1876static inline void tlb_probe(void)
1877{
1878 __asm__ __volatile__(
1879 ".set noreorder\n\t"
1880 "tlbp\n\t"
1881 ".set reorder");
1882}
1883
1884static inline void tlb_read(void)
1885{
1886#if MIPS34K_MISSED_ITLB_WAR
1887 int res = 0;
1888
1889 __asm__ __volatile__(
1890 " .set push \n"
1891 " .set noreorder \n"
1892 " .set noat \n"
1893 " .set mips32r2 \n"
1894 " .word 0x41610001 # dvpe $1 \n"
1895 " move %0, $1 \n"
1896 " ehb \n"
1897 " .set pop \n"
1898 : "=r" (res));
1899
1900 instruction_hazard();
1901#endif
1902
1903 __asm__ __volatile__(
1904 ".set noreorder\n\t"
1905 "tlbr\n\t"
1906 ".set reorder");
1907
1908#if MIPS34K_MISSED_ITLB_WAR
1909 if ((res & _ULCAST_(1)))
1910 __asm__ __volatile__(
1911 " .set push \n"
1912 " .set noreorder \n"
1913 " .set noat \n"
1914 " .set mips32r2 \n"
1915 " .word 0x41600021 # evpe \n"
1916 " ehb \n"
1917 " .set pop \n");
1918#endif
1919}
1920
1921static inline void tlb_write_indexed(void)
1922{
1923 __asm__ __volatile__(
1924 ".set noreorder\n\t"
1925 "tlbwi\n\t"
1926 ".set reorder");
1927}
1928
1929static inline void tlb_write_random(void)
1930{
1931 __asm__ __volatile__(
1932 ".set noreorder\n\t"
1933 "tlbwr\n\t"
1934 ".set reorder");
1935}
1936
1937/*
1938 * Manipulate bits in a c0 register.
1939 */
1940#define __BUILD_SET_C0(name) \
1941static inline unsigned int \
1942set_c0_##name(unsigned int set) \
1943{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001944 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001945 \
1946 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001947 new = res | set; \
1948 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001949 \
1950 return res; \
1951} \
1952 \
1953static inline unsigned int \
1954clear_c0_##name(unsigned int clear) \
1955{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001956 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001957 \
1958 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001959 new = res & ~clear; \
1960 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001961 \
1962 return res; \
1963} \
1964 \
1965static inline unsigned int \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001966change_c0_##name(unsigned int change, unsigned int val) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001967{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001968 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001969 \
1970 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001971 new = res & ~change; \
1972 new |= (val & change); \
1973 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001974 \
1975 return res; \
1976}
1977
1978__BUILD_SET_C0(status)
1979__BUILD_SET_C0(cause)
1980__BUILD_SET_C0(config)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001981__BUILD_SET_C0(config5)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001982__BUILD_SET_C0(intcontrol)
1983__BUILD_SET_C0(intctl)
1984__BUILD_SET_C0(srsmap)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001985__BUILD_SET_C0(pagegrain)
1986__BUILD_SET_C0(brcm_config_0)
1987__BUILD_SET_C0(brcm_bus_pll)
1988__BUILD_SET_C0(brcm_reset)
1989__BUILD_SET_C0(brcm_cmt_intr)
1990__BUILD_SET_C0(brcm_cmt_ctrl)
1991__BUILD_SET_C0(brcm_config)
1992__BUILD_SET_C0(brcm_mode)
1993
1994/*
1995 * Return low 10 bits of ebase.
1996 * Note that under KVM (MIPSVZ) this returns vcpu id.
1997 */
1998static inline unsigned int get_ebase_cpunum(void)
1999{
2000 return read_c0_ebase() & 0x3ff;
2001}
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002002
Gregory CLEMENTe869d792018-12-14 16:16:45 +01002003static inline void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0,
2004 u32 low1)
2005{
2006 write_c0_entrylo0(low0);
2007 write_c0_pagemask(pagemask);
2008 write_c0_entrylo1(low1);
2009 write_c0_entryhi(hi);
2010 write_c0_index(index);
2011 tlb_write_indexed();
2012}
2013
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002014#endif /* !__ASSEMBLY__ */
2015
wdenk4fc95692003-02-28 00:49:47 +00002016#endif /* _ASM_MIPSREGS_H */