/* Copyright (C) 2021 Rain */
/* This file is part of Cunix. */
/*
Cunix 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
(at your option) and later version.
*/
/*
Cunix 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 Cunix. If not, see .
*/
#ifndef INCLUDED_MM_H
#define INCLUDED_MM_H
#include
#include
#include
/* we should use &_end, not _end because they're empty symbols. */
/* define in kernel.lds */
extern __uint64_t _text, _etext;
extern __uint64_t _data, _edata;
extern __uint64_t _rodata, _erodata;
extern __uint64_t _bss, _ebss;
extern __uint64_t _end;
struct e820_entry {
__uint64_t addr;
__uint64_t len;
__uint32_t type;
} __attribute__ ((packed));
/* | 1MB | | total pages / 8 | | */
/* | E820 | KERNEL | PAGE BITMAP | HIGH MEMORY | */
struct mm {
__uint64_t total_ram;
__uint64_t total_pages;
__uint64_t usable_pages;
struct e820_entry *e820;
__uint64_t e820_entries;
struct bitmap_manager pages_bitman;
};
extern struct mm mman;
#define E820_ADDR ((struct e820_entry *) 0x0000000000006000)
errno_t mem_init(void);
void *palloc(void);
void pfree(void *addr);
#define PAGE_2M_SIZE 0x200000UL
#define PAGE_2M_SHIFT 21UL
#define PAGE_2M_MASK (~(PAGE_2M_SIZE - 1))
#define PAGE_4K_SIZE 0x1000UL
#define PAGE_4K_SHIFT 12UL
#define PAGE_4K_MASK (~(PAGE_4K_SIZE - 1))
#endif