The Pedigree Project  0.1
arm_common/ProcessorInformation.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_ARM_COMMON_PROCESSORINFORMATION_H
21 #define KERNEL_PROCESSOR_ARM_COMMON_PROCESSORINFORMATION_H
22 
23 #include "pedigree/kernel/process/PerProcessorScheduler.h"
24 #include "pedigree/kernel/process/Thread.h"
25 #include "pedigree/kernel/processor/VirtualAddressSpace.h"
26 #include "pedigree/kernel/processor/types.h"
27 
33 {
34  friend class Processor;
35  // friend class Multiprocessor;
36  public:
40  {
42  return *m_VirtualAddressSpace;
43  else
45  }
48  inline void setVirtualAddressSpace(VirtualAddressSpace &virtualAddressSpace)
49  {
50  m_VirtualAddressSpace = &virtualAddressSpace;
51  }
52 
53  inline uintptr_t getKernelStack() const;
54  inline void setKernelStack(uintptr_t stack);
55 #ifdef THREADS
56  inline Thread *getCurrentThread() const
57  {
58  return m_pCurrentThread;
59  }
60  inline void setCurrentThread(Thread *pThread)
61  {
62  m_pCurrentThread = pThread;
63  }
64 
65  inline PerProcessorScheduler &getScheduler()
66  {
67  return m_Scheduler;
68  }
69 #endif
70 
71  protected:
75  ProcessorId processorId, uint8_t apicId = 0)
76  : m_ProcessorId(processorId),
77  m_VirtualAddressSpace(&VirtualAddressSpace::getKernelAddressSpace())
78 #ifdef THREADS
79  ,
81 #endif
82  {
83  }
86  {
87  }
88 
89  private:
100 
105 #ifdef THREADS
106 
110 #endif
111 };
112 
115 //
116 // Part of the implementation
117 //
118 uintptr_t ArmCommonProcessorInformation::getKernelStack() const
119 {
120  return 0;
121  /*
122  uintptr_t ret = 0;
123 
124  // Switch to IRQ mode
125  uint32_t cpsr = 0;
126  asm volatile("mrs %0, cpsr" : "=r" (cpsr));
127  uint32_t oldMode = cpsr & 0x3F;
128  if(oldMode != 0x12)
129  {
130  cpsr &= ~0x3F;
131  cpsr |= 0x12;
132  asm volatile("msr cpsr_c, %0" : : "r" (cpsr));
133  }
134 
135  // Load new stack and all that
136  asm volatile("mov %0, sp" : "=r" (ret));
137 
138  // Switch back to the previous mode
139  if(oldMode != 0x12)
140  {
141  cpsr &= ~0x3F;
142  cpsr |= oldMode;
143  asm volatile("msr cpsr_c, %0" : : "r" (cpsr));
144  }
145 
146  return ret;
147  */
148 }
149 void ArmCommonProcessorInformation::setKernelStack(uintptr_t stack)
150 {
151  /*
152  // Handle IRQ save location
153  stack -= 0x10;
154 
155  // Switch to IRQ mode
156  uint32_t cpsr = 0;
157  asm volatile("mrs %0, cpsr" : "=r" (cpsr));
158  uint32_t oldMode = cpsr & 0x3F;
159  if(oldMode == 0x12)
160  {
161  // Can't switch a stack we're using!
162  return;
163  }
164  cpsr &= ~0x3F;
165  cpsr |= 0x12;
166  asm volatile("msr cpsr_c, %0" : : "r" (cpsr));
167 
168  // Load new stack and all that
169  asm volatile("mov sp, %0; mov r13, %1" : : "r" (stack), "r" (stack +
170  0x10) : "sp", "r13");
171 
172  // Switch back to the previous mode
173  cpsr &= ~0x3F;
174  cpsr |= oldMode;
175  asm volatile("msr cpsr_c, %0" : : "r" (cpsr));
176  */
177 }
178 
179 #endif
ArmCommonProcessorInformation(ProcessorId processorId, uint8_t apicId=0)
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
void setVirtualAddressSpace(VirtualAddressSpace &virtualAddressSpace)
The exception was caused by a hardware task switch.
Definition: Processor.h:80
ArmCommonProcessorInformation & operator=(const ArmCommonProcessorInformation &)
size_t ProcessorId
Definition: Thread.h:54
VirtualAddressSpace & getVirtualAddressSpace() const