FreeNOS
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions
Kernel Class Reference

FreeNOS kernel implementation. More...

#include <Kernel.h>

Inheritance diagram for Kernel:
WeakSingleton< Kernel > ARMKernel IntelKernel RaspberryKernel SunxiKernel

Public Types

enum  Result { Success, InvalidBootImage, ProcessError, IOError }
 Result codes. More...
 

Public Member Functions

 Kernel (CoreInfo *info)
 Constructor function. More...
 
SplitAllocatorgetAllocator ()
 Get physical memory allocator. More...
 
ProcessManagergetProcessManager ()
 Get process manager. More...
 
APIgetAPI ()
 Get API. More...
 
MemoryContextgetMemoryContext ()
 Get the current MMU context. More...
 
CoreInfogetCoreInfo ()
 Get CoreInfo. More...
 
TimergetTimer ()
 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 Kernelinstance ()
 Retrieve the instance. More...
 

Protected Attributes

SplitAllocatorm_alloc
 Physical memory allocator. More...
 
ProcessManagerm_procs
 Process Manager. More...
 
APIm_api
 API handlers object. More...
 
CoreInfom_coreInfo
 CoreInfo object for this core. More...
 
Vector< List< InterruptHook * > * > m_interrupts
 Interrupt handlers. More...
 
IntControllerm_intControl
 Interrupt Controller. More...
 
Timerm_timer
 Timer device. More...
 

Private Member Functions

virtual Result loadBootProgram (const BootImageStorage &bootImage, const BootSymbol &program)
 Load a boot program. More...
 

Detailed Description

FreeNOS kernel implementation.

Definition at line 92 of file Kernel.h.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
InvalidBootImage 
ProcessError 
IOError 

Definition at line 99 of file Kernel.h.

Constructor & Destructor Documentation

◆ Kernel()

Kernel::Kernel ( CoreInfo info)

Member Function Documentation

◆ enableIRQ()

void Kernel::enableIRQ ( u32  irq,
bool  enabled 
)
virtual

Enable or disable an hardware interrupt (IRQ).

Parameters
irqIRQ number.
enabledTrue 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().

◆ executeIntVector()

void Kernel::executeIntVector ( u32  vec,
CPUState state 
)
virtual

Execute an interrupt handler.

Parameters
vecInterrupt vector.
stateCPU 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().

◆ getAllocator()

SplitAllocator * Kernel::getAllocator ( )

Get physical memory allocator.

Returns
SplitAllocator object pointer

Definition at line 138 of file Kernel.cpp.

References m_alloc.

Referenced by ProcessShares::releaseShare(), SystemInfoHandler(), VMCtlHandler(), and IntelProcess::~IntelProcess().

◆ getAPI()

API * Kernel::getAPI ( )

Get API.

Returns
Kernel API object pointer.

Definition at line 148 of file Kernel.cpp.

References m_api.

Referenced by ARMKernel::trap(), and IntelKernel::trap().

◆ getCoreInfo()

CoreInfo * Kernel::getCoreInfo ( )

Get CoreInfo.

Returns
CoreInfo object pointer

Definition at line 158 of file Kernel.cpp.

References m_coreInfo.

Referenced by ProcessShares::createShare(), and SystemInfoHandler().

◆ getMemoryContext()

MemoryContext * Kernel::getMemoryContext ( )

Get the current MMU context.

Returns
MemoryContext object pointer

Definition at line 153 of file Kernel.cpp.

References ProcessManager::current(), Process::getMemoryContext(), and m_procs.

◆ getProcessManager()

ProcessManager * Kernel::getProcessManager ( )

◆ getTimer()

Timer * Kernel::getTimer ( )

Get Timer.

Returns
Timer object pointer

Definition at line 163 of file Kernel.cpp.

References m_timer.

Referenced by ProcessCtlHandler(), and ProcessManager::schedule().

◆ hookIntVector()

void Kernel::hookIntVector ( u32  vec,
InterruptHandler  h,
ulong  p 
)
virtual

Hooks a function to an hardware interrupt.

Parameters
vecInterrupt vector to hook on.
hHandler function.
pParameter 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().

◆ initializeHeap()

Error Kernel::initializeHeap ( )
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().

Returns
Zero on success or error code on failure.

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().

◆ loadBootImage()

Kernel::Result Kernel::loadBootImage ( )
virtual

◆ loadBootProgram()

Kernel::Result Kernel::loadBootProgram ( const BootImageStorage bootImage,
const BootSymbol program 
)
privatevirtual

◆ run()

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().

◆ sendIRQ()

Kernel::Result Kernel::sendIRQ ( const uint  coreId,
const uint  irq 
)
virtual

Send a inter-processor-interrupt (IPI) to another core.

Parameters
coreIdTarget Core to deliver the interrupt to.
irqInterrupt number to deliver
Returns
Result code

Definition at line 179 of file Kernel.cpp.

References coreId, ERROR, IOError, m_intControl, IntController::send(), IntController::Success, and Success.

Referenced by ProcessCtlHandler().

Field Documentation

◆ m_alloc

SplitAllocator* Kernel::m_alloc
protected

◆ m_api

API* Kernel::m_api
protected

API handlers object.

Definition at line 233 of file Kernel.h.

Referenced by getAPI(), and Kernel().

◆ m_coreInfo

CoreInfo* Kernel::m_coreInfo
protected

◆ m_intControl

IntController* Kernel::m_intControl
protected

◆ m_interrupts

Vector<List<InterruptHook *> *> Kernel::m_interrupts
protected

Interrupt handlers.

Definition at line 239 of file Kernel.h.

Referenced by executeIntVector(), hookIntVector(), and Kernel().

◆ m_procs

ProcessManager* Kernel::m_procs
protected

Process Manager.

Definition at line 230 of file Kernel.h.

Referenced by executeIntVector(), getMemoryContext(), getProcessManager(), Kernel(), loadBootProgram(), and run().

◆ m_timer

Timer* Kernel::m_timer
protected

The documentation for this class was generated from the following files: