diff --git a/include/mm/mm.h b/include/mm/mm.h deleted file mode 100644 index cb6a005..0000000 --- a/include/mm/mm.h +++ /dev/null @@ -1,213 +0,0 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Desc: Memory manager 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 . // -//----------------------------------------------------------------------------// - -#ifndef _KERNEL_H -#include -#endif - -#ifndef _MM_MM_H -#define _MM_MM_H - -//----------------------------------------------------------------------------// - -#define MINIMUM_RAM_SIZE 16 // Mio, the minimum RAM size. -#define IOMAP_SIZE (8 * 1024) - -#define AVAILABLE_ZONE 1 // Fully usable RAM zone -#define RESERVED_ZONE 2 // Used by the firmware -#define ACPI_ZONE 3 // Used by ACPI but can be freed -#define NVS_ZONE 4 // Dunno -#define BADRAM_ZONE 5 // Invalid zone because material problem... -#define MAX_ENTRIES 2048 // Max number of memory map entries -#define KPAGESIZE (4 * KB) -#define UPAGESIZE (4 * KB) - -//----------------------------------------------------------------------------// - -// The entry structure of the map -struct MapEntry_t { - void *addr; - size_t length; // in bytes - uint type; // reserved or not -} __attribute__((__packed__)); - -// the map structure -struct MemoryMap_t { - size_t length; - size_t freeRamSize; - size_t nonfreeRamSize; - MapEntry_t entry[MAX_ENTRIES]; -} __attribute__((__packed__)); - -// 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 memory map structure -// -void MmInitMemoryMap(void); - -// -// Initializes the memory map structure -// -void MmPrintMemoryMap(void); - -// -// Returns the size of the first available memory zone -// from the start address pointer -// -size_t MmGetAvailZoneSize(void *start); - -// -// Returns the first available memory zone from the start address pointer -// -void *MmGetFirstAvailZone(void *start); - -// -// 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); - -// -// Paging misc -// -void MmInitPaging(void); - -void MmActivatePageHandler(void); - -// -// Returns the address of the stack guard pages -// -void *MmGetStackGuards(char rank); - -// -// Translate a virtual address into physical address and the opposite -// -void *MmTransVirtToPhyAddr(void*); -void *MmTransPhyToVirtAddr(void* virtualAddr); - -// -// Set flags to a page -// -void MmSetPage(void* virtualAddr, ulong flags); -void MmUnSetPage(void* virtualAddr, ulong flags); - -// -// Map a page -// -void MmMapPage(void* virtualAddr, void* physicalAddr, ulong flags); -void MmUnmapPage(void* virtualAddr); - -// Allocations -void *MmGetPhyPageBlock(size_t size, bool usermode); - -// Page table entry -typedef ulong pte_t; - -// Page directory offset -typedef pte_t* pde_t; - -// Page directory pointer offset -typedef pde_t* pdpe_t; - -// Page directory L4 pointer offset -typedef pdpe_t* pml4_t; - -// paging.asm -void MmLoadPML4(void *); -void MmEnableWriteProtect(void); -void MmDisableWriteProtect(void); - -//----------------------------------------------------------------------------// - -#endif diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 12d3792..3a3144c 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -22,7 +22,9 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// -#include +#include +#include +#include #include #include #include diff --git a/kaleid/kernel/mm/gdt.c b/kaleid/kernel/mm/gdt.c index 8bd426a..6a5c188 100644 --- a/kaleid/kernel/mm/gdt.c +++ b/kaleid/kernel/mm/gdt.c @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------// // GNU GPL OS/K // // // -// Desc: Mapping and checking memory related functions // +// Desc: GDT related functions // // // // // // Copyright © 2018-2019 The OS/K Team // @@ -22,7 +22,8 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// -#include +#include +#include #include GdtPtr_t gdtPtr; diff --git a/kaleid/kernel/mm/heap.c b/kaleid/kernel/mm/heap.c index a968231..b4c0c58 100644 --- a/kaleid/kernel/mm/heap.c +++ b/kaleid/kernel/mm/heap.c @@ -22,7 +22,7 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// -#include +#include #include #include #include diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index f7e164c..64156fe 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -22,7 +22,7 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// -#include +#include #include #include #include diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index fa55202..86aee49 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -1,8 +1,33 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Paging 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 . // +//---------------------------------------------------------------------------- + #include #include #include #include -#include +#include +#include #include #include #include @@ -292,52 +317,6 @@ void MmUnmapPage(void* virtualAddr) KeFlushTlbSingle(*page); } -// -// Find a free block of pages -// -/* void *MmGetPhyPageBlock(size_t size, bool usermode) { */ -/* void *startPhyPage = 0; */ -/* void *endPhyPage = 0; */ -/* ulong offset = 0; */ -/* size_t curSize = 0; */ - -/* // Maximum PHYSICAL address in memory */ -/* ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; */ - -/* ulong curVirtAddr = 0; */ - -/* if (!usermode) { */ -/* startPhyPage = MmTransVirtToPhyAddr((void*)KPAGESIZE); */ -/* endPhyPage = (void*)MmPhysLastKernAddress; */ -/* offset = 0; */ -/* } else { */ -/* startPhyPage = MmTransVirtToPhyAddr((void*)USERSPACE); */ -/* endPhyPage = (void*)(phRamSize & ~(KPAGESIZE - 1)); */ -/* offset = (ulong)USERSPACE - MmPhysLastKernAddress - KPAGESIZE; */ -/* } */ - -/* DebugLog("Start phy at %p\n", startPhyPage); */ -/* DebugLog("End phy at %p\n", endPhyPage); */ - -/* for (ulong curPhyAddr = (ulong)startPhyPage; */ -/* curPhyAddr <= (ulong)endPhyPage; */ -/* curPhyAddr += KPAGESIZE) { */ -/* curVirtAddr = (ulong)MmTransPhyToVirtAddr((void*)curPhyAddr); */ - - -/* if (curVirtAddr == 0) { */ -/* DebugLog("CurrentAddr %p\n", curPhyAddr); */ -/* DebugLog("\t Free !\n"); */ -/* curSize += KPAGESIZE; */ -/* } */ - -/* if (curSize >= size) */ -/* break; */ -/* } */ - -/* return NULL; */ -/* } */ - //----------- // diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index 0507e59..d74d7fd 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -23,7 +23,8 @@ //----------------------------------------------------------------------------// #include -#include +#include +#include #include #include #include diff --git a/kaleid/kernel/sh/testcmds.c b/kaleid/kernel/sh/testcmds.c index 8af2fdb..e83667f 100644 --- a/kaleid/kernel/sh/testcmds.c +++ b/kaleid/kernel/sh/testcmds.c @@ -23,7 +23,8 @@ //----------------------------------------------------------------------------// #include -#include +#include +#include #include #include #include @@ -255,7 +256,7 @@ error_t CmdPageBlock(int argc, char **argv, char *cmdline) size_t size = (size_t)atoi(argv[1]); bool usermode = (bool)atoi(argv[2]); - MmGetPhyPageBlock(size, usermode); + //MmGetPhyPageBlock(size, usermode); return EOK; }