The Pedigree Project  0.1
ppc_common/Processor.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_PPC_COMMON_PROCESSOR_H
21 #define KERNEL_PROCESSOR_PPC_COMMON_PROCESSOR_H
22 
23 #define MSR_POW 0x00040000
24 #define MSR_ILE 0x00010000
25 #define MSR_EE 0x00008000
26 #define MSR_PR 0x00004000
27 #define MSR_FP 0x00002000
28 #define MSR_ME 0x00001000
29 #define MSR_FE0 0x00000800
30 #define MSR_SE 0x00000400
31 #define MSR_BE 0x00000200
32 #define MSR_FE1 0x00000100
33 #define MSR_IP 0x00000040
34 #define MSR_IR 0x00000020
35 #define MSR_DR 0x00000010
36 #define MSR_RI 0x00000002
37 #define MSR_LE 0x00000001
38 
40 {
41  asm volatile("trap");
42 }
43 
44 void Processor::halt()
45 {
46  // TODO: gcc will most certainly optimize this away in -O1/2/3 so please
47  // replace it with some unoptimizable mighty magic
48  for (;;)
49  ;
50 }
51 
52 void Processor::invalidate(void *pAddress)
53 {
54  asm volatile("tlbie %0" : : "r"(pAddress));
55 }
56 
57 void Processor::setSegmentRegisters(
58  uint32_t segmentBase, bool supervisorKey, bool userKey)
59 {
60  uint32_t segs[16];
61  for (int i = 0; i < 16; i++)
62  {
63  segs[i] = 0;
64  if (supervisorKey)
65  segs[i] |= 0x40000000;
66  if (userKey)
67  segs[i] |= 0x20000000;
68  segs[i] |= (segmentBase + i) & 0x00FFFFFF;
69  }
70  asm volatile("mtsr 0, %0" : : "r"(segs[0]));
71  asm volatile("mtsr 1, %0" : : "r"(segs[1]));
72  asm volatile("mtsr 2, %0" : : "r"(segs[2]));
73  asm volatile("mtsr 3, %0" : : "r"(segs[3]));
74  asm volatile("mtsr 4, %0" : : "r"(segs[4]));
75  asm volatile("mtsr 5, %0" : : "r"(segs[5]));
76  asm volatile("mtsr 6, %0" : : "r"(segs[6]));
77  asm volatile("mtsr 7, %0" : : "r"(segs[7]));
78  // Don't set kernel regs!
79  // asm volatile("mtsr 8, %0" : :"r"(segs[8]));
80  // asm volatile("mtsr 9, %0" : :"r"(segs[9]));
81  // asm volatile("mtsr 10, %0" : :"r"(segs[10]));
82  // asm volatile("mtsr 11, %0" : :"r"(segs[11]));
83  // asm volatile("mtsr 12, %0" : :"r"(segs[12]));
84  // asm volatile("mtsr 13, %0" : :"r"(segs[13]));
85  // asm volatile("mtsr 14, %0" : :"r"(segs[14]));
86  // asm volatile("mtsr 15, %0" : :"r"(segs[15]));
87  asm volatile("sync");
88 }
89 
90 #endif
static void halt()
static void breakpoint()
static void invalidate(void *pAddress)