All pastes #42605 Raw Edit

Untitled

public text v1 · immutable
#42605 ·published 2006-02-21 07:21 UTC
rendered paste body
/*
	© 2006 XOWare. All Rights Reserved.
	This software is not redistributable in source form without
	explicit permission. For more information about the terms
	and conditions the use and or distribution of this software
	entails, please refer to the complete license located in
	this project's source folder: "Source/License.html".
	
	Module:	X86 Internal Descriptor Table
*/

module Titan.Platforms.X86.IDT;

/* Imports */
private
{
    import Titan.Core;
	alias Titan.Platform.Segment.POINTER POINTER;
}

/* Structs */
align(1) struct DESCRIPTOR
{
    ushort offsetLow;
    ushort segmentSelector;
    ushort flags;
    ushort offsetHigh;
}

/* Members */
private
{
    POINTER pointer;
    DESCRIPTOR[0xFF] descriptors;
}

/* Functions */
void Initialize()
{
    pointer.base = cast(uint)descriptors.ptr;
    pointer.limit = 0x07FF;
    
    DESCRIPTOR r;
    r.offsetLow = 0;
    r.segmentSelector = 0;
    r.flags = 0;
    r.offsetHigh = 0;
    
    for(int i = 0; i < 0xFF; i++)
    {
        descriptors[i] = r;
    }
    asm
    {
	    lidt [pointer];
    }      
}

void InstallIDTEntry(ubyte num, uint base, ushort sel, ubyte flags)
{
	descriptors[num].offsetHigh = cast(ushort)((base >> 16) & 0xFFFF);
	descriptors[num].offsetLow = cast(ushort)(base & 0xFFFF);
	descriptors[num].flags = cast(ushort)(flags);
	descriptors[num].segmentSelector = sel;
}