2013-10-16 11:47:19 +02:00
|
|
|
/*
|
|
|
|
* \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_
|
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
#include <vm_state.h>
|
|
|
|
|
2013-10-16 11:47:19 +02:00
|
|
|
/* core includes */
|
|
|
|
#include <kernel/kernel.h>
|
|
|
|
#include <kernel/pd.h>
|
|
|
|
#include <kernel/signal_receiver.h>
|
|
|
|
|
|
|
|
namespace Kernel
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Kernel backend for a virtual machine
|
|
|
|
*/
|
|
|
|
class Vm;
|
|
|
|
|
|
|
|
typedef Object_pool<Vm> Vm_pool;
|
|
|
|
|
|
|
|
Vm_pool * vm_pool();
|
|
|
|
}
|
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
|
2015-03-27 13:55:03 +01:00
|
|
|
class Kernel::Vm : public Object<Vm, vm_pool>, public Cpu_job
|
2013-10-16 11:47:19 +02:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
enum State { ACTIVE, INACTIVE };
|
|
|
|
|
|
|
|
Genode::Vm_state * const _state;
|
|
|
|
Signal_context * const _context;
|
|
|
|
void * const _table;
|
|
|
|
State _scheduled = INACTIVE;
|
2013-10-16 11:47:19 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* \param state initial CPU state
|
|
|
|
* \param context signal for VM exceptions other than interrupts
|
2015-02-19 14:50:27 +01:00
|
|
|
* \param table translation table for guest to host physical memory
|
|
|
|
*/
|
|
|
|
Vm(void * const state,
|
|
|
|
Signal_context * const context,
|
|
|
|
void * const table);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inject an interrupt to this VM
|
|
|
|
*
|
|
|
|
* \param irq interrupt number to inject
|
2013-10-16 11:47:19 +02:00
|
|
|
*/
|
2015-02-19 14:50:27 +01:00
|
|
|
void inject_irq(unsigned irq);
|
2013-10-16 11:47:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
** Vm_session **
|
|
|
|
****************/
|
|
|
|
|
2015-02-19 14:50:27 +01:00
|
|
|
void run()
|
|
|
|
{
|
|
|
|
if (_scheduled != ACTIVE) Cpu_job::_activate_own_share();
|
|
|
|
_scheduled = ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pause()
|
|
|
|
{
|
|
|
|
if (_scheduled != INACTIVE) Cpu_job::_deactivate_own_share();
|
|
|
|
_scheduled = INACTIVE;
|
|
|
|
}
|
2013-10-16 11:47:19 +02:00
|
|
|
|
|
|
|
|
2014-10-09 14:24:27 +02:00
|
|
|
/*************
|
|
|
|
** Cpu_job **
|
|
|
|
*************/
|
2013-10-16 11:47:19 +02:00
|
|
|
|
2015-02-09 09:54:08 +01:00
|
|
|
void exception(unsigned const cpu);
|
2015-02-19 14:50:27 +01:00
|
|
|
void proceed(unsigned const cpu);
|
2014-12-01 15:10:33 +01:00
|
|
|
Cpu_job * helping_sink() { return this; }
|
2013-10-16 11:47:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _KERNEL__VM_H_ */
|