The Pedigree Project  0.1
ppc_common/Processor.cc
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 #include "pedigree/kernel/processor/Processor.h"
21 #include "pedigree/kernel/Log.h"
22 
24 {
25  return 1;
26 }
27 
29  size_t nBpNumber, DebugFlags::FaultType &nFaultType, size_t &nLength,
30  bool &bEnabled)
31 {
32  return 0;
33 }
34 
36  size_t nBpNumber, uintptr_t nLinearAddress,
37  DebugFlags::FaultType nFaultType, size_t nLength)
38 {
39 }
40 
41 void Processor::disableDebugBreakpoint(size_t nBpNumber)
42 {
43 }
44 
45 void Processor::setInterrupts(bool bEnable)
46 {
47  asm volatile("sync; isync;");
48  uint32_t msr;
49  asm volatile("mfmsr %0" : "=r"(msr));
50  if (bEnable)
51  msr |= MSR_EE;
52  else
53  msr &= ~MSR_EE;
54  asm volatile("mtmsr %0" : : "r"(msr));
55  asm volatile("sync; isync;");
56 }
57 
58 void Processor::setSingleStep(bool bEnable, InterruptState &state)
59 {
60  if (bEnable)
61  state.m_Srr1 |= MSR_SE;
62  else
63  state.m_Srr1 &= ~MSR_SE;
64 }
65 
66 void Processor::invalidateICache(uintptr_t nAddr)
67 {
68  asm volatile("icbi 0, %0" : : "r"(nAddr));
69 }
70 
71 void Processor::invalidateDCache(uintptr_t nAddr)
72 {
73  asm volatile("dcbi 0, %0" : : "r"(nAddr));
74 }
75 
76 void Processor::flushDCache(uintptr_t nAddr)
77 {
78  asm volatile("dcbst 0, %0" : : "r"(nAddr));
79 }
80 
81 void Processor::flushDCacheAndInvalidateICache(
82  uintptr_t startAddr, uintptr_t endAddr)
83 {
84  for (uintptr_t i = startAddr; i < endAddr; i += 4)
85  flushDCache(i);
86 
87  asm volatile("sync");
88 
89  for (uintptr_t i = startAddr; i < endAddr; i += 4)
90  invalidateICache(i);
91 
92  asm volatile("sync");
93  asm volatile("isync");
94 }
static uintptr_t getDebugBreakpoint(size_t nBpNumber, DebugFlags::FaultType &nFaultType, size_t &nLength, bool &bEnabled)
static void enableDebugBreakpoint(size_t nBpNumber, uintptr_t nLinearAddress, DebugFlags::FaultType nFaultType, size_t nLength)
static void setSingleStep(bool bEnable, InterruptState &state)
static void disableDebugBreakpoint(size_t nBpNumber)
static void setInterrupts(bool bEnable)
static size_t getDebugBreakpointCount()