FreeNOS
Kernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 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 #ifndef __KERNEL_H
19 #define __KERNEL_H
20 
21 #include <Macros.h>
22 #include <Types.h>
23 #include <Vector.h>
24 #include <List.h>
25 #include <Singleton.h>
26 #include <BootImage.h>
27 #include <Memory.h>
28 #include <CoreInfo.h>
29 
31 class API;
32 class BootImageStorage;
33 class MemoryContext;
34 class Process;
35 class ProcessManager;
36 class SplitAllocator;
37 class IntController;
38 class Timer;
39 struct CPUState;
40 
53 typedef void InterruptHandler(struct CPUState *state, ulong param, ulong vector);
54 
58 typedef struct InterruptHook
59 {
67  {
68  }
69 
77  {
78  return handler == i->handler && param == i->param;
79  }
80 
83 
86 }
88 
92 class Kernel : public WeakSingleton<Kernel>
93 {
94  public:
95 
99  enum Result
100  {
105  };
106 
112  Kernel(CoreInfo *info);
113 
124  static Error initializeHeap();
125 
132 
139 
145  API * getAPI();
146 
153 
159  CoreInfo * getCoreInfo();
160 
166  Timer * getTimer();
167 
171  int run();
172 
179  virtual void enableIRQ(u32 irq, bool enabled);
180 
189  virtual Result sendIRQ(const uint coreId, const uint irq);
190 
198  virtual void hookIntVector(u32 vec, InterruptHandler h, ulong p);
199 
206  virtual void executeIntVector(u32 vec, CPUState *state);
207 
211  virtual Result loadBootImage();
212 
213  private:
214 
221  virtual Result loadBootProgram(const BootImageStorage &bootImage,
222  const BootSymbol &program);
223 
224  protected:
225 
228 
231 
234 
237 
240 
243 
246 };
247 
252 #endif /* __KERNEL_H */
InterruptHook
Interrupt hook class.
Definition: Kernel.h:58
Kernel::InvalidBootImage
@ InvalidBootImage
Definition: Kernel.h:102
IntController
Interrupt controller interface.
Definition: IntController.h:35
InterruptHook::handler
InterruptHandler * handler
Executed at time of interrupt.
Definition: Kernel.h:82
Kernel::m_api
API * m_api
API handlers object.
Definition: Kernel.h:233
ProcessManager
Represents a process which may run on the host.
Definition: ProcessManager.h:44
InterruptHandler
void InterruptHandler(struct CPUState *state, ulong param, ulong vector)
Function which is called when the CPU is interrupted.
Definition: Kernel.h:53
MemoryContext
Virtual memory abstract interface.
Definition: MemoryContext.h:42
Macros.h
Vector.h
Kernel::loadBootProgram
virtual Result loadBootProgram(const BootImageStorage &bootImage, const BootSymbol &program)
Load a boot program.
Definition: Kernel.cpp:288
Kernel::Result
Result
Result codes.
Definition: Kernel.h:99
ulong
unsigned long ulong
Unsigned long number.
Definition: Types.h:47
Types.h
Kernel::m_coreInfo
CoreInfo * m_coreInfo
CoreInfo object for this core.
Definition: Kernel.h:236
Process
Represents a process which may run on the host.
Definition: Process.h:44
InterruptHook::operator==
bool operator==(InterruptHook *i)
Comparision operator.
Definition: Kernel.h:76
Kernel::getMemoryContext
MemoryContext * getMemoryContext()
Get the current MMU context.
Definition: Kernel.cpp:153
Kernel::m_timer
Timer * m_timer
Timer device.
Definition: Kernel.h:245
Kernel::IOError
@ IOError
Definition: Kernel.h:104
Kernel::initializeHeap
static Error initializeHeap()
Initialize heap.
Definition: Kernel.cpp:108
BootImageStorage
Uses a BootImage as a storage provider.
Definition: BootImageStorage.h:38
InterruptHook
struct InterruptHook InterruptHook
Interrupt hook class.
param
void param(Terminal *term, int key, int value)
Set terminal parameters.
Definition: Terminal.cpp:305
Kernel::run
int run()
Execute the kernel.
Definition: Kernel.cpp:392
Kernel::getAllocator
SplitAllocator * getAllocator()
Get physical memory allocator.
Definition: Kernel.cpp:138
Kernel::Success
@ Success
Definition: Kernel.h:101
API
Generic Kernel API implementation.
Definition: API.h:39
Timer
Represents a configurable timer device.
Definition: Timer.h:35
Kernel::sendIRQ
virtual Result sendIRQ(const uint coreId, const uint irq)
Send a inter-processor-interrupt (IPI) to another core.
Definition: Kernel.cpp:179
Kernel::getProcessManager
ProcessManager * getProcessManager()
Get process manager.
Definition: Kernel.cpp:143
Kernel::ProcessError
@ ProcessError
Definition: Kernel.h:103
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
SplitAllocator
Allocator which separates kernel mapped memory at virtual and physical addresses.
Definition: SplitAllocator.h:37
Kernel::m_intControl
IntController * m_intControl
Interrupt Controller.
Definition: Kernel.h:242
Kernel::getCoreInfo
CoreInfo * getCoreInfo()
Get CoreInfo.
Definition: Kernel.cpp:158
BootImage.h
Kernel::m_interrupts
Vector< List< InterruptHook * > * > m_interrupts
Interrupt handlers.
Definition: Kernel.h:239
Kernel::enableIRQ
virtual void enableIRQ(u32 irq, bool enabled)
Enable or disable an hardware interrupt (IRQ).
Definition: Kernel.cpp:168
Kernel::getAPI
API * getAPI()
Get API.
Definition: Kernel.cpp:148
Error
slong Error
Error code defined in Error.h.
Definition: Types.h:159
Kernel::Kernel
Kernel(CoreInfo *info)
Constructor function.
Definition: Kernel.cpp:33
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
InterruptHook::param
ulong param
Passed to the handler.
Definition: Kernel.h:85
Kernel
FreeNOS kernel implementation.
Definition: Kernel.h:92
WeakSingleton
Singleton design pattern: only one instance is allowed.
Definition: Singleton.h:69
CPUState
Contains all the CPU registers.
Definition: ARMCore.h:243
CoreInfo
Per-Core information structure.
Definition: CoreInfo.h:60
Memory.h
BootSymbol
Program embedded in the BootImage.
Definition: BootImage.h:84
InterruptHook::InterruptHook
InterruptHook(InterruptHandler *h, ulong p)
Constructor function.
Definition: Kernel.h:66
Singleton.h
Kernel::hookIntVector
virtual void hookIntVector(u32 vec, InterruptHandler h, ulong p)
Hooks a function to an hardware interrupt.
Definition: Kernel.cpp:194
Kernel::m_procs
ProcessManager * m_procs
Process Manager.
Definition: Kernel.h:230
CoreInfo.h
CPUState::vector
u32 vector
Definition: IntelCore.h:247
Kernel::m_alloc
SplitAllocator * m_alloc
Physical memory allocator.
Definition: Kernel.h:227
Kernel::loadBootImage
virtual Result loadBootImage()
Loads the boot image.
Definition: Kernel.cpp:237
Vector
Vectors are dynamically resizeable Arrays.
Definition: Vector.h:41
Kernel::getTimer
Timer * getTimer()
Get Timer.
Definition: Kernel.cpp:163
coreId
u8 coreId
Definition: IntelACPI.h:64
Kernel::executeIntVector
virtual void executeIntVector(u32 vec, CPUState *state)
Execute an interrupt handler.
Definition: Kernel.cpp:210
List.h