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
59void 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}
ARM System Control Coprocessor (CP15).
Definition ARMControl.h:48
Result install(ExceptionType vector, Handler handler)
Install an exception handler.
Result initialize(bool performReset=true)
Initialize the controller.
Represents the ARM kernel implementation.
Definition ARMKernel.h:41
ARMException m_exception
ARM exception handling subsystem.
Definition ARMKernel.h:98
ARM specific process implementation.
Definition ARMProcess.h:35
void setCpuState(const CPUState *cpuState)
Overwrite the saved CPU registers for this task.
virtual Result setFrequency(const Size hertz)
Set timer frequency.
Definition ARMTimer.cpp:52
virtual Result clear(uint irq)=0
Clear hardware interrupt (IRQ).
virtual Result nextPending(uint &irq)
Retrieve the next pending interrupt (IRQ).
virtual Result enable(uint irq)=0
Enable hardware interrupt (IRQ).
Result
Result codes.
CoreInfo * m_coreInfo
CoreInfo object for this core.
Definition Kernel.h:236
SplitAllocator * m_alloc
Physical memory allocator.
Definition Kernel.h:227
virtual void executeIntVector(u32 vec, CPUState *state)
Execute an interrupt handler.
Definition Kernel.cpp:210
IntController * m_intControl
Interrupt Controller.
Definition Kernel.h:242
Timer * m_timer
Timer device.
Definition Kernel.h:245
ProcessManager * getProcessManager()
Get process manager.
Definition Kernel.cpp:143
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Result schedule()
Schedule next process to run.
Process * current()
Current process running.
ProcessID getID() const
Retrieve our ID number.
Definition Process.cpp:60
virtual Result allocate(Range &args)
Allocate physical memory.
static const Address SecondaryCoreInfoAddress
Physical memory address for CoreInfo passed to secondary cores during bootup.
Represents the Sunxi kernel implementation.
Definition SunxiKernel.h:37
ARMGenericInterrupt m_gic
ARM Generic Interrupt Controller.
Definition SunxiKernel.h:59
ARMTimer m_armTimer
ARM generic timer.
Definition SunxiKernel.h:62
SunxiKernel(CoreInfo *info)
Constructor function.
static void interrupt(CPUState state)
Interrupt handler routine.
virtual Result tick()
Process timer tick.
Definition Timer.cpp:74
static Kernel * instance()
Retrieve the instance.
Definition Singleton.h:86
#define NOTICE(msg)
Output a notice message.
Definition Log.h:75
#define FATAL(msg)
Output a critical message and terminate program immediatly.
Definition Log.h:50
unsigned int uint
Unsigned integer number.
Definition Types.h:44
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Contains all the CPU registers.
Definition ARMCore.h:244
Per-Core information structure.
Definition CoreInfo.h:61
uint coreId
Core identifier.
Definition CoreInfo.h:66