blob: 7538e6b2e0bf62c608cdb1a3a74141cbfc42dee2 [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
369
370/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900371 * Bits in the coprocessor 0 config register.
wdenk4fc95692003-02-28 00:49:47 +0000372 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900373/* Generic bits. */
wdenk4fc95692003-02-28 00:49:47 +0000374#define CONF_CM_CACHABLE_NO_WA 0
375#define CONF_CM_CACHABLE_WA 1
376#define CONF_CM_UNCACHED 2
377#define CONF_CM_CACHABLE_NONCOHERENT 3
378#define CONF_CM_CACHABLE_CE 4
379#define CONF_CM_CACHABLE_COW 5
380#define CONF_CM_CACHABLE_CUW 6
381#define CONF_CM_CACHABLE_ACCELERATED 7
382#define CONF_CM_CMASK 7
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900383#define CONF_BE (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000384
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900385/* Bits common to various processors. */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100386#define CONF_CU (_ULCAST_(1) << 3)
387#define CONF_DB (_ULCAST_(1) << 4)
388#define CONF_IB (_ULCAST_(1) << 5)
389#define CONF_DC (_ULCAST_(7) << 6)
390#define CONF_IC (_ULCAST_(7) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900391#define CONF_EB (_ULCAST_(1) << 13)
392#define CONF_EM (_ULCAST_(1) << 14)
393#define CONF_SM (_ULCAST_(1) << 16)
394#define CONF_SC (_ULCAST_(1) << 17)
395#define CONF_EW (_ULCAST_(3) << 18)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100396#define CONF_EP (_ULCAST_(15) << 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900397#define CONF_EC (_ULCAST_(7) << 28)
398#define CONF_CM (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000399
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100400/* Bits specific to the R4xx0. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900401#define R4K_CONF_SW (_ULCAST_(1) << 20)
402#define R4K_CONF_SS (_ULCAST_(1) << 21)
403#define R4K_CONF_SB (_ULCAST_(3) << 22)
404
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100405/* Bits specific to the R5000. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900406#define R5K_CONF_SE (_ULCAST_(1) << 12)
407#define R5K_CONF_SS (_ULCAST_(3) << 20)
408
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100409/* Bits specific to the RM7000. */
410#define RM7K_CONF_SE (_ULCAST_(1) << 3)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900411#define RM7K_CONF_TE (_ULCAST_(1) << 12)
412#define RM7K_CONF_CLK (_ULCAST_(1) << 16)
413#define RM7K_CONF_TC (_ULCAST_(1) << 17)
414#define RM7K_CONF_SI (_ULCAST_(3) << 20)
415#define RM7K_CONF_SC (_ULCAST_(1) << 31)
416
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100417/* Bits specific to the R10000. */
418#define R10K_CONF_DN (_ULCAST_(3) << 3)
419#define R10K_CONF_CT (_ULCAST_(1) << 5)
420#define R10K_CONF_PE (_ULCAST_(1) << 6)
421#define R10K_CONF_PM (_ULCAST_(3) << 7)
422#define R10K_CONF_EC (_ULCAST_(15) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900423#define R10K_CONF_SB (_ULCAST_(1) << 13)
424#define R10K_CONF_SK (_ULCAST_(1) << 14)
425#define R10K_CONF_SS (_ULCAST_(7) << 16)
426#define R10K_CONF_SC (_ULCAST_(7) << 19)
427#define R10K_CONF_DC (_ULCAST_(7) << 26)
428#define R10K_CONF_IC (_ULCAST_(7) << 29)
429
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100430/* Bits specific to the VR41xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900431#define VR41_CONF_CS (_ULCAST_(1) << 12)
432#define VR41_CONF_P4K (_ULCAST_(1) << 13)
433#define VR41_CONF_BP (_ULCAST_(1) << 16)
434#define VR41_CONF_M16 (_ULCAST_(1) << 20)
435#define VR41_CONF_AD (_ULCAST_(1) << 23)
436
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100437/* Bits specific to the R30xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900438#define R30XX_CONF_FDM (_ULCAST_(1) << 19)
439#define R30XX_CONF_REV (_ULCAST_(1) << 22)
440#define R30XX_CONF_AC (_ULCAST_(1) << 23)
441#define R30XX_CONF_RF (_ULCAST_(1) << 24)
442#define R30XX_CONF_HALT (_ULCAST_(1) << 25)
443#define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
444#define R30XX_CONF_DBR (_ULCAST_(1) << 29)
445#define R30XX_CONF_SB (_ULCAST_(1) << 30)
446#define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
447
448/* Bits specific to the TX49. */
449#define TX49_CONF_DC (_ULCAST_(1) << 16)
450#define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
451#define TX49_CONF_HALT (_ULCAST_(1) << 18)
452#define TX49_CONF_CWFON (_ULCAST_(1) << 27)
453
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100454/* Bits specific to the MIPS32/64 PRA. */
455#define MIPS_CONF_MT (_ULCAST_(7) << 7)
456#define MIPS_CONF_MT_TLB (_ULCAST_(1) << 7)
457#define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900458#define MIPS_CONF_AR (_ULCAST_(7) << 10)
459#define MIPS_CONF_AT (_ULCAST_(3) << 13)
Paul Burton4f5561c2016-09-21 11:18:50 +0100460#define MIPS_CONF_IMPL (_ULCAST_(0x1ff) << 16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900461#define MIPS_CONF_M (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000462
463/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900464 * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
wdenk4fc95692003-02-28 00:49:47 +0000465 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100466#define MIPS_CONF1_FP (_ULCAST_(1) << 0)
467#define MIPS_CONF1_EP (_ULCAST_(1) << 1)
468#define MIPS_CONF1_CA (_ULCAST_(1) << 2)
469#define MIPS_CONF1_WR (_ULCAST_(1) << 3)
470#define MIPS_CONF1_PC (_ULCAST_(1) << 4)
471#define MIPS_CONF1_MD (_ULCAST_(1) << 5)
472#define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
473#define MIPS_CONF1_DA_SHF 7
474#define MIPS_CONF1_DA_SZ 3
475#define MIPS_CONF1_DA (_ULCAST_(7) << 7)
476#define MIPS_CONF1_DL_SHF 10
477#define MIPS_CONF1_DL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900478#define MIPS_CONF1_DL (_ULCAST_(7) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100479#define MIPS_CONF1_DS_SHF 13
480#define MIPS_CONF1_DS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900481#define MIPS_CONF1_DS (_ULCAST_(7) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100482#define MIPS_CONF1_IA_SHF 16
483#define MIPS_CONF1_IA_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900484#define MIPS_CONF1_IA (_ULCAST_(7) << 16)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100485#define MIPS_CONF1_IL_SHF 19
486#define MIPS_CONF1_IL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900487#define MIPS_CONF1_IL (_ULCAST_(7) << 19)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100488#define MIPS_CONF1_IS_SHF 22
489#define MIPS_CONF1_IS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900490#define MIPS_CONF1_IS (_ULCAST_(7) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100491#define MIPS_CONF1_TLBS_SHIFT (25)
492#define MIPS_CONF1_TLBS_SIZE (6)
493#define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900494
Paul Burton81560782016-09-21 11:18:54 +0100495#define MIPS_CONF2_SA_SHF 0
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100496#define MIPS_CONF2_SA (_ULCAST_(15) << 0)
Paul Burton81560782016-09-21 11:18:54 +0100497#define MIPS_CONF2_SL_SHF 4
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100498#define MIPS_CONF2_SL (_ULCAST_(15) << 4)
Paul Burton81560782016-09-21 11:18:54 +0100499#define MIPS_CONF2_SS_SHF 8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100500#define MIPS_CONF2_SS (_ULCAST_(15) << 8)
Paul Burton81560782016-09-21 11:18:54 +0100501#define MIPS_CONF2_L2B (_ULCAST_(1) << 12)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100502#define MIPS_CONF2_SU (_ULCAST_(15) << 12)
503#define MIPS_CONF2_TA (_ULCAST_(15) << 16)
504#define MIPS_CONF2_TL (_ULCAST_(15) << 20)
505#define MIPS_CONF2_TS (_ULCAST_(15) << 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900506#define MIPS_CONF2_TU (_ULCAST_(7) << 28)
507
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100508#define MIPS_CONF3_TL (_ULCAST_(1) << 0)
509#define MIPS_CONF3_SM (_ULCAST_(1) << 1)
510#define MIPS_CONF3_MT (_ULCAST_(1) << 2)
511#define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
512#define MIPS_CONF3_SP (_ULCAST_(1) << 4)
513#define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
514#define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
515#define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
516#define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
517#define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900518#define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100519#define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
520#define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900521#define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100522#define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
523#define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
524#define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
525#define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
526#define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
527#define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
528#define MIPS_CONF3_PW (_ULCAST_(1) << 24)
529#define MIPS_CONF3_SC (_ULCAST_(1) << 25)
530#define MIPS_CONF3_BI (_ULCAST_(1) << 26)
531#define MIPS_CONF3_BP (_ULCAST_(1) << 27)
532#define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
533#define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
534#define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
535
536#define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
537#define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
538#define MIPS_CONF4_FTLBSETS_SHIFT (0)
539#define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
540#define MIPS_CONF4_FTLBWAYS_SHIFT (4)
541#define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
542#define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
543/* bits 10:8 in FTLB-only configurations */
544#define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
545/* bits 12:8 in VTLB-FTLB only configurations */
546#define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
547#define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
548#define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
549#define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
550#define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
551#define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << 16)
552#define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
553#define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
554#define MIPS_CONF4_AE (_ULCAST_(1) << 28)
555#define MIPS_CONF4_IE (_ULCAST_(3) << 29)
556#define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
557
558#define MIPS_CONF5_NF (_ULCAST_(1) << 0)
559#define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
560#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)
561#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)
562#define MIPS_CONF5_MVH (_ULCAST_(1) << 5)
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100563#define MIPS_CONF5_VP (_ULCAST_(1) << 7)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100564#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)
565#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)
Paul Burton81560782016-09-21 11:18:54 +0100566#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100567#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
568#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
569#define MIPS_CONF5_CV (_ULCAST_(1) << 29)
570#define MIPS_CONF5_K (_ULCAST_(1) << 30)
571
572#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
573/* proAptiv FTLB on/off bit */
574#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
575/* FTLB probability bits */
576#define MIPS_CONF6_FTLBP_SHIFT (16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900577
578#define MIPS_CONF7_WII (_ULCAST_(1) << 31)
579
580#define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
wdenk4fc95692003-02-28 00:49:47 +0000581
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100582#define MIPS_CONF7_IAR (_ULCAST_(1) << 10)
583#define MIPS_CONF7_AR (_ULCAST_(1) << 16)
584/* FTLB probability bits for R6 */
585#define MIPS_CONF7_FTLBP_SHIFT (18)
586
587/* MAAR bit definitions */
588#define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12)
589#define MIPS_MAAR_ADDR_SHIFT 12
590#define MIPS_MAAR_S (_ULCAST_(1) << 1)
591#define MIPS_MAAR_V (_ULCAST_(1) << 0)
592
593/* CMGCRBase bit definitions */
594#define MIPS_CMGCRB_BASE 11
595#define MIPS_CMGCRF_BASE (~_ULCAST_((1 << MIPS_CMGCRB_BASE) - 1))
596
597/*
598 * Bits in the MIPS32 Memory Segmentation registers.
599 */
600#define MIPS_SEGCFG_PA_SHIFT 9
601#define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
602#define MIPS_SEGCFG_AM_SHIFT 4
603#define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
604#define MIPS_SEGCFG_EU_SHIFT 3
605#define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
606#define MIPS_SEGCFG_C_SHIFT 0
607#define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
608
609#define MIPS_SEGCFG_UUSK _ULCAST_(7)
610#define MIPS_SEGCFG_USK _ULCAST_(5)
611#define MIPS_SEGCFG_MUSUK _ULCAST_(4)
612#define MIPS_SEGCFG_MUSK _ULCAST_(3)
613#define MIPS_SEGCFG_MSK _ULCAST_(2)
614#define MIPS_SEGCFG_MK _ULCAST_(1)
615#define MIPS_SEGCFG_UK _ULCAST_(0)
616
617#define MIPS_PWFIELD_GDI_SHIFT 24
618#define MIPS_PWFIELD_GDI_MASK 0x3f000000
619#define MIPS_PWFIELD_UDI_SHIFT 18
620#define MIPS_PWFIELD_UDI_MASK 0x00fc0000
621#define MIPS_PWFIELD_MDI_SHIFT 12
622#define MIPS_PWFIELD_MDI_MASK 0x0003f000
623#define MIPS_PWFIELD_PTI_SHIFT 6
624#define MIPS_PWFIELD_PTI_MASK 0x00000fc0
625#define MIPS_PWFIELD_PTEI_SHIFT 0
626#define MIPS_PWFIELD_PTEI_MASK 0x0000003f
627
628#define MIPS_PWSIZE_GDW_SHIFT 24
629#define MIPS_PWSIZE_GDW_MASK 0x3f000000
630#define MIPS_PWSIZE_UDW_SHIFT 18
631#define MIPS_PWSIZE_UDW_MASK 0x00fc0000
632#define MIPS_PWSIZE_MDW_SHIFT 12
633#define MIPS_PWSIZE_MDW_MASK 0x0003f000
634#define MIPS_PWSIZE_PTW_SHIFT 6
635#define MIPS_PWSIZE_PTW_MASK 0x00000fc0
636#define MIPS_PWSIZE_PTEW_SHIFT 0
637#define MIPS_PWSIZE_PTEW_MASK 0x0000003f
638
639#define MIPS_PWCTL_PWEN_SHIFT 31
640#define MIPS_PWCTL_PWEN_MASK 0x80000000
641#define MIPS_PWCTL_DPH_SHIFT 7
642#define MIPS_PWCTL_DPH_MASK 0x00000080
643#define MIPS_PWCTL_HUGEPG_SHIFT 6
644#define MIPS_PWCTL_HUGEPG_MASK 0x00000060
645#define MIPS_PWCTL_PSN_SHIFT 0
646#define MIPS_PWCTL_PSN_MASK 0x0000003f
647
648/* CDMMBase register bit definitions */
649#define MIPS_CDMMBASE_SIZE_SHIFT 0
650#define MIPS_CDMMBASE_SIZE (_ULCAST_(511) << MIPS_CDMMBASE_SIZE_SHIFT)
651#define MIPS_CDMMBASE_CI (_ULCAST_(1) << 9)
652#define MIPS_CDMMBASE_EN (_ULCAST_(1) << 10)
653#define MIPS_CDMMBASE_ADDR_SHIFT 11
654#define MIPS_CDMMBASE_ADDR_START 15
655
656/*
657 * Bitfields in the TX39 family CP0 Configuration Register 3
658 */
659#define TX39_CONF_ICS_SHIFT 19
660#define TX39_CONF_ICS_MASK 0x00380000
661#define TX39_CONF_ICS_1KB 0x00000000
662#define TX39_CONF_ICS_2KB 0x00080000
663#define TX39_CONF_ICS_4KB 0x00100000
664#define TX39_CONF_ICS_8KB 0x00180000
665#define TX39_CONF_ICS_16KB 0x00200000
666
667#define TX39_CONF_DCS_SHIFT 16
668#define TX39_CONF_DCS_MASK 0x00070000
669#define TX39_CONF_DCS_1KB 0x00000000
670#define TX39_CONF_DCS_2KB 0x00010000
671#define TX39_CONF_DCS_4KB 0x00020000
672#define TX39_CONF_DCS_8KB 0x00030000
673#define TX39_CONF_DCS_16KB 0x00040000
674
675#define TX39_CONF_CWFON 0x00004000
676#define TX39_CONF_WBON 0x00002000
677#define TX39_CONF_RF_SHIFT 10
678#define TX39_CONF_RF_MASK 0x00000c00
679#define TX39_CONF_DOZE 0x00000200
680#define TX39_CONF_HALT 0x00000100
681#define TX39_CONF_LOCK 0x00000080
682#define TX39_CONF_ICE 0x00000020
683#define TX39_CONF_DCE 0x00000010
684#define TX39_CONF_IRSIZE_SHIFT 2
685#define TX39_CONF_IRSIZE_MASK 0x0000000c
686#define TX39_CONF_DRSIZE_SHIFT 0
687#define TX39_CONF_DRSIZE_MASK 0x00000003
688
689/*
690 * Interesting Bits in the R10K CP0 Branch Diagnostic Register
691 */
692/* Disable Branch Target Address Cache */
693#define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27)
694/* Enable Branch Prediction Global History */
695#define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26)
696/* Disable Branch Return Cache */
697#define R10K_DIAG_D_BRC (_ULCAST_(1) << 22)
698
wdenk4fc95692003-02-28 00:49:47 +0000699/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100700 * Coprocessor 1 (FPU) register names
701 */
702#define CP1_REVISION $0
703#define CP1_UFR $1
704#define CP1_UNFR $4
705#define CP1_FCCR $25
706#define CP1_FEXR $26
707#define CP1_FENR $28
708#define CP1_STATUS $31
709
710
711/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900712 * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
wdenk4fc95692003-02-28 00:49:47 +0000713 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900714#define MIPS_FPIR_S (_ULCAST_(1) << 16)
715#define MIPS_FPIR_D (_ULCAST_(1) << 17)
716#define MIPS_FPIR_PS (_ULCAST_(1) << 18)
717#define MIPS_FPIR_3D (_ULCAST_(1) << 19)
718#define MIPS_FPIR_W (_ULCAST_(1) << 20)
719#define MIPS_FPIR_L (_ULCAST_(1) << 21)
720#define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100721#define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
722#define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
723#define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
724
725/*
726 * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
727 */
728#define MIPS_FCCR_CONDX_S 0
729#define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
730#define MIPS_FCCR_COND0_S 0
731#define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
732#define MIPS_FCCR_COND1_S 1
733#define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
734#define MIPS_FCCR_COND2_S 2
735#define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
736#define MIPS_FCCR_COND3_S 3
737#define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
738#define MIPS_FCCR_COND4_S 4
739#define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
740#define MIPS_FCCR_COND5_S 5
741#define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
742#define MIPS_FCCR_COND6_S 6
743#define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
744#define MIPS_FCCR_COND7_S 7
745#define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
746
747/*
748 * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
749 */
750#define MIPS_FENR_FS_S 2
751#define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
752
753/*
754 * FPU Status Register Values
755 */
756#define FPU_CSR_COND_S 23 /* $fcc0 */
757#define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
758
759#define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
760#define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
761
762#define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
763#define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
764#define FPU_CSR_COND1_S 25 /* $fcc1 */
765#define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
766#define FPU_CSR_COND2_S 26 /* $fcc2 */
767#define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
768#define FPU_CSR_COND3_S 27 /* $fcc3 */
769#define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
770#define FPU_CSR_COND4_S 28 /* $fcc4 */
771#define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
772#define FPU_CSR_COND5_S 29 /* $fcc5 */
773#define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
774#define FPU_CSR_COND6_S 30 /* $fcc6 */
775#define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
776#define FPU_CSR_COND7_S 31 /* $fcc7 */
777#define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
778
779/*
780 * Bits 22:20 of the FPU Status Register will be read as 0,
781 * and should be written as zero.
782 */
783#define FPU_CSR_RSVD (_ULCAST_(7) << 20)
784
785#define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
786#define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
787
788/*
789 * X the exception cause indicator
790 * E the exception enable
791 * S the sticky/flag bit
792*/
793#define FPU_CSR_ALL_X 0x0003f000
794#define FPU_CSR_UNI_X 0x00020000
795#define FPU_CSR_INV_X 0x00010000
796#define FPU_CSR_DIV_X 0x00008000
797#define FPU_CSR_OVF_X 0x00004000
798#define FPU_CSR_UDF_X 0x00002000
799#define FPU_CSR_INE_X 0x00001000
800
801#define FPU_CSR_ALL_E 0x00000f80
802#define FPU_CSR_INV_E 0x00000800
803#define FPU_CSR_DIV_E 0x00000400
804#define FPU_CSR_OVF_E 0x00000200
805#define FPU_CSR_UDF_E 0x00000100
806#define FPU_CSR_INE_E 0x00000080
807
808#define FPU_CSR_ALL_S 0x0000007c
809#define FPU_CSR_INV_S 0x00000040
810#define FPU_CSR_DIV_S 0x00000020
811#define FPU_CSR_OVF_S 0x00000010
812#define FPU_CSR_UDF_S 0x00000008
813#define FPU_CSR_INE_S 0x00000004
814
815/* Bits 0 and 1 of FPU Status Register specify the rounding mode */
816#define FPU_CSR_RM 0x00000003
817#define FPU_CSR_RN 0x0 /* nearest */
818#define FPU_CSR_RZ 0x1 /* towards zero */
819#define FPU_CSR_RU 0x2 /* towards +Infinity */
820#define FPU_CSR_RD 0x3 /* towards -Infinity */
821
wdenk4fc95692003-02-28 00:49:47 +0000822
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900823#ifndef __ASSEMBLY__
824
825/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100826 * Macros for handling the ISA mode bit for MIPS16 and microMIPS.
827 */
828#if defined(CONFIG_SYS_SUPPORTS_MIPS16) || \
829 defined(CONFIG_SYS_SUPPORTS_MICROMIPS)
830#define get_isa16_mode(x) ((x) & 0x1)
831#define msk_isa16_mode(x) ((x) & ~0x1)
832#define set_isa16_mode(x) do { (x) |= 0x1; } while (0)
833#else
834#define get_isa16_mode(x) 0
835#define msk_isa16_mode(x) (x)
836#define set_isa16_mode(x) do { } while (0)
837#endif
838
839/*
840 * microMIPS instructions can be 16-bit or 32-bit in length. This
841 * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
842 */
843static inline int mm_insn_16bit(u16 insn)
844{
845 u16 opcode = (insn >> 10) & 0x7;
846
847 return (opcode >= 1 && opcode <= 3) ? 1 : 0;
848}
849
850/*
851 * TLB Invalidate Flush
852 */
853static inline void tlbinvf(void)
854{
855 __asm__ __volatile__(
856 ".set push\n\t"
857 ".set noreorder\n\t"
858 ".word 0x42000004\n\t" /* tlbinvf */
859 ".set pop");
860}
861
862
863/*
864 * Functions to access the R10000 performance counters. These are basically
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900865 * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
866 * performance counter number encoded into bits 1 ... 5 of the instruction.
867 * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
868 * disassembler these will look like an access to sel 0 or 1.
869 */
870#define read_r10k_perf_cntr(counter) \
871({ \
872 unsigned int __res; \
873 __asm__ __volatile__( \
874 "mfpc\t%0, %1" \
875 : "=r" (__res) \
876 : "i" (counter)); \
877 \
878 __res; \
879})
880
881#define write_r10k_perf_cntr(counter,val) \
882do { \
883 __asm__ __volatile__( \
884 "mtpc\t%0, %1" \
885 : \
886 : "r" (val), "i" (counter)); \
887} while (0)
888
889#define read_r10k_perf_event(counter) \
890({ \
891 unsigned int __res; \
892 __asm__ __volatile__( \
893 "mfps\t%0, %1" \
894 : "=r" (__res) \
895 : "i" (counter)); \
896 \
897 __res; \
898})
899
900#define write_r10k_perf_cntl(counter,val) \
901do { \
902 __asm__ __volatile__( \
903 "mtps\t%0, %1" \
904 : \
905 : "r" (val), "i" (counter)); \
906} while (0)
907
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100908
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900909/*
910 * Macros to access the system control coprocessor
911 */
912
913#define __read_32bit_c0_register(source, sel) \
Chris Packham36c624a2015-07-14 22:54:41 +1200914({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900915 if (sel == 0) \
916 __asm__ __volatile__( \
917 "mfc0\t%0, " #source "\n\t" \
918 : "=r" (__res)); \
919 else \
920 __asm__ __volatile__( \
921 ".set\tmips32\n\t" \
922 "mfc0\t%0, " #source ", " #sel "\n\t" \
923 ".set\tmips0\n\t" \
924 : "=r" (__res)); \
925 __res; \
926})
927
928#define __read_64bit_c0_register(source, sel) \
929({ unsigned long long __res; \
930 if (sizeof(unsigned long) == 4) \
931 __res = __read_64bit_c0_split(source, sel); \
932 else if (sel == 0) \
933 __asm__ __volatile__( \
934 ".set\tmips3\n\t" \
935 "dmfc0\t%0, " #source "\n\t" \
936 ".set\tmips0" \
937 : "=r" (__res)); \
938 else \
939 __asm__ __volatile__( \
940 ".set\tmips64\n\t" \
941 "dmfc0\t%0, " #source ", " #sel "\n\t" \
942 ".set\tmips0" \
943 : "=r" (__res)); \
944 __res; \
945})
946
947#define __write_32bit_c0_register(register, sel, value) \
948do { \
949 if (sel == 0) \
950 __asm__ __volatile__( \
951 "mtc0\t%z0, " #register "\n\t" \
952 : : "Jr" ((unsigned int)(value))); \
953 else \
954 __asm__ __volatile__( \
955 ".set\tmips32\n\t" \
956 "mtc0\t%z0, " #register ", " #sel "\n\t" \
957 ".set\tmips0" \
958 : : "Jr" ((unsigned int)(value))); \
959} while (0)
960
961#define __write_64bit_c0_register(register, sel, value) \
962do { \
963 if (sizeof(unsigned long) == 4) \
964 __write_64bit_c0_split(register, sel, value); \
965 else if (sel == 0) \
966 __asm__ __volatile__( \
967 ".set\tmips3\n\t" \
968 "dmtc0\t%z0, " #register "\n\t" \
969 ".set\tmips0" \
970 : : "Jr" (value)); \
971 else \
972 __asm__ __volatile__( \
973 ".set\tmips64\n\t" \
974 "dmtc0\t%z0, " #register ", " #sel "\n\t" \
975 ".set\tmips0" \
976 : : "Jr" (value)); \
977} while (0)
978
979#define __read_ulong_c0_register(reg, sel) \
980 ((sizeof(unsigned long) == 4) ? \
981 (unsigned long) __read_32bit_c0_register(reg, sel) : \
982 (unsigned long) __read_64bit_c0_register(reg, sel))
983
984#define __write_ulong_c0_register(reg, sel, val) \
985do { \
986 if (sizeof(unsigned long) == 4) \
987 __write_32bit_c0_register(reg, sel, val); \
988 else \
989 __write_64bit_c0_register(reg, sel, val); \
990} while (0)
991
992/*
993 * On RM7000/RM9000 these are uses to access cop0 set 1 registers
994 */
995#define __read_32bit_c0_ctrl_register(source) \
Chris Packham36c624a2015-07-14 22:54:41 +1200996({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +0900997 __asm__ __volatile__( \
998 "cfc0\t%0, " #source "\n\t" \
999 : "=r" (__res)); \
1000 __res; \
1001})
1002
1003#define __write_32bit_c0_ctrl_register(register, value) \
1004do { \
1005 __asm__ __volatile__( \
1006 "ctc0\t%z0, " #register "\n\t" \
1007 : : "Jr" ((unsigned int)(value))); \
1008} while (0)
1009
1010/*
1011 * These versions are only needed for systems with more than 38 bits of
1012 * physical address space running the 32-bit kernel. That's none atm :-)
1013 */
1014#define __read_64bit_c0_split(source, sel) \
1015({ \
1016 unsigned long long __val; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001017 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001018 if (sel == 0) \
1019 __asm__ __volatile__( \
1020 ".set\tmips64\n\t" \
1021 "dmfc0\t%M0, " #source "\n\t" \
1022 "dsll\t%L0, %M0, 32\n\t" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001023 "dsra\t%M0, %M0, 32\n\t" \
1024 "dsra\t%L0, %L0, 32\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001025 ".set\tmips0" \
1026 : "=r" (__val)); \
1027 else \
1028 __asm__ __volatile__( \
1029 ".set\tmips64\n\t" \
1030 "dmfc0\t%M0, " #source ", " #sel "\n\t" \
1031 "dsll\t%L0, %M0, 32\n\t" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001032 "dsra\t%M0, %M0, 32\n\t" \
1033 "dsra\t%L0, %L0, 32\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001034 ".set\tmips0" \
1035 : "=r" (__val)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001036 \
1037 __val; \
1038})
1039
1040#define __write_64bit_c0_split(source, sel, val) \
1041do { \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001042 if (sel == 0) \
1043 __asm__ __volatile__( \
1044 ".set\tmips64\n\t" \
1045 "dsll\t%L0, %L0, 32\n\t" \
1046 "dsrl\t%L0, %L0, 32\n\t" \
1047 "dsll\t%M0, %M0, 32\n\t" \
1048 "or\t%L0, %L0, %M0\n\t" \
1049 "dmtc0\t%L0, " #source "\n\t" \
1050 ".set\tmips0" \
1051 : : "r" (val)); \
1052 else \
1053 __asm__ __volatile__( \
1054 ".set\tmips64\n\t" \
1055 "dsll\t%L0, %L0, 32\n\t" \
1056 "dsrl\t%L0, %L0, 32\n\t" \
1057 "dsll\t%M0, %M0, 32\n\t" \
1058 "or\t%L0, %L0, %M0\n\t" \
1059 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
1060 ".set\tmips0" \
1061 : : "r" (val)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001062} while (0)
1063
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001064#define __readx_32bit_c0_register(source) \
1065({ \
1066 unsigned int __res; \
1067 \
1068 __asm__ __volatile__( \
1069 " .set push \n" \
1070 " .set noat \n" \
1071 " .set mips32r2 \n" \
1072 " .insn \n" \
1073 " # mfhc0 $1, %1 \n" \
1074 " .word (0x40410000 | ((%1 & 0x1f) << 11)) \n" \
1075 " move %0, $1 \n" \
1076 " .set pop \n" \
1077 : "=r" (__res) \
1078 : "i" (source)); \
1079 __res; \
1080})
1081
1082#define __writex_32bit_c0_register(register, value) \
1083({ \
1084 __asm__ __volatile__( \
1085 " .set push \n" \
1086 " .set noat \n" \
1087 " .set mips32r2 \n" \
1088 " move $1, %0 \n" \
1089 " # mthc0 $1, %1 \n" \
1090 " .insn \n" \
1091 " .word (0x40c10000 | ((%1 & 0x1f) << 11)) \n" \
1092 " .set pop \n" \
1093 : \
1094 : "r" (value), "i" (register)); \
1095})
1096
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001097#define read_c0_index() __read_32bit_c0_register($0, 0)
1098#define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
1099
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001100#define read_c0_random() __read_32bit_c0_register($1, 0)
1101#define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
1102
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001103#define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
1104#define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
1105
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001106#define readx_c0_entrylo0() __readx_32bit_c0_register(2)
1107#define writex_c0_entrylo0(val) __writex_32bit_c0_register(2, val)
1108
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001109#define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
1110#define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
1111
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001112#define readx_c0_entrylo1() __readx_32bit_c0_register(3)
1113#define writex_c0_entrylo1(val) __writex_32bit_c0_register(3, val)
1114
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001115#define read_c0_conf() __read_32bit_c0_register($3, 0)
1116#define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
1117
1118#define read_c0_context() __read_ulong_c0_register($4, 0)
1119#define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
1120
1121#define read_c0_userlocal() __read_ulong_c0_register($4, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001122#define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001123
1124#define read_c0_pagemask() __read_32bit_c0_register($5, 0)
1125#define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
1126
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001127#define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
1128#define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
1129
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001130#define read_c0_wired() __read_32bit_c0_register($6, 0)
1131#define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
1132
1133#define read_c0_info() __read_32bit_c0_register($7, 0)
1134
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001135#define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001136#define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
1137
1138#define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
1139#define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
1140
1141#define read_c0_count() __read_32bit_c0_register($9, 0)
1142#define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
1143
1144#define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
1145#define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
1146
1147#define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
1148#define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
1149
1150#define read_c0_entryhi() __read_ulong_c0_register($10, 0)
1151#define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
1152
1153#define read_c0_compare() __read_32bit_c0_register($11, 0)
1154#define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
1155
1156#define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
1157#define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
1158
1159#define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
1160#define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
1161
1162#define read_c0_status() __read_32bit_c0_register($12, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001163
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001164#define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001165
1166#define read_c0_cause() __read_32bit_c0_register($13, 0)
1167#define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
1168
1169#define read_c0_epc() __read_ulong_c0_register($14, 0)
1170#define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
1171
1172#define read_c0_prid() __read_32bit_c0_register($15, 0)
1173
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001174#define read_c0_cmgcrbase() __read_ulong_c0_register($15, 3)
1175
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001176#define read_c0_config() __read_32bit_c0_register($16, 0)
1177#define read_c0_config1() __read_32bit_c0_register($16, 1)
1178#define read_c0_config2() __read_32bit_c0_register($16, 2)
1179#define read_c0_config3() __read_32bit_c0_register($16, 3)
1180#define read_c0_config4() __read_32bit_c0_register($16, 4)
1181#define read_c0_config5() __read_32bit_c0_register($16, 5)
1182#define read_c0_config6() __read_32bit_c0_register($16, 6)
1183#define read_c0_config7() __read_32bit_c0_register($16, 7)
1184#define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
1185#define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
1186#define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
1187#define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
1188#define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
1189#define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
1190#define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
1191#define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
1192
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001193#define read_c0_lladdr() __read_ulong_c0_register($17, 0)
1194#define write_c0_lladdr(val) __write_ulong_c0_register($17, 0, val)
1195#define read_c0_maar() __read_ulong_c0_register($17, 1)
1196#define write_c0_maar(val) __write_ulong_c0_register($17, 1, val)
1197#define read_c0_maari() __read_32bit_c0_register($17, 2)
1198#define write_c0_maari(val) __write_32bit_c0_register($17, 2, val)
1199
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001200/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001201 * The WatchLo register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001202 */
1203#define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
1204#define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
1205#define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
1206#define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
1207#define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
1208#define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
1209#define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
1210#define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
1211#define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
1212#define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
1213#define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
1214#define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
1215#define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
1216#define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
1217#define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
1218#define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
1219
1220/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001221 * The WatchHi register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001222 */
1223#define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
1224#define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
1225#define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
1226#define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
1227#define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
1228#define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
1229#define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
1230#define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
1231
1232#define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
1233#define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
1234#define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
1235#define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
1236#define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
1237#define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
1238#define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
1239#define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
1240
1241#define read_c0_xcontext() __read_ulong_c0_register($20, 0)
1242#define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
1243
1244#define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
1245#define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
1246
1247#define read_c0_framemask() __read_32bit_c0_register($21, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001248#define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001249
1250#define read_c0_diag() __read_32bit_c0_register($22, 0)
1251#define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
1252
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001253/* R10K CP0 Branch Diagnostic register is 64bits wide */
1254#define read_c0_r10k_diag() __read_64bit_c0_register($22, 0)
1255#define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val)
1256
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001257#define read_c0_diag1() __read_32bit_c0_register($22, 1)
1258#define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
1259
1260#define read_c0_diag2() __read_32bit_c0_register($22, 2)
1261#define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
1262
1263#define read_c0_diag3() __read_32bit_c0_register($22, 3)
1264#define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
1265
1266#define read_c0_diag4() __read_32bit_c0_register($22, 4)
1267#define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
1268
1269#define read_c0_diag5() __read_32bit_c0_register($22, 5)
1270#define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
1271
1272#define read_c0_debug() __read_32bit_c0_register($23, 0)
1273#define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
1274
1275#define read_c0_depc() __read_ulong_c0_register($24, 0)
1276#define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
1277
1278/*
1279 * MIPS32 / MIPS64 performance counters
1280 */
1281#define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001282#define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001283#define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001284#define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
1285#define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
1286#define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001287#define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001288#define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001289#define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001290#define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
1291#define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
1292#define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001293#define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001294#define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001295#define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001296#define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
1297#define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
1298#define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001299#define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001300#define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001301#define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001302#define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
1303#define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
1304#define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001305
1306#define read_c0_ecc() __read_32bit_c0_register($26, 0)
1307#define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
1308
1309#define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001310#define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001311
1312#define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
1313
1314#define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001315#define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001316
1317#define read_c0_taglo() __read_32bit_c0_register($28, 0)
1318#define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
1319
1320#define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
1321#define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
1322
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001323#define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
1324#define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
1325
1326#define read_c0_staglo() __read_32bit_c0_register($28, 4)
1327#define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
1328
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001329#define read_c0_taghi() __read_32bit_c0_register($29, 0)
1330#define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
1331
1332#define read_c0_errorepc() __read_ulong_c0_register($30, 0)
1333#define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
1334
1335/* MIPSR2 */
1336#define read_c0_hwrena() __read_32bit_c0_register($7, 0)
1337#define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
1338
1339#define read_c0_intctl() __read_32bit_c0_register($12, 1)
1340#define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
1341
1342#define read_c0_srsctl() __read_32bit_c0_register($12, 2)
1343#define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
1344
1345#define read_c0_srsmap() __read_32bit_c0_register($12, 3)
1346#define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
1347
1348#define read_c0_ebase() __read_32bit_c0_register($15, 1)
1349#define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
1350
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001351#define read_c0_cdmmbase() __read_ulong_c0_register($15, 2)
1352#define write_c0_cdmmbase(val) __write_ulong_c0_register($15, 2, val)
1353
1354/* MIPSR3 */
1355#define read_c0_segctl0() __read_32bit_c0_register($5, 2)
1356#define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
1357
1358#define read_c0_segctl1() __read_32bit_c0_register($5, 3)
1359#define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
1360
1361#define read_c0_segctl2() __read_32bit_c0_register($5, 4)
1362#define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
1363
1364/* Hardware Page Table Walker */
1365#define read_c0_pwbase() __read_ulong_c0_register($5, 5)
1366#define write_c0_pwbase(val) __write_ulong_c0_register($5, 5, val)
1367
1368#define read_c0_pwfield() __read_ulong_c0_register($5, 6)
1369#define write_c0_pwfield(val) __write_ulong_c0_register($5, 6, val)
1370
1371#define read_c0_pwsize() __read_ulong_c0_register($5, 7)
1372#define write_c0_pwsize(val) __write_ulong_c0_register($5, 7, val)
1373
1374#define read_c0_pwctl() __read_32bit_c0_register($6, 6)
1375#define write_c0_pwctl(val) __write_32bit_c0_register($6, 6, val)
1376
1377/* Cavium OCTEON (cnMIPS) */
1378#define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
1379#define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
1380
1381#define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
1382#define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
1383
1384#define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
1385#define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001386/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001387 * The cacheerr registers are not standardized. On OCTEON, they are
1388 * 64 bits wide.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001389 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001390#define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
1391#define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001392
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001393#define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
1394#define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
1395
1396/* BMIPS3300 */
1397#define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
1398#define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
1399
1400#define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
1401#define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
1402
1403#define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
1404#define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
1405
1406/* BMIPS43xx */
1407#define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
1408#define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
1409
1410#define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
1411#define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
1412
1413#define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
1414#define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
1415
1416#define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
1417#define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
1418
1419#define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
1420#define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
1421
1422/* BMIPS5000 */
1423#define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
1424#define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
1425
1426#define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
1427#define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
1428
1429#define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
1430#define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
1431
1432#define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
1433#define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
1434
1435#define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
1436#define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
1437
1438#define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
1439#define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
1440
1441/*
1442 * Macros to access the floating point coprocessor control registers
1443 */
1444#define _read_32bit_cp1_register(source, gas_hardfloat) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001445({ \
1446 unsigned int __res; \
1447 \
1448 __asm__ __volatile__( \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001449 " .set push \n" \
1450 " .set reorder \n" \
1451 " # gas fails to assemble cfc1 for some archs, \n" \
1452 " # like Octeon. \n" \
1453 " .set mips1 \n" \
1454 " "STR(gas_hardfloat)" \n" \
1455 " cfc1 %0,"STR(source)" \n" \
1456 " .set pop \n" \
1457 : "=r" (__res)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001458 __res; \
1459})
1460
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001461#define _write_32bit_cp1_register(dest, val, gas_hardfloat) \
1462({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001463 __asm__ __volatile__( \
1464 " .set push \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001465 " .set reorder \n" \
1466 " "STR(gas_hardfloat)" \n" \
1467 " ctc1 %0,"STR(dest)" \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001468 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001469 : : "r" (val)); \
1470})
1471
1472#ifdef GAS_HAS_SET_HARDFLOAT
1473#define read_32bit_cp1_register(source) \
1474 _read_32bit_cp1_register(source, .set hardfloat)
1475#define write_32bit_cp1_register(dest, val) \
1476 _write_32bit_cp1_register(dest, val, .set hardfloat)
1477#else
1478#define read_32bit_cp1_register(source) \
1479 _read_32bit_cp1_register(source, )
1480#define write_32bit_cp1_register(dest, val) \
1481 _write_32bit_cp1_register(dest, val, )
1482#endif
1483
1484#ifdef HAVE_AS_DSP
1485#define rddsp(mask) \
1486({ \
1487 unsigned int __dspctl; \
1488 \
1489 __asm__ __volatile__( \
1490 " .set push \n" \
1491 " .set dsp \n" \
1492 " rddsp %0, %x1 \n" \
1493 " .set pop \n" \
1494 : "=r" (__dspctl) \
1495 : "i" (mask)); \
1496 __dspctl; \
1497})
1498
1499#define wrdsp(val, mask) \
1500({ \
1501 __asm__ __volatile__( \
1502 " .set push \n" \
1503 " .set dsp \n" \
1504 " wrdsp %0, %x1 \n" \
1505 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001506 : \
1507 : "r" (val), "i" (mask)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001508})
1509
1510#define mflo0() \
1511({ \
1512 long mflo0; \
1513 __asm__( \
1514 " .set push \n" \
1515 " .set dsp \n" \
1516 " mflo %0, $ac0 \n" \
1517 " .set pop \n" \
1518 : "=r" (mflo0)); \
1519 mflo0; \
1520})
1521
1522#define mflo1() \
1523({ \
1524 long mflo1; \
1525 __asm__( \
1526 " .set push \n" \
1527 " .set dsp \n" \
1528 " mflo %0, $ac1 \n" \
1529 " .set pop \n" \
1530 : "=r" (mflo1)); \
1531 mflo1; \
1532})
1533
1534#define mflo2() \
1535({ \
1536 long mflo2; \
1537 __asm__( \
1538 " .set push \n" \
1539 " .set dsp \n" \
1540 " mflo %0, $ac2 \n" \
1541 " .set pop \n" \
1542 : "=r" (mflo2)); \
1543 mflo2; \
1544})
1545
1546#define mflo3() \
1547({ \
1548 long mflo3; \
1549 __asm__( \
1550 " .set push \n" \
1551 " .set dsp \n" \
1552 " mflo %0, $ac3 \n" \
1553 " .set pop \n" \
1554 : "=r" (mflo3)); \
1555 mflo3; \
1556})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001557
1558#define mfhi0() \
1559({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001560 long mfhi0; \
1561 __asm__( \
1562 " .set push \n" \
1563 " .set dsp \n" \
1564 " mfhi %0, $ac0 \n" \
1565 " .set pop \n" \
1566 : "=r" (mfhi0)); \
1567 mfhi0; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001568})
1569
1570#define mfhi1() \
1571({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001572 long mfhi1; \
1573 __asm__( \
1574 " .set push \n" \
1575 " .set dsp \n" \
1576 " mfhi %0, $ac1 \n" \
1577 " .set pop \n" \
1578 : "=r" (mfhi1)); \
1579 mfhi1; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001580})
1581
1582#define mfhi2() \
1583({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001584 long mfhi2; \
1585 __asm__( \
1586 " .set push \n" \
1587 " .set dsp \n" \
1588 " mfhi %0, $ac2 \n" \
1589 " .set pop \n" \
1590 : "=r" (mfhi2)); \
1591 mfhi2; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001592})
1593
1594#define mfhi3() \
1595({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001596 long mfhi3; \
1597 __asm__( \
1598 " .set push \n" \
1599 " .set dsp \n" \
1600 " mfhi %0, $ac3 \n" \
1601 " .set pop \n" \
1602 : "=r" (mfhi3)); \
1603 mfhi3; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001604})
1605
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001606
1607#define mtlo0(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001608({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001609 __asm__( \
1610 " .set push \n" \
1611 " .set dsp \n" \
1612 " mtlo %0, $ac0 \n" \
1613 " .set pop \n" \
1614 : \
1615 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001616})
1617
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001618#define mtlo1(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001619({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001620 __asm__( \
1621 " .set push \n" \
1622 " .set dsp \n" \
1623 " mtlo %0, $ac1 \n" \
1624 " .set pop \n" \
1625 : \
1626 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001627})
1628
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001629#define mtlo2(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001630({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001631 __asm__( \
1632 " .set push \n" \
1633 " .set dsp \n" \
1634 " mtlo %0, $ac2 \n" \
1635 " .set pop \n" \
1636 : \
1637 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001638})
1639
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001640#define mtlo3(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001641({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001642 __asm__( \
1643 " .set push \n" \
1644 " .set dsp \n" \
1645 " mtlo %0, $ac3 \n" \
1646 " .set pop \n" \
1647 : \
1648 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001649})
1650
1651#define mthi0(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001652({ \
1653 __asm__( \
1654 " .set push \n" \
1655 " .set dsp \n" \
1656 " mthi %0, $ac0 \n" \
1657 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001658 : \
1659 : "r" (x)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001660})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001661
1662#define mthi1(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001663({ \
1664 __asm__( \
1665 " .set push \n" \
1666 " .set dsp \n" \
1667 " mthi %0, $ac1 \n" \
1668 " .set pop \n" \
1669 : \
1670 : "r" (x)); \
1671})
1672
1673#define mthi2(x) \
1674({ \
1675 __asm__( \
1676 " .set push \n" \
1677 " .set dsp \n" \
1678 " mthi %0, $ac2 \n" \
1679 " .set pop \n" \
1680 : \
1681 : "r" (x)); \
1682})
1683
1684#define mthi3(x) \
1685({ \
1686 __asm__( \
1687 " .set push \n" \
1688 " .set dsp \n" \
1689 " mthi %0, $ac3 \n" \
1690 " .set pop \n" \
1691 : \
1692 : "r" (x)); \
1693})
1694
1695#else
1696
1697#ifdef CONFIG_CPU_MICROMIPS
1698#define rddsp(mask) \
1699({ \
1700 unsigned int __res; \
1701 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001702 __asm__ __volatile__( \
1703 " .set push \n" \
1704 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001705 " # rddsp $1, %x1 \n" \
1706 " .hword ((0x0020067c | (%x1 << 14)) >> 16) \n" \
1707 " .hword ((0x0020067c | (%x1 << 14)) & 0xffff) \n" \
1708 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001709 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001710 : "=r" (__res) \
1711 : "i" (mask)); \
1712 __res; \
1713})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001714
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001715#define wrdsp(val, mask) \
1716({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001717 __asm__ __volatile__( \
1718 " .set push \n" \
1719 " .set noat \n" \
1720 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001721 " # wrdsp $1, %x1 \n" \
1722 " .hword ((0x0020167c | (%x1 << 14)) >> 16) \n" \
1723 " .hword ((0x0020167c | (%x1 << 14)) & 0xffff) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001724 " .set pop \n" \
1725 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001726 : "r" (val), "i" (mask)); \
1727})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001728
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001729#define _umips_dsp_mfxxx(ins) \
1730({ \
1731 unsigned long __treg; \
1732 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001733 __asm__ __volatile__( \
1734 " .set push \n" \
1735 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001736 " .hword 0x0001 \n" \
1737 " .hword %x1 \n" \
1738 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001739 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001740 : "=r" (__treg) \
1741 : "i" (ins)); \
1742 __treg; \
1743})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001744
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001745#define _umips_dsp_mtxxx(val, ins) \
1746({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001747 __asm__ __volatile__( \
1748 " .set push \n" \
1749 " .set noat \n" \
1750 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001751 " .hword 0x0001 \n" \
1752 " .hword %x1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001753 " .set pop \n" \
1754 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001755 : "r" (val), "i" (ins)); \
1756})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001757
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001758#define _umips_dsp_mflo(reg) _umips_dsp_mfxxx((reg << 14) | 0x107c)
1759#define _umips_dsp_mfhi(reg) _umips_dsp_mfxxx((reg << 14) | 0x007c)
1760
1761#define _umips_dsp_mtlo(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x307c))
1762#define _umips_dsp_mthi(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x207c))
1763
1764#define mflo0() _umips_dsp_mflo(0)
1765#define mflo1() _umips_dsp_mflo(1)
1766#define mflo2() _umips_dsp_mflo(2)
1767#define mflo3() _umips_dsp_mflo(3)
1768
1769#define mfhi0() _umips_dsp_mfhi(0)
1770#define mfhi1() _umips_dsp_mfhi(1)
1771#define mfhi2() _umips_dsp_mfhi(2)
1772#define mfhi3() _umips_dsp_mfhi(3)
1773
1774#define mtlo0(x) _umips_dsp_mtlo(x, 0)
1775#define mtlo1(x) _umips_dsp_mtlo(x, 1)
1776#define mtlo2(x) _umips_dsp_mtlo(x, 2)
1777#define mtlo3(x) _umips_dsp_mtlo(x, 3)
1778
1779#define mthi0(x) _umips_dsp_mthi(x, 0)
1780#define mthi1(x) _umips_dsp_mthi(x, 1)
1781#define mthi2(x) _umips_dsp_mthi(x, 2)
1782#define mthi3(x) _umips_dsp_mthi(x, 3)
1783
1784#else /* !CONFIG_CPU_MICROMIPS */
1785#define rddsp(mask) \
1786({ \
1787 unsigned int __res; \
1788 \
1789 __asm__ __volatile__( \
1790 " .set push \n" \
1791 " .set noat \n" \
1792 " # rddsp $1, %x1 \n" \
1793 " .word 0x7c000cb8 | (%x1 << 16) \n" \
1794 " move %0, $1 \n" \
1795 " .set pop \n" \
1796 : "=r" (__res) \
1797 : "i" (mask)); \
1798 __res; \
1799})
1800
1801#define wrdsp(val, mask) \
1802({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001803 __asm__ __volatile__( \
1804 " .set push \n" \
1805 " .set noat \n" \
1806 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001807 " # wrdsp $1, %x1 \n" \
1808 " .word 0x7c2004f8 | (%x1 << 11) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001809 " .set pop \n" \
1810 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001811 : "r" (val), "i" (mask)); \
1812})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001813
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001814#define _dsp_mfxxx(ins) \
1815({ \
1816 unsigned long __treg; \
1817 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001818 __asm__ __volatile__( \
1819 " .set push \n" \
1820 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001821 " .word (0x00000810 | %1) \n" \
1822 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001823 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001824 : "=r" (__treg) \
1825 : "i" (ins)); \
1826 __treg; \
1827})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001828
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001829#define _dsp_mtxxx(val, ins) \
1830({ \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001831 __asm__ __volatile__( \
1832 " .set push \n" \
1833 " .set noat \n" \
1834 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001835 " .word (0x00200011 | %1) \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001836 " .set pop \n" \
1837 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001838 : "r" (val), "i" (ins)); \
1839})
1840
1841#define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
1842#define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
1843
1844#define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
1845#define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
1846
1847#define mflo0() _dsp_mflo(0)
1848#define mflo1() _dsp_mflo(1)
1849#define mflo2() _dsp_mflo(2)
1850#define mflo3() _dsp_mflo(3)
1851
1852#define mfhi0() _dsp_mfhi(0)
1853#define mfhi1() _dsp_mfhi(1)
1854#define mfhi2() _dsp_mfhi(2)
1855#define mfhi3() _dsp_mfhi(3)
1856
1857#define mtlo0(x) _dsp_mtlo(x, 0)
1858#define mtlo1(x) _dsp_mtlo(x, 1)
1859#define mtlo2(x) _dsp_mtlo(x, 2)
1860#define mtlo3(x) _dsp_mtlo(x, 3)
1861
1862#define mthi0(x) _dsp_mthi(x, 0)
1863#define mthi1(x) _dsp_mthi(x, 1)
1864#define mthi2(x) _dsp_mthi(x, 2)
1865#define mthi3(x) _dsp_mthi(x, 3)
1866
1867#endif /* CONFIG_CPU_MICROMIPS */
1868#endif
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001869
1870/*
1871 * TLB operations.
1872 *
1873 * It is responsibility of the caller to take care of any TLB hazards.
1874 */
1875static inline void tlb_probe(void)
1876{
1877 __asm__ __volatile__(
1878 ".set noreorder\n\t"
1879 "tlbp\n\t"
1880 ".set reorder");
1881}
1882
1883static inline void tlb_read(void)
1884{
1885#if MIPS34K_MISSED_ITLB_WAR
1886 int res = 0;
1887
1888 __asm__ __volatile__(
1889 " .set push \n"
1890 " .set noreorder \n"
1891 " .set noat \n"
1892 " .set mips32r2 \n"
1893 " .word 0x41610001 # dvpe $1 \n"
1894 " move %0, $1 \n"
1895 " ehb \n"
1896 " .set pop \n"
1897 : "=r" (res));
1898
1899 instruction_hazard();
1900#endif
1901
1902 __asm__ __volatile__(
1903 ".set noreorder\n\t"
1904 "tlbr\n\t"
1905 ".set reorder");
1906
1907#if MIPS34K_MISSED_ITLB_WAR
1908 if ((res & _ULCAST_(1)))
1909 __asm__ __volatile__(
1910 " .set push \n"
1911 " .set noreorder \n"
1912 " .set noat \n"
1913 " .set mips32r2 \n"
1914 " .word 0x41600021 # evpe \n"
1915 " ehb \n"
1916 " .set pop \n");
1917#endif
1918}
1919
1920static inline void tlb_write_indexed(void)
1921{
1922 __asm__ __volatile__(
1923 ".set noreorder\n\t"
1924 "tlbwi\n\t"
1925 ".set reorder");
1926}
1927
1928static inline void tlb_write_random(void)
1929{
1930 __asm__ __volatile__(
1931 ".set noreorder\n\t"
1932 "tlbwr\n\t"
1933 ".set reorder");
1934}
1935
1936/*
1937 * Manipulate bits in a c0 register.
1938 */
1939#define __BUILD_SET_C0(name) \
1940static inline unsigned int \
1941set_c0_##name(unsigned int set) \
1942{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001943 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001944 \
1945 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001946 new = res | set; \
1947 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001948 \
1949 return res; \
1950} \
1951 \
1952static inline unsigned int \
1953clear_c0_##name(unsigned int clear) \
1954{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001955 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001956 \
1957 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001958 new = res & ~clear; \
1959 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001960 \
1961 return res; \
1962} \
1963 \
1964static inline unsigned int \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001965change_c0_##name(unsigned int change, unsigned int val) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001966{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001967 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001968 \
1969 res = read_c0_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001970 new = res & ~change; \
1971 new |= (val & change); \
1972 write_c0_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001973 \
1974 return res; \
1975}
1976
1977__BUILD_SET_C0(status)
1978__BUILD_SET_C0(cause)
1979__BUILD_SET_C0(config)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001980__BUILD_SET_C0(config5)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001981__BUILD_SET_C0(intcontrol)
1982__BUILD_SET_C0(intctl)
1983__BUILD_SET_C0(srsmap)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001984__BUILD_SET_C0(pagegrain)
1985__BUILD_SET_C0(brcm_config_0)
1986__BUILD_SET_C0(brcm_bus_pll)
1987__BUILD_SET_C0(brcm_reset)
1988__BUILD_SET_C0(brcm_cmt_intr)
1989__BUILD_SET_C0(brcm_cmt_ctrl)
1990__BUILD_SET_C0(brcm_config)
1991__BUILD_SET_C0(brcm_mode)
1992
1993/*
1994 * Return low 10 bits of ebase.
1995 * Note that under KVM (MIPSVZ) this returns vcpu id.
1996 */
1997static inline unsigned int get_ebase_cpunum(void)
1998{
1999 return read_c0_ebase() & 0x3ff;
2000}
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002001
Gregory CLEMENTe869d792018-12-14 16:16:45 +01002002static inline void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0,
2003 u32 low1)
2004{
2005 write_c0_entrylo0(low0);
2006 write_c0_pagemask(pagemask);
2007 write_c0_entrylo1(low1);
2008 write_c0_entryhi(hi);
2009 write_c0_index(index);
2010 tlb_write_indexed();
2011}
2012
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002013#endif /* !__ASSEMBLY__ */
2014
wdenk4fc95692003-02-28 00:49:47 +00002015#endif /* _ASM_MIPSREGS_H */