hw_x86_64: Add Tss class

The class Genode::Tss represents a 64-bit Task State Segment (TSS) as
specified by Intel SDM Vol. 3A, section 7.7.

The setup function sets the stack pointers for privilege levels 0-2 to
the kernel stack address. The load function loads the TSS segment
selector into the task register.
This commit is contained in:
Adrian-Ken Rueegsegger 2015-02-21 01:00:35 +01:00 committed by Christian Helmuth
parent 793b5264e3
commit 2af5aaa54d
3 changed files with 74 additions and 0 deletions

View File

@ -17,6 +17,7 @@ SRC_S += spec/x86_64/isr.s
# add C++ sources
SRC_CC += spec/x86_64/kernel/thread_base.cc
SRC_CC += spec/x86_64/idt.cc
SRC_CC += spec/x86_64/tss.cc
# include less specific configuration
include $(REP_DIR)/lib/mk/x86/core.inc

View File

@ -0,0 +1,53 @@
#ifndef _TSS_H_
#define _TSS_H_
#include <base/stdint.h>
namespace Genode
{
/**
* Task State Segment (TSS)
*
* See Intel SDM Vol. 3A, section 7.7
*/
class Tss;
}
class Genode::Tss
{
private:
enum {
TSS_SELECTOR = 0x28,
};
uint32_t : 32;
addr_t rsp0;
addr_t rsp1;
addr_t rsp2;
uint64_t : 64;
addr_t ist[7];
uint64_t : 64;
uint16_t : 16;
uint16_t iomap_base;
/**
* TSS
*/
static Tss _tss asm ("_tss");
public:
/**
* Setup TSS.
*/
static void setup();
/**
* Load TSS into TR.
*/
static void load();
}__attribute__((packed));
#endif /* _TSS_H_ */

View File

@ -0,0 +1,20 @@
#include "tss.h"
using namespace Genode;
extern char kernel_stack[];
__attribute__((aligned(8))) Tss Tss::_tss;
void Tss::setup()
{
_tss.rsp0 = (addr_t)kernel_stack;
_tss.rsp1 = (addr_t)kernel_stack;
_tss.rsp2 = (addr_t)kernel_stack;
}
void Tss::load()
{
asm volatile ("ltr %w0" : : "r" (TSS_SELECTOR));
}