1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/include/mm/gdt.h

116 lines
3.7 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: GDT related functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _MM_GDT_H
#define _MM_GDT_H
//----------------------------------------------------------------------------//
#define IOMAP_SIZE (8 * 1024)
//----------------------------------------------------------------------------//
// The gdt entry
struct GdtEntry_t
{
ushort lowLimit; // lower 16 bits
ushort lowBase; // lower 16 bits
uchar middleBase; // next 8 bits
uchar access; // determine what ring this segment can be used in
uchar flags;
uchar highBase; // last 8 bits
} __attribute__((__packed__));
struct TssDescriptor_t
{
ushort lowLimit;
ushort lowBase;
uchar middleBase;
uchar access;
uchar flags;
uchar highBase;
uint veryHighBase;
uint reserved;
} __attribute__ ((packed));
struct Tss_t
{
uint reserved1;
// Stack pointers (RSP) for privilege levels 0-2
ulong rsp0;
ulong rsp1;
ulong rsp2;
ulong reserved2;
// Interrupt stack table pointers
ulong ist1;
ulong ist2;
ulong ist3;
ulong ist4;
ulong ist5;
ulong ist6;
ulong ist7;
ulong reserved3;
ushort reserved4;
// Offset to the I/O permission bit map from the 64-bit TSS base
ushort iomap_base;
uchar iomap[IOMAP_SIZE];
} __attribute__ ((packed)) __attribute__((aligned(8)));
// The gdt pointer
struct GdtPtr_t
{
ushort limit; // upper 16 bits
ulong base; // address of the first entry
} __attribute__((__packed__));
//----------------------------------------------------------------------------//
//
// Initializes the descriptor table
//
void MmInitGdt(void);
//
// Loads the descriptor table
//
extern void MmLoadGdt(GdtPtr_t *gdtPtr, ushort tssOffset);
//
// Stores the descriptor table
//
extern void MmStoreGdt(void);
//----------------------------------------------------------------------------//
#endif