xref: /haiku/headers/private/kernel/arch/ppc/arch_cpu.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2 ** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
5 #ifndef _KERNEL_ARCH_PPC_CPU_H
6 #define _KERNEL_ARCH_PPC_CPU_H
7 
8 
9 #include <arch/ppc/arch_thread_types.h>
10 #include <kernel.h>
11 
12 
13 #define PAGE_SIZE 4096
14 
15 struct iframe {
16 	uint32 vector;
17 	uint32 srr0;
18 	uint32 srr1;
19 	uint32 dar;
20 	uint32 dsisr;
21 	uint32 lr;
22 	uint32 cr;
23 	uint32 xer;
24 	uint32 ctr;
25 	uint32 fpscr;
26 	uint32 r31;
27 	uint32 r30;
28 	uint32 r29;
29 	uint32 r28;
30 	uint32 r27;
31 	uint32 r26;
32 	uint32 r25;
33 	uint32 r24;
34 	uint32 r23;
35 	uint32 r22;
36 	uint32 r21;
37 	uint32 r20;
38 	uint32 r19;
39 	uint32 r18;
40 	uint32 r17;
41 	uint32 r16;
42 	uint32 r15;
43 	uint32 r14;
44 	uint32 r13;
45 	uint32 r12;
46 	uint32 r11;
47 	uint32 r10;
48 	uint32 r9;
49 	uint32 r8;
50 	uint32 r7;
51 	uint32 r6;
52 	uint32 r5;
53 	uint32 r4;
54 	uint32 r3;
55 	uint32 r2;
56 	uint32 r1;
57 	uint32 r0;
58 	double f31;
59 	double f30;
60 	double f29;
61 	double f28;
62 	double f27;
63 	double f26;
64 	double f25;
65 	double f24;
66 	double f23;
67 	double f22;
68 	double f21;
69 	double f20;
70 	double f19;
71 	double f18;
72 	double f17;
73 	double f16;
74 	double f15;
75 	double f14;
76 	double f13;
77 	double f12;
78 	double f11;
79 	double f10;
80 	double f9;
81 	double f8;
82 	double f7;
83 	double f6;
84 	double f5;
85 	double f4;
86 	double f3;
87 	double f2;
88 	double f1;
89 	double f0;
90 };
91 
92 enum machine_state {
93 	MSR_EXCEPTIONS_ENABLED			= 1L << 15,		// EE
94 	MSR_PRIVILEGE_LEVEL				= 1L << 14,		// PR
95 	MSR_FP_AVAILABLE				= 1L << 13,		// FP
96 	MSR_MACHINE_CHECK_ENABLED		= 1L << 12,		// ME
97 	MSR_EXCEPTION_PREFIX			= 1L << 6,		// IP
98 	MSR_INST_ADDRESS_TRANSLATION	= 1L << 5,		// IR
99 	MSR_DATA_ADDRESS_TRANSLATION	= 1L << 4,		// DR
100 };
101 
102 struct block_address_translation;
103 
104 typedef struct arch_cpu_info {
105 	int null;
106 } arch_cpu_info;
107 
108 
109 #ifdef __cplusplus
110 extern "C" {
111 #endif
112 
113 extern uint32 get_sdr1(void);
114 extern void set_sdr1(uint32 value);
115 extern uint32 get_sr(void *virtualAddress);
116 extern void set_sr(void *virtualAddress, uint32 value);
117 extern uint32 get_msr(void);
118 extern uint32 set_msr(uint32 value);
119 extern uint32 get_pvr(void);
120 
121 extern void set_ibat0(struct block_address_translation *bat);
122 extern void set_ibat1(struct block_address_translation *bat);
123 extern void set_ibat2(struct block_address_translation *bat);
124 extern void set_ibat3(struct block_address_translation *bat);
125 extern void set_dbat0(struct block_address_translation *bat);
126 extern void set_dbat1(struct block_address_translation *bat);
127 extern void set_dbat2(struct block_address_translation *bat);
128 extern void set_dbat3(struct block_address_translation *bat);
129 
130 extern void get_ibat0(struct block_address_translation *bat);
131 extern void get_ibat1(struct block_address_translation *bat);
132 extern void get_ibat2(struct block_address_translation *bat);
133 extern void get_ibat3(struct block_address_translation *bat);
134 extern void get_dbat0(struct block_address_translation *bat);
135 extern void get_dbat1(struct block_address_translation *bat);
136 extern void get_dbat2(struct block_address_translation *bat);
137 extern void get_dbat3(struct block_address_translation *bat);
138 
139 extern void reset_ibats(void);
140 extern void reset_dbats(void);
141 
142 //extern void sethid0(unsigned int val);
143 //extern unsigned int getl2cr(void);
144 //extern void setl2cr(unsigned int val);
145 extern long long get_time_base(void);
146 
147 void __ppc_setup_system_time(vint32 *cvFactor);
148 	// defined in libroot: os/arch/system_time.c
149 int64 __ppc_get_time_base(void);
150 	// defined in libroot: os/arch/system_time_asm.S
151 
152 extern void ppc_context_switch(void **_oldStackPointer, void *newStackPointer);
153 
154 extern bool ppc_set_fault_handler(addr_t *handlerLocation, addr_t handler)
155 	__attribute__((noinline));
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #define eieio()	asm volatile("eieio")
162 #define isync() asm volatile("isync")
163 #define tlbsync() asm volatile("tlbsync")
164 #define ppc_sync() asm volatile("sync")
165 #define tlbia() asm volatile("tlbia")
166 #define tlbie(addr) asm volatile("tlbie %0" :: "r" (addr))
167 
168 
169 // PowerPC processor version (the upper 16 bits of the PVR).
170 enum ppc_processor_version {
171 	MPC601		= 0x0001,
172 	MPC603		= 0x0003,
173 	MPC604		= 0x0004,
174 	MPC602		= 0x0005,
175 	MPC603e		= 0x0006,
176 	MPC603ev	= 0x0007,
177 	MPC750		= 0x0008,
178 	MPC604ev	= 0x0009,
179 	MPC7400		= 0x000c,
180 	MPC620		= 0x0014,
181 	IBM403		= 0x0020,
182 	IBM401A1	= 0x0021,
183 	IBM401B2	= 0x0022,
184 	IBM401C2	= 0x0023,
185 	IBM401D2	= 0x0024,
186 	IBM401E2	= 0x0025,
187 	IBM401F2	= 0x0026,
188 	IBM401G2	= 0x0027,
189 	IBMPOWER3	= 0x0041,
190 	MPC860		= 0x0050,
191 	MPC8240		= 0x0081,
192 	IBM405GP	= 0x4011,
193 	IBM405L		= 0x4161,
194 	IBM750FX	= 0x7000,
195 	MPC7450		= 0x8000,
196 	MPC7455		= 0x8001,
197 	MPC7457		= 0x8002,
198 	MPC7447A	= 0x8003,
199 	MPC7448		= 0x8004,
200 	MPC7410		= 0x800c,
201 	MPC8245		= 0x8081,
202 };
203 
204 
205 /*
206 	Use of (some) special purpose registers.
207 
208 	SPRG0: per CPU physical address pointer to an ppc_cpu_exception_context
209 	       structure
210 	SPRG1: scratch
211 	SPRG2: current struct thread*
212 	SPRG3: TLS base pointer (only for userland threads)
213 */
214 
215 #endif	/* _KERNEL_ARCH_PPC_CPU_H */
216