2019-03-26 18:20:23 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
|
|
|
// Desc: Mapping and checking memory 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/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-05-13 23:22:27 +02:00
|
|
|
#include <mm/mm.h>
|
2019-05-22 00:38:04 +02:00
|
|
|
#include <init/boot.h>
|
2019-03-26 18:20:23 +01:00
|
|
|
|
2020-01-06 00:30:50 +01:00
|
|
|
GdtPtr_t gdtPtr;
|
|
|
|
GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE)));
|
|
|
|
TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE)));
|
|
|
|
Tss_t tss __attribute__((__aligned__(KPAGESIZE)));
|
2019-03-29 10:29:05 +01:00
|
|
|
|
2019-05-19 23:33:34 +02:00
|
|
|
void MmInitGdt(void)
|
|
|
|
{
|
2019-05-22 00:38:04 +02:00
|
|
|
ushort tssOffset = (ushort)((ulong)(&gdt[2]) - (ulong)(&gdt[0]));
|
|
|
|
|
|
|
|
gdtPtr.base = (ulong)&gdt[0];
|
|
|
|
gdtPtr.limit = sizeof(gdt) - 1;
|
|
|
|
|
|
|
|
memzero((void *)&gdt[0], sizeof(gdt));
|
|
|
|
memzero((void *)&tssDesc, sizeof(tssDesc));
|
|
|
|
memzero((void *)&tss, sizeof(tss));
|
|
|
|
|
|
|
|
gdt[1].lowLimit = 0xFFFF;
|
|
|
|
gdt[1].access = 0x98;
|
|
|
|
gdt[1].flags = 0x20;
|
|
|
|
|
|
|
|
tssDesc.access = 0x89;
|
|
|
|
tssDesc.flags = 0x40;
|
|
|
|
tssDesc.lowBase = (ulong)&tss & 0xFFFF;
|
|
|
|
tssDesc.middleBase = ((ulong)&tss >> 16) & 0xFF;
|
|
|
|
tssDesc.highBase = ((ulong)&tss >> 24) & 0xFF;
|
|
|
|
tssDesc.veryHighBase = ((ulong)&tss >> 32) & 0xFFFFFFFF;
|
|
|
|
tssDesc.lowLimit = sizeof(tss);
|
|
|
|
|
2020-01-05 20:13:53 +01:00
|
|
|
tss.ist1 = (ulong)0x0007FFFF; // ISR RESCUE STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
|
|
|
|
tss.ist2 = (ulong)0x00EFFFFF; // ISR STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
|
2020-01-07 00:44:39 +01:00
|
|
|
tss.ist3 = (ulong)0x00EF0000; // ISR STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
|
2019-05-22 00:38:04 +02:00
|
|
|
tss.iomap_base = sizeof(tss);
|
|
|
|
|
|
|
|
memmove(&gdt[2], &tssDesc, sizeof(TssDescriptor_t));
|
|
|
|
|
|
|
|
/* DebugLog("TSS\n" */
|
|
|
|
/* "gdt[0] %#x\n" */
|
|
|
|
/* "gdt[2] %#x\n" */
|
|
|
|
/* "access : %#x\n" */
|
|
|
|
/* "flags : %#x\n" */
|
|
|
|
/* "lowBase : %#x\n" */
|
|
|
|
/* "middleBase : %#x\n" */
|
|
|
|
/* "highBase : %#x\n" */
|
|
|
|
/* "veryHighBase: %#x\n" */
|
|
|
|
/* "lowLimit : %#x\n" */
|
|
|
|
/* "ist : %#x\n" */
|
|
|
|
/* "iomap_base : %#x\n" */
|
|
|
|
/* "offset : %#x\n", */
|
|
|
|
/* &gdt[0], */
|
|
|
|
/* &gdt[2], */
|
|
|
|
/* tssDesc.access, */
|
|
|
|
/* tssDesc.flags, */
|
|
|
|
/* tssDesc.lowBase, */
|
|
|
|
/* tssDesc.middleBase, */
|
|
|
|
/* tssDesc.highBase, */
|
|
|
|
/* tssDesc.veryHighBase, */
|
|
|
|
/* tssDesc.lowLimit, */
|
|
|
|
/* tss.ist1, */
|
|
|
|
/* tss.iomap_base, */
|
|
|
|
/* tssOffset */
|
|
|
|
/* ); */
|
|
|
|
|
|
|
|
MmLoadGdt(&gdtPtr, tssOffset);
|
2019-03-29 10:29:05 +01:00
|
|
|
}
|