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/mm.h
Julian Barathieu 409e74f934 Header overhaul
2019-05-13 23:22:27 +02:00

146 lines
4.5 KiB
C

//----------------------------------------------------------------------------//
// 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 <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _MM_MM_H
#define _MM_MM_H
//----------------------------------------------------------------------------//
#define MINIMUM_RAM_SIZE 16 // Mio, the minimum RAM size.
#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
//----------------------------------------------------------------------------//
// 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
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 granularity;
uchar highBase; // last 8 bits
} __attribute__((__packed__));
struct TssDescriptor_t
{
ushort limitLow;
ushort base00;
uchar base16;
uchar access;
uchar size;
uchar base24;
uint base32;
uint reserved;
} __attribute__ ((packed));
struct TssEntry_t
{
uint reserved0;
ulong privStackPointer[3]; // stack pointers for CPL 0-2
ulong intStackTable[8]; // /!\ [0] is reserved
ulong reserved1;
ushort reserved2;
ushort ioMapOffset;
} __attribute__ ((packed));
// The gdt pointer
struct GdtPtr_t
{
uchar limit; // upper 16 bits
ushort 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(ulong ds, ulong cs, ulong tr);
//
// Stores the descriptor table
//
extern void MmStoreGdt(void);
//----------------------------------------------------------------------------//
#endif