FreeNOS
SunxiKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/System.h>
19 #include <FreeNOS/ProcessManager.h>
20 #include <Log.h>
21 #include <SplitAllocator.h>
22 #include <CoreInfo.h>
23 #include <arm/ARMException.h>
24 #include <arm/ARMConstant.h>
25 #include <SunxiCoreServer.h>
26 #include "SunxiKernel.h"
27 
29  : ARMKernel(info)
30  , m_gic(GIC_DIST_BASE, GIC_CPU_BASE)
31 {
32  ARMControl ctrl;
33 
34  NOTICE("");
35 
36  // Initialize the IRQ controller
39  {
40  FATAL("failed to initialize the GIC: " << (uint) r);
41  }
42 
43  // Setup interrupt callbacks
47 
48  // Configure clocks and irqs
51  m_intControl->enable(ARMTIMER_IRQ);
52 
53  // Allocate physical memory pages for secondary CoreInfo structure
54  if (m_coreInfo->coreId == 0) {
56  }
57 }
58 
59 void SunxiKernel::interrupt(volatile CPUState state)
60 {
62  ARMProcess *proc = (ARMProcess *) kernel->getProcessManager()->current(), *next;
63  uint irq;
64  bool tick = false;
65 
66  DEBUG("procId = " << proc->getID());
67 
68  IntController::Result result = kernel->m_intControl->nextPending(irq);
69  if (result == IntController::Success)
70  {
71  if (irq == ARMTIMER_IRQ)
72  tick = true;
73  else
74  kernel->executeIntVector(irq, (CPUState *)&state);
75 
76  kernel->m_intControl->clear(irq);
77  }
78 
79  if (tick)
80  {
81  kernel->m_timer->tick();
82  kernel->getProcessManager()->schedule();
83  }
84 
85  // If we scheduled a new process, switch the registers now
86  next = (ARMProcess *) kernel->getProcessManager()->current();
87  if (next != proc)
88  {
89  proc->setCpuState((const CPUState *)&state);
90  MemoryBlock::copy((void *)&state, next->cpuState(), sizeof(state));
91  }
92 }
ARMException.h
SunxiKernel::m_armTimer
ARMTimer m_armTimer
ARM generic timer.
Definition: SunxiKernel.h:62
SunxiKernel::m_gic
ARMGenericInterrupt m_gic
ARM Generic Interrupt Controller.
Definition: SunxiKernel.h:59
MemoryBlock::copy
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Definition: MemoryBlock.cpp:36
IntController::clear
virtual Result clear(uint irq)=0
Clear hardware interrupt (IRQ).
SplitAllocator::allocate
virtual Result allocate(Range &args)
Allocate physical memory.
Definition: SplitAllocator.cpp:35
ARMGenericInterrupt::initialize
Result initialize(bool performReset=true)
Initialize the controller.
Definition: ARMGenericInterrupt.cpp:35
SplitAllocator.h
ARMConstant.h
NOTICE
#define NOTICE(msg)
Output a notice message.
Definition: Log.h:75
Kernel::m_coreInfo
CoreInfo * m_coreInfo
CoreInfo object for this core.
Definition: Kernel.h:236
IntController::nextPending
virtual Result nextPending(uint &irq)
Retrieve the next pending interrupt (IRQ).
Definition: IntController.cpp:30
Kernel::m_timer
Timer * m_timer
Timer device.
Definition: Kernel.h:245
SunxiKernel::SunxiKernel
SunxiKernel(CoreInfo *info)
Constructor function.
Definition: SunxiKernel.cpp:28
Process::getID
ProcessID getID() const
Retrieve our ID number.
Definition: Process.cpp:60
IntController::Success
@ Success
Definition: IntController.h:44
SunxiCoreServer.h
ARMException::IRQ
@ IRQ
Definition: ARMException.h:59
Kernel::getProcessManager
ProcessManager * getProcessManager()
Get process manager.
Definition: Kernel.cpp:143
Log.h
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
CoreInfo::coreId
uint coreId
Core identifier.
Definition: CoreInfo.h:66
SunxiKernel.h
FATAL
#define FATAL(msg)
Output a critical message and terminate program immediatly.
Definition: Log.h:50
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
ARMControl
ARM System Control Coprocessor (CP15).
Definition: ARMControl.h:47
Kernel::m_intControl
IntController * m_intControl
Interrupt Controller.
Definition: Kernel.h:242
SunxiCoreServer::SecondaryCoreInfoAddress
static const Address SecondaryCoreInfoAddress
Physical memory address for CoreInfo passed to secondary cores during bootup.
Definition: SunxiCoreServer.h:43
IntController::enable
virtual Result enable(uint irq)=0
Enable hardware interrupt (IRQ).
ARMException::install
Result install(ExceptionType vector, Handler handler)
Install an exception handler.
Definition: ARMException.cpp:39
SunxiKernel::interrupt
static void interrupt(CPUState state)
Interrupt handler routine.
Definition: SunxiKernel.cpp:59
WeakSingleton< Kernel >::instance
static Kernel * instance()
Retrieve the instance.
Definition: Singleton.h:86
ProcessManager::schedule
Result schedule()
Schedule next process to run.
Definition: ProcessManager.cpp:155
ARMProcess
ARM specific process implementation.
Definition: ARMProcess.h:34
CPUState
Contains all the CPU registers.
Definition: ARMCore.h:243
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
ARMKernel::m_exception
ARMException m_exception
ARM exception handling subsystem.
Definition: ARMKernel.h:98
ARMTimer::setFrequency
virtual Result setFrequency(const Size hertz)
Set timer frequency.
Definition: ARMTimer.cpp:52
ARMException::FIQ
@ FIQ
Definition: ARMException.h:60
ARMProcess::setCpuState
void setCpuState(const CPUState *cpuState)
Overwrite the saved CPU registers for this task.
Definition: ARMProcess.cpp:91
SunxiKernel
Represents the Sunxi kernel implementation.
Definition: SunxiKernel.h:36
ARMKernel
Represents the ARM kernel implementation.
Definition: ARMKernel.h:40
CoreInfo.h
Kernel::m_alloc
SplitAllocator * m_alloc
Physical memory allocator.
Definition: Kernel.h:227
ProcessManager::current
Process * current()
Current process running.
Definition: ProcessManager.cpp:203
Kernel::executeIntVector
virtual void executeIntVector(u32 vec, CPUState *state)
Execute an interrupt handler.
Definition: Kernel.cpp:210
IntController::Result
Result
Result codes.
Definition: IntController.h:42
Timer::tick
virtual Result tick()
Process timer tick.
Definition: Timer.cpp:74