mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-21 02:01:38 +00:00
parent
22d61c241e
commit
0bb6ffa98d
@ -23,11 +23,11 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <cpu/cpu_state.h>
|
||||
#include <base/thread_state.h>
|
||||
|
||||
/* core includes */
|
||||
#include <kernel/pd.h>
|
||||
#include <kernel/vm.h>
|
||||
#include <platform_pd.h>
|
||||
#include <trustzone.h>
|
||||
#include <timer.h>
|
||||
@ -101,68 +101,6 @@ namespace Kernel
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
class Vm;
|
||||
class Vm_ids : public Id_allocator<MAX_VMS> { };
|
||||
typedef Object_pool<Vm> Vm_pool;
|
||||
|
||||
Vm_ids * vm_ids();
|
||||
Vm_pool * vm_pool();
|
||||
|
||||
class Vm : public Object<Vm, MAX_VMS, Vm_ids, vm_ids, vm_pool>,
|
||||
public Execution_context
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Cpu_state_modes * const _state;
|
||||
Signal_context * const _context;
|
||||
|
||||
public:
|
||||
|
||||
void * operator new (size_t, void * p) { return p; }
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
Vm(Genode::Cpu_state_modes * const state,
|
||||
Signal_context * const context)
|
||||
: _state(state), _context(context)
|
||||
{
|
||||
/* set VM to least priority by now */
|
||||
priority = 0;
|
||||
}
|
||||
|
||||
|
||||
/**************************
|
||||
** Vm_session interface **
|
||||
**************************/
|
||||
|
||||
void run() { cpu_scheduler()->insert(this); }
|
||||
void pause() { cpu_scheduler()->remove(this); }
|
||||
|
||||
|
||||
/***********************
|
||||
** Execution_context **
|
||||
***********************/
|
||||
|
||||
void handle_exception()
|
||||
{
|
||||
switch(_state->cpu_exception) {
|
||||
case Genode::Cpu_state::INTERRUPT_REQUEST:
|
||||
case Genode::Cpu_state::FAST_INTERRUPT_REQUEST:
|
||||
handle_interrupt();
|
||||
return;
|
||||
default:
|
||||
cpu_scheduler()->remove(this);
|
||||
_context->submit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void proceed() { mtc()->continue_vm(_state); }
|
||||
};
|
||||
|
||||
Vm_ids * vm_ids() { return unsynchronized_singleton<Vm_ids>(); }
|
||||
Vm_pool * vm_pool() { return unsynchronized_singleton<Vm_pool>(); }
|
||||
|
||||
/**
|
||||
* Access to static CPU scheduler
|
||||
*/
|
||||
|
24
base-hw/src/core/kernel/kernel.h
Normal file
24
base-hw/src/core/kernel/kernel.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* \brief Singlethreaded minimalistic kernel
|
||||
* \author Martin Stein
|
||||
* \date 2013-09-30
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL__KERNEL_H_
|
||||
#define _KERNEL__KERNEL_H_
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
unsigned core_id();
|
||||
|
||||
void handle_interrupt();
|
||||
}
|
||||
|
||||
#endif /* _KERNEL__KERNEL_H_ */
|
@ -31,6 +31,18 @@ namespace Kernel
|
||||
*/
|
||||
template <typename T>
|
||||
class Scheduler;
|
||||
|
||||
/**
|
||||
* Kernel object that can be scheduled for the CPU
|
||||
*/
|
||||
class Execution_context;
|
||||
|
||||
typedef Scheduler<Execution_context> Cpu_scheduler;
|
||||
|
||||
/**
|
||||
* Return the systems CPU scheduler
|
||||
*/
|
||||
Cpu_scheduler * cpu_scheduler();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -210,4 +222,27 @@ class Kernel::Scheduler
|
||||
void remove(T * const i) { _items[i->priority].remove(i); }
|
||||
};
|
||||
|
||||
class Kernel::Execution_context : public Cpu_scheduler::Item
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Handle an exception that occured during execution
|
||||
*/
|
||||
virtual void handle_exception() = 0;
|
||||
|
||||
/**
|
||||
* Continue execution
|
||||
*/
|
||||
virtual void proceed() = 0;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~Execution_context()
|
||||
{
|
||||
if (list()) { cpu_scheduler()->remove(this); }
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _KERNEL__SCHEDULER_H_ */
|
||||
|
@ -41,18 +41,6 @@ namespace Kernel
|
||||
void handle_interrupt(void);
|
||||
void reset_lap_time();
|
||||
|
||||
/**
|
||||
* Kernel object that can be scheduled for the CPU
|
||||
*/
|
||||
class Execution_context;
|
||||
|
||||
typedef Scheduler<Execution_context> Cpu_scheduler;
|
||||
|
||||
/**
|
||||
* Return the systems CPU scheduler
|
||||
*/
|
||||
static Cpu_scheduler * cpu_scheduler();
|
||||
|
||||
/**
|
||||
* Kernel backend for userland execution-contexts
|
||||
*/
|
||||
@ -65,29 +53,6 @@ namespace Kernel
|
||||
Thread_pool * thread_pool();
|
||||
}
|
||||
|
||||
class Kernel::Execution_context : public Cpu_scheduler::Item
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Handle an exception that occured during execution
|
||||
*/
|
||||
virtual void handle_exception() = 0;
|
||||
|
||||
/**
|
||||
* Continue execution
|
||||
*/
|
||||
virtual void proceed() = 0;
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~Execution_context()
|
||||
{
|
||||
if (list()) { cpu_scheduler()->remove(this); }
|
||||
}
|
||||
};
|
||||
|
||||
class Kernel::Thread
|
||||
:
|
||||
public Cpu::User_context,
|
||||
|
21
base-hw/src/core/kernel/vm.cc
Normal file
21
base-hw/src/core/kernel/vm.cc
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* \brief Kernel backend for virtual machines
|
||||
* \author Martin Stein
|
||||
* \date 2013-09-15
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
/* core includes */
|
||||
#include <kernel/vm.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
Vm_ids * vm_ids() { return unsynchronized_singleton<Vm_ids>(); }
|
||||
Vm_pool * vm_pool() { return unsynchronized_singleton<Vm_pool>(); }
|
||||
}
|
100
base-hw/src/core/kernel/vm.h
Normal file
100
base-hw/src/core/kernel/vm.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* \brief Kernel backend for virtual machines
|
||||
* \author Martin Stein
|
||||
* \date 2013-10-30
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL__VM_H_
|
||||
#define _KERNEL__VM_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <cpu/cpu_state.h>
|
||||
|
||||
/* core includes */
|
||||
#include <kernel/scheduler.h>
|
||||
#include <kernel/kernel.h>
|
||||
#include <kernel/pd.h>
|
||||
#include <kernel/signal_receiver.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
/**
|
||||
* Kernel backend for a virtual machine
|
||||
*/
|
||||
class Vm;
|
||||
|
||||
class Vm_ids : public Id_allocator<MAX_VMS> { };
|
||||
typedef Object_pool<Vm> Vm_pool;
|
||||
|
||||
Vm_ids * vm_ids();
|
||||
Vm_pool * vm_pool();
|
||||
}
|
||||
|
||||
class Kernel::Vm : public Object<Vm, MAX_VMS, Vm_ids, vm_ids, vm_pool>,
|
||||
public Execution_context
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Cpu_state_modes * const _state;
|
||||
Signal_context * const _context;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Placement new
|
||||
*/
|
||||
void * operator new (size_t, void * p) { return p; }
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param state initial CPU state
|
||||
* \param context signal for VM exceptions other than interrupts
|
||||
*/
|
||||
Vm(Genode::Cpu_state_modes * const state,
|
||||
Signal_context * const context)
|
||||
:
|
||||
_state(state), _context(context)
|
||||
{
|
||||
/* set VM to least priority by now */
|
||||
priority = 0;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
** Vm_session **
|
||||
****************/
|
||||
|
||||
void run() { cpu_scheduler()->insert(this); }
|
||||
|
||||
void pause() { cpu_scheduler()->remove(this); }
|
||||
|
||||
|
||||
/***********************
|
||||
** Execution_context **
|
||||
***********************/
|
||||
|
||||
void handle_exception()
|
||||
{
|
||||
switch(_state->cpu_exception) {
|
||||
case Genode::Cpu_state::INTERRUPT_REQUEST:
|
||||
case Genode::Cpu_state::FAST_INTERRUPT_REQUEST:
|
||||
handle_interrupt();
|
||||
return;
|
||||
default:
|
||||
cpu_scheduler()->remove(this);
|
||||
_context->submit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void proceed() { mtc()->continue_vm(_state); }
|
||||
};
|
||||
|
||||
#endif /* _KERNEL__VM_H_ */
|
@ -48,6 +48,7 @@ SRC_CC += console.cc \
|
||||
thread.cc \
|
||||
kernel.cc \
|
||||
kernel/thread.cc \
|
||||
kernel/vm.cc \
|
||||
kernel/signal_receiver.cc \
|
||||
rm_session_support.cc \
|
||||
kernel_support.cc \
|
||||
|
Loading…
x
Reference in New Issue
Block a user