2 * HND Run Time Environment for standalone MIPS programs.
4 * Copyright 2006, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: mipsinc.h,v 1.1.1.5 2006/02/27 03:43:16 honor Exp $
21 #ifdef _LANGUAGE_ASSEMBLY
24 * Symbolic register names for 32 bit ABI
26 #define zero $0 /* wired zero */
27 #define AT $1 /* assembler temp - uppercase because of ".set at" */
28 #define v0 $2 /* return value */
30 #define a0 $4 /* argument registers */
34 #define t0 $8 /* caller saved */
42 #define s0 $16 /* callee saved */
50 #define t8 $24 /* caller saved */
52 #define jp $25 /* PIC jump register */
53 #define k0 $26 /* kernel scratch */
55 #define gp $28 /* global pointer */
56 #define sp $29 /* stack pointer */
57 #define fp $30 /* frame pointer */
58 #define s8 $30 /* same like fp! */
59 #define ra $31 /* return address */
67 #define C0_TLBLO C0_TLBLO0
72 #define C0_BADVADDR $8
75 #define C0_COMPARE $11
77 #define C0_STATUS C0_SR
83 #define C0_WATCHLO $18
84 #define C0_WATCHHI $19
86 #define C0_DIAGNOSTIC $22
87 #define C0_BROADCOM C0_DIAGNOSTIC
88 #define C0_PERFORMANCE $25
90 #define C0_CACHEERR $27
97 * LEAF - declare leaf routine
99 #define LEAF(symbol) \
102 .type symbol, @function; \
104 symbol: .frame sp, 0, ra
107 * END - mark end of function
109 #define END(function) \
111 .size function, . - function
115 #define MFC0_SEL(dst, src, sel) \
116 .word\t(0x40000000 | ((dst) << 16) | ((src) << 11) | (sel))
119 #define MTC0_SEL(dst, src, sel) \
120 .word\t(0x40800000 | ((dst) << 16) | ((src) << 11) | (sel))
125 * The following macros are especially useful for __asm__
132 #define STR(x) __STR(x)
135 #define _ULCAST_ (unsigned long)
140 #define C0_INX 0 /* CP0: TLB Index */
141 #define C0_RAND 1 /* CP0: TLB Random */
142 #define C0_TLBLO0 2 /* CP0: TLB EntryLo0 */
143 #define C0_TLBLO C0_TLBLO0 /* CP0: TLB EntryLo0 */
144 #define C0_TLBLO1 3 /* CP0: TLB EntryLo1 */
145 #define C0_CTEXT 4 /* CP0: Context */
146 #define C0_PGMASK 5 /* CP0: TLB PageMask */
147 #define C0_WIRED 6 /* CP0: TLB Wired */
148 #define C0_BADVADDR 8 /* CP0: Bad Virtual Address */
149 #define C0_COUNT 9 /* CP0: Count */
150 #define C0_TLBHI 10 /* CP0: TLB EntryHi */
151 #define C0_COMPARE 11 /* CP0: Compare */
152 #define C0_SR 12 /* CP0: Processor Status */
153 #define C0_STATUS C0_SR /* CP0: Processor Status */
154 #define C0_CAUSE 13 /* CP0: Exception Cause */
155 #define C0_EPC 14 /* CP0: Exception PC */
156 #define C0_PRID 15 /* CP0: Processor Revision Indentifier */
157 #define C0_CONFIG 16 /* CP0: Config */
158 #define C0_LLADDR 17 /* CP0: LLAddr */
159 #define C0_WATCHLO 18 /* CP0: WatchpointLo */
160 #define C0_WATCHHI 19 /* CP0: WatchpointHi */
161 #define C0_XCTEXT 20 /* CP0: XContext */
162 #define C0_DIAGNOSTIC 22 /* CP0: Diagnostic */
163 #define C0_BROADCOM C0_DIAGNOSTIC /* CP0: Broadcom Register */
164 #define C0_PERFORMANCE 25 /* CP0: Performance Counter/Control Registers */
165 #define C0_ECC 26 /* CP0: ECC */
166 #define C0_CACHEERR 27 /* CP0: CacheErr */
167 #define C0_TAGLO 28 /* CP0: TagLo */
168 #define C0_TAGHI 29 /* CP0: TagHi */
169 #define C0_ERREPC 30 /* CP0: ErrorEPC */
170 #define C0_DESAVE 31 /* CP0: DebugSave */
172 #endif /* _LANGUAGE_ASSEMBLY */
175 * Memory segments (32bit kernel mode addresses)
182 #define KUSEG 0x00000000
183 #define KSEG0 0x80000000
184 #define KSEG1 0xa0000000
185 #define KSEG2 0xc0000000
186 #define KSEG3 0xe0000000
187 #define PHYSADDR_MASK 0x1fffffff
190 * Map an address to a certain kernel segment
198 #define PHYSADDR(a) (_ULCAST_(a) & PHYSADDR_MASK)
199 #define KSEG0ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG0)
200 #define KSEG1ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG1)
201 #define KSEG2ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG2)
202 #define KSEG3ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG3)
205 #ifndef Index_Invalidate_I
209 #define Index_Invalidate_I 0x00
210 #define Index_Writeback_Inv_D 0x01
211 #define Index_Invalidate_SI 0x02
212 #define Index_Writeback_Inv_SD 0x03
213 #define Index_Load_Tag_I 0x04
214 #define Index_Load_Tag_D 0x05
215 #define Index_Load_Tag_SI 0x06
216 #define Index_Load_Tag_SD 0x07
217 #define Index_Store_Tag_I 0x08
218 #define Index_Store_Tag_D 0x09
219 #define Index_Store_Tag_SI 0x0A
220 #define Index_Store_Tag_SD 0x0B
221 #define Create_Dirty_Excl_D 0x0d
222 #define Create_Dirty_Excl_SD 0x0f
223 #define Hit_Invalidate_I 0x10
224 #define Hit_Invalidate_D 0x11
225 #define Hit_Invalidate_SI 0x12
226 #define Hit_Invalidate_SD 0x13
228 #define Hit_Writeback_Inv_D 0x15
230 #define Hit_Writeback_Inv_SD 0x17
231 #define R5K_Page_Invalidate_S 0x17
232 #define Hit_Writeback_I 0x18
233 #define Hit_Writeback_D 0x19
235 #define Hit_Writeback_SD 0x1b
238 #define Hit_Set_Virtual_SI 0x1e
239 #define Hit_Set_Virtual_SD 0x1f
240 #endif /* !Index_Invalidate_I */
244 * R4x00 interrupt enable / cause bits
246 #define IE_SW0 (_ULCAST_(1) << 8)
247 #define IE_SW1 (_ULCAST_(1) << 9)
248 #define IE_IRQ0 (_ULCAST_(1) << 10)
249 #define IE_IRQ1 (_ULCAST_(1) << 11)
250 #define IE_IRQ2 (_ULCAST_(1) << 12)
251 #define IE_IRQ3 (_ULCAST_(1) << 13)
252 #define IE_IRQ4 (_ULCAST_(1) << 14)
253 #define IE_IRQ5 (_ULCAST_(1) << 15)
257 * Bitfields in the mips32 cp0 status register
259 #define ST0_IE 0x00000001
260 #define ST0_EXL 0x00000002
261 #define ST0_ERL 0x00000004
262 #define ST0_UM 0x00000010
263 #define ST0_SWINT0 0x00000100
264 #define ST0_SWINT1 0x00000200
265 #define ST0_HWINT0 0x00000400
266 #define ST0_HWINT1 0x00000800
267 #define ST0_HWINT2 0x00001000
268 #define ST0_HWINT3 0x00002000
269 #define ST0_HWINT4 0x00004000
270 #define ST0_HWINT5 0x00008000
271 #define ST0_IM 0x0000ff00
272 #define ST0_NMI 0x00080000
273 #define ST0_SR 0x00100000
274 #define ST0_TS 0x00200000
275 #define ST0_BEV 0x00400000
276 #define ST0_RE 0x02000000
277 #define ST0_RP 0x08000000
278 #define ST0_CU 0xf0000000
279 #define ST0_CU0 0x10000000
280 #define ST0_CU1 0x20000000
281 #define ST0_CU2 0x40000000
282 #define ST0_CU3 0x80000000
287 * Bitfields in the mips32 cp0 cause register
289 #define C_EXC 0x0000007c
290 #define C_EXC_SHIFT 2
291 #define C_INT 0x0000ff00
292 #define C_INT_SHIFT 8
293 #define C_SW0 (_ULCAST_(1) << 8)
294 #define C_SW1 (_ULCAST_(1) << 9)
295 #define C_IRQ0 (_ULCAST_(1) << 10)
296 #define C_IRQ1 (_ULCAST_(1) << 11)
297 #define C_IRQ2 (_ULCAST_(1) << 12)
298 #define C_IRQ3 (_ULCAST_(1) << 13)
299 #define C_IRQ4 (_ULCAST_(1) << 14)
300 #define C_IRQ5 (_ULCAST_(1) << 15)
301 #define C_WP 0x00400000
302 #define C_IV 0x00800000
303 #define C_CE 0x30000000
304 #define C_CE_SHIFT 28
305 #define C_BD 0x80000000
307 /* Values in C_EXC */
327 * Bits in the cp0 config register.
329 #define CONF_CM_CACHABLE_NO_WA 0
330 #define CONF_CM_CACHABLE_WA 1
331 #define CONF_CM_UNCACHED 2
332 #define CONF_CM_CACHABLE_NONCOHERENT 3
333 #define CONF_CM_CACHABLE_CE 4
334 #define CONF_CM_CACHABLE_COW 5
335 #define CONF_CM_CACHABLE_CUW 6
336 #define CONF_CM_CACHABLE_ACCELERATED 7
337 #define CONF_CM_CMASK 7
338 #define CONF_CU (_ULCAST_(1) << 3)
339 #define CONF_DB (_ULCAST_(1) << 4)
340 #define CONF_IB (_ULCAST_(1) << 5)
341 #define CONF_SE (_ULCAST_(1) << 12)
342 #ifndef CONF_BE /* duplicate in mipsregs.h */
343 #define CONF_BE (_ULCAST_(1) << 15)
345 #define CONF_SC (_ULCAST_(1) << 17)
346 #define CONF_AC (_ULCAST_(1) << 23)
347 #define CONF_HALT (_ULCAST_(1) << 25)
348 #ifndef CONF_M /* duplicate in mipsregs.h */
349 #define CONF_M (_ULCAST_(1) << 31)
354 * Bits in the cp0 config register select 1.
356 #define CONF1_FP 0x00000001 /* FPU present */
357 #define CONF1_EP 0x00000002 /* EJTAG present */
358 #define CONF1_CA 0x00000004 /* mips16 implemented */
359 #define CONF1_WR 0x00000008 /* Watch registers present */
360 #define CONF1_PC 0x00000010 /* Performance counters present */
361 #define CONF1_DA_SHIFT 7 /* D$ associativity */
362 #define CONF1_DA_MASK 0x00000380
363 #define CONF1_DA_BASE 1
364 #define CONF1_DL_SHIFT 10 /* D$ line size */
365 #define CONF1_DL_MASK 0x00001c00
366 #define CONF1_DL_BASE 2
367 #define CONF1_DS_SHIFT 13 /* D$ sets/way */
368 #define CONF1_DS_MASK 0x0000e000
369 #define CONF1_DS_BASE 64
370 #define CONF1_IA_SHIFT 16 /* I$ associativity */
371 #define CONF1_IA_MASK 0x00070000
372 #define CONF1_IA_BASE 1
373 #define CONF1_IL_SHIFT 19 /* I$ line size */
374 #define CONF1_IL_MASK 0x00380000
375 #define CONF1_IL_BASE 2
376 #define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
377 #define CONF1_IS_MASK 0x01c00000
378 #define CONF1_IS_BASE 64
379 #define CONF1_MS_MASK 0x7e000000 /* Number of tlb entries */
380 #define CONF1_MS_SHIFT 25
383 #define PRID_COPT_MASK 0xff000000
384 #define PRID_COMP_MASK 0x00ff0000
385 #define PRID_IMP_MASK 0x0000ff00
386 #define PRID_REV_MASK 0x000000ff
388 #define PRID_COMP_LEGACY 0x000000
389 #define PRID_COMP_MIPS 0x010000
390 #define PRID_COMP_BROADCOM 0x020000
391 #define PRID_COMP_ALCHEMY 0x030000
392 #define PRID_COMP_SIBYTE 0x040000
393 #define PRID_IMP_BCM4710 0x4000
394 #define PRID_IMP_BCM3302 0x9000
395 #define PRID_IMP_BCM3303 0x9100
397 #define PRID_IMP_UNKNOWN 0xff00
399 #define BCM330X(id) \
400 (((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == \
401 (PRID_COMP_BROADCOM | PRID_IMP_BCM3302)) || \
402 ((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == \
403 (PRID_COMP_BROADCOM | PRID_IMP_BCM3303)))
405 /* Bits in C0_BROADCOM */
406 #define BRCM_PFC_AVAIL 0x20000000 /* PFC is available */
407 #define BRCM_DC_ENABLE 0x40000000 /* Enable Data $ */
408 #define BRCM_IC_ENABLE 0x80000000 /* Enable Instruction $ */
409 #define BRCM_PFC_ENABLE 0x00400000 /* Obsolete? Enable PFC (at least on 4310) */
410 #define BRCM_CLF_ENABLE 0x00100000 /* Enable cache line first feature */
412 /* PreFetch Cache aka Read Ahead Cache */
414 #define PFC_CR0 0xff400000 /* control reg 0 */
415 #define PFC_CR1 0xff400004 /* control reg 1 */
418 #define PFC_I 0x00000001 /* Enable PFC use for instructions */
419 #define PFC_D 0x00000002 /* Enable PFC use for data */
420 #define PFC_PFI 0x00000004 /* Enable seq. prefetch for instructions */
421 #define PFC_PFD 0x00000008 /* Enable seq. prefetch for data */
422 #define PFC_CINV 0x00000010 /* Enable selective (i/d) cacheop flushing */
423 #define PFC_NCH 0x00000020 /* Disable flushing based on cacheops */
424 #define PFC_DPF 0x00000040 /* Enable directional prefetching */
425 #define PFC_FLUSH 0x00000100 /* Flush the PFC */
426 #define PFC_BRR 0x40000000 /* Bus error indication */
427 #define PFC_PWR 0x80000000 /* Disable power saving (clock gating) */
430 #define PFC_DISABLED 0
431 #define PFC_AUTO 0xffffffff /* auto select the default mode */
432 #define PFC_INST (PFC_I | PFC_PFI | PFC_CINV)
433 #define PFC_INST_NOPF (PFC_I | PFC_CINV)
434 #define PFC_DATA (PFC_D | PFC_PFD | PFC_CINV)
435 #define PFC_DATA_NOPF (PFC_D | PFC_CINV)
436 #define PFC_I_AND_D (PFC_INST | PFC_DATA)
437 #define PFC_I_AND_D_NOPF (PFC_INST_NOPF | PFC_DATA_NOPF)
439 #ifndef _LANGUAGE_ASSEMBLY
442 * Macros to access the system control coprocessor
445 #define MFC0(source, sel) \
448 __asm__ __volatile__(" \
451 .word\t"STR(0x40010000 | ((source) << 11) | (sel))"; \
461 #define MTC0(source, sel, value) \
463 __asm__ __volatile__(" \
467 .word\t"STR(0x40810000 | ((source) << 11) | (sel))"; \
475 #define get_c0_count() \
478 __asm__ __volatile__(" \
488 static INLINE
void icache_probe(uint32 config1
, uint
*size
, uint
*lsize
)
490 uint lsz
, sets
, ways
;
492 /* Instruction Cache Size = Associativity * Line Size * Sets Per Way */
493 if ((lsz
= ((config1
& CONF1_IL_MASK
) >> CONF1_IL_SHIFT
)))
494 lsz
= CONF1_IL_BASE
<< lsz
;
495 sets
= CONF1_IS_BASE
<< ((config1
& CONF1_IS_MASK
) >> CONF1_IS_SHIFT
);
496 ways
= CONF1_IA_BASE
+ ((config1
& CONF1_IA_MASK
) >> CONF1_IA_SHIFT
);
497 *size
= lsz
* sets
* ways
;
501 static INLINE
void dcache_probe(uint32 config1
, uint
*size
, uint
*lsize
)
503 uint lsz
, sets
, ways
;
505 /* Data Cache Size = Associativity * Line Size * Sets Per Way */
506 if ((lsz
= ((config1
& CONF1_DL_MASK
) >> CONF1_DL_SHIFT
)))
507 lsz
= CONF1_DL_BASE
<< lsz
;
508 sets
= CONF1_DS_BASE
<< ((config1
& CONF1_DS_MASK
) >> CONF1_DS_SHIFT
);
509 ways
= CONF1_DA_BASE
+ ((config1
& CONF1_DA_MASK
) >> CONF1_DA_SHIFT
);
510 *size
= lsz
* sets
* ways
;
514 #define cache_op(base, op) \
515 __asm__ __volatile__(" \
525 #define cache_unroll4(base, delta, op) \
526 __asm__ __volatile__(" \
530 cache %1, delta(%0); \
531 cache %1, (2 * delta)(%0); \
532 cache %1, (3 * delta)(%0); \
539 #endif /* !_LANGUAGE_ASSEMBLY */
541 #endif /* _MISPINC_H */
This page took 0.084916 seconds and 5 git commands to generate.