2019-03-14 18:33:12 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
|
|
|
// Desc: 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-03-18 17:43:41 +01:00
|
|
|
|
|
|
|
#include <kernel/base.h>
|
|
|
|
|
2019-03-24 20:25:11 +01:00
|
|
|
#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
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
typedef struct MemoryMap_t MemoryMap_t;
|
|
|
|
typedef struct MapEntry_t MapEntry_t;
|
2019-03-26 17:50:03 +01:00
|
|
|
typedef struct GdtEntry_t GdtEntry_t;
|
|
|
|
typedef struct GdtPtr_t GdtPtr_t;
|
2019-03-24 20:25:11 +01:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------- //
|
|
|
|
// The entry structure of the map
|
|
|
|
struct MapEntry_t {
|
|
|
|
void *addr;
|
|
|
|
size_t length; // in bytes
|
|
|
|
uint type; // reserved or not
|
2019-03-25 17:33:51 +01:00
|
|
|
} __attribute__((__packed__));
|
2019-03-24 20:25:11 +01:00
|
|
|
|
|
|
|
// the map structure
|
|
|
|
struct MemoryMap_t {
|
|
|
|
size_t length;
|
|
|
|
size_t freeRamSize;
|
|
|
|
size_t nonfreeRamSize;
|
|
|
|
MapEntry_t entry[MAX_ENTRIES];
|
2019-03-25 17:33:51 +01:00
|
|
|
} __attribute__((__packed__));
|
2019-03-21 13:30:17 +01:00
|
|
|
|
2019-03-26 17:50:03 +01:00
|
|
|
// 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));
|
2019-03-24 20:25:11 +01:00
|
|
|
|
2019-03-26 17:50:03 +01:00
|
|
|
struct GdtPtr_t
|
|
|
|
{
|
|
|
|
uchar limit; // upper 16 bits
|
|
|
|
ushort base; // address of the first entry
|
|
|
|
}
|
|
|
|
__attribute__((packed));
|
2019-03-24 20:25:11 +01:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------- //
|
2019-03-18 17:43:41 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Initializes the memory map structure
|
|
|
|
//
|
2019-03-24 14:44:59 +01:00
|
|
|
error_t MmInitMemoryMap(void);
|
2019-03-18 17:43:41 +01:00
|
|
|
|
2019-03-24 20:25:11 +01:00
|
|
|
//
|
2019-03-25 17:33:51 +01:00
|
|
|
// Returns the size of the first available memory zone
|
|
|
|
// from the start address pointer
|
2019-03-24 20:25:11 +01:00
|
|
|
//
|
2019-03-24 21:16:19 +01:00
|
|
|
size_t MmGetAvailZoneSize(void *start);
|
2019-03-24 20:25:11 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Returns the first available memory zone from the start address pointer
|
2019-03-26 17:50:03 +01:00
|
|
|
//
|
2019-03-24 21:24:21 +01:00
|
|
|
void *MmGetFirstAvailZone(void *start);
|
2019-03-24 20:25:11 +01:00
|
|
|
|
2019-03-26 17:50:03 +01:00
|
|
|
//
|
|
|
|
// Initialize the descriptor table
|
|
|
|
//
|
|
|
|
void MmInitGdt(void);
|
2019-03-18 17:43:41 +01:00
|
|
|
// -------------------------------------------------------------------------- //
|