blob: d02b1e50bdf0b922befd224ee8f2d0b935cc1108 [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
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020013#include <asm/compiler.h>
14#include <asm/isa-rev.h>
wdenk4fc95692003-02-28 00:49:47 +000015/*
16 * The following macros are especially useful for __asm__
17 * inline assembler.
18 */
19#ifndef __STR
20#define __STR(x) #x
21#endif
22#ifndef STR
23#define STR(x) __STR(x)
24#endif
25
26/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090027 * Configure language
28 */
29#ifdef __ASSEMBLY__
30#define _ULCAST_
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020031#define _U64CAST_
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090032#else
33#define _ULCAST_ (unsigned long)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020034#define _U64CAST_ (u64)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090035#endif
36
37/*
wdenk4fc95692003-02-28 00:49:47 +000038 * Coprocessor 0 register names
39 */
40#define CP0_INDEX $0
41#define CP0_RANDOM $1
42#define CP0_ENTRYLO0 $2
43#define CP0_ENTRYLO1 $3
44#define CP0_CONF $3
Paul Burtonfcdc1fb2016-09-21 14:59:54 +010045#define CP0_GLOBALNUMBER $3, 1
wdenk4fc95692003-02-28 00:49:47 +000046#define CP0_CONTEXT $4
47#define CP0_PAGEMASK $5
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020048#define CP0_PAGEGRAIN $5, 1
49#define CP0_SEGCTL0 $5, 2
50#define CP0_SEGCTL1 $5, 3
51#define CP0_SEGCTL2 $5, 4
wdenk4fc95692003-02-28 00:49:47 +000052#define CP0_WIRED $6
53#define CP0_INFO $7
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020054#define CP0_HWRENA $7
wdenk4fc95692003-02-28 00:49:47 +000055#define CP0_BADVADDR $8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010056#define CP0_BADINSTR $8, 1
wdenk4fc95692003-02-28 00:49:47 +000057#define CP0_COUNT $9
58#define CP0_ENTRYHI $10
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020059#define CP0_GUESTCTL1 $10, 4
60#define CP0_GUESTCTL2 $10, 5
61#define CP0_GUESTCTL3 $10, 6
wdenk4fc95692003-02-28 00:49:47 +000062#define CP0_COMPARE $11
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020063#define CP0_GUESTCTL0EXT $11, 4
wdenk4fc95692003-02-28 00:49:47 +000064#define CP0_STATUS $12
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020065#define CP0_GUESTCTL0 $12, 6
66#define CP0_GTOFFSET $12, 7
wdenk4fc95692003-02-28 00:49:47 +000067#define CP0_CAUSE $13
68#define CP0_EPC $14
69#define CP0_PRID $15
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010070#define CP0_EBASE $15, 1
71#define CP0_CMGCRBASE $15, 3
wdenk4fc95692003-02-28 00:49:47 +000072#define CP0_CONFIG $16
Daniel Schwierzecka6dae712016-01-12 21:48:26 +010073#define CP0_CONFIG3 $16, 3
74#define CP0_CONFIG5 $16, 5
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +020075#define CP0_CONFIG6 $16, 6
wdenk4fc95692003-02-28 00:49:47 +000076#define CP0_LLADDR $17
77#define CP0_WATCHLO $18
78#define CP0_WATCHHI $19
79#define CP0_XCONTEXT $20
80#define CP0_FRAMEMASK $21
81#define CP0_DIAGNOSTIC $22
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090082#define CP0_DEBUG $23
83#define CP0_DEPC $24
wdenk4fc95692003-02-28 00:49:47 +000084#define CP0_PERFORMANCE $25
85#define CP0_ECC $26
86#define CP0_CACHEERR $27
87#define CP0_TAGLO $28
88#define CP0_TAGHI $29
89#define CP0_ERROREPC $30
Shinya Kuribayashi179f9742008-05-30 00:53:38 +090090#define CP0_DESAVE $31
wdenk4fc95692003-02-28 00:49:47 +000091
92/*
93 * R4640/R4650 cp0 register names. These registers are listed
94 * here only for completeness; without MMU these CPUs are not useable
95 * by Linux. A future ELKS port might take make Linux run on them
96 * though ...
97 */
98#define CP0_IBASE $0
99#define CP0_IBOUND $1
100#define CP0_DBASE $2
101#define CP0_DBOUND $3
102#define CP0_CALG $17
103#define CP0_IWATCH $18
104#define CP0_DWATCH $19
105
wdenk57b2d802003-06-27 21:31:46 +0000106/*
wdenk4fc95692003-02-28 00:49:47 +0000107 * Coprocessor 0 Set 1 register names
108 */
109#define CP0_S1_DERRADDR0 $26
110#define CP0_S1_DERRADDR1 $27
111#define CP0_S1_INTCONTROL $20
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900112
113/*
114 * Coprocessor 0 Set 2 register names
115 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100116#define CP0_S2_SRSCTL $12 /* MIPSR2 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900117
118/*
119 * Coprocessor 0 Set 3 register names
120 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100121#define CP0_S3_SRSMAP $12 /* MIPSR2 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900122
123/*
124 * TX39 Series
125 */
126#define CP0_TX39_CACHE $7
127
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100128/* Generic EntryLo bit definitions */
129#define ENTRYLO_G (_ULCAST_(1) << 0)
130#define ENTRYLO_V (_ULCAST_(1) << 1)
131#define ENTRYLO_D (_ULCAST_(1) << 2)
132#define ENTRYLO_C_SHIFT 3
133#define ENTRYLO_C (_ULCAST_(7) << ENTRYLO_C_SHIFT)
wdenk4fc95692003-02-28 00:49:47 +0000134
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100135/* R3000 EntryLo bit definitions */
136#define R3K_ENTRYLO_G (_ULCAST_(1) << 8)
137#define R3K_ENTRYLO_V (_ULCAST_(1) << 9)
138#define R3K_ENTRYLO_D (_ULCAST_(1) << 10)
139#define R3K_ENTRYLO_N (_ULCAST_(1) << 11)
wdenk4fc95692003-02-28 00:49:47 +0000140
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100141/* MIPS32/64 EntryLo bit definitions */
142#define MIPS_ENTRYLO_PFN_SHIFT 6
143#define MIPS_ENTRYLO_XI (_ULCAST_(1) << (BITS_PER_LONG - 2))
144#define MIPS_ENTRYLO_RI (_ULCAST_(1) << (BITS_PER_LONG - 1))
wdenk4fc95692003-02-28 00:49:47 +0000145
146/*
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200147 * MIPSr6+ GlobalNumber register definitions
148 */
149#define MIPS_GLOBALNUMBER_VP_SHF 0
150#define MIPS_GLOBALNUMBER_VP (_ULCAST_(0xff) << MIPS_GLOBALNUMBER_VP_SHF)
151#define MIPS_GLOBALNUMBER_CORE_SHF 8
152#define MIPS_GLOBALNUMBER_CORE (_ULCAST_(0xff) << MIPS_GLOBALNUMBER_CORE_SHF)
153#define MIPS_GLOBALNUMBER_CLUSTER_SHF 16
154#define MIPS_GLOBALNUMBER_CLUSTER (_ULCAST_(0xf) << MIPS_GLOBALNUMBER_CLUSTER_SHF)
155
156/*
wdenk4fc95692003-02-28 00:49:47 +0000157 * Values for PageMask register
158 */
wdenk4fc95692003-02-28 00:49:47 +0000159#ifdef CONFIG_CPU_VR41XX
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900160
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900161/* Why doesn't stupidity hurt ... */
162
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900163#define PM_1K 0x00000000
164#define PM_4K 0x00001800
165#define PM_16K 0x00007800
166#define PM_64K 0x0001f800
167#define PM_256K 0x0007f800
168
wdenk4fc95692003-02-28 00:49:47 +0000169#else
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900170
171#define PM_4K 0x00000000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100172#define PM_8K 0x00002000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900173#define PM_16K 0x00006000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100174#define PM_32K 0x0000e000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900175#define PM_64K 0x0001e000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100176#define PM_128K 0x0003e000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900177#define PM_256K 0x0007e000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100178#define PM_512K 0x000fe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900179#define PM_1M 0x001fe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100180#define PM_2M 0x003fe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900181#define PM_4M 0x007fe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100182#define PM_8M 0x00ffe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900183#define PM_16M 0x01ffe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100184#define PM_32M 0x03ffe000
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900185#define PM_64M 0x07ffe000
186#define PM_256M 0x1fffe000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100187#define PM_1G 0x7fffe000
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900188
wdenk4fc95692003-02-28 00:49:47 +0000189#endif
190
191/*
192 * Values used for computation of new tlb entries
193 */
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900194#define PL_4K 12
195#define PL_16K 14
196#define PL_64K 16
197#define PL_256K 18
198#define PL_1M 20
199#define PL_4M 22
200#define PL_16M 24
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900201#define PL_64M 26
202#define PL_256M 28
wdenk4fc95692003-02-28 00:49:47 +0000203
204/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100205 * PageGrain bits
206 */
207#define PG_RIE (_ULCAST_(1) << 31)
208#define PG_XIE (_ULCAST_(1) << 30)
209#define PG_ELPA (_ULCAST_(1) << 29)
210#define PG_ESP (_ULCAST_(1) << 28)
211#define PG_IEC (_ULCAST_(1) << 27)
212
213/* MIPS32/64 EntryHI bit definitions */
214#define MIPS_ENTRYHI_EHINV (_ULCAST_(1) << 10)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200215#define MIPS_ENTRYHI_ASIDX (_ULCAST_(0x3) << 8)
216#define MIPS_ENTRYHI_ASID (_ULCAST_(0xff) << 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100217
218/*
wdenk4fc95692003-02-28 00:49:47 +0000219 * R4x00 interrupt enable / cause bits
220 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100221#define IE_SW0 (_ULCAST_(1) << 8)
222#define IE_SW1 (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900223#define IE_IRQ0 (_ULCAST_(1) << 10)
224#define IE_IRQ1 (_ULCAST_(1) << 11)
225#define IE_IRQ2 (_ULCAST_(1) << 12)
226#define IE_IRQ3 (_ULCAST_(1) << 13)
227#define IE_IRQ4 (_ULCAST_(1) << 14)
228#define IE_IRQ5 (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000229
230/*
231 * R4x00 interrupt cause bits
232 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100233#define C_SW0 (_ULCAST_(1) << 8)
234#define C_SW1 (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900235#define C_IRQ0 (_ULCAST_(1) << 10)
236#define C_IRQ1 (_ULCAST_(1) << 11)
237#define C_IRQ2 (_ULCAST_(1) << 12)
238#define C_IRQ3 (_ULCAST_(1) << 13)
239#define C_IRQ4 (_ULCAST_(1) << 14)
240#define C_IRQ5 (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000241
wdenk4fc95692003-02-28 00:49:47 +0000242/*
243 * Bitfields in the R4xx0 cp0 status register
244 */
245#define ST0_IE 0x00000001
246#define ST0_EXL 0x00000002
247#define ST0_ERL 0x00000004
248#define ST0_KSU 0x00000018
249# define KSU_USER 0x00000010
250# define KSU_SUPERVISOR 0x00000008
251# define KSU_KERNEL 0x00000000
252#define ST0_UX 0x00000020
253#define ST0_SX 0x00000040
Wolfgang Denka1be4762008-05-20 16:00:29 +0200254#define ST0_KX 0x00000080
wdenk4fc95692003-02-28 00:49:47 +0000255#define ST0_DE 0x00010000
256#define ST0_CE 0x00020000
257
258/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900259 * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
260 * cacheops in userspace. This bit exists only on RM7000 and RM9000
261 * processors.
262 */
263#define ST0_CO 0x08000000
264
265/*
wdenk4fc95692003-02-28 00:49:47 +0000266 * Bitfields in the R[23]000 cp0 status register.
267 */
Shinya Kuribayashi43ce5b72008-05-30 00:53:37 +0900268#define ST0_IEC 0x00000001
wdenk4fc95692003-02-28 00:49:47 +0000269#define ST0_KUC 0x00000002
270#define ST0_IEP 0x00000004
271#define ST0_KUP 0x00000008
272#define ST0_IEO 0x00000010
273#define ST0_KUO 0x00000020
274/* bits 6 & 7 are reserved on R[23]000 */
275#define ST0_ISC 0x00010000
276#define ST0_SWC 0x00020000
277#define ST0_CM 0x00080000
278
279/*
280 * Bits specific to the R4640/R4650
281 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100282#define ST0_UM (_ULCAST_(1) << 4)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900283#define ST0_IL (_ULCAST_(1) << 23)
284#define ST0_DL (_ULCAST_(1) << 24)
wdenk4fc95692003-02-28 00:49:47 +0000285
286/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900287 * Enable the MIPS MDMX and DSP ASEs
288 */
289#define ST0_MX 0x01000000
290
291/*
wdenk4fc95692003-02-28 00:49:47 +0000292 * Status register bits available in all MIPS CPUs.
293 */
294#define ST0_IM 0x0000ff00
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100295#define STATUSB_IP0 8
296#define STATUSF_IP0 (_ULCAST_(1) << 8)
297#define STATUSB_IP1 9
298#define STATUSF_IP1 (_ULCAST_(1) << 9)
299#define STATUSB_IP2 10
300#define STATUSF_IP2 (_ULCAST_(1) << 10)
301#define STATUSB_IP3 11
302#define STATUSF_IP3 (_ULCAST_(1) << 11)
303#define STATUSB_IP4 12
304#define STATUSF_IP4 (_ULCAST_(1) << 12)
305#define STATUSB_IP5 13
306#define STATUSF_IP5 (_ULCAST_(1) << 13)
307#define STATUSB_IP6 14
308#define STATUSF_IP6 (_ULCAST_(1) << 14)
309#define STATUSB_IP7 15
310#define STATUSF_IP7 (_ULCAST_(1) << 15)
311#define STATUSB_IP8 0
312#define STATUSF_IP8 (_ULCAST_(1) << 0)
313#define STATUSB_IP9 1
314#define STATUSF_IP9 (_ULCAST_(1) << 1)
315#define STATUSB_IP10 2
316#define STATUSF_IP10 (_ULCAST_(1) << 2)
317#define STATUSB_IP11 3
318#define STATUSF_IP11 (_ULCAST_(1) << 3)
319#define STATUSB_IP12 4
320#define STATUSF_IP12 (_ULCAST_(1) << 4)
321#define STATUSB_IP13 5
322#define STATUSF_IP13 (_ULCAST_(1) << 5)
323#define STATUSB_IP14 6
324#define STATUSF_IP14 (_ULCAST_(1) << 6)
325#define STATUSB_IP15 7
326#define STATUSF_IP15 (_ULCAST_(1) << 7)
Daniel Schwierzeckecf0d792016-02-08 00:37:59 +0100327#define ST0_IMPL (_ULCAST_(3) << 16)
wdenk4fc95692003-02-28 00:49:47 +0000328#define ST0_CH 0x00040000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100329#define ST0_NMI 0x00080000
wdenk4fc95692003-02-28 00:49:47 +0000330#define ST0_SR 0x00100000
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900331#define ST0_TS 0x00200000
wdenk4fc95692003-02-28 00:49:47 +0000332#define ST0_BEV 0x00400000
333#define ST0_RE 0x02000000
334#define ST0_FR 0x04000000
335#define ST0_CU 0xf0000000
336#define ST0_CU0 0x10000000
337#define ST0_CU1 0x20000000
338#define ST0_CU2 0x40000000
339#define ST0_CU3 0x80000000
340#define ST0_XX 0x80000000 /* MIPS IV naming */
341
342/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100343 * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
344 */
345#define INTCTLB_IPFDC 23
346#define INTCTLF_IPFDC (_ULCAST_(7) << INTCTLB_IPFDC)
347#define INTCTLB_IPPCI 26
348#define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
349#define INTCTLB_IPTI 29
350#define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
351
352/*
wdenk4fc95692003-02-28 00:49:47 +0000353 * Bitfields and bit numbers in the coprocessor 0 cause register.
354 *
355 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
356 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100357#define CAUSEB_EXCCODE 2
358#define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
359#define CAUSEB_IP 8
360#define CAUSEF_IP (_ULCAST_(255) << 8)
361#define CAUSEB_IP0 8
362#define CAUSEF_IP0 (_ULCAST_(1) << 8)
363#define CAUSEB_IP1 9
364#define CAUSEF_IP1 (_ULCAST_(1) << 9)
365#define CAUSEB_IP2 10
366#define CAUSEF_IP2 (_ULCAST_(1) << 10)
367#define CAUSEB_IP3 11
368#define CAUSEF_IP3 (_ULCAST_(1) << 11)
369#define CAUSEB_IP4 12
370#define CAUSEF_IP4 (_ULCAST_(1) << 12)
371#define CAUSEB_IP5 13
372#define CAUSEF_IP5 (_ULCAST_(1) << 13)
373#define CAUSEB_IP6 14
374#define CAUSEF_IP6 (_ULCAST_(1) << 14)
375#define CAUSEB_IP7 15
376#define CAUSEF_IP7 (_ULCAST_(1) << 15)
377#define CAUSEB_FDCI 21
378#define CAUSEF_FDCI (_ULCAST_(1) << 21)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200379#define CAUSEB_WP 22
380#define CAUSEF_WP (_ULCAST_(1) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100381#define CAUSEB_IV 23
382#define CAUSEF_IV (_ULCAST_(1) << 23)
383#define CAUSEB_PCI 26
384#define CAUSEF_PCI (_ULCAST_(1) << 26)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200385#define CAUSEB_DC 27
386#define CAUSEF_DC (_ULCAST_(1) << 27)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100387#define CAUSEB_CE 28
388#define CAUSEF_CE (_ULCAST_(3) << 28)
389#define CAUSEB_TI 30
390#define CAUSEF_TI (_ULCAST_(1) << 30)
391#define CAUSEB_BD 31
392#define CAUSEF_BD (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000393
394/*
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200395 * Cause.ExcCode trap codes.
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100396 */
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200397#define EXCCODE_INT 0 /* Interrupt pending */
398#define EXCCODE_MOD 1 /* TLB modified fault */
399#define EXCCODE_TLBL 2 /* TLB miss on load or ifetch */
400#define EXCCODE_TLBS 3 /* TLB miss on a store */
401#define EXCCODE_ADEL 4 /* Address error on a load or ifetch */
402#define EXCCODE_ADES 5 /* Address error on a store */
403#define EXCCODE_IBE 6 /* Bus error on an ifetch */
404#define EXCCODE_DBE 7 /* Bus error on a load or store */
405#define EXCCODE_SYS 8 /* System call */
406#define EXCCODE_BP 9 /* Breakpoint */
407#define EXCCODE_RI 10 /* Reserved instruction exception */
408#define EXCCODE_CPU 11 /* Coprocessor unusable */
409#define EXCCODE_OV 12 /* Arithmetic overflow */
410#define EXCCODE_TR 13 /* Trap instruction */
411#define EXCCODE_MSAFPE 14 /* MSA floating point exception */
412#define EXCCODE_FPE 15 /* Floating point exception */
413#define EXCCODE_TLBRI 19 /* TLB Read-Inhibit exception */
414#define EXCCODE_TLBXI 20 /* TLB Execution-Inhibit exception */
415#define EXCCODE_MSADIS 21 /* MSA disabled exception */
416#define EXCCODE_MDMX 22 /* MDMX unusable exception */
417#define EXCCODE_WATCH 23 /* Watch address reference */
418#define EXCCODE_MCHECK 24 /* Machine check */
419#define EXCCODE_THREAD 25 /* Thread exceptions (MT) */
420#define EXCCODE_DSPDIS 26 /* DSP disabled exception */
421#define EXCCODE_GE 27 /* Virtualized guest exception (VZ) */
422
423/* Implementation specific trap codes used by MIPS cores */
424#define MIPS_EXCCODE_TLBPAR 16 /* TLB parity error exception */
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100425
426/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900427 * Bits in the coprocessor 0 config register.
wdenk4fc95692003-02-28 00:49:47 +0000428 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900429/* Generic bits. */
wdenk4fc95692003-02-28 00:49:47 +0000430#define CONF_CM_CACHABLE_NO_WA 0
431#define CONF_CM_CACHABLE_WA 1
432#define CONF_CM_UNCACHED 2
433#define CONF_CM_CACHABLE_NONCOHERENT 3
434#define CONF_CM_CACHABLE_CE 4
435#define CONF_CM_CACHABLE_COW 5
436#define CONF_CM_CACHABLE_CUW 6
437#define CONF_CM_CACHABLE_ACCELERATED 7
438#define CONF_CM_CMASK 7
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900439#define CONF_BE (_ULCAST_(1) << 15)
wdenk4fc95692003-02-28 00:49:47 +0000440
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900441/* Bits common to various processors. */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100442#define CONF_CU (_ULCAST_(1) << 3)
443#define CONF_DB (_ULCAST_(1) << 4)
444#define CONF_IB (_ULCAST_(1) << 5)
445#define CONF_DC (_ULCAST_(7) << 6)
446#define CONF_IC (_ULCAST_(7) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900447#define CONF_EB (_ULCAST_(1) << 13)
448#define CONF_EM (_ULCAST_(1) << 14)
449#define CONF_SM (_ULCAST_(1) << 16)
450#define CONF_SC (_ULCAST_(1) << 17)
451#define CONF_EW (_ULCAST_(3) << 18)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200452#define CONF_EP (_ULCAST_(15)<< 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900453#define CONF_EC (_ULCAST_(7) << 28)
454#define CONF_CM (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000455
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100456/* Bits specific to the R4xx0. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900457#define R4K_CONF_SW (_ULCAST_(1) << 20)
458#define R4K_CONF_SS (_ULCAST_(1) << 21)
459#define R4K_CONF_SB (_ULCAST_(3) << 22)
460
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100461/* Bits specific to the R5000. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900462#define R5K_CONF_SE (_ULCAST_(1) << 12)
463#define R5K_CONF_SS (_ULCAST_(3) << 20)
464
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100465/* Bits specific to the RM7000. */
466#define RM7K_CONF_SE (_ULCAST_(1) << 3)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900467#define RM7K_CONF_TE (_ULCAST_(1) << 12)
468#define RM7K_CONF_CLK (_ULCAST_(1) << 16)
469#define RM7K_CONF_TC (_ULCAST_(1) << 17)
470#define RM7K_CONF_SI (_ULCAST_(3) << 20)
471#define RM7K_CONF_SC (_ULCAST_(1) << 31)
472
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100473/* Bits specific to the R10000. */
474#define R10K_CONF_DN (_ULCAST_(3) << 3)
475#define R10K_CONF_CT (_ULCAST_(1) << 5)
476#define R10K_CONF_PE (_ULCAST_(1) << 6)
477#define R10K_CONF_PM (_ULCAST_(3) << 7)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200478#define R10K_CONF_EC (_ULCAST_(15)<< 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900479#define R10K_CONF_SB (_ULCAST_(1) << 13)
480#define R10K_CONF_SK (_ULCAST_(1) << 14)
481#define R10K_CONF_SS (_ULCAST_(7) << 16)
482#define R10K_CONF_SC (_ULCAST_(7) << 19)
483#define R10K_CONF_DC (_ULCAST_(7) << 26)
484#define R10K_CONF_IC (_ULCAST_(7) << 29)
485
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100486/* Bits specific to the VR41xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900487#define VR41_CONF_CS (_ULCAST_(1) << 12)
488#define VR41_CONF_P4K (_ULCAST_(1) << 13)
489#define VR41_CONF_BP (_ULCAST_(1) << 16)
490#define VR41_CONF_M16 (_ULCAST_(1) << 20)
491#define VR41_CONF_AD (_ULCAST_(1) << 23)
492
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100493/* Bits specific to the R30xx. */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900494#define R30XX_CONF_FDM (_ULCAST_(1) << 19)
495#define R30XX_CONF_REV (_ULCAST_(1) << 22)
496#define R30XX_CONF_AC (_ULCAST_(1) << 23)
497#define R30XX_CONF_RF (_ULCAST_(1) << 24)
498#define R30XX_CONF_HALT (_ULCAST_(1) << 25)
499#define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
500#define R30XX_CONF_DBR (_ULCAST_(1) << 29)
501#define R30XX_CONF_SB (_ULCAST_(1) << 30)
502#define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
503
504/* Bits specific to the TX49. */
505#define TX49_CONF_DC (_ULCAST_(1) << 16)
506#define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
507#define TX49_CONF_HALT (_ULCAST_(1) << 18)
508#define TX49_CONF_CWFON (_ULCAST_(1) << 27)
509
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100510/* Bits specific to the MIPS32/64 PRA. */
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200511#define MIPS_CONF_VI (_ULCAST_(1) << 3)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100512#define MIPS_CONF_MT (_ULCAST_(7) << 7)
513#define MIPS_CONF_MT_TLB (_ULCAST_(1) << 7)
514#define MIPS_CONF_MT_FTLB (_ULCAST_(4) << 7)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900515#define MIPS_CONF_AR (_ULCAST_(7) << 10)
516#define MIPS_CONF_AT (_ULCAST_(3) << 13)
Paul Burton4f5561c2016-09-21 11:18:50 +0100517#define MIPS_CONF_IMPL (_ULCAST_(0x1ff) << 16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900518#define MIPS_CONF_M (_ULCAST_(1) << 31)
wdenk4fc95692003-02-28 00:49:47 +0000519
520/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900521 * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
wdenk4fc95692003-02-28 00:49:47 +0000522 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100523#define MIPS_CONF1_FP (_ULCAST_(1) << 0)
524#define MIPS_CONF1_EP (_ULCAST_(1) << 1)
525#define MIPS_CONF1_CA (_ULCAST_(1) << 2)
526#define MIPS_CONF1_WR (_ULCAST_(1) << 3)
527#define MIPS_CONF1_PC (_ULCAST_(1) << 4)
528#define MIPS_CONF1_MD (_ULCAST_(1) << 5)
529#define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
530#define MIPS_CONF1_DA_SHF 7
531#define MIPS_CONF1_DA_SZ 3
532#define MIPS_CONF1_DA (_ULCAST_(7) << 7)
533#define MIPS_CONF1_DL_SHF 10
534#define MIPS_CONF1_DL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900535#define MIPS_CONF1_DL (_ULCAST_(7) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100536#define MIPS_CONF1_DS_SHF 13
537#define MIPS_CONF1_DS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900538#define MIPS_CONF1_DS (_ULCAST_(7) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100539#define MIPS_CONF1_IA_SHF 16
540#define MIPS_CONF1_IA_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900541#define MIPS_CONF1_IA (_ULCAST_(7) << 16)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100542#define MIPS_CONF1_IL_SHF 19
543#define MIPS_CONF1_IL_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900544#define MIPS_CONF1_IL (_ULCAST_(7) << 19)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100545#define MIPS_CONF1_IS_SHF 22
546#define MIPS_CONF1_IS_SZ 3
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900547#define MIPS_CONF1_IS (_ULCAST_(7) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100548#define MIPS_CONF1_TLBS_SHIFT (25)
549#define MIPS_CONF1_TLBS_SIZE (6)
550#define MIPS_CONF1_TLBS (_ULCAST_(63) << MIPS_CONF1_TLBS_SHIFT)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900551
Paul Burton81560782016-09-21 11:18:54 +0100552#define MIPS_CONF2_SA_SHF 0
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100553#define MIPS_CONF2_SA (_ULCAST_(15) << 0)
Paul Burton81560782016-09-21 11:18:54 +0100554#define MIPS_CONF2_SL_SHF 4
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100555#define MIPS_CONF2_SL (_ULCAST_(15) << 4)
Paul Burton81560782016-09-21 11:18:54 +0100556#define MIPS_CONF2_SS_SHF 8
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100557#define MIPS_CONF2_SS (_ULCAST_(15) << 8)
Paul Burton81560782016-09-21 11:18:54 +0100558#define MIPS_CONF2_L2B (_ULCAST_(1) << 12)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100559#define MIPS_CONF2_SU (_ULCAST_(15) << 12)
560#define MIPS_CONF2_TA (_ULCAST_(15) << 16)
561#define MIPS_CONF2_TL (_ULCAST_(15) << 20)
562#define MIPS_CONF2_TS (_ULCAST_(15) << 24)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900563#define MIPS_CONF2_TU (_ULCAST_(7) << 28)
564
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100565#define MIPS_CONF3_TL (_ULCAST_(1) << 0)
566#define MIPS_CONF3_SM (_ULCAST_(1) << 1)
567#define MIPS_CONF3_MT (_ULCAST_(1) << 2)
568#define MIPS_CONF3_CDMM (_ULCAST_(1) << 3)
569#define MIPS_CONF3_SP (_ULCAST_(1) << 4)
570#define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
571#define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
572#define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
573#define MIPS_CONF3_ITL (_ULCAST_(1) << 8)
574#define MIPS_CONF3_CTXTC (_ULCAST_(1) << 9)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900575#define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100576#define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
577#define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900578#define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100579#define MIPS_CONF3_ISA (_ULCAST_(3) << 14)
580#define MIPS_CONF3_ISA_OE (_ULCAST_(1) << 16)
581#define MIPS_CONF3_MCU (_ULCAST_(1) << 17)
582#define MIPS_CONF3_MMAR (_ULCAST_(7) << 18)
583#define MIPS_CONF3_IPLW (_ULCAST_(3) << 21)
584#define MIPS_CONF3_VZ (_ULCAST_(1) << 23)
585#define MIPS_CONF3_PW (_ULCAST_(1) << 24)
586#define MIPS_CONF3_SC (_ULCAST_(1) << 25)
587#define MIPS_CONF3_BI (_ULCAST_(1) << 26)
588#define MIPS_CONF3_BP (_ULCAST_(1) << 27)
589#define MIPS_CONF3_MSA (_ULCAST_(1) << 28)
590#define MIPS_CONF3_CMGCR (_ULCAST_(1) << 29)
591#define MIPS_CONF3_BPG (_ULCAST_(1) << 30)
592
593#define MIPS_CONF4_MMUSIZEEXT_SHIFT (0)
594#define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
595#define MIPS_CONF4_FTLBSETS_SHIFT (0)
596#define MIPS_CONF4_FTLBSETS (_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
597#define MIPS_CONF4_FTLBWAYS_SHIFT (4)
598#define MIPS_CONF4_FTLBWAYS (_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
599#define MIPS_CONF4_FTLBPAGESIZE_SHIFT (8)
600/* bits 10:8 in FTLB-only configurations */
601#define MIPS_CONF4_FTLBPAGESIZE (_ULCAST_(7) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
602/* bits 12:8 in VTLB-FTLB only configurations */
603#define MIPS_CONF4_VFTLBPAGESIZE (_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
604#define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
605#define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
606#define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT (_ULCAST_(2) << 14)
607#define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT (_ULCAST_(3) << 14)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200608#define MIPS_CONF4_KSCREXIST_SHIFT (16)
609#define MIPS_CONF4_KSCREXIST (_ULCAST_(255) << MIPS_CONF4_KSCREXIST_SHIFT)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100610#define MIPS_CONF4_VTLBSIZEEXT_SHIFT (24)
611#define MIPS_CONF4_VTLBSIZEEXT (_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
612#define MIPS_CONF4_AE (_ULCAST_(1) << 28)
613#define MIPS_CONF4_IE (_ULCAST_(3) << 29)
614#define MIPS_CONF4_TLBINV (_ULCAST_(2) << 29)
615
616#define MIPS_CONF5_NF (_ULCAST_(1) << 0)
617#define MIPS_CONF5_UFR (_ULCAST_(1) << 2)
618#define MIPS_CONF5_MRP (_ULCAST_(1) << 3)
619#define MIPS_CONF5_LLB (_ULCAST_(1) << 4)
620#define MIPS_CONF5_MVH (_ULCAST_(1) << 5)
Paul Burtonfcdc1fb2016-09-21 14:59:54 +0100621#define MIPS_CONF5_VP (_ULCAST_(1) << 7)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200622#define MIPS_CONF5_SBRI (_ULCAST_(1) << 6)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100623#define MIPS_CONF5_FRE (_ULCAST_(1) << 8)
624#define MIPS_CONF5_UFE (_ULCAST_(1) << 9)
Paul Burton81560782016-09-21 11:18:54 +0100625#define MIPS_CONF5_L2C (_ULCAST_(1) << 10)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200626#define MIPS_CONF5_CA2 (_ULCAST_(1) << 14)
627#define MIPS_CONF5_MI (_ULCAST_(1) << 17)
628#define MIPS_CONF5_CRCP (_ULCAST_(1) << 18)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100629#define MIPS_CONF5_MSAEN (_ULCAST_(1) << 27)
630#define MIPS_CONF5_EVA (_ULCAST_(1) << 28)
631#define MIPS_CONF5_CV (_ULCAST_(1) << 29)
632#define MIPS_CONF5_K (_ULCAST_(1) << 30)
633
634#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
635/* proAptiv FTLB on/off bit */
636#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200637/* Loongson-3 FTLB on/off bit */
638#define MIPS_CONF6_FTLBDIS (_ULCAST_(1) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100639/* FTLB probability bits */
640#define MIPS_CONF6_FTLBP_SHIFT (16)
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900641
642#define MIPS_CONF7_WII (_ULCAST_(1) << 31)
643
644#define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
wdenk4fc95692003-02-28 00:49:47 +0000645
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100646#define MIPS_CONF7_IAR (_ULCAST_(1) << 10)
647#define MIPS_CONF7_AR (_ULCAST_(1) << 16)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200648
649/* Ingenic HPTLB off bits */
650#define XBURST_PAGECTRL_HPTLB_DIS 0xa9000000
651
652/* Ingenic Config7 bits */
653#define MIPS_CONF7_BTB_LOOP_EN (_ULCAST_(1) << 4)
654
655/* Config7 Bits specific to MIPS Technologies. */
656
657/* Performance counters implemented Per TC */
658#define MTI_CONF7_PTC (_ULCAST_(1) << 19)
659
660/* WatchLo* register definitions */
661#define MIPS_WATCHLO_IRW (_ULCAST_(0x7) << 0)
662
663/* WatchHi* register definitions */
664#define MIPS_WATCHHI_M (_ULCAST_(1) << 31)
665#define MIPS_WATCHHI_G (_ULCAST_(1) << 30)
666#define MIPS_WATCHHI_WM (_ULCAST_(0x3) << 28)
667#define MIPS_WATCHHI_WM_R_RVA (_ULCAST_(0) << 28)
668#define MIPS_WATCHHI_WM_R_GPA (_ULCAST_(1) << 28)
669#define MIPS_WATCHHI_WM_G_GVA (_ULCAST_(2) << 28)
670#define MIPS_WATCHHI_EAS (_ULCAST_(0x3) << 24)
671#define MIPS_WATCHHI_ASID (_ULCAST_(0xff) << 16)
672#define MIPS_WATCHHI_MASK (_ULCAST_(0x1ff) << 3)
673#define MIPS_WATCHHI_I (_ULCAST_(1) << 2)
674#define MIPS_WATCHHI_R (_ULCAST_(1) << 1)
675#define MIPS_WATCHHI_W (_ULCAST_(1) << 0)
676#define MIPS_WATCHHI_IRW (_ULCAST_(0x7) << 0)
677
678/* PerfCnt control register definitions */
679#define MIPS_PERFCTRL_EXL (_ULCAST_(1) << 0)
680#define MIPS_PERFCTRL_K (_ULCAST_(1) << 1)
681#define MIPS_PERFCTRL_S (_ULCAST_(1) << 2)
682#define MIPS_PERFCTRL_U (_ULCAST_(1) << 3)
683#define MIPS_PERFCTRL_IE (_ULCAST_(1) << 4)
684#define MIPS_PERFCTRL_EVENT_S 5
685#define MIPS_PERFCTRL_EVENT (_ULCAST_(0x3ff) << MIPS_PERFCTRL_EVENT_S)
686#define MIPS_PERFCTRL_PCTD (_ULCAST_(1) << 15)
687#define MIPS_PERFCTRL_EC (_ULCAST_(0x3) << 23)
688#define MIPS_PERFCTRL_EC_R (_ULCAST_(0) << 23)
689#define MIPS_PERFCTRL_EC_RI (_ULCAST_(1) << 23)
690#define MIPS_PERFCTRL_EC_G (_ULCAST_(2) << 23)
691#define MIPS_PERFCTRL_EC_GRI (_ULCAST_(3) << 23)
692#define MIPS_PERFCTRL_W (_ULCAST_(1) << 30)
693#define MIPS_PERFCTRL_M (_ULCAST_(1) << 31)
694
695/* PerfCnt control register MT extensions used by MIPS cores */
696#define MIPS_PERFCTRL_VPEID_S 16
697#define MIPS_PERFCTRL_VPEID (_ULCAST_(0xf) << MIPS_PERFCTRL_VPEID_S)
698#define MIPS_PERFCTRL_TCID_S 22
699#define MIPS_PERFCTRL_TCID (_ULCAST_(0xff) << MIPS_PERFCTRL_TCID_S)
700#define MIPS_PERFCTRL_MT_EN (_ULCAST_(0x3) << 20)
701#define MIPS_PERFCTRL_MT_EN_ALL (_ULCAST_(0) << 20)
702#define MIPS_PERFCTRL_MT_EN_VPE (_ULCAST_(1) << 20)
703#define MIPS_PERFCTRL_MT_EN_TC (_ULCAST_(2) << 20)
704
705/* PerfCnt control register MT extensions used by BMIPS5000 */
706#define BRCM_PERFCTRL_TC (_ULCAST_(1) << 30)
707
708/* PerfCnt control register MT extensions used by Netlogic XLR */
709#define XLR_PERFCTRL_ALLTHREADS (_ULCAST_(1) << 13)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100710
711/* MAAR bit definitions */
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200712#define MIPS_MAAR_VH (_U64CAST_(1) << 63)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100713#define MIPS_MAAR_ADDR ((BIT_ULL(BITS_PER_LONG - 12) - 1) << 12)
714#define MIPS_MAAR_ADDR_SHIFT 12
715#define MIPS_MAAR_S (_ULCAST_(1) << 1)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200716#define MIPS_MAAR_VL (_ULCAST_(1) << 0)
717
718/* MAARI bit definitions */
719#define MIPS_MAARI_INDEX (_ULCAST_(0x3f) << 0)
720
721/* EBase bit definitions */
722#define MIPS_EBASE_CPUNUM_SHIFT 0
723#define MIPS_EBASE_CPUNUM (_ULCAST_(0x3ff) << 0)
724#define MIPS_EBASE_WG_SHIFT 11
725#define MIPS_EBASE_WG (_ULCAST_(1) << 11)
726#define MIPS_EBASE_BASE_SHIFT 12
727#define MIPS_EBASE_BASE (~_ULCAST_((1 << MIPS_EBASE_BASE_SHIFT) - 1))
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100728
729/* CMGCRBase bit definitions */
730#define MIPS_CMGCRB_BASE 11
731#define MIPS_CMGCRF_BASE (~_ULCAST_((1 << MIPS_CMGCRB_BASE) - 1))
732
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200733/* LLAddr bit definitions */
734#define MIPS_LLADDR_LLB_SHIFT 0
735#define MIPS_LLADDR_LLB (_ULCAST_(1) << MIPS_LLADDR_LLB_SHIFT)
736
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100737/*
738 * Bits in the MIPS32 Memory Segmentation registers.
739 */
740#define MIPS_SEGCFG_PA_SHIFT 9
741#define MIPS_SEGCFG_PA (_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
742#define MIPS_SEGCFG_AM_SHIFT 4
743#define MIPS_SEGCFG_AM (_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
744#define MIPS_SEGCFG_EU_SHIFT 3
745#define MIPS_SEGCFG_EU (_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
746#define MIPS_SEGCFG_C_SHIFT 0
747#define MIPS_SEGCFG_C (_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
748
749#define MIPS_SEGCFG_UUSK _ULCAST_(7)
750#define MIPS_SEGCFG_USK _ULCAST_(5)
751#define MIPS_SEGCFG_MUSUK _ULCAST_(4)
752#define MIPS_SEGCFG_MUSK _ULCAST_(3)
753#define MIPS_SEGCFG_MSK _ULCAST_(2)
754#define MIPS_SEGCFG_MK _ULCAST_(1)
755#define MIPS_SEGCFG_UK _ULCAST_(0)
756
757#define MIPS_PWFIELD_GDI_SHIFT 24
758#define MIPS_PWFIELD_GDI_MASK 0x3f000000
759#define MIPS_PWFIELD_UDI_SHIFT 18
760#define MIPS_PWFIELD_UDI_MASK 0x00fc0000
761#define MIPS_PWFIELD_MDI_SHIFT 12
762#define MIPS_PWFIELD_MDI_MASK 0x0003f000
763#define MIPS_PWFIELD_PTI_SHIFT 6
764#define MIPS_PWFIELD_PTI_MASK 0x00000fc0
765#define MIPS_PWFIELD_PTEI_SHIFT 0
766#define MIPS_PWFIELD_PTEI_MASK 0x0000003f
767
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200768#define MIPS_PWSIZE_PS_SHIFT 30
769#define MIPS_PWSIZE_PS_MASK 0x40000000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100770#define MIPS_PWSIZE_GDW_SHIFT 24
771#define MIPS_PWSIZE_GDW_MASK 0x3f000000
772#define MIPS_PWSIZE_UDW_SHIFT 18
773#define MIPS_PWSIZE_UDW_MASK 0x00fc0000
774#define MIPS_PWSIZE_MDW_SHIFT 12
775#define MIPS_PWSIZE_MDW_MASK 0x0003f000
776#define MIPS_PWSIZE_PTW_SHIFT 6
777#define MIPS_PWSIZE_PTW_MASK 0x00000fc0
778#define MIPS_PWSIZE_PTEW_SHIFT 0
779#define MIPS_PWSIZE_PTEW_MASK 0x0000003f
780
781#define MIPS_PWCTL_PWEN_SHIFT 31
782#define MIPS_PWCTL_PWEN_MASK 0x80000000
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200783#define MIPS_PWCTL_XK_SHIFT 28
784#define MIPS_PWCTL_XK_MASK 0x10000000
785#define MIPS_PWCTL_XS_SHIFT 27
786#define MIPS_PWCTL_XS_MASK 0x08000000
787#define MIPS_PWCTL_XU_SHIFT 26
788#define MIPS_PWCTL_XU_MASK 0x04000000
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100789#define MIPS_PWCTL_DPH_SHIFT 7
790#define MIPS_PWCTL_DPH_MASK 0x00000080
791#define MIPS_PWCTL_HUGEPG_SHIFT 6
792#define MIPS_PWCTL_HUGEPG_MASK 0x00000060
793#define MIPS_PWCTL_PSN_SHIFT 0
794#define MIPS_PWCTL_PSN_MASK 0x0000003f
795
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200796/* GuestCtl0 fields */
797#define MIPS_GCTL0_GM_SHIFT 31
798#define MIPS_GCTL0_GM (_ULCAST_(1) << MIPS_GCTL0_GM_SHIFT)
799#define MIPS_GCTL0_RI_SHIFT 30
800#define MIPS_GCTL0_RI (_ULCAST_(1) << MIPS_GCTL0_RI_SHIFT)
801#define MIPS_GCTL0_MC_SHIFT 29
802#define MIPS_GCTL0_MC (_ULCAST_(1) << MIPS_GCTL0_MC_SHIFT)
803#define MIPS_GCTL0_CP0_SHIFT 28
804#define MIPS_GCTL0_CP0 (_ULCAST_(1) << MIPS_GCTL0_CP0_SHIFT)
805#define MIPS_GCTL0_AT_SHIFT 26
806#define MIPS_GCTL0_AT (_ULCAST_(0x3) << MIPS_GCTL0_AT_SHIFT)
807#define MIPS_GCTL0_GT_SHIFT 25
808#define MIPS_GCTL0_GT (_ULCAST_(1) << MIPS_GCTL0_GT_SHIFT)
809#define MIPS_GCTL0_CG_SHIFT 24
810#define MIPS_GCTL0_CG (_ULCAST_(1) << MIPS_GCTL0_CG_SHIFT)
811#define MIPS_GCTL0_CF_SHIFT 23
812#define MIPS_GCTL0_CF (_ULCAST_(1) << MIPS_GCTL0_CF_SHIFT)
813#define MIPS_GCTL0_G1_SHIFT 22
814#define MIPS_GCTL0_G1 (_ULCAST_(1) << MIPS_GCTL0_G1_SHIFT)
815#define MIPS_GCTL0_G0E_SHIFT 19
816#define MIPS_GCTL0_G0E (_ULCAST_(1) << MIPS_GCTL0_G0E_SHIFT)
817#define MIPS_GCTL0_PT_SHIFT 18
818#define MIPS_GCTL0_PT (_ULCAST_(1) << MIPS_GCTL0_PT_SHIFT)
819#define MIPS_GCTL0_RAD_SHIFT 9
820#define MIPS_GCTL0_RAD (_ULCAST_(1) << MIPS_GCTL0_RAD_SHIFT)
821#define MIPS_GCTL0_DRG_SHIFT 8
822#define MIPS_GCTL0_DRG (_ULCAST_(1) << MIPS_GCTL0_DRG_SHIFT)
823#define MIPS_GCTL0_G2_SHIFT 7
824#define MIPS_GCTL0_G2 (_ULCAST_(1) << MIPS_GCTL0_G2_SHIFT)
825#define MIPS_GCTL0_GEXC_SHIFT 2
826#define MIPS_GCTL0_GEXC (_ULCAST_(0x1f) << MIPS_GCTL0_GEXC_SHIFT)
827#define MIPS_GCTL0_SFC2_SHIFT 1
828#define MIPS_GCTL0_SFC2 (_ULCAST_(1) << MIPS_GCTL0_SFC2_SHIFT)
829#define MIPS_GCTL0_SFC1_SHIFT 0
830#define MIPS_GCTL0_SFC1 (_ULCAST_(1) << MIPS_GCTL0_SFC1_SHIFT)
831
832/* GuestCtl0.AT Guest address translation control */
833#define MIPS_GCTL0_AT_ROOT 1 /* Guest MMU under Root control */
834#define MIPS_GCTL0_AT_GUEST 3 /* Guest MMU under Guest control */
835
836/* GuestCtl0.GExcCode Hypervisor exception cause codes */
837#define MIPS_GCTL0_GEXC_GPSI 0 /* Guest Privileged Sensitive Instruction */
838#define MIPS_GCTL0_GEXC_GSFC 1 /* Guest Software Field Change */
839#define MIPS_GCTL0_GEXC_HC 2 /* Hypercall */
840#define MIPS_GCTL0_GEXC_GRR 3 /* Guest Reserved Instruction Redirect */
841#define MIPS_GCTL0_GEXC_GVA 8 /* Guest Virtual Address available */
842#define MIPS_GCTL0_GEXC_GHFC 9 /* Guest Hardware Field Change */
843#define MIPS_GCTL0_GEXC_GPA 10 /* Guest Physical Address available */
844
845/* GuestCtl0Ext fields */
846#define MIPS_GCTL0EXT_RPW_SHIFT 8
847#define MIPS_GCTL0EXT_RPW (_ULCAST_(0x3) << MIPS_GCTL0EXT_RPW_SHIFT)
848#define MIPS_GCTL0EXT_NCC_SHIFT 6
849#define MIPS_GCTL0EXT_NCC (_ULCAST_(0x3) << MIPS_GCTL0EXT_NCC_SHIFT)
850#define MIPS_GCTL0EXT_CGI_SHIFT 4
851#define MIPS_GCTL0EXT_CGI (_ULCAST_(1) << MIPS_GCTL0EXT_CGI_SHIFT)
852#define MIPS_GCTL0EXT_FCD_SHIFT 3
853#define MIPS_GCTL0EXT_FCD (_ULCAST_(1) << MIPS_GCTL0EXT_FCD_SHIFT)
854#define MIPS_GCTL0EXT_OG_SHIFT 2
855#define MIPS_GCTL0EXT_OG (_ULCAST_(1) << MIPS_GCTL0EXT_OG_SHIFT)
856#define MIPS_GCTL0EXT_BG_SHIFT 1
857#define MIPS_GCTL0EXT_BG (_ULCAST_(1) << MIPS_GCTL0EXT_BG_SHIFT)
858#define MIPS_GCTL0EXT_MG_SHIFT 0
859#define MIPS_GCTL0EXT_MG (_ULCAST_(1) << MIPS_GCTL0EXT_MG_SHIFT)
860
861/* GuestCtl0Ext.RPW Root page walk configuration */
862#define MIPS_GCTL0EXT_RPW_BOTH 0 /* Root PW for GPA->RPA and RVA->RPA */
863#define MIPS_GCTL0EXT_RPW_GPA 2 /* Root PW for GPA->RPA */
864#define MIPS_GCTL0EXT_RPW_RVA 3 /* Root PW for RVA->RPA */
865
866/* GuestCtl0Ext.NCC Nested cache coherency attributes */
867#define MIPS_GCTL0EXT_NCC_IND 0 /* Guest CCA independent of Root CCA */
868#define MIPS_GCTL0EXT_NCC_MOD 1 /* Guest CCA modified by Root CCA */
869
870/* GuestCtl1 fields */
871#define MIPS_GCTL1_ID_SHIFT 0
872#define MIPS_GCTL1_ID_WIDTH 8
873#define MIPS_GCTL1_ID (_ULCAST_(0xff) << MIPS_GCTL1_ID_SHIFT)
874#define MIPS_GCTL1_RID_SHIFT 16
875#define MIPS_GCTL1_RID_WIDTH 8
876#define MIPS_GCTL1_RID (_ULCAST_(0xff) << MIPS_GCTL1_RID_SHIFT)
877#define MIPS_GCTL1_EID_SHIFT 24
878#define MIPS_GCTL1_EID_WIDTH 8
879#define MIPS_GCTL1_EID (_ULCAST_(0xff) << MIPS_GCTL1_EID_SHIFT)
880
881/* GuestID reserved for root context */
882#define MIPS_GCTL1_ROOT_GUESTID 0
883
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100884/* CDMMBase register bit definitions */
885#define MIPS_CDMMBASE_SIZE_SHIFT 0
886#define MIPS_CDMMBASE_SIZE (_ULCAST_(511) << MIPS_CDMMBASE_SIZE_SHIFT)
887#define MIPS_CDMMBASE_CI (_ULCAST_(1) << 9)
888#define MIPS_CDMMBASE_EN (_ULCAST_(1) << 10)
889#define MIPS_CDMMBASE_ADDR_SHIFT 11
890#define MIPS_CDMMBASE_ADDR_START 15
891
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200892/* RDHWR register numbers */
893#define MIPS_HWR_CPUNUM 0 /* CPU number */
894#define MIPS_HWR_SYNCISTEP 1 /* SYNCI step size */
895#define MIPS_HWR_CC 2 /* Cycle counter */
896#define MIPS_HWR_CCRES 3 /* Cycle counter resolution */
897#define MIPS_HWR_ULR 29 /* UserLocal */
898#define MIPS_HWR_IMPL1 30 /* Implementation dependent */
899#define MIPS_HWR_IMPL2 31 /* Implementation dependent */
900
901/* Bits in HWREna register */
902#define MIPS_HWRENA_CPUNUM (_ULCAST_(1) << MIPS_HWR_CPUNUM)
903#define MIPS_HWRENA_SYNCISTEP (_ULCAST_(1) << MIPS_HWR_SYNCISTEP)
904#define MIPS_HWRENA_CC (_ULCAST_(1) << MIPS_HWR_CC)
905#define MIPS_HWRENA_CCRES (_ULCAST_(1) << MIPS_HWR_CCRES)
906#define MIPS_HWRENA_ULR (_ULCAST_(1) << MIPS_HWR_ULR)
907#define MIPS_HWRENA_IMPL1 (_ULCAST_(1) << MIPS_HWR_IMPL1)
908#define MIPS_HWRENA_IMPL2 (_ULCAST_(1) << MIPS_HWR_IMPL2)
909
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100910/*
911 * Bitfields in the TX39 family CP0 Configuration Register 3
912 */
913#define TX39_CONF_ICS_SHIFT 19
914#define TX39_CONF_ICS_MASK 0x00380000
915#define TX39_CONF_ICS_1KB 0x00000000
916#define TX39_CONF_ICS_2KB 0x00080000
917#define TX39_CONF_ICS_4KB 0x00100000
918#define TX39_CONF_ICS_8KB 0x00180000
919#define TX39_CONF_ICS_16KB 0x00200000
920
921#define TX39_CONF_DCS_SHIFT 16
922#define TX39_CONF_DCS_MASK 0x00070000
923#define TX39_CONF_DCS_1KB 0x00000000
924#define TX39_CONF_DCS_2KB 0x00010000
925#define TX39_CONF_DCS_4KB 0x00020000
926#define TX39_CONF_DCS_8KB 0x00030000
927#define TX39_CONF_DCS_16KB 0x00040000
928
929#define TX39_CONF_CWFON 0x00004000
930#define TX39_CONF_WBON 0x00002000
931#define TX39_CONF_RF_SHIFT 10
932#define TX39_CONF_RF_MASK 0x00000c00
933#define TX39_CONF_DOZE 0x00000200
934#define TX39_CONF_HALT 0x00000100
935#define TX39_CONF_LOCK 0x00000080
936#define TX39_CONF_ICE 0x00000020
937#define TX39_CONF_DCE 0x00000010
938#define TX39_CONF_IRSIZE_SHIFT 2
939#define TX39_CONF_IRSIZE_MASK 0x0000000c
940#define TX39_CONF_DRSIZE_SHIFT 0
941#define TX39_CONF_DRSIZE_MASK 0x00000003
942
943/*
944 * Interesting Bits in the R10K CP0 Branch Diagnostic Register
945 */
946/* Disable Branch Target Address Cache */
947#define R10K_DIAG_D_BTAC (_ULCAST_(1) << 27)
948/* Enable Branch Prediction Global History */
949#define R10K_DIAG_E_GHIST (_ULCAST_(1) << 26)
950/* Disable Branch Return Cache */
951#define R10K_DIAG_D_BRC (_ULCAST_(1) << 22)
952
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +0200953/* Flush ITLB */
954#define LOONGSON_DIAG_ITLB (_ULCAST_(1) << 2)
955/* Flush DTLB */
956#define LOONGSON_DIAG_DTLB (_ULCAST_(1) << 3)
957/* Flush VTLB */
958#define LOONGSON_DIAG_VTLB (_ULCAST_(1) << 12)
959/* Flush FTLB */
960#define LOONGSON_DIAG_FTLB (_ULCAST_(1) << 13)
961
962/* CvmCtl register field definitions */
963#define CVMCTL_IPPCI_SHIFT 7
964#define CVMCTL_IPPCI (_U64CAST_(0x7) << CVMCTL_IPPCI_SHIFT)
965#define CVMCTL_IPTI_SHIFT 4
966#define CVMCTL_IPTI (_U64CAST_(0x7) << CVMCTL_IPTI_SHIFT)
967
968/* CvmMemCtl2 register field definitions */
969#define CVMMEMCTL2_INHIBITTS (_U64CAST_(1) << 17)
970
971/* CvmVMConfig register field definitions */
972#define CVMVMCONF_DGHT (_U64CAST_(1) << 60)
973#define CVMVMCONF_MMUSIZEM1_S 12
974#define CVMVMCONF_MMUSIZEM1 (_U64CAST_(0xff) << CVMVMCONF_MMUSIZEM1_S)
975#define CVMVMCONF_RMMUSIZEM1_S 0
976#define CVMVMCONF_RMMUSIZEM1 (_U64CAST_(0xff) << CVMVMCONF_RMMUSIZEM1_S)
977
wdenk4fc95692003-02-28 00:49:47 +0000978/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100979 * Coprocessor 1 (FPU) register names
980 */
981#define CP1_REVISION $0
982#define CP1_UFR $1
983#define CP1_UNFR $4
984#define CP1_FCCR $25
985#define CP1_FEXR $26
986#define CP1_FENR $28
987#define CP1_STATUS $31
988
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100989/*
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900990 * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
wdenk4fc95692003-02-28 00:49:47 +0000991 */
Shinya Kuribayashi179f9742008-05-30 00:53:38 +0900992#define MIPS_FPIR_S (_ULCAST_(1) << 16)
993#define MIPS_FPIR_D (_ULCAST_(1) << 17)
994#define MIPS_FPIR_PS (_ULCAST_(1) << 18)
995#define MIPS_FPIR_3D (_ULCAST_(1) << 19)
996#define MIPS_FPIR_W (_ULCAST_(1) << 20)
997#define MIPS_FPIR_L (_ULCAST_(1) << 21)
998#define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +0100999#define MIPS_FPIR_HAS2008 (_ULCAST_(1) << 23)
1000#define MIPS_FPIR_UFRP (_ULCAST_(1) << 28)
1001#define MIPS_FPIR_FREP (_ULCAST_(1) << 29)
1002
1003/*
1004 * Bits in the MIPS32/64 coprocessor 1 (FPU) condition codes register.
1005 */
1006#define MIPS_FCCR_CONDX_S 0
1007#define MIPS_FCCR_CONDX (_ULCAST_(255) << MIPS_FCCR_CONDX_S)
1008#define MIPS_FCCR_COND0_S 0
1009#define MIPS_FCCR_COND0 (_ULCAST_(1) << MIPS_FCCR_COND0_S)
1010#define MIPS_FCCR_COND1_S 1
1011#define MIPS_FCCR_COND1 (_ULCAST_(1) << MIPS_FCCR_COND1_S)
1012#define MIPS_FCCR_COND2_S 2
1013#define MIPS_FCCR_COND2 (_ULCAST_(1) << MIPS_FCCR_COND2_S)
1014#define MIPS_FCCR_COND3_S 3
1015#define MIPS_FCCR_COND3 (_ULCAST_(1) << MIPS_FCCR_COND3_S)
1016#define MIPS_FCCR_COND4_S 4
1017#define MIPS_FCCR_COND4 (_ULCAST_(1) << MIPS_FCCR_COND4_S)
1018#define MIPS_FCCR_COND5_S 5
1019#define MIPS_FCCR_COND5 (_ULCAST_(1) << MIPS_FCCR_COND5_S)
1020#define MIPS_FCCR_COND6_S 6
1021#define MIPS_FCCR_COND6 (_ULCAST_(1) << MIPS_FCCR_COND6_S)
1022#define MIPS_FCCR_COND7_S 7
1023#define MIPS_FCCR_COND7 (_ULCAST_(1) << MIPS_FCCR_COND7_S)
1024
1025/*
1026 * Bits in the MIPS32/64 coprocessor 1 (FPU) enables register.
1027 */
1028#define MIPS_FENR_FS_S 2
1029#define MIPS_FENR_FS (_ULCAST_(1) << MIPS_FENR_FS_S)
1030
1031/*
1032 * FPU Status Register Values
1033 */
1034#define FPU_CSR_COND_S 23 /* $fcc0 */
1035#define FPU_CSR_COND (_ULCAST_(1) << FPU_CSR_COND_S)
1036
1037#define FPU_CSR_FS_S 24 /* flush denormalised results to 0 */
1038#define FPU_CSR_FS (_ULCAST_(1) << FPU_CSR_FS_S)
1039
1040#define FPU_CSR_CONDX_S 25 /* $fcc[7:1] */
1041#define FPU_CSR_CONDX (_ULCAST_(127) << FPU_CSR_CONDX_S)
1042#define FPU_CSR_COND1_S 25 /* $fcc1 */
1043#define FPU_CSR_COND1 (_ULCAST_(1) << FPU_CSR_COND1_S)
1044#define FPU_CSR_COND2_S 26 /* $fcc2 */
1045#define FPU_CSR_COND2 (_ULCAST_(1) << FPU_CSR_COND2_S)
1046#define FPU_CSR_COND3_S 27 /* $fcc3 */
1047#define FPU_CSR_COND3 (_ULCAST_(1) << FPU_CSR_COND3_S)
1048#define FPU_CSR_COND4_S 28 /* $fcc4 */
1049#define FPU_CSR_COND4 (_ULCAST_(1) << FPU_CSR_COND4_S)
1050#define FPU_CSR_COND5_S 29 /* $fcc5 */
1051#define FPU_CSR_COND5 (_ULCAST_(1) << FPU_CSR_COND5_S)
1052#define FPU_CSR_COND6_S 30 /* $fcc6 */
1053#define FPU_CSR_COND6 (_ULCAST_(1) << FPU_CSR_COND6_S)
1054#define FPU_CSR_COND7_S 31 /* $fcc7 */
1055#define FPU_CSR_COND7 (_ULCAST_(1) << FPU_CSR_COND7_S)
1056
1057/*
1058 * Bits 22:20 of the FPU Status Register will be read as 0,
1059 * and should be written as zero.
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001060 * MAC2008 was removed in Release 5 so we still treat it as
1061 * reserved.
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001062 */
1063#define FPU_CSR_RSVD (_ULCAST_(7) << 20)
1064
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001065#define FPU_CSR_MAC2008 (_ULCAST_(1) << 20)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001066#define FPU_CSR_ABS2008 (_ULCAST_(1) << 19)
1067#define FPU_CSR_NAN2008 (_ULCAST_(1) << 18)
1068
1069/*
1070 * X the exception cause indicator
1071 * E the exception enable
1072 * S the sticky/flag bit
1073*/
1074#define FPU_CSR_ALL_X 0x0003f000
1075#define FPU_CSR_UNI_X 0x00020000
1076#define FPU_CSR_INV_X 0x00010000
1077#define FPU_CSR_DIV_X 0x00008000
1078#define FPU_CSR_OVF_X 0x00004000
1079#define FPU_CSR_UDF_X 0x00002000
1080#define FPU_CSR_INE_X 0x00001000
1081
1082#define FPU_CSR_ALL_E 0x00000f80
1083#define FPU_CSR_INV_E 0x00000800
1084#define FPU_CSR_DIV_E 0x00000400
1085#define FPU_CSR_OVF_E 0x00000200
1086#define FPU_CSR_UDF_E 0x00000100
1087#define FPU_CSR_INE_E 0x00000080
1088
1089#define FPU_CSR_ALL_S 0x0000007c
1090#define FPU_CSR_INV_S 0x00000040
1091#define FPU_CSR_DIV_S 0x00000020
1092#define FPU_CSR_OVF_S 0x00000010
1093#define FPU_CSR_UDF_S 0x00000008
1094#define FPU_CSR_INE_S 0x00000004
1095
1096/* Bits 0 and 1 of FPU Status Register specify the rounding mode */
1097#define FPU_CSR_RM 0x00000003
1098#define FPU_CSR_RN 0x0 /* nearest */
1099#define FPU_CSR_RZ 0x1 /* towards zero */
1100#define FPU_CSR_RU 0x2 /* towards +Infinity */
1101#define FPU_CSR_RD 0x3 /* towards -Infinity */
1102
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001103#ifndef __ASSEMBLY__
1104
1105/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001106 * Macros for handling the ISA mode bit for MIPS16 and microMIPS.
1107 */
1108#if defined(CONFIG_SYS_SUPPORTS_MIPS16) || \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001109 defined(CONFIG_SYS_SUPPORTS_MICROMIPS)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001110#define get_isa16_mode(x) ((x) & 0x1)
1111#define msk_isa16_mode(x) ((x) & ~0x1)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001112#define set_isa16_mode(x) do { (x) |= 0x1; } while(0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001113#else
1114#define get_isa16_mode(x) 0
1115#define msk_isa16_mode(x) (x)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001116#define set_isa16_mode(x) do { } while(0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001117#endif
1118
1119/*
1120 * microMIPS instructions can be 16-bit or 32-bit in length. This
1121 * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
1122 */
1123static inline int mm_insn_16bit(u16 insn)
1124{
1125 u16 opcode = (insn >> 10) & 0x7;
1126
1127 return (opcode >= 1 && opcode <= 3) ? 1 : 0;
1128}
1129
1130/*
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001131 * Helper macros for generating raw instruction encodings in inline asm.
1132 */
1133#ifdef CONFIG_CPU_MICROMIPS
1134#define _ASM_INSN16_IF_MM(_enc) \
1135 ".insn\n\t" \
1136 ".hword (" #_enc ")\n\t"
1137#define _ASM_INSN32_IF_MM(_enc) \
1138 ".insn\n\t" \
1139 ".hword ((" #_enc ") >> 16)\n\t" \
1140 ".hword ((" #_enc ") & 0xffff)\n\t"
1141#else
1142#define _ASM_INSN_IF_MIPS(_enc) \
1143 ".insn\n\t" \
1144 ".word (" #_enc ")\n\t"
1145#endif
1146
1147#ifndef _ASM_INSN16_IF_MM
1148#define _ASM_INSN16_IF_MM(_enc)
1149#endif
1150#ifndef _ASM_INSN32_IF_MM
1151#define _ASM_INSN32_IF_MM(_enc)
1152#endif
1153#ifndef _ASM_INSN_IF_MIPS
1154#define _ASM_INSN_IF_MIPS(_enc)
1155#endif
1156
1157/*
1158 * parse_r var, r - Helper assembler macro for parsing register names.
1159 *
1160 * This converts the register name in $n form provided in \r to the
1161 * corresponding register number, which is assigned to the variable \var. It is
1162 * needed to allow explicit encoding of instructions in inline assembly where
1163 * registers are chosen by the compiler in $n form, allowing us to avoid using
1164 * fixed register numbers.
1165 *
1166 * It also allows newer instructions (not implemented by the assembler) to be
1167 * transparently implemented using assembler macros, instead of needing separate
1168 * cases depending on toolchain support.
1169 *
1170 * Simple usage example:
1171 * __asm__ __volatile__("parse_r __rt, %0\n\t"
1172 * ".insn\n\t"
1173 * "# di %0\n\t"
1174 * ".word (0x41606000 | (__rt << 16))"
1175 * : "=r" (status);
1176 */
1177
1178/* Match an individual register number and assign to \var */
1179#define _IFC_REG(n) \
1180 ".ifc \\r, $" #n "\n\t" \
1181 "\\var = " #n "\n\t" \
1182 ".endif\n\t"
1183
1184__asm__(".macro parse_r var r\n\t"
1185 "\\var = -1\n\t"
1186 _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3)
1187 _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7)
1188 _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11)
1189 _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15)
1190 _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19)
1191 _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23)
1192 _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27)
1193 _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31)
1194 ".iflt \\var\n\t"
1195 ".error \"Unable to parse register name \\r\"\n\t"
1196 ".endif\n\t"
1197 ".endm");
1198
1199#undef _IFC_REG
1200
1201/*
1202 * C macros for generating assembler macros for common instruction formats.
1203 *
1204 * The names of the operands can be chosen by the caller, and the encoding of
1205 * register operand \<Rn> is assigned to __<Rn> where it can be accessed from
1206 * the ENC encodings.
1207 */
1208
1209/* Instructions with no operands */
1210#define _ASM_MACRO_0(OP, ENC) \
1211 __asm__(".macro " #OP "\n\t" \
1212 ENC \
1213 ".endm")
1214
1215/* Instructions with 1 register operand & 1 immediate operand */
1216#define _ASM_MACRO_1R1I(OP, R1, I2, ENC) \
1217 __asm__(".macro " #OP " " #R1 ", " #I2 "\n\t" \
1218 "parse_r __" #R1 ", \\" #R1 "\n\t" \
1219 ENC \
1220 ".endm")
1221
1222/* Instructions with 2 register operands */
1223#define _ASM_MACRO_2R(OP, R1, R2, ENC) \
1224 __asm__(".macro " #OP " " #R1 ", " #R2 "\n\t" \
1225 "parse_r __" #R1 ", \\" #R1 "\n\t" \
1226 "parse_r __" #R2 ", \\" #R2 "\n\t" \
1227 ENC \
1228 ".endm")
1229
1230/* Instructions with 3 register operands */
1231#define _ASM_MACRO_3R(OP, R1, R2, R3, ENC) \
1232 __asm__(".macro " #OP " " #R1 ", " #R2 ", " #R3 "\n\t" \
1233 "parse_r __" #R1 ", \\" #R1 "\n\t" \
1234 "parse_r __" #R2 ", \\" #R2 "\n\t" \
1235 "parse_r __" #R3 ", \\" #R3 "\n\t" \
1236 ENC \
1237 ".endm")
1238
1239/* Instructions with 2 register operands and 1 optional select operand */
1240#define _ASM_MACRO_2R_1S(OP, R1, R2, SEL3, ENC) \
1241 __asm__(".macro " #OP " " #R1 ", " #R2 ", " #SEL3 " = 0\n\t" \
1242 "parse_r __" #R1 ", \\" #R1 "\n\t" \
1243 "parse_r __" #R2 ", \\" #R2 "\n\t" \
1244 ENC \
1245 ".endm")
1246
1247/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001248 * TLB Invalidate Flush
1249 */
1250static inline void tlbinvf(void)
1251{
1252 __asm__ __volatile__(
1253 ".set push\n\t"
1254 ".set noreorder\n\t"
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001255 "# tlbinvf\n\t"
1256 _ASM_INSN_IF_MIPS(0x42000004)
1257 _ASM_INSN32_IF_MM(0x0000537c)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001258 ".set pop");
1259}
1260
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001261/*
1262 * Functions to access the R10000 performance counters. These are basically
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001263 * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
1264 * performance counter number encoded into bits 1 ... 5 of the instruction.
1265 * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
1266 * disassembler these will look like an access to sel 0 or 1.
1267 */
1268#define read_r10k_perf_cntr(counter) \
1269({ \
1270 unsigned int __res; \
1271 __asm__ __volatile__( \
1272 "mfpc\t%0, %1" \
1273 : "=r" (__res) \
1274 : "i" (counter)); \
1275 \
1276 __res; \
1277})
1278
1279#define write_r10k_perf_cntr(counter,val) \
1280do { \
1281 __asm__ __volatile__( \
1282 "mtpc\t%0, %1" \
1283 : \
1284 : "r" (val), "i" (counter)); \
1285} while (0)
1286
1287#define read_r10k_perf_event(counter) \
1288({ \
1289 unsigned int __res; \
1290 __asm__ __volatile__( \
1291 "mfps\t%0, %1" \
1292 : "=r" (__res) \
1293 : "i" (counter)); \
1294 \
1295 __res; \
1296})
1297
1298#define write_r10k_perf_cntl(counter,val) \
1299do { \
1300 __asm__ __volatile__( \
1301 "mtps\t%0, %1" \
1302 : \
1303 : "r" (val), "i" (counter)); \
1304} while (0)
1305
1306/*
1307 * Macros to access the system control coprocessor
1308 */
1309
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001310#define ___read_32bit_c0_register(source, sel, vol) \
Chris Packham36c624a2015-07-14 22:54:41 +12001311({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001312 if (sel == 0) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001313 __asm__ vol( \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001314 "mfc0\t%0, " #source "\n\t" \
1315 : "=r" (__res)); \
1316 else \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001317 __asm__ vol( \
1318 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001319 ".set\tmips32\n\t" \
1320 "mfc0\t%0, " #source ", " #sel "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001321 ".set\tpop\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001322 : "=r" (__res)); \
1323 __res; \
1324})
1325
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001326#define ___read_64bit_c0_register(source, sel, vol) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001327({ unsigned long long __res; \
1328 if (sizeof(unsigned long) == 4) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001329 __res = __read_64bit_c0_split(source, sel, vol); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001330 else if (sel == 0) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001331 __asm__ vol( \
1332 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001333 ".set\tmips3\n\t" \
1334 "dmfc0\t%0, " #source "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001335 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001336 : "=r" (__res)); \
1337 else \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001338 __asm__ vol( \
1339 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001340 ".set\tmips64\n\t" \
1341 "dmfc0\t%0, " #source ", " #sel "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001342 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001343 : "=r" (__res)); \
1344 __res; \
1345})
1346
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001347#define __read_32bit_c0_register(source, sel) \
1348 ___read_32bit_c0_register(source, sel, __volatile__)
1349
1350#define __read_const_32bit_c0_register(source, sel) \
1351 ___read_32bit_c0_register(source, sel,)
1352
1353#define __read_64bit_c0_register(source, sel) \
1354 ___read_64bit_c0_register(source, sel, __volatile__)
1355
1356#define __read_const_64bit_c0_register(source, sel) \
1357 ___read_64bit_c0_register(source, sel,)
1358
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001359#define __write_32bit_c0_register(register, sel, value) \
1360do { \
1361 if (sel == 0) \
1362 __asm__ __volatile__( \
1363 "mtc0\t%z0, " #register "\n\t" \
1364 : : "Jr" ((unsigned int)(value))); \
1365 else \
1366 __asm__ __volatile__( \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001367 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001368 ".set\tmips32\n\t" \
1369 "mtc0\t%z0, " #register ", " #sel "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001370 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001371 : : "Jr" ((unsigned int)(value))); \
1372} while (0)
1373
1374#define __write_64bit_c0_register(register, sel, value) \
1375do { \
1376 if (sizeof(unsigned long) == 4) \
1377 __write_64bit_c0_split(register, sel, value); \
1378 else if (sel == 0) \
1379 __asm__ __volatile__( \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001380 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001381 ".set\tmips3\n\t" \
1382 "dmtc0\t%z0, " #register "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001383 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001384 : : "Jr" (value)); \
1385 else \
1386 __asm__ __volatile__( \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001387 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001388 ".set\tmips64\n\t" \
1389 "dmtc0\t%z0, " #register ", " #sel "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001390 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001391 : : "Jr" (value)); \
1392} while (0)
1393
1394#define __read_ulong_c0_register(reg, sel) \
1395 ((sizeof(unsigned long) == 4) ? \
1396 (unsigned long) __read_32bit_c0_register(reg, sel) : \
1397 (unsigned long) __read_64bit_c0_register(reg, sel))
1398
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001399#define __read_const_ulong_c0_register(reg, sel) \
1400 ((sizeof(unsigned long) == 4) ? \
1401 (unsigned long) __read_const_32bit_c0_register(reg, sel) : \
1402 (unsigned long) __read_const_64bit_c0_register(reg, sel))
1403
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001404#define __write_ulong_c0_register(reg, sel, val) \
1405do { \
1406 if (sizeof(unsigned long) == 4) \
1407 __write_32bit_c0_register(reg, sel, val); \
1408 else \
1409 __write_64bit_c0_register(reg, sel, val); \
1410} while (0)
1411
1412/*
1413 * On RM7000/RM9000 these are uses to access cop0 set 1 registers
1414 */
1415#define __read_32bit_c0_ctrl_register(source) \
Chris Packham36c624a2015-07-14 22:54:41 +12001416({ unsigned int __res; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001417 __asm__ __volatile__( \
1418 "cfc0\t%0, " #source "\n\t" \
1419 : "=r" (__res)); \
1420 __res; \
1421})
1422
1423#define __write_32bit_c0_ctrl_register(register, value) \
1424do { \
1425 __asm__ __volatile__( \
1426 "ctc0\t%z0, " #register "\n\t" \
1427 : : "Jr" ((unsigned int)(value))); \
1428} while (0)
1429
1430/*
1431 * These versions are only needed for systems with more than 38 bits of
1432 * physical address space running the 32-bit kernel. That's none atm :-)
1433 */
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001434#define __read_64bit_c0_split(source, sel, vol) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001435({ \
1436 unsigned long long __val; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001437 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001438 if (sel == 0) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001439 __asm__ vol( \
1440 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001441 ".set\tmips64\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001442 "dmfc0\t%L0, " #source "\n\t" \
1443 "dsra\t%M0, %L0, 32\n\t" \
1444 "sll\t%L0, %L0, 0\n\t" \
1445 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001446 : "=r" (__val)); \
1447 else \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001448 __asm__ vol( \
1449 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001450 ".set\tmips64\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001451 "dmfc0\t%L0, " #source ", " #sel "\n\t" \
1452 "dsra\t%M0, %L0, 32\n\t" \
1453 "sll\t%L0, %L0, 0\n\t" \
1454 ".set\tpop" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001455 : "=r" (__val)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001456 \
1457 __val; \
1458})
1459
1460#define __write_64bit_c0_split(source, sel, val) \
1461do { \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001462 unsigned long long __tmp = (val); \
1463 if (MIPS_ISA_REV >= 2) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001464 __asm__ __volatile__( \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001465 ".set\tpush\n\t" \
1466 ".set\t" MIPS_ISA_LEVEL "\n\t" \
1467 "dins\t%L0, %M0, 32, 32\n\t" \
1468 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
1469 ".set\tpop" \
1470 : "+r" (__tmp)); \
1471 else if (sel == 0) \
1472 __asm__ __volatile__( \
1473 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001474 ".set\tmips64\n\t" \
1475 "dsll\t%L0, %L0, 32\n\t" \
1476 "dsrl\t%L0, %L0, 32\n\t" \
1477 "dsll\t%M0, %M0, 32\n\t" \
1478 "or\t%L0, %L0, %M0\n\t" \
1479 "dmtc0\t%L0, " #source "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001480 ".set\tpop" \
1481 : "+r" (__tmp)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001482 else \
1483 __asm__ __volatile__( \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001484 ".set\tpush\n\t" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001485 ".set\tmips64\n\t" \
1486 "dsll\t%L0, %L0, 32\n\t" \
1487 "dsrl\t%L0, %L0, 32\n\t" \
1488 "dsll\t%M0, %M0, 32\n\t" \
1489 "or\t%L0, %L0, %M0\n\t" \
1490 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001491 ".set\tpop" \
1492 : "+r" (__tmp)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001493} while (0)
1494
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001495#ifndef TOOLCHAIN_SUPPORTS_XPA
1496_ASM_MACRO_2R_1S(mfhc0, rt, rs, sel,
1497 _ASM_INSN_IF_MIPS(0x40400000 | __rt << 16 | __rs << 11 | \\sel)
1498 _ASM_INSN32_IF_MM(0x000000f4 | __rt << 21 | __rs << 16 | \\sel << 11));
1499_ASM_MACRO_2R_1S(mthc0, rt, rd, sel,
1500 _ASM_INSN_IF_MIPS(0x40c00000 | __rt << 16 | __rd << 11 | \\sel)
1501 _ASM_INSN32_IF_MM(0x000002f4 | __rt << 21 | __rd << 16 | \\sel << 11));
1502#define _ASM_SET_XPA ""
1503#else /* !TOOLCHAIN_SUPPORTS_XPA */
1504#define _ASM_SET_XPA ".set\txpa\n\t"
1505#endif
1506
1507#define __readx_32bit_c0_register(source, sel) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001508({ \
1509 unsigned int __res; \
1510 \
1511 __asm__ __volatile__( \
1512 " .set push \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001513 " .set mips32r2 \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001514 _ASM_SET_XPA \
1515 " mfhc0 %0, " #source ", %1 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001516 " .set pop \n" \
1517 : "=r" (__res) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001518 : "i" (sel)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001519 __res; \
1520})
1521
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001522#define __writex_32bit_c0_register(register, sel, value) \
1523do { \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001524 __asm__ __volatile__( \
1525 " .set push \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001526 " .set mips32r2 \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001527 _ASM_SET_XPA \
1528 " mthc0 %z0, " #register ", %1 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001529 " .set pop \n" \
1530 : \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001531 : "Jr" (value), "i" (sel)); \
1532} while (0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001533
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001534#define read_c0_index() __read_32bit_c0_register($0, 0)
1535#define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
1536
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001537#define read_c0_random() __read_32bit_c0_register($1, 0)
1538#define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
1539
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001540#define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
1541#define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
1542
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001543#define readx_c0_entrylo0() __readx_32bit_c0_register($2, 0)
1544#define writex_c0_entrylo0(val) __writex_32bit_c0_register($2, 0, val)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001545
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001546#define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
1547#define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
1548
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001549#define readx_c0_entrylo1() __readx_32bit_c0_register($3, 0)
1550#define writex_c0_entrylo1(val) __writex_32bit_c0_register($3, 0, val)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001551
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001552#define read_c0_conf() __read_32bit_c0_register($3, 0)
1553#define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
1554
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001555#define read_c0_globalnumber() __read_32bit_c0_register($3, 1)
1556
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001557#define read_c0_context() __read_ulong_c0_register($4, 0)
1558#define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
1559
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001560#define read_c0_contextconfig() __read_32bit_c0_register($4, 1)
1561#define write_c0_contextconfig(val) __write_32bit_c0_register($4, 1, val)
1562
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001563#define read_c0_userlocal() __read_ulong_c0_register($4, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001564#define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001565
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001566#define read_c0_xcontextconfig() __read_ulong_c0_register($4, 3)
1567#define write_c0_xcontextconfig(val) __write_ulong_c0_register($4, 3, val)
1568
1569#define read_c0_memorymapid() __read_32bit_c0_register($4, 5)
1570#define write_c0_memorymapid(val) __write_32bit_c0_register($4, 5, val)
1571
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001572#define read_c0_pagemask() __read_32bit_c0_register($5, 0)
1573#define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
1574
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001575#define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
1576#define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
1577
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001578#define read_c0_wired() __read_32bit_c0_register($6, 0)
1579#define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
1580
1581#define read_c0_info() __read_32bit_c0_register($7, 0)
1582
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001583#define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001584#define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
1585
1586#define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
1587#define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
1588
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001589#define read_c0_badinstr() __read_32bit_c0_register($8, 1)
1590#define read_c0_badinstrp() __read_32bit_c0_register($8, 2)
1591
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001592#define read_c0_count() __read_32bit_c0_register($9, 0)
1593#define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
1594
1595#define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
1596#define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
1597
1598#define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
1599#define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
1600
1601#define read_c0_entryhi() __read_ulong_c0_register($10, 0)
1602#define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
1603
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001604#define read_c0_guestctl1() __read_32bit_c0_register($10, 4)
1605#define write_c0_guestctl1(val) __write_32bit_c0_register($10, 4, val)
1606
1607#define read_c0_guestctl2() __read_32bit_c0_register($10, 5)
1608#define write_c0_guestctl2(val) __write_32bit_c0_register($10, 5, val)
1609
1610#define read_c0_guestctl3() __read_32bit_c0_register($10, 6)
1611#define write_c0_guestctl3(val) __write_32bit_c0_register($10, 6, val)
1612
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001613#define read_c0_compare() __read_32bit_c0_register($11, 0)
1614#define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
1615
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001616#define read_c0_guestctl0ext() __read_32bit_c0_register($11, 4)
1617#define write_c0_guestctl0ext(val) __write_32bit_c0_register($11, 4, val)
1618
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001619#define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
1620#define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
1621
1622#define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
1623#define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
1624
1625#define read_c0_status() __read_32bit_c0_register($12, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001626
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001627#define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001628
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001629#define read_c0_guestctl0() __read_32bit_c0_register($12, 6)
1630#define write_c0_guestctl0(val) __write_32bit_c0_register($12, 6, val)
1631
1632#define read_c0_gtoffset() __read_32bit_c0_register($12, 7)
1633#define write_c0_gtoffset(val) __write_32bit_c0_register($12, 7, val)
1634
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001635#define read_c0_cause() __read_32bit_c0_register($13, 0)
1636#define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
1637
1638#define read_c0_epc() __read_ulong_c0_register($14, 0)
1639#define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
1640
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001641#define read_c0_prid() __read_const_32bit_c0_register($15, 0)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001642
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001643#define read_c0_cmgcrbase() __read_ulong_c0_register($15, 3)
1644
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001645#define read_c0_config() __read_32bit_c0_register($16, 0)
1646#define read_c0_config1() __read_32bit_c0_register($16, 1)
1647#define read_c0_config2() __read_32bit_c0_register($16, 2)
1648#define read_c0_config3() __read_32bit_c0_register($16, 3)
1649#define read_c0_config4() __read_32bit_c0_register($16, 4)
1650#define read_c0_config5() __read_32bit_c0_register($16, 5)
1651#define read_c0_config6() __read_32bit_c0_register($16, 6)
1652#define read_c0_config7() __read_32bit_c0_register($16, 7)
1653#define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
1654#define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
1655#define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
1656#define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
1657#define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
1658#define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
1659#define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
1660#define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
1661
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001662#define read_c0_lladdr() __read_ulong_c0_register($17, 0)
1663#define write_c0_lladdr(val) __write_ulong_c0_register($17, 0, val)
1664#define read_c0_maar() __read_ulong_c0_register($17, 1)
1665#define write_c0_maar(val) __write_ulong_c0_register($17, 1, val)
1666#define read_c0_maari() __read_32bit_c0_register($17, 2)
1667#define write_c0_maari(val) __write_32bit_c0_register($17, 2, val)
1668
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001669/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001670 * The WatchLo register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001671 */
1672#define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
1673#define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
1674#define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
1675#define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
1676#define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
1677#define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
1678#define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
1679#define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
1680#define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
1681#define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
1682#define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
1683#define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
1684#define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
1685#define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
1686#define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
1687#define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
1688
1689/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001690 * The WatchHi register. There may be up to 8 of them.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001691 */
1692#define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
1693#define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
1694#define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
1695#define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
1696#define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
1697#define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
1698#define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
1699#define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
1700
1701#define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
1702#define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
1703#define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
1704#define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
1705#define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
1706#define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
1707#define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
1708#define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
1709
1710#define read_c0_xcontext() __read_ulong_c0_register($20, 0)
1711#define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
1712
1713#define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
1714#define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
1715
1716#define read_c0_framemask() __read_32bit_c0_register($21, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001717#define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001718
1719#define read_c0_diag() __read_32bit_c0_register($22, 0)
1720#define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
1721
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001722/* R10K CP0 Branch Diagnostic register is 64bits wide */
1723#define read_c0_r10k_diag() __read_64bit_c0_register($22, 0)
1724#define write_c0_r10k_diag(val) __write_64bit_c0_register($22, 0, val)
1725
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001726#define read_c0_diag1() __read_32bit_c0_register($22, 1)
1727#define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
1728
1729#define read_c0_diag2() __read_32bit_c0_register($22, 2)
1730#define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
1731
1732#define read_c0_diag3() __read_32bit_c0_register($22, 3)
1733#define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
1734
1735#define read_c0_diag4() __read_32bit_c0_register($22, 4)
1736#define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
1737
1738#define read_c0_diag5() __read_32bit_c0_register($22, 5)
1739#define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
1740
1741#define read_c0_debug() __read_32bit_c0_register($23, 0)
1742#define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
1743
1744#define read_c0_depc() __read_ulong_c0_register($24, 0)
1745#define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
1746
1747/*
1748 * MIPS32 / MIPS64 performance counters
1749 */
1750#define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001751#define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001752#define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001753#define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
1754#define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
1755#define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001756#define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001757#define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001758#define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001759#define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
1760#define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
1761#define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001762#define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001763#define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001764#define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001765#define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
1766#define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
1767#define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001768#define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001769#define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001770#define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001771#define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
1772#define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
1773#define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001774
1775#define read_c0_ecc() __read_32bit_c0_register($26, 0)
1776#define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
1777
1778#define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001779#define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001780
1781#define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
1782
1783#define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001784#define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001785
1786#define read_c0_taglo() __read_32bit_c0_register($28, 0)
1787#define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
1788
1789#define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
1790#define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
1791
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001792#define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
1793#define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
1794
1795#define read_c0_staglo() __read_32bit_c0_register($28, 4)
1796#define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
1797
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001798#define read_c0_taghi() __read_32bit_c0_register($29, 0)
1799#define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
1800
1801#define read_c0_errorepc() __read_ulong_c0_register($30, 0)
1802#define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
1803
1804/* MIPSR2 */
1805#define read_c0_hwrena() __read_32bit_c0_register($7, 0)
1806#define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
1807
1808#define read_c0_intctl() __read_32bit_c0_register($12, 1)
1809#define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
1810
1811#define read_c0_srsctl() __read_32bit_c0_register($12, 2)
1812#define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
1813
1814#define read_c0_srsmap() __read_32bit_c0_register($12, 3)
1815#define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
1816
1817#define read_c0_ebase() __read_32bit_c0_register($15, 1)
1818#define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
1819
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001820#define read_c0_ebase_64() __read_64bit_c0_register($15, 1)
1821#define write_c0_ebase_64(val) __write_64bit_c0_register($15, 1, val)
1822
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001823#define read_c0_cdmmbase() __read_ulong_c0_register($15, 2)
1824#define write_c0_cdmmbase(val) __write_ulong_c0_register($15, 2, val)
1825
1826/* MIPSR3 */
1827#define read_c0_segctl0() __read_32bit_c0_register($5, 2)
1828#define write_c0_segctl0(val) __write_32bit_c0_register($5, 2, val)
1829
1830#define read_c0_segctl1() __read_32bit_c0_register($5, 3)
1831#define write_c0_segctl1(val) __write_32bit_c0_register($5, 3, val)
1832
1833#define read_c0_segctl2() __read_32bit_c0_register($5, 4)
1834#define write_c0_segctl2(val) __write_32bit_c0_register($5, 4, val)
1835
1836/* Hardware Page Table Walker */
1837#define read_c0_pwbase() __read_ulong_c0_register($5, 5)
1838#define write_c0_pwbase(val) __write_ulong_c0_register($5, 5, val)
1839
1840#define read_c0_pwfield() __read_ulong_c0_register($5, 6)
1841#define write_c0_pwfield(val) __write_ulong_c0_register($5, 6, val)
1842
1843#define read_c0_pwsize() __read_ulong_c0_register($5, 7)
1844#define write_c0_pwsize(val) __write_ulong_c0_register($5, 7, val)
1845
1846#define read_c0_pwctl() __read_32bit_c0_register($6, 6)
1847#define write_c0_pwctl(val) __write_32bit_c0_register($6, 6, val)
1848
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001849#define read_c0_pgd() __read_64bit_c0_register($9, 7)
1850#define write_c0_pgd(val) __write_64bit_c0_register($9, 7, val)
1851
1852#define read_c0_kpgd() __read_64bit_c0_register($31, 7)
1853#define write_c0_kpgd(val) __write_64bit_c0_register($31, 7, val)
1854
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001855/* Cavium OCTEON (cnMIPS) */
1856#define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
1857#define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
1858
1859#define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
1860#define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
1861
1862#define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
1863#define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001864
1865#define read_c0_cvmmemctl2() __read_64bit_c0_register($16, 6)
1866#define write_c0_cvmmemctl2(val) __write_64bit_c0_register($16, 6, val)
1867
1868#define read_c0_cvmvmconfig() __read_64bit_c0_register($16, 7)
1869#define write_c0_cvmvmconfig(val) __write_64bit_c0_register($16, 7, val)
1870
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001871/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001872 * The cacheerr registers are not standardized. On OCTEON, they are
1873 * 64 bits wide.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001874 */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001875#define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
1876#define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09001877
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01001878#define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
1879#define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
1880
1881/* BMIPS3300 */
1882#define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
1883#define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
1884
1885#define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
1886#define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
1887
1888#define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
1889#define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
1890
1891/* BMIPS43xx */
1892#define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
1893#define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
1894
1895#define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
1896#define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
1897
1898#define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
1899#define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
1900
1901#define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
1902#define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
1903
1904#define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
1905#define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
1906
1907/* BMIPS5000 */
1908#define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
1909#define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
1910
1911#define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
1912#define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
1913
1914#define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
1915#define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
1916
1917#define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
1918#define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
1919
1920#define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
1921#define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
1922
1923#define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
1924#define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
1925
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02001926/* Ingenic page ctrl register */
1927#define write_c0_page_ctrl(val) __write_32bit_c0_register($5, 4, val)
1928
1929/*
1930 * Macros to access the guest system control coprocessor
1931 */
1932
1933#ifndef TOOLCHAIN_SUPPORTS_VIRT
1934_ASM_MACRO_2R_1S(mfgc0, rt, rs, sel,
1935 _ASM_INSN_IF_MIPS(0x40600000 | __rt << 16 | __rs << 11 | \\sel)
1936 _ASM_INSN32_IF_MM(0x000004fc | __rt << 21 | __rs << 16 | \\sel << 11));
1937_ASM_MACRO_2R_1S(dmfgc0, rt, rs, sel,
1938 _ASM_INSN_IF_MIPS(0x40600100 | __rt << 16 | __rs << 11 | \\sel)
1939 _ASM_INSN32_IF_MM(0x580004fc | __rt << 21 | __rs << 16 | \\sel << 11));
1940_ASM_MACRO_2R_1S(mtgc0, rt, rd, sel,
1941 _ASM_INSN_IF_MIPS(0x40600200 | __rt << 16 | __rd << 11 | \\sel)
1942 _ASM_INSN32_IF_MM(0x000006fc | __rt << 21 | __rd << 16 | \\sel << 11));
1943_ASM_MACRO_2R_1S(dmtgc0, rt, rd, sel,
1944 _ASM_INSN_IF_MIPS(0x40600300 | __rt << 16 | __rd << 11 | \\sel)
1945 _ASM_INSN32_IF_MM(0x580006fc | __rt << 21 | __rd << 16 | \\sel << 11));
1946_ASM_MACRO_0(tlbgp, _ASM_INSN_IF_MIPS(0x42000010)
1947 _ASM_INSN32_IF_MM(0x0000017c));
1948_ASM_MACRO_0(tlbgr, _ASM_INSN_IF_MIPS(0x42000009)
1949 _ASM_INSN32_IF_MM(0x0000117c));
1950_ASM_MACRO_0(tlbgwi, _ASM_INSN_IF_MIPS(0x4200000a)
1951 _ASM_INSN32_IF_MM(0x0000217c));
1952_ASM_MACRO_0(tlbgwr, _ASM_INSN_IF_MIPS(0x4200000e)
1953 _ASM_INSN32_IF_MM(0x0000317c));
1954_ASM_MACRO_0(tlbginvf, _ASM_INSN_IF_MIPS(0x4200000c)
1955 _ASM_INSN32_IF_MM(0x0000517c));
1956#define _ASM_SET_VIRT ""
1957#else /* !TOOLCHAIN_SUPPORTS_VIRT */
1958#define _ASM_SET_VIRT ".set\tvirt\n\t"
1959#endif
1960
1961#define __read_32bit_gc0_register(source, sel) \
1962({ int __res; \
1963 __asm__ __volatile__( \
1964 ".set\tpush\n\t" \
1965 ".set\tmips32r2\n\t" \
1966 _ASM_SET_VIRT \
1967 "mfgc0\t%0, " #source ", %1\n\t" \
1968 ".set\tpop" \
1969 : "=r" (__res) \
1970 : "i" (sel)); \
1971 __res; \
1972})
1973
1974#define __read_64bit_gc0_register(source, sel) \
1975({ unsigned long long __res; \
1976 __asm__ __volatile__( \
1977 ".set\tpush\n\t" \
1978 ".set\tmips64r2\n\t" \
1979 _ASM_SET_VIRT \
1980 "dmfgc0\t%0, " #source ", %1\n\t" \
1981 ".set\tpop" \
1982 : "=r" (__res) \
1983 : "i" (sel)); \
1984 __res; \
1985})
1986
1987#define __write_32bit_gc0_register(register, sel, value) \
1988do { \
1989 __asm__ __volatile__( \
1990 ".set\tpush\n\t" \
1991 ".set\tmips32r2\n\t" \
1992 _ASM_SET_VIRT \
1993 "mtgc0\t%z0, " #register ", %1\n\t" \
1994 ".set\tpop" \
1995 : : "Jr" ((unsigned int)(value)), \
1996 "i" (sel)); \
1997} while (0)
1998
1999#define __write_64bit_gc0_register(register, sel, value) \
2000do { \
2001 __asm__ __volatile__( \
2002 ".set\tpush\n\t" \
2003 ".set\tmips64r2\n\t" \
2004 _ASM_SET_VIRT \
2005 "dmtgc0\t%z0, " #register ", %1\n\t" \
2006 ".set\tpop" \
2007 : : "Jr" (value), \
2008 "i" (sel)); \
2009} while (0)
2010
2011#define __read_ulong_gc0_register(reg, sel) \
2012 ((sizeof(unsigned long) == 4) ? \
2013 (unsigned long) __read_32bit_gc0_register(reg, sel) : \
2014 (unsigned long) __read_64bit_gc0_register(reg, sel))
2015
2016#define __write_ulong_gc0_register(reg, sel, val) \
2017do { \
2018 if (sizeof(unsigned long) == 4) \
2019 __write_32bit_gc0_register(reg, sel, val); \
2020 else \
2021 __write_64bit_gc0_register(reg, sel, val); \
2022} while (0)
2023
2024#define read_gc0_index() __read_32bit_gc0_register($0, 0)
2025#define write_gc0_index(val) __write_32bit_gc0_register($0, 0, val)
2026
2027#define read_gc0_entrylo0() __read_ulong_gc0_register($2, 0)
2028#define write_gc0_entrylo0(val) __write_ulong_gc0_register($2, 0, val)
2029
2030#define read_gc0_entrylo1() __read_ulong_gc0_register($3, 0)
2031#define write_gc0_entrylo1(val) __write_ulong_gc0_register($3, 0, val)
2032
2033#define read_gc0_context() __read_ulong_gc0_register($4, 0)
2034#define write_gc0_context(val) __write_ulong_gc0_register($4, 0, val)
2035
2036#define read_gc0_contextconfig() __read_32bit_gc0_register($4, 1)
2037#define write_gc0_contextconfig(val) __write_32bit_gc0_register($4, 1, val)
2038
2039#define read_gc0_userlocal() __read_ulong_gc0_register($4, 2)
2040#define write_gc0_userlocal(val) __write_ulong_gc0_register($4, 2, val)
2041
2042#define read_gc0_xcontextconfig() __read_ulong_gc0_register($4, 3)
2043#define write_gc0_xcontextconfig(val) __write_ulong_gc0_register($4, 3, val)
2044
2045#define read_gc0_pagemask() __read_32bit_gc0_register($5, 0)
2046#define write_gc0_pagemask(val) __write_32bit_gc0_register($5, 0, val)
2047
2048#define read_gc0_pagegrain() __read_32bit_gc0_register($5, 1)
2049#define write_gc0_pagegrain(val) __write_32bit_gc0_register($5, 1, val)
2050
2051#define read_gc0_segctl0() __read_ulong_gc0_register($5, 2)
2052#define write_gc0_segctl0(val) __write_ulong_gc0_register($5, 2, val)
2053
2054#define read_gc0_segctl1() __read_ulong_gc0_register($5, 3)
2055#define write_gc0_segctl1(val) __write_ulong_gc0_register($5, 3, val)
2056
2057#define read_gc0_segctl2() __read_ulong_gc0_register($5, 4)
2058#define write_gc0_segctl2(val) __write_ulong_gc0_register($5, 4, val)
2059
2060#define read_gc0_pwbase() __read_ulong_gc0_register($5, 5)
2061#define write_gc0_pwbase(val) __write_ulong_gc0_register($5, 5, val)
2062
2063#define read_gc0_pwfield() __read_ulong_gc0_register($5, 6)
2064#define write_gc0_pwfield(val) __write_ulong_gc0_register($5, 6, val)
2065
2066#define read_gc0_pwsize() __read_ulong_gc0_register($5, 7)
2067#define write_gc0_pwsize(val) __write_ulong_gc0_register($5, 7, val)
2068
2069#define read_gc0_wired() __read_32bit_gc0_register($6, 0)
2070#define write_gc0_wired(val) __write_32bit_gc0_register($6, 0, val)
2071
2072#define read_gc0_pwctl() __read_32bit_gc0_register($6, 6)
2073#define write_gc0_pwctl(val) __write_32bit_gc0_register($6, 6, val)
2074
2075#define read_gc0_hwrena() __read_32bit_gc0_register($7, 0)
2076#define write_gc0_hwrena(val) __write_32bit_gc0_register($7, 0, val)
2077
2078#define read_gc0_badvaddr() __read_ulong_gc0_register($8, 0)
2079#define write_gc0_badvaddr(val) __write_ulong_gc0_register($8, 0, val)
2080
2081#define read_gc0_badinstr() __read_32bit_gc0_register($8, 1)
2082#define write_gc0_badinstr(val) __write_32bit_gc0_register($8, 1, val)
2083
2084#define read_gc0_badinstrp() __read_32bit_gc0_register($8, 2)
2085#define write_gc0_badinstrp(val) __write_32bit_gc0_register($8, 2, val)
2086
2087#define read_gc0_count() __read_32bit_gc0_register($9, 0)
2088
2089#define read_gc0_entryhi() __read_ulong_gc0_register($10, 0)
2090#define write_gc0_entryhi(val) __write_ulong_gc0_register($10, 0, val)
2091
2092#define read_gc0_compare() __read_32bit_gc0_register($11, 0)
2093#define write_gc0_compare(val) __write_32bit_gc0_register($11, 0, val)
2094
2095#define read_gc0_status() __read_32bit_gc0_register($12, 0)
2096#define write_gc0_status(val) __write_32bit_gc0_register($12, 0, val)
2097
2098#define read_gc0_intctl() __read_32bit_gc0_register($12, 1)
2099#define write_gc0_intctl(val) __write_32bit_gc0_register($12, 1, val)
2100
2101#define read_gc0_cause() __read_32bit_gc0_register($13, 0)
2102#define write_gc0_cause(val) __write_32bit_gc0_register($13, 0, val)
2103
2104#define read_gc0_epc() __read_ulong_gc0_register($14, 0)
2105#define write_gc0_epc(val) __write_ulong_gc0_register($14, 0, val)
2106
2107#define read_gc0_prid() __read_32bit_gc0_register($15, 0)
2108
2109#define read_gc0_ebase() __read_32bit_gc0_register($15, 1)
2110#define write_gc0_ebase(val) __write_32bit_gc0_register($15, 1, val)
2111
2112#define read_gc0_ebase_64() __read_64bit_gc0_register($15, 1)
2113#define write_gc0_ebase_64(val) __write_64bit_gc0_register($15, 1, val)
2114
2115#define read_gc0_config() __read_32bit_gc0_register($16, 0)
2116#define read_gc0_config1() __read_32bit_gc0_register($16, 1)
2117#define read_gc0_config2() __read_32bit_gc0_register($16, 2)
2118#define read_gc0_config3() __read_32bit_gc0_register($16, 3)
2119#define read_gc0_config4() __read_32bit_gc0_register($16, 4)
2120#define read_gc0_config5() __read_32bit_gc0_register($16, 5)
2121#define read_gc0_config6() __read_32bit_gc0_register($16, 6)
2122#define read_gc0_config7() __read_32bit_gc0_register($16, 7)
2123#define write_gc0_config(val) __write_32bit_gc0_register($16, 0, val)
2124#define write_gc0_config1(val) __write_32bit_gc0_register($16, 1, val)
2125#define write_gc0_config2(val) __write_32bit_gc0_register($16, 2, val)
2126#define write_gc0_config3(val) __write_32bit_gc0_register($16, 3, val)
2127#define write_gc0_config4(val) __write_32bit_gc0_register($16, 4, val)
2128#define write_gc0_config5(val) __write_32bit_gc0_register($16, 5, val)
2129#define write_gc0_config6(val) __write_32bit_gc0_register($16, 6, val)
2130#define write_gc0_config7(val) __write_32bit_gc0_register($16, 7, val)
2131
2132#define read_gc0_lladdr() __read_ulong_gc0_register($17, 0)
2133#define write_gc0_lladdr(val) __write_ulong_gc0_register($17, 0, val)
2134
2135#define read_gc0_watchlo0() __read_ulong_gc0_register($18, 0)
2136#define read_gc0_watchlo1() __read_ulong_gc0_register($18, 1)
2137#define read_gc0_watchlo2() __read_ulong_gc0_register($18, 2)
2138#define read_gc0_watchlo3() __read_ulong_gc0_register($18, 3)
2139#define read_gc0_watchlo4() __read_ulong_gc0_register($18, 4)
2140#define read_gc0_watchlo5() __read_ulong_gc0_register($18, 5)
2141#define read_gc0_watchlo6() __read_ulong_gc0_register($18, 6)
2142#define read_gc0_watchlo7() __read_ulong_gc0_register($18, 7)
2143#define write_gc0_watchlo0(val) __write_ulong_gc0_register($18, 0, val)
2144#define write_gc0_watchlo1(val) __write_ulong_gc0_register($18, 1, val)
2145#define write_gc0_watchlo2(val) __write_ulong_gc0_register($18, 2, val)
2146#define write_gc0_watchlo3(val) __write_ulong_gc0_register($18, 3, val)
2147#define write_gc0_watchlo4(val) __write_ulong_gc0_register($18, 4, val)
2148#define write_gc0_watchlo5(val) __write_ulong_gc0_register($18, 5, val)
2149#define write_gc0_watchlo6(val) __write_ulong_gc0_register($18, 6, val)
2150#define write_gc0_watchlo7(val) __write_ulong_gc0_register($18, 7, val)
2151
2152#define read_gc0_watchhi0() __read_32bit_gc0_register($19, 0)
2153#define read_gc0_watchhi1() __read_32bit_gc0_register($19, 1)
2154#define read_gc0_watchhi2() __read_32bit_gc0_register($19, 2)
2155#define read_gc0_watchhi3() __read_32bit_gc0_register($19, 3)
2156#define read_gc0_watchhi4() __read_32bit_gc0_register($19, 4)
2157#define read_gc0_watchhi5() __read_32bit_gc0_register($19, 5)
2158#define read_gc0_watchhi6() __read_32bit_gc0_register($19, 6)
2159#define read_gc0_watchhi7() __read_32bit_gc0_register($19, 7)
2160#define write_gc0_watchhi0(val) __write_32bit_gc0_register($19, 0, val)
2161#define write_gc0_watchhi1(val) __write_32bit_gc0_register($19, 1, val)
2162#define write_gc0_watchhi2(val) __write_32bit_gc0_register($19, 2, val)
2163#define write_gc0_watchhi3(val) __write_32bit_gc0_register($19, 3, val)
2164#define write_gc0_watchhi4(val) __write_32bit_gc0_register($19, 4, val)
2165#define write_gc0_watchhi5(val) __write_32bit_gc0_register($19, 5, val)
2166#define write_gc0_watchhi6(val) __write_32bit_gc0_register($19, 6, val)
2167#define write_gc0_watchhi7(val) __write_32bit_gc0_register($19, 7, val)
2168
2169#define read_gc0_xcontext() __read_ulong_gc0_register($20, 0)
2170#define write_gc0_xcontext(val) __write_ulong_gc0_register($20, 0, val)
2171
2172#define read_gc0_perfctrl0() __read_32bit_gc0_register($25, 0)
2173#define write_gc0_perfctrl0(val) __write_32bit_gc0_register($25, 0, val)
2174#define read_gc0_perfcntr0() __read_32bit_gc0_register($25, 1)
2175#define write_gc0_perfcntr0(val) __write_32bit_gc0_register($25, 1, val)
2176#define read_gc0_perfcntr0_64() __read_64bit_gc0_register($25, 1)
2177#define write_gc0_perfcntr0_64(val) __write_64bit_gc0_register($25, 1, val)
2178#define read_gc0_perfctrl1() __read_32bit_gc0_register($25, 2)
2179#define write_gc0_perfctrl1(val) __write_32bit_gc0_register($25, 2, val)
2180#define read_gc0_perfcntr1() __read_32bit_gc0_register($25, 3)
2181#define write_gc0_perfcntr1(val) __write_32bit_gc0_register($25, 3, val)
2182#define read_gc0_perfcntr1_64() __read_64bit_gc0_register($25, 3)
2183#define write_gc0_perfcntr1_64(val) __write_64bit_gc0_register($25, 3, val)
2184#define read_gc0_perfctrl2() __read_32bit_gc0_register($25, 4)
2185#define write_gc0_perfctrl2(val) __write_32bit_gc0_register($25, 4, val)
2186#define read_gc0_perfcntr2() __read_32bit_gc0_register($25, 5)
2187#define write_gc0_perfcntr2(val) __write_32bit_gc0_register($25, 5, val)
2188#define read_gc0_perfcntr2_64() __read_64bit_gc0_register($25, 5)
2189#define write_gc0_perfcntr2_64(val) __write_64bit_gc0_register($25, 5, val)
2190#define read_gc0_perfctrl3() __read_32bit_gc0_register($25, 6)
2191#define write_gc0_perfctrl3(val) __write_32bit_gc0_register($25, 6, val)
2192#define read_gc0_perfcntr3() __read_32bit_gc0_register($25, 7)
2193#define write_gc0_perfcntr3(val) __write_32bit_gc0_register($25, 7, val)
2194#define read_gc0_perfcntr3_64() __read_64bit_gc0_register($25, 7)
2195#define write_gc0_perfcntr3_64(val) __write_64bit_gc0_register($25, 7, val)
2196
2197#define read_gc0_errorepc() __read_ulong_gc0_register($30, 0)
2198#define write_gc0_errorepc(val) __write_ulong_gc0_register($30, 0, val)
2199
2200#define read_gc0_kscratch1() __read_ulong_gc0_register($31, 2)
2201#define read_gc0_kscratch2() __read_ulong_gc0_register($31, 3)
2202#define read_gc0_kscratch3() __read_ulong_gc0_register($31, 4)
2203#define read_gc0_kscratch4() __read_ulong_gc0_register($31, 5)
2204#define read_gc0_kscratch5() __read_ulong_gc0_register($31, 6)
2205#define read_gc0_kscratch6() __read_ulong_gc0_register($31, 7)
2206#define write_gc0_kscratch1(val) __write_ulong_gc0_register($31, 2, val)
2207#define write_gc0_kscratch2(val) __write_ulong_gc0_register($31, 3, val)
2208#define write_gc0_kscratch3(val) __write_ulong_gc0_register($31, 4, val)
2209#define write_gc0_kscratch4(val) __write_ulong_gc0_register($31, 5, val)
2210#define write_gc0_kscratch5(val) __write_ulong_gc0_register($31, 6, val)
2211#define write_gc0_kscratch6(val) __write_ulong_gc0_register($31, 7, val)
2212
2213/* Cavium OCTEON (cnMIPS) */
2214#define read_gc0_cvmcount() __read_ulong_gc0_register($9, 6)
2215#define write_gc0_cvmcount(val) __write_ulong_gc0_register($9, 6, val)
2216
2217#define read_gc0_cvmctl() __read_64bit_gc0_register($9, 7)
2218#define write_gc0_cvmctl(val) __write_64bit_gc0_register($9, 7, val)
2219
2220#define read_gc0_cvmmemctl() __read_64bit_gc0_register($11, 7)
2221#define write_gc0_cvmmemctl(val) __write_64bit_gc0_register($11, 7, val)
2222
2223#define read_gc0_cvmmemctl2() __read_64bit_gc0_register($16, 6)
2224#define write_gc0_cvmmemctl2(val) __write_64bit_gc0_register($16, 6, val)
2225
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002226/*
2227 * Macros to access the floating point coprocessor control registers
2228 */
2229#define _read_32bit_cp1_register(source, gas_hardfloat) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002230({ \
2231 unsigned int __res; \
2232 \
2233 __asm__ __volatile__( \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002234 " .set push \n" \
2235 " .set reorder \n" \
2236 " # gas fails to assemble cfc1 for some archs, \n" \
2237 " # like Octeon. \n" \
2238 " .set mips1 \n" \
2239 " "STR(gas_hardfloat)" \n" \
2240 " cfc1 %0,"STR(source)" \n" \
2241 " .set pop \n" \
2242 : "=r" (__res)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002243 __res; \
2244})
2245
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002246#define _write_32bit_cp1_register(dest, val, gas_hardfloat) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002247do { \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002248 __asm__ __volatile__( \
2249 " .set push \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002250 " .set reorder \n" \
2251 " "STR(gas_hardfloat)" \n" \
2252 " ctc1 %0,"STR(dest)" \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002253 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002254 : : "r" (val)); \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002255} while (0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002256
2257#ifdef GAS_HAS_SET_HARDFLOAT
2258#define read_32bit_cp1_register(source) \
2259 _read_32bit_cp1_register(source, .set hardfloat)
2260#define write_32bit_cp1_register(dest, val) \
2261 _write_32bit_cp1_register(dest, val, .set hardfloat)
2262#else
2263#define read_32bit_cp1_register(source) \
2264 _read_32bit_cp1_register(source, )
2265#define write_32bit_cp1_register(dest, val) \
2266 _write_32bit_cp1_register(dest, val, )
2267#endif
2268
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002269#ifdef TOOLCHAIN_SUPPORTS_DSP
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002270#define rddsp(mask) \
2271({ \
2272 unsigned int __dspctl; \
2273 \
2274 __asm__ __volatile__( \
2275 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002276 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002277 " .set dsp \n" \
2278 " rddsp %0, %x1 \n" \
2279 " .set pop \n" \
2280 : "=r" (__dspctl) \
2281 : "i" (mask)); \
2282 __dspctl; \
2283})
2284
2285#define wrdsp(val, mask) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002286do { \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002287 __asm__ __volatile__( \
2288 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002289 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002290 " .set dsp \n" \
2291 " wrdsp %0, %x1 \n" \
2292 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002293 : \
2294 : "r" (val), "i" (mask)); \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002295} while (0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002296
2297#define mflo0() \
2298({ \
2299 long mflo0; \
2300 __asm__( \
2301 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002302 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002303 " .set dsp \n" \
2304 " mflo %0, $ac0 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002305 " .set pop \n" \
2306 : "=r" (mflo0)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002307 mflo0; \
2308})
2309
2310#define mflo1() \
2311({ \
2312 long mflo1; \
2313 __asm__( \
2314 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002315 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002316 " .set dsp \n" \
2317 " mflo %0, $ac1 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002318 " .set pop \n" \
2319 : "=r" (mflo1)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002320 mflo1; \
2321})
2322
2323#define mflo2() \
2324({ \
2325 long mflo2; \
2326 __asm__( \
2327 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002328 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002329 " .set dsp \n" \
2330 " mflo %0, $ac2 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002331 " .set pop \n" \
2332 : "=r" (mflo2)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002333 mflo2; \
2334})
2335
2336#define mflo3() \
2337({ \
2338 long mflo3; \
2339 __asm__( \
2340 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002341 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002342 " .set dsp \n" \
2343 " mflo %0, $ac3 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002344 " .set pop \n" \
2345 : "=r" (mflo3)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002346 mflo3; \
2347})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002348
2349#define mfhi0() \
2350({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002351 long mfhi0; \
2352 __asm__( \
2353 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002354 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002355 " .set dsp \n" \
2356 " mfhi %0, $ac0 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002357 " .set pop \n" \
2358 : "=r" (mfhi0)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002359 mfhi0; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002360})
2361
2362#define mfhi1() \
2363({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002364 long mfhi1; \
2365 __asm__( \
2366 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002367 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002368 " .set dsp \n" \
2369 " mfhi %0, $ac1 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002370 " .set pop \n" \
2371 : "=r" (mfhi1)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002372 mfhi1; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002373})
2374
2375#define mfhi2() \
2376({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002377 long mfhi2; \
2378 __asm__( \
2379 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002380 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002381 " .set dsp \n" \
2382 " mfhi %0, $ac2 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002383 " .set pop \n" \
2384 : "=r" (mfhi2)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002385 mfhi2; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002386})
2387
2388#define mfhi3() \
2389({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002390 long mfhi3; \
2391 __asm__( \
2392 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002393 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002394 " .set dsp \n" \
2395 " mfhi %0, $ac3 \n" \
Wolfgang Denk62fb2b42021-09-27 17:42:39 +02002396 " .set pop \n" \
2397 : "=r" (mfhi3)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002398 mfhi3; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002399})
2400
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002401#define mtlo0(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002402({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002403 __asm__( \
2404 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002405 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002406 " .set dsp \n" \
2407 " mtlo %0, $ac0 \n" \
2408 " .set pop \n" \
2409 : \
2410 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002411})
2412
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002413#define mtlo1(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002414({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002415 __asm__( \
2416 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002417 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002418 " .set dsp \n" \
2419 " mtlo %0, $ac1 \n" \
2420 " .set pop \n" \
2421 : \
2422 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002423})
2424
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002425#define mtlo2(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002426({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002427 __asm__( \
2428 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002429 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002430 " .set dsp \n" \
2431 " mtlo %0, $ac2 \n" \
2432 " .set pop \n" \
2433 : \
2434 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002435})
2436
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002437#define mtlo3(x) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002438({ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002439 __asm__( \
2440 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002441 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002442 " .set dsp \n" \
2443 " mtlo %0, $ac3 \n" \
2444 " .set pop \n" \
2445 : \
2446 : "r" (x)); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002447})
2448
2449#define mthi0(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002450({ \
2451 __asm__( \
2452 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002453 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002454 " .set dsp \n" \
2455 " mthi %0, $ac0 \n" \
2456 " .set pop \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002457 : \
2458 : "r" (x)); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002459})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002460
2461#define mthi1(x) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002462({ \
2463 __asm__( \
2464 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002465 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002466 " .set dsp \n" \
2467 " mthi %0, $ac1 \n" \
2468 " .set pop \n" \
2469 : \
2470 : "r" (x)); \
2471})
2472
2473#define mthi2(x) \
2474({ \
2475 __asm__( \
2476 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002477 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002478 " .set dsp \n" \
2479 " mthi %0, $ac2 \n" \
2480 " .set pop \n" \
2481 : \
2482 : "r" (x)); \
2483})
2484
2485#define mthi3(x) \
2486({ \
2487 __asm__( \
2488 " .set push \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002489 " .set " MIPS_ISA_LEVEL " \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002490 " .set dsp \n" \
2491 " mthi %0, $ac3 \n" \
2492 " .set pop \n" \
2493 : \
2494 : "r" (x)); \
2495})
2496
2497#else
2498
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002499#define rddsp(mask) \
2500({ \
2501 unsigned int __res; \
2502 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002503 __asm__ __volatile__( \
2504 " .set push \n" \
2505 " .set noat \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002506 " # rddsp $1, %x1 \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002507 _ASM_INSN_IF_MIPS(0x7c000cb8 | (%x1 << 16)) \
2508 _ASM_INSN32_IF_MM(0x0020067c | (%x1 << 14)) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002509 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002510 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002511 : "=r" (__res) \
2512 : "i" (mask)); \
2513 __res; \
2514})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002515
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002516#define wrdsp(val, mask) \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002517do { \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002518 __asm__ __volatile__( \
2519 " .set push \n" \
2520 " .set noat \n" \
2521 " move $1, %0 \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002522 " # wrdsp $1, %x1 \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002523 _ASM_INSN_IF_MIPS(0x7c2004f8 | (%x1 << 11)) \
2524 _ASM_INSN32_IF_MM(0x0020167c | (%x1 << 14)) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002525 " .set pop \n" \
2526 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002527 : "r" (val), "i" (mask)); \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002528} while (0)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002529
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002530#define _dsp_mfxxx(ins) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002531({ \
2532 unsigned long __treg; \
2533 \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002534 __asm__ __volatile__( \
2535 " .set push \n" \
2536 " .set noat \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002537 _ASM_INSN_IF_MIPS(0x00000810 | %X1) \
2538 _ASM_INSN32_IF_MM(0x0001007c | %x1) \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002539 " move %0, $1 \n" \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002540 " .set pop \n" \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002541 : "=r" (__treg) \
2542 : "i" (ins)); \
2543 __treg; \
2544})
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002545
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002546#define _dsp_mtxxx(val, ins) \
2547do { \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002548 __asm__ __volatile__( \
2549 " .set push \n" \
2550 " .set noat \n" \
2551 " move $1, %0 \n" \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002552 _ASM_INSN_IF_MIPS(0x00200011 | %X1) \
2553 _ASM_INSN32_IF_MM(0x0001207c | %x1) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002554 " .set pop \n" \
2555 : \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002556 : "r" (val), "i" (ins)); \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002557} while (0)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002558
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002559#ifdef CONFIG_CPU_MICROMIPS
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002560
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002561#define _dsp_mflo(reg) _dsp_mfxxx((reg << 14) | 0x1000)
2562#define _dsp_mfhi(reg) _dsp_mfxxx((reg << 14) | 0x0000)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002563
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002564#define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 14) | 0x1000))
2565#define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 14) | 0x0000))
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002566
2567#else /* !CONFIG_CPU_MICROMIPS */
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002568
2569#define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
2570#define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
2571
2572#define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
2573#define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
2574
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002575#endif /* CONFIG_CPU_MICROMIPS */
2576
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002577#define mflo0() _dsp_mflo(0)
2578#define mflo1() _dsp_mflo(1)
2579#define mflo2() _dsp_mflo(2)
2580#define mflo3() _dsp_mflo(3)
2581
2582#define mfhi0() _dsp_mfhi(0)
2583#define mfhi1() _dsp_mfhi(1)
2584#define mfhi2() _dsp_mfhi(2)
2585#define mfhi3() _dsp_mfhi(3)
2586
2587#define mtlo0(x) _dsp_mtlo(x, 0)
2588#define mtlo1(x) _dsp_mtlo(x, 1)
2589#define mtlo2(x) _dsp_mtlo(x, 2)
2590#define mtlo3(x) _dsp_mtlo(x, 3)
2591
2592#define mthi0(x) _dsp_mthi(x, 0)
2593#define mthi1(x) _dsp_mthi(x, 1)
2594#define mthi2(x) _dsp_mthi(x, 2)
2595#define mthi3(x) _dsp_mthi(x, 3)
2596
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002597#endif
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002598
2599/*
2600 * TLB operations.
2601 *
2602 * It is responsibility of the caller to take care of any TLB hazards.
2603 */
2604static inline void tlb_probe(void)
2605{
2606 __asm__ __volatile__(
2607 ".set noreorder\n\t"
2608 "tlbp\n\t"
2609 ".set reorder");
2610}
2611
2612static inline void tlb_read(void)
2613{
2614#if MIPS34K_MISSED_ITLB_WAR
2615 int res = 0;
2616
2617 __asm__ __volatile__(
2618 " .set push \n"
2619 " .set noreorder \n"
2620 " .set noat \n"
2621 " .set mips32r2 \n"
2622 " .word 0x41610001 # dvpe $1 \n"
2623 " move %0, $1 \n"
2624 " ehb \n"
2625 " .set pop \n"
2626 : "=r" (res));
2627
2628 instruction_hazard();
2629#endif
2630
2631 __asm__ __volatile__(
2632 ".set noreorder\n\t"
2633 "tlbr\n\t"
2634 ".set reorder");
2635
2636#if MIPS34K_MISSED_ITLB_WAR
2637 if ((res & _ULCAST_(1)))
2638 __asm__ __volatile__(
2639 " .set push \n"
2640 " .set noreorder \n"
2641 " .set noat \n"
2642 " .set mips32r2 \n"
2643 " .word 0x41600021 # evpe \n"
2644 " ehb \n"
2645 " .set pop \n");
2646#endif
2647}
2648
2649static inline void tlb_write_indexed(void)
2650{
2651 __asm__ __volatile__(
2652 ".set noreorder\n\t"
2653 "tlbwi\n\t"
2654 ".set reorder");
2655}
2656
2657static inline void tlb_write_random(void)
2658{
2659 __asm__ __volatile__(
2660 ".set noreorder\n\t"
2661 "tlbwr\n\t"
2662 ".set reorder");
2663}
2664
2665/*
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002666 * Guest TLB operations.
2667 *
2668 * It is responsibility of the caller to take care of any TLB hazards.
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002669 */
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002670static inline void guest_tlb_probe(void)
2671{
2672 __asm__ __volatile__(
2673 ".set push\n\t"
2674 ".set noreorder\n\t"
2675 _ASM_SET_VIRT
2676 "tlbgp\n\t"
2677 ".set pop");
2678}
2679
2680static inline void guest_tlb_read(void)
2681{
2682 __asm__ __volatile__(
2683 ".set push\n\t"
2684 ".set noreorder\n\t"
2685 _ASM_SET_VIRT
2686 "tlbgr\n\t"
2687 ".set pop");
2688}
2689
2690static inline void guest_tlb_write_indexed(void)
2691{
2692 __asm__ __volatile__(
2693 ".set push\n\t"
2694 ".set noreorder\n\t"
2695 _ASM_SET_VIRT
2696 "tlbgwi\n\t"
2697 ".set pop");
2698}
2699
2700static inline void guest_tlb_write_random(void)
2701{
2702 __asm__ __volatile__(
2703 ".set push\n\t"
2704 ".set noreorder\n\t"
2705 _ASM_SET_VIRT
2706 "tlbgwr\n\t"
2707 ".set pop");
2708}
2709
2710/*
2711 * Guest TLB Invalidate Flush
2712 */
2713static inline void guest_tlbinvf(void)
2714{
2715 __asm__ __volatile__(
2716 ".set push\n\t"
2717 ".set noreorder\n\t"
2718 _ASM_SET_VIRT
2719 "tlbginvf\n\t"
2720 ".set pop");
2721}
2722
2723/*
2724 * Manipulate bits in a register.
2725 */
2726#define __BUILD_SET_COMMON(name) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002727static inline unsigned int \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002728set_##name(unsigned int set) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002729{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002730 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002731 \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002732 res = read_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002733 new = res | set; \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002734 write_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002735 \
2736 return res; \
2737} \
2738 \
2739static inline unsigned int \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002740clear_##name(unsigned int clear) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002741{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002742 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002743 \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002744 res = read_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002745 new = res & ~clear; \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002746 write_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002747 \
2748 return res; \
2749} \
2750 \
2751static inline unsigned int \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002752change_##name(unsigned int change, unsigned int val) \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002753{ \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002754 unsigned int res, new; \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002755 \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002756 res = read_##name(); \
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002757 new = res & ~change; \
2758 new |= (val & change); \
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002759 write_##name(new); \
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002760 \
2761 return res; \
2762}
2763
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002764/*
2765 * Manipulate bits in a c0 register.
2766 */
2767#define __BUILD_SET_C0(name) __BUILD_SET_COMMON(c0_##name)
2768
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002769__BUILD_SET_C0(status)
2770__BUILD_SET_C0(cause)
2771__BUILD_SET_C0(config)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002772__BUILD_SET_C0(config5)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002773__BUILD_SET_C0(config7)
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002774__BUILD_SET_C0(intcontrol)
2775__BUILD_SET_C0(intctl)
2776__BUILD_SET_C0(srsmap)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002777__BUILD_SET_C0(pagegrain)
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002778__BUILD_SET_C0(guestctl0)
2779__BUILD_SET_C0(guestctl0ext)
2780__BUILD_SET_C0(guestctl1)
2781__BUILD_SET_C0(guestctl2)
2782__BUILD_SET_C0(guestctl3)
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002783__BUILD_SET_C0(brcm_config_0)
2784__BUILD_SET_C0(brcm_bus_pll)
2785__BUILD_SET_C0(brcm_reset)
2786__BUILD_SET_C0(brcm_cmt_intr)
2787__BUILD_SET_C0(brcm_cmt_ctrl)
2788__BUILD_SET_C0(brcm_config)
2789__BUILD_SET_C0(brcm_mode)
2790
2791/*
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002792 * Manipulate bits in a guest c0 register.
2793 */
2794#define __BUILD_SET_GC0(name) __BUILD_SET_COMMON(gc0_##name)
2795
2796__BUILD_SET_GC0(wired)
2797__BUILD_SET_GC0(status)
2798__BUILD_SET_GC0(cause)
2799__BUILD_SET_GC0(ebase)
2800__BUILD_SET_GC0(config1)
2801
2802/*
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002803 * Return low 10 bits of ebase.
2804 * Note that under KVM (MIPSVZ) this returns vcpu id.
2805 */
2806static inline unsigned int get_ebase_cpunum(void)
2807{
Daniel Schwierzecke4ccb472020-07-12 01:46:18 +02002808 return read_c0_ebase() & MIPS_EBASE_CPUNUM;
Daniel Schwierzecka6dae712016-01-12 21:48:26 +01002809}
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002810
Gregory CLEMENTe869d792018-12-14 16:16:45 +01002811static inline void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0,
2812 u32 low1)
2813{
2814 write_c0_entrylo0(low0);
2815 write_c0_pagemask(pagemask);
2816 write_c0_entrylo1(low1);
2817 write_c0_entryhi(hi);
2818 write_c0_index(index);
2819 tlb_write_indexed();
2820}
2821
Shinya Kuribayashi0fdd27e2008-05-30 00:53:38 +09002822#endif /* !__ASSEMBLY__ */
2823
wdenk4fc95692003-02-28 00:49:47 +00002824#endif /* _ASM_MIPSREGS_H */