FreeNOS
|
FreeNOS kernel implementation. More...
#include <Kernel.h>
Public Types | |
enum | Result { Success, InvalidBootImage, ProcessError, IOError } |
Result codes. More... | |
Public Member Functions | |
Kernel (CoreInfo *info) | |
Constructor function. More... | |
SplitAllocator * | getAllocator () |
Get physical memory allocator. More... | |
ProcessManager * | getProcessManager () |
Get process manager. More... | |
API * | getAPI () |
Get API. More... | |
MemoryContext * | getMemoryContext () |
Get the current MMU context. More... | |
CoreInfo * | getCoreInfo () |
Get CoreInfo. More... | |
Timer * | getTimer () |
Get Timer. More... | |
int | run () |
Execute the kernel. More... | |
virtual void | enableIRQ (u32 irq, bool enabled) |
Enable or disable an hardware interrupt (IRQ). More... | |
virtual Result | sendIRQ (const uint coreId, const uint irq) |
Send a inter-processor-interrupt (IPI) to another core. More... | |
virtual void | hookIntVector (u32 vec, InterruptHandler h, ulong p) |
Hooks a function to an hardware interrupt. More... | |
virtual void | executeIntVector (u32 vec, CPUState *state) |
Execute an interrupt handler. More... | |
virtual Result | loadBootImage () |
Loads the boot image. More... | |
Public Member Functions inherited from WeakSingleton< Kernel > | |
WeakSingleton (Kernel *obj) | |
Constructor. More... | |
Static Public Member Functions | |
static Error | initializeHeap () |
Initialize heap. More... | |
Static Public Member Functions inherited from WeakSingleton< Kernel > | |
static Kernel * | instance () |
Retrieve the instance. More... | |
Protected Attributes | |
SplitAllocator * | m_alloc |
Physical memory allocator. More... | |
ProcessManager * | m_procs |
Process Manager. More... | |
API * | m_api |
API handlers object. More... | |
CoreInfo * | m_coreInfo |
CoreInfo object for this core. More... | |
Vector< List< InterruptHook * > * > | m_interrupts |
Interrupt handlers. More... | |
IntController * | m_intControl |
Interrupt Controller. More... | |
Timer * | m_timer |
Timer device. More... | |
Private Member Functions | |
virtual Result | loadBootProgram (const BootImageStorage &bootImage, const BootSymbol &program) |
Load a boot program. More... | |
enum Kernel::Result |
Kernel::Kernel | ( | CoreInfo * | info | ) |
Constructor function.
info | CoreInfo structure for this core. |
Definition at line 33 of file Kernel.cpp.
References SplitAllocator::allocate(), Log::append(), assert, BANNER, CoreInfo::bootImageAddress, CoreInfo::bootImageSize, CoreInfo::coreChannelAddress, CoreInfo::coreChannelSize, CoreInfo::coreId, Sequence< T >::fill(), CoreInfo::heapAddress, CoreInfo::heapSize, WeakSingleton< Log >::instance(), CoreInfo::kernel, MemoryMap::KernelData, m_alloc, m_api, m_coreInfo, m_intControl, m_interrupts, m_procs, m_timer, CoreInfo::memory, NOTICE, PAGESIZE, Memory::Range::phys, MemoryMap::range(), Memory::Range::size, SplitAllocator::toPhysical(), Memory::Range::virt, and ZERO.
|
virtual |
Enable or disable an hardware interrupt (IRQ).
irq | IRQ number. |
enabled | True to enable, and false to disable. |
Reimplemented in IntelKernel.
Definition at line 168 of file Kernel.cpp.
References IntController::disable(), IntController::enable(), and m_intControl.
Referenced by IntelKernel::enableIRQ(), executeIntVector(), and ProcessCtlHandler().
Execute an interrupt handler.
vec | Interrupt vector. |
state | CPU state. |
Definition at line 210 of file Kernel.cpp.
References enableIRQ(), FATAL, IntController::getBase(), ListIterator< T >::hasCurrent(), ProcessManager::interruptNotify(), m_intControl, m_interrupts, m_procs, and ProcessManager::Success.
Referenced by executeInterrupt(), SunxiKernel::interrupt(), and RaspberryKernel::interrupt().
SplitAllocator * Kernel::getAllocator | ( | ) |
Get physical memory allocator.
Definition at line 138 of file Kernel.cpp.
References m_alloc.
Referenced by ProcessShares::releaseShare(), SystemInfoHandler(), VMCtlHandler(), and IntelProcess::~IntelProcess().
API * Kernel::getAPI | ( | ) |
Get API.
Definition at line 148 of file Kernel.cpp.
References m_api.
Referenced by ARMKernel::trap(), and IntelKernel::trap().
CoreInfo * Kernel::getCoreInfo | ( | ) |
Get CoreInfo.
Definition at line 158 of file Kernel.cpp.
References m_coreInfo.
Referenced by ProcessShares::createShare(), and SystemInfoHandler().
MemoryContext * Kernel::getMemoryContext | ( | ) |
Get the current MMU context.
Definition at line 153 of file Kernel.cpp.
References ProcessManager::current(), Process::getMemoryContext(), and m_procs.
ProcessManager * Kernel::getProcessManager | ( | ) |
Get process manager.
Definition at line 143 of file Kernel.cpp.
References m_procs.
Referenced by IntelKernel::clocktick(), ProcessShares::createShare(), ARMKernel::dataAbort(), IntelKernel::exception(), SunxiKernel::interrupt(), ARMKernel::interrupt(), RaspberryKernel::interrupt(), ARMKernel::prefetchAbort(), PrivExecHandler(), ProcessCtlHandler(), ProcessShares::releaseShare(), ARMKernel::reserved(), ARMKernel::trap(), ARMKernel::undefinedInstruction(), VMCopyHandler(), VMCtlHandler(), VMShareHandler(), and ProcessShares::~ProcessShares().
Timer * Kernel::getTimer | ( | ) |
Get Timer.
Definition at line 163 of file Kernel.cpp.
References m_timer.
Referenced by ProcessCtlHandler(), and ProcessManager::schedule().
|
virtual |
Hooks a function to an hardware interrupt.
vec | Interrupt vector to hook on. |
h | Handler function. |
p | Parameter to pass to the handler function. |
Definition at line 194 of file Kernel.cpp.
References Vector< T >::insert(), and m_interrupts.
Referenced by IntelKernel::IntelKernel().
|
static |
Initialize heap.
This function sets up the kernel heap for dynamic memory allocation with new() and delete() operators. It must be called before any object is created using new().
Definition at line 108 of file Kernel.cpp.
References CoreInfo::bootImageAddress, CoreInfo::bootImageSize, coreInfo, CoreInfo::heapAddress, CoreInfo::heapSize, MemoryMap::KernelData, MegaByte, CoreInfo::memory, PAGESIZE, Memory::Range::phys, MemoryBlock::set(), Allocator::setDefault(), and Memory::Range::virt.
Referenced by kernel_main().
|
virtual |
Loads the boot image.
Definition at line 237 of file Kernel.cpp.
References BootImageStorage::bootImage(), CoreInfo::bootImageAddress, CoreInfo::bootImageSize, BootPrivProgram, BootProgram, FATAL, BootImageStorage::initialize(), IOError, loadBootProgram(), m_alloc, m_coreInfo, BootSymbol::name, NOTICE, BootImageStorage::read(), FileSystem::Success, Success, BootImage::symbolTableCount, BootImage::symbolTableOffset, SplitAllocator::toVirtual(), and BootSymbol::type.
Referenced by run().
|
privatevirtual |
Load a boot program.
bootImage | Reference to the BootImageStorage |
program | Reference to the BootSymbol of the program to load. |
Definition at line 288 of file Kernel.cpp.
References Memory::Range::access, Allocator::Range::address, Allocator::Range::alignment, SplitAllocator::allocate(), assert, BootImageStorage::bootImage(), BOOTIMAGE_NAMELEN, BootPrivProgram, BootProgram, MemoryBlock::copy(), ProcessManager::create(), BootSymbol::entry, Memory::Executable, FATAL, Process::getMemoryContext(), m_alloc, m_procs, MemoryContext::mapRangeContiguous(), BootSymbol::name, NOTICE, BootSegment::offset, PAGESIZE, Memory::Range::phys, ProcessError, MemoryMap::range(), BootImageStorage::read(), Memory::Readable, BootSymbol::segmentsCount, BootSymbol::segmentsOffset, BootImage::segmentsTableOffset, MemoryBlock::set(), Memory::Range::size, Allocator::Range::size, BootSegment::size, MemoryContext::Success, FileSystem::Success, Allocator::Success, Success, SplitAllocator::toVirtual(), BootSymbol::type, Memory::User, MemoryMap::UserArgs, Memory::Range::virt, BootSegment::virtualAddress, and Memory::Writable.
Referenced by loadBootImage().
int Kernel::run | ( | ) |
Execute the kernel.
Definition at line 392 of file Kernel.cpp.
References loadBootImage(), m_procs, NOTICE, and ProcessManager::schedule().
Referenced by kernel_main().
|
virtual |
Send a inter-processor-interrupt (IPI) to another core.
coreId | Target Core to deliver the interrupt to. |
irq | Interrupt number to deliver |
Definition at line 179 of file Kernel.cpp.
References coreId, ERROR, IOError, m_intControl, IntController::send(), IntController::Success, and Success.
Referenced by ProcessCtlHandler().
|
protected |
Physical memory allocator.
Definition at line 227 of file Kernel.h.
Referenced by ARMKernel::ARMKernel(), getAllocator(), IntelKernel::IntelKernel(), Kernel(), loadBootImage(), loadBootProgram(), and SunxiKernel::SunxiKernel().
|
protected |
|
protected |
CoreInfo object for this core.
Definition at line 236 of file Kernel.h.
Referenced by ARMKernel::ARMKernel(), getCoreInfo(), IntelKernel::IntelKernel(), Kernel(), loadBootImage(), and SunxiKernel::SunxiKernel().
|
protected |
Interrupt Controller.
Definition at line 242 of file Kernel.h.
Referenced by enableIRQ(), executeIntVector(), IntelKernel::IntelKernel(), SunxiKernel::interrupt(), RaspberryKernel::interrupt(), IntelKernel::interrupt(), Kernel(), RaspberryKernel::RaspberryKernel(), sendIRQ(), and SunxiKernel::SunxiKernel().
|
protected |
Interrupt handlers.
Definition at line 239 of file Kernel.h.
Referenced by executeIntVector(), hookIntVector(), and Kernel().
|
protected |
Process Manager.
Definition at line 230 of file Kernel.h.
Referenced by executeIntVector(), getMemoryContext(), getProcessManager(), Kernel(), loadBootProgram(), and run().
|
protected |
Timer device.
Definition at line 245 of file Kernel.h.
Referenced by IntelKernel::clocktick(), getTimer(), IntelKernel::IntelKernel(), SunxiKernel::interrupt(), RaspberryKernel::interrupt(), Kernel(), RaspberryKernel::RaspberryKernel(), and SunxiKernel::SunxiKernel().