20 #include "pedigree/kernel/processor/Processor.h" 21 #include "InterruptManager.h" 22 #include "PhysicalMemoryManager.h" 23 #include "SyscallManager.h" 24 #include "VirtualAddressSpace.h" 25 #include "pedigree/kernel/process/Scheduler.h" 26 #include "pedigree/kernel/process/Thread.h" 27 #include "pedigree/kernel/process/initialiseMultitasking.h" 28 #include "pedigree/kernel/processor/PageFaultHandler.h" 38 bool Processor::m_bInterrupts;
40 typedef void (*jump_func_t)(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
59 initialiseMultitasking();
70 str.append(
"Hosted Processor");
75 return reinterpret_cast<uintptr_t
>(__builtin_return_address(0));
85 return reinterpret_cast<uintptr_t
>(__builtin_frame_address(0));
90 ERROR(
"Processor::saveState is NOT safe on HOSTED builds.");
93 if (sigsetjmp(_state, 0) == 1)
96 MemoryCopy(state.state, _state,
sizeof(_state));
106 MemoryCopy(_state, state.state,
sizeof(_state));
107 siglongjmp(_state, 1);
112 volatile uintptr_t *pLock, uintptr_t address, uintptr_t stack, uintptr_t p1,
113 uintptr_t p2, uintptr_t p3, uintptr_t p4)
116 jumpKernel(pLock, address, stack, p1, p2, p3, p4);
119 #ifdef SYSTEM_REQUIRES_ATOMIC_CONTEXT_SWITCH 120 void Processor::switchState(
121 bool bInterrupts, SchedulerState &a, SchedulerState &b,
122 volatile uintptr_t *pLock)
125 if (sigsetjmp(_state, 0) == 1)
132 MemoryCopy(a.state, _state,
sizeof(_state));
133 restoreState(b, pLock);
136 void Processor::switchState(
137 bool bInterrupts, SchedulerState &a, SyscallState &b,
138 volatile uintptr_t *pLock)
141 if (sigsetjmp(_state, 0) == 1)
148 MemoryCopy(a.state, _state,
sizeof(_state));
152 void Processor::saveAndJumpKernel(
153 bool bInterrupts, SchedulerState &s,
volatile uintptr_t *pLock,
154 uintptr_t address, uintptr_t stack, uintptr_t p1, uintptr_t p2,
155 uintptr_t p3, uintptr_t p4)
158 if (sigsetjmp(_state, 0) == 1)
165 MemoryCopy(s.state, _state,
sizeof(_state));
169 void Processor::saveAndJumpUser(
170 bool bInterrupts, SchedulerState &s,
volatile uintptr_t *pLock,
171 uintptr_t address, uintptr_t stack, uintptr_t p1, uintptr_t p2,
172 uintptr_t p3, uintptr_t p4)
174 Processor::saveAndJumpKernel(
175 bInterrupts, s, pLock, address, stack, p1, p2, p3, p4);
177 #endif // SYSTEM_REQUIRES_ATOMIC_CONTEXT_SWITCH 182 if (&info.getVirtualAddressSpace() != &AddressSpace)
184 info.setVirtualAddressSpace(AddressSpace);
186 info.getVirtualAddressSpace(), AddressSpace);
200 size_t nBpNumber, DebugFlags::FaultType &nFaultType,
size_t &nLength,
208 size_t nBpNumber, uintptr_t nLinearAddress,
209 DebugFlags::FaultType nFaultType,
size_t nLength)
232 sigaddset(&
set, SIGUSR1);
233 sigaddset(&
set, SIGUSR2);
241 m_bInterrupts =
true;
244 int r = sigprocmask(SIG_SETMASK, &
set, 0);
247 ERROR(
"Processor::setInterrupts failed to set new mask");
255 m_bInterrupts =
false;
261 return m_bInterrupts;
284 void Processor::_breakpoint()
290 sigaddset(&
set, SIGTRAP);
291 sigprocmask(SIG_UNBLOCK, &
set, &oset);
293 sigprocmask(SIG_SETMASK, &oset, 0);
296 void Processor::_reset()
302 void Processor::_haltUntilInterrupt()
304 bool bOld = m_bInterrupts;
314 Processor::_breakpoint();
325 asm volatile(
"pause");
335 Processor::_haltUntilInterrupt();
Bootstrap structure passed to the kernel entry point.
static void restoreState(SchedulerState &state, volatile uintptr_t *pLock=0) NORETURN
static bool getInterrupts()
static void initialiseProcessor() INITIALISATION_ONLY
static void setTlsBase(uintptr_t newBase)
static void jumpKernel(volatile uintptr_t *pLock, uintptr_t address, uintptr_t stack, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0) NORETURN
static uintptr_t getDebugBreakpoint(size_t nBpNumber, DebugFlags::FaultType &nFaultType, size_t &nLength, bool &bEnabled)
static void initialise2(const BootstrapStruct_t &Info) INITIALISATION_ONLY
second/last stage in the initialisation of the processor-specific interface
static void initialiseProcessor() INITIALISATION_ONLY
static void initialisationDone()
static ProcessorInformation & information()
static void switchAddressSpace(VirtualAddressSpace &AddressSpace)
static void enableDebugBreakpoint(size_t nBpNumber, uintptr_t nLinearAddress, DebugFlags::FaultType nFaultType, size_t nLength)
static PageFaultHandler & instance()
void initialisationDone()
static void setSingleStep(bool bEnable, InterruptState &state)
static void initialise1(const BootstrapStruct_t &Info) INITIALISATION_ONLY
first stage in the initialisation of the processor-specific interface
static bool saveState(SchedulerState &state)
static void jumpUser(volatile uintptr_t *pLock, uintptr_t address, uintptr_t stack, uintptr_t p1=0, uintptr_t p2=0, uintptr_t p3=0, uintptr_t p4=0) NORETURN
void initialise(const BootstrapStruct_t &Info) INITIALISATION_ONLY
static void disableDebugBreakpoint(size_t nBpNumber)
static void haltUntilInterrupt()
static void deinitialise()
static void setInterrupts(bool bEnable)
static void identify(HugeStaticString &str)
static HostedPhysicalMemoryManager & instance()
static uintptr_t getStackPointer()
static size_t getDebugBreakpointCount()
static uintptr_t getInstructionPointer()
static void switchAddressSpace(VirtualAddressSpace &oldSpace, VirtualAddressSpace &newSpace)
static uintptr_t getBasePointer()
static void invalidate(void *pAddress)