]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/proc_reg.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 #ifndef _PPC_PROC_REG_H_
27 #define _PPC_PROC_REG_H_
29 #include <mach/boolean.h>
31 /* Define some useful masks that convert from bit numbers */
36 #define ENDIAN_MASK(val,size) (1 << ((size-1) - val))
39 #error code not ported to little endian targets yet
40 #endif /* _BIG_ENDIAN */
43 #define MASK32(PART) ENDIAN_MASK(PART ## _BIT, 32)
44 #define MASK16(PART) ENDIAN_MASK(PART ## _BIT, 16)
45 #define MASK8(PART) ENDIAN_MASK(PART ## _BIT, 8)
48 #define MASK(PART) MASK32(PART)
50 #define BITS_PER_WORD 32
51 #define BITS_PER_WORD_POW2 5
53 /* Defines for decoding the MSR bits */
56 #define MSR_RES1_BIT 1
57 #define MSR_RES2_BIT 2
58 #define MSR_RES3_BIT 3
59 #define MSR_RES4_BIT 4
60 #define MSR_RES5_BIT 5
62 #define MSR_RES7_BIT 7
63 #define MSR_RES8_BIT 8
64 #define MSR_RES9_BIT 9
65 #define MSR_RES10_BIT 10
66 #define MSR_RES11_BIT 11
67 #define MSR_KEY_BIT 12 /* Key bit on 603e (not on 603) */
68 #define MSR_POW_BIT 13
69 #define MSR_TGPR_BIT 14 /* Temporary GPR mappings on 603/603e */
70 #define MSR_ILE_BIT 15
75 #define MSR_FE0_BIT 20
78 #define MSR_FE1_BIT 23
79 #define MSR_RES24_BIT 24 /* AL bit in power architectures */
83 #define MSR_RES28_BIT 28
88 /* MSR for kernel mode, interrupts disabled, running in virtual mode */
89 #define MSR_SUPERVISOR_INT_OFF (MASK(MSR_ME) | MASK(MSR_IR) | MASK(MSR_DR))
91 /* MSR for above but with interrupts enabled */
92 #define MSR_SUPERVISOR_INT_ON (MSR_SUPERVISOR_INT_OFF | MASK(MSR_EE))
94 /* MSR for physical mode code */
95 #define MSR_VM_OFF (MASK(MSR_ME))
97 /* MSR for physical instruction, virtual data */
98 #define MSR_PHYS_INST_VIRT_DATA (MASK(MSR_ME) | MASK(MSR_IR))
100 /* MSR mask for user-exported bits - identify bits that must be set/reset */
102 /* SET - external exceptions, machine check, vm on, user-level privs */
103 #define MSR_EXPORT_MASK_SET (MASK(MSR_EE)| MASK(MSR_ME)| \
104 MASK(MSR_IR)|MASK(MSR_DR)|MASK(MSR_PR))
106 /* only the following bits may be changed by a task */
107 #define MSR_IMPORT_BITS (MASK(MSR_FE0)|MASK(MSR_SE)|MASK(MSR_BE)| \
108 MASK(MSR_FE1)| MASK(MSR_PM) | MASK(MSR_LE))
110 #define MSR_PREPARE_FOR_IMPORT(origmsr, newmsr) \
111 ((origmsr & ~MSR_IMPORT_BITS) | (newmsr & MSR_IMPORT_BITS))
113 #define MSR_VEC_ON (MASK(MSR_VEC))
115 #define USER_MODE(msr) (msr & MASK(MSR_PR) ? TRUE : FALSE)
117 /* seg reg values must be simple expressions so that assembler can cope */
118 #define SEG_REG_INVALID 0x0000
119 #define KERNEL_SEG_REG0_VALUE 0x20000000 /* T=0,Ks=0,Ku=1 PPC_SID_KERNEL=0*/
121 /* For SEG_REG_PROT we have T=0, Ks=0, Ku=1 */
122 #define SEG_REG_PROT 0x20000000 /* seg regs should have these bits set */
124 /* SR_COPYIN is used for copyin/copyout+remapping and must be
125 * saved and restored in the thread context.
127 /* SR_UNUSED_BY_KERN is unused by the kernel, and thus contains
128 * the space ID of the currently interrupted user task immediately
129 * after an exception and before interrupts are reenabled. It's used
130 * purely for an assert.
133 /* SR_KERNEL used for asserts... */
135 #define SR_COPYIN sr14
136 #define SR_UNUSED_BY_KERN sr13
137 #define SR_KERNEL sr0
139 #define SR_UNUSED_BY_KERN_NUM 13
140 #define SR_COPYIN_NAME sr14
141 #define SR_COPYIN_NUM 14
144 /* DSISR bits on data access exceptions */
146 #define DSISR_IO_BIT 0 /* NOT USED on 601 */
147 #define DSISR_HASH_BIT 1
148 #define DSISR_PROT_BIT 4
149 #define DSISR_IO_SPC_BIT 5
150 #define DSISR_WRITE_BIT 6
151 #define DSISR_WATCH_BIT 9
152 #define DSISR_EIO_BIT 11
154 /* SRR1 bits on data/instruction translation exceptions */
156 #define SRR1_TRANS_HASH_BIT 1
157 #define SRR1_TRANS_IO_BIT 3
158 #define SRR1_TRANS_PROT_BIT 4
159 #define SRR1_TRANS_NO_PTE_BIT 10
161 /* SRR1 bits on program exceptions */
163 #define SRR1_PRG_FE_BIT 11
164 #define SRR1_PRG_ILL_INS_BIT 12
165 #define SRR1_PRG_PRV_INS_BIT 13
166 #define SRR1_PRG_TRAP_BIT 14
168 /* BAT information */
170 /* Constants used when setting mask values */
172 #define BAT_INVALID 0
175 * Virtual to physical mapping macros/structures.
176 * IMPORTANT NOTE: there is one mapping per HW page, not per MACH page.
179 #define CACHE_LINE_SIZE 32
180 #define CACHE_LINE_POW2 5
181 #define cache_align(x) (((x) + CACHE_LINE_SIZE-1) & ~(CACHE_LINE_SIZE - 1))
183 #define PTE1_WIMG_GUARD_BIT 28 /* Needed for assembler */
184 #define PTE1_REFERENCED_BIT 23 /* ditto */
185 #define PTE1_CHANGED_BIT 24
186 #define PTE0_HASH_ID_BIT 25
188 #define PTE_NULL ((pte_t*) NULL) /* No pte found/associated with this */
189 #define PTE_EMPTY 0x7fffffbf /* Value in the pte0.word of a free pte */
191 #define PTE_WIMG_CB_CACHED 0 /* cached, writeback */
192 #define PTE_WIMG_CB_CACHED_GUARDED 1 /* cached, writeback, guarded */
193 #define PTE_WIMG_CB_CACHED_COHERENT 2 /* cached, writeback, coherent (default) */
194 #define PTE_WIMG_CB_CACHED_COHERENT_GUARDED 3 /* cached, writeback, coherent, guarded */
195 #define PTE_WIMG_UNCACHED 4 /* uncached */
196 #define PTE_WIMG_UNCACHED_GUARDED 5 /* uncached, guarded */
197 #define PTE_WIMG_UNCACHED_COHERENT 6 /* uncached, coherentt */
198 #define PTE_WIMG_UNCACHED_COHERENT_GUARDED 7 /* uncached, coherent, guarded */
199 #define PTE_WIMG_WT_CACHED 8 /* cached, writethru */
200 #define PTE_WIMG_WT_CACHED_GUARDED 9 /* cached, writethru, guarded */
201 #define PTE_WIMG_WT_CACHED_COHERENT 10 /* cached, writethru, coherent */
202 #define PTE_WIMG_WT_CACHED_COHERENT_GUARDED 11 /* cached, writethru, coherent, guarded */
204 #define PTE_WIMG_DEFAULT PTE_WIMG_CB_CACHED_COHERENT
205 #define PTE_WIMG_IO PTE_WIMG_UNCACHED_COHERENT_GUARDED
213 #error - bitfield structures are not checked for bit ordering in words
214 #endif /* _BIG_ENDIAN */
216 /* Structures and types for machine registers */
221 unsigned int htaborg
: 16;
222 unsigned int reserved
: 7;
223 unsigned int htabmask
: 9;
227 /* Block mapping registers. These values are model dependent.
228 * Eventually, we will need to up these to 64 bit values.
231 #define blokValid 0x1FFE0000
232 #define batMin 0x00020000
233 #define batMax 0x10000000
237 /* BAT register structures.
238 * Not used for standard mappings, but may be used
239 * for mapping devices. Note that the 601 has a
240 * different BAT layout than the other PowerPC processors
246 unsigned int blpi
: 15;
247 unsigned int reserved
: 10;
248 unsigned int wim
: 3;
258 unsigned int pbn
: 15;
259 unsigned int reserved
: 10;
260 unsigned int valid
: 1;
261 unsigned int bsm
: 6;
265 typedef struct bat601_t
{
273 unsigned int bepi
: 15;
274 unsigned int reserved
: 4;
275 unsigned int bl
: 11;
284 unsigned int brpn
: 15;
285 unsigned int reserved
: 10;
286 unsigned int wimg
: 4;
287 unsigned int reserved2
: 1;
292 typedef struct bat_t
{
298 * Used extensively for standard mappings
304 unsigned int valid
: 1;
305 unsigned int segment_id
: 24;
306 unsigned int hash_id
: 1;
307 unsigned int page_index
: 6; /* Abbreviated */
310 unsigned int valid
: 1;
311 unsigned int not_used
: 5;
312 unsigned int segment_id
: 19; /* Least Sig 19 bits */
313 unsigned int hash_id
: 1;
314 unsigned int page_index
: 6;
321 unsigned int phys_page
: 20;
322 unsigned int reserved3
: 3;
323 unsigned int referenced
: 1;
324 unsigned int changed
: 1;
325 unsigned int wimg
: 4;
326 unsigned int reserved1
: 1;
327 unsigned int protection
: 2;
331 typedef struct pte_t
{
337 * A virtual address is decoded into various parts when looking for its PTE
340 typedef struct va_full_t
{
341 unsigned int seg_num
: 4;
342 unsigned int page_index
: 16;
343 unsigned int byte_ofs
: 12;
346 typedef struct va_abbrev_t
{ /* use bits.abbrev for abbreviated page index */
347 unsigned int seg_num
: 4;
348 unsigned int page_index
: 6;
349 unsigned int junk
: 10;
350 unsigned int byte_ofs
: 12;
359 /* A physical address can be split up into page and offset */
361 typedef struct pa_t
{
362 unsigned int page_no
: 20;
363 unsigned int offset
: 12;
372 * C-helper inline functions for accessing machine registers follow.
377 #define __CASMNL__ ";"
379 #define __CASMNL__ "@"
382 /* Return the current GOT pointer */
384 extern unsigned int get_got(void);
386 extern __inline__
unsigned int get_got(void)
390 __asm__
volatile("mr %0, r2" : "=r" (result
));
392 __asm__
volatile("mr %0, 2" : "=r" (result
));
398 * Various memory/IO synchronisation instructions
401 /* Use eieio as a memory barrier to order stores.
402 * Useful for device control and PTE maintenance.
406 __asm__ volatile("eieio")
408 /* Use sync to ensure previous stores have completed.
409 This is required when manipulating locks and/or
410 maintaining PTEs or other shared structures on SMP
415 __asm__ volatile("sync")
417 /* Use isync to sychronize context; that is, the ensure
418 no prefetching of instructions happen before the
423 __asm__ volatile("isync")
427 * This guy will make sure all tlbs on all processors finish their tlbies
430 __asm__ volatile("tlbsync")
433 /* Invalidate TLB entry. Caution, requires context synchronization.
435 extern void tlbie(unsigned int val
);
437 extern __inline__
void tlbie(unsigned int val
)
439 __asm__
volatile("tlbie %0" : : "r" (val
));
446 * Access to various system registers
449 extern unsigned int mflr(void);
451 extern __inline__
unsigned int mflr(void)
454 __asm__
volatile("mflr %0" : "=r" (result
));
458 extern unsigned int mfpvr(void);
460 extern __inline__
unsigned int mfpvr(void)
463 __asm__ ("mfpvr %0" : "=r" (result
));
467 /* mtmsr might need syncs etc around it, don't provide simple
471 extern unsigned int mfmsr(void);
473 extern __inline__
unsigned int mfmsr(void)
476 __asm__
volatile("mfmsr %0" : "=r" (result
));
480 /* mtsr and mfsr must be macros since SR must be hardcoded */
483 #define mtsr(SR, REG) \
484 __asm__ volatile("sync" __CASMNL__ "mtsr %0, %1 " __CASMNL__ "isync" : : "i" (SR), "r" (REG));
485 #define mfsr(REG, SR) \
486 __asm__ volatile("mfsr %0, %1" : "=r" (REG) : "i" (SR));
488 #define mtsr(SR, REG) \
489 __asm__ volatile("sync" __CASMNL__ "mtsr sr%0, %1 " __CASMNL__ "isync" : : "i" (SR), "r" (REG));
491 #define mfsr(REG, SR) \
492 __asm__ volatile("mfsr %0, sr%1" : "=r" (REG) : "i" (SR));
496 extern void mtsrin(unsigned int val
, unsigned int reg
);
498 extern __inline__
void mtsrin(unsigned int val
, unsigned int reg
)
500 __asm__
volatile("sync" __CASMNL__
"mtsrin %0, %1" __CASMNL__
" isync" : : "r" (val
), "r" (reg
));
504 extern unsigned int mfsrin(unsigned int reg
);
506 extern __inline__
unsigned int mfsrin(unsigned int reg
)
509 __asm__
volatile("mfsrin %0, %1" : "=r" (result
) : "r" (reg
));
513 extern void mtsdr1(unsigned int val
);
515 extern __inline__
void mtsdr1(unsigned int val
)
517 __asm__
volatile("mtsdr1 %0" : : "r" (val
));
521 extern void mtdar(unsigned int val
);
523 extern __inline__
void mtdar(unsigned int val
)
525 __asm__
volatile("mtdar %0" : : "r" (val
));
529 extern unsigned int mfdar(void);
531 extern __inline__
unsigned int mfdar(void)
534 __asm__
volatile("mfdar %0" : "=r" (result
));
538 extern void mtdec(unsigned int val
);
540 extern __inline__
void mtdec(unsigned int val
)
542 __asm__
volatile("mtdec %0" : : "r" (val
));
546 extern int isync_mfdec(void);
548 extern __inline__
int isync_mfdec(void)
551 __asm__
volatile("isync" __CASMNL__
"mfdec %0" : "=r" (result
));
555 /* Read and write the value from the real-time clock
556 * or time base registers. Note that you have to
557 * use the right ones depending upon being on
558 * 601 or 603/604. Care about carries between
559 * the words and using the right registers must be
560 * done by the calling function.
563 extern void mttb(unsigned int val
);
565 extern __inline__
void mttb(unsigned int val
)
567 __asm__
volatile("mtspr tbl, %0" : : "r" (val
));
571 extern unsigned int mftb(void);
573 extern __inline__
unsigned int mftb(void)
576 __asm__
volatile("mftb %0" : "=r" (result
));
580 extern void mttbu(unsigned int val
);
582 extern __inline__
void mttbu(unsigned int val
)
584 __asm__
volatile("mtspr tbu, %0" : : "r" (val
));
588 extern unsigned int mftbu(void);
590 extern __inline__
unsigned int mftbu(void)
593 __asm__
volatile("mftbu %0" : "=r" (result
));
597 extern void mtrtcl(unsigned int val
);
599 extern __inline__
void mtrtcl(unsigned int val
)
601 __asm__
volatile("mtspr 21,%0" : : "r" (val
));
605 extern unsigned int mfrtcl(void);
607 extern __inline__
unsigned int mfrtcl(void)
610 __asm__
volatile("mfspr %0,5" : "=r" (result
));
614 extern void mtrtcu(unsigned int val
);
616 extern __inline__
void mtrtcu(unsigned int val
)
618 __asm__
volatile("mtspr 20,%0" : : "r" (val
));
622 extern unsigned int mfrtcu(void);
624 extern __inline__
unsigned int mfrtcu(void)
627 __asm__
volatile("mfspr %0,4" : "=r" (result
));
631 extern void mtl2cr(unsigned int val
);
633 extern __inline__
void mtl2cr(unsigned int val
)
635 __asm__
volatile("mtspr l2cr, %0" : : "r" (val
));
639 extern unsigned int mfl2cr(void);
641 extern __inline__
unsigned int mfl2cr(void)
644 __asm__
volatile("mfspr %0, l2cr" : "=r" (result
));
648 extern unsigned int cntlzw(unsigned int num
);
650 extern __inline__
unsigned int cntlzw(unsigned int num
)
653 __asm__
volatile("cntlzw %0, %1" : "=r" (result
) : "r" (num
));
658 /* functions for doing byte reversed loads and stores */
660 extern unsigned int lwbrx(unsigned int addr
);
662 extern __inline__
unsigned int lwbrx(unsigned int addr
)
665 __asm__
volatile("lwbrx %0, 0, %1" : "=r" (result
) : "r" (addr
));
669 extern void stwbrx(unsigned int data
, unsigned int addr
);
671 extern __inline__
void stwbrx(unsigned int data
, unsigned int addr
)
673 __asm__
volatile("stwbrx %0, 0, %1" : : "r" (data
), "r" (addr
));
676 /* Performance Monitor Register access routines */
677 extern unsigned long mfmmcr0(void);
678 extern void mtmmcr0(unsigned long);
679 extern unsigned long mfmmcr1(void);
680 extern void mtmmcr1(unsigned long);
681 extern unsigned long mfmmcr2(void);
682 extern void mtmmcr2(unsigned long);
683 extern unsigned long mfpmc1(void);
684 extern void mtpmc1(unsigned long);
685 extern unsigned long mfpmc2(void);
686 extern void mtpmc2(unsigned long);
687 extern unsigned long mfpmc3(void);
688 extern void mtpmc3(unsigned long);
689 extern unsigned long mfpmc4(void);
690 extern void mtpmc4(unsigned long);
691 extern unsigned long mfsia(void);
692 extern unsigned long mfsda(void);
694 /* macros since the argument n is a hard-coded constant */
696 #define mtibatu(n, reg) __asm__ volatile("mtibatu " # n ", %0" : : "r" (reg))
697 #define mtibatl(n, reg) __asm__ volatile("mtibatl " # n ", %0" : : "r" (reg))
699 #define mtdbatu(n, reg) __asm__ volatile("mtdbatu " # n ", %0" : : "r" (reg))
700 #define mtdbatl(n, reg) __asm__ volatile("mtdbatl " # n ", %0" : : "r" (reg))
702 #define mfibatu(reg, n) __asm__ volatile("mfibatu %0, " # n : "=r" (reg))
703 #define mfibatl(reg, n) __asm__ volatile("mfibatl %0, " # n : "=r" (reg))
705 #define mfdbatu(reg, n) __asm__ volatile("mfdbatu %0, " # n : "=r" (reg))
706 #define mfdbatl(reg, n) __asm__ volatile("mfdbatl %0, " # n : "=r" (reg))
708 #define mtsprg(n, reg) __asm__ volatile("mtsprg " # n ", %0" : : "r" (reg))
709 #define mfsprg(reg, n) __asm__ volatile("mfsprg %0, " # n : "=r" (reg))
711 #define mtspr(spr, val) __asm__ volatile("mtspr " # spr ", %0" : : "r" (val))
712 #define mfspr(reg, spr) __asm__ volatile("mfspr %0, " # spr : "=r" (reg))
714 #endif /* __GNUC__ */
715 #endif /* !ASSEMBLER */
717 #endif /* _PPC_PROC_REG_H_ */