HelenOS sources
#ifndef KERN_amd64_PM_H_
#define KERN_amd64_PM_H_
#ifndef __ASSEMBLER__
#include <typedefs.h>
#include <arch/context.h>
#endif
#define IDT_ITEMS 64
#define GDT_ITEMS 8
#define NULL_DES 0
#define KTEXT_DES 1
#define KDATA_DES 2
#define UDATA_DES 3
#define UTEXT_DES 4
#define KTEXT32_DES 5
#define TSS_DES 6
#ifdef CONFIG_FB
#define VESA_INIT_SEGMENT 0x8000
#define VESA_INIT_CODE_DES 8
#define VESA_INIT_DATA_DES 9
#undef GDT_ITEMS
#define GDT_ITEMS 10
#endif
#define GDT_SELECTOR(des) ((des) << 3)
#define PL_KERNEL 0
#define PL_USER 3
#define AR_PRESENT (1 << 7)
#define AR_DATA (2 << 3)
#define AR_CODE (3 << 3)
#define AR_WRITABLE (1 << 1)
#define AR_READABLE (1 << 1)
#define AR_TSS (0x09U)
#define AR_INTERRUPT (0x0eU)
#define AR_TRAP (0x0fU)
#define DPL_KERNEL (PL_KERNEL << 5)
#define DPL_USER (PL_USER << 5)
#define TSS_BASIC_SIZE 104
#define TSS_IOMAP_SIZE (8 * 1024 + 1)
#define IO_PORTS (64 * 1024)
#ifndef __ASSEMBLER__
typedef struct {
unsigned limit_0_15 : 16;
unsigned base_0_15 : 16;
unsigned base_16_23 : 8;
unsigned access : 8;
unsigned limit_16_19 : 4;
unsigned available : 1;
unsigned longmode : 1;
unsigned special : 1;
unsigned granularity : 1;
unsigned base_24_31 : 8;
} __attribute__((packed)) descriptor_t;
typedef struct {
unsigned limit_0_15 : 16;
unsigned base_0_15 : 16;
unsigned base_16_23 : 8;
unsigned type : 4;
unsigned : 1;
unsigned dpl : 2;
unsigned present : 1;
unsigned limit_16_19 : 4;
unsigned available : 1;
unsigned : 2;
unsigned granularity : 1;
unsigned base_24_31 : 8;
unsigned base_32_63 : 32;
unsigned : 32;
} __attribute__((packed)) tss_descriptor_t;
typedef struct {
unsigned offset_0_15 : 16;
unsigned selector : 16;
unsigned ist : 3;
unsigned unused : 5;
unsigned type : 5;
unsigned dpl : 2;
unsigned present : 1;
unsigned offset_16_31 : 16;
unsigned offset_32_63 : 32;
unsigned : 32;
} __attribute__((packed)) idescriptor_t;
typedef struct {
uint16_t limit;
uint64_t base;
} __attribute__((packed)) ptr_16_64_t;
typedef struct {
uint16_t limit;
uint32_t base;
} __attribute__((packed)) ptr_16_32_t;
typedef struct {
uint32_t reserve1;
uint64_t rsp0;
uint64_t rsp1;
uint64_t rsp2;
uint64_t reserve2;
uint64_t ist1;
uint64_t ist2;
uint64_t ist3;
uint64_t ist4;
uint64_t ist5;
uint64_t ist6;
uint64_t ist7;
uint64_t reserve3;
uint16_t reserve4;
uint16_t iomap_base;
uint8_t iomap[TSS_IOMAP_SIZE];
} __attribute__((packed)) tss_t;
extern tss_t *tss_p;
extern descriptor_t gdt[];
extern idescriptor_t idt[];
extern ptr_16_64_t gdtr;
extern ptr_16_32_t protected_ap_gdtr;
extern void pm_init(void);
extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base);
extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit);
extern void idt_init(void);
extern void idt_setoffset(idescriptor_t *d, uintptr_t offset);
extern void tss_initialize(tss_t *t);
#endif
#endif
HelenOS homepage, sources at GitHub