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